@luxfhe/wasm 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,14 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
6
12
  var __copyProps = (to, from, except, desc) => {
7
13
  if (from && typeof from === "object" || typeof from === "function") {
8
14
  for (let key of __getOwnPropNames(from))
@@ -11,14 +17,159 @@ var __copyProps = (to, from, except, desc) => {
11
17
  }
12
18
  return to;
13
19
  };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
15
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
29
 
17
30
  // src/node.ts
18
31
  var node_exports = {};
32
+ __export(node_exports, {
33
+ CompactCiphertextList: () => CompactCiphertextList,
34
+ CompactCiphertextListBuilder: () => CompactCiphertextListBuilder,
35
+ CompactPkeCrs: () => CompactPkeCrs,
36
+ CompactPkePublicParams: () => CompactPkePublicParams,
37
+ TfheCompactPublicKey: () => TfheCompactPublicKey,
38
+ ZkComputeLoad: () => ZkComputeLoad,
39
+ decrypt: () => decrypt,
40
+ default: () => initTFHE,
41
+ encrypt: () => encrypt,
42
+ generateKeys: () => generateKeys,
43
+ getLuxFHE: () => getLuxFHE,
44
+ init: () => init,
45
+ initThreadPool: () => initThreadPool,
46
+ init_panic_hook: () => init_panic_hook
47
+ });
19
48
  module.exports = __toCommonJS(node_exports);
20
- __reExport(node_exports, require("node-tfhe"), module.exports);
49
+ var fs = __toESM(require("fs"), 1);
50
+ var path = __toESM(require("path"), 1);
51
+ var wasmInstance = null;
52
+ var goInstance = null;
53
+ var initPromise = null;
54
+ async function init() {
55
+ if (wasmInstance) return;
56
+ if (initPromise) return initPromise;
57
+ initPromise = (async () => {
58
+ const wasmExecPath = path.join(__dirname, "..", "wasm", "wasm_exec.js");
59
+ require(wasmExecPath);
60
+ const go = new Go();
61
+ goInstance = go;
62
+ const wasmPath = path.join(__dirname, "..", "wasm", "luxfhe.wasm");
63
+ const wasmBuffer = fs.readFileSync(wasmPath);
64
+ const wasmModule = await WebAssembly.compile(wasmBuffer);
65
+ wasmInstance = await WebAssembly.instantiate(wasmModule, go.importObject);
66
+ go.run(wasmInstance);
67
+ })();
68
+ return initPromise;
69
+ }
70
+ function getLuxFHE() {
71
+ if (!wasmInstance) {
72
+ throw new Error("FHE not initialized. Call init() first.");
73
+ }
74
+ return globalThis.luxfhe;
75
+ }
76
+ async function generateKeys() {
77
+ await init();
78
+ const fhe = getLuxFHE();
79
+ return fhe.generateKeys();
80
+ }
81
+ async function encrypt(value, publicKey) {
82
+ await init();
83
+ const fhe = getLuxFHE();
84
+ return fhe.encrypt(value, publicKey);
85
+ }
86
+ async function decrypt(ciphertext, privateKey) {
87
+ await init();
88
+ const fhe = getLuxFHE();
89
+ return fhe.decrypt(ciphertext, privateKey);
90
+ }
91
+ function init_panic_hook() {
92
+ }
93
+ async function initThreadPool(numThreads) {
94
+ }
95
+ var TfheCompactPublicKey = class _TfheCompactPublicKey {
96
+ key;
97
+ constructor(key) {
98
+ this.key = key || new Uint8Array();
99
+ }
100
+ static deserialize(bytes) {
101
+ return new _TfheCompactPublicKey(bytes);
102
+ }
103
+ serialize() {
104
+ return this.key;
105
+ }
106
+ };
107
+ var CompactPkeCrs = class _CompactPkeCrs {
108
+ static from_config(config, maxBits) {
109
+ return new _CompactPkeCrs();
110
+ }
111
+ };
112
+ var CompactPkePublicParams = class _CompactPkePublicParams {
113
+ static new(crs, maxBits) {
114
+ return new _CompactPkePublicParams();
115
+ }
116
+ static deserialize(bytes) {
117
+ return new _CompactPkePublicParams();
118
+ }
119
+ serialize() {
120
+ return new Uint8Array();
121
+ }
122
+ };
123
+ var CompactCiphertextList = class _CompactCiphertextList {
124
+ data;
125
+ constructor(data) {
126
+ this.data = data || new Uint8Array();
127
+ }
128
+ static builder(params) {
129
+ return new CompactCiphertextListBuilder();
130
+ }
131
+ static deserialize(bytes) {
132
+ return new _CompactCiphertextList(bytes);
133
+ }
134
+ serialize() {
135
+ return this.data;
136
+ }
137
+ };
138
+ var CompactCiphertextListBuilder = class {
139
+ push(value) {
140
+ return this;
141
+ }
142
+ build() {
143
+ return new CompactCiphertextList();
144
+ }
145
+ build_with_proof_packed(key, load) {
146
+ return {
147
+ list: new CompactCiphertextList(),
148
+ proof: new Uint8Array()
149
+ };
150
+ }
151
+ };
152
+ var ZkComputeLoad = /* @__PURE__ */ ((ZkComputeLoad2) => {
153
+ ZkComputeLoad2["Proof"] = "Proof";
154
+ ZkComputeLoad2["Verify"] = "Verify";
155
+ return ZkComputeLoad2;
156
+ })(ZkComputeLoad || {});
157
+ async function initTFHE(options) {
158
+ await init();
159
+ }
21
160
  // Annotate the CommonJS export names for ESM import in node:
22
161
  0 && (module.exports = {
23
- ...require("node-tfhe")
162
+ CompactCiphertextList,
163
+ CompactCiphertextListBuilder,
164
+ CompactPkeCrs,
165
+ CompactPkePublicParams,
166
+ TfheCompactPublicKey,
167
+ ZkComputeLoad,
168
+ decrypt,
169
+ encrypt,
170
+ generateKeys,
171
+ getLuxFHE,
172
+ init,
173
+ initThreadPool,
174
+ init_panic_hook
24
175
  });
@@ -1 +1,102 @@
1
- export * from 'node-tfhe';
1
+ /**
2
+ * LuxFHE WASM Node.js bindings
3
+ *
4
+ * Native Go FHE compiled to WebAssembly for Node.js
5
+ * Includes backward-compatible exports for Zama TFHE interface
6
+ */
7
+ /**
8
+ * InitInput type for backward compatibility with Zama TFHE
9
+ */
10
+ type InitInput = string | URL | ArrayBuffer | WebAssembly.Module;
11
+ /**
12
+ * Initialize the FHE WASM module
13
+ */
14
+ declare function init(): Promise<void>;
15
+ /**
16
+ * Get the LuxFHE instance after initialization
17
+ */
18
+ declare function getLuxFHE(): any;
19
+ interface LuxFHEKeys {
20
+ publicKey: Uint8Array;
21
+ privateKey: Uint8Array;
22
+ evaluationKey: Uint8Array;
23
+ }
24
+ /**
25
+ * Generate FHE keys
26
+ */
27
+ declare function generateKeys(): Promise<LuxFHEKeys>;
28
+ /**
29
+ * Encrypt a value
30
+ */
31
+ declare function encrypt(value: number | bigint, publicKey: Uint8Array): Promise<Uint8Array>;
32
+ /**
33
+ * Decrypt a ciphertext
34
+ */
35
+ declare function decrypt(ciphertext: Uint8Array, privateKey: Uint8Array): Promise<bigint>;
36
+ /**
37
+ * Initialize panic hook - stub for Zama compatibility
38
+ */
39
+ declare function init_panic_hook(): void;
40
+ /**
41
+ * Initialize thread pool - stub for Zama compatibility
42
+ */
43
+ declare function initThreadPool(numThreads?: number): Promise<void>;
44
+ /**
45
+ * TfheCompactPublicKey - stub class for Zama compatibility
46
+ */
47
+ declare class TfheCompactPublicKey {
48
+ private key;
49
+ constructor(key?: Uint8Array);
50
+ static deserialize(bytes: Uint8Array): TfheCompactPublicKey;
51
+ serialize(): Uint8Array;
52
+ }
53
+ /**
54
+ * CompactPkeCrs - stub class for Zama compatibility
55
+ */
56
+ declare class CompactPkeCrs {
57
+ static from_config(config: any, maxBits: number): CompactPkeCrs;
58
+ }
59
+ /**
60
+ * CompactPkePublicParams - stub class for Zama compatibility
61
+ */
62
+ declare class CompactPkePublicParams {
63
+ static new(crs: CompactPkeCrs, maxBits: number): CompactPkePublicParams;
64
+ static deserialize(bytes: Uint8Array): CompactPkePublicParams;
65
+ serialize(): Uint8Array;
66
+ }
67
+ /**
68
+ * CompactCiphertextList - stub class for Zama compatibility
69
+ */
70
+ declare class CompactCiphertextList {
71
+ private data;
72
+ constructor(data?: Uint8Array);
73
+ static builder(params: CompactPkePublicParams): CompactCiphertextListBuilder;
74
+ static deserialize(bytes: Uint8Array): CompactCiphertextList;
75
+ serialize(): Uint8Array;
76
+ }
77
+ /**
78
+ * CompactCiphertextListBuilder - stub class for Zama compatibility
79
+ */
80
+ declare class CompactCiphertextListBuilder {
81
+ push(value: any): CompactCiphertextListBuilder;
82
+ build(): CompactCiphertextList;
83
+ build_with_proof_packed(key: TfheCompactPublicKey, load: ZkComputeLoad): {
84
+ list: CompactCiphertextList;
85
+ proof: Uint8Array;
86
+ };
87
+ }
88
+ /**
89
+ * ZkComputeLoad enum - stub for Zama compatibility
90
+ */
91
+ declare enum ZkComputeLoad {
92
+ Proof = "Proof",
93
+ Verify = "Verify"
94
+ }
95
+ /**
96
+ * Default export matching Zama TFHE init signature
97
+ */
98
+ declare function initTFHE(options?: {
99
+ module_or_path?: InitInput;
100
+ }): Promise<void>;
101
+
102
+ export { CompactCiphertextList, CompactCiphertextListBuilder, CompactPkeCrs, CompactPkePublicParams, type InitInput, type LuxFHEKeys, TfheCompactPublicKey, ZkComputeLoad, decrypt, initTFHE as default, encrypt, generateKeys, getLuxFHE, init, initThreadPool, init_panic_hook };
@@ -1 +1,102 @@
1
- export * from 'node-tfhe';
1
+ /**
2
+ * LuxFHE WASM Node.js bindings
3
+ *
4
+ * Native Go FHE compiled to WebAssembly for Node.js
5
+ * Includes backward-compatible exports for Zama TFHE interface
6
+ */
7
+ /**
8
+ * InitInput type for backward compatibility with Zama TFHE
9
+ */
10
+ type InitInput = string | URL | ArrayBuffer | WebAssembly.Module;
11
+ /**
12
+ * Initialize the FHE WASM module
13
+ */
14
+ declare function init(): Promise<void>;
15
+ /**
16
+ * Get the LuxFHE instance after initialization
17
+ */
18
+ declare function getLuxFHE(): any;
19
+ interface LuxFHEKeys {
20
+ publicKey: Uint8Array;
21
+ privateKey: Uint8Array;
22
+ evaluationKey: Uint8Array;
23
+ }
24
+ /**
25
+ * Generate FHE keys
26
+ */
27
+ declare function generateKeys(): Promise<LuxFHEKeys>;
28
+ /**
29
+ * Encrypt a value
30
+ */
31
+ declare function encrypt(value: number | bigint, publicKey: Uint8Array): Promise<Uint8Array>;
32
+ /**
33
+ * Decrypt a ciphertext
34
+ */
35
+ declare function decrypt(ciphertext: Uint8Array, privateKey: Uint8Array): Promise<bigint>;
36
+ /**
37
+ * Initialize panic hook - stub for Zama compatibility
38
+ */
39
+ declare function init_panic_hook(): void;
40
+ /**
41
+ * Initialize thread pool - stub for Zama compatibility
42
+ */
43
+ declare function initThreadPool(numThreads?: number): Promise<void>;
44
+ /**
45
+ * TfheCompactPublicKey - stub class for Zama compatibility
46
+ */
47
+ declare class TfheCompactPublicKey {
48
+ private key;
49
+ constructor(key?: Uint8Array);
50
+ static deserialize(bytes: Uint8Array): TfheCompactPublicKey;
51
+ serialize(): Uint8Array;
52
+ }
53
+ /**
54
+ * CompactPkeCrs - stub class for Zama compatibility
55
+ */
56
+ declare class CompactPkeCrs {
57
+ static from_config(config: any, maxBits: number): CompactPkeCrs;
58
+ }
59
+ /**
60
+ * CompactPkePublicParams - stub class for Zama compatibility
61
+ */
62
+ declare class CompactPkePublicParams {
63
+ static new(crs: CompactPkeCrs, maxBits: number): CompactPkePublicParams;
64
+ static deserialize(bytes: Uint8Array): CompactPkePublicParams;
65
+ serialize(): Uint8Array;
66
+ }
67
+ /**
68
+ * CompactCiphertextList - stub class for Zama compatibility
69
+ */
70
+ declare class CompactCiphertextList {
71
+ private data;
72
+ constructor(data?: Uint8Array);
73
+ static builder(params: CompactPkePublicParams): CompactCiphertextListBuilder;
74
+ static deserialize(bytes: Uint8Array): CompactCiphertextList;
75
+ serialize(): Uint8Array;
76
+ }
77
+ /**
78
+ * CompactCiphertextListBuilder - stub class for Zama compatibility
79
+ */
80
+ declare class CompactCiphertextListBuilder {
81
+ push(value: any): CompactCiphertextListBuilder;
82
+ build(): CompactCiphertextList;
83
+ build_with_proof_packed(key: TfheCompactPublicKey, load: ZkComputeLoad): {
84
+ list: CompactCiphertextList;
85
+ proof: Uint8Array;
86
+ };
87
+ }
88
+ /**
89
+ * ZkComputeLoad enum - stub for Zama compatibility
90
+ */
91
+ declare enum ZkComputeLoad {
92
+ Proof = "Proof",
93
+ Verify = "Verify"
94
+ }
95
+ /**
96
+ * Default export matching Zama TFHE init signature
97
+ */
98
+ declare function initTFHE(options?: {
99
+ module_or_path?: InitInput;
100
+ }): Promise<void>;
101
+
102
+ export { CompactCiphertextList, CompactCiphertextListBuilder, CompactPkeCrs, CompactPkePublicParams, type InitInput, type LuxFHEKeys, TfheCompactPublicKey, ZkComputeLoad, decrypt, initTFHE as default, encrypt, generateKeys, getLuxFHE, init, initThreadPool, init_panic_hook };
@@ -1,2 +1,135 @@
1
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined") return require.apply(this, arguments);
5
+ throw Error('Dynamic require of "' + x + '" is not supported');
6
+ });
7
+
1
8
  // src/node.ts
