xwing-wasm 0.1.0 → 0.2.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.
@@ -1,18 +1,18 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  export interface EncapsulateResult {
4
- ciphertext: string;
5
- sharedKey: string;
4
+ ciphertext: Uint8Array;
5
+ sharedKey: Uint8Array;
6
6
  }
7
7
 
8
8
  export interface GenerateKeypairResult {
9
- secretKey: string;
10
- publicKey: string;
9
+ secretKey: Uint8Array;
10
+ publicKey: Uint8Array;
11
11
  }
12
12
 
13
13
 
14
- export function decapsulate(sk: string, ciphertext: string): string;
14
+ export function decapsulate(sk: Uint8Array, ciphertext: Uint8Array): Uint8Array;
15
15
 
16
- export function encapsulate(pk: string): EncapsulateResult;
16
+ export function encapsulate(pk: Uint8Array): EncapsulateResult;
17
17
 
18
18
  export function generateKeypair(): GenerateKeypairResult;
@@ -1,37 +1,28 @@
1
1
  /**
2
- * @param {string} sk
3
- * @param {string} ciphertext
4
- * @returns {string}
2
+ * @param {Uint8Array} sk
3
+ * @param {Uint8Array} ciphertext
4
+ * @returns {Uint8Array}
5
5
  */
6
6
  export function decapsulate(sk, ciphertext) {
7
- let deferred4_0;
8
- let deferred4_1;
9
- try {
10
- const ptr0 = passStringToWasm0(sk, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
11
- const len0 = WASM_VECTOR_LEN;
12
- const ptr1 = passStringToWasm0(ciphertext, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
13
- const len1 = WASM_VECTOR_LEN;
14
- const ret = wasm.decapsulate(ptr0, len0, ptr1, len1);
15
- var ptr3 = ret[0];
16
- var len3 = ret[1];
17
- if (ret[3]) {
18
- ptr3 = 0; len3 = 0;
19
- throw takeFromExternrefTable0(ret[2]);
20
- }
21
- deferred4_0 = ptr3;
22
- deferred4_1 = len3;
23
- return getStringFromWasm0(ptr3, len3);
24
- } finally {
25
- wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
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]);
26
14
  }
15
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
16
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
17
+ return v3;
27
18
  }
28
19
 
29
20
  /**
30
- * @param {string} pk
21
+ * @param {Uint8Array} pk
31
22
  * @returns {EncapsulateResult}
32
23
  */
