ox 1.8.15 → 1.8.18
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 +108 -0
- package/dist/core/AbiError.d.ts +52 -6
- package/dist/core/AbiError.d.ts.map +1 -1
- package/dist/core/AbiError.js +60 -4
- package/dist/core/AbiError.js.map +1 -1
- package/dist/core/AbiEvent.d.ts +5 -3
- package/dist/core/AbiEvent.d.ts.map +1 -1
- package/dist/core/AbiEvent.js +89 -58
- package/dist/core/AbiEvent.js.map +1 -1
- package/dist/core/AbiFunction.d.ts +48 -2
- package/dist/core/AbiFunction.d.ts.map +1 -1
- package/dist/core/AbiFunction.js +59 -3
- package/dist/core/AbiFunction.js.map +1 -1
- package/dist/core/AbiItem.d.ts.map +1 -1
- package/dist/core/AbiItem.js +15 -5
- package/dist/core/AbiItem.js.map +1 -1
- package/dist/core/AbiParameters.d.ts +1 -1
- package/dist/core/AbiParameters.d.ts.map +1 -1
- package/dist/core/AbiParameters.js +8 -2
- package/dist/core/AbiParameters.js.map +1 -1
- package/dist/core/Address.d.ts +17 -2
- package/dist/core/Address.d.ts.map +1 -1
- package/dist/core/Address.js +17 -1
- package/dist/core/Address.js.map +1 -1
- package/dist/core/Authorization.d.ts +24 -2
- package/dist/core/Authorization.d.ts.map +1 -1
- package/dist/core/Authorization.js +29 -2
- package/dist/core/Authorization.js.map +1 -1
- package/dist/core/Base58.d.ts.map +1 -1
- package/dist/core/Base58.js +16 -4
- package/dist/core/Base58.js.map +1 -1
- package/dist/core/Blobs.d.ts +2 -3
- package/dist/core/Blobs.d.ts.map +1 -1
- package/dist/core/Blobs.js +38 -43
- package/dist/core/Blobs.js.map +1 -1
- package/dist/core/Bytes.d.ts.map +1 -1
- package/dist/core/Bytes.js +10 -2
- package/dist/core/Bytes.js.map +1 -1
- package/dist/core/Cbor.d.ts +13 -6
- package/dist/core/Cbor.d.ts.map +1 -1
- package/dist/core/Cbor.js +31 -18
- package/dist/core/Cbor.js.map +1 -1
- package/dist/core/Ens.js +2 -2
- package/dist/core/Ens.js.map +1 -1
- package/dist/core/FrameReceipt.d.ts.map +1 -1
- package/dist/core/FrameReceipt.js +4 -1
- package/dist/core/FrameReceipt.js.map +1 -1
- package/dist/core/Hex.d.ts.map +1 -1
- package/dist/core/Hex.js +34 -31
- package/dist/core/Hex.js.map +1 -1
- package/dist/core/Keystore.d.ts +31 -2
- package/dist/core/Keystore.d.ts.map +1 -1
- package/dist/core/Keystore.js +28 -2
- package/dist/core/Keystore.js.map +1 -1
- package/dist/core/Rlp.d.ts +1 -1
- package/dist/core/Rlp.d.ts.map +1 -1
- package/dist/core/Rlp.js +107 -0
- package/dist/core/Rlp.js.map +1 -1
- package/dist/core/RpcTransport.d.ts.map +1 -1
- package/dist/core/RpcTransport.js +3 -1
- package/dist/core/RpcTransport.js.map +1 -1
- package/dist/core/Secp256k1.d.ts.map +1 -1
- package/dist/core/Secp256k1.js +4 -1
- package/dist/core/Secp256k1.js.map +1 -1
- package/dist/core/Signature.d.ts +1 -1
- package/dist/core/Signature.d.ts.map +1 -1
- package/dist/core/Signature.js +4 -2
- package/dist/core/Signature.js.map +1 -1
- package/dist/core/Siwe.d.ts +4 -0
- package/dist/core/Siwe.d.ts.map +1 -1
- package/dist/core/Siwe.js +29 -3
- package/dist/core/Siwe.js.map +1 -1
- package/dist/core/Transaction.d.ts.map +1 -1
- package/dist/core/Transaction.js +4 -2
- package/dist/core/Transaction.js.map +1 -1
- package/dist/core/TransactionReceipt.d.ts.map +1 -1
- package/dist/core/TransactionReceipt.js +8 -2
- package/dist/core/TransactionReceipt.js.map +1 -1
- package/dist/core/TxEnvelopeEip1559.d.ts.map +1 -1
- package/dist/core/TxEnvelopeEip1559.js +2 -1
- package/dist/core/TxEnvelopeEip1559.js.map +1 -1
- package/dist/core/TxEnvelopeEip2930.d.ts.map +1 -1
- package/dist/core/TxEnvelopeEip2930.js +2 -1
- package/dist/core/TxEnvelopeEip2930.js.map +1 -1
- package/dist/core/TxEnvelopeEip7702.d.ts +1 -1
- package/dist/core/TxEnvelopeEip7702.d.ts.map +1 -1
- package/dist/core/TxEnvelopeEip7702.js +6 -1
- package/dist/core/TxEnvelopeEip7702.js.map +1 -1
- package/dist/core/TxEnvelopeLegacy.d.ts.map +1 -1
- package/dist/core/TxEnvelopeLegacy.js +49 -7
- package/dist/core/TxEnvelopeLegacy.js.map +1 -1
- package/dist/core/TypedData.d.ts +3 -1
- package/dist/core/TypedData.d.ts.map +1 -1
- package/dist/core/TypedData.js +23 -11
- package/dist/core/TypedData.js.map +1 -1
- package/dist/core/Value.d.ts.map +1 -1
- package/dist/core/Value.js +14 -3
- package/dist/core/Value.js.map +1 -1
- package/dist/core/internal/abiParameters.d.ts +3 -3
- package/dist/core/internal/abiParameters.d.ts.map +1 -1
- package/dist/core/internal/abiParameters.js +99 -69
- package/dist/core/internal/abiParameters.js.map +1 -1
- package/dist/core/internal/base58.d.ts.map +1 -1
- package/dist/core/internal/base58.js +9 -3
- package/dist/core/internal/base58.js.map +1 -1
- package/dist/core/internal/caches.d.ts +6 -0
- package/dist/core/internal/caches.d.ts.map +1 -1
- package/dist/core/internal/caches.js +3 -1
- package/dist/core/internal/caches.js.map +1 -1
- package/dist/core/internal/codec/hex.d.ts +13 -0
- package/dist/core/internal/codec/hex.d.ts.map +1 -1
- package/dist/core/internal/codec/hex.js +25 -2
- package/dist/core/internal/codec/hex.js.map +1 -1
- package/dist/core/internal/codec/int.d.ts.map +1 -1
- package/dist/core/internal/codec/int.js +48 -32
- package/dist/core/internal/codec/int.js.map +1 -1
- package/dist/core/internal/cursor.d.ts +24 -4
- package/dist/core/internal/cursor.d.ts.map +1 -1
- package/dist/core/internal/cursor.js +62 -11
- package/dist/core/internal/cursor.js.map +1 -1
- package/dist/core/internal/lru.d.ts +11 -12
- package/dist/core/internal/lru.d.ts.map +1 -1
- package/dist/core/internal/lru.js +22 -32
- package/dist/core/internal/lru.js.map +1 -1
- package/dist/core/internal/promise.d.ts.map +1 -1
- package/dist/core/internal/promise.js +13 -7
- package/dist/core/internal/promise.js.map +1 -1
- package/dist/erc4337/UserOperation.d.ts.map +1 -1
- package/dist/erc4337/UserOperation.js +1 -3
- package/dist/erc4337/UserOperation.js.map +1 -1
- package/dist/erc6492/SignatureErc6492.d.ts +1 -1
- package/dist/erc6492/SignatureErc6492.d.ts.map +1 -1
- package/dist/erc6492/SignatureErc6492.js +1 -1
- package/dist/erc6492/SignatureErc6492.js.map +1 -1
- package/dist/erc7821/Execute.d.ts +45 -0
- package/dist/erc7821/Execute.d.ts.map +1 -1
- package/dist/erc7821/Execute.js +70 -2
- package/dist/erc7821/Execute.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/tempo/KeyAuthorization.d.ts +9 -3
- package/dist/tempo/KeyAuthorization.d.ts.map +1 -1
- package/dist/tempo/KeyAuthorization.js +16 -0
- package/dist/tempo/KeyAuthorization.js.map +1 -1
- package/dist/tempo/SignatureEnvelope.d.ts +1 -1
- package/dist/tempo/SignatureEnvelope.d.ts.map +1 -1
- package/dist/tempo/SignatureEnvelope.js +53 -54
- package/dist/tempo/SignatureEnvelope.js.map +1 -1
- package/dist/tempo/TransactionReceipt.d.ts.map +1 -1
- package/dist/tempo/TransactionReceipt.js +4 -1
- package/dist/tempo/TransactionReceipt.js.map +1 -1
- package/dist/tempo/TransactionRequest.d.ts +1 -1
- package/dist/tempo/TransactionRequest.d.ts.map +1 -1
- package/dist/tempo/TransactionRequest.js +5 -2
- package/dist/tempo/TransactionRequest.js.map +1 -1
- package/dist/tempo/TxEnvelopeTempo.d.ts +30 -1
- package/dist/tempo/TxEnvelopeTempo.d.ts.map +1 -1
- package/dist/tempo/TxEnvelopeTempo.js +51 -2
- package/dist/tempo/TxEnvelopeTempo.js.map +1 -1
- package/dist/tempo/ZoneId.d.ts +3 -1
- package/dist/tempo/ZoneId.d.ts.map +1 -1
- package/dist/tempo/ZoneId.js +7 -1
- package/dist/tempo/ZoneId.js.map +1 -1
- package/dist/tempo/internal/virtualMasterPool.d.ts.map +1 -1
- package/dist/tempo/internal/virtualMasterPool.js +17 -6
- package/dist/tempo/internal/virtualMasterPool.js.map +1 -1
- package/dist/tempo/internal/webauthnData.d.ts +23 -0
- package/dist/tempo/internal/webauthnData.d.ts.map +1 -0
- package/dist/tempo/internal/webauthnData.js +75 -0
- package/dist/tempo/internal/webauthnData.js.map +1 -0
- package/dist/webauthn/Registration.d.ts +2 -0
- package/dist/webauthn/Registration.d.ts.map +1 -1
- package/dist/webauthn/Registration.js +2 -6
- package/dist/webauthn/Registration.js.map +1 -1
- package/dist/zod/TypedData.d.ts +4 -4
- package/dist/zod/tempo/KeyAuthorization.d.ts.map +1 -1
- package/dist/zod/tempo/KeyAuthorization.js +4 -2
- package/dist/zod/tempo/KeyAuthorization.js.map +1 -1
- package/dist/zod/tempo/SignatureEnvelope.d.ts.map +1 -1
- package/dist/zod/tempo/SignatureEnvelope.js +29 -29
- package/dist/zod/tempo/SignatureEnvelope.js.map +1 -1
- package/package.json +2 -2
- package/src/core/AbiError.ts +82 -8
- package/src/core/AbiEvent.bench.ts +45 -0
- package/src/core/AbiEvent.ts +120 -68
- package/src/core/AbiFunction.bench.ts +16 -0
- package/src/core/AbiFunction.ts +76 -4
- package/src/core/AbiItem.ts +13 -4
- package/src/core/AbiParameters.bench.ts +33 -0
- package/src/core/AbiParameters.ts +8 -1
- package/src/core/Address.ts +18 -1
- package/src/core/Authorization.ts +34 -4
- package/src/core/Base58.bench.ts +28 -0
- package/src/core/Base58.ts +15 -4
- package/src/core/Blobs.bench.ts +40 -0
- package/src/core/Blobs.ts +47 -55
- package/src/core/Bytes.bench.ts +34 -0
- package/src/core/Bytes.ts +10 -2
- package/src/core/Cbor.ts +36 -14
- package/src/core/Ens.ts +2 -2
- package/src/core/FrameReceipt.ts +4 -1
- package/src/core/Hex.bench.ts +17 -0
- package/src/core/Hex.ts +29 -32
- package/src/core/Keystore.ts +40 -3
- package/src/core/Rlp.ts +139 -1
- package/src/core/Rlp_tx.bench.ts +55 -0
- package/src/core/RpcTransport.ts +3 -1
- package/src/core/Secp256k1.ts +4 -1
- package/src/core/Signature.ts +7 -3
- package/src/core/Siwe.ts +29 -3
- package/src/core/Transaction.ts +4 -2
- package/src/core/TransactionReceipt.ts +8 -2
- package/src/core/TxEnvelopeEip1559.ts +4 -1
- package/src/core/TxEnvelopeEip2930.ts +4 -1
- package/src/core/TxEnvelopeEip7702.ts +9 -2
- package/src/core/TxEnvelopeLegacy.ts +58 -7
- package/src/core/TypedData.bench.ts +50 -0
- package/src/core/TypedData.ts +24 -11
- package/src/core/Value.ts +14 -3
- package/src/core/_test/AbiError.test.ts +105 -2
- package/src/core/_test/AbiEvent.fuzz.ts +1 -1
- package/src/core/_test/AbiEvent.test-d.ts +46 -0
- package/src/core/_test/AbiEvent.test.ts +646 -11
- package/src/core/_test/AbiFunction.test.ts +79 -6
- package/src/core/_test/AbiParameters.adversarial.fuzz.ts +1 -0
- package/src/core/_test/AbiParameters.decode.test.ts +143 -0
- package/src/core/_test/AbiParameters.encode.test.ts +36 -1
- package/src/core/_test/AbiParameters.test.ts +15 -0
- package/src/core/_test/Address.test.ts +41 -0
- package/src/core/_test/Authorization.test.ts +130 -0
- package/src/core/_test/Bytes.test.ts +33 -0
- package/src/core/_test/Caches.test.ts +20 -1
- package/src/core/_test/Cbor.test.ts +26 -0
- package/src/core/_test/FrameReceipt.test.ts +13 -0
- package/src/core/_test/Keystore.test.ts +65 -1
- package/src/core/_test/Rlp.fuzz.ts +55 -1
- package/src/core/_test/Rlp.test.ts +64 -0
- package/src/core/_test/RpcTransport.test.ts +15 -2
- package/src/core/_test/Secp256k1.test.ts +36 -0
- package/src/core/_test/Signature.test.ts +102 -0
- package/src/core/_test/Siwe.test.ts +123 -0
- package/src/core/_test/Transaction.test.ts +17 -0
- package/src/core/_test/TransactionEnvelopeEip1559.test.ts +28 -0
- package/src/core/_test/TransactionEnvelopeEip2930.test.ts +28 -0
- package/src/core/_test/TransactionEnvelopeEip7702.test.ts +133 -0
- package/src/core/_test/TransactionEnvelopeLegacy.test.ts +322 -1
- package/src/core/_test/TransactionReceipt.test.ts +41 -0
- package/src/core/_test/TypedData.test.ts +197 -0
- package/src/core/_test/Value.test.ts +21 -0
- package/src/core/_test/internal/cursor.test.ts +71 -0
- package/src/core/internal/abiParameters.ts +123 -81
- package/src/core/internal/base58.ts +9 -3
- package/src/core/internal/caches.ts +3 -1
- package/src/core/internal/codec/hex.ts +27 -2
- package/src/core/internal/codec/int.ts +45 -32
- package/src/core/internal/cursor.ts +84 -19
- package/src/core/internal/lru.ts +21 -35
- package/src/core/internal/promise.ts +11 -5
- package/src/erc4337/UserOperation.ts +3 -4
- package/src/erc4337/_test/UserOperation.test.ts +59 -1
- package/src/erc6492/SignatureErc6492.ts +1 -1
- package/src/erc6492/_test/SignatureErc6492.test.ts +48 -1
- package/src/erc7821/Execute.ts +83 -2
- package/src/erc7821/_test/Execute.test.ts +217 -1
- package/src/index.ts +1 -1
- package/src/tempo/KeyAuthorization.test.ts +91 -0
- package/src/tempo/KeyAuthorization.ts +32 -3
- package/src/tempo/SignatureEnvelope.test.ts +300 -28
- package/src/tempo/SignatureEnvelope.ts +62 -54
- package/src/tempo/TransactionReceipt.test.ts +8 -0
- package/src/tempo/TransactionReceipt.ts +4 -1
- package/src/tempo/TransactionRequest.test.ts +30 -0
- package/src/tempo/TransactionRequest.ts +7 -2
- package/src/tempo/TxEnvelopeTempo.test.ts +310 -0
- package/src/tempo/TxEnvelopeTempo.ts +64 -1
- package/src/tempo/VirtualMaster.bench.ts +7 -0
- package/src/tempo/ZoneId.test.ts +11 -0
- package/src/tempo/ZoneId.ts +7 -1
- package/src/tempo/configurableAccounts.e2e.test.ts +1 -1
- package/src/tempo/internal/virtualMasterPool.ts +20 -6
- package/src/tempo/internal/webauthnData.ts +84 -0
- package/src/version.ts +1 -1
- package/src/webauthn/Registration.ts +4 -6
- package/src/webauthn/_test/Registration.browser.test.ts +14 -0
- package/src/webauthn/_test/Registration.test.ts +60 -0
- package/src/zod/tempo/KeyAuthorization.ts +12 -5
- package/src/zod/tempo/SignatureEnvelope.ts +38 -32
- package/src/zod/tempo/_test/KeyAuthorization.test.ts +36 -0
- package/src/zod/tempo/_test/SignatureEnvelope.test.ts +138 -4
- package/src/core/_test/internal/lru.test.ts +0 -38
- package/src/core/_test/internal/uid.test.ts +0 -7
- package/src/core/internal/uid.ts +0 -15
package/src/erc7821/Execute.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as AbiFunction from '../core/AbiFunction.js'
|
|
2
|
+
import * as Errors from '../core/Errors.js'
|
|
2
3
|
import * as Hex from '../core/Hex.js'
|
|
3
4
|
import { AbiParameters } from '../index.js'
|
|
4
5
|
import * as Calls from './Calls.js'
|
|
@@ -42,6 +43,10 @@ export const mode = {
|
|
|
42
43
|
/**
|
|
43
44
|
* Decodes calls from ERC-7821 `execute` function data.
|
|
44
45
|
*
|
|
46
|
+
* Decodes the single batch modes only (`mode.default` and `mode.opData`). Throws
|
|
47
|
+
* `Execute.UnsupportedModeError` for the "batch of batches" mode (use
|
|
48
|
+
* {@link ox#Execute.decodeBatchOfBatchesData} instead) and for unknown modes.
|
|
49
|
+
*
|
|
45
50
|
* @example
|
|
46
51
|
* ```ts twoslash
|
|
47
52
|
* import { Execute } from 'ox/erc7821'
|
|
@@ -57,7 +62,13 @@ export function decodeData(data: Hex.Hex): decodeData.ReturnType {
|
|
|
57
62
|
Hex.Hex,
|
|
58
63
|
Hex.Hex,
|
|
59
64
|
]
|
|
60
|
-
|
|
65
|
+
const name = getModeName(m)
|
|
66
|
+
if (name !== 'default' && name !== 'opData')
|
|
67
|
+
throw new UnsupportedModeError({
|
|
68
|
+
mode: m,
|
|
69
|
+
supported: ['default', 'opData'],
|
|
70
|
+
})
|
|
71
|
+
return Calls.decode(executionData, { opData: name === 'opData' })
|
|
61
72
|
}
|
|
62
73
|
|
|
63
74
|
export declare namespace decodeData {
|
|
@@ -65,11 +76,15 @@ export declare namespace decodeData {
|
|
|
65
76
|
calls: Call[]
|
|
66
77
|
opData?: Hex.Hex | undefined
|
|
67
78
|
}
|
|
79
|
+
|
|
80
|
+
type ErrorType = UnsupportedModeError | Errors.GlobalErrorType
|
|
68
81
|
}
|
|
69
82
|
|
|
70
83
|
/**
|
|
71
84
|
* Decodes batches from ERC-7821 `execute` function data in "batch of batches" mode.
|
|
72
85
|
*
|
|
86
|
+
* Throws `Execute.UnsupportedModeError` for any other mode.
|
|
87
|
+
*
|
|
73
88
|
* @example
|
|
74
89
|
* ```ts twoslash
|
|
75
90
|
* import { Execute } from 'ox/erc7821'
|
|
@@ -83,10 +98,12 @@ export declare namespace decodeData {
|
|
|
83
98
|
export function decodeBatchOfBatchesData(
|
|
84
99
|
data: Hex.Hex,
|
|
85
100
|
): decodeBatchOfBatchesData.ReturnType {
|
|
86
|
-
const [, executionData] = AbiFunction.decodeData(abiFunction, data) as [
|
|
101
|
+
const [m, executionData] = AbiFunction.decodeData(abiFunction, data) as [
|
|
87
102
|
Hex.Hex,
|
|
88
103
|
Hex.Hex,
|
|
89
104
|
]
|
|
105
|
+
if (getModeName(m) !== 'batchOfBatches')
|
|
106
|
+
throw new UnsupportedModeError({ mode: m, supported: ['batchOfBatches'] })
|
|
90
107
|
|
|
91
108
|
const [encodedBatches] = AbiParameters.decode(
|
|
92
109
|
batchesParameters,
|
|
@@ -112,6 +129,8 @@ export function decodeBatchOfBatchesData(
|
|
|
112
129
|
|
|
113
130
|
export declare namespace decodeBatchOfBatchesData {
|
|
114
131
|
type ReturnType = Batch[]
|
|
132
|
+
|
|
133
|
+
type ErrorType = UnsupportedModeError | Errors.GlobalErrorType
|
|
115
134
|
}
|
|
116
135
|
|
|
117
136
|
/**
|
|
@@ -195,3 +214,65 @@ export declare namespace encodeData {
|
|
|
195
214
|
opData?: Hex.Hex | undefined
|
|
196
215
|
}
|
|
197
216
|
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Thrown when the mode of ERC-7821 `execute` function data is not supported by the decoder.
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```ts twoslash
|
|
223
|
+
* import { Execute } from 'ox/erc7821'
|
|
224
|
+
*
|
|
225
|
+
* const data = Execute.encodeBatchOfBatchesData([
|
|
226
|
+
* {
|
|
227
|
+
* calls: [
|
|
228
|
+
* {
|
|
229
|
+
* data: '0xcafebabe',
|
|
230
|
+
* to: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
|
|
231
|
+
* value: 1n
|
|
232
|
+
* }
|
|
233
|
+
* ]
|
|
234
|
+
* }
|
|
235
|
+
* ])
|
|
236
|
+
*
|
|
237
|
+
* Execute.decodeData(data)
|
|
238
|
+
* // @error: Execute.UnsupportedModeError: Execution mode `0x0100000000007821000200000000000000000000000000000000000000000000` is not supported.
|
|
239
|
+
* ```
|
|
240
|
+
*/
|
|
241
|
+
export class UnsupportedModeError extends Errors.BaseError {
|
|
242
|
+
override readonly name = 'Execute.UnsupportedModeError'
|
|
243
|
+
|
|
244
|
+
constructor({ mode, supported }: UnsupportedModeError.Options) {
|
|
245
|
+
super(`Execution mode \`${mode}\` is not supported.`, {
|
|
246
|
+
metaMessages: [
|
|
247
|
+
`Supported modes: ${supported.map((name) => `\`${name}\``).join(', ')}.`,
|
|
248
|
+
],
|
|
249
|
+
})
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export declare namespace UnsupportedModeError {
|
|
254
|
+
/** Options for {@link ox#Execute.UnsupportedModeError}. */
|
|
255
|
+
type Options = {
|
|
256
|
+
/** Mode of the `execute` function data. */
|
|
257
|
+
mode: Hex.Hex
|
|
258
|
+
/** Names of the modes (keys of `Execute.mode`) the decoder supports. */
|
|
259
|
+
supported: readonly (keyof typeof mode)[]
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Identifies an ERC-7821 execution mode the way the reference implementation
|
|
265
|
+
* (`_executionModeId`) does. Bytes `[0..1]` (call type and execution type) and
|
|
266
|
+
* bytes `[6..9]` (mode selector) identify the mode. Bytes `[2..5]` (reserved by
|
|
267
|
+
* ERC-7579) and bytes `[10..31]` (unused) are ignored.
|
|
268
|
+
*
|
|
269
|
+
* @internal
|
|
270
|
+
*/
|
|
271
|
+
function getModeName(m: Hex.Hex): keyof typeof mode | undefined {
|
|
272
|
+
if (Hex.slice(m, 0, 2) !== '0x0100') return undefined
|
|
273
|
+
const selector = Hex.slice(m, 6, 10)
|
|
274
|
+
if (selector === '0x00000000') return 'default'
|
|
275
|
+
if (selector === '0x78210001') return 'opData'
|
|
276
|
+
if (selector === '0x78210002') return 'batchOfBatches'
|
|
277
|
+
return undefined
|
|
278
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AbiFunction, AbiParameters } from 'ox'
|
|
2
|
+
import { Calls, Execute } from 'ox/erc7821'
|
|
2
3
|
import { describe, expect, test } from 'vp/test'
|
|
3
4
|
|
|
4
5
|
describe('encodeData', () => {
|
|
@@ -251,6 +252,130 @@ describe('decodeData', () => {
|
|
|
251
252
|
|
|
252
253
|
expect(result).toEqual({ calls })
|
|
253
254
|
})
|
|
255
|
+
|
|
256
|
+
test('behavior: ignores reserved and unused mode bytes', () => {
|
|
257
|
+
const calls = [
|
|
258
|
+
{
|
|
259
|
+
data: '0xdeadbeef',
|
|
260
|
+
to: '0xCafEBAbECAFEbAbEcaFEbabECAfebAbEcAFEBaBe',
|
|
261
|
+
value: 1n,
|
|
262
|
+
},
|
|
263
|
+
] as const
|
|
264
|
+
const opData = '0x1234567890abcdef' as const
|
|
265
|
+
|
|
266
|
+
// Bytes [2..5] are reserved by ERC-7579 and bytes [10..31] are unused.
|
|
267
|
+
expect(
|
|
268
|
+
Execute.decodeData(
|
|
269
|
+
AbiFunction.encodeData(Execute.abiFunction, [
|
|
270
|
+
'0x0100deadbeef00000000ffffffffffffffffffffffffffffffffffffffffffff',
|
|
271
|
+
Calls.encode(calls),
|
|
272
|
+
]),
|
|
273
|
+
),
|
|
274
|
+
).toEqual({ calls })
|
|
275
|
+
expect(
|
|
276
|
+
Execute.decodeData(
|
|
277
|
+
AbiFunction.encodeData(Execute.abiFunction, [
|
|
278
|
+
'0x0100deadbeef78210001ffffffffffffffffffffffffffffffffffffffffffff',
|
|
279
|
+
Calls.encode(calls, { opData }),
|
|
280
|
+
]),
|
|
281
|
+
),
|
|
282
|
+
).toEqual({ calls, opData })
|
|
283
|
+
})
|
|
284
|
+
|
|
285
|
+
test('error: batch of batches mode', () => {
|
|
286
|
+
const executionData = Calls.encode(
|
|
287
|
+
[
|
|
288
|
+
{
|
|
289
|
+
data: '0xdeadbeef',
|
|
290
|
+
to: '0xCafEBAbECAFEbAbEcaFEbabECAfebAbEcAFEBaBe',
|
|
291
|
+
value: 1n,
|
|
292
|
+
},
|
|
293
|
+
],
|
|
294
|
+
{ opData: '0x1234567890abcdef' },
|
|
295
|
+
)
|
|
296
|
+
|
|
297
|
+
expect(() =>
|
|
298
|
+
Execute.decodeData(
|
|
299
|
+
AbiFunction.encodeData(Execute.abiFunction, [
|
|
300
|
+
Execute.mode.batchOfBatches,
|
|
301
|
+
executionData,
|
|
302
|
+
]),
|
|
303
|
+
),
|
|
304
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
305
|
+
[Execute.UnsupportedModeError: Execution mode \`0x0100000000007821000200000000000000000000000000000000000000000000\` is not supported.
|
|
306
|
+
|
|
307
|
+
Supported modes: \`default\`, \`opData\`.]
|
|
308
|
+
`)
|
|
309
|
+
expect(() =>
|
|
310
|
+
Execute.decodeData(Execute.encodeBatchOfBatchesData([])),
|
|
311
|
+
).toThrow(Execute.UnsupportedModeError)
|
|
312
|
+
})
|
|
313
|
+
|
|
314
|
+
test('error: unknown mode', () => {
|
|
315
|
+
const executionData = Calls.encode(
|
|
316
|
+
[
|
|
317
|
+
{
|
|
318
|
+
data: '0xdeadbeef',
|
|
319
|
+
to: '0xCafEBAbECAFEbAbEcaFEbabECAfebAbEcAFEBaBe',
|
|
320
|
+
value: 1n,
|
|
321
|
+
},
|
|
322
|
+
],
|
|
323
|
+
{ opData: '0x1234567890abcdef' },
|
|
324
|
+
)
|
|
325
|
+
|
|
326
|
+
// Unknown call type.
|
|
327
|
+
expect(() =>
|
|
328
|
+
Execute.decodeData(
|
|
329
|
+
AbiFunction.encodeData(Execute.abiFunction, [
|
|
330
|
+
'0xff00000000000000000000000000000000000000000000000000000000000000',
|
|
331
|
+
executionData,
|
|
332
|
+
]),
|
|
333
|
+
),
|
|
334
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
335
|
+
[Execute.UnsupportedModeError: Execution mode \`0xff00000000000000000000000000000000000000000000000000000000000000\` is not supported.
|
|
336
|
+
|
|
337
|
+
Supported modes: \`default\`, \`opData\`.]
|
|
338
|
+
`)
|
|
339
|
+
// Unknown execution type.
|
|
340
|
+
expect(() =>
|
|
341
|
+
Execute.decodeData(
|
|
342
|
+
AbiFunction.encodeData(Execute.abiFunction, [
|
|
343
|
+
'0x0101000000007821000100000000000000000000000000000000000000000000',
|
|
344
|
+
executionData,
|
|
345
|
+
]),
|
|
346
|
+
),
|
|
347
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
348
|
+
[Execute.UnsupportedModeError: Execution mode \`0x0101000000007821000100000000000000000000000000000000000000000000\` is not supported.
|
|
349
|
+
|
|
350
|
+
Supported modes: \`default\`, \`opData\`.]
|
|
351
|
+
`)
|
|
352
|
+
// Unknown mode selector.
|
|
353
|
+
expect(() =>
|
|
354
|
+
Execute.decodeData(
|
|
355
|
+
AbiFunction.encodeData(Execute.abiFunction, [
|
|
356
|
+
'0x0100000000007821000300000000000000000000000000000000000000000000',
|
|
357
|
+
executionData,
|
|
358
|
+
]),
|
|
359
|
+
),
|
|
360
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
361
|
+
[Execute.UnsupportedModeError: Execution mode \`0x0100000000007821000300000000000000000000000000000000000000000000\` is not supported.
|
|
362
|
+
|
|
363
|
+
Supported modes: \`default\`, \`opData\`.]
|
|
364
|
+
`)
|
|
365
|
+
})
|
|
366
|
+
|
|
367
|
+
test('error: selector mismatch', () => {
|
|
368
|
+
expect(() =>
|
|
369
|
+
Execute.decodeData(
|
|
370
|
+
'0x095ea7b3000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa960450000000000000000000000000000000000000000000000000000000000000001',
|
|
371
|
+
),
|
|
372
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
373
|
+
[AbiFunction.SelectorMismatchError: Selector "0x095ea7b3" does not match the expected selector "0xe9ae5c53".
|
|
374
|
+
|
|
375
|
+
Function: function execute(bytes32 mode, bytes executionData) payable
|
|
376
|
+
Selector: 0xe9ae5c53]
|
|
377
|
+
`)
|
|
378
|
+
})
|
|
254
379
|
})
|
|
255
380
|
|
|
256
381
|
describe('encodeBatchOfBatchesData', () => {
|
|
@@ -545,4 +670,95 @@ describe('decodeBatchOfBatchesData', () => {
|
|
|
545
670
|
|
|
546
671
|
expect(result).toEqual(batches)
|
|
547
672
|
})
|
|
673
|
+
|
|
674
|
+
test('behavior: ignores reserved and unused mode bytes', () => {
|
|
675
|
+
const batches = [
|
|
676
|
+
{
|
|
677
|
+
calls: [
|
|
678
|
+
{
|
|
679
|
+
data: '0xdeadbeef',
|
|
680
|
+
to: '0xCafEBAbECAFEbAbEcaFEbabECAfebAbEcAFEBaBe',
|
|
681
|
+
value: 1n,
|
|
682
|
+
},
|
|
683
|
+
],
|
|
684
|
+
},
|
|
685
|
+
] as const
|
|
686
|
+
|
|
687
|
+
const executionData = AbiParameters.encode(AbiParameters.from('bytes[]'), [
|
|
688
|
+
[Calls.encode(batches[0].calls)],
|
|
689
|
+
])
|
|
690
|
+
|
|
691
|
+
// Bytes [2..5] are reserved by ERC-7579 and bytes [10..31] are unused.
|
|
692
|
+
expect(
|
|
693
|
+
Execute.decodeBatchOfBatchesData(
|
|
694
|
+
AbiFunction.encodeData(Execute.abiFunction, [
|
|
695
|
+
'0x0100deadbeef78210002ffffffffffffffffffffffffffffffffffffffffffff',
|
|
696
|
+
executionData,
|
|
697
|
+
]),
|
|
698
|
+
),
|
|
699
|
+
).toEqual(batches)
|
|
700
|
+
})
|
|
701
|
+
|
|
702
|
+
test('error: single batch mode', () => {
|
|
703
|
+
const executionData = AbiParameters.encode(AbiParameters.from('bytes[]'), [
|
|
704
|
+
[],
|
|
705
|
+
])
|
|
706
|
+
|
|
707
|
+
expect(() =>
|
|
708
|
+
Execute.decodeBatchOfBatchesData(
|
|
709
|
+
AbiFunction.encodeData(Execute.abiFunction, [
|
|
710
|
+
Execute.mode.default,
|
|
711
|
+
executionData,
|
|
712
|
+
]),
|
|
713
|
+
),
|
|
714
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
715
|
+
[Execute.UnsupportedModeError: Execution mode \`0x0100000000000000000000000000000000000000000000000000000000000000\` is not supported.
|
|
716
|
+
|
|
717
|
+
Supported modes: \`batchOfBatches\`.]
|
|
718
|
+
`)
|
|
719
|
+
expect(() =>
|
|
720
|
+
Execute.decodeBatchOfBatchesData(
|
|
721
|
+
AbiFunction.encodeData(Execute.abiFunction, [
|
|
722
|
+
Execute.mode.opData,
|
|
723
|
+
executionData,
|
|
724
|
+
]),
|
|
725
|
+
),
|
|
726
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
727
|
+
[Execute.UnsupportedModeError: Execution mode \`0x0100000000007821000100000000000000000000000000000000000000000000\` is not supported.
|
|
728
|
+
|
|
729
|
+
Supported modes: \`batchOfBatches\`.]
|
|
730
|
+
`)
|
|
731
|
+
})
|
|
732
|
+
|
|
733
|
+
test('error: unknown mode', () => {
|
|
734
|
+
const executionData = AbiParameters.encode(AbiParameters.from('bytes[]'), [
|
|
735
|
+
[],
|
|
736
|
+
])
|
|
737
|
+
|
|
738
|
+
expect(() =>
|
|
739
|
+
Execute.decodeBatchOfBatchesData(
|
|
740
|
+
AbiFunction.encodeData(Execute.abiFunction, [
|
|
741
|
+
'0xff00000000000000000000000000000000000000000000000000000000000000',
|
|
742
|
+
executionData,
|
|
743
|
+
]),
|
|
744
|
+
),
|
|
745
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
746
|
+
[Execute.UnsupportedModeError: Execution mode \`0xff00000000000000000000000000000000000000000000000000000000000000\` is not supported.
|
|
747
|
+
|
|
748
|
+
Supported modes: \`batchOfBatches\`.]
|
|
749
|
+
`)
|
|
750
|
+
})
|
|
751
|
+
|
|
752
|
+
test('error: selector mismatch', () => {
|
|
753
|
+
expect(() =>
|
|
754
|
+
Execute.decodeBatchOfBatchesData(
|
|
755
|
+
'0x095ea7b3000000000000000000000000d8da6bf26964af9d7eed9e03e53415d37aa960450000000000000000000000000000000000000000000000000000000000000001',
|
|
756
|
+
),
|
|
757
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
758
|
+
[AbiFunction.SelectorMismatchError: Selector "0x095ea7b3" does not match the expected selector "0xe9ae5c53".
|
|
759
|
+
|
|
760
|
+
Function: function execute(bytes32 mode, bytes executionData) payable
|
|
761
|
+
Selector: 0xe9ae5c53]
|
|
762
|
+
`)
|
|
763
|
+
})
|
|
548
764
|
})
|
package/src/index.ts
CHANGED
|
@@ -205,7 +205,7 @@ export * as AbiConstructor from './core/AbiConstructor.js'
|
|
|
205
205
|
* const abi = Abi.from([...])
|
|
206
206
|
* const error = AbiError.fromAbi(abi, 'InvalidSignature')
|
|
207
207
|
*
|
|
208
|
-
* const value = AbiError.decode(error, '
|
|
208
|
+
* const value = AbiError.decode(error, '0xe466f0a500000000000000000000000000000000000000000000000000000000000001a400000000000000000000000000000000000000000000000000000000000000450000000000000000000000000000000000000000000000000000000000000001') // [!code focus]
|
|
209
209
|
* // @log: [420n, 69n, 1]
|
|
210
210
|
* ```
|
|
211
211
|
*
|
|
@@ -198,6 +198,44 @@ describe('from', () => {
|
|
|
198
198
|
}).toEqual(limitsVectors)
|
|
199
199
|
})
|
|
200
200
|
|
|
201
|
+
test('error: rejects recipients without a selector', () => {
|
|
202
|
+
const base = { address, chainId: 4217n, type: 'secp256k1' } as const
|
|
203
|
+
const recipients = ['0x1111111111111111111111111111111111111111'] as const
|
|
204
|
+
expect(() =>
|
|
205
|
+
KeyAuthorization.from({
|
|
206
|
+
...base,
|
|
207
|
+
scopes: [{ address: token, recipients }],
|
|
208
|
+
}),
|
|
209
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
210
|
+
`[KeyAuthorization.InvalidScopeError: Scope for \`0x20c0000000000000000000000000000000000001\` has \`recipients\` but no \`selector\`; a recipient allowlist requires a selector.]`,
|
|
211
|
+
)
|
|
212
|
+
expect(() =>
|
|
213
|
+
KeyAuthorization.from({
|
|
214
|
+
...base,
|
|
215
|
+
scopes: [
|
|
216
|
+
{ address: token, selector: 'transfer(address,uint256)' },
|
|
217
|
+
{ address: token, recipients },
|
|
218
|
+
],
|
|
219
|
+
}),
|
|
220
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
221
|
+
`[KeyAuthorization.InvalidScopeError: Scope for \`0x20c0000000000000000000000000000000000001\` has \`recipients\` but no \`selector\`; a recipient allowlist requires a selector.]`,
|
|
222
|
+
)
|
|
223
|
+
expect(
|
|
224
|
+
KeyAuthorization.from({
|
|
225
|
+
...base,
|
|
226
|
+
scopes: [{ address: token, recipients: [] }],
|
|
227
|
+
}).scopes,
|
|
228
|
+
).toMatchInlineSnapshot(`
|
|
229
|
+
[
|
|
230
|
+
{
|
|
231
|
+
"address": "0x20c0000000000000000000000000000000000001",
|
|
232
|
+
"recipients": [],
|
|
233
|
+
"selector": undefined,
|
|
234
|
+
},
|
|
235
|
+
]
|
|
236
|
+
`)
|
|
237
|
+
})
|
|
238
|
+
|
|
201
239
|
test('accepts configurable grants and delegates', () => {
|
|
202
240
|
const signed = KeyAuthorization.from(
|
|
203
241
|
{
|
|
@@ -1488,6 +1526,25 @@ describe('serialize', () => {
|
|
|
1488
1526
|
})
|
|
1489
1527
|
|
|
1490
1528
|
describe('toRpc', () => {
|
|
1529
|
+
test('error: rejects recipients without a selector', () => {
|
|
1530
|
+
expect(() =>
|
|
1531
|
+
KeyAuthorization.toRpc({
|
|
1532
|
+
address,
|
|
1533
|
+
chainId: 4217n,
|
|
1534
|
+
scopes: [
|
|
1535
|
+
{
|
|
1536
|
+
address: token,
|
|
1537
|
+
recipients: ['0x1111111111111111111111111111111111111111'],
|
|
1538
|
+
},
|
|
1539
|
+
],
|
|
1540
|
+
signature: SignatureEnvelope.from(signature_secp256k1),
|
|
1541
|
+
type: 'secp256k1',
|
|
1542
|
+
}),
|
|
1543
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1544
|
+
`[KeyAuthorization.InvalidScopeError: Scope for \`0x20c0000000000000000000000000000000000001\` has \`recipients\` but no \`selector\`; a recipient allowlist requires a selector.]`,
|
|
1545
|
+
)
|
|
1546
|
+
})
|
|
1547
|
+
|
|
1491
1548
|
test('behavior: configurable key type uses the RPC configurableAccount key type', () => {
|
|
1492
1549
|
const authorization = KeyAuthorization.from(
|
|
1493
1550
|
{ account: address, address, chainId: 1n, type: 'configurable' },
|
|
@@ -1770,6 +1827,40 @@ describe('toRpc', () => {
|
|
|
1770
1827
|
})
|
|
1771
1828
|
|
|
1772
1829
|
describe('toTuple', () => {
|
|
1830
|
+
test('error: rejects recipients without a selector', () => {
|
|
1831
|
+
const authorization = {
|
|
1832
|
+
address,
|
|
1833
|
+
chainId: 4217n,
|
|
1834
|
+
scopes: [
|
|
1835
|
+
{
|
|
1836
|
+
address: token,
|
|
1837
|
+
recipients: ['0x1111111111111111111111111111111111111111'],
|
|
1838
|
+
},
|
|
1839
|
+
],
|
|
1840
|
+
type: 'secp256k1',
|
|
1841
|
+
} as const
|
|
1842
|
+
expect(() =>
|
|
1843
|
+
KeyAuthorization.toTuple(authorization),
|
|
1844
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1845
|
+
`[KeyAuthorization.InvalidScopeError: Scope for \`0x20c0000000000000000000000000000000000001\` has \`recipients\` but no \`selector\`; a recipient allowlist requires a selector.]`,
|
|
1846
|
+
)
|
|
1847
|
+
expect(() =>
|
|
1848
|
+
KeyAuthorization.getSignPayload(authorization),
|
|
1849
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1850
|
+
`[KeyAuthorization.InvalidScopeError: Scope for \`0x20c0000000000000000000000000000000000001\` has \`recipients\` but no \`selector\`; a recipient allowlist requires a selector.]`,
|
|
1851
|
+
)
|
|
1852
|
+
expect(() =>
|
|
1853
|
+
KeyAuthorization.hash(authorization),
|
|
1854
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1855
|
+
`[KeyAuthorization.InvalidScopeError: Scope for \`0x20c0000000000000000000000000000000000001\` has \`recipients\` but no \`selector\`; a recipient allowlist requires a selector.]`,
|
|
1856
|
+
)
|
|
1857
|
+
expect(() =>
|
|
1858
|
+
KeyAuthorization.serialize(authorization),
|
|
1859
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1860
|
+
`[KeyAuthorization.InvalidScopeError: Scope for \`0x20c0000000000000000000000000000000000001\` has \`recipients\` but no \`selector\`; a recipient allowlist requires a selector.]`,
|
|
1861
|
+
)
|
|
1862
|
+
})
|
|
1863
|
+
|
|
1773
1864
|
test('behavior: round-trips Tempo node limits encoding', () => {
|
|
1774
1865
|
for (const { hash, rlp } of Object.values(limitsVectors)) {
|
|
1775
1866
|
const authorization = KeyAuthorization.fromTuple([
|
|
@@ -261,6 +261,7 @@ export type Scope = {
|
|
|
261
261
|
* - `[...]` = only listed recipients allowed
|
|
262
262
|
*
|
|
263
263
|
* Only valid for constrained selectors: `transfer`, `approve`, `transferWithMemo`.
|
|
264
|
+
* A non-empty list requires `selector`.
|
|
264
265
|
*/
|
|
265
266
|
recipients?: readonly Address.Address[] | undefined
|
|
266
267
|
/**
|
|
@@ -470,6 +471,7 @@ export function from<
|
|
|
470
471
|
}
|
|
471
472
|
if (auth.witness !== undefined) assertWitness(auth.witness)
|
|
472
473
|
if (auth.signature) assertSignature(auth.signature)
|
|
474
|
+
if (auth.scopes) assertScopes(auth.scopes)
|
|
473
475
|
const resolved = {
|
|
474
476
|
...auth,
|
|
475
477
|
...(auth.scopes
|
|
@@ -523,7 +525,10 @@ export declare namespace from {
|
|
|
523
525
|
: {})
|
|
524
526
|
>
|
|
525
527
|
|
|
526
|
-
type ErrorType =
|
|
528
|
+
type ErrorType =
|
|
529
|
+
| InvalidScopeError
|
|
530
|
+
| InvalidSignatureTypeError
|
|
531
|
+
| Errors.GlobalErrorType
|
|
527
532
|
}
|
|
528
533
|
|
|
529
534
|
/**
|
|
@@ -985,6 +990,7 @@ export function toRpc(authorization: toRpc.Input): Rpc {
|
|
|
985
990
|
// Group flat scopes by address into nested allowedCalls wire format
|
|
986
991
|
const allowedCalls = (() => {
|
|
987
992
|
if (!scopes) return undefined
|
|
993
|
+
assertScopes(scopes)
|
|
988
994
|
const grouped = new Map<string, RpcSelectorRule[]>()
|
|
989
995
|
for (const scope of scopes) {
|
|
990
996
|
const key = scope.address as string
|
|
@@ -1032,7 +1038,10 @@ export declare namespace toRpc {
|
|
|
1032
1038
|
/** Numberish input accepted by {@link ox#KeyAuthorization.(toRpc:function)}. */
|
|
1033
1039
|
type Input = Signed<Hex.Hex | bigint | number, Hex.Hex | number>
|
|
1034
1040
|
|
|
1035
|
-
type ErrorType =
|
|
1041
|
+
type ErrorType =
|
|
1042
|
+
| InvalidScopeError
|
|
1043
|
+
| InvalidSignatureTypeError
|
|
1044
|
+
| Errors.GlobalErrorType
|
|
1036
1045
|
}
|
|
1037
1046
|
|
|
1038
1047
|
/**
|
|
@@ -1110,6 +1119,7 @@ export function toTuple<const authorization extends KeyAuthorization>(
|
|
|
1110
1119
|
// Group flat scopes by address for wire format
|
|
1111
1120
|
const callsValue = (() => {
|
|
1112
1121
|
if (!scopes) return undefined
|
|
1122
|
+
assertScopes(scopes)
|
|
1113
1123
|
const grouped = new Map<
|
|
1114
1124
|
string,
|
|
1115
1125
|
[Hex.Hex, (readonly Address.Address[])[]][]
|
|
@@ -1179,7 +1189,10 @@ export declare namespace toTuple {
|
|
|
1179
1189
|
type ReturnType<authorization extends KeyAuthorization = KeyAuthorization> =
|
|
1180
1190
|
Compute<Tuple<authorization extends KeyAuthorization<true> ? true : false>>
|
|
1181
1191
|
|
|
1182
|
-
type ErrorType =
|
|
1192
|
+
type ErrorType =
|
|
1193
|
+
| InvalidScopeError
|
|
1194
|
+
| InvalidSignatureTypeError
|
|
1195
|
+
| Errors.GlobalErrorType
|
|
1183
1196
|
}
|
|
1184
1197
|
|
|
1185
1198
|
function bigintToHex(value: bigint): Hex.Hex {
|
|
@@ -1217,6 +1230,12 @@ function assertWitness(witness: Hex.Hex): void {
|
|
|
1217
1230
|
if (Hex.size(witness) !== 32) throw new InvalidWitnessSizeError(witness)
|
|
1218
1231
|
}
|
|
1219
1232
|
|
|
1233
|
+
function assertScopes(scopes: readonly Scope[]): void {
|
|
1234
|
+
for (const scope of scopes)
|
|
1235
|
+
if (!scope.selector && scope.recipients && scope.recipients.length > 0)
|
|
1236
|
+
throw new InvalidScopeError(scope)
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1220
1239
|
function assertSignature<numberType>(
|
|
1221
1240
|
signature: SignatureEnvelope.SignatureEnvelope<numberType>,
|
|
1222
1241
|
): asserts signature is
|
|
@@ -1260,6 +1279,16 @@ export class InvalidSignatureTypeError extends Error {
|
|
|
1260
1279
|
}
|
|
1261
1280
|
}
|
|
1262
1281
|
|
|
1282
|
+
/** Thrown when a call scope has a recipient allowlist but no selector. */
|
|
1283
|
+
export class InvalidScopeError extends Error {
|
|
1284
|
+
override readonly name = 'KeyAuthorization.InvalidScopeError'
|
|
1285
|
+
constructor(scope: Scope) {
|
|
1286
|
+
super(
|
|
1287
|
+
`Scope for \`${scope.address}\` has \`recipients\` but no \`selector\`; a recipient allowlist requires a selector.`,
|
|
1288
|
+
)
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1263
1292
|
/**
|
|
1264
1293
|
* Thrown when a configurable account key grant omits its parent account binding.
|
|
1265
1294
|
*
|