ox 0.14.65 → 0.14.67

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 (173) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/_cjs/core/AbiError.js +25 -4
  3. package/_cjs/core/AbiError.js.map +1 -1
  4. package/_cjs/core/AbiEvent.js +18 -3
  5. package/_cjs/core/AbiEvent.js.map +1 -1
  6. package/_cjs/core/AbiFunction.js +27 -3
  7. package/_cjs/core/AbiFunction.js.map +1 -1
  8. package/_cjs/core/Address.js +1 -0
  9. package/_cjs/core/Address.js.map +1 -1
  10. package/_cjs/core/Authorization.js +29 -2
  11. package/_cjs/core/Authorization.js.map +1 -1
  12. package/_cjs/core/Keystore.js +18 -0
  13. package/_cjs/core/Keystore.js.map +1 -1
  14. package/_cjs/core/Secp256k1.js +5 -1
  15. package/_cjs/core/Secp256k1.js.map +1 -1
  16. package/_cjs/core/Signature.js +4 -2
  17. package/_cjs/core/Signature.js.map +1 -1
  18. package/_cjs/core/Siwe.js +22 -3
  19. package/_cjs/core/Siwe.js.map +1 -1
  20. package/_cjs/core/TxEnvelopeEip1559.js +2 -1
  21. package/_cjs/core/TxEnvelopeEip1559.js.map +1 -1
  22. package/_cjs/core/TxEnvelopeEip2930.js +2 -1
  23. package/_cjs/core/TxEnvelopeEip2930.js.map +1 -1
  24. package/_cjs/core/TxEnvelopeEip7702.js +5 -1
  25. package/_cjs/core/TxEnvelopeEip7702.js.map +1 -1
  26. package/_cjs/core/TxEnvelopeLegacy.js +41 -8
  27. package/_cjs/core/TxEnvelopeLegacy.js.map +1 -1
  28. package/_cjs/core/TypedData.js +7 -9
  29. package/_cjs/core/TypedData.js.map +1 -1
  30. package/_cjs/core/Value.js +8 -3
  31. package/_cjs/core/Value.js.map +1 -1
  32. package/_cjs/core/internal/abiParameters.js +6 -2
  33. package/_cjs/core/internal/abiParameters.js.map +1 -1
  34. package/_cjs/core/internal/cursor.js +30 -1
  35. package/_cjs/core/internal/cursor.js.map +1 -1
  36. package/_cjs/erc4337/UserOperation.js +1 -1
  37. package/_cjs/erc4337/UserOperation.js.map +1 -1
  38. package/_cjs/erc7821/Execute.js +41 -3
  39. package/_cjs/erc7821/Execute.js.map +1 -1
  40. package/_cjs/tempo/KeyAuthorization.js +22 -1
  41. package/_cjs/tempo/KeyAuthorization.js.map +1 -1
  42. package/_cjs/tempo/SignatureEnvelope.js +44 -50
  43. package/_cjs/tempo/SignatureEnvelope.js.map +1 -1
  44. package/_cjs/tempo/TxEnvelopeTempo.js +34 -3
  45. package/_cjs/tempo/TxEnvelopeTempo.js.map +1 -1
  46. package/_cjs/tempo/internal/webauthnData.js +57 -0
  47. package/_cjs/tempo/internal/webauthnData.js.map +1 -0
  48. package/_cjs/version.js +1 -1
  49. package/_cjs/webauthn/Registration.js +2 -6
  50. package/_cjs/webauthn/Registration.js.map +1 -1
  51. package/_esm/core/AbiError.js +64 -3
  52. package/_esm/core/AbiError.js.map +1 -1
  53. package/_esm/core/AbiEvent.js +24 -3
  54. package/_esm/core/AbiEvent.js.map +1 -1
  55. package/_esm/core/AbiFunction.js +64 -3
  56. package/_esm/core/AbiFunction.js.map +1 -1
  57. package/_esm/core/Address.js +17 -1
  58. package/_esm/core/Address.js.map +1 -1
  59. package/_esm/core/Authorization.js +47 -2
  60. package/_esm/core/Authorization.js.map +1 -1
  61. package/_esm/core/Keystore.js +33 -2
  62. package/_esm/core/Keystore.js.map +1 -1
  63. package/_esm/core/Secp256k1.js +5 -1
  64. package/_esm/core/Secp256k1.js.map +1 -1
  65. package/_esm/core/Signature.js +4 -2
  66. package/_esm/core/Signature.js.map +1 -1
  67. package/_esm/core/Siwe.js +29 -3
  68. package/_esm/core/Siwe.js.map +1 -1
  69. package/_esm/core/TxEnvelopeEip1559.js +2 -1
  70. package/_esm/core/TxEnvelopeEip1559.js.map +1 -1
  71. package/_esm/core/TxEnvelopeEip2930.js +2 -1
  72. package/_esm/core/TxEnvelopeEip2930.js.map +1 -1
  73. package/_esm/core/TxEnvelopeEip7702.js +6 -1
  74. package/_esm/core/TxEnvelopeEip7702.js.map +1 -1
  75. package/_esm/core/TxEnvelopeLegacy.js +49 -9
  76. package/_esm/core/TxEnvelopeLegacy.js.map +1 -1
  77. package/_esm/core/TypedData.js +9 -9
  78. package/_esm/core/TypedData.js.map +1 -1
  79. package/_esm/core/Value.js +14 -3
  80. package/_esm/core/Value.js.map +1 -1
  81. package/_esm/core/internal/abiParameters.js +9 -2
  82. package/_esm/core/internal/abiParameters.js.map +1 -1
  83. package/_esm/core/internal/cursor.js +32 -0
  84. package/_esm/core/internal/cursor.js.map +1 -1
  85. package/_esm/erc4337/UserOperation.js +1 -1
  86. package/_esm/erc4337/UserOperation.js.map +1 -1
  87. package/_esm/erc7821/Execute.js +76 -2
  88. package/_esm/erc7821/Execute.js.map +1 -1
  89. package/_esm/index.js +1 -1
  90. package/_esm/tempo/KeyAuthorization.js +21 -0
  91. package/_esm/tempo/KeyAuthorization.js.map +1 -1
  92. package/_esm/tempo/SignatureEnvelope.js +53 -54
  93. package/_esm/tempo/SignatureEnvelope.js.map +1 -1
  94. package/_esm/tempo/TxEnvelopeTempo.js +56 -2
  95. package/_esm/tempo/TxEnvelopeTempo.js.map +1 -1
  96. package/_esm/tempo/internal/webauthnData.js +79 -0
  97. package/_esm/tempo/internal/webauthnData.js.map +1 -0
  98. package/_esm/version.js +1 -1
  99. package/_esm/webauthn/Registration.js +2 -6
  100. package/_esm/webauthn/Registration.js.map +1 -1
  101. package/_types/core/AbiError.d.ts +51 -5
  102. package/_types/core/AbiError.d.ts.map +1 -1
  103. package/_types/core/AbiEvent.d.ts +4 -2
  104. package/_types/core/AbiEvent.d.ts.map +1 -1
  105. package/_types/core/AbiFunction.d.ts +48 -2
  106. package/_types/core/AbiFunction.d.ts.map +1 -1
  107. package/_types/core/Address.d.ts +17 -2
  108. package/_types/core/Address.d.ts.map +1 -1
  109. package/_types/core/Authorization.d.ts +24 -2
  110. package/_types/core/Authorization.d.ts.map +1 -1
  111. package/_types/core/Keystore.d.ts +31 -2
  112. package/_types/core/Keystore.d.ts.map +1 -1
  113. package/_types/core/Secp256k1.d.ts.map +1 -1
  114. package/_types/core/Signature.d.ts +1 -1
  115. package/_types/core/Signature.d.ts.map +1 -1
  116. package/_types/core/Siwe.d.ts +4 -0
  117. package/_types/core/Siwe.d.ts.map +1 -1
  118. package/_types/core/TxEnvelopeEip1559.d.ts.map +1 -1
  119. package/_types/core/TxEnvelopeEip2930.d.ts.map +1 -1
  120. package/_types/core/TxEnvelopeEip7702.d.ts +1 -1
  121. package/_types/core/TxEnvelopeEip7702.d.ts.map +1 -1
  122. package/_types/core/TxEnvelopeLegacy.d.ts.map +1 -1
  123. package/_types/core/TypedData.d.ts +3 -1
  124. package/_types/core/TypedData.d.ts.map +1 -1
  125. package/_types/core/Value.d.ts.map +1 -1
  126. package/_types/core/internal/abiParameters.d.ts +1 -1
  127. package/_types/core/internal/abiParameters.d.ts.map +1 -1
  128. package/_types/core/internal/cursor.d.ts +13 -0
  129. package/_types/core/internal/cursor.d.ts.map +1 -1
  130. package/_types/erc7821/Execute.d.ts +46 -1
  131. package/_types/erc7821/Execute.d.ts.map +1 -1
  132. package/_types/index.d.ts +1 -1
  133. package/_types/tempo/KeyAuthorization.d.ts +9 -3
  134. package/_types/tempo/KeyAuthorization.d.ts.map +1 -1
  135. package/_types/tempo/SignatureEnvelope.d.ts +1 -1
  136. package/_types/tempo/SignatureEnvelope.d.ts.map +1 -1
  137. package/_types/tempo/TxEnvelopeTempo.d.ts +30 -1
  138. package/_types/tempo/TxEnvelopeTempo.d.ts.map +1 -1
  139. package/_types/tempo/internal/webauthnData.d.ts +26 -0
  140. package/_types/tempo/internal/webauthnData.d.ts.map +1 -0
  141. package/_types/version.d.ts +1 -1
  142. package/_types/webauthn/Registration.d.ts +2 -0
  143. package/_types/webauthn/Registration.d.ts.map +1 -1
  144. package/core/AbiError.ts +81 -7
  145. package/core/AbiEvent.ts +50 -11
  146. package/core/AbiFunction.ts +76 -4
  147. package/core/Address.ts +18 -1
  148. package/core/Authorization.ts +47 -4
  149. package/core/Keystore.ts +40 -3
  150. package/core/Secp256k1.ts +5 -1
  151. package/core/Signature.ts +7 -2
  152. package/core/Siwe.ts +29 -3
  153. package/core/TxEnvelopeEip1559.ts +4 -1
  154. package/core/TxEnvelopeEip2930.ts +4 -1
  155. package/core/TxEnvelopeEip7702.ts +9 -2
  156. package/core/TxEnvelopeLegacy.ts +56 -10
  157. package/core/TypedData.ts +10 -9
  158. package/core/Value.ts +14 -3
  159. package/core/internal/abiParameters.ts +8 -2
  160. package/core/internal/cursor.ts +36 -0
  161. package/erc4337/UserOperation.ts +1 -1
  162. package/erc7821/Execute.ts +84 -3
  163. package/index.ts +1 -1
  164. package/package.json +1 -1
  165. package/tempo/KeyAuthorization.test.ts +91 -0
  166. package/tempo/KeyAuthorization.ts +32 -3
  167. package/tempo/SignatureEnvelope.test.ts +300 -28
  168. package/tempo/SignatureEnvelope.ts +62 -54
  169. package/tempo/TxEnvelopeTempo.test.ts +310 -0
  170. package/tempo/TxEnvelopeTempo.ts +64 -1
  171. package/tempo/internal/webauthnData.ts +89 -0
  172. package/version.ts +1 -1
  173. package/webauthn/Registration.ts +4 -6
