ox 1.1.0 → 1.2.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 (284) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/dist/core/Engine.d.ts +43 -11
  3. package/dist/core/Engine.d.ts.map +1 -1
  4. package/dist/core/Engine.js +40 -10
  5. package/dist/core/Engine.js.map +1 -1
  6. package/dist/core/Hash.d.ts +36 -0
  7. package/dist/core/Hash.d.ts.map +1 -1
  8. package/dist/core/Hash.js +35 -0
  9. package/dist/core/Hash.js.map +1 -1
  10. package/dist/core/internal/engine.d.ts +8 -8
  11. package/dist/core/internal/engine.d.ts.map +1 -1
  12. package/dist/index.d.ts +5 -2
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +5 -2
  15. package/dist/index.js.map +1 -1
  16. package/dist/node/Ed25519.d.ts +33 -0
  17. package/dist/node/Ed25519.d.ts.map +1 -0
  18. package/dist/node/Ed25519.js +67 -0
  19. package/dist/node/Ed25519.js.map +1 -0
  20. package/dist/node/Engine.d.ts +29 -16
  21. package/dist/node/Engine.d.ts.map +1 -1
  22. package/dist/node/Engine.js +38 -14
  23. package/dist/node/Engine.js.map +1 -1
  24. package/dist/node/Hash.d.ts +17 -19
  25. package/dist/node/Hash.d.ts.map +1 -1
  26. package/dist/node/Hash.js +17 -19
  27. package/dist/node/Hash.js.map +1 -1
  28. package/dist/node/Keystore.d.ts +36 -0
  29. package/dist/node/Keystore.d.ts.map +1 -0
  30. package/dist/node/Keystore.js +72 -0
  31. package/dist/node/Keystore.js.map +1 -0
  32. package/dist/node/Mnemonic.d.ts +35 -0
  33. package/dist/node/Mnemonic.d.ts.map +1 -0
  34. package/dist/node/Mnemonic.js +46 -0
  35. package/dist/node/Mnemonic.js.map +1 -0
  36. package/dist/node/P256.d.ts +32 -0
  37. package/dist/node/P256.d.ts.map +1 -0
  38. package/dist/node/P256.js +34 -0
  39. package/dist/node/P256.js.map +1 -0
  40. package/dist/node/X25519.d.ts +31 -0
  41. package/dist/node/X25519.d.ts.map +1 -0
  42. package/dist/node/X25519.js +71 -0
  43. package/dist/node/X25519.js.map +1 -0
  44. package/dist/node/index.d.ts +95 -8
  45. package/dist/node/index.d.ts.map +1 -1
  46. package/dist/node/index.js +95 -8
  47. package/dist/node/index.js.map +1 -1
  48. package/dist/trusted-setups/Paths.d.ts +1 -0
  49. package/dist/trusted-setups/Paths.d.ts.map +1 -1
  50. package/dist/trusted-setups/Paths.js +1 -0
  51. package/dist/trusted-setups/Paths.js.map +1 -1
  52. package/dist/trusted-setups/Setups.d.ts +35 -0
  53. package/dist/trusted-setups/Setups.d.ts.map +1 -0
  54. package/dist/trusted-setups/Setups.js +29 -0
  55. package/dist/trusted-setups/Setups.js.map +1 -0
  56. package/dist/trusted-setups/index.d.ts +20 -0
  57. package/dist/trusted-setups/index.d.ts.map +1 -1
  58. package/dist/trusted-setups/index.js +20 -0
  59. package/dist/trusted-setups/index.js.map +1 -1
  60. package/dist/trusted-setups/internal/paths.d.ts.map +1 -1
  61. package/dist/trusted-setups/internal/paths.js +1 -1
  62. package/dist/trusted-setups/internal/paths.js.map +1 -1
  63. package/dist/trusted-setups/internal/setups/mainnet.d.ts +7 -0
  64. package/dist/trusted-setups/internal/setups/mainnet.d.ts.map +1 -0
  65. package/dist/trusted-setups/internal/setups/mainnet.js +11 -0
  66. package/dist/trusted-setups/internal/setups/mainnet.js.map +1 -0
  67. package/dist/wasm/Ed25519.d.ts +35 -0
  68. package/dist/wasm/Ed25519.d.ts.map +1 -0
  69. package/dist/wasm/Ed25519.js +88 -0
  70. package/dist/wasm/Ed25519.js.map +1 -0
  71. package/dist/wasm/Engine.d.ts +36 -26
  72. package/dist/wasm/Engine.d.ts.map +1 -1
  73. package/dist/wasm/Engine.js +44 -25
  74. package/dist/wasm/Engine.js.map +1 -1
  75. package/dist/wasm/Hash.d.ts +13 -19
  76. package/dist/wasm/Hash.d.ts.map +1 -1
  77. package/dist/wasm/Hash.js +21 -27
  78. package/dist/wasm/Hash.js.map +1 -1
  79. package/dist/wasm/Keystore.d.ts +51 -0
  80. package/dist/wasm/Keystore.d.ts.map +1 -0
  81. package/dist/wasm/Keystore.js +51 -0
  82. package/dist/wasm/Keystore.js.map +1 -0
  83. package/dist/wasm/Kzg.d.ts +112 -0
  84. package/dist/wasm/Kzg.d.ts.map +1 -0
  85. package/dist/wasm/Kzg.js +333 -0
  86. package/dist/wasm/Kzg.js.map +1 -0
  87. package/dist/wasm/Mnemonic.d.ts +33 -0
  88. package/dist/wasm/Mnemonic.d.ts.map +1 -0
  89. package/dist/wasm/Mnemonic.js +30 -0
  90. package/dist/wasm/Mnemonic.js.map +1 -0
  91. package/dist/wasm/Secp256k1.d.ts +55 -0
  92. package/dist/wasm/Secp256k1.d.ts.map +1 -0
  93. package/dist/wasm/Secp256k1.js +181 -0
  94. package/dist/wasm/Secp256k1.js.map +1 -0
  95. package/dist/wasm/X25519.d.ts +33 -0
  96. package/dist/wasm/X25519.d.ts.map +1 -0
  97. package/dist/wasm/X25519.js +53 -0
  98. package/dist/wasm/X25519.js.map +1 -0
  99. package/dist/wasm/index.d.ts +124 -12
  100. package/dist/wasm/index.d.ts.map +1 -1
  101. package/dist/wasm/index.js +124 -12
  102. package/dist/wasm/index.js.map +1 -1
  103. package/dist/wasm/internal/blake3.d.ts +11 -0
  104. package/dist/wasm/internal/blake3.d.ts.map +1 -0
  105. package/dist/wasm/internal/blake3.js +31 -0
  106. package/dist/wasm/internal/blake3.js.map +1 -0
  107. package/dist/wasm/internal/blake3.wasm.d.ts +3 -0
  108. package/dist/wasm/internal/blake3.wasm.d.ts.map +1 -0
  109. package/dist/wasm/internal/blake3.wasm.js +10 -0
  110. package/dist/wasm/internal/blake3.wasm.js.map +1 -0
  111. package/dist/wasm/internal/crypto25519.d.ts +16 -0
  112. package/dist/wasm/internal/crypto25519.d.ts.map +1 -0
  113. package/dist/wasm/internal/crypto25519.js +5 -0
  114. package/dist/wasm/internal/crypto25519.js.map +1 -0
  115. package/dist/wasm/internal/crypto25519.wasm.d.ts +3 -0
  116. package/dist/wasm/internal/crypto25519.wasm.d.ts.map +1 -0
  117. package/dist/wasm/internal/crypto25519.wasm.js +10 -0
  118. package/dist/wasm/internal/crypto25519.wasm.js.map +1 -0
  119. package/dist/wasm/internal/ed25519.d.ts +4 -0
  120. package/dist/wasm/internal/ed25519.d.ts.map +1 -0
  121. package/dist/wasm/internal/ed25519.js +21 -0
  122. package/dist/wasm/internal/ed25519.js.map +1 -0
  123. package/dist/wasm/internal/hashes.d.ts +12 -0
  124. package/dist/wasm/internal/hashes.d.ts.map +1 -0
  125. package/dist/wasm/internal/hashes.js +8 -0
  126. package/dist/wasm/internal/hashes.js.map +1 -0
  127. package/dist/wasm/internal/hashes.wasm.d.ts +4 -2
  128. package/dist/wasm/internal/hashes.wasm.d.ts.map +1 -1
  129. package/dist/wasm/internal/hashes.wasm.js +4 -2
  130. package/dist/wasm/internal/hashes.wasm.js.map +1 -1
  131. package/dist/wasm/internal/instantiate.d.ts +12 -0
  132. package/dist/wasm/internal/instantiate.d.ts.map +1 -1
  133. package/dist/wasm/internal/instantiate.js +23 -7
  134. package/dist/wasm/internal/instantiate.js.map +1 -1
  135. package/dist/wasm/internal/keystore.d.ts +10 -0
  136. package/dist/wasm/internal/keystore.d.ts.map +1 -0
  137. package/dist/wasm/internal/keystore.js +10 -0
  138. package/dist/wasm/internal/keystore.js.map +1 -0
  139. package/dist/wasm/internal/kzg.d.ts +17 -0
  140. package/dist/wasm/internal/kzg.d.ts.map +1 -0
  141. package/dist/wasm/internal/kzg.js +8 -0
  142. package/dist/wasm/internal/kzg.js.map +1 -0
  143. package/dist/wasm/internal/kzg.wasm.d.ts +3 -0
  144. package/dist/wasm/internal/kzg.wasm.d.ts.map +1 -0
  145. package/dist/wasm/internal/kzg.wasm.js +10 -0
  146. package/dist/wasm/internal/kzg.wasm.js.map +1 -0
  147. package/dist/wasm/internal/mnemonic.d.ts +4 -0
  148. package/dist/wasm/internal/mnemonic.d.ts.map +1 -0
  149. package/dist/wasm/internal/mnemonic.js +45 -0
  150. package/dist/wasm/internal/mnemonic.js.map +1 -0
  151. package/dist/wasm/internal/pbkdf2.d.ts +12 -0
  152. package/dist/wasm/internal/pbkdf2.d.ts.map +1 -0
  153. package/dist/wasm/internal/pbkdf2.js +51 -0
  154. package/dist/wasm/internal/pbkdf2.js.map +1 -0
  155. package/dist/wasm/internal/scrypt.d.ts +16 -0
  156. package/dist/wasm/internal/scrypt.d.ts.map +1 -0
  157. package/dist/wasm/internal/scrypt.js +78 -0
  158. package/dist/wasm/internal/scrypt.js.map +1 -0
  159. package/dist/wasm/internal/scrypt.wasm.d.ts +7 -0
  160. package/dist/wasm/internal/scrypt.wasm.d.ts.map +1 -0
  161. package/dist/wasm/internal/scrypt.wasm.js +14 -0
  162. package/dist/wasm/internal/scrypt.wasm.js.map +1 -0
  163. package/dist/wasm/internal/secp256k1.d.ts +16 -0
  164. package/dist/wasm/internal/secp256k1.d.ts.map +1 -0
  165. package/dist/wasm/internal/secp256k1.js +20 -0
  166. package/dist/wasm/internal/secp256k1.js.map +1 -0
  167. package/dist/wasm/internal/secp256k1.wasm.d.ts +3 -0
  168. package/dist/wasm/internal/secp256k1.wasm.d.ts.map +1 -0
  169. package/dist/wasm/internal/secp256k1.wasm.js +10 -0
  170. package/dist/wasm/internal/secp256k1.wasm.js.map +1 -0
  171. package/dist/wasm/internal/x25519.d.ts +4 -0
  172. package/dist/wasm/internal/x25519.d.ts.map +1 -0
  173. package/dist/wasm/internal/x25519.js +21 -0
  174. package/dist/wasm/internal/x25519.js.map +1 -0
  175. package/package.json +64 -2
  176. package/src/core/Engine.ts +84 -11
  177. package/src/core/Hash.ts +59 -0
  178. package/src/core/_test/Block.test.ts +9 -2
  179. package/src/core/_test/Engine.test-d.ts +56 -0
  180. package/src/core/_test/Engine.test.ts +95 -0
  181. package/src/core/_test/Hash.test-d.ts +18 -0
  182. package/src/core/_test/Hash.test.ts +100 -1
  183. package/src/core/_test/Hash.vectors.test.ts +7 -0
  184. package/src/core/_test/Transaction.test.ts +11 -2
  185. package/src/core/internal/engine.ts +8 -8
  186. package/src/index.ts +5 -2
  187. package/src/node/Ed25519.ts +87 -0
  188. package/src/node/Engine.ts +79 -23
  189. package/src/node/Hash.ts +25 -30
  190. package/src/node/Keystore.ts +103 -0
  191. package/src/node/Mnemonic.ts +68 -0
  192. package/src/node/P256.ts +48 -0
  193. package/src/node/X25519.ts +93 -0
  194. package/src/node/_test/Curves.fuzz.ts +76 -0
  195. package/src/node/_test/Ed25519.test-d.ts +35 -0
  196. package/src/node/_test/Ed25519.test.ts +220 -0
  197. package/src/node/_test/Engine.test-d.ts +28 -0
  198. package/src/node/_test/Engine.test.ts +62 -22
  199. package/src/node/_test/Hash.test-d.ts +16 -9
  200. package/src/node/_test/Hash.test.ts +10 -11
  201. package/src/node/_test/Keystore.fuzz.ts +58 -0
  202. package/src/node/_test/Keystore.test-d.ts +43 -0
  203. package/src/node/_test/Keystore.test.ts +198 -0
  204. package/src/node/_test/Mnemonic.fuzz.ts +31 -0
  205. package/src/node/_test/Mnemonic.test-d.ts +21 -0
  206. package/src/node/_test/Mnemonic.test.ts +98 -0
  207. package/src/node/_test/P256.test-d.ts +29 -0
  208. package/src/node/_test/P256.test.ts +102 -0
  209. package/src/node/_test/X25519.test-d.ts +28 -0
  210. package/src/node/_test/X25519.test.ts +239 -0
  211. package/src/node/index.ts +100 -8
  212. package/src/trusted-setups/Paths.ts +1 -0
  213. package/src/trusted-setups/README.md +39 -0
  214. package/src/trusted-setups/Setups.ts +46 -0
  215. package/src/trusted-setups/_test/Paths.test.ts +16 -0
  216. package/src/trusted-setups/_test/Setups.test-d.ts +7 -0
  217. package/src/trusted-setups/_test/Setups.test.ts +43 -0
  218. package/src/trusted-setups/_test/index.test.ts +1 -0
  219. package/src/trusted-setups/index.ts +21 -0
  220. package/src/trusted-setups/internal/paths.ts +4 -1
  221. package/src/trusted-setups/internal/setups/mainnet.source.json +7 -0
  222. package/src/trusted-setups/internal/setups/mainnet.ts +16 -0
  223. package/src/version.ts +1 -1
  224. package/src/wasm/Ed25519.ts +114 -0
  225. package/src/wasm/Engine.ts +78 -31
  226. package/src/wasm/Hash.bench.ts +2 -2
  227. package/src/wasm/Hash.ts +29 -50
  228. package/src/wasm/Keystore.bench.ts +26 -0
  229. package/src/wasm/Keystore.ts +66 -0
  230. package/src/wasm/Kzg.bench.ts +63 -0
  231. package/src/wasm/Kzg.ts +518 -0
  232. package/src/wasm/Mnemonic.ts +44 -0
  233. package/src/wasm/Secp256k1.bench.ts +79 -0
  234. package/src/wasm/Secp256k1.ts +248 -0
  235. package/src/wasm/X25519.ts +70 -0
  236. package/src/wasm/_test/Crypto25519.conformance.ts +57 -0
  237. package/src/wasm/_test/Crypto25519.fuzz.ts +187 -0
  238. package/src/wasm/_test/Ed25519.test-d.ts +28 -0
  239. package/src/wasm/_test/Ed25519.test.ts +168 -0
  240. package/src/wasm/_test/Ed25519.vectors.test.ts +73 -0
  241. package/src/wasm/_test/Engine.test-d.ts +29 -0
  242. package/src/wasm/_test/Engine.test.ts +59 -25
  243. package/src/wasm/_test/Hash.browser.test.ts +14 -7
  244. package/src/wasm/_test/Hash.fuzz.ts +58 -23
  245. package/src/wasm/_test/Hash.test-d.ts +16 -10
  246. package/src/wasm/_test/Hash.test.ts +148 -48
  247. package/src/wasm/_test/Hash.vectors.test.ts +15 -8
  248. package/src/wasm/_test/Keystore.browser.test.ts +73 -0
  249. package/src/wasm/_test/Keystore.fuzz.ts +163 -0
  250. package/src/wasm/_test/Keystore.test-d.ts +42 -0
  251. package/src/wasm/_test/Keystore.test.ts +477 -0
  252. package/src/wasm/_test/Keystore.vectors.test.ts +21 -0
  253. package/src/wasm/_test/Kzg.test-d.ts +19 -0
  254. package/src/wasm/_test/Kzg.test.ts +220 -0
  255. package/src/wasm/_test/Mnemonic.test-d.ts +17 -0
  256. package/src/wasm/_test/Mnemonic.test.ts +110 -0
  257. package/src/wasm/_test/Runtime.test.ts +9 -0
  258. package/src/wasm/_test/Secp256k1.test-d.ts +35 -0
  259. package/src/wasm/_test/Secp256k1.test.ts +354 -0
  260. package/src/wasm/_test/X25519.test-d.ts +21 -0
  261. package/src/wasm/_test/X25519.test.ts +194 -0
  262. package/src/wasm/_test/fixtures.ts +4 -0
  263. package/src/wasm/index.ts +130 -12
  264. package/src/wasm/internal/blake3.ts +45 -0
  265. package/src/wasm/internal/blake3.wasm.ts +11 -0
  266. package/src/wasm/internal/crypto25519.ts +43 -0
  267. package/src/wasm/internal/crypto25519.wasm.ts +11 -0
  268. package/src/wasm/internal/ed25519.ts +31 -0
  269. package/src/wasm/internal/hashes.ts +29 -0
  270. package/src/wasm/internal/hashes.wasm.ts +5 -2
  271. package/src/wasm/internal/instantiate.ts +29 -9
  272. package/src/wasm/internal/keystore.ts +19 -0
  273. package/src/wasm/internal/kzg.ts +50 -0
  274. package/src/wasm/internal/kzg.wasm.ts +11 -0
  275. package/src/wasm/internal/mnemonic.ts +56 -0
  276. package/src/wasm/internal/pbkdf2.ts +86 -0
  277. package/src/wasm/internal/scrypt.ts +131 -0
  278. package/src/wasm/internal/scrypt.wasm.ts +17 -0
  279. package/src/wasm/internal/secp256k1.ts +62 -0
  280. package/src/wasm/internal/secp256k1.wasm.ts +11 -0
  281. package/src/wasm/internal/x25519.ts +29 -0
  282. package/wasm/vendor/c-kzg-4844/LICENSE +201 -0
  283. package/wasm/vendor/c-kzg-4844/blst/LICENSE +201 -0
  284. package/src/trusted-setups/internal/setups/mainnet.txt +0 -4163
