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
|
@@ -46,6 +46,19 @@ describe('fromRpc', () => {
|
|
|
46
46
|
status: expected,
|
|
47
47
|
})
|
|
48
48
|
})
|
|
49
|
+
|
|
50
|
+
test('behavior: unknown status named like an `Object.prototype` key', () => {
|
|
51
|
+
for (const status of ['__proto__', 'constructor', 'toString'])
|
|
52
|
+
expect(
|
|
53
|
+
FrameReceipt.fromRpc({
|
|
54
|
+
executionGasUsed: '0x0',
|
|
55
|
+
gasUsed: '0x0',
|
|
56
|
+
logs: [],
|
|
57
|
+
stateGasUsed: '0x0',
|
|
58
|
+
status: status as never,
|
|
59
|
+
}).status,
|
|
60
|
+
).toBeUndefined()
|
|
61
|
+
})
|
|
49
62
|
})
|
|
50
63
|
|
|
51
64
|
describe('toRpc', () => {
|
|
@@ -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', () => {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { test } from '@fast-check/vitest'
|
|
1
|
+
import { fc, test } from '@fast-check/vitest'
|
|
2
2
|
import { type Bytes, Hex, Rlp } from 'ox'
|
|
3
3
|
import { describe, expect } from 'vp/test'
|
|
4
4
|
|
|
@@ -36,8 +36,62 @@ describe('Rlp round-trip', () => {
|
|
|
36
36
|
expect(asHex).toEqual(Hex.fromBytes(asBytes))
|
|
37
37
|
},
|
|
38
38
|
)
|
|
39
|
+
|
|
40
|
+
test.prop(
|
|
41
|
+
{
|
|
42
|
+
edit: fc.tuple(
|
|
43
|
+
fc.nat(),
|
|
44
|
+
fc.nat(0xff),
|
|
45
|
+
fc.constantFrom('cut', 'set', 'add', 'char'),
|
|
46
|
+
),
|
|
47
|
+
tree: arbitraryRecursiveRlpHex(),
|
|
48
|
+
},
|
|
49
|
+
{ numRuns },
|
|
50
|
+
)(
|
|
51
|
+
'hex and bytes decode paths agree on mutated encodings, errors included',
|
|
52
|
+
({ edit: [at, byte, kind], tree }) => {
|
|
53
|
+
const body = Rlp.from(tree, { as: 'Hex' }).slice(2)
|
|
54
|
+
const index = (at % (body.length / 2 + 1)) * 2
|
|
55
|
+
const pair = byte.toString(16).padStart(2, '0')
|
|
56
|
+
const mutated = `0x${(() => {
|
|
57
|
+
if (kind === 'cut') return body.slice(0, index)
|
|
58
|
+
if (kind === 'set')
|
|
59
|
+
return `${body.slice(0, index)}${pair}${body.slice(index + 2)}`
|
|
60
|
+
if (kind === 'add')
|
|
61
|
+
return `${body.slice(0, index)}${pair}${body.slice(index)}`
|
|
62
|
+
return `${body.slice(0, index)}g${body.slice(index + 1)}`
|
|
63
|
+
})()}` as Hex.Hex
|
|
64
|
+
expect(outcome(() => Rlp.toHex(mutated))).toEqual(
|
|
65
|
+
outcome(() => normalizeBytesToHex(Rlp.toBytes(mutated))),
|
|
66
|
+
)
|
|
67
|
+
},
|
|
68
|
+
)
|
|
39
69
|
})
|
|
40
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Returns a decode result or its error, so that two decode paths can be
|
|
73
|
+
* compared on malformed input.
|
|
74
|
+
*
|
|
75
|
+
* @internal
|
|
76
|
+
*/
|
|
77
|
+
function outcome(fn: () => unknown) {
|
|
78
|
+
try {
|
|
79
|
+
return { value: fn() }
|
|
80
|
+
} catch (error) {
|
|
81
|
+
return { error: `${(error as Error).name}: ${(error as Error).message}` }
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Converts `Uint8Array` leaves to hex, as `Rlp.toHex` returns them.
|
|
87
|
+
*
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
function normalizeBytesToHex(value: RecursiveArray<Bytes.Bytes>): unknown {
|
|
91
|
+
if (Array.isArray(value)) return value.map(normalizeBytesToHex)
|
|
92
|
+
return Hex.fromBytes(value as Uint8Array)
|
|
93
|
+
}
|
|
94
|
+
|
|
41
95
|
/**
|
|
42
96
|
* Lower-case any hex string in a recursive tree. The encoder emits
|
|
43
97
|
* lowercase but the arbitrary may produce mixed casing in the future,
|
|
@@ -157,6 +157,70 @@ describe('Rlp.to', () => {
|
|
|
157
157
|
expect(Rlp.toHex(rlpBytes)).toEqual('0x')
|
|
158
158
|
})
|
|
159
159
|
|
|
160
|
+
test('behavior: hex leaves of a hex input', () => {
|
|
161
|
+
// Short and long leaves, nested, in short and long (> 4096 hex
|
|
162
|
+
// characters) inputs.
|
|
163
|
+
for (const length of [32, 4_096]) {
|
|
164
|
+
const value = [
|
|
165
|
+
'0x0a',
|
|
166
|
+
'0x',
|
|
167
|
+
`0x${'ab'.repeat(20)}`,
|
|
168
|
+
[[`0x${'cd'.repeat(length)}`], '0x7f', '0x80'],
|
|
169
|
+
`0x${'ef'.repeat(56)}`,
|
|
170
|
+
] as const
|
|
171
|
+
const encoded = Rlp.fromHex(value as never)
|
|
172
|
+
expect(Rlp.toHex(encoded)).toEqual(value)
|
|
173
|
+
// Leaves are lowercase, as `Hex.fromBytes` writes them.
|
|
174
|
+
expect(Rlp.toHex(`0x${encoded.slice(2).toUpperCase()}`)).toEqual(value)
|
|
175
|
+
}
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
test('behavior: hex input decodes and fails like byte input', () => {
|
|
179
|
+
// Decoding to bytes always goes through `Bytes.fromHex` and the cursor,
|
|
180
|
+
// which short hex input to hex skips.
|
|
181
|
+
const toHex = (value: unknown): unknown =>
|
|
182
|
+
Array.isArray(value) ? value.map(toHex) : Hex.fromBytes(value as never)
|
|
183
|
+
const outcome = (fn: () => unknown) => {
|
|
184
|
+
try {
|
|
185
|
+
return { value: fn() }
|
|
186
|
+
} catch (error) {
|
|
187
|
+
return {
|
|
188
|
+
error: `${(error as Error).name}: ${(error as Error).message}`,
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
for (const value of [
|
|
193
|
+
'0x',
|
|
194
|
+
'0x00',
|
|
195
|
+
'0x7F',
|
|
196
|
+
'0x8180',
|
|
197
|
+
'0xC88363617483646F67',
|
|
198
|
+
'0xc0',
|
|
199
|
+
'0xzz',
|
|
200
|
+
'0x8',
|
|
201
|
+
'0x0\u0130',
|
|
202
|
+
'0x82',
|
|
203
|
+
'0x8201',
|
|
204
|
+
'0xb8',
|
|
205
|
+
'0xb801ff',
|
|
206
|
+
'0xb838',
|
|
207
|
+
'0xb90001',
|
|
208
|
+
'0xbc',
|
|
209
|
+
'0x8100',
|
|
210
|
+
'0x817f',
|
|
211
|
+
'0xc20102',
|
|
212
|
+
'0xc1c0c0',
|
|
213
|
+
'0xc3010203ff',
|
|
214
|
+
'0xc28201',
|
|
215
|
+
'0xff',
|
|
216
|
+
'0x0101',
|
|
217
|
+
`0x${'c1'.repeat(1_025)}`,
|
|
218
|
+
] as const)
|
|
219
|
+
expect(outcome(() => Rlp.toHex(value as Hex.Hex))).toEqual(
|
|
220
|
+
outcome(() => toHex(Rlp.toBytes(value as Hex.Hex))),
|
|
221
|
+
)
|
|
222
|
+
})
|
|
223
|
+
|
|
160
224
|
describe('prefix < 0x80', () => {
|
|
161
225
|
test('bytes -> bytes', () => {
|
|
162
226
|
expect(Rlp.toBytes(Rlp.fromBytes(Bytes.fromHex('0x00')))).toEqual(
|
|
@@ -224,7 +224,7 @@ describe('fromHttp', () => {
|
|
|
224
224
|
|
|
225
225
|
Status: 400
|
|
226
226
|
URL: https://oxlib.sh/rpc
|
|
227
|
-
Body:
|
|
227
|
+
Body: {"id":0,"method":"eth_accounts","jsonrpc":"2.0"}
|
|
228
228
|
|
|
229
229
|
Details: Bad Request]
|
|
230
230
|
`)
|
|
@@ -244,7 +244,7 @@ describe('fromHttp', () => {
|
|
|
244
244
|
|
|
245
245
|
Status: 400
|
|
246
246
|
URL: https://oxlib.sh/rpc
|
|
247
|
-
Body:
|
|
247
|
+
Body: {"id":0,"method":"eth_accounts","jsonrpc":"2.0"}
|
|
248
248
|
|
|
249
249
|
Details: bad]
|
|
250
250
|
`)
|
|
@@ -317,6 +317,19 @@ describe('fromHttp', () => {
|
|
|
317
317
|
}
|
|
318
318
|
})
|
|
319
319
|
|
|
320
|
+
test('behavior: timeout rejects when `fetchFn` ignores the signal', async () => {
|
|
321
|
+
const transport = RpcTransport.fromHttp('https://example.com', {
|
|
322
|
+
fetchFn: () => new Promise<Response>(() => {}),
|
|
323
|
+
timeout: 50,
|
|
324
|
+
})
|
|
325
|
+
|
|
326
|
+
await expect(() =>
|
|
327
|
+
transport.request({ method: 'eth_accounts' }),
|
|
328
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
329
|
+
`[Promise.TimeoutError: Operation timed out.]`,
|
|
330
|
+
)
|
|
331
|
+
})
|
|
332
|
+
|
|
320
333
|
test('behavior: timeout covers a response body that stalls after its headers', async () => {
|
|
321
334
|
const server = await createHttpServer(async (_, res) => {
|
|
322
335
|
res.writeHead(200, { 'Content-Type': 'application/json' })
|
|
@@ -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', () => {
|
|
@@ -92,6 +92,54 @@ describe('assert', () => {
|
|
|
92
92
|
'[Signature.InvalidSError: Value `0x10000000000000000000000000000000000000000000000000000000000000000` is an invalid s value. s must be a positive integer less than 2^256.]',
|
|
93
93
|
)
|
|
94
94
|
})
|
|
95
|
+
|
|
96
|
+
test('error: yParity that is not exactly 0 or 1', () => {
|
|
97
|
+
const r =
|
|
98
|
+
'0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf'
|
|
99
|
+
const s =
|
|
100
|
+
'0x4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db8'
|
|
101
|
+
|
|
102
|
+
expect(() =>
|
|
103
|
+
Signature.assert({ r, s, yParity: '0x1' as never }),
|
|
104
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
105
|
+
`[Signature.InvalidYParityError: Value \`0x1\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
|
|
106
|
+
)
|
|
107
|
+
expect(() =>
|
|
108
|
+
Signature.assert({ r, s, yParity: 1n as never }),
|
|
109
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
110
|
+
`[Signature.InvalidYParityError: Value \`1\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
|
|
111
|
+
)
|
|
112
|
+
expect(() =>
|
|
113
|
+
Signature.assert({ r, s, yParity: true as never }),
|
|
114
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
115
|
+
`[Signature.InvalidYParityError: Value \`true\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
|
|
116
|
+
)
|
|
117
|
+
expect(() =>
|
|
118
|
+
Signature.assert({ r, s, yParity: null as never }),
|
|
119
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
120
|
+
`[Signature.InvalidYParityError: Value \`null\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
|
|
121
|
+
)
|
|
122
|
+
expect(() =>
|
|
123
|
+
Signature.assert({ r, s, yParity: {} as never }),
|
|
124
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
125
|
+
`[Signature.InvalidYParityError: Value \`[object Object]\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
|
|
126
|
+
)
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
test('options: recovered: null yParity is missing', () => {
|
|
130
|
+
expect(() =>
|
|
131
|
+
Signature.assert(
|
|
132
|
+
{
|
|
133
|
+
r: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
134
|
+
s: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
135
|
+
yParity: null as never,
|
|
136
|
+
},
|
|
137
|
+
{ recovered: true },
|
|
138
|
+
),
|
|
139
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
140
|
+
`[Signature.MissingPropertiesError: Signature \`{"r":"0x0000000000000000000000000000000000000000000000000000000000000000","s":"0x0000000000000000000000000000000000000000000000000000000000000000","yParity":null}\` is missing either an \`r\`, \`s\`, or \`yParity\` property.]`,
|
|
141
|
+
)
|
|
142
|
+
})
|
|
95
143
|
})
|
|
96
144
|
|
|
97
145
|
describe('fromHex', () => {
|
|
@@ -994,6 +1042,34 @@ describe('toTuple', () => {
|
|
|
994
1042
|
]
|
|
995
1043
|
`)
|
|
996
1044
|
})
|
|
1045
|
+
|
|
1046
|
+
test('error: yParity that is not exactly 0 or 1', () => {
|
|
1047
|
+
const r =
|
|
1048
|
+
'0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf'
|
|
1049
|
+
const s =
|
|
1050
|
+
'0x4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db8'
|
|
1051
|
+
|
|
1052
|
+
expect(() =>
|
|
1053
|
+
Signature.toTuple({ r, s, yParity: 27 }),
|
|
1054
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1055
|
+
`[Signature.InvalidYParityError: Value \`27\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
|
|
1056
|
+
)
|
|
1057
|
+
expect(() =>
|
|
1058
|
+
Signature.toTuple({ r, s, yParity: 27n as never }),
|
|
1059
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1060
|
+
`[Signature.InvalidYParityError: Value \`27\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
|
|
1061
|
+
)
|
|
1062
|
+
expect(() =>
|
|
1063
|
+
Signature.toTuple({ r, s, yParity: '0x0' as never }),
|
|
1064
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1065
|
+
`[Signature.InvalidYParityError: Value \`0x0\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
|
|
1066
|
+
)
|
|
1067
|
+
expect(() =>
|
|
1068
|
+
Signature.toTuple({ r, s } as never),
|
|
1069
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1070
|
+
`[Signature.MissingPropertiesError: Signature \`{"r":"0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf","s":"0x4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db8"}\` is missing either an \`r\`, \`s\`, or \`yParity\` property.]`,
|
|
1071
|
+
)
|
|
1072
|
+
})
|
|
997
1073
|
})
|
|
998
1074
|
|
|
999
1075
|
describe('validate', () => {
|
|
@@ -1013,6 +1089,32 @@ describe('validate', () => {
|
|
|
1013
1089
|
}),
|
|
1014
1090
|
).toBe(false)
|
|
1015
1091
|
})
|
|
1092
|
+
|
|
1093
|
+
test('behavior: yParity that is not exactly 0 or 1', () => {
|
|
1094
|
+
const r =
|
|
1095
|
+
'0x6e100a352ec6ad1b70802290e18aeed190704973570f3b8ed42cb9808e2ea6bf'
|
|
1096
|
+
const s =
|
|
1097
|
+
'0x4a90a229a244495b41890987806fcbd2d5d23fc0dbe5f5256c2613c039d76db8'
|
|
1098
|
+
|
|
1099
|
+
expect(
|
|
1100
|
+
[2, '0x5', 2n, 27n, true, null, {}].map((yParity) =>
|
|
1101
|
+
Signature.validate({ r, s, yParity: yParity as never }),
|
|
1102
|
+
),
|
|
1103
|
+
).toMatchInlineSnapshot(`
|
|
1104
|
+
[
|
|
1105
|
+
false,
|
|
1106
|
+
false,
|
|
1107
|
+
false,
|
|
1108
|
+
false,
|
|
1109
|
+
false,
|
|
1110
|
+
false,
|
|
1111
|
+
false,
|
|
1112
|
+
]
|
|
1113
|
+
`)
|
|
1114
|
+
expect(
|
|
1115
|
+
Signature.validate({ r, s, yParity: null as never }, { recovered: true }),
|
|
1116
|
+
).toMatchInlineSnapshot(`false`)
|
|
1117
|
+
})
|
|
1016
1118
|
})
|
|
1017
1119
|
|
|
1018
1120
|
describe('vToYParity', () => {
|
|
@@ -442,6 +442,27 @@ describe('createMessage', () => {
|
|
|
442
442
|
`)
|
|
443
443
|
})
|
|
444
444
|
|
|
445
|
+
test('behavior: invalid requestId', () => {
|
|
446
|
+
expect(() => Siwe.createMessage({ ...message, requestId: 'foo\nbar' }))
|
|
447
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
448
|
+
[Siwe.InvalidMessageFieldError: Invalid Sign-In with Ethereum message field "requestId".
|
|
449
|
+
|
|
450
|
+
- Request ID must not include '\\n' or '\\r'.
|
|
451
|
+
|
|
452
|
+
Provided value: foo
|
|
453
|
+
bar]
|
|
454
|
+
`)
|
|
455
|
+
expect(() => Siwe.createMessage({ ...message, requestId: 'foo\rbar' }))
|
|
456
|
+
.toThrowErrorMatchingInlineSnapshot(`
|
|
457
|
+
[Siwe.InvalidMessageFieldError: Invalid Sign-In with Ethereum message field "requestId".
|
|
458
|
+
|
|
459
|
+
- Request ID must not include '\\n' or '\\r'.
|
|
460
|
+
|
|
461
|
+
Provided value: foo
|
|
462
|
+
bar]
|
|
463
|
+
`)
|
|
464
|
+
})
|
|
465
|
+
|
|
445
466
|
test('behavior: invalid resources', () => {
|
|
446
467
|
expect(() =>
|
|
447
468
|
Siwe.createMessage({
|
|
@@ -1013,6 +1034,76 @@ Request ID: 123e4567-e89b-12d3-a456-426614174000`
|
|
|
1013
1034
|
const parsed = Siwe.parseMessage(message)
|
|
1014
1035
|
expect(parsed).toMatchInlineSnapshot('{}')
|
|
1015
1036
|
})
|
|
1037
|
+
|
|
1038
|
+
test.each([
|
|
1039
|
+
{
|
|
1040
|
+
name: 'expirationTime after notBefore',
|
|
1041
|
+
tail: '\nNot Before: 2023-02-01T00:00:00.000Z\nExpiration Time: 2023-03-01T00:00:00.000Z',
|
|
1042
|
+
},
|
|
1043
|
+
{
|
|
1044
|
+
name: 'expirationTime after requestId',
|
|
1045
|
+
tail: '\nRequest ID: foo\nExpiration Time: 2023-03-01T00:00:00.000Z',
|
|
1046
|
+
},
|
|
1047
|
+
{
|
|
1048
|
+
name: 'notBefore after resources',
|
|
1049
|
+
tail: '\nResources:\n- https://example.com/foo\nNot Before: 2023-02-01T00:00:00.000Z',
|
|
1050
|
+
},
|
|
1051
|
+
{
|
|
1052
|
+
name: 'blank line before expirationTime',
|
|
1053
|
+
tail: '\n\nExpiration Time: 2023-03-01T00:00:00.000Z',
|
|
1054
|
+
},
|
|
1055
|
+
{
|
|
1056
|
+
name: 'unknown field label',
|
|
1057
|
+
tail: '\nExpiration Time: 2023-03-01T00:00:00.000Z',
|
|
1058
|
+
},
|
|
1059
|
+
{ name: 'trailing line feed', tail: '\n' },
|
|
1060
|
+
])('behavior: text after the suffix ($name)', ({ tail }) => {
|
|
1061
|
+
const message = `example.com wants you to sign in with your Ethereum account:
|
|
1062
|
+
0xA0Cf798816D4b9b9866b5330EEa46a18382f251e
|
|
1063
|
+
|
|
1064
|
+
I accept the ExampleOrg Terms of Service: https://example.com/tos
|
|
1065
|
+
|
|
1066
|
+
URI: https://example.com/path
|
|
1067
|
+
Version: 1
|
|
1068
|
+
Chain ID: 1
|
|
1069
|
+
Nonce: foobarbaz
|
|
1070
|
+
Issued At: 2023-02-01T00:00:00.000Z`
|
|
1071
|
+
expect(Siwe.parseMessage(message + tail)).toEqual({})
|
|
1072
|
+
})
|
|
1073
|
+
|
|
1074
|
+
test('behavior: text between the prefix and the suffix', () => {
|
|
1075
|
+
const message = `example.com wants you to sign in with your Ethereum account:
|
|
1076
|
+
0xA0Cf798816D4b9b9866b5330EEa46a18382f251e
|
|
1077
|
+
|
|
1078
|
+
I accept the ExampleOrg Terms of Service: https://example.com/tos
|
|
1079
|
+
|
|
1080
|
+
foo
|
|
1081
|
+
URI: https://example.com/path
|
|
1082
|
+
Version: 1
|
|
1083
|
+
Chain ID: 1
|
|
1084
|
+
Nonce: foobarbaz
|
|
1085
|
+
Issued At: 2023-02-01T00:00:00.000Z`
|
|
1086
|
+
expect(Siwe.parseMessage(message)).toMatchInlineSnapshot('{}')
|
|
1087
|
+
})
|
|
1088
|
+
|
|
1089
|
+
test('behavior: text before the suffix without a prefix', () => {
|
|
1090
|
+
const message = `foo
|
|
1091
|
+
URI: https://example.com/path
|
|
1092
|
+
Version: 1
|
|
1093
|
+
Chain ID: 1
|
|
1094
|
+
Nonce: foobarbaz
|
|
1095
|
+
Issued At: 2023-02-01T00:00:00.000Z`
|
|
1096
|
+
expect(Siwe.parseMessage(message)).toMatchInlineSnapshot('{}')
|
|
1097
|
+
})
|
|
1098
|
+
|
|
1099
|
+
test(
|
|
1100
|
+
'behavior: long message of repeated field labels',
|
|
1101
|
+
{ timeout: 5_000 },
|
|
1102
|
+
() => {
|
|
1103
|
+
const message = 'URI: '.repeat(60_000)
|
|
1104
|
+
expect(Siwe.parseMessage(message)).toMatchInlineSnapshot('{}')
|
|
1105
|
+
},
|
|
1106
|
+
)
|
|
1016
1107
|
})
|
|
1017
1108
|
|
|
1018
1109
|
describe('validateMessage', () => {
|
|
@@ -1132,6 +1223,38 @@ Issued At: 2023-02-01T00:00:00.000Z`)
|
|
|
1132
1223
|
).toBeFalsy()
|
|
1133
1224
|
})
|
|
1134
1225
|
|
|
1226
|
+
test('behavior: parsed message with expirationTime out of order', () => {
|
|
1227
|
+
const message = Siwe.createMessage({
|
|
1228
|
+
address: '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e',
|
|
1229
|
+
chainId: 1,
|
|
1230
|
+
domain: 'example.com',
|
|
1231
|
+
issuedAt: new Date(Date.UTC(2024, 0, 1)),
|
|
1232
|
+
nonce: 'foobarbaz',
|
|
1233
|
+
uri: 'https://example.com/path',
|
|
1234
|
+
version: '1',
|
|
1235
|
+
})
|
|
1236
|
+
const time = new Date(Date.UTC(2025, 1, 1))
|
|
1237
|
+
expect(
|
|
1238
|
+
Siwe.validateMessage({ message: Siwe.parseMessage(message), time }),
|
|
1239
|
+
).toBeTruthy()
|
|
1240
|
+
expect(
|
|
1241
|
+
Siwe.validateMessage({
|
|
1242
|
+
message: Siwe.parseMessage(
|
|
1243
|
+
`${message}\nExpiration Time: 2024-02-01T00:00:00.000Z`,
|
|
1244
|
+
),
|
|
1245
|
+
time,
|
|
1246
|
+
}),
|
|
1247
|
+
).toBeFalsy()
|
|
1248
|
+
expect(
|
|
1249
|
+
Siwe.validateMessage({
|
|
1250
|
+
message: Siwe.parseMessage(
|
|
1251
|
+
`${message}\nNot Before: 2024-01-01T00:00:00.000Z\nExpiration Time: 2024-02-01T00:00:00.000Z`,
|
|
1252
|
+
),
|
|
1253
|
+
time,
|
|
1254
|
+
}),
|
|
1255
|
+
).toBeFalsy()
|
|
1256
|
+
})
|
|
1257
|
+
|
|
1135
1258
|
test.each(['expirationTime', 'notBefore'] as const)(
|
|
1136
1259
|
'behavior: invalid %s',
|
|
1137
1260
|
(field) => {
|
|
@@ -13,6 +13,23 @@ import { accounts } from '../../../test/constants/accounts.js'
|
|
|
13
13
|
import { anvilMainnet } from '../../../test/prool.js'
|
|
14
14
|
|
|
15
15
|
describe('fromRpc', () => {
|
|
16
|
+
test('behavior: unknown type named like an `Object.prototype` key', () => {
|
|
17
|
+
const transaction = Transaction.fromRpc({
|
|
18
|
+
blockHash: null,
|
|
19
|
+
blockNumber: null,
|
|
20
|
+
from: '0x814e5e0e31016b9a7f138c76b7e7b2bb5c1ab6a6',
|
|
21
|
+
gas: '0x5208',
|
|
22
|
+
hash: '0x353fdfc38a2f26115daadee9f5b8392ce62b84f410957967e2ed56b35338cdd0',
|
|
23
|
+
input: '0x',
|
|
24
|
+
nonce: '0x0',
|
|
25
|
+
to: null,
|
|
26
|
+
transactionIndex: null,
|
|
27
|
+
type: 'constructor',
|
|
28
|
+
value: '0x0',
|
|
29
|
+
} as unknown as Transaction.Rpc)
|
|
30
|
+
expect(transaction.type).toMatchInlineSnapshot(`"constructor"`)
|
|
31
|
+
})
|
|
32
|
+
|
|
16
33
|
describe('legacy', () => {
|
|
17
34
|
test('default', () => {
|
|
18
35
|
expect(
|
|
@@ -47,6 +47,34 @@ describe('assert', () => {
|
|
|
47
47
|
)
|
|
48
48
|
})
|
|
49
49
|
|
|
50
|
+
test('invalid chainId (not a positive safe integer)', () => {
|
|
51
|
+
expect(() =>
|
|
52
|
+
TxEnvelopeEip1559.assert({ chainId: Number.NaN }),
|
|
53
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
54
|
+
`[TransactionEnvelope.InvalidChainIdError: Chain ID "NaN" is invalid.]`,
|
|
55
|
+
)
|
|
56
|
+
expect(() =>
|
|
57
|
+
TxEnvelopeEip1559.assert({ chainId: 1.5 }),
|
|
58
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
59
|
+
`[TransactionEnvelope.InvalidChainIdError: Chain ID "1.5" is invalid.]`,
|
|
60
|
+
)
|
|
61
|
+
expect(() =>
|
|
62
|
+
TxEnvelopeEip1559.assert({ chainId: Number.MAX_SAFE_INTEGER + 1 }),
|
|
63
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
64
|
+
`[TransactionEnvelope.InvalidChainIdError: Chain ID "9007199254740992" is invalid.]`,
|
|
65
|
+
)
|
|
66
|
+
expect(() =>
|
|
67
|
+
TxEnvelopeEip1559.assert({ chainId: '1' as never }),
|
|
68
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
69
|
+
`[TransactionEnvelope.InvalidChainIdError: Chain ID "1" is invalid.]`,
|
|
70
|
+
)
|
|
71
|
+
expect(() =>
|
|
72
|
+
TxEnvelopeEip1559.assert({ chainId: 1n as never }),
|
|
73
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
74
|
+
`[TransactionEnvelope.InvalidChainIdError: Chain ID "1" is invalid.]`,
|
|
75
|
+
)
|
|
76
|
+
})
|
|
77
|
+
|
|
50
78
|
test('invalid address', () => {
|
|
51
79
|
expect(() => TxEnvelopeEip1559.assert({ to: '0x123', chainId: 1 }))
|
|
52
80
|
.toThrowErrorMatchingInlineSnapshot(`
|
|
@@ -23,6 +23,34 @@ describe('assert', () => {
|
|
|
23
23
|
)
|
|
24
24
|
})
|
|
25
25
|
|
|
26
|
+
test('invalid chainId (not a positive safe integer)', () => {
|
|
27
|
+
expect(() =>
|
|
28
|
+
TxEnvelopeEip2930.assert({ chainId: Number.NaN }),
|
|
29
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
30
|
+
`[TransactionEnvelope.InvalidChainIdError: Chain ID "NaN" is invalid.]`,
|
|
31
|
+
)
|
|
32
|
+
expect(() =>
|
|
33
|
+
TxEnvelopeEip2930.assert({ chainId: 1.5 }),
|
|
34
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
35
|
+
`[TransactionEnvelope.InvalidChainIdError: Chain ID "1.5" is invalid.]`,
|
|
36
|
+
)
|
|
37
|
+
expect(() =>
|
|
38
|
+
TxEnvelopeEip2930.assert({ chainId: Number.MAX_SAFE_INTEGER + 1 }),
|
|
39
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
40
|
+
`[TransactionEnvelope.InvalidChainIdError: Chain ID "9007199254740992" is invalid.]`,
|
|
41
|
+
)
|
|
42
|
+
expect(() =>
|
|
43
|
+
TxEnvelopeEip2930.assert({ chainId: '1' as never }),
|
|
44
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
45
|
+
`[TransactionEnvelope.InvalidChainIdError: Chain ID "1" is invalid.]`,
|
|
46
|
+
)
|
|
47
|
+
expect(() =>
|
|
48
|
+
TxEnvelopeEip2930.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(() => TxEnvelopeEip2930.assert({ to: '0x123', chainId: 1 }))
|
|
28
56
|
.toThrowErrorMatchingInlineSnapshot(`
|