Configure accounts and signers
The Delegation Toolkit supports different delegator accounts types, each with its own configuration and support for different signing mechanisms. You can create flexible and secure delegator accounts tailored to your specific needs.
Configure a Hybrid Delegator
The Hybrid Delegator supports both an EOA "owner" and any number of P256 (passkey) signers.
To configure a Hybrid Delegator, provide the following parameters:
owner
: The owner's account address as a hex string. The owner can be the zero address, indicating that there is no owner configured.p256KeyIds
: An array of key identifiers for P256 signers as hex strings.p256XValues
: An array of public key x-values for P256 signers asbigint
s.p256YValues
: An array of public key y-values for P256 signers asbigint
s.signatory
: A signer that will sign on behalf of the delegator account.
You can set all p256
parameters to empty arrays to configure no WebAuthn signer.
However, we recommend configuring at least one signer for account recoverability.
For a Hybrid Delegator, you can configure the following types of signatories:
Configure an account signatory
This example uses Viem's privateKeyToAccount
function to create a signatory from a private key.
- example.ts
- client.ts
- signatory.ts
import { publicClient } from "./client.ts"
import { signatory } from "./signatory.ts";
import {
Implementation,
toMetaMaskSmartAccount,
} from "@metamask-private/delegator-core-viem";
const smartAccount = await toMetaMaskSmartAccount({
client: publicClient,
implementation: Implementation.Hybrid,
deployParams: [owner, p256KeyIds, p256XValues, p256YValues],
deploySalt: "0x",
signatory,
});
import { http, createPublicClient } from "viem";
import { lineaSepolia as chain } from "viem/chains";
const transport = http();
export const publicClient = createPublicClient({
transport,
chain,
});
import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
const privateKey = generatePrivateKey();
const account = privateKeyToAccount(privateKey);
export const signatory = { account };
Configure a Wallet Client signatory
This example uses Viem's createWalletClient
function to create a WalletClient
as the signatory.
- example.ts
- client.ts
- signatory.ts
import { publicClient } from "./client.ts"
import { signatory } from "./signatory.ts";
import {
Implementation,
toMetaMaskSmartAccount,
} from "@metamask-private/delegator-core-viem";
const smartAccount = await toMetaMaskSmartAccount({
client: publicClient,
implementation: Implementation.Hybrid,
deployParams: [owner, p256KeyIds, p256XValues, p256YValues],
deploySalt: "0x",
signatory,
});
import { http, createPublicClient } from "viem";
import { lineaSepolia as chain } from "viem/chains";
const transport = http();
export const publicClient = createPublicClient({
transport,
chain,
});
import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
import { lineaSepolia as chain } from "viem/chains";
import { http, createWalletClient } from "viem";
const privateKey = generatePrivateKey();
const account = privateKeyToAccount(privateKey);
const walletClient = createWalletClient({
account,
chain,
transport: http()
})
export const signatory = { walletClient };
Configure a WebAuthn (passkey) signatory
This example uses Viem's toWebAuthnAccount
function to create a WebAuthnAccount
as the signatory.
- example.ts
- client.ts
- signatory.ts
import { publicClient } from "./client.ts"
import { signatory } from "./signatory.ts";
import {
Implementation,
toMetaMaskSmartAccount,
} from "@metamask-private/delegator-core-viem";
const smartAccount = await toMetaMaskSmartAccount({
client: publicClient,
implementation: Implementation.Hybrid,
deployParams: [owner, p256KeyIds, p256XValues, p256YValues],
deploySalt: "0x",
signatory,
});
import { http, createPublicClient } from "viem";
import { lineaSepolia as chain } from "viem/chains";
const transport = http();
export const publicClient = createPublicClient({
transport,
chain,
});
import { createCredential, parsePublicKey } from "webauthn-p256";
import { toWebAuthnAccount } from "viem/account-abstraction";
import { toHex } from "viem";
const credential = await createCredential({ name: "Your Delegator Passkey" });
const webAuthnAccount = toWebAuthnAccount({ credential });
const keyId = toHex("my-key-id");
const signatory = { webAuthnAccount, keyId };
Configure a Multisig Delegator
The Multisig Delegator supports multiple EOA signers with a configurable threshold for execution.
To configure a Multisig Delegator, provide the following parameters:
signers
: An array of EOA signer addresses as hex strings.threshold
: The number of signers required to execute a transaction, as abigint
.signatory
: An array of signatories that will sign on behalf of the delegator account.
Configure signatories
For a Multisig Delegator, you can use a combination of account signatories and Wallet Client signatories. For example:
- example.ts
- client.ts
- signers.ts
import { publiClient } from "./client.ts";
import { account, walletClient } from "./signers.ts";
import {
Implementation,
toMetaMaskSmartAccount,
} from "@metamask-private/delegator-core-viem";
const signers = [ account.address, walletClient.address ];
const signatory = { account, walletClient };
const threshold = 2n
const smartAccount = await toMetaMaskSmartAccount({
client: publicClient,
implementation: Implementation.MultiSig,
deployParams: [signers, threshold],
deploySalt: "0x",
signatory,
});
import { http, createPublicClient } from "viem";
import { lineaSepolia as chain } from "viem/chains";
const transport = http();
export const publicClient = createPublicClient({
transport,
chain,
});
import { privateKeyToAccount, generatePrivateKey } from "viem/accounts";
import { lineaSepolia as chain } from "viem/chains";
import { http, createWalletClient } from "viem";
// This private key will be used to generate the first signer.
const privateKey = generatePrivateKey();
export const account = privateKeyToAccount(privateKey);
// This private key will be used to generate the second signer.
const walletClientPivatekey = generatePrivateKey();
const walletClientAccount = privateKeyToAccount(walletClientPivatekey);
export const walletClient = createWalletClient({
account: walletClientAccount,
chain,
transport: http()
});
The number of signers in the signatories must be at least equal to the threshold for valid signature generation.