2
- export * from "node-tfhe";
9
+ import * as fs from "fs";
10
+ import * as path from "path";
11
+ var wasmInstance = null;
12
+ var goInstance = null;
13
+ var initPromise = null;
14
+ async function init() {
15
+ if (wasmInstance) return;
16
+ if (initPromise) return initPromise;
17
+ initPromise = (async () => {
18
+ const wasmExecPath = path.join(__dirname, "..", "wasm", "wasm_exec.js");
19
+ __require(wasmExecPath);
20
+ const go = new Go();
21
+ goInstance = go;
22
+ const wasmPath = path.join(__dirname, "..", "wasm", "luxfhe.wasm");
23
+ const wasmBuffer = fs.readFileSync(wasmPath);
24
+ const wasmModule = await WebAssembly.compile(wasmBuffer);
25
+ wasmInstance = await WebAssembly.instantiate(wasmModule, go.importObject);
26
+ go.run(wasmInstance);
27
+ })();
28
+ return initPromise;
29
+ }
30
+ function getLuxFHE() {
31
+ if (!wasmInstance) {
32
+ throw new Error("FHE not initialized. Call init() first.");
33
+ }
34
+ return globalThis.luxfhe;
35
+ }
36
+ async function generateKeys() {
37
+ await init();
38
+ const fhe = getLuxFHE();
39
+ return fhe.generateKeys();
40
+ }
41
+ async function encrypt(value, publicKey) {
42
+ await init();
43
+ const fhe = getLuxFHE();
44
+ return fhe.encrypt(value, publicKey);
45
+ }
46
+ async function decrypt(ciphertext, privateKey) {
47
+ await init();
48
+ const fhe = getLuxFHE();
49
+ return fhe.decrypt(ciphertext, privateKey);
50
+ }
51
+ function init_panic_hook() {
52
+ }
53
+ async function initThreadPool(numThreads) {
54
+ }
55
+ var TfheCompactPublicKey = class _TfheCompactPublicKey {
56
+ key;
57
+ constructor(key) {
58
+ this.key = key || new Uint8Array();
59
+ }
60
+ static deserialize(bytes) {
61
+ return new _TfheCompactPublicKey(bytes);
62
+ }
63
+ serialize() {
64
+ return this.key;
65
+ }
66
+ };
67
+ var CompactPkeCrs = class _CompactPkeCrs {
68
+ static from_config(config, maxBits) {
69
+ return new _CompactPkeCrs();
70
+ }
71
+ };
72
+ var CompactPkePublicParams = class _CompactPkePublicParams {
73
+ static new(crs, maxBits) {
74
+ return new _CompactPkePublicParams();
75
+ }
76
+ static deserialize(bytes) {
77
+ return new _CompactPkePublicParams();
78
+ }
79
+ serialize() {
80
+ return new Uint8Array();
81
+ }
82
+ };
83
+ var CompactCiphertextList = class _CompactCiphertextList {
84
+ data;
85
+ constructor(data) {
86
+ this.data = data || new Uint8Array();
87
+ }
88
+ static builder(params) {
89
+ return new CompactCiphertextListBuilder();
90
+ }
91
+ static deserialize(bytes) {
92
+ return new _CompactCiphertextList(bytes);
93
+ }
94
+ serialize() {
95
+ return this.data;
96
+ }
97
+ };
98
+ var CompactCiphertextListBuilder = class {
99
+ push(value) {
100
+ return this;
101
+ }
102
+ build() {
103
+ return new CompactCiphertextList();
104
+ }
105
+ build_with_proof_packed(key, load) {
106
+ return {
107
+ list: new CompactCiphertextList(),
108
+ proof: new Uint8Array()
109
+ };
110
+ }
111
+ };
112
+ var ZkComputeLoad = /* @__PURE__ */ ((ZkComputeLoad2) => {
113
+ ZkComputeLoad2["Proof"] = "Proof";
114
+ ZkComputeLoad2["Verify"] = "Verify";
115
+ return ZkComputeLoad2;
116
+ })(ZkComputeLoad || {});
117
+ async function initTFHE(options) {
118
+ await init();
119
+ }
120
+ export {
121
+ CompactCiphertextList,
122
+ CompactCiphertextListBuilder,
123
+ CompactPkeCrs,
124
+ CompactPkePublicParams,
125
+ TfheCompactPublicKey,
126
+ ZkComputeLoad,
127
+ decrypt,
128
+ initTFHE as default,
129
+ encrypt,
130
+ generateKeys,
131
+ getLuxFHE,
132
+ init,
133
+ initThreadPool,
134
+ init_panic_hook
135
+ };
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,26 +15,165 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
19
 
