ox 1.1.2 → 1.3.0

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 (296) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/dist/core/AbiFunction.d.ts +1 -1
  3. package/dist/core/AbiFunction.d.ts.map +1 -1
  4. package/dist/core/AbiFunction.js +6 -2
  5. package/dist/core/AbiFunction.js.map +1 -1
  6. package/dist/core/AbiParameters.d.ts +1 -1
  7. package/dist/core/AbiParameters.d.ts.map +1 -1
  8. package/dist/core/AbiParameters.js +1 -13
  9. package/dist/core/AbiParameters.js.map +1 -1
  10. package/dist/core/AesGcm.d.ts +36 -1
  11. package/dist/core/AesGcm.d.ts.map +1 -1
  12. package/dist/core/AesGcm.js +44 -0
  13. package/dist/core/AesGcm.js.map +1 -1
  14. package/dist/core/Ed25519.d.ts +46 -1
  15. package/dist/core/Ed25519.d.ts.map +1 -1
  16. package/dist/core/Ed25519.js +43 -0
  17. package/dist/core/Ed25519.js.map +1 -1
  18. package/dist/core/Engine.d.ts +1 -1
  19. package/dist/core/Engine.d.ts.map +1 -1
  20. package/dist/core/Engine.js.map +1 -1
  21. package/dist/core/Hash.d.ts +200 -1
  22. package/dist/core/Hash.d.ts.map +1 -1
  23. package/dist/core/Hash.js +207 -0
  24. package/dist/core/Hash.js.map +1 -1
  25. package/dist/core/Hex.d.ts.map +1 -1
  26. package/dist/core/Hex.js +1 -4
  27. package/dist/core/Hex.js.map +1 -1
  28. package/dist/core/Rlp.d.ts +32 -0
  29. package/dist/core/Rlp.d.ts.map +1 -1
  30. package/dist/core/Rlp.js +146 -0
  31. package/dist/core/Rlp.js.map +1 -1
  32. package/dist/core/Secp256k1.d.ts +46 -1
  33. package/dist/core/Secp256k1.d.ts.map +1 -1
  34. package/dist/core/Secp256k1.js +48 -0
  35. package/dist/core/Secp256k1.js.map +1 -1
  36. package/dist/core/WebAuthn.d.ts +224 -0
  37. package/dist/core/WebAuthn.d.ts.map +1 -0
  38. package/dist/core/WebAuthn.js +343 -0
  39. package/dist/core/WebAuthn.js.map +1 -0
  40. package/dist/core/WebAuthnP256.d.ts +46 -50
  41. package/dist/core/WebAuthnP256.d.ts.map +1 -1
  42. package/dist/core/WebAuthnP256.js +44 -50
  43. package/dist/core/WebAuthnP256.js.map +1 -1
  44. package/dist/core/internal/abiParameters.d.ts +7 -87
  45. package/dist/core/internal/abiParameters.d.ts.map +1 -1
  46. package/dist/core/internal/abiParameters.js +339 -194
  47. package/dist/core/internal/abiParameters.js.map +1 -1
  48. package/dist/core/internal/engine.d.ts +35 -2
  49. package/dist/core/internal/engine.d.ts.map +1 -1
  50. package/dist/core/internal/engine.js +12 -1
  51. package/dist/core/internal/engine.js.map +1 -1
  52. package/dist/core/internal/hash.d.ts +10 -0
  53. package/dist/core/internal/hash.d.ts.map +1 -1
  54. package/dist/core/internal/hash.js +26 -1
  55. package/dist/core/internal/hash.js.map +1 -1
  56. package/dist/index.d.ts +23 -14
  57. package/dist/index.d.ts.map +1 -1
  58. package/dist/index.js +23 -14
  59. package/dist/index.js.map +1 -1
  60. package/dist/node/Engine.d.ts +1 -1
  61. package/dist/node/Engine.d.ts.map +1 -1
  62. package/dist/node/Engine.js.map +1 -1
  63. package/dist/node/Hash.d.ts +6 -4
  64. package/dist/node/Hash.d.ts.map +1 -1
  65. package/dist/node/Hash.js +35 -3
  66. package/dist/node/Hash.js.map +1 -1
  67. package/dist/tempo/AuthorizationTempo.d.ts +6 -6
  68. package/dist/tempo/AuthorizationTempo.js +6 -6
  69. package/dist/tempo/KeyAuthorization.d.ts +3 -8
  70. package/dist/tempo/KeyAuthorization.d.ts.map +1 -1
  71. package/dist/tempo/KeyAuthorization.js +3 -8
  72. package/dist/tempo/KeyAuthorization.js.map +1 -1
  73. package/dist/tempo/SignatureEnvelope.d.ts +8 -8
  74. package/dist/tempo/SignatureEnvelope.js +8 -8
  75. package/dist/trusted-setups/Paths.d.ts +1 -0
  76. package/dist/trusted-setups/Paths.d.ts.map +1 -1
  77. package/dist/trusted-setups/Paths.js +1 -0
  78. package/dist/trusted-setups/Paths.js.map +1 -1
  79. package/dist/trusted-setups/Setups.d.ts +35 -0
  80. package/dist/trusted-setups/Setups.d.ts.map +1 -0
  81. package/dist/trusted-setups/Setups.js +29 -0
  82. package/dist/trusted-setups/Setups.js.map +1 -0
  83. package/dist/trusted-setups/index.d.ts +20 -0
  84. package/dist/trusted-setups/index.d.ts.map +1 -1
  85. package/dist/trusted-setups/index.js +20 -0
  86. package/dist/trusted-setups/index.js.map +1 -1
  87. package/dist/trusted-setups/internal/paths.d.ts.map +1 -1
  88. package/dist/trusted-setups/internal/paths.js +1 -1
  89. package/dist/trusted-setups/internal/paths.js.map +1 -1
  90. package/dist/trusted-setups/internal/setups/mainnet.d.ts +7 -0
  91. package/dist/trusted-setups/internal/setups/mainnet.d.ts.map +1 -0
  92. package/dist/trusted-setups/internal/setups/mainnet.js +11 -0
  93. package/dist/trusted-setups/internal/setups/mainnet.js.map +1 -0
  94. package/dist/wasm/Engine.d.ts +4 -3
  95. package/dist/wasm/Engine.d.ts.map +1 -1
  96. package/dist/wasm/Engine.js +5 -5
  97. package/dist/wasm/Engine.js.map +1 -1
  98. package/dist/wasm/Hash.d.ts +1 -1
  99. package/dist/wasm/Hash.d.ts.map +1 -1
  100. package/dist/wasm/Hash.js +5 -0
  101. package/dist/wasm/Hash.js.map +1 -1
  102. package/dist/wasm/Keystore.d.ts +23 -9
  103. package/dist/wasm/Keystore.d.ts.map +1 -1
  104. package/dist/wasm/Keystore.js +30 -13
  105. package/dist/wasm/Keystore.js.map +1 -1
  106. package/dist/wasm/Kzg.d.ts +112 -0
  107. package/dist/wasm/Kzg.d.ts.map +1 -0
  108. package/dist/wasm/Kzg.js +333 -0
  109. package/dist/wasm/Kzg.js.map +1 -0
  110. package/dist/wasm/Secp256k1.d.ts +55 -0
  111. package/dist/wasm/Secp256k1.d.ts.map +1 -0
  112. package/dist/wasm/Secp256k1.js +181 -0
  113. package/dist/wasm/Secp256k1.js.map +1 -0
  114. package/dist/wasm/index.d.ts +44 -1
  115. package/dist/wasm/index.d.ts.map +1 -1
  116. package/dist/wasm/index.js +44 -1
  117. package/dist/wasm/index.js.map +1 -1
  118. package/dist/wasm/internal/blake3.d.ts +10 -1
  119. package/dist/wasm/internal/blake3.d.ts.map +1 -1
  120. package/dist/wasm/internal/blake3.js +12 -1
  121. package/dist/wasm/internal/blake3.js.map +1 -1
  122. package/dist/wasm/internal/blake3.wasm.d.ts +3 -1
  123. package/dist/wasm/internal/blake3.wasm.d.ts.map +1 -1
  124. package/dist/wasm/internal/blake3.wasm.js +3 -1
  125. package/dist/wasm/internal/blake3.wasm.js.map +1 -1
  126. package/dist/wasm/internal/hash.d.ts +9 -0
  127. package/dist/wasm/internal/hash.d.ts.map +1 -1
  128. package/dist/wasm/internal/hash.js +13 -1
  129. package/dist/wasm/internal/hash.js.map +1 -1
  130. package/dist/wasm/internal/hashState.d.ts +25 -0
  131. package/dist/wasm/internal/hashState.d.ts.map +1 -0
  132. package/dist/wasm/internal/hashState.js +105 -0
  133. package/dist/wasm/internal/hashState.js.map +1 -0
  134. package/dist/wasm/internal/hashes.d.ts +12 -1
  135. package/dist/wasm/internal/hashes.d.ts.map +1 -1
  136. package/dist/wasm/internal/hashes.js +18 -1
  137. package/dist/wasm/internal/hashes.js.map +1 -1
  138. package/dist/wasm/internal/hashes.wasm.d.ts +11 -3
  139. package/dist/wasm/internal/hashes.wasm.d.ts.map +1 -1
  140. package/dist/wasm/internal/hashes.wasm.js +11 -3
  141. package/dist/wasm/internal/hashes.wasm.js.map +1 -1
  142. package/dist/wasm/internal/instantiate.d.ts +12 -0
  143. package/dist/wasm/internal/instantiate.d.ts.map +1 -1
  144. package/dist/wasm/internal/instantiate.js +23 -7
  145. package/dist/wasm/internal/instantiate.js.map +1 -1
  146. package/dist/wasm/internal/keystore.d.ts +10 -0
  147. package/dist/wasm/internal/keystore.d.ts.map +1 -0
  148. package/dist/wasm/internal/keystore.js +10 -0
  149. package/dist/wasm/internal/keystore.js.map +1 -0
  150. package/dist/wasm/internal/kzg.d.ts +17 -0
  151. package/dist/wasm/internal/kzg.d.ts.map +1 -0
  152. package/dist/wasm/internal/kzg.js +8 -0
  153. package/dist/wasm/internal/kzg.js.map +1 -0
  154. package/dist/wasm/internal/kzg.wasm.d.ts +3 -0
  155. package/dist/wasm/internal/kzg.wasm.d.ts.map +1 -0
  156. package/dist/wasm/internal/kzg.wasm.js +10 -0
  157. package/dist/wasm/internal/kzg.wasm.js.map +1 -0
  158. package/dist/wasm/internal/scrypt.d.ts +16 -0
  159. package/dist/wasm/internal/scrypt.d.ts.map +1 -0
  160. package/dist/wasm/internal/scrypt.js +78 -0
  161. package/dist/wasm/internal/scrypt.js.map +1 -0
  162. package/dist/wasm/internal/scrypt.wasm.d.ts +7 -0
  163. package/dist/wasm/internal/scrypt.wasm.d.ts.map +1 -0
  164. package/dist/wasm/internal/scrypt.wasm.js +14 -0
  165. package/dist/wasm/internal/scrypt.wasm.js.map +1 -0
  166. package/dist/wasm/internal/secp256k1.d.ts +16 -0
  167. package/dist/wasm/internal/secp256k1.d.ts.map +1 -0
  168. package/dist/wasm/internal/secp256k1.js +20 -0
  169. package/dist/wasm/internal/secp256k1.js.map +1 -0
  170. package/dist/wasm/internal/secp256k1.wasm.d.ts +3 -0
  171. package/dist/wasm/internal/secp256k1.wasm.d.ts.map +1 -0
  172. package/dist/wasm/internal/secp256k1.wasm.js +10 -0
  173. package/dist/wasm/internal/secp256k1.wasm.js.map +1 -0
  174. package/dist/webauthn/Authentication.d.ts +2 -0
  175. package/dist/webauthn/Authentication.d.ts.map +1 -1
  176. package/dist/webauthn/Authentication.js +2 -1
  177. package/dist/webauthn/Authentication.js.map +1 -1
  178. package/dist/webauthn/Registration.d.ts.map +1 -1
  179. package/dist/webauthn/Registration.js +2 -1
  180. package/dist/webauthn/Registration.js.map +1 -1
  181. package/dist/webauthn/Types.d.ts +27 -6
  182. package/dist/webauthn/Types.d.ts.map +1 -1
  183. package/dist/webauthn/internal/utils.d.ts.map +1 -1
  184. package/dist/webauthn/internal/utils.js +35 -9
  185. package/dist/webauthn/internal/utils.js.map +1 -1
  186. package/dist/zod/TypedData.d.ts +2 -2
  187. package/package.json +27 -2
  188. package/src/benchmarks/Ox.bench.ts +6 -0
  189. package/src/benchmarks/OxNode.bench.ts +8 -0
  190. package/src/benchmarks/OxV0.bench.ts +4 -0
  191. package/src/benchmarks/OxWasm.bench.ts +22 -0
  192. package/src/core/AbiFunction.ts +5 -5
  193. package/src/core/AbiParameters.ts +8 -20
  194. package/src/core/AesGcm.ts +86 -1
  195. package/src/core/Ed25519.ts +87 -1
  196. package/src/core/Engine.ts +1 -0
  197. package/src/core/Hash.ts +321 -1
  198. package/src/core/Hex.ts +1 -4
  199. package/src/core/Rlp.ts +172 -5
  200. package/src/core/Secp256k1.ts +92 -1
  201. package/src/core/WebAuthn.ts +579 -0
  202. package/src/core/WebAuthnP256.ts +47 -50
  203. package/src/core/_test/AbiFunction.test.ts +9 -0
  204. package/src/core/_test/AbiParameters.differential.fuzz.ts +156 -0
  205. package/src/core/_test/AbiParameters.encode.test.ts +22 -0
  206. package/src/core/_test/AbiParameters.fuzz.ts +4 -0
  207. package/src/core/_test/AesGcm.test.ts +76 -0
  208. package/src/core/_test/Block.test.ts +9 -2
  209. package/src/core/_test/Ed25519.test-d.ts +13 -1
  210. package/src/core/_test/Ed25519.test.ts +120 -1
  211. package/src/core/_test/Engine.test-d.ts +9 -0
  212. package/src/core/_test/Engine.test.ts +1 -1
  213. package/src/core/_test/Hash.test-d.ts +41 -0
  214. package/src/core/_test/Hash.test.ts +278 -1
  215. package/src/core/_test/Hash.vectors.test.ts +1 -2
  216. package/src/core/_test/Hex.test.ts +2 -0
  217. package/src/core/_test/Rlp.test-d.ts +18 -0
  218. package/src/core/_test/Rlp.test.ts +109 -0
  219. package/src/core/_test/Secp256k1.test-d.ts +14 -0
  220. package/src/core/_test/Secp256k1.test.ts +91 -1
  221. package/src/core/_test/Transaction.test.ts +11 -2
  222. package/src/core/_test/WebAuthn.test-d.ts +142 -0
  223. package/src/core/_test/WebAuthn.test.ts +766 -0
  224. package/src/core/_test/index.test.ts +1 -0
  225. package/src/core/internal/abiParameters.ts +466 -326
  226. package/src/core/internal/engine.ts +47 -2
  227. package/src/core/internal/hash.ts +53 -1
  228. package/src/index.ts +24 -14
  229. package/src/node/Engine.ts +1 -0
  230. package/src/node/Hash.ts +43 -6
  231. package/src/node/_test/Engine.test-d.ts +1 -0
  232. package/src/node/_test/Engine.test.ts +2 -0
  233. package/src/node/_test/Hash.test-d.ts +11 -0
  234. package/src/node/_test/Hash.test.ts +46 -0
  235. package/src/tempo/AuthorizationTempo.ts +6 -6
  236. package/src/tempo/KeyAuthorization.ts +3 -8
  237. package/src/tempo/SignatureEnvelope.ts +8 -8
  238. package/src/trusted-setups/Paths.ts +1 -0
  239. package/src/trusted-setups/README.md +39 -0
  240. package/src/trusted-setups/Setups.ts +46 -0
  241. package/src/trusted-setups/_test/Paths.test.ts +16 -0
  242. package/src/trusted-setups/_test/Setups.test-d.ts +7 -0
  243. package/src/trusted-setups/_test/Setups.test.ts +43 -0
  244. package/src/trusted-setups/_test/index.test.ts +1 -0
  245. package/src/trusted-setups/index.ts +21 -0
  246. package/src/trusted-setups/internal/paths.ts +4 -1
  247. package/src/trusted-setups/internal/setups/mainnet.source.json +7 -0
  248. package/src/trusted-setups/internal/setups/mainnet.ts +16 -0
  249. package/src/version.ts +1 -1
  250. package/src/wasm/Engine.ts +9 -6
  251. package/src/wasm/Hash.ts +10 -0
  252. package/src/wasm/Keystore.bench.ts +26 -0
  253. package/src/wasm/Keystore.ts +32 -14
  254. package/src/wasm/Kzg.bench.ts +63 -0
  255. package/src/wasm/Kzg.ts +518 -0
  256. package/src/wasm/Secp256k1.bench.ts +79 -0
  257. package/src/wasm/Secp256k1.ts +248 -0
  258. package/src/wasm/_test/Engine.test-d.ts +2 -0
  259. package/src/wasm/_test/Engine.test.ts +5 -0
  260. package/src/wasm/_test/Hash.browser.test.ts +31 -0
  261. package/src/wasm/_test/Hash.test-d.ts +17 -0
  262. package/src/wasm/_test/Hash.test.ts +252 -3
  263. package/src/wasm/_test/Keystore.browser.test.ts +31 -0
  264. package/src/wasm/_test/Keystore.fuzz.ts +50 -0
  265. package/src/wasm/_test/Keystore.test-d.ts +10 -1
  266. package/src/wasm/_test/Keystore.test.ts +289 -4
  267. package/src/wasm/_test/Kzg.test-d.ts +19 -0
  268. package/src/wasm/_test/Kzg.test.ts +220 -0
  269. package/src/wasm/_test/Runtime.test.ts +9 -0
  270. package/src/wasm/_test/Secp256k1.test-d.ts +35 -0
  271. package/src/wasm/_test/Secp256k1.test.ts +354 -0
  272. package/src/wasm/index.ts +46 -1
  273. package/src/wasm/internal/blake3.ts +23 -2
  274. package/src/wasm/internal/blake3.wasm.ts +4 -1
  275. package/src/wasm/internal/hash.ts +27 -1
  276. package/src/wasm/internal/hashState.ts +154 -0
  277. package/src/wasm/internal/hashes.ts +56 -15
  278. package/src/wasm/internal/hashes.wasm.ts +15 -3
  279. package/src/wasm/internal/instantiate.ts +29 -9
  280. package/src/wasm/internal/keystore.ts +19 -0
  281. package/src/wasm/internal/kzg.ts +50 -0
  282. package/src/wasm/internal/kzg.wasm.ts +11 -0
  283. package/src/wasm/internal/scrypt.ts +131 -0
  284. package/src/wasm/internal/scrypt.wasm.ts +17 -0
  285. package/src/wasm/internal/secp256k1.ts +62 -0
  286. package/src/wasm/internal/secp256k1.wasm.ts +11 -0
  287. package/src/webauthn/Authentication.ts +4 -0
  288. package/src/webauthn/Registration.ts +2 -0
  289. package/src/webauthn/Types.ts +32 -2
  290. package/src/webauthn/_test/Authentication.test.ts +123 -1
  291. package/src/webauthn/_test/Registration.test.ts +26 -6
  292. package/src/webauthn/_test/WebAuthn.browser.test.ts +28 -0
  293. package/src/webauthn/internal/utils.ts +41 -8
  294. package/wasm/vendor/c-kzg-4844/LICENSE +201 -0
  295. package/wasm/vendor/c-kzg-4844/blst/LICENSE +201 -0
  296. package/src/trusted-setups/internal/setups/mainnet.txt +0 -4163
