ox 0.14.64 → 0.14.66

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 (184) 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 +37 -12
  43. package/_cjs/tempo/SignatureEnvelope.js.map +1 -1
  44. package/_cjs/tempo/SignaturePreAuthorized.js +177 -0
  45. package/_cjs/tempo/SignaturePreAuthorized.js.map +1 -0
  46. package/_cjs/tempo/TxEnvelopeTempo.js +34 -3
  47. package/_cjs/tempo/TxEnvelopeTempo.js.map +1 -1
  48. package/_cjs/tempo/index.js +2 -1
  49. package/_cjs/tempo/index.js.map +1 -1
  50. package/_cjs/version.js +1 -1
  51. package/_cjs/webauthn/Registration.js +2 -6
  52. package/_cjs/webauthn/Registration.js.map +1 -1
  53. package/_esm/core/AbiError.js +64 -3
  54. package/_esm/core/AbiError.js.map +1 -1
  55. package/_esm/core/AbiEvent.js +24 -3
  56. package/_esm/core/AbiEvent.js.map +1 -1
  57. package/_esm/core/AbiFunction.js +64 -3
  58. package/_esm/core/AbiFunction.js.map +1 -1
  59. package/_esm/core/Address.js +17 -1
  60. package/_esm/core/Address.js.map +1 -1
  61. package/_esm/core/Authorization.js +47 -2
  62. package/_esm/core/Authorization.js.map +1 -1
  63. package/_esm/core/Keystore.js +33 -2
  64. package/_esm/core/Keystore.js.map +1 -1
  65. package/_esm/core/Secp256k1.js +5 -1
  66. package/_esm/core/Secp256k1.js.map +1 -1
  67. package/_esm/core/Signature.js +4 -2
  68. package/_esm/core/Signature.js.map +1 -1
  69. package/_esm/core/Siwe.js +29 -3
  70. package/_esm/core/Siwe.js.map +1 -1
  71. package/_esm/core/TxEnvelopeEip1559.js +2 -1
  72. package/_esm/core/TxEnvelopeEip1559.js.map +1 -1
  73. package/_esm/core/TxEnvelopeEip2930.js +2 -1
  74. package/_esm/core/TxEnvelopeEip2930.js.map +1 -1
  75. package/_esm/core/TxEnvelopeEip7702.js +6 -1
  76. package/_esm/core/TxEnvelopeEip7702.js.map +1 -1
  77. package/_esm/core/TxEnvelopeLegacy.js +49 -9
  78. package/_esm/core/TxEnvelopeLegacy.js.map +1 -1
  79. package/_esm/core/TypedData.js +9 -9
  80. package/_esm/core/TypedData.js.map +1 -1
  81. package/_esm/core/Value.js +14 -3
  82. package/_esm/core/Value.js.map +1 -1
  83. package/_esm/core/internal/abiParameters.js +9 -2
  84. package/_esm/core/internal/abiParameters.js.map +1 -1
  85. package/_esm/core/internal/cursor.js +32 -0
  86. package/_esm/core/internal/cursor.js.map +1 -1
  87. package/_esm/erc4337/UserOperation.js +1 -1
  88. package/_esm/erc4337/UserOperation.js.map +1 -1
  89. package/_esm/erc7821/Execute.js +76 -2
  90. package/_esm/erc7821/Execute.js.map +1 -1
  91. package/_esm/index.js +1 -1
  92. package/_esm/tempo/KeyAuthorization.js +21 -0
  93. package/_esm/tempo/KeyAuthorization.js.map +1 -1
  94. package/_esm/tempo/SignatureEnvelope.js +46 -13
  95. package/_esm/tempo/SignatureEnvelope.js.map +1 -1
  96. package/_esm/tempo/SignaturePreAuthorized.js +314 -0
  97. package/_esm/tempo/SignaturePreAuthorized.js.map +1 -0
  98. package/_esm/tempo/TxEnvelopeTempo.js +56 -2
  99. package/_esm/tempo/TxEnvelopeTempo.js.map +1 -1
  100. package/_esm/tempo/index.js +8 -0
  101. package/_esm/tempo/index.js.map +1 -1
  102. package/_esm/version.js +1 -1
  103. package/_esm/webauthn/Registration.js +2 -6
  104. package/_esm/webauthn/Registration.js.map +1 -1
  105. package/_types/core/AbiError.d.ts +51 -5
  106. package/_types/core/AbiError.d.ts.map +1 -1
  107. package/_types/core/AbiEvent.d.ts +4 -2
  108. package/_types/core/AbiEvent.d.ts.map +1 -1
  109. package/_types/core/AbiFunction.d.ts +48 -2
  110. package/_types/core/AbiFunction.d.ts.map +1 -1
  111. package/_types/core/Address.d.ts +17 -2
  112. package/_types/core/Address.d.ts.map +1 -1
  113. package/_types/core/Authorization.d.ts +24 -2
  114. package/_types/core/Authorization.d.ts.map +1 -1
  115. package/_types/core/Keystore.d.ts +31 -2
  116. package/_types/core/Keystore.d.ts.map +1 -1
  117. package/_types/core/Secp256k1.d.ts.map +1 -1
  118. package/_types/core/Signature.d.ts +1 -1
  119. package/_types/core/Signature.d.ts.map +1 -1
  120. package/_types/core/Siwe.d.ts +4 -0
  121. package/_types/core/Siwe.d.ts.map +1 -1
  122. package/_types/core/TxEnvelopeEip1559.d.ts.map +1 -1
  123. package/_types/core/TxEnvelopeEip2930.d.ts.map +1 -1
  124. package/_types/core/TxEnvelopeEip7702.d.ts +1 -1
  125. package/_types/core/TxEnvelopeEip7702.d.ts.map +1 -1
  126. package/_types/core/TxEnvelopeLegacy.d.ts.map +1 -1
  127. package/_types/core/TypedData.d.ts +3 -1
  128. package/_types/core/TypedData.d.ts.map +1 -1
  129. package/_types/core/Value.d.ts.map +1 -1
  130. package/_types/core/internal/abiParameters.d.ts +1 -1
  131. package/_types/core/internal/abiParameters.d.ts.map +1 -1
  132. package/_types/core/internal/cursor.d.ts +13 -0
  133. package/_types/core/internal/cursor.d.ts.map +1 -1
  134. package/_types/erc7821/Execute.d.ts +46 -1
  135. package/_types/erc7821/Execute.d.ts.map +1 -1
  136. package/_types/index.d.ts +1 -1
  137. package/_types/tempo/KeyAuthorization.d.ts +9 -3
  138. package/_types/tempo/KeyAuthorization.d.ts.map +1 -1
  139. package/_types/tempo/SignatureEnvelope.d.ts +1 -1
  140. package/_types/tempo/SignatureEnvelope.d.ts.map +1 -1
  141. package/_types/tempo/SignaturePreAuthorized.d.ts +192 -0
  142. package/_types/tempo/SignaturePreAuthorized.d.ts.map +1 -0
  143. package/_types/tempo/TxEnvelopeTempo.d.ts +30 -1
  144. package/_types/tempo/TxEnvelopeTempo.d.ts.map +1 -1
  145. package/_types/tempo/index.d.ts +8 -0
  146. package/_types/tempo/index.d.ts.map +1 -1
  147. package/_types/version.d.ts +1 -1
  148. package/_types/webauthn/Registration.d.ts +2 -0
  149. package/_types/webauthn/Registration.d.ts.map +1 -1
  150. package/core/AbiError.ts +81 -7
  151. package/core/AbiEvent.ts +50 -11
  152. package/core/AbiFunction.ts +76 -4
  153. package/core/Address.ts +18 -1
  154. package/core/Authorization.ts +47 -4
  155. package/core/Keystore.ts +40 -3
  156. package/core/Secp256k1.ts +5 -1
  157. package/core/Signature.ts +7 -2
  158. package/core/Siwe.ts +29 -3
  159. package/core/TxEnvelopeEip1559.ts +4 -1
  160. package/core/TxEnvelopeEip2930.ts +4 -1
  161. package/core/TxEnvelopeEip7702.ts +9 -2
  162. package/core/TxEnvelopeLegacy.ts +56 -10
  163. package/core/TypedData.ts +10 -9
  164. package/core/Value.ts +14 -3
  165. package/core/internal/abiParameters.ts +8 -2
  166. package/core/internal/cursor.ts +36 -0
  167. package/erc4337/UserOperation.ts +1 -1
  168. package/erc7821/Execute.ts +84 -3
  169. package/index.ts +1 -1
  170. package/package.json +11 -1
  171. package/tempo/KeyAuthorization.test.ts +91 -0
  172. package/tempo/KeyAuthorization.ts +32 -3
  173. package/tempo/SignatureEnvelope.test.ts +211 -27
  174. package/tempo/SignatureEnvelope.ts +55 -11
  175. package/tempo/SignaturePreAuthorized/package.json +6 -0
  176. package/tempo/SignaturePreAuthorized.test-d/package.json +6 -0
  177. package/tempo/SignaturePreAuthorized.test-d.ts +29 -0
  178. package/tempo/SignaturePreAuthorized.test.ts +410 -0
  179. package/tempo/SignaturePreAuthorized.ts +370 -0
  180. package/tempo/TxEnvelopeTempo.test.ts +310 -0
  181. package/tempo/TxEnvelopeTempo.ts +64 -1
  182. package/tempo/index.ts +9 -0
  183. package/version.ts +1 -1
  184. package/webauthn/Registration.ts +4 -6
