@oqs/liboqs-js 0.15.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 (317) hide show
  1. package/LICENSE.md +50 -0
  2. package/README.md +829 -0
  3. package/bin/cli.js +16 -0
  4. package/dist/classic-mceliece-348864.deno.js +0 -0
  5. package/dist/classic-mceliece-348864.min.js +0 -0
  6. package/dist/classic-mceliece-348864f.deno.js +0 -0
  7. package/dist/classic-mceliece-348864f.min.js +0 -0
  8. package/dist/classic-mceliece-460896.deno.js +0 -0
  9. package/dist/classic-mceliece-460896.min.js +0 -0
  10. package/dist/classic-mceliece-460896f.deno.js +0 -0
  11. package/dist/classic-mceliece-460896f.min.js +0 -0
  12. package/dist/classic-mceliece-6688128.deno.js +0 -0
  13. package/dist/classic-mceliece-6688128.min.js +0 -0
  14. package/dist/classic-mceliece-6688128f.deno.js +0 -0
  15. package/dist/classic-mceliece-6688128f.min.js +0 -0
  16. package/dist/classic-mceliece-6960119.deno.js +0 -0
  17. package/dist/classic-mceliece-6960119.min.js +0 -0
  18. package/dist/classic-mceliece-6960119f.deno.js +0 -0
  19. package/dist/classic-mceliece-6960119f.min.js +0 -0
  20. package/dist/classic-mceliece-8192128.deno.js +0 -0
  21. package/dist/classic-mceliece-8192128.min.js +0 -0
  22. package/dist/classic-mceliece-8192128f.deno.js +0 -0
  23. package/dist/classic-mceliece-8192128f.min.js +0 -0
  24. package/dist/cross-rsdp-128-balanced.deno.js +0 -0
  25. package/dist/cross-rsdp-128-balanced.min.js +0 -0
  26. package/dist/cross-rsdp-128-fast.deno.js +0 -0
  27. package/dist/cross-rsdp-128-fast.min.js +0 -0
  28. package/dist/cross-rsdp-128-small.deno.js +0 -0
  29. package/dist/cross-rsdp-128-small.min.js +0 -0
  30. package/dist/cross-rsdp-192-balanced.deno.js +0 -0
  31. package/dist/cross-rsdp-192-balanced.min.js +0 -0
  32. package/dist/cross-rsdp-192-fast.deno.js +0 -0
  33. package/dist/cross-rsdp-192-fast.min.js +0 -0
  34. package/dist/cross-rsdp-192-small.deno.js +0 -0
  35. package/dist/cross-rsdp-192-small.min.js +0 -0
  36. package/dist/cross-rsdp-256-balanced.deno.js +0 -0
  37. package/dist/cross-rsdp-256-balanced.min.js +0 -0
  38. package/dist/cross-rsdp-256-fast.deno.js +0 -0
  39. package/dist/cross-rsdp-256-fast.min.js +0 -0
  40. package/dist/cross-rsdp-256-small.deno.js +0 -0
  41. package/dist/cross-rsdp-256-small.min.js +0 -0
  42. package/dist/cross-rsdpg-128-balanced.deno.js +0 -0
  43. package/dist/cross-rsdpg-128-balanced.min.js +0 -0
  44. package/dist/cross-rsdpg-128-fast.deno.js +0 -0
  45. package/dist/cross-rsdpg-128-fast.min.js +0 -0
  46. package/dist/cross-rsdpg-128-small.deno.js +0 -0
  47. package/dist/cross-rsdpg-128-small.min.js +0 -0
  48. package/dist/cross-rsdpg-192-balanced.deno.js +0 -0
  49. package/dist/cross-rsdpg-192-balanced.min.js +0 -0
  50. package/dist/cross-rsdpg-192-fast.deno.js +0 -0
  51. package/dist/cross-rsdpg-192-fast.min.js +0 -0
  52. package/dist/cross-rsdpg-192-small.deno.js +0 -0
  53. package/dist/cross-rsdpg-192-small.min.js +0 -0
  54. package/dist/cross-rsdpg-256-balanced.deno.js +0 -0
  55. package/dist/cross-rsdpg-256-balanced.min.js +0 -0
  56. package/dist/cross-rsdpg-256-fast.deno.js +0 -0
  57. package/dist/cross-rsdpg-256-fast.min.js +0 -0
  58. package/dist/cross-rsdpg-256-small.deno.js +0 -0
  59. package/dist/cross-rsdpg-256-small.min.js +0 -0
  60. package/dist/falcon-1024.deno.js +0 -0
  61. package/dist/falcon-1024.min.js +0 -0
  62. package/dist/falcon-512.deno.js +0 -0
  63. package/dist/falcon-512.min.js +0 -0
  64. package/dist/falcon-padded-1024.deno.js +0 -0
  65. package/dist/falcon-padded-1024.min.js +0 -0
  66. package/dist/falcon-padded-512.deno.js +0 -0
  67. package/dist/falcon-padded-512.min.js +0 -0
  68. package/dist/frodokem-1344-aes.deno.js +0 -0
  69. package/dist/frodokem-1344-aes.min.js +0 -0
  70. package/dist/frodokem-1344-shake.deno.js +0 -0
  71. package/dist/frodokem-1344-shake.min.js +0 -0
  72. package/dist/frodokem-640-aes.deno.js +0 -0
  73. package/dist/frodokem-640-aes.min.js +0 -0
  74. package/dist/frodokem-640-shake.deno.js +0 -0
  75. package/dist/frodokem-640-shake.min.js +0 -0
  76. package/dist/frodokem-976-aes.deno.js +0 -0
  77. package/dist/frodokem-976-aes.min.js +0 -0
  78. package/dist/frodokem-976-shake.deno.js +0 -0
  79. package/dist/frodokem-976-shake.min.js +0 -0
  80. package/dist/hqc-128.deno.js +0 -0
  81. package/dist/hqc-128.min.js +0 -0
  82. package/dist/hqc-192.deno.js +0 -0
  83. package/dist/hqc-192.min.js +0 -0
  84. package/dist/hqc-256.deno.js +0 -0
  85. package/dist/hqc-256.min.js +0 -0
  86. package/dist/kyber-1024.deno.js +0 -0
  87. package/dist/kyber-1024.min.js +0 -0
  88. package/dist/kyber-512.deno.js +0 -0
  89. package/dist/kyber-512.min.js +0 -0
  90. package/dist/kyber-768.deno.js +0 -0
  91. package/dist/kyber-768.min.js +0 -0
  92. package/dist/mayo-1.deno.js +0 -0
  93. package/dist/mayo-1.min.js +0 -0
  94. package/dist/mayo-2.deno.js +0 -0
  95. package/dist/mayo-2.min.js +0 -0
  96. package/dist/mayo-3.deno.js +0 -0
  97. package/dist/mayo-3.min.js +0 -0
  98. package/dist/mayo-5.deno.js +0 -0
  99. package/dist/mayo-5.min.js +0 -0
  100. package/dist/ml-dsa-44.deno.js +0 -0
  101. package/dist/ml-dsa-44.min.js +0 -0
  102. package/dist/ml-dsa-65.deno.js +0 -0
  103. package/dist/ml-dsa-65.min.js +0 -0
  104. package/dist/ml-dsa-87.deno.js +0 -0
  105. package/dist/ml-dsa-87.min.js +0 -0
  106. package/dist/ml-kem-1024.deno.js +0 -0
  107. package/dist/ml-kem-1024.min.js +0 -0
  108. package/dist/ml-kem-512.deno.js +0 -0
  109. package/dist/ml-kem-512.min.js +0 -0
  110. package/dist/ml-kem-768.deno.js +0 -0
  111. package/dist/ml-kem-768.min.js +0 -0
  112. package/dist/ntru-hps-2048-509.deno.js +0 -0
  113. package/dist/ntru-hps-2048-509.min.js +0 -0
  114. package/dist/ntru-hps-2048-677.deno.js +0 -0
  115. package/dist/ntru-hps-2048-677.min.js +0 -0
  116. package/dist/ntru-hps-4096-1229.deno.js +0 -0
  117. package/dist/ntru-hps-4096-1229.min.js +0 -0
  118. package/dist/ntru-hps-4096-821.deno.js +0 -0
  119. package/dist/ntru-hps-4096-821.min.js +0 -0
  120. package/dist/ntru-hrss-1373.deno.js +0 -0
  121. package/dist/ntru-hrss-1373.min.js +0 -0
  122. package/dist/ntru-hrss-701.deno.js +0 -0
  123. package/dist/ntru-hrss-701.min.js +0 -0
  124. package/dist/ov-iii-pkc-skc.deno.js +0 -0
  125. package/dist/ov-iii-pkc-skc.min.js +0 -0
  126. package/dist/ov-iii-pkc.deno.js +0 -0
  127. package/dist/ov-iii-pkc.min.js +0 -0
  128. package/dist/ov-iii.deno.js +0 -0
  129. package/dist/ov-iii.min.js +0 -0
  130. package/dist/ov-ip-pkc-skc.deno.js +0 -0
  131. package/dist/ov-ip-pkc-skc.min.js +0 -0
  132. package/dist/ov-ip-pkc.deno.js +0 -0
  133. package/dist/ov-ip-pkc.min.js +0 -0
  134. package/dist/ov-ip.deno.js +0 -0
  135. package/dist/ov-ip.min.js +0 -0
  136. package/dist/ov-is-pkc-skc.deno.js +0 -0
  137. package/dist/ov-is-pkc-skc.min.js +0 -0
  138. package/dist/ov-is-pkc.deno.js +0 -0
  139. package/dist/ov-is-pkc.min.js +0 -0
  140. package/dist/ov-is.deno.js +0 -0
  141. package/dist/ov-is.min.js +0 -0
  142. package/dist/ov-v-pkc-skc.deno.js +0 -0
  143. package/dist/ov-v-pkc-skc.min.js +0 -0
  144. package/dist/ov-v-pkc.deno.js +0 -0
  145. package/dist/ov-v-pkc.min.js +0 -0
  146. package/dist/ov-v.deno.js +0 -0
  147. package/dist/ov-v.min.js +0 -0
  148. package/dist/slh-dsa-sha2-128f.deno.js +0 -0
  149. package/dist/slh-dsa-sha2-128f.min.js +0 -0
  150. package/dist/slh-dsa-sha2-128s.deno.js +0 -0
  151. package/dist/slh-dsa-sha2-128s.min.js +0 -0
  152. package/dist/slh-dsa-sha2-192f.deno.js +0 -0
  153. package/dist/slh-dsa-sha2-192f.min.js +0 -0
  154. package/dist/slh-dsa-sha2-192s.deno.js +0 -0
  155. package/dist/slh-dsa-sha2-192s.min.js +0 -0
  156. package/dist/slh-dsa-sha2-256f.deno.js +0 -0
  157. package/dist/slh-dsa-sha2-256f.min.js +0 -0
  158. package/dist/slh-dsa-sha2-256s.deno.js +0 -0
  159. package/dist/slh-dsa-sha2-256s.min.js +0 -0
  160. package/dist/slh-dsa-shake-128f.deno.js +0 -0
  161. package/dist/slh-dsa-shake-128f.min.js +0 -0
  162. package/dist/slh-dsa-shake-128s.deno.js +0 -0
  163. package/dist/slh-dsa-shake-128s.min.js +0 -0
  164. package/dist/slh-dsa-shake-192f.deno.js +0 -0
  165. package/dist/slh-dsa-shake-192f.min.js +0 -0
  166. package/dist/slh-dsa-shake-192s.deno.js +0 -0
  167. package/dist/slh-dsa-shake-192s.min.js +0 -0
  168. package/dist/slh-dsa-shake-256f.deno.js +0 -0
  169. package/dist/slh-dsa-shake-256f.min.js +0 -0
  170. package/dist/slh-dsa-shake-256s.deno.js +0 -0
  171. package/dist/slh-dsa-shake-256s.min.js +0 -0
  172. package/dist/snova-24-5-4-esk.deno.js +0 -0
  173. package/dist/snova-24-5-4-esk.min.js +0 -0
  174. package/dist/snova-24-5-4-shake-esk.deno.js +0 -0
  175. package/dist/snova-24-5-4-shake-esk.min.js +0 -0
  176. package/dist/snova-24-5-4-shake.deno.js +0 -0
  177. package/dist/snova-24-5-4-shake.min.js +0 -0
  178. package/dist/snova-24-5-4.deno.js +0 -0
  179. package/dist/snova-24-5-4.min.js +0 -0
  180. package/dist/snova-24-5-5.deno.js +0 -0
  181. package/dist/snova-24-5-5.min.js +0 -0
  182. package/dist/snova-25-8-3.deno.js +0 -0
  183. package/dist/snova-25-8-3.min.js +0 -0
  184. package/dist/snova-29-6-5.deno.js +0 -0
  185. package/dist/snova-29-6-5.min.js +0 -0
  186. package/dist/snova-37-17-2.deno.js +0 -0
  187. package/dist/snova-37-17-2.min.js +0 -0
  188. package/dist/snova-37-8-4.deno.js +0 -0
  189. package/dist/snova-37-8-4.min.js +0 -0
  190. package/dist/snova-49-11-3.deno.js +0 -0
  191. package/dist/snova-49-11-3.min.js +0 -0
  192. package/dist/snova-56-25-2.deno.js +0 -0
  193. package/dist/snova-56-25-2.min.js +0 -0
  194. package/dist/snova-60-10-4.deno.js +0 -0
  195. package/dist/snova-60-10-4.min.js +0 -0
  196. package/dist/sntrup761.deno.js +0 -0
  197. package/dist/sntrup761.min.js +0 -0
  198. package/package.json +108 -0
  199. package/src/algorithms/kem/classic-mceliece/classic-mceliece-348864.js +336 -0
  200. package/src/algorithms/kem/classic-mceliece/classic-mceliece-348864f.js +336 -0
  201. package/src/algorithms/kem/classic-mceliece/classic-mceliece-460896.js +336 -0
  202. package/src/algorithms/kem/classic-mceliece/classic-mceliece-460896f.js +336 -0
  203. package/src/algorithms/kem/classic-mceliece/classic-mceliece-6688128.js +336 -0
  204. package/src/algorithms/kem/classic-mceliece/classic-mceliece-6688128f.js +336 -0
  205. package/src/algorithms/kem/classic-mceliece/classic-mceliece-6960119.js +336 -0
  206. package/src/algorithms/kem/classic-mceliece/classic-mceliece-6960119f.js +336 -0
  207. package/src/algorithms/kem/classic-mceliece/classic-mceliece-8192128.js +336 -0
  208. package/src/algorithms/kem/classic-mceliece/classic-mceliece-8192128f.js +336 -0
  209. package/src/algorithms/kem/frodokem/efrodokem-1344-aes.js +366 -0
  210. package/src/algorithms/kem/frodokem/efrodokem-1344-shake.js +366 -0
  211. package/src/algorithms/kem/frodokem/efrodokem-640-aes.js +366 -0
  212. package/src/algorithms/kem/frodokem/efrodokem-640-shake.js +366 -0
  213. package/src/algorithms/kem/frodokem/efrodokem-976-aes.js +366 -0
  214. package/src/algorithms/kem/frodokem/efrodokem-976-shake.js +366 -0
  215. package/src/algorithms/kem/frodokem/frodokem-1344-aes.js +366 -0
  216. package/src/algorithms/kem/frodokem/frodokem-1344-shake.js +366 -0
  217. package/src/algorithms/kem/frodokem/frodokem-640-aes.js +366 -0
  218. package/src/algorithms/kem/frodokem/frodokem-640-shake.js +366 -0
  219. package/src/algorithms/kem/frodokem/frodokem-976-aes.js +366 -0
  220. package/src/algorithms/kem/frodokem/frodokem-976-shake.js +366 -0
  221. package/src/algorithms/kem/hqc/hqc-128.js +366 -0
  222. package/src/algorithms/kem/hqc/hqc-192.js +366 -0
  223. package/src/algorithms/kem/hqc/hqc-256.js +366 -0
  224. package/src/algorithms/kem/kyber/kyber-1024.js +349 -0
  225. package/src/algorithms/kem/kyber/kyber-512.js +347 -0
  226. package/src/algorithms/kem/kyber/kyber-768.js +348 -0
  227. package/src/algorithms/kem/ml-kem/ml-kem-1024.js +345 -0
  228. package/src/algorithms/kem/ml-kem/ml-kem-512.js +345 -0
  229. package/src/algorithms/kem/ml-kem/ml-kem-768.js +344 -0
  230. package/src/algorithms/kem/ntru/ntru-hps-2048-509.js +366 -0
  231. package/src/algorithms/kem/ntru/ntru-hps-2048-677.js +366 -0
  232. package/src/algorithms/kem/ntru/ntru-hps-4096-1229.js +366 -0
  233. package/src/algorithms/kem/ntru/ntru-hps-4096-821.js +366 -0
  234. package/src/algorithms/kem/ntru/ntru-hrss-1373.js +366 -0
  235. package/src/algorithms/kem/ntru/ntru-hrss-701.js +366 -0
  236. package/src/algorithms/kem/ntru/sntrup761.js +367 -0
  237. package/src/algorithms/sig/cross/cross-rsdp-128-balanced.js +391 -0
  238. package/src/algorithms/sig/cross/cross-rsdp-128-fast.js +391 -0
  239. package/src/algorithms/sig/cross/cross-rsdp-128-small.js +391 -0
  240. package/src/algorithms/sig/cross/cross-rsdp-192-balanced.js +391 -0
  241. package/src/algorithms/sig/cross/cross-rsdp-192-fast.js +391 -0
  242. package/src/algorithms/sig/cross/cross-rsdp-192-small.js +391 -0
  243. package/src/algorithms/sig/cross/cross-rsdp-256-balanced.js +391 -0
  244. package/src/algorithms/sig/cross/cross-rsdp-256-fast.js +391 -0
  245. package/src/algorithms/sig/cross/cross-rsdp-256-small.js +391 -0
  246. package/src/algorithms/sig/cross/cross-rsdpg-128-balanced.js +391 -0
  247. package/src/algorithms/sig/cross/cross-rsdpg-128-fast.js +391 -0
  248. package/src/algorithms/sig/cross/cross-rsdpg-128-small.js +391 -0
  249. package/src/algorithms/sig/cross/cross-rsdpg-192-balanced.js +391 -0
  250. package/src/algorithms/sig/cross/cross-rsdpg-192-fast.js +391 -0
  251. package/src/algorithms/sig/cross/cross-rsdpg-192-small.js +391 -0
  252. package/src/algorithms/sig/cross/cross-rsdpg-256-balanced.js +391 -0
  253. package/src/algorithms/sig/cross/cross-rsdpg-256-fast.js +391 -0
  254. package/src/algorithms/sig/cross/cross-rsdpg-256-small.js +391 -0
  255. package/src/algorithms/sig/falcon/falcon-1024.js +378 -0
  256. package/src/algorithms/sig/falcon/falcon-512.js +379 -0
  257. package/src/algorithms/sig/falcon/falcon-padded-1024.js +380 -0
  258. package/src/algorithms/sig/falcon/falcon-padded-512.js +380 -0
  259. package/src/algorithms/sig/mayo/mayo-1.js +390 -0
  260. package/src/algorithms/sig/mayo/mayo-2.js +390 -0
  261. package/src/algorithms/sig/mayo/mayo-3.js +390 -0
  262. package/src/algorithms/sig/mayo/mayo-5.js +390 -0
  263. package/src/algorithms/sig/ml-dsa/ml-dsa-44.js +338 -0
  264. package/src/algorithms/sig/ml-dsa/ml-dsa-65.js +338 -0
  265. package/src/algorithms/sig/ml-dsa/ml-dsa-87.js +338 -0
  266. package/src/algorithms/sig/slh-dsa/slh-dsa-sha2-128f.js +367 -0
  267. package/src/algorithms/sig/slh-dsa/slh-dsa-sha2-128s.js +367 -0
  268. package/src/algorithms/sig/slh-dsa/slh-dsa-sha2-192f.js +367 -0
  269. package/src/algorithms/sig/slh-dsa/slh-dsa-sha2-192s.js +367 -0
  270. package/src/algorithms/sig/slh-dsa/slh-dsa-sha2-256f.js +367 -0
  271. package/src/algorithms/sig/slh-dsa/slh-dsa-sha2-256s.js +367 -0
  272. package/src/algorithms/sig/slh-dsa/slh-dsa-shake-128f.js +367 -0
  273. package/src/algorithms/sig/slh-dsa/slh-dsa-shake-128s.js +367 -0
  274. package/src/algorithms/sig/slh-dsa/slh-dsa-shake-192f.js +367 -0
  275. package/src/algorithms/sig/slh-dsa/slh-dsa-shake-192s.js +367 -0
  276. package/src/algorithms/sig/slh-dsa/slh-dsa-shake-256f.js +367 -0
  277. package/src/algorithms/sig/slh-dsa/slh-dsa-shake-256s.js +367 -0
  278. package/src/algorithms/sig/snova/snova-24-5-4-esk.js +391 -0
  279. package/src/algorithms/sig/snova/snova-24-5-4-shake-esk.js +391 -0
  280. package/src/algorithms/sig/snova/snova-24-5-4-shake.js +391 -0
  281. package/src/algorithms/sig/snova/snova-24-5-4.js +391 -0
  282. package/src/algorithms/sig/snova/snova-24-5-5.js +391 -0
  283. package/src/algorithms/sig/snova/snova-25-8-3.js +391 -0
  284. package/src/algorithms/sig/snova/snova-29-6-5.js +391 -0
  285. package/src/algorithms/sig/snova/snova-37-17-2.js +391 -0
  286. package/src/algorithms/sig/snova/snova-37-8-4.js +391 -0
  287. package/src/algorithms/sig/snova/snova-49-11-3.js +391 -0
  288. package/src/algorithms/sig/snova/snova-56-25-2.js +391 -0
  289. package/src/algorithms/sig/snova/snova-60-10-4.js +391 -0
  290. package/src/algorithms/sig/uov/ov-iii-pkc-skc.js +390 -0
  291. package/src/algorithms/sig/uov/ov-iii-pkc.js +390 -0
  292. package/src/algorithms/sig/uov/ov-iii.js +390 -0
  293. package/src/algorithms/sig/uov/ov-ip-pkc-skc.js +390 -0
  294. package/src/algorithms/sig/uov/ov-ip-pkc.js +390 -0
  295. package/src/algorithms/sig/uov/ov-ip.js +390 -0
  296. package/src/algorithms/sig/uov/ov-is-pkc-skc.js +390 -0
  297. package/src/algorithms/sig/uov/ov-is-pkc.js +390 -0
  298. package/src/algorithms/sig/uov/ov-is.js +390 -0
  299. package/src/algorithms/sig/uov/ov-v-pkc-skc.js +390 -0
  300. package/src/algorithms/sig/uov/ov-v-pkc.js +390 -0
  301. package/src/algorithms/sig/uov/ov-v.js +390 -0
  302. package/src/cli/algorithms.js +254 -0
  303. package/src/cli/commands/info.js +35 -0
  304. package/src/cli/commands/kem.js +91 -0
  305. package/src/cli/commands/list.js +30 -0
  306. package/src/cli/commands/sig.js +98 -0
  307. package/src/cli/index.js +86 -0
  308. package/src/cli/io.js +147 -0
  309. package/src/cli/parser.js +64 -0
  310. package/src/core/errors.js +75 -0
  311. package/src/core/validation.js +28 -0
  312. package/src/index.js +164 -0
  313. package/src/kem.js +60 -0
  314. package/src/sig.js +87 -0
  315. package/src/types/algorithms.d.ts +1543 -0
  316. package/src/types/errors.d.ts +60 -0
  317. package/src/types/index.d.ts +9 -0
