@awacloud/fw 0.1.0 → 1.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 (609) hide show
  1. package/CHANGELOG.md +125 -0
  2. package/NOTICE +8 -0
  3. package/README.md +163 -31
  4. package/dist/build/fw.core.pure.meta.json +6 -6
  5. package/dist/build/fw.core.pure.min.js +15 -12
  6. package/dist/build/fw.full.pure.meta.json +13 -7
  7. package/dist/build/fw.full.pure.min.js +45 -42
  8. package/dist/build/fw.minimal.pure.meta.json +6 -6
  9. package/dist/build/fw.minimal.pure.min.js +16 -13
  10. package/dist/build/fw.pack.compress-heavy.pure.meta.json +6 -6
  11. package/dist/build/fw.pack.compress-heavy.pure.min.js +3 -3
  12. package/dist/build/fw.pack.crypto-advanced.pure.meta.json +6 -6
  13. package/dist/build/fw.pack.crypto-advanced.pure.min.js +1 -1
  14. package/dist/build/fw.pack.crypto-basic.pure.meta.json +6 -6
  15. package/dist/build/fw.pack.crypto-basic.pure.min.js +1 -1
  16. package/dist/build/fw.pack.crypto-identity.pure.meta.json +7 -6
  17. package/dist/build/fw.pack.crypto-identity.pure.min.js +4 -4
  18. package/dist/build/fw.pwa.pure.meta.json +7 -6
  19. package/dist/build/fw.pwa.pure.min.js +38 -35
  20. package/dist/build/fw.site-interactive.pure.meta.json +6 -6
  21. package/dist/build/fw.site-interactive.pure.min.js +37 -34
  22. package/dist/build/fw.site.pure.meta.json +6 -6
  23. package/dist/build/fw.site.pure.min.js +24 -21
  24. package/dist/build/fw.spa.pure.meta.json +8 -7
  25. package/dist/build/fw.spa.pure.min.js +41 -38
  26. package/dist/build/sanity-base-classic.min.js +1 -1
  27. package/dist/build/sanity.min.js +1 -1
  28. package/dist/types/core/internal.d.ts +29 -0
  29. package/dist/types/core/internal.d.ts.map +1 -0
  30. package/dist/types/core/logger.d.ts +23 -4
  31. package/dist/types/core/logger.d.ts.map +1 -1
  32. package/dist/types/core/modules.d.ts +374 -61
  33. package/dist/types/core/modules.d.ts.map +1 -1
  34. package/dist/types/core/runtime.d.ts +10 -6
  35. package/dist/types/core/runtime.d.ts.map +1 -1
  36. package/dist/types/core/worker-helper.d.ts +35 -0
  37. package/dist/types/core/worker-helper.d.ts.map +1 -1
  38. package/dist/types/crypto/cipher/aes.d.ts +1 -7
  39. package/dist/types/crypto/cipher/aes.d.ts.map +1 -1
  40. package/dist/types/crypto/cipher/chacha20.d.ts +0 -10
  41. package/dist/types/crypto/cipher/chacha20.d.ts.map +1 -1
  42. package/dist/types/crypto/hash/argon2.d.ts +0 -15
  43. package/dist/types/crypto/hash/argon2.d.ts.map +1 -1
  44. package/dist/types/crypto/hash/blake2b.d.ts.map +1 -1
  45. package/dist/types/crypto/hash/hmac.d.ts.map +1 -1
  46. package/dist/types/crypto/hash/pbkdf2.d.ts.map +1 -1
  47. package/dist/types/crypto/hash/poly1305.d.ts.map +1 -1
  48. package/dist/types/crypto/hash/sha224.d.ts +1 -1
  49. package/dist/types/crypto/hash/sha256.d.ts +4 -13
  50. package/dist/types/crypto/hash/sha256.d.ts.map +1 -1
  51. package/dist/types/crypto/hash/sha3.d.ts.map +1 -1
  52. package/dist/types/crypto/hash/sha384.d.ts +1 -1
  53. package/dist/types/crypto/hash/sha512.d.ts +4 -13
  54. package/dist/types/crypto/hash/sha512.d.ts.map +1 -1
  55. package/dist/types/crypto/mode/cmac.d.ts +0 -6
  56. package/dist/types/crypto/mode/cmac.d.ts.map +1 -1
  57. package/dist/types/crypto/mode/ctr.d.ts +0 -6
  58. package/dist/types/crypto/mode/ctr.d.ts.map +1 -1
  59. package/dist/types/crypto/mode/gcm.d.ts +0 -9
  60. package/dist/types/crypto/mode/gcm.d.ts.map +1 -1
  61. package/dist/types/crypto/pkc/ecc.d.ts +0 -1
  62. package/dist/types/crypto/pkc/ecc.d.ts.map +1 -1
  63. package/dist/types/crypto/pkc/ed25519.d.ts +4 -25
  64. package/dist/types/crypto/pkc/ed25519.d.ts.map +1 -1
  65. package/dist/types/crypto/pkc/hybridSign.d.ts +25 -5
  66. package/dist/types/crypto/pkc/hybridSign.d.ts.map +1 -1
  67. package/dist/types/crypto/pkc/ml_dsa.d.ts +6 -26
  68. package/dist/types/crypto/pkc/ml_dsa.d.ts.map +1 -1
  69. package/dist/types/crypto/pkc/ml_kem.d.ts +0 -43
  70. package/dist/types/crypto/pkc/ml_kem.d.ts.map +1 -1
  71. package/dist/types/crypto/pkc/rsa.d.ts +0 -24
  72. package/dist/types/crypto/pkc/rsa.d.ts.map +1 -1
  73. package/dist/types/crypto/pkc/slh_dsa.d.ts +6 -16
  74. package/dist/types/crypto/pkc/slh_dsa.d.ts.map +1 -1
  75. package/dist/types/crypto/pkc/x25519.d.ts +0 -6
  76. package/dist/types/crypto/pkc/x25519.d.ts.map +1 -1
  77. package/dist/types/crypto/utils/bitArray.d.ts +0 -8
  78. package/dist/types/crypto/utils/bitArray.d.ts.map +1 -1
  79. package/dist/types/crypto/utils/jws.d.ts +6 -14
  80. package/dist/types/crypto/utils/jws.d.ts.map +1 -1
  81. package/dist/types/crypto/utils/keyformat.d.ts +52 -0
  82. package/dist/types/crypto/utils/keyformat.d.ts.map +1 -1
  83. package/dist/types/crypto/utils/random.d.ts +1 -10
  84. package/dist/types/crypto/utils/random.d.ts.map +1 -1
  85. package/dist/types/crypto/utils/rsaKeygen.d.ts +0 -10
  86. package/dist/types/crypto/utils/rsaKeygen.d.ts.map +1 -1
  87. package/dist/types/crypto/utils/uuid.d.ts.map +1 -1
  88. package/dist/types/crypto/utils/x509.d.ts +397 -0
  89. package/dist/types/crypto/utils/x509.d.ts.map +1 -0
  90. package/dist/types/crypto/wasm/argon2.d.ts +2 -1
  91. package/dist/types/crypto/wasm/argon2.d.ts.map +1 -1
  92. package/dist/types/crypto/wasm/pbkdf2.d.ts +2 -2
  93. package/dist/types/crypto/wasm/pbkdf2.d.ts.map +1 -1
  94. package/dist/types/crypto/wasm/rsa.d.ts.map +1 -1
  95. package/dist/types/crypto/wasm/runtime.d.ts +13 -0
  96. package/dist/types/crypto/wasm/runtime.d.ts.map +1 -1
  97. package/dist/types/crypto/webcrypto/aes.d.ts.map +1 -1
  98. package/dist/types/crypto/webcrypto/aeskw.d.ts.map +1 -1
  99. package/dist/types/crypto/webcrypto/digest.d.ts +0 -4
  100. package/dist/types/crypto/webcrypto/digest.d.ts.map +1 -1
  101. package/dist/types/crypto/webcrypto/rsa.d.ts.map +1 -1
  102. package/dist/types/dom/fs/fileIntake.d.ts +59 -0
  103. package/dist/types/dom/fs/fileIntake.d.ts.map +1 -0
  104. package/dist/types/dom/fs/fsAccess.d.ts.map +1 -1
  105. package/dist/types/dom/query/dnd.d.ts.map +1 -1
  106. package/dist/types/dom/query/sound.d.ts +89 -0
  107. package/dist/types/dom/query/sound.d.ts.map +1 -0
  108. package/dist/types/dom/rendering/chart.d.ts.map +1 -1
  109. package/dist/types/dom/rendering/component.d.ts +9 -3
  110. package/dist/types/dom/rendering/component.d.ts.map +1 -1
  111. package/dist/types/dom/rendering/parser.d.ts +39 -0
  112. package/dist/types/dom/rendering/parser.d.ts.map +1 -1
  113. package/dist/types/dom/rendering/render.d.ts.map +1 -1
  114. package/dist/types/dom/rendering/sanitize.d.ts +4 -0
  115. package/dist/types/dom/rendering/sanitize.d.ts.map +1 -1
  116. package/dist/types/dom/rendering/secPolicy.d.ts.map +1 -1
  117. package/dist/types/dom/rendering/styleSheet.d.ts +74 -0
  118. package/dist/types/dom/rendering/styleSheet.d.ts.map +1 -0
  119. package/dist/types/dom/rendering/template.d.ts +9 -3
  120. package/dist/types/dom/rendering/template.d.ts.map +1 -1
  121. package/dist/types/dom/rendering/themeTokens.d.ts +9 -3
  122. package/dist/types/dom/rendering/themeTokens.d.ts.map +1 -1
  123. package/dist/types/dom/rendering/uiSession-core.d.ts +9 -3
  124. package/dist/types/dom/rendering/uiSession-core.d.ts.map +1 -1
  125. package/dist/types/dom/rendering/uiSession-list.d.ts +9 -3
  126. package/dist/types/dom/rendering/uiSession-list.d.ts.map +1 -1
  127. package/dist/types/dom/rendering/uiSession.d.ts +18 -6
  128. package/dist/types/dom/rendering/uiSession.d.ts.map +1 -1
  129. package/dist/types/dom/sw/installPrompt.d.ts +89 -0
  130. package/dist/types/dom/sw/installPrompt.d.ts.map +1 -0
  131. package/dist/types/dom/sw/precache.d.ts +149 -0
  132. package/dist/types/dom/sw/precache.d.ts.map +1 -0
  133. package/dist/types/dom/sw/swUpdate.d.ts +129 -0
  134. package/dist/types/dom/sw/swUpdate.d.ts.map +1 -0
  135. package/dist/types/dom/utils/clipboard.d.ts +8 -0
  136. package/dist/types/dom/utils/clipboard.d.ts.map +1 -1
  137. package/dist/types/dom/utils/keybindings.d.ts.map +1 -1
  138. package/dist/types/dom/utils/route.d.ts.map +1 -1
  139. package/dist/types/dom/utils/ua.d.ts +2 -2
  140. package/dist/types/dom/utils/ua.d.ts.map +1 -1
  141. package/dist/types/io/calc/crc32.d.ts.map +1 -1
  142. package/dist/types/io/codec/b64.d.ts +24 -0
  143. package/dist/types/io/codec/b64.d.ts.map +1 -1
  144. package/dist/types/io/codec/cbor.d.ts +1 -0
  145. package/dist/types/io/codec/cbor.d.ts.map +1 -1
  146. package/dist/types/io/codec/hex.d.ts.map +1 -1
  147. package/dist/types/io/codec/msgpack.d.ts +1 -0
  148. package/dist/types/io/codec/msgpack.d.ts.map +1 -1
  149. package/dist/types/io/codec/url.d.ts +3 -1
  150. package/dist/types/io/codec/url.d.ts.map +1 -1
  151. package/dist/types/io/codec/utf8.d.ts.map +1 -1
  152. package/dist/types/io/compress/bitstream.d.ts +1 -1
  153. package/dist/types/io/compress/brotli.d.ts +0 -1
  154. package/dist/types/io/compress/brotli.d.ts.map +1 -1
  155. package/dist/types/io/compress/brotli_shared.d.ts +0 -4
  156. package/dist/types/io/compress/brotli_shared.d.ts.map +1 -1
  157. package/dist/types/io/compress/deflate.d.ts +14 -1
  158. package/dist/types/io/compress/deflate.d.ts.map +1 -1
  159. package/dist/types/io/compress/gzip.d.ts +4 -0
  160. package/dist/types/io/compress/gzip.d.ts.map +1 -1
  161. package/dist/types/io/compress/huffman.d.ts +7 -0
  162. package/dist/types/io/compress/huffman.d.ts.map +1 -1
  163. package/dist/types/io/compress/lz4.d.ts +4 -2
  164. package/dist/types/io/compress/lz4.d.ts.map +1 -1
  165. package/dist/types/io/compress/lz77.d.ts +17 -0
  166. package/dist/types/io/compress/lz77.d.ts.map +1 -1
  167. package/dist/types/io/compress/lzw.d.ts +2 -0
  168. package/dist/types/io/compress/lzw.d.ts.map +1 -1
  169. package/dist/types/io/compress/zip.d.ts.map +1 -1
  170. package/dist/types/io/compress/zlib.d.ts +9 -2
  171. package/dist/types/io/compress/zlib.d.ts.map +1 -1
  172. package/dist/types/io/math/linalg.d.ts.map +1 -1
  173. package/dist/types/process/rpc.d.ts.map +1 -1
  174. package/dist/types/process/workerPool.d.ts.map +1 -1
  175. package/dist/types/sanity/base.d.ts +12 -2
  176. package/dist/types/sanity/base.d.ts.map +1 -1
  177. package/dist/types/sanity/lockdown.d.ts +6 -5
  178. package/dist/types/sanity/lockdown.d.ts.map +1 -1
  179. package/dist/types/sanity/wasm-gate.d.ts +1 -1
  180. package/docs/README.md +17 -10
  181. package/docs/api/README.md +5 -5
  182. package/docs/api/core/logger.md +2 -1
  183. package/docs/api/core/modules.md +3 -3
  184. package/docs/api/core/runtime.md +9 -9
  185. package/docs/api/core/worker-helper.md +12 -2
  186. package/docs/api/crypto/README.md +1 -1
  187. package/docs/api/crypto/cipher/README.md +2 -2
  188. package/docs/api/crypto/cipher/aes.md +5 -10
  189. package/docs/api/crypto/cipher/chacha20.md +3 -8
  190. package/docs/api/crypto/hash/README.md +5 -5
  191. package/docs/api/crypto/hash/adf.md +21 -11
  192. package/docs/api/crypto/hash/argon2.md +3 -12
  193. package/docs/api/crypto/hash/blake2b.md +12 -14
  194. package/docs/api/crypto/hash/pbkdf2.md +1 -1
  195. package/docs/api/crypto/hash/sha224.md +2 -2
  196. package/docs/api/crypto/hash/sha256.md +4 -4
  197. package/docs/api/crypto/hash/sha3.md +2 -2
  198. package/docs/api/crypto/hash/sha384.md +1 -1
  199. package/docs/api/crypto/hash/sha512.md +5 -5
  200. package/docs/api/crypto/hash/sha512_224.md +1 -1
  201. package/docs/api/crypto/hash/sha512_256.md +1 -1
  202. package/docs/api/crypto/mode/README.md +3 -3
  203. package/docs/api/crypto/mode/cbc.md +2 -2
  204. package/docs/api/crypto/mode/chacha20poly1305.md +1 -1
  205. package/docs/api/crypto/mode/cmac.md +4 -4
  206. package/docs/api/crypto/mode/ctr.md +2 -3
  207. package/docs/api/crypto/mode/gcm.md +5 -5
  208. package/docs/api/crypto/mode/kw.md +4 -4
  209. package/docs/api/crypto/pkc/README.md +8 -8
  210. package/docs/api/crypto/pkc/ecc.md +19 -17
  211. package/docs/api/crypto/pkc/ed25519.md +10 -15
  212. package/docs/api/crypto/pkc/hybridKem.md +8 -2
  213. package/docs/api/crypto/pkc/hybridSign.md +34 -7
  214. package/docs/api/crypto/pkc/ml_dsa.md +20 -19
  215. package/docs/api/crypto/pkc/ml_kem.md +3 -3
  216. package/docs/api/crypto/pkc/rsa.md +7 -9
  217. package/docs/api/crypto/pkc/slh_dsa.md +12 -12
  218. package/docs/api/crypto/pkc/x25519.md +5 -4
  219. package/docs/api/crypto/utils/README.md +7 -7
  220. package/docs/api/crypto/utils/aes_modes.md +2 -5
  221. package/docs/api/crypto/utils/asn1.md +25 -16
  222. package/docs/api/crypto/utils/jws.md +6 -4
  223. package/docs/api/crypto/utils/keyformat.md +24 -15
  224. package/docs/api/crypto/utils/pad.md +1 -1
  225. package/docs/api/crypto/utils/pem.md +3 -3
  226. package/docs/api/crypto/utils/random.md +3 -4
  227. package/docs/api/crypto/utils/rsaKeygen.md +2 -2
  228. package/docs/api/crypto/utils/totp.md +2 -2
  229. package/docs/api/crypto/utils/uuid.md +5 -5
  230. package/docs/api/crypto/utils/x509.md +124 -0
  231. package/docs/api/crypto/wasm/aes.md +1 -1
  232. package/docs/api/crypto/wasm/argon2.md +6 -4
  233. package/docs/api/crypto/wasm/ml_kem.md +1 -0
  234. package/docs/api/crypto/wasm/pbkdf2.md +8 -8
  235. package/docs/api/crypto/wasm/rsa.md +1 -1
  236. package/docs/api/crypto/wasm/runtime.md +27 -10
  237. package/docs/api/crypto/webcrypto/aes.md +1 -1
  238. package/docs/api/crypto/webcrypto/aeskw.md +2 -2
  239. package/docs/api/crypto/webcrypto/digest.md +3 -5
  240. package/docs/api/crypto/webcrypto/ecc.md +1 -1
  241. package/docs/api/crypto/webcrypto/ed25519.md +1 -1
  242. package/docs/api/crypto/webcrypto/rsa.md +3 -2
  243. package/docs/api/crypto/webcrypto/x25519.md +1 -1
  244. package/docs/api/dom/README.md +6 -1
  245. package/docs/api/dom/fs/README.md +1 -0
  246. package/docs/api/dom/fs/fileIntake.md +120 -0
  247. package/docs/api/dom/fs/fsAccess.md +1 -0
  248. package/docs/api/dom/fs/indexedDB.md +1 -1
  249. package/docs/api/dom/fs/storage.md +1 -1
  250. package/docs/api/dom/query/README.md +2 -1
  251. package/docs/api/dom/query/dnd.md +4 -1
  252. package/docs/api/dom/query/dom.md +5 -0
  253. package/docs/api/dom/query/sound.md +103 -0
  254. package/docs/api/dom/rendering/README.md +4 -3
  255. package/docs/api/dom/rendering/chart.md +5 -4
  256. package/docs/api/dom/rendering/component.md +25 -3
  257. package/docs/api/dom/rendering/parser.md +5 -2
  258. package/docs/api/dom/rendering/reactiveBind.md +1 -1
  259. package/docs/api/dom/rendering/render.md +2 -2
  260. package/docs/api/dom/rendering/sanitize.md +10 -2
  261. package/docs/api/dom/rendering/secPolicy.md +4 -4
  262. package/docs/api/dom/rendering/styleSheet.md +85 -0
  263. package/docs/api/dom/rendering/template.md +20 -5
  264. package/docs/api/dom/rendering/themeTokens.md +6 -3
  265. package/docs/api/dom/rendering/uiSession.md +18 -5
  266. package/docs/api/dom/rendering/virtualScroll.md +2 -2
  267. package/docs/api/dom/sensors/geolocation.md +1 -1
  268. package/docs/api/dom/sw/README.md +7 -1
  269. package/docs/api/dom/sw/cache.md +2 -1
  270. package/docs/api/dom/sw/installPrompt.md +111 -0
  271. package/docs/api/dom/sw/precache.md +124 -0
  272. package/docs/api/dom/sw/serviceWorker.md +4 -2
  273. package/docs/api/dom/sw/swUpdate.md +112 -0
  274. package/docs/api/dom/utils/clipboard.md +56 -5
  275. package/docs/api/dom/utils/entropyCollector.md +1 -1
  276. package/docs/api/dom/utils/keybindings.md +17 -2
  277. package/docs/api/dom/utils/leaderElection.md +2 -2
  278. package/docs/api/dom/utils/route.md +1 -0
  279. package/docs/api/dom/utils/ua.md +15 -10
  280. package/docs/api/io/calc/crc32.md +4 -1
  281. package/docs/api/io/codec/README.md +2 -2
  282. package/docs/api/io/codec/b64.md +31 -2
  283. package/docs/api/io/codec/buffer.md +1 -1
  284. package/docs/api/io/codec/cbor.md +6 -4
  285. package/docs/api/io/codec/csv.md +178 -178
  286. package/docs/api/io/codec/hex.md +10 -2
  287. package/docs/api/io/codec/msgpack.md +4 -3
  288. package/docs/api/io/codec/url.md +4 -3
  289. package/docs/api/io/codec/utf8.md +3 -3
  290. package/docs/api/io/compress/bitstream.md +6 -3
  291. package/docs/api/io/compress/brotli.md +36 -4
  292. package/docs/api/io/compress/brotli_shared.md +1 -1
  293. package/docs/api/io/compress/deflate.md +42 -34
  294. package/docs/api/io/compress/gzip.md +26 -6
  295. package/docs/api/io/compress/huffman.md +2 -1
  296. package/docs/api/io/compress/lz4.md +5 -3
  297. package/docs/api/io/compress/lz77.md +26 -3
  298. package/docs/api/io/compress/lzw.md +13 -8
  299. package/docs/api/io/compress/zip.md +36 -10
  300. package/docs/api/io/compress/zlib.md +21 -5
  301. package/docs/api/io/math/linalg.md +1 -1
  302. package/docs/api/io/utils/valid.md +1 -1
  303. package/docs/api/process/rpc.md +3 -2
  304. package/docs/api/process/workerPool.md +1 -1
  305. package/docs/api/sanity/base.md +9 -5
  306. package/docs/api/sanity/lockdown.md +7 -6
  307. package/docs/api/surface.json +12311 -0
  308. package/docs/api/typed.md +5 -3
  309. package/docs/dev/README.md +2 -0
  310. package/docs/dev/bench.md +76 -0
  311. package/docs/dev/crypto-references.md +54 -0
  312. package/docs/dev/provenance.md +30 -7
  313. package/docs/dev/publishing.md +7 -7
  314. package/docs/dev/runtime.md +1 -1
  315. package/docs/dev/testing.md +13 -0
  316. package/docs/evidence/l4-evidence.md +86 -0
  317. package/docs/evidence/pqc-hybrid-evidence.md +7 -6
  318. package/docs/guide/README.md +1 -0
  319. package/docs/guide/_QUICK_REF.md +5 -5
  320. package/docs/guide/doc-format.md +4 -3
  321. package/docs/guide/integrations-hmr.md +1 -1
  322. package/docs/guide/module-creation-workflow.md +8 -8
  323. package/docs/guide/rendering-pipeline.md +11 -4
  324. package/docs/guide/security.md +7 -5
  325. package/docs/guide/stability.md +123 -0
  326. package/docs/guide/tutorial-todo.md +20 -8
  327. package/docs/guide/typescript.md +9 -0
  328. package/docs/guide/worker-confinement.md +30 -17
  329. package/docs/notes/lz77-deflate-factorization.md +3 -3
  330. package/docs/tools/README.md +1 -1
  331. package/docs/tools/bundler.md +3 -3
  332. package/docs/tools/codegen.md +1 -1
  333. package/docs/tools/standalone.md +0 -1
  334. package/fw.config.json +2 -2
  335. package/integrations/_shared/catalog.generated.json +7 -1
  336. package/integrations/_shared/core.js +1 -1
  337. package/integrations/astro/index.js +1 -1
  338. package/integrations/eslint/README.md +7 -1
  339. package/integrations/nextjs/index.js +1 -1
  340. package/integrations/nodejs/README.md +3 -3
  341. package/integrations/turbopack/index.js +2 -2
  342. package/integrations/typedoc/categorize.js +1 -1
  343. package/integrations/typedoc/typedoc.json +2 -1
  344. package/integrations/vite/index.js +2 -2
  345. package/integrations/vite/vite-env.d.ts +7 -4
  346. package/integrations/webpack/index.js +3 -3
  347. package/package.json +76 -10
  348. package/src/core/internal.js +31 -0
  349. package/src/core/logger.js +95 -23
  350. package/src/core/modules.js +17 -8
  351. package/src/core/readyState.js +1 -1
  352. package/src/core/runtime.js +74 -27
  353. package/src/core/worker-helper.js +83 -4
  354. package/src/crypto/NIST_CONFORMANCE.md +47 -34
  355. package/src/crypto/cipher/aes.acvp.md +7 -8
  356. package/src/crypto/cipher/aes.js +280 -229
  357. package/src/crypto/cipher/chacha20.acvp.md +6 -7
  358. package/src/crypto/cipher/chacha20.js +91 -61
  359. package/src/crypto/hash/adf.js +1 -1
  360. package/src/crypto/hash/argon2.acvp.md +11 -15
  361. package/src/crypto/hash/argon2.js +9 -24
  362. package/src/crypto/hash/blake2b.js +157 -125
  363. package/src/crypto/hash/hkdf.acvp.md +15 -15
  364. package/src/crypto/hash/hkdf.js +1 -1
  365. package/src/crypto/hash/hmac.acvp.md +10 -12
  366. package/src/crypto/hash/hmac.js +5 -1
  367. package/src/crypto/hash/pbkdf2.acvp.md +13 -13
  368. package/src/crypto/hash/pbkdf2.js +36 -8
  369. package/src/crypto/hash/poly1305.acvp.md +10 -6
  370. package/src/crypto/hash/poly1305.js +171 -50
  371. package/src/crypto/hash/sha224.acvp.md +3 -3
  372. package/src/crypto/hash/sha224.js +4 -4
  373. package/src/crypto/hash/sha256.acvp.md +2 -2
  374. package/src/crypto/hash/sha256.js +514 -50
  375. package/src/crypto/hash/sha3.acvp.md +9 -9
  376. package/src/crypto/hash/sha3.js +127 -71
  377. package/src/crypto/hash/sha384.acvp.md +3 -3
  378. package/src/crypto/hash/sha384.js +4 -4
  379. package/src/crypto/hash/sha512.acvp.md +7 -8
  380. package/src/crypto/hash/sha512.js +107 -108
  381. package/src/crypto/hash/sha512_224.acvp.md +6 -6
  382. package/src/crypto/hash/sha512_224.js +2 -2
  383. package/src/crypto/hash/sha512_256.acvp.md +6 -6
  384. package/src/crypto/hash/sha512_256.js +2 -2
  385. package/src/crypto/mode/cbc.acvp.md +2 -2
  386. package/src/crypto/mode/cbc.js +1 -1
  387. package/src/crypto/mode/chacha20poly1305.acvp.md +6 -6
  388. package/src/crypto/mode/chacha20poly1305.js +3 -3
  389. package/src/crypto/mode/cmac.acvp.md +5 -5
  390. package/src/crypto/mode/cmac.js +8 -8
  391. package/src/crypto/mode/ctr.acvp.md +2 -2
  392. package/src/crypto/mode/ctr.js +1 -3
  393. package/src/crypto/mode/gcm.acvp.md +6 -6
  394. package/src/crypto/mode/gcm.js +7 -7
  395. package/src/crypto/mode/kw.acvp.md +4 -4
  396. package/src/crypto/mode/kw.js +5 -5
  397. package/src/crypto/pkc/ecc.acvp.md +13 -13
  398. package/src/crypto/pkc/ecc.js +9 -11
  399. package/src/crypto/pkc/ed25519.acvp.md +30 -34
  400. package/src/crypto/pkc/ed25519.js +453 -94
  401. package/src/crypto/pkc/hybrid-kat.provenance.md +4 -4
  402. package/src/crypto/pkc/hybridSign.js +103 -24
  403. package/src/crypto/pkc/ml_dsa.acvp.md +18 -18
  404. package/src/crypto/pkc/ml_dsa.js +29 -32
  405. package/src/crypto/pkc/ml_kem.acvp.md +7 -7
  406. package/src/crypto/pkc/ml_kem.js +15 -21
  407. package/src/crypto/pkc/rsa.acvp.md +11 -15
  408. package/src/crypto/pkc/rsa.js +7 -44
  409. package/src/crypto/pkc/slh_dsa.acvp.md +16 -16
  410. package/src/crypto/pkc/slh_dsa.js +16 -18
  411. package/src/crypto/pkc/x25519.acvp.md +13 -10
  412. package/src/crypto/pkc/x25519.js +273 -29
  413. package/src/crypto/utils/aes_modes.acvp.md +1 -2
  414. package/src/crypto/utils/aes_modes.js +2 -2
  415. package/src/crypto/utils/asn1-oid.js +1 -1
  416. package/src/crypto/utils/asn1.js +1 -1
  417. package/src/crypto/utils/bitArray.js +33 -48
  418. package/src/crypto/utils/bn.js +1 -1
  419. package/src/crypto/utils/jws.js +37 -41
  420. package/src/crypto/utils/keyformat.js +181 -2
  421. package/src/crypto/utils/pem.js +1 -1
  422. package/src/crypto/utils/random.acvp.md +5 -5
  423. package/src/crypto/utils/random.js +845 -846
  424. package/src/crypto/utils/rsaKeygen.acvp.md +3 -2
  425. package/src/crypto/utils/rsaKeygen.js +6 -6
  426. package/src/crypto/utils/totp.js +1 -1
  427. package/src/crypto/utils/uuid.acvp.md +5 -5
  428. package/src/crypto/utils/uuid.js +11 -10
  429. package/src/crypto/utils/x509.js +591 -0
  430. package/src/crypto/wasm/aes.js +1 -1
  431. package/src/crypto/wasm/aes.scalar.wasm +0 -0
  432. package/src/crypto/wasm/argon2.js +17 -1
  433. package/src/crypto/wasm/argon2.scalar.wasm +0 -0
  434. package/src/crypto/wasm/blake2b.scalar.wasm +0 -0
  435. package/src/crypto/wasm/blake2b.simd.wasm +0 -0
  436. package/src/crypto/wasm/chacha20poly1305.scalar.wasm +0 -0
  437. package/src/crypto/wasm/chacha20poly1305.simd.wasm +0 -0
  438. package/src/crypto/wasm/cmac.scalar.wasm +0 -0
  439. package/src/crypto/wasm/ecc.js +3 -3
  440. package/src/crypto/wasm/ecc.scalar.wasm +0 -0
  441. package/src/crypto/wasm/ed25519.js +1 -1
  442. package/src/crypto/wasm/ed25519.scalar.wasm +0 -0
  443. package/src/crypto/wasm/hkdf.scalar.wasm +0 -0
  444. package/src/crypto/wasm/hmac.scalar.wasm +0 -0
  445. package/src/crypto/wasm/ml_dsa.js +2 -2
  446. package/src/crypto/wasm/ml_dsa.scalar.wasm +0 -0
  447. package/src/crypto/wasm/ml_dsa.simd.wasm +0 -0
  448. package/src/crypto/wasm/ml_kem.js +2 -2
  449. package/src/crypto/wasm/ml_kem.scalar.wasm +0 -0
  450. package/src/crypto/wasm/ml_kem.simd.wasm +0 -0
  451. package/src/crypto/wasm/pbkdf2.js +8 -6
  452. package/src/crypto/wasm/pbkdf2.scalar.wasm +0 -0
  453. package/src/crypto/wasm/rsa.js +6 -5
  454. package/src/crypto/wasm/rsa.scalar.wasm +0 -0
  455. package/src/crypto/wasm/runtime.js +84 -17
  456. package/src/crypto/wasm/sha2.scalar.wasm +0 -0
  457. package/src/crypto/wasm/sha3.scalar.wasm +0 -0
  458. package/src/crypto/wasm/sha3.simd.wasm +0 -0
  459. package/src/crypto/wasm/slh_dsa.js +1 -1
  460. package/src/crypto/wasm/slh_dsa.scalar.wasm +0 -0
  461. package/src/crypto/wasm/x25519.js +1 -1
  462. package/src/crypto/wasm/x25519.scalar.wasm +0 -0
  463. package/src/crypto/webcrypto/aes.js +8 -2
  464. package/src/crypto/webcrypto/aeskw.js +7 -2
  465. package/src/crypto/webcrypto/digest.js +1 -15
  466. package/src/crypto/webcrypto/ecc.js +2 -2
  467. package/src/crypto/webcrypto/ed25519.js +2 -2
  468. package/src/crypto/webcrypto/hmac.js +2 -2
  469. package/src/crypto/webcrypto/rsa.js +7 -2
  470. package/src/crypto/webcrypto/x25519.js +2 -2
  471. package/src/dom/display/animate.js +1 -1
  472. package/src/dom/display/fullscreen.js +1 -1
  473. package/src/dom/fs/download.js +1 -1
  474. package/src/dom/fs/fileIntake.js +192 -0
  475. package/src/dom/fs/fsAccess.js +2 -3
  476. package/src/dom/fs/indexedDB.js +1 -1
  477. package/src/dom/fs/remoteStore.js +1 -1
  478. package/src/dom/fs/storage.js +1 -1
  479. package/src/dom/lifecycle/idle.js +1 -1
  480. package/src/dom/lifecycle/visibility.js +1 -1
  481. package/src/dom/lifecycle/wakeLock.js +1 -1
  482. package/src/dom/net/ajax.js +1 -1
  483. package/src/dom/net/network.js +1 -1
  484. package/src/dom/net/sse.js +1 -1
  485. package/src/dom/net/webrtc.js +1 -1
  486. package/src/dom/net/ws.js +1 -1
  487. package/src/dom/query/dnd.js +56 -4
  488. package/src/dom/query/dom.js +1 -1
  489. package/src/dom/query/events.js +1 -1
  490. package/src/dom/query/gesture.js +1 -1
  491. package/src/dom/query/media.js +1 -1
  492. package/src/dom/query/sound.js +333 -0
  493. package/src/dom/rendering/chart.js +736 -663
  494. package/src/dom/rendering/component.js +25 -14
  495. package/src/dom/rendering/devtools.js +2 -2
  496. package/src/dom/rendering/parser.js +155 -12
  497. package/src/dom/rendering/render.js +14 -4
  498. package/src/dom/rendering/sanitize.js +11 -4
  499. package/src/dom/rendering/secPolicy.js +6 -4
  500. package/src/dom/rendering/styleSheet.js +217 -0
  501. package/src/dom/rendering/template.js +72 -13
  502. package/src/dom/rendering/themeTokens.js +542 -522
  503. package/src/dom/rendering/uiSession-core.js +51 -6
  504. package/src/dom/rendering/uiSession-direct.js +1 -1
  505. package/src/dom/rendering/uiSession-list.js +4 -4
  506. package/src/dom/rendering/uiSession.js +1 -1
  507. package/src/dom/rendering/virtualScroll.js +341 -341
  508. package/src/dom/sensors/battery.js +1 -1
  509. package/src/dom/sensors/geolocation.js +1 -1
  510. package/src/dom/sensors/networkInfo.js +1 -1
  511. package/src/dom/sensors/sensors.js +1 -1
  512. package/src/dom/sw/backgroundSync.js +1 -1
  513. package/src/dom/sw/cache.js +1 -1
  514. package/src/dom/sw/installPrompt.js +151 -0
  515. package/src/dom/sw/precache.js +257 -0
  516. package/src/dom/sw/push.js +1 -1
  517. package/src/dom/sw/sharedWorker.js +1 -1
  518. package/src/dom/sw/swUpdate.js +239 -0
  519. package/src/dom/utils/a11y.js +1 -1
  520. package/src/dom/utils/clipboard.js +56 -6
  521. package/src/dom/utils/entropyCollector.js +1 -1
  522. package/src/dom/utils/focus.js +1 -1
  523. package/src/dom/utils/form.js +1 -1
  524. package/src/dom/utils/keybindings.js +600 -574
  525. package/src/dom/utils/leaderElection.js +1 -1
  526. package/src/dom/utils/notifications.js +1 -1
  527. package/src/dom/utils/permissions.js +107 -107
  528. package/src/dom/utils/route.js +14 -2
  529. package/src/dom/utils/ua.js +42 -28
  530. package/src/dom/utils/webauthn.js +1 -1
  531. package/src/io/binary/reader.js +1 -1
  532. package/src/io/binary/writer.js +1 -1
  533. package/src/io/calc/bigint.js +1 -1
  534. package/src/io/calc/crc32.js +28 -2
  535. package/src/io/calc/easing.js +514 -514
  536. package/src/io/codec/b64.js +189 -52
  537. package/src/io/codec/base32.js +1 -1
  538. package/src/io/codec/base58.js +1 -1
  539. package/src/io/codec/buffer.js +1 -1
  540. package/src/io/codec/cbor.js +111 -18
  541. package/src/io/codec/csv.js +1 -1
  542. package/src/io/codec/hex.js +51 -6
  543. package/src/io/codec/mime.js +1 -1
  544. package/src/io/codec/msgpack.js +47 -6
  545. package/src/io/codec/url.js +24 -7
  546. package/src/io/codec/utf8.js +5 -3
  547. package/src/io/codec/xml.js +1 -1
  548. package/src/io/compress/bitstream.js +2 -2
  549. package/src/io/compress/brotli.js +663 -163
  550. package/src/io/compress/brotli_dict.js +1 -1
  551. package/src/io/compress/brotli_dict_words.js +1 -1
  552. package/src/io/compress/brotli_frame.js +1 -1
  553. package/src/io/compress/brotli_shared.js +7 -7
  554. package/src/io/compress/deflate.js +87 -53
  555. package/src/io/compress/gzip.js +187 -74
  556. package/src/io/compress/huffman.js +24 -1
  557. package/src/io/compress/lz4.js +45 -7
  558. package/src/io/compress/lz77.js +148 -63
  559. package/src/io/compress/lzw.js +35 -19
  560. package/src/io/compress/zip.js +862 -815
  561. package/src/io/compress/zlib.js +87 -7
  562. package/src/io/i18n/i18n.js +1 -1
  563. package/src/io/math/fixed-point.js +1 -1
  564. package/src/io/math/geom.js +1 -1
  565. package/src/io/math/interp.js +1 -1
  566. package/src/io/math/linalg.js +10 -4
  567. package/src/io/math/stats.js +1 -1
  568. package/src/io/structures/btree.js +1 -1
  569. package/src/io/structures/heap.js +1 -1
  570. package/src/io/structures/lruCache.js +1 -1
  571. package/src/io/structures/ringBuffer.js +1 -1
  572. package/src/io/structures/tree-walker.js +1 -1
  573. package/src/io/structures/trie.js +1 -1
  574. package/src/io/sync/abort.js +1 -1
  575. package/src/io/sync/atomics.js +1 -1
  576. package/src/io/sync/cancellable.js +1 -1
  577. package/src/io/sync/channel.js +1 -1
  578. package/src/io/sync/mutex.js +1 -1
  579. package/src/io/sync/semaphore.js +1 -1
  580. package/src/io/sync/tokenBucket.js +1 -1
  581. package/src/io/text/ansi.js +1 -1
  582. package/src/io/text/html-entities.js +1 -1
  583. package/src/io/time/date.js +1 -1
  584. package/src/io/timing/clock.js +1 -1
  585. package/src/io/timing/rateLimit.js +1 -1
  586. package/src/io/timing/scheduler.js +1 -1
  587. package/src/io/utils/errors.js +1 -1
  588. package/src/io/utils/eventBus.js +1 -1
  589. package/src/io/utils/signal.js +1 -1
  590. package/src/io/utils/valid.js +1 -1
  591. package/src/main.js +1 -1
  592. package/src/process/message.js +1 -1
  593. package/src/process/rpc.js +7 -3
  594. package/src/process/workerPool.js +11 -4
  595. package/src/sanity/base.js +85 -39
  596. package/src/sanity/lockdown-apply.js +3 -3
  597. package/src/sanity/lockdown.js +58 -32
  598. package/src/sanity/wasm-gate.js +2 -2
  599. package/src/typed.js +7 -3
  600. package/third-party/NOTICE-brotli-dictionary.txt +69 -0
  601. package/third-party/NOTICE-fw-wasm-crypto.txt +576 -0
  602. package/third-party/NOTICE-whatwg-entities.txt +44 -0
  603. package/types/registry.generated.d.ts +7 -1
  604. package/types/typed.d.ts +7 -3
  605. package/dist/types/crypto/utils/aes_ctr.d.ts +0 -84
  606. package/dist/types/crypto/utils/aes_ctr.d.ts.map +0 -1
  607. package/docs/api/crypto/utils/aes_ctr.md +0 -71
  608. package/src/crypto/utils/aes_ctr.acvp.md +0 -67
  609. package/src/crypto/utils/aes_ctr.js +0 -134