@@ -7,10 +7,15 @@ export type Cursor = {
7
7
  dataView: DataView
8
8
  position: number
9
9
  positionReadCount: Map<number, number>
10
+ /** Total number of bytes read. */
11
+ readSize: number
12
+ /** Maximum total number of bytes that can be read. */
13
+ readSizeLimit: number
10
14
  recursiveReadCount: number
11
15
  recursiveReadLimit: number
12
16
  remaining: number
13
17
  assertReadLimit(position?: number): void
18
+ assertReadSize(length: number): void
14
19
  assertPosition(position: number): void
15
20
  decrementPosition(offset: number): void
16
21
  getReadCount(position?: number): number
@@ -42,6 +47,8 @@ const staticCursor: Cursor = {
42
47
  dataView: new DataView(new ArrayBuffer(0)),
43
48
  position: 0,
44
49
  positionReadCount: new Map(),
50
+ readSize: 0,
51
+ readSizeLimit: Number.POSITIVE_INFINITY,
45
52
  recursiveReadCount: 0,
46
53
  recursiveReadLimit: Number.POSITIVE_INFINITY,
47
54
  assertReadLimit() {
@@ -51,6 +58,14 @@ const staticCursor: Cursor = {
51
58
  limit: this.recursiveReadLimit,
52
59
  })
53
60
  },
61
+ assertReadSize(length) {
62
+ this.readSize += length
63
+ if (this.readSize > this.readSizeLimit)
64
+ throw new ReadSizeLimitExceededError({
65
+ limit: this.readSizeLimit,
66
+ size: this.readSize,
67
+ })
68
+ },
54
69
  assertPosition(position) {
55
70
  if (position < 0 || position > this.bytes.length - 1)
56
71
  throw new PositionOutOfBoundsError({
@@ -141,6 +156,7 @@ const staticCursor: Cursor = {
141
156
  this.assertReadLimit()
142
157
  this._touch()
143
158
  const value = this.inspectByte()
159
+ this.assertReadSize(1)
144
160
  this.position++
145
161
  return value
146
162
  },
@@ -148,6 +164,7 @@ const staticCursor: Cursor = {
148
164
  this.assertReadLimit()
149
165
  this._touch()
150
166
  const value = this.inspectBytes(length)
167
+ this.assertReadSize(length)
151
168
  this.position += size ?? length
152
169
  return value
153
170
  },
@@ -155,6 +172,7 @@ const staticCursor: Cursor = {
155
172
  this.assertReadLimit()
156
173
  this._touch()
157
174
  const value = this.inspectUint8()
175
+ this.assertReadSize(1)
158
176
  this.position += 1
159
177
  return value
160
178
  },
@@ -162,6 +180,7 @@ const staticCursor: Cursor = {
162
180
  this.assertReadLimit()
163
181
  this._touch()
164
182
  const value = this.inspectUint16()
183
+ this.assertReadSize(2)
165
184
  this.position += 2
166
185
  return value
167
186
  },
@@ -169,6 +188,7 @@ const staticCursor: Cursor = {
169
188
  this.assertReadLimit()
170
189
  this._touch()
171
190
  const value = this.inspectUint24()
191
+ this.assertReadSize(3)
172
192
  this.position += 3
173
193
  return value
174
194
  },
@@ -176,6 +196,7 @@ const staticCursor: Cursor = {
176
196
  this.assertReadLimit()
177
197
  this._touch()
178
198
  const value = this.inspectUint32()
199
+ this.assertReadSize(4)
179
200
  this.position += 4
180
201
  return value
181
202
  },
@@ -210,6 +231,10 @@ export function create(
210
231
  )
211
232
  cursor.positionReadCount = new Map()
212
233
  cursor.recursiveReadLimit = recursiveReadLimit
234
+ // `recursiveReadLimit` allows one read per position plus that many repeated
235
+ // reads. Allow as many bytes as that number of 32-byte reads, so that reads
236
+ // of any length are bounded by the size of the data as well.
237
+ cursor.readSizeLimit = 32 * (bytes.length + recursiveReadLimit)
213
238
  return cursor
214
239
  }
215
240
 
@@ -240,6 +265,17 @@ export class PositionOutOfBoundsError extends Errors.BaseError {
240
265
  }
241
266
  }
242
267
 
268
+ /** @internal */
269
+ export class ReadSizeLimitExceededError extends Errors.BaseError {
270
+ override readonly name = 'Cursor.ReadSizeLimitExceededError'
271
+
272
+ constructor({ limit, size }: { limit: number; size: number }) {
273
+ super(
274
+ `Read size limit of \`${limit}\` bytes exceeded (read size: \`${size}\` bytes).`,
275
+ )
276
+ }
277
+ }
278
+
243
279
  /** @internal */
244
280
  export class RecursiveReadLimitExceededError extends Errors.BaseError {
245
281
  override readonly name = 'Cursor.RecursiveReadLimitExceededError'
@@ -500,7 +500,7 @@ export function hash<
500
500
  Hex.padLeft(Hex.fromNumber(maxFeePerGas), 16),
501
501
  )
502
502
  const initCode_hashed = Hash.keccak256(
503
- factory && factoryData ? Hex.concat(factory, factoryData) : '0x',
503
+ toInitCode({ factory, factoryData }),
504
504
  )
505
505
  const paymasterAndData_hashed = Hash.keccak256(
506
506
  paymaster
@@ -1,5 +1,6 @@
1
1
  import * as AbiFunction from '../core/AbiFunction.js'
2
- import type * as Hex from '../core/Hex.js'
2
+ import * as Errors from '../core/Errors.js'
3
+ import * as Hex from '../core/Hex.js'
3
4
  import { AbiParameters } from '../index.js'
4
5
  import * as Calls from './Calls.js'
5
6
 
@@ -39,6 +40,10 @@ export const mode = {
39
40
  /**
40
41
  * Decodes calls from ERC-7821 `execute` function data.
41
42
  *
43
+ * Decodes the single batch modes only (`mode.default` and `mode.opData`). Throws
44
+ * `Execute.UnsupportedModeError` for the "batch of batches" mode (use
45
+ * `Execute.decodeBatchOfBatchesData` instead) and for unknown modes.
46
+ *
42
47
  * @example
43
48
  * ```ts twoslash
44
49
  * import { Execute } from 'ox/erc7821'
@@ -54,7 +59,13 @@ export function decodeData(data: Hex.Hex): decodeData.ReturnType {
54
59
  Hex.Hex,
55
60
  Hex.Hex,
56
61
  ]
57
- return Calls.decode(executionData, { opData: m !== mode.default })
62
+ const name = getModeName(m)
63
+ if (name !== 'default' && name !== 'opData')
64
+ throw new UnsupportedModeError({
65
+ mode: m,
66
+ supported: ['default', 'opData'],
67
+ })
68
+ return Calls.decode(executionData, { opData: name === 'opData' })
58
69
  }
59
70
 
60
71
  export declare namespace decodeData {
@@ -62,11 +73,15 @@ export declare namespace decodeData {
62
73
  calls: Call[]
63
74
  opData?: Hex.Hex | undefined
64
75
  }
76
+
77
+ type ErrorType = UnsupportedModeError | Errors.GlobalErrorType
65
78
  }
66
79
 
67
80
  /**
68
81
  * Decodes batches from ERC-7821 `execute` function data in "batch of batches" mode.
69
82
  *
83
+ * Throws `Execute.UnsupportedModeError` for any other mode.
84
+ *
70
85
  * @example
71
86
  * ```ts twoslash
72
87
  * import { Execute } from 'ox/erc7821'
@@ -80,10 +95,12 @@ export declare namespace decodeData {
80
95
  export function decodeBatchOfBatchesData(
81
96
  data: Hex.Hex,
82
97
  ): decodeBatchOfBatchesData.ReturnType {
83
- const [, executionData] = AbiFunction.decodeData(abiFunction, data) as [
98
+ const [m, executionData] = AbiFunction.decodeData(abiFunction, data) as [
84
99
  Hex.Hex,
85
100
  Hex.Hex,
86
101
  ]
102
+ if (getModeName(m) !== 'batchOfBatches')
103
+ throw new UnsupportedModeError({ mode: m, supported: ['batchOfBatches'] })
87
104
 
88
105
  const [encodedBatches] = AbiParameters.decode(
89
106
  AbiParameters.from('bytes[]'),
@@ -112,6 +129,8 @@ export function decodeBatchOfBatchesData(
112
129
 
113
130
  export declare namespace decodeBatchOfBatchesData {
114
131
  type ReturnType = Batch[]
132
+
133
+ type ErrorType = UnsupportedModeError | Errors.GlobalErrorType
115
134
  }
116
135
 
117
136
  /**
@@ -195,3 +214,65 @@ export declare namespace encodeData {
195
214
  opData?: Hex.Hex | undefined
196
215
  }
197
216
  }
217
+
218
+ /**
219
+ * Thrown when the mode of ERC-7821 `execute` function data is not supported by the decoder.
220
+ *
221
+ * @example
222
+ * ```ts twoslash
223
+ * import { Execute } from 'ox/erc7821'
224
+ *
225
+ * const data = Execute.encodeBatchOfBatchesData([
226
+ * {
227
+ * calls: [
228
+ * {
229
+ * data: '0xcafebabe',
230
+ * to: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
231
+ * value: 1n
232
+ * }
233
+ * ]
234
+ * }
235
+ * ])
236
+ *
237
+ * Execute.decodeData(data)
238
+ * // @error: Execute.UnsupportedModeError: Execution mode `0x0100000000007821000200000000000000000000000000000000000000000000` is not supported.
239
+ * ```
240
+ */
241
+ export class UnsupportedModeError extends Errors.BaseError {
242
+ override readonly name = 'Execute.UnsupportedModeError'
243
+
244
+ constructor({ mode, supported }: UnsupportedModeError.Options) {
245
+ super(`Execution mode \`${mode}\` is not supported.`, {
246
+ metaMessages: [
247
+ `Supported modes: ${supported.map((name) => `\`${name}\``).join(', ')}.`,
248
+ ],
249
+ })
250
+ }
251
+ }
252
+
253
+ export declare namespace UnsupportedModeError {
254
+ /** Options for `Execute.UnsupportedModeError`. */
255
+ type Options = {
256
+ /** Mode of the `execute` function data. */
257
+ mode: Hex.Hex
258
+ /** Names of the modes (keys of `Execute.mode`) the decoder supports. */
259
+ supported: readonly (keyof typeof mode)[]
260
+ }
261
+ }
262
+
263
+ /**
264
+ * Identifies an ERC-7821 execution mode the way the reference implementation
265
+ * (`_executionModeId`) does. Bytes `[0..1]` (call type and execution type) and
266
+ * bytes `[6..9]` (mode selector) identify the mode. Bytes `[2..5]` (reserved by
267
+ * ERC-7579) and bytes `[10..31]` (unused) are ignored.
268
+ *
269
+ * @internal
270
+ */
271
+ function getModeName(m: Hex.Hex): keyof typeof mode | undefined {
272
+ if (Hex.slice(m, 0, 2) !== '0x0100') return undefined
273
+ const selector = Hex.slice(m, 6, 10)
274
+ if (selector === '0x00000000') return 'default'
275
+ if (selector === '0x78210001') return 'opData'
276
+ if (selector === '0x78210002') return 'batchOfBatches'
277
+ return undefined
278
+ }
package/index.ts CHANGED
@@ -259,7 +259,7 @@ export * as AbiConstructor from './core/AbiConstructor.js'
259
259
  * const abi = Abi.from([...])
260
260
  * const error = AbiError.fromAbi(abi, 'InvalidSignature')
261
261
  *
262
- * const value = AbiError.decode(error, '0xecde634900000000000000000000000000000000000000000000000000000000000001a400000000000000000000000000000000000000000000000000000000000000450000000000000000000000000000000000000000000000000000000000000001') // [!code focus]
262
+ * const value = AbiError.decode(error, '0xe466f0a500000000000000000000000000000000000000000000000000000000000001a400000000000000000000000000000000000000000000000000000000000000450000000000000000000000000000000000000000000000000000000000000001') // [!code focus]
263
263
  * // @log: [420n, 69n, 1]
264
264
  * ```
265
265
  *
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ox",
3
3
  "description": "Ethereum Standard Library",
4
- "version": "0.14.65",
4
+ "version": "0.14.67",
5
5
  "main": "./_cjs/index.js",
6
6
  "module": "./_esm/index.js",
7
7
  "types": "./_types/index.d.ts",
@@ -223,6 +223,44 @@ describe('from', () => {
223
223
  }).toEqual(limitsVectors)
224
224
  })
225
225
 
226
+ test('error: rejects recipients without a selector', () => {
227
+ const base = { address, chainId: 4217n, type: 'secp256k1' } as const
228
+ const recipients = ['0x1111111111111111111111111111111111111111'] as const
229
+ expect(() =>
230
+ KeyAuthorization.from({
231
+ ...base,
232
+ scopes: [{ address: token, recipients }],
233
+ }),
234
+ ).toThrowErrorMatchingInlineSnapshot(
235
+ `[KeyAuthorization.InvalidScopeError: Scope for \`0x20c0000000000000000000000000000000000001\` has \`recipients\` but no \`selector\`; a recipient allowlist requires a selector.]`,
236
+ )
237
+ expect(() =>
238
+ KeyAuthorization.from({
239
+ ...base,
240
+ scopes: [
241
+ { address: token, selector: 'transfer(address,uint256)' },
242
+ { address: token, recipients },
243
+ ],
244
+ }),
245
+ ).toThrowErrorMatchingInlineSnapshot(
246
+ `[KeyAuthorization.InvalidScopeError: Scope for \`0x20c0000000000000000000000000000000000001\` has \`recipients\` but no \`selector\`; a recipient allowlist requires a selector.]`,
247
+ )
248
+ expect(
249
+ KeyAuthorization.from({
250
+ ...base,
251
+ scopes: [{ address: token, recipients: [] }],
252
+ }).scopes,
253
+ ).toMatchInlineSnapshot(`
254
+ [
255
+ {
256
+ "address": "0x20c0000000000000000000000000000000000001",
257
+ "recipients": [],
258
+ "selector": undefined,
259
+ },
260
+ ]
261
+ `)
262
+ })
263
+
226
264
  test('accepts configurable grants and delegates', () => {
227
265
  const signed = KeyAuthorization.from(
228
266
  {
@@ -1547,6 +1585,25 @@ describe('serialize', () => {
1547
1585
  })
1548
1586
 
1549
1587
  describe('toRpc', () => {
1588
+ test('error: rejects recipients without a selector', () => {
1589
+ expect(() =>
1590
+ KeyAuthorization.toRpc({
1591
+ address,
1592
+ chainId: 4217n,
1593
+ scopes: [
1594
+ {
1595
+ address: token,
1596
+ recipients: ['0x1111111111111111111111111111111111111111'],
1597
+ },
1598
+ ],
1599
+ signature: SignatureEnvelope.from(signature_secp256k1),
1600
+ type: 'secp256k1',
1601
+ }),
1602
+ ).toThrowErrorMatchingInlineSnapshot(
1603
+ `[KeyAuthorization.InvalidScopeError: Scope for \`0x20c0000000000000000000000000000000000001\` has \`recipients\` but no \`selector\`; a recipient allowlist requires a selector.]`,
1604
+ )
1605
+ })
1606
+
1550
1607
  test('behavior: configurable key type uses the RPC configurableAccount key type', () => {
1551
1608
  const authorization = KeyAuthorization.from(
1552
1609
  { account: address, address, chainId: 1n, type: 'configurable' },
@@ -1829,6 +1886,40 @@ describe('toRpc', () => {
1829
1886
  })
1830
1887
 
1831
1888
  describe('toTuple', () => {
1889
+ test('error: rejects recipients without a selector', () => {
1890
+ const authorization = {
1891
+ address,
1892
+ chainId: 4217n,
1893
+ scopes: [
1894
+ {
1895
+ address: token,
1896
+ recipients: ['0x1111111111111111111111111111111111111111'],
1897
+ },
1898
+ ],
1899
+ type: 'secp256k1',
1900
+ } as const
1901
+ expect(() =>
1902
+ KeyAuthorization.toTuple(authorization),
1903
+ ).toThrowErrorMatchingInlineSnapshot(
1904
+ `[KeyAuthorization.InvalidScopeError: Scope for \`0x20c0000000000000000000000000000000000001\` has \`recipients\` but no \`selector\`; a recipient allowlist requires a selector.]`,
1905
+ )
1906
+ expect(() =>
1907
+ KeyAuthorization.getSignPayload(authorization),
1908
+ ).toThrowErrorMatchingInlineSnapshot(
1909
+ `[KeyAuthorization.InvalidScopeError: Scope for \`0x20c0000000000000000000000000000000000001\` has \`recipients\` but no \`selector\`; a recipient allowlist requires a selector.]`,
1910
+ )
1911
+ expect(() =>
1912
+ KeyAuthorization.hash(authorization),
1913
+ ).toThrowErrorMatchingInlineSnapshot(
1914
+ `[KeyAuthorization.InvalidScopeError: Scope for \`0x20c0000000000000000000000000000000000001\` has \`recipients\` but no \`selector\`; a recipient allowlist requires a selector.]`,
1915
+ )
1916
+ expect(() =>
1917
+ KeyAuthorization.serialize(authorization),
1918
+ ).toThrowErrorMatchingInlineSnapshot(
1919
+ `[KeyAuthorization.InvalidScopeError: Scope for \`0x20c0000000000000000000000000000000000001\` has \`recipients\` but no \`selector\`; a recipient allowlist requires a selector.]`,
1920
+ )
1921
+ })
1922
+
1832
1923
  test('behavior: round-trips Tempo node limits encoding', () => {
1833
1924
  for (const { hash, rlp } of Object.values(limitsVectors)) {
1834
1925
  const authorization = KeyAuthorization.fromTuple([
@@ -291,6 +291,7 @@ export type Scope<addressType = Address.Address> = {
291
291
  * - `[...]` = only listed recipients allowed
292
292
  *
293
293
  * Only valid for constrained selectors: `transfer`, `approve`, `transferWithMemo`.
294
+ * A non-empty list requires `selector`.
294
295
  */
295
296
  recipients?: readonly addressType[] | undefined
296
297
  /** Function selector or human-readable ABI signature. */
@@ -477,6 +478,7 @@ export function from<
477
478
  }
478
479
  if (auth.witness !== undefined) assertWitness(auth.witness)
479
480
  if (auth.signature) assertSignature(auth.signature)
481
+ if (auth.scopes) assertScopes(auth.scopes)
480
482
  const resolved = {
481
483
  ...auth,
482
484
  ...(auth.account !== undefined
@@ -552,7 +554,10 @@ export declare namespace from {
552
554
  >
553
555
  >
554
556
 
555
- type ErrorType = InvalidSignatureTypeError | Errors.GlobalErrorType
557
+ type ErrorType =
558
+ | InvalidScopeError
559
+ | InvalidSignatureTypeError
560
+ | Errors.GlobalErrorType
556
561
  }
557
562
 
558
563
  /**
@@ -987,6 +992,7 @@ export function toRpc(authorization: Signed): Rpc {
987
992
  // Group flat scopes by address into nested allowedCalls wire format
988
993
  const allowedCalls = (() => {
989
994
  if (!scopes) return undefined
995
+ assertScopes(scopes)
990
996
  const grouped = new Map<string, RpcSelectorRule[]>()
991
997
  for (const scope of scopes) {
992
998
  const key = scope.address as string
@@ -1031,7 +1037,10 @@ export function toRpc(authorization: Signed): Rpc {
1031
1037
  }
1032
1038
 
1033
1039
  export declare namespace toRpc {
1034
- type ErrorType = InvalidSignatureTypeError | Errors.GlobalErrorType
1040
+ type ErrorType =
1041
+ | InvalidScopeError
1042
+ | InvalidSignatureTypeError
1043
+ | Errors.GlobalErrorType
1035
1044
  }
1036
1045
 
1037
1046
  /**
@@ -1108,6 +1117,7 @@ export function toTuple<const authorization extends KeyAuthorization>(
1108
1117
  // Group flat scopes by address for wire format
1109
1118
  const callsValue = (() => {
1110
1119
  if (!scopes) return undefined
1120
+ assertScopes(scopes)
1111
1121
  const grouped = new Map<
1112
1122
  string,
1113
1123
  [Hex.Hex, (readonly Address.Address[])[]][]
@@ -1177,7 +1187,10 @@ export declare namespace toTuple {
1177
1187
  type ReturnType<authorization extends KeyAuthorization = KeyAuthorization> =
1178
1188
  Compute<Tuple<authorization extends KeyAuthorization<true> ? true : false>>
1179
1189
 
1180
- type ErrorType = InvalidSignatureTypeError | Errors.GlobalErrorType
1190
+ type ErrorType =
1191
+ | InvalidScopeError
1192
+ | InvalidSignatureTypeError
1193
+ | Errors.GlobalErrorType
1181
1194
  }
1182
1195
 
1183
1196
  function bigintToHex(value: bigint): Hex.Hex {
@@ -1215,6 +1228,12 @@ function assertWitness(witness: Hex.Hex): void {
1215
1228
  if (Hex.size(witness) !== 32) throw new InvalidWitnessSizeError(witness)
1216
1229
  }
1217
1230
 
1231
+ function assertScopes(scopes: readonly Scope[]): void {
1232
+ for (const scope of scopes)
1233
+ if (!scope.selector && scope.recipients && scope.recipients.length > 0)
1234
+ throw new InvalidScopeError(scope)
1235
+ }
1236
+
1218
1237
  function assertSignature<bigintType, numberType>(
1219
1238
  signature: SignatureEnvelope.SignatureEnvelope<bigintType, numberType>,
1220
1239
  ): asserts signature is Signature<bigintType, numberType> {
@@ -1256,6 +1275,16 @@ export class InvalidSignatureTypeError extends Error {
1256
1275
  }
1257
1276
  }
1258
1277
 
1278
+ /** Thrown when a call scope has a recipient allowlist but no selector. */
1279
+ export class InvalidScopeError extends Error {
1280
+ override readonly name = 'KeyAuthorization.InvalidScopeError'
1281
+ constructor(scope: Scope) {
1282
+ super(
1283
+ `Scope for \`${scope.address}\` has \`recipients\` but no \`selector\`; a recipient allowlist requires a selector.`,
1284
+ )
1285
+ }
1286
+ }
1287
+
1259
1288
  /**
1260
1289
  * Thrown when a configurable account key grant omits its parent account binding.
1261
1290
  *