ox 1.1.0 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. package/CHANGELOG.md +27 -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/internal/engine.d.ts +8 -8
  7. package/dist/core/internal/engine.d.ts.map +1 -1
  8. package/dist/index.d.ts +5 -2
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +5 -2
  11. package/dist/index.js.map +1 -1
  12. package/dist/node/Ed25519.d.ts +33 -0
  13. package/dist/node/Ed25519.d.ts.map +1 -0
  14. package/dist/node/Ed25519.js +67 -0
  15. package/dist/node/Ed25519.js.map +1 -0
  16. package/dist/node/Engine.d.ts +29 -16
  17. package/dist/node/Engine.d.ts.map +1 -1
  18. package/dist/node/Engine.js +38 -14
  19. package/dist/node/Engine.js.map +1 -1
  20. package/dist/node/Hash.d.ts +14 -16
  21. package/dist/node/Hash.d.ts.map +1 -1
  22. package/dist/node/Hash.js +14 -16
  23. package/dist/node/Hash.js.map +1 -1
  24. package/dist/node/Keystore.d.ts +36 -0
  25. package/dist/node/Keystore.d.ts.map +1 -0
  26. package/dist/node/Keystore.js +72 -0
  27. package/dist/node/Keystore.js.map +1 -0
  28. package/dist/node/Mnemonic.d.ts +35 -0
  29. package/dist/node/Mnemonic.d.ts.map +1 -0
  30. package/dist/node/Mnemonic.js +46 -0
  31. package/dist/node/Mnemonic.js.map +1 -0
  32. package/dist/node/P256.d.ts +32 -0
  33. package/dist/node/P256.d.ts.map +1 -0
  34. package/dist/node/P256.js +34 -0
  35. package/dist/node/P256.js.map +1 -0
  36. package/dist/node/X25519.d.ts +31 -0
  37. package/dist/node/X25519.d.ts.map +1 -0
  38. package/dist/node/X25519.js +71 -0
  39. package/dist/node/X25519.js.map +1 -0
  40. package/dist/node/index.d.ts +95 -8
  41. package/dist/node/index.d.ts.map +1 -1
  42. package/dist/node/index.js +95 -8
  43. package/dist/node/index.js.map +1 -1
  44. package/dist/wasm/Ed25519.d.ts +35 -0
  45. package/dist/wasm/Ed25519.d.ts.map +1 -0
  46. package/dist/wasm/Ed25519.js +88 -0
  47. package/dist/wasm/Ed25519.js.map +1 -0
  48. package/dist/wasm/Engine.d.ts +35 -26
  49. package/dist/wasm/Engine.d.ts.map +1 -1
  50. package/dist/wasm/Engine.js +44 -25
  51. package/dist/wasm/Engine.js.map +1 -1
  52. package/dist/wasm/Hash.d.ts +13 -19
  53. package/dist/wasm/Hash.d.ts.map +1 -1
  54. package/dist/wasm/Hash.js +21 -27
  55. package/dist/wasm/Hash.js.map +1 -1
  56. package/dist/wasm/Keystore.d.ts +37 -0
  57. package/dist/wasm/Keystore.d.ts.map +1 -0
  58. package/dist/wasm/Keystore.js +34 -0
  59. package/dist/wasm/Keystore.js.map +1 -0
  60. package/dist/wasm/Mnemonic.d.ts +33 -0
  61. package/dist/wasm/Mnemonic.d.ts.map +1 -0
  62. package/dist/wasm/Mnemonic.js +30 -0
  63. package/dist/wasm/Mnemonic.js.map +1 -0
  64. package/dist/wasm/X25519.d.ts +33 -0
  65. package/dist/wasm/X25519.d.ts.map +1 -0
  66. package/dist/wasm/X25519.js +53 -0
  67. package/dist/wasm/X25519.js.map +1 -0
  68. package/dist/wasm/index.d.ts +81 -12
  69. package/dist/wasm/index.d.ts.map +1 -1
  70. package/dist/wasm/index.js +81 -12
  71. package/dist/wasm/index.js.map +1 -1
  72. package/dist/wasm/internal/blake3.d.ts +11 -0
  73. package/dist/wasm/internal/blake3.d.ts.map +1 -0
  74. package/dist/wasm/internal/blake3.js +31 -0
  75. package/dist/wasm/internal/blake3.js.map +1 -0
  76. package/dist/wasm/internal/blake3.wasm.d.ts +3 -0
  77. package/dist/wasm/internal/blake3.wasm.d.ts.map +1 -0
  78. package/dist/wasm/internal/blake3.wasm.js +10 -0
  79. package/dist/wasm/internal/blake3.wasm.js.map +1 -0
  80. package/dist/wasm/internal/crypto25519.d.ts +16 -0
  81. package/dist/wasm/internal/crypto25519.d.ts.map +1 -0
  82. package/dist/wasm/internal/crypto25519.js +5 -0
  83. package/dist/wasm/internal/crypto25519.js.map +1 -0
  84. package/dist/wasm/internal/crypto25519.wasm.d.ts +3 -0
  85. package/dist/wasm/internal/crypto25519.wasm.d.ts.map +1 -0
  86. package/dist/wasm/internal/crypto25519.wasm.js +10 -0
  87. package/dist/wasm/internal/crypto25519.wasm.js.map +1 -0
  88. package/dist/wasm/internal/ed25519.d.ts +4 -0
  89. package/dist/wasm/internal/ed25519.d.ts.map +1 -0
  90. package/dist/wasm/internal/ed25519.js +21 -0
  91. package/dist/wasm/internal/ed25519.js.map +1 -0
  92. package/dist/wasm/internal/hashes.d.ts +12 -0
  93. package/dist/wasm/internal/hashes.d.ts.map +1 -0
  94. package/dist/wasm/internal/hashes.js +8 -0
  95. package/dist/wasm/internal/hashes.js.map +1 -0
  96. package/dist/wasm/internal/hashes.wasm.d.ts +4 -2
  97. package/dist/wasm/internal/hashes.wasm.d.ts.map +1 -1
  98. package/dist/wasm/internal/hashes.wasm.js +4 -2
  99. package/dist/wasm/internal/hashes.wasm.js.map +1 -1
  100. package/dist/wasm/internal/mnemonic.d.ts +4 -0
  101. package/dist/wasm/internal/mnemonic.d.ts.map +1 -0
  102. package/dist/wasm/internal/mnemonic.js +45 -0
  103. package/dist/wasm/internal/mnemonic.js.map +1 -0
  104. package/dist/wasm/internal/pbkdf2.d.ts +12 -0
  105. package/dist/wasm/internal/pbkdf2.d.ts.map +1 -0
  106. package/dist/wasm/internal/pbkdf2.js +51 -0
  107. package/dist/wasm/internal/pbkdf2.js.map +1 -0
  108. package/dist/wasm/internal/x25519.d.ts +4 -0
  109. package/dist/wasm/internal/x25519.d.ts.map +1 -0
  110. package/dist/wasm/internal/x25519.js +21 -0
  111. package/dist/wasm/internal/x25519.js.map +1 -0
  112. package/package.json +46 -1
  113. package/src/core/Engine.ts +84 -11
  114. package/src/core/_test/Engine.test-d.ts +56 -0
  115. package/src/core/_test/Engine.test.ts +95 -0
  116. package/src/core/_test/Hash.vectors.test.ts +8 -0
  117. package/src/core/internal/engine.ts +8 -8
  118. package/src/index.ts +5 -2
  119. package/src/node/Ed25519.ts +87 -0
  120. package/src/node/Engine.ts +79 -23
  121. package/src/node/Hash.ts +22 -27
  122. package/src/node/Keystore.ts +103 -0
  123. package/src/node/Mnemonic.ts +68 -0
  124. package/src/node/P256.ts +48 -0
  125. package/src/node/X25519.ts +93 -0
  126. package/src/node/_test/Curves.fuzz.ts +76 -0
  127. package/src/node/_test/Ed25519.test-d.ts +35 -0
  128. package/src/node/_test/Ed25519.test.ts +220 -0
  129. package/src/node/_test/Engine.test-d.ts +28 -0
  130. package/src/node/_test/Engine.test.ts +62 -22
  131. package/src/node/_test/Hash.test-d.ts +15 -9
  132. package/src/node/_test/Hash.test.ts +10 -11
  133. package/src/node/_test/Keystore.fuzz.ts +58 -0
  134. package/src/node/_test/Keystore.test-d.ts +43 -0
  135. package/src/node/_test/Keystore.test.ts +198 -0
  136. package/src/node/_test/Mnemonic.fuzz.ts +31 -0
  137. package/src/node/_test/Mnemonic.test-d.ts +21 -0
  138. package/src/node/_test/Mnemonic.test.ts +98 -0
  139. package/src/node/_test/P256.test-d.ts +29 -0
  140. package/src/node/_test/P256.test.ts +102 -0
  141. package/src/node/_test/X25519.test-d.ts +28 -0
  142. package/src/node/_test/X25519.test.ts +239 -0
  143. package/src/node/index.ts +100 -8
  144. package/src/version.ts +1 -1
  145. package/src/wasm/Ed25519.ts +114 -0
  146. package/src/wasm/Engine.ts +76 -31
  147. package/src/wasm/Hash.bench.ts +2 -2
  148. package/src/wasm/Hash.ts +29 -50
  149. package/src/wasm/Keystore.ts +48 -0
  150. package/src/wasm/Mnemonic.ts +44 -0
  151. package/src/wasm/X25519.ts +70 -0
  152. package/src/wasm/_test/Crypto25519.conformance.ts +57 -0
  153. package/src/wasm/_test/Crypto25519.fuzz.ts +187 -0
  154. package/src/wasm/_test/Ed25519.test-d.ts +28 -0
  155. package/src/wasm/_test/Ed25519.test.ts +168 -0
  156. package/src/wasm/_test/Ed25519.vectors.test.ts +73 -0
  157. package/src/wasm/_test/Engine.test-d.ts +28 -0
  158. package/src/wasm/_test/Engine.test.ts +59 -25
  159. package/src/wasm/_test/Hash.browser.test.ts +11 -7
  160. package/src/wasm/_test/Hash.fuzz.ts +58 -23
  161. package/src/wasm/_test/Hash.test-d.ts +15 -10
  162. package/src/wasm/_test/Hash.test.ts +148 -48
  163. package/src/wasm/_test/Hash.vectors.test.ts +15 -8
  164. package/src/wasm/_test/Keystore.browser.test.ts +42 -0
  165. package/src/wasm/_test/Keystore.fuzz.ts +113 -0
  166. package/src/wasm/_test/Keystore.test-d.ts +33 -0
  167. package/src/wasm/_test/Keystore.test.ts +192 -0
  168. package/src/wasm/_test/Keystore.vectors.test.ts +21 -0
  169. package/src/wasm/_test/Mnemonic.test-d.ts +17 -0
  170. package/src/wasm/_test/Mnemonic.test.ts +110 -0
  171. package/src/wasm/_test/X25519.test-d.ts +21 -0
  172. package/src/wasm/_test/X25519.test.ts +194 -0
  173. package/src/wasm/_test/fixtures.ts +4 -0
  174. package/src/wasm/index.ts +85 -12
  175. package/src/wasm/internal/blake3.ts +45 -0
  176. package/src/wasm/internal/blake3.wasm.ts +11 -0
  177. package/src/wasm/internal/crypto25519.ts +43 -0
  178. package/src/wasm/internal/crypto25519.wasm.ts +11 -0
  179. package/src/wasm/internal/ed25519.ts +31 -0
  180. package/src/wasm/internal/hashes.ts +29 -0
  181. package/src/wasm/internal/hashes.wasm.ts +5 -2
  182. package/src/wasm/internal/mnemonic.ts +56 -0
  183. package/src/wasm/internal/pbkdf2.ts +86 -0
  184. package/src/wasm/internal/x25519.ts +29 -0