@@ -0,0 +1,239 @@
1
+ import * as fs from 'node:fs'
2
+ import { x25519 } from '@noble/curves/ed25519.js'
3
+ import { Hex } from 'ox'
4
+ import { describe, expect, test } from 'vp/test'
5
+ import * as X25519 from '../X25519.js'
6
+
7
+ type LowOrderVector = {
8
+ name: string
9
+ publicKey: string
10
+ }
11
+
12
+ const alicePrivateKey =
13
+ '77076d0a7318a57d3c16c17251b26645df4c2f87ebc0992ab177fba51db92c2a'
14
+ const bobPrivateKey =
15
+ '5dab087e624a8a4b79e17f8b83800ee66f3bb1292618b6fd1c2f8b27ff88e0eb'
16
+
17
+ const lowOrderPublicKeys = JSON.parse(
18
+ fs.readFileSync(
19
+ new URL('../../../test/vectors/x25519/low-order.json', import.meta.url),
20
+ 'utf8',
21
+ ),
22
+ ) as readonly LowOrderVector[]
23
+
24
+ describe('engine', () => {
25
+ test('behavior: exposes only the supported primitives', async () => {
26
+ const engine = await X25519.engine()
27
+
28
+ expect(Object.keys(engine).sort()).toMatchInlineSnapshot(`
29
+ [
30
+ "getPublicKey",
31
+ "getSharedSecret",
32
+ ]
33
+ `)
34
+ })
35
+
36
+ test('behavior: matches RFC 7748 key-agreement vectors', async () => {
37
+ const engine = await X25519.engine()
38
+ const alicePublicKey = engine.getPublicKey(fromHex(alicePrivateKey))
39
+ const bobPublicKey = engine.getPublicKey(fromHex(bobPrivateKey))
40
+
41
+ expect({
42
+ alicePublicKey: Hex.fromBytes(alicePublicKey),
43
+ bobPublicKey: Hex.fromBytes(bobPublicKey),
44
+ sharedSecret: Hex.fromBytes(
45
+ engine.getSharedSecret(fromHex(alicePrivateKey), bobPublicKey),
46
+ ),
47
+ }).toMatchInlineSnapshot(`
48
+ {
49
+ "alicePublicKey": "0x8520f0098930a754748b7ddcb43ef75a0dbf3a0d26381af4eba4a98eaa9b4e6a",
50
+ "bobPublicKey": "0xde9edb7d7b7dc1b4d35b61c2ece435373f8343c85b78674dadfc7e146f882b4f",
51
+ "sharedSecret": "0x4a5d9d5ba4ce2de1728e3bf480350f25e07e21c947d19e3376f09b3c1e161742",
52
+ }
53
+ `)
54
+ })
55
+
56
+ test('behavior: matches RFC 7748 arbitrary-point vectors', async () => {
57
+ const engine = await X25519.engine()
58
+ const vectors = [
59
+ {
60
+ privateKey:
61
+ 'a546e36bf0527c9d3b16154b82465edd62144c0ac1fc5a18506a2244ba449ac4',
62
+ publicKey:
63
+ 'e6db6867583030db3594c1a424b15f7c726624ec26b3353b10a903a6d0ab1c4c',
64
+ },
65
+ {
66
+ privateKey:
67
+ '4b66e9d4d1b4673c5ad22691957d6af5c11b6421e0ea01d42ca4169e7918ba0d',
68
+ publicKey:
69
+ 'e5210f12786811d3f4b7959d0538ae2c31dbe7106fc03c3efc4cd549c715a493',
70
+ },
71
+ ] as const
72
+
73
+ expect(
74
+ vectors.map(({ privateKey, publicKey }) =>
75
+ Hex.fromBytes(
76
+ engine.getSharedSecret(fromHex(privateKey), fromHex(publicKey)),
77
+ ),
78
+ ),
79
+ ).toMatchInlineSnapshot(`
80
+ [
81
+ "0xc3da55379de9c6908e94ea4df28d084f32eccf03491c71f754b4075577a28552",
82
+ "0x95cbde9476e8907d7aade45cb4b873f88b595a68799fa152e6f8f7647aac7957",
83
+ ]
84
+ `)
85
+ })
86
+
87
+ test('behavior: matches the default across private keys', async () => {
88
+ const engine = await X25519.engine()
89
+ const privateKeys = [
90
+ fromHex(alicePrivateKey),
91
+ fromHex(bobPrivateKey),
92
+ new Uint8Array(32),
93
+ new Uint8Array(32).fill(0xff),
94
+ Uint8Array.from({ length: 32 }, (_, index) => index),
95
+ ]
96
+
97
+ for (const [index, privateKey] of privateKeys.entries()) {
98
+ const peerPrivateKey = Uint8Array.from(
99
+ { length: 32 },
100
+ (_, offset) => (offset * 17 + index + 1) % 251,
101
+ )
102
+ const publicKey = x25519.getPublicKey(peerPrivateKey)
103
+ expect(engine.getPublicKey(privateKey)).toEqual(
104
+ x25519.getPublicKey(privateKey),
105
+ )
106
+ expect(engine.getSharedSecret(privateKey, publicKey)).toEqual(
107
+ x25519.getSharedSecret(privateKey, publicKey),
108
+ )
109
+ }
110
+ })
111
+
112
+ test('behavior: masks the public u-coordinate high bit', async () => {
113
+ const engine = await X25519.engine()
114
+ const privateKey = fromHex(alicePrivateKey)
115
+ const publicKey = x25519.getPublicKey(fromHex(bobPrivateKey))
116
+ const highBitPublicKey = publicKey.slice()
117
+ highBitPublicKey[31]! |= 0x80
118
+ const expected = x25519.getSharedSecret(privateKey, publicKey)
119
+
120
+ expect(x25519.getSharedSecret(privateKey, highBitPublicKey)).toEqual(
121
+ expected,
122
+ )
123
+ expect(engine.getSharedSecret(privateKey, highBitPublicKey)).toEqual(
124
+ expected,
125
+ )
126
+ })
127
+
128
+ test('behavior: reduces noncanonical public u-coordinates', async () => {
129
+ const engine = await X25519.engine()
130
+ const privateKey = fromHex(alicePrivateKey)
131
+ // 2^255 - 19 + 9 encodes the base point modulo the field prime.
132
+ const publicKey = fromHex(`f6${'ff'.repeat(30)}7f`)
133
+ const expected = x25519.getPublicKey(privateKey)
134
+
135
+ expect(x25519.getSharedSecret(privateKey, publicKey)).toEqual(expected)
136
+ expect(engine.getSharedSecret(privateKey, publicKey)).toEqual(expected)
137
+ })
138
+
139
+ test('behavior: rejects the complete published low-order set', async () => {
140
+ const engine = await X25519.engine()
141
+ const privateKey = fromHex(alicePrivateKey)
142
+
143
+ expect(lowOrderPublicKeys).toHaveLength(7)
144
+ for (const vector of lowOrderPublicKeys) {
145
+ const publicKey = fromHex(vector.publicKey)
146
+ const highBitPublicKey = publicKey.slice()
147
+ highBitPublicKey[31]! |= 0x80
148
+
149
+ for (const [name, value] of [
150
+ ['published', publicKey],
151
+ ['top-bit alias', highBitPublicKey],
152
+ ] as const) {
153
+ expect(
154
+ () => x25519.getSharedSecret(privateKey, value),
155
+ `${vector.name} (${name})`,
156
+ ).toThrowError()
157
+ expect(
158
+ () => engine.getSharedSecret(privateKey, value),
159
+ `${vector.name} (${name})`,
160
+ ).toThrowError()
161
+ }
162
+ }
163
+ })
164
+
165
+ test('behavior: respects typed-array offsets without mutating inputs', async () => {
166
+ const engine = await X25519.engine()
167
+ const privateKey = offsetView(fromHex(alicePrivateKey))
168
+ const publicKey = offsetView(x25519.getPublicKey(fromHex(bobPrivateKey)))
169
+ const privateKeyBefore = privateKey.slice()
170
+ const publicKeyBefore = publicKey.slice()
171
+
172
+ expect(engine.getPublicKey(privateKey)).toEqual(
173
+ x25519.getPublicKey(privateKey),
174
+ )
175
+ expect(engine.getSharedSecret(privateKey, publicKey)).toEqual(
176
+ x25519.getSharedSecret(privateKey, publicKey),
177
+ )
178
+ expect({ privateKey, publicKey }).toEqual({
179
+ privateKey: privateKeyBefore,
180
+ publicKey: publicKeyBefore,
181
+ })
182
+ })
183
+
184
+ test('behavior: rejects malformed key lengths', async () => {
185
+ const engine = await X25519.engine()
186
+ const privateKey = fromHex(alicePrivateKey)
187
+ const publicKey = x25519.getPublicKey(fromHex(bobPrivateKey))
188
+
189
+ for (const size of [0, 1, 31, 33, 64]) {
190
+ expect(() => engine.getPublicKey(new Uint8Array(size))).toThrowError(
191
+ `X25519 private key must be 32 bytes, got ${size}`,
192
+ )
193
+ expect(() =>
194
+ engine.getSharedSecret(new Uint8Array(size), publicKey),
195
+ ).toThrowError(`X25519 private key must be 32 bytes, got ${size}`)
196
+ expect(() =>
197
+ engine.getSharedSecret(privateKey, new Uint8Array(size)),
198
+ ).toThrowError(`X25519 public key must be 32 bytes, got ${size}`)
199
+ }
200
+ })
201
+
202
+ test('behavior: returns owned Uint8Array values', async () => {
203
+ const engine = await X25519.engine()
204
+ const privateKey = fromHex(alicePrivateKey)
205
+ const publicKey = x25519.getPublicKey(fromHex(bobPrivateKey))
206
+ const outputs = [
207
+ engine.getPublicKey(privateKey),
208
+ engine.getSharedSecret(privateKey, publicKey),
209
+ ]
210
+
211
+ expect(outputs.map((output) => output.constructor === Uint8Array))
212
+ .toMatchInlineSnapshot(`
213
+ [
214
+ true,
215
+ true,
216
+ ]
217
+ `)
218
+ expect(
219
+ engine.getPublicKey(privateKey) === engine.getPublicKey(privateKey),
220
+ ).toMatchInlineSnapshot('false')
221
+ })
222
+
223
+ test('behavior: returns a fresh engine', async () => {
224
+ const first = await X25519.engine()
225
+ const second = await X25519.engine()
226
+
227
+ expect(first === second).toMatchInlineSnapshot('false')
228
+ })
229
+ })
230
+
231
+ function fromHex(value: string): Uint8Array {
232
+ return Hex.toBytes(`0x${value}`)
233
+ }
234
+
235
+ function offsetView(value: Uint8Array): Uint8Array {
236
+ const bytes = new Uint8Array(value.length + 4).fill(0xff)
237
+ bytes.set(value, 2)
238
+ return bytes.subarray(2, -2)
239
+ }
package/src/node/index.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  /** @entrypointCategory Node */
2
2
 
