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,6 +1,7 @@
1
1
  /** @entrypointCategory Node */
2
2
  /**
3
- * Node.js implementations of Ox's hash primitives, backed by `node:crypto`.
3
+ * Node.js implementations of Ox's supported cryptographic primitives, backed
4
+ * by `node:crypto`.
4
5
  *
5
6
  * Import this entrypoint only in Node.js. Its static `node:crypto` dependency
6
7
  * is intentionally kept outside Ox's runtime-neutral entrypoint.
@@ -8,10 +9,9 @@
8
9
  * @example
9
10
  * ```ts twoslash
10
11
  * // @noErrors
11
- * import { Hash } from 'ox'
12
- * import { Engine } from 'ox/node'
12
+ * import { Engine, Hash } from 'ox/node'
13
13
  *
14
- * await Engine.load()
14
+ * await Engine.install()
15
15
  *
16
16
  * Hash.sha256('0xdeadbeef')
17
17
  * ```
@@ -20,15 +20,32 @@
20
20
  */
21
21
  export * as Engine from './Engine.js';
22
22
  /**
23
- * Node.js implementations of Ox's supported hash primitives.
23
+ * Ox's Ed25519 API and its supported Node.js engine primitives.
24
24
  *
25
25
  * @example
26
26
  * ```ts twoslash
27
27
  * // @noErrors
28
- * import { Engine, Hash } from 'ox'
29
- * import * as NodeHash from 'ox/node/Hash'
28
+ * import { Engine } from 'ox'
29
+ * import { Ed25519 } from 'ox/node'
30
30
  *
31
- * Engine.set(await NodeHash.create())
31
+ * await Engine.install({ Ed25519: Ed25519.engine() })
32
+ *
33
+ * Ed25519.getPublicKey({ privateKey: '0x...' })
34
+ * ```
35
+ *
36
+ * @category Crypto
37
+ */
38
+ export * as Ed25519 from './Ed25519.js';
39
+ /**
40
+ * Ox's hash API and its supported Node.js engine primitives.
41
+ *
42
+ * @example
43
+ * ```ts twoslash
44
+ * // @noErrors
45
+ * import { Engine } from 'ox'
46
+ * import { Hash } from 'ox/node'
47
+ *
48
+ * await Engine.install({ Hash: Hash.engine() })
32
49
  *
33
50
  * Hash.sha256('0xdeadbeef')
34
51
  * ```
@@ -36,4 +53,74 @@ export * as Engine from './Engine.js';
36
53
  * @category Crypto
37
54
  */
38
55
  export * as Hash from './Hash.js';
56
+ /**
57
+ * Ox's keystore API and its supported Node.js engine primitives.
58
+ *
59
+ * @example
60
+ * ```ts twoslash
61
+ * // @noErrors
62
+ * import { Engine } from 'ox'
63
+ * import { Keystore } from 'ox/node'
64
+ *
65
+ * await Engine.install({ Keystore: Keystore.engine() })
66
+ *
67
+ * Keystore.pbkdf2({ password: 'testpassword' })
68
+ * ```
69
+ *
70
+ * @category Crypto
71
+ */
72
+ export * as Keystore from './Keystore.js';
73
+ /**
74
+ * Ox's mnemonic API and its Node.js BIP-39 seed engine primitive.
75
+ *
76
+ * @example
77
+ * ```ts twoslash
78
+ * // @noErrors
79
+ * import { Engine } from 'ox'
80
+ * import { Mnemonic } from 'ox/node'
81
+ *
82
+ * await Engine.install({ Mnemonic: Mnemonic.engine() })
83
+ *
84
+ * Mnemonic.toSeed(
85
+ * 'test test test test test test test test test test test junk'
86
+ * )
87
+ * ```
88
+ *
89
+ * @category Crypto
90
+ */
91
+ export * as Mnemonic from './Mnemonic.js';
92
+ /**
93
+ * Ox's P256 API and its Node.js public-key derivation engine primitive.
94
+ *
95
+ * @example
96
+ * ```ts twoslash
97
+ * // @noErrors
98
+ * import { Engine } from 'ox'
99
+ * import { P256 } from 'ox/node'
100
+ *
101
+ * await Engine.install({ P256: P256.engine() })
102
+ *
103
+ * P256.getPublicKey({ privateKey: '0x...' })
104
+ * ```
105
+ *
106
+ * @category Crypto
107
+ */
108
+ export * as P256 from './P256.js';
109
+ /**
110
+ * Ox's X25519 API and its supported Node.js engine primitives.
111
+ *
112
+ * @example
113
+ * ```ts twoslash
114
+ * // @noErrors
115
+ * import { Engine } from 'ox'
116
+ * import { X25519 } from 'ox/node'
117
+ *
118
+ * await Engine.install({ X25519: X25519.engine() })
119
+ *
120
+ * X25519.getPublicKey({ privateKey: '0x...' })
121
+ * ```
122
+ *
123
+ * @category Crypto
124
+ */
125
+ export * as X25519 from './X25519.js';
39
126
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAEzC;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAEzC;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA"}
@@ -1,6 +1,7 @@
1
1
  /** @entrypointCategory Node */
