ox 1.8.12 → 1.8.14

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.
Files changed (188) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/dist/core/AbiError.d.ts +2 -2
  3. package/dist/core/AbiError.d.ts.map +1 -1
  4. package/dist/core/AbiError.js +6 -2
  5. package/dist/core/AbiError.js.map +1 -1
  6. package/dist/core/AbiEvent.d.ts +71 -1
  7. package/dist/core/AbiEvent.d.ts.map +1 -1
  8. package/dist/core/AbiEvent.js +160 -19
  9. package/dist/core/AbiEvent.js.map +1 -1
  10. package/dist/core/AbiFunction.d.ts +1 -1
  11. package/dist/core/AbiFunction.d.ts.map +1 -1
  12. package/dist/core/AbiFunction.js +3 -5
  13. package/dist/core/AbiFunction.js.map +1 -1
  14. package/dist/core/AbiItem.d.ts.map +1 -1
  15. package/dist/core/AbiItem.js +18 -8
  16. package/dist/core/AbiItem.js.map +1 -1
  17. package/dist/core/Base32.d.ts +3 -3
  18. package/dist/core/Base32.d.ts.map +1 -1
  19. package/dist/core/Base32.js +5 -2
  20. package/dist/core/Base32.js.map +1 -1
  21. package/dist/core/Bytes.d.ts.map +1 -1
  22. package/dist/core/Bytes.js +4 -3
  23. package/dist/core/Bytes.js.map +1 -1
  24. package/dist/core/Caches.d.ts +1 -2
  25. package/dist/core/Caches.d.ts.map +1 -1
  26. package/dist/core/Caches.js +1 -4
  27. package/dist/core/Caches.js.map +1 -1
  28. package/dist/core/Cbor.d.ts.map +1 -1
  29. package/dist/core/Cbor.js +16 -2
  30. package/dist/core/Cbor.js.map +1 -1
  31. package/dist/core/CompactSize.d.ts +8 -1
  32. package/dist/core/CompactSize.d.ts.map +1 -1
  33. package/dist/core/CompactSize.js +9 -0
  34. package/dist/core/CompactSize.js.map +1 -1
  35. package/dist/core/Hex.d.ts.map +1 -1
  36. package/dist/core/Hex.js +9 -4
  37. package/dist/core/Hex.js.map +1 -1
  38. package/dist/core/Rlp.d.ts +9 -2
  39. package/dist/core/Rlp.d.ts.map +1 -1
  40. package/dist/core/Rlp.js +51 -8
  41. package/dist/core/Rlp.js.map +1 -1
  42. package/dist/core/RpcTransport.d.ts.map +1 -1
  43. package/dist/core/RpcTransport.js +11 -4
  44. package/dist/core/RpcTransport.js.map +1 -1
  45. package/dist/core/Siwe.d.ts.map +1 -1
  46. package/dist/core/Siwe.js +24 -9
  47. package/dist/core/Siwe.js.map +1 -1
  48. package/dist/core/TxEnvelope.d.ts.map +1 -1
  49. package/dist/core/TxEnvelope.js +5 -3
  50. package/dist/core/TxEnvelope.js.map +1 -1
  51. package/dist/core/TxEnvelopeEip1559.d.ts.map +1 -1
  52. package/dist/core/TxEnvelopeEip1559.js +6 -2
  53. package/dist/core/TxEnvelopeEip1559.js.map +1 -1
  54. package/dist/core/TxEnvelopeEip4844.d.ts.map +1 -1
  55. package/dist/core/TxEnvelopeEip4844.js +4 -0
  56. package/dist/core/TxEnvelopeEip4844.js.map +1 -1
  57. package/dist/core/TxEnvelopeEip7702.d.ts.map +1 -1
  58. package/dist/core/TxEnvelopeEip7702.js +4 -0
  59. package/dist/core/TxEnvelopeEip7702.js.map +1 -1
  60. package/dist/core/TypedData.d.ts +8 -1
  61. package/dist/core/TypedData.d.ts.map +1 -1
  62. package/dist/core/TypedData.js +55 -14
  63. package/dist/core/TypedData.js.map +1 -1
  64. package/dist/core/Value.d.ts.map +1 -1
  65. package/dist/core/Value.js +5 -3
  66. package/dist/core/Value.js.map +1 -1
  67. package/dist/core/internal/abiItem.d.ts +3 -1
  68. package/dist/core/internal/abiItem.d.ts.map +1 -1
  69. package/dist/core/internal/abiItem.js +46 -13
  70. package/dist/core/internal/abiItem.js.map +1 -1
  71. package/dist/core/internal/abiParameters.d.ts +2 -2
  72. package/dist/core/internal/abiParameters.d.ts.map +1 -1
  73. package/dist/core/internal/abiParameters.js +24 -7
  74. package/dist/core/internal/abiParameters.js.map +1 -1
  75. package/dist/core/internal/caches.d.ts +10 -0
  76. package/dist/core/internal/caches.d.ts.map +1 -0
  77. package/dist/core/internal/caches.js +10 -0
  78. package/dist/core/internal/caches.js.map +1 -0
  79. package/dist/core/internal/frameNonce.d.ts.map +1 -1
  80. package/dist/core/internal/frameNonce.js +2 -2
  81. package/dist/core/internal/frameNonce.js.map +1 -1
  82. package/dist/core/internal/rpcSchemas/eth.d.ts +3 -2
  83. package/dist/core/internal/rpcSchemas/eth.d.ts.map +1 -1
  84. package/dist/erc4337/UserOperation.d.ts +15 -2
  85. package/dist/erc4337/UserOperation.d.ts.map +1 -1
  86. package/dist/erc4337/UserOperation.js +8 -2
  87. package/dist/erc4337/UserOperation.js.map +1 -1
  88. package/dist/erc8021/Attribution.d.ts.map +1 -1
  89. package/dist/erc8021/Attribution.js +12 -3
  90. package/dist/erc8021/Attribution.js.map +1 -1
  91. package/dist/tempo/AccountOperation.d.ts +8 -0
  92. package/dist/tempo/AccountOperation.d.ts.map +1 -1
  93. package/dist/tempo/AccountOperation.js +26 -6
  94. package/dist/tempo/AccountOperation.js.map +1 -1
  95. package/dist/tempo/KeyAuthorization.d.ts +21 -6
  96. package/dist/tempo/KeyAuthorization.d.ts.map +1 -1
  97. package/dist/tempo/KeyAuthorization.js +7 -4
  98. package/dist/tempo/KeyAuthorization.js.map +1 -1
  99. package/dist/tempo/SignatureEnvelope.d.ts +4 -4
  100. package/dist/tempo/Tick.d.ts.map +1 -1
  101. package/dist/tempo/Tick.js +4 -3
  102. package/dist/tempo/Tick.js.map +1 -1
  103. package/dist/tempo/TxEnvelopeTempo.d.ts.map +1 -1
  104. package/dist/tempo/TxEnvelopeTempo.js +6 -2
  105. package/dist/tempo/TxEnvelopeTempo.js.map +1 -1
  106. package/dist/zod/Address.d.ts.map +1 -1
  107. package/dist/zod/Address.js +2 -1
  108. package/dist/zod/Address.js.map +1 -1
  109. package/dist/zod/FrameRequest.d.ts.map +1 -1
  110. package/dist/zod/FrameRequest.js +2 -1
  111. package/dist/zod/FrameRequest.js.map +1 -1
  112. package/dist/zod/Hex.d.ts.map +1 -1
  113. package/dist/zod/Hex.js +2 -1
  114. package/dist/zod/Hex.js.map +1 -1
  115. package/dist/zod/Solidity.d.ts.map +1 -1
  116. package/dist/zod/Solidity.js +12 -7
  117. package/dist/zod/Solidity.js.map +1 -1
  118. package/dist/zod/TypedData.d.ts +12 -12
  119. package/package.json +5 -2
  120. package/src/core/AbiError.ts +33 -22
  121. package/src/core/AbiEvent.ts +177 -18
  122. package/src/core/AbiFunction.ts +10 -7
  123. package/src/core/AbiItem.ts +17 -8
  124. package/src/core/Base32.ts +8 -3
  125. package/src/core/Bytes.ts +4 -3
  126. package/src/core/Caches.ts +1 -6
  127. package/src/core/Cbor.ts +20 -2
  128. package/src/core/CompactSize.ts +13 -0
  129. package/src/core/Hex.ts +10 -5
  130. package/src/core/Rlp.ts +55 -5
  131. package/src/core/RpcTransport.ts +11 -4
  132. package/src/core/Siwe.ts +26 -11
  133. package/src/core/TxEnvelope.ts +5 -3
  134. package/src/core/TxEnvelopeEip1559.ts +8 -2
  135. package/src/core/TxEnvelopeEip4844.ts +6 -0
  136. package/src/core/TxEnvelopeEip7702.ts +6 -0
  137. package/src/core/TypedData.ts +62 -13
  138. package/src/core/Value.ts +6 -3
  139. package/src/core/_test/AbiError.test-d.ts +10 -0
  140. package/src/core/_test/AbiError.test.ts +73 -0
  141. package/src/core/_test/AbiEvent.fuzz.ts +260 -0
  142. package/src/core/_test/AbiEvent.snap-d.ts +9 -0
  143. package/src/core/_test/AbiEvent.test.ts +421 -0
  144. package/src/core/_test/AbiFunction.snap-d.ts +25 -0
  145. package/src/core/_test/AbiFunction.test.ts +101 -18
  146. package/src/core/_test/AbiItem.snap-d.ts +11 -0
  147. package/src/core/_test/AbiItem.test.ts +393 -5
  148. package/src/core/_test/AbiParameters.decode.test.ts +140 -1
  149. package/src/core/_test/Base32.test.ts +16 -0
  150. package/src/core/_test/Bytes.test.ts +15 -0
  151. package/src/core/_test/Caches.test.ts +10 -1
  152. package/src/core/_test/Cbor.test.ts +23 -0
  153. package/src/core/_test/CompactSize.test.ts +14 -0
  154. package/src/core/_test/Hex.test.ts +25 -0
  155. package/src/core/_test/Rlp.test.ts +51 -0
  156. package/src/core/_test/RpcSchema.test-d.ts +23 -1
  157. package/src/core/_test/RpcTransport.test.ts +47 -0
  158. package/src/core/_test/Siwe.test.ts +28 -0
  159. package/src/core/_test/TransactionEnvelopeEip1559.test.ts +24 -0
  160. package/src/core/_test/TransactionEnvelopeEip4844.test.ts +13 -0
  161. package/src/core/_test/TransactionEnvelopeEip7702.test.ts +13 -0
  162. package/src/core/_test/TypedData.test.ts +203 -1
  163. package/src/core/internal/abiItem.ts +58 -18
  164. package/src/core/internal/abiParameters.ts +26 -8
  165. package/src/core/internal/caches.ts +12 -0
  166. package/src/core/internal/frameNonce.ts +3 -4
  167. package/src/core/internal/rpcSchemas/eth.ts +2 -1
  168. package/src/erc4337/UserOperation.ts +30 -3
  169. package/src/erc4337/_test/UserOperation.test.ts +132 -35
  170. package/src/erc8021/Attribution.ts +9 -7
  171. package/src/erc8021/_test/Attribution.test.ts +37 -0
  172. package/src/tempo/AccountOperation.test.ts +116 -0
  173. package/src/tempo/AccountOperation.ts +38 -5
  174. package/src/tempo/AccountSimulation.test.ts +1 -1
  175. package/src/tempo/KeyAuthorization.test.ts +6 -4
  176. package/src/tempo/KeyAuthorization.ts +26 -8
  177. package/src/tempo/SignatureEnvelope.test.ts +12 -0
  178. package/src/tempo/SignatureEnvelope.ts +4 -4
  179. package/src/tempo/Tick.test.ts +10 -0
  180. package/src/tempo/Tick.ts +5 -3
  181. package/src/tempo/TxEnvelopeTempo.test.ts +26 -0
  182. package/src/tempo/TxEnvelopeTempo.ts +8 -2
  183. package/src/tempo/e2e.test.ts +73 -17
  184. package/src/version.ts +1 -1
  185. package/src/zod/Address.ts +3 -3
  186. package/src/zod/FrameRequest.ts +3 -4
  187. package/src/zod/Hex.ts +3 -1
  188. package/src/zod/Solidity.ts +15 -18
