ox 1.8.15 → 1.8.18

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 (292) hide show
  1. package/CHANGELOG.md +108 -0
  2. package/dist/core/AbiError.d.ts +52 -6
  3. package/dist/core/AbiError.d.ts.map +1 -1
  4. package/dist/core/AbiError.js +60 -4
  5. package/dist/core/AbiError.js.map +1 -1
  6. package/dist/core/AbiEvent.d.ts +5 -3
  7. package/dist/core/AbiEvent.d.ts.map +1 -1
  8. package/dist/core/AbiEvent.js +89 -58
  9. package/dist/core/AbiEvent.js.map +1 -1
  10. package/dist/core/AbiFunction.d.ts +48 -2
  11. package/dist/core/AbiFunction.d.ts.map +1 -1
  12. package/dist/core/AbiFunction.js +59 -3
  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 +15 -5
  16. package/dist/core/AbiItem.js.map +1 -1
  17. package/dist/core/AbiParameters.d.ts +1 -1
  18. package/dist/core/AbiParameters.d.ts.map +1 -1
  19. package/dist/core/AbiParameters.js +8 -2
  20. package/dist/core/AbiParameters.js.map +1 -1
  21. package/dist/core/Address.d.ts +17 -2
  22. package/dist/core/Address.d.ts.map +1 -1
  23. package/dist/core/Address.js +17 -1
  24. package/dist/core/Address.js.map +1 -1
  25. package/dist/core/Authorization.d.ts +24 -2
  26. package/dist/core/Authorization.d.ts.map +1 -1
  27. package/dist/core/Authorization.js +29 -2
  28. package/dist/core/Authorization.js.map +1 -1
  29. package/dist/core/Base58.d.ts.map +1 -1
  30. package/dist/core/Base58.js +16 -4
  31. package/dist/core/Base58.js.map +1 -1
  32. package/dist/core/Blobs.d.ts +2 -3
  33. package/dist/core/Blobs.d.ts.map +1 -1
  34. package/dist/core/Blobs.js +38 -43
  35. package/dist/core/Blobs.js.map +1 -1
  36. package/dist/core/Bytes.d.ts.map +1 -1
  37. package/dist/core/Bytes.js +10 -2
  38. package/dist/core/Bytes.js.map +1 -1
  39. package/dist/core/Cbor.d.ts +13 -6
  40. package/dist/core/Cbor.d.ts.map +1 -1
  41. package/dist/core/Cbor.js +31 -18
  42. package/dist/core/Cbor.js.map +1 -1
  43. package/dist/core/Ens.js +2 -2
  44. package/dist/core/Ens.js.map +1 -1
  45. package/dist/core/FrameReceipt.d.ts.map +1 -1
  46. package/dist/core/FrameReceipt.js +4 -1
  47. package/dist/core/FrameReceipt.js.map +1 -1
  48. package/dist/core/Hex.d.ts.map +1 -1
  49. package/dist/core/Hex.js +34 -31
  50. package/dist/core/Hex.js.map +1 -1
  51. package/dist/core/Keystore.d.ts +31 -2
  52. package/dist/core/Keystore.d.ts.map +1 -1
  53. package/dist/core/Keystore.js +28 -2
  54. package/dist/core/Keystore.js.map +1 -1
  55. package/dist/core/Rlp.d.ts +1 -1
  56. package/dist/core/Rlp.d.ts.map +1 -1
  57. package/dist/core/Rlp.js +107 -0
  58. package/dist/core/Rlp.js.map +1 -1
  59. package/dist/core/RpcTransport.d.ts.map +1 -1
  60. package/dist/core/RpcTransport.js +3 -1
  61. package/dist/core/RpcTransport.js.map +1 -1
  62. package/dist/core/Secp256k1.d.ts.map +1 -1
  63. package/dist/core/Secp256k1.js +4 -1
  64. package/dist/core/Secp256k1.js.map +1 -1
  65. package/dist/core/Signature.d.ts +1 -1
  66. package/dist/core/Signature.d.ts.map +1 -1
  67. package/dist/core/Signature.js +4 -2
  68. package/dist/core/Signature.js.map +1 -1
  69. package/dist/core/Siwe.d.ts +4 -0
  70. package/dist/core/Siwe.d.ts.map +1 -1
  71. package/dist/core/Siwe.js +29 -3
  72. package/dist/core/Siwe.js.map +1 -1
  73. package/dist/core/Transaction.d.ts.map +1 -1
  74. package/dist/core/Transaction.js +4 -2
  75. package/dist/core/Transaction.js.map +1 -1
  76. package/dist/core/TransactionReceipt.d.ts.map +1 -1
  77. package/dist/core/TransactionReceipt.js +8 -2
  78. package/dist/core/TransactionReceipt.js.map +1 -1
  79. package/dist/core/TxEnvelopeEip1559.d.ts.map +1 -1
  80. package/dist/core/TxEnvelopeEip1559.js +2 -1
  81. package/dist/core/TxEnvelopeEip1559.js.map +1 -1
  82. package/dist/core/TxEnvelopeEip2930.d.ts.map +1 -1
  83. package/dist/core/TxEnvelopeEip2930.js +2 -1
  84. package/dist/core/TxEnvelopeEip2930.js.map +1 -1
  85. package/dist/core/TxEnvelopeEip7702.d.ts +1 -1
  86. package/dist/core/TxEnvelopeEip7702.d.ts.map +1 -1
  87. package/dist/core/TxEnvelopeEip7702.js +6 -1
  88. package/dist/core/TxEnvelopeEip7702.js.map +1 -1
  89. package/dist/core/TxEnvelopeLegacy.d.ts.map +1 -1
  90. package/dist/core/TxEnvelopeLegacy.js +49 -7
  91. package/dist/core/TxEnvelopeLegacy.js.map +1 -1
  92. package/dist/core/TypedData.d.ts +3 -1
  93. package/dist/core/TypedData.d.ts.map +1 -1
  94. package/dist/core/TypedData.js +23 -11
  95. package/dist/core/TypedData.js.map +1 -1
  96. package/dist/core/Value.d.ts.map +1 -1
  97. package/dist/core/Value.js +14 -3
  98. package/dist/core/Value.js.map +1 -1
  99. package/dist/core/internal/abiParameters.d.ts +3 -3
  100. package/dist/core/internal/abiParameters.d.ts.map +1 -1
  101. package/dist/core/internal/abiParameters.js +99 -69
  102. package/dist/core/internal/abiParameters.js.map +1 -1
  103. package/dist/core/internal/base58.d.ts.map +1 -1
  104. package/dist/core/internal/base58.js +9 -3
  105. package/dist/core/internal/base58.js.map +1 -1
  106. package/dist/core/internal/caches.d.ts +6 -0
  107. package/dist/core/internal/caches.d.ts.map +1 -1
  108. package/dist/core/internal/caches.js +3 -1
  109. package/dist/core/internal/caches.js.map +1 -1
  110. package/dist/core/internal/codec/hex.d.ts +13 -0
  111. package/dist/core/internal/codec/hex.d.ts.map +1 -1
  112. package/dist/core/internal/codec/hex.js +25 -2
  113. package/dist/core/internal/codec/hex.js.map +1 -1
  114. package/dist/core/internal/codec/int.d.ts.map +1 -1
  115. package/dist/core/internal/codec/int.js +48 -32
  116. package/dist/core/internal/codec/int.js.map +1 -1
  117. package/dist/core/internal/cursor.d.ts +24 -4
  118. package/dist/core/internal/cursor.d.ts.map +1 -1
  119. package/dist/core/internal/cursor.js +62 -11
  120. package/dist/core/internal/cursor.js.map +1 -1
  121. package/dist/core/internal/lru.d.ts +11 -12
  122. package/dist/core/internal/lru.d.ts.map +1 -1
  123. package/dist/core/internal/lru.js +22 -32
  124. package/dist/core/internal/lru.js.map +1 -1
  125. package/dist/core/internal/promise.d.ts.map +1 -1
  126. package/dist/core/internal/promise.js +13 -7
  127. package/dist/core/internal/promise.js.map +1 -1
  128. package/dist/erc4337/UserOperation.d.ts.map +1 -1
  129. package/dist/erc4337/UserOperation.js +1 -3
  130. package/dist/erc4337/UserOperation.js.map +1 -1
  131. package/dist/erc6492/SignatureErc6492.d.ts +1 -1
  132. package/dist/erc6492/SignatureErc6492.d.ts.map +1 -1
  133. package/dist/erc6492/SignatureErc6492.js +1 -1
  134. package/dist/erc6492/SignatureErc6492.js.map +1 -1
  135. package/dist/erc7821/Execute.d.ts +45 -0
  136. package/dist/erc7821/Execute.d.ts.map +1 -1
  137. package/dist/erc7821/Execute.js +70 -2
  138. package/dist/erc7821/Execute.js.map +1 -1
  139. package/dist/index.d.ts +1 -1
  140. package/dist/index.js +1 -1
  141. package/dist/tempo/KeyAuthorization.d.ts +9 -3
  142. package/dist/tempo/KeyAuthorization.d.ts.map +1 -1
  143. package/dist/tempo/KeyAuthorization.js +16 -0
  144. package/dist/tempo/KeyAuthorization.js.map +1 -1
  145. package/dist/tempo/SignatureEnvelope.d.ts +1 -1
  146. package/dist/tempo/SignatureEnvelope.d.ts.map +1 -1
  147. package/dist/tempo/SignatureEnvelope.js +53 -54
  148. package/dist/tempo/SignatureEnvelope.js.map +1 -1
  149. package/dist/tempo/TransactionReceipt.d.ts.map +1 -1
  150. package/dist/tempo/TransactionReceipt.js +4 -1
  151. package/dist/tempo/TransactionReceipt.js.map +1 -1
  152. package/dist/tempo/TransactionRequest.d.ts +1 -1
  153. package/dist/tempo/TransactionRequest.d.ts.map +1 -1
  154. package/dist/tempo/TransactionRequest.js +5 -2
  155. package/dist/tempo/TransactionRequest.js.map +1 -1
  156. package/dist/tempo/TxEnvelopeTempo.d.ts +30 -1
  157. package/dist/tempo/TxEnvelopeTempo.d.ts.map +1 -1
  158. package/dist/tempo/TxEnvelopeTempo.js +51 -2
  159. package/dist/tempo/TxEnvelopeTempo.js.map +1 -1
  160. package/dist/tempo/ZoneId.d.ts +3 -1
  161. package/dist/tempo/ZoneId.d.ts.map +1 -1
  162. package/dist/tempo/ZoneId.js +7 -1
  163. package/dist/tempo/ZoneId.js.map +1 -1
  164. package/dist/tempo/internal/virtualMasterPool.d.ts.map +1 -1
  165. package/dist/tempo/internal/virtualMasterPool.js +17 -6
  166. package/dist/tempo/internal/virtualMasterPool.js.map +1 -1
  167. package/dist/tempo/internal/webauthnData.d.ts +23 -0
  168. package/dist/tempo/internal/webauthnData.d.ts.map +1 -0
  169. package/dist/tempo/internal/webauthnData.js +75 -0
  170. package/dist/tempo/internal/webauthnData.js.map +1 -0
  171. package/dist/webauthn/Registration.d.ts +2 -0
  172. package/dist/webauthn/Registration.d.ts.map +1 -1
  173. package/dist/webauthn/Registration.js +2 -6
  174. package/dist/webauthn/Registration.js.map +1 -1
  175. package/dist/zod/TypedData.d.ts +4 -4
  176. package/dist/zod/tempo/KeyAuthorization.d.ts.map +1 -1
  177. package/dist/zod/tempo/KeyAuthorization.js +4 -2
  178. package/dist/zod/tempo/KeyAuthorization.js.map +1 -1
  179. package/dist/zod/tempo/SignatureEnvelope.d.ts.map +1 -1
  180. package/dist/zod/tempo/SignatureEnvelope.js +29 -29
  181. package/dist/zod/tempo/SignatureEnvelope.js.map +1 -1
  182. package/package.json +2 -2
  183. package/src/core/AbiError.ts +82 -8
  184. package/src/core/AbiEvent.bench.ts +45 -0
  185. package/src/core/AbiEvent.ts +120 -68
  186. package/src/core/AbiFunction.bench.ts +16 -0
  187. package/src/core/AbiFunction.ts +76 -4
  188. package/src/core/AbiItem.ts +13 -4
  189. package/src/core/AbiParameters.bench.ts +33 -0
  190. package/src/core/AbiParameters.ts +8 -1
  191. package/src/core/Address.ts +18 -1
  192. package/src/core/Authorization.ts +34 -4
  193. package/src/core/Base58.bench.ts +28 -0
  194. package/src/core/Base58.ts +15 -4
  195. package/src/core/Blobs.bench.ts +40 -0
  196. package/src/core/Blobs.ts +47 -55
  197. package/src/core/Bytes.bench.ts +34 -0
  198. package/src/core/Bytes.ts +10 -2
  199. package/src/core/Cbor.ts +36 -14
  200. package/src/core/Ens.ts +2 -2
  201. package/src/core/FrameReceipt.ts +4 -1
  202. package/src/core/Hex.bench.ts +17 -0
  203. package/src/core/Hex.ts +29 -32
  204. package/src/core/Keystore.ts +40 -3
  205. package/src/core/Rlp.ts +139 -1
  206. package/src/core/Rlp_tx.bench.ts +55 -0
  207. package/src/core/RpcTransport.ts +3 -1
  208. package/src/core/Secp256k1.ts +4 -1
  209. package/src/core/Signature.ts +7 -3
  210. package/src/core/Siwe.ts +29 -3
  211. package/src/core/Transaction.ts +4 -2
  212. package/src/core/TransactionReceipt.ts +8 -2
  213. package/src/core/TxEnvelopeEip1559.ts +4 -1
  214. package/src/core/TxEnvelopeEip2930.ts +4 -1
  215. package/src/core/TxEnvelopeEip7702.ts +9 -2
  216. package/src/core/TxEnvelopeLegacy.ts +58 -7
  217. package/src/core/TypedData.bench.ts +50 -0
  218. package/src/core/TypedData.ts +24 -11
  219. package/src/core/Value.ts +14 -3
  220. package/src/core/_test/AbiError.test.ts +105 -2
  221. package/src/core/_test/AbiEvent.fuzz.ts +1 -1
  222. package/src/core/_test/AbiEvent.test-d.ts +46 -0
  223. package/src/core/_test/AbiEvent.test.ts +646 -11
  224. package/src/core/_test/AbiFunction.test.ts +79 -6
  225. package/src/core/_test/AbiParameters.adversarial.fuzz.ts +1 -0
  226. package/src/core/_test/AbiParameters.decode.test.ts +143 -0
  227. package/src/core/_test/AbiParameters.encode.test.ts +36 -1
  228. package/src/core/_test/AbiParameters.test.ts +15 -0
  229. package/src/core/_test/Address.test.ts +41 -0
  230. package/src/core/_test/Authorization.test.ts +130 -0
  231. package/src/core/_test/Bytes.test.ts +33 -0
  232. package/src/core/_test/Caches.test.ts +20 -1
  233. package/src/core/_test/Cbor.test.ts +26 -0
  234. package/src/core/_test/FrameReceipt.test.ts +13 -0
  235. package/src/core/_test/Keystore.test.ts +65 -1
  236. package/src/core/_test/Rlp.fuzz.ts +55 -1
  237. package/src/core/_test/Rlp.test.ts +64 -0
  238. package/src/core/_test/RpcTransport.test.ts +15 -2
  239. package/src/core/_test/Secp256k1.test.ts +36 -0
  240. package/src/core/_test/Signature.test.ts +102 -0
  241. package/src/core/_test/Siwe.test.ts +123 -0
  242. package/src/core/_test/Transaction.test.ts +17 -0
  243. package/src/core/_test/TransactionEnvelopeEip1559.test.ts +28 -0
  244. package/src/core/_test/TransactionEnvelopeEip2930.test.ts +28 -0
  245. package/src/core/_test/TransactionEnvelopeEip7702.test.ts +133 -0
  246. package/src/core/_test/TransactionEnvelopeLegacy.test.ts +322 -1
  247. package/src/core/_test/TransactionReceipt.test.ts +41 -0
  248. package/src/core/_test/TypedData.test.ts +197 -0
  249. package/src/core/_test/Value.test.ts +21 -0
  250. package/src/core/_test/internal/cursor.test.ts +71 -0
  251. package/src/core/internal/abiParameters.ts +123 -81
  252. package/src/core/internal/base58.ts +9 -3
  253. package/src/core/internal/caches.ts +3 -1
  254. package/src/core/internal/codec/hex.ts +27 -2
  255. package/src/core/internal/codec/int.ts +45 -32
  256. package/src/core/internal/cursor.ts +84 -19
  257. package/src/core/internal/lru.ts +21 -35
  258. package/src/core/internal/promise.ts +11 -5
  259. package/src/erc4337/UserOperation.ts +3 -4
  260. package/src/erc4337/_test/UserOperation.test.ts +59 -1
  261. package/src/erc6492/SignatureErc6492.ts +1 -1
  262. package/src/erc6492/_test/SignatureErc6492.test.ts +48 -1
  263. package/src/erc7821/Execute.ts +83 -2
  264. package/src/erc7821/_test/Execute.test.ts +217 -1
  265. package/src/index.ts +1 -1
  266. package/src/tempo/KeyAuthorization.test.ts +91 -0
  267. package/src/tempo/KeyAuthorization.ts +32 -3
  268. package/src/tempo/SignatureEnvelope.test.ts +300 -28
  269. package/src/tempo/SignatureEnvelope.ts +62 -54
  270. package/src/tempo/TransactionReceipt.test.ts +8 -0
  271. package/src/tempo/TransactionReceipt.ts +4 -1
  272. package/src/tempo/TransactionRequest.test.ts +30 -0
  273. package/src/tempo/TransactionRequest.ts +7 -2
  274. package/src/tempo/TxEnvelopeTempo.test.ts +310 -0
  275. package/src/tempo/TxEnvelopeTempo.ts +64 -1
  276. package/src/tempo/VirtualMaster.bench.ts +7 -0
  277. package/src/tempo/ZoneId.test.ts +11 -0
  278. package/src/tempo/ZoneId.ts +7 -1
  279. package/src/tempo/configurableAccounts.e2e.test.ts +1 -1
  280. package/src/tempo/internal/virtualMasterPool.ts +20 -6
  281. package/src/tempo/internal/webauthnData.ts +84 -0
  282. package/src/version.ts +1 -1
  283. package/src/webauthn/Registration.ts +4 -6
  284. package/src/webauthn/_test/Registration.browser.test.ts +14 -0
  285. package/src/webauthn/_test/Registration.test.ts +60 -0
  286. package/src/zod/tempo/KeyAuthorization.ts +12 -5
  287. package/src/zod/tempo/SignatureEnvelope.ts +38 -32
  288. package/src/zod/tempo/_test/KeyAuthorization.test.ts +36 -0
  289. package/src/zod/tempo/_test/SignatureEnvelope.test.ts +138 -4
  290. package/src/core/_test/internal/lru.test.ts +0 -38
  291. package/src/core/_test/internal/uid.test.ts +0 -7
  292. package/src/core/internal/uid.ts +0 -15