@@ -0,0 +1,379 @@
1
+ /**
2
+ * @fileoverview Falcon-512 signature algorithm implementation
3
+ * @module algorithms/sig/falcon/falcon-512
4
+ * @description
5
+ * Falcon-512 is a lattice-based signature scheme providing NIST security level 1.
6
+ * It offers compact signatures and fast verification, based on NTRU lattices and Fast Fourier sampling.
7
+ *
8
+ * Key features:
9
+ * - Compact signatures (~752 bytes average)
10
+ * - Fast verification
11
+ * - Security Level 1 (128-bit classical, quantum-resistant)
12
+ * - Variable-length signatures
13
+ *
14
+ * @see {@link https://falcon-sign.info/} - Falcon specification
15
+ */
16
+
17
+ import { LibOQSError, LibOQSInitError, LibOQSOperationError, LibOQSValidationError } from '../../../core/errors.js';
18
+ import { isUint8Array } from '../../../core/validation.js';
19
+
20
+ // Dynamic module loading for cross-runtime compatibility
21
+ async function loadModule() {
22
+ const isDeno = typeof Deno !== 'undefined';
23
+ const modulePath = isDeno
24
+ ? `../../../../dist/falcon-512.deno.js`
25
+ : `../../../../dist/falcon-512.min.js`;
26
+
27
+ const module = await import(modulePath);
28
+ return module.default;
29
+ }
30
+
31
+ /**
32
+ * FALCON-512-INFO algorithm constants and metadata
33
+ * @type {{readonly name: 'Falcon-512', readonly identifier: 'Falcon-512', readonly type: 'sig', readonly securityLevel: 1, readonly standardized: false, readonly description: string, readonly keySize: {readonly publicKey: 897, readonly secretKey: 1281, readonly signature: 752}}}
34
+ */
35
+ export const FALCON_512_INFO = {
36
+ name: 'Falcon-512',
37
+ identifier: 'Falcon-512',
38
+ type: 'sig',
39
+ securityLevel: 1,
40
+ standardized: false,
41
+ description: 'Falcon-512 lattice-based signature (NIST Level 1, 128-bit quantum security)',
42
+ keySize: {
43
+ publicKey: 897,
44
+ secretKey: 1281,
45
+ signature: 752
46
+ }
47
+ };
48
+
49
+ /**
50
+ * Factory function to create a Falcon-512 signature instance
51
+ *
52
+ * @async
53
+ * @function createFalcon512
54
+ * @returns {Promise<Falcon512>} Initialized Falcon-512 instance
55
+ * @throws {LibOQSInitError} If module initialization fails
56
+ *
57
+ * @example
58
+ * import { createFalcon512 } from '@oqs/liboqs-js';
59
+ *
60
+ * const sig = await createFalcon512();
61
+ * const { publicKey, secretKey } = sig.generateKeyPair();
62
+ * sig.destroy();
63
+ */
64
+ export async function createFalcon512() {
65
+ const moduleFactory = await loadModule();
66
+ const wasmModule = await moduleFactory();
67
+ wasmModule._OQS_init();
68
+
69
+ const algoName = FALCON_512_INFO.identifier;
70
+ const nameLen = wasmModule.lengthBytesUTF8(algoName);
71
+ const namePtr = wasmModule._malloc(nameLen + 1);
72
+ wasmModule.stringToUTF8(algoName, namePtr, nameLen + 1);
73
+
74
+ const sigPtr = wasmModule._OQS_SIG_new(namePtr);
75
+ wasmModule._free(namePtr);
76
+
77
+ if (!sigPtr) {
78
+ throw new LibOQSInitError('Falcon-512', 'Failed to create SIG instance');
79
+ }
80
+
81
+ return new Falcon512(wasmModule, sigPtr);
82
+ }
83
+
84
+ /**
85
+ * Falcon-512 signature algorithm wrapper class
86
+ *
87
+ * @class Falcon512
88
+ * @description
89
+ * High-level wrapper for Falcon-512 signature operations. Provides secure key generation,
90
+ * message signing, and signature verification with automatic memory management.
91
+ *
92
+ * Memory Management:
93
+ * - All WASM memory is managed internally
94
+ * - Call destroy() when finished to free resources
95
+ * - Do not use instance after calling destroy()
96
+ *
97
+ * @example
98
+ * const sig = await createFalcon512();
99
+ *
100
+ * // Generate keypair
101
+ * const { publicKey, secretKey } = sig.generateKeyPair();
102
+ *
103
+ * // Sign message
104
+ * const message = new TextEncoder().encode('Hello, quantum world!');
105
+ * const signature = sig.sign(message, secretKey);
106
+ *
107
+ * // Verify signature
108
+ * const isValid = sig.verify(message, signature, publicKey);
109
+ * console.log('Valid:', isValid); // true
110
+ *
111
+ * // Cleanup
112
+ * sig.destroy();
113
+ */
114
+ export class Falcon512 {
115
+ /** @type {Object} @private */ #wasmModule;
116
+ /** @type {number} @private */ #sigPtr;
117
+ /** @type {boolean} @private */ #destroyed = false;
118
+
119
+ /**
120
+ * @private
121
+ * @constructor
122
+ * @param {Object} wasmModule - Emscripten WASM module
123
+ * @param {number} sigPtr - Pointer to OQS_SIG structure
124
+ */
125
+ constructor(wasmModule, sigPtr) {
126
+ this.#wasmModule = wasmModule;
127
+ this.#sigPtr = sigPtr;
128
+ }
129
+
130
+ /**
131
+ * Generate a new Falcon-512 keypair
132
+ *
133
+ * @async
134
+ * @returns {{publicKey: Uint8Array, secretKey: Uint8Array}}
135
+ * @throws {LibOQSError} If instance is destroyed
136
+ * @throws {LibOQSOperationError} If key generation fails
137
+ *
138
+ * @example
139
+ * const { publicKey, secretKey } = sig.generateKeyPair();
140
+ * console.log('Public key:', publicKey.length); // 897 bytes
141
+ * console.log('Secret key:', secretKey.length); // 1281 bytes
142
+ */
143
+ generateKeyPair() {
144
+ this.#checkDestroyed();
145
+
146
+ const publicKeyPtr = this.#wasmModule._malloc(FALCON_512_INFO.keySize.publicKey);
147
+ const secretKeyPtr = this.#wasmModule._malloc(FALCON_512_INFO.keySize.secretKey);
148
+
149
+ try {
150
+ const result = this.#wasmModule._OQS_SIG_keypair(this.#sigPtr, publicKeyPtr, secretKeyPtr);
151
+
152
+ if (result !== 0) {
153
+ throw new LibOQSOperationError('generateKeyPair', 'Falcon-512', 'Key generation failed');
154
+ }
155
+
156
+ const publicKey = new Uint8Array(
157
+ this.#wasmModule.HEAPU8.buffer,
158
+ publicKeyPtr,
159
+ FALCON_512_INFO.keySize.publicKey
160
+ ).slice();
161
+
162
+ const secretKey = new Uint8Array(
163
+ this.#wasmModule.HEAPU8.buffer,
164
+ secretKeyPtr,
165
+ FALCON_512_INFO.keySize.secretKey
166
+ ).slice();
167
+
168
+ return { publicKey, secretKey };
169
+ } finally {
170
+ this.#wasmModule._free(publicKeyPtr);
171
+ this.#wasmModule._free(secretKeyPtr);
172
+ }
173
+ }
174
+
175
+ /**
176
+ * Sign a message with Falcon-512
177
+ *
178
+ * @async
179
+ * @param {Uint8Array} message - Message to sign (any length)
180
+ * @param {Uint8Array} secretKey - Secret key (1281 bytes)
181
+ * @returns {Uint8Array} Signature (variable length, max 752 bytes)
182
+ * @throws {LibOQSError} If instance is destroyed
183
+ * @throws {LibOQSValidationError} If secret key size is invalid
184
+ * @throws {LibOQSOperationError} If signing fails
185
+ *
186
+ * @example
187
+ * const message = new TextEncoder().encode('Sign this message');
188
+ * const signature = sig.sign(message, secretKey);
189
+ * console.log('Signature length:', signature.length); // ~752 bytes (variable)
190
+ */
191
+ sign(message, secretKey) {
192
+ this.#checkDestroyed();
193
+ this.#validateSecretKey(secretKey);
194
+
195
+ const messagePtr = this.#wasmModule._malloc(message.length);
196
+ const secretKeyPtr = this.#wasmModule._malloc(FALCON_512_INFO.keySize.secretKey);
197
+ const signaturePtr = this.#wasmModule._malloc(FALCON_512_INFO.keySize.signature);
198
+ const signatureLenPtr = this.#wasmModule._malloc(8);
199
+
200
+ try {
201
+ this.#wasmModule.HEAPU8.set(message, messagePtr);
202
+ this.#wasmModule.HEAPU8.set(secretKey, secretKeyPtr);
203
+
204
+ const result = this.#wasmModule._OQS_SIG_sign(
205
+ this.#sigPtr,
206
+ signaturePtr,
207
+ signatureLenPtr,
208
+ messagePtr,
209
+ message.length,
210
+ secretKeyPtr
211
+ );
212
+
213
+ if (result !== 0) {
214
+ throw new LibOQSOperationError('sign', 'Falcon-512', 'Signature generation failed');
215
+ }
216
+
217
+ const signatureLen = this.#wasmModule.getValue(signatureLenPtr, 'i32');
218
+
219
+ const signature = new Uint8Array(
220
+ this.#wasmModule.HEAPU8.buffer,
221
+ signaturePtr,
222
+ signatureLen
223
+ ).slice();
224
+
225
+ return signature;
226
+ } finally {
227
+ this.#wasmModule._free(messagePtr);
228
+ this.#wasmModule._free(secretKeyPtr);
229
+ this.#wasmModule._free(signaturePtr);
230
+ this.#wasmModule._free(signatureLenPtr);
231
+ }
232
+ }
233
+
234
+ /**
235
+ * Verify a Falcon-512 signature
236
+ *
237
+ * @async
238
+ * @param {Uint8Array} message - Original message
239
+ * @param {Uint8Array} signature - Signature to verify
240
+ * @param {Uint8Array} publicKey - Public key (897 bytes)
241
+ * @returns {boolean} True if signature is valid, false otherwise
242
+ * @throws {LibOQSError} If instance is destroyed
243
+ * @throws {LibOQSValidationError} If public key or signature size is invalid
244
+ *
245
+ * @example
246
+ * const isValid = sig.verify(message, signature, publicKey);
247
+ * if (isValid) {
248
+ * console.log('Signature is valid!');
249
+ * } else {
250
+ * console.log('Signature verification failed');
251
+ * }
252
+ */
253
+ verify(message, signature, publicKey) {
254
+ this.#checkDestroyed();
255
+ this.#validatePublicKey(publicKey);
256
+ this.#validateSignature(signature);
257
+
258
+ const messagePtr = this.#wasmModule._malloc(message.length);
259
+ const signaturePtr = this.#wasmModule._malloc(signature.length);
260
+ const publicKeyPtr = this.#wasmModule._malloc(FALCON_512_INFO.keySize.publicKey);
261
+
262
+ try {
263
+ this.#wasmModule.HEAPU8.set(message, messagePtr);
264
+ this.#wasmModule.HEAPU8.set(signature, signaturePtr);
265
+ this.#wasmModule.HEAPU8.set(publicKey, publicKeyPtr);
266
+
267
+ const result = this.#wasmModule._OQS_SIG_verify(
268
+ this.#sigPtr,
269
+ messagePtr,
270
+ message.length,
271
+ signaturePtr,
272
+ signature.length,
273
+ publicKeyPtr
274
+ );
275
+
276
+ return result === 0;
277
+ } finally {
278
+ this.#wasmModule._free(messagePtr);
279
+ this.#wasmModule._free(signaturePtr);
280
+ this.#wasmModule._free(publicKeyPtr);
281
+ }
282
+ }
283
+
284
+ /**
285
+ * Free WASM resources
286
+ *
287
+ * @description
288
+ * Releases all WASM memory associated with this instance.
289
+ * The instance cannot be used after calling destroy().
290
+ *
291
+ * @example
292
+ * sig.destroy();
293
+ * // sig is now unusable
294
+ */
295
+ destroy() {
296
+ if (!this.#destroyed && this.#sigPtr) {
297
+ this.#wasmModule._OQS_SIG_free(this.#sigPtr);
298
+ this.#sigPtr = null;
299
+ this.#destroyed = true;
300
+ }
301
+ }
302
+
303
+ /**
304
+ * Enables automatic cleanup via `using` declarations
305
+ * @example
306
+ * using instance = await create...();
307
+ * // automatically cleaned up at end of scope
308
+ */
309
+ [Symbol.dispose]() {
310
+ this.destroy();
311
+ }
312
+
313
+ /**
314
+ * Get algorithm information
315
+ *
316
+ * @readonly
317
+ * @returns {typeof FALCON_512_INFO} Algorithm metadata
318
+ *
319
+ * @example
320
+ * console.log(sig.info.name); // 'Falcon-512'
321
+ * console.log(sig.info.securityLevel); // 1
322
+ * console.log(sig.info.keySize); // { publicKey: 897, secretKey: 1281, signature: 752 }
323
+ */
324
+ get info() {
325
+ return FALCON_512_INFO;
326
+ }
327
+
328
+ /**
329
+ * @private
330
+ * @throws {LibOQSError} If instance is destroyed
331
+ */
332
+ #checkDestroyed() {
333
+ if (this.#destroyed) {
334
+ throw new LibOQSError('Instance has been destroyed', 'Falcon-512');
335
+ }
336
+ }
337
+
338
+ /**
339
+ * @private
340
+ * @param {Uint8Array} publicKey
341
+ * @throws {LibOQSValidationError} If public key size is invalid
342
+ */
343
+ #validatePublicKey(publicKey) {
344
+ if (!isUint8Array(publicKey) || publicKey.length !== FALCON_512_INFO.keySize.publicKey) {
345
+ throw new LibOQSValidationError(
346
+ `Invalid public key size: expected ${FALCON_512_INFO.keySize.publicKey} bytes, got ${publicKey.length}`,
347
+ 'Falcon-512'
348
+ );
349
+ }
350
+ }
351
+
352
+ /**
353
+ * @private
354
+ * @param {Uint8Array} secretKey
355
+ * @throws {LibOQSValidationError} If secret key size is invalid
356
+ */
357
+ #validateSecretKey(secretKey) {
358
+ if (!isUint8Array(secretKey) || secretKey.length !== FALCON_512_INFO.keySize.secretKey) {
359
+ throw new LibOQSValidationError(
360
+ `Invalid secret key size: expected ${FALCON_512_INFO.keySize.secretKey} bytes, got ${secretKey.length}`,
361
+ 'Falcon-512'
362
+ );
363
+ }
364
+ }
365
+
366
+ /**
367
+ * @private
368
+ * @param {Uint8Array} signature
369
+ * @throws {LibOQSValidationError} If signature size is invalid
370
+ */
371
+ #validateSignature(signature) {
372
+ if (!isUint8Array(signature) || signature.length === 0 || signature.length > FALCON_512_INFO.keySize.signature) {
373
+ throw new LibOQSValidationError(
374
+ `Invalid signature size: expected 1-${FALCON_512_INFO.keySize.signature} bytes, got ${signature.length}`,
375
+ 'Falcon-512'
376
+ );
377
+ }
378
+ }
379
+ }