@@ -391,6 +391,83 @@ describe('serializeKeyAuthorization', () => {
391
391
  })
392
392
 
393
393
  describe('serializeTransaction', () => {
394
+ test('access key transactions', async () => {
395
+ const userAddress = '0x4444444444444444444444444444444444444444'
396
+ const results = []
397
+ for (const transaction_ of [
398
+ transaction,
399
+ TxEnvelopeTempo.serialize(TxEnvelopeTempo.deserialize(transaction), {
400
+ format: 'feePayer',
401
+ sender: userAddress,
402
+ }),
403
+ ]) {
404
+ const hash = AccountOperation.getHash({
405
+ account,
406
+ config: currentConfig,
407
+ transaction: transaction_,
408
+ type: 'transaction',
409
+ userAddress,
410
+ })
411
+ const selection = await AccountOperation.selectApprovals({
412
+ account,
413
+ approvals: [
414
+ signApproval(owners[0]!, hash),
415
+ signApproval(owners[1]!, hash),
416
+ ],
417
+ config: currentConfig,
418
+ hash,
419
+ })
420
+ const operation = AccountOperation.from({
421
+ account,
422
+ approvals: selection.approvals,
423
+ config: currentConfig,
424
+ createdAt: 1,
425
+ hash,
426
+ signatureCount: selection.signatureCount,
427
+ status: 'pending',
428
+ threshold: selection.threshold,
429
+ transaction: transaction_,
430
+ type: 'transaction',
431
+ updatedAt: 1,
432
+ userAddress,
433
+ weight: selection.weight,
434
+ })
435
+ const value = TxEnvelopeTempo.deserialize(
436
+ AccountOperation.serializeTransaction(operation, {
437
+ approvals: selection.selectedApprovals,
438
+ }),
439
+ )
440
+ const { signature } = value
441
+ if (signature?.type !== 'keychain') throw new Error('expected keychain')
442
+ results.push({
443
+ from: value.from,
444
+ innerAccount:
445
+ signature.inner.type === 'configurable'
446
+ ? signature.inner.account
447
+ : undefined,
448
+ userAddress: signature.userAddress,
449
+ version: signature.version,
450
+ })
451
+ }
452
+
453
+ expect(results).toMatchInlineSnapshot(`
454
+ [
455
+ {
456
+ "from": "0x4444444444444444444444444444444444444444",
457
+ "innerAccount": "0xb3cc0b31026c7a54a9c45e468c674722c3c5b3b5",
458
+ "userAddress": "0x4444444444444444444444444444444444444444",
459
+ "version": "v2",
460
+ },
461
+ {
462
+ "from": "0x4444444444444444444444444444444444444444",
463
+ "innerAccount": "0xb3cc0b31026c7a54a9c45e468c674722c3c5b3b5",
464
+ "userAddress": "0x4444444444444444444444444444444444444444",
465
+ "version": "v2",
466
+ },
467
+ ]
468
+ `)
469
+ })
470
+
394
471
  test('current and initial transactions', async () => {
395
472
  const results = []
396
473
  for (const applicableConfig of [currentConfig, config]) {
@@ -593,6 +670,45 @@ describe('serializeTransaction', () => {
593
670
  })
594
671
 
595
672
  describe('from', () => {
673
+ test('error: access key transaction hash without userAddress', () => {
674
+ const userAddress = '0x4444444444444444444444444444444444444444'
675
+ const hash = AccountOperation.getHash({
676
+ account,
677
+ config: currentConfig,
678
+ transaction,
679
+ type: 'transaction',
680
+ userAddress,
681
+ })
682
+ const base = {
683
+ account,
684
+ approvals: [],
685
+ config: currentConfig,
686
+ createdAt: 1,
687
+ hash,
688
+ signatureCount: 0,
689
+ status: 'pending',
690
+ threshold: 2,
691
+ transaction,
692
+ type: 'transaction',
693
+ updatedAt: 1,
694
+ weight: 0,
695
+ } as const
696
+
697
+ expect(() =>
698
+ AccountOperation.from(base),
699
+ ).toThrowErrorMatchingInlineSnapshot(
700
+ `[AccountOperation.InvalidOperationError: Invalid account operation: hash does not match the operation payload.]`,
701
+ )
702
+ expect(() =>
703
+ AccountOperation.from({ ...base, userAddress: account }),
704
+ ).toThrowErrorMatchingInlineSnapshot(
705
+ `[AccountOperation.InvalidOperationError: Invalid account operation: a configurable account cannot be its own access key.]`,
706
+ )
707
+ expect(AccountOperation.from({ ...base, userAddress }).userAddress).toBe(
708
+ userAddress,
709
+ )
710
+ })
711
+
596
712
  test('transaction states', () => {
597
713
  const pending = AccountOperation.from(transactionPending)
598
714
  const submitting = AccountOperation.from({
@@ -43,6 +43,12 @@ export type TransactionOperation<quantity = bigint> = Base<quantity> & {
43
43
  transactionHash?: Hex.Hex | undefined
44
44
  /** Operation kind. */
45
45
  type: 'transaction'
46
+ /**
47
+ * Parent account when the configurable account signs as its access key
48
+ * (TIP-1111). The transaction is then sent from it with a keychain V2
49
+ * signature wrapping the owner quorum.
50
+ */
51
+ userAddress?: Address.Address | undefined
46
52
  }
47
53
 
48
54
  /** Account key authorization approval operation. */
@@ -94,6 +100,7 @@ export function getHash(options: getHash.Options): Hex.Hex {
94
100
  options.type === 'transaction'
95
101
  ? TxEnvelopeTempo.getSignPayload(
96
102
  TxEnvelopeTempo.deserialize(options.transaction),
103
+ { from: options.userAddress },
97
104
  )
98
105
  : KeyAuthorization_.getSignPayload(
99
106
  KeyAuthorization_.deserialize(options.keyAuthorization),
@@ -124,6 +131,8 @@ export declare namespace getHash {
124
131
  transaction: TxEnvelopeTempo.Serialized
125
132
  /** Operation kind. */
126
133
  type: 'transaction'
134
+ /** Parent account when the configurable account signs as its access key. */
135
+ userAddress?: Address.Address | undefined
127
136
  }
128
137
  )
129
138
 
@@ -333,17 +342,26 @@ export function serializeTransaction(
333
342
  assertApproval(value.account, approval, value.config),
334
343
  )
335
344
  assertRetainedApprovals(value, approvals)
345
+ const { userAddress } = value
336
346
  const signatures = SignatureEnvelope.sortApprovals({
337
347
  account: value.account,
338
348
  config: value.config,
339
- payload: TxEnvelopeTempo.getSignPayload(envelope),
349
+ payload: TxEnvelopeTempo.getSignPayload(envelope, { from: userAddress }),
340
350
  signatures: approvals,
341
351
  })
342
- const signature = SignatureEnvelope.from({
352
+ const configurable = SignatureEnvelope.from({
343
353
  account: value.account,
344
354
  config: value.config,
345
355
  signatures,
346
356
  })
357
+ const signature = userAddress
358
+ ? SignatureEnvelope.from({
359
+ inner: configurable,
360
+ type: 'keychain',
361
+ userAddress,
362
+ version: 'v2',
363
+ })
364
+ : configurable
347
365
  return TxEnvelopeTempo.serialize(
348
366
  envelope,
349
367
  value.transaction.startsWith(TxEnvelopeTempo.feePayerMagic)
@@ -808,14 +826,27 @@ function assertTransaction(operation: TransactionOperation): void {
808
826
  throw new InvalidOperationError({
809
827
  reason: 'transaction must not contain an outer sender signature',
810
828
  })
829
+ const { userAddress } = operation
830
+ if (userAddress !== undefined) {
831
+ if (!Address.validate(userAddress) || Hex.toBigInt(userAddress) === 0n)
832
+ throw new InvalidOperationError({ reason: 'userAddress is invalid' })
833
+ if (userAddress.toLowerCase() === operation.account.toLowerCase())
834
+ throw new InvalidOperationError({
835
+ reason: 'a configurable account cannot be its own access key',
836
+ })
837
+ }
838
+ const sender = userAddress ?? operation.account
811
839
  if (
812
840
  transaction.from &&
813
- transaction.from.toLowerCase() !== operation.account.toLowerCase()
841
+ transaction.from.toLowerCase() !== sender.toLowerCase()
814
842
  )
815
843
  throw new InvalidOperationError({
816
844
  reason: 'transaction sender does not match the operation account',
817
845
  })
818
- assertOperationHash(operation, TxEnvelopeTempo.getSignPayload(transaction))
846
+ assertOperationHash(
847
+ operation,
848
+ TxEnvelopeTempo.getSignPayload(transaction, { from: userAddress }),
849
+ )
819
850
  const normalized = TxEnvelopeTempo.serialize(
820
851
  transaction,
821
852
  feePayer
@@ -844,12 +875,14 @@ function assertKeyAuthorization(
844
875
  submissionId?: unknown
845
876
  transaction?: unknown
846
877
  transactionHash?: unknown
878
+ userAddress?: unknown
847
879
  }
848
880
  if (
849
881
  transactionFields.expiresAt !== undefined ||
850
882
  transactionFields.submissionId !== undefined ||
851
883
  transactionFields.transaction !== undefined ||
852
- transactionFields.transactionHash !== undefined
884
+ transactionFields.transactionHash !== undefined ||
885
+ transactionFields.userAddress !== undefined
853
886
  )
854
887
  throw new InvalidOperationError({
855
888
  reason: 'key authorization operations cannot contain transaction fields',
@@ -107,7 +107,7 @@ describe('fromRpc', () => {
107
107
  expect(() =>
108
108
  AccountSimulation.fromRpc({ ...rpc, config: noncanonical }),
109
109
  ).toThrowErrorMatchingInlineSnapshot(
110
- `[AccountSimulation.InvalidSimulationError: Invalid account simulation: invalid config encoding.]`,
110
+ `[Rlp.NonCanonicalError: RLP payload is not canonically encoded: single byte \`0x00\` is wrapped in an explicit length prefix instead of being encoded as itself.]`,
111
111
  )
112
112
  })
113
113
  })
@@ -97,8 +97,8 @@ const signature_keychain = {
97
97
 
98
98
  describe('configurable account binding', () => {
99
99
  test('behavior: accepts unbound configurable grants', () => {
100
- // The node binds a root-signed grant to its signer, so only admin-signed
101
- // grants need `account` (TIP-1049).
100
+ // The node binds a grant to its signer, so `account` is optional. From T14
101
+ // only the root key or owner quorum may sign a grant (TIP-1137).
102
102
  const signed = KeyAuthorization.from(
103
103
  { address, chainId: 1n, type: 'configurable' },
104
104
  { signature: signature_secp256k1 },
@@ -2673,7 +2673,9 @@ describe('witness (TIP-1053)', () => {
2673
2673
  })
2674
2674
  })
2675
2675
 
2676
- describe('admin keys (TIP-1049)', () => {
2676
+ // TIP-1137 removes admin keys at T14, but the wire fields are unchanged, so
2677
+ // pre-T14 history (T6 to T13) must still encode, decode, and hash.
2678
+ describe('historical admin keys (TIP-1049)', () => {
2677
2679
  const account = '0x1111111111111111111111111111111111111111' as const
2678
2680
 
2679
2681
  test('from: preserves isAdmin and account', () => {
@@ -2858,7 +2860,7 @@ describe('admin keys (TIP-1049)', () => {
2858
2860
  })
2859
2861
 
2860
2862
  describe('configurable admin keys', () => {
2861
- test('behavior: a configurable account may sign or be granted an admin key', () => {
2863
+ test('behavior: round-trips a pre-T14 configurable admin grant', () => {
2862
2864
  const signed = KeyAuthorization.from(
2863
2865
  {
2864
2866
  account: signature_configurable.account,
@@ -38,7 +38,10 @@ export type KeyAuthorization<
38
38
  bigintType = bigint,
39
39
  numberType = number,
40
40
  > = {
41
- /** Account address this authorization is bound to. Required when an admin access key signs the grant (TIP-1049). */
41
+ /**
42
+ * Account address this authorization is bound to. When present, the Tempo node
43
+ * requires it to equal the transaction sender.
44
+ */
42
45
  account?: Address.Address | undefined
43
46
  /** Address derived from the public key of the key type. */
44
47
  address: Address.Address
@@ -46,7 +49,14 @@ export type KeyAuthorization<
46
49
  chainId: bigintType
47
50
  /** Unix timestamp when key expires (undefined = never expires). */
48
51
  expiry?: numberType | null | undefined
49
- /** Whether this authorization provisions an admin access key. */
52
+ /**
53
+ * Whether this authorization provisions an admin access key (TIP-1049).
54
+ *
55
+ * @deprecated Admin access keys are removed at T14 by
56
+ * [TIP-1137](https://docs.tempo.xyz/protocol/tips/tip-1137). From T14 the Tempo
57
+ * node rejects any key authorization with `isAdmin: true`. The field is still
58
+ * encoded and decoded so pre-T14 history round-trips.
59
+ */
50
60
  isAdmin?: boolean | undefined
51
61
  /**
52
62
  * TIP20 spending limits for this key.
@@ -104,7 +114,7 @@ export type Input = KeyAuthorization<false, bigint, number>
104
114
 
105
115
  /** RPC representation matching the node's wire format. */
106
116
  export type Rpc = {
107
- /** Optional account address binding (TIP-1049). */
117
+ /** Optional account address binding. When present, must equal the transaction sender. */
108
118
  account?: Address.Address | null | undefined
109
119
  /** Allowed call scopes (node field: `allowedCalls`). */
110
120
  allowedCalls?: readonly RpcCallScope[] | null | undefined
@@ -112,7 +122,12 @@ export type Rpc = {
112
122
  chainId: Hex.Hex
113
123
  /** Expiry timestamp (hex quantity or null). */
114
124
  expiry: Hex.Hex | null | undefined
115
- /** Whether this authorization provisions an admin access key (TIP-1049). */
125
+ /**
126
+ * Whether this authorization provisions an admin access key (TIP-1049).
127
+ *
128
+ * @deprecated Rejected from T14 by [TIP-1137](https://docs.tempo.xyz/protocol/tips/tip-1137).
129
+ * Still decoded for pre-T14 history.
130
+ */
116
131
  isAdmin?: boolean | null | undefined
117
132
  /** Key identifier. */
118
133
  keyId: Address.Address
@@ -712,7 +727,9 @@ export function fromTuple<const tuple extends Tuple>(
712
727
  const isAdmin = (() => {
713
728
  if (isAbsent(rawIsAdmin)) return undefined
714
729
  // TIP-1049: the admin marker is strictly `0x01`. Any other value is a
715
- // protocol-level decode error on the node, so reject it here too.
730
+ // protocol-level decode error on the node, so reject it here too. T14
731
+ // (TIP-1137) rejects admin authorizations at validation, not decoding,
732
+ // so pre-T14 history still decodes.
716
733
  if (rawIsAdmin !== '0x01')
717
734
  throw new InvalidAdminMarkerError(rawIsAdmin as Hex.Hex)
718
735
  return true
@@ -1140,8 +1157,9 @@ export function toTuple<const authorization extends KeyAuthorization>(
1140
1157
  { value: witness, placeholder: '0x' },
1141
1158
  // TIP-1049: admin marker. Present = `0x01` (RLP integer 1); absent
1142
1159
  // skipped or omitted. Any other value is a hard decode error on the node.
1160
+ // TIP-1137 keeps this encoding but rejects `0x01` from T14.
1143
1161
  { value: isAdmin ? '0x01' : undefined, placeholder: '0x' },
1144
- // TIP-1049: optional account binding. Last field — never a placeholder.
1162
+ // Optional account binding. Last field — never a placeholder.
1145
1163
  { value: account, placeholder: '0x' },
1146
1164
  ]
1147
1165
  let lastPresent = -1
@@ -1245,8 +1263,8 @@ export class InvalidSignatureTypeError extends Error {
1245
1263
  /**
1246
1264
  * Thrown when a configurable account key grant omits its parent account binding.
1247
1265
  *
1248
- * @deprecated No longer thrown. The Tempo node only requires `account` on grants
1249
- * signed by an admin access key, which it checks against the transaction sender.
1266
+ * @deprecated No longer thrown. The Tempo node does not require `account`; when
1267
+ * present, it must equal the transaction sender.
1250
1268
  */
1251
1269
  export class MissingAccountError extends Error {
1252
1270
  override readonly name = 'KeyAuthorization.MissingAccountError'
@@ -1059,6 +1059,18 @@ describe('from', () => {
1059
1059
  expect(envelope.type).toBe('keychain')
1060
1060
  })
1061
1061
 
1062
+ test('behavior: defaults version to v2', () => {
1063
+ const envelope = SignatureEnvelope.from({
1064
+ inner: SignatureEnvelope.from(signature_secp256k1),
1065
+ userAddress: '0x1234567890123456789012345678901234567890',
1066
+ })
1067
+
1068
+ expect(envelope).toMatchObject({ version: 'v2' })
1069
+ expect(
1070
+ Hex.slice(SignatureEnvelope.serialize(envelope), 0, 1),
1071
+ ).toMatchInlineSnapshot(`"0x04"`)
1072
+ })
1073
+
1062
1074
  test('behavior: computes keyId from p256 inner publicKey', () => {
1063
1075
  const envelope = SignatureEnvelope.from({
1064
1076
  userAddress: '0x1234567890123456789012345678901234567890',
@@ -110,7 +110,7 @@ export type GetType<
110
110
  *
111
111
  * - **keychain** (type `0x03` V1, `0x04` V2): Access key signature that wraps an inner signature
112
112
  * (secp256k1, p256, or webAuthn). Format: type byte + user_address (20 bytes) + inner signature.
113
- * V2 binds the signature to the user account via `keccak256(sigHash || userAddress)`.
113
+ * V2 binds the signature to the user account via `keccak256(0x04 || sigHash || userAddress)`.
114
114
  * The protocol validates the access key authorization via the AccountKeychain precompile.
115
115
  *
116
116
  * - **configurable** (type `0x05`): Configurable account signature carrying the account address,
@@ -145,8 +145,8 @@ export type PrimitiveRpc = OneOf<Secp256k1Rpc | P256Rpc | WebAuthnRpc>
145
145
  * Keychain signature version.
146
146
  *
147
147
  * - `'v1'`: Legacy format. Inner signature signs the raw `sig_hash` directly. Deprecated at T1C.
148
- * - `'v2'`: Inner signature signs `keccak256(sig_hash || user_address)`, binding the signature
149
- * to the specific user account.
148
+ * - `'v2'`: Inner signature signs `keccak256(0x04 || sig_hash || user_address)`, binding the
149
+ * signature to the specific user account.
150
150
  */
151
151
  export type KeychainVersion = 'v1' | 'v2'
152
152
 
@@ -158,7 +158,7 @@ export type Keychain<numberType = number> = {
158
158
  type: 'keychain'
159
159
  /** Root account address that this transaction is being executed for */
160
160
  userAddress: Address.Address
161
- /** Keychain signature version. @default 'v1' */
161
+ /** Keychain signature version. @default 'v2' */
162
162
  version?: KeychainVersion | undefined
163
163
  }
164
164
 
@@ -115,6 +115,16 @@ describe('fromPrice', () => {
115
115
  expect(Tick.fromPrice(' 1.0 ')).toBe(0)
116
116
  expect(Tick.fromPrice(' 1.001 ')).toBe(100)
117
117
  })
118
+
119
+ test('throws error when price is negative', () => {
120
+ expect(() => Tick.fromPrice('-0.999')).toThrowErrorMatchingInlineSnapshot(`
121
+ [Tick.PriceOutOfBoundsError: Price "-0.999" results in tick -199900 which is out of bounds.
122
+
123
+ Tick must be between -2000 and 2000.]
124
+ `)
125
+ expect(() => Tick.fromPrice('-0.98')).toThrow(Tick.PriceOutOfBoundsError)
126
+ expect(() => Tick.fromPrice('-0.99999')).toThrow(Tick.PriceOutOfBoundsError)
127
+ })
118
128
  })
119
129
 
120
130
  describe('round-trip conversions', () => {
package/src/tempo/Tick.ts CHANGED
@@ -101,14 +101,16 @@ export function fromPrice(price: fromPrice.Price): fromPrice.ReturnType {
101
101
  throw new InvalidPriceFormatError({ price })
102
102
 
103
103
  // Parse price using string manipulation to avoid float precision issues
104
- const [w, d = '0'] = priceStr.split('.')
104
+ const negative = priceStr.startsWith('-')
105
+ const [w, d = '0'] = (negative ? priceStr.slice(1) : priceStr).split('.')
105
106
  const whole = BigInt(w!)
106
107
 
107
108
  // Pad or truncate decimal to exactly 5 digits
108
109
  const decimal = BigInt(d.padEnd(5, '0').slice(0, 5))
109
110
 
110
- // Calculate price
111
- const priceInt = whole * BigInt(priceScale) + decimal
111
+ // Calculate price, applying the sign last since `BigInt('-0')` is `0n`
112
+ const priceInt =
113
+ (negative ? -1n : 1n) * (whole * BigInt(priceScale) + decimal)
112
114
 
113
115
  // Calculate tick
114
116
  const tick = Number(priceInt - BigInt(priceScale))
@@ -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,19 @@ 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
+
141
167
  test('fee payer', () => {
142
168
  const serialized = TxEnvelopeTempo.serialize(transaction, {
143
169
  format: 'feePayer',
@@ -214,8 +214,8 @@ export function assert(envelope: PartialBy<TxEnvelopeTempo, 'type'>) {
214
214
  })
215
215
 
216
216
  if (
217
- maxPriorityFeePerGas &&
218
- maxFeePerGas &&
217
+ typeof maxPriorityFeePerGas === 'bigint' &&
218
+ typeof maxFeePerGas === 'bigint' &&
219
219
  maxPriorityFeePerGas > maxFeePerGas
220
220
  )
221
221
  throw new TransactionEnvelope.TipAboveFeeCapError({
@@ -335,6 +335,12 @@ export function deserialize(serialized: Serialized): Compute<TxEnvelopeTempo> {
335
335
  transaction.maxFeePerGas = BigInt(maxFeePerGas)
336
336
  if (Hex.validate(maxPriorityFeePerGas) && maxPriorityFeePerGas !== '0x')
337
337
  transaction.maxPriorityFeePerGas = BigInt(maxPriorityFeePerGas)
338
+ // An empty `maxFeePerGas` encodes zero, so a tip above it is rejected.
339
+ if (
340
+ transaction.maxPriorityFeePerGas &&
341
+ typeof transaction.maxFeePerGas === 'undefined'
342
+ )
343
+ transaction.maxFeePerGas = 0n
338
344
  if (Hex.validate(nonceKey))
339
345
  transaction.nonceKey = nonceKey === '0x' ? 0n : BigInt(nonceKey)
340
346
  if (Hex.validate(validBefore) && validBefore !== '0x')
@@ -2807,14 +2807,10 @@ describe('behavior: keyAuthorization', () => {
2807
2807
  },
2808
2808
  )
2809
2809
 
2810
- // TIP-1049 admin keys are not yet in any released tempo tag (only on
2811
- // `main` via PR #4265). CI runs the localnet job against the `edge`
2812
- // image which tracks main; devnet/testnet still ship the older
2813
- // release and would reject the 9-field wire format with
2814
- // `failed to decode signed transaction`.
2815
- // TODO: remove skipIf when devnet/testnet have T6 (TIP-1049).
2810
+ // TIP-1137 removes TIP-1049 admin keys at T14. The localnet job runs the
2811
+ // `edge` image, which has T14 active; devnet/testnet may not.
2816
2812
  test.skipIf(nodeEnv !== 'localnet')(
2817
- 'behavior: TIP-1049 admin access key round-trips through registration',
2813
+ 'behavior: TIP-1137 rejects an admin key authorization',
2818
2814
  async () => {
2819
2815
  const accessPrivateKey = Secp256k1.randomPrivateKey()
2820
2816
  const accessAddress = Address.fromPublicKey(
@@ -2822,8 +2818,8 @@ describe('behavior: keyAuthorization', () => {
2822
2818
  )
2823
2819
 
2824
2820
  const keyAuth = KeyAuthorization.from({
2825
- address: accessAddress,
2826
2821
  account: root.address,
2822
+ address: accessAddress,
2827
2823
  chainId: BigInt(chainId),
2828
2824
  isAdmin: true,
2829
2825
  type: 'secp256k1',
@@ -2847,15 +2843,79 @@ describe('behavior: keyAuthorization', () => {
2847
2843
  calls: [{ to: '0x0000000000000000000000000000000000000000' }],
2848
2844
  chainId,
2849
2845
  feeToken: '0x20c0000000000000000000000000000000000001',
2846
+ gas: 1_000_000n,
2850
2847
  keyAuthorization: keyAuth_signed,
2848
+ maxFeePerGas: Value.fromGwei('20'),
2849
+ maxPriorityFeePerGas: Value.fromGwei('10'),
2851
2850
  nonce: BigInt(nonce),
2851
+ })
2852
+
2853
+ const signature = Secp256k1.sign({
2854
+ payload: TxEnvelopeTempo.getSignPayload(transaction, {
2855
+ from: root.address,
2856
+ }),
2857
+ privateKey: accessPrivateKey,
2858
+ })
2859
+
2860
+ const serialized_signed = TxEnvelopeTempo.serialize(transaction, {
2861
+ signature: SignatureEnvelope.from({
2862
+ inner: SignatureEnvelope.from(signature),
2863
+ type: 'keychain',
2864
+ userAddress: root.address,
2865
+ }),
2866
+ })
2867
+
2868
+ // From T14 no path can set `is_admin = true`.
2869
+ await expect(
2870
+ client.request({
2871
+ method: 'eth_sendRawTransactionSync',
2872
+ params: [serialized_signed],
2873
+ }),
2874
+ ).rejects.toThrow('InvalidKeyId')
2875
+ },
2876
+ )
2877
+
2878
+ test.skipIf(nodeEnv !== 'localnet')(
2879
+ 'behavior: account-bound key authorization round-trips through registration',
2880
+ async () => {
2881
+ const accessPrivateKey = Secp256k1.randomPrivateKey()
2882
+ const accessAddress = Address.fromPublicKey(
2883
+ Secp256k1.getPublicKey({ privateKey: accessPrivateKey }),
2884
+ )
2885
+
2886
+ // From T14 an `account` binding must equal the transaction sender.
2887
+ const keyAuth = KeyAuthorization.from({
2888
+ account: root.address,
2889
+ address: accessAddress,
2890
+ chainId: BigInt(chainId),
2891
+ type: 'secp256k1',
2892
+ })
2893
+
2894
+ const keyAuth_signed = KeyAuthorization.from(keyAuth, {
2895
+ signature: SignatureEnvelope.from(
2896
+ Secp256k1.sign({
2897
+ payload: KeyAuthorization.getSignPayload(keyAuth),
2898
+ privateKey: root.privateKey,
2899
+ }),
2900
+ ),
2901
+ })
2902
+
2903
+ const nonce = await getTransactionCount(client, {
2904
+ address: root.address,
2905
+ blockTag: 'pending',
2906
+ })
2907
+
2908
+ const transaction = TxEnvelopeTempo.from({
2909
+ calls: [{ to: '0x0000000000000000000000000000000000000000' }],
2910
+ chainId,
2911
+ feeToken: '0x20c0000000000000000000000000000000000001',
2852
2912
  gas: 1_000_000n,
2913
+ keyAuthorization: keyAuth_signed,
2853
2914
  maxFeePerGas: Value.fromGwei('20'),
2854
2915
  maxPriorityFeePerGas: Value.fromGwei('10'),
2916
+ nonce: BigInt(nonce),
2855
2917
  })
2856
2918
 
2857
- // The admin access key signs and authorizes itself in the same tx
2858
- // (the canonical "auth+use" registration pattern).
2859
2919
  const signature = Secp256k1.sign({
2860
2920
  payload: TxEnvelopeTempo.getSignPayload(transaction, {
2861
2921
  from: root.address,
@@ -2865,9 +2925,9 @@ describe('behavior: keyAuthorization', () => {
2865
2925
 
2866
2926
  const serialized_signed = TxEnvelopeTempo.serialize(transaction, {
2867
2927
  signature: SignatureEnvelope.from({
2868
- userAddress: root.address,
2869
2928
  inner: SignatureEnvelope.from(signature),
2870
2929
  type: 'keychain',
2930
+ userAddress: root.address,
2871
2931
  }),
2872
2932
  })
2873
2933
 
@@ -2887,12 +2947,8 @@ describe('behavior: keyAuthorization', () => {
2887
2947
  .then((tx) => Transaction.fromRpc(tx as any))
2888
2948
  if (!response) throw new Error()
2889
2949
 
2890
- // isAdmin + account must survive the round trip through the node.
2891
- expect(response.keyAuthorization?.isAdmin).toBe(true)
2950
+ expect(response.keyAuthorization?.isAdmin).toBeUndefined()
2892
2951
  expect(response.keyAuthorization?.account).toBe(root.address)
2893
-
2894
- // The signing hash of the round-tripped authorization equals the
2895
- // admin-bearing hash.
2896
2952
  expect(KeyAuthorization.hash(response.keyAuthorization!)).toBe(
2897
2953
  KeyAuthorization.hash(keyAuth_signed),
2898
2954
  )
@@ -2901,7 +2957,7 @@ describe('behavior: keyAuthorization', () => {
2901
2957
 
2902
2958
  // TODO: remove skipIf when devnet/testnet have T6.
2903
2959
  test.skipIf(nodeEnv !== 'localnet')(
2904
- 'behavior: TIP-1049 non-admin authorization is byte-equivalent to pre-TIP-1049',
2960
+ 'behavior: unbound authorization is byte-equivalent to pre-TIP-1049',
2905
2961
  async () => {
2906
2962
  const accessPrivateKey = Secp256k1.randomPrivateKey()
2907
2963
  const accessAddress = Address.fromPublicKey(
package/src/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  /** @internal */
2
- export const version = '1.8.12'
2
+ export const version = '1.8.14'
@@ -1,9 +1,9 @@
1
1
  /* eslint-disable jsdoc-js/require-jsdoc, jsdoc-js/require-description, jsdoc-js/require-example */
2
2
  import * as z from 'zod/mini'
3
3
 
4
+ const addressRegex = /^0x[0-9a-fA-F]{40}$/
5
+
4
6
  /** Address schema. */
5
7
  export const Address = z
6
8
  .templateLiteral([z.literal('0x'), z.string()])
7
- .check(
8
- z.refine((value) => /^0x[0-9a-fA-F]{40}$/.test(value), 'expected address'),
9
- )
9
+ .check(z.refine((value) => addressRegex.test(value), 'expected address'))