Skip to content

signTypedData

signTypedData supports signing typed data from the PassportSigner.

This method must be called after authenticate. Otherwise, this method will throw an error with the message Not Authenticated.

Usage

ts
import { createPassportSigner } from "./passport";

const passportSigner = await createPassportSigner();

const signedTypedData = await passportSigner.signTypedData({
  domain: {
    name: "Ether Mail",
    version: "1",
    chainId: 1,
    verifyingContract: "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC",
  },
  types: {
    Person: [
      { name: "name", type: "string" },
      { name: "wallet", type: "address" },
    ],
    Mail: [
      { name: "from", type: "Person" },
      { name: "to", type: "Person" },
      { name: "contents", type: "string" },
    ],
  },
  primaryType: "Mail",
  message: {
    from: {
      name: "Cow",
      wallet: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826",
    },
    to: {
      name: "Bob",
      wallet: "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB",
    },
    contents: "Hello, Bob!",
  },
});
ts
import { PassportSigner } from "@alchemy/aa-signers/passport";
import { Passport } from "@0xpass/passport";
import { WebauthnSigner } from "@0xpass/webauthn-signer";
import { http } from "viem";
import { sepolia } from "@alchemy/aa-core";

export const passport = new Passport({
  scope_id: "scope_id",
  signer: new WebauthnSigner({
    rpId: "rpId",
    rpName: "rpName",
  }),
});

export const createPassportSigner = async () => {
  const passportSigner = new PassportSigner({ inner: passport });

  await passportSigner.authenticate({
    username: "test",
    userDisplayName: "test",
    chain: sepolia,
    fallbackProvider: http(
      "https://eth-sepolia.g.alchemy.com/v2/ALCHEMY_API_KEY"
    ),
  });

  return passportSigner;
};

Returns

Promise<Hex>

A Promise containing the signature of the typed data.

Parameters

params: SignTypedDataParams -- the typed data to sign

  • domain: TypedDataDomain -- The typed data domain
  • types: Object -- the type definitions for the typed data
  • primaryType: inferred String -- the primary type to extract from types and use in value
  • message: inferred from types & primaryType -- the message, inferred from