@abhedyam/wasm 1.0.34 → 1.0.39
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 +55 -11
- package/abhedya_wasm_bg.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,26 +2,70 @@
|
|
|
2
2
|
|
|
3
3
|
WebAssembly bindings for **Abhedya**: Post-Quantum Sanskrit Cryptography.
|
|
4
4
|
|
|
5
|
+
This package brings the power of the Abhedya Rust core (Lattice-based LWE, $N=768$) to the JavaScript ecosystem via WebAssembly.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @abhedyam/wasm
|
|
11
|
+
```
|
|
12
|
+
|
|
5
13
|
## Usage
|
|
6
14
|
|
|
15
|
+
```javascript
|
|
7
16
|
import init, { AbhedyaWasm } from "@abhedyam/wasm";
|
|
8
17
|
|
|
9
|
-
async function
|
|
10
|
-
|
|
18
|
+
async function main() {
|
|
19
|
+
// 1. Initialize WASM module
|
|
20
|
+
await init();
|
|
21
|
+
const abhedya = new AbhedyaWasm();
|
|
11
22
|
|
|
12
|
-
|
|
13
|
-
|
|
23
|
+
// 2. Generate Keys using internal CSPRNG
|
|
24
|
+
console.log("Generating Keys...");
|
|
25
|
+
abhedya.keygen();
|
|
26
|
+
// Keys are stored statefully in the WASM instance for security.
|
|
14
27
|
|
|
15
|
-
|
|
16
|
-
const
|
|
28
|
+
// 3. Encrypt Data
|
|
29
|
+
const message = "The quick brown fox jumps over the lazy dog";
|
|
30
|
+
const plainBytes = new TextEncoder().encode(message);
|
|
17
31
|
|
|
18
|
-
|
|
32
|
+
// Mode: false = Standard (Binary), true = Metered (Sanskrit Steganography)
|
|
33
|
+
const encrypted = abhedya.encrypt(plainBytes, false);
|
|
34
|
+
console.log(`Ciphertext Size: ${encrypted.length} bytes`);
|
|
19
35
|
|
|
20
|
-
|
|
21
|
-
|
|
36
|
+
// 4. Decrypt Data
|
|
37
|
+
const decrypted = abhedya.decrypt(encrypted);
|
|
38
|
+
console.log("Decrypted:", new TextDecoder().decode(decrypted));
|
|
22
39
|
}
|
|
23
|
-
run();
|
|
24
40
|
|
|
41
|
+
main();
|
|
25
42
|
```
|
|
26
43
|
|
|
27
|
-
|
|
44
|
+
## API Reference
|
|
45
|
+
|
|
46
|
+
### `new AbhedyaWasm()`
|
|
47
|
+
|
|
48
|
+
Creates a new cryptographic context. The state (keys) is encapsulated within this instance.
|
|
49
|
+
|
|
50
|
+
### `.keygen()`
|
|
51
|
+
|
|
52
|
+
Generates a new Kyber-768 equivalent Lattice Keypair ($N=768, Q=3329$).
|
|
53
|
+
|
|
54
|
+
- **Returns**: `void` (Keys are stored internally).
|
|
55
|
+
|
|
56
|
+
### `.encrypt(data: Uint8Array, metered: boolean): Uint8Array`
|
|
57
|
+
|
|
58
|
+
Encrypts the input bytes.
|
|
59
|
+
|
|
60
|
+
- `data`: The plaintext bytes.
|
|
61
|
+
- `metered`:
|
|
62
|
+
- `false`: **Standard Mode**. High-throughput binary output.
|
|
63
|
+
- `true`: **Metered Mode**. Output is shaped to match valid Sanskrit prosody (Anushtubh meter) for steganography.
|
|
64
|
+
- **Returns**: The ciphertext bytes.
|
|
65
|
+
|
|
66
|
+
### `.decrypt(ciphertext: Uint8Array): Uint8Array`
|
|
67
|
+
|
|
68
|
+
Decrypts the input using the stored private key.
|
|
69
|
+
|
|
70
|
+
- **Returns**: The decrypted plaintext bytes.
|
|
71
|
+
- **Performance**: Uses O(1) Sanskrit-Phonetic lookup for ultra-fast decryption (~2.39µs).
|
package/abhedya_wasm_bg.wasm
CHANGED
|
Binary file
|