@luxfhe/wasm 0.1.3 → 0.2.1
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.
- package/dist/node/index.cjs +71 -3
- package/dist/node/index.d.cts +39 -1
- package/dist/node/index.d.ts +39 -1
- package/dist/node/index.js +59 -1
- package/dist/web/index.cjs +70 -15
- package/dist/web/index.d.cts +39 -2
- package/dist/web/index.d.ts +39 -2
- package/dist/web/index.js +64 -3
- package/package.json +10 -8
package/dist/node/index.cjs
CHANGED
|
@@ -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,76 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
11
17
|
}
|
|
12
18
|
return to;
|
|
13
19
|
};
|
|
14
|
-
var
|
|
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
|
+
decrypt: () => decrypt,
|
|
34
|
+
default: () => node_default,
|
|
35
|
+
encrypt: () => encrypt,
|
|
36
|
+
generateKeys: () => generateKeys,
|
|
37
|
+
getLuxFHE: () => getLuxFHE,
|
|
38
|
+
init: () => init
|
|
39
|
+
});
|
|
19
40
|
module.exports = __toCommonJS(node_exports);
|
|
20
|
-
|
|
41
|
+
var fs = __toESM(require("fs"), 1);
|
|
42
|
+
var path = __toESM(require("path"), 1);
|
|
43
|
+
var wasmInstance = null;
|
|
44
|
+
var goInstance = null;
|
|
45
|
+
async function init() {
|
|
46
|
+
if (wasmInstance) return;
|
|
47
|
+
const wasmExecPath = path.join(__dirname, "..", "wasm", "wasm_exec.js");
|
|
48
|
+
require(wasmExecPath);
|
|
49
|
+
const go = new Go();
|
|
50
|
+
goInstance = go;
|
|
51
|
+
const wasmPath = path.join(__dirname, "..", "wasm", "luxfhe.wasm");
|
|
52
|
+
const wasmBuffer = fs.readFileSync(wasmPath);
|
|
53
|
+
const wasmModule = await WebAssembly.compile(wasmBuffer);
|
|
54
|
+
wasmInstance = await WebAssembly.instantiate(wasmModule, go.importObject);
|
|
55
|
+
go.run(wasmInstance);
|
|
56
|
+
}
|
|
57
|
+
function getLuxFHE() {
|
|
58
|
+
if (!wasmInstance) {
|
|
59
|
+
throw new Error("FHE not initialized. Call init() first.");
|
|
60
|
+
}
|
|
61
|
+
return globalThis.luxfhe;
|
|
62
|
+
}
|
|
63
|
+
async function generateKeys() {
|
|
64
|
+
await init();
|
|
65
|
+
const fhe = getLuxFHE();
|
|
66
|
+
return fhe.generateKeys();
|
|
67
|
+
}
|
|
68
|
+
async function encrypt(value, publicKey) {
|
|
69
|
+
await init();
|
|
70
|
+
const fhe = getLuxFHE();
|
|
71
|
+
return fhe.encrypt(value, publicKey);
|
|
72
|
+
}
|
|
73
|
+
async function decrypt(ciphertext, privateKey) {
|
|
74
|
+
await init();
|
|
75
|
+
const fhe = getLuxFHE();
|
|
76
|
+
return fhe.decrypt(ciphertext, privateKey);
|
|
77
|
+
}
|
|
78
|
+
var node_default = {
|
|
79
|
+
init,
|
|
80
|
+
getLuxFHE,
|
|
81
|
+
generateKeys,
|
|
82
|
+
encrypt,
|
|
83
|
+
decrypt
|
|
84
|
+
};
|
|
21
85
|
// Annotate the CommonJS export names for ESM import in node:
|
|
22
86
|
0 && (module.exports = {
|
|
23
|
-
|
|
87
|
+
decrypt,
|
|
88
|
+
encrypt,
|
|
89
|
+
generateKeys,
|
|
90
|
+
getLuxFHE,
|
|
91
|
+
init
|
|
24
92
|
});
|
package/dist/node/index.d.cts
CHANGED
|
@@ -1 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* LuxFHE WASM Node.js bindings
|
|
3
|
+
*
|
|
4
|
+
* Native Go FHE compiled to WebAssembly for Node.js
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Initialize the FHE WASM module
|
|
8
|
+
*/
|
|
9
|
+
declare function init(): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Get the LuxFHE instance after initialization
|
|
12
|
+
*/
|
|
13
|
+
declare function getLuxFHE(): any;
|
|
14
|
+
interface LuxFHEKeys {
|
|
15
|
+
publicKey: Uint8Array;
|
|
16
|
+
privateKey: Uint8Array;
|
|
17
|
+
evaluationKey: Uint8Array;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Generate FHE keys
|
|
21
|
+
*/
|
|
22
|
+
declare function generateKeys(): Promise<LuxFHEKeys>;
|
|
23
|
+
/**
|
|
24
|
+
* Encrypt a value
|
|
25
|
+
*/
|
|
26
|
+
declare function encrypt(value: number | bigint, publicKey: Uint8Array): Promise<Uint8Array>;
|
|
27
|
+
/**
|
|
28
|
+
* Decrypt a ciphertext
|
|
29
|
+
*/
|
|
30
|
+
declare function decrypt(ciphertext: Uint8Array, privateKey: Uint8Array): Promise<bigint>;
|
|
31
|
+
declare const _default: {
|
|
32
|
+
init: typeof init;
|
|
33
|
+
getLuxFHE: typeof getLuxFHE;
|
|
34
|
+
generateKeys: typeof generateKeys;
|
|
35
|
+
encrypt: typeof encrypt;
|
|
36
|
+
decrypt: typeof decrypt;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { type LuxFHEKeys, decrypt, _default as default, encrypt, generateKeys, getLuxFHE, init };
|
package/dist/node/index.d.ts
CHANGED
|
@@ -1 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* LuxFHE WASM Node.js bindings
|
|
3
|
+
*
|
|
4
|
+
* Native Go FHE compiled to WebAssembly for Node.js
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Initialize the FHE WASM module
|
|
8
|
+
*/
|
|
9
|
+
declare function init(): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Get the LuxFHE instance after initialization
|
|
12
|
+
*/
|
|
13
|
+
declare function getLuxFHE(): any;
|
|
14
|
+
interface LuxFHEKeys {
|
|
15
|
+
publicKey: Uint8Array;
|
|
16
|
+
privateKey: Uint8Array;
|
|
17
|
+
evaluationKey: Uint8Array;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Generate FHE keys
|
|
21
|
+
*/
|
|
22
|
+
declare function generateKeys(): Promise<LuxFHEKeys>;
|
|
23
|
+
/**
|
|
24
|
+
* Encrypt a value
|
|
25
|
+
*/
|
|
26
|
+
declare function encrypt(value: number | bigint, publicKey: Uint8Array): Promise<Uint8Array>;
|
|
27
|
+
/**
|
|
28
|
+
* Decrypt a ciphertext
|
|
29
|
+
*/
|
|
30
|
+
declare function decrypt(ciphertext: Uint8Array, privateKey: Uint8Array): Promise<bigint>;
|
|
31
|
+
declare const _default: {
|
|
32
|
+
init: typeof init;
|
|
33
|
+
getLuxFHE: typeof getLuxFHE;
|
|
34
|
+
generateKeys: typeof generateKeys;
|
|
35
|
+
encrypt: typeof encrypt;
|
|
36
|
+
decrypt: typeof decrypt;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { type LuxFHEKeys, decrypt, _default as default, encrypt, generateKeys, getLuxFHE, init };
|
package/dist/node/index.js
CHANGED
|
@@ -1,2 +1,60 @@
|
|
|
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
|
-
|
|
9
|
+
import * as fs from "fs";
|
|
10
|
+
import * as path from "path";
|
|
11
|
+
var wasmInstance = null;
|
|
12
|
+
var goInstance = null;
|
|
13
|
+
async function init() {
|
|
14
|
+
if (wasmInstance) return;
|
|
15
|
+
const wasmExecPath = path.join(__dirname, "..", "wasm", "wasm_exec.js");
|
|
16
|
+
__require(wasmExecPath);
|
|
17
|
+
const go = new Go();
|
|
18
|
+
goInstance = go;
|
|
19
|
+
const wasmPath = path.join(__dirname, "..", "wasm", "luxfhe.wasm");
|
|
20
|
+
const wasmBuffer = fs.readFileSync(wasmPath);
|
|
21
|
+
const wasmModule = await WebAssembly.compile(wasmBuffer);
|
|
22
|
+
wasmInstance = await WebAssembly.instantiate(wasmModule, go.importObject);
|
|
23
|
+
go.run(wasmInstance);
|
|
24
|
+
}
|
|
25
|
+
function getLuxFHE() {
|
|
26
|
+
if (!wasmInstance) {
|
|
27
|
+
throw new Error("FHE not initialized. Call init() first.");
|
|
28
|
+
}
|
|
29
|
+
return globalThis.luxfhe;
|
|
30
|
+
}
|
|
31
|
+
async function generateKeys() {
|
|
32
|
+
await init();
|
|
33
|
+
const fhe = getLuxFHE();
|
|
34
|
+
return fhe.generateKeys();
|
|
35
|
+
}
|
|
36
|
+
async function encrypt(value, publicKey) {
|
|
37
|
+
await init();
|
|
38
|
+
const fhe = getLuxFHE();
|
|
39
|
+
return fhe.encrypt(value, publicKey);
|
|
40
|
+
}
|
|
41
|
+
async function decrypt(ciphertext, privateKey) {
|
|
42
|
+
await init();
|
|
43
|
+
const fhe = getLuxFHE();
|
|
44
|
+
return fhe.decrypt(ciphertext, privateKey);
|
|
45
|
+
}
|
|
46
|
+
var node_default = {
|
|
47
|
+
init,
|
|
48
|
+
getLuxFHE,
|
|
49
|
+
generateKeys,
|
|
50
|
+
encrypt,
|
|
51
|
+
decrypt
|
|
52
|
+
};
|
|
53
|
+
export {
|
|
54
|
+
decrypt,
|
|
55
|
+
node_default as default,
|
|
56
|
+
encrypt,
|
|
57
|
+
generateKeys,
|
|
58
|
+
getLuxFHE,
|
|
59
|
+
init
|
|
60
|
+
};
|
package/dist/web/index.cjs
CHANGED
|
@@ -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,83 @@ 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
|
-
|
|
23
|
+
decrypt: () => decrypt,
|
|
24
|
+
default: () => web_default,
|
|
25
|
+
encrypt: () => encrypt,
|
|
26
|
+
generateKeys: () => generateKeys,
|
|
27
|
+
getLuxFHE: () => getLuxFHE,
|
|
28
|
+
init: () => init
|
|
35
29
|
});
|
|
36
30
|
module.exports = __toCommonJS(web_exports);
|
|
37
|
-
|
|
38
|
-
var
|
|
31
|
+
var import_meta = {};
|
|
32
|
+
var wasmInstance = null;
|
|
33
|
+
var goInstance = null;
|
|
34
|
+
var initPromise = null;
|
|
35
|
+
async function init(wasmUrl) {
|
|
36
|
+
if (wasmInstance) return;
|
|
37
|
+
if (initPromise) return initPromise;
|
|
38
|
+
initPromise = (async () => {
|
|
39
|
+
if (typeof Go === "undefined") {
|
|
40
|
+
await loadScript(new URL("../wasm/wasm_exec.js", import_meta.url).href);
|
|
41
|
+
}
|
|
42
|
+
const go = new Go();
|
|
43
|
+
goInstance = go;
|
|
44
|
+
const wasmPath = wasmUrl || new URL("../wasm/luxfhe.wasm", import_meta.url).href;
|
|
45
|
+
const response = await fetch(wasmPath);
|
|
46
|
+
const wasmBuffer = await response.arrayBuffer();
|
|
47
|
+
const wasmModule = await WebAssembly.compile(wasmBuffer);
|
|
48
|
+
wasmInstance = await WebAssembly.instantiate(wasmModule, go.importObject);
|
|
49
|
+
go.run(wasmInstance);
|
|
50
|
+
})();
|
|
51
|
+
return initPromise;
|
|
52
|
+
}
|
|
53
|
+
function loadScript(src) {
|
|
54
|
+
return new Promise((resolve, reject) => {
|
|
55
|
+
const script = document.createElement("script");
|
|
56
|
+
script.src = src;
|
|
57
|
+
script.onload = () => resolve();
|
|
58
|
+
script.onerror = reject;
|
|
59
|
+
document.head.appendChild(script);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function getLuxFHE() {
|
|
63
|
+
if (!wasmInstance) {
|
|
64
|
+
throw new Error("FHE not initialized. Call init() first.");
|
|
65
|
+
}
|
|
66
|
+
return globalThis.luxfhe;
|
|
67
|
+
}
|
|
68
|
+
async function generateKeys() {
|
|
69
|
+
await init();
|
|
70
|
+
const fhe = getLuxFHE();
|
|
71
|
+
return fhe.generateKeys();
|
|
72
|
+
}
|
|
73
|
+
async function encrypt(value, publicKey) {
|
|
74
|
+
await init();
|
|
75
|
+
const fhe = getLuxFHE();
|
|
76
|
+
return fhe.encrypt(value, publicKey);
|
|
77
|
+
}
|
|
78
|
+
async function decrypt(ciphertext, privateKey) {
|
|
79
|
+
await init();
|
|
80
|
+
const fhe = getLuxFHE();
|
|
81
|
+
return fhe.decrypt(ciphertext, privateKey);
|
|
82
|
+
}
|
|
83
|
+
var web_default = {
|
|
84
|
+
init,
|
|
85
|
+
getLuxFHE,
|
|
86
|
+
generateKeys,
|
|
87
|
+
encrypt,
|
|
88
|
+
decrypt
|
|
89
|
+
};
|
|
39
90
|
// Annotate the CommonJS export names for ESM import in node:
|
|
40
91
|
0 && (module.exports = {
|
|
41
|
-
|
|
92
|
+
decrypt,
|
|
93
|
+
encrypt,
|
|
94
|
+
generateKeys,
|
|
95
|
+
getLuxFHE,
|
|
96
|
+
init
|
|
42
97
|
});
|
package/dist/web/index.d.cts
CHANGED
|
@@ -1,2 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* LuxFHE WASM Web bindings
|
|
3
|
+
*
|
|
4
|
+
* Native Go FHE compiled to WebAssembly for browser
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Initialize the FHE WASM module
|
|
8
|
+
*/
|
|
9
|
+
declare function init(wasmUrl?: string): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Get the LuxFHE instance after initialization
|
|
12
|
+
*/
|
|
13
|
+
declare function getLuxFHE(): any;
|
|
14
|
+
interface LuxFHEKeys {
|
|
15
|
+
publicKey: Uint8Array;
|
|
16
|
+
privateKey: Uint8Array;
|
|
17
|
+
evaluationKey: Uint8Array;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Generate FHE keys
|
|
21
|
+
*/
|
|
22
|
+
declare function generateKeys(): Promise<LuxFHEKeys>;
|
|
23
|
+
/**
|
|
24
|
+
* Encrypt a value
|
|
25
|
+
*/
|
|
26
|
+
declare function encrypt(value: number | bigint, publicKey: Uint8Array): Promise<Uint8Array>;
|
|
27
|
+
/**
|
|
28
|
+
* Decrypt a ciphertext
|
|
29
|
+
*/
|
|
30
|
+
declare function decrypt(ciphertext: Uint8Array, privateKey: Uint8Array): Promise<bigint>;
|
|
31
|
+
declare const _default: {
|
|
32
|
+
init: typeof init;
|
|
33
|
+
getLuxFHE: typeof getLuxFHE;
|
|
34
|
+
generateKeys: typeof generateKeys;
|
|
35
|
+
encrypt: typeof encrypt;
|
|
36
|
+
decrypt: typeof decrypt;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { type LuxFHEKeys, decrypt, _default as default, encrypt, generateKeys, getLuxFHE, init };
|
package/dist/web/index.d.ts
CHANGED
|
@@ -1,2 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* LuxFHE WASM Web bindings
|
|
3
|
+
*
|
|
4
|
+
* Native Go FHE compiled to WebAssembly for browser
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Initialize the FHE WASM module
|
|
8
|
+
*/
|
|
9
|
+
declare function init(wasmUrl?: string): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Get the LuxFHE instance after initialization
|
|
12
|
+
*/
|
|
13
|
+
declare function getLuxFHE(): any;
|
|
14
|
+
interface LuxFHEKeys {
|
|
15
|
+
publicKey: Uint8Array;
|
|
16
|
+
privateKey: Uint8Array;
|
|
17
|
+
evaluationKey: Uint8Array;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Generate FHE keys
|
|
21
|
+
*/
|
|
22
|
+
declare function generateKeys(): Promise<LuxFHEKeys>;
|
|
23
|
+
/**
|
|
24
|
+
* Encrypt a value
|
|
25
|
+
*/
|
|
26
|
+
declare function encrypt(value: number | bigint, publicKey: Uint8Array): Promise<Uint8Array>;
|
|
27
|
+
/**
|
|
28
|
+
* Decrypt a ciphertext
|
|
29
|
+
*/
|
|
30
|
+
declare function decrypt(ciphertext: Uint8Array, privateKey: Uint8Array): Promise<bigint>;
|
|
31
|
+
declare const _default: {
|
|
32
|
+
init: typeof init;
|
|
33
|
+
getLuxFHE: typeof getLuxFHE;
|
|
34
|
+
generateKeys: typeof generateKeys;
|
|
35
|
+
encrypt: typeof encrypt;
|
|
36
|
+
decrypt: typeof decrypt;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { type LuxFHEKeys, decrypt, _default as default, encrypt, generateKeys, getLuxFHE, init };
|
package/dist/web/index.js
CHANGED
|
@@ -1,6 +1,67 @@
|
|
|
1
1
|
// src/web.ts
|
|
2
|
-
|
|
3
|
-
|
|
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
|
+
var web_default = {
|
|
54
|
+
init,
|
|
55
|
+
getLuxFHE,
|
|
56
|
+
generateKeys,
|
|
57
|
+
encrypt,
|
|
58
|
+
decrypt
|
|
59
|
+
};
|
|
4
60
|
export {
|
|
5
|
-
|
|
61
|
+
decrypt,
|
|
62
|
+
web_default as default,
|
|
63
|
+
encrypt,
|
|
64
|
+
generateKeys,
|
|
65
|
+
getLuxFHE,
|
|
66
|
+
init
|
|
6
67
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luxfhe/wasm",
|
|
3
|
-
"version": "0.1
|
|
4
|
-
"description": "LuxFHE
|
|
3
|
+
"version": "0.2.1",
|
|
4
|
+
"description": "LuxFHE Go WASM bindings for web and node",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/node/index.js",
|
|
7
7
|
"module": "./dist/web/index.js",
|
|
@@ -28,19 +28,21 @@
|
|
|
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"
|
|
35
36
|
],
|
|
36
37
|
"scripts": {
|
|
37
|
-
"build": "
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
"
|
|
41
|
-
"node-tfhe": "^0.8.1"
|
|
38
|
+
"build:wasm": "cd ~/work/lux/fhe && GOOS=js GOARCH=wasm go build -o sdk/wasm/luxfhe.wasm ./sdk/wasm/",
|
|
39
|
+
"build:copy": "cp ~/work/lux/fhe/sdk/wasm/luxfhe.wasm wasm/ && cp $(go env GOROOT)/lib/wasm/wasm_exec.js wasm/",
|
|
40
|
+
"build:ts": "tsup",
|
|
41
|
+
"build": "npm run build:ts"
|
|
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
|
},
|