Skip to content

Portal Signer

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

PassportSigner 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

PassportSigner requires installation of the package requires installation of the @0xpass/passport and @0xpass/webauthn-signer.

bash
npm i @0xpass/passport
npm i @0xpass/webauthn-signer
bash
yarn add @0xpass/passport
yarn add @0xpass/webauthn-signer

Usage

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

const passportSigner = await createPassportSigner();

const address = await passportSigner.getAddress();

const details = await passportSigner.getAuthDetails();

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

const typedData = {
  types: {
    Request: [{ name: "hello", type: "string" }],
  },
  primaryType: "Request",
  message: {
    hello: "world",
  },
};
const signTypedData = await passportSigner.signTypedData(typedData);
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;
};