ox 1.8.15 → 1.8.16
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 +66 -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 +4 -2
- package/dist/core/AbiEvent.d.ts.map +1 -1
- package/dist/core/AbiEvent.js +62 -36
- 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/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/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/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/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 +9 -9
- 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 +1 -1
- package/dist/core/internal/abiParameters.d.ts.map +1 -1
- package/dist/core/internal/abiParameters.js +7 -2
- package/dist/core/internal/abiParameters.js.map +1 -1
- package/dist/core/internal/cursor.d.ts +13 -0
- package/dist/core/internal/cursor.d.ts.map +1 -1
- package/dist/core/internal/cursor.js +27 -0
- package/dist/core/internal/cursor.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/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 +46 -13
- package/dist/tempo/SignatureEnvelope.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/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/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 +24 -14
- package/dist/zod/tempo/SignatureEnvelope.js.map +1 -1
- package/package.json +1 -1
- package/src/core/AbiError.ts +82 -8
- package/src/core/AbiEvent.ts +90 -45
- package/src/core/AbiFunction.ts +76 -4
- package/src/core/Address.ts +18 -1
- package/src/core/Authorization.ts +34 -4
- package/src/core/Keystore.ts +40 -3
- package/src/core/Secp256k1.ts +4 -1
- package/src/core/Signature.ts +7 -3
- package/src/core/Siwe.ts +29 -3
- 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.ts +10 -9
- 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 +563 -11
- package/src/core/_test/AbiFunction.test.ts +74 -2
- package/src/core/_test/AbiParameters.adversarial.fuzz.ts +1 -0
- package/src/core/_test/AbiParameters.decode.test.ts +110 -0
- package/src/core/_test/AbiParameters.encode.test.ts +26 -1
- package/src/core/_test/Address.test.ts +41 -0
- package/src/core/_test/Authorization.test.ts +130 -0
- package/src/core/_test/Keystore.test.ts +65 -1
- 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/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/TypedData.test.ts +178 -0
- package/src/core/_test/Value.test.ts +21 -0
- package/src/core/_test/internal/cursor.test.ts +35 -0
- package/src/core/internal/abiParameters.ts +7 -2
- package/src/core/internal/cursor.ts +36 -0
- package/src/erc4337/UserOperation.ts +3 -4
- package/src/erc4337/_test/UserOperation.test.ts +59 -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 +211 -27
- package/src/tempo/SignatureEnvelope.ts +55 -11
- 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/configurableAccounts.e2e.test.ts +1 -1
- 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 +31 -16
- package/src/zod/tempo/_test/KeyAuthorization.test.ts +36 -0
- package/src/zod/tempo/_test/SignatureEnvelope.test.ts +101 -3
|
@@ -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', () => {
|
|
@@ -254,9 +325,9 @@ describe('encodeData', () => {
|
|
|
254
325
|
test('behavior: malformed bytes compatibility', () => {
|
|
255
326
|
const abiFunction = AbiFunction.from('function foo(bytes)')
|
|
256
327
|
expect(
|
|
257
|
-
AbiFunction.encodeData(abiFunction, ['
|
|
328
|
+
AbiFunction.encodeData(abiFunction, ['0xzz11']),
|
|
258
329
|
).toMatchInlineSnapshot(
|
|
259
|
-
`"
|
|
330
|
+
`"0x30c8d1da00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002zz11000000000000000000000000000000000000000000000000000000000000"`,
|
|
260
331
|
)
|
|
261
332
|
})
|
|
262
333
|
|
|
@@ -1362,6 +1433,7 @@ test('exports', () => {
|
|
|
1362
1433
|
"from",
|
|
1363
1434
|
"fromAbi",
|
|
1364
1435
|
"getSelector",
|
|
1436
|
+
"SelectorMismatchError",
|
|
1365
1437
|
]
|
|
1366
1438
|
`)
|
|
1367
1439
|
})
|
|
@@ -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',
|
|
@@ -1558,6 +1558,56 @@ test('data size too small', () => {
|
|
|
1558
1558
|
`)
|
|
1559
1559
|
})
|
|
1560
1560
|
|
|
1561
|
+
test('data size too small: fixed-size bytes', () => {
|
|
1562
|
+
expect(
|
|
1563
|
+
AbiParameters.decode(
|
|
1564
|
+
AbiParameters.from('uint256, bytes4'),
|
|
1565
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001deadbeef00000000000000000000000000000000000000000000000000000000',
|
|
1566
|
+
),
|
|
1567
|
+
).toMatchInlineSnapshot(`
|
|
1568
|
+
[
|
|
1569
|
+
1n,
|
|
1570
|
+
"0xdeadbeef",
|
|
1571
|
+
]
|
|
1572
|
+
`)
|
|
1573
|
+
|
|
1574
|
+
expect(() =>
|
|
1575
|
+
AbiParameters.decode(
|
|
1576
|
+
AbiParameters.from('uint256, bytes4'),
|
|
1577
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001deadbeef',
|
|
1578
|
+
),
|
|
1579
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
1580
|
+
[AbiParameters.DataSizeTooSmallError: Data size of 36 bytes is too small for given parameters.
|
|
1581
|
+
|
|
1582
|
+
Params: (uint256, bytes4)
|
|
1583
|
+
Data: 0x0000000000000000000000000000000000000000000000000000000000000001deadbeef (36 bytes)]
|
|
1584
|
+
`)
|
|
1585
|
+
|
|
1586
|
+
expect(() =>
|
|
1587
|
+
AbiParameters.decode(
|
|
1588
|
+
AbiParameters.from('bytes4[2]'),
|
|
1589
|
+
'0xdeadbeef00000000000000000000000000000000000000000000000000000000cafebabe',
|
|
1590
|
+
),
|
|
1591
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
1592
|
+
[AbiParameters.DataSizeTooSmallError: Data size of 36 bytes is too small for given parameters.
|
|
1593
|
+
|
|
1594
|
+
Params: (bytes4[2])
|
|
1595
|
+
Data: 0xdeadbeef00000000000000000000000000000000000000000000000000000000cafebabe (36 bytes)]
|
|
1596
|
+
`)
|
|
1597
|
+
|
|
1598
|
+
expect(() =>
|
|
1599
|
+
AbiParameters.decode(
|
|
1600
|
+
AbiParameters.from('bytes4[]'),
|
|
1601
|
+
'0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001deadbeef',
|
|
1602
|
+
),
|
|
1603
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
1604
|
+
[AbiParameters.DataSizeTooSmallError: Data size of 68 bytes is too small for given parameters.
|
|
1605
|
+
|
|
1606
|
+
Params: (bytes4[])
|
|
1607
|
+
Data: 0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001deadbeef (68 bytes)]
|
|
1608
|
+
`)
|
|
1609
|
+
})
|
|
1610
|
+
|
|
1561
1611
|
test('invalid type', () => {
|
|
1562
1612
|
expect(() =>
|
|
1563
1613
|
AbiParameters.decode(
|
|
@@ -1802,6 +1852,66 @@ test('recursive 2', () => {
|
|
|
1802
1852
|
)
|
|
1803
1853
|
})
|
|
1804
1854
|
|
|
1855
|
+
describe('read size', () => {
|
|
1856
|
+
test('behavior: parameters sharing one tail', () => {
|
|
1857
|
+
expect(
|
|
1858
|
+
AbiParameters.decode(
|
|
1859
|
+
AbiParameters.from('bytes, string, bytes'),
|
|
1860
|
+
Hex.concat(
|
|
1861
|
+
'0x0000000000000000000000000000000000000000000000000000000000000060', // ptr
|
|
1862
|
+
'0x0000000000000000000000000000000000000000000000000000000000000060', // same ptr
|
|
1863
|
+
'0x0000000000000000000000000000000000000000000000000000000000000060', // same ptr
|
|
1864
|
+
'0x0000000000000000000000000000000000000000000000000000000000000004', // len=4
|
|
1865
|
+
'0x7761676d00000000000000000000000000000000000000000000000000000000',
|
|
1866
|
+
),
|
|
1867
|
+
),
|
|
1868
|
+
).toMatchInlineSnapshot(`
|
|
1869
|
+
[
|
|
1870
|
+
"0x7761676d",
|
|
1871
|
+
"wagm",
|
|
1872
|
+
"0x7761676d",
|
|
1873
|
+
]
|
|
1874
|
+
`)
|
|
1875
|
+
})
|
|
1876
|
+
|
|
1877
|
+
test('behavior: array elements sharing one tail', () => {
|
|
1878
|
+
const length = 1_000
|
|
1879
|
+
const tail = Hex.fromBytes(new Uint8Array(256).fill(0xab))
|
|
1880
|
+
// Each element points at the tail that follows the offsets.
|
|
1881
|
+
const offset = Hex.fromNumber(32 * length, { size: 32 })
|
|
1882
|
+
const data = Hex.concat(
|
|
1883
|
+
Hex.fromNumber(32, { size: 32 }), // ptr
|
|
1884
|
+
Hex.fromNumber(length, { size: 32 }), // len
|
|
1885
|
+
...Array.from({ length }, () => offset),
|
|
1886
|
+
Hex.fromNumber(256, { size: 32 }), // len of tail
|
|
1887
|
+
tail,
|
|
1888
|
+
)
|
|
1889
|
+
const [value] = AbiParameters.decode(AbiParameters.from('bytes[]'), data)
|
|
1890
|
+
expect(value).toEqual(Array.from({ length }, () => tail))
|
|
1891
|
+
})
|
|
1892
|
+
|
|
1893
|
+
test('error: array elements with overlapping tails', () => {
|
|
1894
|
+
// Each element starts 33 bytes after the previous one and runs to the end
|
|
1895
|
+
// of the data.
|
|
1896
|
+
const length = 512
|
|
1897
|
+
const start = 64 + 32 * length
|
|
1898
|
+
const data = new Uint8Array(start + 33 * length)
|
|
1899
|
+
const view = new DataView(data.buffer)
|
|
1900
|
+
view.setUint32(28, 32) // ptr
|
|
1901
|
+
view.setUint32(60, length) // len
|
|
1902
|
+
for (let i = 0; i < length; i++) {
|
|
1903
|
+
const position = start + 33 * i
|
|
1904
|
+
view.setUint32(64 + 32 * i + 28, position - 64)
|
|
1905
|
+
view.setUint32(position + 28, data.length - position - 32)
|
|
1906
|
+
}
|
|
1907
|
+
expect(() =>
|
|
1908
|
+
AbiParameters.decode(AbiParameters.from('bytes[]'), data),
|
|
1909
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1910
|
+
`[Cursor.ReadSizeLimitExceededError: Read size limit of \`1329152\` bytes exceeded (read size: \`1335257\` bytes).]`,
|
|
1911
|
+
)
|
|
1912
|
+
})
|
|
1913
|
+
})
|
|
1914
|
+
|
|
1805
1915
|
describe('zero-width types', () => {
|
|
1806
1916
|
test('zero-length fixed array', () => {
|
|
1807
1917
|
expect(
|
|
@@ -744,7 +744,7 @@ describe('static', () => {
|
|
|
744
744
|
type: 'tuple',
|
|
745
745
|
},
|
|
746
746
|
],
|
|
747
|
-
[[69, ['
|
|
747
|
+
[[69, ['0x1230', '0x4560']]],
|
|
748
748
|
),
|
|
749
749
|
).toMatchInlineSnapshot(
|
|
750
750
|
'"0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000004500000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000800000000000000000000000000000000000000000000000000000000000000002123000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024560000000000000000000000000000000000000000000000000000000000000"',
|
|
@@ -1825,6 +1825,31 @@ test('invalid bytes', () => {
|
|
|
1825
1825
|
)
|
|
1826
1826
|
})
|
|
1827
1827
|
|
|
1828
|
+
test('odd-length bytes', () => {
|
|
1829
|
+
expect(() => AbiParameters.encode([{ name: 'x', type: 'bytes2' }], ['0x123']))
|
|
1830
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
1831
|
+
[Hex.InvalidLengthError: Hex value \`"0x123"\` is an odd length (3 nibbles).
|
|
1832
|
+
|
|
1833
|
+
It must be an even length.]
|
|
1834
|
+
`)
|
|
1835
|
+
expect(() => AbiParameters.encode([{ name: 'x', type: 'bytes' }], ['0x123']))
|
|
1836
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
1837
|
+
[Hex.InvalidLengthError: Hex value \`"0x123"\` is an odd length (3 nibbles).
|
|
1838
|
+
|
|
1839
|
+
It must be an even length.]
|
|
1840
|
+
`)
|
|
1841
|
+
expect(() =>
|
|
1842
|
+
AbiParameters.encode(
|
|
1843
|
+
[{ name: 'x', type: 'bytes2[]' }],
|
|
1844
|
+
[['0x0123', '0x123']],
|
|
1845
|
+
),
|
|
1846
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
1847
|
+
[Hex.InvalidLengthError: Hex value \`"0x123"\` is an odd length (3 nibbles).
|
|
1848
|
+
|
|
1849
|
+
It must be an even length.]
|
|
1850
|
+
`)
|
|
1851
|
+
})
|
|
1852
|
+
|
|
1828
1853
|
test('invalid bytes type', () => {
|
|
1829
1854
|
expect(() =>
|
|
1830
1855
|
AbiParameters.encode([{ name: 'x', type: 'bytes0' }], ['0x']),
|
|
@@ -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
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Vectors from https://github.com/ethereum/wiki/wiki/Web3-Secret-Storage-Definition
|
|
2
2
|
|
|
3
|
-
import { Bytes, Keystore } from 'ox'
|
|
3
|
+
import { Bytes, Hex, Keystore } from 'ox'
|
|
4
4
|
import { describe, expect, test } from 'vp/test'
|
|
5
5
|
|
|
6
6
|
describe('encrypt/decrypt', () => {
|
|
@@ -320,6 +320,70 @@ describe('encrypt/decrypt', () => {
|
|
|
320
320
|
const decrypted = Keystore.decrypt(encrypted, key())
|
|
321
321
|
expect(decrypted).toEqual(secret)
|
|
322
322
|
})
|
|
323
|
+
|
|
324
|
+
test('behavior: key longer than 32 bytes', () => {
|
|
325
|
+
const [key, opts] = Keystore.scrypt({
|
|
326
|
+
iv: '0x83dbcc02d8ccb40e466191a123791e0e',
|
|
327
|
+
salt: '0xab0c7876052600dd703518d6fc3fe8984592145b591fc8fb5c6d43190334ba19',
|
|
328
|
+
password: 'testpassword',
|
|
329
|
+
n: 1024,
|
|
330
|
+
})
|
|
331
|
+
const longKey = Hex.concat(key(), '0xdeadbeef')
|
|
332
|
+
|
|
333
|
+
const secret =
|
|
334
|
+
'0x7a28b5ba57c53603b0b07b56bba752f7784bf506fa95edc395f5cf6c7514fe9d'
|
|
335
|
+
|
|
336
|
+
const encrypted = Keystore.encrypt(secret, longKey, { ...opts, id: 'id' })
|
|
337
|
+
expect(encrypted).toEqual(
|
|
338
|
+
Keystore.encrypt(secret, key(), { ...opts, id: 'id' }),
|
|
339
|
+
)
|
|
340
|
+
expect(Keystore.decrypt(encrypted, longKey)).toEqual(secret)
|
|
341
|
+
})
|
|
342
|
+
|
|
343
|
+
test('error: key shorter than 32 bytes', () => {
|
|
344
|
+
const [key, opts] = Keystore.scrypt({
|
|
345
|
+
iv: '0x83dbcc02d8ccb40e466191a123791e0e',
|
|
346
|
+
salt: '0xab0c7876052600dd703518d6fc3fe8984592145b591fc8fb5c6d43190334ba19',
|
|
347
|
+
password: 'testpassword',
|
|
348
|
+
n: 1024,
|
|
349
|
+
})
|
|
350
|
+
|
|
351
|
+
const secret =
|
|
352
|
+
'0x7a28b5ba57c53603b0b07b56bba752f7784bf506fa95edc395f5cf6c7514fe9d'
|
|
353
|
+
const encrypted = Keystore.encrypt(secret, key(), opts)
|
|
354
|
+
|
|
355
|
+
expect(() =>
|
|
356
|
+
Keystore.encrypt(secret, Hex.slice(key(), 0, 17), opts),
|
|
357
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
358
|
+
`[Keystore.InvalidKeySizeError: Key must contain at least 32 bytes. Received 17 bytes.]`,
|
|
359
|
+
)
|
|
360
|
+
expect(() =>
|
|
361
|
+
Keystore.encrypt(secret, Hex.slice(key(), 0, 31), opts),
|
|
362
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
363
|
+
`[Keystore.InvalidKeySizeError: Key must contain at least 32 bytes. Received 31 bytes.]`,
|
|
364
|
+
)
|
|
365
|
+
expect(() =>
|
|
366
|
+
Keystore.encrypt(secret, () => Hex.slice(key(), 0, 31), opts),
|
|
367
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
368
|
+
`[Keystore.InvalidKeySizeError: Key must contain at least 32 bytes. Received 31 bytes.]`,
|
|
369
|
+
)
|
|
370
|
+
|
|
371
|
+
expect(() =>
|
|
372
|
+
Keystore.decrypt(encrypted, Hex.slice(key(), 0, 17)),
|
|
373
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
374
|
+
`[Keystore.InvalidKeySizeError: Key must contain at least 32 bytes. Received 17 bytes.]`,
|
|
375
|
+
)
|
|
376
|
+
expect(() =>
|
|
377
|
+
Keystore.decrypt(encrypted, Hex.slice(key(), 0, 31)),
|
|
378
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
379
|
+
`[Keystore.InvalidKeySizeError: Key must contain at least 32 bytes. Received 31 bytes.]`,
|
|
380
|
+
)
|
|
381
|
+
expect(() =>
|
|
382
|
+
Keystore.decrypt(encrypted, () => Hex.slice(key(), 0, 31)),
|
|
383
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
384
|
+
`[Keystore.InvalidKeySizeError: Key must contain at least 32 bytes. Received 31 bytes.]`,
|
|
385
|
+
)
|
|
386
|
+
})
|
|
323
387
|
})
|
|
324
388
|
|
|
325
389
|
describe('pbkdf2', () => {
|
|
@@ -672,6 +672,42 @@ describe('verify', () => {
|
|
|
672
672
|
Secp256k1.verify({ hash: true, publicKey, payload, signature: { r, s } }),
|
|
673
673
|
).toBe(true)
|
|
674
674
|
})
|
|
675
|
+
|
|
676
|
+
test('options: hash w/ address', () => {
|
|
677
|
+
const payload = '0xdeadbeef'
|
|
678
|
+
const publicKey = Secp256k1.getPublicKey({ privateKey })
|
|
679
|
+
|
|
680
|
+
// Signature over `sha256(payload)`.
|
|
681
|
+
{
|
|
682
|
+
const signature = Secp256k1.sign({ hash: true, payload, privateKey })
|
|
683
|
+
expect(
|
|
684
|
+
Secp256k1.verify({ address, hash: true, payload, signature }),
|
|
685
|
+
).toBe(true)
|
|
686
|
+
expect(
|
|
687
|
+
Secp256k1.verify({
|
|
688
|
+
address,
|
|
689
|
+
hash: true,
|
|
690
|
+
payload: Bytes.fromHex(payload),
|
|
691
|
+
signature,
|
|
692
|
+
}),
|
|
693
|
+
).toBe(true)
|
|
694
|
+
expect(
|
|
695
|
+
Secp256k1.verify({ hash: true, payload, publicKey, signature }),
|
|
696
|
+
).toBe(true)
|
|
697
|
+
expect(Secp256k1.verify({ address, payload, signature })).toBe(false)
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// Signature over the payload itself.
|
|
701
|
+
{
|
|
702
|
+
const signature = Secp256k1.sign({ payload, privateKey })
|
|
703
|
+
expect(
|
|
704
|
+
Secp256k1.verify({ address, hash: true, payload, signature }),
|
|
705
|
+
).toBe(false)
|
|
706
|
+
expect(
|
|
707
|
+
Secp256k1.verify({ hash: true, payload, publicKey, signature }),
|
|
708
|
+
).toBe(false)
|
|
709
|
+
}
|
|
710
|
+
})
|
|
675
711
|
})
|
|
676
712
|
|
|
677
713
|
test('exports', () => {
|