Skip to content

Fordefi Signer

FordefiSigner is a signer implementation which extends SmartAccountAuthenticator to leverage the Fordefi Web3 Provider. It supports features such as authentication, message and typed data signing, and authentication details retrieval.

FordefiSigner provides implementations for all methods on SmartAccountAuthenticator:

  1. authenticate -- supports user authentication.
  2. getAddress -- gets the address of the smart contract account's connected EOA signer account.
  3. signMessage -- supports message signatures.
  4. signTypedData -- supports typed data signatures.
  5. getAuthDetails -- verifies that this signer is authenticated, it does not return any details.

Install Dependencies

FordefiSigner requires installation of the @fordefi/web3-provider SDK. aa-signers lists it as an optional dependency.

bash
npm i -s @fordefi/web3-provider
bash
yarn add @fordefi/web3-provider

Usage

ts
import { createFordefiSigner } from "./fordefi";

const fordefiSigner = await createFordefiSigner();

const address = await fordefiSigner.getAddress();

const details = await fordefiSigner.getAuthDetails();

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

const typedData = {
  types: {
    Request: [{ name: "hello", type: "string" }],
  },
  primaryType: "Request",
  message: {
    hello: "world",
  },
};
const signTypedData = await fordefiSigner.signTypedData(typedData);
ts
import { FordefiSigner } from "@alchemy/aa-signers/fordefi";
import { FordefiWeb3Provider } from "@fordefi/web3-provider";

const fordefi = new FordefiWeb3Provider({
  address: "0x1234567890123456789012345678901234567890",
  chainId: 11155111,
  apiUserToken: process.env.FORDEFI_API_USER_TOKEN!,
  apiPayloadSignKey: process.env.FORDEFI_API_PAYLOAD_SIGNING_KEY!,
});

export const createFordefiSigner = async () => {
  const fordefiSigner = new FordefiSigner(fordefi);

  await fordefiSigner.authenticate();

  return fordefiSigner;
};