3
3
  /**
4
- * Node.js implementations of Ox's hash primitives, backed by `node:crypto`.
4
+ * Node.js implementations of Ox's supported cryptographic primitives, backed
5
+ * by `node:crypto`.
5
6
  *
6
7
  * Import this entrypoint only in Node.js. Its static `node:crypto` dependency
7
8
  * is intentionally kept outside Ox's runtime-neutral entrypoint.
@@ -9,10 +10,9 @@
9
10
  * @example
10
11
  * ```ts twoslash
11
12
  * // @noErrors
12
- * import { Hash } from 'ox'
13
- * import { Engine } from 'ox/node'
13
+ * import { Engine, Hash } from 'ox/node'
14
14
  *
15
- * await Engine.load()
15
+ * await Engine.install()
16
16
  *
17
17
  * Hash.sha256('0xdeadbeef')
18
18
  * ```
@@ -22,15 +22,33 @@
22
22
  export * as Engine from './Engine.js'
23
23
 
24
24
  /**
25
- * Node.js implementations of Ox's supported hash primitives.
25
+ * Ox's Ed25519 API and its supported Node.js engine primitives.
26
26
  *
27
27
  * @example
28
28
  * ```ts twoslash
29
29
  * // @noErrors
30
- * import { Engine, Hash } from 'ox'
31
- * import * as NodeHash from 'ox/node/Hash'
30
+ * import { Engine } from 'ox'
31
+ * import { Ed25519 } from 'ox/node'
32
32
  *
33
- * Engine.set(await NodeHash.create())
33
+ * await Engine.install({ Ed25519: Ed25519.engine() })
34
+ *
35
+ * Ed25519.getPublicKey({ privateKey: '0x...' })
36
+ * ```
37
+ *
38
+ * @category Crypto
39
+ */
40
+ export * as Ed25519 from './Ed25519.js'
41
+
42
+ /**
43
+ * Ox's hash API and its supported Node.js engine primitives.
44
+ *
45
+ * @example
46
+ * ```ts twoslash
47
+ * // @noErrors
48
+ * import { Engine } from 'ox'
49
+ * import { Hash } from 'ox/node'
50
+ *
51
+ * await Engine.install({ Hash: Hash.engine() })
34
52
  *
35
53
  * Hash.sha256('0xdeadbeef')
36
54
  * ```
@@ -38,3 +56,77 @@ export * as Engine from './Engine.js'
38
56
  * @category Crypto
39
57
  */