@@ -0,0 +1,591 @@
1
+ // Copyright (c) 2026 AwaCloud SAS
2
+ // Author: Matthieu Bouilloux
3
+ // SPDX-License-Identifier: Apache-2.0
4
+
5
+ /**
6
+ * @fileoverview X.509 v3 certificates (RFC 5280): create, parse, verify, PEM.
7
+ *
8
+ * Keys and signatures: Ed25519 (RFC 8410 — pure Ed25519 over the TBS bytes, no
9
+ * AlgorithmIdentifier parameters) and ECDSA P-256 with SHA-256 (RFC 5758 —
10
+ * `ecdsa-with-SHA256`, DER `SEQUENCE { r, s }`, RFC 6979 deterministic `k`).
11
+ *
12
+ * - `create(spec, signer)` → DER, or `false` on any malformed input. Issuer
13
+ * defaults to the subject (self-signed); names from `CN`, `O`, `OU`, `L`,
14
+ * `ST`, `C`; UTCTime before 2050, GeneralizedTime from 2050 (§ 4.1.2.5);
15
+ * extensions `basicConstraints`, `keyUsage`, `extKeyUsage`,
16
+ * `subjectAltName` (DNS names, emails), `subjectKeyIdentifier`,
17
+ * `authorityKeyIdentifier` (key ids: the leftmost 160 bits of SHA-256 of
18
+ * the subjectPublicKey bits, RFC 7093 § 2 method 1 — fw has no SHA-1).
19
+ * - `parse(der)` → the TBS fields, or `false`.
20
+ * - `verify(der, issuerPublicKey)` → `true` when the issuer key signed it.
21
+ * - `toPem(der)` / `fromPem(text)` (`CERTIFICATE` label).
22
+ *
23
+ * Not claimed: path validation (chains, revocation, name constraints,
24
+ * validity against a clock) — `verify` checks one signature; RSA keys.
25
+ *
26
+ * Seeded from the PAdES recipe (`apps/examples/recipes/pades-sign/x509.js`,
27
+ * the same project's code).
28
+ */
29
+
30
+ /**
31
+ * A subject or issuer name: known attributes by short name; an attribute fw
32
+ * does not name appears under its dotted OID, and a repeated one as an array.
33
+ * @typedef {Record<string, string | string[]>} X509Name
34
+ */
35
+
36
+ /**
37
+ * @typedef {{ alg: 'Ed25519', key: Uint8Array } | { alg: 'ECDSA-P256', key: Uint8Array }} X509PublicKey
38
+ * Ed25519: the 32-byte key. ECDSA-P256: the 65-byte SEC1 uncompressed point.
39
+ */
40
+
41
+ /**
42
+ * @typedef {{ alg: 'Ed25519', privateKey: Uint8Array, publicKey?: Uint8Array } | { alg: 'ECDSA-P256', privateKey: Uint8Array, publicKey?: Uint8Array }} X509Signer
43
+ * Ed25519: the 64-byte private key (seed ‖ public key, as `ed25519.keyPair`
44
+ * returns it). ECDSA-P256: the 32-byte scalar. `publicKey` is the issuer's
45
+ * key, needed for `authorityKeyIdentifier`.
46
+ */
47
+
48
+ /**
49
+ * @typedef {object} X509Extensions
50
+ * @property {{ ca: boolean, pathLen?: number }} [basicConstraints] Critical. `pathLen` only with `ca`.
51
+ * @property {string[]} [keyUsage] Critical. Names: digitalSignature, nonRepudiation, keyEncipherment,
52
+ * dataEncipherment, keyAgreement, keyCertSign, cRLSign, encipherOnly, decipherOnly.
53
+ * @property {string[]} [extKeyUsage] Dotted OIDs (e.g. `1.3.6.1.5.5.7.3.1` serverAuth).
54
+ * @property {{ dns?: string[], email?: string[] }} [subjectAltName] ASCII values.
55
+ * @property {boolean} [subjectKeyIdentifier]
56
+ * @property {boolean} [authorityKeyIdentifier] Needs the issuer key (`signer.publicKey`, or the subject key when self-signed).
57
+ */
58
+
59
+ /**
60
+ * @typedef {object} X509Spec
61
+ * @property {Record<string, string>} subject `{ CN, O, OU, L, ST, C }`, at least one; `C` two upper-case letters.
62
+ * @property {Record<string, string>} [issuer] Defaults to `subject`.
63
+ * @property {Uint8Array} serial Unsigned big-endian, positive, at most 20 encoded octets.
64
+ * @property {Date} notBefore
65
+ * @property {Date} notAfter Later than `notBefore`.
66
+ * @property {X509PublicKey} publicKey The certified key.
67
+ * @property {X509Extensions} [extensions]
68
+ */
69
+
70
+ /**
71
+ * @typedef {object} X509Parsed
72
+ * @property {number} version 1, 2 or 3.
73
+ * @property {Uint8Array} serial Unsigned big-endian.
74
+ * @property {string} signatureAlgorithm `'Ed25519'`, `'ECDSA-SHA256'` or the dotted OID.
75
+ * @property {X509Name} issuer
76
+ * @property {X509Name} subject
77
+ * @property {Date} notBefore
78
+ * @property {Date} notAfter
79
+ * @property {X509PublicKey | { alg: string, key: null, spki: Uint8Array }} publicKey
80
+ * @property {object} extensions The six known ones decoded (each with `critical`), the rest in `other`.
81
+ * @property {Uint8Array} tbs The signed TBSCertificate bytes.
82
+ * @property {Uint8Array} signature
83
+ */
84
+
85
+ /**
86
+ * Public surface of `x509.factory()`.
87
+ * @typedef {object} X509API
88
+ * @property {(spec: X509Spec, signer: X509Signer) => (Uint8Array|false)} create Build and sign a certificate (DER).
89
+ * @property {(der: Uint8Array) => (X509Parsed|false)} parse Read a certificate.
90
+ * @property {(der: Uint8Array, issuerPublicKey: X509PublicKey) => boolean} verify Check the certificate's signature.
91
+ * @property {(der: Uint8Array) => string} toPem PEM `CERTIFICATE` block.
92
+ * @property {(text: string) => (Uint8Array|false)} fromPem DER of the first `CERTIFICATE` block.
93
+ */
94
+
95
+ import { asn1 } from './asn1.js';
96
+ import { keyformat } from './keyformat.js';
97
+ import { pem } from './pem.js';
98
+ import { ed25519 } from '../pkc/ed25519.js';
99
+ import { ecc } from '../pkc/ecc.js';
100
+ import { sha256 } from '../hash/sha256.js';
101
+ import { bitArray } from './bitArray.js';
102
+
103
+ export const x509 = {
104
+ name: 'x509',
105
+ version: '1.0.0',
106
+ type: 'fw.crypto.utils',
107
+ dependencies: ['asn1', 'keyformat', 'pem', 'ed25519', 'ecc', 'sha256', 'bitArray'],
108
+ deps: [asn1, keyformat, pem, ed25519, ecc, sha256, bitArray],
109
+
110
+ /** @returns {X509API} */
111
+ factory(asn1, keyformat, pem, ed25519, ecc, sha256, bitArray) {
112
+
113
+ // ── constants (inside the factory: worker-serialisable) ──────────────
114
+ const OID = {
115
+ ED25519: '1.3.101.112',
116
+ ECDSA_SHA256: '1.2.840.10045.4.3.2',
117
+ EC_PUBKEY: '1.2.840.10045.2.1',
118
+ P256: '1.2.840.10045.3.1.7',
119
+ BASIC_CONSTRAINTS: '2.5.29.19',
120
+ KEY_USAGE: '2.5.29.15',
121
+ EXT_KEY_USAGE: '2.5.29.37',
122
+ SUBJECT_ALT_NAME: '2.5.29.17',
123
+ SUBJECT_KEY_ID: '2.5.29.14',
124
+ AUTHORITY_KEY_ID: '2.5.29.35',
125
+ };
126
+ const NAME_OIDS = { CN: '2.5.4.3', O: '2.5.4.10', OU: '2.5.4.11', L: '2.5.4.7', ST: '2.5.4.8', C: '2.5.4.6' };
127
+ const NAME_BY_OID = Object.fromEntries(Object.entries(NAME_OIDS).map(([k, v]) => [v, k]));
128
+ const KEY_USAGES = ['digitalSignature', 'nonRepudiation', 'keyEncipherment', 'dataEncipherment',
129
+ 'keyAgreement', 'keyCertSign', 'cRLSign', 'encipherOnly', 'decipherOnly'];
130
+ const T = { BOOLEAN: 0x01, INTEGER: 0x02, BIT_STRING: 0x03, OCTET_STRING: 0x04, OID: 0x06,
131
+ UTF8: 0x0c, PRINTABLE: 0x13, TELETEX: 0x14, IA5: 0x16, UTC: 0x17, GENERALIZED: 0x18, BMP: 0x1e,
132
+ SEQUENCE: 0x30, SET: 0x31 };
133
+ const HEX = '0123456789abcdef';
134
+
135
+ /** @param {string} why @returns {false} */
136
+ function bad(why) {
137
+ console.warn('[crypto] INVALID: x509: ' + why);
138
+ return false;
139
+ }
140
+
141
+ /** A thrown marker for a malformed input inside `create` / `parse`. */
142
+ class Invalid extends Error {}
143
+ /** @param {string} why @returns {never} */
144
+ function invalid(why) { throw new Invalid(why); }
145
+ /** @template T @param {T|false} v @param {string} why @returns {T} */
146
+ function must(v, why) { if (v === false || v === null || v === undefined) invalid(why); return /** @type {T} */ (v); }
147
+
148
+ // ── DER pieces asn1 has no encoder for ────────────────────────────────
149
+
150
+ /** One definite-length TLV (X.690 § 8.1.3). */
151
+ function tlv(tag, body) {
152
+ const n = body.length;
153
+ const len = n < 0x80 ? [n]
154
+ : n < 0x100 ? [0x81, n]
155
+ : n < 0x10000 ? [0x82, n >> 8, n & 0xff]
156
+ : [0x83, n >> 16, (n >> 8) & 0xff, n & 0xff];
157
+ const out = new Uint8Array(1 + len.length + n);
158
+ out[0] = tag;
159
+ out.set(len, 1);
160
+ out.set(body, 1 + len.length);
161
+ return out;
162
+ }
163
+ const enc = (s) => new TextEncoder().encode(s);
164
+ const dec = (b) => new TextDecoder('utf-8', { fatal: true }).decode(b);
165
+ const toHex = (b) => { let s = ''; for (const x of b) s += HEX[x >> 4] + HEX[x & 15]; return s; };
166
+ const seq = (items) => must(asn1.encodeSequence(items), 'SEQUENCE');
167
+
168
+ // ── names (RFC 5280 § 4.1.2.4) ────────────────────────────────────────
169
+
170
+ function encodeName(name) {
171
+ if (!name || typeof name !== 'object') invalid('name must be an object');
172
+ const keys = Object.keys(name);
173
+ if (keys.length === 0) invalid('a name needs at least one attribute');
174
+ const rdns = keys.map((k) => {
175
+ const oid = NAME_OIDS[k];
176
+ if (!oid) invalid('unknown name attribute ' + k);
177
+ const v = name[k];
178
+ if (typeof v !== 'string' || v.length === 0 || v.length > 64) invalid('name attribute ' + k + ' must be 1..64 characters');
179
+ let value;
180
+ if (k === 'C') {
181
+ if (!/^[A-Z]{2}$/.test(v)) invalid('C must be two upper-case letters');
182
+ value = tlv(T.PRINTABLE, enc(v));
183
+ } else {
184
+ value = tlv(T.UTF8, enc(v));
185
+ }
186
+ return must(asn1.encodeSet([seq([must(asn1.encodeOid(oid), 'OID'), value])]), 'SET');
187
+ });
188
+ return seq(rdns);
189
+ }
190
+
191
+ function decodeString(node) {
192
+ const v = node.value;
193
+ if (node.tag === T.UTF8) return dec(v);
194
+ if (node.tag === T.PRINTABLE || node.tag === T.IA5) { for (const x of v) if (x > 0x7e) invalid('non-ASCII string'); return dec(v); }
195
+ if (node.tag === T.TELETEX) return String.fromCharCode(...v);
196
+ if (node.tag === T.BMP) {
197
+ if (v.length % 2) invalid('BMPString length');
198
+ let s = ''; for (let i = 0; i < v.length; i += 2) s += String.fromCharCode((v[i] << 8) | v[i + 1]); return s;
199
+ }
200
+ return invalid('unsupported string tag 0x' + node.tag.toString(16));
201
+ }
202
+
203
+ function decodeName(node) {
204
+ if (node.tag !== T.SEQUENCE) invalid('Name is not a SEQUENCE');
205
+ /** @type {X509Name} */
206
+ const out = {};
207
+ for (const rdn of must(asn1.parseChildren(node.value), 'RDN')) {
208
+ if (rdn.tag !== T.SET) invalid('RDN is not a SET');
209
+ for (const atv of must(asn1.parseChildren(rdn.value), 'ATV')) {
210
+ const kv = must(asn1.parseChildren(atv.value), 'ATV');
211
+ if (atv.tag !== T.SEQUENCE || kv.length !== 2) invalid('AttributeTypeAndValue');
212
+ const oid = must(asn1.readOid(kv[0]), 'attribute OID');
213
+ const key = NAME_BY_OID[oid] || oid;
214
+ const value = decodeString(kv[1]);
215
+ const prev = out[key];
216
+ out[key] = prev === undefined ? value : [].concat(prev, value);
217
+ }
218
+ }
219
+ return out;
220
+ }
221
+
222
+ // ── time (RFC 5280 § 4.1.2.5) ────────────────────────────────────────
223
+
224
+ function encodeTime(d) {
225
+ if (!(d instanceof Date) || Number.isNaN(d.getTime())) invalid('a validity bound is not a Date');
226
+ const two = (n) => String(n).padStart(2, '0');
227
+ const y = d.getUTCFullYear();
228
+ if (y < 1950 || y > 9999) invalid('year out of range');
229
+ const rest = two(d.getUTCMonth() + 1) + two(d.getUTCDate()) + two(d.getUTCHours()) + two(d.getUTCMinutes()) + two(d.getUTCSeconds()) + 'Z';
230
+ return y < 2050 ? tlv(T.UTC, enc(two(y % 100) + rest)) : tlv(T.GENERALIZED, enc(String(y) + rest));
231
+ }
232
+
233
+ function decodeTime(node) {
234
+ const s = dec(node.value);
235
+ let m;
236
+ let year;
237
+ if (node.tag === T.UTC && (m = /^(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z$/.exec(s))) {
238
+ year = Number(m[1]); year += year < 50 ? 2000 : 1900;
239
+ } else if (node.tag === T.GENERALIZED && (m = /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z$/.exec(s))) {
240
+ year = Number(m[1]);
241
+ } else {
242
+ invalid('malformed time');
243
+ }
244
+ const t = Date.UTC(year, Number(m[2]) - 1, Number(m[3]), Number(m[4]), Number(m[5]), Number(m[6]));
245
+ return new Date(t);
246
+ }
247
+
248
+ // ── keys ──────────────────────────────────────────────────────────────
249
+
250
+ /** The public point, validated on the curve and in the subgroup. */
251
+ function ecPublic(point) {
252
+ if (!(point instanceof Uint8Array) || point.length !== 65 || point[0] !== 0x04) invalid('ECDSA-P256 public key must be 65 bytes 04 || X || Y');
253
+ return must(ecc.deserialize({ type: 'ecdsa', secretKey: false, curve: 'c256', point: toHex(point.subarray(1)) }), 'ECDSA-P256 point not on the curve');
254
+ }
255
+
256
+ function encodeSpki(pub) {
257
+ if (!pub || typeof pub !== 'object') invalid('publicKey must be { alg, key }');
258
+ if (pub.alg === 'Ed25519') {
259
+ if (!(pub.key instanceof Uint8Array) || pub.key.length !== 32) invalid('Ed25519 public key must be 32 bytes');
260
+ return must(keyformat.encodeSpkiEdwards(OID.ED25519, pub.key), 'SPKI');
261
+ }
262
+ if (pub.alg === 'ECDSA-P256') {
263
+ ecPublic(pub.key);
264
+ return must(keyformat.encodeSpkiEc(OID.P256, pub.key), 'SPKI');
265
+ }
266
+ return invalid('unknown key algorithm ' + pub.alg);
267
+ }
268
+
269
+ /** The subjectPublicKey BIT STRING contents of an SPKI (the key id's input). */
270
+ function spkiKeyBits(spki) {
271
+ const kids = must(asn1.parseChildren(must(asn1.parseOne(spki, 0), 'SPKI').value), 'SPKI');
272
+ return must(asn1.readBitString(kids[1]), 'SPKI key').bytes;
273
+ }
274
+
275
+ const keyId = (spki) => bitArray.ba_to_ui8(sha256.hash(bitArray.ui8_to_ba(spkiKeyBits(spki)))).subarray(0, 20);
276
+
277
+ function sigAlgOf(alg) {
278
+ if (alg === 'Ed25519') return seq([must(asn1.encodeOid(OID.ED25519), 'OID')]);
279
+ if (alg === 'ECDSA-P256') return seq([must(asn1.encodeOid(OID.ECDSA_SHA256), 'OID')]);
280
+ return invalid('unknown signer algorithm ' + alg);
281
+ }
282
+
283
+ function sign(signer, tbs) {
284
+ if (!signer || typeof signer !== 'object') invalid('signer must be { alg, privateKey }');
285
+ if (signer.alg === 'Ed25519') {
286
+ if (!(signer.privateKey instanceof Uint8Array) || signer.privateKey.length !== 64) invalid('Ed25519 private key must be 64 bytes (seed || public key)');
287
+ return must(ed25519.sign(signer.privateKey, tbs), 'Ed25519 signing failed');
288
+ }
289
+ if (signer.alg === 'ECDSA-P256') {
290
+ const d = signer.privateKey;
291
+ if (!(d instanceof Uint8Array) || d.length !== 32 || d.every((x) => x === 0)) invalid('ECDSA-P256 private key must be a non-zero 32-byte scalar');
292
+ const sec = must(ecc.deserialize({ type: 'ecdsa', secretKey: true, curve: 'c256', exponent: toHex(d) }), 'ECDSA-P256 private key');
293
+ const rs = bitArray.ba_to_ui8(sec.sign(sha256.hash(bitArray.ui8_to_ba(tbs)), {})); // RFC 6979
294
+ if (rs.length !== 64) invalid('ECDSA signature length');
295
+ return seq([must(asn1.encodeInteger(rs.subarray(0, 32)), 'r'), must(asn1.encodeInteger(rs.subarray(32)), 's')]);
296
+ }
297
+ return invalid('unknown signer algorithm ' + signer.alg);
298
+ }
299
+
300
+ // ── extensions (RFC 5280 § 4.2) ───────────────────────────────────────
301
+
302
+ function extension(oid, critical, value) {
303
+ const parts = [must(asn1.encodeOid(oid), 'OID')];
304
+ if (critical) parts.push(tlv(T.BOOLEAN, Uint8Array.of(0xff)));
305
+ parts.push(must(asn1.encodeOctetString(value), 'OCTET STRING'));
306
+ return seq(parts);
307
+ }
308
+
309
+ function encodeExtensions(x, spki, issuerSpki) {
310
+ if (x === undefined) return null;
311
+ if (!x || typeof x !== 'object') invalid('extensions must be an object');
312
+ const out = [];
313
+ if (x.basicConstraints !== undefined) {
314
+ const bc = x.basicConstraints;
315
+ if (!bc || typeof bc.ca !== 'boolean') invalid('basicConstraints needs ca');
316
+ const body = [];
317
+ if (bc.ca) body.push(tlv(T.BOOLEAN, Uint8Array.of(0xff)));
318
+ if (bc.pathLen !== undefined) {
319
+ if (!bc.ca) invalid('pathLen is only allowed with ca');
320
+ if (!Number.isInteger(bc.pathLen) || bc.pathLen < 0) invalid('pathLen must be a non-negative integer');
321
+ body.push(must(asn1.encodeInteger(bc.pathLen), 'pathLen'));
322
+ }
323
+ out.push(extension(OID.BASIC_CONSTRAINTS, true, seq(body)));
324
+ }
325
+ if (x.keyUsage !== undefined) {
326
+ if (!Array.isArray(x.keyUsage) || x.keyUsage.length === 0) invalid('keyUsage must be a non-empty array');
327
+ let high = -1;
328
+ const bits = new Array(9).fill(0);
329
+ for (const u of x.keyUsage) {
330
+ const i = KEY_USAGES.indexOf(u);
331
+ if (i < 0) invalid('unknown key usage ' + u);
332
+ bits[i] = 1;
333
+ high = Math.max(high, i);
334
+ }
335
+ const n = high + 1;
336
+ const bytes = new Uint8Array(Math.ceil(n / 8));
337
+ for (let i = 0; i < n; i++) if (bits[i]) bytes[i >> 3] |= 0x80 >> (i & 7);
338
+ out.push(extension(OID.KEY_USAGE, true, must(asn1.encodeBitString(bytes, bytes.length * 8 - n), 'keyUsage')));
339
+ }
340
+ if (x.extKeyUsage !== undefined) {
341
+ if (!Array.isArray(x.extKeyUsage) || x.extKeyUsage.length === 0) invalid('extKeyUsage must be a non-empty array of OIDs');
342
+ out.push(extension(OID.EXT_KEY_USAGE, false, seq(x.extKeyUsage.map((o) => must(asn1.encodeOid(String(o)), 'extKeyUsage OID')))));
343
+ }
344
+ if (x.subjectAltName !== undefined) {
345
+ const san = x.subjectAltName || {};
346
+ /** @type {Array<[number, Uint8Array]>} */
347
+ const names = [];
348
+ /** @type {Array<[string, number]>} */
349
+ const kinds = [['email', 0x81], ['dns', 0x82]];
350
+ for (const [field, tag] of kinds) {
351
+ for (const v of san[field] || []) {
352
+ if (typeof v !== 'string' || !/^[\x21-\x7e]+$/.test(v)) invalid('subjectAltName values are ASCII without spaces');
353
+ names.push([tag, tlv(tag, enc(v))]);
354
+ }
355
+ }
356
+ if (names.length === 0) invalid('subjectAltName needs a DNS name or an email');
357
+ names.sort((a, b) => b[0] - a[0]); // dNSName [2] first, as written by most tools
358
+ out.push(extension(OID.SUBJECT_ALT_NAME, false, seq(names.map((n) => n[1]))));
359
+ }
360
+ if (x.subjectKeyIdentifier) {
361
+ out.push(extension(OID.SUBJECT_KEY_ID, false, must(asn1.encodeOctetString(keyId(spki)), 'SKI')));
362
+ }
363
+ if (x.authorityKeyIdentifier) {
364
+ if (!issuerSpki) invalid('authorityKeyIdentifier needs the issuer key (signer.publicKey)');
365
+ out.push(extension(OID.AUTHORITY_KEY_ID, false, seq([tlv(0x80, keyId(issuerSpki))])));
366
+ }
367
+ return out.length ? must(asn1.encodeExplicit(3, seq(out)), 'extensions') : null;
368
+ }
369
+
370
+ function decodeExtensions(node) {
371
+ const out = { other: [] };
372
+ const list = must(asn1.parseChildren(node.value), 'extensions');
373
+ if (list.length !== 1 || list[0].tag !== T.SEQUENCE) invalid('extensions');
374
+ for (const ext of must(asn1.parseChildren(list[0].value), 'extensions')) {
375
+ const k = must(asn1.parseChildren(ext.value), 'Extension');
376
+ const oid = must(asn1.readOid(k[0]), 'extnID');
377
+ let i = 1;
378
+ let critical = false;
379
+ if (k[i] && k[i].tag === T.BOOLEAN) { critical = k[i].value[0] !== 0; i++; }
380
+ if (!k[i] || k[i].tag !== T.OCTET_STRING || i + 1 !== k.length) invalid('Extension');
381
+ const inner = k[i].value;
382
+ const kids = () => must(asn1.parseChildren(must(asn1.parseOne(inner, 0), 'extnValue').value), 'extnValue');
383
+ if (oid === OID.BASIC_CONSTRAINTS) {
384
+ const c = kids();
385
+ const bc = { ca: false };
386
+ for (const e of c) {
387
+ if (e.tag === T.BOOLEAN) bc.ca = e.value[0] !== 0;
388
+ else if (e.tag === T.INTEGER) bc.pathLen = e.value.reduce((n, b) => n * 256 + b, 0);
389
+ }
390
+ out.basicConstraints = { ...bc, critical };
391
+ } else if (oid === OID.KEY_USAGE) {
392
+ const bs = must(asn1.readBitString(must(asn1.parseOne(inner, 0), 'keyUsage')), 'keyUsage');
393
+ const usages = KEY_USAGES.filter((_, b) => (bs.bytes[b >> 3] || 0) & (0x80 >> (b & 7)));
394
+ out.keyUsage = { usages, critical };
395
+ } else if (oid === OID.EXT_KEY_USAGE) {
396
+ out.extKeyUsage = { oids: kids().map((e) => must(asn1.readOid(e), 'EKU OID')), critical };
397
+ } else if (oid === OID.SUBJECT_ALT_NAME) {
398
+ const san = { dns: [], email: [], critical };
399
+ for (const g of kids()) {
400
+ if (g.tag === 0x82) san.dns.push(dec(g.value));
401
+ else if (g.tag === 0x81) san.email.push(dec(g.value));
402
+ }
403
+ out.subjectAltName = san;
404
+ } else if (oid === OID.SUBJECT_KEY_ID) {
405
+ out.subjectKeyIdentifier = { keyId: new Uint8Array(must(asn1.parseOne(inner, 0), 'SKI').value), critical };
406
+ } else if (oid === OID.AUTHORITY_KEY_ID) {
407
+ const id = kids().find((e) => e.tag === 0x80);
408
+ out.authorityKeyIdentifier = { keyId: id ? new Uint8Array(id.value) : null, critical };
409
+ } else {
410
+ out.other.push({ oid, critical, value: new Uint8Array(inner) });
411
+ }
412
+ }
413
+ return out;
414
+ }
415
+
416
+ // ── create ────────────────────────────────────────────────────────────
417
+
418
+ function create(spec, signer) {
419
+ try {
420
+ if (!spec || typeof spec !== 'object') invalid('spec must be an object');
421
+ const serial = spec.serial;
422
+ if (!(serial instanceof Uint8Array) || serial.every((x) => x === 0)) invalid('serial must be a positive big-endian integer');
423
+ const serialDer = must(asn1.encodeInteger(serial), 'serial');
424
+ if (serialDer.length - 2 > 20) invalid('serial longer than 20 octets');
425
+ if (!(spec.notBefore instanceof Date) || !(spec.notAfter instanceof Date) || !(spec.notBefore < spec.notAfter)) {
426
+ invalid('notBefore must be a Date before notAfter');
427
+ }
428
+ const alg = signer && signer.alg;
429
+ const sigAlg = sigAlgOf(alg);
430
+ const subject = encodeName(spec.subject);
431
+ const selfSigned = spec.issuer === undefined;
432
+ const issuer = selfSigned ? subject : encodeName(spec.issuer);
433
+ const spki = encodeSpki(spec.publicKey);
434
+ const issuerKey = signer.publicKey ? { alg, key: signer.publicKey } : (selfSigned ? spec.publicKey : null);
435
+ const issuerSpki = issuerKey ? encodeSpki(issuerKey) : null;
436
+ const parts = [
437
+ must(asn1.encodeExplicit(0, must(asn1.encodeInteger(2), 'version')), 'version'),
438
+ serialDer,
439
+ sigAlg,
440
+ issuer,
441
+ seq([encodeTime(spec.notBefore), encodeTime(spec.notAfter)]),
442
+ subject,
443
+ spki,
444
+ ];
445
+ const ext = encodeExtensions(spec.extensions, spki, issuerSpki);
446
+ if (ext) parts.push(ext);
447
+ const tbs = seq(parts);
448
+ const sig = sign(signer, tbs);
449
+ return seq([tbs, sigAlg, must(asn1.encodeBitString(sig, 0), 'signature')]);
450
+ } catch (e) {
451
+ if (e instanceof Invalid) return bad(e.message);
452
+ return bad('create failed: ' + (e && e.message));
453
+ }
454
+ }
455
+
456
+ // ── parse ─────────────────────────────────────────────────────────────
457
+
458
+ /** Split a certificate into its parts; throws `Invalid`. */
459
+ function split(der) {
460
+ if (!(der instanceof Uint8Array)) invalid('DER must be a Uint8Array');
461
+ const top = must(asn1.parseOne(der, 0), 'certificate');
462
+ if (top.tag !== T.SEQUENCE || top.next !== der.length) invalid('certificate is not one SEQUENCE');
463
+ const c = must(asn1.parseChildren(top.value), 'certificate');
464
+ if (c.length !== 3 || c[0].tag !== T.SEQUENCE || c[1].tag !== T.SEQUENCE) invalid('certificate needs tbs, algorithm, signature');
465
+ const sig = must(asn1.readBitString(c[2]), 'signature');
466
+ if (sig.unusedBits !== 0) invalid('signature has unused bits');
467
+ const tbs = top.value.subarray(0, c[0].next);
468
+ const algBytes = top.value.subarray(c[0].next, c[1].next);
469
+ return { c, tbs, algBytes, signature: new Uint8Array(sig.bytes) };
470
+ }
471
+
472
+ function algName(node) {
473
+ const oid = must(asn1.readOid(must(asn1.parseChildren(node.value), 'algorithm')[0]), 'algorithm OID');
474
+ return oid === OID.ED25519 ? 'Ed25519' : oid === OID.ECDSA_SHA256 ? 'ECDSA-SHA256' : oid;
475
+ }
476
+
477
+ /** @returns {X509Parsed['publicKey']} */
478
+ function decodeSpki(node, raw) {
479
+ const k = must(asn1.parseChildren(node.value), 'SPKI');
480
+ const algKids = must(asn1.parseChildren(k[0].value), 'SPKI algorithm');
481
+ const oid = asn1.readOid(algKids[0]);
482
+ if (oid === OID.ED25519) {
483
+ const e = must(keyformat.decodeSpkiEdwards(raw), 'Ed25519 SPKI');
484
+ return /** @type {X509PublicKey} */ ({ alg: 'Ed25519', key: e.publicKey });
485
+ }
486
+ if (oid === OID.EC_PUBKEY && algKids[1] && asn1.readOid(algKids[1]) === OID.P256) {
487
+ const e = must(keyformat.decodeSpkiEc(raw), 'EC SPKI');
488
+ return /** @type {X509PublicKey} */ ({ alg: 'ECDSA-P256', key: e.point });
489
+ }
490
+ return { alg: String(oid), key: null, spki: new Uint8Array(raw) };
491
+ }
492
+
493
+ function parse(der) {
494
+ try {
495
+ const { c, tbs, signature } = split(der);
496
+ const t = must(asn1.parseChildren(c[0].value), 'tbs');
497
+ let i = 0;
498
+ let version = 1;
499
+ if (t[0] && t[0].tag === 0xa0) {
500
+ const v = must(asn1.readInteger(must(asn1.parseOne(t[0].value, 0), 'version')), 'version');
501
+ version = v[v.length - 1] + 1;
502
+ i = 1;
503
+ }
504
+ const serialRaw = must(asn1.readInteger(t[i]), 'serial');
505
+ let s = 0;
506
+ while (s < serialRaw.length - 1 && serialRaw[s] === 0) s++;
507
+ const algo = algName(t[i + 1]);
508
+ const issuer = decodeName(t[i + 2]);
509
+ const validity = must(asn1.parseChildren(t[i + 3].value), 'validity');
510
+ if (validity.length !== 2) invalid('validity');
511
+ const subject = decodeName(t[i + 4]);
512
+ const spkiNode = t[i + 5];
513
+ if (!spkiNode) invalid('subjectPublicKeyInfo');
514
+ const spkiRaw = c[0].value.subarray(t[i + 4].next, spkiNode.next);
515
+ const publicKey = decodeSpki(spkiNode, spkiRaw);
516
+ let extensions = { other: [] };
517
+ for (const extra of t.slice(i + 6)) if (extra.tag === 0xa3) extensions = decodeExtensions(extra);
518
+ return {
519
+ version,
520
+ serial: new Uint8Array(serialRaw.subarray(s)),
521
+ signatureAlgorithm: algo,
522
+ issuer,
523
+ subject,
524
+ notBefore: decodeTime(validity[0]),
525
+ notAfter: decodeTime(validity[1]),
526
+ publicKey,
527
+ extensions,
528
+ tbs: new Uint8Array(tbs),
529
+ signature,
530
+ };
531
+ } catch (e) {
532
+ if (e instanceof Invalid) return bad(e.message);
533
+ return bad('parse failed: ' + (e && e.message));
534
+ }
535
+ }
536
+
537
+ // ── verify ────────────────────────────────────────────────────────────
538
+
539
+ function verify(der, issuerPublicKey) {
540
+ try {
541
+ const { c, tbs, algBytes, signature } = split(der);
542
+ const t = must(asn1.parseChildren(c[0].value), 'tbs');
543
+ const at = t[0] && t[0].tag === 0xa0 ? 2 : 1; // [version] serial signature …
544
+ if (!t[at]) return false;
545
+ const innerBytes = c[0].value.subarray(t[at - 1].next, t[at].next);
546
+ if (innerBytes.length !== algBytes.length || innerBytes.some((b, k) => b !== algBytes[k])) return false; // RFC 5280 § 4.1.1.2
547
+ const alg = algName(c[1]);
548
+ if (!issuerPublicKey || typeof issuerPublicKey !== 'object') return false;
549
+ if (alg === 'Ed25519' && issuerPublicKey.alg === 'Ed25519') {
550
+ if (!(issuerPublicKey.key instanceof Uint8Array) || issuerPublicKey.key.length !== 32 || signature.length !== 64) return false;
551
+ return ed25519.verify(issuerPublicKey.key, signature, tbs) === true;
552
+ }
553
+ if (alg === 'ECDSA-SHA256' && issuerPublicKey.alg === 'ECDSA-P256') {
554
+ const pub = ecPublic(issuerPublicKey.key);
555
+ const top = must(asn1.parseOne(signature, 0), 'ECDSA signature');
556
+ if (top.tag !== T.SEQUENCE || top.next !== signature.length) return false;
557
+ const rs = must(asn1.parseChildren(top.value), 'ECDSA signature');
558
+ if (rs.length !== 2) return false;
559
+ const fixed = new Uint8Array(64);
560
+ for (const [j, node] of rs.entries()) {
561
+ const raw = must(asn1.readInteger(node), 'r / s');
562
+ if (raw[0] & 0x80) return false;
563
+ let z = 0; while (z < raw.length - 1 && raw[z] === 0) z++;
564
+ const v = raw.subarray(z);
565
+ if (v.length > 32) return false;
566
+ fixed.set(v, j * 32 + 32 - v.length);
567
+ }
568
+ return pub.verify(sha256.hash(bitArray.ui8_to_ba(tbs)), bitArray.ui8_to_ba(fixed)) === true;
569
+ }
570
+ return false;
571
+ } catch (e) {
572
+ if (!(e instanceof Invalid)) bad('verify failed: ' + (e && e.message));
573
+ return false;
574
+ }
575
+ }
576
+
577
+ // ── PEM ───────────────────────────────────────────────────────────────
578
+
579
+ function toPem(der) {
580
+ return pem.encode(der, 'CERTIFICATE');
581
+ }
582
+
583
+ function fromPem(text) {
584
+ if (typeof text !== 'string') return bad('PEM must be a string');
585
+ const r = pem.decode(text, 'CERTIFICATE');
586
+ return r ? r.bytes : false;
587
+ }
588
+
589
+ return { create, parse, verify, toPem, fromPem };
590
+ }
591
+ };
@@ -56,7 +56,7 @@
56
56
  * of the 128-bit counter block are the block index, started at 0 by the ABI),
