hpke 0.2.0 → 0.2.1
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/hpke_dispatch.js +803 -2
- package/hpke_dispatch_bg.wasm +0 -0
- package/package.json +2 -4
- package/hpke_dispatch_bg.js +0 -789
package/hpke_dispatch.js
CHANGED
|
@@ -1,2 +1,803 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
let imports = {};
|
|
2
|
+
imports['__wbindgen_placeholder__'] = module.exports;
|
|
3
|
+
let wasm;
|
|
4
|
+
const { TextDecoder } = require(`util`);
|
|
5
|
+
|
|
6
|
+
const heap = new Array(32).fill(undefined);
|
|
7
|
+
|
|
8
|
+
heap.push(undefined, null, true, false);
|
|
9
|
+
|
|
10
|
+
function getObject(idx) { return heap[idx]; }
|
|
11
|
+
|
|
12
|
+
let heap_next = heap.length;
|
|
13
|
+
|
|
14
|
+
function dropObject(idx) {
|
|
15
|
+
if (idx < 36) return;
|
|
16
|
+
heap[idx] = heap_next;
|
|
17
|
+
heap_next = idx;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function takeObject(idx) {
|
|
21
|
+
const ret = getObject(idx);
|
|
22
|
+
dropObject(idx);
|
|
23
|
+
return ret;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function addHeapObject(obj) {
|
|
27
|
+
if (heap_next === heap.length) heap.push(heap.length + 1);
|
|
28
|
+
const idx = heap_next;
|
|
29
|
+
heap_next = heap[idx];
|
|
30
|
+
|
|
31
|
+
heap[idx] = obj;
|
|
32
|
+
return idx;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
36
|
+
|
|
37
|
+
cachedTextDecoder.decode();
|
|
38
|
+
|
|
39
|
+
let cachegetUint8Memory0 = null;
|
|
40
|
+
function getUint8Memory0() {
|
|
41
|
+
if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
|
|
42
|
+
cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
|
|
43
|
+
}
|
|
44
|
+
return cachegetUint8Memory0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function getStringFromWasm0(ptr, len) {
|
|
48
|
+
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
let cachegetInt32Memory0 = null;
|
|
52
|
+
function getInt32Memory0() {
|
|
53
|
+
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
|
|
54
|
+
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
|
55
|
+
}
|
|
56
|
+
return cachegetInt32Memory0;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function getArrayU8FromWasm0(ptr, len) {
|
|
60
|
+
return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
let WASM_VECTOR_LEN = 0;
|
|
64
|
+
|
|
65
|
+
function passArray8ToWasm0(arg, malloc) {
|
|
66
|
+
const ptr = malloc(arg.length * 1);
|
|
67
|
+
getUint8Memory0().set(arg, ptr / 1);
|
|
68
|
+
WASM_VECTOR_LEN = arg.length;
|
|
69
|
+
return ptr;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function _assertClass(instance, klass) {
|
|
73
|
+
if (!(instance instanceof klass)) {
|
|
74
|
+
throw new Error(`expected instance of ${klass.name}`);
|
|
75
|
+
}
|
|
76
|
+
return instance.ptr;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
*`base_mode_seal` provides an interface to [`hpke::single_shot_seal`]
|
|
81
|
+
*that does not require compile time selection of an
|
|
82
|
+
*algorithm. Instead, the selected algorithm is provided through the
|
|
83
|
+
*[`Config`] passed as the first argument.
|
|
84
|
+
*
|
|
85
|
+
*Requires the `base-mode-seal` crate feature to be enabled.
|
|
86
|
+
*
|
|
87
|
+
*# Errors
|
|
88
|
+
*
|
|
89
|
+
*This will return an `Result::Err` variant if:
|
|
90
|
+
*
|
|
91
|
+
** we are unable to deserialize the recipient public key
|
|
92
|
+
** there is an error in key encapsultion
|
|
93
|
+
** there is an error in encryption
|
|
94
|
+
*
|
|
95
|
+
*
|
|
96
|
+
* @param {Config} config
|
|
97
|
+
* @param {Uint8Array} recipient_public_key
|
|
98
|
+
* @param {Uint8Array} info
|
|
99
|
+
* @param {Uint8Array} plaintext
|
|
100
|
+
* @param {Uint8Array} aad
|
|
101
|
+
* @returns {EncappedKeyAndCiphertext}
|
|
102
|
+
*/
|
|
103
|
+
module.exports.base_mode_seal = function(config, recipient_public_key, info, plaintext, aad) {
|
|
104
|
+
try {
|
|
105
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
106
|
+
_assertClass(config, Config);
|
|
107
|
+
const ptr0 = passArray8ToWasm0(recipient_public_key, wasm.__wbindgen_malloc);
|
|
108
|
+
const len0 = WASM_VECTOR_LEN;
|
|
109
|
+
const ptr1 = passArray8ToWasm0(info, wasm.__wbindgen_malloc);
|
|
110
|
+
const len1 = WASM_VECTOR_LEN;
|
|
111
|
+
const ptr2 = passArray8ToWasm0(plaintext, wasm.__wbindgen_malloc);
|
|
112
|
+
const len2 = WASM_VECTOR_LEN;
|
|
113
|
+
const ptr3 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
|
|
114
|
+
const len3 = WASM_VECTOR_LEN;
|
|
115
|
+
wasm.base_mode_seal(retptr, config.ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
|
|
116
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
117
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
118
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
119
|
+
if (r2) {
|
|
120
|
+
throw takeObject(r1);
|
|
121
|
+
}
|
|
122
|
+
return EncappedKeyAndCiphertext.__wrap(r0);
|
|
123
|
+
} finally {
|
|
124
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
*
|
|
130
|
+
*`base_mode_open` provides an interface to [`hpke::single_shot_open`]
|
|
131
|
+
*that does not require compile time selection of an algorithm. Instead,
|
|
132
|
+
*the selected algorithm is provided through the [`Config`] passed as
|
|
133
|
+
*the first argument.
|
|
134
|
+
*
|
|
135
|
+
*Requires the `base-mode-open` crate feature to be enabled.
|
|
136
|
+
*
|
|
137
|
+
*# Errors
|
|
138
|
+
*
|
|
139
|
+
*This will return an `Result::Err` variant if:
|
|
140
|
+
*
|
|
141
|
+
** we are unable to deserialize the private key or encapsulated key
|
|
142
|
+
** there is an error in key decapsulation
|
|
143
|
+
** there is an error in decryption
|
|
144
|
+
*
|
|
145
|
+
* @param {Config} config
|
|
146
|
+
* @param {Uint8Array} private_key
|
|
147
|
+
* @param {Uint8Array} encapped_key
|
|
148
|
+
* @param {Uint8Array} info
|
|
149
|
+
* @param {Uint8Array} ciphertext
|
|
150
|
+
* @param {Uint8Array} aad
|
|
151
|
+
* @returns {Uint8Array}
|
|
152
|
+
*/
|
|
153
|
+
module.exports.base_mode_open = function(config, private_key, encapped_key, info, ciphertext, aad) {
|
|
154
|
+
try {
|
|
155
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
156
|
+
_assertClass(config, Config);
|
|
157
|
+
const ptr0 = passArray8ToWasm0(private_key, wasm.__wbindgen_malloc);
|
|
158
|
+
const len0 = WASM_VECTOR_LEN;
|
|
159
|
+
const ptr1 = passArray8ToWasm0(encapped_key, wasm.__wbindgen_malloc);
|
|
160
|
+
const len1 = WASM_VECTOR_LEN;
|
|
161
|
+
const ptr2 = passArray8ToWasm0(info, wasm.__wbindgen_malloc);
|
|
162
|
+
const len2 = WASM_VECTOR_LEN;
|
|
163
|
+
const ptr3 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
|
|
164
|
+
const len3 = WASM_VECTOR_LEN;
|
|
165
|
+
const ptr4 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
|
|
166
|
+
const len4 = WASM_VECTOR_LEN;
|
|
167
|
+
wasm.base_mode_open(retptr, config.ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4);
|
|
168
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
169
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
170
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
171
|
+
var r3 = getInt32Memory0()[retptr / 4 + 3];
|
|
172
|
+
if (r3) {
|
|
173
|
+
throw takeObject(r2);
|
|
174
|
+
}
|
|
175
|
+
var v5 = getArrayU8FromWasm0(r0, r1).slice();
|
|
176
|
+
wasm.__wbindgen_free(r0, r1 * 1);
|
|
177
|
+
return v5;
|
|
178
|
+
} finally {
|
|
179
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
function handleError(f, args) {
|
|
184
|
+
try {
|
|
185
|
+
return f.apply(this, args);
|
|
186
|
+
} catch (e) {
|
|
187
|
+
wasm.__wbindgen_exn_store(addHeapObject(e));
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
*
|
|
192
|
+
*Aead represents an authenticated encryption with additional data
|
|
193
|
+
*encryption function, as per [RFC9180§7.3](https://www.rfc-editor.org/rfc/rfc9180.html#section-7.3)
|
|
194
|
+
*/
|
|
195
|
+
module.exports.Aead = Object.freeze({
|
|
196
|
+
/**
|
|
197
|
+
* AES-128-GCM [GCM](https://doi.org/10.6028/nist.sp.800-38d)
|
|
198
|
+
*/
|
|
199
|
+
AesGcm128:1,"1":"AesGcm128",
|
|
200
|
+
/**
|
|
201
|
+
* AES-256-GCM [GCM](https://doi.org/10.6028/nist.sp.800-38d)
|
|
202
|
+
*/
|
|
203
|
+
AesGcm256:2,"2":"AesGcm256",
|
|
204
|
+
/**
|
|
205
|
+
* ChaCha20Poly1305 [RFC8439](https://www.rfc-editor.org/info/rfc8439)
|
|
206
|
+
*/
|
|
207
|
+
ChaCha20Poly1305:3,"3":"ChaCha20Poly1305", });
|
|
208
|
+
/**
|
|
209
|
+
*
|
|
210
|
+
*Kdf represents an key derivation function, as per
|
|
211
|
+
*[RFC9180§7.2](https://www.rfc-editor.org/rfc/rfc9180.html#section-7.2)
|
|
212
|
+
*/
|
|
213
|
+
module.exports.Kdf = Object.freeze({
|
|
214
|
+
/**
|
|
215
|
+
* Sha256 [RFC5869](https://www.rfc-editor.org/info/rfc5869)
|
|
216
|
+
*/
|
|
217
|
+
Sha256:1,"1":"Sha256",
|
|
218
|
+
/**
|
|
219
|
+
* Sha384 [RFC5869](https://www.rfc-editor.org/info/rfc5869)
|
|
220
|
+
*/
|
|
221
|
+
Sha384:2,"2":"Sha384",
|
|
222
|
+
/**
|
|
223
|
+
* Sha512 [RFC5869](https://www.rfc-editor.org/info/rfc5869)
|
|
224
|
+
*/
|
|
225
|
+
Sha512:3,"3":"Sha512", });
|
|
226
|
+
/**
|
|
227
|
+
*
|
|
228
|
+
*Kem represents an asymmetric key encapsulation mechanism, as per
|
|
229
|
+
*[RFC9180§7.1][section-7.1]. Currently only two of options listed in
|
|
230
|
+
*the hpke draft are available.
|
|
231
|
+
*
|
|
232
|
+
*[section-7.1]: https://www.rfc-editor.org/rfc/rfc9180.html#section-7.1
|
|
233
|
+
*/
|
|
234
|
+
module.exports.Kem = Object.freeze({
|
|
235
|
+
/**
|
|
236
|
+
* DHKEM(P-256, HKDF-SHA256) [NISTCurves](https://doi.org/10.6028/nist.fips.186-4)
|
|
237
|
+
*/
|
|
238
|
+
DhP256HkdfSha256:16,"16":"DhP256HkdfSha256",
|
|
239
|
+
/**
|
|
240
|
+
* DHKEM(X25519, HKDF-SHA256) [RFC7748](https://www.rfc-editor.org/info/rfc7748)
|
|
241
|
+
*/
|
|
242
|
+
X25519HkdfSha256:32,"32":"X25519HkdfSha256", });
|
|
243
|
+
/**
|
|
244
|
+
*
|
|
245
|
+
*Config is an open struct that contains an ([`Aead`], [`Kdf`], [`Kem`])
|
|
246
|
+
*algorithmic triple. This can be used with [`Config::base_mode_seal`],
|
|
247
|
+
*[`Config::base_mode_open`], [`base_mode_seal`], or [`base_mode_open`].
|
|
248
|
+
*/
|
|
249
|
+
class Config {
|
|
250
|
+
|
|
251
|
+
static __wrap(ptr) {
|
|
252
|
+
const obj = Object.create(Config.prototype);
|
|
253
|
+
obj.ptr = ptr;
|
|
254
|
+
|
|
255
|
+
return obj;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
__destroy_into_raw() {
|
|
259
|
+
const ptr = this.ptr;
|
|
260
|
+
this.ptr = 0;
|
|
261
|
+
|
|
262
|
+
return ptr;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
free() {
|
|
266
|
+
const ptr = this.__destroy_into_raw();
|
|
267
|
+
wasm.__wbg_config_free(ptr);
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* the [authenticated encryption with additional data encryption function](crate::Aead) to be used
|
|
271
|
+
*/
|
|
272
|
+
get aead() {
|
|
273
|
+
const ret = wasm.__wbg_get_config_aead(this.ptr);
|
|
274
|
+
return ret >>> 0;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* the [authenticated encryption with additional data encryption function](crate::Aead) to be used
|
|
278
|
+
* @param {number} arg0
|
|
279
|
+
*/
|
|
280
|
+
set aead(arg0) {
|
|
281
|
+
wasm.__wbg_set_config_aead(this.ptr, arg0);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* the [key derivation function](crate::Kdf) to be used
|
|
285
|
+
*/
|
|
286
|
+
get kdf() {
|
|
287
|
+
const ret = wasm.__wbg_get_config_kdf(this.ptr);
|
|
288
|
+
return ret >>> 0;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* the [key derivation function](crate::Kdf) to be used
|
|
292
|
+
* @param {number} arg0
|
|
293
|
+
*/
|
|
294
|
+
set kdf(arg0) {
|
|
295
|
+
wasm.__wbg_set_config_kdf(this.ptr, arg0);
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* the [asymmetric key encapsulation mechanism](crate::Kem) to be used
|
|
299
|
+
*/
|
|
300
|
+
get kem() {
|
|
301
|
+
const ret = wasm.__wbg_get_config_kem(this.ptr);
|
|
302
|
+
return ret >>> 0;
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* the [asymmetric key encapsulation mechanism](crate::Kem) to be used
|
|
306
|
+
* @param {number} arg0
|
|
307
|
+
*/
|
|
308
|
+
set kem(arg0) {
|
|
309
|
+
wasm.__wbg_set_config_kem(this.ptr, arg0);
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
*
|
|
313
|
+
* base_mode_seal provides an interface to [`hpke::single_shot_seal`] that does
|
|
314
|
+
* not require compile time selection of an algorithm. Instead, the
|
|
315
|
+
* selected algorithm is provided through the [`Config`] that this
|
|
316
|
+
* method is called on.
|
|
317
|
+
*
|
|
318
|
+
* Requires the `base-mode-seal` crate feature to be enabled.
|
|
319
|
+
*
|
|
320
|
+
* # Errors
|
|
321
|
+
*
|
|
322
|
+
* This will return an `Result::Err` variant if:
|
|
323
|
+
*
|
|
324
|
+
* * we are unable to deserialize the recipient public key
|
|
325
|
+
* * there is an error in key encapsultion
|
|
326
|
+
* * there is an error in encryption
|
|
327
|
+
*
|
|
328
|
+
*
|
|
329
|
+
* @param {Uint8Array} recipient_public_key
|
|
330
|
+
* @param {Uint8Array} info
|
|
331
|
+
* @param {Uint8Array} plaintext
|
|
332
|
+
* @param {Uint8Array} aad
|
|
333
|
+
* @returns {EncappedKeyAndCiphertext}
|
|
334
|
+
*/
|
|
335
|
+
base_mode_seal(recipient_public_key, info, plaintext, aad) {
|
|
336
|
+
try {
|
|
337
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
338
|
+
const ptr0 = passArray8ToWasm0(recipient_public_key, wasm.__wbindgen_malloc);
|
|
339
|
+
const len0 = WASM_VECTOR_LEN;
|
|
340
|
+
const ptr1 = passArray8ToWasm0(info, wasm.__wbindgen_malloc);
|
|
341
|
+
const len1 = WASM_VECTOR_LEN;
|
|
342
|
+
const ptr2 = passArray8ToWasm0(plaintext, wasm.__wbindgen_malloc);
|
|
343
|
+
const len2 = WASM_VECTOR_LEN;
|
|
344
|
+
const ptr3 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
|
|
345
|
+
const len3 = WASM_VECTOR_LEN;
|
|
346
|
+
wasm.config_base_mode_seal(retptr, this.ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3);
|
|
347
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
348
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
349
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
350
|
+
if (r2) {
|
|
351
|
+
throw takeObject(r1);
|
|
352
|
+
}
|
|
353
|
+
return EncappedKeyAndCiphertext.__wrap(r0);
|
|
354
|
+
} finally {
|
|
355
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
*
|
|
360
|
+
* base_mode_open provides an interface to [`hpke::single_shot_open`]
|
|
361
|
+
* that does not require compile time selection of an
|
|
362
|
+
* algorithm. Instead, the selected algorithm is provided through the
|
|
363
|
+
* [`Config`] that this method is called on.
|
|
364
|
+
*
|
|
365
|
+
* Requires the `base-mode-open` crate feature to be enabled.
|
|
366
|
+
*
|
|
367
|
+
* # Errors
|
|
368
|
+
*
|
|
369
|
+
* This will return an `Result::Err` variant if:
|
|
370
|
+
*
|
|
371
|
+
* * we are unable to deserialize the private key or encapsulated key
|
|
372
|
+
* * there is an error in key decapsulation
|
|
373
|
+
* * there is an error in decryption
|
|
374
|
+
*
|
|
375
|
+
*
|
|
376
|
+
* @param {Uint8Array} private_key
|
|
377
|
+
* @param {Uint8Array} encapped_key
|
|
378
|
+
* @param {Uint8Array} info
|
|
379
|
+
* @param {Uint8Array} ciphertext
|
|
380
|
+
* @param {Uint8Array} aad
|
|
381
|
+
* @returns {Uint8Array}
|
|
382
|
+
*/
|
|
383
|
+
base_mode_open(private_key, encapped_key, info, ciphertext, aad) {
|
|
384
|
+
try {
|
|
385
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
386
|
+
const ptr0 = passArray8ToWasm0(private_key, wasm.__wbindgen_malloc);
|
|
387
|
+
const len0 = WASM_VECTOR_LEN;
|
|
388
|
+
const ptr1 = passArray8ToWasm0(encapped_key, wasm.__wbindgen_malloc);
|
|
389
|
+
const len1 = WASM_VECTOR_LEN;
|
|
390
|
+
const ptr2 = passArray8ToWasm0(info, wasm.__wbindgen_malloc);
|
|
391
|
+
const len2 = WASM_VECTOR_LEN;
|
|
392
|
+
const ptr3 = passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc);
|
|
393
|
+
const len3 = WASM_VECTOR_LEN;
|
|
394
|
+
const ptr4 = passArray8ToWasm0(aad, wasm.__wbindgen_malloc);
|
|
395
|
+
const len4 = WASM_VECTOR_LEN;
|
|
396
|
+
wasm.config_base_mode_open(retptr, this.ptr, ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4);
|
|
397
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
398
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
399
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
400
|
+
var r3 = getInt32Memory0()[retptr / 4 + 3];
|
|
401
|
+
if (r3) {
|
|
402
|
+
throw takeObject(r2);
|
|
403
|
+
}
|
|
404
|
+
var v5 = getArrayU8FromWasm0(r0, r1).slice();
|
|
405
|
+
wasm.__wbindgen_free(r0, r1 * 1);
|
|
406
|
+
return v5;
|
|
407
|
+
} finally {
|
|
408
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Attempt to convert three u16 ids into a valid config. The id mappings are defined in the draft.
|
|
413
|
+
* @param {number} aead_id
|
|
414
|
+
* @param {number} kdf_id
|
|
415
|
+
* @param {number} kem_id
|
|
416
|
+
* @returns {Config}
|
|
417
|
+
*/
|
|
418
|
+
static try_from_ids(aead_id, kdf_id, kem_id) {
|
|
419
|
+
try {
|
|
420
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
421
|
+
wasm.config_try_from_ids(retptr, aead_id, kdf_id, kem_id);
|
|
422
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
423
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
424
|
+
var r2 = getInt32Memory0()[retptr / 4 + 2];
|
|
425
|
+
if (r2) {
|
|
426
|
+
throw takeObject(r1);
|
|
427
|
+
}
|
|
428
|
+
return Config.__wrap(r0);
|
|
429
|
+
} finally {
|
|
430
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
module.exports.Config = Config;
|
|
435
|
+
/**
|
|
436
|
+
*
|
|
437
|
+
*a simple struct to return the combined encapsulated key
|
|
438
|
+
*and ciphertext from seal
|
|
439
|
+
*/
|
|
440
|
+
class EncappedKeyAndCiphertext {
|
|
441
|
+
|
|
442
|
+
static __wrap(ptr) {
|
|
443
|
+
const obj = Object.create(EncappedKeyAndCiphertext.prototype);
|
|
444
|
+
obj.ptr = ptr;
|
|
445
|
+
|
|
446
|
+
return obj;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
__destroy_into_raw() {
|
|
450
|
+
const ptr = this.ptr;
|
|
451
|
+
this.ptr = 0;
|
|
452
|
+
|
|
453
|
+
return ptr;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
free() {
|
|
457
|
+
const ptr = this.__destroy_into_raw();
|
|
458
|
+
wasm.__wbg_encappedkeyandciphertext_free(ptr);
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* the encapsulated encryption key
|
|
462
|
+
*/
|
|
463
|
+
get encapped_key() {
|
|
464
|
+
try {
|
|
465
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
466
|
+
wasm.__wbg_get_encappedkeyandciphertext_encapped_key(retptr, this.ptr);
|
|
467
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
468
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
469
|
+
var v0 = getArrayU8FromWasm0(r0, r1).slice();
|
|
470
|
+
wasm.__wbindgen_free(r0, r1 * 1);
|
|
471
|
+
return v0;
|
|
472
|
+
} finally {
|
|
473
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* the encapsulated encryption key
|
|
478
|
+
* @param {Uint8Array} arg0
|
|
479
|
+
*/
|
|
480
|
+
set encapped_key(arg0) {
|
|
481
|
+
const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
|
|
482
|
+
const len0 = WASM_VECTOR_LEN;
|
|
483
|
+
wasm.__wbg_set_encappedkeyandciphertext_encapped_key(this.ptr, ptr0, len0);
|
|
484
|
+
}
|
|
485
|
+
/**
|
|
486
|
+
* the ciphertext, encrypted with the key
|
|
487
|
+
*/
|
|
488
|
+
get ciphertext() {
|
|
489
|
+
try {
|
|
490
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
491
|
+
wasm.__wbg_get_encappedkeyandciphertext_ciphertext(retptr, this.ptr);
|
|
492
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
493
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
494
|
+
var v0 = getArrayU8FromWasm0(r0, r1).slice();
|
|
495
|
+
wasm.__wbindgen_free(r0, r1 * 1);
|
|
496
|
+
return v0;
|
|
497
|
+
} finally {
|
|
498
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* the ciphertext, encrypted with the key
|
|
503
|
+
* @param {Uint8Array} arg0
|
|
504
|
+
*/
|
|
505
|
+
set ciphertext(arg0) {
|
|
506
|
+
const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
|
|
507
|
+
const len0 = WASM_VECTOR_LEN;
|
|
508
|
+
wasm.__wbg_set_encappedkeyandciphertext_ciphertext(this.ptr, ptr0, len0);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
module.exports.EncappedKeyAndCiphertext = EncappedKeyAndCiphertext;
|
|
512
|
+
/**
|
|
513
|
+
*r"
|
|
514
|
+
* a newtype wrapper for HpkeError so we can use it in wasm_bindgen
|
|
515
|
+
*
|
|
516
|
+
*/
|
|
517
|
+
class HpkeError {
|
|
518
|
+
|
|
519
|
+
static __wrap(ptr) {
|
|
520
|
+
const obj = Object.create(HpkeError.prototype);
|
|
521
|
+
obj.ptr = ptr;
|
|
522
|
+
|
|
523
|
+
return obj;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
__destroy_into_raw() {
|
|
527
|
+
const ptr = this.ptr;
|
|
528
|
+
this.ptr = 0;
|
|
529
|
+
|
|
530
|
+
return ptr;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
free() {
|
|
534
|
+
const ptr = this.__destroy_into_raw();
|
|
535
|
+
wasm.__wbg_hpkeerror_free(ptr);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
module.exports.HpkeError = HpkeError;
|
|
539
|
+
/**
|
|
540
|
+
*
|
|
541
|
+
*A simple error type for failed id lookups
|
|
542
|
+
*
|
|
543
|
+
*/
|
|
544
|
+
class IdLookupError {
|
|
545
|
+
|
|
546
|
+
static __wrap(ptr) {
|
|
547
|
+
const obj = Object.create(IdLookupError.prototype);
|
|
548
|
+
obj.ptr = ptr;
|
|
549
|
+
|
|
550
|
+
return obj;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
__destroy_into_raw() {
|
|
554
|
+
const ptr = this.ptr;
|
|
555
|
+
this.ptr = 0;
|
|
556
|
+
|
|
557
|
+
return ptr;
|
|
558
|
+
}
|
|
559
|
+
|
|
560
|
+
free() {
|
|
561
|
+
const ptr = this.__destroy_into_raw();
|
|
562
|
+
wasm.__wbg_idlookuperror_free(ptr);
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
module.exports.IdLookupError = IdLookupError;
|
|
566
|
+
/**
|
|
567
|
+
* An encoded keypair
|
|
568
|
+
*/
|
|
569
|
+
class Keypair {
|
|
570
|
+
|
|
571
|
+
static __wrap(ptr) {
|
|
572
|
+
const obj = Object.create(Keypair.prototype);
|
|
573
|
+
obj.ptr = ptr;
|
|
574
|
+
|
|
575
|
+
return obj;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
__destroy_into_raw() {
|
|
579
|
+
const ptr = this.ptr;
|
|
580
|
+
this.ptr = 0;
|
|
581
|
+
|
|
582
|
+
return ptr;
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
free() {
|
|
586
|
+
const ptr = this.__destroy_into_raw();
|
|
587
|
+
wasm.__wbg_keypair_free(ptr);
|
|
588
|
+
}
|
|
589
|
+
/**
|
|
590
|
+
* the public key for this keypair
|
|
591
|
+
*/
|
|
592
|
+
get public_key() {
|
|
593
|
+
try {
|
|
594
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
595
|
+
wasm.__wbg_get_keypair_public_key(retptr, this.ptr);
|
|
596
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
597
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
598
|
+
var v0 = getArrayU8FromWasm0(r0, r1).slice();
|
|
599
|
+
wasm.__wbindgen_free(r0, r1 * 1);
|
|
600
|
+
return v0;
|
|
601
|
+
} finally {
|
|
602
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* the public key for this keypair
|
|
607
|
+
* @param {Uint8Array} arg0
|
|
608
|
+
*/
|
|
609
|
+
set public_key(arg0) {
|
|
610
|
+
const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
|
|
611
|
+
const len0 = WASM_VECTOR_LEN;
|
|
612
|
+
wasm.__wbg_set_keypair_public_key(this.ptr, ptr0, len0);
|
|
613
|
+
}
|
|
614
|
+
/**
|
|
615
|
+
* the private key for this keypair,
|
|
616
|
+
*/
|
|
617
|
+
get private_key() {
|
|
618
|
+
try {
|
|
619
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
620
|
+
wasm.__wbg_get_keypair_private_key(retptr, this.ptr);
|
|
621
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
622
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
623
|
+
var v0 = getArrayU8FromWasm0(r0, r1).slice();
|
|
624
|
+
wasm.__wbindgen_free(r0, r1 * 1);
|
|
625
|
+
return v0;
|
|
626
|
+
} finally {
|
|
627
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
/**
|
|
631
|
+
* the private key for this keypair,
|
|
632
|
+
* @param {Uint8Array} arg0
|
|
633
|
+
*/
|
|
634
|
+
set private_key(arg0) {
|
|
635
|
+
const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc);
|
|
636
|
+
const len0 = WASM_VECTOR_LEN;
|
|
637
|
+
wasm.__wbg_set_keypair_private_key(this.ptr, ptr0, len0);
|
|
638
|
+
}
|
|
639
|
+
/**
|
|
640
|
+
* generate a keypair from a [`Kem`]
|
|
641
|
+
* @param {number} kem
|
|
642
|
+
*/
|
|
643
|
+
constructor(kem) {
|
|
644
|
+
const ret = wasm.keypair_new(kem);
|
|
645
|
+
return Keypair.__wrap(ret);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
module.exports.Keypair = Keypair;
|
|
649
|
+
|
|
650
|
+
module.exports.__wbg_idlookuperror_new = function(arg0) {
|
|
651
|
+
const ret = IdLookupError.__wrap(arg0);
|
|
652
|
+
return addHeapObject(ret);
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
module.exports.__wbg_hpkeerror_new = function(arg0) {
|
|
656
|
+
const ret = HpkeError.__wrap(arg0);
|
|
657
|
+
return addHeapObject(ret);
|
|
658
|
+
};
|
|
659
|
+
|
|
660
|
+
module.exports.__wbg_randomFillSync_654a7797990fb8db = function() { return handleError(function (arg0, arg1, arg2) {
|
|
661
|
+
getObject(arg0).randomFillSync(getArrayU8FromWasm0(arg1, arg2));
|
|
662
|
+
}, arguments) };
|
|
663
|
+
|
|
664
|
+
module.exports.__wbindgen_object_drop_ref = function(arg0) {
|
|
665
|
+
takeObject(arg0);
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
module.exports.__wbg_getRandomValues_fb6b088efb6bead2 = function() { return handleError(function (arg0, arg1) {
|
|
669
|
+
getObject(arg0).getRandomValues(getObject(arg1));
|
|
670
|
+
}, arguments) };
|
|
671
|
+
|
|
672
|
+
module.exports.__wbg_process_70251ed1291754d5 = function(arg0) {
|
|
673
|
+
const ret = getObject(arg0).process;
|
|
674
|
+
return addHeapObject(ret);
|
|
675
|
+
};
|
|
676
|
+
|
|
677
|
+
module.exports.__wbindgen_is_object = function(arg0) {
|
|
678
|
+
const val = getObject(arg0);
|
|
679
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
680
|
+
return ret;
|
|
681
|
+
};
|
|
682
|
+
|
|
683
|
+
module.exports.__wbg_versions_b23f2588cdb2ddbb = function(arg0) {
|
|
684
|
+
const ret = getObject(arg0).versions;
|
|
685
|
+
return addHeapObject(ret);
|
|
686
|
+
};
|
|
687
|
+
|
|
688
|
+
module.exports.__wbg_node_61b8c9a82499895d = function(arg0) {
|
|
689
|
+
const ret = getObject(arg0).node;
|
|
690
|
+
return addHeapObject(ret);
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
module.exports.__wbindgen_is_string = function(arg0) {
|
|
694
|
+
const ret = typeof(getObject(arg0)) === 'string';
|
|
695
|
+
return ret;
|
|
696
|
+
};
|
|
697
|
+
|
|
698
|
+
module.exports.__wbg_static_accessor_NODE_MODULE_33b45247c55045b0 = function() {
|
|
699
|
+
const ret = module;
|
|
700
|
+
return addHeapObject(ret);
|
|
701
|
+
};
|
|
702
|
+
|
|
703
|
+
module.exports.__wbg_require_2a93bc09fee45aca = function() { return handleError(function (arg0, arg1, arg2) {
|
|
704
|
+
const ret = getObject(arg0).require(getStringFromWasm0(arg1, arg2));
|
|
705
|
+
return addHeapObject(ret);
|
|
706
|
+
}, arguments) };
|
|
707
|
+
|
|
708
|
+
module.exports.__wbg_crypto_2f56257a38275dbd = function(arg0) {
|
|
709
|
+
const ret = getObject(arg0).crypto;
|
|
710
|
+
return addHeapObject(ret);
|
|
711
|
+
};
|
|
712
|
+
|
|
713
|
+
module.exports.__wbg_msCrypto_d07655bf62361f21 = function(arg0) {
|
|
714
|
+
const ret = getObject(arg0).msCrypto;
|
|
715
|
+
return addHeapObject(ret);
|
|
716
|
+
};
|
|
717
|
+
|
|
718
|
+
module.exports.__wbg_newnoargs_e23b458e372830de = function(arg0, arg1) {
|
|
719
|
+
const ret = new Function(getStringFromWasm0(arg0, arg1));
|
|
720
|
+
return addHeapObject(ret);
|
|
721
|
+
};
|
|
722
|
+
|
|
723
|
+
module.exports.__wbg_call_ae78342adc33730a = function() { return handleError(function (arg0, arg1) {
|
|
724
|
+
const ret = getObject(arg0).call(getObject(arg1));
|
|
725
|
+
return addHeapObject(ret);
|
|
726
|
+
}, arguments) };
|
|
727
|
+
|
|
728
|
+
module.exports.__wbindgen_object_clone_ref = function(arg0) {
|
|
729
|
+
const ret = getObject(arg0);
|
|
730
|
+
return addHeapObject(ret);
|
|
731
|
+
};
|
|
732
|
+
|
|
733
|
+
module.exports.__wbg_self_99737b4dcdf6f0d8 = function() { return handleError(function () {
|
|
734
|
+
const ret = self.self;
|
|
735
|
+
return addHeapObject(ret);
|
|
736
|
+
}, arguments) };
|
|
737
|
+
|
|
738
|
+
module.exports.__wbg_window_9b61fbbf3564c4fb = function() { return handleError(function () {
|
|
739
|
+
const ret = window.window;
|
|
740
|
+
return addHeapObject(ret);
|
|
741
|
+
}, arguments) };
|
|
742
|
+
|
|
743
|
+
module.exports.__wbg_globalThis_8e275ef40caea3a3 = function() { return handleError(function () {
|
|
744
|
+
const ret = globalThis.globalThis;
|
|
745
|
+
return addHeapObject(ret);
|
|
746
|
+
}, arguments) };
|
|
747
|
+
|
|
748
|
+
module.exports.__wbg_global_5de1e0f82bddcd27 = function() { return handleError(function () {
|
|
749
|
+
const ret = global.global;
|
|
750
|
+
return addHeapObject(ret);
|
|
751
|
+
}, arguments) };
|
|
752
|
+
|
|
753
|
+
module.exports.__wbindgen_is_undefined = function(arg0) {
|
|
754
|
+
const ret = getObject(arg0) === undefined;
|
|
755
|
+
return ret;
|
|
756
|
+
};
|
|
757
|
+
|
|
758
|
+
module.exports.__wbg_buffer_7af23f65f6c64548 = function(arg0) {
|
|
759
|
+
const ret = getObject(arg0).buffer;
|
|
760
|
+
return addHeapObject(ret);
|
|
761
|
+
};
|
|
762
|
+
|
|
763
|
+
module.exports.__wbg_new_cc9018bd6f283b6f = function(arg0) {
|
|
764
|
+
const ret = new Uint8Array(getObject(arg0));
|
|
765
|
+
return addHeapObject(ret);
|
|
766
|
+
};
|
|
767
|
+
|
|
768
|
+
module.exports.__wbg_set_f25e869e4565d2a2 = function(arg0, arg1, arg2) {
|
|
769
|
+
getObject(arg0).set(getObject(arg1), arg2 >>> 0);
|
|
770
|
+
};
|
|
771
|
+
|
|
772
|
+
module.exports.__wbg_length_0acb1cf9bbaf8519 = function(arg0) {
|
|
773
|
+
const ret = getObject(arg0).length;
|
|
774
|
+
return ret;
|
|
775
|
+
};
|
|
776
|
+
|
|
777
|
+
module.exports.__wbg_newwithlength_8f0657faca9f1422 = function(arg0) {
|
|
778
|
+
const ret = new Uint8Array(arg0 >>> 0);
|
|
779
|
+
return addHeapObject(ret);
|
|
780
|
+
};
|
|
781
|
+
|
|
782
|
+
module.exports.__wbg_subarray_da527dbd24eafb6b = function(arg0, arg1, arg2) {
|
|
783
|
+
const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0);
|
|
784
|
+
return addHeapObject(ret);
|
|
785
|
+
};
|
|
786
|
+
|
|
787
|
+
module.exports.__wbindgen_throw = function(arg0, arg1) {
|
|
788
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
789
|
+
};
|
|
790
|
+
|
|
791
|
+
module.exports.__wbindgen_memory = function() {
|
|
792
|
+
const ret = wasm.memory;
|
|
793
|
+
return addHeapObject(ret);
|
|
794
|
+
};
|
|
795
|
+
|
|
796
|
+
const path = require('path').join(__dirname, 'hpke_dispatch_bg.wasm');
|
|
797
|
+
const bytes = require('fs').readFileSync(path);
|
|
798
|
+
|
|
799
|
+
const wasmModule = new WebAssembly.Module(bytes);
|
|
800
|
+
const wasmInstance = new WebAssembly.Instance(wasmModule, imports);
|
|
801
|
+
wasm = wasmInstance.exports;
|
|
802
|
+
module.exports.__wasm = wasm;
|
|
803
|
+
|