40
58
  export * as Hash from './Hash.js'
59
+
60
+ /**
61
+ * Ox's keystore API and its supported Node.js engine primitives.
62
+ *
63
+ * @example
64
+ * ```ts twoslash
65
+ * // @noErrors
66
+ * import { Engine } from 'ox'
67
+ * import { Keystore } from 'ox/node'
68
+ *
69
+ * await Engine.install({ Keystore: Keystore.engine() })
70
+ *
71
+ * Keystore.pbkdf2({ password: 'testpassword' })
72
+ * ```
73
+ *
74
+ * @category Crypto
75
+ */
76
+ export * as Keystore from './Keystore.js'
77
+
78
+ /**
79
+ * Ox's mnemonic API and its Node.js BIP-39 seed engine primitive.
80
+ *
81
+ * @example
82
+ * ```ts twoslash
83
+ * // @noErrors
84
+ * import { Engine } from 'ox'
85
+ * import { Mnemonic } from 'ox/node'
86
+ *
87
+ * await Engine.install({ Mnemonic: Mnemonic.engine() })
88
+ *
89
+ * Mnemonic.toSeed(
90
+ * 'test test test test test test test test test test test junk'
91
+ * )
92
+ * ```
93
+ *
94
+ * @category Crypto
95
+ */
96
+ export * as Mnemonic from './Mnemonic.js'
97
+
98
+ /**
99
+ * Ox's P256 API and its Node.js public-key derivation engine primitive.
100
+ *
101
+ * @example
102
+ * ```ts twoslash
103
+ * // @noErrors
104
+ * import { Engine } from 'ox'
105
+ * import { P256 } from 'ox/node'
106
+ *
107
+ * await Engine.install({ P256: P256.engine() })
108
+ *
109
+ * P256.getPublicKey({ privateKey: '0x...' })
110
+ * ```
111
+ *
112
+ * @category Crypto
113
+ */
114
+ export * as P256 from './P256.js'
115
+
116
+ /**
117
+ * Ox's X25519 API and its supported Node.js engine primitives.
118
+ *
119
+ * @example
120
+ * ```ts twoslash
121
+ * // @noErrors
122
+ * import { Engine } from 'ox'
123
+ * import { X25519 } from 'ox/node'
124
+ *
125
+ * await Engine.install({ X25519: X25519.engine() })
126
+ *
127
+ * X25519.getPublicKey({ privateKey: '0x...' })
128
+ * ```
129
+ *
130
+ * @category Crypto
131
+ */
132
+ export * as X25519 from './X25519.js'
@@ -1,3 +1,4 @@
1
1
  import { path } from './internal/paths.js'