2
2
  /**
3
- * Node.js implementations of Ox's hash primitives, backed by `node:crypto`.
3
+ * Node.js implementations of Ox's supported cryptographic primitives, backed
4
+ * by `node:crypto`.
4
5
  *
5
6
  * Import this entrypoint only in Node.js. Its static `node:crypto` dependency
6
7
  * is intentionally kept outside Ox's runtime-neutral entrypoint.
@@ -8,10 +9,9 @@
8
9
  * @example
9
10
  * ```ts twoslash
10
11
  * // @noErrors
11
- * import { Hash } from 'ox'
12
- * import { Engine } from 'ox/node'
12
+ * import { Engine, Hash } from 'ox/node'
13
13
  *
14
- * await Engine.load()
14
+ * await Engine.install()
15
15
  *
16
16
  * Hash.sha256('0xdeadbeef')
17
17
  * ```
@@ -20,15 +20,32 @@
20
20
  */
21
21
  export * as Engine from './Engine.js';
22
22
  /**
23
- * Node.js implementations of Ox's supported hash primitives.
23
+ * Ox's Ed25519 API and its supported Node.js engine primitives.
24
24
  *
25
25
  * @example
26
26
  * ```ts twoslash
27
27
  * // @noErrors
28
- * import { Engine, Hash } from 'ox'
29
- * import * as NodeHash from 'ox/node/Hash'
28
+ * import { Engine } from 'ox'
29
+ * import { Ed25519 } from 'ox/node'
30
30
  *
31
- * Engine.set(await NodeHash.create())
31
+ * await Engine.install({ Ed25519: Ed25519.engine() })
32
+ *
33
+ * Ed25519.getPublicKey({ privateKey: '0x...' })
34
+ * ```
35
+ *
36
+ * @category Crypto
37
+ */
38
+ export * as Ed25519 from './Ed25519.js';
39
+ /**
40
+ * Ox's hash API and its supported Node.js engine primitives.
41
+ *
42
+ * @example
43
+ * ```ts twoslash
44
+ * // @noErrors
45
+ * import { Engine } from 'ox'
46
+ * import { Hash } from 'ox/node'
47
+ *
48
+ * await Engine.install({ Hash: Hash.engine() })
32
49
  *
33
50
  * Hash.sha256('0xdeadbeef')
34
51
  * ```
@@ -36,4 +53,74 @@ export * as Engine from './Engine.js';
36
53
  * @category Crypto
37
54
  */
38
55
  export * as Hash from './Hash.js';
