viem 0.0.0-main.20240526T170333 → 0.0.0-main.20240527T071914

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/_cjs/accounts/privateKeyToAccount.js +0 -4
  2. package/_cjs/accounts/privateKeyToAccount.js.map +1 -1
  3. package/_cjs/accounts/toAccount.js +0 -1
  4. package/_cjs/accounts/toAccount.js.map +1 -1
  5. package/_cjs/errors/version.js +1 -1
  6. package/_cjs/experimental/index.js +1 -15
  7. package/_cjs/experimental/index.js.map +1 -1
  8. package/_esm/accounts/privateKeyToAccount.js +0 -4
  9. package/_esm/accounts/privateKeyToAccount.js.map +1 -1
  10. package/_esm/accounts/toAccount.js +0 -1
  11. package/_esm/accounts/toAccount.js.map +1 -1
  12. package/_esm/errors/version.js +1 -1
  13. package/_esm/experimental/index.js +0 -7
  14. package/_esm/experimental/index.js.map +1 -1
  15. package/_types/accounts/privateKeyToAccount.d.ts.map +1 -1
  16. package/_types/accounts/toAccount.d.ts.map +1 -1
  17. package/_types/accounts/types.d.ts +2 -4
  18. package/_types/accounts/types.d.ts.map +1 -1
  19. package/_types/celo/chainConfig.d.ts +76 -76
  20. package/_types/celo/formatters.d.ts +38 -38
  21. package/_types/chains/definitions/ancient8.d.ts +30 -30
  22. package/_types/chains/definitions/ancient8Sepolia.d.ts +30 -30
  23. package/_types/chains/definitions/base.d.ts +30 -30
  24. package/_types/chains/definitions/baseGoerli.d.ts +30 -30
  25. package/_types/chains/definitions/baseSepolia.d.ts +30 -30
  26. package/_types/chains/definitions/celo.d.ts +76 -76
  27. package/_types/chains/definitions/celoAlfajores.d.ts +76 -76
  28. package/_types/chains/definitions/fraxtal.d.ts +30 -30
  29. package/_types/chains/definitions/fraxtalTestnet.d.ts +30 -30
  30. package/_types/chains/definitions/funkiSepolia.d.ts +30 -30
  31. package/_types/chains/definitions/liskSepolia.d.ts +30 -30
  32. package/_types/chains/definitions/metalL2.d.ts +30 -30
  33. package/_types/chains/definitions/optimism.d.ts +30 -30
  34. package/_types/chains/definitions/optimismGoerli.d.ts +30 -30
  35. package/_types/chains/definitions/optimismSepolia.d.ts +30 -30
  36. package/_types/chains/definitions/pgn.d.ts +30 -30
  37. package/_types/chains/definitions/pgnTestnet.d.ts +30 -30
  38. package/_types/chains/definitions/rss3.d.ts +30 -30
  39. package/_types/chains/definitions/rss3Sepolia.d.ts +30 -30
  40. package/_types/chains/definitions/zora.d.ts +30 -30
  41. package/_types/chains/definitions/zoraSepolia.d.ts +30 -30
  42. package/_types/chains/definitions/zoraTestnet.d.ts +30 -30
  43. package/_types/errors/version.d.ts +1 -1
  44. package/_types/experimental/index.d.ts +0 -7
  45. package/_types/experimental/index.d.ts.map +1 -1
  46. package/_types/op-stack/chainConfig.d.ts +30 -30
  47. package/_types/op-stack/formatters.d.ts +30 -30
  48. package/_types/utils/formatters/transaction.d.ts +1 -1
  49. package/accounts/privateKeyToAccount.ts +0 -4
  50. package/accounts/toAccount.ts +0 -1
  51. package/accounts/types.ts +2 -9
  52. package/errors/version.ts +1 -1
  53. package/experimental/index.ts +0 -44
  54. package/package.json +1 -1
  55. package/_cjs/experimental/eip3074/actions/signAuthMessage.js +0 -29
  56. package/_cjs/experimental/eip3074/actions/signAuthMessage.js.map +0 -1
  57. package/_cjs/experimental/eip3074/constants/abis.js +0 -123
  58. package/_cjs/experimental/eip3074/constants/abis.js.map +0 -1
  59. package/_cjs/experimental/eip3074/decorators/eip3074.js +0 -13
  60. package/_cjs/experimental/eip3074/decorators/eip3074.js.map +0 -1
  61. package/_cjs/experimental/eip3074/invokers/coders/batchInvokerCoder.js +0 -26
  62. package/_cjs/experimental/eip3074/invokers/coders/batchInvokerCoder.js.map +0 -1
  63. package/_cjs/experimental/eip3074/invokers/coders/defineInvokerCoder.js +0 -8
  64. package/_cjs/experimental/eip3074/invokers/coders/defineInvokerCoder.js.map +0 -1
  65. package/_cjs/experimental/eip3074/invokers/getInvoker.js +0 -64
  66. package/_cjs/experimental/eip3074/invokers/getInvoker.js.map +0 -1
  67. package/_cjs/experimental/eip3074/utils/recoverAuthMessageAddress.js +0 -12
  68. package/_cjs/experimental/eip3074/utils/recoverAuthMessageAddress.js.map +0 -1
  69. package/_cjs/experimental/eip3074/utils/signAuthMessage.js +0 -17
  70. package/_cjs/experimental/eip3074/utils/signAuthMessage.js.map +0 -1
  71. package/_cjs/experimental/eip3074/utils/toAuthMessage.js +0 -17
  72. package/_cjs/experimental/eip3074/utils/toAuthMessage.js.map +0 -1
  73. package/_cjs/experimental/eip3074/utils/verifyAuthMessage.js +0 -11
  74. package/_cjs/experimental/eip3074/utils/verifyAuthMessage.js.map +0 -1
  75. package/_esm/experimental/eip3074/actions/signAuthMessage.js +0 -78
  76. package/_esm/experimental/eip3074/actions/signAuthMessage.js.map +0 -1
  77. package/_esm/experimental/eip3074/constants/abis.js +0 -120
  78. package/_esm/experimental/eip3074/constants/abis.js.map +0 -1
  79. package/_esm/experimental/eip3074/decorators/eip3074.js +0 -26
  80. package/_esm/experimental/eip3074/decorators/eip3074.js.map +0 -1
  81. package/_esm/experimental/eip3074/invokers/coders/batchInvokerCoder.js +0 -22
  82. package/_esm/experimental/eip3074/invokers/coders/batchInvokerCoder.js.map +0 -1
  83. package/_esm/experimental/eip3074/invokers/coders/defineInvokerCoder.js +0 -4
  84. package/_esm/experimental/eip3074/invokers/coders/defineInvokerCoder.js.map +0 -1
  85. package/_esm/experimental/eip3074/invokers/getInvoker.js +0 -60
  86. package/_esm/experimental/eip3074/invokers/getInvoker.js.map +0 -1
  87. package/_esm/experimental/eip3074/utils/recoverAuthMessageAddress.js +0 -8
  88. package/_esm/experimental/eip3074/utils/recoverAuthMessageAddress.js.map +0 -1
  89. package/_esm/experimental/eip3074/utils/signAuthMessage.js +0 -16
  90. package/_esm/experimental/eip3074/utils/signAuthMessage.js.map +0 -1
  91. package/_esm/experimental/eip3074/utils/toAuthMessage.js +0 -16
  92. package/_esm/experimental/eip3074/utils/toAuthMessage.js.map +0 -1
  93. package/_esm/experimental/eip3074/utils/verifyAuthMessage.js +0 -13
  94. package/_esm/experimental/eip3074/utils/verifyAuthMessage.js.map +0 -1
  95. package/_types/experimental/eip3074/actions/signAuthMessage.d.ts +0 -82
  96. package/_types/experimental/eip3074/actions/signAuthMessage.d.ts.map +0 -1
  97. package/_types/experimental/eip3074/constants/abis.d.ts +0 -91
  98. package/_types/experimental/eip3074/constants/abis.d.ts.map +0 -1
  99. package/_types/experimental/eip3074/decorators/eip3074.d.ts +0 -27
  100. package/_types/experimental/eip3074/decorators/eip3074.d.ts.map +0 -1
  101. package/_types/experimental/eip3074/invokers/coders/batchInvokerCoder.d.ts +0 -11
  102. package/_types/experimental/eip3074/invokers/coders/batchInvokerCoder.d.ts.map +0 -1
  103. package/_types/experimental/eip3074/invokers/coders/defineInvokerCoder.d.ts +0 -14
  104. package/_types/experimental/eip3074/invokers/coders/defineInvokerCoder.d.ts.map +0 -1
  105. package/_types/experimental/eip3074/invokers/getInvoker.d.ts +0 -48
  106. package/_types/experimental/eip3074/invokers/getInvoker.d.ts.map +0 -1
  107. package/_types/experimental/eip3074/utils/recoverAuthMessageAddress.d.ts +0 -12
  108. package/_types/experimental/eip3074/utils/recoverAuthMessageAddress.d.ts.map +0 -1
  109. package/_types/experimental/eip3074/utils/signAuthMessage.d.ts +0 -16
  110. package/_types/experimental/eip3074/utils/signAuthMessage.d.ts.map +0 -1
  111. package/_types/experimental/eip3074/utils/toAuthMessage.d.ts +0 -20
  112. package/_types/experimental/eip3074/utils/toAuthMessage.d.ts.map +0 -1
  113. package/_types/experimental/eip3074/utils/verifyAuthMessage.d.ts +0 -19
  114. package/_types/experimental/eip3074/utils/verifyAuthMessage.d.ts.map +0 -1
  115. package/experimental/eip3074/actions/signAuthMessage.ts +0 -151
  116. package/experimental/eip3074/constants/abis.ts +0 -119
  117. package/experimental/eip3074/decorators/eip3074.ts +0 -58
  118. package/experimental/eip3074/invokers/coders/batchInvokerCoder.ts +0 -46
  119. package/experimental/eip3074/invokers/coders/defineInvokerCoder.ts +0 -20
  120. package/experimental/eip3074/invokers/getInvoker.ts +0 -192
  121. package/experimental/eip3074/utils/recoverAuthMessageAddress.ts +0 -29
  122. package/experimental/eip3074/utils/signAuthMessage.ts +0 -40
  123. package/experimental/eip3074/utils/toAuthMessage.ts +0 -50
  124. package/experimental/eip3074/utils/verifyAuthMessage.ts +0 -46
