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,67 @@
1
+ import * as crypto from 'node:crypto';
2
+ export * from '../core/Ed25519.js';
3
+ const privateKeyPrefix = Buffer.from('302e020100300506032b657004220420', 'hex');
4
+ /**
5
+ * Creates a Node.js implementation of the [`Ed25519`](/api/Ed25519) engine
6
+ * slot, without installing it.
7
+ *
8
+ * Node's verifier does not implement Ox's ZIP-215 verification semantics, so
9
+ * this engine deliberately omits `verify`. Public-key conversion and random
10
+ * key generation also remain on Ox's default implementation.
11
+ *
12
+ * @example
13
+ * ```ts twoslash
14
+ * // @noErrors
15
+ * import { Engine } from 'ox'
16
+ * import { Ed25519 } from 'ox/node'
17
+ *
18
+ * await Engine.install({ Ed25519: Ed25519.engine() })
19
+ *
20
+ * Ed25519.getPublicKey({ privateKey: '0x...' })
21
+ * ```
22
+ *
23
+ * @returns The raw `Ed25519` engine slot.
24
+ */
25
+ export function engine() {
26
+ return Promise.resolve({
27
+ getPublicKey: (privateKey) => rawPublicKey(crypto.createPublicKey(toPrivateKey(privateKey))),
28
+ sign: (payload, privateKey) => new Uint8Array(crypto.sign(null, payload, toPrivateKey(privateKey))),
29
+ toMontgomerySecret: (privateKey) => {
30
+ assertLength(privateKey);
31
+ const digest = crypto.hash('sha512', privateKey, 'buffer');
32
+ try {
33
+ const secretKey = Uint8Array.from(digest.subarray(0, 32));
34
+ secretKey[0] &= 248;
35
+ secretKey[31] &= 127;
36
+ secretKey[31] |= 64;
37
+ return secretKey;
38
+ }
39
+ finally {
40
+ digest.fill(0);
41
+ }
42
+ },
43
+ });
44
+ }
45
+ function assertLength(key) {
46
+ if (key.length !== 32)
47
+ throw new RangeError(`Ed25519 private key must be 32 bytes, got ${key.length}`);
48
+ }
49
+ function rawPublicKey(publicKey) {
50
+ const der = publicKey.export({ format: 'der', type: 'spki' });
51
+ return Uint8Array.from(der.subarray(-32));
52
+ }
53
+ function toPrivateKey(privateKey) {
54
+ assertLength(privateKey);
55
+ const der = Buffer.concat([privateKeyPrefix, privateKey]);
56
+ try {
57
+ return crypto.createPrivateKey({
58
+ format: 'der',
59
+ key: der,
60
+ type: 'pkcs8',
61
+ });
62
+ }
63
+ finally {
64
+ der.fill(0);
65
+ }
66
+ }
67
+ //# sourceMappingURL=Ed25519.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Ed25519.js","sourceRoot":"","sources":["../../src/node/Ed25519.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,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,MAAM,EAAE,CAC1D,CAAA;AACL,CAAC;AAED,SAAS,YAAY,CAAC,SAA2B;IAC/C,MAAM,GAAG,GAAG,SAAS,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAA;IAC7D,OAAO,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;AAC3C,CAAC;AAED,SAAS,YAAY,CAAC,UAAsB;IAC1C,YAAY,CAAC,UAAU,CAAC,CAAA;IACxB,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,gBAAgB,EAAE,UAAU,CAAC,CAAC,CAAA;IACzD,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,gBAAgB,CAAC;YAC7B,MAAM,EAAE,KAAK;YACb,GAAG,EAAE,GAAG;YACR,IAAI,EAAE,OAAO;SACd,CAAC,CAAA;IACJ,CAAC;YAAS,CAAC;QACT,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACb,CAAC;AACH,CAAC"}
@@ -1,30 +1,36 @@
1
1
  import * as CoreEngine from '../core/Engine.js';
2
2
  import type * as Errors from '../core/Errors.js';
3
+ import * as Ed25519 from './Ed25519.js';
3
4
  import * as Hash from './Hash.js';
