Skip to content

Commit 20d27b5

Browse files
committed
chore: tsdoc - signTypedData
1 parent b78b12c commit 20d27b5

File tree

3 files changed

+41
-85
lines changed

3 files changed

+41
-85
lines changed

src/sdk/clients/decorators/smartAccount/signTypedData.ts

+41-85
Original file line numberDiff line numberDiff line change
@@ -15,102 +15,58 @@ import { parseAccount } from "viem/utils"
1515
import { AccountNotFoundError } from "../../../account/utils/AccountNotFound"
1616

1717
/**
18-
* Signs typed data and calculates an Ethereum-specific signature in [https://eips.ethereum.org/EIPS/eip-712](https://eips.ethereum.org/EIPS/eip-712): `sign(keccak256("\x19\x01" ‖ domainSeparator ‖ hashStruct(message)))`
18+
* Signs typed data using the smart account.
1919
*
20-
* - Docs: https://viem.sh/docs/actions/wallet/signTypedData.html
21-
* - JSON-RPC Methods:
22-
* - JSON-RPC Accounts: [`eth_signTypedData_v4`](https://docs.metamask.io/guide/signing-data.html#signtypeddata-v4)
23-
* - Local Accounts: Signs locally. No JSON-RPC request.
20+
* This function calculates an Ethereum-specific signature in [EIP-712 format](https://eips.ethereum.org/EIPS/eip-712):
21+
* `sign(keccak256("\x19\x01" ‖ domainSeparator ‖ hashStruct(message)))`
2422
*
25-
* @param client - Client to use
26-
* @param parameters - {@link SignTypedDataParameters}
27-
* @returns The signed data. {@link SignTypedDataReturnType}
23+
* @param client - The client instance.
24+
* @param parameters - Parameters for signing the typed data.
25+
* @returns The signature as a hexadecimal string.
26+
* @throws {AccountNotFoundError} If the account is not found.
2827
*
2928
* @example
30-
* import { createWalletClient, custom } from 'viem'
31-
* import { mainnet } from 'viem/chains'
32-
* import { signTypedData } from 'viem/wallet'
29+
* import { signTypedData } from '@biconomy/sdk'
30+
* import { keccak256, encodeAbiParameters, parseAbiParameters } from 'viem'
3331
*
34-
* const client = createWalletClient({
35-
* chain: mainnet,
36-
* transport: custom(window.ethereum),
37-
* })
38-
* const signature = await signTypedData(client, {
39-
* account: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
40-
* domain: {
41-
* name: 'Ether Mail',
42-
* version: '1',
43-
* chainId: 1,
44-
* verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
45-
* },
46-
* types: {
47-
* Person: [
48-
* { name: 'name', type: 'string' },
49-
* { name: 'wallet', type: 'address' },
50-
* ],
51-
* Mail: [
52-
* { name: 'from', type: 'Person' },
53-
* { name: 'to', type: 'Person' },
54-
* { name: 'contents', type: 'string' },
55-
* ],
56-
* },
57-
* primaryType: 'Mail',
58-
* message: {
59-
* from: {
60-
* name: 'Cow',
61-
* wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
62-
* },
63-
* to: {
64-
* name: 'Bob',
65-
* wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
66-
* },
67-
* contents: 'Hello, Bob!',
68-
* },
69-
* })
32+
* const domain = {
33+
* name: 'Ether Mail',
34+
* version: '1',
35+
* chainId: 1,
36+
* verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC'
37+
* }
7038
*
71-
* @example
72-
* // Account Hoisting
73-
* import { createWalletClient, http } from 'viem'
74-
* import { privateKeyToAccount } from 'viem/accounts'
75-
* import { mainnet } from 'viem/chains'
76-
* import { signTypedData } from 'viem/wallet'
39+
* const types = {
40+
* Person: [
41+
* { name: 'name', type: 'string' },
42+
* { name: 'wallet', type: 'address' }
43+
* ],
44+
* Mail: [
45+
* { name: 'from', type: 'Person' },
46+
* { name: 'to', type: 'Person' },
47+
* { name: 'contents', type: 'string' }
48+
* ]
49+
* }
7750
*
78-
* const client = createWalletClient({
79-
* account: privateKeyToAccount('0x…'),
80-
* chain: mainnet,
81-
* transport: http(),
82-
* })
83-
* const signature = await signTypedData(client, {
84-
* domain: {
85-
* name: 'Ether Mail',
86-
* version: '1',
87-
* chainId: 1,
88-
* verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
51+
* const message = {
52+
* from: {
53+
* name: 'Cow',
54+
* wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826'
8955
* },
90-
* types: {
91-
* Person: [
92-
* { name: 'name', type: 'string' },
93-
* { name: 'wallet', type: 'address' },
94-
* ],
95-
* Mail: [
96-
* { name: 'from', type: 'Person' },
97-
* { name: 'to', type: 'Person' },
98-
* { name: 'contents', type: 'string' },
99-
* ],
56+
* to: {
57+
* name: 'Bob',
58+
* wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB'
10059
* },
60+
* contents: 'Hello, Bob!'
61+
* }
62+
*
63+
* const signature = await signTypedData(nexusClient, {
64+
* domain,
65+
* types,
10166
* primaryType: 'Mail',
102-
* message: {
103-
* from: {
104-
* name: 'Cow',
105-
* wallet: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826',
106-
* },
107-
* to: {
108-
* name: 'Bob',
109-
* wallet: '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB',
110-
* },
111-
* contents: 'Hello, Bob!',
112-
* },
67+
* message
11368
* })
69+
* console.log(signature) // '0x...'
11470
*/
11571
export async function signTypedData<
11672
const TTypedData extends TypedData | { [key: string]: unknown },

0 commit comments

Comments
 (0)