@abhedyam/wasm 1.0.32
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 +25 -0
- package/abhedya_wasm.d.ts +20 -0
- package/abhedya_wasm.js +160 -0
- package/abhedya_wasm_bg.wasm +0 -0
- package/package.json +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Abhedya WASM
|
|
2
|
+
|
|
3
|
+
WebAssembly bindings for **Abhedya**: Post-Quantum Sanskrit Cryptography.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
```javascript
|
|
8
|
+
import init, { AbhedyaWasm } from "./abhedya_wasm.js";
|
|
9
|
+
|
|
10
|
+
async function run() {
|
|
11
|
+
await init();
|
|
12
|
+
|
|
13
|
+
const abhedya = new AbhedyaWasm();
|
|
14
|
+
abhedya.keygen();
|
|
15
|
+
|
|
16
|
+
const plain = new TextEncoder().encode("Hello World");
|
|
17
|
+
const encrypted = abhedya.encrypt(plain, false); // Standard Mode
|
|
18
|
+
|
|
19
|
+
console.log("Encrypted bytes:", encrypted);
|
|
20
|
+
|
|
21
|
+
const decrypted = abhedya.decrypt(encrypted);
|
|
22
|
+
console.log("Decrypted:", new TextDecoder().decode(decrypted));
|
|
23
|
+
}
|
|
24
|
+
run();
|
|
25
|
+
```
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
export class AbhedyaWasm {
|
|
5
|
+
free(): void;
|
|
6
|
+
[Symbol.dispose](): void;
|
|
7
|
+
/**
|
|
8
|
+
* Decrypt a ciphertext
|
|
9
|
+
*/
|
|
10
|
+
decrypt(ct: Uint8Array): Uint8Array;
|
|
11
|
+
/**
|
|
12
|
+
* Encrypt a message (string or bytes)
|
|
13
|
+
*/
|
|
14
|
+
encrypt(msg: Uint8Array, is_metered: boolean): Uint8Array;
|
|
15
|
+
/**
|
|
16
|
+
* Generate a fresh KeyPair
|
|
17
|
+
*/
|
|
18
|
+
keygen(): any;
|
|
19
|
+
constructor();
|
|
20
|
+
}
|
package/abhedya_wasm.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/* @ts-self-types="./abhedya_wasm.d.ts" */
|
|
2
|
+
|
|
3
|
+
class AbhedyaWasm {
|
|
4
|
+
__destroy_into_raw() {
|
|
5
|
+
const ptr = this.__wbg_ptr;
|
|
6
|
+
this.__wbg_ptr = 0;
|
|
7
|
+
AbhedyaWasmFinalization.unregister(this);
|
|
8
|
+
return ptr;
|
|
9
|
+
}
|
|
10
|
+
free() {
|
|
11
|
+
const ptr = this.__destroy_into_raw();
|
|
12
|
+
wasm.__wbg_abhedyawasm_free(ptr, 0);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Decrypt a ciphertext
|
|
16
|
+
* @param {Uint8Array} ct
|
|
17
|
+
* @returns {Uint8Array}
|
|
18
|
+
*/
|
|
19
|
+
decrypt(ct) {
|
|
20
|
+
const ptr0 = passArray8ToWasm0(ct, wasm.__wbindgen_malloc);
|
|
21
|
+
const len0 = WASM_VECTOR_LEN;
|
|
22
|
+
const ret = wasm.abhedyawasm_decrypt(this.__wbg_ptr, ptr0, len0);
|
|
23
|
+
if (ret[3]) {
|
|
24
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
25
|
+
}
|
|
26
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
27
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
28
|
+
return v2;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Encrypt a message (string or bytes)
|
|
32
|
+
* @param {Uint8Array} msg
|
|
33
|
+
* @param {boolean} is_metered
|
|
34
|
+
* @returns {Uint8Array}
|
|
35
|
+
*/
|
|
36
|
+
encrypt(msg, is_metered) {
|
|
37
|
+
const ptr0 = passArray8ToWasm0(msg, wasm.__wbindgen_malloc);
|
|
38
|
+
const len0 = WASM_VECTOR_LEN;
|
|
39
|
+
const ret = wasm.abhedyawasm_encrypt(this.__wbg_ptr, ptr0, len0, is_metered);
|
|
40
|
+
if (ret[3]) {
|
|
41
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
42
|
+
}
|
|
43
|
+
var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
44
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
45
|
+
return v2;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Generate a fresh KeyPair
|
|
49
|
+
* @returns {any}
|
|
50
|
+
*/
|
|
51
|
+
keygen() {
|
|
52
|
+
const ret = wasm.abhedyawasm_keygen(this.__wbg_ptr);
|
|
53
|
+
if (ret[2]) {
|
|
54
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
55
|
+
}
|
|
56
|
+
return takeFromExternrefTable0(ret[0]);
|
|
57
|
+
}
|
|
58
|
+
constructor() {
|
|
59
|
+
const ret = wasm.abhedyawasm_new();
|
|
60
|
+
this.__wbg_ptr = ret >>> 0;
|
|
61
|
+
AbhedyaWasmFinalization.register(this, this.__wbg_ptr, this);
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (Symbol.dispose) AbhedyaWasm.prototype[Symbol.dispose] = AbhedyaWasm.prototype.free;
|
|
66
|
+
exports.AbhedyaWasm = AbhedyaWasm;
|
|
67
|
+
|
|
68
|
+
function __wbg_get_imports() {
|
|
69
|
+
const import0 = {
|
|
70
|
+
__proto__: null,
|
|
71
|
+
__wbg___wbindgen_throw_be289d5034ed271b: function(arg0, arg1) {
|
|
72
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
73
|
+
},
|
|
74
|
+
__wbg_getRandomValues_1c61fac11405ffdc: function() { return handleError(function (arg0, arg1) {
|
|
75
|
+
globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
|
|
76
|
+
}, arguments); },
|
|
77
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
78
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
79
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
80
|
+
return ret;
|
|
81
|
+
},
|
|
82
|
+
__wbindgen_init_externref_table: function() {
|
|
83
|
+
const table = wasm.__wbindgen_externrefs;
|
|
84
|
+
const offset = table.grow(4);
|
|
85
|
+
table.set(0, undefined);
|
|
86
|
+
table.set(offset + 0, undefined);
|
|
87
|
+
table.set(offset + 1, null);
|
|
88
|
+
table.set(offset + 2, true);
|
|
89
|
+
table.set(offset + 3, false);
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
__proto__: null,
|
|
94
|
+
"./abhedya_wasm_bg.js": import0,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const AbhedyaWasmFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
99
|
+
? { register: () => {}, unregister: () => {} }
|
|
100
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_abhedyawasm_free(ptr >>> 0, 1));
|
|
101
|
+
|
|
102
|
+
function addToExternrefTable0(obj) {
|
|
103
|
+
const idx = wasm.__externref_table_alloc();
|
|
104
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
105
|
+
return idx;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
109
|
+
ptr = ptr >>> 0;
|
|
110
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function getStringFromWasm0(ptr, len) {
|
|
114
|
+
ptr = ptr >>> 0;
|
|
115
|
+
return decodeText(ptr, len);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
let cachedUint8ArrayMemory0 = null;
|
|
119
|
+
function getUint8ArrayMemory0() {
|
|
120
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
121
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
122
|
+
}
|
|
123
|
+
return cachedUint8ArrayMemory0;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function handleError(f, args) {
|
|
127
|
+
try {
|
|
128
|
+
return f.apply(this, args);
|
|
129
|
+
} catch (e) {
|
|
130
|
+
const idx = addToExternrefTable0(e);
|
|
131
|
+
wasm.__wbindgen_exn_store(idx);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
136
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
137
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
138
|
+
WASM_VECTOR_LEN = arg.length;
|
|
139
|
+
return ptr;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function takeFromExternrefTable0(idx) {
|
|
143
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
144
|
+
wasm.__externref_table_dealloc(idx);
|
|
145
|
+
return value;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
149
|
+
cachedTextDecoder.decode();
|
|
150
|
+
function decodeText(ptr, len) {
|
|
151
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
let WASM_VECTOR_LEN = 0;
|
|
155
|
+
|
|
156
|
+
const wasmPath = `${__dirname}/abhedya_wasm_bg.wasm`;
|
|
157
|
+
const wasmBytes = require('fs').readFileSync(wasmPath);
|
|
158
|
+
const wasmModule = new WebAssembly.Module(wasmBytes);
|
|
159
|
+
const wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
|
|
160
|
+
wasm.__wbindgen_start();
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@abhedyam/wasm",
|
|
3
|
+
"collaborators": [
|
|
4
|
+
"ParamTatva <bot@paramtatva.org>"
|
|
5
|
+
],
|
|
6
|
+
"description": "WASM Bindings for Abhedya: Sanskrit-Encoded PQC",
|
|
7
|
+
"version": "1.0.32",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/ParamTatva-org/abhedyam"
|
|
12
|
+
},
|
|
13
|
+
"files": [
|
|
14
|
+
"abhedya_wasm_bg.wasm",
|
|
15
|
+
"abhedya_wasm.js",
|
|
16
|
+
"abhedya_wasm.d.ts"
|
|
17
|
+
],
|
|
18
|
+
"main": "abhedya_wasm.js",
|
|
19
|
+
"types": "abhedya_wasm.d.ts"
|
|
20
|
+
}
|