@factoidal/core 0.1.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 (43) hide show
  1. package/CHANGELOG.md +121 -0
  2. package/LICENSE +201 -0
  3. package/README.md +514 -0
  4. package/browser-wasm.js +872 -0
  5. package/browser.d.ts +514 -0
  6. package/browser.js +2276 -0
  7. package/factoidal-npm-entry.js +32609 -0
  8. package/factoidal-npm-entry.wasm.assets/code-7ac046580f1bbdda8dc6.wasm +0 -0
  9. package/factoidal-npm-entry.wasm.js +455 -0
  10. package/factoidal.js +27560 -0
  11. package/factoidal.wasm.assets/code-bbe6099bfb5b10c4c3ab.wasm +0 -0
  12. package/factoidal.wasm.js +457 -0
  13. package/fn.d.ts +519 -0
  14. package/fn.js +916 -0
  15. package/hacl-init.js +92 -0
  16. package/hacl-wasm/FStar.wasm +0 -0
  17. package/hacl-wasm/Hacl_Bignum.wasm +0 -0
  18. package/hacl-wasm/Hacl_Bignum25519_51.wasm +0 -0
  19. package/hacl-wasm/Hacl_Bignum_Base.wasm +0 -0
  20. package/hacl-wasm/Hacl_Curve25519_51.wasm +0 -0
  21. package/hacl-wasm/Hacl_Ed25519.wasm +0 -0
  22. package/hacl-wasm/Hacl_Ed25519_PrecompTable.wasm +0 -0
  23. package/hacl-wasm/Hacl_Hash_Base.wasm +0 -0
  24. package/hacl-wasm/Hacl_Hash_SHA2.wasm +0 -0
  25. package/hacl-wasm/Hacl_IntTypes_Intrinsics.wasm +0 -0
  26. package/hacl-wasm/LowStar_Endianness.wasm +0 -0
  27. package/hacl-wasm/WasmSupport.wasm +0 -0
  28. package/hacl-wasm/api.js +775 -0
  29. package/hacl-wasm/api.json +3787 -0
  30. package/hacl-wasm/layouts.json +1 -0
  31. package/hacl-wasm/loader.js +568 -0
  32. package/hacl-wasm/shell.js +12 -0
  33. package/index.d.ts +1068 -0
  34. package/index.js +237 -0
  35. package/index.mjs +85 -0
  36. package/lib/api.js +2140 -0
  37. package/lib/engine-js.js +165 -0
  38. package/lib/engine-wasm.js +300 -0
  39. package/package.json +101 -0
  40. package/rdfjs.js +540 -0
  41. package/version.json +101 -0
  42. package/wasm.d.ts +130 -0
  43. package/wasm.js +158 -0