@@ -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;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM;IAC1B,OAAO,EAAE,GAAG,CAAC,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,CAAA;AACrC,CAAC"}
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,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AACzC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC,OAAO,EACL,eAAe,EACf,GAAG,EACH,qBAAqB,EACrB,KAAK,EACL,GAAG,EACH,qBAAqB,EACrB,gBAAgB,EAChB,IAAI,GACL,MAAM,mBAAmB,CAAA;AAY1B;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,OAAO;IACrB,OAAO,UAAU,CAAC,OAAO,CAAC;QACxB,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE;QACzB,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;QACnB,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE;QAC3B,QAAQ,EAAE,QAAQ,CAAC,MAAM,EAAE;QAC3B,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE;QACnB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;KACxB,CAAC,CAAA;AACJ,CAAC;AASD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM;IAC1B,MAAM,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC1E,OAAO,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,13 +1,13 @@
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
12
  * Node's `sha3-256` is not Ethereum Keccak256, so this engine deliberately
13
13
  * omits `keccak256`. Any earlier override remains installed; otherwise Ox uses
@@ -16,23 +16,21 @@ import type * as Errors from '../core/Errors.js';
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,12 +1,12 @@
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
11
  * Node's `sha3-256` is not Ethereum Keccak256, so this engine deliberately
