signTypedData
signTypedData
supports signing typed data from the TurnkeySigner
.
This method must be called after authenticate
. Otherwise, this method will throw an error with the message Not Authenticated
.
Usage
ts
import { createTurnkeySigner } from "./turnkey";
const turnkeySigner = await createTurnkeySigner();
const signedTypedData = await turnkeySigner.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 {
TurnkeySigner,
TurnkeySubOrganization,
} from "@alchemy/aa-signers/turnkey";
import { WebauthnStamper } from "@turnkey/webauthn-stamper";
import { http } from "viem";
const TURNKEY_BASE_URL = "https://api.turnkey.com";
export const createTurnkeySigner = async () => {
const turnkeySigner = new TurnkeySigner({
apiUrl: TURNKEY_BASE_URL,
// API Key, WebAuthn, or Email Auth [stampers](https://docs.turnkey.com/category/api-design)
// must sign all requests to Turnkey.
stamper: new WebauthnStamper({
rpId: "your.app.xyz",
}),
});
await turnkeySigner.authenticate({
resolveSubOrganization: async () => {
return new TurnkeySubOrganization({
subOrganizationId: "12345678-1234-1234-1234-123456789abc",
signWith: "0x1234567890123456789012345678901234567890",
});
},
transport: http("https://eth-sepolia.g.alchemy.com/v2/ALCHEMY_API_KEY"),
});
return turnkeySigner;
};
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