5
+ import * as Keystore from './Keystore.js';
6
+ import * as Mnemonic from './Mnemonic.js';
7
+ import * as P256 from './P256.js';
8
+ import * as X25519 from './X25519.js';
9
+ export { AsyncScopeError, get, InvalidSlotValueError, reset, set, UnknownPrimitiveError, UnknownSlotError, with, } from '../core/Engine.js';
10
+ export type { Bls, Ecdh, Ecdsa, Eddsa, Engine, Hash, Keystore, Mnemonic, } from '../core/Engine.js';
4
11
  /**
5
- * Creates and installs every Node.js implementation this entrypoint provides.
12
+ * Installs every Node.js implementation this entrypoint provides.
6
13
  *
7
- * The function is asynchronous to match the `ox/wasm` entrypoint, even though
8
- * Node's built-in cryptography needs no compilation. Call it once during
9
- * startup, before any cryptographic operation.
14
+ * Slots initialize in parallel and are installed atomically. Call this once
15
+ * during startup, before any cryptographic operation.
10
16
  *
11
17
  * @example
12
18
  * ```ts twoslash
13
19
  * // @noErrors
14
- * import { Hash } from 'ox'
15
- * import { Engine } from 'ox/node'
20
+ * import { Engine, Hash } from 'ox/node'
16
21
  *
17
- * await Engine.load()
22
+ * await Engine.install()
18
23
  *
19
24
  * Hash.sha256('0xdeadbeef')
20
25
  * ```
21
26
  *
22
27
  * @returns The engine that was installed.
23
28
  */
