Skip to content

Capsule Signer

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

CapsuleSigner 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

CapsuleSigner requires installation of the @usecapsule/web-sdk SDK. aa-signers lists it as an optional dependency.

bash
npm i -s @usecapsule/web-sdk
bash
yarn add @usecapsule/web-sdk

Usage

ts
import { createCapsuleSigner } from "./capsule";

const capsuleSigner = await createCapsuleSigner();

const address = await capsuleSigner.getAddress();

const details = await capsuleSigner.getAuthDetails();

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

const typedData = {
  types: {
    Request: [{ name: "hello", type: "string" }],
  },
  primaryType: "Request",
  message: {
    hello: "world",
  },
};
const signTypedData = await capsuleSigner.signTypedData(typedData);
ts
import { sepolia } from "@alchemy/aa-core";
import { CapsuleSigner } from "@alchemy/aa-signers/capsule";
import { Environment } from "@usecapsule/web-sdk";
import { http } from "viem";

export const createCapsuleSigner = async () => {
  // get an API Key by filling out this form: https://form.typeform.com/to/hLaJeYJW
  const capsuleSigner = new CapsuleSigner({
    env: Environment.DEVELOPMENT,
    apiKey: "CAPSULE_API_KEY",
    walletConfig: {
      chain: sepolia,
      // get your own Alchemy API key at: https://dashboard.alchemy.com/
      transport: http(`${sepolia.rpcUrls.alchemy.http[0]}/ALCHEMY_API_KEY`),
    },
  });

  await capsuleSigner.authenticate();

  return capsuleSigner;
};