31
20
  // src/web.ts
32
21
  var web_exports = {};
33
22
  __export(web_exports, {
34
- default: () => import_tfhe.default
23
+ CompactCiphertextList: () => CompactCiphertextList,
24
+ CompactCiphertextListBuilder: () => CompactCiphertextListBuilder,
25
+ CompactPkeCrs: () => CompactPkeCrs,
26
+ CompactPkePublicParams: () => CompactPkePublicParams,
27
+ TfheCompactPublicKey: () => TfheCompactPublicKey,
28
+ ZkComputeLoad: () => ZkComputeLoad,
29
+ decrypt: () => decrypt,
30
+ default: () => initTFHE,
31
+ encrypt: () => encrypt,
32
+ generateKeys: () => generateKeys,
33
+ getLuxFHE: () => getLuxFHE,
34
+ init: () => init,
35
+ initThreadPool: () => initThreadPool,
36
+ init_panic_hook: () => init_panic_hook
35
37
  });
36
38
  module.exports = __toCommonJS(web_exports);
37
- __reExport(web_exports, require("tfhe"), module.exports);
38
- var import_tfhe = __toESM(require("tfhe"), 1);
39
+ var import_meta = {};
40
+ var wasmInstance = null;
41
+ var goInstance = null;
42
+ var initPromise = null;
43
+ async function init(wasmUrl) {
44
+ if (wasmInstance) return;
45
+ if (initPromise) return initPromise;
46
+ initPromise = (async () => {
47
+ if (typeof Go === "undefined") {
48
+ await loadScript(new URL("../wasm/wasm_exec.js", import_meta.url).href);
49
+ }
50
+ const go = new Go();
51
+ goInstance = go;
52
+ const wasmPath = wasmUrl || new URL("../wasm/luxfhe.wasm", import_meta.url).href;
53
+ const response = await fetch(wasmPath);
54
+ const wasmBuffer = await response.arrayBuffer();
55
+ const wasmModule = await WebAssembly.compile(wasmBuffer);
56
+ wasmInstance = await WebAssembly.instantiate(wasmModule, go.importObject);
57
+ go.run(wasmInstance);
58
+ })();
59
+ return initPromise;
60
+ }
61
+ function loadScript(src) {
62
+ return new Promise((resolve, reject) => {
63
+ const script = document.createElement("script");
64
+ script.src = src;
65
+ script.onload = () => resolve();
66
+ script.onerror = reject;
67
+ document.head.appendChild(script);
68
+ });
69
+ }
70
+ function getLuxFHE() {
71
+ if (!wasmInstance) {
72
+ throw new Error("FHE not initialized. Call init() first.");
73
+ }
74
+ return globalThis.luxfhe;
75
+ }
76
+ async function generateKeys() {
77
+ await init();
78
+ const fhe = getLuxFHE();
79
+ return fhe.generateKeys();
80
+ }
81
+ async function encrypt(value, publicKey) {
82
+ await init();
83
+ const fhe = getLuxFHE();
84
+ return fhe.encrypt(value, publicKey);
85
+ }
86
+ async function decrypt(ciphertext, privateKey) {
87
+ await init();
88
+ const fhe = getLuxFHE();
89
+ return fhe.decrypt(ciphertext, privateKey);
90
+ }
91
+ function init_panic_hook() {
92
+ }
93
+ async function initThreadPool(numThreads) {
94
+ }
95
+ var TfheCompactPublicKey = class _TfheCompactPublicKey {
96
+ key;
97
+ constructor(key) {
98
+ this.key = key || new Uint8Array();
99
+ }
100
+ static deserialize(bytes) {
101
+ return new _TfheCompactPublicKey(bytes);
102
+ }
103
+ serialize() {
104
+ return this.key;
105
+ }
106
+ };
107
+ var CompactPkeCrs = class _CompactPkeCrs {
108
+ static from_config(config, maxBits) {
109
+ return new _CompactPkeCrs();
110
+ }
111
+ };
112
+ var CompactPkePublicParams = class _CompactPkePublicParams {
113
+ static new(crs, maxBits) {
114
+ return new _CompactPkePublicParams();
115
+ }
116
+ static deserialize(bytes) {
117
+ return new _CompactPkePublicParams();
118
+ }
119
+ serialize() {
120
+ return new Uint8Array();
121
+ }
122
+ };
123
+ var CompactCiphertextList = class _CompactCiphertextList {
124
+ data;
125
+ constructor(data) {
126
+ this.data = data || new Uint8Array();
127
+ }
128
+ static builder(params) {
129
+ return new CompactCiphertextListBuilder();
130
+ }
131
+ static deserialize(bytes) {
132
+ return new _CompactCiphertextList(bytes);
133
+ }
134
+ serialize() {
135
+ return this.data;
136
+ }
137
+ };
138
+ var CompactCiphertextListBuilder = class {
139
+ push(value) {
140
+ return this;
141
+ }
142
+ build() {
143
+ return new CompactCiphertextList();
144
+ }
145
+ build_with_proof_packed(key, load) {
146
+ return {
147
+ list: new CompactCiphertextList(),
148
+ proof: new Uint8Array()
149
+ };
150
+ }
151
+ };
152
+ var ZkComputeLoad = /* @__PURE__ */ ((ZkComputeLoad2) => {
153
+ ZkComputeLoad2["Proof"] = "Proof";
154
+ ZkComputeLoad2["Verify"] = "Verify";
155
+ return ZkComputeLoad2;
156
+ })(ZkComputeLoad || {});
157
+ async function initTFHE(options) {
158
+ if (options?.module_or_path && typeof options.module_or_path === "string") {
159
+ await init(options.module_or_path);
160
+ } else {
161
+ await init();
162
+ }
163
+ }
39
164
  // Annotate the CommonJS export names for ESM import in node:
40
165
  0 && (module.exports = {
41
- ...require("tfhe")
166
+ CompactCiphertextList,
167
+ CompactCiphertextListBuilder,
168
+ CompactPkeCrs,
169
+ CompactPkePublicParams,
170
+ TfheCompactPublicKey,
171
+ ZkComputeLoad,
172
+ decrypt,
173
+ encrypt,
174
+ generateKeys,
175
+ getLuxFHE,
176
+ init,
177
+ initThreadPool,
178
+ init_panic_hook
42
179
  });
@@ -1,2 +1,102 @@
1
- export * from 'tfhe';
2
- export { default } from 'tfhe';
1
+ /**
2
+ * LuxFHE WASM Web bindings
3
+ *
4
+ * Native Go FHE compiled to WebAssembly for browser
5
+ * Includes backward-compatible exports for Zama TFHE interface
6
+ */
7
+ /**
8
+ * InitInput type for backward compatibility with Zama TFHE
9
+ */
10
+ type InitInput = string | URL | Request | Response | ArrayBuffer | WebAssembly.Module;
11
+ /**
12
+ * Initialize the FHE WASM module
13
+ */
14
+ declare function init(wasmUrl?: string): Promise<void>;
15
+ /**
16
+ * Get the LuxFHE instance after initialization
17
+ */
18
+ declare function getLuxFHE(): any;
19
+ interface LuxFHEKeys {
20
+ publicKey: Uint8Array;
21
+ privateKey: Uint8Array;
22
+ evaluationKey: Uint8Array;
23
+ }
24
+ /**
25
+ * Generate FHE keys
26
+ */
27
+ declare function generateKeys(): Promise<LuxFHEKeys>;
28
+ /**
29
+ * Encrypt a value
30
+ */
31
+ declare function encrypt(value: number | bigint, publicKey: Uint8Array): Promise<Uint8Array>;
32
+ /**
33
+ * Decrypt a ciphertext
34
+ */
35
+ declare function decrypt(ciphertext: Uint8Array, privateKey: Uint8Array): Promise<bigint>;
36
+ /**
37
+ * Initialize panic hook - stub for Zama compatibility
38
+ */
39
+ declare function init_panic_hook(): void;
40
+ /**
41
+ * Initialize thread pool - stub for Zama compatibility
42
+ */
43
+ declare function initThreadPool(numThreads?: number): Promise<void>;
44
+ /**
45
+ * TfheCompactPublicKey - stub class for Zama compatibility
46
+ */
47
+ declare class TfheCompactPublicKey {
48
+ private key;
49
+ constructor(key?: Uint8Array);
50
+ static deserialize(bytes: Uint8Array): TfheCompactPublicKey;
51
+ serialize(): Uint8Array;
52
+ }
53
+ /**
54
+ * CompactPkeCrs - stub class for Zama compatibility
55
+ */
56
+ declare class CompactPkeCrs {
57
+ static from_config(config: any, maxBits: number): CompactPkeCrs;
58
+ }
59
+ /**
60
+ * CompactPkePublicParams - stub class for Zama compatibility
61
+ */
62
+ declare class CompactPkePublicParams {
63
+ static new(crs: CompactPkeCrs, maxBits: number): CompactPkePublicParams;
64
+ static deserialize(bytes: Uint8Array): CompactPkePublicParams;
65
+ serialize(): Uint8Array;
66
+ }
67
+ /**
68
+ * CompactCiphertextList - stub class for Zama compatibility
69
+ */
70
+ declare class CompactCiphertextList {
71
+ private data;
72
+ constructor(data?: Uint8Array);
73
+ static builder(params: CompactPkePublicParams): CompactCiphertextListBuilder;
74
+ static deserialize(bytes: Uint8Array): CompactCiphertextList;
75
+ serialize(): Uint8Array;
76
+ }
77
+ /**
78
+ * CompactCiphertextListBuilder - stub class for Zama compatibility
79
+ */
80
+ declare class CompactCiphertextListBuilder {
81
+ push(value: any): CompactCiphertextListBuilder;
82
+ build(): CompactCiphertextList;
83
+ build_with_proof_packed(key: TfheCompactPublicKey, load: ZkComputeLoad): {
84
+ list: CompactCiphertextList;
85
+ proof: Uint8Array;
86
+ };
87
+ }
88
+ /**
89
+ * ZkComputeLoad enum - stub for Zama compatibility
90
+ */
91
+ declare enum ZkComputeLoad {
92
+ Proof = "Proof",
93
+ Verify = "Verify"
94
+ }
95
+ /**
96
+ * Default export matching Zama TFHE init signature
97
+ */
98
+ declare function initTFHE(options?: {
99
+ module_or_path?: InitInput;
100
+ }): Promise<void>;
101
+
102
+ export { CompactCiphertextList, CompactCiphertextListBuilder, CompactPkeCrs, CompactPkePublicParams, type InitInput, type LuxFHEKeys, TfheCompactPublicKey, ZkComputeLoad, decrypt, initTFHE as default, encrypt, generateKeys, getLuxFHE, init, initThreadPool, init_panic_hook };
@@ -1,2 +1,102 @@
1
- export * from 'tfhe';
2
- export { default } from 'tfhe';
1
+ /**
2
+ * LuxFHE WASM Web bindings
3
+ *
4
+ * Native Go FHE compiled to WebAssembly for browser
5
+ * Includes backward-compatible exports for Zama TFHE interface
6
+ */
7
+ /**
8
+ * InitInput type for backward compatibility with Zama TFHE
9
+ */
10
+ type InitInput = string | URL | Request | Response | ArrayBuffer | WebAssembly.Module;
11
+ /**
12
+ * Initialize the FHE WASM module
13
+ */
14
+ declare function init(wasmUrl?: string): Promise<void>;
15
+ /**
16
+ * Get the LuxFHE instance after initialization
17
+ */
18
+ declare function getLuxFHE(): any;
19
+ interface LuxFHEKeys {
20
+ publicKey: Uint8Array;
21
+ privateKey: Uint8Array;
22
+ evaluationKey: Uint8Array;
23
+ }
24
+ /**
25
+ * Generate FHE keys
26
+ */
27
+ declare function generateKeys(): Promise<LuxFHEKeys>;
28
+ /**
29
+ * Encrypt a value
30
+ */
31
+ declare function encrypt(value: number | bigint, publicKey: Uint8Array): Promise<Uint8Array>;
32
+ /**
33
+ * Decrypt a ciphertext
34
+ */
35
+ declare function decrypt(ciphertext: Uint8Array, privateKey: Uint8Array): Promise<bigint>;
36
+ /**
37
+ * Initialize panic hook - stub for Zama compatibility
38
+ */
39
+ declare function init_panic_hook(): void;
40
+ /**
41
+ * Initialize thread pool - stub for Zama compatibility
42
+ */
43
+ declare function initThreadPool(numThreads?: number): Promise<void>;
44
+ /**
45
+ * TfheCompactPublicKey - stub class for Zama compatibility
46
+ */
47
+ declare class TfheCompactPublicKey {
48
+ private key;
49
+ constructor(key?: Uint8Array);
50
+ static deserialize(bytes: Uint8Array): TfheCompactPublicKey;
51
+ serialize(): Uint8Array;
52
+ }
53
+ /**
54
+ * CompactPkeCrs - stub class for Zama compatibility
55
+ */
56
+ declare class CompactPkeCrs {
57
+ static from_config(config: any, maxBits: number): CompactPkeCrs;
58
+ }
59
+ /**
60
+ * CompactPkePublicParams - stub class for Zama compatibility
61
+ */
62
+ declare class CompactPkePublicParams {
63
+ static new(crs: CompactPkeCrs, maxBits: number): CompactPkePublicParams;
64
+ static deserialize(bytes: Uint8Array): CompactPkePublicParams;
65
+ serialize(): Uint8Array;
66
+ }
67
+ /**
68
+ * CompactCiphertextList - stub class for Zama compatibility
69
+ */
70
+ declare class CompactCiphertextList {
71
+ private data;
72
+ constructor(data?: Uint8Array);
73
+ static builder(params: CompactPkePublicParams): CompactCiphertextListBuilder;
74
+ static deserialize(bytes: Uint8Array): CompactCiphertextList;
75
+ serialize(): Uint8Array;
76
+ }
77
+ /**
78
+ * CompactCiphertextListBuilder - stub class for Zama compatibility
79
+ */
80
+ declare class CompactCiphertextListBuilder {
81
+ push(value: any): CompactCiphertextListBuilder;
82
+ build(): CompactCiphertextList;
83
+ build_with_proof_packed(key: TfheCompactPublicKey, load: ZkComputeLoad): {
84
+ list: CompactCiphertextList;
85
+ proof: Uint8Array;
86
+ };
87
+ }
88
+ /**
89
+ * ZkComputeLoad enum - stub for Zama compatibility
90
+ */
91
+ declare enum ZkComputeLoad {
92
+ Proof = "Proof",
93
+ Verify = "Verify"
94
+ }
95
+ /**
96
+ * Default export matching Zama TFHE init signature
97
+ */
98
+ declare function initTFHE(options?: {
99
+ module_or_path?: InitInput;
100
+ }): Promise<void>;
101
+
102
+ export { CompactCiphertextList, CompactCiphertextListBuilder, CompactPkeCrs, CompactPkePublicParams, type InitInput, type LuxFHEKeys, TfheCompactPublicKey, ZkComputeLoad, decrypt, initTFHE as default, encrypt, generateKeys, getLuxFHE, init, initThreadPool, init_panic_hook };
package/dist/web/index.js CHANGED
@@ -1,6 +1,141 @@
1
1
  // src/web.ts