package/hacl-init.js ADDED
@@ -0,0 +1,92 @@
1
+ // hacl-init.js — one-time async initialiser for the HACL* WebAssembly
2
+ // crypto backend used by the VC Data Integrity (eddsa-rdfc-2022) ABI
3
+ // (vcVerify / vcSign / vcSha256Hex etc. on `factoidalNpmEntry`).
4
+ //
5
+ // Why an explicit init step: js_of_ocaml `external` primitives are
6
+ // SYNCHRONOUS, but WebAssembly instantiation is ASYNCHRONOUS. So the
7
+ // consumer initialises the HACL* wasm modules ONCE (await), which stashes
8
+ // the ready HACL* API object on `globalThis.__factoidalHacl`; after that
9
+ // the synchronous `caml_hacl_*` stubs in the bundle (hacl_stubs.js) read
10
+ // that global and call HACL* synchronously — no await on the hot path.
11
+ //
12
+ // Crypto sourcing policy: skills/crypto-policy/SKILL.md. The crypto itself
13
+ // is HACL*'s OWN official WebAssembly build (third_party/hacl-wasm/, the
14
+ // `hacl-wasm` npm artifacts, F*/Low*-verified, KaRaMeL->wasm). This file
15
+ // contains NO cryptographic logic — it only loads the verified modules and
16
+ // drives HACL*'s own vendored `api.js` bindings.
17
+ //
18
+ // Usage (Node):
19
+ // const { initHacl } = require('factoidal/hacl-init.js');
20
+ // await initHacl();
21
+ // require('./factoidal-npm-entry.js'); // sets globalThis.factoidalNpmEntry
22
+ // const r = JSON.parse(globalThis.factoidalNpmEntry.vcEd25519Verify(pk, msg, sig));
23
+ //
24
+ // Usage (browser): serve the `hacl-wasm/` directory next to the page and
25
+ // call `await initHacl({ apiUrl: '/path/to/hacl-wasm/api.js' })`. HACL*'s
26
+ // api.js fetches its own .wasm/.json relative to that URL.
27
+
28
+ 'use strict';
29
+
30
+ // Transitive closure of Ed25519 + SHA-2, in load order. Matches the module
31
+ // subset vendored under third_party/hacl-wasm/ (see PROVENANCE.md).
32
+ var HACL_MODULES = [
33
+ 'WasmSupport', 'FStar', 'LowStar_Endianness',
34
+ 'Hacl_Hash_Base', 'Hacl_Hash_SHA2',
35
+ 'Hacl_IntTypes_Intrinsics', 'Hacl_Bignum_Base', 'Hacl_Bignum',
36
+ 'Hacl_Bignum25519_51', 'Hacl_Curve25519_51',
37
+ 'Hacl_Ed25519_PrecompTable', 'Hacl_Ed25519'
38
+ ];
39
+
40
+ var _initPromise = null;
41
+
42
+ // Load HACL*'s own api.js bindings. In Node we `require` the vendored copy
43
+ // (which reads its .wasm/.json off disk relative to itself). Callers may
44
+ // override with opts.apiPath (Node) or opts.HaclWasm (a pre-required module).
45
+ function _loadHaclWasm(opts) {
46
+ if (opts && opts.HaclWasm) return opts.HaclWasm;
47
+ var path = require('path');
48
+ var candidates = [];
49
+ if (opts && opts.apiPath) candidates.push(opts.apiPath);
50
+ // Packaged layout: hacl-wasm/ sits next to this file.
51
+ candidates.push(path.resolve(__dirname, './hacl-wasm/api.js'));
52
+ // In-repo layout: run directly out of the source tree.
53
+ candidates.push(path.resolve(__dirname, '../../third_party/hacl-wasm/api.js'));
54
+ var lastErr = null;
55
+ for (var i = 0; i < candidates.length; i++) {
56
+ try { return require(candidates[i]); }
57
+ catch (e) { lastErr = e; }
58
+ }
59
+ throw new Error(
60
+ 'hacl-init: could not locate HACL* wasm bindings (api.js). Tried: ' +
61
+ candidates.join(', ') + '. Last error: ' + (lastErr && lastErr.message));
62
+ }
63
+
64
+ /**
65
+ * Initialise the HACL* WebAssembly crypto backend exactly once.
66
+ * Idempotent: repeated calls return the same promise.
67
+ *
68
+ * @param {object} [opts]
69
+ * @param {string} [opts.apiPath] Node: path to a HACL* api.js to require.
70
+ * @param {object} [opts.HaclWasm] Pre-required HACL* module (skips lookup).
71
+ * @param {string[]} [opts.modules] Override the wasm module list.
72
+ * @returns {Promise<object>} the ready HACL* API object.
73
+ */
74
+ function initHacl(opts) {
75
+ if (_initPromise) return _initPromise;
76
+ opts = opts || {};
77
+ _initPromise = (async function () {
78
+ var HaclWasm = _loadHaclWasm(opts);
79
+ var modules = opts.modules || HACL_MODULES;
80
+ var Hacl = await HaclWasm.getInitializedHaclModule(modules);
81
+ globalThis.__factoidalHacl = Hacl;
82
+ return Hacl;
83
+ })();
84
+ return _initPromise;
85
+ }
86
+
87
+ /** True once initHacl() has completed and the backend is live. */
88
+ function haclReady() {
89
+ return !!(typeof globalThis !== 'undefined' && globalThis.__factoidalHacl);
90
+ }
91
+
92
+ module.exports = { initHacl: initHacl, haclReady: haclReady, HACL_MODULES: HACL_MODULES };
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file