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
|
@@ -186,6 +186,36 @@ describe('fromRpc', () => {
|
|
|
186
186
|
const request = TransactionRequest.fromRpc({})
|
|
187
187
|
expect(request).toMatchInlineSnapshot('{}')
|
|
188
188
|
})
|
|
189
|
+
|
|
190
|
+
test('behavior: fee payer signature', () => {
|
|
191
|
+
const feePayerSignature = {
|
|
192
|
+
r: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
193
|
+
s: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
194
|
+
} as const
|
|
195
|
+
expect(
|
|
196
|
+
TransactionRequest.fromRpc({
|
|
197
|
+
feePayerSignature: { ...feePayerSignature, yParity: '0x1' },
|
|
198
|
+
type: '0x76',
|
|
199
|
+
}),
|
|
200
|
+
).toMatchInlineSnapshot(`
|
|
201
|
+
{
|
|
202
|
+
"feePayerSignature": {
|
|
203
|
+
"r": "0x0000000000000000000000000000000000000000000000000000000000000001",
|
|
204
|
+
"s": "0x0000000000000000000000000000000000000000000000000000000000000001",
|
|
205
|
+
"yParity": 1,
|
|
206
|
+
},
|
|
207
|
+
"type": "tempo",
|
|
208
|
+
}
|
|
209
|
+
`)
|
|
210
|
+
expect(() =>
|
|
211
|
+
TransactionRequest.fromRpc({
|
|
212
|
+
feePayerSignature: { ...feePayerSignature, yParity: '0x2' },
|
|
213
|
+
type: '0x76',
|
|
214
|
+
}),
|
|
215
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
216
|
+
`[Signature.InvalidYParityError: Value \`2\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
|
|
217
|
+
)
|
|
218
|
+
})
|
|
189
219
|
})
|
|
190
220
|
|
|
191
221
|
describe('toRpc', () => {
|
|
@@ -123,8 +123,11 @@ export function fromRpc(request: Rpc): TransactionRequest {
|
|
|
123
123
|
)
|
|
124
124
|
if (request.signature)
|
|
125
125
|
request_.signature = SignatureEnvelope.fromRpc(request.signature)
|
|
126
|
-
if (request.feePayerSignature)
|
|
127
|
-
|
|
126
|
+
if (request.feePayerSignature) {
|
|
127
|
+
const feePayerSignature = Signature.fromRpc(request.feePayerSignature)
|
|
128
|
+
Signature.assert(feePayerSignature, { recovered: true })
|
|
129
|
+
request_.feePayerSignature = feePayerSignature
|
|
130
|
+
}
|
|
128
131
|
if (request.calls)
|
|
129
132
|
request_.calls = request.calls.map((call) => {
|
|
130
133
|
const mapped: Call<bigint> = {
|
|
@@ -170,6 +173,8 @@ export declare namespace fromRpc {
|
|
|
170
173
|
| Hex.toNumber.ErrorType
|
|
171
174
|
| Hex.toBigInt.ErrorType
|
|
172
175
|
| AccountSimulation.fromRpc.ErrorType
|
|
176
|
+
| Signature.assert.ErrorType
|
|
177
|
+
| Signature.fromRpc.ErrorType
|
|
173
178
|
| Errors.GlobalErrorType
|
|
174
179
|
}
|
|
175
180
|
|
|
@@ -66,6 +66,50 @@ describe('assert', () => {
|
|
|
66
66
|
)
|
|
67
67
|
})
|
|
68
68
|
|
|
69
|
+
test('invalid validity bound', () => {
|
|
70
|
+
const envelope = {
|
|
71
|
+
calls: [{ to: '0x0000000000000000000000000000000000000000' }],
|
|
72
|
+
chainId: 1,
|
|
73
|
+
} as const
|
|
74
|
+
expect(() =>
|
|
75
|
+
TxEnvelopeTempo.assert({
|
|
76
|
+
...envelope,
|
|
77
|
+
validBefore: 1700003600n as never,
|
|
78
|
+
}),
|
|
79
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
80
|
+
`[TxEnvelopeTempo.InvalidValidityBoundError: validBefore (1700003600n) must be a non-negative safe integer number.]`,
|
|
81
|
+
)
|
|
82
|
+
expect(() =>
|
|
83
|
+
TxEnvelopeTempo.assert({
|
|
84
|
+
...envelope,
|
|
85
|
+
validAfter: '0x6553f100' as never,
|
|
86
|
+
}),
|
|
87
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
88
|
+
`[TxEnvelopeTempo.InvalidValidityBoundError: validAfter ("0x6553f100") must be a non-negative safe integer number.]`,
|
|
89
|
+
)
|
|
90
|
+
expect(() =>
|
|
91
|
+
TxEnvelopeTempo.assert({ ...envelope, validBefore: -1 }),
|
|
92
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
93
|
+
`[TxEnvelopeTempo.InvalidValidityBoundError: validBefore (-1) must be a non-negative safe integer number.]`,
|
|
94
|
+
)
|
|
95
|
+
expect(() =>
|
|
96
|
+
TxEnvelopeTempo.assert({ ...envelope, validAfter: 1.5 }),
|
|
97
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
98
|
+
`[TxEnvelopeTempo.InvalidValidityBoundError: validAfter (1.5) must be a non-negative safe integer number.]`,
|
|
99
|
+
)
|
|
100
|
+
expect(() =>
|
|
101
|
+
TxEnvelopeTempo.assert({
|
|
102
|
+
...envelope,
|
|
103
|
+
validBefore: Number.MAX_SAFE_INTEGER + 1,
|
|
104
|
+
}),
|
|
105
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
106
|
+
`[TxEnvelopeTempo.InvalidValidityBoundError: validBefore (9007199254740992) must be a non-negative safe integer number.]`,
|
|
107
|
+
)
|
|
108
|
+
expect(() =>
|
|
109
|
+
TxEnvelopeTempo.assert({ ...envelope, validAfter: 0, validBefore: 1 }),
|
|
110
|
+
).not.toThrow()
|
|
111
|
+
})
|
|
112
|
+
|
|
69
113
|
test('invalid call address', () => {
|
|
70
114
|
expect(() =>
|
|
71
115
|
TxEnvelopeTempo.assert({
|
|
@@ -129,6 +173,93 @@ describe('assert', () => {
|
|
|
129
173
|
`[TransactionEnvelope.InvalidChainIdError: Chain ID "0" is invalid.]`,
|
|
130
174
|
)
|
|
131
175
|
})
|
|
176
|
+
|
|
177
|
+
test('invalid chain id (not a positive safe integer)', () => {
|
|
178
|
+
expect(() =>
|
|
179
|
+
TxEnvelopeTempo.assert({
|
|
180
|
+
calls: [{ to: '0x0000000000000000000000000000000000000000' }],
|
|
181
|
+
chainId: Number.NaN,
|
|
182
|
+
}),
|
|
183
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
184
|
+
`[TransactionEnvelope.InvalidChainIdError: Chain ID "NaN" is invalid.]`,
|
|
185
|
+
)
|
|
186
|
+
expect(() =>
|
|
187
|
+
TxEnvelopeTempo.assert({
|
|
188
|
+
calls: [{ to: '0x0000000000000000000000000000000000000000' }],
|
|
189
|
+
chainId: 1.5,
|
|
190
|
+
}),
|
|
191
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
192
|
+
`[TransactionEnvelope.InvalidChainIdError: Chain ID "1.5" is invalid.]`,
|
|
193
|
+
)
|
|
194
|
+
expect(() =>
|
|
195
|
+
TxEnvelopeTempo.assert({
|
|
196
|
+
calls: [{ to: '0x0000000000000000000000000000000000000000' }],
|
|
197
|
+
chainId: Number.MAX_SAFE_INTEGER + 1,
|
|
198
|
+
}),
|
|
199
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
200
|
+
`[TransactionEnvelope.InvalidChainIdError: Chain ID "9007199254740992" is invalid.]`,
|
|
201
|
+
)
|
|
202
|
+
expect(() =>
|
|
203
|
+
TxEnvelopeTempo.assert({
|
|
204
|
+
calls: [{ to: '0x0000000000000000000000000000000000000000' }],
|
|
205
|
+
chainId: '1' as never,
|
|
206
|
+
}),
|
|
207
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
208
|
+
`[TransactionEnvelope.InvalidChainIdError: Chain ID "1" is invalid.]`,
|
|
209
|
+
)
|
|
210
|
+
expect(() =>
|
|
211
|
+
TxEnvelopeTempo.assert({
|
|
212
|
+
calls: [{ to: '0x0000000000000000000000000000000000000000' }],
|
|
213
|
+
chainId: 1n as never,
|
|
214
|
+
}),
|
|
215
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
216
|
+
`[TransactionEnvelope.InvalidChainIdError: Chain ID "1" is invalid.]`,
|
|
217
|
+
)
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
test('invalid fee payer signature', () => {
|
|
221
|
+
const envelope = {
|
|
222
|
+
calls: [{ to: '0x0000000000000000000000000000000000000000' }],
|
|
223
|
+
chainId: 1,
|
|
224
|
+
} as const
|
|
225
|
+
const feePayerSignature = {
|
|
226
|
+
r: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
227
|
+
s: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
228
|
+
} as const
|
|
229
|
+
expect(() =>
|
|
230
|
+
TxEnvelopeTempo.assert({
|
|
231
|
+
...envelope,
|
|
232
|
+
feePayerSignature: { ...feePayerSignature, yParity: 2 },
|
|
233
|
+
}),
|
|
234
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
235
|
+
`[Signature.InvalidYParityError: Value \`2\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
|
|
236
|
+
)
|
|
237
|
+
expect(() =>
|
|
238
|
+
TxEnvelopeTempo.assert({
|
|
239
|
+
...envelope,
|
|
240
|
+
feePayerSignature: { ...feePayerSignature, yParity: 27 },
|
|
241
|
+
}),
|
|
242
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
243
|
+
`[Signature.InvalidYParityError: Value \`27\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
|
|
244
|
+
)
|
|
245
|
+
expect(() =>
|
|
246
|
+
TxEnvelopeTempo.assert({
|
|
247
|
+
...envelope,
|
|
248
|
+
feePayerSignature: feePayerSignature as never,
|
|
249
|
+
}),
|
|
250
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
251
|
+
`[Signature.MissingPropertiesError: Signature \`{"r":"0x0000000000000000000000000000000000000000000000000000000000000001","s":"0x0000000000000000000000000000000000000000000000000000000000000001"}\` is missing either an \`r\`, \`s\`, or \`yParity\` property.]`,
|
|
252
|
+
)
|
|
253
|
+
expect(() =>
|
|
254
|
+
TxEnvelopeTempo.assert({
|
|
255
|
+
...envelope,
|
|
256
|
+
feePayerSignature: { ...feePayerSignature, yParity: 1 },
|
|
257
|
+
}),
|
|
258
|
+
).not.toThrow()
|
|
259
|
+
expect(() =>
|
|
260
|
+
TxEnvelopeTempo.assert({ ...envelope, feePayerSignature: null }),
|
|
261
|
+
).not.toThrow()
|
|
262
|
+
})
|
|
132
263
|
})
|
|
133
264
|
|
|
134
265
|
describe('deserialize', () => {
|
|
@@ -805,6 +936,19 @@ describe('from', () => {
|
|
|
805
936
|
}
|
|
806
937
|
})
|
|
807
938
|
|
|
939
|
+
test('invalid validity bound', () => {
|
|
940
|
+
expect(() =>
|
|
941
|
+
TxEnvelopeTempo.from({
|
|
942
|
+
calls: [{ to: '0x0000000000000000000000000000000000000000' }],
|
|
943
|
+
chainId: 1,
|
|
944
|
+
validAfter: 1700000000n as never,
|
|
945
|
+
validBefore: 1700003600n as never,
|
|
946
|
+
}),
|
|
947
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
948
|
+
`[TxEnvelopeTempo.InvalidValidityBoundError: validBefore (1700003600n) must be a non-negative safe integer number.]`,
|
|
949
|
+
)
|
|
950
|
+
})
|
|
951
|
+
|
|
808
952
|
test('options: signature', () => {
|
|
809
953
|
const envelope = TxEnvelopeTempo.from(
|
|
810
954
|
{
|
|
@@ -945,6 +1089,23 @@ describe('from', () => {
|
|
|
945
1089
|
}
|
|
946
1090
|
`)
|
|
947
1091
|
})
|
|
1092
|
+
|
|
1093
|
+
test('invalid fee payer signature', () => {
|
|
1094
|
+
expect(() =>
|
|
1095
|
+
TxEnvelopeTempo.from({
|
|
1096
|
+
calls: [{}],
|
|
1097
|
+
chainId: 1,
|
|
1098
|
+
feePayerSignature: {
|
|
1099
|
+
r: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1100
|
+
s: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1101
|
+
yParity: 2,
|
|
1102
|
+
},
|
|
1103
|
+
nonce: 0n,
|
|
1104
|
+
}),
|
|
1105
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1106
|
+
`[Signature.InvalidYParityError: Value \`2\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
|
|
1107
|
+
)
|
|
1108
|
+
})
|
|
948
1109
|
})
|
|
949
1110
|
|
|
950
1111
|
describe('serialize', () => {
|
|
@@ -989,6 +1150,40 @@ describe('serialize', () => {
|
|
|
989
1150
|
)
|
|
990
1151
|
})
|
|
991
1152
|
|
|
1153
|
+
test('validBefore and validAfter', () => {
|
|
1154
|
+
const transaction = {
|
|
1155
|
+
chainId: 1,
|
|
1156
|
+
calls: [{}],
|
|
1157
|
+
nonce: 0n,
|
|
1158
|
+
} as const
|
|
1159
|
+
expect(
|
|
1160
|
+
TxEnvelopeTempo.serialize({
|
|
1161
|
+
...transaction,
|
|
1162
|
+
validAfter: 1700000000,
|
|
1163
|
+
validBefore: 1700003600,
|
|
1164
|
+
}),
|
|
1165
|
+
).toMatchInlineSnapshot(
|
|
1166
|
+
`"0x76d901808080c4c3808080c08080846553ff10846553f1008080c0"`,
|
|
1167
|
+
)
|
|
1168
|
+
expect(() =>
|
|
1169
|
+
TxEnvelopeTempo.serialize({
|
|
1170
|
+
...transaction,
|
|
1171
|
+
validAfter: 1700000000n as never,
|
|
1172
|
+
validBefore: 1700003600n as never,
|
|
1173
|
+
}),
|
|
1174
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1175
|
+
`[TxEnvelopeTempo.InvalidValidityBoundError: validBefore (1700003600n) must be a non-negative safe integer number.]`,
|
|
1176
|
+
)
|
|
1177
|
+
expect(() =>
|
|
1178
|
+
TxEnvelopeTempo.serialize({
|
|
1179
|
+
...transaction,
|
|
1180
|
+
validBefore: '0x6553ff10' as never,
|
|
1181
|
+
}),
|
|
1182
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1183
|
+
`[TxEnvelopeTempo.InvalidValidityBoundError: validBefore ("0x6553ff10") must be a non-negative safe integer number.]`,
|
|
1184
|
+
)
|
|
1185
|
+
})
|
|
1186
|
+
|
|
992
1187
|
test('multiple calls', () => {
|
|
993
1188
|
const transaction = TxEnvelopeTempo.from({
|
|
994
1189
|
chainId: 1,
|
|
@@ -1341,6 +1536,47 @@ describe('serialize', () => {
|
|
|
1341
1536
|
)
|
|
1342
1537
|
})
|
|
1343
1538
|
|
|
1539
|
+
test('with feePayerSignature (invalid yParity)', () => {
|
|
1540
|
+
const transaction = {
|
|
1541
|
+
calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }],
|
|
1542
|
+
chainId: 1,
|
|
1543
|
+
nonce: 0n,
|
|
1544
|
+
} as const
|
|
1545
|
+
const feePayerSignature = {
|
|
1546
|
+
r: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1547
|
+
s: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1548
|
+
} as const
|
|
1549
|
+
expect(
|
|
1550
|
+
TxEnvelopeTempo.serialize(transaction, {
|
|
1551
|
+
feePayerSignature: { ...feePayerSignature, yParity: 1 },
|
|
1552
|
+
}),
|
|
1553
|
+
).toMatchInlineSnapshot(
|
|
1554
|
+
`"0x76e801808080d8d79470997970c51812dc3a010c7d01b50e0d17dc79c88080c08080808080c3010101c0"`,
|
|
1555
|
+
)
|
|
1556
|
+
expect(() =>
|
|
1557
|
+
TxEnvelopeTempo.serialize(transaction, {
|
|
1558
|
+
feePayerSignature: { ...feePayerSignature, yParity: 2 },
|
|
1559
|
+
}),
|
|
1560
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1561
|
+
`[Signature.InvalidYParityError: Value \`2\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
|
|
1562
|
+
)
|
|
1563
|
+
expect(() =>
|
|
1564
|
+
TxEnvelopeTempo.serialize(transaction, {
|
|
1565
|
+
feePayerSignature: { ...feePayerSignature, yParity: 27 },
|
|
1566
|
+
}),
|
|
1567
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1568
|
+
`[Signature.InvalidYParityError: Value \`27\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
|
|
1569
|
+
)
|
|
1570
|
+
expect(() =>
|
|
1571
|
+
TxEnvelopeTempo.serialize({
|
|
1572
|
+
...transaction,
|
|
1573
|
+
feePayerSignature: { ...feePayerSignature, yParity: 2 },
|
|
1574
|
+
}),
|
|
1575
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1576
|
+
`[Signature.InvalidYParityError: Value \`2\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
|
|
1577
|
+
)
|
|
1578
|
+
})
|
|
1579
|
+
|
|
1344
1580
|
test('format: feePayer', () => {
|
|
1345
1581
|
const transaction = TxEnvelopeTempo.from({
|
|
1346
1582
|
chainId: 1,
|
|
@@ -1466,6 +1702,24 @@ describe('hash', () => {
|
|
|
1466
1702
|
})
|
|
1467
1703
|
})
|
|
1468
1704
|
|
|
1705
|
+
test('invalid fee payer signature', () => {
|
|
1706
|
+
expect(() =>
|
|
1707
|
+
TxEnvelopeTempo.hash({
|
|
1708
|
+
calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }],
|
|
1709
|
+
chainId: 1,
|
|
1710
|
+
feePayerSignature: {
|
|
1711
|
+
r: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1712
|
+
s: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1713
|
+
yParity: 2,
|
|
1714
|
+
},
|
|
1715
|
+
nonce: 0n,
|
|
1716
|
+
type: 'tempo',
|
|
1717
|
+
} as never),
|
|
1718
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1719
|
+
`[Signature.InvalidYParityError: Value \`2\` is an invalid y-parity value. Y-parity must be 0 or 1.]`,
|
|
1720
|
+
)
|
|
1721
|
+
})
|
|
1722
|
+
|
|
1469
1723
|
test('presign', () => {
|
|
1470
1724
|
const transaction = TxEnvelopeTempo.from({
|
|
1471
1725
|
chainId: 1,
|
|
@@ -1482,6 +1736,23 @@ describe('hash', () => {
|
|
|
1482
1736
|
`"0xe1222a45806457acbe3a13940aae4c34f3180659fa16613b5a45dc183adae07c"`,
|
|
1483
1737
|
)
|
|
1484
1738
|
})
|
|
1739
|
+
|
|
1740
|
+
test('invalid validity bound', () => {
|
|
1741
|
+
expect(() =>
|
|
1742
|
+
TxEnvelopeTempo.hash(
|
|
1743
|
+
{
|
|
1744
|
+
calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }],
|
|
1745
|
+
chainId: 1,
|
|
1746
|
+
nonce: 0n,
|
|
1747
|
+
type: 'tempo',
|
|
1748
|
+
validBefore: 1700003600n as never,
|
|
1749
|
+
},
|
|
1750
|
+
{ presign: true },
|
|
1751
|
+
),
|
|
1752
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1753
|
+
`[TxEnvelopeTempo.InvalidValidityBoundError: validBefore (1700003600n) must be a non-negative safe integer number.]`,
|
|
1754
|
+
)
|
|
1755
|
+
})
|
|
1485
1756
|
})
|
|
1486
1757
|
|
|
1487
1758
|
describe('encodeForSigning', () => {
|
|
@@ -1560,6 +1831,20 @@ describe('getSignPayload', () => {
|
|
|
1560
1831
|
`"0xe1222a45806457acbe3a13940aae4c34f3180659fa16613b5a45dc183adae07c"`,
|
|
1561
1832
|
)
|
|
1562
1833
|
})
|
|
1834
|
+
|
|
1835
|
+
test('invalid validity bound', () => {
|
|
1836
|
+
expect(() =>
|
|
1837
|
+
TxEnvelopeTempo.getSignPayload({
|
|
1838
|
+
calls: [{ to: '0x70997970c51812dc3a010c7d01b50e0d17dc79c8' }],
|
|
1839
|
+
chainId: 1,
|
|
1840
|
+
nonce: 0n,
|
|
1841
|
+
type: 'tempo',
|
|
1842
|
+
validBefore: 1700003600n as never,
|
|
1843
|
+
}),
|
|
1844
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
1845
|
+
`[TxEnvelopeTempo.InvalidValidityBoundError: validBefore (1700003600n) must be a non-negative safe integer number.]`,
|
|
1846
|
+
)
|
|
1847
|
+
})
|
|
1563
1848
|
})
|
|
1564
1849
|
|
|
1565
1850
|
describe('getFeePayerSignPayload', () => {
|
|
@@ -1629,6 +1914,20 @@ describe('validate', () => {
|
|
|
1629
1914
|
).toBe(false)
|
|
1630
1915
|
})
|
|
1631
1916
|
|
|
1917
|
+
test('invalid (fee payer signature)', () => {
|
|
1918
|
+
expect(
|
|
1919
|
+
TxEnvelopeTempo.validate({
|
|
1920
|
+
calls: [{ to: '0x0000000000000000000000000000000000000000' }],
|
|
1921
|
+
chainId: 1,
|
|
1922
|
+
feePayerSignature: {
|
|
1923
|
+
r: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1924
|
+
s: '0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1925
|
+
yParity: 2,
|
|
1926
|
+
},
|
|
1927
|
+
}),
|
|
1928
|
+
).toBe(false)
|
|
1929
|
+
})
|
|
1930
|
+
|
|
1632
1931
|
test('invalid (validity window)', () => {
|
|
1633
1932
|
expect(
|
|
1634
1933
|
TxEnvelopeTempo.validate({
|
|
@@ -1639,6 +1938,17 @@ describe('validate', () => {
|
|
|
1639
1938
|
}),
|
|
1640
1939
|
).toBe(false)
|
|
1641
1940
|
})
|
|
1941
|
+
|
|
1942
|
+
test('invalid (validity bound)', () => {
|
|
1943
|
+
expect(
|
|
1944
|
+
TxEnvelopeTempo.validate({
|
|
1945
|
+
calls: [{ to: '0x0000000000000000000000000000000000000000' }],
|
|
1946
|
+
chainId: 1,
|
|
1947
|
+
validBefore: 100n as never,
|
|
1948
|
+
validAfter: 200n as never,
|
|
1949
|
+
}),
|
|
1950
|
+
).toBe(false)
|
|
1951
|
+
})
|
|
1642
1952
|
})
|
|
1643
1953
|
|
|
1644
1954
|
describe('toTransactionRequest', () => {
|
|
@@ -173,6 +173,7 @@ export function assert(envelope: PartialBy<TxEnvelopeTempo, 'type'>) {
|
|
|
173
173
|
const {
|
|
174
174
|
calls,
|
|
175
175
|
chainId,
|
|
176
|
+
feePayerSignature,
|
|
176
177
|
feeToken,
|
|
177
178
|
maxFeePerGas,
|
|
178
179
|
maxPriorityFeePerGas,
|
|
@@ -183,6 +184,18 @@ export function assert(envelope: PartialBy<TxEnvelopeTempo, 'type'>) {
|
|
|
183
184
|
// Calls must not be empty
|
|
184
185
|
if (!calls || calls.length === 0) throw new CallsEmptyError()
|
|
185
186
|
|
|
187
|
+
// validBefore and validAfter must be non-negative safe integers if set
|
|
188
|
+
for (const [name, value] of [
|
|
189
|
+
['validBefore', validBefore],
|
|
190
|
+
['validAfter', validAfter],
|
|
191
|
+
] as const)
|
|
192
|
+
if (
|
|
193
|
+
value !== undefined &&
|
|
194
|
+
value !== null &&
|
|
195
|
+
!(Number.isSafeInteger(value) && value >= 0)
|
|
196
|
+
)
|
|
197
|
+
throw new InvalidValidityBoundError({ name, value })
|
|
198
|
+
|
|
186
199
|
// validBefore must be greater than validAfter if both are set
|
|
187
200
|
if (
|
|
188
201
|
typeof validBefore === 'number' &&
|
|
@@ -204,7 +217,10 @@ export function assert(envelope: PartialBy<TxEnvelopeTempo, 'type'>) {
|
|
|
204
217
|
if (feeToken) Address.assert(feeToken, { strict: false })
|
|
205
218
|
|
|
206
219
|
// Validate chain ID
|
|
207
|
-
if (
|
|
220
|
+
if (
|
|
221
|
+
typeof chainId !== 'undefined' &&
|
|
222
|
+
(!Number.isSafeInteger(chainId) || chainId <= 0)
|
|
223
|
+
)
|
|
208
224
|
throw new TransactionEnvelope.InvalidChainIdError({ chainId })
|
|
209
225
|
|
|
210
226
|
// Validate max fee per gas
|
|
@@ -222,13 +238,19 @@ export function assert(envelope: PartialBy<TxEnvelopeTempo, 'type'>) {
|
|
|
222
238
|
maxFeePerGas,
|
|
223
239
|
maxPriorityFeePerGas,
|
|
224
240
|
})
|
|
241
|
+
|
|
242
|
+
// Validate fee payer signature
|
|
243
|
+
if (feePayerSignature)
|
|
244
|
+
Signature.assert(feePayerSignature, { recovered: true })
|
|
225
245
|
}
|
|
226
246
|
|
|
227
247
|
export declare namespace assert {
|
|
228
248
|
type ErrorType =
|
|
229
249
|
| Address.assert.ErrorType
|
|
230
250
|
| CallsEmptyError
|
|
251
|
+
| InvalidValidityBoundError
|
|
231
252
|
| InvalidValidityWindowError
|
|
253
|
+
| Signature.assert.ErrorType
|
|
232
254
|
| Errors.GlobalErrorType
|
|
233
255
|
}
|
|
234
256
|
|
|
@@ -716,6 +738,7 @@ export function serialize(
|
|
|
716
738
|
// No fee payer involvement — omit from the envelope.
|
|
717
739
|
if (!feePayerSignature) return '0x'
|
|
718
740
|
// Fee payer has signed — encode the signature as an RLP tuple.
|
|
741
|
+
Signature.assert(feePayerSignature, { recovered: true })
|
|
719
742
|
return Signature.toTuple(feePayerSignature)
|
|
720
743
|
})()
|
|
721
744
|
|
|
@@ -1136,6 +1159,46 @@ export class CallsEmptyError extends Errors.BaseError {
|
|
|
1136
1159
|
}
|
|
1137
1160
|
}
|
|
1138
1161
|
|
|
1162
|
+
/**
|
|
1163
|
+
* Thrown when validBefore or validAfter is not a non-negative safe integer number.
|
|
1164
|
+
*
|
|
1165
|
+
* @example
|
|
1166
|
+
* ```ts twoslash
|
|
1167
|
+
* import { Address } from 'ox'
|
|
1168
|
+
* import { TxEnvelopeTempo } from 'ox/tempo'
|
|
1169
|
+
*
|
|
1170
|
+
* TxEnvelopeTempo.assert({
|
|
1171
|
+
* calls: [
|
|
1172
|
+
* {
|
|
1173
|
+
* to: Address.from(
|
|
1174
|
+
* '0x0000000000000000000000000000000000000000'
|
|
1175
|
+
* )
|
|
1176
|
+
* }
|
|
1177
|
+
* ],
|
|
1178
|
+
* chainId: 1,
|
|
1179
|
+
* validBefore: -1
|
|
1180
|
+
* })
|
|
1181
|
+
* // @error: TxEnvelopeTempo.InvalidValidityBoundError: validBefore (-1) must be a non-negative safe integer number.
|
|
1182
|
+
* ```
|
|
1183
|
+
*/
|
|
1184
|
+
export class InvalidValidityBoundError extends Errors.BaseError {
|
|
1185
|
+
override readonly name = 'TxEnvelopeTempo.InvalidValidityBoundError'
|
|
1186
|
+
constructor({
|
|
1187
|
+
name,
|
|
1188
|
+
value,
|
|
1189
|
+
}: {
|
|
1190
|
+
name: 'validAfter' | 'validBefore'
|
|
1191
|
+
value: unknown
|
|
1192
|
+
}) {
|
|
1193
|
+
const value_ = (() => {
|
|
1194
|
+
if (typeof value === 'bigint') return `${value}n`
|
|
1195
|
+
if (typeof value === 'string') return `"${value}"`
|
|
1196
|
+
return String(value)
|
|
1197
|
+
})()
|
|
1198
|
+
super(`${name} (${value_}) must be a non-negative safe integer number.`)
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1139
1202
|
/**
|
|
1140
1203
|
* Thrown when validBefore is not greater than validAfter.
|
|
1141
1204
|
*
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { bench, describe } from 'vp/test'
|
|
2
|
+
import * as VirtualMasterPool from './internal/virtualMasterPool.js'
|
|
2
3
|
import * as VirtualMaster from './VirtualMaster.js'
|
|
3
4
|
|
|
4
5
|
const address = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266' as const
|
|
@@ -40,3 +41,9 @@ describe('VirtualMaster.validateSalt', () => {
|
|
|
40
41
|
VirtualMaster.validateSalt({ address, salt: 0n })
|
|
41
42
|
})
|
|
42
43
|
})
|
|
44
|
+
|
|
45
|
+
describe('VirtualMasterPool.resolveNode', () => {
|
|
46
|
+
bench('default', async () => {
|
|
47
|
+
await VirtualMasterPool.resolveNode()
|
|
48
|
+
})
|
|
49
|
+
})
|
package/src/tempo/ZoneId.test.ts
CHANGED
|
@@ -13,6 +13,17 @@ describe('fromChainId', () => {
|
|
|
13
13
|
)
|
|
14
14
|
})
|
|
15
15
|
|
|
16
|
+
test('other source chains', () => {
|
|
17
|
+
// Source chain 31318, zone 1: 31318 * 2^32 + 1.
|
|
18
|
+
expect(ZoneId.fromChainId(134_509_785_776_129)).toMatchInlineSnapshot(`1`)
|
|
19
|
+
expect(
|
|
20
|
+
ZoneId.fromChainId(134_509_785_776_129, 42_431),
|
|
21
|
+
).toMatchInlineSnapshot(`1`)
|
|
22
|
+
expect(ZoneId.fromChainId(2 ** 32 + 4_294_967_295)).toMatchInlineSnapshot(
|
|
23
|
+
`4294967295`,
|
|
24
|
+
)
|
|
25
|
+
})
|
|
26
|
+
|
|
16
27
|
test('unsupported source id', () => {
|
|
17
28
|
expect(() =>
|
|
18
29
|
// @ts-expect-error Unsupported source ID.
|
package/src/tempo/ZoneId.ts
CHANGED
|
@@ -13,6 +13,9 @@ const chainIdConfig = {
|
|
|
13
13
|
|
|
14
14
|
const defaultSourceId = 4_217
|
|
15
15
|
|
|
16
|
+
/** Chain IDs at or above this value carry their source chain ID in the high 32 bits. */
|
|
17
|
+
const genericChainIdBase = 2 ** 32
|
|
18
|
+
|
|
16
19
|
/**
|
|
17
20
|
* Base offset for deriving Presto zone chain IDs.
|
|
18
21
|
*/
|
|
@@ -24,7 +27,9 @@ export type SourceId = keyof typeof chainIdConfig
|
|
|
24
27
|
/**
|
|
25
28
|
* Derives a zone ID from a zone chain ID.
|
|
26
29
|
*
|
|
27
|
-
* Zone chain IDs use the base assigned to their Tempo source chain.
|
|
30
|
+
* Zone chain IDs use the base assigned to their Tempo source chain. Zones of other Tempo chains
|
|
31
|
+
* (such as devnets) encode the source chain ID in the high 32 bits and the zone ID in the low 32
|
|
32
|
+
* bits, so the zone ID is read from the chain ID alone.
|
|
28
33
|
*
|
|
29
34
|
* @example
|
|
30
35
|
* ```ts twoslash
|
|
@@ -42,6 +47,7 @@ export function fromChainId(
|
|
|
42
47
|
chainId: number,
|
|
43
48
|
sourceId: SourceId = defaultSourceId,
|
|
44
49
|
): number {
|
|
50
|
+
if (chainId >= genericChainIdBase) return chainId % genericChainIdBase
|
|
45
51
|
return chainId - getChainIdConfig(sourceId).base
|
|
46
52
|
}
|
|
47
53
|
|
|
@@ -245,7 +245,7 @@ describe('behavior: configurable accounts', () => {
|
|
|
245
245
|
...signature,
|
|
246
246
|
signatures: signature.signatures.slice(0, 1),
|
|
247
247
|
}),
|
|
248
|
-
).rejects.toThrow(
|
|
248
|
+
).rejects.toThrow('invalid transaction signature')
|
|
249
249
|
expect((await submit(tx, signature)).status).toMatchInlineSnapshot(
|
|
250
250
|
'"success"',
|
|
251
251
|
)
|
|
@@ -26,7 +26,7 @@ export type Pool = {
|
|
|
26
26
|
): { postMessage(data: unknown): void; terminate(): void }
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
let cachedPool: Pool | undefined
|
|
29
|
+
let cachedPool: Promise<Pool | undefined> | undefined
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* Whether the current runtime is Node.js.
|
|
@@ -42,9 +42,21 @@ const isNode =
|
|
|
42
42
|
*
|
|
43
43
|
* @internal
|
|
44
44
|
*/
|
|
45
|
-
export
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
export function resolve(): Promise<Pool | undefined> {
|
|
46
|
+
// The promise is cached rather than its result, so calls made while the
|
|
47
|
+
// pool resolves share it instead of each building a pool (and, in browsers,
|
|
48
|
+
// a Blob URL that is never revoked). A failed attempt is discarded so a
|
|
49
|
+
// later call can retry, and so is one that found no pool.
|
|
50
|
+
cachedPool ??= (isNode ? resolveNode() : resolveBrowser()).then(
|
|
51
|
+
(pool) => {
|
|
52
|
+
if (!pool) cachedPool = undefined
|
|
53
|
+
return pool
|
|
54
|
+
},
|
|
55
|
+
(error) => {
|
|
56
|
+
cachedPool = undefined
|
|
57
|
+
throw error
|
|
58
|
+
},
|
|
59
|
+
)
|
|
48
60
|
return cachedPool
|
|
49
61
|
}
|
|
50
62
|
|
|
@@ -55,8 +67,10 @@ export async function resolve(): Promise<Pool | undefined> {
|
|
|
55
67
|
*/
|
|
56
68
|
export async function resolveNode(): Promise<Pool | undefined> {
|
|
57
69
|
const id = 'node:worker_threads'
|
|
58
|
-
const { Worker } = await
|
|
59
|
-
|
|
70
|
+
const [{ Worker }, { wasmBase64 }] = await Promise.all([
|
|
71
|
+
import(id),
|
|
72
|
+
import('./mine.wasm.js'),
|
|
73
|
+
])
|
|
60
74
|
const workerSource = getNodeWorkerSource()
|
|
61
75
|
|
|
62
76
|
return {
|