57
57
  * matching the shim's J0-style counter and the package KAT (which references
58
58
  * WebCrypto AES-CTR with `counter = nonce(12)||be32(0)`, `length:32`). The
59
- * indicative "Expected ABI" in the task plan named a 16-byte full-width
59
+ * an earlier ABI draft named a 16-byte full-width
60
60
  * counter; the delivered binary (targets.json + shims/aes.c) is authoritative,
61
61
  * so `encryptCtr`/`decryptCtr` take a 12-byte nonce.
62
62
  *
Binary file
@@ -30,6 +30,12 @@
30
30
  * where `t` = passes (timeCost), `m` = memory in KiB, `p` = lanes
31
31
  * (parallelism). The tag is written to `outPtr` (`outLen` bytes).
32
32
  *
33
+ * Memory: the binary takes the block matrix from linear memory grown for the
34
+ * call (not from its 16 MiB scratch arena), up to a ceiling of 1048576 KiB
35
+ * (1 GiB). Linear memory never shrinks: once grown, it stays allocated for
36
+ * the life of the loaded module and is reused by later calls. `m` above the
37
+ * ceiling is refused here, before the call, with a named error.
38
+ *
33
39
  * Worker-safe: pure factory; `WebAssembly` exists in workers; the binary is
34
40
  * fetched by the package loader (via `import.meta.url`) inside `wasmRuntime`.
