signTypedData
signTypedData
supports signing typed data from the CapsuleSigner
.
This method must be called after authenticate
. Otherwise, this method will throw an error with the message Not Authenticated
.
Usage
ts
import { createCapsuleSigner } from "./capsule";
const capsuleSigner = await createCapsuleSigner();
const signedTypedData = await capsuleSigner.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 { 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;
};
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 domaintypes: Object
-- the type definitions for the typed dataprimaryType: inferred String
-- the primary type to extract from types and use in valuemessage: inferred from types & primaryType
-- the message, inferred from