@holoscript/core 6.0.4 → 7.0.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 (236) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -1
  3. package/dist/compiler/index.d.ts +82 -0
  4. package/dist/constants.d.ts +3 -2
  5. package/dist/coordinators/index.d.ts +189 -0
  6. package/dist/index.d.ts +501 -19
  7. package/dist/paper-0c-spike/index.d.ts +29 -0
  8. package/dist/reconstruction/index.d.ts +78 -0
  9. package/dist/tools/index.d.ts +22 -1
  10. package/dist/traitDocs/traitDocs.d.ts +69 -0
  11. package/dist/traits/index.d.ts +61 -0
  12. package/package.json +105 -57
  13. package/dist/GLTFPipeline-DEN36VNK.js +0 -12
  14. package/dist/GLTFPipeline-YPCAK236.cjs +0 -33
  15. package/dist/HoloScriptPlusParser-BN6KVRCM.js +0 -692
  16. package/dist/HoloScriptPlusParser-NC5FE6AL.cjs +0 -697
  17. package/dist/USDZExporter-NTMBNTDB.js +0 -707
  18. package/dist/USDZExporter-UWGWNMMD.cjs +0 -709
  19. package/dist/chunk-27LWW5FU.cjs +0 -410
  20. package/dist/chunk-2CWOLHTE.js +0 -69
  21. package/dist/chunk-33LSUQDD.cjs +0 -835
  22. package/dist/chunk-3FJCK5XA.js +0 -2232
  23. package/dist/chunk-3FXV5S25.cjs +0 -633
  24. package/dist/chunk-3FYZOR7S.cjs +0 -69
  25. package/dist/chunk-3SAK5KFL.cjs +0 -83
  26. package/dist/chunk-4XSNJCLC.cjs +0 -1859
  27. package/dist/chunk-54FHG2MX.js +0 -655
  28. package/dist/chunk-56IF4NTA.js +0 -56
  29. package/dist/chunk-5BGSECRJ.cjs +0 -2237
  30. package/dist/chunk-5GLCTO44.js +0 -161
  31. package/dist/chunk-5O6TQC6M.cjs +0 -1871
  32. package/dist/chunk-5OEOHAAW.cjs +0 -682
  33. package/dist/chunk-5TOFIR6L.js +0 -407
  34. package/dist/chunk-5WUNN6ZN.cjs +0 -428
  35. package/dist/chunk-6TZPZCOJ.cjs +0 -1404
  36. package/dist/chunk-6UEHYZ7V.cjs +0 -773
  37. package/dist/chunk-6XSERL6L.js +0 -5678
  38. package/dist/chunk-72EQECGT.cjs +0 -908
  39. package/dist/chunk-7AGYRWKW.cjs +0 -507
  40. package/dist/chunk-7LCYLPW2.cjs +0 -663
  41. package/dist/chunk-A7PIMZGU.js +0 -263
  42. package/dist/chunk-ATSKSYVE.cjs +0 -51683
  43. package/dist/chunk-B5TCIAPQ.cjs +0 -117
  44. package/dist/chunk-BF2235SI.cjs +0 -5714
  45. package/dist/chunk-BKIGPPVM.js +0 -629
  46. package/dist/chunk-BND3ST2K.cjs +0 -662
  47. package/dist/chunk-BU7VWW2K.js +0 -2522
  48. package/dist/chunk-BWFJEM5A.js +0 -5419
  49. package/dist/chunk-CAUCGUEA.cjs +0 -130
  50. package/dist/chunk-CBJSLA2E.cjs +0 -5423
  51. package/dist/chunk-CDPGV4DN.js +0 -114
  52. package/dist/chunk-CLYEIWA5.cjs +0 -408
  53. package/dist/chunk-CS2EMTGF.js +0 -1966
  54. package/dist/chunk-DMG7C4H2.js +0 -975
  55. package/dist/chunk-DXJQDCFL.js +0 -468
  56. package/dist/chunk-E3FWRT3Z.js +0 -608
  57. package/dist/chunk-E3UALNFA.js +0 -421
  58. package/dist/chunk-EONILVMF.js +0 -762
  59. package/dist/chunk-EQV4R3EV.cjs +0 -769
  60. package/dist/chunk-F3HH56EB.cjs +0 -5538
  61. package/dist/chunk-F4IULT7N.js +0 -1488
  62. package/dist/chunk-FF3Q7ADR.js +0 -380
  63. package/dist/chunk-FFKU7BTK.cjs +0 -1046
  64. package/dist/chunk-FHQVYCH2.js +0 -70
  65. package/dist/chunk-FSF7EQVA.cjs +0 -1974
  66. package/dist/chunk-G4VZTCIB.js +0 -659
  67. package/dist/chunk-G7CT3EMP.cjs +0 -1002
  68. package/dist/chunk-GGHSW2NN.js +0 -51334
  69. package/dist/chunk-GVUR45UF.cjs +0 -777
  70. package/dist/chunk-H5Z7NASB.js +0 -9662
  71. package/dist/chunk-HE7ULERA.cjs +0 -697
  72. package/dist/chunk-HJJLD366.js +0 -1169
  73. package/dist/chunk-HPS76H7Q.js +0 -309
  74. package/dist/chunk-HQUEA5R6.cjs +0 -424
  75. package/dist/chunk-HYNTS5CP.js +0 -422
  76. package/dist/chunk-I6XZ5DZF.cjs +0 -488
  77. package/dist/chunk-IBDG74G2.cjs +0 -1219
  78. package/dist/chunk-IFNQFCTM.js +0 -3098
  79. package/dist/chunk-IHOUYQIA.js +0 -406
  80. package/dist/chunk-ILRBGFVD.cjs +0 -72
  81. package/dist/chunk-IWI6J7FX.js +0 -421
  82. package/dist/chunk-K3JDKWGI.cjs +0 -270
  83. package/dist/chunk-K6EKD26I.js +0 -630
  84. package/dist/chunk-KCQ5NDYC.cjs +0 -3172
  85. package/dist/chunk-KED34ILP.js +0 -832
  86. package/dist/chunk-KSGXLT74.cjs +0 -457
  87. package/dist/chunk-L4G4RLXX.js +0 -767
  88. package/dist/chunk-LDP5OK6G.js +0 -1216
  89. package/dist/chunk-LGGRPKTV.cjs +0 -735
  90. package/dist/chunk-LK5IAVH6.cjs +0 -1173
  91. package/dist/chunk-LSW7P7ML.js +0 -3675
  92. package/dist/chunk-LXJ4667L.cjs +0 -3874
  93. package/dist/chunk-LZ266PCM.cjs +0 -4499
  94. package/dist/chunk-MD6KDHVE.cjs +0 -237
  95. package/dist/chunk-MEASWI2Y.js +0 -126
  96. package/dist/chunk-MPXBVFHQ.js +0 -768
  97. package/dist/chunk-N5FTS757.cjs +0 -415
  98. package/dist/chunk-NCUKG4SK.cjs +0 -3075
  99. package/dist/chunk-NDQNIJEH.js +0 -1715
  100. package/dist/chunk-NOZZ46QU.js +0 -168
  101. package/dist/chunk-OFKWH2IP.js +0 -449
  102. package/dist/chunk-PHENW4MQ.js +0 -65
  103. package/dist/chunk-PMGODDJA.cjs +0 -319
  104. package/dist/chunk-Q4QX3AET.cjs +0 -1505
  105. package/dist/chunk-Q56TT7IL.js +0 -483
  106. package/dist/chunk-Q5JT3YML.cjs +0 -129
  107. package/dist/chunk-Q5SJOGHQ.cjs +0 -4256
  108. package/dist/chunk-QGKNANZ3.js +0 -3071
  109. package/dist/chunk-QLEAOI3Q.cjs +0 -424
  110. package/dist/chunk-R7MA7QWV.js +0 -732
  111. package/dist/chunk-RVYPEYPX.js +0 -678
  112. package/dist/chunk-S2N5TNMA.js +0 -1855
  113. package/dist/chunk-S565K7NK.js +0 -752
  114. package/dist/chunk-SDAMZIRE.js +0 -765
  115. package/dist/chunk-T36DDXSF.js +0 -4250
  116. package/dist/chunk-T4NKMBDL.js +0 -5474
  117. package/dist/chunk-T7LEXZUZ.cjs +0 -2526
  118. package/dist/chunk-TEWCN33Y.js +0 -694
  119. package/dist/chunk-TQSZUOW5.cjs +0 -793
  120. package/dist/chunk-TSH3MSQU.cjs +0 -129
  121. package/dist/chunk-UERJ3YJV.js +0 -504
  122. package/dist/chunk-UPJBDCVF.js +0 -1395
  123. package/dist/chunk-V3NN3HPP.js +0 -4462
  124. package/dist/chunk-VJ3L7CHT.cjs +0 -169
  125. package/dist/chunk-WB4Z63GG.js +0 -229
  126. package/dist/chunk-WDW67DZB.cjs +0 -9728
  127. package/dist/chunk-WGMEAYBG.js +0 -126
  128. package/dist/chunk-X4ZF6CNE.cjs +0 -473
  129. package/dist/chunk-X6SEAXAX.cjs +0 -3681
  130. package/dist/chunk-XCWFGZAA.js +0 -1043
  131. package/dist/chunk-XD6IYDUX.js +0 -903
  132. package/dist/chunk-XG23EUQX.cjs +0 -1717
  133. package/dist/chunk-XRKWN5PL.cjs +0 -173
  134. package/dist/chunk-XUILI4KB.cjs +0 -430
  135. package/dist/chunk-XUTX5CBW.js +0 -126
  136. package/dist/chunk-XWPNTWDN.cjs +0 -755
  137. package/dist/chunk-XXINBTZK.cjs +0 -633
  138. package/dist/chunk-YCXFCXDS.js +0 -1868
  139. package/dist/chunk-YQK5JNFK.js +0 -3725
  140. package/dist/chunk-YYXH45E2.js +0 -426
  141. package/dist/chunk-Z34RLXRA.cjs +0 -612
  142. package/dist/chunk-ZP4D3CSX.cjs +0 -72
  143. package/dist/cli/holoscript-runner.cjs +0 -2259
  144. package/dist/cli/holoscript-runner.js +0 -2234
  145. package/dist/codebase/index.cjs +0 -336
  146. package/dist/codebase/index.js +0 -331
  147. package/dist/compiler/agent-inference.cjs +0 -28
  148. package/dist/compiler/agent-inference.js +0 -5
  149. package/dist/compiler/android-xr.cjs +0 -19
  150. package/dist/compiler/android-xr.js +0 -9
  151. package/dist/compiler/android.cjs +0 -20
  152. package/dist/compiler/android.js +0 -10
  153. package/dist/compiler/ar.cjs +0 -20
  154. package/dist/compiler/ar.js +0 -8
  155. package/dist/compiler/babylon.cjs +0 -17
  156. package/dist/compiler/babylon.js +0 -11
  157. package/dist/compiler/coco.cjs +0 -27
  158. package/dist/compiler/coco.js +0 -4
  159. package/dist/compiler/domain-block-utils.cjs +0 -602
  160. package/dist/compiler/domain-block-utils.js +0 -8
  161. package/dist/compiler/dtdl.cjs +0 -24
  162. package/dist/compiler/dtdl.js +0 -8
  163. package/dist/compiler/gltf-pipeline.cjs +0 -39
  164. package/dist/compiler/gltf-pipeline.js +0 -4
  165. package/dist/compiler/godot.cjs +0 -15
  166. package/dist/compiler/godot.js +0 -9
  167. package/dist/compiler/incremental.cjs +0 -29
  168. package/dist/compiler/incremental.js +0 -4
  169. package/dist/compiler/index.cjs +0 -2578
  170. package/dist/compiler/index.js +0 -2383
  171. package/dist/compiler/ios.cjs +0 -20
  172. package/dist/compiler/ios.js +0 -10
  173. package/dist/compiler/multi-layer.cjs +0 -20
  174. package/dist/compiler/multi-layer.js +0 -11
  175. package/dist/compiler/nodetoy.cjs +0 -23
  176. package/dist/compiler/nodetoy.js +0 -4
  177. package/dist/compiler/openxr.cjs +0 -15
  178. package/dist/compiler/openxr.js +0 -9
  179. package/dist/compiler/playcanvas.cjs +0 -16
  180. package/dist/compiler/playcanvas.js +0 -10
  181. package/dist/compiler/r3f.cjs +0 -34
  182. package/dist/compiler/r3f.js +0 -12
  183. package/dist/compiler/remotion.cjs +0 -23
  184. package/dist/compiler/remotion.js +0 -4
  185. package/dist/compiler/reproducibility.cjs +0 -39
  186. package/dist/compiler/reproducibility.js +0 -4
  187. package/dist/compiler/sdf.cjs +0 -21
  188. package/dist/compiler/sdf.js +0 -9
  189. package/dist/compiler/semantic-scene.cjs +0 -31
  190. package/dist/compiler/semantic-scene.js +0 -4
  191. package/dist/compiler/state.cjs +0 -17
  192. package/dist/compiler/state.js +0 -7
  193. package/dist/compiler/trait-composition.cjs +0 -26
  194. package/dist/compiler/trait-composition.js +0 -5
  195. package/dist/compiler/unity.cjs +0 -15
  196. package/dist/compiler/unity.js +0 -9
  197. package/dist/compiler/unreal.cjs +0 -19
  198. package/dist/compiler/unreal.js +0 -9
  199. package/dist/compiler/urdf.cjs +0 -45
  200. package/dist/compiler/urdf.js +0 -9
  201. package/dist/compiler/usd-physics.cjs +0 -23
  202. package/dist/compiler/usd-physics.js +0 -6
  203. package/dist/compiler/visionos.cjs +0 -15
  204. package/dist/compiler/visionos.js +0 -9
  205. package/dist/compiler/vrchat.cjs +0 -19
  206. package/dist/compiler/vrchat.js +0 -9
  207. package/dist/compiler/vrr.cjs +0 -21
  208. package/dist/compiler/vrr.js +0 -9
  209. package/dist/compiler/wasm.cjs +0 -33
  210. package/dist/compiler/wasm.js +0 -9
  211. package/dist/compiler/webgpu.cjs +0 -15
  212. package/dist/compiler/webgpu.js +0 -9
  213. package/dist/debugger.cjs +0 -21
  214. package/dist/debugger.js +0 -8
  215. package/dist/entries/interop.cjs +0 -62
  216. package/dist/entries/interop.js +0 -5
  217. package/dist/entries/scripting.cjs +0 -68
  218. package/dist/entries/scripting.js +0 -11
  219. package/dist/index.cjs +0 -40921
  220. package/dist/index.js +0 -37763
  221. package/dist/math/vec3.cjs +0 -57
  222. package/dist/math/vec3.js +0 -4
  223. package/dist/ml-dsa-PHCWUBPX.cjs +0 -1178
  224. package/dist/ml-dsa-WYLJHJO6.js +0 -1178
  225. package/dist/parser.cjs +0 -27
  226. package/dist/parser.js +0 -10
  227. package/dist/playwright-5OSAPTNH.js +0 -98660
  228. package/dist/playwright-RL6GY4F7.cjs +0 -98673
  229. package/dist/runtime.cjs +0 -16
  230. package/dist/runtime.js +0 -7
  231. package/dist/storage/index.cjs +0 -37
  232. package/dist/storage/index.js +0 -4
  233. package/dist/traits/index.cjs +0 -14649
  234. package/dist/traits/index.js +0 -12243
  235. package/dist/type-checker.cjs +0 -18
  236. package/dist/type-checker.js +0 -5
