ox 0.14.62 → 0.14.64

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 (121) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/_cjs/core/AbiError.js +6 -2
  3. package/_cjs/core/AbiError.js.map +1 -1
  4. package/_cjs/core/AbiEvent.js +4 -0
  5. package/_cjs/core/AbiEvent.js.map +1 -1
  6. package/_cjs/core/AbiFunction.js +2 -2
  7. package/_cjs/core/AbiFunction.js.map +1 -1
  8. package/_cjs/core/AbiItem.js +6 -7
  9. package/_cjs/core/AbiItem.js.map +1 -1
  10. package/_cjs/core/Base32.js +15 -1
  11. package/_cjs/core/Base32.js.map +1 -1
  12. package/_cjs/core/Bytes.js +4 -5
  13. package/_cjs/core/Bytes.js.map +1 -1
  14. package/_cjs/core/Cbor.js +13 -2
  15. package/_cjs/core/Cbor.js.map +1 -1
  16. package/_cjs/core/Hex.js +2 -3
  17. package/_cjs/core/Hex.js.map +1 -1
  18. package/_cjs/core/Rlp.js +49 -8
  19. package/_cjs/core/Rlp.js.map +1 -1
  20. package/_cjs/core/RpcTransport.js +9 -4
  21. package/_cjs/core/RpcTransport.js.map +1 -1
  22. package/_cjs/core/Siwe.js +4 -0
  23. package/_cjs/core/Siwe.js.map +1 -1
  24. package/_cjs/core/TypedData.js +2 -2
  25. package/_cjs/core/TypedData.js.map +1 -1
  26. package/_cjs/core/internal/abiItem.js +1 -1
  27. package/_cjs/core/internal/abiItem.js.map +1 -1
  28. package/_cjs/erc4337/UserOperation.js +7 -4
  29. package/_cjs/erc4337/UserOperation.js.map +1 -1
  30. package/_cjs/erc8021/Attribution.js +13 -3
  31. package/_cjs/erc8021/Attribution.js.map +1 -1
  32. package/_cjs/tempo/AccountOperation.js +26 -6
  33. package/_cjs/tempo/AccountOperation.js.map +1 -1
  34. package/_cjs/tempo/Tick.js +3 -2
  35. package/_cjs/tempo/Tick.js.map +1 -1
  36. package/_cjs/version.js +1 -1
  37. package/_esm/core/AbiError.js +6 -2
  38. package/_esm/core/AbiError.js.map +1 -1
  39. package/_esm/core/AbiEvent.js +5 -0
  40. package/_esm/core/AbiEvent.js.map +1 -1
  41. package/_esm/core/AbiFunction.js +2 -2
  42. package/_esm/core/AbiFunction.js.map +1 -1
  43. package/_esm/core/AbiItem.js +8 -7
  44. package/_esm/core/AbiItem.js.map +1 -1
  45. package/_esm/core/Base32.js +17 -2
  46. package/_esm/core/Base32.js.map +1 -1
  47. package/_esm/core/Bytes.js +4 -5
  48. package/_esm/core/Bytes.js.map +1 -1
  49. package/_esm/core/Cbor.js +16 -2
  50. package/_esm/core/Cbor.js.map +1 -1
  51. package/_esm/core/Hex.js +3 -3
  52. package/_esm/core/Hex.js.map +1 -1
  53. package/_esm/core/Rlp.js +56 -8
  54. package/_esm/core/Rlp.js.map +1 -1
  55. package/_esm/core/RpcTransport.js +12 -4
  56. package/_esm/core/RpcTransport.js.map +1 -1
  57. package/_esm/core/Siwe.js +5 -0
  58. package/_esm/core/Siwe.js.map +1 -1
  59. package/_esm/core/TypedData.js +7 -6
  60. package/_esm/core/TypedData.js.map +1 -1
  61. package/_esm/core/internal/abiItem.js +2 -1
  62. package/_esm/core/internal/abiItem.js.map +1 -1
  63. package/_esm/erc4337/UserOperation.js +10 -4
  64. package/_esm/erc4337/UserOperation.js.map +1 -1
  65. package/_esm/erc8021/Attribution.js +15 -3
  66. package/_esm/erc8021/Attribution.js.map +1 -1
  67. package/_esm/tempo/AccountOperation.js +26 -6
  68. package/_esm/tempo/AccountOperation.js.map +1 -1
  69. package/_esm/tempo/Tick.js +4 -3
  70. package/_esm/tempo/Tick.js.map +1 -1
  71. package/_esm/version.js +1 -1
  72. package/_types/core/AbiError.d.ts +2 -2
  73. package/_types/core/AbiError.d.ts.map +1 -1
  74. package/_types/core/AbiEvent.d.ts.map +1 -1
  75. package/_types/core/AbiFunction.d.ts +1 -1
  76. package/_types/core/AbiFunction.d.ts.map +1 -1
  77. package/_types/core/AbiItem.d.ts.map +1 -1
  78. package/_types/core/Base32.d.ts +8 -3
  79. package/_types/core/Base32.d.ts.map +1 -1
  80. package/_types/core/Bytes.d.ts.map +1 -1
  81. package/_types/core/Cbor.d.ts.map +1 -1
  82. package/_types/core/Hex.d.ts.map +1 -1
  83. package/_types/core/Rlp.d.ts +9 -2
  84. package/_types/core/Rlp.d.ts.map +1 -1
  85. package/_types/core/RpcTransport.d.ts.map +1 -1
  86. package/_types/core/Siwe.d.ts.map +1 -1
  87. package/_types/core/internal/abiItem.d.ts +3 -1
  88. package/_types/core/internal/abiItem.d.ts.map +1 -1
  89. package/_types/erc4337/UserOperation.d.ts +20 -2
  90. package/_types/erc4337/UserOperation.d.ts.map +1 -1
  91. package/_types/erc8021/Attribution.d.ts.map +1 -1
  92. package/_types/package.json +1 -0
  93. package/_types/tempo/AccountOperation.d.ts +8 -0
  94. package/_types/tempo/AccountOperation.d.ts.map +1 -1
  95. package/_types/tempo/SignatureEnvelope.d.ts +4 -4
  96. package/_types/tempo/Tick.d.ts.map +1 -1
  97. package/_types/version.d.ts +1 -1
  98. package/core/AbiError.ts +33 -22
  99. package/core/AbiEvent.ts +7 -0
  100. package/core/AbiFunction.ts +7 -5
  101. package/core/AbiItem.ts +8 -7
  102. package/core/Base32.ts +17 -3
  103. package/core/Bytes.ts +3 -5
  104. package/core/Cbor.ts +20 -2
  105. package/core/Hex.ts +4 -4
  106. package/core/Rlp.ts +55 -5
  107. package/core/RpcTransport.ts +12 -4
  108. package/core/Siwe.ts +5 -0
  109. package/core/TypedData.ts +7 -6
  110. package/core/internal/abiItem.ts +13 -2
  111. package/erc4337/UserOperation.ts +37 -3
  112. package/erc8021/Attribution.ts +11 -7
  113. package/package.json +1 -1
  114. package/tempo/AccountOperation.test.ts +116 -0
  115. package/tempo/AccountOperation.ts +38 -5
  116. package/tempo/AccountSimulation.test.ts +1 -1
  117. package/tempo/SignatureEnvelope.test.ts +12 -0
  118. package/tempo/SignatureEnvelope.ts +4 -4
  119. package/tempo/Tick.test.ts +10 -0
  120. package/tempo/Tick.ts +5 -3
  121. package/version.ts +1 -1
