UNPKG

@zerodev/sdk

Version:

A utility library for working with ERC-4337

50 lines 2.2 kB
import type { Chain, Client, SignMessageParameters, SignMessageReturnType, Transport } from "viem"; import type { SmartAccount } from "viem/account-abstraction"; /** * 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 client - Client to use * @param parameters - {@link SignMessageParameters} * @returns The signed message. {@link SignMessageReturnType} * * @example * import { createWalletClient, custom } from 'viem' * import { mainnet } from 'viem/chains' * import { signMessage } from 'viem/wallet' * * const client = createWalletClient({ * chain: mainnet, * transport: custom(window.ethereum), * }) * const signature = await signMessage(client, { * account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e', * message: 'hello world', * }) * * @example * // Account Hoisting * import { createWalletClient, custom } from 'viem' * import { privateKeyToAccount } from 'viem/accounts' * import { mainnet } from 'viem/chains' * import { signMessage } from 'viem/wallet' * * const client = createWalletClient({ * account: privateKeyToAccount('0x…'), * chain: mainnet, * transport: custom(window.ethereum), * }) * const signature = await signMessage(client, { * message: 'hello world', * }) */ export declare function signMessage<TAccount extends SmartAccount | undefined>(client: Client<Transport, Chain | undefined, TAccount>, { account: account_, message }: SignMessageParameters<TAccount>): Promise<SignMessageReturnType>; //# sourceMappingURL=signMessage.d.ts.map