xwing-wasm 0.2.0 → 0.2.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.
Files changed (3) hide show
  1. package/index.d.ts +3 -1
  2. package/package.json +5 -3
  3. package/xwing_bg.js +214 -0
package/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  // SPDX-License-Identifier: MIT OR Apache-2.0
2
2
  // Copyright 2026 Thomas <tom@unebaguette.fr>
3
3
 
4
- export {generateKeypair, encapsulate, decapsulate, GenerateKeypairResult, EncapsulateResult} from './bundler/xwing';
4
+ export {generateKeypair, encapsulate, decapsulate, GenerateKeypairResult, EncapsulateResult} from './bundler/xwing';
5
+
6
+ export type { default } from './web/xwing';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xwing-wasm",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "description": "X-Wing hybrid KEM (ML-KEM-768 + X25519) via Rust/WASM",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "repository": {
@@ -13,9 +13,10 @@
13
13
  ".": {
14
14
  "node": {
15
15
  "require": "./node/xwing.js",
16
- "import": "./index.js"
16
+ "import": "./node/xwing.js"
17
17
  },
18
- "import": "./index.js",
18
+ "webpack": "./bundler/xwing.js",
19
+ "import": "./web/xwing.js",
19
20
  "default": "./web/xwing.js"
20
21
  }
21
22
  },
@@ -26,6 +27,7 @@
26
27
  "index.js",
27
28
  "index.d.ts",
28
29
  "xwing_bg.wasm",
30
+ "xwing_bg.js",
29
31
  "README.md",
30
32
  "LICENSE-MIT",
31
33
  "LICENSE-APACHE"