@@ -1,1178 +0,0 @@
1
- import { __esm, __publicField } from './chunk-2CWOLHTE.js';
2
-
3
- // ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/utils.js
4
- function isBytes(a) {
5
- return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
6
- }
7
- function anumber(n, title = "") {
8
- if (!Number.isSafeInteger(n) || n < 0) {
9
- const prefix = title && `"${title}" `;
10
- throw new Error(`${prefix}expected integer >= 0, got ${n}`);
11
- }
12
- }
13
- function abytes(value, length, title = "") {
14
- const bytes = isBytes(value);
15
- const len = value?.length;
16
- const needsLen = length !== void 0;
17
- if (!bytes || needsLen && len !== length) {
18
- const prefix = title && `"${title}" `;
19
- const ofLen = needsLen ? ` of length ${length}` : "";
20
- const got = bytes ? `length=${len}` : `type=${typeof value}`;
21
- throw new Error(prefix + "expected Uint8Array" + ofLen + ", got " + got);
22
- }
23
- return value;
24
- }
25
- function aexists(instance, checkFinished = true) {
26
- if (instance.destroyed)
27
- throw new Error("Hash instance has been destroyed");
28
- if (checkFinished && instance.finished)
29
- throw new Error("Hash#digest() has already been called");
30
- }
31
- function aoutput(out, instance) {
32
- abytes(out, void 0, "digestInto() output");
33
- const min = instance.outputLen;
34
- if (out.length < min) {
35
- throw new Error('"digestInto() output" expected to be of length >=' + min);
36
- }
37
- }
38
- function u32(arr) {
39
- return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
40
- }
41
- function clean(...arrays) {
42
- for (let i = 0; i < arrays.length; i++) {
43
- arrays[i].fill(0);
44
- }
45
- }
46
- function byteSwap(word) {
47
- return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
48
- }
49
- function byteSwap32(arr) {
50
- for (let i = 0; i < arr.length; i++) {
51
- arr[i] = byteSwap(arr[i]);
52
- }
53
- return arr;
54
- }
55
- function concatBytes(...arrays) {
56
- let sum = 0;
57
- for (let i = 0; i < arrays.length; i++) {
58
- const a = arrays[i];
59
- abytes(a);
60
- sum += a.length;
61
- }
62
- const res = new Uint8Array(sum);
63
- for (let i = 0, pad = 0; i < arrays.length; i++) {
64
- const a = arrays[i];
65
- res.set(a, pad);
66
- pad += a.length;
67
- }
68
- return res;
69
- }
70
- function createHasher(hashCons, info = {}) {
71
- const hashC = (msg, opts) => hashCons(opts).update(msg).digest();
72
- const tmp = hashCons(void 0);
73
- hashC.outputLen = tmp.outputLen;
74
- hashC.blockLen = tmp.blockLen;
75
- hashC.create = (opts) => hashCons(opts);
76
- Object.assign(hashC, info);
77
- return Object.freeze(hashC);
78
- }
79
- function randomBytes(bytesLength = 32) {
80
- const cr = typeof globalThis === "object" ? globalThis.crypto : null;
81
- if (typeof cr?.getRandomValues !== "function")
82
- throw new Error("crypto.getRandomValues must be defined");
83
- return cr.getRandomValues(new Uint8Array(bytesLength));
84
- }
85
- var isLE, swap32IfBE, oidNist;
86
- var init_utils = __esm({
87
- "../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/utils.js"() {
88
- isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
89
- swap32IfBE = isLE ? (u) => u : byteSwap32;
90
- oidNist = (suffix) => ({
91
- oid: Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2, suffix])
92
- });
93
- }
94
- });
95
-
96
- // ../../node_modules/.pnpm/@noble+curves@2.0.1/node_modules/@noble/curves/utils.js
97
- function abool(value, title = "") {
98
- if (typeof value !== "boolean") {
99
- const prefix = title && `"${title}" `;
100
- throw new Error(prefix + "expected boolean, got type=" + typeof value);
101
- }
102
- return value;
103
- }
104
- var init_utils2 = __esm({
105
- "../../node_modules/.pnpm/@noble+curves@2.0.1/node_modules/@noble/curves/utils.js"() {
106
- }
107
- });
108
-
109
- // ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/_u64.js
110
- function fromBig(n, le = false) {
111
- if (le)
112
- return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
113
- return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
114
- }
115
- function split(lst, le = false) {
116
- const len = lst.length;
117
- let Ah = new Uint32Array(len);
118
- let Al = new Uint32Array(len);
119
- for (let i = 0; i < len; i++) {
120
- const { h, l } = fromBig(lst[i], le);
121
- [Ah[i], Al[i]] = [h, l];
122
- }
123
- return [Ah, Al];
124
- }
125
- var U32_MASK64, _32n, rotlSH, rotlSL, rotlBH, rotlBL;
126
- var init_u64 = __esm({
127
- "../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/_u64.js"() {
128
- U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
129
- _32n = /* @__PURE__ */ BigInt(32);
130
- rotlSH = (h, l, s) => h << s | l >>> 32 - s;
131
- rotlSL = (h, l, s) => l << s | h >>> 32 - s;
132
- rotlBH = (h, l, s) => l << s - 32 | h >>> 64 - s;
133
- rotlBL = (h, l, s) => h << s - 32 | l >>> 64 - s;
134
- }
135
- });
136
-
137
- // ../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/sha3.js
138
- function keccakP(s, rounds = 24) {
139
- const B = new Uint32Array(5 * 2);
140
- for (let round = 24 - rounds; round < 24; round++) {
141
- for (let x = 0; x < 10; x++)
142
- B[x] = s[x] ^ s[x + 10] ^ s[x + 20] ^ s[x + 30] ^ s[x + 40];
143
- for (let x = 0; x < 10; x += 2) {
144
- const idx1 = (x + 8) % 10;
145
- const idx0 = (x + 2) % 10;
146
- const B0 = B[idx0];
147
- const B1 = B[idx0 + 1];
148
- const Th = rotlH(B0, B1, 1) ^ B[idx1];
149
- const Tl = rotlL(B0, B1, 1) ^ B[idx1 + 1];
150
- for (let y = 0; y < 50; y += 10) {
151
- s[x + y] ^= Th;
152
- s[x + y + 1] ^= Tl;
153
- }
154
- }
155
- let curH = s[2];
156
- let curL = s[3];
157
- for (let t = 0; t < 24; t++) {
158
- const shift = SHA3_ROTL[t];
159
- const Th = rotlH(curH, curL, shift);
160
- const Tl = rotlL(curH, curL, shift);
161
- const PI = SHA3_PI[t];
162
- curH = s[PI];
163
- curL = s[PI + 1];
164
- s[PI] = Th;
165
- s[PI + 1] = Tl;
166
- }
167
- for (let y = 0; y < 50; y += 10) {
168
- for (let x = 0; x < 10; x++)
169
- B[x] = s[y + x];
170
- for (let x = 0; x < 10; x++)
171
- s[y + x] ^= ~B[(x + 2) % 10] & B[(x + 4) % 10];
172
- }
173
- s[0] ^= SHA3_IOTA_H[round];
174
- s[1] ^= SHA3_IOTA_L[round];
175
- }
176
- clean(B);
177
- }
178
- var _0n, _1n, _2n, _7n, _256n, _0x71n, SHA3_PI, SHA3_ROTL, _SHA3_IOTA, IOTAS, SHA3_IOTA_H, SHA3_IOTA_L, rotlH, rotlL, Keccak, genShake, shake128, shake256;
179
- var init_sha3 = __esm({
180
- "../../node_modules/.pnpm/@noble+hashes@2.0.1/node_modules/@noble/hashes/sha3.js"() {
181
- init_u64();
182
- init_utils();
183
- _0n = BigInt(0);
184
- _1n = BigInt(1);
185
- _2n = BigInt(2);
186
- _7n = BigInt(7);
187
- _256n = BigInt(256);
188
- _0x71n = BigInt(113);
189
- SHA3_PI = [];
190
- SHA3_ROTL = [];
191
- _SHA3_IOTA = [];
192
- for (let round = 0, R = _1n, x = 1, y = 0; round < 24; round++) {
193
- [x, y] = [y, (2 * x + 3 * y) % 5];
194
- SHA3_PI.push(2 * (5 * y + x));
195
- SHA3_ROTL.push((round + 1) * (round + 2) / 2 % 64);
196
- let t = _0n;
197
- for (let j = 0; j < 7; j++) {
198
- R = (R << _1n ^ (R >> _7n) * _0x71n) % _256n;
199
- if (R & _2n)
200
- t ^= _1n << (_1n << BigInt(j)) - _1n;
201
- }
202
- _SHA3_IOTA.push(t);
203
- }
204
- IOTAS = split(_SHA3_IOTA, true);
205
- SHA3_IOTA_H = IOTAS[0];
206
- SHA3_IOTA_L = IOTAS[1];
207
- rotlH = (h, l, s) => s > 32 ? rotlBH(h, l, s) : rotlSH(h, l, s);
208
- rotlL = (h, l, s) => s > 32 ? rotlBL(h, l, s) : rotlSL(h, l, s);
209
- Keccak = class _Keccak {
210
- // NOTE: we accept arguments in bytes instead of bits here.
211
- constructor(blockLen, suffix, outputLen, enableXOF = false, rounds = 24) {
212
- __publicField(this, "state");
213
- __publicField(this, "pos", 0);
214
- __publicField(this, "posOut", 0);
215
- __publicField(this, "finished", false);
216
- __publicField(this, "state32");
217
- __publicField(this, "destroyed", false);
218
- __publicField(this, "blockLen");
219
- __publicField(this, "suffix");
220
- __publicField(this, "outputLen");
221
- __publicField(this, "enableXOF", false);
222
- __publicField(this, "rounds");
223
- this.blockLen = blockLen;
224
- this.suffix = suffix;
225
- this.outputLen = outputLen;
226
- this.enableXOF = enableXOF;
227
- this.rounds = rounds;
228
- anumber(outputLen, "outputLen");
229
- if (!(0 < blockLen && blockLen < 200))
230
- throw new Error("only keccak-f1600 function is supported");
231
- this.state = new Uint8Array(200);
232
- this.state32 = u32(this.state);
233
- }
234
- clone() {
235
- return this._cloneInto();
236
- }
237
- keccak() {
238
- swap32IfBE(this.state32);
239
- keccakP(this.state32, this.rounds);
240
- swap32IfBE(this.state32);
241
- this.posOut = 0;
242
- this.pos = 0;
243
- }
244
- update(data) {
245
- aexists(this);
246
- abytes(data);
247
- const { blockLen, state } = this;
248
- const len = data.length;
249
- for (let pos = 0; pos < len; ) {
250
- const take = Math.min(blockLen - this.pos, len - pos);
251
- for (let i = 0; i < take; i++)
252
- state[this.pos++] ^= data[pos++];
253
- if (this.pos === blockLen)
254
- this.keccak();
255
- }
256
- return this;
257
- }
258
- finish() {
259
- if (this.finished)
260
- return;
261
- this.finished = true;
262
- const { state, suffix, pos, blockLen } = this;
263
- state[pos] ^= suffix;
264
- if ((suffix & 128) !== 0 && pos === blockLen - 1)
265
- this.keccak();
266
- state[blockLen - 1] ^= 128;
267
- this.keccak();
268
- }
269
- writeInto(out) {
270
- aexists(this, false);
271
- abytes(out);
272
- this.finish();
273
- const bufferOut = this.state;
274
- const { blockLen } = this;
275
- for (let pos = 0, len = out.length; pos < len; ) {
276
- if (this.posOut >= blockLen)
277
- this.keccak();
278
- const take = Math.min(blockLen - this.posOut, len - pos);
279
- out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
280
- this.posOut += take;
281
- pos += take;
282
- }
283
- return out;
284
- }
285
- xofInto(out) {
286
- if (!this.enableXOF)
287
- throw new Error("XOF is not possible for this instance");
288
- return this.writeInto(out);
289
- }
290
- xof(bytes) {
291
- anumber(bytes);
292
- return this.xofInto(new Uint8Array(bytes));
293
- }
294
- digestInto(out) {
295
- aoutput(out, this);
296
- if (this.finished)
297
- throw new Error("digest() was already called");
298
- this.writeInto(out);
299
- this.destroy();
300
- return out;
301
- }
302
- digest() {
303
- return this.digestInto(new Uint8Array(this.outputLen));
304
- }
305
- destroy() {
306
- this.destroyed = true;
307
- clean(this.state);
308
- }
309
- _cloneInto(to) {
310
- const { blockLen, suffix, outputLen, rounds, enableXOF } = this;
311
- to || (to = new _Keccak(blockLen, suffix, outputLen, enableXOF, rounds));
312
- to.state32.set(this.state32);
313
- to.pos = this.pos;
314
- to.posOut = this.posOut;
315
- to.finished = this.finished;
316
- to.rounds = rounds;
317
- to.suffix = suffix;
318
- to.outputLen = outputLen;
319
- to.enableXOF = enableXOF;
320
- to.destroyed = this.destroyed;
321
- return to;
322
- }
323
- };
324
- genShake = (suffix, blockLen, outputLen, info = {}) => createHasher((opts = {}) => new Keccak(blockLen, suffix, opts.dkLen === void 0 ? outputLen : opts.dkLen, true), info);
325
- shake128 = /* @__PURE__ */ genShake(31, 168, 16, /* @__PURE__ */ oidNist(11));
326
- shake256 = /* @__PURE__ */ genShake(31, 136, 32, /* @__PURE__ */ oidNist(12));
327
- }
328
- });
329
-
330
- // ../../node_modules/.pnpm/@noble+curves@2.0.1/node_modules/@noble/curves/abstract/fft.js
331
- function checkU32(n) {
332
- if (!Number.isSafeInteger(n) || n < 0 || n > 4294967295)
333
- throw new Error("wrong u32 integer:" + n);
334
- return n;
335
- }
336
- function isPowerOfTwo(x) {
337
- checkU32(x);
338
- return (x & x - 1) === 0 && x !== 0;
339
- }
340
- function reverseBits(n, bits) {
341
- checkU32(n);
342
- let reversed = 0;
343
- for (let i = 0; i < bits; i++, n >>>= 1)
344
- reversed = reversed << 1 | n & 1;
345
- return reversed;
346
- }
347
- function log2(n) {
348
- checkU32(n);
349
- return 31 - Math.clz32(n);
350
- }
351
- function bitReversalInplace(values) {
352
- const n = values.length;
353
- if (n < 2 || !isPowerOfTwo(n))
354
- throw new Error("n must be a power of 2 and greater than 1. Got " + n);
355
- const bits = log2(n);
356
- for (let i = 0; i < n; i++) {
357
- const j = reverseBits(i, bits);
358
- if (i < j) {
359
- const tmp = values[i];
360
- values[i] = values[j];
361
- values[j] = tmp;
362
- }
363
- }
364
- return values;
365
- }
366
- var FFTCore;
367
- var init_fft = __esm({
368
- "../../node_modules/.pnpm/@noble+curves@2.0.1/node_modules/@noble/curves/abstract/fft.js"() {
369
- FFTCore = (F2, coreOpts) => {
370
- const { N: N2, roots, dit, invertButterflies = false, skipStages = 0, brp = true } = coreOpts;
371
- const bits = log2(N2);
372
- if (!isPowerOfTwo(N2))
373
- throw new Error("FFT: Polynomial size should be power of two");
374
- const isDit = dit !== invertButterflies;
375
- return (values) => {
376
- if (values.length !== N2)
377
- throw new Error("FFT: wrong Polynomial length");
378
- if (dit && brp)
379
- bitReversalInplace(values);
380
- for (let i = 0, g = 1; i < bits - skipStages; i++) {
381
- const s = dit ? i + 1 + skipStages : bits - i;
382
- const m = 1 << s;
383
- const m2 = m >> 1;
384
- const stride = N2 >> s;
385
- for (let k = 0; k < N2; k += m) {
386
- for (let j = 0, grp = g++; j < m2; j++) {
387
- const rootPos = invertButterflies ? dit ? N2 - grp : grp : j * stride;
388
- const i0 = k + j;
389
- const i1 = k + j + m2;
390
- const omega = roots[rootPos];
391
- const b = values[i1];
392
- const a = values[i0];
393
- if (isDit) {
394
- const t = F2.mul(b, omega);
395
- values[i0] = F2.add(a, t);
396
- values[i1] = F2.sub(a, t);
397
- } else if (invertButterflies) {
398
- values[i0] = F2.add(b, a);
399
- values[i1] = F2.mul(F2.sub(b, a), omega);
400
- } else {
401
- values[i0] = F2.add(a, b);
402
- values[i1] = F2.mul(F2.sub(a, b), omega);
403
- }
404
- }
405
- }
406
- }
407
- if (!dit && brp)
408
- bitReversalInplace(values);
409
- return values;
410
- };
411
- };
412
- }
413
- });
414
-
415
- // ../../node_modules/.pnpm/@noble+post-quantum@0.6.0/node_modules/@noble/post-quantum/utils.js
416
- function equalBytes(a, b) {
417
- if (a.length !== b.length)
418
- return false;
419
- let diff = 0;
420
- for (let i = 0; i < a.length; i++)
421
- diff |= a[i] ^ b[i];
422
- return diff === 0;
423
- }
424
- function validateOpts(opts) {
425
- if (Object.prototype.toString.call(opts) !== "[object Object]")
426
- throw new TypeError("expected valid options object");
427
- }
428
- function validateVerOpts(opts) {
429
- validateOpts(opts);
430
- if (opts.context !== void 0)
431
- abytes(opts.context, void 0, "opts.context");
432
- }
433
- function validateSigOpts(opts) {
434
- validateVerOpts(opts);
435
- if (opts.extraEntropy !== false && opts.extraEntropy !== void 0)
436
- abytes(opts.extraEntropy, void 0, "opts.extraEntropy");
437
- }
438
- function splitCoder(label, ...lengths) {
439
- const getLength = (c) => typeof c === "number" ? c : c.bytesLen;
440
- const bytesLen = lengths.reduce((sum, a) => sum + getLength(a), 0);
441
- return {
442
- bytesLen,
443
- encode: (bufs) => {
444
- const res = new Uint8Array(bytesLen);
445
- for (let i = 0, pos = 0; i < lengths.length; i++) {
446
- const c = lengths[i];
447
- const l = getLength(c);
448
- const b = typeof c === "number" ? bufs[i] : c.encode(bufs[i]);
449
- abytes(b, l, label);
450
- res.set(b, pos);
451
- if (typeof c !== "number")
452
- b.fill(0);
453
- pos += l;
454
- }
455
- return res;
456
- },
457
- decode: (buf) => {
458
- abytes(buf, bytesLen, label);
459
- const res = [];
460
- for (const c of lengths) {
461
- const l = getLength(c);
462
- const b = buf.subarray(0, l);
463
- res.push(typeof c === "number" ? b : c.decode(b));
464
- buf = buf.subarray(l);
465
- }
466
- return res;
467
- }
468
- };
469
- }
470
- function vecCoder(c, vecLen) {
471
- const bytesLen = vecLen * c.bytesLen;
472
- return {
473
- bytesLen,
474
- encode: (u) => {
475
- if (u.length !== vecLen)
476
- throw new RangeError(`vecCoder.encode: wrong length=${u.length}. Expected: ${vecLen}`);
477
- const res = new Uint8Array(bytesLen);
478
- for (let i = 0, pos = 0; i < u.length; i++) {
479
- const b = c.encode(u[i]);
480
- res.set(b, pos);
481
- b.fill(0);
482
- pos += b.length;
483
- }
484
- return res;
485
- },
486
- decode: (a) => {
487
- abytes(a, bytesLen);
488
- const r = [];
489
- for (let i = 0; i < a.length; i += c.bytesLen)
490
- r.push(c.decode(a.subarray(i, i + c.bytesLen)));
491
- return r;
492
- }
493
- };
494
- }
495
- function cleanBytes(...list) {
496
- for (const t of list) {
497
- if (Array.isArray(t))
498
- for (const b of t)
499
- b.fill(0);
500
- else
501
- t.fill(0);
502
- }
503
- }
504
- function getMask(bits) {
505
- if (!Number.isSafeInteger(bits) || bits < 0 || bits > 32)
506
- throw new RangeError(`expected bits in [0..32], got ${bits}`);
507
- return bits === 32 ? 4294967295 : ~(-1 << bits) >>> 0;
508
- }
509
- function getMessage(msg, ctx = EMPTY) {
510
- abytes(msg);
511
- abytes(ctx);
512
- if (ctx.length > 255)
513
- throw new RangeError("context should be 255 bytes or less");
514
- return concatBytes(new Uint8Array([0, ctx.length]), ctx, msg);
515
- }
516
- function checkHash(hash, requiredStrength = 0) {
517
- if (!hash.oid || !equalBytes(hash.oid.subarray(0, 10), oidNistP))
518
- throw new Error("hash.oid is invalid: expected NIST hash");
519
- const collisionResistance = hash.outputLen * 8 / 2;
520
- if (requiredStrength > collisionResistance) {
521
- throw new Error("Pre-hash security strength too low: " + collisionResistance + ", required: " + requiredStrength);
522
- }
523
- }
524
- function getMessagePrehash(hash, msg, ctx = EMPTY) {
525
- abytes(msg);
526
- abytes(ctx);
527
- if (ctx.length > 255)
528
- throw new RangeError("context should be 255 bytes or less");
529
- const hashed = hash(msg);
530
- return concatBytes(new Uint8Array([1, ctx.length]), ctx, hash.oid, hashed);
531
- }
532
- var abytesDoc, randomBytes2, EMPTY, oidNistP;
533
- var init_utils3 = __esm({
534
- "../../node_modules/.pnpm/@noble+post-quantum@0.6.0/node_modules/@noble/post-quantum/utils.js"() {
535
- init_utils();
536
- abytesDoc = abytes;
537
- randomBytes2 = randomBytes;
538
- EMPTY = /* @__PURE__ */ Uint8Array.of();
539
- oidNistP = /* @__PURE__ */ Uint8Array.from([6, 9, 96, 134, 72, 1, 101, 3, 4, 2]);
540
- }
541
- });
542
-
543
- // ../../node_modules/.pnpm/@noble+post-quantum@0.6.0/node_modules/@noble/post-quantum/_crystals.js
544
- var genCrystals, createXofShake, XOF128, XOF256;
545
- var init_crystals = __esm({
546
- "../../node_modules/.pnpm/@noble+post-quantum@0.6.0/node_modules/@noble/post-quantum/_crystals.js"() {
547
- init_fft();
548
- init_sha3();
549
- init_utils3();
550
- genCrystals = (opts) => {
551
- const { newPoly: newPoly2, N: N2, Q: Q2, F: F2, ROOT_OF_UNITY: ROOT_OF_UNITY2, brvBits, isKyber } = opts;
552
- const mod = (a, modulo = Q2) => {
553
- const result = a % modulo | 0;
554
- return (result >= 0 ? result | 0 : modulo + result | 0) | 0;
555
- };
556
- const smod = (a, modulo = Q2) => {
557
- const r = mod(a, modulo) | 0;
558
- return (r > modulo >> 1 ? r - modulo | 0 : r) | 0;
559
- };
560
- function getZettas() {
561
- const out = newPoly2(N2);
562
- for (let i = 0; i < N2; i++) {
563
- const b = reverseBits(i, brvBits);
564
- const p = BigInt(ROOT_OF_UNITY2) ** BigInt(b) % BigInt(Q2);
565
- out[i] = Number(p) | 0;
566
- }
567
- return out;
568
- }
569
- const nttZetas = getZettas();
570
- const field = {
571
- add: (a, b) => mod((a | 0) + (b | 0)) | 0,
572
- sub: (a, b) => mod((a | 0) - (b | 0)) | 0,
573
- mul: (a, b) => mod((a | 0) * (b | 0)) | 0,
574
- inv: (_a) => {
575
- throw new Error("not implemented");
576
- }
577
- };
578
- const nttOpts = {
579
- N: N2,
580
- roots: nttZetas,
581
- invertButterflies: true,
582
- skipStages: isKyber ? 1 : 0,
583
- brp: false
584
- };
585
- const dif = FFTCore(field, { dit: false, ...nttOpts });
586
- const dit = FFTCore(field, { dit: true, ...nttOpts });
587
- const NTT = {
588
- encode: (r) => {
589
- return dif(r);
590
- },
591
- decode: (r) => {
592
- dit(r);
593
- for (let i = 0; i < r.length; i++)
594
- r[i] = mod(F2 * r[i]);
595
- return r;
596
- }
597
- };
598
- const bitsCoder = (d, c) => {
599
- const mask = getMask(d);
600
- const bytesLen = d * (N2 / 8);
601
- return {
602
- bytesLen,
603
- encode: (poly) => {
604
- const r = new Uint8Array(bytesLen);
605
- for (let i = 0, buf = 0, bufLen = 0, pos = 0; i < poly.length; i++) {
606
- buf |= (c.encode(poly[i]) & mask) << bufLen;
607
- bufLen += d;
608
- for (; bufLen >= 8; bufLen -= 8, buf >>= 8)
609
- r[pos++] = buf & getMask(bufLen);
610
- }
611
- return r;
612
- },
613
- decode: (bytes) => {
614
- const r = newPoly2(N2);
615
- for (let i = 0, buf = 0, bufLen = 0, pos = 0; i < bytes.length; i++) {
616
- buf |= bytes[i] << bufLen;
617
- bufLen += 8;
618
- for (; bufLen >= d; bufLen -= d, buf >>= d)
619
- r[pos++] = c.decode(buf & mask);
620
- }
621
- return r;
622
- }
623
- };
624
- };
625
- return { mod, smod, nttZetas, NTT, bitsCoder };
626
- };
627
- createXofShake = (shake) => (seed, blockLen) => {
628
- if (!blockLen)
629
- blockLen = shake.blockLen;
630
- const _seed = new Uint8Array(seed.length + 2);
631
- _seed.set(seed);
632
- const seedLen = seed.length;
633
- const buf = new Uint8Array(blockLen);
634
- let h = shake.create({});
635
- let calls = 0;
636
- let xofs = 0;
637
- return {
638
- stats: () => ({ calls, xofs }),
639
- get: (x, y) => {
640
- _seed[seedLen + 0] = x;
641
- _seed[seedLen + 1] = y;
642
- h.destroy();
643
- h = shake.create({}).update(_seed);
644
- calls++;
645
- return () => {
646
- xofs++;
647
- return h.xofInto(buf);
648
- };
649
- },
650
- clean: () => {
651
- h.destroy();
652
- cleanBytes(buf, _seed);
653
- }
654
- };
655
- };
656
- XOF128 = /* @__PURE__ */ createXofShake(shake128);
657
- XOF256 = /* @__PURE__ */ createXofShake(shake256);
658
- }
659
- });
660
-
661
- // ../../node_modules/.pnpm/@noble+post-quantum@0.6.0/node_modules/@noble/post-quantum/ml-dsa.js
662
- function validateInternalOpts(opts) {
663
- validateOpts(opts);
664
- if (opts.externalMu !== void 0)
665
- abool(opts.externalMu, "opts.externalMu");
666
- }
667
- function RejNTTPoly(xof) {
668
- const r = newPoly(N);
669
- for (let j = 0; j < N; ) {
670
- const b = xof();
671
- if (b.length % 3)
672
- throw new Error("RejNTTPoly: unaligned block");
673
- for (let i = 0; j < N && i <= b.length - 3; i += 3) {
674
- const t = (b[i + 0] | b[i + 1] << 8 | b[i + 2] << 16) & 8388607;
675
- if (t < Q)
676
- r[j++] = t;
677
- }
678
- }
679
- return r;
680
- }
681
- function getDilithium(opts) {
682
- const { K, L, GAMMA1, GAMMA2, TAU, ETA, OMEGA } = opts;
683
- const { CRH_BYTES, TR_BYTES, C_TILDE_BYTES, XOF128: XOF1282, XOF256: XOF2562, securityLevel } = opts;
684
- if (![2, 4].includes(ETA))
685
- throw new Error("Wrong ETA");
686
- if (![1 << 17, 1 << 19].includes(GAMMA1))
687
- throw new Error("Wrong GAMMA1");
688
- if (![GAMMA2_1, GAMMA2_2].includes(GAMMA2))
689
- throw new Error("Wrong GAMMA2");
690
- const BETA = TAU * ETA;
691
- const decompose = (r) => {
692
- const rPlus = crystals.mod(r);
693
- const r0 = crystals.smod(rPlus, 2 * GAMMA2) | 0;
694
- if (rPlus - r0 === Q - 1)
695
- return { r1: 0 | 0, r0: r0 - 1 | 0 };
696
- const r1 = Math.floor((rPlus - r0) / (2 * GAMMA2)) | 0;
697
- return { r1, r0 };
698
- };
699
- const HighBits = (r) => decompose(r).r1;
700
- const LowBits = (r) => decompose(r).r0;
701
- const MakeHint = (z, r) => {
702
- const res0 = z <= GAMMA2 || z > Q - GAMMA2 || z === Q - GAMMA2 && r === 0 ? 0 : 1;
703
- return res0;
704
- };
705
- const UseHint = (h, r) => {
706
- const m = Math.floor((Q - 1) / (2 * GAMMA2));
707
- const { r1, r0 } = decompose(r);
708
- if (h === 1)
709
- return r0 > 0 ? crystals.mod(r1 + 1, m) | 0 : crystals.mod(r1 - 1, m) | 0;
710
- return r1 | 0;
711
- };
712
- const Power2Round = (r) => {
713
- const rPlus = crystals.mod(r);
714
- const r0 = crystals.smod(rPlus, 2 ** D) | 0;
715
- return { r1: Math.floor((rPlus - r0) / 2 ** D) | 0, r0 };
716
- };
717
- const hintCoder = {
718
- bytesLen: OMEGA + K,
719
- encode: (h) => {
720
- if (h === false)
721
- throw new Error("hint.encode: hint is false");
722
- const res = new Uint8Array(OMEGA + K);
723
- for (let i = 0, k = 0; i < K; i++) {
724
- for (let j = 0; j < N; j++)
725
- if (h[i][j] !== 0)
726
- res[k++] = j;
727
- res[OMEGA + i] = k;
728
- }
729
- return res;
730
- },
731
- decode: (buf) => {
732
- const h = [];
733
- let k = 0;
734
- for (let i = 0; i < K; i++) {
735
- const hi = newPoly(N);
736
- if (buf[OMEGA + i] < k || buf[OMEGA + i] > OMEGA)
737
- return false;
738
- for (let j = k; j < buf[OMEGA + i]; j++) {
739
- if (j > k && buf[j] <= buf[j - 1])
740
- return false;
741
- hi[buf[j]] = 1;
742
- }
743
- k = buf[OMEGA + i];
744
- h.push(hi);
745
- }
746
- for (let j = k; j < OMEGA; j++)
747
- if (buf[j] !== 0)
748
- return false;
749
- return h;
750
- }
751
- };
752
- const ETACoder = polyCoder(ETA === 2 ? 3 : 4, (i) => ETA - i, (i) => {
753
- if (!(-ETA <= i && i <= ETA))
754
- throw new Error(`malformed key s1/s3 ${i} outside of ETA range [${-ETA}, ${ETA}]`);
755
- return i;
756
- });
757
- const T0Coder = polyCoder(13, (i) => (1 << D - 1) - i);
758
- const T1Coder = polyCoder(10);
759
- const ZCoder = polyCoder(GAMMA1 === 1 << 17 ? 18 : 20, (i) => crystals.smod(GAMMA1 - i));
760
- const W1Coder = polyCoder(GAMMA2 === GAMMA2_1 ? 6 : 4);
761
- const W1Vec = vecCoder(W1Coder, K);
762
- const publicCoder = splitCoder("publicKey", 32, vecCoder(T1Coder, K));
763
- const secretCoder = splitCoder("secretKey", 32, 32, TR_BYTES, vecCoder(ETACoder, L), vecCoder(ETACoder, K), vecCoder(T0Coder, K));
764
- const sigCoder = splitCoder("signature", C_TILDE_BYTES, vecCoder(ZCoder, L), hintCoder);
765
- const CoefFromHalfByte = ETA === 2 ? (n) => n < 15 ? 2 - n % 5 : false : (n) => n < 9 ? 4 - n : false;
766
- function RejBoundedPoly(xof) {
767
- const r = newPoly(N);
768
- for (let j = 0; j < N; ) {
769
- const b = xof();
770
- for (let i = 0; j < N && i < b.length; i += 1) {
771
- const d1 = CoefFromHalfByte(b[i] & 15);
772
- const d2 = CoefFromHalfByte(b[i] >> 4 & 15);
773
- if (d1 !== false)
774
- r[j++] = d1;
775
- if (j < N && d2 !== false)
776
- r[j++] = d2;
777
- }
778
- }
779
- return r;
780
- }
781
- const SampleInBall = (seed) => {
782
- const pre = newPoly(N);
783
- const s = shake256.create({}).update(seed);
784
- const buf = new Uint8Array(shake256.blockLen);
785
- s.xofInto(buf);
786
- const masks = buf.slice(0, 8);
787
- for (let i = N - TAU, pos = 8, maskPos = 0, maskBit = 0; i < N; i++) {
788
- let b = i + 1;
789
- for (; b > i; ) {
790
- b = buf[pos++];
791
- if (pos < shake256.blockLen)
792
- continue;
793
- s.xofInto(buf);
794
- pos = 0;
795
- }
796
- pre[i] = pre[b];
797
- pre[b] = 1 - ((masks[maskPos] >> maskBit++ & 1) << 1);
798
- if (maskBit >= 8) {
799
- maskPos++;
800
- maskBit = 0;
801
- }
802
- }
803
- return pre;
804
- };
805
- const polyPowerRound = (p) => {
806
- const res0 = newPoly(N);
807
- const res1 = newPoly(N);
808
- for (let i = 0; i < p.length; i++) {
809
- const { r0, r1 } = Power2Round(p[i]);
810
- res0[i] = r0;
811
- res1[i] = r1;
812
- }
813
- return { r0: res0, r1: res1 };
814
- };
815
- const polyUseHint = (u, h) => {
816
- for (let i = 0; i < N; i++)
817
- u[i] = UseHint(h[i], u[i]);
818
- return u;
819
- };
820
- const polyMakeHint = (a, b) => {
821
- const v = newPoly(N);
822
- let cnt = 0;
823
- for (let i = 0; i < N; i++) {
824
- const h = MakeHint(a[i], b[i]);
825
- v[i] = h;
826
- cnt += h;
827
- }
828
- return { v, cnt };
829
- };
830
- const signRandBytes = 32;
831
- const seedCoder = splitCoder("seed", 32, 64, 32);
832
- const internal = {
833
- info: { type: "internal-ml-dsa" },
834
- lengths: {
835
- secretKey: secretCoder.bytesLen,
836
- publicKey: publicCoder.bytesLen,
837
- seed: 32,
838
- signature: sigCoder.bytesLen,
839
- signRand: signRandBytes
840
- },
841
- keygen: (seed) => {
842
- const seedDst = new Uint8Array(32 + 2);
843
- const randSeed = seed === void 0;
844
- if (randSeed)
845
- seed = randomBytes2(32);
846
- abytesDoc(seed, 32, "seed");
847
- seedDst.set(seed);
848
- if (randSeed)
849
- cleanBytes(seed);
850
- seedDst[32] = K;
851
- seedDst[33] = L;
852
- const [rho, rhoPrime, K_] = seedCoder.decode(shake256(seedDst, { dkLen: seedCoder.bytesLen }));
853
- const xofPrime = XOF2562(rhoPrime);
854
- const s1 = [];
855
- for (let i = 0; i < L; i++)
856
- s1.push(RejBoundedPoly(xofPrime.get(i & 255, i >> 8 & 255)));
857
- const s2 = [];
858
- for (let i = L; i < L + K; i++)
859
- s2.push(RejBoundedPoly(xofPrime.get(i & 255, i >> 8 & 255)));
860
- const s1Hat = s1.map((i) => crystals.NTT.encode(i.slice()));
861
- const t0 = [];
862
- const t1 = [];
863
- const xof = XOF1282(rho);
864
- const t = newPoly(N);
865
- for (let i = 0; i < K; i++) {
866
- cleanBytes(t);
867
- for (let j = 0; j < L; j++) {
868
- const aij = RejNTTPoly(xof.get(j, i));
869
- polyAdd(t, MultiplyNTTs(aij, s1Hat[j]));
870
- }
871
- crystals.NTT.decode(t);
872
- const { r0, r1 } = polyPowerRound(polyAdd(t, s2[i]));
873
- t0.push(r0);
874
- t1.push(r1);
875
- }
876
- const publicKey = publicCoder.encode([rho, t1]);
877
- const tr = shake256(publicKey, { dkLen: TR_BYTES });
878
- const secretKey = secretCoder.encode([rho, K_, tr, s1, s2, t0]);
879
- xof.clean();
880
- xofPrime.clean();
881
- cleanBytes(rho, rhoPrime, K_, s1, s2, s1Hat, t, t0, t1, tr, seedDst);
882
- return { publicKey, secretKey };
883
- },
884
- getPublicKey: (secretKey) => {
885
- const [rho, _K, _tr, s1, s2, _t0] = secretCoder.decode(secretKey);
886
- const xof = XOF1282(rho);
887
- const s1Hat = s1.map((p) => crystals.NTT.encode(p.slice()));
888
- const t1 = [];
889
- const tmp = newPoly(N);
890
- for (let i = 0; i < K; i++) {
891
- tmp.fill(0);
892
- for (let j = 0; j < L; j++) {
893
- const aij = RejNTTPoly(xof.get(j, i));
894
- polyAdd(tmp, MultiplyNTTs(aij, s1Hat[j]));
895
- }
896
- crystals.NTT.decode(tmp);
897
- polyAdd(tmp, s2[i]);
898
- const { r1 } = polyPowerRound(tmp);
899
- t1.push(r1);
900
- }
901
- xof.clean();
902
- cleanBytes(tmp, s1Hat, _t0, s1, s2);
903
- return publicCoder.encode([rho, t1]);
904
- },
905
- // NOTE: random is optional.
906
- sign: (msg, secretKey, opts2 = {}) => {
907
- validateSigOpts(opts2);
908
- validateInternalOpts(opts2);
909
- let { extraEntropy: random, externalMu = false } = opts2;
910
- const [rho, _K, tr, s1, s2, t0] = secretCoder.decode(secretKey);
911
- const A = [];
912
- const xof = XOF1282(rho);
913
- for (let i = 0; i < K; i++) {
914
- const pv = [];
915
- for (let j = 0; j < L; j++)
916
- pv.push(RejNTTPoly(xof.get(j, i)));
917
- A.push(pv);
918
- }
919
- xof.clean();
920
- for (let i = 0; i < L; i++)
921
- crystals.NTT.encode(s1[i]);
922
- for (let i = 0; i < K; i++) {
923
- crystals.NTT.encode(s2[i]);
924
- crystals.NTT.encode(t0[i]);
925
- }
926
- const mu = externalMu ? msg : (
927
- // 6: µ ← H(tr||M, 512)
928
- // ▷ Compute message representative µ
929
- shake256.create({ dkLen: CRH_BYTES }).update(tr).update(msg).digest()
930
- );
931
- const rnd = random === false ? new Uint8Array(32) : random === void 0 ? randomBytes2(signRandBytes) : random;
932
- abytesDoc(rnd, 32, "extraEntropy");
933
- const rhoprime = shake256.create({ dkLen: CRH_BYTES }).update(_K).update(rnd).update(mu).digest();
934
- abytesDoc(rhoprime, CRH_BYTES);
935
- const x256 = XOF2562(rhoprime, ZCoder.bytesLen);
936
- main_loop: for (let kappa = 0; ; ) {
937
- const y = [];
938
- for (let i = 0; i < L; i++, kappa++)
939
- y.push(ZCoder.decode(x256.get(kappa & 255, kappa >> 8)()));
940
- const z = y.map((i) => crystals.NTT.encode(i.slice()));
941
- const w = [];
942
- for (let i = 0; i < K; i++) {
943
- const wi = newPoly(N);
944
- for (let j = 0; j < L; j++)
945
- polyAdd(wi, MultiplyNTTs(A[i][j], z[j]));
946
- crystals.NTT.decode(wi);
947
- w.push(wi);
948
- }
949
- const w1 = w.map((j) => j.map(HighBits));
950
- const cTilde = shake256.create({ dkLen: C_TILDE_BYTES }).update(mu).update(W1Vec.encode(w1)).digest();
951
- const cHat = crystals.NTT.encode(SampleInBall(cTilde));
952
- const cs1 = s1.map((i) => MultiplyNTTs(i, cHat));
953
- for (let i = 0; i < L; i++) {
954
- polyAdd(crystals.NTT.decode(cs1[i]), y[i]);
955
- if (polyChknorm(cs1[i], GAMMA1 - BETA))
956
- continue main_loop;
957
- }
958
- let cnt = 0;
959
- const h = [];
960
- for (let i = 0; i < K; i++) {
961
- const cs2 = crystals.NTT.decode(MultiplyNTTs(s2[i], cHat));
962
- const r0 = polySub(w[i], cs2).map(LowBits);
963
- if (polyChknorm(r0, GAMMA2 - BETA))
964
- continue main_loop;
965
- const ct0 = crystals.NTT.decode(MultiplyNTTs(t0[i], cHat));
966
- if (polyChknorm(ct0, GAMMA2))
967
- continue main_loop;
968
- polyAdd(r0, ct0);
969
- const hint = polyMakeHint(r0, w1[i]);
970
- h.push(hint.v);
971
- cnt += hint.cnt;
972
- }
973
- if (cnt > OMEGA)
974
- continue;
975
- x256.clean();
976
- const res = sigCoder.encode([cTilde, cs1, h]);
977
- cleanBytes(cTilde, cs1, h, cHat, w1, w, z, y, rhoprime, s1, s2, t0, ...A);
978
- if (!externalMu)
979
- cleanBytes(mu);
980
- return res;
981
- }
982
- throw new Error("Unreachable code path reached, report this error");
983
- },
984
- verify: (sig, msg, publicKey, opts2 = {}) => {
985
- validateInternalOpts(opts2);
986
- const { externalMu = false } = opts2;
987
- const [rho, t1] = publicCoder.decode(publicKey);
988
- const tr = shake256(publicKey, { dkLen: TR_BYTES });
989
- if (sig.length !== sigCoder.bytesLen)
990
- return false;
991
- const [cTilde, z, h] = sigCoder.decode(sig);
992
- if (h === false)
993
- return false;
994
- for (let i = 0; i < L; i++)
995
- if (polyChknorm(z[i], GAMMA1 - BETA))
996
- return false;
997
- const mu = externalMu ? msg : (
998
- // 7: µ ← H(tr||M, 512)
999
- shake256.create({ dkLen: CRH_BYTES }).update(tr).update(msg).digest()
1000
- );
1001
- const c = crystals.NTT.encode(SampleInBall(cTilde));
1002
- const zNtt = z.map((i) => i.slice());
1003
- for (let i = 0; i < L; i++)
1004
- crystals.NTT.encode(zNtt[i]);
1005
- const wTick1 = [];
1006
- const xof = XOF1282(rho);
1007
- for (let i = 0; i < K; i++) {
1008
- const ct12d = MultiplyNTTs(crystals.NTT.encode(polyShiftl(t1[i])), c);
1009
- const Az = newPoly(N);
1010
- for (let j = 0; j < L; j++) {
1011
- const aij = RejNTTPoly(xof.get(j, i));
1012
- polyAdd(Az, MultiplyNTTs(aij, zNtt[j]));
1013
- }
1014
- const wApprox = crystals.NTT.decode(polySub(Az, ct12d));
1015
- wTick1.push(polyUseHint(wApprox, h[i]));
1016
- }
1017
- xof.clean();
1018
- const c2 = shake256.create({ dkLen: C_TILDE_BYTES }).update(mu).update(W1Vec.encode(wTick1)).digest();
1019
- for (const t of h) {
1020
- const sum = t.reduce((acc, i) => acc + i, 0);
1021
- if (!(sum <= OMEGA))
1022
- return false;
1023
- }
1024
- for (const t of z)
1025
- if (polyChknorm(t, GAMMA1 - BETA))
1026
- return false;
1027
- return equalBytes(cTilde, c2);
1028
- }
1029
- };
1030
- return {
1031
- info: { type: "ml-dsa" },
1032
- internal,
1033
- securityLevel,
1034
- keygen: internal.keygen,
1035
- lengths: internal.lengths,
1036
- getPublicKey: internal.getPublicKey,
1037
- sign: (msg, secretKey, opts2 = {}) => {
1038
- validateSigOpts(opts2);
1039
- const M = getMessage(msg, opts2.context);
1040
- const res = internal.sign(M, secretKey, opts2);
1041
- cleanBytes(M);
1042
- return res;
1043
- },
1044
- verify: (sig, msg, publicKey, opts2 = {}) => {
1045
- validateVerOpts(opts2);
1046
- return internal.verify(sig, getMessage(msg, opts2.context), publicKey);
1047
- },
1048
- prehash: (hash) => {
1049
- checkHash(hash, securityLevel);
1050
- return {
1051
- info: { type: "hashml-dsa" },
1052
- securityLevel,
1053
- lengths: internal.lengths,
1054
- keygen: internal.keygen,
1055
- getPublicKey: internal.getPublicKey,
1056
- sign: (msg, secretKey, opts2 = {}) => {
1057
- validateSigOpts(opts2);
1058
- const M = getMessagePrehash(hash, msg, opts2.context);
1059
- const res = internal.sign(M, secretKey, opts2);
1060
- cleanBytes(M);
1061
- return res;
1062
- },
1063
- verify: (sig, msg, publicKey, opts2 = {}) => {
1064
- validateVerOpts(opts2);
1065
- return internal.verify(sig, getMessagePrehash(hash, msg, opts2.context), publicKey);
1066
- }
1067
- };
1068
- }
1069
- };
1070
- }
1071
- var N, Q, ROOT_OF_UNITY, F, D, GAMMA2_1, GAMMA2_2, PARAMS, newPoly, crystals, id, polyCoder, polyAdd, polySub, polyShiftl, polyChknorm, MultiplyNTTs, ml_dsa44, ml_dsa65, ml_dsa87;
1072
- var init_ml_dsa = __esm({
1073
- "../../node_modules/.pnpm/@noble+post-quantum@0.6.0/node_modules/@noble/post-quantum/ml-dsa.js"() {
1074
- init_utils2();
1075
- init_sha3();
1076
- init_crystals();
1077
- init_utils3();
1078
- N = 256;
1079
- Q = 8380417;
1080
- ROOT_OF_UNITY = 1753;
1081
- F = 8347681;
1082
- D = 13;
1083
- GAMMA2_1 = Math.floor((Q - 1) / 88) | 0;
1084
- GAMMA2_2 = Math.floor((Q - 1) / 32) | 0;
1085
- PARAMS = /* @__PURE__ */ (() => ({
1086
- 2: { K: 4, L: 4, D, GAMMA1: 2 ** 17, GAMMA2: GAMMA2_1, TAU: 39, ETA: 2, OMEGA: 80 },
1087
- 3: { K: 6, L: 5, D, GAMMA1: 2 ** 19, GAMMA2: GAMMA2_2, TAU: 49, ETA: 4, OMEGA: 55 },
1088
- 5: { K: 8, L: 7, D, GAMMA1: 2 ** 19, GAMMA2: GAMMA2_2, TAU: 60, ETA: 2, OMEGA: 75 }
1089
- }))();
1090
- newPoly = (n) => new Int32Array(n);
1091
- crystals = /* @__PURE__ */ genCrystals({
1092
- N,
1093
- Q,
1094
- F,
1095
- ROOT_OF_UNITY,
1096
- newPoly,
1097
- isKyber: false,
1098
- brvBits: 8
1099
- });
1100
- id = (n) => n;
1101
- polyCoder = (d, compress = id, verify = id) => crystals.bitsCoder(d, {
1102
- encode: (i) => compress(verify(i)),
1103
- decode: (i) => verify(compress(i))
1104
- });
1105
- polyAdd = (a, b) => {
1106
- for (let i = 0; i < a.length; i++)
1107
- a[i] = crystals.mod(a[i] + b[i]);
1108
- return a;
1109
- };
1110
- polySub = (a, b) => {
1111
- for (let i = 0; i < a.length; i++)
1112
- a[i] = crystals.mod(a[i] - b[i]);
1113
- return a;
1114
- };
1115
- polyShiftl = (p) => {
1116
- for (let i = 0; i < N; i++)
1117
- p[i] <<= D;
1118
- return p;
1119
- };
1120
- polyChknorm = (p, B) => {
1121
- for (let i = 0; i < N; i++)
1122
- if (Math.abs(crystals.smod(p[i])) >= B)
1123
- return true;
1124
- return false;
1125
- };
1126
- MultiplyNTTs = (a, b) => {
1127
- const c = newPoly(N);
1128
- for (let i = 0; i < a.length; i++)
1129
- c[i] = crystals.mod(a[i] * b[i]);
1130
- return c;
1131
- };
1132
- ml_dsa44 = /* @__PURE__ */ (() => getDilithium({
1133
- ...PARAMS[2],
1134
- CRH_BYTES: 64,
1135
- TR_BYTES: 64,
1136
- C_TILDE_BYTES: 32,
1137
- XOF128,
1138
- XOF256,
1139
- securityLevel: 128
1140
- }))();
1141
- ml_dsa65 = /* @__PURE__ */ (() => getDilithium({
1142
- ...PARAMS[3],
1143
- CRH_BYTES: 64,
1144
- TR_BYTES: 64,
1145
- C_TILDE_BYTES: 48,
1146
- XOF128,
1147
- XOF256,
1148
- securityLevel: 192
1149
- }))();
1150
- ml_dsa87 = /* @__PURE__ */ (() => getDilithium({
1151
- ...PARAMS[5],
1152
- CRH_BYTES: 64,
1153
- TR_BYTES: 64,
1154
- C_TILDE_BYTES: 64,
1155
- XOF128,
1156
- XOF256,
1157
- securityLevel: 256
1158
- }))();
1159
- }
1160
- });
1161
- init_ml_dsa();
1162
- /*! Bundled license information:
1163
-
1164
- @noble/hashes/utils.js:
1165
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
1166
-
1167
- @noble/curves/utils.js:
1168
- (*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
1169
-
1170
- @noble/post-quantum/utils.js:
1171
- @noble/post-quantum/_crystals.js:
1172
- @noble/post-quantum/ml-dsa.js:
1173
- (*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) *)
1174
- */
1175
-
1176
- export { PARAMS, ml_dsa44, ml_dsa65, ml_dsa87 };
1177
- //# sourceMappingURL=ml-dsa-WYLJHJO6.js.map
1178
- //# sourceMappingURL=ml-dsa-WYLJHJO6.js.map