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
|
@@ -23,6 +23,34 @@ describe('assert', () => {
|
|
|
23
23
|
)
|
|
24
24
|
})
|
|
25
25
|
|
|
26
|
+
test('invalid chainId (not a positive safe integer)', () => {
|
|
27
|
+
expect(() =>
|
|
28
|
+
TxEnvelopeLegacy.assert({ chainId: Number.NaN }),
|
|
29
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
30
|
+
`[TransactionEnvelope.InvalidChainIdError: Chain ID "NaN" is invalid.]`,
|
|
31
|
+
)
|
|
32
|
+
expect(() =>
|
|
33
|
+
TxEnvelopeLegacy.assert({ chainId: 1.5 }),
|
|
34
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
35
|
+
`[TransactionEnvelope.InvalidChainIdError: Chain ID "1.5" is invalid.]`,
|
|
36
|
+
)
|
|
37
|
+
expect(() =>
|
|
38
|
+
TxEnvelopeLegacy.assert({ chainId: Number.MAX_SAFE_INTEGER + 1 }),
|
|
39
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
40
|
+
`[TransactionEnvelope.InvalidChainIdError: Chain ID "9007199254740992" is invalid.]`,
|
|
41
|
+
)
|
|
42
|
+
expect(() =>
|
|
43
|
+
TxEnvelopeLegacy.assert({ chainId: '1' as never }),
|
|
44
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
45
|
+
`[TransactionEnvelope.InvalidChainIdError: Chain ID "1" is invalid.]`,
|
|
46
|
+
)
|
|
47
|
+
expect(() =>
|
|
48
|
+
TxEnvelopeLegacy.assert({ chainId: 1n as never }),
|
|
49
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
50
|
+
`[TransactionEnvelope.InvalidChainIdError: Chain ID "1" is invalid.]`,
|
|
51
|
+
)
|
|
52
|
+
})
|
|
53
|
+
|
|
26
54
|
test('invalid address', () => {
|
|
27
55
|
expect(() => TxEnvelopeLegacy.assert({ to: '0x123', chainId: 1 }))
|
|
28
56
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
@@ -266,6 +294,35 @@ describe('deserialize', () => {
|
|
|
266
294
|
}
|
|
267
295
|
`)
|
|
268
296
|
})
|
|
297
|
+
|
|
298
|
+
test('largest safe v', () => {
|
|
299
|
+
const serialized = Rlp.fromHex([
|
|
300
|
+
'0x01', // nonce
|
|
301
|
+
'0x02', // gasPrice
|
|
302
|
+
'0x5208', // gas
|
|
303
|
+
'0x70997970c51812dc3a010c7d01b50e0d17dc79c8', // to
|
|
304
|
+
'0x03', // value
|
|
305
|
+
'0x', // data
|
|
306
|
+
Hex.fromNumber(Number.MAX_SAFE_INTEGER), // v
|
|
307
|
+
`0x${'ff'.repeat(32)}`, // r
|
|
308
|
+
`0x${'ff'.repeat(32)}`, // s
|
|
309
|
+
])
|
|
310
|
+
expect(TxEnvelopeLegacy.deserialize(serialized)).toMatchInlineSnapshot(`
|
|
311
|
+
{
|
|
312
|
+
"chainId": 4503599627370478,
|
|
313
|
+
"gas": 21000n,
|
|
314
|
+
"gasPrice": 2n,
|
|
315
|
+
"nonce": 1n,
|
|
316
|
+
"r": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
|
317
|
+
"s": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff",
|
|
318
|
+
"to": "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
|
|
319
|
+
"type": "legacy",
|
|
320
|
+
"v": 9007199254740991,
|
|
321
|
+
"value": 3n,
|
|
322
|
+
"yParity": 0,
|
|
323
|
+
}
|
|
324
|
+
`)
|
|
325
|
+
})
|
|
269
326
|
})
|
|
270
327
|
|
|
271
328
|
describe('errors', () => {
|
|
@@ -362,6 +419,148 @@ describe('deserialize', () => {
|
|
|
362
419
|
'[Signature.InvalidVError: Value `35` is an invalid v value. v must be 27, 28 or >=35.]',
|
|
363
420
|
)
|
|
364
421
|
})
|
|
422
|
+
|
|
423
|
+
const fields = [
|
|
424
|
+
'0x01', // nonce
|
|
425
|
+
'0x02', // gasPrice
|
|
426
|
+
'0x5208', // gas
|
|
427
|
+
'0x70997970c51812dc3a010c7d01b50e0d17dc79c8', // to
|
|
428
|
+
'0x03', // value
|
|
429
|
+
'0x', // data
|
|
430
|
+
] as const
|
|
431
|
+
const word =
|
|
432
|
+
'0x1111111111111111111111111111111111111111111111111111111111111111'
|
|
433
|
+
|
|
434
|
+
test('unsigned: invalid `to`', () => {
|
|
435
|
+
const to = '0x11111111111111111111111111111111111111'
|
|
436
|
+
expect(() =>
|
|
437
|
+
TxEnvelopeLegacy.deserialize(
|
|
438
|
+
Rlp.fromHex(['0x01', '0x02', '0x5208', to, '0x03', '0x']),
|
|
439
|
+
),
|
|
440
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
441
|
+
[Address.InvalidAddressError: Address "0x11111111111111111111111111111111111111" is invalid.
|
|
442
|
+
|
|
443
|
+
Details: Address is not a 20 byte (40 hexadecimal character) value.]
|
|
444
|
+
`)
|
|
445
|
+
expect(() =>
|
|
446
|
+
TxEnvelopeLegacy.deserialize(
|
|
447
|
+
Rlp.fromHex([
|
|
448
|
+
'0x01',
|
|
449
|
+
'0x02',
|
|
450
|
+
'0x5208',
|
|
451
|
+
to,
|
|
452
|
+
'0x03',
|
|
453
|
+
'0x',
|
|
454
|
+
'0x01',
|
|
455
|
+
'0x',
|
|
456
|
+
'0x',
|
|
457
|
+
]),
|
|
458
|
+
),
|
|
459
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
460
|
+
[Address.InvalidAddressError: Address "0x11111111111111111111111111111111111111" is invalid.
|
|
461
|
+
|
|
462
|
+
Details: Address is not a 20 byte (40 hexadecimal character) value.]
|
|
463
|
+
`)
|
|
464
|
+
})
|
|
465
|
+
|
|
466
|
+
test('gasPrice longer than 32 bytes', () => {
|
|
467
|
+
const gasPrice = `0x01${'00'.repeat(32)}` as const
|
|
468
|
+
const [nonce, , ...rest] = fields
|
|
469
|
+
expect(() =>
|
|
470
|
+
TxEnvelopeLegacy.deserialize(Rlp.fromHex([nonce, gasPrice, ...rest])),
|
|
471
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
472
|
+
`[TransactionEnvelope.GasPriceTooHighError: The gas price (\`gasPrice\`) cannot be higher than the maximum allowed value (2^256-1).]`,
|
|
473
|
+
)
|
|
474
|
+
expect(() =>
|
|
475
|
+
TxEnvelopeLegacy.deserialize(
|
|
476
|
+
Rlp.fromHex([nonce, gasPrice, ...rest, '0x25', word, word]),
|
|
477
|
+
),
|
|
478
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
479
|
+
`[TransactionEnvelope.GasPriceTooHighError: The gas price (\`gasPrice\`) cannot be higher than the maximum allowed value (2^256-1).]`,
|
|
480
|
+
)
|
|
481
|
+
})
|
|
482
|
+
|
|
483
|
+
test('r or s longer than 32 bytes', () => {
|
|
484
|
+
expect(() =>
|
|
485
|
+
TxEnvelopeLegacy.deserialize(
|
|
486
|
+
Rlp.fromHex([...fields, '0x25', `${word}11`, word]),
|
|
487
|
+
),
|
|
488
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
489
|
+
`[Signature.InvalidRError: Value \`0x111111111111111111111111111111111111111111111111111111111111111111\` is an invalid r value. r must be a positive integer less than 2^256.]`,
|
|
490
|
+
)
|
|
491
|
+
expect(() =>
|
|
492
|
+
TxEnvelopeLegacy.deserialize(
|
|
493
|
+
Rlp.fromHex([...fields, '0x25', word, `${word}11`]),
|
|
494
|
+
),
|
|
495
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
496
|
+
`[Signature.InvalidSError: Value \`0x111111111111111111111111111111111111111111111111111111111111111111\` is an invalid s value. s must be a positive integer less than 2^256.]`,
|
|
497
|
+
)
|
|
498
|
+
})
|
|
499
|
+
|
|
500
|
+
test('list in place of a field', () => {
|
|
501
|
+
const signed = [...fields, '0x25', word, word] as const
|
|
502
|
+
expect(() =>
|
|
503
|
+
TxEnvelopeLegacy.deserialize(
|
|
504
|
+
Rlp.fromHex([['0x01', '0x02'], ...fields.slice(1)]),
|
|
505
|
+
),
|
|
506
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
507
|
+
[TransactionEnvelope.InvalidSerializedError: Invalid serialized transaction of type "legacy" was provided.
|
|
508
|
+
|
|
509
|
+
Serialized Transaction: "0xdec20102028252089470997970c51812dc3a010c7d01b50e0d17dc79c80380"]
|
|
510
|
+
`)
|
|
511
|
+
for (const tuple of [fields, signed])
|
|
512
|
+
for (let i = 0; i < tuple.length; i++)
|
|
513
|
+
expect(() =>
|
|
514
|
+
TxEnvelopeLegacy.deserialize(
|
|
515
|
+
Rlp.fromHex(tuple.map((x, j) => (i === j ? [x] : x))),
|
|
516
|
+
),
|
|
517
|
+
).toThrowError(
|
|
518
|
+
'Invalid serialized transaction of type "legacy" was provided.',
|
|
519
|
+
)
|
|
520
|
+
expect(() =>
|
|
521
|
+
TxEnvelopeLegacy.deserialize(Rlp.fromHex([...fields, '0x25', [], []])),
|
|
522
|
+
).toThrowError(
|
|
523
|
+
'Invalid serialized transaction of type "legacy" was provided.',
|
|
524
|
+
)
|
|
525
|
+
})
|
|
526
|
+
|
|
527
|
+
test('byte string in place of the list', () => {
|
|
528
|
+
expect(() => TxEnvelopeLegacy.deserialize('0x86aabbccddeeff'))
|
|
529
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
530
|
+
[TransactionEnvelope.InvalidSerializedError: Invalid serialized transaction of type "legacy" was provided.
|
|
531
|
+
|
|
532
|
+
Serialized Transaction: "0x86aabbccddeeff"]
|
|
533
|
+
`)
|
|
534
|
+
})
|
|
535
|
+
|
|
536
|
+
test('v above the safe integer range', () => {
|
|
537
|
+
// 2^53 + 15
|
|
538
|
+
expect(() =>
|
|
539
|
+
TxEnvelopeLegacy.deserialize(
|
|
540
|
+
Rlp.fromHex([...fields, '0x2000000000000f', word, word]),
|
|
541
|
+
),
|
|
542
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
543
|
+
[TransactionEnvelope.InvalidSerializedError: Invalid serialized transaction of type "legacy" was provided.
|
|
544
|
+
|
|
545
|
+
Serialized Transaction: "0xf86601028252089470997970c51812dc3a010c7d01b50e0d17dc79c80380872000000000000fa01111111111111111111111111111111111111111111111111111111111111111a01111111111111111111111111111111111111111111111111111111111111111"]
|
|
546
|
+
`)
|
|
547
|
+
// 2^53 + 1 (unsigned)
|
|
548
|
+
expect(() =>
|
|
549
|
+
TxEnvelopeLegacy.deserialize(
|
|
550
|
+
Rlp.fromHex([...fields, '0x20000000000001', '0x', '0x']),
|
|
551
|
+
),
|
|
552
|
+
).toThrowError(
|
|
553
|
+
'Invalid serialized transaction of type "legacy" was provided.',
|
|
554
|
+
)
|
|
555
|
+
// 2^1100
|
|
556
|
+
expect(() =>
|
|
557
|
+
TxEnvelopeLegacy.deserialize(
|
|
558
|
+
Rlp.fromHex([...fields, `0x10${'00'.repeat(137)}`, word, word]),
|
|
559
|
+
),
|
|
560
|
+
).toThrowError(
|
|
561
|
+
'Invalid serialized transaction of type "legacy" was provided.',
|
|
562
|
+
)
|
|
563
|
+
})
|
|
365
564
|
})
|
|
366
565
|
})
|
|
367
566
|
|
|
@@ -507,6 +706,50 @@ describe('hash', () => {
|
|
|
507
706
|
`"0x5e427e088ae00b084b41e198c52440aa43b2d6f8f1f01246fd25d4e9b6ebfdab"`,
|
|
508
707
|
)
|
|
509
708
|
})
|
|
709
|
+
|
|
710
|
+
test('options: presign: chain ID carried by `v`', () => {
|
|
711
|
+
const unsigned = {
|
|
712
|
+
gas: 21000n,
|
|
713
|
+
gasPrice: 1000000000n,
|
|
714
|
+
nonce: 665n,
|
|
715
|
+
to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
|
716
|
+
value: 1000000000000000000n,
|
|
717
|
+
} as const
|
|
718
|
+
const payload = TxEnvelopeLegacy.getSignPayload(
|
|
719
|
+
TxEnvelopeLegacy.from({ ...unsigned, chainId: 1 }),
|
|
720
|
+
)
|
|
721
|
+
const { r, s, yParity } = Secp256k1.sign({
|
|
722
|
+
payload,
|
|
723
|
+
privateKey: accounts[0].privateKey,
|
|
724
|
+
})
|
|
725
|
+
|
|
726
|
+
// EIP-155 `v`, no `chainId`
|
|
727
|
+
const envelope = TxEnvelopeLegacy.from({
|
|
728
|
+
...unsigned,
|
|
729
|
+
r,
|
|
730
|
+
s,
|
|
731
|
+
v: 37 + yParity,
|
|
732
|
+
})
|
|
733
|
+
expect(
|
|
734
|
+
TxEnvelopeLegacy.hash(envelope, { presign: true }),
|
|
735
|
+
).toMatchInlineSnapshot(
|
|
736
|
+
`"0x4c1dec0d90aa1a17cb0aa735b5550e43a1bd27cd1cacb8987522576fa6220e46"`,
|
|
737
|
+
)
|
|
738
|
+
expect(TxEnvelopeLegacy.hash(envelope, { presign: true })).toBe(payload)
|
|
739
|
+
expect(TxEnvelopeLegacy.getSignPayload(envelope)).toBe(
|
|
740
|
+
TxEnvelopeLegacy.getSignPayload(
|
|
741
|
+
TxEnvelopeLegacy.deserialize(TxEnvelopeLegacy.serialize(envelope)),
|
|
742
|
+
),
|
|
743
|
+
)
|
|
744
|
+
|
|
745
|
+
// pre-EIP-155 `v`, no `chainId`
|
|
746
|
+
expect(
|
|
747
|
+
TxEnvelopeLegacy.hash(
|
|
748
|
+
TxEnvelopeLegacy.from({ ...unsigned, r, s, v: 27 + yParity }),
|
|
749
|
+
{ presign: true },
|
|
750
|
+
),
|
|
751
|
+
).toBe(TxEnvelopeLegacy.getSignPayload(TxEnvelopeLegacy.from(unsigned)))
|
|
752
|
+
})
|
|
510
753
|
})
|
|
511
754
|
|
|
512
755
|
describe('serialize', () => {
|
|
@@ -787,7 +1030,7 @@ describe('serialize', () => {
|
|
|
787
1030
|
value: BigInt('0x0'),
|
|
788
1031
|
})
|
|
789
1032
|
expect(serialized).toEqual(
|
|
790
|
-
'
|
|
1033
|
+
'0xe280808305208094c00000000000000000000000000000000000000080808284f38080',
|
|
791
1034
|
)
|
|
792
1035
|
})
|
|
793
1036
|
|
|
@@ -803,6 +1046,84 @@ describe('serialize', () => {
|
|
|
803
1046
|
'[Signature.InvalidVError: Value `29` is an invalid v value. v must be 27, 28 or >=35.]',
|
|
804
1047
|
)
|
|
805
1048
|
})
|
|
1049
|
+
|
|
1050
|
+
describe('v + chainId', () => {
|
|
1051
|
+
const signed = {
|
|
1052
|
+
...transaction,
|
|
1053
|
+
chainId: 1,
|
|
1054
|
+
r: '0x60fdd29ff912ce880cd3edaf9f932dc61d3dae823ea77e0323f94adb9f6a72fe',
|
|
1055
|
+
s: '0x60fdd29ff912ce880cd3edaf9f932dc61d3dae823ea77e0323f94adb9f6a72fe',
|
|
1056
|
+
} as const
|
|
1057
|
+
|
|
1058
|
+
test('behavior: v as parity', () => {
|
|
1059
|
+
expect(
|
|
1060
|
+
[0, 1, 27, 28, 37, 38].map((v) => {
|
|
1061
|
+
const { chainId, v: v_ } = TxEnvelopeLegacy.deserialize(
|
|
1062
|
+
TxEnvelopeLegacy.serialize({ ...signed, v }),
|
|
1063
|
+
)
|
|
1064
|
+
return { chainId, v: v_ }
|
|
1065
|
+
}),
|
|
1066
|
+
).toMatchInlineSnapshot(`
|
|
1067
|
+
[
|
|
1068
|
+
{
|
|
1069
|
+
"chainId": 1,
|
|
1070
|
+
"v": 37,
|
|
1071
|
+
},
|
|
1072
|
+
{
|
|
1073
|
+
"chainId": 1,
|
|
1074
|
+
"v": 38,
|
|
1075
|
+
},
|
|
1076
|
+
{
|
|
1077
|
+
"chainId": 1,
|
|
1078
|
+
"v": 37,
|
|
1079
|
+
},
|
|
1080
|
+
{
|
|
1081
|
+
"chainId": 1,
|
|
1082
|
+
"v": 38,
|
|
1083
|
+
},
|
|
1084
|
+
{
|
|
1085
|
+
"chainId": 1,
|
|
1086
|
+
"v": 37,
|
|
1087
|
+
},
|
|
1088
|
+
{
|
|
1089
|
+
"chainId": 1,
|
|
1090
|
+
"v": 38,
|
|
1091
|
+
},
|
|
1092
|
+
]
|
|
1093
|
+
`)
|
|
1094
|
+
})
|
|
1095
|
+
|
|
1096
|
+
test('error: v encodes another chain', () => {
|
|
1097
|
+
expect(() =>
|
|
1098
|
+
TxEnvelopeLegacy.serialize({ ...signed, v: 40 }),
|
|
1099
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1100
|
+
`[TransactionEnvelope.InvalidChainIdError: Chain ID "1" is invalid.]`,
|
|
1101
|
+
)
|
|
1102
|
+
expect(() =>
|
|
1103
|
+
TxEnvelopeLegacy.serialize({ ...signed, v: 35 }),
|
|
1104
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1105
|
+
`[TransactionEnvelope.InvalidChainIdError: Chain ID "1" is invalid.]`,
|
|
1106
|
+
)
|
|
1107
|
+
expect(() =>
|
|
1108
|
+
TxEnvelopeLegacy.serialize({ ...signed, chainId: 17000, v: 37 }),
|
|
1109
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1110
|
+
`[TransactionEnvelope.InvalidChainIdError: Chain ID "17000" is invalid.]`,
|
|
1111
|
+
)
|
|
1112
|
+
})
|
|
1113
|
+
|
|
1114
|
+
test('error: invalid v', () => {
|
|
1115
|
+
expect(() =>
|
|
1116
|
+
TxEnvelopeLegacy.serialize({ ...signed, v: 29 }),
|
|
1117
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1118
|
+
`[Signature.InvalidVError: Value \`29\` is an invalid v value. v must be 27, 28 or >=35.]`,
|
|
1119
|
+
)
|
|
1120
|
+
expect(() =>
|
|
1121
|
+
TxEnvelopeLegacy.serialize({ ...signed, v: 2 }),
|
|
1122
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1123
|
+
`[Signature.InvalidVError: Value \`2\` is an invalid v value. v must be 27, 28 or >=35.]`,
|
|
1124
|
+
)
|
|
1125
|
+
})
|
|
1126
|
+
})
|
|
806
1127
|
})
|
|
807
1128
|
|
|
808
1129
|
describe('toRpc', () => {
|
|
@@ -200,6 +200,23 @@ describe('assert', () => {
|
|
|
200
200
|
)
|
|
201
201
|
})
|
|
202
202
|
|
|
203
|
+
test('bytes odd length', () => {
|
|
204
|
+
expect(() =>
|
|
205
|
+
TypedData.assert({
|
|
206
|
+
message: { hash: '0x123' },
|
|
207
|
+
primaryType: 'Foo',
|
|
208
|
+
types: {
|
|
209
|
+
EIP712Domain: [],
|
|
210
|
+
Foo: [{ name: 'hash', type: 'bytes2' }],
|
|
211
|
+
},
|
|
212
|
+
}),
|
|
213
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
214
|
+
[Hex.InvalidLengthError: Hex value \`"0x123"\` is an odd length (3 nibbles).
|
|
215
|
+
|
|
216
|
+
It must be an even length.]
|
|
217
|
+
`)
|
|
218
|
+
})
|
|
219
|
+
|
|
203
220
|
test('domain: invalid', () => {
|
|
204
221
|
expect(() =>
|
|
205
222
|
TypedData.assert({
|
|
@@ -663,6 +680,24 @@ describe('domainSeparator', () => {
|
|
|
663
680
|
`"0x2fdf3441fcaf4f30c7e16292b258a5d7054a4e2e00dbd7b7d2f467f2b8fb9413"`,
|
|
664
681
|
)
|
|
665
682
|
})
|
|
683
|
+
|
|
684
|
+
test('behavior: string chainId', () => {
|
|
685
|
+
const domain = {
|
|
686
|
+
name: 'Ether Mail',
|
|
687
|
+
verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
|
|
688
|
+
} as const
|
|
689
|
+
|
|
690
|
+
expect(
|
|
691
|
+
TypedData.domainSeparator({ ...domain, chainId: 1 }),
|
|
692
|
+
).toMatchInlineSnapshot(
|
|
693
|
+
`"0xcbea6135f3930521627c49608c80b1e98ac5e9966ebf71d0d52f39fa5acc7a58"`,
|
|
694
|
+
)
|
|
695
|
+
expect(
|
|
696
|
+
TypedData.domainSeparator({ ...domain, chainId: '1' } as never),
|
|
697
|
+
).toMatchInlineSnapshot(
|
|
698
|
+
`"0xcbea6135f3930521627c49608c80b1e98ac5e9966ebf71d0d52f39fa5acc7a58"`,
|
|
699
|
+
)
|
|
700
|
+
})
|
|
666
701
|
})
|
|
667
702
|
|
|
668
703
|
describe('encode', () => {
|
|
@@ -963,6 +998,58 @@ describe('extractEip712DomainTypes', () => {
|
|
|
963
998
|
]
|
|
964
999
|
`)
|
|
965
1000
|
})
|
|
1001
|
+
|
|
1002
|
+
test('behavior: string chainId', () => {
|
|
1003
|
+
expect(
|
|
1004
|
+
TypedData.extractEip712DomainTypes({
|
|
1005
|
+
chainId: '1',
|
|
1006
|
+
name: 'Ether Mail',
|
|
1007
|
+
} as never),
|
|
1008
|
+
).toMatchInlineSnapshot(`
|
|
1009
|
+
[
|
|
1010
|
+
{
|
|
1011
|
+
"name": "name",
|
|
1012
|
+
"type": "string",
|
|
1013
|
+
},
|
|
1014
|
+
{
|
|
1015
|
+
"name": "chainId",
|
|
1016
|
+
"type": "uint256",
|
|
1017
|
+
},
|
|
1018
|
+
]
|
|
1019
|
+
`)
|
|
1020
|
+
})
|
|
1021
|
+
|
|
1022
|
+
test('behavior: empty verifyingContract and salt', () => {
|
|
1023
|
+
expect(
|
|
1024
|
+
TypedData.extractEip712DomainTypes({
|
|
1025
|
+
salt: '',
|
|
1026
|
+
verifyingContract: '',
|
|
1027
|
+
} as never),
|
|
1028
|
+
).toMatchInlineSnapshot(`
|
|
1029
|
+
[
|
|
1030
|
+
{
|
|
1031
|
+
"name": "verifyingContract",
|
|
1032
|
+
"type": "address",
|
|
1033
|
+
},
|
|
1034
|
+
{
|
|
1035
|
+
"name": "salt",
|
|
1036
|
+
"type": "bytes32",
|
|
1037
|
+
},
|
|
1038
|
+
]
|
|
1039
|
+
`)
|
|
1040
|
+
})
|
|
1041
|
+
|
|
1042
|
+
test('behavior: null and undefined fields are omitted', () => {
|
|
1043
|
+
expect(
|
|
1044
|
+
TypedData.extractEip712DomainTypes({
|
|
1045
|
+
chainId: undefined,
|
|
1046
|
+
name: null,
|
|
1047
|
+
salt: undefined,
|
|
1048
|
+
verifyingContract: null,
|
|
1049
|
+
version: undefined,
|
|
1050
|
+
} as never),
|
|
1051
|
+
).toMatchInlineSnapshot(`[]`)
|
|
1052
|
+
})
|
|
966
1053
|
})
|
|
967
1054
|
|
|
968
1055
|
describe('getSignPayload', () => {
|
|
@@ -1064,6 +1151,97 @@ describe('getSignPayload', () => {
|
|
|
1064
1151
|
expect(hashWithNumber).toBe(hashWithBigint)
|
|
1065
1152
|
})
|
|
1066
1153
|
|
|
1154
|
+
test('domain: string chainId produces same hash as number chainId', () => {
|
|
1155
|
+
const value = {
|
|
1156
|
+
domain: {
|
|
1157
|
+
chainId: 1,
|
|
1158
|
+
name: 'Ether Mail',
|
|
1159
|
+
verifyingContract: '0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC',
|
|
1160
|
+
},
|
|
1161
|
+
message: { contents: 'Hello, Bob!' },
|
|
1162
|
+
primaryType: 'Mail',
|
|
1163
|
+
types: { Mail: [{ name: 'contents', type: 'string' }] },
|
|
1164
|
+
} as const
|
|
1165
|
+
const { chainId: _, ...domain } = value.domain
|
|
1166
|
+
|
|
1167
|
+
expect(TypedData.getSignPayload(value)).toMatchInlineSnapshot(
|
|
1168
|
+
`"0x653cec21fbc0c9034d94bc61d4d36850d0455272dcec0d1655a008c81193701f"`,
|
|
1169
|
+
)
|
|
1170
|
+
expect(
|
|
1171
|
+
TypedData.getSignPayload({
|
|
1172
|
+
...value,
|
|
1173
|
+
domain: { ...domain, chainId: '1' },
|
|
1174
|
+
} as never),
|
|
1175
|
+
).toMatchInlineSnapshot(
|
|
1176
|
+
`"0x653cec21fbc0c9034d94bc61d4d36850d0455272dcec0d1655a008c81193701f"`,
|
|
1177
|
+
)
|
|
1178
|
+
expect(
|
|
1179
|
+
TypedData.getSignPayload({
|
|
1180
|
+
...value,
|
|
1181
|
+
domain: { ...domain, chainId: '0x1' },
|
|
1182
|
+
} as never),
|
|
1183
|
+
).toMatchInlineSnapshot(
|
|
1184
|
+
`"0x653cec21fbc0c9034d94bc61d4d36850d0455272dcec0d1655a008c81193701f"`,
|
|
1185
|
+
)
|
|
1186
|
+
expect(
|
|
1187
|
+
TypedData.getSignPayload({ ...value, domain }),
|
|
1188
|
+
).toMatchInlineSnapshot(
|
|
1189
|
+
`"0xa892aed0abd1aabdd57495f612097d467c47042ae2dbe1a98be9c5291eee51fb"`,
|
|
1190
|
+
)
|
|
1191
|
+
})
|
|
1192
|
+
|
|
1193
|
+
test('domain: string chainId survives a serialize round trip', () => {
|
|
1194
|
+
const value = {
|
|
1195
|
+
domain: { chainId: 1n, name: 'Ether Mail' },
|
|
1196
|
+
message: { contents: 'Hello, Bob!' },
|
|
1197
|
+
primaryType: 'Mail',
|
|
1198
|
+
types: { Mail: [{ name: 'contents', type: 'string' }] },
|
|
1199
|
+
} as const
|
|
1200
|
+
|
|
1201
|
+
expect(
|
|
1202
|
+
TypedData.getSignPayload(JSON.parse(TypedData.serialize(value))),
|
|
1203
|
+
).toBe(TypedData.getSignPayload(value))
|
|
1204
|
+
})
|
|
1205
|
+
|
|
1206
|
+
test('domain: non-numeric string chainId', () => {
|
|
1207
|
+
expect(() =>
|
|
1208
|
+
TypedData.getSignPayload({
|
|
1209
|
+
domain: { chainId: 'abc', name: 'Ether Mail' },
|
|
1210
|
+
message: { contents: 'Hello, Bob!' },
|
|
1211
|
+
primaryType: 'Mail',
|
|
1212
|
+
types: { Mail: [{ name: 'contents', type: 'string' }] },
|
|
1213
|
+
} as never),
|
|
1214
|
+
).toThrow(SyntaxError)
|
|
1215
|
+
})
|
|
1216
|
+
|
|
1217
|
+
test('domain: empty verifyingContract', () => {
|
|
1218
|
+
expect(() =>
|
|
1219
|
+
TypedData.getSignPayload({
|
|
1220
|
+
domain: { name: 'Ether Mail', verifyingContract: '' },
|
|
1221
|
+
message: { contents: 'Hello, Bob!' },
|
|
1222
|
+
primaryType: 'Mail',
|
|
1223
|
+
types: { Mail: [{ name: 'contents', type: 'string' }] },
|
|
1224
|
+
} as never),
|
|
1225
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
1226
|
+
[Address.InvalidAddressError: Address "" is invalid.
|
|
1227
|
+
|
|
1228
|
+
Details: Address is not a 20 byte (40 hexadecimal character) value.]
|
|
1229
|
+
`)
|
|
1230
|
+
})
|
|
1231
|
+
|
|
1232
|
+
test('domain: empty salt', () => {
|
|
1233
|
+
expect(() =>
|
|
1234
|
+
TypedData.getSignPayload({
|
|
1235
|
+
domain: { name: 'Ether Mail', salt: '' },
|
|
1236
|
+
message: { contents: 'Hello, Bob!' },
|
|
1237
|
+
primaryType: 'Mail',
|
|
1238
|
+
types: { Mail: [{ name: 'contents', type: 'string' }] },
|
|
1239
|
+
} as never),
|
|
1240
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1241
|
+
`[TypedData.BytesSizeMismatchError: Expected bytes32, got bytes-1.]`,
|
|
1242
|
+
)
|
|
1243
|
+
})
|
|
1244
|
+
|
|
1067
1245
|
test('minimal valid typed message', () => {
|
|
1068
1246
|
const payload = TypedData.getSignPayload({
|
|
1069
1247
|
types: {
|
|
@@ -44,6 +44,14 @@ describe('format', () => {
|
|
|
44
44
|
),
|
|
45
45
|
).toMatchInlineSnapshot('"-6942123123123069420.1234544444678912345"')
|
|
46
46
|
})
|
|
47
|
+
|
|
48
|
+
test(
|
|
49
|
+
'behavior: long run of zeros before a non-zero digit',
|
|
50
|
+
{ timeout: 5_000 },
|
|
51
|
+
() => {
|
|
52
|
+
expect(Value.format(1n, 200_001)).toBe(`0.${'0'.repeat(200_000)}1`)
|
|
53
|
+
},
|
|
54
|
+
)
|
|
47
55
|
})
|
|
48
56
|
|
|
49
57
|
describe('formatEther', () => {
|
|
@@ -402,6 +410,19 @@ describe('from', () => {
|
|
|
402
410
|
)
|
|
403
411
|
})
|
|
404
412
|
|
|
413
|
+
test(
|
|
414
|
+
'behavior: long run of zeros before a non-zero digit',
|
|
415
|
+
{ timeout: 5_000 },
|
|
416
|
+
() => {
|
|
417
|
+
expect(Value.from(`0.${'0'.repeat(200_000)}1`, 18)).toMatchInlineSnapshot(
|
|
418
|
+
'0n',
|
|
419
|
+
)
|
|
420
|
+
expect(Value.from(`1.5${'0'.repeat(200_000)}`, 18)).toMatchInlineSnapshot(
|
|
421
|
+
'1500000000000000000n',
|
|
422
|
+
)
|
|
423
|
+
},
|
|
424
|
+
)
|
|
425
|
+
|
|
405
426
|
test('error: invalid decimal number', () => {
|
|
406
427
|
expect(() =>
|
|
407
428
|
Value.from('123.456.789', 9),
|
|
@@ -611,6 +611,41 @@ test('remaining', () => {
|
|
|
611
611
|
expect(cursor.remaining).toBe(410)
|
|
612
612
|
})
|
|
613
613
|
|
|
614
|
+
describe('readSizeLimit', () => {
|
|
615
|
+
test('default', () => {
|
|
616
|
+
const cursor = Cursor.create(new Uint8Array(generateBytes(420)))
|
|
617
|
+
expect(cursor.readSizeLimit).toMatchInlineSnapshot(`275584`)
|
|
618
|
+
|
|
619
|
+
cursor.readBytes(420)
|
|
620
|
+
cursor.setPosition(0)
|
|
621
|
+
cursor.readUint32()
|
|
622
|
+
expect(cursor.readSize).toMatchInlineSnapshot(`424`)
|
|
623
|
+
})
|
|
624
|
+
|
|
625
|
+
test('behavior: reads past the limit', () => {
|
|
626
|
+
const cursor = Cursor.create(new Uint8Array(generateBytes(420)), {
|
|
627
|
+
recursiveReadLimit: 2,
|
|
628
|
+
})
|
|
629
|
+
expect(cursor.readSizeLimit).toMatchInlineSnapshot(`13504`)
|
|
630
|
+
|
|
631
|
+
for (let i = 0; i < 33; i++) {
|
|
632
|
+
cursor.setPosition(i)
|
|
633
|
+
cursor.readBytes(420 - i)
|
|
634
|
+
}
|
|
635
|
+
cursor.setPosition(33)
|
|
636
|
+
expect(() => cursor.readBytes(387)).toThrowErrorMatchingInlineSnapshot(
|
|
637
|
+
`[Cursor.ReadSizeLimitExceededError: Read size limit of \`13504\` bytes exceeded (read size: \`13719\` bytes).]`,
|
|
638
|
+
)
|
|
639
|
+
})
|
|
640
|
+
|
|
641
|
+
test('behavior: no recursiveReadLimit', () => {
|
|
642
|
+
const cursor = Cursor.create(new Uint8Array(generateBytes(420)), {
|
|
643
|
+
recursiveReadLimit: Number.POSITIVE_INFINITY,
|
|
644
|
+
})
|
|
645
|
+
expect(cursor.readSizeLimit).toMatchInlineSnapshot(`Infinity`)
|
|
646
|
+
})
|
|
647
|
+
})
|
|
648
|
+
|
|
614
649
|
describe('args: recursiveReadLimit', () => {
|
|
615
650
|
test('default', () => {
|
|
616
651
|
const cursor = Cursor.create(new Uint8Array(generateBytes(420)), {
|
|
@@ -347,8 +347,9 @@ export function decodeBytes(
|
|
|
347
347
|
return [Hex.fromBytes(data), 32]
|
|
348
348
|
}
|
|
349
349
|
|
|
350
|
-
|
|
351
|
-
|
|
350
|
+
// Read the whole slot so that a slot cut short of its padding is out of bounds.
|
|
351
|
+
const word = cursor.readBytes(32)
|
|
352
|
+
return [Hex.fromBytes(word.subarray(0, Number.parseInt(size, 10))), 32]
|
|
352
353
|
}
|
|
353
354
|
|
|
354
355
|
export declare namespace decodeBytes {
|
|
@@ -551,6 +552,7 @@ export declare namespace encodeParameters {
|
|
|
551
552
|
| AbiParameters.InvalidTypeError
|
|
552
553
|
| Address.assert.ErrorType
|
|
553
554
|
| Hex.IntegerOutOfRangeError
|
|
555
|
+
| Hex.InvalidLengthError
|
|
554
556
|
| Hex.fromBytes.ErrorType
|
|
555
557
|
| Errors.GlobalErrorType
|
|
556
558
|
}
|
|
@@ -749,6 +751,9 @@ function measureParameter(
|
|
|
749
751
|
expectedSize: parameter.size,
|
|
750
752
|
value: value_,
|
|
751
753
|
})
|
|
754
|
+
// An unpaired nibble has no byte to belong to, so reject it instead of
|
|
755
|
+
// guessing which half of a byte it is.
|
|
756
|
+
if (value_.length % 2 !== 0) throw new Hex.InvalidLengthError(value_)
|
|
752
757
|
if (parameter.size !== null) return 32
|
|
753
758
|
return 32 + Math.ceil(size / 32) * 32
|
|
754
759
|
}
|