12
12
  * omits `keccak256`. Any earlier override remains installed; otherwise Ox uses
@@ -15,23 +15,21 @@ import * as crypto from 'node:crypto';
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":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AAC,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,MA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AAC,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"}
@@ -0,0 +1,34 @@
1
+ import * as crypto from 'node:crypto';
2
+ export * from '../core/P256.js';
3
+ /**
4
+ * Creates a Node.js implementation of the [`P256`](/api/P256) engine slot,
5
+ * without installing it.
6
+ *
7
+ * Node's other P256 operations do not reproduce Ox's recovered-signature and
8
+ * compressed-shared-point contracts, so they remain on Ox's defaults.
9
+ *
10
+ * @example
11
+ * ```ts twoslash
12
+ * // @noErrors
13
+ * import { Engine } from 'ox'
14
+ * import { P256 } from 'ox/node'
15
+ *
16
+ * await Engine.install({ P256: P256.engine() })
17
+ *
18
+ * P256.getPublicKey({ privateKey: '0x...' })
19
+ * ```
20
+ *
21
+ * @returns The raw `P256` engine slot.
22
+ */
23
+ export function engine() {
24
+ return Promise.resolve({
25
+ getPublicKey: (privateKey) => {
26
+ if (privateKey.length !== 32)
27
+ throw new RangeError(`P256 private key must be 32 bytes, got ${privateKey.length}`);
28
+ const ecdh = crypto.createECDH('prime256v1');
29
+ ecdh.setPrivateKey(privateKey);
30
+ return new Uint8Array(ecdh.getPublicKey(undefined, 'uncompressed'));
31
+ },
32
+ });
33
+ }
34
+ //# sourceMappingURL=P256.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"P256.js","sourceRoot":"","sources":["../../src/node/P256.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAIrC,cAAc,iBAAiB,CAAA;AAE/B;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,MAAM;IACpB,OAAO,OAAO,CAAC,OAAO,CAAC;QACrB,YAAY,EAAE,CAAC,UAAU,EAAE,EAAE;YAC3B,IAAI,UAAU,CAAC,MAAM,KAAK,EAAE;gBAC1B,MAAM,IAAI,UAAU,CAClB,0CAA0C,UAAU,CAAC,MAAM,EAAE,CAC9D,CAAA;YACH,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,YAAY,CAAC,CAAA;YAC5C,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAA;YAC9B,OAAO,IAAI,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC,CAAA;QACrE,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type * as Engine from '../core/Engine.js';
2
+ import type * as Errors from '../core/Errors.js';
3
+ export * from '../core/X25519.js';
4
+ /**
5
+ * Creates a Node.js implementation of the [`X25519`](/api/X25519) engine slot,
6
+ * without installing it.
7
+ *
8
+ * Random key generation remains on Ox's default implementation.
9
+ *
10
+ * @example
11
+ * ```ts twoslash
12
+ * // @noErrors
13
+ * import { Engine } from 'ox'
14
+ * import { X25519 } from 'ox/node'
15
+ *
16
+ * await Engine.install({ X25519: X25519.engine() })
17
+ *
18
+ * X25519.getPublicKey({ privateKey: '0x...' })
19
+ * ```
20
+ *
21
+ * @returns The raw `X25519` engine slot.
22
+ */
23
+ export declare function engine(): Promise<engine.ReturnType>;
24
+ export declare namespace engine {
25
+ /** Every `X25519` primitive this module implements. */
26
+ type ReturnType = {
27
+ [key in 'getPublicKey' | 'getSharedSecret']-?: NonNullable<Engine.Ecdh[key]>;
28
+ };
29
+ type ErrorType = Errors.GlobalErrorType;
30
+ }
31
+ //# sourceMappingURL=X25519.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"X25519.d.ts","sourceRoot":"","sources":["../../src/node/X25519.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAEhD,cAAc,mBAAmB,CAAA;AAKjC;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAYnD;AAED,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,uDAAuD;IACvD,KAAK,UAAU,GAAG;SACf,GAAG,IAAI,cAAc,GAAG,iBAAiB,CAAC,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KAC7E,CAAA;IAED,KAAK,SAAS,GAAG,MAAM,CAAC,eAAe,CAAA;CACxC"}
@@ -0,0 +1,71 @@
1
+ import * as crypto from 'node:crypto';
2
+ export * from '../core/X25519.js';
3
+ const privateKeyPrefix = Buffer.from('302e020100300506032b656e04220420', 'hex');
4
+ const publicKeyPrefix = Buffer.from('302a300506032b656e032100', 'hex');
5
+ /**
6
+ * Creates a Node.js implementation of the [`X25519`](/api/X25519) engine slot,
7
+ * without installing it.
8
+ *
9
+ * Random key generation remains on Ox's default implementation.
10
+ *
11
+ * @example
12
+ * ```ts twoslash
13
+ * // @noErrors
14
+ * import { Engine } from 'ox'
15
+ * import { X25519 } from 'ox/node'
16
+ *
17
+ * await Engine.install({ X25519: X25519.engine() })
18
+ *
19
+ * X25519.getPublicKey({ privateKey: '0x...' })
20
+ * ```
21
+ *
22
+ * @returns The raw `X25519` engine slot.
23
+ */
24
+ export function engine() {
25
+ return Promise.resolve({
26
+ getPublicKey: (privateKey) => rawPublicKey(crypto.createPublicKey(toPrivateKey(privateKey))),
27
+ getSharedSecret: (privateKey, publicKey) => copyAndClear(crypto.diffieHellman({
28
+ privateKey: toPrivateKey(privateKey),
29
+ publicKey: toPublicKey(publicKey),
30
+ })),
31
+ });
32
+ }
33
+ function copyAndClear(value) {
34
+ try {
35
+ return Uint8Array.from(value);
36
+ }
37
+ finally {
38
+ value.fill(0);
39
+ }
40
+ }
41
+ function assertLength(key, type) {
42
+ if (key.length !== 32)
43
+ throw new RangeError(`X25519 ${type} key must be 32 bytes, got ${key.length}`);
44
+ }
45
+ function rawPublicKey(publicKey) {
46
+ const der = publicKey.export({ format: 'der', type: 'spki' });
47
+ return Uint8Array.from(der.subarray(-32));
48
+ }
49
+ function toPrivateKey(privateKey) {
50
+ assertLength(privateKey, 'private');
51
+ const der = Buffer.concat([privateKeyPrefix, privateKey]);
52
+ try {
53
+ return crypto.createPrivateKey({
54
+ format: 'der',
55
+ key: der,
56
+ type: 'pkcs8',
57
+ });
58
+ }
59
+ finally {
60
+ der.fill(0);
61
+ }
62
+ }
63
+ function toPublicKey(publicKey) {
64
+ assertLength(publicKey, 'public');
65
+ return crypto.createPublicKey({
66
+ format: 'der',
67
+ key: Buffer.concat([publicKeyPrefix, publicKey]),
68
+ type: 'spki',
69
+ });
70
+ }
71
+ //# sourceMappingURL=X25519.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"X25519.js","sourceRoot":"","sources":["../../src/node/X25519.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAIrC,cAAc,mBAAmB,CAAA;AAEjC,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAA;AAC/E,MAAM,eAAe,GAAG,MAAM,CAAC,IAAI,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAA;AAEtE;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,MAAM;IACpB,OAAO,OAAO,CAAC,OAAO,CAAC;QACrB,YAAY,EAAE,CAAC,UAAU,EAAE,EAAE,CAC3B,YAAY,CAAC,MAAM,CAAC,eAAe,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC,CAAC;QAChE,eAAe,EAAE,CAAC,UAAU,EAAE,SAAS,EAAE,EAAE,CACzC,YAAY,CACV,MAAM,CAAC,aAAa,CAAC;YACnB,UAAU,EAAE,YAAY,CAAC,UAAU,CAAC;YACpC,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC;SAClC,CAAC,CACH;KACJ,CAAC,CAAA;AACJ,CAAC;AAWD,SAAS,YAAY,CAAC,KAAa;IACjC,IAAI,CAAC;QACH,OAAO,UAAU,CAAC,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