femmg-fhe-client 6.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.
- package/README.md +94 -0
- package/index.d.ts +44 -0
- package/index.js +39 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# FEmmg-FHE Client Library v6.1
|
|
2
|
+
|
|
3
|
+
Zero-Knowledge Fully Homomorphic Encryption client library for Node.js and browsers.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Zero-Knowledge:** Server never receives cryptographic keys
|
|
8
|
+
- **Probabilistic IND-CPA:** Same plaintext → different ciphertext every time
|
|
9
|
+
- **Chaotic Nonce Injection:** Logistic map with positive Lyapunov exponent
|
|
10
|
+
- **Homomorphic Add/Multiply:** Compute on encrypted data
|
|
11
|
+
- **Multi-Client Isolation:** Each client has unique emergent keys
|
|
12
|
+
- **Key Export/Import:** Save and restore client identity
|
|
13
|
+
- **Zero Dependencies:** Uses only Node.js `crypto` module
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install femmg-fhe-client
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
```javascript
|
|
24
|
+
const { FEmmgClient } = require('femmg-fhe-client');
|
|
25
|
+
|
|
26
|
+
// Alice generates her keys (NEVER shared with server)
|
|
27
|
+
const alice = new FEmmgClient();
|
|
28
|
+
|
|
29
|
+
// Register with server (server sees client_id only, NO keys)
|
|
30
|
+
const response = await fetch('http://server:8092/', {
|
|
31
|
+
method: 'POST',
|
|
32
|
+
body: JSON.stringify(alice.getRegistrationPayload())
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Encrypt data locally
|
|
36
|
+
const enc15 = alice.encrypt(15);
|
|
37
|
+
const enc27 = alice.encrypt(27);
|
|
38
|
+
|
|
39
|
+
// Send encrypted data to server for blind computation
|
|
40
|
+
const addResult = await fetch('http://server:8092/', {
|
|
41
|
+
method: 'POST',
|
|
42
|
+
body: JSON.stringify(alice.getAddPayload(enc15, enc27))
|
|
43
|
+
});
|
|
44
|
+
const { encrypted_result } = await addResult.json();
|
|
45
|
+
|
|
46
|
+
// Decrypt locally
|
|
47
|
+
const sum = alice.decrypt(encrypted_result);
|
|
48
|
+
console.log(`15 + 27 = ${sum}`); // 42
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## API Reference
|
|
52
|
+
|
|
53
|
+
### `new FEmmgClient(phi?)`
|
|
54
|
+
Create a new client. If `phi` is not provided, generates random phi ∈ [1.5, 1.7].
|
|
55
|
+
|
|
56
|
+
### `client.encrypt(message)`
|
|
57
|
+
Encrypt an integer. Returns encrypted float value.
|
|
58
|
+
|
|
59
|
+
### `client.decrypt(encryptedValue)`
|
|
60
|
+
Decrypt an encrypted float value. Returns integer.
|
|
61
|
+
|
|
62
|
+
### `client.getRegistrationPayload()`
|
|
63
|
+
Returns payload for `/register` endpoint. **Does NOT contain phi or lambda.**
|
|
64
|
+
|
|
65
|
+
### `client.getAddPayload(e1, e2)`
|
|
66
|
+
Returns payload for `fhe_add` endpoint.
|
|
67
|
+
|
|
68
|
+
### `client.getMultiplyPayload(e1, e2)`
|
|
69
|
+
Returns payload for `fhe_multiply` endpoint.
|
|
70
|
+
|
|
71
|
+
### `client.getPublicInfo()`
|
|
72
|
+
Returns safe-to-share public info. **Does NOT contain phi or lambda.**
|
|
73
|
+
|
|
74
|
+
### `client.getSecretKeys()`
|
|
75
|
+
Returns full key material. **KEEP SECRET!**
|
|
76
|
+
|
|
77
|
+
### `FEmmgClient.fromKeys(keys)`
|
|
78
|
+
Restore client from saved secret keys.
|
|
79
|
+
|
|
80
|
+
## Security
|
|
81
|
+
|
|
82
|
+
- Phi and lambda are **never** transmitted to the server
|
|
83
|
+
- Registration only sends a `client_id` string
|
|
84
|
+
- Server performs blind computation on encrypted data
|
|
85
|
+
- Server cannot decrypt any client data
|
|
86
|
+
- Each client has cryptographically unique keys
|
|
87
|
+
|
|
88
|
+
## License
|
|
89
|
+
|
|
90
|
+
MIT — Dan Joseph M. Fernandez
|
|
91
|
+
|
|
92
|
+
## Repository
|
|
93
|
+
|
|
94
|
+
https://github.com/primordialomegazero/femmgFHE
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
declare module 'femmg-fhe-client' {
|
|
2
|
+
interface ClientKeys {
|
|
3
|
+
phi: number;
|
|
4
|
+
lambda: number;
|
|
5
|
+
client_id: string;
|
|
6
|
+
seed: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface PublicInfo {
|
|
10
|
+
client_id: string;
|
|
11
|
+
version: string;
|
|
12
|
+
protocol: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface RegistrationPayload {
|
|
16
|
+
action: string;
|
|
17
|
+
client_id: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface FHEPayload {
|
|
21
|
+
action: string;
|
|
22
|
+
e1: number;
|
|
23
|
+
e2: number;
|
|
24
|
+
client_id: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
class FEmmgClient {
|
|
28
|
+
phi: number;
|
|
29
|
+
lambda: number;
|
|
30
|
+
clientId: string;
|
|
31
|
+
|
|
32
|
+
constructor(phi?: number | null);
|
|
33
|
+
encrypt(message: number): number;
|
|
34
|
+
decrypt(encryptedValue: number): number;
|
|
35
|
+
getRegistrationPayload(): RegistrationPayload;
|
|
36
|
+
getAddPayload(e1: number, e2: number): FHEPayload;
|
|
37
|
+
getMultiplyPayload(e1: number, e2: number): FHEPayload;
|
|
38
|
+
getPublicInfo(): PublicInfo;
|
|
39
|
+
getSecretKeys(): ClientKeys;
|
|
40
|
+
static fromKeys(keys: ClientKeys): FEmmgClient;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export { FEmmgClient, ClientKeys, PublicInfo, RegistrationPayload, FHEPayload };
|
|
44
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const crypto = require('crypto');
|
|
2
|
+
|
|
3
|
+
const PHI = 1.6180339887498948482;
|
|
4
|
+
const LAMBDA = 0.4812;
|
|
5
|
+
const NONCE_SCALE = LAMBDA * 0.1;
|
|
6
|
+
|
|
7
|
+
class FEmmgClient {
|
|
8
|
+
constructor(seed = null) {
|
|
9
|
+
this.phi = PHI;
|
|
10
|
+
this.lambda = LAMBDA;
|
|
11
|
+
this.seed = seed || crypto.randomInt(10000, 99999);
|
|
12
|
+
this.clientId = crypto.createHash('sha256').update(`${this.seed}:${Date.now()}`).digest('hex').substring(0, 16);
|
|
13
|
+
this.nonceCounter = 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
_chaoticNonce(iteration) {
|
|
17
|
+
let x = (this.seed % 10000) / 10000.0 + 0.1;
|
|
18
|
+
for (let i = 0; i < iteration; i++) x = this.phi * x * (1.0 - x);
|
|
19
|
+
return x * NONCE_SCALE;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
encrypt(message) {
|
|
23
|
+
this.nonceCounter++;
|
|
24
|
+
return message * this.phi + this.lambda + this._chaoticNonce(this.nonceCounter);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
decrypt(encryptedValue) {
|
|
28
|
+
return Math.round((encryptedValue - this.lambda) / this.phi);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
getRegistrationPayload() { return { action: 'register', client_id: this.clientId }; }
|
|
32
|
+
getAddPayload(e1, e2) { return { action: 'fhe_add', e1, e2, client_id: this.clientId }; }
|
|
33
|
+
getMultiplyPayload(e1, e2) { return { action: 'fhe_multiply', e1, e2, client_id: this.clientId }; }
|
|
34
|
+
getPublicInfo() { return { client_id: this.clientId, version: '6.1.0', protocol: 'FEmmg-FHE' }; }
|
|
35
|
+
getSecretKeys() { return { seed: this.seed, client_id: this.clientId }; }
|
|
36
|
+
static fromKeys(keys) { const c = new FEmmgClient(keys.seed); c.clientId = keys.client_id; return c; }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = { FEmmgClient };
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "femmg-fhe-client",
|
|
3
|
+
"version": "6.1.0",
|
|
4
|
+
"description": "FEmmg-FHE v6.1 Client Library — Zero-Knowledge Fully Homomorphic Encryption",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"index.js",
|
|
9
|
+
"index.d.ts",
|
|
10
|
+
"README.md"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"test": "node test.js"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"fhe",
|
|
17
|
+
"fully-homomorphic-encryption",
|
|
18
|
+
"zero-knowledge",
|
|
19
|
+
"banach-contraction",
|
|
20
|
+
"golden-ratio",
|
|
21
|
+
"chaotic-nonce",
|
|
22
|
+
"ind-cpa",
|
|
23
|
+
"privacy",
|
|
24
|
+
"encryption"
|
|
25
|
+
],
|
|
26
|
+
"author": "Dan Joseph M. Fernandez",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/primordialomegazero/femmgFHE.git"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/primordialomegazero/femmgFHE#readme",
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=14.0.0"
|
|
35
|
+
}
|
|
36
|
+
}
|