2
- export * from "tfhe";
3
- import { default as default2 } from "tfhe";
2
+ var wasmInstance = null;
3
+ var goInstance = null;
4
+ var initPromise = null;
5
+ async function init(wasmUrl) {
6
+ if (wasmInstance) return;
7
+ if (initPromise) return initPromise;
8
+ initPromise = (async () => {
9
+ if (typeof Go === "undefined") {
10
+ await loadScript(new URL("../wasm/wasm_exec.js", import.meta.url).href);
11
+ }
12
+ const go = new Go();
13
+ goInstance = go;
14
+ const wasmPath = wasmUrl || new URL("../wasm/luxfhe.wasm", import.meta.url).href;
15
+ const response = await fetch(wasmPath);
16
+ const wasmBuffer = await response.arrayBuffer();
17
+ const wasmModule = await WebAssembly.compile(wasmBuffer);
18
+ wasmInstance = await WebAssembly.instantiate(wasmModule, go.importObject);
19
+ go.run(wasmInstance);
20
+ })();
21
+ return initPromise;
22
+ }
23
+ function loadScript(src) {
24
+ return new Promise((resolve, reject) => {
25
+ const script = document.createElement("script");
26
+ script.src = src;
27
+ script.onload = () => resolve();
28
+ script.onerror = reject;
29
+ document.head.appendChild(script);
30
+ });
31
+ }
32
+ function getLuxFHE() {
33
+ if (!wasmInstance) {
34
+ throw new Error("FHE not initialized. Call init() first.");
35
+ }
36
+ return globalThis.luxfhe;
37
+ }
38
+ async function generateKeys() {
39
+ await init();
40
+ const fhe = getLuxFHE();
41
+ return fhe.generateKeys();
42
+ }
43
+ async function encrypt(value, publicKey) {
44
+ await init();
45
+ const fhe = getLuxFHE();
46
+ return fhe.encrypt(value, publicKey);
47
+ }
48
+ async function decrypt(ciphertext, privateKey) {
49
+ await init();
50
+ const fhe = getLuxFHE();
51
+ return fhe.decrypt(ciphertext, privateKey);
52
+ }
53
+ function init_panic_hook() {
54
+ }
55
+ async function initThreadPool(numThreads) {
56
+ }
57
+ var TfheCompactPublicKey = class _TfheCompactPublicKey {
58
+ key;
59
+ constructor(key) {
60
+ this.key = key || new Uint8Array();
61
+ }
62
+ static deserialize(bytes) {
63
+ return new _TfheCompactPublicKey(bytes);
64
+ }
65
+ serialize() {
66
+ return this.key;
67
+ }
68
+ };
69
+ var CompactPkeCrs = class _CompactPkeCrs {
70
+ static from_config(config, maxBits) {
71
+ return new _CompactPkeCrs();
72
+ }
73
+ };
74
+ var CompactPkePublicParams = class _CompactPkePublicParams {
75
+ static new(crs, maxBits) {
76
+ return new _CompactPkePublicParams();
77
+ }
78
+ static deserialize(bytes) {
79
+ return new _CompactPkePublicParams();
80
+ }
81
+ serialize() {
82
+ return new Uint8Array();
83
+ }
84
+ };
85
+ var CompactCiphertextList = class _CompactCiphertextList {
86
+ data;
87
+ constructor(data) {
88
+ this.data = data || new Uint8Array();
89
+ }
90
+ static builder(params) {
91
+ return new CompactCiphertextListBuilder();
92
+ }
93
+ static deserialize(bytes) {
94
+ return new _CompactCiphertextList(bytes);
95
+ }
96
+ serialize() {
97
+ return this.data;
98
+ }
99
+ };
100
+ var CompactCiphertextListBuilder = class {
101
+ push(value) {
102
+ return this;
103
+ }
104
+ build() {
105
+ return new CompactCiphertextList();
106
+ }
107
+ build_with_proof_packed(key, load) {
108
+ return {
109
+ list: new CompactCiphertextList(),
110
+ proof: new Uint8Array()
111
+ };
112
+ }
113
+ };
114
+ var ZkComputeLoad = /* @__PURE__ */ ((ZkComputeLoad2) => {
115
+ ZkComputeLoad2["Proof"] = "Proof";
116
+ ZkComputeLoad2["Verify"] = "Verify";
117
+ return ZkComputeLoad2;
118
+ })(ZkComputeLoad || {});
119
+ async function initTFHE(options) {
120
+ if (options?.module_or_path && typeof options.module_or_path === "string") {
121
+ await init(options.module_or_path);
122
+ } else {
123
+ await init();
124
+ }
125
+ }
4
126
  export {
5
- default2 as default
127
+ CompactCiphertextList,
128
+ CompactCiphertextListBuilder,
129
+ CompactPkeCrs,
130
+ CompactPkePublicParams,
131
+ TfheCompactPublicKey,
132
+ ZkComputeLoad,
133
+ decrypt,
134
+ initTFHE as default,
135
+ encrypt,
136
+ generateKeys,
137
+ getLuxFHE,
138
+ init,
139
+ initThreadPool,
140
+ init_panic_hook
6
141
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@luxfhe/wasm",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "LuxFHE Go WASM bindings for web and node",
5
5
  "type": "module",
6
6
  "main": "./dist/node/index.js",
@@ -28,7 +28,8 @@
28
28
  "types": "./dist/web/index.d.ts",
29
29
  "import": "./dist/web/index.js",
30
30
  "require": "./dist/web/index.cjs"
31
- }
31
+ },
32
+ "./package.json": "./package.json"
32
33
  },
33
34
  "files": [
34
35
  "dist"
@@ -37,10 +38,11 @@
37
38
  "build:wasm": "cd ~/work/lux/fhe && GOOS=js GOARCH=wasm go build -o sdk/wasm/luxfhe.wasm ./sdk/wasm/",
38
39
  "build:copy": "cp ~/work/lux/fhe/sdk/wasm/luxfhe.wasm wasm/ && cp $(go env GOROOT)/lib/wasm/wasm_exec.js wasm/",
39
40
  "build:ts": "tsup",
40
- "build": "pnpm build:copy && pnpm build:ts"
41
+ "build": "npm run build:ts"
41
42
  },
42
43
  "dependencies": {},
43
44
  "devDependencies": {
45
+ "@types/node": "^20.0.0",
44
46
  "tsup": "^8.0.0",
45
47
  "typescript": "^5.0.0"
46
48
  },