Skip to content

Particle Signer

ParticleSigner is a signer implementation which extends SmartAccountAuthenticator to leverage the Particle SDK. It supports features such as authentication, message and typed data signing, and authentication details retrieval.

ParticleSigner provides implementations for all methods on SmartAccountAuthenticator:

  1. authenticate -- supports user authentication.
  2. getAddress -- gets the address of the the smart contract account's connected EOA signer account.
  3. signMessage -- supports message signatures.
  4. signTypedData -- supports typed data signatures.
  5. getAuthDetails -- supports authentication details retrieval.

Install Dependencies

ParticleSigner requires installation of the @particle-network/auth and @particle-network/provider. aa-signers lists them as optional dependencies.

bash
npm i -s @particle-network/auth
npm i -s @particle-network/provider
bash
yarn add @particle-network/auth
yarn add @particle-network/provider

Usage

ts
import { createParticleSigner } from "./particle";

const particleSigner = await createParticleSigner();

const address = await particleSigner.getAddress();

const details = await particleSigner.getAuthDetails();

const signedMessage = await particleSigner.signMessage("test");

const typedData = {
  types: {
    Request: [{ name: "hello", type: "string" }],
  },
  primaryType: "Request",
  message: {
    hello: "world",
  },
};
const signTypedData = await particleSigner.signTypedData(typedData);
ts
import { ParticleSigner } from "@alchemy/aa-signers/particle";
import { ParticleNetwork } from "@particle-network/auth";
import { ParticleProvider } from "@particle-network/provider";

export const createParticleSigner = async () => {
  const particle = new ParticleNetwork({
    projectId: process.env.REACT_APP_PROJECT_ID as string,
    clientKey: process.env.REACT_APP_CLIENT_KEY as string,
    appId: process.env.REACT_APP_APP_ID as string,
    chainName: "polygon",
    chainId: 80001,
  });
  const particleProvider = new ParticleProvider(particle.auth);

  const particleSigner = new ParticleSigner({
    inner: particle,
    provider: particleProvider,
  });

  particleSigner.authenticate({
    loginOptions: {},
    login: async (loginOptions) => {
      particleSigner.inner.auth.login(loginOptions);
    },
  });

  return particleSigner;
};