@@ -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. */
@@ -96,6 +102,7 @@ export function getHash(options: getHash.Options): Hex.Hex {
96
102
  TxEnvelopeTempo.deserialize(
97
103
  options.transaction as TxEnvelopeTempo.Serialized,
98
104
  ),
105
+ { from: options.userAddress },
99
106
  )
100
107
  : KeyAuthorization_.getSignPayload(
101
108
  KeyAuthorization_.deserialize(options.keyAuthorization),
@@ -126,6 +133,8 @@ export declare namespace getHash {
126
133
  transaction: Hex.Hex
127
134
  /** Operation kind. */
128
135
  type: 'transaction'
136
+ /** Parent account when the configurable account signs as its access key. */
137
+ userAddress?: Address.Address | undefined
129
138
  }
130
139
  )
131
140
 
@@ -331,17 +340,26 @@ export function serializeTransaction(
331
340
  assertApproval(value.account, approval, value.config),
332
341
  )
333
342
  assertRetainedApprovals(value, approvals)
343
+ const { userAddress } = value
334
344
  const signatures = SignatureEnvelope.sortApprovals({
335
345
  account: value.account,
336
346
  config: value.config,
337
- payload: TxEnvelopeTempo.getSignPayload(envelope),
347
+ payload: TxEnvelopeTempo.getSignPayload(envelope, { from: userAddress }),
338
348
  signatures: approvals,
339
349
  })
