Skip to content

Web3auth Signer

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

Web3AuthSigner 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

Web3AuthSigner requires installation of the @web3auth/modal and @web3auth/base SDKs. aa-signers lists them as optional dependencies.

bash
npm i -s @web3auth/modal
npm i -s @web3auth/base
bash
yarn add @web3auth/modal
yarn add @web3auth/base

Usage

ts
import { createWeb3AuthSigner } from "./web3auth";

const web3AuthSigner = await createWeb3AuthSigner();

const address = await web3AuthSigner.getAddress();

const details = await web3AuthSigner.getAuthDetails();

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

const typedData = {
  types: {
    Request: [{ name: "hello", type: "string" }],
  },
  primaryType: "Request",
  message: {
    hello: "world",
  },
};
const signTypedData = await web3AuthSigner.signTypedData(typedData);
ts
import { Web3AuthSigner } from "@alchemy/aa-signers/web3auth";

export const createWeb3AuthSigner = async () => {
  const web3AuthSigner = new Web3AuthSigner({
    clientId: "test",
    chainConfig: {
      chainNamespace: "eip155",
    },
  });

  await web3AuthSigner.authenticate({
    init: async () => {
      await web3AuthSigner.inner.initModal();
    },
    connect: async () => {
      await web3AuthSigner.inner.connect();
    },
  });

  return web3AuthSigner;
};