@@ -16,9 +16,9 @@ export const createChallenge = Registration.createChallenge
16
16
  *
17
17
  * @example
18
18
  * ```ts twoslash
19
- * import { WebAuthnP256 } from 'ox'
19
+ * import { WebAuthn } from 'ox'
20
20
  *
21
- * const credential = await WebAuthnP256.createCredential({
21
+ * const credential = await WebAuthn.createCredential({
22
22
  * name: 'Example'
23
23
  * }) // [!code focus]
24
24
  * // @log: {
@@ -27,7 +27,7 @@ export const createChallenge = Registration.createChallenge
27
27
  * // @log: raw: PublicKeyCredential {},
28
28
  * // @log: }
29
29
  *
30
- * const { metadata, signature } = await WebAuthnP256.sign({
30
+ * const { metadata, signature } = await WebAuthn.sign({
31
31
  * credentialId: credential.id,
32
32
  * challenge: '0xdeadbeef'
33
33
  * })
@@ -49,27 +49,25 @@ export declare namespace createCredential {
49
49
 
50
50
  /**
51
51
  * Gets the authenticator data which contains information about the
52
- * processing of an authenticator request (ie. from `WebAuthnP256.sign`).
52
+ * processing of an authenticator request (ie. from `WebAuthn.sign`).
53
53
  *
54
54
  * :::warning
55
55
  *
56
56
  * This function is mainly for testing purposes or for manually constructing
57
57
  * autenticator data. In most cases you will not need this function.
58
58
  * `authenticatorData` is typically returned as part of the
59
- * {@link ox#WebAuthnP256.(sign:function)} response (ie. an authenticator response).
59
+ * {@link ox#WebAuthn.(sign:function)} response (ie. an authenticator response).
60
60
  *
61
61
  * :::
62
62
  *
63
63
  * @example
64
64
  * ```ts twoslash