340
- const signature = SignatureEnvelope.from({
350
+ const configurable = SignatureEnvelope.from({
341
351
  account: value.account,
342
352
  config: value.config,
343
353
  signatures,
344
354
  })
355
+ const signature = userAddress
356
+ ? SignatureEnvelope.from({
357
+ inner: configurable,
358
+ type: 'keychain',
359
+ userAddress,
360
+ version: 'v2',
361
+ })
362
+ : configurable
345
363
  return TxEnvelopeTempo.serialize(
346
364
  envelope,
347
365
  value.transaction.startsWith(TxEnvelopeTempo.feePayerMagic)
@@ -803,14 +821,27 @@ function assertTransaction(operation: TransactionOperation): void {
803
821
  throw new InvalidOperationError({
804
822
  reason: 'transaction must not contain an outer sender signature',
805
823
  })
824
+ const { userAddress } = operation
825
+ if (userAddress !== undefined) {
826
+ if (!Address.validate(userAddress) || Hex.toBigInt(userAddress) === 0n)
827
+ throw new InvalidOperationError({ reason: 'userAddress is invalid' })
828
+ if (userAddress.toLowerCase() === operation.account.toLowerCase())
829
+ throw new InvalidOperationError({
830
+ reason: 'a configurable account cannot be its own access key',
831
+ })
832
+ }
833
+ const sender = userAddress ?? operation.account
806
834
  if (
807
835
  transaction.from &&
808
- transaction.from.toLowerCase() !== operation.account.toLowerCase()
836
+ transaction.from.toLowerCase() !== sender.toLowerCase()
809
837
  )
810
838
  throw new InvalidOperationError({
811
839
  reason: 'transaction sender does not match the operation account',
812
840
  })
813
- assertOperationHash(operation, TxEnvelopeTempo.getSignPayload(transaction))
841
+ assertOperationHash(
842
+ operation,
843
+ TxEnvelopeTempo.getSignPayload(transaction, { from: userAddress }),
844
+ )
814
845
  const feePayer = operation.transaction.startsWith(
815
846
  TxEnvelopeTempo.feePayerMagic,
816
847
  )
@@ -842,12 +873,14 @@ function assertKeyAuthorization(
842
873
  submissionId?: unknown
843
874
  transaction?: unknown
844
875
  transactionHash?: unknown
876
+ userAddress?: unknown
845
877
  }
846
878
  if (
847
879
  transactionFields.expiresAt !== undefined ||
848
880
  transactionFields.submissionId !== undefined ||
849
881
  transactionFields.transaction !== undefined ||
850
- transactionFields.transactionHash !== undefined
882
+ transactionFields.transactionHash !== undefined ||
883
+ transactionFields.userAddress !== undefined
851
884
  )
852
885
  throw new InvalidOperationError({
853
886
  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
  })
@@ -1043,6 +1043,18 @@ describe('from', () => {
1043
1043
  expect(envelope.type).toBe('keychain')
1044
1044
  })
1045
1045
 
1046
+ test('behavior: defaults version to v2', () => {
1047
+ const envelope = SignatureEnvelope.from({
1048
+ inner: SignatureEnvelope.from(signature_secp256k1),
1049
+ userAddress: '0x1234567890123456789012345678901234567890',
1050
+ })
1051
+
1052
+ expect(envelope).toMatchObject({ version: 'v2' })
1053
+ expect(
1054
+ Hex.slice(SignatureEnvelope.serialize(envelope), 0, 1),
1055
+ ).toMatchInlineSnapshot(`"0x04"`)
1056
+ })
1057
+
1046
1058
  test('behavior: computes keyId from p256 inner publicKey', () => {
1047
1059
  const envelope = SignatureEnvelope.from({
1048
1060
  userAddress: '0x1234567890123456789012345678901234567890',
@@ -139,7 +139,7 @@ export type GetType<
139
139
  *
140
140
  * - **keychain** (type `0x03` V1, `0x04` V2): Access key signature that wraps an inner signature
141
141
  * (secp256k1, p256, or webAuthn). Format: type byte + user_address (20 bytes) + inner signature.
142
- * V2 binds the signature to the user account via `keccak256(sigHash || userAddress)`.
142
+ * V2 binds the signature to the user account via `keccak256(0x04 || sigHash || userAddress)`.
143
143
  * The protocol validates the access key authorization via the AccountKeychain precompile.
144
144
  *
145
145
  * - **configurable** (type `0x05`): Configurable account signature carrying the account address,
@@ -181,8 +181,8 @@ export type PrimitiveRpc = OneOf<Secp256k1Rpc | P256Rpc | WebAuthnRpc>
181
181
  * Keychain signature version.
182
182
  *
183
183
  * - `'v1'`: Legacy format. Inner signature signs the raw `sig_hash` directly. Deprecated at T1C.
184
- * - `'v2'`: Inner signature signs `keccak256(sig_hash || user_address)`, binding the signature
185
- * to the specific user account.
184
+ * - `'v2'`: Inner signature signs `keccak256(0x04 || sig_hash || user_address)`, binding the
185
+ * signature to the specific user account.
186
186
  */
187
187
  export type KeychainVersion = 'v1' | 'v2'
188
188
 
@@ -194,7 +194,7 @@ export type Keychain<bigintType = bigint, numberType = number> = {
194
194
  type: 'keychain'
195
195
  /** Root account address that this transaction is being executed for */
196
196
  userAddress: Address.Address
197
- /** Keychain signature version. @default 'v1' */
197
+ /** Keychain signature version. @default 'v2' */
198
198
  version?: KeychainVersion | undefined
199
199
  }
200
200
 
@@ -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/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))
package/version.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  /** @internal */
2
- export const version = '0.14.62'
2
+ export const version = '0.14.64'