56
+ /**
57
+ * Ox's keystore API and its supported Node.js engine primitives.
58
+ *
59
+ * @example
60
+ * ```ts twoslash
61
+ * // @noErrors
62
+ * import { Engine } from 'ox'
63
+ * import { Keystore } from 'ox/node'
64
+ *
65
+ * await Engine.install({ Keystore: Keystore.engine() })
66
+ *
67
+ * Keystore.pbkdf2({ password: 'testpassword' })
68
+ * ```
69
+ *
70
+ * @category Crypto
71
+ */
72
+ export * as Keystore from './Keystore.js';
73
+ /**
74
+ * Ox's mnemonic API and its Node.js BIP-39 seed engine primitive.
75
+ *
76
+ * @example
77
+ * ```ts twoslash
78
+ * // @noErrors
79
+ * import { Engine } from 'ox'
80
+ * import { Mnemonic } from 'ox/node'
81
+ *
82
+ * await Engine.install({ Mnemonic: Mnemonic.engine() })
83
+ *
84
+ * Mnemonic.toSeed(
85
+ * 'test test test test test test test test test test test junk'
86
+ * )
87
+ * ```
88
+ *
89
+ * @category Crypto
90
+ */
91
+ export * as Mnemonic from './Mnemonic.js';
92
+ /**
93
+ * Ox's P256 API and its Node.js public-key derivation engine primitive.
94
+ *
95
+ * @example
96
+ * ```ts twoslash
97
+ * // @noErrors
98
+ * import { Engine } from 'ox'
99
+ * import { P256 } from 'ox/node'
100
+ *
101
+ * await Engine.install({ P256: P256.engine() })
102
+ *
103
+ * P256.getPublicKey({ privateKey: '0x...' })
104
+ * ```
105
+ *
106
+ * @category Crypto
107
+ */
108
+ export * as P256 from './P256.js';
109
+ /**
110
+ * Ox's X25519 API and its supported Node.js engine primitives.
111
+ *
112
+ * @example
113
+ * ```ts twoslash
114
+ * // @noErrors
115
+ * import { Engine } from 'ox'
116
+ * import { X25519 } from 'ox/node'
117
+ *
118
+ * await Engine.install({ X25519: X25519.engine() })
119
+ *
120
+ * X25519.getPublicKey({ privateKey: '0x...' })
121
+ * ```
122
+ *
123
+ * @category Crypto
124
+ */
125
+ export * as X25519 from './X25519.js';
39
126
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAE/B;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AAEvC;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAEzC;;;;;;;;;;;;;;;;;GAiBG;AACH,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAA;AAEzC;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA"}
@@ -0,0 +1,35 @@
1
+ import type * as Engine from '../core/Engine.js';
2
+ import type * as Errors from '../core/Errors.js';
3
+ import * as internal from './internal/instantiate.js';
4
+ export * from '../core/Ed25519.js';
5
+ export { MemoryError } from './internal/instantiate.js';
6
+ /**
7
+ * Compiles WASM implementations of selected [`Ed25519`](/api/Ed25519)
8
+ * primitives, without installing them.
9
+ *
10
+ * Public-key conversion and random key generation remain on Ox's default
11
+ * implementation. The public conversion is omitted because Monocypher does not
12
+ * reproduce Ox's invalid-point validation.
13
+ *
14
+ * @example
15
+ * ```ts twoslash
16
+ * // @noErrors
17
+ * import { Engine } from 'ox'
18
+ * import { Ed25519 } from 'ox/wasm'
19
+ *
20
+ * await Engine.install({ Ed25519: Ed25519.engine() })
21
+ *
22
+ * Ed25519.getPublicKey({ privateKey: '0x...' })
23
+ * ```
24
+ *
25
+ * @returns The WASM implementation of part of the `Ed25519` slot.
26
+ */
27
+ export declare function engine(): Promise<engine.ReturnType>;
28
+ export declare namespace engine {
29
+ /** Every `Ed25519` primitive this module implements. */
30
+ type ReturnType = {
31
+ [key in 'getPublicKey' | 'sign' | 'toMontgomerySecret' | 'verify']-?: NonNullable<Engine.Eddsa[key]>;
32
+ };
33
+ type ErrorType = internal.MemoryError | Errors.GlobalErrorType;
34
+ }
35
+ //# sourceMappingURL=Ed25519.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Ed25519.d.ts","sourceRoot":"","sources":["../../src/wasm/Ed25519.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAChD,OAAO,KAAK,KAAK,MAAM,MAAM,mBAAmB,CAAA;AAGhD,OAAO,KAAK,QAAQ,MAAM,2BAA2B,CAAA;AAErD,cAAc,oBAAoB,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAKvD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CA4DzD;AAED,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,wDAAwD;IACxD,KAAK,UAAU,GAAG;SACf,GAAG,IACA,cAAc,GACd,MAAM,GACN,oBAAoB,GACpB,QAAQ,CAAC,CAAC,GAAG,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;KAChD,CAAA;IAED,KAAK,SAAS,GAAG,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,eAAe,CAAA;CAC/D"}
@@ -0,0 +1,88 @@
1
+ import * as crypto25519 from './internal/crypto25519.js';
2
+ import * as ed25519 from './internal/ed25519.js';
3
+ export * from '../core/Ed25519.js';
4
+ export { MemoryError } from './internal/instantiate.js';
5
+ const keySize = 32;
6
+ const signatureSize = 64;
7
+ /**
8
+ * Compiles WASM implementations of selected [`Ed25519`](/api/Ed25519)
9
+ * primitives, without installing them.
10
+ *
11
+ * Public-key conversion and random key generation remain on Ox's default
12
+ * implementation. The public conversion is omitted because Monocypher does not
13
+ * reproduce Ox's invalid-point validation.
14
+ *
15
+ * @example
16
+ * ```ts twoslash
17
+ * // @noErrors
18
+ * import { Engine } from 'ox'
19
+ * import { Ed25519 } from 'ox/wasm'
20
+ *
21
+ * await Engine.install({ Ed25519: Ed25519.engine() })
22
+ *
23
+ * Ed25519.getPublicKey({ privateKey: '0x...' })
24
+ * ```
25
+ *
26
+ * @returns The WASM implementation of part of the `Ed25519` slot.
27
+ */
28
+ export async function engine() {
29
+ const module = await crypto25519.load();
30
+ return {
31
+ getPublicKey(privateKey) {
32
+ assertLength(privateKey, keySize, 'private key');
33
+ module.reserve(keySize * 2);
34
+ const privateKeyPtr = module.heapBase;
35
+ const publicKeyPtr = privateKeyPtr + keySize;
36
+ try {
37
+ module.view().set(privateKey, privateKeyPtr);
38
+ module.exports.ed25519_get_public_key(privateKeyPtr, publicKeyPtr);
39
+ return module.view().slice(publicKeyPtr, publicKeyPtr + keySize);
40
+ }
41
+ finally {
42
+ module.exports.zero(privateKeyPtr, keySize * 2);
43
+ }
44
+ },
45
+ sign(payload, privateKey) {
46
+ assertLength(privateKey, keySize, 'private key');
47
+ return ed25519.sign(module, payload, privateKey);
48
+ },
49
+ toMontgomerySecret(privateKey) {
50
+ assertLength(privateKey, keySize, 'private key');
51
+ module.reserve(keySize * 2);
52
+ const privateKeyPtr = module.heapBase;
53
+ const secretKeyPtr = privateKeyPtr + keySize;
54
+ try {
55
+ module.view().set(privateKey, privateKeyPtr);
56
+ module.exports.ed25519_to_montgomery_secret(privateKeyPtr, secretKeyPtr);
57
+ return module.view().slice(secretKeyPtr, secretKeyPtr + keySize);
58
+ }
59
+ finally {
60
+ module.exports.zero(privateKeyPtr, keySize * 2);
61
+ }
62
+ },
63
+ verify(signature, payload, publicKey) {
64
+ assertLength(signature, signatureSize, 'signature');
65
+ assertLength(publicKey, keySize, 'public key');
66
+ const size = signatureSize + payload.length + keySize;
67
+ module.reserve(size);
68
+ const signaturePtr = module.heapBase;
69
+ const payloadPtr = signaturePtr + signatureSize;
70
+ const publicKeyPtr = payloadPtr + payload.length;
71
+ try {
72
+ const memory = module.view();
73
+ memory.set(signature, signaturePtr);
74
+ memory.set(payload, payloadPtr);
75
+ memory.set(publicKey, publicKeyPtr);
76
+ return (module.exports.ed25519_verify(signaturePtr, payloadPtr, payload.length, publicKeyPtr) === 1);
77
+ }
78
+ finally {
79
+ module.exports.zero(signaturePtr, size);
80
+ }
81
+ },
82
+ };
83
+ }
84
+ function assertLength(value, length, name) {
85
+ if (value.length !== length)
86
+ throw new RangeError(`Ed25519 ${name} must be ${length} bytes, got ${value.length}`);
87
+ }
88
+ //# sourceMappingURL=Ed25519.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Ed25519.js","sourceRoot":"","sources":["../../src/wasm/Ed25519.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,WAAW,MAAM,2BAA2B,CAAA;AACxD,OAAO,KAAK,OAAO,MAAM,uBAAuB,CAAA;AAGhD,cAAc,oBAAoB,CAAA;AAClC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAA;AAEvD,MAAM,OAAO,GAAG,EAAE,CAAA;AAClB,MAAM,aAAa,GAAG,EAAE,CAAA;AAExB;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM;IAC1B,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,IAAI,EAAE,CAAA;IAEvC,OAAO;QACL,YAAY,CAAC,UAAU;YACrB,YAAY,CAAC,UAAU,EAAE,OAAO,EAAE,aAAa,CAAC,CAAA;YAChD,MAAM,CAAC,OAAO,CAAC,OAAO,GAAG,CAAC,CAAC,CAAA;YAC3B,MAAM,aAAa,GAAG,MAAM,CAAC,QAAQ,CAAA;YACrC,MAAM,YAAY,GAAG,aAAa,GAAG,OAAO,CAAA;YAC5C,IAAI,CAAC;gBACH,MAAM,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,UAAU,EAAE,aAAa,CAAC,CAAA;gBAC5C,MAAM,CAAC,OAAO,CAAC,sBAAsB,CAAC,aAAa,EAAE,YAAY,CAAC,CAAA;gBAClE,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,CAAA;YAClE,CAAC;oBAAS,CAAC;gBACT,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,GAAG,CAAC,CAAC,CAAA;YACjD,CAAC;QACH,CAAC;QAC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YAAY,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAA;YAChD,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,EAAE,CAAA;gBAC5B,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,YAAY,CAAC,CAAA;gBACnC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;gBAC/B,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,YAAY,CAAC,CAAA;gBACnC,OAAO,CACL,MAAM,CAAC,OAAO,CAAC,cAAc,CAC3B,YAAY,EACZ,UAAU,EACV,OAAO,CAAC,MAAM,EACd,YAAY,CACb,KAAK,CAAC,CACR,CAAA;YACH,CAAC;oBAAS,CAAC;gBACT,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,EAAE,IAAI,CAAC,CAAA;YACzC,CAAC;QACH,CAAC;KACF,CAAA;AACH,CAAC;AAeD,SAAS,YAAY,CAAC,KAAiB,EAAE,MAAc,EAAE,IAAY;IACnE,IAAI,KAAK,CAAC,MAAM,KAAK,MAAM;QACzB,MAAM,IAAI,UAAU,CAClB,WAAW,IAAI,YAAY,MAAM,eAAe,KAAK,CAAC,MAAM,EAAE,CAC/D,CAAA;AACL,CAAC"}
@@ -1,44 +1,47 @@
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 X25519 from './X25519.js';
4
8
  import type * as internal from './internal/instantiate.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';