package/xwing_bg.js ADDED
@@ -0,0 +1,214 @@
1
+ /**
2
+ * @param {Uint8Array} sk
3
+ * @param {Uint8Array} ciphertext
4
+ * @returns {Uint8Array}
5
+ */
6
+ export function decapsulate(sk, ciphertext) {
7
+ const ptr0 = passArray8ToWasm0(sk, wasm.__wbindgen_malloc);
8
+ const len0 = WASM_VECTOR_LEN;
9
+ const ptr1 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
10
+ const len1 = WASM_VECTOR_LEN;
11
+ const ret = wasm.decapsulate(ptr0, len0, ptr1, len1);
12
+ if (ret[3]) {
13
+ throw takeFromExternrefTable0(ret[2]);
14
+ }
15
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
16
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
17
+ return v3;
18
+ }
19
+
20
+ /**
21
+ * @param {Uint8Array} pk
22
+ * @returns {EncapsulateResult}
23
+ */
24
+ export function encapsulate(pk) {
25
+ const ptr0 = passArray8ToWasm0(pk, wasm.__wbindgen_malloc);
26
+ const len0 = WASM_VECTOR_LEN;
27
+ const ret = wasm.encapsulate(ptr0, len0);
28
+ if (ret[2]) {
29
+ throw takeFromExternrefTable0(ret[1]);
30
+ }
31
+ return takeFromExternrefTable0(ret[0]);
32
+ }
33
+
34
+ /**
35
+ * @returns {GenerateKeypairResult}
36
+ */
37
+ export function generateKeypair() {
38
+ const ret = wasm.generateKeypair();
39
+ return ret;
40
+ }
41
+ export function __wbg_Error_9dc85fe1bc224456(arg0, arg1) {
42
+ const ret = Error(getStringFromWasm0(arg0, arg1));
43
+ return ret;
44
+ }
45
+ export function __wbg_String_8564e559799eccda(arg0, arg1) {
46
+ const ret = String(arg1);
47
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
48
+ const len1 = WASM_VECTOR_LEN;
49
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
50
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
51
+ }
52
+ export function __wbg___wbindgen_throw_bbadd78c1bac3a77(arg0, arg1) {
53
+ throw new Error(getStringFromWasm0(arg0, arg1));
54
+ }
55
+ export function __wbg_getRandomValues_76dfc69825c9c552() { return handleError(function (arg0, arg1) {
56
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
57
+ }, arguments); }
58
+ export function __wbg_new_0b303268aa395a38() {
59
+ const ret = new Array();
60
+ return ret;
61
+ }
62
+ export function __wbg_new_20b778a4c5c691c3() {
63
+ const ret = new Object();
64
+ return ret;
65
+ }
66
+ export function __wbg_set_6be42768c690e380(arg0, arg1, arg2) {
67
+ arg0[arg1] = arg2;
68
+ }
69
+ export function __wbg_set_da33c120a6584674(arg0, arg1, arg2) {
70
+ arg0[arg1 >>> 0] = arg2;
71
+ }
72
+ export function __wbindgen_cast_0000000000000001(arg0) {
73
+ // Cast intrinsic for `F64 -> Externref`.
74
+ const ret = arg0;
75
+ return ret;
76
+ }
77
+ export function __wbindgen_cast_0000000000000002(arg0, arg1) {
78
+ // Cast intrinsic for `Ref(String) -> Externref`.
79
+ const ret = getStringFromWasm0(arg0, arg1);
80
+ return ret;
81
+ }
82
+ export function __wbindgen_init_externref_table() {
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
+ function addToExternrefTable0(obj) {
92
+ const idx = wasm.__externref_table_alloc();
93
+ wasm.__wbindgen_externrefs.set(idx, obj);
94
+ return idx;
95
+ }
96
+
97
+ function getArrayU8FromWasm0(ptr, len) {
98
+ ptr = ptr >>> 0;
99
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
100
+ }
101
+
102
+ let cachedDataViewMemory0 = null;
103
+ function getDataViewMemory0() {
104
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
105
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
106
+ }
107
+ return cachedDataViewMemory0;
108
+ }
109
+
110
+ function getStringFromWasm0(ptr, len) {
111
+ return decodeText(ptr >>> 0, len);
112
+ }
113
+
114
+ let cachedUint8ArrayMemory0 = null;
115
+ function getUint8ArrayMemory0() {
116
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
117
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
118
+ }
119
+ return cachedUint8ArrayMemory0;
120
+ }
121
+
122
+ function handleError(f, args) {
123
+ try {
124
+ return f.apply(this, args);
125
+ } catch (e) {
126
+ const idx = addToExternrefTable0(e);
127
+ wasm.__wbindgen_exn_store(idx);
128
+ }
129
+ }
130
+
131
+ function passArray8ToWasm0(arg, malloc) {
132
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
133
+ getUint8ArrayMemory0().set(arg, ptr / 1);
134
+ WASM_VECTOR_LEN = arg.length;
135
+ return ptr;
136
+ }
137
+
138
+ function passStringToWasm0(arg, malloc, realloc) {
139
+ if (realloc === undefined) {
140
+ const buf = cachedTextEncoder.encode(arg);
141
+ const ptr = malloc(buf.length, 1) >>> 0;
142
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
143
+ WASM_VECTOR_LEN = buf.length;
144
+ return ptr;
145
+ }
146
+
147
+ let len = arg.length;
148
+ let ptr = malloc(len, 1) >>> 0;
149
+
150
+ const mem = getUint8ArrayMemory0();
151
+
152
+ let offset = 0;
153
+
154
+ for (; offset < len; offset++) {
155
+ const code = arg.charCodeAt(offset);
156
+ if (code > 0x7F) break;
157
+ mem[ptr + offset] = code;
158
+ }
159
+ if (offset !== len) {
160
+ if (offset !== 0) {
161
+ arg = arg.slice(offset);
162
+ }
163
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
164
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
165
+ const ret = cachedTextEncoder.encodeInto(arg, view);
166
+
167
+ offset += ret.written;
168
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
169
+ }
170
+
171
+ WASM_VECTOR_LEN = offset;
172
+ return ptr;
173
+ }
174
+
175
+ function takeFromExternrefTable0(idx) {
176
+ const value = wasm.__wbindgen_externrefs.get(idx);
177
+ wasm.__externref_table_dealloc(idx);
178
+ return value;
179
+ }
180
+
181
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
182
+ cachedTextDecoder.decode();
183
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
184
+ let numBytesDecoded = 0;
185
+ function decodeText(ptr, len) {
186
+ numBytesDecoded += len;
187
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
188
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
189
+ cachedTextDecoder.decode();
190
+ numBytesDecoded = len;
191
+ }
192
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
193
+ }
194
+
195
+ const cachedTextEncoder = new TextEncoder();
196
+
197
+ if (!('encodeInto' in cachedTextEncoder)) {
198
+ cachedTextEncoder.encodeInto = function (arg, view) {
199
+ const buf = cachedTextEncoder.encode(arg);
200
+ view.set(buf);
201
+ return {
202
+ read: arg.length,
203
+ written: buf.length
204
+ };
205
+ };
206
+ }
207
+
208
+ let WASM_VECTOR_LEN = 0;
209
+
210
+
211
+ let wasm;
212
+ export function __wbg_set_wasm(val) {
213
+ wasm = val;
214
+ }