24
- export declare function load(): Promise<load.ReturnType>;
25
- export declare namespace load {
26
- type ReturnType = create.ReturnType;
27
- type ErrorType = create.ErrorType | CoreEngine.set.ErrorType | Errors.GlobalErrorType;
29
+ export declare function install(): Promise<install.ReturnType>;
30
+ export declare namespace install {
31
+ /** Every slot this entrypoint installs, each with its primitives present. */
32
+ type ReturnType = engine.ReturnType;
33
+ type ErrorType = engine.ErrorType | CoreEngine.install.ErrorType;
28
34
  }
29
35
  /**
30
36
  * Creates every Node.js implementation this entrypoint provides, without
@@ -39,17 +45,24 @@ export declare namespace load {
39
45
  * import { Engine, Hash } from 'ox'
40
46
  * import { Engine as NodeEngine } from 'ox/node'
41
47
  *
42
- * const node = await NodeEngine.create()
48
+ * const node = await NodeEngine.engine()
43
49
  *
44
50
  * Engine.with(node, () => Hash.sha256('0xdeadbeef'))
45
51
  * ```
46
52
  *
47
53
  * @returns An engine, ready to install.
48
54
  */
49
- export declare function create(): Promise<create.ReturnType>;
50
- export declare namespace create {
55
+ export declare function engine(): Promise<engine.ReturnType>;
56
+ export declare namespace engine {
51
57
  /** Every slot this entrypoint supplies, each with its primitives present. */
52
- type ReturnType = Hash.create.ReturnType;
53
- type ErrorType = Hash.create.ErrorType | Errors.GlobalErrorType;
58
+ type ReturnType = {
59
+ Ed25519: Ed25519.engine.ReturnType;
60
+ Hash: Hash.engine.ReturnType;
61
+ Keystore: Keystore.engine.ReturnType;
62
+ Mnemonic: Mnemonic.engine.ReturnType;
63
+ P256: P256.engine.ReturnType;
64
+ X25519: X25519.engine.ReturnType;
65
+ };
66
+ type ErrorType = Ed25519.engine.ErrorType | Hash.engine.ErrorType | Keystore.engine.ErrorType | Mnemonic.engine.ErrorType | P256.engine.ErrorType | X25519.engine.ErrorType | Errors.GlobalErrorType;
54
67
  }
55
68
  //# sourceMappingURL=Engine.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Engine.d.ts","sourceRoot":"","sources":["../../src/node/Engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAIrD;AAED,MAAM,CAAC,OAAO,WAAW,IAAI,CAAC;IAC5B,KAAK,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;IAEnC,KAAK,SAAS,GACV,MAAM,CAAC,SAAS,GAChB,UAAU,CAAC,GAAG,CAAC,SAAS,GACxB,MAAM,CAAC,eAAe,CAAA;CAC3B;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAEzD;AAED,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,6EAA6E;IAC7E,KAAK,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,CAAA;IAExC,KAAK,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,eAAe,CAAA;CAChE"}
1
+ {"version":3,"file":"Engine.d.ts","sourceRoot":"","sources":["../../src/node/Engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,KAAK,MAAM,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C,UAAU,CAAA;QACpC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,CAAA;QAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAA;KACjC,CAAA;IAED,KAAK,SAAS,GACV,OAAO,CAAC,MAAM,CAAC,SAAS,GACxB,IAAI,CAAC,MAAM,CAAC,SAAS,GACrB,QAAQ,CAAC,MAAM,CAAC,SAAS,GACzB,QAAQ,CAAC,MAAM,CAAC,SAAS,GACzB,IAAI,CAAC,MAAM,CAAC,SAAS,GACrB,MAAM,CAAC,MAAM,CAAC,SAAS,GACvB,MAAM,CAAC,eAAe,CAAA;CAC3B"}
@@ -1,29 +1,38 @@
1
1
  import * as CoreEngine from '../core/Engine.js';
2
+ import * as Ed25519 from './Ed25519.js';
2
3
  import * as Hash from './Hash.js';
4
+ import * as Keystore from './Keystore.js';
5
+ import * as Mnemonic from './Mnemonic.js';
6
+ import * as P256 from './P256.js';
7
+ import * as X25519 from './X25519.js';
8
+ export { AsyncScopeError, get, InvalidSlotValueError, reset, set, UnknownPrimitiveError, UnknownSlotError, with, } from '../core/Engine.js';
3
9
  /**
4
- * Creates and installs every Node.js implementation this entrypoint provides.
10
+ * Installs every Node.js implementation this entrypoint provides.
5
11
  *
6
- * The function is asynchronous to match the `ox/wasm` entrypoint, even though
7
- * Node's built-in cryptography needs no compilation. Call it once during
8
- * startup, before any cryptographic operation.
12
+ * Slots initialize in parallel and are installed atomically. Call this once
13
+ * during startup, before any cryptographic operation.
9
14
  *
10
15
  * @example
11
16
  * ```ts twoslash
12
17
  * // @noErrors
13
- * import { Hash } from 'ox'
14
- * import { Engine } from 'ox/node'
18
+ * import { Engine, Hash } from 'ox/node'
15
19
  *
16
- * await Engine.load()
20
+ * await Engine.install()
17
21
  *
18
22
  * Hash.sha256('0xdeadbeef')
19
23
  * ```
20
24
  *
21
25
  * @returns The engine that was installed.
22
26
  */
23
- export async function load() {
24
- const engine = await create();
25
- CoreEngine.set(engine);
26
- return engine;
27
+ export function install() {
28
+ return CoreEngine.install({
29
+ Ed25519: Ed25519.engine(),
30
+ Hash: Hash.engine(),
31
+ Keystore: Keystore.engine(),
32
+ Mnemonic: Mnemonic.engine(),
33
+ P256: P256.engine(),
34
+ X25519: X25519.engine(),
35
+ });
27
36
  }
28
37
  /**
29
38
  * Creates every Node.js implementation this entrypoint provides, without
@@ -38,14 +47,29 @@ export async function load() {
38
47
  * import { Engine, Hash } from 'ox'
39
48
  * import { Engine as NodeEngine } from 'ox/node'
40
49
  *
41
- * const node = await NodeEngine.create()
50
+ * const node = await NodeEngine.engine()
42
51
  *
43
52
  * Engine.with(node, () => Hash.sha256('0xdeadbeef'))
44
53
  * ```
45
54
  *
46
55
  * @returns An engine, ready to install.
47
56
  */
48
- export async function create() {
49
- return { ...(await Hash.create()) };
57
+ export async function engine() {
58
+ const [ed25519, hash, keystore, mnemonic, p256, x25519] = await Promise.all([
59
+ Ed25519.engine(),
60
+ Hash.engine(),
61
+ Keystore.engine(),
62
+ Mnemonic.engine(),
63
+ P256.engine(),
64
+ X25519.engine(),
65
+ ]);
66
+ return {
67
+ Ed25519: ed25519,
68
+ Hash: hash,
69
+ Keystore: keystore,
70
+ Mnemonic: mnemonic,
71
+ P256: p256,
72
+ X25519: x25519,
73
+ };
50
74
  }
51
75
  //# sourceMappingURL=Engine.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Engine.js","sourceRoot":"","sources":["../../src/node/Engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAE/C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,KAAK,UAAU,IAAI;IACxB,MAAM,MAAM,GAAG,MAAM,MAAM,EAAE,CAAA;IAC7B,UAAU,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;IACtB,OAAO,MAAM,CAAA;AACf,CAAC;AAWD;;;;;;;;;;;;;;;;;;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AAO,CAAC,MAAM,EAAE;QAChB,IAAI,CAAC,MAAM,EAAE;QACb,QAAQ,CAAC,MAAM,EAAE;QACjB,QAAQ,CAAC,MAAM,EAAE;QACjB,IAAI,CAAC,MAAM,EAAE;QACb,MAAM,CAAC,MAAM,EAAE;KAChB,CAAC,CAAA;IACF,OAAO;QACL,OAAO,EAAE,OAAO;QAChB,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,QAAQ;QAClB,QAAQ,EAAE,QAAQ;QAClB,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,MAAM;KACf,CAAA;AACH,CAAC"}
@@ -1,38 +1,36 @@
1
1
  import type * as Engine from '../core/Engine.js';
2
2
  import type * as Errors from '../core/Errors.js';
3
+ export * from '../core/Hash.js';
3
4
  /**
4
- * Creates Node.js implementations of the [`Hash`](/api/Hash) primitives, without
5
- * installing them.
5
+ * Creates a Node.js implementation of the [`Hash`](/api/Hash) engine slot,
6
+ * without installing it.
6
7
  *
7
- * Most callers want {@link ox#Engine.load} instead, which installs every
8
- * implementation this entrypoint provides. Reach for this to take the `Hash`
9
- * slot on its own, or to hold the implementation without touching the
10
- * installed engine.
8
+ * Most callers want [`Engine.install`](/node/crypto/Engine/install) instead,
9
+ * which installs every implementation this entrypoint provides. Reach for this
10
+ * to install or hold the `Hash` slot on its own.
11
11
  *
12
- * Node's `sha3-256` is not Ethereum Keccak256, so this engine deliberately
13
- * omits `keccak256`. Any earlier override remains installed; otherwise Ox uses
14
- * its default implementation.
12
+ * Node does not provide BLAKE3, and its `sha3-256` is not Ethereum Keccak256, so
13
+ * this engine deliberately omits `blake3` and `keccak256`. Any earlier override
14
+ * remains installed; otherwise Ox uses its default implementation.
15
15
  *
16
16
  * @example
17
17
  * ```ts twoslash
18
18
  * // @noErrors
19
- * import { Engine, Hash } from 'ox'
20
- * import * as NodeHash from 'ox/node/Hash'
19
+ * import { Engine } from 'ox'
20
+ * import { Hash } from 'ox/node'
21
21
  *
22
- * Engine.set(await NodeHash.create())
22
+ * await Engine.install({ Hash: Hash.engine() })
23
23
  *
24
24
  * Hash.sha256('0xdeadbeef')
25
25
  * ```
26
26
  *
27
- * @returns An engine supplying the `Hash` slot.
27
+ * @returns The raw `Hash` engine slot.
28
28
  */
29
- export declare function create(): Promise<create.ReturnType>;
30
- export declare namespace create {
31
- /** The `Hash` slot, carrying every primitive this module implements. */
29
+ export declare function engine(): Promise<engine.ReturnType>;
30
+ export declare namespace engine {
31
+ /** Every `Hash` primitive this module implements. */
32
32
  type ReturnType = {
33
- Hash: {
34
- [key in 'hmacSha256' | 'ripemd160' | 'sha256']-?: NonNullable<Engine.Hash[key]>;
35
- };
33
+ [key in 'hmacSha256' | 'ripemd160' | 'sha256']-?: NonNullable<Engine.Hash[key]>;
36
34
  };
37
35
  type ErrorType = Errors.GlobalErrorType;
38
36
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Hash.d.ts","sourceRoot":"","sources":["../../src/node/Hash.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAYnD;AAED,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,wEAAwE;IACxE,KAAK,UAAU,GAAG;QAChB,IAAI,EAAE;aACH,GAAG,IAAI,YAAY,GAAG,WAAW,GAAG,QAAQ,CAAC,CAAC,GAAG,WAAW,CAC3D,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CACjB;SACF,CAAA;KACF,CAAA;IAED,KAAK,SAAS,GAAG,MAAM,CAAC,eAAe,CAAA;CACxC"}
1
+ {"version":3,"file":"Hash.d.ts","sourceRoot":"","sources":["../../src/node/Hash.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAEhD,cAAc,iBAAiB,CAAA;AAE/B;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAQnD;AAED,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,qDAAqD;IACrD,KAAK,UAAU,GAAG;SACf,GAAG,IAAI,YAAY,GAAG,WAAW,GAAG,QAAQ,CAAC,CAAC,GAAG,WAAW,CAC3D,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CACjB;KACF,CAAA;IAED,KAAK,SAAS,GAAG,MAAM,CAAC,eAAe,CAAA;CACxC"}
package/dist/node/Hash.js CHANGED
@@ -1,37 +1,35 @@
1
1
  import * as crypto from 'node:crypto';
2
+ export * from '../core/Hash.js';
2
3
  /**
3
- * Creates Node.js implementations of the [`Hash`](/api/Hash) primitives, without
4
- * installing them.
4
+ * Creates a Node.js implementation of the [`Hash`](/api/Hash) engine slot,
5
+ * without installing it.
5
6
  *
6
- * Most callers want {@link ox#Engine.load} instead, which installs every
7
- * implementation this entrypoint provides. Reach for this to take the `Hash`
8
- * slot on its own, or to hold the implementation without touching the
9
- * installed engine.
7
+ * Most callers want [`Engine.install`](/node/crypto/Engine/install) instead,
8
+ * which installs every implementation this entrypoint provides. Reach for this
9
+ * to install or hold the `Hash` slot on its own.
10
10
  *
11
- * Node's `sha3-256` is not Ethereum Keccak256, so this engine deliberately
12
- * omits `keccak256`. Any earlier override remains installed; otherwise Ox uses
13
- * its default implementation.
11
+ * Node does not provide BLAKE3, and its `sha3-256` is not Ethereum Keccak256, so
12
+ * this engine deliberately omits `blake3` and `keccak256`. Any earlier override
13
+ * remains installed; otherwise Ox uses its default implementation.
14
14
  *
15
15
  * @example
16
16
  * ```ts twoslash
17
17
  * // @noErrors
18
- * import { Engine, Hash } from 'ox'
19
- * import * as NodeHash from 'ox/node/Hash'
18
+ * import { Engine } from 'ox'
19
+ * import { Hash } from 'ox/node'
20
20
  *
21
- * Engine.set(await NodeHash.create())
21
+ * await Engine.install({ Hash: Hash.engine() })
22
22
  *
23
23
  * Hash.sha256('0xdeadbeef')
24
24
  * ```
25
25
  *
26
- * @returns An engine supplying the `Hash` slot.
26
+ * @returns The raw `Hash` engine slot.
27
27
  */
28
- export function create() {
28
+ export function engine() {
29
29
  return Promise.resolve({
30
- Hash: {
31
- hmacSha256: (key, message) => new Uint8Array(crypto.createHmac('sha256', key).update(message).digest()),
32
- ripemd160: (input) => new Uint8Array(crypto.hash('ripemd160', input, 'buffer')),
33
- sha256: (input) => new Uint8Array(crypto.hash('sha256', input, 'buffer')),
34
- },
30
+ hmacSha256: (key, message) => new Uint8Array(crypto.createHmac('sha256', key).update(message).digest()),
31
+ ripemd160: (input) => new Uint8Array(crypto.hash('ripemd160', input, 'buffer')),
32
+ sha256: (input) => new Uint8Array(crypto.hash('sha256', input, 'buffer')),
35
33
  });
36
34
  }
37
35
  //# sourceMappingURL=Hash.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Hash.js","sourceRoot":"","sources":["../../src/node/Hash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAIrC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,MAAM;IACpB,OAAO,OAAO,CAAC,OAAO,CAAC;QACrB,IAAI,EAAE;YACJ,UAAU,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAC3B,IAAI,UAAU,CACZ,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAC1D;YACH,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CACnB,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;YAC3D,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;SAC1E;KACF,CAAC,CAAA;AACJ,CAAC"}
1
+ {"version":3,"file":"Hash.js","sourceRoot":"","sources":["../../src/node/Hash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAIrC,cAAc,iBAAiB,CAAA;AAE/B;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,MAAM;IACpB,OAAO,OAAO,CAAC,OAAO,CAAC;QACrB,UAAU,EAAE,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE,CAC3B,IAAI,UAAU,CAAC,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,CAAC;QAC3E,SAAS,EAAE,CAAC,KAAK,EAAE,EAAE,CACnB,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC3D,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC;KAC1E,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,36 @@
1
+ import type * as Engine from '../core/Engine.js';
2
+ import type * as Errors from '../core/Errors.js';
3
+ export * from '../core/Keystore.js';
4
+ /**
5
+ * Creates a Node.js implementation of the [`Keystore`](/api/Keystore) engine
6
+ * slot, without installing it.
7
+ *
8
+ * Most callers want [`Engine.install`](/node/crypto/Engine/install) instead,
9
+ * which installs every implementation this entrypoint provides. Reach for this
10
+ * to install or hold the `Keystore` slot on its own.
11
+ *
12
+ * This engine deliberately omits scrypt. OpenSSL rejects Ox's default scrypt
13
+ * parameter shape, so installing it would make valid existing calls fail.
14
+ *
15
+ * @example
16
+ * ```ts twoslash
17
+ * // @noErrors
18
+ * import { Engine } from 'ox'
19
+ * import { Keystore } from 'ox/node'
20
+ *
21
+ * await Engine.install({ Keystore: Keystore.engine() })
22
+ *
23
+ * Keystore.pbkdf2({ password: 'testpassword' })
24
+ * ```
25
+ *
26
+ * @returns The raw `Keystore` engine slot.
27
+ */
28
+ export declare function engine(): Promise<engine.ReturnType>;
29
+ export declare namespace engine {
30
+ /** Every `Keystore` primitive this module implements. */
31
+ type ReturnType = {
32
+ [key in 'aesCtrDecrypt' | 'aesCtrEncrypt' | 'pbkdf2Sha256' | 'pbkdf2Sha256Async']-?: NonNullable<Engine.Keystore[key]>;
33
+ };
34
+ type ErrorType = Errors.GlobalErrorType;
35
+ }
36
+ //# sourceMappingURL=Keystore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Keystore.d.ts","sourceRoot":"","sources":["../../src/node/Keystore.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAEhD,cAAc,qBAAqB,CAAA;AAEnC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAqCnD;AAED,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,yDAAyD;IACzD,KAAK,UAAU,GAAG;SACf,GAAG,IACA,eAAe,GACf,eAAe,GACf,cAAc,GACd,mBAAmB,CAAC,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;KAC9D,CAAA;IAED,KAAK,SAAS,GAAG,MAAM,CAAC,eAAe,CAAA;CACxC"}
@@ -0,0 +1,72 @@
1
+ import * as crypto from 'node:crypto';
2
+ export * from '../core/Keystore.js';
3
+ /**
4
+ * Creates a Node.js implementation of the [`Keystore`](/api/Keystore) engine
5
+ * slot, without installing it.
6
+ *
7
+ * Most callers want [`Engine.install`](/node/crypto/Engine/install) instead,
8
+ * which installs every implementation this entrypoint provides. Reach for this
9
+ * to install or hold the `Keystore` slot on its own.
10
+ *
11
+ * This engine deliberately omits scrypt. OpenSSL rejects Ox's default scrypt
12
+ * parameter shape, so installing it would make valid existing calls fail.
13
+ *
14
+ * @example
15
+ * ```ts twoslash
16
+ * // @noErrors
17
+ * import { Engine } from 'ox'
18
+ * import { Keystore } from 'ox/node'
19
+ *
20
+ * await Engine.install({ Keystore: Keystore.engine() })
21
+ *
22
+ * Keystore.pbkdf2({ password: 'testpassword' })
23
+ * ```
24
+ *
25
+ * @returns The raw `Keystore` engine slot.
26
+ */
27
+ export function engine() {
28
+ return Promise.resolve({
29
+ aesCtrDecrypt: (key, iv, data) => {
30
+ const cipher = crypto.createDecipheriv(`aes-${key.length * 8}-ctr`, key, iv);
31
+ return cipherData(cipher, data);
32
+ },
33
+ aesCtrEncrypt: (key, iv, data) => {
34
+ const cipher = crypto.createCipheriv(`aes-${key.length * 8}-ctr`, key, iv);
35
+ return cipherData(cipher, data);
36
+ },
37
+ pbkdf2Sha256: (password, salt, options) => copyAndClear(crypto.pbkdf2Sync(password, salt, options.c, options.dkLen, 'sha256')),
38
+ pbkdf2Sha256Async: (password, salt, options) => new Promise((resolve, reject) => {
39
+ crypto.pbkdf2(password, salt, options.c, options.dkLen, 'sha256', (error, key) => {
40
+ if (error)
41
+ return reject(error);
42
+ try {
43
+ resolve(copyAndClear(key));
44
+ }
45
+ catch (error) {
46
+ reject(error);
47
+ }
48
+ });
49
+ }),
50
+ });
51
+ }
52
+ function cipherData(cipher, data) {
53
+ const chunks = [];
54
+ try {
55
+ chunks.push(cipher.update(data));
56
+ chunks.push(cipher.final());
57
+ return copyAndClear(Buffer.concat(chunks));
58
+ }
59
+ finally {
60
+ for (const chunk of chunks)
61
+ chunk.fill(0);
62
+ }
63
+ }
64
+ function copyAndClear(value) {
65
+ try {
66
+ return Uint8Array.from(value);
67
+ }
68
+ finally {
69
+ value.fill(0);
70
+ }
71
+ }
72
+ //# sourceMappingURL=Keystore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Keystore.js","sourceRoot":"","sources":["../../src/node/Keystore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAIrC,cAAc,qBAAqB,CAAA;AAEnC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,MAAM;IACpB,OAAO,OAAO,CAAC,OAAO,CAAC;QACrB,aAAa,EAAE,CAAC,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE;YAC/B,MAAM,MAAM,GAAG,MAAM,CAAC,gBAAgB,CACpC,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,MAAM,EAC3B,GAAG,EACH,EAAE,CACH,CAAA;YACD,OAAO,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QACjC,CAAC;QACD,aAAa,EAAE,CAAC,GAAG,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE;YAC/B,MAAM,MAAM,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,CAAA;YAC1E,OAAO,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,CAAA;QACjC,CAAC;QACD,YAAY,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CACxC,YAAY,CACV,MAAM,CAAC,UAAU,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CACtE;QACH,iBAAiB,EAAE,CAAC,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,CAC7C,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC9B,MAAM,CAAC,MAAM,CACX,QAAQ,EACR,IAAI,EACJ,OAAO,CAAC,CAAC,EACT,OAAO,CAAC,KAAK,EACb,QAAQ,EACR,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;gBACb,IAAI,KAAK;oBAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;gBAC/B,IAAI,CAAC;oBACH,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAA;gBAC5B,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,MAAM,CAAC,KAAK,CAAC,CAAA;gBACf,CAAC;YACH,CAAC,CACF,CAAA;QACH,CAAC,CAAC;KACL,CAAC,CAAA;AACJ,CAAC;AAeD,SAAS,UAAU,CACjB,MAA2C,EAC3C,IAAgB;IAEhB,MAAM,MAAM,GAAa,EAAE,CAAA;IAC3B,IAAI,CAAC;QACH,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAA;QAChC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAA;QAC3B,OAAO,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAA;IAC5C,CAAC;YAAS,CAAC;QACT,KAAK,MAAM,KAAK,IAAI,MAAM;YAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAC3C,CAAC;AACH,CAAC;AAED,SAAS,YAAY,CAAC,KAAa;IACjC,IAAI,CAAC;QACH,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC/B,CAAC;YAAS,CAAC;QACT,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACf,CAAC;AACH,CAAC"}
@@ -0,0 +1,35 @@
1
+ import type * as Engine from '../core/Engine.js';
2
+ import type * as Errors from '../core/Errors.js';
3
+ export * from '../core/Mnemonic.js';
4
+ /**
5
+ * Creates a Node.js implementation of the [`Mnemonic`](/api/Mnemonic) engine
6
+ * slot, without installing it.
7
+ *
8
+ * Most callers want [`Engine.install`](/node/crypto/Engine/install) instead,
9
+ * which installs every implementation this entrypoint provides. Reach for this
10
+ * to install or hold the `Mnemonic` slot on its own.
11
+ *
12
+ * @example
13
+ * ```ts twoslash
14
+ * // @noErrors
15
+ * import { Engine } from 'ox'
16
+ * import { Mnemonic } from 'ox/node'
17
+ *
18
+ * await Engine.install({ Mnemonic: Mnemonic.engine() })
19
+ *
20
+ * Mnemonic.toSeed(
21
+ * 'test test test test test test test test test test test junk'
22
+ * )
23
+ * ```
24
+ *
25
+ * @returns The raw `Mnemonic` engine slot.
26
+ */
27
+ export declare function engine(): Promise<engine.ReturnType>;
28
+ export declare namespace engine {
29
+ /** Every `Mnemonic` primitive this module implements. */
30
+ type ReturnType = {
31
+ [key in 'toSeed']-?: NonNullable<Engine.Mnemonic[key]>;
32
+ };
33
+ type ErrorType = Errors.GlobalErrorType;
34
+ }
35
+ //# sourceMappingURL=Mnemonic.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Mnemonic.d.ts","sourceRoot":"","sources":["../../src/node/Mnemonic.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAEhD,cAAc,qBAAqB,CAAA;AAEnC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAqBnD;AAED,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,yDAAyD;IACzD,KAAK,UAAU,GAAG;SACf,GAAG,IAAI,QAAQ,CAAC,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;KACvD,CAAA;IAED,KAAK,SAAS,GAAG,MAAM,CAAC,eAAe,CAAA;CACxC"}
@@ -0,0 +1,46 @@
1
+ import * as crypto from 'node:crypto';
2
+ export * from '../core/Mnemonic.js';
3
+ /**
4
+ * Creates a Node.js implementation of the [`Mnemonic`](/api/Mnemonic) engine
5
+ * slot, without installing it.
6
+ *
7
+ * Most callers want [`Engine.install`](/node/crypto/Engine/install) instead,
8
+ * which installs every implementation this entrypoint provides. Reach for this
9
+ * to install or hold the `Mnemonic` slot on its own.
10
+ *
11
+ * @example
12
+ * ```ts twoslash
13
+ * // @noErrors
14
+ * import { Engine } from 'ox'
15
+ * import { Mnemonic } from 'ox/node'
16
+ *
17
+ * await Engine.install({ Mnemonic: Mnemonic.engine() })
18
+ *
19
+ * Mnemonic.toSeed(
20
+ * 'test test test test test test test test test test test junk'
21
+ * )
22
+ * ```
23
+ *
24
+ * @returns The raw `Mnemonic` engine slot.
25
+ */
26
+ export function engine() {
27
+ return Promise.resolve({
28
+ toSeed: (mnemonic, passphrase = '') => {
29
+ if (typeof mnemonic !== 'string')
30
+ throw new TypeError(`invalid mnemonic type: ${typeof mnemonic}`);
31
+ const normalized = mnemonic.normalize('NFKD');
32
+ if (![12, 15, 18, 21, 24].includes(normalized.split(' ').length))
33
+ throw new Error('Invalid mnemonic');
34
+ return copyAndClear(crypto.pbkdf2Sync(normalized, `mnemonic${passphrase}`.normalize('NFKD'), 2048, 64, 'sha512'));
35
+ },
36
+ });
37
+ }
38
+ function copyAndClear(value) {
39
+ try {
40
+ return Uint8Array.from(value);
41
+ }
42
+ finally {
43
+ value.fill(0);
44
+ }
45
+ }
46
+ //# sourceMappingURL=Mnemonic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Mnemonic.js","sourceRoot":"","sources":["../../src/node/Mnemonic.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAIrC,cAAc,qBAAqB,CAAA;AAEnC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,MAAM;IACpB,OAAO,OAAO,CAAC,OAAO,CAAC;QACrB,MAAM,EAAE,CAAC,QAAQ,EAAE,UAAU,GAAG,EAAE,EAAE,EAAE;YACpC,IAAI,OAAO,QAAQ,KAAK,QAAQ;gBAC9B,MAAM,IAAI,SAAS,CAAC,0BAA0B,OAAO,QAAQ,EAAE,CAAC,CAAA;YAElE,MAAM,UAAU,GAAG,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;YAC7C,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;gBAC9D,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAA;YAErC,OAAO,YAAY,CACjB,MAAM,CAAC,UAAU,CACf,UAAU,EACV,WAAW,UAAU,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,EACzC,IAAI,EACJ,EAAE,EACF,QAAQ,CACT,CACF,CAAA;QACH,CAAC;KACF,CAAC,CAAA;AACJ,CAAC;AAWD,SAAS,YAAY,CAAC,KAAa;IACjC,IAAI,CAAC;QACH,OAAO,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC/B,CAAC;YAAS,CAAC;QACT,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IACf,CAAC;AACH,CAAC"}
@@ -0,0 +1,32 @@
1
+ import type * as Engine from '../core/Engine.js';
2
+ import type * as Errors from '../core/Errors.js';
3
+ export * from '../core/P256.js';
4
+ /**
5
+ * Creates a Node.js implementation of the [`P256`](/api/P256) engine slot,
6
+ * without installing it.
7
+ *
8
+ * Node's other P256 operations do not reproduce Ox's recovered-signature and
9
+ * compressed-shared-point contracts, so they remain on Ox's defaults.
10
+ *
11
+ * @example
12
+ * ```ts twoslash
13
+ * // @noErrors
14
+ * import { Engine } from 'ox'
15
+ * import { P256 } from 'ox/node'
16
+ *
17
+ * await Engine.install({ P256: P256.engine() })
18
+ *
19
+ * P256.getPublicKey({ privateKey: '0x...' })
20
+ * ```
21
+ *
22
+ * @returns The raw `P256` engine slot.
23
+ */
24
+ export declare function engine(): Promise<engine.ReturnType>;
25
+ export declare namespace engine {
26
+ /** Every `P256` primitive this module implements. */
27
+ type ReturnType = {
28
+ getPublicKey: NonNullable<Engine.Ecdsa['getPublicKey']>;
29
+ };
30
+ type ErrorType = Errors.GlobalErrorType;
31
+ }
32
+ //# sourceMappingURL=P256.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"P256.d.ts","sourceRoot":"","sources":["../../src/node/P256.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAEhD,cAAc,iBAAiB,CAAA;AAE/B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAYnD;AAED,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,qDAAqD;IACrD,KAAK,UAAU,GAAG;QAChB,YAAY,EAAE,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAA;KACxD,CAAA;IAED,KAAK,SAAS,GAAG,MAAM,CAAC,eAAe,CAAA;CACxC"}