viem 2.57.13 → 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 +60 -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/Formatters.js +4 -1
- package/_cjs/tempo/Formatters.js.map +1 -1
- package/_cjs/tempo/Relay.js +5 -0
- package/_cjs/tempo/Relay.js.map +1 -1
- package/_cjs/tempo/Transaction.js +2 -1
- package/_cjs/tempo/Transaction.js.map +1 -1
- package/_cjs/tempo/chainConfig.js +10 -13
- package/_cjs/tempo/chainConfig.js.map +1 -1
- package/_cjs/tempo/internal/relay/autoSwap.js +200 -0
- package/_cjs/tempo/internal/relay/autoSwap.js.map +1 -0
- package/_cjs/tempo/internal/relay/error.js +5 -1
- package/_cjs/tempo/internal/relay/error.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/tempo/internal/relay/feeToken.js +14 -1
- package/_cjs/tempo/internal/relay/feeToken.js.map +1 -1
- package/_cjs/tempo/internal/relay/simulate.js +57 -15
- package/_cjs/tempo/internal/relay/simulate.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/Formatters.js +5 -2
- package/_esm/tempo/Formatters.js.map +1 -1
- package/_esm/tempo/Relay.js +20 -0
- package/_esm/tempo/Relay.js.map +1 -1
- package/_esm/tempo/Transaction.js +2 -0
- package/_esm/tempo/Transaction.js.map +1 -1
- package/_esm/tempo/chainConfig.js +20 -14
- package/_esm/tempo/chainConfig.js.map +1 -1
- package/_esm/tempo/internal/relay/autoSwap.js +218 -0
- package/_esm/tempo/internal/relay/autoSwap.js.map +1 -0
- package/_esm/tempo/internal/relay/error.js +6 -2
- package/_esm/tempo/internal/relay/error.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/tempo/internal/relay/feeToken.js +17 -3
- package/_esm/tempo/internal/relay/feeToken.js.map +1 -1
- package/_esm/tempo/internal/relay/simulate.js +68 -17
- package/_esm/tempo/internal/relay/simulate.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 +78 -5
- package/_types/tempo/Account.d.ts.map +1 -1
- package/_types/tempo/Capabilities.d.ts +32 -2
- package/_types/tempo/Capabilities.d.ts.map +1 -1
- package/_types/tempo/Relay.d.ts +27 -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/actions/accessKey.d.ts +2 -2
- package/_types/tempo/chainConfig.d.ts.map +1 -1
- package/_types/tempo/internal/relay/autoSwap.d.ts +3 -0
- package/_types/tempo/internal/relay/autoSwap.d.ts.map +1 -0
- package/_types/tempo/internal/relay/error.d.ts.map +1 -1
- package/_types/tempo/internal/relay/feePayer.d.ts.map +1 -1
- package/_types/tempo/internal/relay/feeToken.d.ts.map +1 -1
- package/_types/tempo/internal/relay/simulate.d.ts +4 -0
- package/_types/tempo/internal/relay/simulate.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 +203 -17
- package/tempo/Capabilities.ts +34 -2
- package/tempo/Formatters.ts +5 -5
- package/tempo/Relay.ts +32 -1
- package/tempo/Transaction.ts +3 -0
- package/tempo/actions/accessKey.ts +2 -2
- package/tempo/chainConfig.ts +22 -14
- package/tempo/internal/relay/autoSwap.ts +263 -0
- package/tempo/internal/relay/error.ts +7 -2
- package/tempo/internal/relay/feePayer.ts +30 -7
- package/tempo/internal/relay/feeToken.ts +21 -3
- package/tempo/internal/relay/simulate.ts +106 -19
- 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> =
|
|
@@ -910,7 +1011,7 @@ export declare namespace signKeyAuthorization {
|
|
|
910
1011
|
/**
|
|
911
1012
|
* Whether to authorize the key as an admin key. Admin keys are
|
|
912
1013
|
* unrestricted and can manage the account's other access keys; `expiry`,
|
|
913
|
-
* `limits`, and `scopes` are ignored. Requires the T6 hardfork.
|
|
1014
|
+
* `limits`, and `scopes` are ignored. Requires the T6 hardfork; T14 (TIP-1137) removes admin key creation.
|
|
914
1015
|
*
|
|
915
1016
|
* [TIP-1049](https://tips.sh/1049)
|
|
916
1017
|
*/
|
|
@@ -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/Capabilities.ts
CHANGED
|
@@ -16,13 +16,23 @@ export type Schema = Omit<DefaultCapabilitiesSchema, 'sendCalls'> & {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
export type FillTransactionRequestCapabilities = {
|
|
19
|
-
/**
|
|
19
|
+
/** Opts into a `Relay.autoSwap` buy of a missing token. A `slippage` can only tighten the relay's bound. */
|
|
20
|
+
autoSwap?:
|
|
21
|
+
| boolean
|
|
22
|
+
| {
|
|
23
|
+
/** Largest accepted price slippage, between 0 and 1. */
|
|
24
|
+
slippage?: number | undefined
|
|
25
|
+
}
|
|
26
|
+
| undefined
|
|
27
|
+
/** Opts into `balanceDiffs` in the response. */
|
|
20
28
|
balanceDiffs?: boolean | undefined
|
|
21
29
|
/** Whether execution reverts return error capabilities instead of throwing. */
|
|
22
30
|
errors?: boolean | undefined
|
|
23
31
|
}
|
|
24
32
|
|
|
25
33
|
export type FillTransactionCapabilities = {
|
|
34
|
+
/** Stablecoin DEX buy prepended by `Relay.autoSwap` to cover a missing token. */
|
|
35
|
+
autoSwap?: AutoSwap | undefined
|
|
26
36
|
balanceDiffs?: Readonly<Record<Address, readonly BalanceDiff[]>> | undefined
|
|
27
37
|
error?: ExecutionError.Rpc | undefined
|
|
28
38
|
fee?:
|
|
@@ -54,7 +64,29 @@ export type FillTransactionCapabilities = {
|
|
|
54
64
|
virtualAddresses?: Readonly<Record<Address, Address | null>> | undefined
|
|
55
65
|
}
|
|
56
66
|
|
|
57
|
-
/** A
|
|
67
|
+
/** A swap that buys a fill's missing token before its calls. */
|
|
68
|
+
export type AutoSwap = {
|
|
69
|
+
/** Swap calls prepended to the transaction. */
|
|
70
|
+
calls: readonly { data: Hex; to: Address }[]
|
|
71
|
+
/** Largest amount of the input token the swap may spend. */
|
|
72
|
+
maxIn: AutoSwapAmount
|
|
73
|
+
/** Amount of the missing token the swap buys. */
|
|
74
|
+
minOut: AutoSwapAmount
|
|
75
|
+
/** Largest accepted price slippage over the missing amount. */
|
|
76
|
+
slippage: number
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** One side of an {@link AutoSwap}. */
|
|
80
|
+
export type AutoSwapAmount = {
|
|
81
|
+
decimals: number
|
|
82
|
+
formatted: string
|
|
83
|
+
name: string
|
|
84
|
+
symbol: string
|
|
85
|
+
token: Address
|
|
86
|
+
value: Hex
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** A token balance preview. A token's incoming and outgoing movements use separate entries; outgoing includes remaining approval exposure. */
|
|
58
90
|
export type BalanceDiff = {
|
|
59
91
|
address: Address
|
|
60
92
|
decimals: number
|
package/tempo/Formatters.ts
CHANGED
|
@@ -127,12 +127,12 @@ export function formatTransactionRequest(
|
|
|
127
127
|
'A local owner account is required to approve a configurable account transaction.',
|
|
128
128
|
)
|
|
129
129
|
|
|
130
|
-
// If the request is not a Tempo transaction, route to Viem formatter.
|
|
130
|
+
// If the request is not a Tempo transaction, route to Viem formatter, keeping relay capabilities.
|
|
131
131
|
if (!isTempo(request))
|
|
132
|
-
return
|
|
133
|
-
r as never,
|
|
134
|
-
|
|
135
|
-
|
|
132
|
+
return {
|
|
133
|
+
...viem_formatTransactionRequest(r as never, action),
|
|
134
|
+
...(request.capabilities ? { capabilities: request.capabilities } : {}),
|
|
135
|
+
} as TransactionRequestRpc
|
|
136
136
|
|
|
137
137
|
if (action)
|
|
138
138
|
request.calls = request.calls ?? [
|
package/tempo/Relay.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { ChainNotConfiguredError } from '../clients/createClientResolver.js'
|
|
|
8
8
|
import type { EIP1193RequestOptions } from '../types/eip1193.js'
|
|
9
9
|
import type { MaybePromise } from '../types/utils.js'
|
|
10
10
|
import * as Accounts from './internal/relay/accounts.js'
|
|
11
|
+
import * as AutoSwap from './internal/relay/autoSwap.js'
|
|
11
12
|
import * as Sponsorship from './internal/relay/feePayer.js'
|
|
12
13
|
import * as FeeToken from './internal/relay/feeToken.js'
|
|
13
14
|
import * as KeyAuthorization from './internal/relay/keyAuthorization.js'
|
|
@@ -375,6 +376,36 @@ export declare namespace accounts {
|
|
|
375
376
|
export type ReturnType = Plugin & { readonly [accountsBrand]: true }
|
|
376
377
|
}
|
|
377
378
|
|
|
379
|
+
/**
|
|
380
|
+
* Recovers fills that revert with `InsufficientBalance` by buying the missing
|
|
381
|
+
* amount on the stablecoin DEX from a funded token. The swap call is
|
|
382
|
+
* prepended to the transaction and reported as `capabilities.autoSwap`.
|
|
383
|
+
*
|
|
384
|
+
* Place this plugin last, after `Relay.simulate()`, so it sees node reverts
|
|
385
|
+
* before they become error capabilities.
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```ts
|
|
389
|
+
* import { Relay } from 'viem/tempo'
|
|
390
|
+
* const plugins = [Relay.feeToken(), Relay.simulate(), Relay.autoSwap()]
|
|
391
|
+
* ```
|
|
392
|
+
* @param options - Slippage tolerance and metadata store.
|
|
393
|
+
* @returns An auto-swap relay plugin.
|
|
394
|
+
*/
|
|
395
|
+
export function autoSwap(options: autoSwap.Options = {}): Plugin {
|
|
396
|
+
return AutoSwap.create(options)
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export declare namespace autoSwap {
|
|
400
|
+
/** Auto-swap configuration. */
|
|
401
|
+
export type Options = {
|
|
402
|
+
/** Largest accepted price slippage over the missing amount, between 0 and 1. @default 0.05 */
|
|
403
|
+
slippage?: number | undefined
|
|
404
|
+
/** Store for cached token metadata. Omit to read metadata for each request. */
|
|
405
|
+
store?: Store.Store | undefined
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
378
409
|
/**
|
|
379
410
|
* Sponsors transactions with a local account or an external fee-payer relay.
|
|
380
411
|
*
|
|
@@ -419,7 +450,7 @@ export declare namespace feePayer {
|
|
|
419
450
|
url?: string | undefined
|
|
420
451
|
/** Only `true` authorizes sponsorship. Rejected fills fall back to sender-paid transactions. */
|
|
421
452
|
validate?: Sponsorship.Validate | undefined
|
|
422
|
-
/** 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 */
|
|
423
454
|
validity?: number | undefined
|
|
424
455
|
}
|
|
425
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'] {
|
|
@@ -134,7 +134,7 @@ export namespace authorize {
|
|
|
134
134
|
/**
|
|
135
135
|
* Whether to authorize the key as an admin key. Admin keys are unrestricted
|
|
136
136
|
* and can manage the account's other access keys; `expiry`, `limits`, and
|
|
137
|
-
* `scopes` are ignored. Requires the T6 hardfork.
|
|
137
|
+
* `scopes` are ignored. Requires the T6 hardfork; T14 (TIP-1137) removes admin key creation.
|
|
138
138
|
*
|
|
139
139
|
* [TIP-1049](https://tips.sh/1049)
|
|
140
140
|
*/
|
|
@@ -1135,7 +1135,7 @@ export namespace prepareAuthorization {
|
|
|
1135
1135
|
/**
|
|
1136
1136
|
* Whether to authorize the key as an admin key. Admin keys are unrestricted
|
|
1137
1137
|
* and can manage the account's other access keys; `expiry`, `limits`, and
|
|
1138
|
-
* `scopes` are ignored. Requires the T6 hardfork.
|
|
1138
|
+
* `scopes` are ignored. Requires the T6 hardfork; T14 (TIP-1137) removes admin key creation.
|
|
1139
1139
|
*
|
|
1140
1140
|
* [TIP-1049](https://tips.sh/1049)
|
|
1141
1141
|
*/
|
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) =>
|
|
@@ -155,11 +156,19 @@ export const chainConfig = {
|
|
|
155
156
|
// Actual tx has larger keychain/webAuthn sigs + real fee payer sig, costing more intrinsic gas.
|
|
156
157
|
if (phase === 'afterFillParameters') {
|
|
157
158
|
// Fee payer signature covers the gas limit, so the relay must set it before signing and Viem must not change it afterward.
|
|
159
|
+
// Owner approvals also cover it, so a request carrying them keeps its gas.
|
|
160
|
+
const approved =
|
|
161
|
+
Array.isArray((request as { signatures?: unknown }).signatures) &&
|
|
162
|
+
(request as { signatures: readonly unknown[] }).signatures.length > 0
|
|
158
163
|
if (
|
|
159
164
|
typeof request.gas !== 'undefined' &&
|
|
160
165
|
request.feePayer &&
|
|
161
|
-
!request.feePayerSignature
|
|
166
|
+
!request.feePayerSignature &&
|
|
167
|
+
!approved
|
|
162
168
|
) {
|
|
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.
|
|
171
|
+
request.gas = (request.gas ?? 0n) + feePayerGas
|
|
163
172
|
if (request.keyAuthorization?.signature.type === 'webAuthn')
|
|
164
173
|
request.gas = (request.gas ?? 0n) + 20_000n
|
|
165
174
|
else if (request.account?.source === 'accessKey')
|
|
@@ -252,11 +261,12 @@ export const chainConfig = {
|
|
|
252
261
|
request.nonce = 0
|
|
253
262
|
} else if (useExpiringNonce) {
|
|
254
263
|
request.nonceKey = maxUint256
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
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))
|
|
258
267
|
if (typeof request.validBefore === 'undefined')
|
|
259
|
-
request.validBefore =
|
|
268
|
+
request.validBefore =
|
|
269
|
+
Math.floor(Date.now() / 1000) + expiringNonceExpiry
|
|
260
270
|
} else if (
|
|
261
271
|
typeof request.nonceKey !== 'undefined' &&
|
|
262
272
|
// Nonce key 0 is the protocol nonce, so core fills it like an Ethereum nonce.
|
|
@@ -499,14 +509,6 @@ function getSimulationKey(
|
|
|
499
509
|
return { keyData: '0x0578' as const, keyType: 'webAuthn' as const }
|
|
500
510
|
}
|
|
501
511
|
|
|
502
|
-
/** Returns random past seconds to distinguish otherwise-identical expiring transactions. */
|
|
503
|
-
function randomValidAfter(): number {
|
|
504
|
-
const now = BigInt(Math.floor(Date.now() / 1_000))
|
|
505
|
-
const latest = now - 60n
|
|
506
|
-
if (latest <= 0n) return 0
|
|
507
|
-
return Number(BigInt(Hex.random(8)) % latest)
|
|
508
|
-
}
|
|
509
|
-
|
|
510
512
|
/** Selects a deterministic minimum-cardinality owner quorum. */
|
|
511
513
|
function selectOwners(config: AccountConfig.Config) {
|
|
512
514
|
const owners = [...config.owners].sort(
|
|
@@ -525,3 +527,9 @@ function selectOwners(config: AccountConfig.Config) {
|
|
|
525
527
|
a.owner.toLowerCase().localeCompare(b.owner.toLowerCase()),
|
|
526
528
|
)
|
|
527
529
|
}
|
|
530
|
+
|
|
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
|
+
*/
|
|
535
|
+
const feePayerGas = 5_000n
|