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
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'
|
|
@@ -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/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 {
|
package/src/core/Keystore.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Bytes from './Bytes.js'
|
|
2
|
-
import
|
|
2
|
+
import * as Errors from './Errors.js'
|
|
3
3
|
import * as engine from './internal/keystore.js'
|
|
4
4
|
import * as Hash from './Hash.js'
|
|
5
5
|
import type * as Hex from './Hex.js'
|
|
@@ -83,7 +83,7 @@ export type ScryptDeriveOpts = BaseDeriveOpts<
|
|
|
83
83
|
* ```
|
|
84
84
|
*
|
|
85
85
|
* @param keystore - JSON keystore.
|
|
86
|
-
* @param key - Key to use for decryption.
|
|
86
|
+
* @param key - Key to use for decryption. Must contain at least 32 bytes; the first 32 bytes are used.
|
|
87
87
|
* @param options - Decryption options.
|
|
88
88
|
* @returns Decrypted private key.
|
|
89
89
|
*/
|
|
@@ -94,6 +94,7 @@ export function decrypt<as extends 'Hex' | 'Bytes' = 'Hex'>(
|
|
|
94
94
|
): decrypt.ReturnType<as> {
|
|
95
95
|
const { as = 'Hex' } = options
|
|
96
96
|
const key_ = Bytes.from(typeof key === 'function' ? key() : key)
|
|
97
|
+
if (key_.length < 32) throw new InvalidKeySizeError({ size: key_.length })
|
|
97
98
|
|
|
98
99
|
const encKey = Bytes.slice(key_, 0, 16)
|
|
99
100
|
const macKey = Bytes.slice(key_, 16, 32)
|
|
@@ -123,6 +124,8 @@ export declare namespace decrypt {
|
|
|
123
124
|
type ReturnType<as extends 'Hex' | 'Bytes' = 'Hex' | 'Bytes'> =
|
|
124
125
|
| (as extends 'Hex' ? Hex.Hex : never)
|
|
125
126
|
| (as extends 'Bytes' ? Bytes.Bytes : never)
|
|
127
|
+
|
|
128
|
+
type ErrorType = InvalidKeySizeError | Errors.GlobalErrorType
|
|
126
129
|
}
|
|
127
130
|
|
|
128
131
|
/**
|
|
@@ -169,7 +172,7 @@ export declare namespace decrypt {
|
|
|
169
172
|
* ```
|
|
170
173
|
*
|
|
171
174
|
* @param privateKey - Private key to encrypt.
|
|
172
|
-
* @param key - Key to use for encryption.
|
|
175
|
+
* @param key - Key to use for encryption. Must contain at least 32 bytes; the first 32 bytes are used.
|
|
173
176
|
* @param options - Encryption options.
|
|
174
177
|
* @returns Encrypted keystore.
|
|
175
178
|
*/
|
|
@@ -181,6 +184,7 @@ export function encrypt(
|
|
|
181
184
|
const { id = crypto.randomUUID(), kdf, kdfparams, iv } = options
|
|
182
185
|
|
|
183
186
|
const key_ = Bytes.from(typeof key === 'function' ? key() : key)
|
|
187
|
+
if (key_.length < 32) throw new InvalidKeySizeError({ size: key_.length })
|
|
184
188
|
const value_ = Bytes.from(privateKey)
|
|
185
189
|
|
|
186
190
|
const encKey = Bytes.slice(key_, 0, 16)
|
|
@@ -208,6 +212,8 @@ export declare namespace encrypt {
|
|
|
208
212
|
/** UUID. */
|
|
209
213
|
id?: string | undefined
|
|
210
214
|
}
|
|
215
|
+
|
|
216
|
+
type ErrorType = InvalidKeySizeError | Errors.GlobalErrorType
|
|
211
217
|
}
|
|
212
218
|
|
|
213
219
|
/**
|
|
@@ -532,6 +538,37 @@ export declare namespace toKeyAsync {
|
|
|
532
538
|
}
|
|
533
539
|
}
|
|
534
540
|
|
|
541
|
+
/**
|
|
542
|
+
* Thrown when a key contains fewer than 32 bytes.
|
|
543
|
+
*
|
|
544
|
+
* @example
|
|
545
|
+
* ```ts twoslash
|
|
546
|
+
* import { Keystore } from 'ox'
|
|
547
|
+
*
|
|
548
|
+
* const [, opts] = Keystore.pbkdf2({
|
|
549
|
+
* password: 'testpassword'
|
|
550
|
+
* })
|
|
551
|
+
*
|
|
552
|
+
* Keystore.encrypt('0x01', '0x0123456789abcdef', opts)
|
|
553
|
+
* // @error: Keystore.InvalidKeySizeError: Key must contain at least 32 bytes. Received 8 bytes.
|
|
554
|
+
* ```
|
|
555
|
+
*/
|
|
556
|
+
export class InvalidKeySizeError extends Errors.BaseError {
|
|
557
|
+
override readonly name = 'Keystore.InvalidKeySizeError'
|
|
558
|
+
|
|
559
|
+
constructor(options: InvalidKeySizeError.Options) {
|
|
560
|
+
super(`Key must contain at least 32 bytes. Received ${options.size} bytes.`)
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
export declare namespace InvalidKeySizeError {
|
|
565
|
+
/** Options for {@link ox#Keystore.InvalidKeySizeError}. */
|
|
566
|
+
type Options = {
|
|
567
|
+
/** Received key size. */
|
|
568
|
+
size: number
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
535
572
|
///////////////////////////////////////////////////////////////////////////
|
|
536
573
|
|
|
537
574
|
/** @internal */
|
package/src/core/Rlp.ts
CHANGED
|
@@ -2,12 +2,20 @@ import * as Bytes from './Bytes.js'
|
|
|
2
2
|
import * as Errors from './Errors.js'
|
|
3
3
|
import * as Hex from './Hex.js'
|
|
4
4
|
import * as internal_bytes from './internal/bytes.js'
|
|
5
|
+
import { assertHexBytes, nibbleTable } from './internal/codec/hex.js'
|
|
5
6
|
import * as Cursor from './internal/cursor.js'
|
|
6
7
|
import type { ExactPartial, RecursiveArray } from './internal/types.js'
|
|
7
8
|
|
|
8
9
|
/** Maximum nesting depth permitted when decoding an RLP value. */
|
|
9
10
|
const depthLimit = 1_024
|
|
10
11
|
|
|
12
|
+
/**
|
|
13
|
+
* Hex input length up to which decoded hex leaves are sliced from the input. A
|
|
14
|
+
* sliced string keeps its whole parent alive, so this bounds what one kept leaf
|
|
15
|
+
* can retain.
|
|
16
|
+
*/
|
|
17
|
+
const sliceMaxLength = 4_096
|
|
18
|
+
|
|
11
19
|
/**
|
|
12
20
|
* Decodes a Recursive-Length Prefix (RLP) value into a {@link ox#Bytes.Bytes} value.
|
|
13
21
|
*
|
|
@@ -63,6 +71,16 @@ export function to<
|
|
|
63
71
|
>(value: value, to: to | 'Hex' | 'Bytes'): to.ReturnType<to> {
|
|
64
72
|
const to_ = to ?? (typeof value === 'string' ? 'Hex' : 'Bytes')
|
|
65
73
|
|
|
74
|
+
// Hex in and out: read a short input straight from the string, skipping the
|
|
75
|
+
// byte copy. A long input pays a JavaScript scan to validate it, which costs
|
|
76
|
+
// more than `Bytes.fromHex`, and leaves sliced from it would keep it alive.
|
|
77
|
+
if (
|
|
78
|
+
typeof value === 'string' &&
|
|
79
|
+
to_ === 'Hex' &&
|
|
80
|
+
value.length <= sliceMaxLength
|
|
81
|
+
)
|
|
82
|
+
return decodeHex(value) as to.ReturnType<to>
|
|
83
|
+
|
|
66
84
|
const bytes =
|
|
67
85
|
typeof value === 'string' ? Bytes.fromHex(value) : (value as Bytes.Bytes)
|
|
68
86
|
|
|
@@ -155,7 +173,10 @@ export declare namespace decodeRlpCursor {
|
|
|
155
173
|
|
|
156
174
|
/** @internal */
|
|
157
175
|
export function readLength(
|
|
158
|
-
cursor:
|
|
176
|
+
cursor: Pick<
|
|
177
|
+
Cursor.Cursor,
|
|
178
|
+
'readUint8' | 'readUint16' | 'readUint24' | 'readUint32'
|
|
179
|
+
>,
|
|
159
180
|
prefix: number,
|
|
160
181
|
offset: number,
|
|
161
182
|
) {
|
|
@@ -233,6 +254,123 @@ export declare namespace readList {
|
|
|
233
254
|
| Errors.GlobalErrorType
|
|
234
255
|
}
|
|
235
256
|
|
|
257
|
+
type HexReader = {
|
|
258
|
+
/** Byte length of the input. */
|
|
259
|
+
length: number
|
|
260
|
+
/** Position in bytes. */
|
|
261
|
+
position: number
|
|
262
|
+
readUint8(): number
|
|
263
|
+
readUint16(): number
|
|
264
|
+
readUint24(): number
|
|
265
|
+
readUint32(): number
|
|
266
|
+
/** Lowercase hex input. */
|
|
267
|
+
source: string
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* Decodes a hex RLP value straight from its string, slicing leaves out of it.
|
|
272
|
+
* Mirrors `Bytes.fromHex` followed by {@link decodeRlpCursor}, including the
|
|
273
|
+
* cursor's bounds errors.
|
|
274
|
+
*
|
|
275
|
+
* @internal
|
|
276
|
+
*/
|
|
277
|
+
function decodeHex(value: Hex.Hex): RecursiveArray<Hex.Hex> {
|
|
278
|
+
assertHexBytes(value)
|
|
279
|
+
const length = (value.length - 2) / 2
|
|
280
|
+
if (length === 0) return '0x'
|
|
281
|
+
const reader: HexReader = {
|
|
282
|
+
length,
|
|
283
|
+
position: 0,
|
|
284
|
+
readUint8() {
|
|
285
|
+
return readHexUint(this, 1)
|
|
286
|
+
},
|
|
287
|
+
readUint16() {
|
|
288
|
+
return readHexUint(this, 2)
|
|
289
|
+
},
|
|
290
|
+
readUint24() {
|
|
291
|
+
return readHexUint(this, 3)
|
|
292
|
+
},
|
|
293
|
+
readUint32() {
|
|
294
|
+
return readHexUint(this, 4)
|
|
295
|
+
},
|
|
296
|
+
source: value.toLowerCase(),
|
|
297
|
+
}
|
|
298
|
+
const result = decodeHexItem(reader, 0)
|
|
299
|
+
// RLP payloads encode exactly one item (Yellow Paper, Appendix B).
|
|
300
|
+
if (reader.position < length)
|
|
301
|
+
throw new TrailingBytesError({ count: length - reader.position })
|
|
302
|
+
return result
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function decodeHexItem(
|
|
306
|
+
reader: HexReader,
|
|
307
|
+
depth: number,
|
|
308
|
+
): RecursiveArray<Hex.Hex> {
|
|
309
|
+
if (depth >= depthLimit)
|
|
310
|
+
throw new DepthLimitExceededError({ limit: depthLimit })
|
|
311
|
+
|
|
312
|
+
const prefix = reader.readUint8()
|
|
313
|
+
if (prefix < 0x80) reader.position--
|
|
314
|
+
|
|
315
|
+
// bytes
|
|
316
|
+
if (prefix < 0xc0) {
|
|
317
|
+
const length = readLength(reader, prefix, 0x80)
|
|
318
|
+
const start = reader.position
|
|
319
|
+
assertHexPosition(reader, start + length - 1)
|
|
320
|
+
reader.position += length
|
|
321
|
+
const first = length === 1 ? readSourceByte(reader.source, start) : 0
|
|
322
|
+
// See `decodeRlpCursor`.
|
|
323
|
+
if (prefix >= 0x80 && length === 1 && first < 0x80)
|
|
324
|
+
throw new NonCanonicalError({
|
|
325
|
+
reason: `single byte \`0x${first.toString(16).padStart(2, '0')}\` is wrapped in an explicit length prefix instead of being encoded as itself`,
|
|
326
|
+
})
|
|
327
|
+
return `0x${reader.source.slice(2 + start * 2, 2 + reader.position * 2)}`
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// list
|
|
331
|
+
const length = readLength(reader, prefix, 0xc0)
|
|
332
|
+
const position = reader.position
|
|
333
|
+
const value: RecursiveArray<Hex.Hex>[] = []
|
|
334
|
+
while (reader.position - position < length)
|
|
335
|
+
value.push(decodeHexItem(reader, depth + 1))
|
|
336
|
+
// Items must consume exactly the declared list length.
|
|
337
|
+
if (reader.position - position !== length)
|
|
338
|
+
throw new ListBoundaryExceededError({
|
|
339
|
+
consumed: reader.position - position,
|
|
340
|
+
declared: length,
|
|
341
|
+
})
|
|
342
|
+
return value as RecursiveArray<Hex.Hex>
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Throws the cursor's error for reading past the end of the input.
|
|
347
|
+
*
|
|
348
|
+
* @internal
|
|
349
|
+
*/
|
|
350
|
+
function assertHexPosition(reader: HexReader, position: number) {
|
|
351
|
+
if (position > reader.length - 1)
|
|
352
|
+
throw new Cursor.PositionOutOfBoundsError({
|
|
353
|
+
length: reader.length,
|
|
354
|
+
position,
|
|
355
|
+
})
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
function readHexUint(reader: HexReader, size: number): number {
|
|
359
|
+
assertHexPosition(reader, reader.position + size - 1)
|
|
360
|
+
let value = 0
|
|
361
|
+
for (let i = 0; i < size; i++)
|
|
362
|
+
value = value * 256 + readSourceByte(reader.source, reader.position++)
|
|
363
|
+
return value
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
function readSourceByte(source: string, position: number): number {
|
|
367
|
+
const i = 2 + position * 2
|
|
368
|
+
return (
|
|
369
|
+
(nibbleTable[source.charCodeAt(i)]! << 4) |
|
|
370
|
+
nibbleTable[source.charCodeAt(i + 1)]!
|
|
371
|
+
)
|
|
372
|
+
}
|
|
373
|
+
|
|
236
374
|
/**
|
|
237
375
|
* Encodes a value as Recursive-Length Prefix (RLP) and writes the encoded bytes
|
|
238
376
|
* through a synchronous callback without allocating the complete encoding.
|
package/src/core/Rlp_tx.bench.ts
CHANGED
|
@@ -60,6 +60,53 @@ const eip7702Tuple = [
|
|
|
60
60
|
|
|
61
61
|
const eip7702TupleHex = Rlp.fromHex(eip7702Tuple as never, { as: 'Hex' })
|
|
62
62
|
|
|
63
|
+
// Legacy (EIP-155) tuple: 9 elements.
|
|
64
|
+
const legacyTuple = [
|
|
65
|
+
'0x09',
|
|
66
|
+
'0x04a817c800',
|
|
67
|
+
'0x5208',
|
|
68
|
+
'0x3535353535353535353535353535353535353535',
|
|
69
|
+
'0x0de0b6b3a7640000',
|
|
70
|
+
'0x',
|
|
71
|
+
'0x25',
|
|
72
|
+
'0xa0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0',
|
|
73
|
+
'0xb0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0',
|
|
74
|
+
] as const
|
|
75
|
+
|
|
76
|
+
const legacyTupleHex = Rlp.fromHex(legacyTuple as never, { as: 'Hex' })
|
|
77
|
+
|
|
78
|
+
// EIP-4844 network wrapper with 3 blobs, their commitments and proofs.
|
|
79
|
+
const blob = (i: number) =>
|
|
80
|
+
`0x${i.toString(16).padStart(2, '0').repeat(131_072)}` as const
|
|
81
|
+
const kzg = (i: number) =>
|
|
82
|
+
`0x${i.toString(16).padStart(2, '0').repeat(48)}` as const
|
|
83
|
+
const eip4844SidecarsHex = Rlp.fromHex(
|
|
84
|
+
[
|
|
85
|
+
[
|
|
86
|
+
'0x01',
|
|
87
|
+
'0x10',
|
|
88
|
+
'0x3b9aca00',
|
|
89
|
+
'0x6fc23ac0',
|
|
90
|
+
'0x5208',
|
|
91
|
+
'0x70997970c51812dc3a010c7d01b50e0d17dc79c8',
|
|
92
|
+
'0x0de0b6b3a7640000',
|
|
93
|
+
'0x',
|
|
94
|
+
[],
|
|
95
|
+
'0x3b9aca00',
|
|
96
|
+
[1, 2, 3].map(
|
|
97
|
+
(i) => `0x01${i.toString(16).padStart(2, '0').repeat(31)}` as const,
|
|
98
|
+
),
|
|
99
|
+
'0x01',
|
|
100
|
+
'0xa0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0',
|
|
101
|
+
'0xb0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0',
|
|
102
|
+
],
|
|
103
|
+
[1, 2, 3].map(blob),
|
|
104
|
+
[1, 2, 3].map(kzg),
|
|
105
|
+
[4, 5, 6].map(kzg),
|
|
106
|
+
] as never,
|
|
107
|
+
{ as: 'Hex' },
|
|
108
|
+
)
|
|
109
|
+
|
|
63
110
|
describe('Rlp.fromHex (transaction-shaped)', () => {
|
|
64
111
|
bench('eip1559 tuple', () => {
|
|
65
112
|
Rlp.fromHex(eip1559Tuple as never, { as: 'Hex' })
|
|
@@ -71,6 +118,14 @@ describe('Rlp.fromHex (transaction-shaped)', () => {
|
|
|
71
118
|
})
|
|
72
119
|
|
|
73
120
|
describe('Rlp.toHex (transaction-shaped)', () => {
|
|
121
|
+
bench('legacy tuple', () => {
|
|
122
|
+
Rlp.toHex(legacyTupleHex)
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
bench('eip4844 network wrapper (3 blobs)', () => {
|
|
126
|
+
Rlp.toHex(eip4844SidecarsHex)
|
|
127
|
+
})
|
|
128
|
+
|
|
74
129
|
bench('eip1559 tuple', () => {
|
|
75
130
|
Rlp.toHex(eip1559TupleHex)
|
|
76
131
|
})
|
package/src/core/RpcTransport.ts
CHANGED
|
@@ -218,7 +218,9 @@ export class HttpError extends Errors.BaseError {
|
|
|
218
218
|
metaMessages: [
|
|
219
219
|
`Status: ${response.status}`,
|
|
220
220
|
`URL: ${getUrl(url)}`,
|
|
221
|
-
body
|
|
221
|
+
body
|
|
222
|
+
? `Body: ${typeof body === 'string' ? body : JSON.stringify(body)}`
|
|
223
|
+
: undefined,
|
|
222
224
|
],
|
|
223
225
|
})
|
|
224
226
|
}
|
package/src/core/Secp256k1.ts
CHANGED
|
@@ -635,7 +635,10 @@ export function verify(options: verify.Options): boolean {
|
|
|
635
635
|
if (options.address)
|
|
636
636
|
return Address.isEqual(
|
|
637
637
|
options.address,
|
|
638
|
-
recoverAddress({
|
|
638
|
+
recoverAddress({
|
|
639
|
+
payload: hash === true ? Hash.sha256(payload) : payload,
|
|
640
|
+
signature: options.signature,
|
|
641
|
+
}),
|
|
639
642
|
)
|
|
640
643
|
const sig = normalizeSignature(options.signature)
|
|
641
644
|
return engine.verify(
|