viem 2.57.14 → 2.57.15
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.
- package/CHANGELOG.md +44 -0
- package/_cjs/account-abstraction/utils/formatters/userOperationReceipt.js +2 -0
- package/_cjs/account-abstraction/utils/formatters/userOperationReceipt.js.map +1 -1
- package/_cjs/actions/public/estimateGas.js +5 -2
- package/_cjs/actions/public/estimateGas.js.map +1 -1
- package/_cjs/actions/public/fillTransaction.js +2 -0
- package/_cjs/actions/public/fillTransaction.js.map +1 -1
- package/_cjs/actions/public/getFilterChanges.js +1 -0
- package/_cjs/actions/public/getFilterChanges.js.map +1 -1
- package/_cjs/actions/public/getFilterLogs.js +1 -0
- package/_cjs/actions/public/getFilterLogs.js.map +1 -1
- package/_cjs/actions/public/watchBlockNumber.js +3 -1
- package/_cjs/actions/public/watchBlockNumber.js.map +1 -1
- package/_cjs/actions/public/watchBlocks.js +20 -8
- package/_cjs/actions/public/watchBlocks.js.map +1 -1
- package/_cjs/actions/public/watchContractEvent.js +10 -3
- package/_cjs/actions/public/watchContractEvent.js.map +1 -1
- package/_cjs/actions/public/watchEvent.js +5 -0
- package/_cjs/actions/public/watchEvent.js.map +1 -1
- package/_cjs/actions/wallet/prepareTransactionRequest.js +3 -2
- package/_cjs/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_cjs/actions/wallet/sendTransaction.js +4 -2
- package/_cjs/actions/wallet/sendTransaction.js.map +1 -1
- package/_cjs/actions/wallet/sendTransactionSync.js +48 -7
- package/_cjs/actions/wallet/sendTransactionSync.js.map +1 -1
- package/_cjs/chains/definitions/hashKeyChain.js +4 -4
- package/_cjs/chains/definitions/hashKeyChain.js.map +1 -1
- package/_cjs/chains/definitions/hashkeyChainTestnet.js +4 -4
- package/_cjs/chains/definitions/hashkeyChainTestnet.js.map +1 -1
- package/_cjs/chains/definitions/turkchain.js +26 -0
- package/_cjs/chains/definitions/turkchain.js.map +1 -0
- package/_cjs/chains/definitions/zksync.js +1 -1
- package/_cjs/chains/definitions/zksync.js.map +1 -1
- package/_cjs/chains/index.js +4 -2
- package/_cjs/chains/index.js.map +1 -1
- package/_cjs/clients/createClient.js.map +1 -1
- package/_cjs/clients/transports/fallback.js +5 -0
- package/_cjs/clients/transports/fallback.js.map +1 -1
- package/_cjs/errors/node.js +10 -4
- package/_cjs/errors/node.js.map +1 -1
- package/_cjs/errors/typedData.js +4 -2
- package/_cjs/errors/typedData.js.map +1 -1
- package/_cjs/errors/version.js +1 -1
- package/_cjs/index.js +5 -4
- package/_cjs/index.js.map +1 -1
- package/_cjs/tempo/Account.js +85 -12
- package/_cjs/tempo/Account.js.map +1 -1
- package/_cjs/tempo/Transaction.js +2 -1
- package/_cjs/tempo/Transaction.js.map +1 -1
- package/_cjs/tempo/chainConfig.js +4 -12
- package/_cjs/tempo/chainConfig.js.map +1 -1
- package/_cjs/tempo/internal/relay/feePayer.js +18 -5
- package/_cjs/tempo/internal/relay/feePayer.js.map +1 -1
- package/_cjs/utils/abi/decodeEventLog.js +57 -7
- package/_cjs/utils/abi/decodeEventLog.js.map +1 -1
- package/_cjs/utils/abi/getAbiItem.js +27 -6
- package/_cjs/utils/abi/getAbiItem.js.map +1 -1
- package/_cjs/utils/abi/parseEventLogs.js +27 -4
- package/_cjs/utils/abi/parseEventLogs.js.map +1 -1
- package/_cjs/utils/authorization/recoverAuthorizationAddress.js +9 -2
- package/_cjs/utils/authorization/recoverAuthorizationAddress.js.map +1 -1
- package/_cjs/utils/authorization/verifyAuthorization.js +14 -4
- package/_cjs/utils/authorization/verifyAuthorization.js.map +1 -1
- package/_cjs/utils/ccip.js +134 -28
- package/_cjs/utils/ccip.js.map +1 -1
- package/_cjs/utils/ccipTunnel.js +5 -1
- package/_cjs/utils/ccipTunnel.js.map +1 -1
- package/_cjs/utils/ens/localBatchGatewayRequest.js +55 -5
- package/_cjs/utils/ens/localBatchGatewayRequest.js.map +1 -1
- package/_cjs/utils/internal/http.js +79 -0
- package/_cjs/utils/internal/http.js.map +1 -0
- package/_cjs/utils/nonceManager.js.map +1 -1
- package/_cjs/utils/rpc/http.js +3 -73
- package/_cjs/utils/rpc/http.js.map +1 -1
- package/_cjs/utils/transaction/assertRequest.js +2 -2
- package/_cjs/utils/transaction/assertRequest.js.map +1 -1
- package/_cjs/utils/transaction/assertTransaction.js +2 -2
- package/_cjs/utils/transaction/assertTransaction.js.map +1 -1
- package/_cjs/utils/transaction/parseTransaction.js +21 -7
- package/_cjs/utils/transaction/parseTransaction.js.map +1 -1
- package/_cjs/utils/typedData.js +19 -6
- package/_cjs/utils/typedData.js.map +1 -1
- package/_esm/account-abstraction/utils/formatters/userOperationReceipt.js +2 -0
- package/_esm/account-abstraction/utils/formatters/userOperationReceipt.js.map +1 -1
- package/_esm/actions/public/estimateGas.js +10 -5
- package/_esm/actions/public/estimateGas.js.map +1 -1
- package/_esm/actions/public/fillTransaction.js +2 -0
- package/_esm/actions/public/fillTransaction.js.map +1 -1
- package/_esm/actions/public/getFilterChanges.js +1 -0
- package/_esm/actions/public/getFilterChanges.js.map +1 -1
- package/_esm/actions/public/getFilterLogs.js +1 -0
- package/_esm/actions/public/getFilterLogs.js.map +1 -1
- package/_esm/actions/public/watchBlockNumber.js +5 -1
- package/_esm/actions/public/watchBlockNumber.js.map +1 -1
- package/_esm/actions/public/watchBlocks.js +28 -8
- package/_esm/actions/public/watchBlocks.js.map +1 -1
- package/_esm/actions/public/watchContractEvent.js +15 -5
- package/_esm/actions/public/watchContractEvent.js.map +1 -1
- package/_esm/actions/public/watchEvent.js +11 -2
- package/_esm/actions/public/watchEvent.js.map +1 -1
- package/_esm/actions/wallet/prepareTransactionRequest.js +3 -2
- package/_esm/actions/wallet/prepareTransactionRequest.js.map +1 -1
- package/_esm/actions/wallet/sendTransaction.js +6 -2
- package/_esm/actions/wallet/sendTransaction.js.map +1 -1
- package/_esm/actions/wallet/sendTransactionSync.js +59 -8
- package/_esm/actions/wallet/sendTransactionSync.js.map +1 -1
- package/_esm/chains/definitions/hashKeyChain.js +4 -4
- package/_esm/chains/definitions/hashKeyChain.js.map +1 -1
- package/_esm/chains/definitions/hashkeyChainTestnet.js +4 -4
- package/_esm/chains/definitions/hashkeyChainTestnet.js.map +1 -1
- package/_esm/chains/definitions/turkchain.js +23 -0
- package/_esm/chains/definitions/turkchain.js.map +1 -0
- package/_esm/chains/definitions/zksync.js +1 -1
- package/_esm/chains/definitions/zksync.js.map +1 -1
- package/_esm/chains/index.js +1 -0
- package/_esm/chains/index.js.map +1 -1
- package/_esm/clients/createClient.js.map +1 -1
- package/_esm/clients/transports/fallback.js +8 -0
- package/_esm/clients/transports/fallback.js.map +1 -1
- package/_esm/errors/node.js +10 -4
- package/_esm/errors/node.js.map +1 -1
- package/_esm/errors/typedData.js +5 -2
- package/_esm/errors/typedData.js.map +1 -1
- package/_esm/errors/version.js +1 -1
- package/_esm/index.js +1 -1
- package/_esm/index.js.map +1 -1
- package/_esm/tempo/Account.js +122 -11
- package/_esm/tempo/Account.js.map +1 -1
- package/_esm/tempo/Transaction.js +2 -0
- package/_esm/tempo/Transaction.js.map +1 -1
- package/_esm/tempo/chainConfig.js +13 -15
- package/_esm/tempo/chainConfig.js.map +1 -1
- package/_esm/tempo/internal/relay/feePayer.js +24 -7
- package/_esm/tempo/internal/relay/feePayer.js.map +1 -1
- package/_esm/utils/abi/decodeEventLog.js +69 -7
- package/_esm/utils/abi/decodeEventLog.js.map +1 -1
- package/_esm/utils/abi/getAbiItem.js +34 -6
- package/_esm/utils/abi/getAbiItem.js.map +1 -1
- package/_esm/utils/abi/parseEventLogs.js +43 -10
- package/_esm/utils/abi/parseEventLogs.js.map +1 -1
- package/_esm/utils/authorization/recoverAuthorizationAddress.js +11 -2
- package/_esm/utils/authorization/recoverAuthorizationAddress.js.map +1 -1
- package/_esm/utils/authorization/verifyAuthorization.js +15 -4
- package/_esm/utils/authorization/verifyAuthorization.js.map +1 -1
- package/_esm/utils/ccip.js +163 -31
- package/_esm/utils/ccip.js.map +1 -1
- package/_esm/utils/ccipTunnel.js +5 -1
- package/_esm/utils/ccipTunnel.js.map +1 -1
- package/_esm/utils/ens/localBatchGatewayRequest.js +69 -4
- package/_esm/utils/ens/localBatchGatewayRequest.js.map +1 -1
- package/_esm/utils/internal/http.js +83 -0
- package/_esm/utils/internal/http.js.map +1 -0
- package/_esm/utils/nonceManager.js.map +1 -1
- package/_esm/utils/rpc/http.js +1 -75
- package/_esm/utils/rpc/http.js.map +1 -1
- package/_esm/utils/transaction/assertRequest.js +2 -2
- package/_esm/utils/transaction/assertRequest.js.map +1 -1
- package/_esm/utils/transaction/assertTransaction.js +2 -2
- package/_esm/utils/transaction/assertTransaction.js.map +1 -1
- package/_esm/utils/transaction/parseTransaction.js +24 -7
- package/_esm/utils/transaction/parseTransaction.js.map +1 -1
- package/_esm/utils/typedData.js +25 -8
- package/_esm/utils/typedData.js.map +1 -1
- package/_types/account-abstraction/utils/formatters/userOperationReceipt.d.ts.map +1 -1
- package/_types/actions/public/estimateGas.d.ts.map +1 -1
- package/_types/actions/public/fillTransaction.d.ts.map +1 -1
- package/_types/actions/public/getFilterChanges.d.ts.map +1 -1
- package/_types/actions/public/getFilterLogs.d.ts.map +1 -1
- package/_types/actions/public/watchBlockNumber.d.ts +6 -2
- package/_types/actions/public/watchBlockNumber.d.ts.map +1 -1
- package/_types/actions/public/watchBlocks.d.ts +7 -2
- package/_types/actions/public/watchBlocks.d.ts.map +1 -1
- package/_types/actions/public/watchContractEvent.d.ts.map +1 -1
- package/_types/actions/public/watchEvent.d.ts.map +1 -1
- package/_types/actions/wallet/prepareTransactionRequest.d.ts.map +1 -1
- package/_types/actions/wallet/sendTransaction.d.ts.map +1 -1
- package/_types/actions/wallet/sendTransactionSync.d.ts.map +1 -1
- package/_types/chains/definitions/hashKeyChain.d.ts +4 -4
- package/_types/chains/definitions/hashkeyChainTestnet.d.ts +4 -4
- package/_types/chains/definitions/turkchain.d.ts +53 -0
- package/_types/chains/definitions/turkchain.d.ts.map +1 -0
- package/_types/chains/definitions/zksync.d.ts +1 -1
- package/_types/chains/index.d.ts +1 -0
- package/_types/chains/index.d.ts.map +1 -1
- package/_types/clients/createClient.d.ts +6 -0
- package/_types/clients/createClient.d.ts.map +1 -1
- package/_types/clients/transports/fallback.d.ts.map +1 -1
- package/_types/errors/node.d.ts.map +1 -1
- package/_types/errors/typedData.d.ts.map +1 -1
- package/_types/errors/version.d.ts +1 -1
- package/_types/index.d.ts +1 -1
- package/_types/index.d.ts.map +1 -1
- package/_types/tempo/Account.d.ts +77 -4
- package/_types/tempo/Account.d.ts.map +1 -1
- package/_types/tempo/Relay.d.ts +1 -1
- package/_types/tempo/Relay.d.ts.map +1 -1
- package/_types/tempo/Transaction.d.ts +2 -0
- package/_types/tempo/Transaction.d.ts.map +1 -1
- package/_types/tempo/chainConfig.d.ts.map +1 -1
- package/_types/tempo/internal/relay/feePayer.d.ts.map +1 -1
- package/_types/tempo/internal/relay/utils.d.ts +8 -8
- package/_types/utils/abi/decodeEventLog.d.ts +13 -1
- package/_types/utils/abi/decodeEventLog.d.ts.map +1 -1
- package/_types/utils/abi/getAbiItem.d.ts.map +1 -1
- package/_types/utils/abi/parseEventLogs.d.ts.map +1 -1
- package/_types/utils/authorization/recoverAuthorizationAddress.d.ts +2 -1
- package/_types/utils/authorization/recoverAuthorizationAddress.d.ts.map +1 -1
- package/_types/utils/authorization/verifyAuthorization.d.ts.map +1 -1
- package/_types/utils/ccip.d.ts +24 -4
- package/_types/utils/ccip.d.ts.map +1 -1
- package/_types/utils/ccipTunnel.d.ts.map +1 -1
- package/_types/utils/ens/localBatchGatewayRequest.d.ts +26 -0
- package/_types/utils/ens/localBatchGatewayRequest.d.ts.map +1 -1
- package/_types/utils/internal/http.d.ts +16 -0
- package/_types/utils/internal/http.d.ts.map +1 -0
- package/_types/utils/nonceManager.d.ts +15 -1
- package/_types/utils/nonceManager.d.ts.map +1 -1
- package/_types/utils/rpc/http.d.ts.map +1 -1
- package/_types/utils/transaction/parseTransaction.d.ts.map +1 -1
- package/_types/utils/typedData.d.ts.map +1 -1
- package/account-abstraction/utils/formatters/userOperationReceipt.ts +1 -0
- package/actions/public/estimateGas.ts +12 -5
- package/actions/public/fillTransaction.ts +2 -0
- package/actions/public/getFilterChanges.ts +1 -0
- package/actions/public/getFilterLogs.ts +1 -0
- package/actions/public/watchBlockNumber.ts +11 -2
- package/actions/public/watchBlocks.ts +46 -14
- package/actions/public/watchContractEvent.ts +22 -4
- package/actions/public/watchEvent.ts +17 -1
- package/actions/wallet/prepareTransactionRequest.ts +6 -2
- package/actions/wallet/sendTransaction.ts +9 -3
- package/actions/wallet/sendTransactionSync.ts +74 -12
- package/chains/definitions/hashKeyChain.ts +4 -4
- package/chains/definitions/hashkeyChainTestnet.ts +4 -4
- package/chains/definitions/turkchain.ts +23 -0
- package/chains/definitions/zksync.ts +1 -1
- package/chains/index.ts +1 -0
- package/clients/createClient.ts +6 -0
- package/clients/transports/fallback.ts +11 -0
- package/errors/node.ts +11 -5
- package/errors/typedData.ts +5 -2
- package/errors/version.ts +1 -1
- package/index.ts +2 -0
- package/package.json +1 -1
- package/tempo/Account.ts +202 -16
- package/tempo/Relay.ts +1 -1
- package/tempo/Transaction.ts +3 -0
- package/tempo/chainConfig.ts +13 -15
- package/tempo/internal/relay/feePayer.ts +30 -7
- package/utils/abi/decodeEventLog.ts +97 -10
- package/utils/abi/getAbiItem.ts +35 -5
- package/utils/abi/parseEventLogs.ts +48 -11
- package/utils/authorization/recoverAuthorizationAddress.ts +18 -2
- package/utils/authorization/verifyAuthorization.ts +12 -7
- package/utils/ccip.ts +199 -33
- package/utils/ccipTunnel.ts +5 -1
- package/utils/ens/localBatchGatewayRequest.ts +82 -4
- package/utils/internal/http.ts +92 -0
- package/utils/nonceManager.ts +16 -1
- package/utils/rpc/http.ts +1 -83
- package/utils/transaction/assertRequest.ts +2 -2
- package/utils/transaction/assertTransaction.ts +2 -2
- package/utils/transaction/parseTransaction.ts +32 -7
- package/utils/typedData.ts +31 -8
package/tempo/Account.ts
CHANGED
|
@@ -17,6 +17,7 @@ import type {
|
|
|
17
17
|
Account as viem_Account,
|
|
18
18
|
} from '../accounts/types.js'
|
|
19
19
|
import { parseAccount } from '../accounts/utils/parseAccount.js'
|
|
20
|
+
import { BaseError } from '../errors/base.js'
|
|
20
21
|
import type { TransactionSerializable } from '../types/transaction.js'
|
|
21
22
|
import type { OneOf, RequiredBy } from '../types/utils.js'
|
|
22
23
|
import { hashAuthorization } from '../utils/authorization/hashAuthorization.js'
|
|
@@ -93,6 +94,73 @@ export type AccessKeyAccount = Account_base<'accessKey'> & {
|
|
|
93
94
|
|
|
94
95
|
export type Account = OneOf<RootAccount | AccessKeyAccount>
|
|
95
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Rebuilds a configurable account (TIP-1107) from the value of {@link serialize},
|
|
99
|
+
* such as one read from storage, without a request.
|
|
100
|
+
*
|
|
101
|
+
* Passkeys among `credentials` sign as owners when their public key derives an
|
|
102
|
+
* owner's address; others are ignored. A version-zero config must derive
|
|
103
|
+
* `address`, and a later version keeps `address`.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* ```ts
|
|
107
|
+
* import { Account } from 'viem/tempo'
|
|
108
|
+
*
|
|
109
|
+
* const account = Account.deserialize(JSON.parse(localStorage.getItem('account')!), {
|
|
110
|
+
* credentials: [credential],
|
|
111
|
+
* })
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* @param value Serialized account.
|
|
115
|
+
* @param options Options.
|
|
116
|
+
* @returns Configurable account.
|
|
117
|
+
*/
|
|
118
|
+
export function deserialize(
|
|
119
|
+
value: Serialized,
|
|
120
|
+
options: deserialize.Options = {},
|
|
121
|
+
): ConfigurableAccount {
|
|
122
|
+
const { address, config } = value
|
|
123
|
+
const { credentials = [], getFn } = options
|
|
124
|
+
if (!config) return fromConfig(address)
|
|
125
|
+
|
|
126
|
+
const owners = config.owners.map(({ owner, weight }) => {
|
|
127
|
+
const credential = credentials.find((credential) =>
|
|
128
|
+
Address.isEqual(
|
|
129
|
+
Address.fromPublicKey(PublicKey.fromHex(credential.publicKey)),
|
|
130
|
+
owner,
|
|
131
|
+
),
|
|
132
|
+
)
|
|
133
|
+
if (!credential) return { owner, weight }
|
|
134
|
+
const { rpId } = credential
|
|
135
|
+
return { owner: fromWebAuthnP256(credential, { getFn, rpId }), weight }
|
|
136
|
+
})
|
|
137
|
+
const { salt, threshold } = config
|
|
138
|
+
const version = BigInt(config.version)
|
|
139
|
+
const account =
|
|
140
|
+
version === 0n
|
|
141
|
+
? fromConfig({ owners, salt, threshold })
|
|
142
|
+
: fromConfig({ address, owners, salt, threshold, version })
|
|
143
|
+
if (!Address.isEqual(account.address, address))
|
|
144
|
+
throw new AddressMismatchError({ address, derived: account.address })
|
|
145
|
+
return account
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export declare namespace deserialize {
|
|
149
|
+
export type Credential = fromWebAuthnP256.Credential & {
|
|
150
|
+
/** Relying party ID of the passkey, such as `example.com`. */
|
|
151
|
+
rpId?: string | undefined
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
export type Options = {
|
|
155
|
+
/** Passkeys that may hold owner keys of the account. */
|
|
156
|
+
credentials?: readonly Credential[] | undefined
|
|
157
|
+
/** Runs a passkey owner's ceremony in place of `navigator.credentials.get`. */
|
|
158
|
+
getFn?: fromWebAuthnP256.Options['getFn'] | undefined
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export type ErrorType = AddressMismatchError | Error
|
|
162
|
+
}
|
|
163
|
+
|
|
96
164
|
/** Instantiates an Account. */
|
|
97
165
|
export function from<const parameters extends from.Parameters>(
|
|
98
166
|
parameters: parameters | from.Parameters,
|
|
@@ -137,13 +205,19 @@ export function fromHeadlessWebAuthn<
|
|
|
137
205
|
privateKey: Hex.Hex,
|
|
138
206
|
options: options | fromHeadlessWebAuthn.Options,
|
|
139
207
|
): fromHeadlessWebAuthn.ReturnValue<options> {
|
|
140
|
-
const {
|
|
141
|
-
|
|
208
|
+
const {
|
|
209
|
+
access,
|
|
210
|
+
keyAuthorization,
|
|
211
|
+
keyAuthorizationManager,
|
|
212
|
+
rpId,
|
|
213
|
+
origin,
|
|
214
|
+
internal_version,
|
|
215
|
+
} = options
|
|
142
216
|
|
|
143
217
|
const publicKey = P256.getPublicKey({ privateKey })
|
|
144
218
|
|
|
145
219
|
return from({
|
|
146
|
-
...(access ? { access, keyAuthorizationManager } : {}),
|
|
220
|
+
...(access ? { access, keyAuthorization, keyAuthorizationManager } : {}),
|
|
147
221
|
internal_version,
|
|
148
222
|
keyType: 'webAuthn',
|
|
149
223
|
publicKey,
|
|
@@ -176,7 +250,10 @@ export declare namespace fromHeadlessWebAuthn {
|
|
|
176
250
|
> &
|
|
177
251
|
Pick<
|
|
178
252
|
from.Parameters,
|
|
179
|
-
|
|
253
|
+
| 'access'
|
|
254
|
+
| 'internal_version'
|
|
255
|
+
| 'keyAuthorization'
|
|
256
|
+
| 'keyAuthorizationManager'
|
|
180
257
|
> & {
|
|
181
258
|
rpId: string
|
|
182
259
|
origin: string
|
|
@@ -203,11 +280,16 @@ export function fromP256<const options extends fromP256.Options>(
|
|
|
203
280
|
privateKey: Hex.Hex,
|
|
204
281
|
options: options | fromP256.Options = {},
|
|
205
282
|
): fromP256.ReturnValue<options> {
|
|
206
|
-
const {
|
|
283
|
+
const {
|
|
284
|
+
access,
|
|
285
|
+
keyAuthorization,
|
|
286
|
+
keyAuthorizationManager,
|
|
287
|
+
internal_version,
|
|
288
|
+
} = options
|
|
207
289
|
const publicKey = P256.getPublicKey({ privateKey })
|
|
208
290
|
|
|
209
291
|
return from({
|
|
210
|
-
...(access ? { access, keyAuthorizationManager } : {}),
|
|
292
|
+
...(access ? { access, keyAuthorization, keyAuthorizationManager } : {}),
|
|
211
293
|
internal_version,
|
|
212
294
|
keyType: 'p256',
|
|
213
295
|
publicKey,
|
|
@@ -225,7 +307,10 @@ export function fromP256<const options extends fromP256.Options>(
|
|
|
225
307
|
export declare namespace fromP256 {
|
|
226
308
|
export type Options = Pick<
|
|
227
309
|
from.Parameters,
|
|
228
|
-
|
|
310
|
+
| 'access'
|
|
311
|
+
| 'internal_version'
|
|
312
|
+
| 'keyAuthorization'
|
|
313
|
+
| 'keyAuthorizationManager'
|
|
229
314
|
>
|
|
230
315
|
|
|
231
316
|
export type ReturnValue<options extends Options = Options> =
|
|
@@ -249,11 +334,16 @@ export function fromSecp256k1<const options extends fromSecp256k1.Options>(
|
|
|
249
334
|
privateKey: Hex.Hex,
|
|
250
335
|
options: options | fromSecp256k1.Options = {},
|
|
251
336
|
): fromSecp256k1.ReturnValue<options> {
|
|
252
|
-
const {
|
|
337
|
+
const {
|
|
338
|
+
access,
|
|
339
|
+
keyAuthorization,
|
|
340
|
+
keyAuthorizationManager,
|
|
341
|
+
internal_version,
|
|
342
|
+
} = options
|
|
253
343
|
const publicKey = Secp256k1.getPublicKey({ privateKey })
|
|
254
344
|
|
|
255
345
|
return from({
|
|
256
|
-
...(access ? { access, keyAuthorizationManager } : {}),
|
|
346
|
+
...(access ? { access, keyAuthorization, keyAuthorizationManager } : {}),
|
|
257
347
|
internal_version,
|
|
258
348
|
keyType: 'secp256k1',
|
|
259
349
|
publicKey,
|
|
@@ -268,7 +358,10 @@ export function fromSecp256k1<const options extends fromSecp256k1.Options>(
|
|
|
268
358
|
export declare namespace fromSecp256k1 {
|
|
269
359
|
export type Options = Pick<
|
|
270
360
|
from.Parameters,
|
|
271
|
-
|
|
361
|
+
| 'access'
|
|
362
|
+
| 'internal_version'
|
|
363
|
+
| 'keyAuthorization'
|
|
364
|
+
| 'keyAuthorizationManager'
|
|
272
365
|
>
|
|
273
366
|
|
|
274
367
|
export type ReturnValue<options extends Options = Options> =
|
|
@@ -745,11 +838,16 @@ export function fromWebCryptoP256<
|
|
|
745
838
|
keyPair: Awaited<ReturnType<typeof WebCryptoP256.createKeyPair>>,
|
|
746
839
|
options: options | fromWebCryptoP256.Options = {},
|
|
747
840
|
): fromWebCryptoP256.ReturnValue<options> {
|
|
748
|
-
const {
|
|
841
|
+
const {
|
|
842
|
+
access,
|
|
843
|
+
keyAuthorization,
|
|
844
|
+
keyAuthorizationManager,
|
|
845
|
+
internal_version,
|
|
846
|
+
} = options
|
|
749
847
|
const { publicKey, privateKey } = keyPair
|
|
750
848
|
|
|
751
849
|
return from({
|
|
752
|
-
...(access ? { access, keyAuthorizationManager } : {}),
|
|
850
|
+
...(access ? { access, keyAuthorization, keyAuthorizationManager } : {}),
|
|
753
851
|
internal_version,
|
|
754
852
|
keyType: 'p256',
|
|
755
853
|
publicKey,
|
|
@@ -768,7 +866,10 @@ export function fromWebCryptoP256<
|
|
|
768
866
|
export declare namespace fromWebCryptoP256 {
|
|
769
867
|
export type Options = Pick<
|
|
770
868
|
from.Parameters,
|
|
771
|
-
|
|
869
|
+
| 'access'
|
|
870
|
+
| 'internal_version'
|
|
871
|
+
| 'keyAuthorization'
|
|
872
|
+
| 'keyAuthorizationManager'
|
|
772
873
|
>
|
|
773
874
|
|
|
774
875
|
export type ReturnValue<options extends Options = Options> =
|
|
@@ -1114,17 +1215,52 @@ declare namespace fromRoot {
|
|
|
1114
1215
|
|
|
1115
1216
|
// biome-ignore lint/correctness/noUnusedVariables: _
|
|
1116
1217
|
function fromAccessKey(parameters: fromAccessKey.Parameters): AccessKeyAccount {
|
|
1117
|
-
const { access,
|
|
1218
|
+
const { access, keyAuthorization } = parameters
|
|
1118
1219
|
const { address: parentAddress } = parseAccount(access)
|
|
1119
|
-
const
|
|
1220
|
+
const accessKeyAddress = Address.fromPublicKey(parameters.publicKey)
|
|
1221
|
+
if (
|
|
1222
|
+
keyAuthorization &&
|
|
1223
|
+
!Address.isEqual(keyAuthorization.address, accessKeyAddress)
|
|
1224
|
+
)
|
|
1225
|
+
throw new Error('Key authorization does not authorize this access key.')
|
|
1226
|
+
const keyAuthorizationManager =
|
|
1227
|
+
parameters.keyAuthorizationManager ??
|
|
1228
|
+
(keyAuthorization ? pending(keyAuthorization) : undefined)
|
|
1229
|
+
const account = fromBase({
|
|
1230
|
+
...parameters,
|
|
1231
|
+
keyAuthorizationManager,
|
|
1232
|
+
parentAddress,
|
|
1233
|
+
})
|
|
1120
1234
|
return {
|
|
1121
1235
|
...account,
|
|
1122
|
-
accessKeyAddress
|
|
1236
|
+
accessKeyAddress,
|
|
1123
1237
|
keyAuthorizationManager,
|
|
1124
1238
|
source: 'accessKey',
|
|
1125
1239
|
}
|
|
1126
1240
|
}
|
|
1127
1241
|
|
|
1242
|
+
/**
|
|
1243
|
+
* Returns a key authorization manager that holds `keyAuthorization` until the
|
|
1244
|
+
* chain registers its access key.
|
|
1245
|
+
*/
|
|
1246
|
+
function pending(
|
|
1247
|
+
keyAuthorization: KeyAuthorization.Signed,
|
|
1248
|
+
): KeyAuthorizationManager {
|
|
1249
|
+
let value: KeyAuthorization.Signed | undefined = keyAuthorization
|
|
1250
|
+
const matches = (key: { accessKey: Address.Address; chainId: number }) =>
|
|
1251
|
+
Address.isEqual(key.accessKey, keyAuthorization.address) &&
|
|
1252
|
+
BigInt(key.chainId) === BigInt(keyAuthorization.chainId)
|
|
1253
|
+
return {
|
|
1254
|
+
get: (key) => (matches(key) ? value : undefined),
|
|
1255
|
+
remove(key) {
|
|
1256
|
+
if (matches(key)) value = undefined
|
|
1257
|
+
},
|
|
1258
|
+
set(key, next) {
|
|
1259
|
+
if (matches(key)) value = next
|
|
1260
|
+
},
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1128
1264
|
declare namespace fromAccessKey {
|
|
1129
1265
|
export type Parameters = fromBase.Parameters & {
|
|
1130
1266
|
/**
|
|
@@ -1133,6 +1269,12 @@ declare namespace fromAccessKey {
|
|
|
1133
1269
|
* the parent account's address as the keychain address.
|
|
1134
1270
|
*/
|
|
1135
1271
|
access: viem_Account | Address.Address
|
|
1272
|
+
/**
|
|
1273
|
+
* Signed key authorization of the access key, which the account attaches
|
|
1274
|
+
* to its transactions until the chain registers the access key. Ignored
|
|
1275
|
+
* when `keyAuthorizationManager` is set.
|
|
1276
|
+
*/
|
|
1277
|
+
keyAuthorization?: KeyAuthorization.Signed | undefined
|
|
1136
1278
|
/** Pending key authorization manager. */
|
|
1137
1279
|
keyAuthorizationManager?: KeyAuthorizationManager | undefined
|
|
1138
1280
|
}
|
|
@@ -1190,6 +1332,50 @@ export declare namespace resolveAccessKey {
|
|
|
1190
1332
|
}
|
|
1191
1333
|
}
|
|
1192
1334
|
|
|
1335
|
+
/**
|
|
1336
|
+
* Returns a configurable account (TIP-1107) as JSON-safe public values: its
|
|
1337
|
+
* address and, when known, its config. {@link deserialize} rebuilds it.
|
|
1338
|
+
*
|
|
1339
|
+
* @example
|
|
1340
|
+
* ```ts
|
|
1341
|
+
* import { Account } from 'viem/tempo'
|
|
1342
|
+
*
|
|
1343
|
+
* localStorage.setItem('account', JSON.stringify(Account.serialize(account)))
|
|
1344
|
+
* ```
|
|
1345
|
+
*
|
|
1346
|
+
* @param account Configurable account.
|
|
1347
|
+
* @returns Serialized account.
|
|
1348
|
+
*/
|
|
1349
|
+
export function serialize(account: ConfigurableAccount): Serialized {
|
|
1350
|
+
const { address, config } = account
|
|
1351
|
+
return {
|
|
1352
|
+
address,
|
|
1353
|
+
...(config ? { config: AccountConfig.toRpc(config) } : {}),
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
/** Configurable account as JSON, which {@link serialize} returns and {@link deserialize} rebuilds. */
|
|
1358
|
+
export type Serialized = {
|
|
1359
|
+
/** Account address. */
|
|
1360
|
+
address: Address.Address
|
|
1361
|
+
/** Current config, in RPC format. Absent for an address-only account. */
|
|
1362
|
+
config?: AccountConfig.Rpc | undefined
|
|
1363
|
+
}
|
|
1364
|
+
|
|
1365
|
+
/** Thrown when a version-zero config does not derive the account's address. */
|
|
1366
|
+
export class AddressMismatchError extends BaseError {
|
|
1367
|
+
/** Address the config derives. */
|
|
1368
|
+
readonly derived: Address.Address
|
|
1369
|
+
|
|
1370
|
+
constructor(options: { address: Address.Address; derived: Address.Address }) {
|
|
1371
|
+
const { address, derived } = options
|
|
1372
|
+
super(`Account config derives ${derived}, not ${address}.`, {
|
|
1373
|
+
name: 'Account.AddressMismatchError',
|
|
1374
|
+
})
|
|
1375
|
+
this.derived = derived
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
|
|
1193
1379
|
// Export types required for inference.
|
|
1194
1380
|
// biome-ignore lint/performance/noBarrelFile: _
|
|
1195
1381
|
export {
|
package/tempo/Relay.ts
CHANGED
|
@@ -450,7 +450,7 @@ export declare namespace feePayer {
|
|
|
450
450
|
url?: string | undefined
|
|
451
451
|
/** Only `true` authorizes sponsorship. Rejected fills fall back to sender-paid transactions. */
|
|
452
452
|
validate?: Sponsorship.Validate | undefined
|
|
453
|
-
/** Longest on-chain validity, in seconds, of a returned fee-payer signature. Fills without `validBefore` receive one; `eth_signRawTransaction` requires one. @default 3600 */
|
|
453
|
+
/** Longest on-chain validity, in seconds, of a returned fee-payer signature. Fills without `validBefore` receive one; `eth_signRawTransaction` requires one. Expiring nonce transactions are capped at `Transaction.expiringNonceMaxExpiry`. @default 3600 */
|
|
454
454
|
validity?: number | undefined
|
|
455
455
|
}
|
|
456
456
|
/** Result of a sponsorship policy check. */
|
package/tempo/Transaction.ts
CHANGED
|
@@ -207,6 +207,9 @@ export type TransactionSerializedFeePayer = `0x78${string}`
|
|
|
207
207
|
|
|
208
208
|
export type TransactionType = viem_TransactionType | 'tempo'
|
|
209
209
|
|
|
210
|
+
/** Longest distance, in seconds, between now and an expiring nonce transaction's `validBefore`. */
|
|
211
|
+
export const expiringNonceMaxExpiry = 300
|
|
212
|
+
|
|
210
213
|
export function getType(
|
|
211
214
|
transaction: Record<string, unknown>,
|
|
212
215
|
): Transaction['type'] {
|
package/tempo/chainConfig.ts
CHANGED
|
@@ -36,7 +36,8 @@ import * as Concurrent from './internal/concurrent.js'
|
|
|
36
36
|
import { transactionReplacement } from './internal/replacement.js'
|
|
37
37
|
import * as Transaction from './Transaction.js'
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
/** Default distance, in seconds, of a generated expiring nonce `validBefore`. Stays under the 300-second limit to allow for clock skew. */
|
|
40
|
+
const expiringNonceExpiry = 270
|
|
40
41
|
|
|
41
42
|
// TODO: casting to satisfy viem – viem v3 to have more flexible serializer type.
|
|
42
43
|
const serializeTransaction = ((transaction, signature) =>
|
|
@@ -165,7 +166,8 @@ export const chainConfig = {
|
|
|
165
166
|
!request.feePayerSignature &&
|
|
166
167
|
!approved
|
|
167
168
|
) {
|
|
168
|
-
// The fill omits the fee payer's signature and fee token (85 bytes), which count toward intrinsic gas
|
|
169
|
+
// The fill omits the fee payer's signature and fee token (85 bytes), which count toward intrinsic gas,
|
|
170
|
+
// and, from T14, the cold access (2,600 gas) of the fee payer's account.
|
|
169
171
|
request.gas = (request.gas ?? 0n) + feePayerGas
|
|
170
172
|
if (request.keyAuthorization?.signature.type === 'webAuthn')
|
|
171
173
|
request.gas = (request.gas ?? 0n) + 20_000n
|
|
@@ -259,11 +261,12 @@ export const chainConfig = {
|
|
|
259
261
|
request.nonce = 0
|
|
260
262
|
} else if (useExpiringNonce) {
|
|
261
263
|
request.nonceKey = maxUint256
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
264
|
+
// A random discriminator keeps otherwise identical expiring transactions distinct.
|
|
265
|
+
// 48 bits stay within `Number.MAX_SAFE_INTEGER`.
|
|
266
|
+
request.nonce ??= Hex.toNumber(Hex.random(6))
|
|
265
267
|
if (typeof request.validBefore === 'undefined')
|
|
266
|
-
request.validBefore =
|
|
268
|
+
request.validBefore =
|
|
269
|
+
Math.floor(Date.now() / 1000) + expiringNonceExpiry
|
|
267
270
|
} else if (
|
|
268
271
|
typeof request.nonceKey !== 'undefined' &&
|
|
269
272
|
// Nonce key 0 is the protocol nonce, so core fills it like an Ethereum nonce.
|
|
@@ -506,14 +509,6 @@ function getSimulationKey(
|
|
|
506
509
|
return { keyData: '0x0578' as const, keyType: 'webAuthn' as const }
|
|
507
510
|
}
|
|
508
511
|
|
|
509
|
-
/** Returns random past seconds to distinguish otherwise-identical expiring transactions. */
|
|
510
|
-
function randomValidAfter(): number {
|
|
511
|
-
const now = BigInt(Math.floor(Date.now() / 1_000))
|
|
512
|
-
const latest = now - 60n
|
|
513
|
-
if (latest <= 0n) return 0
|
|
514
|
-
return Number(BigInt(Hex.random(8)) % latest)
|
|
515
|
-
}
|
|
516
|
-
|
|
517
512
|
/** Selects a deterministic minimum-cardinality owner quorum. */
|
|
518
513
|
function selectOwners(config: AccountConfig.Config) {
|
|
519
514
|
const owners = [...config.owners].sort(
|
|
@@ -533,5 +528,8 @@ function selectOwners(config: AccountConfig.Config) {
|
|
|
533
528
|
)
|
|
534
529
|
}
|
|
535
530
|
|
|
536
|
-
/**
|
|
531
|
+
/**
|
|
532
|
+
* Intrinsic gas reserved for what `eth_fillTransaction` estimates without: the fee payer's signature and
|
|
533
|
+
* fee token, and, from T14, one cold access (2,600 gas) of the fee payer's account. Earlier forks refund the unused gas.
|
|
534
|
+
*/
|
|
537
535
|
const feePayerGas = 5_000n
|
|
@@ -19,6 +19,7 @@ import { getBlockNumber } from '../../../actions/public/getBlockNumber.js'
|
|
|
19
19
|
import { readContract } from '../../../actions/public/readContract.js'
|
|
20
20
|
import { type Client, createClient } from '../../../clients/createClient.js'
|
|
21
21
|
import { http } from '../../../clients/transports/http.js'
|
|
22
|
+
import { maxUint256 } from '../../../constants/number.js'
|
|
22
23
|
import * as AccessKey from '../../actions/accessKey.js'
|
|
23
24
|
import type * as Relay from '../../Relay.js'
|
|
24
25
|
import * as Transaction from '../../Transaction.js'
|
|
@@ -180,7 +181,10 @@ export function create(options: Relay.feePayer.Options): Relay.Plugin {
|
|
|
180
181
|
// Bound before validation so the validated envelope is the one signed, and returned signatures expire.
|
|
181
182
|
const signs = !!options.account && !external && !defer
|
|
182
183
|
if (signs && filled.validBefore == null)
|
|
183
|
-
filled.validBefore = Validity.generate({
|
|
184
|
+
filled.validBefore = Validity.generate({
|
|
185
|
+
nonceKey: filled.nonceKey,
|
|
186
|
+
validity,
|
|
187
|
+
})
|
|
184
188
|
|
|
185
189
|
const sponsored =
|
|
186
190
|
external ||
|
|
@@ -835,27 +839,37 @@ const defaultValidity = 3_600
|
|
|
835
839
|
/** Granularity, in seconds, of a generated `validBefore`, so identical fill retries share one sign payload. */
|
|
836
840
|
const validityStep = 300
|
|
837
841
|
|
|
842
|
+
/** Headroom, in seconds, that generated expiring windows leave under the protocol limit. */
|
|
843
|
+
const skew = 30
|
|
844
|
+
|
|
838
845
|
/** Bounds on how long a returned fee-payer signature stays valid on chain. */
|
|
839
846
|
namespace Validity {
|
|
840
|
-
/** Returns a `validBefore` rounded down to the generation step, then extended by
|
|
847
|
+
/** Returns a `validBefore` rounded down to the generation step, then extended by the window's limit. */
|
|
841
848
|
export function generate(options: generate.Options) {
|
|
842
|
-
|
|
843
|
-
const
|
|
849
|
+
// Generated expiring windows stay under the protocol limit to allow for clock skew against the node.
|
|
850
|
+
const max =
|
|
851
|
+
options.nonceKey === maxUint256
|
|
852
|
+
? Math.min(limit(options), Transaction.expiringNonceMaxExpiry - skew)
|
|
853
|
+
: limit(options)
|
|
854
|
+
// A step of at most a tenth of the limit keeps every generated window at least 90% of it.
|
|
855
|
+
const step = Math.min(validityStep, Math.ceil(max / 10))
|
|
844
856
|
const time = Math.floor(Date.now() / 1_000)
|
|
845
|
-
return time - (time % step) +
|
|
857
|
+
return time - (time % step) + max
|
|
846
858
|
}
|
|
847
859
|
|
|
848
860
|
export declare namespace generate {
|
|
849
861
|
type Options = {
|
|
862
|
+
/** Nonce lane of the transaction. An expiring nonce lane caps the window at the protocol limit. */
|
|
863
|
+
nonceKey?: bigint | undefined
|
|
850
864
|
/** Longest validity window, in seconds. */
|
|
851
865
|
validity: number
|
|
852
866
|
}
|
|
853
867
|
}
|
|
854
868
|
|
|
855
|
-
/** Throws unless `validBefore` is a future time within
|
|
869
|
+
/** Throws unless `validBefore` is a future time within the window's limit that opens after `validAfter`. */
|
|
856
870
|
export function assert(window: assert.Window, options: assert.Options) {
|
|
857
871
|
const { validAfter, validBefore } = window
|
|
858
|
-
const {
|
|
872
|
+
const validity = limit({ nonceKey: window.nonceKey, ...options })
|
|
859
873
|
const time = Math.floor(Date.now() / 1_000)
|
|
860
874
|
if (
|
|
861
875
|
validBefore === undefined ||
|
|
@@ -875,6 +889,8 @@ namespace Validity {
|
|
|
875
889
|
export declare namespace assert {
|
|
876
890
|
/** Validity window of the transaction being co-signed, in unix seconds. */
|
|
877
891
|
type Window = {
|
|
892
|
+
/** Nonce lane. An expiring nonce lane caps the window at the protocol limit. */
|
|
893
|
+
nonceKey?: bigint | undefined
|
|
878
894
|
/** Earliest inclusion time. */
|
|
879
895
|
validAfter?: number | null | undefined
|
|
880
896
|
/** Latest inclusion time. */
|
|
@@ -886,6 +902,13 @@ namespace Validity {
|
|
|
886
902
|
validity: number
|
|
887
903
|
}
|
|
888
904
|
}
|
|
905
|
+
|
|
906
|
+
/** Returns `validity`, capped at the protocol limit for expiring nonce lanes. */
|
|
907
|
+
function limit(options: generate.Options) {
|
|
908
|
+
const { nonceKey, validity } = options
|
|
909
|
+
if (nonceKey !== maxUint256) return validity
|
|
910
|
+
return Math.min(validity, Transaction.expiringNonceMaxExpiry)
|
|
911
|
+
}
|
|
889
912
|
}
|
|
890
913
|
|
|
891
914
|
/** Facts of one sponsorship commitment, emitted at fee-payer signing time. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Abi, AbiParameter } from 'abitype'
|
|
1
|
+
import type { Abi, AbiEvent, AbiParameter } from 'abitype'
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
AbiDecodingDataSizeTooSmallError,
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
DecodeLogTopicsMismatch,
|
|
13
13
|
type DecodeLogTopicsMismatchErrorType,
|
|
14
14
|
} from '../../errors/abi.js'
|
|
15
|
+
import { BaseError } from '../../errors/base.js'
|
|
15
16
|
import { PositionOutOfBoundsError } from '../../errors/cursor.js'
|
|
16
17
|
import type { ErrorType } from '../../errors/utils.js'
|
|
17
18
|
import type {
|
|
@@ -84,6 +85,7 @@ export type DecodeEventLogReturnType<
|
|
|
84
85
|
|
|
85
86
|
export type DecodeEventLogErrorType =
|
|
86
87
|
| AbiDecodingDataSizeTooSmallErrorType
|
|
88
|
+
| AbiEventAmbiguityErrorType
|
|
87
89
|
| AbiEventSignatureEmptyTopicsErrorType
|
|
88
90
|
| AbiEventSignatureNotFoundErrorType
|
|
89
91
|
| DecodeAbiParametersErrorType
|
|
@@ -107,23 +109,81 @@ export function decodeEventLog<
|
|
|
107
109
|
const {
|
|
108
110
|
abi,
|
|
109
111
|
data,
|
|
112
|
+
eventName,
|
|
110
113
|
strict: strict_,
|
|
111
114
|
topics,
|
|
112
115
|
} = parameters as DecodeEventLogParameters
|
|
113
116
|
|
|
114
117
|
const strict = strict_ ?? true
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const abiItem = abi.find(
|
|
119
|
-
(x) =>
|
|
120
|
-
x.type === 'event' &&
|
|
121
|
-
signature === toEventSelector(formatAbiItem(x) as EventDefinition),
|
|
118
|
+
const events = abi.filter(
|
|
119
|
+
(item): item is AbiEvent => item.type === 'event' && 'name' in item,
|
|
122
120
|
)
|
|
121
|
+
// Anonymous events omit the signature topic, so `topics[0]` is an indexed
|
|
122
|
+
// argument. A signature match still wins when the log has one.
|
|
123
|
+
const signature = topics[0]
|
|
124
|
+
const bySelector = signature
|
|
125
|
+
? events.find(
|
|
126
|
+
(item) =>
|
|
127
|
+
!item.anonymous &&
|
|
128
|
+
signature === toEventSelector(formatAbiItem(item) as EventDefinition),
|
|
129
|
+
)
|
|
130
|
+
: undefined
|
|
131
|
+
const candidates = bySelector
|
|
132
|
+
? [bySelector]
|
|
133
|
+
: anonymousCandidates(events, topics.length, eventName)
|
|
123
134
|
|
|
124
|
-
if (
|
|
135
|
+
if (candidates.length > 1)
|
|
136
|
+
throw new AbiEventAmbiguityError(candidates.map((item) => item.name))
|
|
137
|
+
const abiItem = candidates[0]
|
|
138
|
+
if (!abiItem) {
|
|
139
|
+
if (!signature) throw new AbiEventSignatureEmptyTopicsError({ docsPath })
|
|
125
140
|
throw new AbiEventSignatureNotFoundError(signature, { docsPath })
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
return decodeMatchedEventLog({
|
|
144
|
+
abiItem,
|
|
145
|
+
argTopics: abiItem.anonymous ? topics : topics.slice(1),
|
|
146
|
+
data,
|
|
147
|
+
strict,
|
|
148
|
+
}) as DecodeEventLogReturnType<abi, eventName, topics, data, strict>
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function anonymousCandidates(
|
|
152
|
+
events: readonly AbiEvent[],
|
|
153
|
+
topicCount: number,
|
|
154
|
+
eventName: string | undefined,
|
|
155
|
+
) {
|
|
156
|
+
// Nothing in a log identifies an anonymous event, so any log with the same
|
|
157
|
+
// topic count fits it. Anonymous events are only considered when requested:
|
|
158
|
+
// `eventName` names one, or every event in the ABI is anonymous. Otherwise a
|
|
159
|
+
// log from another contract is decoded as the anonymous event.
|
|
160
|
+
const requested = (() => {
|
|
161
|
+
if (eventName) return events.filter((item) => item.name === eventName)
|
|
162
|
+
if (events.every((item) => item.anonymous)) return events
|
|
163
|
+
return []
|
|
164
|
+
})()
|
|
165
|
+
// `eventName` does not skip the arity check, or a same-name overload with
|
|
166
|
+
// extra topics is guessed.
|
|
167
|
+
return requested.filter(
|
|
168
|
+
(item) => item.anonymous && indexedCount(item) === topicCount,
|
|
169
|
+
)
|
|
170
|
+
}
|
|
126
171
|
|
|
172
|
+
function indexedCount(item: AbiEvent) {
|
|
173
|
+
return item.inputs?.filter((input) => input.indexed).length ?? 0
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function decodeMatchedEventLog({
|
|
177
|
+
abiItem,
|
|
178
|
+
argTopics,
|
|
179
|
+
data,
|
|
180
|
+
strict,
|
|
181
|
+
}: {
|
|
182
|
+
abiItem: AbiEvent
|
|
183
|
+
argTopics: readonly Hex[]
|
|
184
|
+
data: Hex | undefined
|
|
185
|
+
strict: boolean
|
|
186
|
+
}): DecodeEventLogReturnType {
|
|
127
187
|
const { name, inputs } = abiItem
|
|
128
188
|
const isUnnamed = inputs?.some((x) => !('name' in x && x.name))
|
|
129
189
|
|
|
@@ -216,7 +276,7 @@ export function decodeEventLog<
|
|
|
216
276
|
return {
|
|
217
277
|
eventName: name,
|
|
218
278
|
args: Object.values(args).length > 0 ? args : undefined,
|
|
219
|
-
} as
|
|
279
|
+
} as DecodeEventLogReturnType
|
|
220
280
|
}
|
|
221
281
|
|
|
222
282
|
function decodeTopic({ param, value }: { param: AbiParameter; value: Hex }) {
|
|
@@ -230,3 +290,30 @@ function decodeTopic({ param, value }: { param: AbiParameter; value: Hex }) {
|
|
|
230
290
|
const decodedArg = decodeAbiParameters([param], value) || []
|
|
231
291
|
return decodedArg[0]
|
|
232
292
|
}
|
|
293
|
+
|
|
294
|
+
/** Error type thrown when an anonymous event log matches more than one event. */
|
|
295
|
+
export type AbiEventAmbiguityErrorType = AbiEventAmbiguityError & {
|
|
296
|
+
name: 'AbiEventAmbiguityError'
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Thrown by {@link decodeEventLog} when an anonymous event log fits more than
|
|
300
|
+
* one requested anonymous event with the same number of indexed inputs.
|
|
301
|
+
*/
|
|
302
|
+
export class AbiEventAmbiguityError extends BaseError {
|
|
303
|
+
constructor(eventNames: readonly string[]) {
|
|
304
|
+
// `eventName` cannot choose between overloads that share a name, so those
|
|
305
|
+
// need an ABI narrowed to one event.
|
|
306
|
+
const distinct = new Set(eventNames).size === eventNames.length
|
|
307
|
+
super('Ambiguous anonymous event log.', {
|
|
308
|
+
docsPath,
|
|
309
|
+
metaMessages: [
|
|
310
|
+
`Matched ${eventNames.map((name) => `\`${name}\``).join(', ')}.`,
|
|
311
|
+
'These events take the same number of indexed topics.',
|
|
312
|
+
distinct
|
|
313
|
+
? 'Pass `eventName` to choose one.'
|
|
314
|
+
: 'Pass an `abi` that holds only the event to decode.',
|
|
315
|
+
],
|
|
316
|
+
name: 'AbiEventAmbiguityError',
|
|
317
|
+
})
|
|
318
|
+
}
|
|
319
|
+
}
|