@@ -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
  *
@@ -437,6 +437,20 @@ describe('assert', () => {
437
437
  expect(() => SignatureEnvelope.assert(signatureWithoutType)).not.toThrow()
438
438
  })
439
439
 
440
+ test('error: throws on keychain inner signature', () => {
441
+ for (const version of ['v1', 'v2'] as const)
442
+ expect(() =>
443
+ SignatureEnvelope.assert({
444
+ inner: signature_keychain_secp256k1,
445
+ type: 'keychain',
446
+ userAddress: '0x1234567890123456789012345678901234567890',
447
+ version,
448
+ }),
449
+ ).toThrowErrorMatchingInlineSnapshot(
450
+ `[SignatureEnvelope.InvalidApprovalError: Invalid owner approval: keychain signatures cannot wrap a keychain signature.]`,
451
+ )
452
+ })
453
+
440
454
  test('error: throws on invalid inner signature', () => {
441
455
  expect(() =>
442
456
  SignatureEnvelope.assert({
@@ -472,6 +486,23 @@ describe('assert', () => {
472
486
  `[SignatureEnvelope.CoercionError: Unable to coerce value (\`{"r":"0#__bigint","s":"0#__bigint"}\`) to a valid signature envelope.]`,
473
487
  )
474
488
  })
489
+
490
+ test('error: throws on unsupported type', () => {
491
+ expect(() =>
492
+ SignatureEnvelope.assert({ type: 'webauthn' } as any),
493
+ ).toThrowErrorMatchingInlineSnapshot(
494
+ `[SignatureEnvelope.CoercionError: Unable to coerce value (\`{"type":"webauthn"}\`) to a valid signature envelope.]`,
495
+ )
496
+ expect(() =>
497
+ SignatureEnvelope.assert({
498
+ inner: { type: 'bogus' },
499
+ type: 'keychain',
500
+ userAddress: '0x1234567890123456789012345678901234567890',
501
+ } as any),
502
+ ).toThrowErrorMatchingInlineSnapshot(
503
+ `[SignatureEnvelope.CoercionError: Unable to coerce value (\`{"type":"bogus"}\`) to a valid signature envelope.]`,
504
+ )
505
+ })
475
506
  })
476
507
 
477
508
  describe('deserialize', () => {
@@ -646,6 +677,42 @@ describe('deserialize', () => {
646
677
  )
647
678
  })
648
679
 
680
+ test('error: throws on WebAuthn signature above the maximum size', () => {
681
+ const authenticatorData = `0x${'00'.repeat(37)}` as const
682
+ // 37 (authenticatorData) + 1883 (clientDataJSON) + 128 = 2048 bytes
683
+ const max = {
684
+ ...signature_webauthn,
685
+ metadata: {
686
+ authenticatorData,
687
+ clientDataJSON: JSON.stringify({ challenge: 'a'.repeat(1867) }),
688
+ },
689
+ }
690
+ const serialized = SignatureEnvelope.serialize(max)
691
+ expect(Hex.size(serialized)).toMatchInlineSnapshot(`2049`)
692
+ expect(SignatureEnvelope.deserialize(serialized)).toMatchObject({
693
+ metadata: max.metadata,
694
+ })
695
+
696
+ expect(() =>
697
+ SignatureEnvelope.deserialize(
698
+ SignatureEnvelope.serialize({
699
+ ...max,
700
+ metadata: {
701
+ authenticatorData,
702
+ clientDataJSON: JSON.stringify({ challenge: 'a'.repeat(1868) }),
703
+ },
704
+ }),
705
+ ),
706
+ ).toThrow(
707
+ 'Invalid WebAuthn signature envelope size: expected at most 2048 bytes, got 2049 bytes',
708
+ )
709
+ expect(() =>
710
+ SignatureEnvelope.deserialize(`0x02${'41'.repeat(40_000)}`),
711
+ ).toThrow(
712
+ 'Invalid WebAuthn signature envelope size: expected at most 2048 bytes, got 40000 bytes',
713
+ )
714
+ })
715
+
649
716
  test('error: throws on invalid clientDataJSON', () => {
650
717
  // Create a signature with invalid JSON (not properly formatted)
651
718
  const invalidMetadata = {
@@ -767,6 +834,48 @@ describe('deserialize', () => {
767
834
  })
768
835
  })
769
836
 
837
+ test('behavior: deserializes 65-byte inner starting with a keychain type as secp256k1', () => {
838
+ const userAddress = '0x1234567890123456789012345678901234567890'
839
+ const inner = `0x03${'11'.repeat(31)}${'22'.repeat(32)}1b` as const
840
+ expect(
841
+ SignatureEnvelope.deserialize(Hex.concat('0x04', userAddress, inner)),
842
+ ).toMatchInlineSnapshot(`
843
+ {
844
+ "inner": {
845
+ "signature": {
846
+ "r": 1387092735655350257678194091249907229492296691307152590056002308428126032145n,
847
+ "s": 15438945231642159389809464667825054380435997955418741871927677867721750618658n,
848
+ "yParity": 0,
849
+ },
850
+ "type": "secp256k1",
851
+ },
852
+ "type": "keychain",
853
+ "userAddress": "0x1234567890123456789012345678901234567890",
854
+ "version": "v2",
855
+ }
856
+ `)
857
+ })
858
+
859
+ test('error: throws on keychain inner signature', () => {
860
+ const userAddress = '0x1234567890123456789012345678901234567890'
861
+ const inner = SignatureEnvelope.serialize(signature_keychain_secp256k1)
862
+ for (const typeId of ['0x03', '0x04'] as const)
863
+ expect(() =>
864
+ SignatureEnvelope.deserialize(Hex.concat(typeId, userAddress, inner)),
865
+ ).toThrow(
866
+ 'Unable to deserialize signature envelope: keychain signatures cannot wrap a keychain signature',
867
+ )
868
+
869
+ // 2000 nested keychains
870
+ const nested = Hex.concat(
871
+ `0x${`03${userAddress.slice(2)}`.repeat(2000)}`,
872
+ Signature.toHex(signature_secp256k1),
873
+ )
874
+ expect(() => SignatureEnvelope.deserialize(nested)).toThrow(
875
+ SignatureEnvelope.InvalidSerializedError,
876
+ )
877
+ })
878
+
770
879
  test('error: throws on invalid keychain signature length', () => {
771
880
  // Keychain signature too short (must be at least 21 bytes: 1 type + 20 address)
772
881
  const invalidSig = `0x03${'00'.repeat(10)}` as const
@@ -1907,6 +2016,17 @@ describe('validate', () => {
1907
2016
  expect(SignatureEnvelope.validate({} as any)).toBe(false)
1908
2017
  })
1909
2018
 
2019
+ test('behavior: returns false for unsupported type', () => {
2020
+ expect(SignatureEnvelope.validate({ type: 'webauthn' } as any)).toBe(false)
2021
+ expect(
2022
+ SignatureEnvelope.validate({
2023
+ inner: { type: 'bogus' },
2024
+ type: 'keychain',
2025
+ userAddress: '0x1234567890123456789012345678901234567890',
2026
+ } as any),
2027
+ ).toBe(false)
2028
+ })
2029
+
1910
2030
  test('behavior: returns false for incomplete signature', () => {
1911
2031
  expect(
1912
2032
  SignatureEnvelope.validate({
@@ -2295,6 +2415,49 @@ describe('fromRpc', () => {
2295
2415
  type: 'webAuthn',
2296
2416
  })
2297
2417
  })
2418
+
2419
+ test('error: throws on WebAuthn data above the maximum size', () => {
2420
+ const rpc = {
2421
+ pubKeyX: Hex.fromNumber(publicKey.x, { size: 32 }),
2422
+ pubKeyY: Hex.fromNumber(publicKey.y, { size: 32 }),
2423
+ r: Hex.fromNumber(p256Signature.r, { size: 32 }),
2424
+ s: Hex.fromNumber(p256Signature.s, { size: 32 }),
2425
+ type: 'webAuthn',
2426
+ } as const
2427
+ const authenticatorData = `0x${'00'.repeat(37)}` as const
2428
+ const clientDataJSON = JSON.stringify({ challenge: 'a'.repeat(1867) })
2429
+
2430
+ // 37 (authenticatorData) + 1883 (clientDataJSON) = 1920 bytes
2431
+ expect(
2432
+ SignatureEnvelope.fromRpc({
2433
+ ...rpc,
2434
+ webauthnData: Hex.concat(
2435
+ authenticatorData,
2436
+ Hex.fromString(clientDataJSON),
2437
+ ),
2438
+ }),
2439
+ ).toMatchObject({ metadata: { authenticatorData, clientDataJSON } })
2440
+
2441
+ expect(() =>
2442
+ SignatureEnvelope.fromRpc({
2443
+ ...rpc,
2444
+ webauthnData: Hex.concat(
2445
+ authenticatorData,
2446
+ Hex.fromString(JSON.stringify({ challenge: 'a'.repeat(1868) })),
2447
+ ),
2448
+ }),
2449
+ ).toThrow(
2450
+ 'Invalid WebAuthn data size: expected at most 1920 bytes, got 1921 bytes',
2451
+ )
2452
+ expect(() =>
2453
+ SignatureEnvelope.fromRpc({
2454
+ ...rpc,
2455
+ webauthnData: `0x${'41'.repeat(40_000)}`,
2456
+ }),
2457
+ ).toThrow(
2458
+ 'Invalid WebAuthn data size: expected at most 1920 bytes, got 40000 bytes',
2459
+ )
2460
+ })
2298
2461
  })
2299
2462
 
2300
2463
  describe('keychain', () => {
@@ -2425,6 +2588,36 @@ describe('fromRpc', () => {
2425
2588
 
2426
2589
  expect(envelope.keyId).toBe('0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c')
2427
2590
  })
2591
+
2592
+ test('error: throws on keychain inner signature', () => {
2593
+ const inner = {
2594
+ signature: {
2595
+ r: '0xa2bb71146c20ce932456c043ebb2973ed205e07cd32c35a60bdefca1285fd132',
2596
+ s: '0x7cba10692bccdbfba9a215418443c2903dbee6fe5cb55c91172e47efc607840e',
2597
+ type: 'secp256k1',
2598
+ yParity: '0x1',
2599
+ },
2600
+ userAddress: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
2601
+ } as const
2602
+ expect(() =>
2603
+ SignatureEnvelope.fromRpc({
2604
+ signature: { ...inner, type: 'keychain' },
2605
+ type: 'keychain',
2606
+ userAddress: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
2607
+ }),
2608
+ ).toThrowErrorMatchingInlineSnapshot(
2609
+ `[SignatureEnvelope.InvalidApprovalError: Invalid owner approval: keychain signatures cannot wrap a keychain signature.]`,
2610
+ )
2611
+ // inner keychain without an explicit type
2612
+ expect(() =>
2613
+ SignatureEnvelope.fromRpc({
2614
+ signature: inner as never,
2615
+ type: 'keychain',
2616
+ userAddress: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
2617
+ version: 'v1',
2618
+ }),
2619
+ ).toThrow(SignatureEnvelope.InvalidApprovalError)
2620
+ })
2428
2621
  })
2429
2622
  })
2430
2623
 
@@ -3006,18 +3199,21 @@ describe('configurable', () => {
3006
3199
  }),
3007
3200
  ).toThrowError(SignatureEnvelope.InvalidApprovalError)
3008
3201
  })
3009
- test('rejects V1 wrappers around recursively nested configurable delegates', () => {
3010
- let inner: SignatureEnvelope.SignatureEnvelope = envelope
3011
- for (let depth = 0; depth < 3; depth++) {
3012
- inner = { inner, type: 'keychain', userAddress: account, version: 'v2' }
3013
- const valid: SignatureEnvelope.Keychain = {
3202
+ test('rejects keychain wrappers around keychain-wrapped configurable delegates', () => {
3203
+ const inner: SignatureEnvelope.Keychain = {
3204
+ inner: envelope,
3205
+ type: 'keychain',
3206
+ userAddress: account,
3207
+ version: 'v2',
3208
+ }
3209
+ expect(SignatureEnvelope.validate(inner)).toBe(true)
3210
+ for (const version of ['v1', 'v2'] as const) {
3211
+ const invalid: SignatureEnvelope.Keychain = {
3014
3212
  inner,
3015
3213
  type: 'keychain',
3016
3214
  userAddress: account,
3017
- version: 'v2',
3215
+ version,
3018
3216
  }
3019
- const invalid = { ...valid, version: 'v1' } as const
3020
- expect(SignatureEnvelope.validate(valid)).toBe(true)
3021
3217
  expect(SignatureEnvelope.validate(invalid)).toBe(false)
3022
3218
  expect(() => SignatureEnvelope.serialize(invalid)).toThrowError(
3023
3219
  SignatureEnvelope.InvalidApprovalError,
@@ -3029,32 +3225,20 @@ describe('configurable', () => {
3029
3225
  SignatureEnvelope.fromRpc({
3030
3226
  type: 'keychain',
3031
3227
  userAddress: account,
3032
- version: 'v1',
3228
+ version,
3033
3229
  signature: SignatureEnvelope.toRpc(inner),
3034
3230
  }),
3035
3231
  ).toThrowError(SignatureEnvelope.InvalidApprovalError)
3036
3232
  expect(() =>
3037
3233
  SignatureEnvelope.deserialize(
3038
- Hex.concat('0x03', account, SignatureEnvelope.serialize(inner)),
3234
+ Hex.concat(
3235
+ version === 'v1' ? '0x03' : '0x04',
3236
+ account,
3237
+ SignatureEnvelope.serialize(inner),
3238
+ ),
3039
3239
  ),
3040
- ).toThrowError(SignatureEnvelope.InvalidApprovalError)
3041
- expect(() =>
3042
- SignatureEnvelope.serialize({ ...valid, inner: invalid }),
3043
- ).toThrowError(SignatureEnvelope.InvalidApprovalError)
3240
+ ).toThrowError(SignatureEnvelope.InvalidSerializedError)
3044
3241
  }
3045
- expect(
3046
- SignatureEnvelope.validate({
3047
- inner: {
3048
- inner: primitive,
3049
- type: 'keychain',
3050
- userAddress: account,
3051
- version: 'v2',
3052
- },
3053
- type: 'keychain',
3054
- userAddress: account,
3055
- version: 'v1',
3056
- }),
3057
- ).toBe(true)
3058
3242
  })
3059
3243
  test('RPC rejects 64-byte values that resemble primitive signatures', () => {
3060
3244
  expect(() =>
@@ -27,6 +27,12 @@ const serializedKeychainType = '0x03'
27
27
  const serializedKeychainV2Type = '0x04'
28
28
  const serializedConfigurableType = '0x05'
29
29
 
30
+ /**
31
+ * Maximum WebAuthn signature size in bytes, excluding the type identifier
32
+ * (Tempo's `MAX_WEBAUTHN_SIGNATURE_LENGTH`).
33
+ */
34
+ const maxWebAuthnSize = 2048
35
+
30
36
  type EnvelopeOneOf<
31
37
  union extends object,
32
38
  keys extends PropertyKey,
@@ -307,7 +313,7 @@ export type Type = (typeof types)[number]
307
313
  * ```
308
314
  *
309
315
  * @param envelope - The signature envelope to assert.
310
- * @throws `CoercionError` if the envelope type cannot be determined.
316
+ * @throws `CoercionError` if the envelope type cannot be determined or is not supported.
311
317
  */
312
318
  export function assert(envelope: PartialBy<SignatureEnvelope, 'type'>): void {
313
319
  const type = getType(envelope)
@@ -362,7 +368,7 @@ export function assert(envelope: PartialBy<SignatureEnvelope, 'type'>): void {
362
368
 
363
369
  if (type === 'keychain') {
364
370
  const keychain = envelope as Keychain
365
- assertKeychainVersion(keychain)
371
+ assertKeychainInner(keychain)
366
372
  assert(keychain.inner)
367
373
  return
368
374
  }
@@ -372,6 +378,8 @@ export function assert(envelope: PartialBy<SignatureEnvelope, 'type'>): void {
372
378
  assertConfigurable(configurable)
373
379
  return
374
380
  }
381
+
382
+ throw new CoercionError({ envelope })
375
383
  }
376
384
 
377
385
  export declare namespace assert {
@@ -385,11 +393,13 @@ export declare namespace assert {
385
393
  | Errors.GlobalErrorType
386
394
  }
387
395
 
388
- function assertKeychainVersion(keychain: Keychain): void {
389
- if (keychain.version !== 'v1') return
390
- let inner = keychain.inner
391
- while (getType(inner) === 'keychain') inner = (inner as Keychain).inner
392
- if (getType(inner) === 'configurable')
396
+ function assertKeychainInner(keychain: Keychain): void {
397
+ const type = getType(keychain.inner)
398
+ if (type === 'keychain')
399
+ throw new InvalidApprovalError({
400
+ reason: 'keychain signatures cannot wrap a keychain signature',
401
+ })
402
+ if (keychain.version === 'v1' && type === 'configurable')
393
403
  throw new InvalidApprovalError({
394
404
  reason: 'configurable access keys require keychain V2',
395
405
  })
@@ -642,11 +652,17 @@ function deserialize_(value: Serialized): SignatureEnvelope {
642
652
  if (typeId === serializedWebAuthnType) {
643
653
  // WebAuthn: variable (webauthnData) + 32 (r) + 32 (s) + 32 (pubKeyX) + 32 (pubKeyY)
644
654
  // Minimum: 128 bytes (at least some authenticator data + signature components)
655
+ // Maximum: 2048 bytes
645
656
  if (dataSize < 128)
646
657
  throw new InvalidSerializedError({
647
658
  reason: `Invalid WebAuthn signature envelope size: expected at least 128 bytes, got ${dataSize} bytes`,
648
659
  serialized,
649
660
  })
661
+ if (dataSize > maxWebAuthnSize)
662
+ throw new InvalidSerializedError({
663
+ reason: `Invalid WebAuthn signature envelope size: expected at most ${maxWebAuthnSize} bytes, got ${dataSize} bytes`,
664
+ serialized,
665
+ })
650
666
 
651
667
  const webauthnDataSize = dataSize - 128
652
668
  const webauthnData = Hex.slice(data, 0, webauthnDataSize)
@@ -708,11 +724,22 @@ function deserialize_(value: Serialized): SignatureEnvelope {
708
724
  typeId === serializedKeychainV2Type
709
725
  ) {
710
726
  const userAddress = Hex.slice(data, 0, 20)
711
- const inner = deserialize_(Hex.slice(data, 20))
727
+ const inner = Hex.slice(data, 20)
728
+ // Reject nested keychains before decoding their contents.
729
+ if (
730
+ Hex.size(inner) !== 65 &&
731
+ [serializedKeychainType, serializedKeychainV2Type].includes(
732
+ Hex.slice(inner, 0, 1),
733
+ )
734
+ )
735
+ throw new InvalidSerializedError({
736
+ reason: 'keychain signatures cannot wrap a keychain signature',
737
+ serialized,
738
+ })
712
739
 
713
740
  const envelope = {
714
741
  userAddress,
715
- inner,
742
+ inner: deserialize_(inner),
716
743
  type: 'keychain',
717
744
  version: typeId === serializedKeychainV2Type ? 'v2' : 'v1',
718
745
  } satisfies Keychain
@@ -1079,6 +1106,13 @@ export function fromRpc(envelope: SignatureEnvelopeRpc): SignatureEnvelope {
1079
1106
  const webauthnData = envelope.webauthnData
1080
1107
  const webauthnDataSize = Hex.size(webauthnData)
1081
1108
 
1109
+ // The signature and public key take 128 bytes of the maximum size.
1110
+ if (webauthnDataSize > maxWebAuthnSize - 128)
1111
+ throw new InvalidSerializedError({
1112
+ reason: `Invalid WebAuthn data size: expected at most ${maxWebAuthnSize - 128} bytes, got ${webauthnDataSize} bytes`,
1113
+ serialized: webauthnData,
1114
+ })
1115
+
1082
1116
  // Parse webauthnData into authenticatorData and clientDataJSON
1083
1117
  let authenticatorData: Hex.Hex | undefined
1084
1118
  let clientDataJSON: string | undefined
@@ -1126,10 +1160,20 @@ export function fromRpc(envelope: SignatureEnvelopeRpc): SignatureEnvelope {
1126
1160
  ('userAddress' in envelope && 'signature' in envelope)
1127
1161
  ) {
1128
1162
  const keychain = envelope as KeychainRpc
1163
+ const { signature } = keychain
1164
+ // Reject nested keychains before decoding their contents.
1165
+ if (
1166
+ typeof signature === 'object' &&
1167
+ (signature.type === 'keychain' ||
1168
+ ('userAddress' in signature && 'signature' in signature))
1169
+ )
1170
+ throw new InvalidApprovalError({
1171
+ reason: 'keychain signatures cannot wrap a keychain signature',
1172
+ })
1129
1173
  const result = {
1130
1174
  type: 'keychain',
1131
1175
  userAddress: keychain.userAddress,
1132
- inner: fromRpc(keychain.signature),
1176
+ inner: fromRpc(signature),
1133
1177
  ...(keychain.keyId ? { keyId: keychain.keyId } : {}),
1134
1178
  ...(keychain.version ? { version: keychain.version } : {}),
1135
1179
  } satisfies Keychain
@@ -1460,7 +1504,7 @@ export function toRpc<const envelope extends toRpc.Input>(
1460
1504
 
1461
1505
  if (type === 'keychain') {
1462
1506
  const keychain = envelope as Keychain
1463
- assertKeychainVersion(keychain)
1507
+ assertKeychainInner(keychain)
1464
1508
  return {
1465
1509
  type: 'keychain',
1466
1510
  userAddress: keychain.userAddress,
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../../_types/tempo/SignaturePreAuthorized.d.ts",
4
+ "main": "../../_cjs/tempo/SignaturePreAuthorized.js",
5
+ "module": "../../_esm/tempo/SignaturePreAuthorized.js"
6
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "types": "../../_types/tempo/SignaturePreAuthorized.test-d.d.ts",
4
+ "main": "../../_cjs/tempo/SignaturePreAuthorized.test-d.js",
5
+ "module": "../../_esm/tempo/SignaturePreAuthorized.test-d.js"
6
+ }