5
11
  /**
6
- * Compiles every implementation this entrypoint provides and installs it.
12
+ * Compiles and installs every WASM implementation this entrypoint provides.
7
13
  *
8
- * WASM must be compiled asynchronously, so this is where the `await` lives.
9
- * Everything afterwards, including the hashing itself, is synchronous.
14
+ * Slot compilation starts concurrently. Nothing is installed until every slot
15
+ * resolves successfully.
10
16
  *
11
- * Call it once, during startup, before any crypto call. ox resolves the engine
12
- * at call time, so values computed beforehand used whatever was installed then.
17
+ * Call this once, during startup, before any crypto call. Ox resolves the
18
+ * engine at call time, so values computed beforehand used whatever was
19
+ * installed then.
13
20
  *
14
21
  * @example
15
22
  * ```ts twoslash
16
23
  * // @noErrors
17
- * import { Hash } from 'ox'
18
- * import { Engine } from 'ox/wasm'
24
+ * import { Engine, Hash } from 'ox/wasm'
19
25
  *
20
- * await Engine.load()
26
+ * await Engine.install()
21
27
  *
22
- * Hash.keccak256('0xdeadbeef')
28
+ * Hash.sha256('0xdeadbeef')
23
29
  * ```
24
30
  *
25
31
  * @returns The engine that was installed.
26
32
  */