33
24
  export function encapsulate(pk) {
34
- const ptr0 = passStringToWasm0(pk, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
25
+ const ptr0 = passArray8ToWasm0(pk, wasm.__wbindgen_malloc);
35
26
  const len0 = WASM_VECTOR_LEN;
36
27
  const ret = wasm.encapsulate(ptr0, len0);
37
28
  if (ret[2]) {
@@ -47,7 +38,7 @@ export function generateKeypair() {
47
38
  const ret = wasm.generateKeypair();
48
39
  return ret;
49
40
  }
50
- export function __wbg_Error_960c155d3d49e4c2(arg0, arg1) {
41
+ export function __wbg_Error_9dc85fe1bc224456(arg0, arg1) {
51
42
  const ret = Error(getStringFromWasm0(arg0, arg1));
52
43
  return ret;
53
44
  }
@@ -58,20 +49,32 @@ export function __wbg_String_8564e559799eccda(arg0, arg1) {
58
49
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
59
50
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
60
51
  }
61
- export function __wbg___wbindgen_throw_6b64449b9b9ed33c(arg0, arg1) {
52
+ export function __wbg___wbindgen_throw_bbadd78c1bac3a77(arg0, arg1) {
62
53
  throw new Error(getStringFromWasm0(arg0, arg1));
63
54
  }
64
55
  export function __wbg_getRandomValues_76dfc69825c9c552() { return handleError(function (arg0, arg1) {
65
56
  globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
66
57
  }, arguments); }
67
- export function __wbg_new_aa8d0fa9762c29bd() {
58
+ export function __wbg_new_0b303268aa395a38() {
59
+ const ret = new Array();
60
+ return ret;
61
+ }
62
+ export function __wbg_new_20b778a4c5c691c3() {
68
63
  const ret = new Object();
69
64
  return ret;
70
65
  }
71
66
  export function __wbg_set_6be42768c690e380(arg0, arg1, arg2) {
72
67
  arg0[arg1] = arg2;
73
68
  }
74
- export function __wbindgen_cast_0000000000000001(arg0, arg1) {
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) {
75
78
  // Cast intrinsic for `Ref(String) -> Externref`.
76
79
  const ret = getStringFromWasm0(arg0, arg1);
77
80
  return ret;
@@ -105,8 +108,7 @@ function getDataViewMemory0() {
105
108
  }
106
109
 
107
110
  function getStringFromWasm0(ptr, len) {
108
- ptr = ptr >>> 0;
109
- return decodeText(ptr, len);
111
+ return decodeText(ptr >>> 0, len);
110
112
  }
111
113
 
112
114
  let cachedUint8ArrayMemory0 = null;
@@ -126,6 +128,13 @@ function handleError(f, args) {
126
128
  }
127
129
  }
128
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
+
129
138
  function passStringToWasm0(arg, malloc, realloc) {
130
139
  if (realloc === undefined) {
131
140
  const buf = cachedTextEncoder.encode(arg);
package/node/xwing.d.ts CHANGED
@@ -1,18 +1,18 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  export interface EncapsulateResult {
4
- ciphertext: string;
5
- sharedKey: string;
4
+ ciphertext: Uint8Array;
5
+ sharedKey: Uint8Array;
6
6
  }
7
7
 
8
8
  export interface GenerateKeypairResult {
9
- secretKey: string;
10
- publicKey: string;
9
+ secretKey: Uint8Array;
10
+ publicKey: Uint8Array;
11
11
  }
12
12
 
13
13
 
14
- export function decapsulate(sk: string, ciphertext: string): string;
14
+ export function decapsulate(sk: Uint8Array, ciphertext: Uint8Array): Uint8Array;
15
15
 
16
- export function encapsulate(pk: string): EncapsulateResult;
16
+ export function encapsulate(pk: Uint8Array): EncapsulateResult;
17
17
 
18
18
  export function generateKeypair(): GenerateKeypairResult;
package/node/xwing.js CHANGED
@@ -1,40 +1,31 @@
1
1
  /* @ts-self-types="./xwing.d.ts" */
2
2
 
3
3
  /**
4
- * @param {string} sk
5
- * @param {string} ciphertext
6
- * @returns {string}
4
+ * @param {Uint8Array} sk
5
+ * @param {Uint8Array} ciphertext
6
+ * @returns {Uint8Array}
7
7
  */
8
8
  function decapsulate(sk, ciphertext) {
9
- let deferred4_0;
10
- let deferred4_1;
11
- try {
12
- const ptr0 = passStringToWasm0(sk, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
13
- const len0 = WASM_VECTOR_LEN;
14
- const ptr1 = passStringToWasm0(ciphertext, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
15
- const len1 = WASM_VECTOR_LEN;
16
- const ret = wasm.decapsulate(ptr0, len0, ptr1, len1);
17
- var ptr3 = ret[0];
18
- var len3 = ret[1];
19
- if (ret[3]) {
20
- ptr3 = 0; len3 = 0;
21
- throw takeFromExternrefTable0(ret[2]);
22
- }
23
- deferred4_0 = ptr3;
24
- deferred4_1 = len3;
25
- return getStringFromWasm0(ptr3, len3);
26
- } finally {
27
- wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
9
+ const ptr0 = passArray8ToWasm0(sk, wasm.__wbindgen_malloc);
10
+ const len0 = WASM_VECTOR_LEN;
11
+ const ptr1 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
12
+ const len1 = WASM_VECTOR_LEN;
13
+ const ret = wasm.decapsulate(ptr0, len0, ptr1, len1);
14
+ if (ret[3]) {
15
+ throw takeFromExternrefTable0(ret[2]);
28
16
  }
17
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
18
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
19
+ return v3;
29
20
  }
30
21
  exports.decapsulate = decapsulate;
31
22
 
32
23
  /**
33
- * @param {string} pk
24
+ * @param {Uint8Array} pk
34
25
  * @returns {EncapsulateResult}
35
26
  */
36
27
  function encapsulate(pk) {
37
- const ptr0 = passStringToWasm0(pk, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
28
+ const ptr0 = passArray8ToWasm0(pk, wasm.__wbindgen_malloc);
38
29
  const len0 = WASM_VECTOR_LEN;
39
30
  const ret = wasm.encapsulate(ptr0, len0);
40
31
  if (ret[2]) {
@@ -55,7 +46,7 @@ exports.generateKeypair = generateKeypair;
55
46
  function __wbg_get_imports() {
56
47
  const import0 = {
57
48
  __proto__: null,
58
- __wbg_Error_960c155d3d49e4c2: function(arg0, arg1) {
49
+ __wbg_Error_9dc85fe1bc224456: function(arg0, arg1) {
59
50
  const ret = Error(getStringFromWasm0(arg0, arg1));
60
51
  return ret;
61
52
  },
@@ -66,20 +57,32 @@ function __wbg_get_imports() {
66
57
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
67
58
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
68
59
  },
69
- __wbg___wbindgen_throw_6b64449b9b9ed33c: function(arg0, arg1) {
60
+ __wbg___wbindgen_throw_bbadd78c1bac3a77: function(arg0, arg1) {
70
61
  throw new Error(getStringFromWasm0(arg0, arg1));
71
62
  },
72
63
  __wbg_getRandomValues_76dfc69825c9c552: function() { return handleError(function (arg0, arg1) {
73
64
  globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
74
65
  }, arguments); },
75
- __wbg_new_aa8d0fa9762c29bd: function() {
66
+ __wbg_new_0b303268aa395a38: function() {
67
+ const ret = new Array();
68
+ return ret;
69
+ },
70
+ __wbg_new_20b778a4c5c691c3: function() {
76
71
  const ret = new Object();
77
72
  return ret;
78
73
  },
79
74
  __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
80
75
  arg0[arg1] = arg2;
81
76
  },
82
- __wbindgen_cast_0000000000000001: function(arg0, arg1) {
77
+ __wbg_set_da33c120a6584674: function(arg0, arg1, arg2) {
78
+ arg0[arg1 >>> 0] = arg2;
79
+ },
80
+ __wbindgen_cast_0000000000000001: function(arg0) {
81
+ // Cast intrinsic for `F64 -> Externref`.
82
+ const ret = arg0;
83
+ return ret;
84
+ },
85
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
83
86
  // Cast intrinsic for `Ref(String) -> Externref`.
84
87
  const ret = getStringFromWasm0(arg0, arg1);
85
88
  return ret;
@@ -120,8 +123,7 @@ function getDataViewMemory0() {
120
123
  }
121
124
 
122
125
  function getStringFromWasm0(ptr, len) {
123
- ptr = ptr >>> 0;
124
- return decodeText(ptr, len);
126
+ return decodeText(ptr >>> 0, len);
125
127
  }
126
128
 
127
129
  let cachedUint8ArrayMemory0 = null;
@@ -141,6 +143,13 @@ function handleError(f, args) {
141
143
  }
142
144
  }
143
145
 
146
+ function passArray8ToWasm0(arg, malloc) {
147
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
148
+ getUint8ArrayMemory0().set(arg, ptr / 1);
149
+ WASM_VECTOR_LEN = arg.length;
150
+ return ptr;
151
+ }
152
+
144
153
  function passStringToWasm0(arg, malloc, realloc) {
145
154
  if (realloc === undefined) {
146
155
  const buf = cachedTextEncoder.encode(arg);
@@ -208,5 +217,6 @@ let WASM_VECTOR_LEN = 0;
208
217
  const wasmPath = `${__dirname}/../xwing_bg.wasm`;
209
218
  const wasmBytes = require('fs').readFileSync(wasmPath);
210
219
  const wasmModule = new WebAssembly.Module(wasmBytes);
211
- let wasm = new WebAssembly.Instance(wasmModule, __wbg_get_imports()).exports;
220
+ let wasmInstance = new WebAssembly.Instance(wasmModule, __wbg_get_imports());
221
+ let wasm = wasmInstance.exports;
212
222
  wasm.__wbindgen_start();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xwing-wasm",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
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": {
package/web/xwing.d.ts CHANGED
@@ -1,19 +1,19 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
  export interface EncapsulateResult {
4
- ciphertext: string;
5
- sharedKey: string;
4
+ ciphertext: Uint8Array;
5
+ sharedKey: Uint8Array;
6
6
  }
7
7
 
8
8
  export interface GenerateKeypairResult {
9
- secretKey: string;
10
- publicKey: string;
9
+ secretKey: Uint8Array;
10
+ publicKey: Uint8Array;
11
11
  }
12
12
 
13
13
 
14
- export function decapsulate(sk: string, ciphertext: string): string;
14
+ export function decapsulate(sk: Uint8Array, ciphertext: Uint8Array): Uint8Array;
15
15
 
16
- export function encapsulate(pk: string): EncapsulateResult;
16
+ export function encapsulate(pk: Uint8Array): EncapsulateResult;
17
17
 
18
18
  export function generateKeypair(): GenerateKeypairResult;
19
19
 
package/web/xwing.js CHANGED
@@ -1,39 +1,30 @@
1
1
  /* @ts-self-types="./xwing.d.ts" */
2
2
 
3
3
  /**
4
- * @param {string} sk
5
- * @param {string} ciphertext
6
- * @returns {string}
4
+ * @param {Uint8Array} sk
5
+ * @param {Uint8Array} ciphertext
6
+ * @returns {Uint8Array}
7
7
  */
8
8
  export function decapsulate(sk, ciphertext) {
9
- let deferred4_0;
10
- let deferred4_1;
11
- try {
12
- const ptr0 = passStringToWasm0(sk, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
13
- const len0 = WASM_VECTOR_LEN;
14
- const ptr1 = passStringToWasm0(ciphertext, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
15
- const len1 = WASM_VECTOR_LEN;
16
- const ret = wasm.decapsulate(ptr0, len0, ptr1, len1);
17
- var ptr3 = ret[0];
18
- var len3 = ret[1];
19
- if (ret[3]) {
20
- ptr3 = 0; len3 = 0;
21
- throw takeFromExternrefTable0(ret[2]);
22
- }
23
- deferred4_0 = ptr3;
24
- deferred4_1 = len3;
25
- return getStringFromWasm0(ptr3, len3);
26
- } finally {
27
- wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
9
+ const ptr0 = passArray8ToWasm0(sk, wasm.__wbindgen_malloc);
10
+ const len0 = WASM_VECTOR_LEN;
11
+ const ptr1 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
12
+ const len1 = WASM_VECTOR_LEN;
13
+ const ret = wasm.decapsulate(ptr0, len0, ptr1, len1);
14
+ if (ret[3]) {
15
+ throw takeFromExternrefTable0(ret[2]);
28
16
  }
17
+ var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
18
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
19
+ return v3;
29
20
  }
30
21
 
31
22
  /**
32
- * @param {string} pk
23
+ * @param {Uint8Array} pk
33
24
  * @returns {EncapsulateResult}
34
25
  */
35
26
  export function encapsulate(pk) {
36
- const ptr0 = passStringToWasm0(pk, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
27
+ const ptr0 = passArray8ToWasm0(pk, wasm.__wbindgen_malloc);
37
28
  const len0 = WASM_VECTOR_LEN;
38
29
  const ret = wasm.encapsulate(ptr0, len0);
39
30
  if (ret[2]) {
@@ -52,7 +43,7 @@ export function generateKeypair() {
52
43
  function __wbg_get_imports() {
53
44
  const import0 = {
54
45
  __proto__: null,
55
- __wbg_Error_960c155d3d49e4c2: function(arg0, arg1) {
46
+ __wbg_Error_9dc85fe1bc224456: function(arg0, arg1) {
56
47
  const ret = Error(getStringFromWasm0(arg0, arg1));
57
48
  return ret;
58
49
  },
@@ -63,20 +54,32 @@ function __wbg_get_imports() {
63
54
  getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
64
55
  getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
65
56
  },
66
- __wbg___wbindgen_throw_6b64449b9b9ed33c: function(arg0, arg1) {
57
+ __wbg___wbindgen_throw_bbadd78c1bac3a77: function(arg0, arg1) {
67
58
  throw new Error(getStringFromWasm0(arg0, arg1));
68
59
  },
69
60
  __wbg_getRandomValues_76dfc69825c9c552: function() { return handleError(function (arg0, arg1) {
70
61
  globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
71
62
  }, arguments); },
72
- __wbg_new_aa8d0fa9762c29bd: function() {
63
+ __wbg_new_0b303268aa395a38: function() {
64
+ const ret = new Array();
65
+ return ret;
66
+ },
67
+ __wbg_new_20b778a4c5c691c3: function() {
73
68
  const ret = new Object();
74
69
  return ret;
75
70
  },
76
71
  __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
77
72
  arg0[arg1] = arg2;
78
73
  },
79
- __wbindgen_cast_0000000000000001: function(arg0, arg1) {
74
+ __wbg_set_da33c120a6584674: function(arg0, arg1, arg2) {
75
+ arg0[arg1 >>> 0] = arg2;
76
+ },
77
+ __wbindgen_cast_0000000000000001: function(arg0) {
78
+ // Cast intrinsic for `F64 -> Externref`.
79
+ const ret = arg0;
80
+ return ret;
81
+ },
82
+ __wbindgen_cast_0000000000000002: function(arg0, arg1) {
80
83
  // Cast intrinsic for `Ref(String) -> Externref`.
81
84
  const ret = getStringFromWasm0(arg0, arg1);
82
85
  return ret;
@@ -117,8 +120,7 @@ function getDataViewMemory0() {
117
120
  }
118
121
 
119
122
  function getStringFromWasm0(ptr, len) {
120
- ptr = ptr >>> 0;
121
- return decodeText(ptr, len);
123
+ return decodeText(ptr >>> 0, len);
122
124
  }
123
125
 
124
126
  let cachedUint8ArrayMemory0 = null;
@@ -138,6 +140,13 @@ function handleError(f, args) {
138
140
  }
139
141
  }
140
142
 
143
+ function passArray8ToWasm0(arg, malloc) {
144
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
145
+ getUint8ArrayMemory0().set(arg, ptr / 1);
146
+ WASM_VECTOR_LEN = arg.length;
147
+ return ptr;
148
+ }
149
+
141
150
  function passStringToWasm0(arg, malloc, realloc) {
142
151
  if (realloc === undefined) {
143
152
  const buf = cachedTextEncoder.encode(arg);
@@ -210,8 +219,9 @@ if (!('encodeInto' in cachedTextEncoder)) {
210
219
 
211
220
  let WASM_VECTOR_LEN = 0;
212
221
 
213
- let wasmModule, wasm;
222
+ let wasmModule, wasmInstance, wasm;
214
223
  function __wbg_finalize_init(instance, module) {
224
+ wasmInstance = instance;
215
225
  wasm = instance.exports;
216
226
  wasmModule = module;
217
227
  cachedDataViewMemory0 = null;
package/xwing_bg.wasm CHANGED
Binary file