35
41
  * ALL constants live inside `factory()` so `factory.toString()` carries no
@@ -40,7 +46,8 @@
40
46
  * Tuning + optional-input parameters for {@link WasmArgon2API.hash}.
41
47
  * @typedef {object} WasmArgon2Options
42
48
  * @property {number} timeCost Passes `t` (≥ 1).
43
- * @property {number} memoryKiB Memory cost `m` in KiB (≥ 8·parallelism).
49
+ * @property {number} memoryKiB Memory cost `m` in KiB (≥ 8·parallelism,
50
+ * ≤ 1048576 — the binary's 1 GiB ceiling).
44
51
  * @property {number} parallelism Lanes `p` (≥ 1).
45
52
  * @property {number} hashLen Output tag length in bytes (4 .. 2^32-1).
46
53
  * @property {Uint8Array} [secret] Optional key `K`.
@@ -86,6 +93,10 @@ export const wasmArgon2 = {
86
93
  // hashLen ∈ [4, 2^32-1] per RFC 9106 §3.1.
87
94
  const _MIN_HASH_LEN = 4;
88
95
  const _MAX_HASH_LEN = 0xffffffff;
96
+ // The binary's memory ceiling: the largest `m` (KiB) it accepts, 1 GiB
97
+ // (shims/argon2.c ARGON2_MAX_MEMORY_KIB). Refused here up front so the
98
+ // caller reads a named cause, not the binary's bare status.
99
+ const _MAX_MEMORY_KIB = 1048576;
89
100
 
90
101
  /**
91
102
  * Whether the WASM tier can run here.
@@ -119,6 +130,11 @@ export const wasmArgon2 = {
119
130
  console.error('[crypto] INVALID: wasmArgon2: memoryKiB must be ≥ 8·parallelism');
120
131
  return false;
121
132
  }
133
+ if (memoryKiB > _MAX_MEMORY_KIB) {
134
+ console.error('[crypto] INVALID: wasmArgon2: memoryKiB above the ceiling of '
135
+ + _MAX_MEMORY_KIB + ' KiB (1 GiB)');
136
+ return false;
137
+ }
122
138
  if (!(hashLen >= _MIN_HASH_LEN && hashLen <= _MAX_HASH_LEN)) {
123
139
  console.error('[crypto] INVALID: wasmArgon2: hashLen must be in [4, 2^32-1]');
124
140
  return false;
Binary file