Skip to content

Portal Signer

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

PortalSigner 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 -- supports authentication details retrieval.

Install Dependencies

PortalSigner requires installation of the @portal-hq/web SDK. aa-signers lists it as an optional dependency.

bash
npm i -s @portal-hq/web
bash
yarn add @portal-hq/web

Usage

ts
import { createPortalSigner } from "./portal";

const portalSigner = await createPortalSigner();

const address = await portalSigner.getAddress();

const details = await portalSigner.getAuthDetails();

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

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

export const createPortalSigner = async () => {
  const portalSigner = new PortalSigner({
    autoApprove: true,
    gatewayConfig: `${sepolia.rpcUrls.alchemy.http}/${process.env.ALCHEMY_API_KEY}`,
    chainId: sepolia.id,
  });

  await portalSigner.authenticate();

  return portalSigner;
};