ox 0.14.60 → 0.14.62
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 +24 -0
- package/_cjs/core/AbiEvent.js +14 -8
- package/_cjs/core/AbiEvent.js.map +1 -1
- package/_cjs/core/AbiItem.js +8 -1
- package/_cjs/core/AbiItem.js.map +1 -1
- package/_cjs/core/Caches.js +3 -6
- package/_cjs/core/Caches.js.map +1 -1
- package/_cjs/core/Hex.js +2 -1
- package/_cjs/core/Hex.js.map +1 -1
- package/_cjs/core/Siwe.js +10 -5
- package/_cjs/core/Siwe.js.map +1 -1
- package/_cjs/core/TxEnvelope.js +5 -3
- package/_cjs/core/TxEnvelope.js.map +1 -1
- package/_cjs/core/TxEnvelopeEip1559.js +5 -2
- package/_cjs/core/TxEnvelopeEip1559.js.map +1 -1
- package/_cjs/core/TxEnvelopeEip4844.js +3 -0
- package/_cjs/core/TxEnvelopeEip4844.js.map +1 -1
- package/_cjs/core/TxEnvelopeEip7702.js +3 -0
- package/_cjs/core/TxEnvelopeEip7702.js.map +1 -1
- package/_cjs/core/TypedData.js +49 -13
- package/_cjs/core/TypedData.js.map +1 -1
- package/_cjs/core/Value.js +5 -3
- package/_cjs/core/Value.js.map +1 -1
- package/_cjs/core/internal/abiItem.js +31 -7
- package/_cjs/core/internal/abiItem.js.map +1 -1
- package/_cjs/core/internal/abiParameters.js +20 -7
- package/_cjs/core/internal/abiParameters.js.map +1 -1
- package/_cjs/core/internal/caches.js +9 -0
- package/_cjs/core/internal/caches.js.map +1 -0
- package/_cjs/core/internal/frameNonce.js +2 -2
- package/_cjs/core/internal/frameNonce.js.map +1 -1
- package/_cjs/tempo/KeyAuthorization.js.map +1 -1
- package/_cjs/tempo/TxEnvelopeTempo.js +5 -2
- package/_cjs/tempo/TxEnvelopeTempo.js.map +1 -1
- package/_cjs/version.js +1 -1
- package/_esm/core/AbiEvent.js +18 -8
- package/_esm/core/AbiEvent.js.map +1 -1
- package/_esm/core/AbiItem.js +10 -1
- package/_esm/core/AbiItem.js.map +1 -1
- package/_esm/core/Caches.js +1 -4
- package/_esm/core/Caches.js.map +1 -1
- package/_esm/core/Hex.js +2 -1
- package/_esm/core/Hex.js.map +1 -1
- package/_esm/core/Siwe.js +11 -5
- package/_esm/core/Siwe.js.map +1 -1
- package/_esm/core/TxEnvelope.js +5 -3
- package/_esm/core/TxEnvelope.js.map +1 -1
- package/_esm/core/TxEnvelopeEip1559.js +6 -2
- package/_esm/core/TxEnvelopeEip1559.js.map +1 -1
- package/_esm/core/TxEnvelopeEip4844.js +4 -0
- package/_esm/core/TxEnvelopeEip4844.js.map +1 -1
- package/_esm/core/TxEnvelopeEip7702.js +4 -0
- package/_esm/core/TxEnvelopeEip7702.js.map +1 -1
- package/_esm/core/TypedData.js +59 -13
- package/_esm/core/TypedData.js.map +1 -1
- package/_esm/core/Value.js +5 -3
- package/_esm/core/Value.js.map +1 -1
- package/_esm/core/internal/abiItem.js +52 -11
- package/_esm/core/internal/abiItem.js.map +1 -1
- package/_esm/core/internal/abiParameters.js +24 -7
- package/_esm/core/internal/abiParameters.js.map +1 -1
- package/_esm/core/internal/caches.js +10 -0
- package/_esm/core/internal/caches.js.map +1 -0
- package/_esm/core/internal/frameNonce.js +2 -2
- package/_esm/core/internal/frameNonce.js.map +1 -1
- package/_esm/tempo/KeyAuthorization.js +7 -4
- package/_esm/tempo/KeyAuthorization.js.map +1 -1
- package/_esm/tempo/TxEnvelopeTempo.js +6 -2
- package/_esm/tempo/TxEnvelopeTempo.js.map +1 -1
- package/_esm/version.js +1 -1
- package/_types/core/AbiEvent.d.ts +2 -4
- package/_types/core/AbiEvent.d.ts.map +1 -1
- package/_types/core/AbiItem.d.ts.map +1 -1
- package/_types/core/Caches.d.ts +1 -2
- package/_types/core/Caches.d.ts.map +1 -1
- package/_types/core/Hex.d.ts.map +1 -1
- package/_types/core/Siwe.d.ts.map +1 -1
- package/_types/core/TxEnvelope.d.ts.map +1 -1
- package/_types/core/TxEnvelopeEip1559.d.ts.map +1 -1
- package/_types/core/TxEnvelopeEip4844.d.ts.map +1 -1
- package/_types/core/TxEnvelopeEip7702.d.ts.map +1 -1
- package/_types/core/TypedData.d.ts +8 -1
- package/_types/core/TypedData.d.ts.map +1 -1
- package/_types/core/Value.d.ts.map +1 -1
- package/_types/core/internal/abiItem.d.ts.map +1 -1
- package/_types/core/internal/abiParameters.d.ts +2 -2
- package/_types/core/internal/abiParameters.d.ts.map +1 -1
- package/_types/core/internal/caches.d.ts +10 -0
- package/_types/core/internal/caches.d.ts.map +1 -0
- package/_types/core/internal/frameNonce.d.ts.map +1 -1
- package/_types/tempo/KeyAuthorization.d.ts +26 -8
- package/_types/tempo/KeyAuthorization.d.ts.map +1 -1
- package/_types/tempo/TxEnvelopeTempo.d.ts.map +1 -1
- package/_types/version.d.ts +1 -1
- package/core/AbiEvent.ts +22 -11
- package/core/AbiItem.ts +9 -1
- package/core/Caches.ts +1 -6
- package/core/Hex.ts +3 -1
- package/core/Siwe.ts +13 -7
- package/core/TxEnvelope.ts +5 -3
- package/core/TxEnvelopeEip1559.ts +8 -2
- package/core/TxEnvelopeEip4844.ts +6 -0
- package/core/TxEnvelopeEip7702.ts +6 -0
- package/core/TypedData.ts +61 -12
- package/core/Value.ts +6 -3
- package/core/internal/abiItem.ts +54 -14
- package/core/internal/abiParameters.ts +26 -8
- package/core/internal/caches.ts +12 -0
- package/core/internal/frameNonce.ts +3 -4
- package/package.json +1 -1
- package/tempo/KeyAuthorization.test.ts +6 -4
- package/tempo/KeyAuthorization.ts +31 -10
- package/tempo/TxEnvelopeTempo.test.ts +51 -0
- package/tempo/TxEnvelopeTempo.ts +8 -2
- package/tempo/e2e.test.ts +73 -17
- package/version.ts +1 -1
package/core/internal/abiItem.ts
CHANGED
|
@@ -4,6 +4,7 @@ import type * as AbiItem from '../AbiItem.js'
|
|
|
4
4
|
import type * as AbiParameters from '../AbiParameters.js'
|
|
5
5
|
import * as Address from '../Address.js'
|
|
6
6
|
import * as Errors from '../Errors.js'
|
|
7
|
+
import * as Hex from '../Hex.js'
|
|
7
8
|
import { getArrayComponents } from './abiParameters.js'
|
|
8
9
|
import type {
|
|
9
10
|
Compute,
|
|
@@ -490,6 +491,23 @@ export declare namespace normalizeSignature {
|
|
|
490
491
|
export type ErrorType = Errors.BaseError | Errors.GlobalErrorType
|
|
491
492
|
}
|
|
492
493
|
|
|
494
|
+
/**
|
|
495
|
+
* `(u)int<M>` regex: (un)signed integer type of `M` bits, `0 < M <= 256`,
|
|
496
|
+
* `M % 8 == 0`. Hoisted to module scope; the prior literal at the call
|
|
497
|
+
* site was recompiled per overload-resolution iteration.
|
|
498
|
+
*
|
|
499
|
+
* @internal
|
|
500
|
+
*/
|
|
501
|
+
const integerTypeRegex =
|
|
502
|
+
/^u?int(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/
|
|
503
|
+
|
|
504
|
+
/**
|
|
505
|
+
* `bytes<M>` regex: binary type of `M` bytes, `0 < M <= 32`.
|
|
506
|
+
*
|
|
507
|
+
* @internal
|
|
508
|
+
*/
|
|
509
|
+
const fixedBytesTypeRegex = /^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/
|
|
510
|
+
|
|
493
511
|
/** @internal */
|
|
494
512
|
export function isArgOfType(
|
|
495
513
|
arg: unknown,
|
|
@@ -520,19 +538,30 @@ export function isArgOfType(
|
|
|
520
538
|
},
|
|
521
539
|
)
|
|
522
540
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
541
|
+
const integerMatch = integerTypeRegex.exec(abiParameterType)
|
|
542
|
+
if (integerMatch) {
|
|
543
|
+
if (typeof arg !== 'bigint' && typeof arg !== 'number') return false
|
|
544
|
+
if (typeof arg === 'number' && !Number.isInteger(arg)) return false
|
|
545
|
+
|
|
546
|
+
// An overload whose integer range excludes the value does not match.
|
|
547
|
+
const signed = abiParameterType.startsWith('int')
|
|
548
|
+
const bits = Number.parseInt(integerMatch[1] ?? '256', 10)
|
|
549
|
+
const max = 2n ** (BigInt(bits) - (signed ? 1n : 0n)) - 1n
|
|
550
|
+
const min = signed ? -max - 1n : 0n
|
|
551
|
+
return arg >= min && arg <= max
|
|
552
|
+
}
|
|
531
553
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
554
|
+
if (fixedBytesTypeRegex.test(abiParameterType)) {
|
|
555
|
+
if (typeof arg !== 'string' && !(arg instanceof Uint8Array))
|
|
556
|
+
return false
|
|
557
|
+
// An overload whose fixed size differs from the value does not match.
|
|
558
|
+
const bytes = abiParameterType.slice(5)
|
|
559
|
+
if (!bytes) return true
|
|
560
|
+
if (arg instanceof Uint8Array)
|
|
561
|
+
return arg.length === Number.parseInt(bytes, 10)
|
|
562
|
+
if (!Hex.validate(arg)) return false
|
|
563
|
+
return Hex.size(arg as Hex.Hex) === Number.parseInt(bytes, 10)
|
|
564
|
+
}
|
|
536
565
|
|
|
537
566
|
// fixed-length (`<type>[M]`) and dynamic (`<type>[]`) arrays
|
|
538
567
|
const arrayComponents = getArrayComponents(abiParameterType)
|
|
@@ -604,6 +633,15 @@ export function getAmbiguousTypes(
|
|
|
604
633
|
[(args[parameterIndex] as readonly unknown[] | undefined)?.[0]],
|
|
605
634
|
)
|
|
606
635
|
if (types) return types
|
|
636
|
+
// Same element type, different array shape: `uint256[]` and `uint256[2]`
|
|
637
|
+
// both accept `[1n, 1n]`, but one is dynamic and the other is static.
|
|
638
|
+
// Skip this when the element types differ. `string[]` vs `address[]`
|
|
639
|
+
// stays unambiguous for a non-address string.
|
|
640
|
+
if (
|
|
641
|
+
sourceArray[1] === targetArray[1] &&
|
|
642
|
+
sourceParameter.type !== targetParameter.type
|
|
643
|
+
)
|
|
644
|
+
return [sourceParameter.type, targetParameter.type]
|
|
607
645
|
continue
|
|
608
646
|
}
|
|
609
647
|
|
|
@@ -612,8 +650,8 @@ export function getAmbiguousTypes(
|
|
|
612
650
|
const value = args[parameterIndex]
|
|
613
651
|
|
|
614
652
|
const ambiguous = (() => {
|
|
615
|
-
if (types.includes('address') && types.includes('bytes20')) return true
|
|
616
653
|
// An `undefined` value comes from an empty array, which matches both types.
|
|
654
|
+
// This stays above the catch-all: a non-address string is not ambiguous.
|
|
617
655
|
if (
|
|
618
656
|
types.includes('address') &&
|
|
619
657
|
(types.includes('string') || types.includes('bytes'))
|
|
@@ -622,7 +660,9 @@ export function getAmbiguousTypes(
|
|
|
622
660
|
value === undefined ||
|
|
623
661
|
Address.validate(value as Address.Address, { strict: false })
|
|
624
662
|
)
|
|
625
|
-
|
|
663
|
+
// Distinct types that both matched cannot be distinguished at runtime
|
|
664
|
+
// (e.g. `bytes` vs `bytes32`, `uint256` vs `int256`, `address` vs `bytes20`).
|
|
665
|
+
return sourceParameter.type !== targetParameter.type
|
|
626
666
|
})()
|
|
627
667
|
|
|
628
668
|
if (ambiguous) return types
|
|
@@ -114,6 +114,14 @@ export function decodeAddress(
|
|
|
114
114
|
) {
|
|
115
115
|
const { checksum = false } = options
|
|
116
116
|
const value = cursor.readBytes(32)
|
|
117
|
+
// An address occupies the low 20 bytes of the word; the high 12 bytes
|
|
118
|
+
// must be zero padding.
|
|
119
|
+
for (let i = 0; i < 12; i++)
|
|
120
|
+
if (value[i] !== 0)
|
|
121
|
+
throw new Address.InvalidAddressError({
|
|
122
|
+
address: Hex.fromBytes(value),
|
|
123
|
+
cause: new Address.InvalidInputError(),
|
|
124
|
+
})
|
|
117
125
|
const wrap = (address: Hex.Hex) =>
|
|
118
126
|
checksum ? Address.checksum(address) : address
|
|
119
127
|
return [wrap(Hex.fromBytes(Bytes.slice(value, -20))), 32]
|
|
@@ -121,6 +129,7 @@ export function decodeAddress(
|
|
|
121
129
|
|
|
122
130
|
export declare namespace decodeAddress {
|
|
123
131
|
type ErrorType =
|
|
132
|
+
| Address.InvalidAddressError
|
|
124
133
|
| Hex.fromBytes.ErrorType
|
|
125
134
|
| Bytes.slice.ErrorType
|
|
126
135
|
| Errors.GlobalErrorType
|
|
@@ -289,19 +298,28 @@ export function decodeNumber(
|
|
|
289
298
|
) {
|
|
290
299
|
const signed = param.type.startsWith('int')
|
|
291
300
|
const size = Number.parseInt(param.type.split('int')[1] || '256', 10)
|
|
292
|
-
const value = cursor.readBytes(32)
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
301
|
+
const value = Bytes.toBigInt(cursor.readBytes(32), { signed })
|
|
302
|
+
// The word must hold a value that fits the declared size (zero-padded for
|
|
303
|
+
// unsigned, sign-extended for signed types).
|
|
304
|
+
if (size < 256) {
|
|
305
|
+
const max = (1n << BigInt(signed ? size - 1 : size)) - 1n
|
|
306
|
+
const min = signed ? -max - 1n : 0n
|
|
307
|
+
if (value > max || value < min)
|
|
308
|
+
throw new Hex.IntegerOutOfRangeError({
|
|
309
|
+
max: max.toString(),
|
|
310
|
+
min: min.toString(),
|
|
311
|
+
signed,
|
|
312
|
+
size: size / 8,
|
|
313
|
+
value: value.toString(),
|
|
314
|
+
})
|
|
315
|
+
}
|
|
316
|
+
return [size > 48 ? value : Number(value), 32]
|
|
299
317
|
}
|
|
300
318
|
|
|
301
319
|
export declare namespace decodeNumber {
|
|
302
320
|
type ErrorType =
|
|
303
|
-
| Bytes.toNumber.ErrorType
|
|
304
321
|
| Bytes.toBigInt.ErrorType
|
|
322
|
+
| Hex.IntegerOutOfRangeError
|
|
305
323
|
| Errors.GlobalErrorType
|
|
306
324
|
}
|
|
307
325
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type * as Address from '../Address.js'
|
|
2
|
+
import type * as Hex from '../Hex.js'
|
|
3
|
+
import { LruMap } from './lru.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Global caches, cleared together by `Caches.clear`.
|
|
7
|
+
* Only `checksum` is public (`Caches.checksum`).
|
|
8
|
+
*/
|
|
9
|
+
export const caches = {
|
|
10
|
+
checksum: /*#__PURE__*/ new LruMap<Address.Address>(8192),
|
|
11
|
+
signatureHash: /*#__PURE__*/ new LruMap<Hex.Hex>(8192),
|
|
12
|
+
}
|
|
@@ -2,6 +2,8 @@ import * as Errors from '../Errors.js'
|
|
|
2
2
|
import * as Hex from '../Hex.js'
|
|
3
3
|
import * as Quantity from './quantity.js'
|
|
4
4
|
|
|
5
|
+
const quantityRegex = /^0x(?:0|[1-9a-fA-F][0-9a-fA-F]*)$/
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* Asserts keyed nonce constraints.
|
|
7
9
|
* @internal
|
|
@@ -36,10 +38,7 @@ export function fromRpc(
|
|
|
36
38
|
): readonly bigint[] {
|
|
37
39
|
if (!Array.isArray(keys)) throw new InvalidError('Expected a nonce key list.')
|
|
38
40
|
const integer = (value: Hex.Hex): bigint => {
|
|
39
|
-
if (
|
|
40
|
-
typeof value !== 'string' ||
|
|
41
|
-
!/^0x(?:0|[1-9a-fA-F][0-9a-fA-F]*)$/.test(value)
|
|
42
|
-
)
|
|
41
|
+
if (typeof value !== 'string' || !quantityRegex.test(value))
|
|
43
42
|
throw new InvalidError('Expected a canonical RPC nonce quantity.')
|
|
44
43
|
return Hex.toBigInt(value)
|
|
45
44
|
}
|
package/package.json
CHANGED
|
@@ -118,8 +118,8 @@ describe('configurable account binding', () => {
|
|
|
118
118
|
})
|
|
119
119
|
|
|
120
120
|
test('behavior: accepts unbound configurable grants', () => {
|
|
121
|
-
// The node binds a
|
|
122
|
-
//
|
|
121
|
+
// The node binds a grant to its signer, so `account` is optional. From T14
|
|
122
|
+
// only the root key or owner quorum may sign a grant (TIP-1137).
|
|
123
123
|
const signed = KeyAuthorization.from(
|
|
124
124
|
{ address, chainId: 1n, type: 'configurable' },
|
|
125
125
|
{ signature: signature_secp256k1 },
|
|
@@ -2743,7 +2743,9 @@ describe('witness (TIP-1053)', () => {
|
|
|
2743
2743
|
})
|
|
2744
2744
|
})
|
|
2745
2745
|
|
|
2746
|
-
|
|
2746
|
+
// TIP-1137 removes admin keys at T14, but the wire fields are unchanged, so
|
|
2747
|
+
// pre-T14 history (T6 to T13) must still encode, decode, and hash.
|
|
2748
|
+
describe('historical admin keys (TIP-1049)', () => {
|
|
2747
2749
|
const account = '0x1111111111111111111111111111111111111111' as const
|
|
2748
2750
|
|
|
2749
2751
|
test('from: preserves isAdmin and account', () => {
|
|
@@ -2928,7 +2930,7 @@ describe('admin keys (TIP-1049)', () => {
|
|
|
2928
2930
|
})
|
|
2929
2931
|
|
|
2930
2932
|
describe('configurable admin keys', () => {
|
|
2931
|
-
test('behavior: a configurable
|
|
2933
|
+
test('behavior: round-trips a pre-T14 configurable admin grant', () => {
|
|
2932
2934
|
const signed = KeyAuthorization.from(
|
|
2933
2935
|
{
|
|
2934
2936
|
account: signature_configurable.account,
|
|
@@ -45,7 +45,14 @@ export type KeyAuthorization<
|
|
|
45
45
|
chainId: bigintType
|
|
46
46
|
/** Unix timestamp when key expires (undefined = never expires). */
|
|
47
47
|
expiry?: numberType | null | undefined
|
|
48
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* Whether this authorization provisions an admin access key (TIP-1049).
|
|
50
|
+
*
|
|
51
|
+
* @deprecated Admin access keys are removed at T14 by
|
|
52
|
+
* [TIP-1137](https://docs.tempo.xyz/protocol/tips/tip-1137). From T14 the Tempo
|
|
53
|
+
* node rejects any key authorization with `isAdmin: true`. The field is still
|
|
54
|
+
* encoded and decoded so pre-T14 history round-trips.
|
|
55
|
+
*/
|
|
49
56
|
isAdmin?: boolean | undefined
|
|
50
57
|
/**
|
|
51
58
|
* TIP20 spending limits for this key.
|
|
@@ -77,13 +84,19 @@ export type KeyAuthorization<
|
|
|
77
84
|
witness?: Hex.Hex | undefined
|
|
78
85
|
} & (
|
|
79
86
|
| {
|
|
80
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* Account address this authorization is bound to. When present, the Tempo node
|
|
89
|
+
* requires it to equal the transaction sender.
|
|
90
|
+
*/
|
|
81
91
|
account?: addressType | undefined
|
|
82
92
|
/** Primitive key type. */
|
|
83
93
|
type: SignatureEnvelope.Type
|
|
84
94
|
}
|
|
85
95
|
| {
|
|
86
|
-
/**
|
|
96
|
+
/**
|
|
97
|
+
* Account address this authorization is bound to. When present, the Tempo node
|
|
98
|
+
* requires it to equal the transaction sender.
|
|
99
|
+
*/
|
|
87
100
|
account?: addressType | undefined
|
|
88
101
|
/** Configurable account key type. */
|
|
89
102
|
type: 'configurable'
|
|
@@ -128,7 +141,12 @@ export type Rpc = {
|
|
|
128
141
|
chainId: Hex.Hex
|
|
129
142
|
/** Expiry timestamp (hex quantity or null). */
|
|
130
143
|
expiry: Hex.Hex | null | undefined
|
|
131
|
-
/**
|
|
144
|
+
/**
|
|
145
|
+
* Whether this authorization provisions an admin access key (TIP-1049).
|
|
146
|
+
*
|
|
147
|
+
* @deprecated Rejected from T14 by [TIP-1137](https://docs.tempo.xyz/protocol/tips/tip-1137).
|
|
148
|
+
* Still decoded for pre-T14 history.
|
|
149
|
+
*/
|
|
132
150
|
isAdmin?: boolean | null | undefined
|
|
133
151
|
/** Key identifier. */
|
|
134
152
|
keyId: Address.Address
|
|
@@ -140,13 +158,13 @@ export type Rpc = {
|
|
|
140
158
|
witness?: Hex.Hex | null | undefined
|
|
141
159
|
} & (
|
|
142
160
|
| {
|
|
143
|
-
/** Optional account address binding
|
|
161
|
+
/** Optional account address binding. When present, must equal the transaction sender. */
|
|
144
162
|
account?: Address.Address | null | undefined
|
|
145
163
|
/** Primitive key type. */
|
|
146
164
|
keyType: SignatureEnvelope.Type
|
|
147
165
|
}
|
|
148
166
|
| {
|
|
149
|
-
/** Optional account address binding
|
|
167
|
+
/** Optional account address binding. When present, must equal the transaction sender. */
|
|
150
168
|
account?: Address.Address | null | undefined
|
|
151
169
|
/** Configurable account key type, named `configurableAccount` by the node. */
|
|
152
170
|
keyType: 'configurableAccount'
|
|
@@ -723,7 +741,9 @@ export function fromTuple<const tuple extends Tuple>(
|
|
|
723
741
|
const isAdmin = (() => {
|
|
724
742
|
if (isAbsent(rawIsAdmin)) return undefined
|
|
725
743
|
// TIP-1049: the admin marker is strictly `0x01`. Any other value is a
|
|
726
|
-
// protocol-level decode error on the node, so reject it here too.
|
|
744
|
+
// protocol-level decode error on the node, so reject it here too. T14
|
|
745
|
+
// (TIP-1137) rejects admin authorizations at validation, not decoding,
|
|
746
|
+
// so pre-T14 history still decodes.
|
|
727
747
|
if (rawIsAdmin !== '0x01')
|
|
728
748
|
throw new InvalidAdminMarkerError(rawIsAdmin as Hex.Hex)
|
|
729
749
|
return true
|
|
@@ -1135,8 +1155,9 @@ export function toTuple<const authorization extends KeyAuthorization>(
|
|
|
1135
1155
|
{ value: witness, placeholder: '0x' },
|
|
1136
1156
|
// TIP-1049: admin marker. Present = `0x01` (RLP integer 1); absent
|
|
1137
1157
|
// skipped or omitted. Any other value is a hard decode error on the node.
|
|
1158
|
+
// TIP-1137 keeps this encoding but rejects `0x01` from T14.
|
|
1138
1159
|
{ value: isAdmin ? '0x01' : undefined, placeholder: '0x' },
|
|
1139
|
-
//
|
|
1160
|
+
// Optional account binding. Last field — never a placeholder.
|
|
1140
1161
|
{ value: account, placeholder: '0x' },
|
|
1141
1162
|
]
|
|
1142
1163
|
let lastPresent = -1
|
|
@@ -1238,8 +1259,8 @@ export class InvalidSignatureTypeError extends Error {
|
|
|
1238
1259
|
/**
|
|
1239
1260
|
* Thrown when a configurable account key grant omits its parent account binding.
|
|
1240
1261
|
*
|
|
1241
|
-
* @deprecated No longer thrown. The Tempo node
|
|
1242
|
-
*
|
|
1262
|
+
* @deprecated No longer thrown. The Tempo node does not require `account`; when
|
|
1263
|
+
* present, it must equal the transaction sender.
|
|
1243
1264
|
*/
|
|
1244
1265
|
export class MissingAccountError extends Error {
|
|
1245
1266
|
override readonly name = 'KeyAuthorization.MissingAccountError'
|
|
@@ -106,6 +106,19 @@ describe('assert', () => {
|
|
|
106
106
|
)
|
|
107
107
|
})
|
|
108
108
|
|
|
109
|
+
test('tip above zero fee cap', () => {
|
|
110
|
+
expect(() =>
|
|
111
|
+
TxEnvelopeTempo.assert({
|
|
112
|
+
calls: [{ to: '0x0000000000000000000000000000000000000000' }],
|
|
113
|
+
chainId: 1,
|
|
114
|
+
maxFeePerGas: 0n,
|
|
115
|
+
maxPriorityFeePerGas: 1n,
|
|
116
|
+
}),
|
|
117
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
118
|
+
`[TransactionEnvelope.TipAboveFeeCapError: The provided tip (\`maxPriorityFeePerGas\` = 0.000000001 gwei) cannot be higher than the fee cap (\`maxFeePerGas\` = 0 gwei).]`,
|
|
119
|
+
)
|
|
120
|
+
})
|
|
121
|
+
|
|
109
122
|
test('invalid chain id', () => {
|
|
110
123
|
expect(() =>
|
|
111
124
|
TxEnvelopeTempo.assert({
|
|
@@ -138,6 +151,44 @@ describe('deserialize', () => {
|
|
|
138
151
|
expect(deserialized).toEqual(transaction)
|
|
139
152
|
})
|
|
140
153
|
|
|
154
|
+
test('tip above empty fee cap', () => {
|
|
155
|
+
const serialized = TxEnvelopeTempo.serialize({
|
|
156
|
+
calls: [{ to: '0x0000000000000000000000000000000000000000' }],
|
|
157
|
+
chainId: 1,
|
|
158
|
+
maxPriorityFeePerGas: 1n,
|
|
159
|
+
})
|
|
160
|
+
expect(() =>
|
|
161
|
+
TxEnvelopeTempo.deserialize(serialized),
|
|
162
|
+
).toThrowErrorMatchingInlineSnapshot(
|
|
163
|
+
`[TransactionEnvelope.TipAboveFeeCapError: The provided tip (\`maxPriorityFeePerGas\` = 0.000000001 gwei) cannot be higher than the fee cap (\`maxFeePerGas\` = 0 gwei).]`,
|
|
164
|
+
)
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
test('fee payer', () => {
|
|
168
|
+
const serialized = TxEnvelopeTempo.serialize(transaction, {
|
|
169
|
+
format: 'feePayer',
|
|
170
|
+
sender: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
expect(TxEnvelopeTempo.deserialize(serialized)).toMatchInlineSnapshot(`
|
|
174
|
+
{
|
|
175
|
+
"calls": [
|
|
176
|
+
{
|
|
177
|
+
"to": "0x70997970c51812dc3a010c7d01b50e0d17dc79c8",
|
|
178
|
+
},
|
|
179
|
+
],
|
|
180
|
+
"chainId": 1,
|
|
181
|
+
"feePayerSignature": null,
|
|
182
|
+
"from": "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266",
|
|
183
|
+
"maxFeePerGas": 2000000000n,
|
|
184
|
+
"maxPriorityFeePerGas": 2000000000n,
|
|
185
|
+
"nonce": 785n,
|
|
186
|
+
"nonceKey": 0n,
|
|
187
|
+
"type": "tempo",
|
|
188
|
+
}
|
|
189
|
+
`)
|
|
190
|
+
})
|
|
191
|
+
|
|
141
192
|
test('minimal', () => {
|
|
142
193
|
const transaction = TxEnvelopeTempo.from({
|
|
143
194
|
chainId: 1,
|
package/tempo/TxEnvelopeTempo.ts
CHANGED
|
@@ -215,8 +215,8 @@ export function assert(envelope: PartialBy<TxEnvelopeTempo, 'type'>) {
|
|
|
215
215
|
})
|
|
216
216
|
|
|
217
217
|
if (
|
|
218
|
-
maxPriorityFeePerGas &&
|
|
219
|
-
maxFeePerGas &&
|
|
218
|
+
typeof maxPriorityFeePerGas === 'bigint' &&
|
|
219
|
+
typeof maxFeePerGas === 'bigint' &&
|
|
220
220
|
maxPriorityFeePerGas > maxFeePerGas
|
|
221
221
|
)
|
|
222
222
|
throw new TransactionEnvelope.TipAboveFeeCapError({
|
|
@@ -326,6 +326,12 @@ export function deserialize(serialized: Serialized): Compute<TxEnvelopeTempo> {
|
|
|
326
326
|
transaction.maxFeePerGas = BigInt(maxFeePerGas)
|
|
327
327
|
if (Hex.validate(maxPriorityFeePerGas) && maxPriorityFeePerGas !== '0x')
|
|
328
328
|
transaction.maxPriorityFeePerGas = BigInt(maxPriorityFeePerGas)
|
|
329
|
+
// An empty `maxFeePerGas` encodes zero, so a tip above it is rejected.
|
|
330
|
+
if (
|
|
331
|
+
transaction.maxPriorityFeePerGas &&
|
|
332
|
+
typeof transaction.maxFeePerGas === 'undefined'
|
|
333
|
+
)
|
|
334
|
+
transaction.maxFeePerGas = 0n
|
|
329
335
|
if (Hex.validate(nonceKey))
|
|
330
336
|
transaction.nonceKey = nonceKey === '0x' ? 0n : BigInt(nonceKey)
|
|
331
337
|
if (Hex.validate(validBefore) && validBefore !== '0x')
|
package/tempo/e2e.test.ts
CHANGED
|
@@ -2849,14 +2849,10 @@ describe('behavior: keyAuthorization', () => {
|
|
|
2849
2849
|
},
|
|
2850
2850
|
)
|
|
2851
2851
|
|
|
2852
|
-
// TIP-1049 admin keys
|
|
2853
|
-
// `
|
|
2854
|
-
// image which tracks main; devnet/testnet still ship the older
|
|
2855
|
-
// release and would reject the 9-field wire format with
|
|
2856
|
-
// `failed to decode signed transaction`.
|
|
2857
|
-
// TODO: remove skipIf when devnet/testnet have T6 (TIP-1049).
|
|
2852
|
+
// TIP-1137 removes TIP-1049 admin keys at T14. The localnet job runs the
|
|
2853
|
+
// `edge` image, which has T14 active; devnet/testnet may not.
|
|
2858
2854
|
test.skipIf(nodeEnv !== 'localnet')(
|
|
2859
|
-
'behavior: TIP-
|
|
2855
|
+
'behavior: TIP-1137 rejects an admin key authorization',
|
|
2860
2856
|
async () => {
|
|
2861
2857
|
const accessPrivateKey = Secp256k1.randomPrivateKey()
|
|
2862
2858
|
const accessAddress = Address.fromPublicKey(
|
|
@@ -2864,8 +2860,8 @@ describe('behavior: keyAuthorization', () => {
|
|
|
2864
2860
|
)
|
|
2865
2861
|
|
|
2866
2862
|
const keyAuth = KeyAuthorization.from({
|
|
2867
|
-
address: accessAddress,
|
|
2868
2863
|
account: root.address,
|
|
2864
|
+
address: accessAddress,
|
|
2869
2865
|
chainId: BigInt(chainId),
|
|
2870
2866
|
isAdmin: true,
|
|
2871
2867
|
type: 'secp256k1',
|
|
@@ -2889,15 +2885,79 @@ describe('behavior: keyAuthorization', () => {
|
|
|
2889
2885
|
calls: [{ to: '0x0000000000000000000000000000000000000000' }],
|
|
2890
2886
|
chainId,
|
|
2891
2887
|
feeToken: '0x20c0000000000000000000000000000000000001',
|
|
2888
|
+
gas: 1_000_000n,
|
|
2892
2889
|
keyAuthorization: keyAuth_signed,
|
|
2890
|
+
maxFeePerGas: Value.fromGwei('20'),
|
|
2891
|
+
maxPriorityFeePerGas: Value.fromGwei('10'),
|
|
2893
2892
|
nonce: BigInt(nonce),
|
|
2893
|
+
})
|
|
2894
|
+
|
|
2895
|
+
const signature = Secp256k1.sign({
|
|
2896
|
+
payload: TxEnvelopeTempo.getSignPayload(transaction, {
|
|
2897
|
+
from: root.address,
|
|
2898
|
+
}),
|
|
2899
|
+
privateKey: accessPrivateKey,
|
|
2900
|
+
})
|
|
2901
|
+
|
|
2902
|
+
const serialized_signed = TxEnvelopeTempo.serialize(transaction, {
|
|
2903
|
+
signature: SignatureEnvelope.from({
|
|
2904
|
+
inner: SignatureEnvelope.from(signature),
|
|
2905
|
+
type: 'keychain',
|
|
2906
|
+
userAddress: root.address,
|
|
2907
|
+
}),
|
|
2908
|
+
})
|
|
2909
|
+
|
|
2910
|
+
// From T14 no path can set `is_admin = true`.
|
|
2911
|
+
await expect(
|
|
2912
|
+
client.request({
|
|
2913
|
+
method: 'eth_sendRawTransactionSync',
|
|
2914
|
+
params: [serialized_signed],
|
|
2915
|
+
}),
|
|
2916
|
+
).rejects.toThrow('InvalidKeyId')
|
|
2917
|
+
},
|
|
2918
|
+
)
|
|
2919
|
+
|
|
2920
|
+
test.skipIf(nodeEnv !== 'localnet')(
|
|
2921
|
+
'behavior: account-bound key authorization round-trips through registration',
|
|
2922
|
+
async () => {
|
|
2923
|
+
const accessPrivateKey = Secp256k1.randomPrivateKey()
|
|
2924
|
+
const accessAddress = Address.fromPublicKey(
|
|
2925
|
+
Secp256k1.getPublicKey({ privateKey: accessPrivateKey }),
|
|
2926
|
+
)
|
|
2927
|
+
|
|
2928
|
+
// From T14 an `account` binding must equal the transaction sender.
|
|
2929
|
+
const keyAuth = KeyAuthorization.from({
|
|
2930
|
+
account: root.address,
|
|
2931
|
+
address: accessAddress,
|
|
2932
|
+
chainId: BigInt(chainId),
|
|
2933
|
+
type: 'secp256k1',
|
|
2934
|
+
})
|
|
2935
|
+
|
|
2936
|
+
const keyAuth_signed = KeyAuthorization.from(keyAuth, {
|
|
2937
|
+
signature: SignatureEnvelope.from(
|
|
2938
|
+
Secp256k1.sign({
|
|
2939
|
+
payload: KeyAuthorization.getSignPayload(keyAuth),
|
|
2940
|
+
privateKey: root.privateKey,
|
|
2941
|
+
}),
|
|
2942
|
+
),
|
|
2943
|
+
})
|
|
2944
|
+
|
|
2945
|
+
const nonce = await getTransactionCount(client, {
|
|
2946
|
+
address: root.address,
|
|
2947
|
+
blockTag: 'pending',
|
|
2948
|
+
})
|
|
2949
|
+
|
|
2950
|
+
const transaction = TxEnvelopeTempo.from({
|
|
2951
|
+
calls: [{ to: '0x0000000000000000000000000000000000000000' }],
|
|
2952
|
+
chainId,
|
|
2953
|
+
feeToken: '0x20c0000000000000000000000000000000000001',
|
|
2894
2954
|
gas: 1_000_000n,
|
|
2955
|
+
keyAuthorization: keyAuth_signed,
|
|
2895
2956
|
maxFeePerGas: Value.fromGwei('20'),
|
|
2896
2957
|
maxPriorityFeePerGas: Value.fromGwei('10'),
|
|
2958
|
+
nonce: BigInt(nonce),
|
|
2897
2959
|
})
|
|
2898
2960
|
|
|
2899
|
-
// The admin access key signs and authorizes itself in the same tx
|
|
2900
|
-
// (the canonical "auth+use" registration pattern).
|
|
2901
2961
|
const signature = Secp256k1.sign({
|
|
2902
2962
|
payload: TxEnvelopeTempo.getSignPayload(transaction, {
|
|
2903
2963
|
from: root.address,
|
|
@@ -2907,9 +2967,9 @@ describe('behavior: keyAuthorization', () => {
|
|
|
2907
2967
|
|
|
2908
2968
|
const serialized_signed = TxEnvelopeTempo.serialize(transaction, {
|
|
2909
2969
|
signature: SignatureEnvelope.from({
|
|
2910
|
-
userAddress: root.address,
|
|
2911
2970
|
inner: SignatureEnvelope.from(signature),
|
|
2912
2971
|
type: 'keychain',
|
|
2972
|
+
userAddress: root.address,
|
|
2913
2973
|
}),
|
|
2914
2974
|
})
|
|
2915
2975
|
|
|
@@ -2929,12 +2989,8 @@ describe('behavior: keyAuthorization', () => {
|
|
|
2929
2989
|
.then((tx) => Transaction.fromRpc(tx as any))
|
|
2930
2990
|
if (!response) throw new Error()
|
|
2931
2991
|
|
|
2932
|
-
|
|
2933
|
-
expect(response.keyAuthorization?.isAdmin).toBe(true)
|
|
2992
|
+
expect(response.keyAuthorization?.isAdmin).toBeUndefined()
|
|
2934
2993
|
expect(response.keyAuthorization?.account).toBe(root.address)
|
|
2935
|
-
|
|
2936
|
-
// The signing hash of the round-tripped authorization equals the
|
|
2937
|
-
// admin-bearing hash.
|
|
2938
2994
|
expect(KeyAuthorization.hash(response.keyAuthorization!)).toBe(
|
|
2939
2995
|
KeyAuthorization.hash(keyAuth_signed),
|
|
2940
2996
|
)
|
|
@@ -2943,7 +2999,7 @@ describe('behavior: keyAuthorization', () => {
|
|
|
2943
2999
|
|
|
2944
3000
|
// TODO: remove skipIf when devnet/testnet have T6.
|
|
2945
3001
|
test.skipIf(nodeEnv !== 'localnet')(
|
|
2946
|
-
'behavior:
|
|
3002
|
+
'behavior: unbound authorization is byte-equivalent to pre-TIP-1049',
|
|
2947
3003
|
async () => {
|
|
2948
3004
|
const accessPrivateKey = Secp256k1.randomPrivateKey()
|
|
2949
3005
|
const accessAddress = Address.fromPublicKey(
|
package/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** @internal */
|
|
2
|
-
export const version = '0.14.
|
|
2
|
+
export const version = '0.14.62'
|