UNPKG

@cometh/connect-sdk-4337

Version:
1,181 lines (1,146 loc) 79.3 kB
export { erc7579Actions } from 'permissionless/actions/erc7579'; import * as viem from 'viem'; import { Address, Hex, PrivateKeyAccount, Chain, PublicClient, LocalAccount, UnionPartialBy, Transport, Client, Prettify as Prettify$1, Hash, SendTransactionParameters, Abi, ContractFunctionName, ContractFunctionArgs, WriteContractParameters, TypedData, RpcSchema, BundlerRpcSchema, PublicClientConfig, Account, OneOf, AbiFunction, ByteArray, WalletClient, SignableMessage, TypedDataDefinition, EIP1193Provider as EIP1193Provider$1, BaseError, EIP1193Parameters, EIP1193RequestFn } from 'viem'; import { Prettify } from 'viem/types/utils'; import { ToSafeSmartAccountReturnType } from 'permissionless/accounts'; import { UserOperation, SmartAccount, SendUserOperationParameters, BundlerActions, PaymasterActions } from 'viem/account-abstraction'; import { SmartAccountClientConfig } from 'permissionless'; import { Prettify as Prettify$2 } from 'viem/chains'; import { signMessage, signTypedData } from 'permissionless/actions/smartAccount'; import { Session, SmartSessionMode, EnableSessionData } from '@rhinestone/module-sdk'; export { SmartSessionMode } from '@rhinestone/module-sdk'; import { Handler } from 'mitt'; declare const ENTRYPOINT_ADDRESS_V07 = "0x0000000071727De22E5E9d8BAf0edAc6f37da032"; declare const customChains: ({ blockExplorers?: { [key: string]: { name: string; url: string; apiUrl?: string | undefined; }; default: { name: string; url: string; apiUrl?: string | undefined; }; } | undefined | undefined; blockTime?: number | undefined | undefined; contracts: { readonly multicall3: { readonly address: "0xcA11bde05977b3631167028862bE2a173976CA11"; }; }; ensTlds?: readonly string[] | undefined; id: 4078; name: "Muster"; nativeCurrency: { readonly decimals: 18; readonly name: "Ether"; readonly symbol: "ETH"; }; experimental_preconfirmationTime?: number | undefined | undefined; rpcUrls: { readonly default: { readonly http: readonly ["https://muster.alt.technology/"]; }; readonly public: { readonly http: readonly ["https://muster.alt.technology/"]; }; }; sourceId?: number | undefined | undefined; testnet?: boolean | undefined | undefined; custom?: Record<string, unknown> | undefined; fees?: viem.ChainFees<undefined> | undefined; formatters?: undefined; serializers?: viem.ChainSerializers<undefined, viem.TransactionSerializable> | undefined; readonly network: "muster"; } | { blockExplorers?: { [key: string]: { name: string; url: string; apiUrl?: string | undefined; }; default: { name: string; url: string; apiUrl?: string | undefined; }; } | undefined | undefined; blockTime?: number | undefined | undefined; contracts: { readonly multicall3: { readonly address: "0xcA11bde05977b3631167028862bE2a173976CA11"; }; }; ensTlds?: readonly string[] | undefined; id: 1291; name: "Swisstronik testnet"; nativeCurrency: { readonly decimals: 18; readonly name: "Ether"; readonly symbol: "ETH"; }; experimental_preconfirmationTime?: number | undefined | undefined; rpcUrls: { readonly default: { readonly http: readonly ["https://json-rpc.testnet.swisstronik.com/unencrypted/"]; }; readonly public: { readonly http: readonly ["https://json-rpc.testnet.swisstronik.com/unencrypted/"]; }; }; sourceId?: number | undefined | undefined; testnet?: boolean | undefined | undefined; custom?: Record<string, unknown> | undefined; fees?: viem.ChainFees<undefined> | undefined; formatters?: undefined; serializers?: viem.ChainSerializers<undefined, viem.TransactionSerializable> | undefined; readonly network: "swisstronik testnet"; })[]; declare enum WalletVersion { V1 = "v1.0" } type SafeContractParams = { safeProxyFactoryAddress: Address; safeSingletonAddress: Address; multisendAddress: Address; fallbackHandler: Address; setUpContractAddress: Address; safeWebAuthnSharedSignerContractAddress: Address; p256Verifier: Address; safeWebAuthnSignerFactory: Address; safe4337ModuleAddress?: Address; safe4337SessionKeysModule?: Address; migrationContractAddress?: Address; }; type RecoveryParams = { socialRecoveryModuleAddress: Address; moduleFactoryAddress: Address; delayModuleAddress: Address; recoveryCooldown: number; recoveryExpiration: number; guardianAddress: Address; }; type DeploymentParams = { version: WalletVersion; safeContractParams: SafeContractParams; recoveryParams: RecoveryParams; }; type ProjectParams = { chainId: string; safeContractParams: SafeContractParams; recoveryParams: RecoveryParams; }; type Wallet = { projectId: string; chainId: string; address: string; creationDate: Date; connectionDate: Date; initiatorAddress: string; deploymentParams: DeploymentParams; }; type DeviceData = { browser: string; os: string; platform: string; }; type WebAuthnSigner = { projectId: string; userId: string; chainId: string; smartAccountAddress: string; publicKeyId: string; publicKeyX: string; publicKeyY: string; signerAddress: string; deviceData: DeviceData; creationDate?: Date; }; type Signer$1 = { signerAddress: Address; deviceData: DeviceData; publicKeyId?: Hex; publicKeyX?: Hex; publicKeyY?: Hex; }; type RelayedTransactionStatus = { received: { date: Date; }; attributed?: { date: Date; relayerAddress: string; }; sent?: { date: Date; hash: string; gasLimit: string; maxPriorityFeePerGas: string; maxFeePerGas: string; nonce: number; }; rebroadcasted?: { date: Date; hash: string; gasLimit: string; maxPriorityFeePerGas: string; maxFeePerGas: string; nonce: number; }[]; confirmed?: { date: Date; hash: string; gasUsed: string; effectiveGasPrice: string; status: number; }; }; type RelayedTransactionDetails = { id: string; to: string; data: string; projectId?: string; isSponsored?: boolean; status: RelayedTransactionStatus; }; declare enum OperationType { Call = 0, DelegateCall = 1 } interface MetaTransactionData { readonly to: string; readonly value: string; readonly data: string; readonly operation?: OperationType | string; } interface SafeTransactionDataPartial extends MetaTransactionData { readonly operation?: OperationType | string; readonly safeTxGas?: number | string; readonly baseGas?: number | string; readonly gasPrice?: number | string; readonly gasToken?: number | string; readonly refundReceiver?: string; readonly nonce?: number | string; } declare class API { private readonly api; private readonly _apiKey; constructor(apiKey: string, baseUrl?: string); get apiUrl(): string; get apiKey(): string; getProjectParams(chainId: number): Promise<ProjectParams>; getWalletByNetworks(walletAddress: Address): Promise<Wallet[]>; createWallet({ chainId, smartAccountAddress, initiatorAddress, }: { chainId: number; smartAccountAddress: Address; initiatorAddress: Address; }): Promise<void>; initWallet({ chainId, smartAccountAddress, initiatorAddress, publicKeyId, publicKeyX, publicKeyY, deviceData, }: { chainId: number; smartAccountAddress: Address; initiatorAddress: Address; publicKeyId?: Hex; publicKeyX?: Hex; publicKeyY?: Hex; deviceData?: DeviceData; }): Promise<boolean>; importExternalSafe({ smartAccountAddress, publicKeyId, publicKeyX, publicKeyY, deviceData, signerAddress, chainId, transactionCalldata, }: { smartAccountAddress: Address; publicKeyId?: Hex; publicKeyX?: Hex; publicKeyY?: Hex; deviceData?: DeviceData; signerAddress: Address; chainId: string; transactionCalldata: Hex; }): Promise<any>; /** * WebAuthn Section */ createWebAuthnSigner({ chainId, walletAddress, publicKeyId, publicKeyX, publicKeyY, deviceData, signerAddress, isSharedWebAuthnSigner, }: { chainId: number; walletAddress: Hex; publicKeyId: Hex; publicKeyX: Hex; publicKeyY: Hex; deviceData: DeviceData; signerAddress: Address; isSharedWebAuthnSigner: boolean; }): Promise<void>; getPasskeySignerByPublicKeyId(publicKeyId: Hex): Promise<WebAuthnSigner[]>; getPasskeySignersByWalletAddress(walletAddress: Address): Promise<WebAuthnSigner[]>; predictWebAuthnSignerAddress({ publicKeyX, publicKeyY, }: { publicKeyX: Hex; publicKeyY: Hex; }): Promise<Hex>; getWebAuthnSignersByWalletAddressAndChain(walletAddress: Address, chainId: number): Promise<WebAuthnSigner[]>; isValidSignature(walletAddress: Address, message: string, signature: Hex, chainId: number): Promise<boolean>; getRelayedTransaction(relayId: string, chainId: number): Promise<RelayedTransactionDetails>; } type eoaFallback = { signer: PrivateKeyAccount; privateKey: Hex; encryptionSalt?: string; }; interface webAuthnOptions { authenticatorSelection?: { authenticatorAttachment?: AuthenticatorAttachment; userVerification?: UserVerificationRequirement; requireResidentKey?: boolean; residentKey?: ResidentKeyRequirement; }; extensions?: any; } type PasskeyLocalStorageFormat = { id: Hex; pubkeyCoordinates: { x: Hex; y: Hex; }; signerAddress: Address; publicKeyAlgorithm?: number; }; interface ComethSignerTypes { type: "localWallet" | "passkey"; } interface FallbackEoaSigner extends ComethSignerTypes { type: "localWallet"; eoaFallback: eoaFallback; } interface PasskeySigner extends ComethSignerTypes { type: "passkey"; passkey: PasskeyLocalStorageFormat; } type ComethSigner = FallbackEoaSigner | PasskeySigner; type ComethSignerConfig = { disableEoaFallback?: boolean; encryptionSalt?: string; webAuthnOptions?: webAuthnOptions; rpId?: string; passKeyName?: string; fullDomainSelected?: boolean; }; type CreateSignerParams = { apiKey: string; chain: Chain; smartAccountAddress?: Address; safeContractParams: SafeContractParams; baseUrl?: string; publicClient?: PublicClient; } & ComethSignerConfig; type Signer = ComethSigner | PrivateKeyAccount; type SafeSigner<Name extends string = string> = LocalAccount<Name> & { getStubSignature(): Promise<Hex>; signUserOperation: (parameters: UnionPartialBy<UserOperation, "sender"> & { chainId?: number | undefined; }) => Promise<Hex>; }; type ComethSafeSmartAccount = ToSafeSmartAccountReturnType<"0.7"> & { connectApiInstance: API; signerAddress: Address; safeContractParams: SafeContractParams; comethSignerConfig?: ComethSignerConfig; publicClient?: PublicClient; }; type createSafeSmartAccountParameters$1 = Prettify<{ apiKey: string; chain: Chain; publicClient?: PublicClient; baseUrl?: string; smartAccountAddress?: Address; comethSignerConfig?: ComethSignerConfig; safeContractConfig?: SafeContractParams; signer?: Signer; smartSessionSigner?: SafeSigner; }>; /** * Create a Safe smart account */ declare function createSafeSmartAccount<TTransport extends Transport = Transport, TChain extends Chain = Chain>({ apiKey, chain, publicClient, baseUrl, smartAccountAddress, comethSignerConfig, safeContractConfig, signer, smartSessionSigner, }: createSafeSmartAccountParameters$1): Promise<ComethSafeSmartAccount>; interface QRCodeOptions { width?: number; margin?: number; color?: { dark?: string; light?: string; }; } type CreateNewSignerParams = { webAuthnOptions?: webAuthnOptions; passKeyName?: string; fullDomainSelected?: boolean; encryptionSalt?: string; }; /** * Creates a new passkey signer for a smart account * @param apiKey - The API key for authentication * @param baseUrl - Optional base URL for the API * @param smartAccountAddress - The address of the smart account * @param passKeyName - Optional name for the passkey * @param encryptionSalt - Optional encryption salt * @param fullDomainSelected - Optional selected the full domain for the passkey */ declare const createNewSignerWithAccountAddress: ({ apiKey, baseUrl, smartAccountAddress, params, }: { apiKey: string; smartAccountAddress: Address; baseUrl?: string; params?: CreateNewSignerParams; }) => Promise<Signer$1>; /** * Creates a new passkey signer * @param apiKey - The API key for authentication * @param baseUrl - Optional base URL for the API * @param passKeyName - Optional name for the passkey * @param encryptionSalt - Optional encryption salt * @param fullDomainSelected - Optional selected the full domain for the passkey */ declare const createNewSigner: ({ apiKey, baseUrl, params, }: { apiKey: string; baseUrl?: string; params?: CreateNewSignerParams; }) => Promise<Signer$1>; declare const serializeUrlWithSignerPayload: (validationPageUrl: string, signerPayload: Signer$1) => Promise<URL>; declare const generateQRCodeUrl: (validationPageUrl: string, signerPayload: Signer$1, options?: QRCodeOptions) => Promise<string>; /** * Function used to retrieve an account address from passkeys * @param apiKey * @param chain * @param fullDomainSelected * @param rpId */ declare const retrieveAccountAddressFromPasskeys: ({ apiKey, chain, fullDomainSelected, rpId, baseUrl, publicClient, checkLegacy, legacyBaseUrl, }: { apiKey: string; chain: Chain; fullDomainSelected?: boolean; rpId?: string; baseUrl?: string; publicClient?: PublicClient; checkLegacy?: boolean; legacyBaseUrl?: string; }) => Promise<Address>; /** * Function used to retrieve an account address from a passkey id * @param apiKey * @param id * @param chain * @param fullDomainSelected * @param rpId */ declare const retrieveAccountAddressFromPasskeyId: ({ apiKey, id, chain, fullDomainSelected, rpId, baseUrl, publicClient, }: { apiKey: string; id: string; chain: Chain; fullDomainSelected?: boolean; rpId?: string; baseUrl?: string; publicClient?: PublicClient; }) => Promise<Address>; type SafeImportActions = { prepareImportSafe1_1Tx: () => Promise<{ tx: SafeTransactionDataPartial; passkey?: PasskeyLocalStorageFormat; eoaSigner?: PrivateKeyAccount; }>; prepareImportSafe1_3Tx: () => Promise<{ tx: SafeTransactionDataPartial; passkey?: PasskeyLocalStorageFormat; eoaSigner?: PrivateKeyAccount; }>; prepareImportSafe1_4Tx: () => Promise<{ tx: SafeTransactionDataPartial; passkey?: PasskeyLocalStorageFormat; eoaSigner?: PrivateKeyAccount; }>; importSafe: ({ tx, signature, passkey, eoaSigner, }: { tx: SafeTransactionDataPartial; signature: Hex; passkey?: PasskeyLocalStorageFormat; eoaSigner?: PrivateKeyAccount; }) => Promise<Hex | undefined>; signTransactionByExternalOwner: ({ signer, tx, }: { signer: PrivateKeyAccount; tx: SafeTransactionDataPartial; }) => Promise<Hex | undefined>; signTransactionByExternalOwnerFor1_1: ({ signer, tx, }: { signer: PrivateKeyAccount; tx: SafeTransactionDataPartial; }) => Promise<Hex | undefined>; }; declare function importSafeActions(): <TAccount extends ComethSafeSmartAccount | undefined = ComethSafeSmartAccount | undefined>(client: Client<Transport, Chain | undefined, TAccount>) => SafeImportActions; type ValidateAddDevice = { signer: Signer$1; }; declare function validateAddDevice<TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, TAccount extends ComethSafeSmartAccount | undefined = ComethSafeSmartAccount | undefined>(client: Client<TTransport, TChain, TAccount>, args: Prettify$1<ValidateAddDevice>): Promise<Hash>; type CancelRecoveryRequestParams = { effectiveDelayAddress?: Address; }; declare function cancelRecoveryRequest<TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, TAccount extends ComethSafeSmartAccount | undefined = ComethSafeSmartAccount | undefined>(client: Client<TTransport, TChain, TAccount>, args: Prettify$1<CancelRecoveryRequestParams>): Promise<Hex>; type GetDelayModuleAddressParams = { expiration: number; cooldown: number; }; declare function getDelayModuleAddress<TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, TAccount extends ComethSafeSmartAccount | undefined = ComethSafeSmartAccount | undefined>(client: Client<TTransport, TChain, TAccount>, args: Prettify$1<GetDelayModuleAddressParams>): Promise<Address>; type GetGuardianAddressParams = { delayModuleAddress: Address; }; declare function getGuardianAddress<TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, TAccount extends ComethSafeSmartAccount | undefined = ComethSafeSmartAccount | undefined>(client: Client<TTransport, TChain, TAccount>, args: Prettify$1<GetGuardianAddressParams>): Promise<Address>; type AddGuardianParams = { delayModuleAddress: Address; guardianAddress: Address; }; declare function addGuardian<TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, TAccount extends ComethSafeSmartAccount | undefined = ComethSafeSmartAccount | undefined>(client: Client<TTransport, TChain, TAccount>, args: Prettify$1<AddGuardianParams>): Promise<Hex>; type DisableGuardianParams = { guardianAddress: Address; expiration?: number; cooldown?: number; }; declare function disableGuardian<TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, TAccount extends ComethSafeSmartAccount | undefined = ComethSafeSmartAccount | undefined>(client: Client<TTransport, TChain, TAccount>, args: Prettify$1<DisableGuardianParams>): Promise<Hex>; type SetupCustomDelayModuleParams = { guardianAddress: Address; expiration?: number; cooldown?: number; }; declare function setupCustomDelayModule<TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, TAccount extends ComethSafeSmartAccount | undefined = ComethSafeSmartAccount | undefined>(client: Client<TTransport, TChain, TAccount>, args: Prettify$1<SetupCustomDelayModuleParams>): Promise<Hex>; type RecoveryParamsResponse = { txCreatedAt: bigint; txHash: string; }; type GetRecoveryRequestParams = { effectiveDelayAddress?: Address; }; declare function getRecoveryRequest<TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, TAccount extends ComethSafeSmartAccount | undefined = ComethSafeSmartAccount | undefined>(client: Client<TTransport, TChain, TAccount>, args?: Prettify$1<GetRecoveryRequestParams>): Promise<RecoveryParamsResponse | undefined>; type IsRecoveryActiveParams = { effectiveDelayAddress?: Address; }; type IsRecoveryActiveReturnType = { isDelayModuleDeployed: boolean; guardianAddress: Address | null; }; declare function isRecoveryActive<TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, TAccount extends ComethSafeSmartAccount | undefined = ComethSafeSmartAccount | undefined>(client: Client<TTransport, TChain, TAccount>, args?: Prettify$1<IsRecoveryActiveParams>): Promise<IsRecoveryActiveReturnType>; /** * Creates, signs, and sends a new transaction to the network. * This function also allows you to sponsor this transaction if sender is a smartAccount * * - Docs: https://viem.sh/docs/actions/wallet/sendTransaction.html * - Examples: https://stackblitz.com/github/wagmi-dev/viem/tree/main/examples/transactions/sending-transactions * - JSON-RPC Methods: * - JSON-RPC Accounts: [`eth_sendTransaction`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sendtransaction) * - Local Accounts: [`eth_sendRawTransaction`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sendrawtransaction) * * @param client - Client to use * @param parameters - {@link SendTransactionParameters} * @returns The [Transaction](https://viem.sh/docs/glossary/terms.html#transaction) hash. * * @example * import { createWalletClient, custom } from 'viem' * import { mainnet } from 'viem/chains' * import { sendTransaction } from 'viem/wallet' * * const client = createWalletClient({ * chain: mainnet, * transport: custom(window.ethereum), * }) * const hash = await sendTransaction(client, { * account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', * value: 1000000000000000000n, * }) * * @example * // Account Hoisting * import { createWalletClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { mainnet } from 'viem/chains' * import { sendTransaction } from 'viem/wallet' * * const client = createWalletClient({ * account: privateKeyToAccount('0x…'), * chain: mainnet, * transport: http(), * }) * const hash = await sendTransaction(client, { * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', * value: 1000000000000000000n, * }) */ declare function sendTransaction<account extends SmartAccount | undefined, chain extends Chain | undefined, accountOverride extends SmartAccount | undefined = undefined, chainOverride extends Chain | undefined = Chain | undefined, calls extends readonly unknown[] = readonly unknown[]>(client: Client<Transport, chain, account>, args: SendTransactionParameters<chain, account, chainOverride> | SendUserOperationParameters<account, accountOverride, calls>): Promise<Hash>; declare function writeContract<TChain extends Chain | undefined, TAccount extends SmartAccount | undefined, const TAbi extends Abi | readonly unknown[], TFunctionName extends ContractFunctionName<TAbi, "nonpayable" | "payable"> = ContractFunctionName<TAbi, "nonpayable" | "payable">, TArgs extends ContractFunctionArgs<TAbi, "nonpayable" | "payable", TFunctionName> = ContractFunctionArgs<TAbi, "nonpayable" | "payable", TFunctionName>, TChainOverride extends Chain | undefined = undefined>(client: Client<Transport, TChain, TAccount>, { abi, address, args, dataSuffix, functionName, ...request }: WriteContractParameters<TAbi, TFunctionName, TArgs, TChain, TAccount, TChainOverride>): Promise<Hash>; type SmartAccountActions<TChain extends Chain | undefined = Chain | undefined, TSmartAccount extends SmartAccount | undefined = SmartAccount | undefined> = { /** * Creates, signs, and sends a new transaction to the network. * This function also allows you to sponsor this transaction if sender is a smartAccount * * - Docs: https://viem.sh/docs/actions/wallet/sendTransaction.html * - Examples: https://stackblitz.com/github/wagmi-dev/viem/tree/main/examples/transactions/sending-transactions * - JSON-RPC Methods: * - JSON-RPC Accounts: [`eth_sendTransaction`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sendtransaction) * - Local Accounts: [`eth_sendRawTransaction`](https://ethereum.org/en/developers/docs/apis/json-rpc/#eth_sendrawtransaction) * * @param args - {@link SendTransactionParameters} * @returns The [Transaction](https://viem.sh/docs/glossary/terms.html#transaction) hash. {@link SendTransactionReturnType} * * @example * import { createWalletClient, custom } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createWalletClient({ * chain: mainnet, * transport: custom(window.ethereum), * }) * const hash = await client.sendTransaction({ * account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', * value: 1000000000000000000n, * }) * * @example * // Account Hoisting * import { createWalletClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { mainnet } from 'viem/chains' * * const client = createWalletClient({ * account: privateKeyToAccount('0x…'), * chain: mainnet, * transport: http(), * }) * const hash = await client.sendTransaction({ * to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8', * value: 1000000000000000000n, * }) */ sendTransaction: <TChainOverride extends Chain | undefined = undefined, accountOverride extends SmartAccount | undefined = undefined, calls extends readonly unknown[] = readonly unknown[]>(args: Parameters<typeof sendTransaction<TSmartAccount, TChain, accountOverride, TChainOverride, calls>>[1]) => Promise<Hash>; /** * Calculates an Ethereum-specific signature in [EIP-191 format](https://eips.ethereum.org/EIPS/eip-191): `keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))`. * * - Docs: https://viem.sh/docs/actions/wallet/signMessage.html * - JSON-RPC Methods: * - JSON-RPC Accounts: [`personal_sign`](https://docs.metamask.io/guide/signing-data.html#personal-sign) * - Local Accounts: Signs locally. No JSON-RPC request. * * With the calculated signature, you can: * - use [`verifyMessage`](https://viem.sh/docs/utilities/verifyMessage.html) to verify the signature, * - use [`recoverMessageAddress`](https://viem.sh/docs/utilities/recoverMessageAddress.html) to recover the signing address from a signature. * * @param args - {@link SignMessageParameters} * @returns The signed message. {@link SignMessageReturnType} * * @example * import { createWalletClient, custom } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createWalletClient({ * chain: mainnet, * transport: custom(window.ethereum), * }) * const signature = await client.signMessage({ * account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', * message: 'hello world', * }) * * @example * // Account Hoisting * import { createWalletClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { mainnet } from 'viem/chains' * * const client = createWalletClient({ * account: privateKeyToAccount('0x…'), * chain: mainnet, * transport: http(), * }) * const signature = await client.signMessage({ * message: 'hello world', * }) */ signMessage: (args: Parameters<typeof signMessage<TSmartAccount>>[1]) => ReturnType<typeof signMessage<TSmartAccount>>; /** * Signs typed data and calculates an Ethereum-specific signature in [EIP-191 format](https://eips.ethereum.org/EIPS/eip-191): `keccak256("\x19Ethereum Signed Message:\n" + len(message) + message))`. * * - Docs: https://viem.sh/docs/actions/wallet/signTypedData.html * - JSON-RPC Methods: * - JSON-RPC Accounts: [`eth_signTypedData_v4`](https://docs.metamask.io/guide/signing-data.html#signtypeddata-v4) * - Local Accounts: Signs locally. No JSON-RPC request. * * @param client - Client to use * @param args - {@link SignTypedDataParameters} * @returns The signed data. {@link SignTypedDataReturnType} * * @example * import { createWalletClient, custom } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createWalletClient({ * chain: mainnet, * transport: custom(window.ethereum), * }) * const signature = await client.signTypedData({ * account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', * 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!', * }, * }) * * @example * // Account Hoisting * import { createWalletClient, http } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { mainnet } from 'viem/chains' * * const client = createWalletClient({ * account: privateKeyToAccount('0x…'), * chain: mainnet, * transport: http(), * }) * const signature = await client.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!', * }, * }) */ signTypedData: <const TTypedData extends TypedData | { [key: string]: unknown; }, TPrimaryType extends string>(args: Parameters<typeof signTypedData<TTypedData, TPrimaryType, TSmartAccount>>[1]) => ReturnType<typeof signTypedData<TTypedData, TPrimaryType, TSmartAccount>>; /** * Executes a write function on a contract. * This function also allows you to sponsor this transaction if sender is a smartAccount * * - Docs: https://viem.sh/docs/contract/writeContract.html * - Examples: https://stackblitz.com/github/wagmi-dev/viem/tree/main/examples/contracts/writing-to-contracts * * A "write" function on a Solidity contract modifies the state of the blockchain. These types of functions require gas to be executed, and hence a [Transaction](https://viem.sh/docs/glossary/terms.html) is needed to be broadcast in order to change the state. * * Internally, uses a [Wallet Client](https://viem.sh/docs/clients/wallet.html) to call the [`sendTransaction` action](https://viem.sh/docs/actions/wallet/sendTransaction.html) with [ABI-encoded `data`](https://viem.sh/docs/contract/encodeFunctionData.html). * * __Warning: The `write` internally sends a transaction – it does not validate if the contract write will succeed (the contract may throw an error). It is highly recommended to [simulate the contract write with `contract.simulate`](https://viem.sh/docs/contract/writeContract.html#usage) before you execute it.__ * * @param args - {@link WriteContractParameters} * @returns A [Transaction Hash](https://viem.sh/docs/glossary/terms.html#hash). {@link WriteContractReturnType} * * @example * import { createWalletClient, custom, parseAbi } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createWalletClient({ * chain: mainnet, * transport: custom(window.ethereum), * }) * const hash = await client.writeContract({ * address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', * abi: parseAbi(['function mint(uint32 tokenId) nonpayable']), * functionName: 'mint', * args: [69420], * }) * * @example * // With Validation * import { createWalletClient, custom, parseAbi } from 'viem' * import { mainnet } from 'viem/chains' * * const client = createWalletClient({ * chain: mainnet, * transport: custom(window.ethereum), * }) * const { request } = await client.simulateContract({ * address: '0xFBA3912Ca04dd458c843e2EE08967fC04f3579c2', * abi: parseAbi(['function mint(uint32 tokenId) nonpayable']), * functionName: 'mint', * args: [69420], * } * const hash = await client.writeContract(request) */ writeContract: <const TAbi extends Abi | readonly unknown[], TFunctionName extends ContractFunctionName<TAbi, "nonpayable" | "payable"> = ContractFunctionName<TAbi, "nonpayable" | "payable">, TArgs extends ContractFunctionArgs<TAbi, "nonpayable" | "payable", TFunctionName> = ContractFunctionArgs<TAbi, "nonpayable" | "payable", TFunctionName>, TChainOverride extends Chain | undefined = undefined>(args: WriteContractParameters<TAbi, TFunctionName, TArgs, TChain, TSmartAccount, TChainOverride>) => ReturnType<typeof writeContract<TChain, TSmartAccount, TAbi, TFunctionName, TArgs, TChainOverride>>; }; type VerifySignatureParams = { message: string; signature: Hex; }; declare function verifySignature<TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, TSmartAccount extends ComethSafeSmartAccount | undefined = ComethSafeSmartAccount | undefined>(client: Client<TTransport, TChain, TSmartAccount>, args: Prettify$1<VerifySignatureParams>): Promise<boolean>; type ComethClientActions<TChain extends Chain | undefined = Chain | undefined, TSmartAccount extends ComethSafeSmartAccount | undefined = ComethSafeSmartAccount | undefined> = SmartAccountActions<TChain, TSmartAccount> & { validateAddDevice: <TTransport extends Transport>(args: Parameters<typeof validateAddDevice<TTransport, TChain, TSmartAccount>>[1]) => Promise<Hash>; setUpRecoveryModule: () => Promise<Hash>; cancelRecoveryRequest: <TTransport extends Transport>(args: Parameters<typeof cancelRecoveryRequest<TTransport, TChain, TSmartAccount>>[1]) => Promise<Hash>; isRecoveryActive: <TTransport extends Transport>(args: Parameters<typeof isRecoveryActive<TTransport, TChain, TSmartAccount>>[1]) => Promise<IsRecoveryActiveReturnType>; getRecoveryRequest: <TTransport extends Transport>(args: Parameters<typeof getRecoveryRequest<TTransport, TChain, TSmartAccount>>[1]) => Promise<RecoveryParamsResponse | undefined>; verifySignature: <TTransport extends Transport>(args: Parameters<typeof verifySignature<TTransport, TChain, TSmartAccount>>[1]) => Promise<boolean>; getDelayModuleAddress: <TTransport extends Transport>(args: Parameters<typeof getDelayModuleAddress<TTransport, TChain, TSmartAccount>>[1]) => Promise<Address>; getGuardianAddress: <TTransport extends Transport>(args: Parameters<typeof getGuardianAddress<TTransport, TChain, TSmartAccount>>[1]) => Promise<Address>; addGuardian: <TTransport extends Transport>(args: Parameters<typeof addGuardian<TTransport, TChain, TSmartAccount>>[1]) => Promise<Hex>; disableGuardian: <TTransport extends Transport>(args: Parameters<typeof disableGuardian<TTransport, TChain, TSmartAccount>>[1]) => Promise<Hex>; setupCustomDelayModule: <TTransport extends Transport>(args: Parameters<typeof setupCustomDelayModule<TTransport, TChain, TSmartAccount>>[1]) => Promise<Hex>; setFallbackTo7579: () => Promise<Hex>; is7579Installed: () => Promise<boolean>; }; type ComethAccountClientActions<chain extends Chain | undefined = Chain | undefined, account extends ComethSafeSmartAccount | undefined = ComethSafeSmartAccount | undefined> = ComethClientActions<chain, account> & SafeOwnerPluginActions; type ComethSmartAccountClient<transport extends Transport = Transport, chain extends Chain | undefined = Chain | undefined, account extends ComethSafeSmartAccount | undefined = ComethSafeSmartAccount | undefined, client extends Client | undefined = Client | undefined, rpcSchema extends RpcSchema | undefined = undefined> = Prettify$2<Client<transport, chain extends Chain ? chain : client extends Client<any, infer chain> ? chain : undefined, account, rpcSchema extends RpcSchema ? [...BundlerRpcSchema, ...rpcSchema] : BundlerRpcSchema, BundlerActions<account> & ComethAccountClientActions<chain, account>>>; declare function createSmartAccountClient<transport extends Transport, chain extends Chain | undefined = undefined, account extends ComethSafeSmartAccount | undefined = ComethSafeSmartAccount | undefined, client extends Client | undefined = undefined, rpcSchema extends RpcSchema | undefined = undefined>(parameters: SmartAccountClientConfig<transport, chain, account, client, rpcSchema>): ComethSmartAccountClient<transport, chain, account, client>; type EnrichedOwner = { address: Address; deviceData?: DeviceData; creationDate?: Date; isSmartContract?: boolean; }; type SafeOwnerPluginActions = { addOwner: (args: { ownerToAdd: Address; }) => Promise<Hash>; removeOwner: (args: { ownerToRemove: Address; }) => Promise<Hash>; getOwners: () => Promise<readonly Address[]>; getEnrichedOwners: () => Promise<EnrichedOwner[]>; }; /** * RPC interface that's used for the cometh paymaster communication */ type ComethPaymasterRpcSchema = [ { Method: "pm_sponsorUserOperation"; Parameters: [userOperation: UserOperation<"0.7">, EntryPoint: Address]; ReturnType: { callGasLimit: Hex; verificationGasLimit: Hex; preVerificationGas: Hex; paymasterPostOpGasLimit: Hex; paymasterVerificationGasLimit: Hex; }; } ]; type ComethPaymasterClient = Client<Transport, Chain | undefined, Account | undefined, ComethPaymasterRpcSchema, ComethPaymasterClientActions & PaymasterActions>; type ComethPaymasterClientActions = { /** * Returns maxFeePerGas & maxPriorityFeePerGas required to sponsor a userOperation. */ getUserOperationGasPrice: () => Promise<{ maxFeePerGas: bigint; maxPriorityFeePerGas: bigint; }>; }; declare const createComethPaymasterClient: <transport extends Transport = Transport, chain extends Chain | undefined = undefined>(parameters: PublicClientConfig<transport, chain> & { publicClient?: PublicClient; }) => ComethPaymasterClient; type Execution = { target: Address; value: bigint; callData: Hex; }; /** * Represents a hardcoded hex value reference. * Used when you want to bypass automatic hex conversion. */ type HardcodedReference = { /** The raw hex value */ raw: Hex; }; /** * Base types that can be converted to hex references. */ type BaseReferenceValue = string | number | bigint | boolean | ByteArray; /** * Union type of all possible reference values that can be converted to hex. * Includes both basic types and hardcoded references. */ type AnyReferenceValue = BaseReferenceValue | HardcodedReference; type PreparePermissionResponse = { /** Array of permission IDs for the created sessions. */ permissionIds: Hex[]; /** The execution object for the action. */ action: Execution; /** The sessions that were created. */ sessions: Session[]; }; /** * Represents the response for creating sessions. */ type GrantPermissionResponse = { /** The hash of the user operation. */ userOpHash: Hex; } & PreparePermissionResponse; type RemovePermissionResponse = { /** The hash of the user operation. */ userOpHash: Hex; /** The permission ID for the removing session. */ permissionId: Hex; /** The execution object for the action. */ action: Execution; }; type Call = { to: Hex; data?: Hex | undefined; value?: bigint | undefined; }; type OptionalSessionKeyData = OneOf<{ /** Public key for the session. Required for K1 algorithm validators. */ sessionPublicKey: Hex; } | { /** Data for the session key. */ sessionKeyData: Hex; }>; /** * Represents a rule for action policies. */ type Rule = { /** The condition to apply to the parameter */ condition: ParamCondition; /** The offset index in the calldata where the value to be checked is located */ offsetIndex: number; /** Indicates if the rule has a usage limit */ isLimited: boolean; /** The reference value to compare against */ ref: AnyReferenceValue; /** The usage object containing limit and used values (required if isLimited is true) */ usage: LimitUsage; }; type ActionPolicyInfo = { /** The address of the contract to be included in the policy */ contractAddress: Hex; /** The timeframe policy can be used to restrict a session to only be able to be used within a certain timeframe */ validUntil?: number; /** Timestamp after which the policy becomes valid */ validAfter?: number; /** The value limit policy can be used to enforce that only a certain amount of native value can be spent. For ERC-20 limits, use the spending limit policy */ valueLimit?: bigint; /** The spending limits policy can be used to ensure that only a certain amount of ERC-20 tokens can be spent. For native value spends, use the value limit policy */ tokenLimits?: SpendingLimitPolicyData[]; /** The value limit policy can be used to enforce that only a certain amount of native value can be spent. For ERC-20 limits, use the spending limit policy. */ usageLimit?: bigint; /** The sudo policy is an action policy that will allow any action for the specified target and selector. */ sudo?: boolean; } & OneOf<{ /** The specific function selector from the contract to be included in the policy */ functionSelector: string | AbiFunction; /** Array of rules for the policy */ rules?: Rule[]; } | { /** The ABI of the contract to be included in the policy */ abi: Abi; }>; /** * Parameters for creating a session. */ type CreateSessionDataParams = OptionalSessionKeyData & { /** Public key for the session. Required for K1 algorithm validators. */ sessionPublicKey?: Hex; /** Address of the session validator. */ sessionValidator?: Address; /** Data for the session validator. */ sessionValidatorInitData?: Hex; /** Optional salt for the session. */ salt?: Hex; /** Timestamp until which the session is valid. */ sessionValidUntil?: number; /** Timestamp after which the session becomes valid. */ sessionValidAfter?: number; /** Chain IDs where the session should be enabled. Useful for enable mode. */ chainIds?: bigint[]; /** Array of action policy data for the session. */ actionPoliciesInfo?: ActionPolicyInfo[]; }; declare enum ParamCondition { EQUAL = 0, GREATER_THAN = 1, LESS_THAN = 2, GREATER_THAN_OR_EQUAL = 3, LESS_THAN_OR_EQUAL = 4, NOT_EQUAL = 5 } type SpendingLimitPolicyData = { /** The address of the token to be included in the policy */ token: Address; /** The limit for the token */ limit: bigint; }; /** * Represents the usage limit for a rule. */ type LimitUsage = { limit: bigint; used: bigint; }; /** * Represents the possible modes for a smart session. */ type SmartSessionModeType = (typeof SmartSessionMode)[keyof typeof SmartSessionMode]; /** * Represents the data structure for using a session module. */ type UsePermissionModuleData = { /** The mode of the smart session. */ mode?: SmartSessionModeType; /** Data for enabling the session. */ enableSessionData?: EnableSessionData; /** The index of the permission ID to use for the session. Defaults to 0. */ permissionIdIndex?: number; } & PreparePermissionResponse; type GrantPermissionParameters<TAccount extends ComethSafeSmartAccount | undefined = ComethSafeSmartAccount | undefined> = { /** Array of session data parameters for creating multiple sessions. */ sessionRequestedInfo: CreateSessionDataParams[]; /** The maximum fee per gas unit the transaction is willing to pay. */ maxFeePerGas?: bigint; /** The maximum priority fee per gas unit the transaction is willing to pay. */ maxPriorityFeePerGas?: bigint; /** The nonce of the transaction. If not provided, it will be determined automatically. */ nonce?: bigint; /** Optional public client for blockchain interactions. */ publicClient?: PublicClient; /** The modular smart account to create sessions for. If not provided, the client's account will be used. */ account?: TAccount; /** Optional attesters to trust. */ attesters?: Hex[]; /** Additional calls to be included in the user operation. */ calls?: Call[]; }; type IsPermissionInstalledParameters = { session: Session; }; type PreparePermissionParameters<TAccount extends ComethSafeSmartAccount | undefined = ComethSafeSmartAccount | undefined> = { /** Array of session data parameters for creating multiple sessions. */ sessionRequestedInfo: CreateSessionDataParams[]; /** The maximum fee per gas unit the transaction is willing to pay. */ maxFeePerGas?: bigint; /** The maximum priority fee per gas unit the transaction is willing to pay. */ maxPriorityFeePerGas?: bigint; /** The nonce of the transaction. If not provided, it will be determined automatically. */ nonce?: bigint; /** Optional public client for blockchain interactions. */ publicClient?: PublicClient; /** The modular smart account to create sessions for. If not provided, the client's account will be used. */ account?: TAccount; }; type RemovePermissionParameters = { /** The permission ID to remove. */ permissionId: Hex; /** Optional public client for blockchain interactions. */ publicClient?: PublicClient; }; type TrustAttestersParameters<TAccount extends ComethSafeSmartAccount | undefined = ComethSafeSmartAccount | undefined> = { /** The addresses of the attesters to be trusted. */ attesters?: Hex[]; /** The address of the registry contract. */ registryAddress?: Hex; /** The maximum fee per gas unit the transaction is willing to pay. */ maxFeePerGas?: bigint; /** The maximum priority fee per gas unit the transaction is willing to pay. */ maxPriorityFeePerGas?: bigint; /** The nonce of the transaction. If not provided, it will be determined automatically. */ nonce?: bigint; /** The smart account to use for trusting attesters. If not provided, the client's account will be used. */ account?: TAccount; /** The threshold of the attesters to be trusted. */ threshold?: number; }; /** * Parameters for using a smart session to execute actions. * */ type UsePermissionParameters$1 = { /** Array of executions to perform in the session. Allows for batch transactions if the session is enabled for multiple actions. */ actions: Execution[]; /** The maximum fee per gas unit the transaction is willing to pay. */ maxFeePerGas?: bigint; /** The maximum priority fee per gas unit the transaction is willing to pay. */ maxPriorityFeePerGas?: bigint; verificationGasLimit?: bigint; }; type SmartSessionCreateActions<TAccount extends ComethSafeSmartAccount | undefined = ComethSafeSmartAccount | undefined> = { /** * Creates multiple sessions for a smart account. * * @param args - Parameters for creating sessions. * @returns A promise that resolves to the creation response. */ grantPermission: (args: GrantPermissionParameters<TAccount>) => Promise<GrantPermissionResponse>; /** * Removes a session for a smart account. * * @param args - Parameters for removing session. * @returns A promise that resolves to the removal response. */ removePermission: (args: RemovePermissionParameters) => Promise<RemovePermissionResponse>; /** * Prepares permission for a smart account. * * @param args - Parameters for preparing permission. * @returns A promise that resolves to the transaction hash. */ preparePermission: (args: PreparePermissionParameters<TAccount>) => Promise<PreparePermissionResponse>; /** * Creates multiple sessions for a smart account. * * @param args - Parameters for creating sessions. * @returns A promise that resolves to the creation response. */ isPermissionInstalled: (args: IsPermissionInstalledParameters) => Promise<boolean>; /** * Trusts attesters for a smart account. * * @param args - Parameters for trusting attesters. * @returns A promise that resolves to the transaction hash. */ trustAttesters: (args?: TrustAttestersParameters<TAccount>) => Promise<Hash>; /** * Uses a session to perform an action. * * @param args - Parameters for using a session. * @returns A promise that resolves to the transaction hash. */ usePermission: (args: UsePermissionParameters$1) => Promise<Hash>; }; /** * Creates actions for managing smart session creation. * * @returns A function that takes a clien