@luxfhe/wasm 0.1.1 → 0.1.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.
- package/dist/node/index.cjs +24 -0
- package/dist/node/index.d.cts +1 -0
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.js +2 -0
- package/dist/web/index.cjs +24 -0
- package/dist/web/index.d.cts +1 -0
- package/dist/web/index.d.ts +1 -0
- package/dist/web/index.js +2 -0
- package/package.json +29 -53
- package/README.md +0 -198
- package/dist/index.d.ts +0 -38
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -136
- package/dist/index.js.map +0 -1
- package/dist/init.d.ts +0 -13
- package/dist/init.d.ts.map +0 -1
- package/dist/init.js +0 -54
- package/dist/init.js.map +0 -1
- package/dist/types.d.ts +0 -166
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -4
- package/dist/types.js.map +0 -1
- package/pkg/tfhe.wasm +0 -0
- package/pkg/wasm_exec.js +0 -575
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
|
|
17
|
+
// src/node.ts
|
|
18
|
+
var node_exports = {};
|
|
19
|
+
module.exports = __toCommonJS(node_exports);
|
|
20
|
+
__reExport(node_exports, require("node-tfhe"), module.exports);
|
|
21
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
22
|
+
0 && (module.exports = {
|
|
23
|
+
...require("node-tfhe")
|
|
24
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'node-tfhe';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'node-tfhe';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
|
|
17
|
+
// src/web.ts
|
|
18
|
+
var web_exports = {};
|
|
19
|
+
module.exports = __toCommonJS(web_exports);
|
|
20
|
+
__reExport(web_exports, require("tfhe"), module.exports);
|
|
21
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
22
|
+
0 && (module.exports = {
|
|
23
|
+
...require("tfhe")
|
|
24
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'tfhe';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from 'tfhe';
|
package/package.json
CHANGED
|
@@ -1,70 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luxfhe/wasm",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
3
|
+
"version": "0.1.2",
|
|
4
|
+
"description": "LuxFHE TFHE WASM bindings for web and node",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/node/index.js",
|
|
7
|
+
"module": "./dist/web/index.js",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
|
-
"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
"node": {
|
|
11
|
+
"import": "./dist/node/index.js",
|
|
12
|
+
"require": "./dist/node/index.cjs"
|
|
13
|
+
},
|
|
14
|
+
"default": {
|
|
15
|
+
"import": "./dist/web/index.js",
|
|
16
|
+
"require": "./dist/web/index.cjs"
|
|
17
|
+
}
|
|
14
18
|
},
|
|
15
19
|
"./node": {
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"require": "./dist/index.js"
|
|
20
|
+
"import": "./dist/node/index.js",
|
|
21
|
+
"require": "./dist/node/index.cjs"
|
|
19
22
|
},
|
|
20
23
|
"./web": {
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
},
|
|
25
|
-
"./wasm": "./pkg/tfhe.wasm",
|
|
26
|
-
"./wasm_exec": "./pkg/wasm_exec.js"
|
|
24
|
+
"import": "./dist/web/index.js",
|
|
25
|
+
"require": "./dist/web/index.cjs"
|
|
26
|
+
}
|
|
27
27
|
},
|
|
28
28
|
"files": [
|
|
29
|
-
"dist"
|
|
30
|
-
"pkg/tfhe.wasm",
|
|
31
|
-
"pkg/wasm_exec.js"
|
|
29
|
+
"dist"
|
|
32
30
|
],
|
|
33
31
|
"scripts": {
|
|
34
|
-
"build
|
|
35
|
-
"build:ts": "tsc",
|
|
36
|
-
"build": "npm run build:wasm && npm run build:ts",
|
|
37
|
-
"test": "vitest run",
|
|
38
|
-
"test:watch": "vitest",
|
|
39
|
-
"clean": "rm -rf dist pkg/*.wasm pkg/*.js",
|
|
40
|
-
"prepublishOnly": "npm run build"
|
|
41
|
-
},
|
|
42
|
-
"keywords": [
|
|
43
|
-
"fhe",
|
|
44
|
-
"tfhe",
|
|
45
|
-
"homomorphic-encryption",
|
|
46
|
-
"cryptography",
|
|
47
|
-
"wasm",
|
|
48
|
-
"webassembly",
|
|
49
|
-
"lux",
|
|
50
|
-
"blockchain"
|
|
51
|
-
],
|
|
52
|
-
"author": "Lux Industries Inc",
|
|
53
|
-
"license": "BSD-3-Clause",
|
|
54
|
-
"repository": {
|
|
55
|
-
"type": "git",
|
|
56
|
-
"url": "git+https://github.com/luxfhe/wasm.git"
|
|
32
|
+
"build": "tsup"
|
|
57
33
|
},
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
"
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"tfhe": "^0.8.1",
|
|
36
|
+
"node-tfhe": "^0.8.1"
|
|
61
37
|
},
|
|
62
38
|
"devDependencies": {
|
|
63
|
-
"
|
|
64
|
-
"typescript": "^5.
|
|
65
|
-
|
|
39
|
+
"tsup": "^8.0.0",
|
|
40
|
+
"typescript": "^5.0.0"
|
|
41
|
+
},
|
|
42
|
+
"publishConfig": {
|
|
43
|
+
"access": "public"
|
|
66
44
|
},
|
|
67
|
-
"
|
|
68
|
-
"node": ">=18.0.0"
|
|
69
|
-
}
|
|
45
|
+
"license": "MIT"
|
|
70
46
|
}
|
package/README.md
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
# @luxfi/tfhe-wasm
|
|
2
|
-
|
|
3
|
-
WebAssembly bindings for the Lux TFHE (Fully Homomorphic Encryption) library. Enables encrypted computation directly in the browser.
|
|
4
|
-
|
|
5
|
-
## Features
|
|
6
|
-
|
|
7
|
-
- **Fully Homomorphic Encryption**: Compute on encrypted data without decrypting
|
|
8
|
-
- **Boolean Gates**: AND, OR, XOR, NOT, NAND, NOR, XNOR, MUX
|
|
9
|
-
- **Integer Operations**: Add, subtract, multiply, compare encrypted uint8 values
|
|
10
|
-
- **Browser-Ready**: Pure WebAssembly, works in all modern browsers
|
|
11
|
-
- **TypeScript**: Full type definitions included
|
|
12
|
-
|
|
13
|
-
## Installation
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
npm install @luxfi/tfhe-wasm
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Quick Start
|
|
20
|
-
|
|
21
|
-
```typescript
|
|
22
|
-
import { loadWasm, createTFHE } from '@luxfi/tfhe-wasm';
|
|
23
|
-
|
|
24
|
-
// Load WASM module
|
|
25
|
-
await loadWasm('./node_modules/@luxfi/tfhe-wasm/pkg/tfhe.wasm');
|
|
26
|
-
|
|
27
|
-
// Create API instance
|
|
28
|
-
const tfhe = createTFHE();
|
|
29
|
-
|
|
30
|
-
// Initialize
|
|
31
|
-
await tfhe.init();
|
|
32
|
-
|
|
33
|
-
// Generate keys
|
|
34
|
-
const keys = await tfhe.generateKeys();
|
|
35
|
-
console.log('Keys generated');
|
|
36
|
-
|
|
37
|
-
// Encrypt values
|
|
38
|
-
const ct1 = await tfhe.encrypt(true);
|
|
39
|
-
const ct2 = await tfhe.encrypt(false);
|
|
40
|
-
|
|
41
|
-
// Compute on encrypted data
|
|
42
|
-
const result = await tfhe.and(ct1, ct2);
|
|
43
|
-
|
|
44
|
-
// Decrypt result
|
|
45
|
-
const decrypted = await tfhe.decrypt(result);
|
|
46
|
-
console.log('true AND false =', decrypted); // false
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
## API Reference
|
|
50
|
-
|
|
51
|
-
### Initialization
|
|
52
|
-
|
|
53
|
-
```typescript
|
|
54
|
-
// Load WASM (required first)
|
|
55
|
-
await loadWasm(wasmPath: string): Promise<void>
|
|
56
|
-
|
|
57
|
-
// Create TFHE instance
|
|
58
|
-
const tfhe = createTFHE(): TFHE
|
|
59
|
-
|
|
60
|
-
// Initialize TFHE parameters
|
|
61
|
-
await tfhe.init(): Promise<void>
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
### Key Management
|
|
65
|
-
|
|
66
|
-
```typescript
|
|
67
|
-
// Generate new key pair
|
|
68
|
-
const keys = await tfhe.generateKeys(): Promise<KeyPair>
|
|
69
|
-
// keys.secretKey: base64-encoded secret key
|
|
70
|
-
// keys.publicKey: base64-encoded public key
|
|
71
|
-
|
|
72
|
-
// Load existing secret key
|
|
73
|
-
await tfhe.loadSecretKey(secretKey: string): Promise<void>
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
### Boolean Encryption
|
|
77
|
-
|
|
78
|
-
```typescript
|
|
79
|
-
// Encrypt boolean
|
|
80
|
-
const ct = await tfhe.encrypt(value: boolean): Promise<Ciphertext>
|
|
81
|
-
|
|
82
|
-
// Decrypt to boolean
|
|
83
|
-
const value = await tfhe.decrypt(ct: Ciphertext): Promise<boolean>
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
### Boolean Operations
|
|
87
|
-
|
|
88
|
-
```typescript
|
|
89
|
-
await tfhe.and(ct1, ct2): Promise<Ciphertext>
|
|
90
|
-
await tfhe.or(ct1, ct2): Promise<Ciphertext>
|
|
91
|
-
await tfhe.xor(ct1, ct2): Promise<Ciphertext>
|
|
92
|
-
await tfhe.not(ct): Promise<Ciphertext>
|
|
93
|
-
await tfhe.nand(ct1, ct2): Promise<Ciphertext>
|
|
94
|
-
await tfhe.nor(ct1, ct2): Promise<Ciphertext>
|
|
95
|
-
await tfhe.xnor(ct1, ct2): Promise<Ciphertext>
|
|
96
|
-
await tfhe.mux(sel, ctTrue, ctFalse): Promise<Ciphertext>
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
### Integer Encryption (uint8)
|
|
100
|
-
|
|
101
|
-
```typescript
|
|
102
|
-
// Encrypt 8-bit integer (0-255)
|
|
103
|
-
const ct = await tfhe.encryptUint8(value: number): Promise<CiphertextUint8>
|
|
104
|
-
|
|
105
|
-
// Decrypt to 8-bit integer
|
|
106
|
-
const value = await tfhe.decryptUint8(ct: CiphertextUint8): Promise<number>
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
### Integer Operations
|
|
110
|
-
|
|
111
|
-
```typescript
|
|
112
|
-
// Addition (a + b) mod 256
|
|
113
|
-
await tfhe.add(a, b): Promise<CiphertextUint8>
|
|
114
|
-
|
|
115
|
-
// Subtraction (a - b) mod 256
|
|
116
|
-
await tfhe.sub(a, b): Promise<CiphertextUint8>
|
|
117
|
-
|
|
118
|
-
// Multiplication (a * b) mod 256
|
|
119
|
-
await tfhe.mul(a, b): Promise<CiphertextUint8>
|
|
120
|
-
|
|
121
|
-
// Comparison (a < b)
|
|
122
|
-
await tfhe.compare(a, b): Promise<Ciphertext>
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
## Browser Usage
|
|
126
|
-
|
|
127
|
-
Include the WASM support files in your HTML:
|
|
128
|
-
|
|
129
|
-
```html
|
|
130
|
-
<script src="wasm_exec.js"></script>
|
|
131
|
-
<script type="module">
|
|
132
|
-
import { loadWasm, createTFHE } from '@luxfi/tfhe-wasm';
|
|
133
|
-
|
|
134
|
-
const tfhe = createTFHE();
|
|
135
|
-
await loadWasm('./tfhe.wasm');
|
|
136
|
-
await tfhe.init();
|
|
137
|
-
|
|
138
|
-
// Use tfhe...
|
|
139
|
-
</script>
|
|
140
|
-
```
|
|
141
|
-
|
|
142
|
-
## Building from Source
|
|
143
|
-
|
|
144
|
-
Requirements:
|
|
145
|
-
- Go 1.23+
|
|
146
|
-
- Node.js 18+
|
|
147
|
-
|
|
148
|
-
```bash
|
|
149
|
-
# Clone repository
|
|
150
|
-
git clone https://github.com/luxfi/tfhe-wasm
|
|
151
|
-
cd tfhe-wasm
|
|
152
|
-
|
|
153
|
-
# Install dependencies
|
|
154
|
-
make install
|
|
155
|
-
|
|
156
|
-
# Build WASM and TypeScript
|
|
157
|
-
make build
|
|
158
|
-
|
|
159
|
-
# Run tests
|
|
160
|
-
make test
|
|
161
|
-
|
|
162
|
-
# Serve example
|
|
163
|
-
make serve
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
## Performance Notes
|
|
167
|
-
|
|
168
|
-
TFHE is computationally intensive. Expected timings on modern hardware:
|
|
169
|
-
|
|
170
|
-
| Operation | Time |
|
|
171
|
-
|-----------|------|
|
|
172
|
-
| Key Generation | 5-30s |
|
|
173
|
-
| Boolean Gate | 10-50ms |
|
|
174
|
-
| 8-bit Addition | 500ms-2s |
|
|
175
|
-
| 8-bit Comparison | 1-5s |
|
|
176
|
-
|
|
177
|
-
For better performance, consider:
|
|
178
|
-
- Using Web Workers to avoid blocking the UI
|
|
179
|
-
- Caching encrypted values
|
|
180
|
-
- Batching operations where possible
|
|
181
|
-
|
|
182
|
-
## Security
|
|
183
|
-
|
|
184
|
-
This library provides ~128-bit security using the PN10QP27 parameter set:
|
|
185
|
-
- LWE dimension: N=512
|
|
186
|
-
- Modulus: Q=12289
|
|
187
|
-
|
|
188
|
-
Keys should be treated as sensitive data. The secret key must never be exposed to untrusted parties.
|
|
189
|
-
|
|
190
|
-
## License
|
|
191
|
-
|
|
192
|
-
BSD-3-Clause
|
|
193
|
-
|
|
194
|
-
## Related
|
|
195
|
-
|
|
196
|
-
- [luxfi/tfhe](https://github.com/luxfi/tfhe) - Go TFHE library
|
|
197
|
-
- [luxfi/lattice](https://github.com/luxfi/lattice) - Lattice cryptography primitives
|
|
198
|
-
- [TFHE Paper](https://eprint.iacr.org/2018/421) - Original TFHE research
|
package/dist/index.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @luxfi/tfhe-wasm
|
|
3
|
-
*
|
|
4
|
-
* WebAssembly bindings for the Lux TFHE (Fully Homomorphic Encryption) library.
|
|
5
|
-
* Enables encrypted computation directly in the browser.
|
|
6
|
-
*/
|
|
7
|
-
import type { TFHE } from './types';
|
|
8
|
-
export * from './types';
|
|
9
|
-
export { loadWasm, isLoaded } from './init';
|
|
10
|
-
/**
|
|
11
|
-
* TFHEError is thrown when a TFHE operation fails.
|
|
12
|
-
*/
|
|
13
|
-
export declare class TFHEError extends Error {
|
|
14
|
-
constructor(message: string);
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Create a high-level TFHE instance.
|
|
18
|
-
* This wraps the raw WASM functions with proper error handling.
|
|
19
|
-
*
|
|
20
|
-
* @example
|
|
21
|
-
* ```typescript
|
|
22
|
-
* import { loadWasm, createTFHE } from '@luxfi/tfhe-wasm';
|
|
23
|
-
*
|
|
24
|
-
* await loadWasm('./tfhe.wasm');
|
|
25
|
-
* const tfhe = createTFHE();
|
|
26
|
-
*
|
|
27
|
-
* await tfhe.init();
|
|
28
|
-
* const keys = await tfhe.generateKeys();
|
|
29
|
-
*
|
|
30
|
-
* const ct1 = await tfhe.encrypt(true);
|
|
31
|
-
* const ct2 = await tfhe.encrypt(false);
|
|
32
|
-
* const result = await tfhe.and(ct1, ct2);
|
|
33
|
-
* const decrypted = await tfhe.decrypt(result); // false
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
export declare function createTFHE(): TFHE;
|
|
37
|
-
export default createTFHE;
|
|
38
|
-
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../js/index.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,IAAI,EAKL,MAAM,SAAS,CAAC;AAEjB,cAAc,SAAS,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAE5C;;GAEG;AACH,qBAAa,SAAU,SAAQ,KAAK;gBACtB,OAAO,EAAE,MAAM;CAI5B;AAYD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,UAAU,IAAI,IAAI,CA6GjC;AAGD,eAAe,UAAU,CAAC"}
|
package/dist/index.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2025, Lux Industries Inc
|
|
2
|
-
// SPDX-License-Identifier: BSD-3-Clause
|
|
3
|
-
export * from './types';
|
|
4
|
-
export { loadWasm, isLoaded } from './init';
|
|
5
|
-
/**
|
|
6
|
-
* TFHEError is thrown when a TFHE operation fails.
|
|
7
|
-
*/
|
|
8
|
-
export class TFHEError extends Error {
|
|
9
|
-
constructor(message) {
|
|
10
|
-
super(message);
|
|
11
|
-
this.name = 'TFHEError';
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Helper to unwrap TFHEResult and throw on error.
|
|
16
|
-
*/
|
|
17
|
-
function unwrap(result) {
|
|
18
|
-
if (!result.success) {
|
|
19
|
-
throw new TFHEError(result.error || 'Unknown TFHE error');
|
|
20
|
-
}
|
|
21
|
-
return result.data;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Create a high-level TFHE instance.
|
|
25
|
-
* This wraps the raw WASM functions with proper error handling.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```typescript
|
|
29
|
-
* import { loadWasm, createTFHE } from '@luxfi/tfhe-wasm';
|
|
30
|
-
*
|
|
31
|
-
* await loadWasm('./tfhe.wasm');
|
|
32
|
-
* const tfhe = createTFHE();
|
|
33
|
-
*
|
|
34
|
-
* await tfhe.init();
|
|
35
|
-
* const keys = await tfhe.generateKeys();
|
|
36
|
-
*
|
|
37
|
-
* const ct1 = await tfhe.encrypt(true);
|
|
38
|
-
* const ct2 = await tfhe.encrypt(false);
|
|
39
|
-
* const result = await tfhe.and(ct1, ct2);
|
|
40
|
-
* const decrypted = await tfhe.decrypt(result); // false
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
export function createTFHE() {
|
|
44
|
-
const checkLoaded = () => {
|
|
45
|
-
if (typeof window === 'undefined' || typeof window.tfhe_init !== 'function') {
|
|
46
|
-
throw new TFHEError('TFHE WASM not loaded. Call loadWasm() first.');
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
return {
|
|
50
|
-
async init() {
|
|
51
|
-
checkLoaded();
|
|
52
|
-
unwrap(window.tfhe_init());
|
|
53
|
-
},
|
|
54
|
-
async generateKeys() {
|
|
55
|
-
checkLoaded();
|
|
56
|
-
return unwrap(window.tfhe_generateKeys());
|
|
57
|
-
},
|
|
58
|
-
async loadSecretKey(secretKey) {
|
|
59
|
-
checkLoaded();
|
|
60
|
-
unwrap(window.tfhe_loadSecretKey(secretKey));
|
|
61
|
-
},
|
|
62
|
-
async encrypt(value) {
|
|
63
|
-
checkLoaded();
|
|
64
|
-
return unwrap(window.tfhe_encrypt(value));
|
|
65
|
-
},
|
|
66
|
-
async decrypt(ct) {
|
|
67
|
-
checkLoaded();
|
|
68
|
-
return unwrap(window.tfhe_decrypt(ct));
|
|
69
|
-
},
|
|
70
|
-
async encryptUint8(value) {
|
|
71
|
-
checkLoaded();
|
|
72
|
-
if (value < 0 || value > 255) {
|
|
73
|
-
throw new TFHEError(`Value ${value} out of range for uint8 (0-255)`);
|
|
74
|
-
}
|
|
75
|
-
return unwrap(window.tfhe_encryptUint8(value));
|
|
76
|
-
},
|
|
77
|
-
async decryptUint8(cts) {
|
|
78
|
-
checkLoaded();
|
|
79
|
-
if (cts.length !== 8) {
|
|
80
|
-
throw new TFHEError(`Expected 8 ciphertexts, got ${cts.length}`);
|
|
81
|
-
}
|
|
82
|
-
return unwrap(window.tfhe_decryptUint8(cts));
|
|
83
|
-
},
|
|
84
|
-
async and(ct1, ct2) {
|
|
85
|
-
checkLoaded();
|
|
86
|
-
return unwrap(window.tfhe_and(ct1, ct2));
|
|
87
|
-
},
|
|
88
|
-
async or(ct1, ct2) {
|
|
89
|
-
checkLoaded();
|
|
90
|
-
return unwrap(window.tfhe_or(ct1, ct2));
|
|
91
|
-
},
|
|
92
|
-
async xor(ct1, ct2) {
|
|
93
|
-
checkLoaded();
|
|
94
|
-
return unwrap(window.tfhe_xor(ct1, ct2));
|
|
95
|
-
},
|
|
96
|
-
async not(ct) {
|
|
97
|
-
checkLoaded();
|
|
98
|
-
return unwrap(window.tfhe_not(ct));
|
|
99
|
-
},
|
|
100
|
-
async nand(ct1, ct2) {
|
|
101
|
-
checkLoaded();
|
|
102
|
-
return unwrap(window.tfhe_nand(ct1, ct2));
|
|
103
|
-
},
|
|
104
|
-
async nor(ct1, ct2) {
|
|
105
|
-
checkLoaded();
|
|
106
|
-
return unwrap(window.tfhe_nor(ct1, ct2));
|
|
107
|
-
},
|
|
108
|
-
async xnor(ct1, ct2) {
|
|
109
|
-
checkLoaded();
|
|
110
|
-
return unwrap(window.tfhe_xnor(ct1, ct2));
|
|
111
|
-
},
|
|
112
|
-
async mux(sel, ctTrue, ctFalse) {
|
|
113
|
-
checkLoaded();
|
|
114
|
-
return unwrap(window.tfhe_mux(sel, ctTrue, ctFalse));
|
|
115
|
-
},
|
|
116
|
-
async compare(a, b) {
|
|
117
|
-
checkLoaded();
|
|
118
|
-
return unwrap(window.tfhe_compare(a, b));
|
|
119
|
-
},
|
|
120
|
-
async add(a, b) {
|
|
121
|
-
checkLoaded();
|
|
122
|
-
return unwrap(window.tfhe_addUint8(a, b));
|
|
123
|
-
},
|
|
124
|
-
async sub(a, b) {
|
|
125
|
-
checkLoaded();
|
|
126
|
-
return unwrap(window.tfhe_subUint8(a, b));
|
|
127
|
-
},
|
|
128
|
-
async mul(a, b) {
|
|
129
|
-
checkLoaded();
|
|
130
|
-
return unwrap(window.tfhe_mulUint8(a, b));
|
|
131
|
-
},
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
// Default export for convenience
|
|
135
|
-
export default createTFHE;
|
|
136
|
-
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
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AE,CAAC;YACd,OAAO,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC5C,CAAC;QAED,KAAK,CAAC,GAAG,CAAC,CAAkB,EAAE,CAAkB;YAC9C,WAAW,EAAE,CAAC;YACd,OAAO,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC5C,CAAC;QAED,KAAK,CAAC,GAAG,CAAC,CAAkB,EAAE,CAAkB;YAC9C,WAAW,EAAE,CAAC;YACd,OAAO,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;QAC5C,CAAC;KACF,CAAC;AACJ,CAAC;AAED,iCAAiC;AACjC,eAAe,UAAU,CAAC"}
|
package/dist/init.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Load and instantiate the Go WASM runtime.
|
|
3
|
-
* This must be called before using any TFHE functions.
|
|
4
|
-
*
|
|
5
|
-
* @param wasmPath Path to the tfhe.wasm file
|
|
6
|
-
* @returns Promise that resolves when WASM is loaded
|
|
7
|
-
*/
|
|
8
|
-
export declare function loadWasm(wasmPath?: string): Promise<void>;
|
|
9
|
-
/**
|
|
10
|
-
* Check if TFHE WASM is loaded.
|
|
11
|
-
*/
|
|
12
|
-
export declare function isLoaded(): boolean;
|
|
13
|
-
//# sourceMappingURL=init.d.ts.map
|
package/dist/init.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../js/init.ts"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH,wBAAsB,QAAQ,CAAC,QAAQ,GAAE,MAAsB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgC9E;AAmBD;;GAEG;AACH,wBAAgB,QAAQ,IAAI,OAAO,CAElC"}
|
package/dist/init.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2025, Lux Industries Inc
|
|
2
|
-
// SPDX-License-Identifier: BSD-3-Clause
|
|
3
|
-
/**
|
|
4
|
-
* Load and instantiate the Go WASM runtime.
|
|
5
|
-
* This must be called before using any TFHE functions.
|
|
6
|
-
*
|
|
7
|
-
* @param wasmPath Path to the tfhe.wasm file
|
|
8
|
-
* @returns Promise that resolves when WASM is loaded
|
|
9
|
-
*/
|
|
10
|
-
export async function loadWasm(wasmPath = './tfhe.wasm') {
|
|
11
|
-
// Check if Go runtime is available
|
|
12
|
-
if (typeof window === 'undefined' || typeof window.Go === 'undefined') {
|
|
13
|
-
throw new Error('Go runtime not found. Make sure to include wasm_exec.js before calling loadWasm().');
|
|
14
|
-
}
|
|
15
|
-
const go = new window.Go();
|
|
16
|
-
let wasmInstance;
|
|
17
|
-
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
18
|
-
// Modern browsers support streaming instantiation
|
|
19
|
-
const result = await WebAssembly.instantiateStreaming(fetch(wasmPath), go.importObject);
|
|
20
|
-
wasmInstance = result.instance;
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
// Fallback for older browsers
|
|
24
|
-
const response = await fetch(wasmPath);
|
|
25
|
-
const bytes = await response.arrayBuffer();
|
|
26
|
-
const result = await WebAssembly.instantiate(bytes, go.importObject);
|
|
27
|
-
wasmInstance = result.instance;
|
|
28
|
-
}
|
|
29
|
-
// Run the Go program (non-blocking, sets up exports)
|
|
30
|
-
go.run(wasmInstance);
|
|
31
|
-
// Wait for TFHE to be ready
|
|
32
|
-
await waitForTFHE();
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Wait for TFHE functions to be available.
|
|
36
|
-
* The Go WASM module registers functions asynchronously.
|
|
37
|
-
*/
|
|
38
|
-
async function waitForTFHE(timeout = 5000) {
|
|
39
|
-
const start = Date.now();
|
|
40
|
-
while (Date.now() - start < timeout) {
|
|
41
|
-
if (typeof window.tfhe_init === 'function') {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
await new Promise(resolve => setTimeout(resolve, 10));
|
|
45
|
-
}
|
|
46
|
-
throw new Error('Timeout waiting for TFHE WASM to initialize');
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Check if TFHE WASM is loaded.
|
|
50
|
-
*/
|
|
51
|
-
export function isLoaded() {
|
|
52
|
-
return typeof window !== 'undefined' && typeof window.tfhe_init === 'function';
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=init.js.map
|
package/dist/init.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","sourceRoot":"","sources":["../js/init.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,wCAAwC;AAIxC;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,WAAmB,aAAa;IAC7D,mCAAmC;IACnC,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,OAAO,MAAM,CAAC,EAAE,KAAK,WAAW,EAAE,CAAC;QACtE,MAAM,IAAI,KAAK,CACb,oFAAoF,CACrF,CAAC;IACJ,CAAC;IAED,MAAM,EAAE,GAAe,IAAI,MAAM,CAAC,EAAE,EAAE,CAAC;IAEvC,IAAI,YAAkC,CAAC;IAEvC,IAAI,OAAO,WAAW,CAAC,oBAAoB,KAAK,UAAU,EAAE,CAAC;QAC3D,kDAAkD;QAClD,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,oBAAoB,CACnD,KAAK,CAAC,QAAQ,CAAC,EACf,EAAE,CAAC,YAAY,CAChB,CAAC;QACF,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC;IACjC,CAAC;SAAM,CAAC;QACN,8BAA8B;QAC9B,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,QAAQ,CAAC,CAAC;QACvC,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC;QAC3C,MAAM,MAAM,GAAG,MAAM,WAA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