ox 1.8.16 → 1.8.19
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 +70 -0
- package/dist/core/AbiError.d.ts +3 -3
- package/dist/core/AbiError.js +2 -2
- package/dist/core/AbiEvent.d.ts +3 -3
- package/dist/core/AbiEvent.d.ts.map +1 -1
- package/dist/core/AbiEvent.js +29 -24
- package/dist/core/AbiEvent.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/Authorization.d.ts.map +1 -1
- package/dist/core/Authorization.js +6 -3
- 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/BinaryStateTree.js +3 -1
- package/dist/core/BinaryStateTree.js.map +1 -1
- package/dist/core/Blobs.d.ts +4 -5
- package/dist/core/Blobs.d.ts.map +1 -1
- package/dist/core/Blobs.js +40 -45
- package/dist/core/Blobs.js.map +1 -1
- package/dist/core/Block.d.ts +2 -0
- package/dist/core/Block.d.ts.map +1 -1
- package/dist/core/Block.js +1 -0
- package/dist/core/Block.js.map +1 -1
- package/dist/core/BlockOverrides.d.ts +3 -2
- package/dist/core/BlockOverrides.d.ts.map +1 -1
- package/dist/core/BlockOverrides.js +4 -2
- package/dist/core/BlockOverrides.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.d.ts +1 -1
- package/dist/core/Ens.js +3 -3
- 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/Hash.d.ts +1 -1
- package/dist/core/Hash.js +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/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/Siwe.d.ts +1 -0
- package/dist/core/Siwe.d.ts.map +1 -1
- package/dist/core/Siwe.js +15 -8
- package/dist/core/Siwe.js.map +1 -1
- package/dist/core/Transaction.d.ts.map +1 -1
- package/dist/core/Transaction.js +9 -3
- 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/TypedData.d.ts +2 -2
- package/dist/core/TypedData.d.ts.map +1 -1
- package/dist/core/TypedData.js +16 -4
- package/dist/core/TypedData.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 +93 -68
- 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 +11 -4
- package/dist/core/internal/cursor.d.ts.map +1 -1
- package/dist/core/internal/cursor.js +39 -15
- 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/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/tempo/SignatureEnvelope.d.ts.map +1 -1
- package/dist/tempo/SignatureEnvelope.js +7 -41
- 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/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/zod/Authorization.d.ts +14 -14
- package/dist/zod/Authorization.d.ts.map +1 -1
- package/dist/zod/Authorization.js +9 -2
- package/dist/zod/Authorization.js.map +1 -1
- package/dist/zod/Block.d.ts +12 -6
- package/dist/zod/Block.d.ts.map +1 -1
- package/dist/zod/Block.js +1 -0
- package/dist/zod/Block.js.map +1 -1
- package/dist/zod/BlockOverrides.d.ts.map +1 -1
- package/dist/zod/BlockOverrides.js +15 -4
- package/dist/zod/BlockOverrides.js.map +1 -1
- package/dist/zod/RpcSchema.d.ts +58 -46
- package/dist/zod/RpcSchema.d.ts.map +1 -1
- package/dist/zod/Signature.d.ts.map +1 -1
- package/dist/zod/Signature.js +2 -1
- package/dist/zod/Signature.js.map +1 -1
- package/dist/zod/Transaction.d.ts +12 -12
- package/dist/zod/TransactionEnvelope.d.ts +8 -8
- package/dist/zod/TransactionRequest.d.ts +4 -4
- package/dist/zod/TxEnvelopeEip7702.d.ts +8 -8
- package/dist/zod/TypedData.d.ts +4 -4
- package/dist/zod/internal/rpcSchemas/Eth.d.ts +58 -46
- package/dist/zod/internal/rpcSchemas/Eth.d.ts.map +1 -1
- package/dist/zod/internal/rpcSchemas/Wallet.d.ts +4 -4
- package/dist/zod/tempo/RpcSchemaTempo.d.ts +16 -8
- package/dist/zod/tempo/RpcSchemaTempo.d.ts.map +1 -1
- package/dist/zod/tempo/SignatureEnvelope.d.ts.map +1 -1
- package/dist/zod/tempo/SignatureEnvelope.js +5 -15
- package/dist/zod/tempo/SignatureEnvelope.js.map +1 -1
- package/dist/zod/tempo/Transaction.d.ts +6 -6
- package/package.json +2 -2
- package/src/core/AbiError.ts +3 -3
- package/src/core/AbiEvent.bench.ts +45 -0
- package/src/core/AbiEvent.ts +32 -25
- package/src/core/AbiFunction.bench.ts +16 -0
- 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/Authorization.ts +6 -3
- package/src/core/Base58.bench.ts +28 -0
- package/src/core/Base58.ts +15 -4
- package/src/core/BinaryStateTree.ts +4 -1
- package/src/core/Blobs.bench.ts +40 -0
- package/src/core/Blobs.ts +49 -57
- package/src/core/Block.ts +3 -0
- package/src/core/BlockOverrides.ts +7 -3
- 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 +3 -3
- package/src/core/FrameReceipt.ts +4 -1
- package/src/core/Hash.ts +1 -1
- package/src/core/Hex.bench.ts +17 -0
- package/src/core/Hex.ts +29 -32
- 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/Siwe.ts +18 -8
- package/src/core/Transaction.ts +9 -3
- package/src/core/TransactionReceipt.ts +8 -2
- package/src/core/TypedData.bench.ts +50 -0
- package/src/core/TypedData.ts +16 -4
- package/src/core/_test/AbiEvent.test.ts +83 -0
- package/src/core/_test/AbiFunction.test.ts +7 -6
- package/src/core/_test/AbiParameters.decode.test.ts +34 -1
- package/src/core/_test/AbiParameters.encode.test.ts +10 -0
- package/src/core/_test/AbiParameters.test.ts +15 -0
- package/src/core/_test/Authorization.test.ts +36 -0
- package/src/core/_test/BinaryStateTree.test.ts +35 -0
- package/src/core/_test/Block.test.ts +54 -0
- package/src/core/_test/BlockOverrides.test.ts +14 -1
- 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/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/Siwe.test.ts +126 -1
- package/src/core/_test/Transaction.test.ts +47 -2
- package/src/core/_test/TransactionEnvelopeEip7702.test.ts +2 -2
- package/src/core/_test/TransactionReceipt.test.ts +41 -0
- package/src/core/_test/TypedData.test.ts +19 -0
- package/src/core/_test/internal/cursor.test.ts +42 -6
- package/src/core/internal/abiParameters.ts +117 -80
- 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 +52 -23
- package/src/core/internal/lru.ts +21 -35
- package/src/core/internal/promise.ts +11 -5
- package/src/erc4337/_test/UserOperation.test.ts +2 -2
- package/src/erc6492/SignatureErc6492.ts +1 -1
- package/src/erc6492/_test/SignatureErc6492.test.ts +48 -1
- package/src/tempo/SignatureEnvelope.test.ts +89 -1
- package/src/tempo/SignatureEnvelope.ts +7 -43
- package/src/tempo/TransactionReceipt.test.ts +8 -0
- package/src/tempo/TransactionReceipt.ts +4 -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/internal/virtualMasterPool.ts +20 -6
- package/src/tempo/internal/webauthnData.ts +84 -0
- package/src/version.ts +1 -1
- package/src/zod/Authorization.ts +10 -2
- package/src/zod/Block.ts +1 -0
- package/src/zod/BlockOverrides.ts +26 -7
- package/src/zod/Signature.ts +2 -1
- package/src/zod/_test/Authorization.test.ts +26 -0
- package/src/zod/_test/Block.test-d.ts +6 -0
- package/src/zod/_test/Block.test.ts +5 -0
- package/src/zod/_test/BlockOverrides.test.ts +36 -1
- package/src/zod/_test/Signature.test.ts +12 -0
- package/src/zod/tempo/SignatureEnvelope.ts +7 -16
- package/src/zod/tempo/_test/SignatureEnvelope.test.ts +37 -1
- 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
package/src/core/Blobs.ts
CHANGED
|
@@ -3,7 +3,6 @@ import * as Bytes from './Bytes.js'
|
|
|
3
3
|
import * as Errors from './Errors.js'
|
|
4
4
|
import * as Hash from './Hash.js'
|
|
5
5
|
import * as Hex from './Hex.js'
|
|
6
|
-
import * as Cursor from './internal/cursor.js'
|
|
7
6
|
import type { Compute } from './internal/types.js'
|
|
8
7
|
import * as Kzg from './Kzg.js'
|
|
9
8
|
|
|
@@ -290,43 +289,40 @@ export function from<
|
|
|
290
289
|
size: size_,
|
|
291
290
|
})
|
|
292
291
|
|
|
293
|
-
const blobs = []
|
|
292
|
+
const blobs: Bytes.Bytes[] = []
|
|
294
293
|
|
|
295
294
|
let active = true
|
|
296
295
|
let position = 0
|
|
297
296
|
while (active) {
|
|
298
|
-
const blob =
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
297
|
+
const blob = new Uint8Array(bytesPerBlob)
|
|
298
|
+
|
|
299
|
+
// Each field element is a zero byte, so it doesn't overflow the BLS
|
|
300
|
+
// modulus, followed by 31 data bytes. The zero byte is already in place.
|
|
301
|
+
// Copying byte by byte beats a `subarray` view plus `set` at this size, and
|
|
302
|
+
// allocates nothing.
|
|
303
|
+
for (
|
|
304
|
+
let offset = 1;
|
|
305
|
+
offset < bytesPerBlob;
|
|
306
|
+
offset += bytesPerFieldElement
|
|
307
|
+
) {
|
|
308
|
+
const length = Math.min(31, size_ - position)
|
|
309
|
+
for (let i = 0; i < length; i++) blob[offset + i] = data_[position + i]!
|
|
310
|
+
|
|
311
|
+
// A segment shorter than 31 bytes ends the data: push a terminator byte
|
|
312
|
+
// to mark it.
|
|
313
|
+
if (length < 31) {
|
|
314
|
+
blob[offset + length] = 0x80
|
|
314
315
|
active = false
|
|
315
316
|
break
|
|
316
317
|
}
|
|
317
318
|
|
|
318
|
-
size++
|
|
319
319
|
position += 31
|
|
320
320
|
}
|
|
321
321
|
|
|
322
322
|
blobs.push(blob)
|
|
323
323
|
}
|
|
324
324
|
|
|
325
|
-
return (
|
|
326
|
-
as === 'Bytes'
|
|
327
|
-
? blobs.map((x) => x.bytes)
|
|
328
|
-
: blobs.map((x) => Hex.fromBytes(x.bytes))
|
|
329
|
-
) as never
|
|
325
|
+
return (as === 'Bytes' ? blobs : blobs.map((x) => Hex.fromBytes(x))) as never
|
|
330
326
|
}
|
|
331
327
|
|
|
332
328
|
export declare namespace from {
|
|
@@ -344,7 +340,6 @@ export declare namespace from {
|
|
|
344
340
|
| EmptyBlobError
|
|
345
341
|
| Bytes.fromHex.ErrorType
|
|
346
342
|
| Hex.fromBytes.ErrorType
|
|
347
|
-
| Cursor.create.ErrorType
|
|
348
343
|
| Bytes.size.ErrorType
|
|
349
344
|
| Errors.GlobalErrorType
|
|
350
345
|
}
|
|
@@ -371,7 +366,7 @@ export declare namespace from {
|
|
|
371
366
|
*
|
|
372
367
|
* const blobs = Blobs.from('0xdeadbeef')
|
|
373
368
|
* const data = Blobs.to(blobs, 'Bytes')
|
|
374
|
-
* // @log: Uint8Array [
|
|
369
|
+
* // @log: Uint8Array [ 222, 173, 190, 239 ]
|
|
375
370
|
* ```
|
|
376
371
|
*
|
|
377
372
|
* @param blobs - The {@link ox#Blobs.Blobs} to transform.
|
|
@@ -394,39 +389,37 @@ export function to<
|
|
|
394
389
|
: blobs
|
|
395
390
|
) as Bytes.Bytes[]
|
|
396
391
|
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
392
|
+
// Only the final blob contains a terminator: the last `0x80` byte in it, when
|
|
393
|
+
// that byte is data rather than the zero byte leading a field element.
|
|
394
|
+
// Preceding blobs contain only data.
|
|
395
|
+
const last = blobs_[blobs_.length - 1]
|
|
396
|
+
const terminator = last ? last.lastIndexOf(0x80) : -1
|
|
397
|
+
const lastEnd =
|
|
398
|
+
terminator % bytesPerFieldElement > 0 ? terminator : (last?.length ?? 0)
|
|
400
399
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
active = false
|
|
421
|
-
break
|
|
422
|
-
}
|
|
423
|
-
data.pushByte(byte)
|
|
424
|
-
}
|
|
400
|
+
// Each field element contributes all of its bytes but the leading zero byte.
|
|
401
|
+
const dataSize = (end: number) =>
|
|
402
|
+
Math.floor(end / bytesPerFieldElement) * 31 +
|
|
403
|
+
Math.max(0, (end % bytesPerFieldElement) - 1)
|
|
404
|
+
|
|
405
|
+
let length = dataSize(lastEnd)
|
|
406
|
+
for (let index = 0; index < blobs_.length - 1; index++)
|
|
407
|
+
length += dataSize(blobs_[index]!.length)
|
|
408
|
+
|
|
409
|
+
const data = new Uint8Array(length)
|
|
410
|
+
let position = 0
|
|
411
|
+
for (let index = 0; index < blobs_.length; index++) {
|
|
412
|
+
const blob = blobs_[index]!
|
|
413
|
+
const end = index === blobs_.length - 1 ? lastEnd : blob.length
|
|
414
|
+
// Skip the zero byte leading each field element. Copying byte by byte
|
|
415
|
+
// beats a `subarray` view plus `set` for 31 bytes, and allocates nothing.
|
|
416
|
+
for (let offset = 1; offset < end; offset += bytesPerFieldElement) {
|
|
417
|
+
const stop = Math.min(offset + 31, end)
|
|
418
|
+
for (let i = offset; i < stop; i++) data[position++] = blob[i]!
|
|
425
419
|
}
|
|
426
420
|
}
|
|
427
421
|
|
|
428
|
-
|
|
429
|
-
return (to_ === 'Hex' ? Hex.fromBytes(trimmedData) : trimmedData) as never
|
|
422
|
+
return (to_ === 'Hex' ? Hex.fromBytes(data) : data) as never
|
|
430
423
|
}
|
|
431
424
|
|
|
432
425
|
export declare namespace to {
|
|
@@ -437,7 +430,6 @@ export declare namespace to {
|
|
|
437
430
|
type ErrorType =
|
|
438
431
|
| Hex.fromBytes.ErrorType
|
|
439
432
|
| Bytes.fromHex.ErrorType
|
|
440
|
-
| Cursor.create.ErrorType
|
|
441
433
|
| Errors.GlobalErrorType
|
|
442
434
|
}
|
|
443
435
|
|
|
@@ -473,7 +465,7 @@ export declare namespace toHex {
|
|
|
473
465
|
*
|
|
474
466
|
* const blobs = Blobs.from('0xdeadbeef')
|
|
475
467
|
* const data = Blobs.toBytes(blobs) // [!code focus]
|
|
476
|
-
* // @log: Uint8Array [
|
|
468
|
+
* // @log: Uint8Array [ 222, 173, 190, 239 ]
|
|
477
469
|
* ```
|
|
478
470
|
*/
|
|
479
471
|
export function toBytes(
|
package/src/core/Block.ts
CHANGED
|
@@ -49,6 +49,8 @@ export type Block<
|
|
|
49
49
|
parentHash: Hex.Hex
|
|
50
50
|
/** Root of the this block’s receipts trie */
|
|
51
51
|
receiptsRoot: Hex.Hex
|
|
52
|
+
/** EIP-7685 requests hash */
|
|
53
|
+
requestsHash?: Hex.Hex | undefined
|
|
52
54
|
sealFields?: readonly Hex.Hex[] | undefined
|
|
53
55
|
/** SHA3 of the uncles data in this block */
|
|
54
56
|
sha3Uncles: Hex.Hex
|
|
@@ -174,6 +176,7 @@ export function toRpc<
|
|
|
174
176
|
parentBeaconBlockRoot: block.parentBeaconBlockRoot,
|
|
175
177
|
parentHash: block.parentHash,
|
|
176
178
|
receiptsRoot: block.receiptsRoot,
|
|
179
|
+
requestsHash: block.requestsHash,
|
|
177
180
|
sealFields: block.sealFields,
|
|
178
181
|
sha3Uncles: block.sha3Uncles,
|
|
179
182
|
size: Quantity.fromNumberish(block.size),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as Address from './Address.js'
|
|
2
|
-
import
|
|
2
|
+
import * as Hex from './Hex.js'
|
|
3
3
|
import * as Quantity from './internal/quantity.js'
|
|
4
4
|
import * as Withdrawal from './Withdrawal.js'
|
|
5
5
|
|
|
@@ -44,7 +44,8 @@ export type Rpc = BlockOverrides<Hex.Hex, Hex.Hex>
|
|
|
44
44
|
* '0x0000000000000000000000000000000000000000',
|
|
45
45
|
* gasLimit: '0x4',
|
|
46
46
|
* number: '0x5',
|
|
47
|
-
* prevRandao:
|
|
47
|
+
* prevRandao:
|
|
48
|
+
* '0x0000000000000000000000000000000000000000000000000000000000000006',
|
|
48
49
|
* time: '0x1234567890',
|
|
49
50
|
* withdrawals: [
|
|
50
51
|
* {
|
|
@@ -126,7 +127,10 @@ export function toRpc(blockOverrides: toRpc.Input): Rpc {
|
|
|
126
127
|
if (blockOverrides.number !== undefined)
|
|
127
128
|
rpc.number = Quantity.fromNumberish(blockOverrides.number)
|
|
128
129
|
if (blockOverrides.prevRandao !== undefined)
|
|
129
|
-
rpc.prevRandao =
|
|
130
|
+
rpc.prevRandao = Hex.padLeft(
|
|
131
|
+
Quantity.fromNumberish(blockOverrides.prevRandao),
|
|
132
|
+
32,
|
|
133
|
+
)
|
|
130
134
|
if (blockOverrides.time !== undefined)
|
|
131
135
|
rpc.time = Quantity.fromNumberish(blockOverrides.time)
|
|
132
136
|
if (blockOverrides.withdrawals !== undefined)
|
package/src/core/Bytes.bench.ts
CHANGED
|
@@ -21,6 +21,8 @@ const bytes32 = (() => {
|
|
|
21
21
|
return b
|
|
22
22
|
})()
|
|
23
23
|
const bytes32Zero = new Uint8Array(32)
|
|
24
|
+
const bytes32Small = Bytes.fromNumber(1_234_567n, { size: 32 })
|
|
25
|
+
const bytes32Wei = Bytes.fromNumber(42n * 10n ** 18n, { size: 32 })
|
|
24
26
|
|
|
25
27
|
describe('Bytes.fromHex', () => {
|
|
26
28
|
bench('32 bytes', () => {
|
|
@@ -106,9 +108,31 @@ describe('Bytes.toBigInt', () => {
|
|
|
106
108
|
Bytes.toBigInt(bytes32Zero)
|
|
107
109
|
})
|
|
108
110
|
|
|
111
|
+
bench('32 bytes (small value)', () => {
|
|
112
|
+
Bytes.toBigInt(bytes32Small)
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
bench('32 bytes (wei value)', () => {
|
|
116
|
+
Bytes.toBigInt(bytes32Wei)
|
|
117
|
+
})
|
|
118
|
+
|
|
109
119
|
bench('32 bytes, size: 32', () => {
|
|
110
120
|
Bytes.toBigInt(bytes32, { size: 32 })
|
|
111
121
|
})
|
|
122
|
+
|
|
123
|
+
bench('32-byte word holding a small value', () => {
|
|
124
|
+
Bytes.toBigInt(bytes32Small)
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
bench('32 bytes, signed', () => {
|
|
128
|
+
Bytes.toBigInt(bytes32, { signed: true })
|
|
129
|
+
})
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
describe('Bytes.toNumber', () => {
|
|
133
|
+
bench('32-byte word holding a small value', () => {
|
|
134
|
+
Bytes.toNumber(bytes32Small)
|
|
135
|
+
})
|
|
112
136
|
})
|
|
113
137
|
|
|
114
138
|
describe('Bytes.padLeft', () => {
|
|
@@ -119,3 +143,13 @@ describe('Bytes.padLeft', () => {
|
|
|
119
143
|
Bytes.padLeft(small.subarray(0, 1), 32)
|
|
120
144
|
})
|
|
121
145
|
})
|
|
146
|
+
|
|
147
|
+
describe('Bytes.validate', () => {
|
|
148
|
+
bench('valid', () => {
|
|
149
|
+
Bytes.validate(small)
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
bench('invalid', () => {
|
|
153
|
+
Bytes.validate('0xdeadbeef')
|
|
154
|
+
})
|
|
155
|
+
})
|
package/src/core/Bytes.ts
CHANGED
|
@@ -745,9 +745,17 @@ export declare namespace trimRight {
|
|
|
745
745
|
* @returns `true` if the value is {@link ox#Bytes.Bytes}, otherwise `false`.
|
|
746
746
|
*/
|
|
747
747
|
export function validate(value: unknown): value is Bytes {
|
|
748
|
+
// The checks `assert` makes, without building and catching an error.
|
|
749
|
+
if (!value || typeof value !== 'object') return false
|
|
750
|
+
// A revoked Proxy, or a trap or getter, can throw from these checks; that
|
|
751
|
+
// is invalid input too.
|
|
748
752
|
try {
|
|
749
|
-
|
|
750
|
-
return
|
|
753
|
+
if (value instanceof Uint8Array) return true
|
|
754
|
+
return (
|
|
755
|
+
'BYTES_PER_ELEMENT' in value &&
|
|
756
|
+
value.BYTES_PER_ELEMENT === 1 &&
|
|
757
|
+
value.constructor.name === 'Uint8Array'
|
|
758
|
+
)
|
|
751
759
|
} catch {
|
|
752
760
|
return false
|
|
753
761
|
}
|
package/src/core/Cbor.ts
CHANGED
|
@@ -3,6 +3,9 @@ import * as Errors from './Errors.js'
|
|
|
3
3
|
import * as Hex from './Hex.js'
|
|
4
4
|
import * as Cursor from './internal/cursor.js'
|
|
5
5
|
|
|
6
|
+
/** Maximum nesting depth permitted when decoding a CBOR value. */
|
|
7
|
+
const depthLimit = 1_024
|
|
8
|
+
|
|
6
9
|
/**
|
|
7
10
|
* Encodes a value into CBOR (Concise Binary Object Representation) format.
|
|
8
11
|
*
|
|
@@ -99,6 +102,15 @@ export declare namespace decode {
|
|
|
99
102
|
| Errors.GlobalErrorType
|
|
100
103
|
}
|
|
101
104
|
|
|
105
|
+
/** Thrown when CBOR data nests deeper than the decoder allows. */
|
|
106
|
+
export class DepthLimitExceededError extends Errors.BaseError {
|
|
107
|
+
override readonly name = 'Cbor.DepthLimitExceededError'
|
|
108
|
+
|
|
109
|
+
constructor({ limit }: { limit: number }) {
|
|
110
|
+
super(`CBOR depth limit of \`${limit}\` exceeded.`)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
102
114
|
export class InvalidMajorTypeError extends Errors.BaseError {
|
|
103
115
|
override readonly name = 'Cbor.InvalidMajorTypeError'
|
|
104
116
|
|
|
@@ -168,7 +180,7 @@ export class NumberTooLargeError extends Errors.BaseError {
|
|
|
168
180
|
|
|
169
181
|
constructor({ number }: { number: string }) {
|
|
170
182
|
super(
|
|
171
|
-
`Number
|
|
183
|
+
`Number is outside the encodable integer range (-4294967296 to 4294967295): ${number}`,
|
|
172
184
|
)
|
|
173
185
|
}
|
|
174
186
|
}
|
|
@@ -610,7 +622,12 @@ namespace getEncodable {
|
|
|
610
622
|
|
|
611
623
|
/** @internal */
|
|
612
624
|
// biome-ignore lint/correctness/noUnusedVariables: _
|
|
613
|
-
function decodeCursor(cursor: Cursor.Cursor): unknown {
|
|
625
|
+
function decodeCursor(cursor: Cursor.Cursor, depth = 0): unknown {
|
|
626
|
+
// Bounds recursion, so deeply nested data throws instead of overflowing the
|
|
627
|
+
// stack.
|
|
628
|
+
if (depth >= depthLimit)
|
|
629
|
+
throw new DepthLimitExceededError({ limit: depthLimit })
|
|
630
|
+
|
|
614
631
|
const initialByte = cursor.readUint8()
|
|
615
632
|
const majorType = initialByte >> 5
|
|
616
633
|
const additionalInfo = initialByte & 0b00011111
|
|
@@ -626,19 +643,19 @@ function decodeCursor(cursor: Cursor.Cursor): unknown {
|
|
|
626
643
|
|
|
627
644
|
// Major type 2: Byte string
|
|
628
645
|
case 2:
|
|
629
|
-
return decodeCursor.readByteString(cursor, additionalInfo)
|
|
646
|
+
return decodeCursor.readByteString(cursor, additionalInfo, depth)
|
|
630
647
|
|
|
631
648
|
// Major type 3: Text string
|
|
632
649
|
case 3:
|
|
633
|
-
return decodeCursor.readTextString(cursor, additionalInfo)
|
|
650
|
+
return decodeCursor.readTextString(cursor, additionalInfo, depth)
|
|
634
651
|
|
|
635
652
|
// Major type 4: Array
|
|
636
653
|
case 4:
|
|
637
|
-
return decodeCursor.readArray(cursor, additionalInfo)
|
|
654
|
+
return decodeCursor.readArray(cursor, additionalInfo, depth)
|
|
638
655
|
|
|
639
656
|
// Major type 5: Map
|
|
640
657
|
case 5:
|
|
641
|
-
return decodeCursor.readMap(cursor, additionalInfo)
|
|
658
|
+
return decodeCursor.readMap(cursor, additionalInfo, depth)
|
|
642
659
|
|
|
643
660
|
// Major type 6: Tagged data (not yet supported)
|
|
644
661
|
case 6:
|
|
@@ -665,6 +682,7 @@ namespace decodeCursor {
|
|
|
665
682
|
| readSimpleOrFloat.ErrorType
|
|
666
683
|
| UnsupportedTagError
|
|
667
684
|
| InvalidMajorTypeError
|
|
685
|
+
| DepthLimitExceededError
|
|
668
686
|
| Errors.GlobalErrorType
|
|
669
687
|
|
|
670
688
|
/** @internal */
|
|
@@ -717,6 +735,7 @@ namespace decodeCursor {
|
|
|
717
735
|
export function readByteString(
|
|
718
736
|
cursor: Cursor.Cursor,
|
|
719
737
|
additionalInfo: number,
|
|
738
|
+
depth: number,
|
|
720
739
|
): Bytes.Bytes {
|
|
721
740
|
// Indefinite-length byte string
|
|
722
741
|
if (additionalInfo === 31) {
|
|
@@ -729,7 +748,7 @@ namespace decodeCursor {
|
|
|
729
748
|
cursor.readUint8() // consume the break byte
|
|
730
749
|
break
|
|
731
750
|
}
|
|
732
|
-
const chunk = decodeCursor(cursor) as Bytes.Bytes
|
|
751
|
+
const chunk = decodeCursor(cursor, depth + 1) as Bytes.Bytes
|
|
733
752
|
if (!(chunk instanceof Uint8Array))
|
|
734
753
|
throw new InvalidIndefiniteLengthChunkError({ type: 'byte string' })
|
|
735
754
|
chunks.push(chunk)
|
|
@@ -762,6 +781,7 @@ namespace decodeCursor {
|
|
|
762
781
|
export function readTextString(
|
|
763
782
|
cursor: Cursor.Cursor,
|
|
764
783
|
additionalInfo: number,
|
|
784
|
+
depth: number,
|
|
765
785
|
): string {
|
|
766
786
|
// Indefinite-length text string
|
|
767
787
|
if (additionalInfo === 31) {
|
|
@@ -773,7 +793,7 @@ namespace decodeCursor {
|
|
|
773
793
|
cursor.readUint8() // consume the break byte
|
|
774
794
|
break
|
|
775
795
|
}
|
|
776
|
-
const chunk = decodeCursor(cursor)
|
|
796
|
+
const chunk = decodeCursor(cursor, depth + 1)
|
|
777
797
|
if (typeof chunk !== 'string')
|
|
778
798
|
throw new InvalidIndefiniteLengthChunkError({ type: 'text string' })
|
|
779
799
|
chunks.push(chunk)
|
|
@@ -800,6 +820,7 @@ namespace decodeCursor {
|
|
|
800
820
|
export function readArray(
|
|
801
821
|
cursor: Cursor.Cursor,
|
|
802
822
|
additionalInfo: number,
|
|
823
|
+
depth: number,
|
|
803
824
|
): unknown[] {
|
|
804
825
|
// Indefinite-length array
|
|
805
826
|
if (additionalInfo === 31) {
|
|
@@ -811,7 +832,7 @@ namespace decodeCursor {
|
|
|
811
832
|
cursor.readUint8() // consume the break byte
|
|
812
833
|
break
|
|
813
834
|
}
|
|
814
|
-
result.push(decodeCursor(cursor))
|
|
835
|
+
result.push(decodeCursor(cursor, depth + 1))
|
|
815
836
|
}
|
|
816
837
|
|
|
817
838
|
return result
|
|
@@ -821,7 +842,7 @@ namespace decodeCursor {
|
|
|
821
842
|
const result: unknown[] = []
|
|
822
843
|
|
|
823
844
|
for (let i = 0; i < length; i++) {
|
|
824
|
-
result.push(decodeCursor(cursor))
|
|
845
|
+
result.push(decodeCursor(cursor, depth + 1))
|
|
825
846
|
}
|
|
826
847
|
|
|
827
848
|
return result
|
|
@@ -836,6 +857,7 @@ namespace decodeCursor {
|
|
|
836
857
|
export function readMap(
|
|
837
858
|
cursor: Cursor.Cursor,
|
|
838
859
|
additionalInfo: number,
|
|
860
|
+
depth: number,
|
|
839
861
|
): Record<string, unknown> {
|
|
840
862
|
// Indefinite-length map
|
|
841
863
|
if (additionalInfo === 31) {
|
|
@@ -847,7 +869,7 @@ namespace decodeCursor {
|
|
|
847
869
|
cursor.readUint8() // consume the break byte
|
|
848
870
|
break
|
|
849
871
|
}
|
|
850
|
-
const key = decodeCursor(cursor)
|
|
872
|
+
const key = decodeCursor(cursor, depth + 1)
|
|
851
873
|
// Support both string and number keys (for COSE_Key with integer keys)
|
|
852
874
|
const keyStr =
|
|
853
875
|
typeof key === 'string'
|
|
@@ -855,7 +877,7 @@ namespace decodeCursor {
|
|
|
855
877
|
: typeof key === 'number'
|
|
856
878
|
? String(key)
|
|
857
879
|
: String(key)
|
|
858
|
-
const value = decodeCursor(cursor)
|
|
880
|
+
const value = decodeCursor(cursor, depth + 1)
|
|
859
881
|
setEntry(result, keyStr, value)
|
|
860
882
|
}
|
|
861
883
|
|
|
@@ -866,7 +888,7 @@ namespace decodeCursor {
|
|
|
866
888
|
const result: Record<string, unknown> = {}
|
|
867
889
|
|
|
868
890
|
for (let i = 0; i < length; i++) {
|
|
869
|
-
const key = decodeCursor(cursor)
|
|
891
|
+
const key = decodeCursor(cursor, depth + 1)
|
|
870
892
|
// Support both string and number keys (for COSE_Key with integer keys)
|
|
871
893
|
const keyStr =
|
|
872
894
|
typeof key === 'string'
|
|
@@ -874,7 +896,7 @@ namespace decodeCursor {
|
|
|
874
896
|
: typeof key === 'number'
|
|
875
897
|
? String(key)
|
|
876
898
|
: String(key)
|
|
877
|
-
const value = decodeCursor(cursor)
|
|
899
|
+
const value = decodeCursor(cursor, depth + 1)
|
|
878
900
|
setEntry(result, keyStr, value)
|
|
879
901
|
}
|
|
880
902
|
|
package/src/core/Ens.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ensNormalize } from '@adraffy/ens-normalize.ts'
|
|
2
2
|
import * as Bytes from './Bytes.js'
|
|
3
3
|
import * as Errors from './Errors.js'
|
|
4
4
|
import * as Hash from './Hash.js'
|
|
@@ -48,7 +48,7 @@ export declare namespace labelhash {
|
|
|
48
48
|
* ```ts twoslash
|
|
49
49
|
* import { Ens } from 'ox'
|
|
50
50
|
* Ens.namehash('wevm.eth')
|
|
51
|
-
* // @log: '
|
|
51
|
+
* // @log: '0x08c85f2f4059e930c45a6aeff9dcd3bd95dc3c5c1cddef6a0626b31152248560'
|
|
52
52
|
* ```
|
|
53
53
|
*
|
|
54
54
|
* @param name - ENS name.
|
|
@@ -98,7 +98,7 @@ export declare namespace namehash {
|
|
|
98
98
|
* @returns Normalized ENS name.
|
|
99
99
|
*/
|
|
100
100
|
export function normalize(name: string): string {
|
|
101
|
-
return
|
|
101
|
+
return ensNormalize(name)
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
export declare namespace normalize {
|
package/src/core/FrameReceipt.ts
CHANGED
|
@@ -84,7 +84,10 @@ export function fromRpc(receipt: Rpc): FrameReceipt {
|
|
|
84
84
|
gasUsed: Hex.toBigInt(receipt.gasUsed),
|
|
85
85
|
logs: receipt.logs,
|
|
86
86
|
stateGasUsed: Hex.toBigInt(receipt.stateGasUsed),
|
|
87
|
-
|
|
87
|
+
// Own keys only: an inherited one such as `__proto__` is not a status.
|
|
88
|
+
status: Object.hasOwn(fromRpcStatus, receipt.status)
|
|
89
|
+
? fromRpcStatus[receipt.status]
|
|
90
|
+
: (undefined as never),
|
|
88
91
|
}
|
|
89
92
|
}
|
|
90
93
|
|
package/src/core/Hash.ts
CHANGED
|
@@ -261,7 +261,7 @@ export declare namespace blake3 {
|
|
|
261
261
|
* import { Hash, Hex } from 'ox'
|
|
262
262
|
*
|
|
263
263
|
* Hash.keccak256(Hex.fromString('hello world'))
|
|
264
|
-
* // @log: '
|
|
264
|
+
* // @log: '0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad'
|
|
265
265
|
* ```
|
|
266
266
|
*
|
|
267
267
|
* @example
|
package/src/core/Hex.bench.ts
CHANGED
|
@@ -97,6 +97,9 @@ describe('Hex.toBigInt', () => {
|
|
|
97
97
|
bench('32 bytes', () => {
|
|
98
98
|
Hex.toBigInt(smallHex)
|
|
99
99
|
})
|
|
100
|
+
bench('32 bytes, signed', () => {
|
|
101
|
+
Hex.toBigInt(hex32, { signed: true })
|
|
102
|
+
})
|
|
100
103
|
})
|
|
101
104
|
|
|
102
105
|
describe('Hex.padLeft', () => {
|
|
@@ -118,4 +121,18 @@ describe('Hex.validate (strict)', () => {
|
|
|
118
121
|
bench('256 bytes', () => {
|
|
119
122
|
Hex.validate(mediumHex, { strict: true })
|
|
120
123
|
})
|
|
124
|
+
|
|
125
|
+
bench('invalid', () => {
|
|
126
|
+
Hex.validate('0xzz', { strict: true })
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
describe('Hex.validate', () => {
|
|
131
|
+
bench('valid', () => {
|
|
132
|
+
Hex.validate(smallHex)
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
bench('invalid (no prefix)', () => {
|
|
136
|
+
Hex.validate('deadbeef')
|
|
137
|
+
})
|
|
121
138
|
})
|
package/src/core/Hex.ts
CHANGED
|
@@ -82,9 +82,9 @@ export declare namespace assert {
|
|
|
82
82
|
export function concat(...values: readonly Hex[]): Hex {
|
|
83
83
|
if (values.length === 0) return '0x'
|
|
84
84
|
if (values.length === 1) return values[0]!
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return
|
|
85
|
+
let hex = '0x'
|
|
86
|
+
for (let i = 0; i < values.length; i++) hex += values[i]!.slice(2)
|
|
87
|
+
return hex as Hex
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
export declare namespace concat {
|
|
@@ -253,27 +253,29 @@ export function fromNumber(
|
|
|
253
253
|
): Hex {
|
|
254
254
|
const { signed, size } = options
|
|
255
255
|
|
|
256
|
-
//
|
|
256
|
+
// Unsigned fast path: a value fits `size` bytes exactly when its hex has at
|
|
257
|
+
// most `size * 2` digits, so the bound needs no BigInt arithmetic. Sizes
|
|
258
|
+
// that are not integers take the general path, which rejects them.
|
|
257
259
|
if (
|
|
258
260
|
!signed &&
|
|
259
|
-
typeof value === '
|
|
260
|
-
|
|
261
|
-
|
|
261
|
+
(typeof value === 'bigint'
|
|
262
|
+
? value >= 0n
|
|
263
|
+
: value >= 0 && Number.isSafeInteger(value)) &&
|
|
264
|
+
(!size || Number.isInteger(size))
|
|
262
265
|
) {
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return padLeft(hex, size)
|
|
266
|
+
const hex = value.toString(16)
|
|
267
|
+
if (!size) return `0x${hex}`
|
|
268
|
+
if (hex.length > size * 2) {
|
|
269
|
+
const suffix = typeof value === 'bigint' ? 'n' : ''
|
|
270
|
+
throw new IntegerOutOfRangeError({
|
|
271
|
+
max: `${2n ** (BigInt(size) * 8n) - 1n}${suffix}`,
|
|
272
|
+
min: `0${suffix}`,
|
|
273
|
+
signed,
|
|
274
|
+
size,
|
|
275
|
+
value: `${value}${suffix}`,
|
|
276
|
+
})
|
|
275
277
|
}
|
|
276
|
-
return `0x${
|
|
278
|
+
return `0x${hex.padStart(size * 2, '0')}`
|
|
277
279
|
}
|
|
278
280
|
|
|
279
281
|
const value_ = BigInt(value)
|
|
@@ -612,12 +614,7 @@ export function toBigInt(hex: Hex, options: toBigInt.Options = {}): bigint {
|
|
|
612
614
|
|
|
613
615
|
const value = BigInt(hex)
|
|
614
616
|
if (!signed) return value
|
|
615
|
-
|
|
616
|
-
const max_unsigned = (1n << (BigInt(size(hex)) * 8n)) - 1n
|
|
617
|
-
const max_signed = max_unsigned >> 1n
|
|
618
|
-
|
|
619
|
-
if (value <= max_signed) return value
|
|
620
|
-
return value - max_unsigned - 1n
|
|
617
|
+
return BigInt.asIntN(size(hex) * 8, value)
|
|
621
618
|
}
|
|
622
619
|
|
|
623
620
|
export declare namespace toBigInt {
|
|
@@ -829,12 +826,12 @@ export function validate(
|
|
|
829
826
|
options: validate.Options = {},
|
|
830
827
|
): value is Hex {
|
|
831
828
|
const { even = false, strict = false } = options
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
829
|
+
// The checks `assert` makes, without building and catching an error.
|
|
830
|
+
if (typeof value !== 'string') return false
|
|
831
|
+
if (strict && !hexRegex.test(value)) return false
|
|
832
|
+
if (!value.startsWith('0x')) return false
|
|
833
|
+
if (even && value.length % 2 !== 0) return false
|
|
834
|
+
return true
|
|
838
835
|
}
|
|
839
836
|
|
|
840
837
|
export declare namespace validate {
|