@theermite/morphic-wasm-core 2.0.0-alpha.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/LICENSE +661 -0
- package/README.md +76 -0
- package/package.json +24 -0
- package/pkg/README.md +76 -0
- package/pkg/morphic_wasm_core.d.ts +98 -0
- package/pkg/morphic_wasm_core.js +492 -0
- package/pkg/morphic_wasm_core_bg.wasm +0 -0
- package/pkg/morphic_wasm_core_bg.wasm.d.ts +15 -0
- package/pkg/package.json +17 -0
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
/* @ts-self-types="./morphic_wasm_core.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Result type for a generated key pair, exposed to JS as a struct with
|
|
5
|
+
* `publicKey` and `secretKey` getters returning Uint8Array.
|
|
6
|
+
*/
|
|
7
|
+
export class WasmKeyPair {
|
|
8
|
+
static __wrap(ptr) {
|
|
9
|
+
const obj = Object.create(WasmKeyPair.prototype);
|
|
10
|
+
obj.__wbg_ptr = ptr;
|
|
11
|
+
WasmKeyPairFinalization.register(obj, obj.__wbg_ptr, obj);
|
|
12
|
+
return obj;
|
|
13
|
+
}
|
|
14
|
+
__destroy_into_raw() {
|
|
15
|
+
const ptr = this.__wbg_ptr;
|
|
16
|
+
this.__wbg_ptr = 0;
|
|
17
|
+
WasmKeyPairFinalization.unregister(this);
|
|
18
|
+
return ptr;
|
|
19
|
+
}
|
|
20
|
+
free() {
|
|
21
|
+
const ptr = this.__destroy_into_raw();
|
|
22
|
+
wasm.__wbg_wasmkeypair_free(ptr, 0);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* @returns {Uint8Array}
|
|
26
|
+
*/
|
|
27
|
+
get publicKey() {
|
|
28
|
+
try {
|
|
29
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
30
|
+
wasm.wasmkeypair_publicKey(retptr, this.__wbg_ptr);
|
|
31
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
32
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
33
|
+
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
34
|
+
wasm.__wbindgen_export3(r0, r1 * 1, 1);
|
|
35
|
+
return v1;
|
|
36
|
+
} finally {
|
|
37
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* @returns {Uint8Array}
|
|
42
|
+
*/
|
|
43
|
+
get secretKey() {
|
|
44
|
+
try {
|
|
45
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
46
|
+
wasm.wasmkeypair_secretKey(retptr, this.__wbg_ptr);
|
|
47
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
48
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
49
|
+
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
50
|
+
wasm.__wbindgen_export3(r0, r1 * 1, 1);
|
|
51
|
+
return v1;
|
|
52
|
+
} finally {
|
|
53
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
if (Symbol.dispose) WasmKeyPair.prototype[Symbol.dispose] = WasmKeyPair.prototype.free;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Decrypt `ciphertext` using NaCl box.open.
|
|
61
|
+
*
|
|
62
|
+
* Inputs:
|
|
63
|
+
* - ciphertext: bytes produced by `wasm_encrypt_box` (or any NaCl-compatible
|
|
64
|
+
* box implementation, including tweetnacl-js)
|
|
65
|
+
* - nonce: 24 bytes used at encryption time
|
|
66
|
+
* - sender_pk: 32 bytes (peer's public key)
|
|
67
|
+
* - recipient_sk: 32 bytes (our secret key)
|
|
68
|
+
*
|
|
69
|
+
* Returns the plaintext, or Err on any authentication failure (wrong key,
|
|
70
|
+
* tampered ciphertext, wrong nonce, truncated input).
|
|
71
|
+
* @param {Uint8Array} ciphertext
|
|
72
|
+
* @param {Uint8Array} nonce
|
|
73
|
+
* @param {Uint8Array} sender_pk
|
|
74
|
+
* @param {Uint8Array} recipient_sk
|
|
75
|
+
* @returns {Uint8Array}
|
|
76
|
+
*/
|
|
77
|
+
export function wasmDecryptBox(ciphertext, nonce, sender_pk, recipient_sk) {
|
|
78
|
+
try {
|
|
79
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
80
|
+
const ptr0 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_export2);
|
|
81
|
+
const len0 = WASM_VECTOR_LEN;
|
|
82
|
+
const ptr1 = passArray8ToWasm0(nonce, wasm.__wbindgen_export2);
|
|
83
|
+
const len1 = WASM_VECTOR_LEN;
|
|
84
|
+
const ptr2 = passArray8ToWasm0(sender_pk, wasm.__wbindgen_export2);
|
|
85
|
+
const len2 = WASM_VECTOR_LEN;
|
|
86
|
+
const ptr3 = passArray8ToWasm0(recipient_sk, wasm.__wbindgen_export2);
|
|
87
|
+
const len3 = WASM_VECTOR_LEN;
|
|
88
|
+
wasm.wasmDecryptBox(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
|
|
89
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
90
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
91
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
92
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
93
|
+
if (r3) {
|
|
94
|
+
throw takeObject(r2);
|
|
95
|
+
}
|
|
96
|
+
var v5 = getArrayU8FromWasm0(r0, r1).slice();
|
|
97
|
+
wasm.__wbindgen_export3(r0, r1 * 1, 1);
|
|
98
|
+
return v5;
|
|
99
|
+
} finally {
|
|
100
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Encrypt `plaintext` using NaCl box (Curve25519 + XSalsa20Poly1305).
|
|
106
|
+
*
|
|
107
|
+
* Inputs:
|
|
108
|
+
* - plaintext: arbitrary bytes
|
|
109
|
+
* - recipient_pk: 32 bytes (Curve25519 public key)
|
|
110
|
+
* - sender_sk: 32 bytes (Curve25519 secret key)
|
|
111
|
+
* - nonce: 24 bytes (must be unique per (sender, recipient) pair)
|
|
112
|
+
*
|
|
113
|
+
* Output: ciphertext bytes (includes 16-byte Poly1305 tag).
|
|
114
|
+
* @param {Uint8Array} plaintext
|
|
115
|
+
* @param {Uint8Array} recipient_pk
|
|
116
|
+
* @param {Uint8Array} sender_sk
|
|
117
|
+
* @param {Uint8Array} nonce
|
|
118
|
+
* @returns {Uint8Array}
|
|
119
|
+
*/
|
|
120
|
+
export function wasmEncryptBox(plaintext, recipient_pk, sender_sk, nonce) {
|
|
121
|
+
try {
|
|
122
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
123
|
+
const ptr0 = passArray8ToWasm0(plaintext, wasm.__wbindgen_export2);
|
|
124
|
+
const len0 = WASM_VECTOR_LEN;
|
|
125
|
+
const ptr1 = passArray8ToWasm0(recipient_pk, wasm.__wbindgen_export2);
|
|
126
|
+
const len1 = WASM_VECTOR_LEN;
|
|
127
|
+
const ptr2 = passArray8ToWasm0(sender_sk, wasm.__wbindgen_export2);
|
|
128
|
+
const len2 = WASM_VECTOR_LEN;
|
|
129
|
+
const ptr3 = passArray8ToWasm0(nonce, wasm.__wbindgen_export2);
|
|
130
|
+
const len3 = WASM_VECTOR_LEN;
|
|
131
|
+
wasm.wasmEncryptBox(retptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
|
|
132
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
133
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
134
|
+
var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
|
|
135
|
+
var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
|
|
136
|
+
if (r3) {
|
|
137
|
+
throw takeObject(r2);
|
|
138
|
+
}
|
|
139
|
+
var v5 = getArrayU8FromWasm0(r0, r1).slice();
|
|
140
|
+
wasm.__wbindgen_export3(r0, r1 * 1, 1);
|
|
141
|
+
return v5;
|
|
142
|
+
} finally {
|
|
143
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Generate a Curve25519 key pair using the system CSPRNG
|
|
149
|
+
* (Web Crypto API in browser via `getrandom` js feature).
|
|
150
|
+
* @returns {WasmKeyPair}
|
|
151
|
+
*/
|
|
152
|
+
export function wasmGenerateKeypair() {
|
|
153
|
+
const ret = wasm.wasmGenerateKeypair();
|
|
154
|
+
return WasmKeyPair.__wrap(ret);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Sample a fresh nonce using the construction's recommended generator.
|
|
159
|
+
* @returns {Uint8Array}
|
|
160
|
+
*/
|
|
161
|
+
export function wasmGenerateNonce() {
|
|
162
|
+
try {
|
|
163
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
164
|
+
wasm.wasmGenerateNonce(retptr);
|
|
165
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
166
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
167
|
+
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
168
|
+
wasm.__wbindgen_export3(r0, r1 * 1, 1);
|
|
169
|
+
return v1;
|
|
170
|
+
} finally {
|
|
171
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Generate `len` random bytes using the system CSPRNG.
|
|
177
|
+
* @param {number} len
|
|
178
|
+
* @returns {Uint8Array}
|
|
179
|
+
*/
|
|
180
|
+
export function wasmRandomBytes(len) {
|
|
181
|
+
try {
|
|
182
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
183
|
+
wasm.wasmRandomBytes(retptr, len);
|
|
184
|
+
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
185
|
+
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
186
|
+
var v1 = getArrayU8FromWasm0(r0, r1).slice();
|
|
187
|
+
wasm.__wbindgen_export3(r0, r1 * 1, 1);
|
|
188
|
+
return v1;
|
|
189
|
+
} finally {
|
|
190
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function __wbg_get_imports() {
|
|
194
|
+
const import0 = {
|
|
195
|
+
__proto__: null,
|
|
196
|
+
__wbg_Error_ef53bc310eb298a0: function(arg0, arg1) {
|
|
197
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
198
|
+
return addHeapObject(ret);
|
|
199
|
+
},
|
|
200
|
+
__wbg___wbindgen_is_function_754e9f305ff6029e: function(arg0) {
|
|
201
|
+
const ret = typeof(getObject(arg0)) === 'function';
|
|
202
|
+
return ret;
|
|
203
|
+
},
|
|
204
|
+
__wbg___wbindgen_is_object_56732c2bc353f41d: function(arg0) {
|
|
205
|
+
const val = getObject(arg0);
|
|
206
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
207
|
+
return ret;
|
|
208
|
+
},
|
|
209
|
+
__wbg___wbindgen_is_string_c236cabd84a4d769: function(arg0) {
|
|
210
|
+
const ret = typeof(getObject(arg0)) === 'string';
|
|
211
|
+
return ret;
|
|
212
|
+
},
|
|
213
|
+
__wbg___wbindgen_is_undefined_67b456be8673d3d7: function(arg0) {
|
|
214
|
+
const ret = getObject(arg0) === undefined;
|
|
215
|
+
return ret;
|
|
216
|
+
},
|
|
217
|
+
__wbg___wbindgen_throw_1506f2235d1bdba0: function(arg0, arg1) {
|
|
218
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
219
|
+
},
|
|
220
|
+
__wbg_call_9c758de292015997: function() { return handleError(function (arg0, arg1, arg2) {
|
|
221
|
+
const ret = getObject(arg0).call(getObject(arg1), getObject(arg2));
|
|
222
|
+
return addHeapObject(ret);
|
|
223
|
+
}, arguments); },
|
|
224
|
+
__wbg_crypto_38df2bab126b63dc: function(arg0) {
|
|
225
|
+
const ret = getObject(arg0).crypto;
|
|
226
|
+
return addHeapObject(ret);
|
|
227
|
+
},
|
|
228
|
+
__wbg_getRandomValues_c44a50d8cfdaebeb: function() { return handleError(function (arg0, arg1) {
|
|
229
|
+
getObject(arg0).getRandomValues(getObject(arg1));
|
|
230
|
+
}, arguments); },
|
|
231
|
+
__wbg_length_4a591ecaa01354d9: function(arg0) {
|
|
232
|
+
const ret = getObject(arg0).length;
|
|
233
|
+
return ret;
|
|
234
|
+
},
|
|
235
|
+
__wbg_msCrypto_bd5a034af96bcba6: function(arg0) {
|
|
236
|
+
const ret = getObject(arg0).msCrypto;
|
|
237
|
+
return addHeapObject(ret);
|
|
238
|
+
},
|
|
239
|
+
__wbg_new_with_length_36a4998e27b014c5: function(arg0) {
|
|
240
|
+
const ret = new Uint8Array(arg0 >>> 0);
|
|
241
|
+
return addHeapObject(ret);
|
|
242
|
+
},
|
|
243
|
+
__wbg_node_84ea875411254db1: function(arg0) {
|
|
244
|
+
const ret = getObject(arg0).node;
|
|
245
|
+
return addHeapObject(ret);
|
|
246
|
+
},
|
|
247
|
+
__wbg_process_44c7a14e11e9f69e: function(arg0) {
|
|
248
|
+
const ret = getObject(arg0).process;
|
|
249
|
+
return addHeapObject(ret);
|
|
250
|
+
},
|
|
251
|
+
__wbg_prototypesetcall_3249fc62a0fafa30: function(arg0, arg1, arg2) {
|
|
252
|
+
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), getObject(arg2));
|
|
253
|
+
},
|
|
254
|
+
__wbg_randomFillSync_6c25eac9869eb53c: function() { return handleError(function (arg0, arg1) {
|
|
255
|
+
getObject(arg0).randomFillSync(takeObject(arg1));
|
|
256
|
+
}, arguments); },
|
|
257
|
+
__wbg_require_b4edbdcf3e2a1ef0: function() { return handleError(function () {
|
|
258
|
+
const ret = module.require;
|
|
259
|
+
return addHeapObject(ret);
|
|
260
|
+
}, arguments); },
|
|
261
|
+
__wbg_static_accessor_GLOBAL_9d53f2689e622ca1: function() {
|
|
262
|
+
const ret = typeof global === 'undefined' ? null : global;
|
|
263
|
+
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
264
|
+
},
|
|
265
|
+
__wbg_static_accessor_GLOBAL_THIS_a1a35cec07001a8a: function() {
|
|
266
|
+
const ret = typeof globalThis === 'undefined' ? null : globalThis;
|
|
267
|
+
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
268
|
+
},
|
|
269
|
+
__wbg_static_accessor_SELF_4c59f6c7ea29a144: function() {
|
|
270
|
+
const ret = typeof self === 'undefined' ? null : self;
|
|
271
|
+
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
272
|
+
},
|
|
273
|
+
__wbg_static_accessor_WINDOW_e70ae9f2eb052253: function() {
|
|
274
|
+
const ret = typeof window === 'undefined' ? null : window;
|
|
275
|
+
return isLikeNone(ret) ? 0 : addHeapObject(ret);
|
|
276
|
+
},
|
|
277
|
+
__wbg_subarray_4aa221f6a4f5ab22: function(arg0, arg1, arg2) {
|
|
278
|
+
const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);
|
|
279
|
+
return addHeapObject(ret);
|
|
280
|
+
},
|
|
281
|
+
__wbg_versions_276b2795b1c6a219: function(arg0) {
|
|
282
|
+
const ret = getObject(arg0).versions;
|
|
283
|
+
return addHeapObject(ret);
|
|
284
|
+
},
|
|
285
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
286
|
+
// Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
|
|
287
|
+
const ret = getArrayU8FromWasm0(arg0, arg1);
|
|
288
|
+
return addHeapObject(ret);
|
|
289
|
+
},
|
|
290
|
+
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
291
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
292
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
293
|
+
return addHeapObject(ret);
|
|
294
|
+
},
|
|
295
|
+
__wbindgen_object_clone_ref: function(arg0) {
|
|
296
|
+
const ret = getObject(arg0);
|
|
297
|
+
return addHeapObject(ret);
|
|
298
|
+
},
|
|
299
|
+
__wbindgen_object_drop_ref: function(arg0) {
|
|
300
|
+
takeObject(arg0);
|
|
301
|
+
},
|
|
302
|
+
};
|
|
303
|
+
return {
|
|
304
|
+
__proto__: null,
|
|
305
|
+
"./morphic_wasm_core_bg.js": import0,
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const WasmKeyPairFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
310
|
+
? { register: () => {}, unregister: () => {} }
|
|
311
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_wasmkeypair_free(ptr, 1));
|
|
312
|
+
|
|
313
|
+
function addHeapObject(obj) {
|
|
314
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
315
|
+
const idx = heap_next;
|
|
316
|
+
heap_next = heap[idx];
|
|
317
|
+
|
|
318
|
+
heap[idx] = obj;
|
|
319
|
+
return idx;
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function dropObject(idx) {
|
|
323
|
+
if (idx < 1028) return;
|
|
324
|
+
heap[idx] = heap_next;
|
|
325
|
+
heap_next = idx;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
329
|
+
ptr = ptr >>> 0;
|
|
330
|
+
return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
let cachedDataViewMemory0 = null;
|
|
334
|
+
function getDataViewMemory0() {
|
|
335
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
336
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
337
|
+
}
|
|
338
|
+
return cachedDataViewMemory0;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function getStringFromWasm0(ptr, len) {
|
|
342
|
+
return decodeText(ptr >>> 0, len);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
let cachedUint8ArrayMemory0 = null;
|
|
346
|
+
function getUint8ArrayMemory0() {
|
|
347
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
348
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
349
|
+
}
|
|
350
|
+
return cachedUint8ArrayMemory0;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
function getObject(idx) { return heap[idx]; }
|
|
354
|
+
|
|
355
|
+
function handleError(f, args) {
|
|
356
|
+
try {
|
|
357
|
+
return f.apply(this, args);
|
|
358
|
+
} catch (e) {
|
|
359
|
+
wasm.__wbindgen_export(addHeapObject(e));
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
let heap = new Array(1024).fill(undefined);
|
|
364
|
+
heap.push(undefined, null, true, false);
|
|
365
|
+
|
|
366
|
+
let heap_next = heap.length;
|
|
367
|
+
|
|
368
|
+
function isLikeNone(x) {
|
|
369
|
+
return x === undefined || x === null;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
373
|
+
const ptr = malloc(arg.length * 1, 1) >>> 0;
|
|
374
|
+
getUint8ArrayMemory0().set(arg, ptr / 1);
|
|
375
|
+
WASM_VECTOR_LEN = arg.length;
|
|
376
|
+
return ptr;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
function takeObject(idx) {
|
|
380
|
+
const ret = getObject(idx);
|
|
381
|
+
dropObject(idx);
|
|
382
|
+
return ret;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
386
|
+
cachedTextDecoder.decode();
|
|
387
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
388
|
+
let numBytesDecoded = 0;
|
|
389
|
+
function decodeText(ptr, len) {
|
|
390
|
+
numBytesDecoded += len;
|
|
391
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
392
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
393
|
+
cachedTextDecoder.decode();
|
|
394
|
+
numBytesDecoded = len;
|
|
395
|
+
}
|
|
396
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
let WASM_VECTOR_LEN = 0;
|
|
400
|
+
|
|
401
|
+
let wasmModule, wasmInstance, wasm;
|
|
402
|
+
function __wbg_finalize_init(instance, module) {
|
|
403
|
+
wasmInstance = instance;
|
|
404
|
+
wasm = instance.exports;
|
|
405
|
+
wasmModule = module;
|
|
406
|
+
cachedDataViewMemory0 = null;
|
|
407
|
+
cachedUint8ArrayMemory0 = null;
|
|
408
|
+
return wasm;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
async function __wbg_load(module, imports) {
|
|
412
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
413
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
414
|
+
try {
|
|
415
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
416
|
+
} catch (e) {
|
|
417
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
418
|
+
|
|
419
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
420
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
421
|
+
|
|
422
|
+
} else { throw e; }
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
const bytes = await module.arrayBuffer();
|
|
427
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
428
|
+
} else {
|
|
429
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
430
|
+
|
|
431
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
432
|
+
return { instance, module };
|
|
433
|
+
} else {
|
|
434
|
+
return instance;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
function expectedResponseType(type) {
|
|
439
|
+
switch (type) {
|
|
440
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
441
|
+
}
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function initSync(module) {
|
|
447
|
+
if (wasm !== undefined) return wasm;
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
if (module !== undefined) {
|
|
451
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
452
|
+
({module} = module)
|
|
453
|
+
} else {
|
|
454
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
const imports = __wbg_get_imports();
|
|
459
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
460
|
+
module = new WebAssembly.Module(module);
|
|
461
|
+
}
|
|
462
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
463
|
+
return __wbg_finalize_init(instance, module);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
async function __wbg_init(module_or_path) {
|
|
467
|
+
if (wasm !== undefined) return wasm;
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
if (module_or_path !== undefined) {
|
|
471
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
472
|
+
({module_or_path} = module_or_path)
|
|
473
|
+
} else {
|
|
474
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
if (module_or_path === undefined) {
|
|
479
|
+
module_or_path = new URL('morphic_wasm_core_bg.wasm', import.meta.url);
|
|
480
|
+
}
|
|
481
|
+
const imports = __wbg_get_imports();
|
|
482
|
+
|
|
483
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
484
|
+
module_or_path = fetch(module_or_path);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
488
|
+
|
|
489
|
+
return __wbg_finalize_init(instance, module);
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const __wbg_wasmkeypair_free: (a: number, b: number) => void;
|
|
5
|
+
export const wasmDecryptBox: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
|
|
6
|
+
export const wasmEncryptBox: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void;
|
|
7
|
+
export const wasmGenerateKeypair: () => number;
|
|
8
|
+
export const wasmGenerateNonce: (a: number) => void;
|
|
9
|
+
export const wasmRandomBytes: (a: number, b: number) => void;
|
|
10
|
+
export const wasmkeypair_publicKey: (a: number, b: number) => void;
|
|
11
|
+
export const wasmkeypair_secretKey: (a: number, b: number) => void;
|
|
12
|
+
export const __wbindgen_export: (a: number) => void;
|
|
13
|
+
export const __wbindgen_add_to_stack_pointer: (a: number) => number;
|
|
14
|
+
export const __wbindgen_export2: (a: number, b: number) => number;
|
|
15
|
+
export const __wbindgen_export3: (a: number, b: number, c: number) => void;
|
package/pkg/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "morphic-wasm-core",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "Shinkofa Morphic Adaptation — Rust→WASM critical paths (NaCl box, B-018)",
|
|
5
|
+
"version": "2.0.0-alpha.0",
|
|
6
|
+
"license": "AGPL-3.0-or-later",
|
|
7
|
+
"files": [
|
|
8
|
+
"morphic_wasm_core_bg.wasm",
|
|
9
|
+
"morphic_wasm_core.js",
|
|
10
|
+
"morphic_wasm_core.d.ts"
|
|
11
|
+
],
|
|
12
|
+
"main": "morphic_wasm_core.js",
|
|
13
|
+
"types": "morphic_wasm_core.d.ts",
|
|
14
|
+
"sideEffects": [
|
|
15
|
+
"./snippets/*"
|
|
16
|
+
]
|
|
17
|
+
}
|