2
2
 
3
+ /** File-system path to the Ethereum mainnet trusted setup. */
3
4
  export const mainnet = path('mainnet')
@@ -0,0 +1,39 @@
1
+ # Trusted setup maintenance
2
+
3
+ Ox bundles the finalized Ethereum KZG ceremony output. This setup is not a
4
+ rolling network parameter, so a new `c-kzg-4844` release does not normally
5
+ change its points.
6
+
7
+ The committed `mainnet.source.json` records the reviewed `c-kzg-4844` release
8
+ tag, source path, source SHA-256, and generated JSON SHA-256.
9
+
10
+ ## Refresh from c-kzg
11
+
12
+ 1. Review the latest official
13
+ [`c-kzg-4844` release](https://github.com/ethereum/c-kzg-4844/releases/latest)
14
+ and its `src/trusted_setup.txt` changes. Do not update from a moving branch.
15
+ 2. Pass the selected release tag explicitly:
16
+
17
+ ```bash
18
+ pnpm trusted-setups:update v2.1.8
19
+ ```
20
+
21
+ The command downloads that tagged file, requires 4,096 G1 Lagrange points,
22
+ 4,096 G1 monomial points, and 65 G2 monomial points, then regenerates the
23
+ canonical JSON, source metadata, and packed TypeScript artifact.
24
+
25
+ 3. Inspect the setup and metadata diff. Treat any point change as
26
+ security-sensitive. An implementation-only `c-kzg-4844` release should
27
+ change only the recorded tag when the source bytes are identical.
28
+ 4. Verify the generated artifacts and KZG conformance:
29
+
30
+ ```bash
31
+ pnpm trusted-setups:check
32
+ SKIP_GLOBAL_SETUP=1 pnpm test --project core --bail=1 \
33
+ src/trusted-setups src/wasm/_test/Kzg.test.ts
34
+ pnpm check:types
35
+ ```
36
+
37
+ `mainnet.json` remains available for file-based consumers through
38
+ `Paths.mainnet`. `mainnet.ts` is the independently tree-shakeable packed
39
+ artifact behind `Setups.mainnet`.
@@ -0,0 +1,46 @@
1
+ import * as Base64 from '../core/Base64.js'
2
+ import type * as Bytes from '../core/Bytes.js'
3
+ import {
4
+ g1Lagrange,
5
+ g1Monomial,
6
+ g2Monomial,
7
+ } from './internal/setups/mainnet.js'
8
+
9
+ /**
10
+ * Trusted setup points for EIP-4844 and EIP-7594 KZG operations.
11
+ */
12
+ export type TrustedSetup = {
13
+ /** G1 points in Lagrange form. */
14
+ readonly g1_lagrange: Bytes.Bytes
15
+ /** G1 points in monomial form. */
16
+ readonly g1_monomial: Bytes.Bytes
17
+ /** G2 points in monomial form. */
18
+ readonly g2_monomial: Bytes.Bytes
19
+ }
20
+
21
+ /**
22
+ * Ethereum mainnet trusted setup for EIP-4844 and EIP-7594.
23
+ *
24
+ * The setup stores packed points and is safe to reuse across `Kzg.create`
25
+ * calls. `Kzg.create` copies every field before asynchronous initialization.
26
+ *
27
+ * Treat the exported byte arrays as read-only.
28
+ *
29
+ * @example
30
+ * ```ts twoslash
31
+ * // @noErrors
32
+ * import { Setups } from 'ox/trusted-setups'
33
+ * import { Kzg } from 'ox/wasm'
34
+ *
35
+ * const kzg = await Kzg.create({
36
+ * trustedSetup: Setups.mainnet
37
+ * })
38
+ *
39
+ * kzg.dispose()
40
+ * ```
41
+ */
42
+ export const mainnet: TrustedSetup = /* @__PURE__ */ Object.freeze({
43
+ g1_lagrange: /* @__PURE__ */ Base64.toBytes(g1Lagrange),
44
+ g1_monomial: /* @__PURE__ */ Base64.toBytes(g1Monomial),
45
+ g2_monomial: /* @__PURE__ */ Base64.toBytes(g2Monomial),
46
+ })
@@ -1,3 +1,4 @@
1
+ import { readFileSync } from 'node:fs'
1
2
  import { expect, test } from 'vp/test'
2
3
  import * as Module from '../Paths.js'
3
4
 
@@ -8,3 +9,18 @@ test('exports', () => {
8
9
  ]
9
10
  `)
10
11
  })
12
+
13
+ test('mainnet resolves to the packaged trusted setup', () => {
14
+ const setup = JSON.parse(readFileSync(Module.mainnet, 'utf8'))
15
+ expect({
16
+ g1Lagrange: setup.g1_lagrange.length,
17
+ g1Monomial: setup.g1_monomial.length,
18
+ g2Monomial: setup.g2_monomial.length,
19
+ }).toMatchInlineSnapshot(`
20
+ {
21
+ "g1Lagrange": 4096,
22
+ "g1Monomial": 4096,
23
+ "g2Monomial": 65,
24
+ }
25
+ `)
26
+ })
@@ -0,0 +1,7 @@
1
+ import { expectTypeOf, test } from 'vp/test'
2
+ import type * as WasmKzg from '../../wasm/Kzg.js'
3
+ import * as Setups from '../Setups.js'
4
+
5
+ test('mainnet satisfies the WASM KZG trusted setup', () => {
6
+ expectTypeOf(Setups.mainnet).toMatchTypeOf<WasmKzg.TrustedSetup>()
7
+ })
@@ -0,0 +1,43 @@
1
+ import { describe, expect, test } from 'vp/test'
2
+ import * as Hex from '../../core/Hex.js'
3
+ import * as Setups from '../Setups.js'
4
+
5
+ describe('mainnet', () => {
6
+ test('exports the canonical PeerDAS setup as packed points', () => {
7
+ expect({
8
+ g1Lagrange: {
9
+ bytes: Setups.mainnet.g1_lagrange.length,
10
+ first: Hex.fromBytes(Setups.mainnet.g1_lagrange.slice(0, 48)),
11
+ last: Hex.fromBytes(Setups.mainnet.g1_lagrange.slice(-48)),
12
+ },
13
+ g1Monomial: {
14
+ bytes: Setups.mainnet.g1_monomial.length,
15
+ first: Hex.fromBytes(Setups.mainnet.g1_monomial.slice(0, 48)),
16
+ last: Hex.fromBytes(Setups.mainnet.g1_monomial.slice(-48)),
17
+ },
18
+ g2Monomial: {
19
+ bytes: Setups.mainnet.g2_monomial.length,
20
+ first: Hex.fromBytes(Setups.mainnet.g2_monomial.slice(0, 96)),
21
+ last: Hex.fromBytes(Setups.mainnet.g2_monomial.slice(-96)),
22
+ },
23
+ }).toMatchInlineSnapshot(`
24
+ {
25
+ "g1Lagrange": {
26
+ "bytes": 196608,
27
+ "first": "0xa0413c0dcafec6dbc9f47d66785cf1e8c981044f7d13cfe3e4fcbb71b5408dfde6312493cb3c1d30516cb3ca88c03654",
28
+ "last": "0x825a6f586726c68d45f00ad0f5a4436523317939a47713f78fd4fe81cd74236fdac1b04ecd97c2d0267d6f4981d7beb1",
29
+ },
30
+ "g1Monomial": {
31
+ "bytes": 196608,
32
+ "first": "0x97f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb",
33
+ "last": "0xb0bfaf56a5aa59b48960aa7c1617e832e65c823523fb2a5cd44ba606800501cf873e8db1d0dda64065285743dc40786e",
34
+ },
35
+ "g2Monomial": {
36
+ "bytes": 6240,
37
+ "first": "0x93e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8",
38
+ "last": "0x92dcc5a1c8c3e1b28b1524e3dd6dbecd63017c9201da9dbe077f1b82adc08c50169f56fc7b5a3b28ec6b89254de3e2fd12838a761053437883c3e01ba616670cea843754548ef84bcc397de2369adcca2ab54cd73c55dc68d87aec3fc2fe4f10",
39
+ },
40
+ }
41
+ `)
42
+ })
43
+ })
@@ -5,6 +5,7 @@ test('exports', () => {
5
5
  expect(Object.keys(Module)).toMatchInlineSnapshot(`
6
6
  [
7
7
  "Paths",
8
+ "Setups",
8
9
  ]
9
10
  `)
10
11
  })
@@ -1 +1,22 @@
1
+ /**
2
+ * File-system paths for trusted setup files bundled with Ox.
3
+ */
1
4
  export * as Paths from './Paths.js'
5
+
6
+ /**
7
+ * Trusted setup data bundled with Ox.
8
+ *
9
+ * @example
10
+ * ```ts twoslash
11
+ * // @noErrors
12
+ * import { Setups } from 'ox/trusted-setups'
13
+ * import { Kzg } from 'ox/wasm'
14
+ *
15
+ * const kzg = await Kzg.create({
16
+ * trustedSetup: Setups.mainnet
17
+ * })
18
+ *
19
+ * kzg.dispose()
20
+ * ```
21
+ */
22
+ export * as Setups from './Setups.js'
@@ -10,5 +10,8 @@ export function path(name: string) {
10
10
  import.meta.url,
11
11
  )
12
12
  const __dirname = dirname(__filename)
13
- return resolve(__dirname, `./setups/${name}.json`)
13
+ return resolve(
14
+ __dirname,
15
+ `../../../src/trusted-setups/internal/setups/${name}.json`,
16
+ )
14
17
  }
@@ -0,0 +1,7 @@
1
+ {
2
+ "path": "src/trusted_setup.txt",
3
+ "repository": "https://github.com/ethereum/c-kzg-4844",
4
+ "setupSha256": "c4732d98dd1452318e1f1943e240fa4c202a8973a44c24e68c937f86b00f9cb2",
5
+ "sourceSha256": "d39b9f2d047cc9dca2de58f264b6a09448ccd34db967881a6713eacacf0f26b7",
6
+ "tag": "v2.1.8"
7
+ }