ox 1.8.16 → 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 +42 -0
- package/dist/core/AbiEvent.d.ts +1 -1
- package/dist/core/AbiEvent.d.ts.map +1 -1
- package/dist/core/AbiEvent.js +27 -22
- 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/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/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/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/TypedData.d.ts.map +1 -1
- package/dist/core/TypedData.js +14 -2
- 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/TypedData.d.ts +4 -4
- 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/package.json +2 -2
- package/src/core/AbiEvent.bench.ts +45 -0
- package/src/core/AbiEvent.ts +30 -23
- 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/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/Rlp.ts +139 -1
- package/src/core/Rlp_tx.bench.ts +55 -0
- package/src/core/RpcTransport.ts +3 -1
- package/src/core/Transaction.ts +4 -2
- package/src/core/TransactionReceipt.ts +8 -2
- package/src/core/TypedData.bench.ts +50 -0
- package/src/core/TypedData.ts +14 -2
- 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/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/Transaction.test.ts +17 -0
- 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/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/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
|
@@ -4,10 +4,18 @@ import * as Errors from '../Errors.js'
|
|
|
4
4
|
/** @internal */
|
|
5
5
|
export type Cursor = {
|
|
6
6
|
bytes: Bytes
|
|
7
|
-
|
|
7
|
+
/** Lazy: created on first access, since most cursors never use it. */
|
|
8
|
+
readonly dataView: DataView
|
|
9
|
+
/** Backing field of `dataView`. */
|
|
10
|
+
_dataView: DataView | undefined
|
|
8
11
|
position: number
|
|
9
|
-
/**
|
|
10
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Positions read so far, so a repeated read can be counted. Word-aligned
|
|
14
|
+
* positions, where ABI data is read, go in a bit set with one bit per 32
|
|
15
|
+
* bytes; other positions go in a set. Both are allocated on first use.
|
|
16
|
+
*/
|
|
17
|
+
alignedReads: Uint8Array | undefined
|
|
18
|
+
unalignedReads: Set<number> | undefined
|
|
11
19
|
/** Total number of bytes read. */
|
|
12
20
|
readSize: number
|
|
13
21
|
/** Maximum total number of bytes that can be read. */
|
|
@@ -19,7 +27,6 @@ export type Cursor = {
|
|
|
19
27
|
assertReadSize(length: number): void
|
|
20
28
|
assertPosition(position: number): void
|
|
21
29
|
decrementPosition(offset: number): void
|
|
22
|
-
getReadCount(position?: number): number
|
|
23
30
|
incrementPosition(offset: number): void
|
|
24
31
|
inspectByte(position?: number): Bytes[number]
|
|
25
32
|
inspectBytes(length: number, position?: number): Bytes
|
|
@@ -45,9 +52,17 @@ export type Cursor = {
|
|
|
45
52
|
|
|
46
53
|
const staticCursor: Cursor = {
|
|
47
54
|
bytes: new Uint8Array(),
|
|
48
|
-
dataView
|
|
55
|
+
get dataView() {
|
|
56
|
+
return (this._dataView ??= new DataView(
|
|
57
|
+
this.bytes.buffer,
|
|
58
|
+
this.bytes.byteOffset,
|
|
59
|
+
this.bytes.byteLength,
|
|
60
|
+
))
|
|
61
|
+
},
|
|
62
|
+
_dataView: undefined,
|
|
49
63
|
position: 0,
|
|
50
|
-
|
|
64
|
+
alignedReads: undefined,
|
|
65
|
+
unalignedReads: undefined,
|
|
51
66
|
readSize: 0,
|
|
52
67
|
readSizeLimit: Number.POSITIVE_INFINITY,
|
|
53
68
|
recursiveReadCount: 0,
|
|
@@ -80,9 +95,6 @@ const staticCursor: Cursor = {
|
|
|
80
95
|
this.assertPosition(position)
|
|
81
96
|
this.position = position
|
|
82
97
|
},
|
|
83
|
-
getReadCount(position) {
|
|
84
|
-
return this.positionReadCount?.get(position || this.position) || 0
|
|
85
|
-
},
|
|
86
98
|
incrementPosition(offset) {
|
|
87
99
|
if (offset < 0) throw new NegativeOffsetError({ offset })
|
|
88
100
|
const position = this.position + offset
|
|
@@ -212,10 +224,29 @@ const staticCursor: Cursor = {
|
|
|
212
224
|
},
|
|
213
225
|
_touch() {
|
|
214
226
|
if (this.recursiveReadLimit === Number.POSITIVE_INFINITY) return
|
|
215
|
-
const
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
227
|
+
const { position } = this
|
|
228
|
+
if (position % 32 !== 0 || position > this.bytes.length) {
|
|
229
|
+
const reads = (this.unalignedReads ??= new Set())
|
|
230
|
+
if (reads.has(position)) this.recursiveReadCount++
|
|
231
|
+
else reads.add(position)
|
|
232
|
+
return
|
|
233
|
+
}
|
|
234
|
+
// One bit per 32-byte word, so the set is 1/256 the size of the data. It
|
|
235
|
+
// is sized from the data's length at the time of the read, so a resizable
|
|
236
|
+
// buffer that grows while decoding still has every read counted.
|
|
237
|
+
const word = position / 32
|
|
238
|
+
const index = Math.floor(word / 8)
|
|
239
|
+
let reads = this.alignedReads
|
|
240
|
+
if (!reads || index >= reads.length) {
|
|
241
|
+
const grown = new Uint8Array(
|
|
242
|
+
Math.max(Math.floor(this.bytes.length / 256) + 1, index + 1),
|
|
243
|
+
)
|
|
244
|
+
if (reads) grown.set(reads)
|
|
245
|
+
reads = this.alignedReads = grown
|
|
246
|
+
}
|
|
247
|
+
const bit = 1 << (word & 7)
|
|
248
|
+
if (reads[index]! & bit) this.recursiveReadCount++
|
|
249
|
+
else reads[index]! |= bit
|
|
219
250
|
},
|
|
220
251
|
}
|
|
221
252
|
|
|
@@ -226,17 +257,15 @@ export function create(
|
|
|
226
257
|
): Cursor {
|
|
227
258
|
const cursor: Cursor = Object.create(staticCursor)
|
|
228
259
|
cursor.bytes = bytes
|
|
229
|
-
cursor.
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
bytes.byteLength,
|
|
233
|
-
)
|
|
234
|
-
cursor.positionReadCount = undefined
|
|
260
|
+
cursor._dataView = undefined
|
|
261
|
+
cursor.alignedReads = undefined
|
|
262
|
+
cursor.unalignedReads = undefined
|
|
235
263
|
cursor.recursiveReadLimit = recursiveReadLimit
|
|
236
|
-
//
|
|
237
|
-
//
|
|
238
|
-
//
|
|
239
|
-
|
|
264
|
+
// A well-formed payload reads each byte once. Allow twice that, plus as many
|
|
265
|
+
// bytes as `recursiveReadLimit` repeated 32-byte reads (256 KiB by default),
|
|
266
|
+
// so that offsets pointing many times at one region can add at most that
|
|
267
|
+
// fixed amount to the decoded output, whatever the size of the data.
|
|
268
|
+
cursor.readSizeLimit = 2 * bytes.length + 32 * recursiveReadLimit
|
|
240
269
|
return cursor
|
|
241
270
|
}
|
|
242
271
|
|
package/src/core/internal/lru.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Map with a
|
|
2
|
+
* Map with a bounded FIFO eviction policy. Reads do not reorder entries; only
|
|
3
|
+
* writes touch the eviction queue.
|
|
3
4
|
*
|
|
4
|
-
* @see https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU
|
|
5
5
|
* @internal
|
|
6
6
|
*/
|
|
7
|
-
export class
|
|
7
|
+
export class BoundedMap<value = unknown> extends Map<string, value> {
|
|
8
8
|
maxSize: number
|
|
9
9
|
|
|
10
10
|
constructor(size: number) {
|
|
@@ -12,47 +12,33 @@ export class LruMap<value = unknown> extends Map<string, value> {
|
|
|
12
12
|
this.maxSize = size
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
override get(key: string) {
|
|
16
|
-
const value = super.get(key)
|
|
17
|
-
|
|
18
|
-
if (super.has(key) && value !== undefined) {
|
|
19
|
-
this.delete(key)
|
|
20
|
-
super.set(key, value)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return value
|
|
24
|
-
}
|
|
25
|
-
|
|
26
15
|
override set(key: string, value: value) {
|
|
27
|
-
super.
|
|
28
|
-
if (this.maxSize && this.size > this.maxSize) {
|
|
16
|
+
if (!super.has(key) && this.maxSize && this.size >= this.maxSize) {
|
|
29
17
|
const firstKey = this.keys().next().value
|
|
30
|
-
if (firstKey) this.delete(firstKey)
|
|
18
|
+
if (firstKey !== undefined) this.delete(firstKey)
|
|
31
19
|
}
|
|
32
|
-
return
|
|
20
|
+
return super.set(key, value)
|
|
33
21
|
}
|
|
34
22
|
}
|
|
35
23
|
|
|
36
24
|
/**
|
|
37
|
-
*
|
|
38
|
-
* `
|
|
39
|
-
*
|
|
25
|
+
* Cache keyed by object identity. Entries live as long as their key, and
|
|
26
|
+
* `clear` drops them all by swapping in a new `WeakMap`, which has no `clear`
|
|
27
|
+
* of its own.
|
|
40
28
|
*
|
|
41
29
|
* @internal
|
|
42
30
|
*/
|
|
43
|
-
export
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
return super.set(key, value)
|
|
31
|
+
export function weakCache<key extends object, value>() {
|
|
32
|
+
let map = new WeakMap<key, value>()
|
|
33
|
+
return {
|
|
34
|
+
clear() {
|
|
35
|
+
map = new WeakMap()
|
|
36
|
+
},
|
|
37
|
+
get(key: key) {
|
|
38
|
+
return map.get(key)
|
|
39
|
+
},
|
|
40
|
+
set(key: key, value: value) {
|
|
41
|
+
map.set(key, value)
|
|
42
|
+
},
|
|
57
43
|
}
|
|
58
44
|
}
|
|
@@ -5,9 +5,12 @@ export function withTimeout<data>(
|
|
|
5
5
|
fn: withTimeout.Fn<data>,
|
|
6
6
|
options: withTimeout.Options,
|
|
7
7
|
): Promise<data> {
|
|
8
|
-
const {
|
|
8
|
+
const { timeout, signal } = options
|
|
9
9
|
// Fast path: no timeout, skip allocating Promise wrapper and AbortController.
|
|
10
10
|
if (!(timeout > 0)) return fn({ signal: null })
|
|
11
|
+
// Built only on timeout: an error captures a stack trace, which costs more
|
|
12
|
+
// than the request bookkeeping around it.
|
|
13
|
+
const error = () => options.errorInstance ?? new TimeoutError()
|
|
11
14
|
return new Promise((resolve, reject) => {
|
|
12
15
|
void (async () => {
|
|
13
16
|
let timeoutId: any
|
|
@@ -16,13 +19,16 @@ export function withTimeout<data>(
|
|
|
16
19
|
try {
|
|
17
20
|
timeoutId = setTimeout(() => {
|
|
18
21
|
timedOut = true
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
controller?.abort()
|
|
23
|
+
// Reject as well as abort: `fn` may ignore the signal and never
|
|
24
|
+
// settle.
|
|
25
|
+
reject(error())
|
|
21
26
|
}, timeout)
|
|
22
27
|
resolve(await fn({ signal: controller?.signal ?? null }))
|
|
23
28
|
} catch (err) {
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
// A timeout has rejected already.
|
|
30
|
+
if (timedOut) return
|
|
31
|
+
if ((err as Error)?.name === 'AbortError') reject(error())
|
|
26
32
|
else reject(err)
|
|
27
33
|
} finally {
|
|
28
34
|
clearTimeout(timeoutId)
|
|
@@ -33,7 +33,7 @@ const wrappedParameters = /*#__PURE__*/ AbiParameters.from(
|
|
|
33
33
|
* Deployless ERC-6492 signature verification bytecode.
|
|
34
34
|
*/
|
|
35
35
|
export const universalSignatureValidatorBytecode =
|
|
36
|
-
'
|
|
36
|
+
'0x608060405234801561001057600080fd5b506040516106ad3803806106ad83398101604081905261002f91610537565b600061003c848484610048565b9050806000526001601ff35b60007f649264926492649264926492649264926492649264926492649264926492649261007483610425565b036101e7576000606080848060200190518101906100929190610590565b60405192955090935091506000906001600160a01b038516906100b69085906105f6565b6000604051808303816000865af19150503d80600081146100f3576040519150601f19603f3d011682016040523d82523d6000602084013e6100f8565b606091505b50509050876001600160a01b03163b60000361016057806101605760405162461bcd60e51b815260206004820152601e60248201527f5369676e617475726556616c696461746f723a206465706c6f796d656e74000060448201526064015b60405180910390fd5b604051630b135d3f60e11b808252906001600160a01b038a1690631626ba7e90610190908b908790600401610612565b602060405180830381865afa1580156101ad573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101d1919061064c565b6001600160e01b0319161494505050505061041e565b6001600160a01b0384163b1561027a57604051630b135d3f60e11b808252906001600160a01b03861690631626ba7e906102279087908790600401610612565b602060405180830381865afa158015610244573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610268919061064c565b6001600160e01b03191614905061041e565b81516041146102df5760405162461bcd60e51b815260206004820152603a602482015260008051602061068d83398151915260448201527f3a20696e76616c6964207369676e6174757265206c656e6774680000000000006064820152608401610157565b6102e761043e565b5060208201516040808401518451859392600091859190811061030c5761030c610676565b016020015160f81c9050601b811480159061032b57508060ff16601c14155b1561038c5760405162461bcd60e51b815260206004820152603b602482015260008051602061068d83398151915260448201527f3a20696e76616c6964207369676e617475726520762076616c756500000000006064820152608401610157565b604080516000808252602082018084528a905260ff841692820192909252606081018590526080810184905260019060a0016020604051602081039080840390855afa1580156103e0573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b038116158015906104165750886001600160a01b0316816001600160a01b0316145b955050505050505b9392505050565b600060208251101561043657600080fd5b508051015190565b60405180606001604052806003906020820280368337509192915050565b6001600160a01b038116811461047157600080fd5b50565b634e487b7160e01b600052604160045260246000fd5b60005b838110156104a557818101518382015260200161048d565b50506000910152565b600082601f8301126104bf57600080fd5b81516001600160401b038111156104d8576104d8610474565b604051601f8201601f19908116603f011681016001600160401b038111828210171561050657610506610474565b60405281815283820160200185101561051e57600080fd5b61052f82602083016020870161048a565b949350505050565b60008060006060848603121561054c57600080fd5b83516105578161045c565b6020850151604086015191945092506001600160401b0381111561057a57600080fd5b610586868287016104ae565b9150509250925092565b6000806000606084860312156105a557600080fd5b83516105b08161045c565b60208501519093506001600160401b038111156105cc57600080fd5b6105d8868287016104ae565b604086015190935090506001600160401b0381111561057a57600080fd5b6000825161060881846020870161048a565b9190910192915050565b828152604060208201526000825180604084015261063781606085016020870161048a565b601f01601f1916919091016060019392505050565b60006020828403121561065e57600080fd5b81516001600160e01b03198116811461041e57600080fd5b634e487b7160e01b600052603260045260246000fdfe5369676e617475726556616c696461746f72237265636f7665725369676e6572'
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
39
|
* ABI for the ERC-6492 universal deployless signature validator contract.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Secp256k1, Signature } from 'ox'
|
|
1
|
+
import { AbiConstructor, Hex, Secp256k1, Signature } from 'ox'
|
|
2
2
|
import { SignatureErc6492 } from 'ox/erc6492'
|
|
3
3
|
import { describe, expect, test } from 'vp/test'
|
|
4
4
|
import { accounts } from '../../../test/constants/accounts.js'
|
|
5
|
+
import { anvilMainnet } from '../../../test/prool.js'
|
|
5
6
|
|
|
6
7
|
describe('assert', () => {
|
|
7
8
|
test('default', () => {
|
|
@@ -159,3 +160,49 @@ describe('from: validates object inputs', () => {
|
|
|
159
160
|
expect(SignatureErc6492.from(args)).toEqual(args)
|
|
160
161
|
})
|
|
161
162
|
})
|
|
163
|
+
|
|
164
|
+
describe('universalSignatureValidatorBytecode', () => {
|
|
165
|
+
const constructor = AbiConstructor.fromAbi(
|
|
166
|
+
SignatureErc6492.universalSignatureValidatorAbi,
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
function verify(args: readonly [Hex.Hex, Hex.Hex, Hex.Hex]) {
|
|
170
|
+
return anvilMainnet.request({
|
|
171
|
+
method: 'eth_call',
|
|
172
|
+
params: [
|
|
173
|
+
{
|
|
174
|
+
data: AbiConstructor.encode(constructor, {
|
|
175
|
+
args,
|
|
176
|
+
bytecode: SignatureErc6492.universalSignatureValidatorBytecode,
|
|
177
|
+
}),
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
})
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const hash = Hex.padLeft('0xdeadbeef', 32)
|
|
184
|
+
|
|
185
|
+
test('behavior: valid signature', async () => {
|
|
186
|
+
const signature = Secp256k1.sign({
|
|
187
|
+
payload: hash,
|
|
188
|
+
privateKey: accounts[0].privateKey,
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
expect(
|
|
192
|
+
await verify([accounts[0].address, hash, Signature.toHex(signature)]),
|
|
193
|
+
).toMatchInlineSnapshot(`"0x01"`)
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
test('behavior: zero address with a signature that recovers to it', async () => {
|
|
197
|
+
// `r = 0` and `s = 0` with `v = 27`, which `ecrecover` maps to the zero address.
|
|
198
|
+
const signature = Hex.concat(Hex.fromNumber(0, { size: 64 }), '0x1b')
|
|
199
|
+
|
|
200
|
+
expect(
|
|
201
|
+
await verify([
|
|
202
|
+
'0x0000000000000000000000000000000000000000',
|
|
203
|
+
hash,
|
|
204
|
+
signature,
|
|
205
|
+
]),
|
|
206
|
+
).toMatchInlineSnapshot(`"0x00"`)
|
|
207
|
+
})
|
|
208
|
+
})
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
WebAuthnP256,
|
|
10
10
|
WebCryptoP256,
|
|
11
11
|
} from 'ox'
|
|
12
|
-
import { describe, expect, test } from 'vp/test'
|
|
12
|
+
import { describe, expect, onTestFinished, test, vi } from 'vp/test'
|
|
13
13
|
import * as AccountConfig from './AccountConfig.js'
|
|
14
14
|
import * as SignatureEnvelope from './SignatureEnvelope.js'
|
|
15
15
|
|
|
@@ -751,6 +751,58 @@ describe('deserialize', () => {
|
|
|
751
751
|
)
|
|
752
752
|
})
|
|
753
753
|
|
|
754
|
+
test('behavior: splits webauthnData at the object that ends it', () => {
|
|
755
|
+
const metadata = {
|
|
756
|
+
// Ends with bytes that look like the start of a JSON object.
|
|
757
|
+
authenticatorData: Hex.concat(
|
|
758
|
+
signature_webauthn.metadata.authenticatorData,
|
|
759
|
+
Hex.fromString('{"a":"}\\'),
|
|
760
|
+
),
|
|
761
|
+
// Braces, an escaped quote and an escaped backslash inside strings.
|
|
762
|
+
clientDataJSON: JSON.stringify({
|
|
763
|
+
challenge: '{"}\\',
|
|
764
|
+
nested: { origin: '\\"' },
|
|
765
|
+
}),
|
|
766
|
+
}
|
|
767
|
+
expect(
|
|
768
|
+
SignatureEnvelope.deserialize(
|
|
769
|
+
SignatureEnvelope.serialize({ ...signature_webauthn, metadata }),
|
|
770
|
+
),
|
|
771
|
+
).toMatchObject({ metadata })
|
|
772
|
+
})
|
|
773
|
+
|
|
774
|
+
test('behavior: decodes and parses webauthnData at most once', () => {
|
|
775
|
+
// Each opening brace starts an object that only fails to parse past its
|
|
776
|
+
// end, so a search that tries every split offset reads all of it each time.
|
|
777
|
+
const clientDataJSON = `${'{"a":'.repeat(313)}${'}'.repeat(313)}`
|
|
778
|
+
const serialized = SignatureEnvelope.serialize({
|
|
779
|
+
...signature_webauthn,
|
|
780
|
+
metadata: {
|
|
781
|
+
authenticatorData: `0x${'00'.repeat(37)}` as const,
|
|
782
|
+
clientDataJSON,
|
|
783
|
+
},
|
|
784
|
+
})
|
|
785
|
+
|
|
786
|
+
const decode = vi.spyOn(TextDecoder.prototype, 'decode')
|
|
787
|
+
const parse = vi.spyOn(JSON, 'parse')
|
|
788
|
+
onTestFinished(() => {
|
|
789
|
+
vi.restoreAllMocks()
|
|
790
|
+
})
|
|
791
|
+
|
|
792
|
+
expect(() => SignatureEnvelope.deserialize(serialized)).toThrow(
|
|
793
|
+
'Unable to parse WebAuthn metadata',
|
|
794
|
+
)
|
|
795
|
+
expect(
|
|
796
|
+
decode.mock.calls.reduce(
|
|
797
|
+
(size, [input]) => size + (input?.byteLength ?? 0),
|
|
798
|
+
0,
|
|
799
|
+
),
|
|
800
|
+
).toBeLessThanOrEqual(clientDataJSON.length)
|
|
801
|
+
expect(
|
|
802
|
+
parse.mock.calls.reduce((size, [text]) => size + text.length, 0),
|
|
803
|
+
).toBeLessThanOrEqual(clientDataJSON.length)
|
|
804
|
+
})
|
|
805
|
+
|
|
754
806
|
test('error: throws on unknown type identifier', () => {
|
|
755
807
|
const unknownType = `0xff${'00'.repeat(129)}` as const
|
|
756
808
|
expect(() =>
|
|
@@ -2440,6 +2492,42 @@ describe('fromRpc', () => {
|
|
|
2440
2492
|
})
|
|
2441
2493
|
})
|
|
2442
2494
|
|
|
2495
|
+
test('behavior: decodes and parses webauthnData at most once', () => {
|
|
2496
|
+
// Each opening brace starts an object that only fails to parse past its
|
|
2497
|
+
// end, so a search that tries every split offset reads all of it each time.
|
|
2498
|
+
const clientDataJSON = `${'{"a":'.repeat(313)}${'}'.repeat(313)}`
|
|
2499
|
+
const rpc = {
|
|
2500
|
+
pubKeyX: publicKey.x,
|
|
2501
|
+
pubKeyY: publicKey.y,
|
|
2502
|
+
r: p256Signature.r,
|
|
2503
|
+
s: p256Signature.s,
|
|
2504
|
+
type: 'webAuthn',
|
|
2505
|
+
webauthnData: Hex.concat(
|
|
2506
|
+
`0x${'00'.repeat(37)}`,
|
|
2507
|
+
Hex.fromString(clientDataJSON),
|
|
2508
|
+
),
|
|
2509
|
+
} as const
|
|
2510
|
+
|
|
2511
|
+
const decode = vi.spyOn(TextDecoder.prototype, 'decode')
|
|
2512
|
+
const parse = vi.spyOn(JSON, 'parse')
|
|
2513
|
+
onTestFinished(() => {
|
|
2514
|
+
vi.restoreAllMocks()
|
|
2515
|
+
})
|
|
2516
|
+
|
|
2517
|
+
expect(() => SignatureEnvelope.fromRpc(rpc)).toThrow(
|
|
2518
|
+
'Unable to parse WebAuthn metadata',
|
|
2519
|
+
)
|
|
2520
|
+
expect(
|
|
2521
|
+
decode.mock.calls.reduce(
|
|
2522
|
+
(size, [input]) => size + (input?.byteLength ?? 0),
|
|
2523
|
+
0,
|
|
2524
|
+
),
|
|
2525
|
+
).toBeLessThanOrEqual(clientDataJSON.length)
|
|
2526
|
+
expect(
|
|
2527
|
+
parse.mock.calls.reduce((size, [text]) => size + text.length, 0),
|
|
2528
|
+
).toBeLessThanOrEqual(clientDataJSON.length)
|
|
2529
|
+
})
|
|
2530
|
+
|
|
2443
2531
|
test('error: throws on WebAuthn data above the maximum size', () => {
|
|
2444
2532
|
const rpc = {
|
|
2445
2533
|
pubKeyX: publicKey.x,
|
|
@@ -19,6 +19,7 @@ import * as Signature from '../core/Signature.js'
|
|
|
19
19
|
import type * as WebAuthnP256 from '../core/WebAuthnP256.js'
|
|
20
20
|
import * as ox_WebAuthnP256 from '../core/WebAuthnP256.js'
|
|
21
21
|
import * as AccountConfig from './AccountConfig.js'
|
|
22
|
+
import * as WebauthnData from './internal/webauthnData.js'
|
|
22
23
|
|
|
23
24
|
/** Signature type identifiers for encoding/decoding */
|
|
24
25
|
const serializedP256Type = '0x01'
|
|
@@ -641,24 +642,8 @@ function deserialize_(value: Serialized): SignatureEnvelope {
|
|
|
641
642
|
|
|
642
643
|
// Parse webauthnData into authenticatorData and clientDataJSON
|
|
643
644
|
// According to the Rust code, it's authenticatorData || clientDataJSON
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
let clientDataJSON: string | undefined
|
|
647
|
-
|
|
648
|
-
// Try to find the JSON start (clientDataJSON should start with '{')
|
|
649
|
-
for (let split = 37; split < webauthnDataSize; split++) {
|
|
650
|
-
const potentialJson = Hex.toString(Hex.slice(webauthnData, split))
|
|
651
|
-
if (potentialJson.startsWith('{') && potentialJson.endsWith('}')) {
|
|
652
|
-
try {
|
|
653
|
-
JSON.parse(potentialJson)
|
|
654
|
-
authenticatorData = Hex.slice(webauthnData, 0, split)
|
|
655
|
-
clientDataJSON = potentialJson
|
|
656
|
-
break
|
|
657
|
-
} catch {}
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
if (!authenticatorData || !clientDataJSON)
|
|
645
|
+
const metadata = WebauthnData.split(webauthnData)
|
|
646
|
+
if (!metadata)
|
|
662
647
|
throw new InvalidSerializedError({
|
|
663
648
|
reason:
|
|
664
649
|
'Unable to parse WebAuthn metadata: could not extract valid authenticatorData and clientDataJSON',
|
|
@@ -671,10 +656,7 @@ function deserialize_(value: Serialized): SignatureEnvelope {
|
|
|
671
656
|
x: Hex.slice(data, webauthnDataSize + 64, webauthnDataSize + 96),
|
|
672
657
|
y: Hex.slice(data, webauthnDataSize + 96, webauthnDataSize + 128),
|
|
673
658
|
},
|
|
674
|
-
metadata
|
|
675
|
-
authenticatorData,
|
|
676
|
-
clientDataJSON,
|
|
677
|
-
},
|
|
659
|
+
metadata,
|
|
678
660
|
signature: {
|
|
679
661
|
r: Hex.slice(data, webauthnDataSize, webauthnDataSize + 32),
|
|
680
662
|
s: Hex.slice(data, webauthnDataSize + 32, webauthnDataSize + 64),
|
|
@@ -1095,23 +1077,8 @@ export function fromRpc(envelope: SignatureEnvelopeRpc): SignatureEnvelope {
|
|
|
1095
1077
|
})
|
|
1096
1078
|
|
|
1097
1079
|
// Parse webauthnData into authenticatorData and clientDataJSON
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
// Try to find the JSON start (clientDataJSON should start with '{')
|
|
1102
|
-
for (let split = 37; split < webauthnDataSize; split++) {
|
|
1103
|
-
const potentialJson = Hex.toString(Hex.slice(webauthnData, split))
|
|
1104
|
-
if (potentialJson.startsWith('{') && potentialJson.endsWith('}')) {
|
|
1105
|
-
try {
|
|
1106
|
-
JSON.parse(potentialJson)
|
|
1107
|
-
authenticatorData = Hex.slice(webauthnData, 0, split)
|
|
1108
|
-
clientDataJSON = potentialJson
|
|
1109
|
-
break
|
|
1110
|
-
} catch {}
|
|
1111
|
-
}
|
|
1112
|
-
}
|
|
1113
|
-
|
|
1114
|
-
if (!authenticatorData || !clientDataJSON)
|
|
1080
|
+
const metadata = WebauthnData.split(webauthnData)
|
|
1081
|
+
if (!metadata)
|
|
1115
1082
|
throw new InvalidSerializedError({
|
|
1116
1083
|
reason:
|
|
1117
1084
|
'Unable to parse WebAuthn metadata: could not extract valid authenticatorData and clientDataJSON',
|
|
@@ -1119,10 +1086,7 @@ export function fromRpc(envelope: SignatureEnvelopeRpc): SignatureEnvelope {
|
|
|
1119
1086
|
})
|
|
1120
1087
|
|
|
1121
1088
|
return {
|
|
1122
|
-
metadata
|
|
1123
|
-
authenticatorData,
|
|
1124
|
-
clientDataJSON,
|
|
1125
|
-
},
|
|
1089
|
+
metadata,
|
|
1126
1090
|
publicKey: {
|
|
1127
1091
|
prefix: 4,
|
|
1128
1092
|
x: Hex.padLeft(envelope.pubKeyX, 32),
|
|
@@ -23,6 +23,14 @@ const rpc = {
|
|
|
23
23
|
} as const satisfies TransactionReceipt.Rpc
|
|
24
24
|
|
|
25
25
|
describe('fromRpc', () => {
|
|
26
|
+
test('behavior: unknown type named like an `Object.prototype` key', () => {
|
|
27
|
+
for (const type of ['toString', '__proto__'])
|
|
28
|
+
expect(
|
|
29
|
+
TransactionReceipt.fromRpc({ ...rpc, type } as TransactionReceipt.Rpc)
|
|
30
|
+
.type,
|
|
31
|
+
).toBe(type)
|
|
32
|
+
})
|
|
33
|
+
|
|
26
34
|
test('default', () => {
|
|
27
35
|
const receipt = TransactionReceipt.fromRpc(rpc)
|
|
28
36
|
expect(receipt).toMatchInlineSnapshot(`
|
|
@@ -124,7 +124,10 @@ export function fromRpc<const receipt extends Rpc | null>(
|
|
|
124
124
|
if (!decoded) return null as never
|
|
125
125
|
return {
|
|
126
126
|
...decoded,
|
|
127
|
-
|
|
127
|
+
// Own keys only: an inherited one such as `toString` is not a type.
|
|
128
|
+
type: Object.hasOwn(fromRpcType, receipt!.type)
|
|
129
|
+
? fromRpcType[receipt!.type as keyof typeof fromRpcType]
|
|
130
|
+
: receipt!.type,
|
|
128
131
|
} as never
|
|
129
132
|
}
|
|
130
133
|
|
|
@@ -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
|
|
|
@@ -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 {
|