@@ -1,119 +0,0 @@
1
- export const invokerAbi = [
2
- {
3
- type: 'function',
4
- name: 'execute',
5
- inputs: [
6
- {
7
- name: 'execData',
8
- type: 'bytes',
9
- internalType: 'bytes',
10
- },
11
- {
12
- name: 'signature',
13
- type: 'tuple',
14
- internalType: 'struct Auth.Signature',
15
- components: [
16
- {
17
- name: 'signer',
18
- type: 'address',
19
- internalType: 'address',
20
- },
21
- {
22
- name: 'yParity',
23
- type: 'uint8',
24
- internalType: 'uint8',
25
- },
26
- {
27
- name: 'r',
28
- type: 'bytes32',
29
- internalType: 'bytes32',
30
- },
31
- {
32
- name: 's',
33
- type: 'bytes32',
34
- internalType: 'bytes32',
35
- },
36
- ],
37
- },
38
- ],
39
- outputs: [],
40
- stateMutability: 'nonpayable',
41
- },
42
- {
43
- type: 'function',
44
- name: 'getDigest',
45
- inputs: [
46
- {
47
- name: 'execData',
48
- type: 'bytes',
49
- internalType: 'bytes',
50
- },
51
- {
52
- name: 'nonce',
53
- type: 'uint256',
54
- internalType: 'uint256',
55
- },
56
- ],
57
- outputs: [
58
- {
59
- name: 'digest',
60
- type: 'bytes32',
61
- internalType: 'bytes32',
62
- },
63
- ],
64
- stateMutability: 'view',
65
- },
66
- {
67
- type: 'function',
68
- name: 'multiSend',
69
- inputs: [
70
- {
71
- name: 'transactions',
72
- type: 'bytes',
73
- internalType: 'bytes',
74
- },
75
- ],
76
- outputs: [],
77
- stateMutability: 'payable',
78
- },
79
- {
80
- type: 'function',
81
- name: 'nextNonce',
82
- inputs: [
83
- {
84
- name: '',
85
- type: 'address',
86
- internalType: 'address',
87
- },
88
- ],
89
- outputs: [
90
- {
91
- name: '',
92
- type: 'uint256',
93
- internalType: 'uint256',
94
- },
95
- ],
96
- stateMutability: 'view',
97
- },
98
- {
99
- type: 'error',
100
- name: 'BadAuth',
101
- inputs: [],
102
- },
103
- {
104
- type: 'error',
105
- name: 'InvalidNonce',
106
- inputs: [
107
- {
108
- name: 'authority',
109
- type: 'address',
110
- internalType: 'address',
111
- },
112
- {
113
- name: 'attempted',
114
- type: 'uint256',
115
- internalType: 'uint256',
116
- },
117
- ],
118
- },
119
- ] as const
@@ -1,58 +0,0 @@
1
- import type { Client } from '../../../clients/createClient.js'
2
- import type { Transport } from '../../../clients/transports/createTransport.js'
3
- import type { Account } from '../../../types/account.js'
4
- import type { Chain } from '../../../types/chain.js'
5
- import {
6
- type SignAuthMessageParameters,
7
- type SignAuthMessageReturnType,
8
- signAuthMessage,
9
- } from '../actions/signAuthMessage.js'
10
-
11
- export type WalletActionsEip3074<
12
- chain extends Chain | undefined = Chain | undefined,
13
- account extends Account | undefined = Account | undefined,
14
- > = {
15
- signAuthMessage: <
16
- chainOverride extends Chain | undefined = undefined,
17
- accountOverride extends Account | undefined = undefined,
18
- >(
19
- parameters: SignAuthMessageParameters<
20
- chain,
21
- account,
22
- chainOverride,
23
- accountOverride
24
- >,
25
- ) => Promise<SignAuthMessageReturnType>
26
- }
27
-
28
- /**
29
- * A suite of EIP-3074 Wallet Actions.
30
- *
31
- * - Docs: https://viem.sh/experimental
32
- *
33
- * @example
34
- * import { createPublicClient, createWalletClient, http } from 'viem'
35
- * import { mainnet } from 'viem/chains'
36
- * import { walletActionsEip3074 } from 'viem/experimental'
37
- *
38
- * const walletClient = createWalletClient({
39
- * chain: mainnet,
40
- * transport: http(),
41
- * }).extend(walletActionsEip3074())
42
- *
43
- * const signature = await walletClient.signAuthMessage({...})
44
- */
45
- export function walletActionsEip3074() {
46
- return <
47
- transport extends Transport,
48
- chain extends Chain | undefined = Chain | undefined,
49
- account extends Account | undefined = Account | undefined,
50
- >(
51
- client: Client<transport, chain, account>,
52
- ): WalletActionsEip3074<chain, account> => {
53
- return {
54
- signAuthMessage: (parameters) =>
55
- signAuthMessage(client as any, parameters),
56
- }
57
- }
58
- }
@@ -1,46 +0,0 @@
1
- import type { Address } from 'abitype'
2
- import { readContract } from '../../../../actions/public/readContract.js'
3
- import type { Hex } from '../../../../types/misc.js'
4
- import { encodeAbiParameters } from '../../../../utils/abi/encodeAbiParameters.js'
5
- import { encodePacked } from '../../../../utils/abi/encodePacked.js'
6
- import { concat } from '../../../../utils/data/concat.js'
7
- import { size } from '../../../../utils/data/size.js'
8
- import { invokerAbi } from '../../constants/abis.js'
9
- import { defineInvokerCoder } from './defineInvokerCoder.js'
10
-
11
- type Calls = readonly {
12
- to: Address
13
- data?: Hex | undefined
14
- value?: bigint | undefined
15
- }[]
16
-
17
- export type BatchInvokerArgs = Calls
18
-
19
- export function batchInvokerCoder() {
20
- return defineInvokerCoder({
21
- async toExecData(
22
- args: BatchInvokerArgs,
23
- { authority, client, invokerAddress },
24
- ) {
25
- const nonce = await readContract(client, {
26
- abi: invokerAbi,
27
- address: invokerAddress,
28
- functionName: 'nextNonce',
29
- args: [authority],
30
- })
31
-
32
- const calls = concat(
33
- args.map(({ data = '0x', to, value = 0n }) =>
34
- encodePacked(
35
- ['uint8', 'address', 'uint256', 'uint256', 'bytes'],
36
- [2, to, value, BigInt(size(data)), data],
37
- ),
38
- ),
39
- )
40
- return encodeAbiParameters(
41
- [{ type: 'uint256' }, { type: 'bytes' }],
42
- [nonce, calls],
43
- )
44
- },
45
- })
46
- }
@@ -1,20 +0,0 @@
1
- import type { Address } from 'abitype'
2
- import type { Client } from '../../../../clients/createClient.js'
3
- import type { Hex } from '../../../../types/misc.js'
4
-
5
- export type InvokerCoder<args = unknown> = {
6
- toExecData: (
7
- args: args,
8
- options: { authority: Address; client: Client; invokerAddress: Hex },
9
- ) => Promise<Hex>
10
- }
11
-
12
- export type DefineInvokerCoderParameters<args = unknown> = InvokerCoder<args>
13
-
14
- export type DefineInvokerCoderReturnType<args = unknown> = InvokerCoder<args>
15
-
16
- export function defineInvokerCoder<args>(
17
- parameters: DefineInvokerCoderParameters<args>,
18
- ): DefineInvokerCoderReturnType<args> {
19
- return parameters
20
- }
@@ -1,192 +0,0 @@
1
- import type { Address } from 'abitype'
2
- import {
3
- type GetTransactionCountErrorType,
4
- getTransactionCount,
5
- } from '../../../actions/public/getTransactionCount.js'
6
- import {
7
- type WriteContractErrorType,
8
- writeContract,
9
- } from '../../../actions/wallet/writeContract.js'
10
- import type { Client } from '../../../clients/createClient.js'
11
- import type { Transport } from '../../../clients/transports/createTransport.js'
12
- import type { ErrorType } from '../../../errors/utils.js'
13
- import type { Account, LocalAccount } from '../../../types/account.js'
14
- import type { Chain, GetChainParameter } from '../../../types/chain.js'
15
- import type { Hex } from '../../../types/misc.js'
16
- import type { IsUndefined } from '../../../types/utils.js'
17
- import { parseAccount } from '../../../utils/accounts.js'
18
- import {
19
- type IsAddressEqualErrorType,
20
- isAddressEqual,
21
- } from '../../../utils/address/isAddressEqual.js'
22
- import { getAction } from '../../../utils/getAction.js'
23
- import {
24
- type Keccak256ErrorType,
25
- keccak256,
26
- } from '../../../utils/hash/keccak256.js'
27
- import {
28
- type ParseSignatureErrorType,
29
- parseSignature,
30
- } from '../../../utils/signature/parseSignature.js'
31
- import {
32
- type SignAuthMessageErrorType,
33
- signAuthMessage,
34
- } from '../actions/signAuthMessage.js'
35
- import { invokerAbi } from '../constants/abis.js'
36
- import type { InvokerCoder } from './coders/defineInvokerCoder.js'
37
-
38
- type GetExecutorParameter<
39
- TAccount extends Account | undefined = Account | undefined,
40
- TAccountOverride extends Account | Address | undefined = Account | Address,
41
- TRequired extends boolean = true,
42
- > = IsUndefined<TAccount> extends true
43
- ? TRequired extends true
44
- ? { executor: TAccountOverride | Account | Address }
45
- : { executor?: TAccountOverride | Account | Address | undefined }
46
- : { executor?: TAccountOverride | Account | Address | undefined }
47
-
48
- export type InvokerExecuteParameters<
49
- account extends Account | undefined = Account | undefined,
50
- chain extends Chain | undefined = Chain | undefined,
51
- chainOverride extends Chain | undefined = Chain | undefined,
52
- args = unknown,
53
- > = {
54
- args: args
55
- authority: Account | Address
56
- signature: Hex
57
- } & GetExecutorParameter<account> &
58
- GetChainParameter<chain, chainOverride>
59
-
60
- export type InvokerExecuteErrorType =
61
- | WriteContractErrorType
62
- | ParseSignatureErrorType
63
- | ErrorType
64
-
65
- export type InvokerSignParameters<
66
- account extends Account | undefined = Account | undefined,
67
- chain extends Chain | undefined = Chain | undefined,
68
- chainOverride extends Chain | undefined = Chain | undefined,
69
- args = unknown,
70
- > = {
71
- args: args
72
- authority: LocalAccount
73
- } & GetExecutorParameter<account, Account | Address, false> &
74
- GetChainParameter<chain, chainOverride>
75
-
76
- export type InvokerSignErrorType =
77
- | GetTransactionCountErrorType
78
- | SignAuthMessageErrorType
79
- | Keccak256ErrorType
80
- | IsAddressEqualErrorType
81
- | ErrorType
82
-
83
- export type Invoker<
84
- account extends Account | undefined = Account | undefined,
85
- chain extends Chain | undefined = Chain | undefined,
86
- args = unknown,
87
- > = {
88
- address: Address
89
- execute<chainOverride extends Chain | undefined = undefined>(
90
- parameters: InvokerExecuteParameters<account, chain, chainOverride, args>,
91
- ): Promise<Hex>
92
- sign<chainOverride extends Chain | undefined = undefined>(
93
- parameters: InvokerSignParameters<account, chain, chainOverride, args>,
94
- ): Promise<Hex>
95
- }
96
-
97
- export type GetInvokerParameters<
98
- account extends Account | undefined = Account | undefined,
99
- chain extends Chain | undefined = Chain | undefined,
100
- args = unknown,
101
- > = {
102
- address: Address
103
- client: Client<Transport, chain, account>
104
- coder: InvokerCoder<args>
105
- }
106
-
107
- export type GetInvokerErrorType = ErrorType
108
-
109
- export type InvokerArgs<invoker extends Invoker<any, any, any> = Invoker> =
110
- invoker extends Invoker<any, any, infer args> ? args : unknown
111
-
112
- export function getInvoker<
113
- account extends Account | undefined,
114
- chain extends Chain | undefined,
115
- args,
116
- >(
117
- parameters: GetInvokerParameters<account, chain, args>,
118
- ): Invoker<account, chain, args> {
119
- const { address, client, coder } = parameters
120
- return {
121
- address,
122
- async execute(parameters) {
123
- const {
124
- executor: executor_ = client.account,
125
- authority: authority_,
126
- args,
127
- chain = client.chain,
128
- signature,
129
- } = parameters
130
- const authority = parseAccount(authority_!)
131
- const executor = parseAccount(executor_!)
132
-
133
- const execData = await coder.toExecData(args, {
134
- authority: authority.address,
135
- client,
136
- invokerAddress: address,
137
- })
138
-
139
- const { r, s, yParity } = parseSignature(signature)
140
- return getAction(
141
- client,
142
- writeContract,
143
- 'writeContract',
144
- )({
145
- abi: invokerAbi,
146
- address,
147
- account: executor,
148
- chain,
149
- functionName: 'execute',
150
- args: [execData, { signer: authority.address, r, s, yParity }],
151
- })
152
- },
153
- async sign(parameters) {
154
- const {
155
- args,
156
- authority,
157
- executor: executor_ = client.account,
158
- chain = client.chain,
159
- } = parameters
160
- const executor = parseAccount(executor_!)
161
- const [execData, nonce] = await Promise.all([
162
- await coder.toExecData(args, {
163
- authority: authority.address,
164
- client,
165
- invokerAddress: address,
166
- }),
167
- getAction(
168
- client,
169
- getTransactionCount,
170
- 'getTransactionCount',
171
- )({
172
- address: authority.address,
173
- blockTag: 'pending',
174
- }),
175
- ])
176
- const signature = await getAction(
177
- client,
178
- signAuthMessage,
179
- 'signAuthMessage',
180
- )({
181
- account: authority,
182
- chain,
183
- commit: keccak256(execData),
184
- invokerAddress: address,
185
- nonce: isAddressEqual(authority.address, executor.address)
186
- ? nonce + 1
187
- : nonce,
188
- })
189
- return signature
190
- },
191
- }
192
- }
@@ -1,29 +0,0 @@
1
- import type { Address } from 'abitype'
2
-
3
- import type { ByteArray, Hex, Signature } from '../../../types/misc.js'
4
-
5
- import type { ErrorType } from '../../../errors/utils.js'
6
- import { keccak256 } from '../../../utils/hash/keccak256.js'
7
- import {
8
- type RecoverAddressErrorType,
9
- recoverAddress,
10
- } from '../../../utils/signature/recoverAddress.js'
11
- import { type ToAuthMessageParameters, toAuthMessage } from './toAuthMessage.js'
12
-
13
- export type RecoverAuthMessageAddressParameters = ToAuthMessageParameters & {
14
- signature: Hex | ByteArray | Signature
15
- }
16
-
17
- export type RecoverAuthMessageAddressReturnType = Address
18
-
19
- export type RecoverAuthMessageAddressErrorType =
20
- | RecoverAddressErrorType
21
- | ErrorType
22
-
23
- export async function recoverAuthMessageAddress({
24
- signature,
25
- ...parameters
26
- }: RecoverAuthMessageAddressParameters): Promise<RecoverAuthMessageAddressReturnType> {
27
- const hash = keccak256(toAuthMessage(parameters))
28
- return recoverAddress({ hash, signature })
29
- }
@@ -1,40 +0,0 @@
1
- import { type SignErrorType, sign } from '../../../accounts/utils/sign.js'
2
- import type { ErrorType } from '../../../errors/utils.js'
3
- import type { Hex } from '../../../types/misc.js'
4
- import { keccak256 } from '../../../utils/hash/keccak256.js'
5
- import {
6
- type SerializeSignatureErrorType,
7
- serializeSignature,
8
- } from '../../../utils/signature/serializeSignature.js'
9
- import {
10
- type ToAuthMessageErrorType,
11
- type ToAuthMessageParameters,
12
- toAuthMessage,
13
- } from './toAuthMessage.js'
14
-
15
- export type SignAuthMessageParameters = ToAuthMessageParameters & {
16
- /** The private key to sign with. */
17
- privateKey: Hex
18
- }
19
-
20
- export type SignAuthMessageReturnType = Hex
21
-
22
- export type SignAuthMessageErrorType =
23
- | SignErrorType
24
- | ToAuthMessageErrorType
25
- | SerializeSignatureErrorType
26
- | ErrorType
27
-
28
- /**
29
- * Computes a EIP-3074 authorization signature in format: `keccak256(MAGIC || chainId || nonce || invokerAddress || commit))`.
30
- */
31
- export async function signAuthMessage(
32
- parameters: SignAuthMessageParameters,
33
- ): Promise<SignAuthMessageReturnType> {
34
- const { privateKey } = parameters
35
- const signature = await sign({
36
- hash: keccak256(toAuthMessage(parameters)),
37
- privateKey,
38
- })
39
- return serializeSignature(signature)
40
- }
@@ -1,50 +0,0 @@
1
- import type { Address } from 'abitype'
2
- import type { ErrorType } from '../../../errors/utils.js'
3
- import type { Hash } from '../../../types/misc.js'
4
- import {
5
- type EncodePackedErrorType,
6
- encodePacked,
7
- } from '../../../utils/abi/encodePacked.js'
8
- import { type PadHexErrorType, padHex } from '../../../utils/data/pad.js'
9
- import {
10
- type NumberToHexErrorType,
11
- numberToHex,
12
- } from '../../../utils/encoding/toHex.js'
13
- import type { Keccak256ErrorType } from '../../../utils/hash/keccak256.js'
14
-
15
- export type ToAuthMessageParameters = {
16
- chainId: number
17
- commit: Hash
18
- invokerAddress: Address
19
- nonce: number
20
- }
21
-
22
- export type ToAuthMessageReturnType = Hash
23
-
24
- export type ToAuthMessageErrorType =
25
- | Keccak256ErrorType
26
- | EncodePackedErrorType
27
- | NumberToHexErrorType
28
- | PadHexErrorType
29
- | ErrorType
30
-
31
- /**
32
- * Returns the message to be signed for EIP-3074 authorization.
33
- */
34
- export function toAuthMessage({
35
- chainId,
36
- commit,
37
- invokerAddress,
38
- nonce,
39
- }: ToAuthMessageParameters): ToAuthMessageReturnType {
40
- return encodePacked(
41
- ['uint8', 'bytes32', 'uint256', 'bytes32', 'bytes32'],
42
- [
43
- 0x04, // MAGIC
44
- numberToHex(chainId, { size: 32 }),
45
- BigInt(nonce),
46
- padHex(invokerAddress, { size: 32 }),
47
- commit,
48
- ],
49
- )
50
- }
@@ -1,46 +0,0 @@
1
- import type { Address } from 'abitype'
2
-
3
- import type { ErrorType } from '../../../errors/utils.js'
4
- import {
5
- type GetAddressErrorType,
6
- getAddress,
7
- } from '../../../utils/address/getAddress.js'
8
- import {
9
- type IsAddressEqualErrorType,
10
- isAddressEqual,
11
- } from '../../../utils/address/isAddressEqual.js'
12
- import {
13
- type RecoverAuthMessageAddressErrorType,
14
- type RecoverAuthMessageAddressParameters,
15
- recoverAuthMessageAddress,
16
- } from './recoverAuthMessageAddress.js'
17
-
18
- export type VerifyAuthMessageParameters =
19
- RecoverAuthMessageAddressParameters & {
20
- /** The address that signed the original auth message. */
21
- address: Address
22
- }
23
-
24
- export type VerifyAuthMessageReturnType = boolean
25
-
26
- export type VerifyAuthMessageErrorType =
27
- | IsAddressEqualErrorType
28
- | GetAddressErrorType
29
- | RecoverAuthMessageAddressErrorType
30
- | ErrorType
31
-
32
- /**
33
- * Verify that a auth message was signed by the provided address.
34
- *
35
- * @param parameters - {@link VerifyAuthMessageParameters}
36
- * @returns Whether or not the signature is valid. {@link VerifyAuthMessageReturnType}
37
- */
38
- export async function verifyAuthMessage({
39
- address,
40
- ...parameters
41
- }: VerifyAuthMessageParameters): Promise<VerifyAuthMessageReturnType> {
42
- return isAddressEqual(
43
- getAddress(address),
44
- await recoverAuthMessageAddress(parameters),
45
- )
46
- }