65
- * import { WebAuthnP256 } from 'ox'
65
+ * import { WebAuthn } from 'ox'
66
66
  *
67
- * const authenticatorData = WebAuthnP256.getAuthenticatorData(
68
- * {
69
- * rpId: 'example.com',
70
- * signCount: 420
71
- * }
72
- * )
67
+ * const authenticatorData = WebAuthn.getAuthenticatorData({
68
+ * rpId: 'example.com',
69
+ * signCount: 420
70
+ * })
73
71
  * // @log: "0xa379a6f6eeafb9a55e378c118034e2751e682fab9f2d30ab13d2125586ce194705000001a4"
74
72
  * ```
75
73
  *
@@ -79,20 +77,18 @@ export declare namespace createCredential {
79
77
  * Include a credential ID and public key in the authenticator data (for registration responses):
80
78
  *
81
79
  * ```ts twoslash
82
- * import { P256, WebAuthnP256 } from 'ox'
80
+ * import { P256, WebAuthn } from 'ox'
83
81
  *
84
82
  * const { publicKey } = P256.createKeyPair()
85
83
  *
86
- * const authenticatorData = WebAuthnP256.getAuthenticatorData(
87
- * {
88
- * rpId: 'example.com',
89
- * flag: 0x41, // UP + AT
90
- * credential: {
91
- * id: new Uint8Array(32),
92
- * publicKey
93
- * }
84
+ * const authenticatorData = WebAuthn.getAuthenticatorData({
85
+ * rpId: 'example.com',
86
+ * flag: 0x41, // UP + AT
87
+ * credential: {
88
+ * id: new Uint8Array(32),
89
+ * publicKey
94
90
  * }
95
- * )
91
+ * })
96
92
  * ```
97
93
  *
98
94
  * @param options - Options to construct the authenticator data.
@@ -108,22 +104,22 @@ export declare namespace getAuthenticatorData {
108
104
 
109
105
  /**
110
106
  * Constructs the Client Data in stringified JSON format which represents client data that
111
- * was passed to `credentials.get()` in {@link ox#WebAuthnP256.(sign:function)}.
107
+ * was passed to `credentials.get()` in {@link ox#WebAuthn.(sign:function)}.
112
108
  *
113
109
  * :::warning
114
110
  *
115
111
  * This function is mainly for testing purposes or for manually constructing
116
112
  * client data. In most cases you will not need this function.
117
113
  * `clientDataJSON` is typically returned as part of the
118
- * {@link ox#WebAuthnP256.(sign:function)} response (ie. an authenticator response).
114
+ * {@link ox#WebAuthn.(sign:function)} response (ie. an authenticator response).
119
115
  *
120
116
  * :::
121
117
  *
122
118
  * @example
123
119
  * ```ts twoslash
124
- * import { WebAuthnP256 } from 'ox'
120
+ * import { WebAuthn } from 'ox'
125
121
  *
126
- * const clientDataJSON = WebAuthnP256.getClientDataJSON({
122
+ * const clientDataJSON = WebAuthn.getClientDataJSON({
127
123
  * challenge: '0xdeadbeef',
128
124
  * origin: 'https://example.com'
129
125
  * })
@@ -154,19 +150,17 @@ export declare namespace getClientDataJSON {
154
150
  *
155
151
  * @example
156
152
  * ```ts twoslash
157
- * import { P256, WebAuthnP256 } from 'ox'
153
+ * import { P256, WebAuthn } from 'ox'
158
154
  *
159
155
  * const { publicKey } = P256.createKeyPair()
160
156
  *
161
- * const attestationObject = WebAuthnP256.getAttestationObject(
162
- * {
163
- * authData: WebAuthnP256.getAuthenticatorData({
164
- * rpId: 'example.com',
165
- * flag: 0x41,
166
- * credential: { id: new Uint8Array(32), publicKey }
167
- * })
168
- * }
169
- * )
157
+ * const attestationObject = WebAuthn.getAttestationObject({
158
+ * authData: WebAuthn.getAuthenticatorData({
159
+ * rpId: 'example.com',
160
+ * flag: 0x41,
161
+ * credential: { id: new Uint8Array(32), publicKey }
162
+ * })
163
+ * })
170
164
  * ```
171
165
  *
172
166
  * @param options - Options to construct the attestation object.
@@ -186,9 +180,9 @@ export declare namespace getAttestationObject {
186
180
  *
187
181
  * @example
188
182
  * ```ts twoslash
189
- * import { WebAuthnP256 } from 'ox'
183
+ * import { WebAuthn } from 'ox'
190
184
  *
191
- * const options = WebAuthnP256.getCredentialCreationOptions({
185
+ * const options = WebAuthn.getCredentialCreationOptions({
192
186
  * name: 'Example'
193
187
  * })
194
188
  *
@@ -212,9 +206,9 @@ export declare namespace getCredentialCreationOptions {
212
206
  *
213
207
  * @example
214
208
  * ```ts twoslash
215
- * import { WebAuthnP256 } from 'ox'
209
+ * import { WebAuthn } from 'ox'
216
210
  *
217
- * const options = WebAuthnP256.getCredentialRequestOptions({
211
+ * const options = WebAuthn.getCredentialRequestOptions({
218
212
  * challenge: '0xdeadbeef'
219
213
  * })
220
214
  *
@@ -242,15 +236,15 @@ export declare namespace getCredentialRequestOptions {
242
236
  *
243
237
  * This function is mainly for testing purposes or for manually constructing
244
238
  * signing payloads. In most cases you will not need this function and
245
- * instead use {@link ox#WebAuthnP256.(sign:function)}.
239
+ * instead use {@link ox#WebAuthn.(sign:function)}.
246
240
  *
247
241
  * :::
248
242
  *
249
243
  * @example
250
244
  * ```ts twoslash
251
- * import { WebAuthnP256, WebCryptoP256 } from 'ox'
245
+ * import { WebAuthn, WebCryptoP256 } from 'ox'
252
246
  *
253
- * const { metadata, payload } = WebAuthnP256.getSignPayload({
247
+ * const { metadata, payload } = WebAuthn.getSignPayload({
254
248
  * // [!code focus]
255
249
  * challenge: '0xdeadbeef' // [!code focus]
256
250
  * }) // [!code focus]
@@ -294,13 +288,13 @@ export declare namespace getSignPayload {
294
288
  *
295
289
  * @example
296
290
  * ```ts twoslash
297
- * import { WebAuthnP256 } from 'ox'
291
+ * import { WebAuthn } from 'ox'
298
292
  *
299
- * const credential = await WebAuthnP256.createCredential({
293
+ * const credential = await WebAuthn.createCredential({
300
294
  * name: 'Example'
301
295
  * })
302
296
  *
303
- * const { metadata, signature } = await WebAuthnP256.sign({
297
+ * const { metadata, signature } = await WebAuthn.sign({
304
298
  * // [!code focus]
305
299
  * credentialId: credential.id, // [!code focus]
306
300
  * challenge: '0xdeadbeef' // [!code focus]
@@ -337,18 +331,18 @@ export declare namespace sign {
337
331
  *
338
332
  * @example
339
333
  * ```ts twoslash
340
- * import { WebAuthnP256 } from 'ox'
334
+ * import { WebAuthn } from 'ox'
341
335
  *
342
- * const credential = await WebAuthnP256.createCredential({
336
+ * const credential = await WebAuthn.createCredential({
343
337
  * name: 'Example'
344
338
  * })
345
339
  *
346
- * const { metadata, signature } = await WebAuthnP256.sign({
340
+ * const { metadata, signature } = await WebAuthn.sign({
347
341
  * credentialId: credential.id,
348
342
  * challenge: '0xdeadbeef'
349
343
  * })
350
344
  *
351
- * const result = await WebAuthnP256.verify({
345
+ * const result = await WebAuthn.verify({
352
346
  * // [!code focus]
353
347
  * metadata, // [!code focus]
354
348
  * challenge: '0xdeadbeef', // [!code focus]
@@ -398,3 +392,6 @@ export type {
398
392
  ResidentKeyRequirement,
399
393
  UserVerificationRequirement,
400
394
  } from '../webauthn/Types.js'
395
+
396
+ /** @deprecated Use `WebAuthn` instead. */
397
+ declare module './WebAuthnP256.js' {}
@@ -218,6 +218,15 @@ describe('encodeData', () => {
218
218
  )
219
219
  })
220
220
 
221
+ test('behavior: malformed bytes compatibility', () => {
222
+ const abiFunction = AbiFunction.from('function foo(bytes)')
223
+ expect(
224
+ AbiFunction.encodeData(abiFunction, ['0xzz1']),
225
+ ).toMatchInlineSnapshot(
226
+ `"0x30c8d1da00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000002zz10000000000000000000000000000000000000000000000000000000000000"`,
227
+ )
228
+ })
229
+
221
230
  test('behavior: with overloads', () => {
222
231
  const abi = Abi.from([
223
232
  {
@@ -0,0 +1,156 @@
1
+ import { test } from '@fast-check/vitest'
2
+ import { AbiCoder, Interface, ParamType } from 'ethers'
3
+ import { AbiFunction, AbiParameters } from 'ox'
4
+ import { describe, expect } from 'vp/test'
5
+
6
+ import { arbitraryAbiCase } from '../../../test/fuzz/arbitraries/abi.js'
7
+ import { numRuns } from '../../../test/fuzz/numRuns.js'
8
+
9
+ const coder = AbiCoder.defaultAbiCoder()
10
+
11
+ describe('AbiParameters differential', () => {
12
+ test.prop(
13
+ {
14
+ input: arbitraryAbiCase({
15
+ maxArrayLength: 4,
16
+ maxBytesLength: 128,
17
+ maxDepth: 4,
18
+ maxTupleArity: 4,
19
+ minFixedArrayLength: 0,
20
+ }),
21
+ },
22
+ { numRuns },
23
+ )('encode matches ethers AbiCoder', ({ input }) => {
24
+ expectParameters(input.parameters, input.values)
25
+ })
26
+
27
+ test('integer boundaries match ethers AbiCoder', () => {
28
+ for (let bits = 8; bits <= 256; bits += 8) {
29
+ const bits_ = BigInt(bits)
30
+ const maxUnsigned = 2n ** bits_ - 1n
31
+ const maxSigned = 2n ** (bits_ - 1n) - 1n
32
+ const minSigned = -(2n ** (bits_ - 1n))
33
+
34
+ for (const value of [0n, 1n, maxUnsigned])
35
+ expectParameters([{ type: `uint${bits}` }], [value])
36
+ for (const value of [minSigned, -1n, 0n, 1n, maxSigned])
37
+ expectParameters([{ type: `int${bits}` }], [value])
38
+
39
+ if (bits > 64) {
40
+ expectParameters([{ type: `uint${bits}` }], [2n ** 64n - 1n])
41
+ expectParameters([{ type: `uint${bits}` }], [2n ** 64n])
42
+ }
43
+ }
44
+ })
45
+
46
+ test('bytes and string boundaries match ethers AbiCoder', () => {
47
+ for (let size = 1; size <= 32; size++)
48
+ expectParameters([{ type: `bytes${size}` }], [`0x${'ab'.repeat(size)}`])
49
+
50
+ for (const size of [0, 1, 31, 32, 33, 63, 64, 65, 128]) {
51
+ expectParameters([{ type: 'bytes' }], [`0x${'ab'.repeat(size)}`])
52
+ expectParameters([{ type: 'string' }], ['a'.repeat(size)])
53
+ }
54
+
55
+ for (const value of ['\u0000', 'é', '€', '😀', 'a😀b'])
56
+ expectParameters([{ type: 'string' }], [value])
57
+ })
58
+
59
+ test('zero-width types match ethers AbiCoder', () => {
60
+ expectParameters([{ type: 'uint256[0]' }, { type: 'uint256' }], [[], 3n])
61
+ expectParameters([{ type: 'string[0]' }, { type: 'uint256' }], [[], 3n])
62
+ expectParameters([{ type: 'tuple', components: [] }], [[]])
63
+ })
64
+ })
65
+
66
+ describe('AbiFunction differential', () => {
67
+ test.prop(
68
+ {
69
+ input: arbitraryAbiCase({
70
+ maxArrayLength: 4,
71
+ maxBytesLength: 128,
72
+ maxDepth: 4,
73
+ maxTupleArity: 4,
74
+ minFixedArrayLength: 0,
75
+ }),
76
+ },
77
+ { numRuns },
78
+ )('encodeData matches ethers Interface', ({ input }) => {
79
+ expectFunction(input.parameters, input.values)
80
+ })
81
+
82
+ test('nested named dynamic values match ethers Interface', () => {
83
+ expectFunction(
84
+ [
85
+ {
86
+ components: [
87
+ { name: 'maker', type: 'address' },
88
+ {
89
+ components: [
90
+ { name: 'id', type: 'uint256' },
91
+ { name: 'memo', type: 'string' },
92
+ { name: 'payloads', type: 'bytes[]' },
93
+ ],
94
+ name: 'items',
95
+ type: 'tuple[2]',
96
+ },
97
+ ],
98
+ name: 'orders',
99
+ type: 'tuple[]',
100
+ },
101
+ { name: 'suffix', type: 'string[2]' },
102
+ ],
103
+ [
104
+ [
105
+ {
106
+ items: [
107
+ {
108
+ id: 2n ** 64n - 1n,
109
+ memo: '',
110
+ payloads: ['0x', `0x${'ab'.repeat(31)}`],
111
+ },
112
+ {
113
+ id: 2n ** 64n,
114
+ memo: '😀',
115
+ payloads: [`0x${'ab'.repeat(32)}`, `0x${'ab'.repeat(33)}`],
116
+ },
117
+ ],
118
+ maker: '0x0000000000000000000000000000000000000001',
119
+ },
120
+ ],
121
+ ['', 'a'.repeat(33)],
122
+ ],
123
+ )
124
+ })
125
+ })
126
+
127
+ function expectParameters(
128
+ parameters: readonly AbiParameters.Parameter[],
129
+ values: readonly unknown[],
130
+ ) {
131
+ const types = parameters.map((parameter) => ParamType.from(parameter))
132
+ const expected = coder.encode(types, values)
133
+ const encoded = AbiParameters.encode(parameters, values as never)
134
+ expect(encoded).toEqual(expected)
135
+ }
136
+
137
+ function expectFunction(
138
+ parameters: readonly AbiParameters.Parameter[],
139
+ values: readonly unknown[],
140
+ ) {
141
+ const abiFunction: AbiFunction.AbiFunction = {
142
+ inputs: parameters,
143
+ name: 'test',
144
+ outputs: [],
145
+ stateMutability: 'pure',
146
+ type: 'function',
147
+ }
148
+ const inputs = parameters
149
+ .map((parameter) => ParamType.from(parameter).format('full'))
150
+ .join(',')
151
+ const expected = new Interface([
152
+ `function ${abiFunction.name}(${inputs}) pure`,
153
+ ]).encodeFunctionData(abiFunction.name, values)
154
+ const encoded = AbiFunction.encodeData(abiFunction, values as never)
155
+ expect(encoded).toEqual(expected)
156
+ }
@@ -1825,6 +1825,28 @@ test('invalid bytes', () => {
1825
1825
  )
1826
1826
  })
1827
1827
 
1828
+ test('invalid bytes type', () => {
1829
+ expect(() =>
1830
+ AbiParameters.encode([{ name: 'x', type: 'bytes0' }], ['0x']),
1831
+ ).toThrowErrorMatchingInlineSnapshot(
1832
+ '[AbiParameters.InvalidTypeError: Type `bytes0` is not a valid ABI Type.]',
1833
+ )
1834
+ expect(() =>
1835
+ AbiParameters.encode(
1836
+ [
1837
+ { name: 'x', type: 'bytes33' },
1838
+ { name: 'following', type: 'uint256' },
1839
+ ],
1840
+ [
1841
+ '0x000000000000000000000000000000000000000000000000000000000000000000',
1842
+ 1n,
1843
+ ],
1844
+ ),
1845
+ ).toThrowErrorMatchingInlineSnapshot(
1846
+ '[AbiParameters.InvalidTypeError: Type `bytes33` is not a valid ABI Type.]',
1847
+ )
1848
+ })
1849
+
1828
1850
  test('integer out of range', () => {
1829
1851
  expect(() =>
1830
1852
  AbiParameters.encode(
@@ -32,5 +32,9 @@ function normalize(value: unknown): unknown {
32
32
  if (Array.isArray(value)) return value.map(normalize)
33
33
  if (typeof value === 'string' && /^0x[0-9a-fA-F]{40}$/.test(value))
34
34
  return value.toLowerCase()
35
+ if (value && typeof value === 'object')
36
+ return Object.fromEntries(
37
+ Object.entries(value).map(([key, value]) => [key, normalize(value)]),
38
+ )
35
39
  return value
36
40
  }
@@ -85,6 +85,80 @@ describe('encrypt', () => {
85
85
  })
86
86
  })
87
87
 
88
+ describe('fromPrf', () => {
89
+ test('vector', async () => {
90
+ const key = await AesGcm.fromPrf(
91
+ '0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f',
92
+ )
93
+ const expectedKey = await globalThis.crypto.subtle.importKey(
94
+ 'raw',
95
+ Bytes.fromHex(
96
+ '0x95c3c66b64baf063678e43d8aa98e1a4b4447c431fa9434b79e4a8c01ee85e07',
97
+ ),
98
+ { name: 'AES-GCM' },
99
+ false,
100
+ ['decrypt'],
101
+ )
102
+ const value = Bytes.fromString('i am a secret message')
103
+ const encrypted = await AesGcm.encrypt(value, key)
104
+
105
+ await expect(AesGcm.decrypt(encrypted, expectedKey)).resolves.toEqual(value)
106
+ })
107
+
108
+ test('value: Bytes', async () => {
109
+ const key = await AesGcm.fromPrf(
110
+ Bytes.fromHex(
111
+ '0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f',
112
+ ),
113
+ )
114
+ const value = Bytes.fromString('i am a secret message')
115
+
116
+ await expect(
117
+ AesGcm.decrypt(await AesGcm.encrypt(value, key), key),
118
+ ).resolves.toEqual(value)
119
+ })
120
+
121
+ test('behavior: CryptoKey properties', async () => {
122
+ const key = await AesGcm.fromPrf(new Uint8Array(32))
123
+
124
+ expect({
125
+ algorithm: key.algorithm,
126
+ extractable: key.extractable,
127
+ type: key.type,
128
+ usages: key.usages,
129
+ }).toMatchInlineSnapshot(`
130
+ {
131
+ "algorithm": {
132
+ "length": 256,
133
+ "name": "AES-GCM",
134
+ },
135
+ "extractable": false,
136
+ "type": "secret",
137
+ "usages": [
138
+ "encrypt",
139
+ "decrypt",
140
+ ],
141
+ }
142
+ `)
143
+ })
144
+
145
+ test('error: PRF output is too short', async () => {
146
+ await expect(
147
+ AesGcm.fromPrf(new Uint8Array(31)),
148
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
149
+ `[AesGcm.InvalidPrfSizeError: PRF output must be exactly 32 bytes. Received 31 bytes.]`,
150
+ )
151
+ })
152
+
153
+ test('error: PRF output is too long', async () => {
154
+ await expect(
155
+ AesGcm.fromPrf(new Uint8Array(33)),
156
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
157
+ `[AesGcm.InvalidPrfSizeError: PRF output must be exactly 32 bytes. Received 33 bytes.]`,
158
+ )
159
+ })
160
+ })
161
+
88
162
  describe('getKey', () => {
89
163
  test('default', async () => {
90
164
  const key = await AesGcm.getKey({ password: 'qwerty' })
@@ -105,8 +179,10 @@ test('exports', () => {
105
179
  "ivLength",
106
180
  "decrypt",
107
181
  "encrypt",
182
+ "fromPrf",
108
183
  "getKey",
109
184
  "randomSalt",
185
+ "InvalidPrfSizeError",
110
186
  ]
111
187
  `)
112
188
  })
@@ -400,9 +400,16 @@ describe('fromRpc', () => {
400
400
  method: 'eth_getBlockByNumber',
401
401
  params: ['latest', true],
402
402
  })
403
- .then(Block.fromRpc)
403
+ .then((block) => Block.fromRpc(block, { includeTransactions: true }))
404
404
 
405
- expect(block).toMatchSnapshot()
405
+ const transactions = block?.transactions.map((transaction) => {
406
+ const { blockTimestamp: _, ...transaction_ } = {
407
+ blockTimestamp: undefined,
408
+ ...transaction,
409
+ }
410
+ return transaction_
411
+ })
412
+ expect({ ...block, transactions }).toMatchSnapshot()
406
413
  })
407
414
  })
408
415
 
@@ -1,5 +1,5 @@
1
1
  import { attest } from '@ark/attest'
2
- import { Ed25519 } from 'ox'
2
+ import { type Bytes, Ed25519, type Hex } from 'ox'
3
3
  import { expectTypeOf, test } from 'vp/test'
4
4
 
5
5
  test('createKeyPair', () => {
@@ -28,6 +28,18 @@ test('createKeyPair', () => {
28
28
  }
29
29
  })
30
30
 
31
+ test('fromPrf', () => {
32
+ const prf =
33
+ '0x000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f'
34
+
35
+ expectTypeOf(Ed25519.fromPrf(prf)).toEqualTypeOf<Hex.Hex>()
36
+ expectTypeOf(Ed25519.fromPrf(new Uint8Array(32))).toEqualTypeOf<Hex.Hex>()
37
+ expectTypeOf(Ed25519.fromPrf(prf, { as: 'Hex' })).toEqualTypeOf<Hex.Hex>()
38
+ expectTypeOf(
39
+ Ed25519.fromPrf(prf, { as: 'Bytes' }),
40
+ ).toEqualTypeOf<Bytes.Bytes>()
41
+ })
42
+
31
43
  test('getPublicKey', () => {
32
44
  // Default behavior (Hex)
33
45
  {