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
|
@@ -124,6 +124,77 @@ describe('decodeData', () => {
|
|
|
124
124
|
)
|
|
125
125
|
expect(AbiFunction.decodeData(abi, dataWithoutArgs)).toEqual(undefined)
|
|
126
126
|
})
|
|
127
|
+
|
|
128
|
+
test('behavior: uppercase data', () => {
|
|
129
|
+
const approve = AbiFunction.from(
|
|
130
|
+
'function approve(address spender, uint256 amount)',
|
|
131
|
+
)
|
|
132
|
+
expect(
|
|
133
|
+
AbiFunction.decodeData(
|
|
134
|
+
approve,
|
|
135
|
+
'0x095EA7B3000000000000000000000000D8DA6BF26964AF9D7EED9E03E53415D37AA960450000000000000000000000000000000000000000000000000000000000000001',
|
|
136
|
+
),
|
|
137
|
+
).toMatchInlineSnapshot(`
|
|
138
|
+
[
|
|
139
|
+
"0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045",
|
|
140
|
+
1n,
|
|
141
|
+
]
|
|
142
|
+
`)
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
test('error: selector mismatch', () => {
|
|
146
|
+
const abi = Abi.from([
|
|
147
|
+
'function approve(address spender, uint256 amount)',
|
|
148
|
+
'function pause()',
|
|
149
|
+
'function transfer(address to, uint256 amount)',
|
|
150
|
+
])
|
|
151
|
+
const data = AbiFunction.encodeData(AbiFunction.fromAbi(abi, 'approve'), [
|
|
152
|
+
address.vitalik,
|
|
153
|
+
1n,
|
|
154
|
+
])
|
|
155
|
+
|
|
156
|
+
expect(() =>
|
|
157
|
+
AbiFunction.decodeData(AbiFunction.fromAbi(abi, 'transfer'), data),
|
|
158
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
159
|
+
[AbiFunction.SelectorMismatchError: Selector "0x095ea7b3" does not match the expected selector "0xa9059cbb".
|
|
160
|
+
|
|
161
|
+
Function: function transfer(address to, uint256 amount)
|
|
162
|
+
Selector: 0xa9059cbb]
|
|
163
|
+
`)
|
|
164
|
+
expect(() => AbiFunction.decodeData(abi, 'transfer', data))
|
|
165
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
166
|
+
[AbiFunction.SelectorMismatchError: Selector "0x095ea7b3" does not match the expected selector "0xa9059cbb".
|
|
167
|
+
|
|
168
|
+
Function: function transfer(address to, uint256 amount)
|
|
169
|
+
Selector: 0xa9059cbb]
|
|
170
|
+
`)
|
|
171
|
+
expect(() => AbiFunction.decodeData(abi, 'pause', data))
|
|
172
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
173
|
+
[AbiFunction.SelectorMismatchError: Selector "0x095ea7b3" does not match the expected selector "0x8456cb59".
|
|
174
|
+
|
|
175
|
+
Function: function pause()
|
|
176
|
+
Selector: 0x8456cb59]
|
|
177
|
+
`)
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
test('error: selector mismatch, with overloads', () => {
|
|
181
|
+
const abi = Abi.from([
|
|
182
|
+
'function deposit()',
|
|
183
|
+
'function deposit(uint256 assets)',
|
|
184
|
+
'function withdraw(uint256 assets)',
|
|
185
|
+
])
|
|
186
|
+
const data = AbiFunction.encodeData(AbiFunction.fromAbi(abi, 'withdraw'), [
|
|
187
|
+
1n,
|
|
188
|
+
])
|
|
189
|
+
|
|
190
|
+
expect(() => AbiFunction.decodeData(abi, 'deposit', data))
|
|
191
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
192
|
+
[AbiFunction.SelectorMismatchError: Selector "0x2e1a7d4d" does not match the expected selector "0xd0e30db0".
|
|
193
|
+
|
|
194
|
+
Function: function deposit()
|
|
195
|
+
Selector: 0xd0e30db0]
|
|
196
|
+
`)
|
|
197
|
+
})
|
|
127
198
|
})
|
|
128
199
|
|
|
129
200
|
describe('decodeResult', () => {
|
|
@@ -251,13 +322,14 @@ describe('encodeData', () => {
|
|
|
251
322
|
)
|
|
252
323
|
})
|
|
253
324
|
|
|
254
|
-
test('
|
|
325
|
+
test('error: malformed bytes', () => {
|
|
255
326
|
const abiFunction = AbiFunction.from('function foo(bytes)')
|
|
256
|
-
expect(
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
327
|
+
expect(() => AbiFunction.encodeData(abiFunction, ['0xzz11']))
|
|
328
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
329
|
+
[Hex.InvalidHexValueError: Value \`0xzz11\` is an invalid hex value.
|
|
330
|
+
|
|
331
|
+
Hex values must start with \`"0x"\` and contain only hexadecimal characters (0-9, a-f, A-F).]
|
|
332
|
+
`)
|
|
261
333
|
})
|
|
262
334
|
|
|
263
335
|
test('behavior: with overloads', () => {
|
|
@@ -1362,6 +1434,7 @@ test('exports', () => {
|
|
|
1362
1434
|
"from",
|
|
1363
1435
|
"fromAbi",
|
|
1364
1436
|
"getSelector",
|
|
1437
|
+
"SelectorMismatchError",
|
|
1365
1438
|
]
|
|
1366
1439
|
`)
|
|
1367
1440
|
})
|
|
@@ -22,6 +22,7 @@ const allowedErrorNames = new Set<string>([
|
|
|
22
22
|
'BaseError',
|
|
23
23
|
'Cursor.PositionOutOfBoundsError',
|
|
24
24
|
'Cursor.NegativeOffsetError',
|
|
25
|
+
'Cursor.ReadSizeLimitExceededError',
|
|
25
26
|
'Cursor.RecursiveReadLimitExceededError',
|
|
26
27
|
'Hex.InvalidHexValueError',
|
|
27
28
|
'Hex.InvalidLengthError',
|
|
@@ -136,6 +136,17 @@ describe('static', () => {
|
|
|
136
136
|
assertType<readonly [Hex.Hex]>(result)
|
|
137
137
|
expect(result).toEqual(['0x0123456789abcdef'])
|
|
138
138
|
})
|
|
139
|
+
|
|
140
|
+
test('error: non-zero padding', () => {
|
|
141
|
+
expect(() =>
|
|
142
|
+
AbiParameters.decode(
|
|
143
|
+
AbiParameters.from('bytes8'),
|
|
144
|
+
'0x0123456789abcdef000000000000000000000000000000000000000000000001',
|
|
145
|
+
),
|
|
146
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
147
|
+
`[AbiParameters.BytesSizeMismatchError: Size of bytes "0x0123456789abcdef000000000000000000000000000000000000000000000001" (bytes32) does not match expected size (bytes8).]`,
|
|
148
|
+
)
|
|
149
|
+
})
|
|
139
150
|
})
|
|
140
151
|
|
|
141
152
|
describe('bytes16', () => {
|
|
@@ -1558,6 +1569,56 @@ test('data size too small', () => {
|
|
|
1558
1569
|
`)
|
|
1559
1570
|
})
|
|
1560
1571
|
|
|
1572
|
+
test('data size too small: fixed-size bytes', () => {
|
|
1573
|
+
expect(
|
|
1574
|
+
AbiParameters.decode(
|
|
1575
|
+
AbiParameters.from('uint256, bytes4'),
|
|
1576
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001deadbeef00000000000000000000000000000000000000000000000000000000',
|
|
1577
|
+
),
|
|
1578
|
+
).toMatchInlineSnapshot(`
|
|
1579
|
+
[
|
|
1580
|
+
1n,
|
|
1581
|
+
"0xdeadbeef",
|
|
1582
|
+
]
|
|
1583
|
+
`)
|
|
1584
|
+
|
|
1585
|
+
expect(() =>
|
|
1586
|
+
AbiParameters.decode(
|
|
1587
|
+
AbiParameters.from('uint256, bytes4'),
|
|
1588
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001deadbeef',
|
|
1589
|
+
),
|
|
1590
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
1591
|
+
[AbiParameters.DataSizeTooSmallError: Data size of 36 bytes is too small for given parameters.
|
|
1592
|
+
|
|
1593
|
+
Params: (uint256, bytes4)
|
|
1594
|
+
Data: 0x0000000000000000000000000000000000000000000000000000000000000001deadbeef (36 bytes)]
|
|
1595
|
+
`)
|
|
1596
|
+
|
|
1597
|
+
expect(() =>
|
|
1598
|
+
AbiParameters.decode(
|
|
1599
|
+
AbiParameters.from('bytes4[2]'),
|
|
1600
|
+
'0xdeadbeef00000000000000000000000000000000000000000000000000000000cafebabe',
|
|
1601
|
+
),
|
|
1602
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
1603
|
+
[AbiParameters.DataSizeTooSmallError: Data size of 36 bytes is too small for given parameters.
|
|
1604
|
+
|
|
1605
|
+
Params: (bytes4[2])
|
|
1606
|
+
Data: 0xdeadbeef00000000000000000000000000000000000000000000000000000000cafebabe (36 bytes)]
|
|
1607
|
+
`)
|
|
1608
|
+
|
|
1609
|
+
expect(() =>
|
|
1610
|
+
AbiParameters.decode(
|
|
1611
|
+
AbiParameters.from('bytes4[]'),
|
|
1612
|
+
'0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001deadbeef',
|
|
1613
|
+
),
|
|
1614
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
1615
|
+
[AbiParameters.DataSizeTooSmallError: Data size of 68 bytes is too small for given parameters.
|
|
1616
|
+
|
|
1617
|
+
Params: (bytes4[])
|
|
1618
|
+
Data: 0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001deadbeef (68 bytes)]
|
|
1619
|
+
`)
|
|
1620
|
+
})
|
|
1621
|
+
|
|
1561
1622
|
test('invalid type', () => {
|
|
1562
1623
|
expect(() =>
|
|
1563
1624
|
AbiParameters.decode(
|
|
@@ -1802,6 +1863,88 @@ test('recursive 2', () => {
|
|
|
1802
1863
|
)
|
|
1803
1864
|
})
|
|
1804
1865
|
|
|
1866
|
+
describe('read size', () => {
|
|
1867
|
+
test('behavior: parameters sharing one tail', () => {
|
|
1868
|
+
expect(
|
|
1869
|
+
AbiParameters.decode(
|
|
1870
|
+
AbiParameters.from('bytes, string, bytes'),
|
|
1871
|
+
Hex.concat(
|
|
1872
|
+
'0x0000000000000000000000000000000000000000000000000000000000000060', // ptr
|
|
1873
|
+
'0x0000000000000000000000000000000000000000000000000000000000000060', // same ptr
|
|
1874
|
+
'0x0000000000000000000000000000000000000000000000000000000000000060', // same ptr
|
|
1875
|
+
'0x0000000000000000000000000000000000000000000000000000000000000004', // len=4
|
|
1876
|
+
'0x7761676d00000000000000000000000000000000000000000000000000000000',
|
|
1877
|
+
),
|
|
1878
|
+
),
|
|
1879
|
+
).toMatchInlineSnapshot(`
|
|
1880
|
+
[
|
|
1881
|
+
"0x7761676d",
|
|
1882
|
+
"wagm",
|
|
1883
|
+
"0x7761676d",
|
|
1884
|
+
]
|
|
1885
|
+
`)
|
|
1886
|
+
})
|
|
1887
|
+
|
|
1888
|
+
test('behavior: array elements sharing one tail', () => {
|
|
1889
|
+
const length = 1_000
|
|
1890
|
+
const tail = Hex.fromBytes(new Uint8Array(256).fill(0xab))
|
|
1891
|
+
// Each element points at the tail that follows the offsets.
|
|
1892
|
+
const offset = Hex.fromNumber(32 * length, { size: 32 })
|
|
1893
|
+
const data = Hex.concat(
|
|
1894
|
+
Hex.fromNumber(32, { size: 32 }), // ptr
|
|
1895
|
+
Hex.fromNumber(length, { size: 32 }), // len
|
|
1896
|
+
...Array.from({ length }, () => offset),
|
|
1897
|
+
Hex.fromNumber(256, { size: 32 }), // len of tail
|
|
1898
|
+
tail,
|
|
1899
|
+
)
|
|
1900
|
+
const [value] = AbiParameters.decode(AbiParameters.from('bytes[]'), data)
|
|
1901
|
+
expect(value).toEqual(Array.from({ length }, () => tail))
|
|
1902
|
+
})
|
|
1903
|
+
|
|
1904
|
+
test('error: array elements sharing one large tail', () => {
|
|
1905
|
+
// 33 elements point at one 64 KiB tail, so the decoded value would be
|
|
1906
|
+
// 33 times the size of the data.
|
|
1907
|
+
const length = 33
|
|
1908
|
+
const tail = Hex.fromBytes(new Uint8Array(65_536).fill(0xab))
|
|
1909
|
+
const data = Hex.concat(
|
|
1910
|
+
Hex.fromNumber(32, { size: 32 }), // ptr
|
|
1911
|
+
Hex.fromNumber(length, { size: 32 }), // len
|
|
1912
|
+
...Array.from({ length }, () =>
|
|
1913
|
+
Hex.fromNumber(32 * length, { size: 32 }),
|
|
1914
|
+
),
|
|
1915
|
+
Hex.fromNumber(65_536, { size: 32 }), // len of tail
|
|
1916
|
+
tail,
|
|
1917
|
+
)
|
|
1918
|
+
expect(Hex.size(data)).toMatchInlineSnapshot(`66688`)
|
|
1919
|
+
expect(() =>
|
|
1920
|
+
AbiParameters.decode(AbiParameters.from('bytes[]'), data),
|
|
1921
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1922
|
+
`[Cursor.ReadSizeLimitExceededError: Read size limit of \`395520\` bytes exceeded (read size: \`459264\` bytes).]`,
|
|
1923
|
+
)
|
|
1924
|
+
})
|
|
1925
|
+
|
|
1926
|
+
test('error: array elements with overlapping tails', () => {
|
|
1927
|
+
// Each element starts 33 bytes after the previous one and runs to the end
|
|
1928
|
+
// of the data.
|
|
1929
|
+
const length = 512
|
|
1930
|
+
const start = 64 + 32 * length
|
|
1931
|
+
const data = new Uint8Array(start + 33 * length)
|
|
1932
|
+
const view = new DataView(data.buffer)
|
|
1933
|
+
view.setUint32(28, 32) // ptr
|
|
1934
|
+
view.setUint32(60, length) // len
|
|
1935
|
+
for (let i = 0; i < length; i++) {
|
|
1936
|
+
const position = start + 33 * i
|
|
1937
|
+
view.setUint32(64 + 32 * i + 28, position - 64)
|
|
1938
|
+
view.setUint32(position + 28, data.length - position - 32)
|
|
1939
|
+
}
|
|
1940
|
+
expect(() =>
|
|
1941
|
+
AbiParameters.decode(AbiParameters.from('bytes[]'), data),
|
|
1942
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1943
|
+
`[Cursor.ReadSizeLimitExceededError: Read size limit of \`328832\` bytes exceeded (read size: \`332354\` bytes).]`,
|
|
1944
|
+
)
|
|
1945
|
+
})
|
|
1946
|
+
})
|
|
1947
|
+
|
|
1805
1948
|
describe('zero-width types', () => {
|
|
1806
1949
|
test('zero-length fixed array', () => {
|
|
1807
1950
|
expect(
|
|
@@ -348,6 +348,16 @@ describe('static', () => {
|
|
|
348
348
|
`[AbiParameters.BytesSizeMismatchError: Size of bytes "0x0000000000000000000000000000000000000000000000000000000000000000000000000123456789abcdef" (bytes44) does not match expected size (bytes8).]`,
|
|
349
349
|
)
|
|
350
350
|
})
|
|
351
|
+
|
|
352
|
+
test('error: invalid hex', () => {
|
|
353
|
+
expect(() =>
|
|
354
|
+
AbiParameters.encode([{ type: 'bytes8' }], ['0x0123456789abcdeg']),
|
|
355
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
356
|
+
[Hex.InvalidHexValueError: Value \`0x0123456789abcdeg\` is an invalid hex value.
|
|
357
|
+
|
|
358
|
+
Hex values must start with \`"0x"\` and contain only hexadecimal characters (0-9, a-f, A-F).]
|
|
359
|
+
`)
|
|
360
|
+
})
|
|
351
361
|
})
|
|
352
362
|
|
|
353
363
|
describe('bytes16', () => {
|
|
@@ -744,7 +754,7 @@ describe('static', () => {
|
|
|
744
754
|
type: 'tuple',
|
|
745
755
|
},
|
|
746
756
|
],
|
|
747
|
-
[[69, ['
|
|
757
|
+
[[69, ['0x1230', '0x4560']]],
|
|
748
758
|
),
|
|
749
759
|
).toMatchInlineSnapshot(
|
|
750
760
|
'"0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004500000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000002123000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024560000000000000000000000000000000000000000000000000000000000000"',
|
|
@@ -1825,6 +1835,31 @@ test('invalid bytes', () => {
|
|
|
1825
1835
|
)
|
|
1826
1836
|
})
|
|
1827
1837
|
|
|
1838
|
+
test('odd-length bytes', () => {
|
|
1839
|
+
expect(() => AbiParameters.encode([{ name: 'x', type: 'bytes2' }], ['0x123']))
|
|
1840
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
1841
|
+
[Hex.InvalidLengthError: Hex value \`"0x123"\` is an odd length (3 nibbles).
|
|
1842
|
+
|
|
1843
|
+
It must be an even length.]
|
|
1844
|
+
`)
|
|
1845
|
+
expect(() => AbiParameters.encode([{ name: 'x', type: 'bytes' }], ['0x123']))
|
|
1846
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
1847
|
+
[Hex.InvalidLengthError: Hex value \`"0x123"\` is an odd length (3 nibbles).
|
|
1848
|
+
|
|
1849
|
+
It must be an even length.]
|
|
1850
|
+
`)
|
|
1851
|
+
expect(() =>
|
|
1852
|
+
AbiParameters.encode(
|
|
1853
|
+
[{ name: 'x', type: 'bytes2[]' }],
|
|
1854
|
+
[['0x0123', '0x123']],
|
|
1855
|
+
),
|
|
1856
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
1857
|
+
[Hex.InvalidLengthError: Hex value \`"0x123"\` is an odd length (3 nibbles).
|
|
1858
|
+
|
|
1859
|
+
It must be an even length.]
|
|
1860
|
+
`)
|
|
1861
|
+
})
|
|
1862
|
+
|
|
1828
1863
|
test('invalid bytes type', () => {
|
|
1829
1864
|
expect(() =>
|
|
1830
1865
|
AbiParameters.encode([{ name: 'x', type: 'bytes0' }], ['0x']),
|
|
@@ -243,6 +243,21 @@ describe('encodePacked', () => {
|
|
|
243
243
|
)
|
|
244
244
|
})
|
|
245
245
|
|
|
246
|
+
test('error: odd-length bytes', () => {
|
|
247
|
+
expect(() => AbiParameters.encodePacked(['bytes', 'uint8'], ['0x123', 1]))
|
|
248
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
249
|
+
[Hex.InvalidLengthError: Hex value \`"0x123"\` is an odd length (3 nibbles).
|
|
250
|
+
|
|
251
|
+
It must be an even length.]
|
|
252
|
+
`)
|
|
253
|
+
expect(() => AbiParameters.encodePacked(['bytes[]'], [['0x0123', '0x123']]))
|
|
254
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
255
|
+
[Hex.InvalidLengthError: Hex value \`"0x123"\` is an odd length (3 nibbles).
|
|
256
|
+
|
|
257
|
+
It must be an even length.]
|
|
258
|
+
`)
|
|
259
|
+
})
|
|
260
|
+
|
|
246
261
|
test('error: unsupported type', () => {
|
|
247
262
|
expect(
|
|
248
263
|
// @ts-expect-error
|
|
@@ -145,6 +145,47 @@ describe('Address.fromPublicKey', () => {
|
|
|
145
145
|
),
|
|
146
146
|
).toEqual('0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266')
|
|
147
147
|
})
|
|
148
|
+
|
|
149
|
+
test('error: compressed public key', () => {
|
|
150
|
+
const publicKey = PublicKey.from(
|
|
151
|
+
'0x048318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed753547f11ca8696646f2f3acb08e31016afac23e630c5d11f59f61fef57b0d2aa5',
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
expect(() => Address.fromPublicKey(PublicKey.compress(publicKey) as never))
|
|
155
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
156
|
+
[PublicKey.InvalidError: Value \`{"prefix":3,"x":"0x8318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed75"}\` is not a valid public key.
|
|
157
|
+
|
|
158
|
+
Public key must contain:
|
|
159
|
+
- an \`x\` and \`prefix\` value (compressed)
|
|
160
|
+
- an \`x\`, \`y\`, and \`prefix\` value (uncompressed)]
|
|
161
|
+
`)
|
|
162
|
+
expect(() =>
|
|
163
|
+
Address.fromPublicKey(
|
|
164
|
+
PublicKey.from(
|
|
165
|
+
'0x038318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed75',
|
|
166
|
+
),
|
|
167
|
+
),
|
|
168
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
169
|
+
[PublicKey.InvalidError: Value \`{"prefix":3,"x":"0x8318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed75"}\` is not a valid public key.
|
|
170
|
+
|
|
171
|
+
Public key must contain:
|
|
172
|
+
- an \`x\` and \`prefix\` value (compressed)
|
|
173
|
+
- an \`x\`, \`y\`, and \`prefix\` value (uncompressed)]
|
|
174
|
+
`)
|
|
175
|
+
expect(() =>
|
|
176
|
+
Address.fromPublicKey(
|
|
177
|
+
PublicKey.from(
|
|
178
|
+
'0x028318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed75',
|
|
179
|
+
),
|
|
180
|
+
),
|
|
181
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
182
|
+
[PublicKey.InvalidError: Value \`{"prefix":2,"x":"0x8318535b54105d4a7aae60c08fc45f9687181b4fdfc625bd1a753fa7397fed75"}\` is not a valid public key.
|
|
183
|
+
|
|
184
|
+
Public key must contain:
|
|
185
|
+
- an \`x\` and \`prefix\` value (compressed)
|
|
186
|
+
- an \`x\`, \`y\`, and \`prefix\` value (uncompressed)]
|
|
187
|
+
`)
|
|
188
|
+
})
|
|
148
189
|
})
|
|
149
190
|
|
|
150
191
|
describe('Address.isEqual', () => {
|
|
@@ -174,6 +174,36 @@ describe('fromRpc', () => {
|
|
|
174
174
|
`)
|
|
175
175
|
})
|
|
176
176
|
|
|
177
|
+
test('error: chainId above safe integer range', () => {
|
|
178
|
+
expect(() =>
|
|
179
|
+
Authorization.fromRpc({
|
|
180
|
+
address: '0x0000000000000000000000000000000000000000',
|
|
181
|
+
chainId: '0x20000000000001',
|
|
182
|
+
nonce: '0x1',
|
|
183
|
+
r: '0x635dc2033e60185bb36709c29c75d64ea51dfbd91c32ef4be198e4ceb169fb4d',
|
|
184
|
+
s: '0x50c2667ac4c771072746acfdcf1f1483336dcca8bd2df47cd83175dbe60f0540',
|
|
185
|
+
yParity: '0x0',
|
|
186
|
+
}),
|
|
187
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
188
|
+
`[Hex.IntegerOutOfRangeError: Number \`9007199254740992\` is not in safe unsigned integer range (\`0\` to \`9007199254740991\`)]`,
|
|
189
|
+
)
|
|
190
|
+
})
|
|
191
|
+
|
|
192
|
+
test('error: chainId empty quantity', () => {
|
|
193
|
+
expect(() =>
|
|
194
|
+
Authorization.fromRpc({
|
|
195
|
+
address: '0x0000000000000000000000000000000000000000',
|
|
196
|
+
chainId: '0x',
|
|
197
|
+
nonce: '0x1',
|
|
198
|
+
r: '0x635dc2033e60185bb36709c29c75d64ea51dfbd91c32ef4be198e4ceb169fb4d',
|
|
199
|
+
s: '0x50c2667ac4c771072746acfdcf1f1483336dcca8bd2df47cd83175dbe60f0540',
|
|
200
|
+
yParity: '0x0',
|
|
201
|
+
}),
|
|
202
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
203
|
+
`[Hex.IntegerOutOfRangeError: Number \`NaN\` is not in safe unsigned integer range (\`0\` to \`9007199254740991\`)]`,
|
|
204
|
+
)
|
|
205
|
+
})
|
|
206
|
+
|
|
177
207
|
test('error: yParity above 2**8 - 1', () => {
|
|
178
208
|
expect(() =>
|
|
179
209
|
Authorization.fromRpc({
|
|
@@ -267,6 +297,36 @@ describe('fromTuple', () => {
|
|
|
267
297
|
`)
|
|
268
298
|
})
|
|
269
299
|
|
|
300
|
+
test('behavior: chainId at safe integer limit', () => {
|
|
301
|
+
const tuple = [
|
|
302
|
+
'0x1fffffffffffff',
|
|
303
|
+
'0x0000000000000000000000000000000000000000',
|
|
304
|
+
'0x3',
|
|
305
|
+
] as const satisfies Authorization.Tuple
|
|
306
|
+
const authorization = Authorization.fromTuple(tuple)
|
|
307
|
+
expect(authorization).toMatchInlineSnapshot(`
|
|
308
|
+
{
|
|
309
|
+
"address": "0x0000000000000000000000000000000000000000",
|
|
310
|
+
"chainId": 9007199254740991,
|
|
311
|
+
"nonce": 3n,
|
|
312
|
+
}
|
|
313
|
+
`)
|
|
314
|
+
expect(Authorization.toTuple(authorization)).toEqual(tuple)
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
test('error: chainId above safe integer range', () => {
|
|
318
|
+
const tuple = [
|
|
319
|
+
'0x20000000000001',
|
|
320
|
+
'0x0000000000000000000000000000000000000000',
|
|
321
|
+
'0x3',
|
|
322
|
+
] as const satisfies Authorization.Tuple
|
|
323
|
+
expect(() =>
|
|
324
|
+
Authorization.fromTuple(tuple),
|
|
325
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
326
|
+
`[Hex.IntegerOutOfRangeError: Number \`9007199254740992\` is not in safe unsigned integer range (\`0\` to \`9007199254740991\`)]`,
|
|
327
|
+
)
|
|
328
|
+
})
|
|
329
|
+
|
|
270
330
|
test('behavior: signature', () => {
|
|
271
331
|
const tuple = [
|
|
272
332
|
'0x1',
|
|
@@ -326,6 +386,75 @@ describe('fromTuple', () => {
|
|
|
326
386
|
`[Hex.IntegerOutOfRangeError: Number \`256\` is not in safe 8-bit unsigned integer range (\`0\` to \`255\`)]`,
|
|
327
387
|
)
|
|
328
388
|
})
|
|
389
|
+
|
|
390
|
+
test('behavior: round trip', () => {
|
|
391
|
+
const unsigned = [
|
|
392
|
+
'0x1',
|
|
393
|
+
'0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
|
|
394
|
+
'0x3',
|
|
395
|
+
] as const satisfies Authorization.Tuple
|
|
396
|
+
const signed = [
|
|
397
|
+
...unsigned,
|
|
398
|
+
'0x01',
|
|
399
|
+
'0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90',
|
|
400
|
+
'0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064',
|
|
401
|
+
] as const satisfies Authorization.Tuple
|
|
402
|
+
expect(Authorization.toTuple(Authorization.fromTuple(unsigned))).toEqual(
|
|
403
|
+
unsigned,
|
|
404
|
+
)
|
|
405
|
+
expect(Authorization.toTuple(Authorization.fromTuple(signed))).toEqual(
|
|
406
|
+
signed,
|
|
407
|
+
)
|
|
408
|
+
})
|
|
409
|
+
|
|
410
|
+
test('error: 4 fields', () => {
|
|
411
|
+
expect(() =>
|
|
412
|
+
Authorization.fromTuple([
|
|
413
|
+
'0x01',
|
|
414
|
+
'0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
|
|
415
|
+
'0x03',
|
|
416
|
+
'0x01',
|
|
417
|
+
] as never),
|
|
418
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
419
|
+
[Authorization.InvalidError: Invalid authorization.
|
|
420
|
+
|
|
421
|
+
Details: Expected [chainId, address, nonce] or [chainId, address, nonce, yParity, r, s].]
|
|
422
|
+
`)
|
|
423
|
+
})
|
|
424
|
+
|
|
425
|
+
test('error: 5 fields', () => {
|
|
426
|
+
expect(() =>
|
|
427
|
+
Authorization.fromTuple([
|
|
428
|
+
'0x01',
|
|
429
|
+
'0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
|
|
430
|
+
'0x03',
|
|
431
|
+
'0x01',
|
|
432
|
+
'0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90',
|
|
433
|
+
] as never),
|
|
434
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
435
|
+
[Authorization.InvalidError: Invalid authorization.
|
|
436
|
+
|
|
437
|
+
Details: Expected [chainId, address, nonce] or [chainId, address, nonce, yParity, r, s].]
|
|
438
|
+
`)
|
|
439
|
+
})
|
|
440
|
+
|
|
441
|
+
test('error: 7 fields', () => {
|
|
442
|
+
expect(() =>
|
|
443
|
+
Authorization.fromTuple([
|
|
444
|
+
'0x01',
|
|
445
|
+
'0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c',
|
|
446
|
+
'0x03',
|
|
447
|
+
'0x01',
|
|
448
|
+
'0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90',
|
|
449
|
+
'0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064',
|
|
450
|
+
'0xdeadbeef',
|
|
451
|
+
] as never),
|
|
452
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
453
|
+
[Authorization.InvalidError: Invalid authorization.
|
|
454
|
+
|
|
455
|
+
Details: Expected [chainId, address, nonce] or [chainId, address, nonce, yParity, r, s].]
|
|
456
|
+
`)
|
|
457
|
+
})
|
|
329
458
|
})
|
|
330
459
|
|
|
331
460
|
describe('fromTupleList', () => {
|
|
@@ -811,6 +940,7 @@ test('exports', () => {
|
|
|
811
940
|
"toRpcList",
|
|
812
941
|
"toTuple",
|
|
813
942
|
"toTupleList",
|
|
943
|
+
"InvalidError",
|
|
814
944
|
]
|
|
815
945
|
`)
|
|
816
946
|
})
|
|
@@ -1371,6 +1371,39 @@ describe('toBigInt', () => {
|
|
|
1371
1371
|
).toMatchInlineSnapshot('4206942069420694206942069420694206942069n')
|
|
1372
1372
|
})
|
|
1373
1373
|
|
|
1374
|
+
test('behavior: zero-padded values', () => {
|
|
1375
|
+
for (const value of [
|
|
1376
|
+
0n,
|
|
1377
|
+
2n ** 48n - 1n,
|
|
1378
|
+
2n ** 48n,
|
|
1379
|
+
2n ** 64n - 1n,
|
|
1380
|
+
2n ** 64n,
|
|
1381
|
+
2n ** 72n + 1n,
|
|
1382
|
+
2n ** 200n + 12345n,
|
|
1383
|
+
2n ** 256n - 1n,
|
|
1384
|
+
])
|
|
1385
|
+
for (const size of [32, 33, 40, 47])
|
|
1386
|
+
expect(Bytes.toBigInt(Bytes.fromNumber(value, { size }))).toBe(value)
|
|
1387
|
+
})
|
|
1388
|
+
|
|
1389
|
+
test('behavior: values wider than 64 bytes', () => {
|
|
1390
|
+
const ones = new Uint8Array(65).fill(0xff)
|
|
1391
|
+
expect(Bytes.toBigInt(ones)).toEqual((1n << 520n) - 1n)
|
|
1392
|
+
expect(Bytes.toBigInt(ones, { signed: true })).toEqual(-1n)
|
|
1393
|
+
|
|
1394
|
+
const high = new Uint8Array(65)
|
|
1395
|
+
high[0] = 0x80
|
|
1396
|
+
expect(Bytes.toBigInt(high)).toEqual(1n << 519n)
|
|
1397
|
+
expect(Bytes.toBigInt(high, { signed: true })).toEqual(-(1n << 519n))
|
|
1398
|
+
|
|
1399
|
+
// Leading zeros, read from an offset into a larger buffer.
|
|
1400
|
+
const padded = new Uint8Array(101).fill(0x01).subarray(1)
|
|
1401
|
+
padded.fill(0, 0, 20)
|
|
1402
|
+
expect(Bytes.toBigInt(padded, { signed: true })).toEqual(
|
|
1403
|
+
BigInt(`0x${'01'.repeat(80)}`),
|
|
1404
|
+
)
|
|
1405
|
+
})
|
|
1406
|
+
|
|
1374
1407
|
test('args: size', () => {
|
|
1375
1408
|
expect(
|
|
1376
1409
|
Bytes.toBigInt(Bytes.fromNumber(420n, { size: 32 }), {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbiItem, Caches } from 'ox'
|
|
1
|
+
import { AbiItem, Caches, Engine } from 'ox'
|
|
2
2
|
import { expect, test } from 'vp/test'
|
|
3
3
|
import { caches } from '../internal/caches.js'
|
|
4
4
|
|
|
@@ -27,3 +27,22 @@ test('behavior: clears signature hashes', () => {
|
|
|
27
27
|
Caches.clear()
|
|
28
28
|
expect(caches.signatureHash.size).toBe(0)
|
|
29
29
|
})
|
|
30
|
+
|
|
31
|
+
test('behavior: an engine change re-derives ABI item signature hashes', () => {
|
|
32
|
+
const abiItem = {
|
|
33
|
+
inputs: [{ type: 'uint256' }],
|
|
34
|
+
name: 'ownerOf',
|
|
35
|
+
outputs: [],
|
|
36
|
+
stateMutability: 'view',
|
|
37
|
+
type: 'function',
|
|
38
|
+
} as const
|
|
39
|
+
const hash = AbiItem.getSignatureHash(abiItem)
|
|
40
|
+
expect(
|
|
41
|
+
Engine.with({ Hash: { keccak256: () => new Uint8Array(32) } }, () =>
|
|
42
|
+
AbiItem.getSignatureHash(abiItem),
|
|
43
|
+
),
|
|
44
|
+
).toMatchInlineSnapshot(
|
|
45
|
+
`"0x0000000000000000000000000000000000000000000000000000000000000000"`,
|
|
46
|
+
)
|
|
47
|
+
expect(AbiItem.getSignatureHash(abiItem)).toBe(hash)
|
|
48
|
+
})
|
|
@@ -225,6 +225,15 @@ describe('encode', () => {
|
|
|
225
225
|
expect(() => Cbor.encode(num)).toThrow(Cbor.NumberTooLargeError)
|
|
226
226
|
})
|
|
227
227
|
|
|
228
|
+
test('number too large error names the encodable range', () => {
|
|
229
|
+
expect(() => Cbor.encode(0x100000000)).toThrow(
|
|
230
|
+
'Number is outside the encodable integer range (-4294967296 to 4294967295): 4294967296',
|
|
231
|
+
)
|
|
232
|
+
expect(() => Cbor.encode(-0x100000001)).toThrow(
|
|
233
|
+
'Number is outside the encodable integer range (-4294967296 to 4294967295): -4294967297',
|
|
234
|
+
)
|
|
235
|
+
})
|
|
236
|
+
|
|
228
237
|
test('bigint throws', () => {
|
|
229
238
|
expect(() => Cbor.encode(BigInt(42))).toThrow(Cbor.UnsupportedBigIntError)
|
|
230
239
|
})
|
|
@@ -510,6 +519,23 @@ describe('decode', () => {
|
|
|
510
519
|
expect(() => Cbor.decode('0x123')).toThrow()
|
|
511
520
|
})
|
|
512
521
|
|
|
522
|
+
test('error: nesting deeper than the depth limit', () => {
|
|
523
|
+
// `0x81` opens a one-element array.
|
|
524
|
+
expect(
|
|
525
|
+
Cbor.decode(new Uint8Array([...new Uint8Array(1_023).fill(0x81), 0x01])),
|
|
526
|
+
).toBeDefined()
|
|
527
|
+
expect(() =>
|
|
528
|
+
Cbor.decode(new Uint8Array([...new Uint8Array(1_024).fill(0x81), 0x01])),
|
|
529
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
530
|
+
`[Cbor.DepthLimitExceededError: CBOR depth limit of \`1024\` exceeded.]`,
|
|
531
|
+
)
|
|
532
|
+
expect(() =>
|
|
533
|
+
Cbor.decode(new Uint8Array(100_000).fill(0x81)),
|
|
534
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
535
|
+
`[Cbor.DepthLimitExceededError: CBOR depth limit of \`1024\` exceeded.]`,
|
|
536
|
+
)
|
|
537
|
+
})
|
|
538
|
+
|
|
513
539
|
test('large string (> 0xffff)', () => {
|
|
514
540
|
const str = 'a'.repeat(0x10000)
|
|
515
541
|
const encoded = Cbor.encode(str)
|