ox 1.8.14 → 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 +72 -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/SignaturePreAuthorized.d.ts +192 -0
- package/dist/tempo/SignaturePreAuthorized.d.ts.map +1 -0
- package/dist/tempo/SignaturePreAuthorized.js +299 -0
- package/dist/tempo/SignaturePreAuthorized.js.map +1 -0
- 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/index.d.ts +26 -0
- package/dist/tempo/index.d.ts.map +1 -1
- package/dist/tempo/index.js +26 -0
- package/dist/tempo/index.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 +6 -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/SignaturePreAuthorized.test-d.ts +29 -0
- package/src/tempo/SignaturePreAuthorized.test.ts +410 -0
- package/src/tempo/SignaturePreAuthorized.ts +370 -0
- 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/tempo/index.ts +26 -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 +31 -16
- package/src/zod/tempo/_test/KeyAuthorization.test.ts +36 -0
- package/src/zod/tempo/_test/SignatureEnvelope.test.ts +101 -3
|
@@ -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) => {
|
|
@@ -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(`
|
|
@@ -324,6 +324,36 @@ describe('deserialize', () => {
|
|
|
324
324
|
)
|
|
325
325
|
})
|
|
326
326
|
|
|
327
|
+
test('authorization chainId above safe integer range', () => {
|
|
328
|
+
expect(() =>
|
|
329
|
+
TxEnvelopeEip7702.deserialize(
|
|
330
|
+
`0x04${Rlp.fromHex([
|
|
331
|
+
Hex.fromNumber(1), // chainId
|
|
332
|
+
'0x', // nonce
|
|
333
|
+
Hex.fromNumber(1), // maxPriorityFeePerGas
|
|
334
|
+
Hex.fromNumber(1), // maxFeePerGas
|
|
335
|
+
Hex.fromNumber(1), // gas
|
|
336
|
+
'0x0000000000000000000000000000000000000000', // to
|
|
337
|
+
'0x', // value
|
|
338
|
+
'0x', // data
|
|
339
|
+
[], // accessList
|
|
340
|
+
[
|
|
341
|
+
[
|
|
342
|
+
'0x20000000000001',
|
|
343
|
+
'0x0000000000000000000000000000000000000000',
|
|
344
|
+
'0x01',
|
|
345
|
+
'0x',
|
|
346
|
+
'0x01',
|
|
347
|
+
'0x02',
|
|
348
|
+
],
|
|
349
|
+
], // authorizationList
|
|
350
|
+
]).slice(2)}`,
|
|
351
|
+
),
|
|
352
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
353
|
+
`[Hex.IntegerOutOfRangeError: Number \`9007199254740992\` is not in safe unsigned integer range (\`0\` to \`9007199254740991\`)]`,
|
|
354
|
+
)
|
|
355
|
+
})
|
|
356
|
+
|
|
327
357
|
test('invalid access list (invalid address)', () => {
|
|
328
358
|
expect(() =>
|
|
329
359
|
TxEnvelopeEip7702.deserialize(
|
|
@@ -423,6 +453,109 @@ describe('deserialize', () => {
|
|
|
423
453
|
Missing Attributes: r, s]
|
|
424
454
|
`)
|
|
425
455
|
})
|
|
456
|
+
|
|
457
|
+
describe('authorization tuple length', () => {
|
|
458
|
+
const address = '0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c'
|
|
459
|
+
const r =
|
|
460
|
+
'0x68a020a209d3d56c46f38cc50a33f704f4a9a10a59377f8dd762ac66910e9b90'
|
|
461
|
+
const s =
|
|
462
|
+
'0x7e865ad05c4035ab5792787d4a0297a43617ae897930a6fe4d822b8faea52064'
|
|
463
|
+
|
|
464
|
+
const serialize = (authorization: readonly Hex.Hex[]) =>
|
|
465
|
+
`0x04${Rlp.fromHex([
|
|
466
|
+
'0x01', // chainId
|
|
467
|
+
'0x', // nonce
|
|
468
|
+
'0x01', // maxPriorityFeePerGas
|
|
469
|
+
'0x01', // maxFeePerGas
|
|
470
|
+
'0x01', // gas
|
|
471
|
+
'0x0000000000000000000000000000000000000000', // to
|
|
472
|
+
'0x', // value
|
|
473
|
+
'0x', // data
|
|
474
|
+
[], // accessList
|
|
475
|
+
[authorization], // authorizationList
|
|
476
|
+
'0x', // yParity
|
|
477
|
+
'0x01', // r
|
|
478
|
+
'0x02', // s
|
|
479
|
+
]).slice(2)}` as const
|
|
480
|
+
|
|
481
|
+
test('6 fields round trip', () => {
|
|
482
|
+
const serialized = serialize(['0x01', address, '0x03', '0x01', r, s])
|
|
483
|
+
expect(
|
|
484
|
+
TxEnvelopeEip7702.serialize(
|
|
485
|
+
TxEnvelopeEip7702.deserialize(serialized),
|
|
486
|
+
),
|
|
487
|
+
).toBe(serialized)
|
|
488
|
+
})
|
|
489
|
+
|
|
490
|
+
test('3 fields', () => {
|
|
491
|
+
expect(() =>
|
|
492
|
+
TxEnvelopeEip7702.deserialize(serialize(['0x01', address, '0x03'])),
|
|
493
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
494
|
+
[Authorization.InvalidError: Invalid authorization.
|
|
495
|
+
|
|
496
|
+
Details: Expected [chainId, address, nonce, yParity, r, s].]
|
|
497
|
+
`)
|
|
498
|
+
})
|
|
499
|
+
|
|
500
|
+
test('4 fields', () => {
|
|
501
|
+
expect(() =>
|
|
502
|
+
TxEnvelopeEip7702.deserialize(
|
|
503
|
+
serialize(['0x01', address, '0x03', '0x01']),
|
|
504
|
+
),
|
|
505
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
506
|
+
[Authorization.InvalidError: Invalid authorization.
|
|
507
|
+
|
|
508
|
+
Details: Expected [chainId, address, nonce, yParity, r, s].]
|
|
509
|
+
`)
|
|
510
|
+
})
|
|
511
|
+
|
|
512
|
+
test('5 fields', () => {
|
|
513
|
+
expect(() =>
|
|
514
|
+
TxEnvelopeEip7702.deserialize(
|
|
515
|
+
serialize(['0x01', address, '0x03', '0x01', r]),
|
|
516
|
+
),
|
|
517
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
518
|
+
[Authorization.InvalidError: Invalid authorization.
|
|
519
|
+
|
|
520
|
+
Details: Expected [chainId, address, nonce, yParity, r, s].]
|
|
521
|
+
`)
|
|
522
|
+
})
|
|
523
|
+
|
|
524
|
+
test('7 fields', () => {
|
|
525
|
+
expect(() =>
|
|
526
|
+
TxEnvelopeEip7702.deserialize(
|
|
527
|
+
serialize(['0x01', address, '0x03', '0x01', r, s, '0xdeadbeef']),
|
|
528
|
+
),
|
|
529
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
530
|
+
[Authorization.InvalidError: Invalid authorization.
|
|
531
|
+
|
|
532
|
+
Details: Expected [chainId, address, nonce, yParity, r, s].]
|
|
533
|
+
`)
|
|
534
|
+
})
|
|
535
|
+
|
|
536
|
+
test('not a list', () => {
|
|
537
|
+
expect(() =>
|
|
538
|
+
TxEnvelopeEip7702.deserialize(
|
|
539
|
+
`0x04${Rlp.fromHex([
|
|
540
|
+
'0x01', // chainId
|
|
541
|
+
'0x', // nonce
|
|
542
|
+
'0x01', // maxPriorityFeePerGas
|
|
543
|
+
'0x01', // maxFeePerGas
|
|
544
|
+
'0x01', // gas
|
|
545
|
+
'0x0000000000000000000000000000000000000000', // to
|
|
546
|
+
'0x', // value
|
|
547
|
+
'0x', // data
|
|
548
|
+
[], // accessList
|
|
549
|
+
['0x010203040506'], // authorizationList
|
|
550
|
+
]).slice(2)}`,
|
|
551
|
+
),
|
|
552
|
+
).toThrowErrorMatchingInlineSnapshot(`
|
|
553
|
+
[Authorization.InvalidError: Invalid authorization.
|
|
554
|
+
|
|
555
|
+
Details: Expected [chainId, address, nonce, yParity, r, s].]
|
|
556
|
+
`)
|
|
557
|
+
})
|
|
558
|
+
})
|
|
426
559
|
})
|
|
427
560
|
})
|
|
428
561
|
|