@@ -9,7 +9,7 @@ import {
9
9
  WebAuthnP256,
10
10
  WebCryptoP256,
11
11
  } from 'ox'
12
- import { describe, expect, test } from 'vp/test'
12
+ import { describe, expect, onTestFinished, test, vi } from 'vp/test'
13
13
  import * as AccountConfig from './AccountConfig.js'
14
14
  import * as SignatureEnvelope from './SignatureEnvelope.js'
15
15
 
@@ -453,6 +453,20 @@ describe('assert', () => {
453
453
  expect(() => SignatureEnvelope.assert(signatureWithoutType)).not.toThrow()
454
454
  })
455
455
 
456
+ test('error: throws on keychain inner signature', () => {
457
+ for (const version of ['v1', 'v2'] as const)
458
+ expect(() =>
459
+ SignatureEnvelope.assert({
460
+ inner: signature_keychain_secp256k1,
461
+ type: 'keychain',
462
+ userAddress: '0x1234567890123456789012345678901234567890',
463
+ version,
464
+ }),
465
+ ).toThrowErrorMatchingInlineSnapshot(
466
+ `[SignatureEnvelope.InvalidApprovalError: Invalid owner approval: keychain signatures cannot wrap a keychain signature.]`,
467
+ )
468
+ })
469
+
456
470
  test('error: throws on invalid inner signature', () => {
457
471
  expect(() =>
458
472
  SignatureEnvelope.assert({
@@ -488,6 +502,23 @@ describe('assert', () => {
488
502
  `[SignatureEnvelope.CoercionError: Unable to coerce value (\`{"r":"0x0000000000000000000000000000000000000000000000000000000000000000","s":"0x0000000000000000000000000000000000000000000000000000000000000000"}\`) to a valid signature envelope.]`,
489
503
  )
490
504
  })
505
+
506
+ test('error: throws on unsupported type', () => {
507
+ expect(() =>
508
+ SignatureEnvelope.assert({ type: 'webauthn' } as any),
509
+ ).toThrowErrorMatchingInlineSnapshot(
510
+ `[SignatureEnvelope.CoercionError: Unable to coerce value (\`{"type":"webauthn"}\`) to a valid signature envelope.]`,
511
+ )
512
+ expect(() =>
513
+ SignatureEnvelope.assert({
514
+ inner: { type: 'bogus' },
515
+ type: 'keychain',
516
+ userAddress: '0x1234567890123456789012345678901234567890',
517
+ } as any),
518
+ ).toThrowErrorMatchingInlineSnapshot(
519
+ `[SignatureEnvelope.CoercionError: Unable to coerce value (\`{"type":"bogus"}\`) to a valid signature envelope.]`,
520
+ )
521
+ })
491
522
  })
492
523
 
493
524
  describe('deserialize', () => {
@@ -662,6 +693,42 @@ describe('deserialize', () => {
662
693
  )
663
694
  })
664
695
 
696
+ test('error: throws on WebAuthn signature above the maximum size', () => {
697
+ const authenticatorData = `0x${'00'.repeat(37)}` as const
698
+ // 37 (authenticatorData) + 1883 (clientDataJSON) + 128 = 2048 bytes
699
+ const max = {
700
+ ...signature_webauthn,
701
+ metadata: {
702
+ authenticatorData,
703
+ clientDataJSON: JSON.stringify({ challenge: 'a'.repeat(1867) }),
704
+ },
705
+ }
706
+ const serialized = SignatureEnvelope.serialize(max)
707
+ expect(Hex.size(serialized)).toMatchInlineSnapshot(`2049`)
708
+ expect(SignatureEnvelope.deserialize(serialized)).toMatchObject({
709
+ metadata: max.metadata,
710
+ })
711
+
712
+ expect(() =>
713
+ SignatureEnvelope.deserialize(
714
+ SignatureEnvelope.serialize({
715
+ ...max,
716
+ metadata: {
717
+ authenticatorData,
718
+ clientDataJSON: JSON.stringify({ challenge: 'a'.repeat(1868) }),
719
+ },
720
+ }),
721
+ ),
722
+ ).toThrow(
723
+ 'Invalid WebAuthn signature envelope size: expected at most 2048 bytes, got 2049 bytes',
724
+ )
725
+ expect(() =>
726
+ SignatureEnvelope.deserialize(`0x02${'41'.repeat(40_000)}`),
727
+ ).toThrow(
728
+ 'Invalid WebAuthn signature envelope size: expected at most 2048 bytes, got 40000 bytes',
729
+ )
730
+ })
731
+
665
732
  test('error: throws on invalid clientDataJSON', () => {
666
733
  // Create a signature with invalid JSON (not properly formatted)
667
734
  const invalidMetadata = {
@@ -684,6 +751,58 @@ describe('deserialize', () => {
684
751
  )
685
752
  })
686
753
 
754
+ test('behavior: splits webauthnData at the object that ends it', () => {
755
+ const metadata = {
756
+ // Ends with bytes that look like the start of a JSON object.
757
+ authenticatorData: Hex.concat(
758
+ signature_webauthn.metadata.authenticatorData,
759
+ Hex.fromString('{"a":"}\\'),
760
+ ),
761
+ // Braces, an escaped quote and an escaped backslash inside strings.
762
+ clientDataJSON: JSON.stringify({
763
+ challenge: '{"}\\',
764
+ nested: { origin: '\\"' },
765
+ }),
766
+ }
767
+ expect(
768
+ SignatureEnvelope.deserialize(
769
+ SignatureEnvelope.serialize({ ...signature_webauthn, metadata }),
770
+ ),
771
+ ).toMatchObject({ metadata })
772
+ })
773
+
774
+ test('behavior: decodes and parses webauthnData at most once', () => {
775
+ // Each opening brace starts an object that only fails to parse past its
776
+ // end, so a search that tries every split offset reads all of it each time.
777
+ const clientDataJSON = `${'{"a":'.repeat(313)}${'}'.repeat(313)}`
778
+ const serialized = SignatureEnvelope.serialize({
779
+ ...signature_webauthn,
780
+ metadata: {
781
+ authenticatorData: `0x${'00'.repeat(37)}` as const,
782
+ clientDataJSON,
783
+ },
784
+ })
785
+
786
+ const decode = vi.spyOn(TextDecoder.prototype, 'decode')
787
+ const parse = vi.spyOn(JSON, 'parse')
788
+ onTestFinished(() => {
789
+ vi.restoreAllMocks()
790
+ })
791
+
792
+ expect(() => SignatureEnvelope.deserialize(serialized)).toThrow(
793
+ 'Unable to parse WebAuthn metadata',
794
+ )
795
+ expect(
796
+ decode.mock.calls.reduce(
797
+ (size, [input]) => size + (input?.byteLength ?? 0),
798
+ 0,
799
+ ),
800
+ ).toBeLessThanOrEqual(clientDataJSON.length)
801
+ expect(
802
+ parse.mock.calls.reduce((size, [text]) => size + text.length, 0),
803
+ ).toBeLessThanOrEqual(clientDataJSON.length)
804
+ })
805
+
687
806
  test('error: throws on unknown type identifier', () => {
688
807
  const unknownType = `0xff${'00'.repeat(129)}` as const
689
808
  expect(() =>
@@ -783,6 +902,48 @@ describe('deserialize', () => {
783
902
  })
784
903
  })
785
904
 
905
+ test('behavior: deserializes 65-byte inner starting with a keychain type as secp256k1', () => {
906
+ const userAddress = '0x1234567890123456789012345678901234567890'
907
+ const inner = `0x03${'11'.repeat(31)}${'22'.repeat(32)}1b` as const
908
+ expect(
909
+ SignatureEnvelope.deserialize(Hex.concat('0x04', userAddress, inner)),
910
+ ).toMatchInlineSnapshot(`
911
+ {
912
+ "inner": {
913
+ "signature": {
914
+ "r": "0x0311111111111111111111111111111111111111111111111111111111111111",
915
+ "s": "0x2222222222222222222222222222222222222222222222222222222222222222",
916
+ "yParity": 0,
917
+ },
918
+ "type": "secp256k1",
919
+ },
920
+ "type": "keychain",
921
+ "userAddress": "0x1234567890123456789012345678901234567890",
922
+ "version": "v2",
923
+ }
924
+ `)
925
+ })
926
+
927
+ test('error: throws on keychain inner signature', () => {
928
+ const userAddress = '0x1234567890123456789012345678901234567890'
929
+ const inner = SignatureEnvelope.serialize(signature_keychain_secp256k1)
930
+ for (const typeId of ['0x03', '0x04'] as const)
931
+ expect(() =>
932
+ SignatureEnvelope.deserialize(Hex.concat(typeId, userAddress, inner)),
933
+ ).toThrow(
934
+ 'Unable to deserialize signature envelope: keychain signatures cannot wrap a keychain signature',
935
+ )
936
+
937
+ // 2000 nested keychains
938
+ const nested = Hex.concat(
939
+ `0x${`03${userAddress.slice(2)}`.repeat(2000)}`,
940
+ Signature.toHex(signature_secp256k1),
941
+ )
942
+ expect(() => SignatureEnvelope.deserialize(nested)).toThrow(
943
+ SignatureEnvelope.InvalidSerializedError,
944
+ )
945
+ })
946
+
786
947
  test('error: throws on invalid keychain signature length', () => {
787
948
  // Keychain signature too short (must be at least 21 bytes: 1 type + 20 address)
788
949
  const invalidSig = `0x03${'00'.repeat(10)}` as const
@@ -1931,6 +2092,17 @@ describe('validate', () => {
1931
2092
  expect(SignatureEnvelope.validate({} as any)).toBe(false)
1932
2093
  })
1933
2094
 
2095
+ test('behavior: returns false for unsupported type', () => {
2096
+ expect(SignatureEnvelope.validate({ type: 'webauthn' } as any)).toBe(false)
2097
+ expect(
2098
+ SignatureEnvelope.validate({
2099
+ inner: { type: 'bogus' },
2100
+ type: 'keychain',
2101
+ userAddress: '0x1234567890123456789012345678901234567890',
2102
+ } as any),
2103
+ ).toBe(false)
2104
+ })
2105
+
1934
2106
  test('behavior: returns false for incomplete signature', () => {
1935
2107
  expect(
1936
2108
  SignatureEnvelope.validate({
@@ -2319,6 +2491,85 @@ describe('fromRpc', () => {
2319
2491
  type: 'webAuthn',
2320
2492
  })
2321
2493
  })
2494
+
2495
+ test('behavior: decodes and parses webauthnData at most once', () => {
2496
+ // Each opening brace starts an object that only fails to parse past its
2497
+ // end, so a search that tries every split offset reads all of it each time.
2498
+ const clientDataJSON = `${'{"a":'.repeat(313)}${'}'.repeat(313)}`
2499
+ const rpc = {
2500
+ pubKeyX: publicKey.x,
2501
+ pubKeyY: publicKey.y,
2502
+ r: p256Signature.r,
2503
+ s: p256Signature.s,
2504
+ type: 'webAuthn',
2505
+ webauthnData: Hex.concat(
2506
+ `0x${'00'.repeat(37)}`,
2507
+ Hex.fromString(clientDataJSON),
2508
+ ),
2509
+ } as const
2510
+
2511
+ const decode = vi.spyOn(TextDecoder.prototype, 'decode')
2512
+ const parse = vi.spyOn(JSON, 'parse')
2513
+ onTestFinished(() => {
2514
+ vi.restoreAllMocks()
2515
+ })
2516
+
2517
+ expect(() => SignatureEnvelope.fromRpc(rpc)).toThrow(
2518
+ 'Unable to parse WebAuthn metadata',
2519
+ )
2520
+ expect(
2521
+ decode.mock.calls.reduce(
2522
+ (size, [input]) => size + (input?.byteLength ?? 0),
2523
+ 0,
2524
+ ),
2525
+ ).toBeLessThanOrEqual(clientDataJSON.length)
2526
+ expect(
2527
+ parse.mock.calls.reduce((size, [text]) => size + text.length, 0),
2528
+ ).toBeLessThanOrEqual(clientDataJSON.length)
2529
+ })
2530
+
2531
+ test('error: throws on WebAuthn data above the maximum size', () => {
2532
+ const rpc = {
2533
+ pubKeyX: publicKey.x,
2534
+ pubKeyY: publicKey.y,
2535
+ r: p256Signature.r,
2536
+ s: p256Signature.s,
2537
+ type: 'webAuthn',
2538
+ } as const
2539
+ const authenticatorData = `0x${'00'.repeat(37)}` as const
2540
+ const clientDataJSON = JSON.stringify({ challenge: 'a'.repeat(1867) })
2541
+
2542
+ // 37 (authenticatorData) + 1883 (clientDataJSON) = 1920 bytes
2543
+ expect(
2544
+ SignatureEnvelope.fromRpc({
2545
+ ...rpc,
2546
+ webauthnData: Hex.concat(
2547
+ authenticatorData,
2548
+ Hex.fromString(clientDataJSON),
2549
+ ),
2550
+ }),
2551
+ ).toMatchObject({ metadata: { authenticatorData, clientDataJSON } })
2552
+
2553
+ expect(() =>
2554
+ SignatureEnvelope.fromRpc({
2555
+ ...rpc,
2556
+ webauthnData: Hex.concat(
2557
+ authenticatorData,
2558
+ Hex.fromString(JSON.stringify({ challenge: 'a'.repeat(1868) })),
2559
+ ),
2560
+ }),
2561
+ ).toThrow(
2562
+ 'Invalid WebAuthn data size: expected at most 1920 bytes, got 1921 bytes',
2563
+ )
2564
+ expect(() =>
2565
+ SignatureEnvelope.fromRpc({
2566
+ ...rpc,
2567
+ webauthnData: `0x${'41'.repeat(40_000)}`,
2568
+ }),
2569
+ ).toThrow(
2570
+ 'Invalid WebAuthn data size: expected at most 1920 bytes, got 40000 bytes',
2571
+ )
2572
+ })
2322
2573
  })
2323
2574
 
2324
2575
  describe('keychain', () => {
@@ -2449,6 +2700,36 @@ describe('fromRpc', () => {
2449
2700
 
2450
2701
  expect(envelope.keyId).toBe('0xbe95c3f554e9fc85ec51be69a3d807a0d55bcf2c')
2451
2702
  })
2703
+
2704
+ test('error: throws on keychain inner signature', () => {
2705
+ const inner = {
2706
+ signature: {
2707
+ r: '0xa2bb71146c20ce932456c043ebb2973ed205e07cd32c35a60bdefca1285fd132',
2708
+ s: '0x7cba10692bccdbfba9a215418443c2903dbee6fe5cb55c91172e47efc607840e',
2709
+ type: 'secp256k1',
2710
+ yParity: '0x1',
2711
+ },
2712
+ userAddress: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
2713
+ } as const
2714
+ expect(() =>
2715
+ SignatureEnvelope.fromRpc({
2716
+ signature: { ...inner, type: 'keychain' },
2717
+ type: 'keychain',
2718
+ userAddress: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
2719
+ }),
2720
+ ).toThrowErrorMatchingInlineSnapshot(
2721
+ `[SignatureEnvelope.InvalidApprovalError: Invalid owner approval: keychain signatures cannot wrap a keychain signature.]`,
2722
+ )
2723
+ // inner keychain without an explicit type
2724
+ expect(() =>
2725
+ SignatureEnvelope.fromRpc({
2726
+ signature: inner as never,
2727
+ type: 'keychain',
2728
+ userAddress: '0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266',
2729
+ version: 'v1',
2730
+ }),
2731
+ ).toThrow(SignatureEnvelope.InvalidApprovalError)
2732
+ })
2452
2733
  })
2453
2734
  })
2454
2735
 
@@ -3034,18 +3315,21 @@ describe('configurable', () => {
3034
3315
  }),
3035
3316
  ).toThrowError(SignatureEnvelope.InvalidApprovalError)
3036
3317
  })
3037
- test('rejects V1 wrappers around recursively nested configurable delegates', () => {
3038
- let inner: SignatureEnvelope.SignatureEnvelope = envelope
3039
- for (let depth = 0; depth < 3; depth++) {
3040
- inner = { inner, type: 'keychain', userAddress: account, version: 'v2' }
3041
- const valid: SignatureEnvelope.Keychain = {
3318
+ test('rejects keychain wrappers around keychain-wrapped configurable delegates', () => {
3319
+ const inner: SignatureEnvelope.Keychain = {
3320
+ inner: envelope,
3321
+ type: 'keychain',
3322
+ userAddress: account,
3323
+ version: 'v2',
3324
+ }
3325
+ expect(SignatureEnvelope.validate(inner)).toBe(true)
3326
+ for (const version of ['v1', 'v2'] as const) {
3327
+ const invalid: SignatureEnvelope.Keychain = {
3042
3328
  inner,
3043
3329
  type: 'keychain',
3044
3330
  userAddress: account,
3045
- version: 'v2',
3331
+ version,
3046
3332
  }
3047
- const invalid = { ...valid, version: 'v1' } as const
3048
- expect(SignatureEnvelope.validate(valid)).toBe(true)
3049
3333
  expect(SignatureEnvelope.validate(invalid)).toBe(false)
3050
3334
  expect(() => SignatureEnvelope.serialize(invalid)).toThrowError(
3051
3335
  SignatureEnvelope.InvalidApprovalError,
@@ -3057,32 +3341,20 @@ describe('configurable', () => {
3057
3341
  SignatureEnvelope.fromRpc({
3058
3342
  type: 'keychain',
3059
3343
  userAddress: account,
3060
- version: 'v1',
3344
+ version,
3061
3345
  signature: SignatureEnvelope.toRpc(inner),
3062
3346
  }),
3063
3347
  ).toThrowError(SignatureEnvelope.InvalidApprovalError)
3064
3348
  expect(() =>
3065
3349
  SignatureEnvelope.deserialize(
3066
- Hex.concat('0x03', account, SignatureEnvelope.serialize(inner)),
3350
+ Hex.concat(
3351
+ version === 'v1' ? '0x03' : '0x04',
3352
+ account,
3353
+ SignatureEnvelope.serialize(inner),
3354
+ ),
3067
3355
  ),
3068
- ).toThrowError(SignatureEnvelope.InvalidApprovalError)
3069
- expect(() =>
3070
- SignatureEnvelope.serialize({ ...valid, inner: invalid }),
3071
- ).toThrowError(SignatureEnvelope.InvalidApprovalError)
3356
+ ).toThrowError(SignatureEnvelope.InvalidSerializedError)
3072
3357
  }
3073
- expect(
3074
- SignatureEnvelope.validate({
3075
- inner: {
3076
- inner: primitive,
3077
- type: 'keychain',
3078
- userAddress: account,
3079
- version: 'v2',
3080
- },
3081
- type: 'keychain',
3082
- userAddress: account,
3083
- version: 'v1',
3084
- }),
3085
- ).toBe(true)
3086
3358
  })
3087
3359
  test('RPC rejects 64-byte values that resemble primitive signatures', () => {
3088
3360
  expect(() =>
@@ -19,6 +19,7 @@ import * as Signature from '../core/Signature.js'
19
19
  import type * as WebAuthnP256 from '../core/WebAuthnP256.js'
20
20
  import * as ox_WebAuthnP256 from '../core/WebAuthnP256.js'
21
21
  import * as AccountConfig from './AccountConfig.js'
22
+ import * as WebauthnData from './internal/webauthnData.js'
22
23
 
23
24
  /** Signature type identifiers for encoding/decoding */
24
25
  const serializedP256Type = '0x01'
@@ -27,6 +28,12 @@ const serializedKeychainType = '0x03'
27
28
  const serializedKeychainV2Type = '0x04'
28
29
  const serializedConfigurableType = '0x05'
29
30
 
31
+ /**
32
+ * Maximum WebAuthn signature size in bytes, excluding the type identifier
33
+ * (Tempo's `MAX_WEBAUTHN_SIGNATURE_LENGTH`).
34
+ */
35
+ const maxWebAuthnSize = 2048
36
+
30
37
  /** Serialized magic identifier for Tempo signature envelopes. */
31
38
  export const magicBytes =
32
39
  '0x7777777777777777777777777777777777777777777777777777777777777777' // 32 "T"s
@@ -271,7 +278,7 @@ export type Type = (typeof types)[number]
271
278
  * ```
272
279
  *
273
280
  * @param envelope - The signature envelope to assert.
274
- * @throws `CoercionError` if the envelope type cannot be determined.
281
+ * @throws `CoercionError` if the envelope type cannot be determined or is not supported.
275
282
  */
276
283
  export function assert(envelope: PartialBy<SignatureEnvelope, 'type'>): void {
277
284
  const type = getType(envelope)
@@ -326,7 +333,7 @@ export function assert(envelope: PartialBy<SignatureEnvelope, 'type'>): void {
326
333
 
327
334
  if (type === 'keychain') {
328
335
  const keychain = envelope as Keychain
329
- assertKeychainVersion(keychain)
336
+ assertKeychainInner(keychain)
330
337
  assert(keychain.inner)
331
338
  return
332
339
  }
@@ -336,6 +343,8 @@ export function assert(envelope: PartialBy<SignatureEnvelope, 'type'>): void {
336
343
  assertConfigurable(configurable)
337
344
  return
338
345
  }
346
+
347
+ throw new CoercionError({ envelope })
339
348
  }
340
349
 
341
350
  export declare namespace assert {
@@ -349,11 +358,13 @@ export declare namespace assert {
349
358
  | Errors.GlobalErrorType
350
359
  }
351
360
 
352
- function assertKeychainVersion(keychain: Keychain): void {
353
- if (keychain.version !== 'v1') return
354
- let inner = keychain.inner
355
- while (getType(inner) === 'keychain') inner = (inner as Keychain).inner
356
- if (getType(inner) === 'configurable')
361
+ function assertKeychainInner(keychain: Keychain): void {
362
+ const type = getType(keychain.inner)
363
+ if (type === 'keychain')
364
+ throw new InvalidApprovalError({
365
+ reason: 'keychain signatures cannot wrap a keychain signature',
366
+ })
367
+ if (keychain.version === 'v1' && type === 'configurable')
357
368
  throw new InvalidApprovalError({
358
369
  reason: 'configurable access keys require keychain V2',
359
370
  })
@@ -614,35 +625,25 @@ function deserialize_(value: Serialized): SignatureEnvelope {
614
625
  if (typeId === serializedWebAuthnType) {
615
626
  // WebAuthn: variable (webauthnData) + 32 (r) + 32 (s) + 32 (pubKeyX) + 32 (pubKeyY)
616
627
  // Minimum: 128 bytes (at least some authenticator data + signature components)
628
+ // Maximum: 2048 bytes
617
629
  if (dataSize < 128)
618
630
  throw new InvalidSerializedError({
619
631
  reason: `Invalid WebAuthn signature envelope size: expected at least 128 bytes, got ${dataSize} bytes`,
620
632
  serialized,
621
633
  })
634
+ if (dataSize > maxWebAuthnSize)
635
+ throw new InvalidSerializedError({
636
+ reason: `Invalid WebAuthn signature envelope size: expected at most ${maxWebAuthnSize} bytes, got ${dataSize} bytes`,
637
+ serialized,
638
+ })
622
639
 
623
640
  const webauthnDataSize = dataSize - 128
624
641
  const webauthnData = Hex.slice(data, 0, webauthnDataSize)
625
642
 
626
643
  // Parse webauthnData into authenticatorData and clientDataJSON
627
644
  // According to the Rust code, it's authenticatorData || clientDataJSON
628
- // We need to find the split point (minimum authenticatorData is 37 bytes)
629
- let authenticatorData: Hex.Hex | undefined
630
- let clientDataJSON: string | undefined
631
-
632
- // Try to find the JSON start (clientDataJSON should start with '{')
633
- for (let split = 37; split < webauthnDataSize; split++) {
634
- const potentialJson = Hex.toString(Hex.slice(webauthnData, split))
635
- if (potentialJson.startsWith('{') && potentialJson.endsWith('}')) {
636
- try {
637
- JSON.parse(potentialJson)
638
- authenticatorData = Hex.slice(webauthnData, 0, split)
639
- clientDataJSON = potentialJson
640
- break
641
- } catch {}
642
- }
643
- }
644
-
645
- if (!authenticatorData || !clientDataJSON)
645
+ const metadata = WebauthnData.split(webauthnData)
646
+ if (!metadata)
646
647
  throw new InvalidSerializedError({
647
648
  reason:
648
649
  'Unable to parse WebAuthn metadata: could not extract valid authenticatorData and clientDataJSON',
@@ -655,10 +656,7 @@ function deserialize_(value: Serialized): SignatureEnvelope {
655
656
  x: Hex.slice(data, webauthnDataSize + 64, webauthnDataSize + 96),
656
657
  y: Hex.slice(data, webauthnDataSize + 96, webauthnDataSize + 128),
657
658
  },
658
- metadata: {
659
- authenticatorData,
660
- clientDataJSON,
661
- },
659
+ metadata,
662
660
  signature: {
663
661
  r: Hex.slice(data, webauthnDataSize, webauthnDataSize + 32),
664
662
  s: Hex.slice(data, webauthnDataSize + 32, webauthnDataSize + 64),
@@ -672,11 +670,22 @@ function deserialize_(value: Serialized): SignatureEnvelope {
672
670
  typeId === serializedKeychainV2Type
673
671
  ) {
674
672
  const userAddress = Hex.slice(data, 0, 20)
675
- const inner = deserialize_(Hex.slice(data, 20))
673
+ const inner = Hex.slice(data, 20)
674
+ // Reject nested keychains before decoding their contents.
675
+ if (
676
+ Hex.size(inner) !== 65 &&
677
+ [serializedKeychainType, serializedKeychainV2Type].includes(
678
+ Hex.slice(inner, 0, 1),
679
+ )
680
+ )
681
+ throw new InvalidSerializedError({
682
+ reason: 'keychain signatures cannot wrap a keychain signature',
683
+ serialized,
684
+ })
676
685
 
677
686
  const envelope = {
678
687
  userAddress,
679
- inner,
688
+ inner: deserialize_(inner),
680
689
  type: 'keychain',
681
690
  version: typeId === serializedKeychainV2Type ? 'v2' : 'v1',
682
691
  } satisfies Keychain
@@ -1060,24 +1069,16 @@ export function fromRpc(envelope: SignatureEnvelopeRpc): SignatureEnvelope {
1060
1069
  const webauthnData = envelope.webauthnData
1061
1070
  const webauthnDataSize = Hex.size(webauthnData)
1062
1071
 
1063
- // Parse webauthnData into authenticatorData and clientDataJSON
1064
- let authenticatorData: Hex.Hex | undefined
1065
- let clientDataJSON: string | undefined
1066
-
1067
- // Try to find the JSON start (clientDataJSON should start with '{')
1068
- for (let split = 37; split < webauthnDataSize; split++) {
1069
- const potentialJson = Hex.toString(Hex.slice(webauthnData, split))
1070
- if (potentialJson.startsWith('{') && potentialJson.endsWith('}')) {
1071
- try {
1072
- JSON.parse(potentialJson)
1073
- authenticatorData = Hex.slice(webauthnData, 0, split)
1074
- clientDataJSON = potentialJson
1075
- break
1076
- } catch {}
1077
- }
1078
- }
1072
+ // The signature and public key take 128 bytes of the maximum size.
1073
+ if (webauthnDataSize > maxWebAuthnSize - 128)
1074
+ throw new InvalidSerializedError({
1075
+ reason: `Invalid WebAuthn data size: expected at most ${maxWebAuthnSize - 128} bytes, got ${webauthnDataSize} bytes`,
1076
+ serialized: webauthnData,
1077
+ })
1079
1078
 
1080
- if (!authenticatorData || !clientDataJSON)
1079
+ // Parse webauthnData into authenticatorData and clientDataJSON
1080
+ const metadata = WebauthnData.split(webauthnData)
1081
+ if (!metadata)
1081
1082
  throw new InvalidSerializedError({
1082
1083
  reason:
1083
1084
  'Unable to parse WebAuthn metadata: could not extract valid authenticatorData and clientDataJSON',
@@ -1085,10 +1086,7 @@ export function fromRpc(envelope: SignatureEnvelopeRpc): SignatureEnvelope {
1085
1086
  })
1086
1087
 
1087
1088
  return {
1088
- metadata: {
1089
- authenticatorData,
1090
- clientDataJSON,
1091
- },
1089
+ metadata,
1092
1090
  publicKey: {
1093
1091
  prefix: 4,
1094
1092
  x: Hex.padLeft(envelope.pubKeyX, 32),
@@ -1107,10 +1105,20 @@ export function fromRpc(envelope: SignatureEnvelopeRpc): SignatureEnvelope {
1107
1105
  ('userAddress' in envelope && 'signature' in envelope)
1108
1106
  ) {
1109
1107
  const keychain = envelope as KeychainRpc
1108
+ const { signature } = keychain
1109
+ // Reject nested keychains before decoding their contents.
1110
+ if (
1111
+ typeof signature === 'object' &&
1112
+ (signature.type === 'keychain' ||
1113
+ ('userAddress' in signature && 'signature' in signature))
1114
+ )
1115
+ throw new InvalidApprovalError({
1116
+ reason: 'keychain signatures cannot wrap a keychain signature',
1117
+ })
1110
1118
  const result = {
1111
1119
  type: 'keychain',
1112
1120
  userAddress: keychain.userAddress,
1113
- inner: fromRpc(keychain.signature),
1121
+ inner: fromRpc(signature),
1114
1122
  ...(keychain.keyId ? { keyId: keychain.keyId } : {}),
1115
1123
  ...(keychain.version ? { version: keychain.version } : {}),
1116
1124
  } satisfies Keychain
@@ -1453,7 +1461,7 @@ export function toRpc<const envelope extends toRpc.Input>(
1453
1461
 
1454
1462
  if (type === 'keychain') {
1455
1463
  const keychain = envelope as Keychain
1456
- assertKeychainVersion(keychain)
1464
+ assertKeychainInner(keychain)
1457
1465
  return {
1458
1466
  type: 'keychain',
1459
1467
  userAddress: keychain.userAddress,
@@ -23,6 +23,14 @@ const rpc = {
23
23
  } as const satisfies TransactionReceipt.Rpc
24
24
 
25
25
  describe('fromRpc', () => {
26
+ test('behavior: unknown type named like an `Object.prototype` key', () => {
27
+ for (const type of ['toString', '__proto__'])
28
+ expect(
29
+ TransactionReceipt.fromRpc({ ...rpc, type } as TransactionReceipt.Rpc)
30
+ .type,
31
+ ).toBe(type)
32
+ })
33
+
26
34
  test('default', () => {
27
35
  const receipt = TransactionReceipt.fromRpc(rpc)
28
36
  expect(receipt).toMatchInlineSnapshot(`
@@ -124,7 +124,10 @@ export function fromRpc<const receipt extends Rpc | null>(
124
124
  if (!decoded) return null as never
125
125
  return {
126
126
  ...decoded,
127
- type: (fromRpcType as any)[receipt!.type] ?? receipt!.type,
127
+ // Own keys only: an inherited one such as `toString` is not a type.
128
+ type: Object.hasOwn(fromRpcType, receipt!.type)
129
+ ? fromRpcType[receipt!.type as keyof typeof fromRpcType]
130
+ : receipt!.type,
128
131
  } as never
129
132
  }
130
133