27
- export declare function load(): Promise<load.ReturnType>;
28
- export declare namespace load {
29
- type ReturnType = create.ReturnType;
30
- type ErrorType = create.ErrorType | CoreEngine.set.ErrorType | Errors.GlobalErrorType;
33
+ export declare function install(): Promise<install.ReturnType>;
34
+ export declare namespace install {
35
+ type ReturnType = engine.ReturnType;
36
+ type ErrorType = engine.ErrorType | CoreEngine.install.ErrorType | Errors.GlobalErrorType;
31
37
  }
32
38
  /**
33
- * Compiles every implementation this entrypoint provides, without installing
34
- * it.
39
+ * Compiles every WASM implementation this entrypoint provides, without
40
+ * installing it.
35
41
  *
36
- * Reach for this where an engine has to exist as a value: measuring one
37
- * implementation against another, or installing through
38
- * [`Engine.with`](/api/Engine/with) for the duration of a call. Combining
39
- * engines does not need it, because
40
- * [`Engine.set`](/api/Engine/set) merges -- `await load()` followed by
41
- * `Engine.set({ Secp256k1 })` leaves both in place.
42
+ * Reach for this where an engine has to exist as a value, such as a benchmark
43
+ * or an [`Engine.with`](/api/Engine/with) scope. Use the individual module's
44
+ * `engine` function to select only some slots.
42
45
  *
43
46
  * @example
44
47
  * ```ts twoslash
@@ -46,17 +49,23 @@ export declare namespace load {
46
49
  * import { Engine, Hash } from 'ox'
47
50
  * import { Engine as Wasm } from 'ox/wasm'
48
51
  *
49
- * const wasm = await Wasm.create()
52
+ * const wasm = await Wasm.engine()
50
53
  *
51
- * Engine.with(wasm, () => Hash.keccak256('0xdeadbeef'))
54
+ * Engine.with(wasm, () => Hash.sha256('0xdeadbeef'))
52
55
  * ```
53
56
  *
54
57
  * @returns An engine, ready to install.
55
58
  */
56
- export declare function create(): Promise<create.ReturnType>;
57
- export declare namespace create {
59
+ export declare function engine(): Promise<engine.ReturnType>;
60
+ export declare namespace engine {
58
61
  /** Every slot this entrypoint supplies, each with its primitives present. */
59
- type ReturnType = Hash.create.ReturnType;
62
+ type ReturnType = {
63
+ Ed25519: Ed25519.engine.ReturnType;
64
+ Hash: Hash.engine.ReturnType;
65
+ Keystore: Keystore.engine.ReturnType;
66
+ Mnemonic: Mnemonic.engine.ReturnType;
67
+ X25519: X25519.engine.ReturnType;
68
+ };
60
69
  type ErrorType = internal.MemoryError | Errors.GlobalErrorType;
61
70
  }
62
71
  //# sourceMappingURL=Engine.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Engine.d.ts","sourceRoot":"","sources":["../../src/wasm/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;AACjC,OAAO,KAAK,KAAK,QAAQ,MAAM,2BAA2B,CAAA;AAE1D;;;;;;;;;;;;;;;;;;;;;GAqBG;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,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MAAM,CAAC,OAAO,WAAW,OAAO,CAAC;IAC/B,KAAK,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;IAEnC,KAAK,SAAS,GACV,MAAM,CAAC,SAAS,GAChB,UAAU,CAAC,OAAO,CAAC,SAAS,GAC5B,MAAM,CAAC,eAAe,CAAA;CAC3B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,CAezD;AAED,MAAM,CAAC,OAAO,WAAW,MAAM,CAAC;IAC9B,6EAA6E;IAC7E,KAAK,UAAU,GAAG;QAChB,OAAO,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,CAAA;QAClC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU,CAAA;QAC5B,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAA;QACpC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAA;QACpC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAA;KACjC,CAAA;IAED,KAAK,SAAS,GAAG,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,eAAe,CAAA;CAC/D"}
@@ -1,42 +1,48 @@
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 X25519 from './X25519.js';
7
+ export { AsyncScopeError, get, InvalidSlotValueError, reset, set, UnknownPrimitiveError, UnknownSlotError, with, } from '../core/Engine.js';
3
8
  /**
4
- * Compiles every implementation this entrypoint provides and installs it.
9
+ * Compiles and installs every WASM implementation this entrypoint provides.
5
10
  *
6
- * WASM must be compiled asynchronously, so this is where the `await` lives.
7
- * Everything afterwards, including the hashing itself, is synchronous.
11
+ * Slot compilation starts concurrently. Nothing is installed until every slot
12
+ * resolves successfully.
8
13
  *
9
- * Call it once, during startup, before any crypto call. ox resolves the engine
10
- * at call time, so values computed beforehand used whatever was installed then.
14
+ * Call this once, during startup, before any crypto call. Ox resolves the
15
+ * engine at call time, so values computed beforehand used whatever was
16
+ * installed then.
11
17
  *
12
18
  * @example
13
19
  * ```ts twoslash
14
20
  * // @noErrors
15
- * import { Hash } from 'ox'
16
- * import { Engine } from 'ox/wasm'
21
+ * import { Engine, Hash } from 'ox/wasm'
17
22
  *
18
- * await Engine.load()
23
+ * await Engine.install()
19
24
  *
20
- * Hash.keccak256('0xdeadbeef')
25
+ * Hash.sha256('0xdeadbeef')
21
26
  * ```
22
27
  *
23
28
  * @returns The engine that was installed.
24
29
  */
25
- export async function load() {
26
- const engine = await create();
27
- CoreEngine.set(engine);
28
- return engine;
30
+ export async function install() {
31
+ return CoreEngine.install({
32
+ Ed25519: Ed25519.engine(),
33
+ Hash: Hash.engine(),
34
+ Keystore: Keystore.engine(),
35
+ Mnemonic: Mnemonic.engine(),
36
+ X25519: X25519.engine(),
37
+ });
29
38
  }
30
39
  /**
31
- * Compiles every implementation this entrypoint provides, without installing
32
- * it.
40
+ * Compiles every WASM implementation this entrypoint provides, without
41
+ * installing it.
33
42
  *
34
- * Reach for this where an engine has to exist as a value: measuring one
35
- * implementation against another, or installing through
36
- * [`Engine.with`](/api/Engine/with) for the duration of a call. Combining
37
- * engines does not need it, because
38
- * [`Engine.set`](/api/Engine/set) merges -- `await load()` followed by
39
- * `Engine.set({ Secp256k1 })` leaves both in place.
43
+ * Reach for this where an engine has to exist as a value, such as a benchmark
44
+ * or an [`Engine.with`](/api/Engine/with) scope. Use the individual module's
45
+ * `engine` function to select only some slots.
40
46
  *
41
47
  * @example
42
48
  * ```ts twoslash
@@ -44,14 +50,27 @@ export async function load() {
44
50
  * import { Engine, Hash } from 'ox'
45
51
  * import { Engine as Wasm } from 'ox/wasm'
46
52
  *
47
- * const wasm = await Wasm.create()
53
+ * const wasm = await Wasm.engine()
48
54
  *
49
- * Engine.with(wasm, () => Hash.keccak256('0xdeadbeef'))
55
+ * Engine.with(wasm, () => Hash.sha256('0xdeadbeef'))
50
56
  * ```
51
57
  *
52
58
  * @returns An engine, ready to install.
53
59
  */
54
- export async function create() {
55
- return { ...(await Hash.create()) };
60
+ export async function engine() {
61
+ const [ed25519, hash, keystore, mnemonic, x25519] = await Promise.all([
62
+ Ed25519.engine(),
63
+ Hash.engine(),
64
+ Keystore.engine(),
65
+ Mnemonic.engine(),
66
+ X25519.engine(),
67
+ ]);
68
+ return {
69
+ Ed25519: ed25519,
70
+ Hash: hash,
71
+ Keystore: keystore,
72
+ Mnemonic: mnemonic,
73
+ X25519: x25519,
74
+ };
56
75
  }
57
76
  //# sourceMappingURL=Engine.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Engine.js","sourceRoot":"","sources":["../../src/wasm/Engine.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,mBAAmB,CAAA;AAE/C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAGjC;;;;;;;;;;;;;;;;;;;;;GAqBG;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;;;;;;;;;;;;;;;;;;;;;;;GAuBG;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/wasm/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,MAA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