mol_crypto2_lib 0.0.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/web.js ADDED
@@ -0,0 +1,920 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ function require( path ){ return $node[ path ] };
4
+
5
+ var $node = $node || {}
6
+ void function( module ) { var exports = module.exports = this; function require( id ) { return $node[ id.replace( /^.\// , "../" ) ] };
7
+ ;
8
+ "use strict";
9
+ Error.stackTraceLimit = 50;
10
+ var $;
11
+ (function ($) {
12
+ })($ || ($ = {}));
13
+ module.exports = $;
14
+
15
+ ;
16
+
17
+ $node[ "../mam.ts" ] = $node[ "../mam.ts" ] = module.exports }.call( {} , {} )
18
+ ;
19
+ "use strict"
20
+
21
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
22
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
23
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
24
+ else for (var i = decorators.length - 1; i >= 0; i--) if ((d = decorators[i])) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
25
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
26
+ };
27
+
28
+ var $ = ( typeof module === 'object' ) ? ( module['export'+'s'] = globalThis ) : globalThis
29
+ $.$$ = $
30
+
31
+ ;
32
+ "use strict";
33
+ var $;
34
+ (function ($) {
35
+ function $mol_base64_encode(src) {
36
+ return src.toBase64();
37
+ }
38
+ $.$mol_base64_encode = $mol_base64_encode;
39
+ })($ || ($ = {}));
40
+
41
+ ;
42
+ "use strict";
43
+ var $;
44
+ (function ($) {
45
+ })($ || ($ = {}));
46
+
47
+ ;
48
+ "use strict";
49
+ var $;
50
+ (function ($) {
51
+ $.$mol_dom_context = self;
52
+ })($ || ($ = {}));
53
+
54
+ ;
55
+ "use strict";
56
+ var $;
57
+ (function ($) {
58
+ $.$mol_dom = $mol_dom_context;
59
+ })($ || ($ = {}));
60
+
61
+ ;
62
+ "use strict";
63
+ var $;
64
+ (function ($) {
65
+ function binary_string(bytes) {
66
+ let binary = '';
67
+ if (typeof bytes !== 'string') {
68
+ for (const byte of bytes)
69
+ binary += String.fromCharCode(byte);
70
+ }
71
+ else {
72
+ binary = unescape(encodeURIComponent(bytes));
73
+ }
74
+ return binary;
75
+ }
76
+ function $mol_base64_encode_web(str) {
77
+ return $mol_dom_context.btoa(binary_string(str));
78
+ }
79
+ $.$mol_base64_encode_web = $mol_base64_encode_web;
80
+ if (!('toBase64' in Uint8Array.prototype)) {
81
+ $.$mol_base64_encode = $mol_base64_encode_web;
82
+ }
83
+ })($ || ($ = {}));
84
+
85
+ ;
86
+ "use strict";
87
+ var $;
88
+ (function ($) {
89
+ function $mol_base64_decode(base64) {
90
+ return Uint8Array.fromBase64(base64);
91
+ }
92
+ $.$mol_base64_decode = $mol_base64_decode;
93
+ })($ || ($ = {}));
94
+
95
+ ;
96
+ "use strict";
97
+ var $;
98
+ (function ($) {
99
+ function $mol_base64_decode_web(base64Str) {
100
+ const buf = Uint8Array.from($mol_dom_context.atob(base64Str), c => c.charCodeAt(0));
101
+ return buf;
102
+ }
103
+ $.$mol_base64_decode_web = $mol_base64_decode_web;
104
+ if (!('fromBase64' in Uint8Array)) {
105
+ $.$mol_base64_decode = $mol_base64_decode_web;
106
+ }
107
+ })($ || ($ = {}));
108
+
109
+ ;
110
+ "use strict";
111
+ var $;
112
+ (function ($) {
113
+ function $mol_base64_ae_encode(buffer) {
114
+ return $mol_base64_encode(buffer).replace(/\+/g, 'æ').replace(/\//g, 'Æ').replace(/=/g, '');
115
+ }
116
+ $.$mol_base64_ae_encode = $mol_base64_ae_encode;
117
+ function $mol_base64_ae_decode(str) {
118
+ return $mol_base64_decode(str.replace(/æ/g, '+').replace(/Æ/g, '/'));
119
+ }
120
+ $.$mol_base64_ae_decode = $mol_base64_ae_decode;
121
+ })($ || ($ = {}));
122
+
123
+ ;
124
+ "use strict";
125
+ var $;
126
+ (function ($) {
127
+ const named = new WeakSet();
128
+ function $mol_func_name(func) {
129
+ let name = func.name;
130
+ if (name?.length > 1)
131
+ return name;
132
+ if (named.has(func))
133
+ return name;
134
+ for (let key in this) {
135
+ try {
136
+ if (this[key] !== func)
137
+ continue;
138
+ name = key;
139
+ Object.defineProperty(func, 'name', { value: name });
140
+ break;
141
+ }
142
+ catch { }
143
+ }
144
+ named.add(func);
145
+ return name;
146
+ }
147
+ $.$mol_func_name = $mol_func_name;
148
+ function $mol_func_name_from(target, source) {
149
+ Object.defineProperty(target, 'name', { value: source.name });
150
+ return target;
151
+ }
152
+ $.$mol_func_name_from = $mol_func_name_from;
153
+ })($ || ($ = {}));
154
+
155
+ ;
156
+ "use strict";
157
+ var $;
158
+ (function ($) {
159
+ function $mol_fail(error) {
160
+ throw error;
161
+ }
162
+ $.$mol_fail = $mol_fail;
163
+ })($ || ($ = {}));
164
+
165
+ ;
166
+ "use strict";
167
+ var $;
168
+ (function ($) {
169
+ class $mol_buffer extends DataView {
170
+ [Symbol.toStringTag] = this.constructor.name + '<>';
171
+ static from(array) {
172
+ if (typeof array === 'number')
173
+ array = new Uint8Array(array);
174
+ if (typeof array === 'string')
175
+ array = $mol_base64_ae_decode(array);
176
+ if (!ArrayBuffer.isView(array))
177
+ array = new Uint8Array(array);
178
+ return new this(array.buffer, array.byteOffset, array.byteLength);
179
+ }
180
+ static toString() {
181
+ return $$.$mol_func_name(this);
182
+ }
183
+ getUint48(offset, LE = false) {
184
+ if (offset % 4) {
185
+ return this.getUint16(offset, LE) + this.getUint32(offset + 2, LE) * 2 ** 16;
186
+ }
187
+ else {
188
+ return this.getUint32(offset, LE) + this.getUint16(offset + 4, LE) * 2 ** 32;
189
+ }
190
+ }
191
+ setUint48(offset, value, LE = false) {
192
+ if (offset % 4) {
193
+ this.setUint16(offset, value & ((1 << 16) - 1), LE);
194
+ this.setUint32(offset + 2, (value / 2 ** 16) | 0, LE);
195
+ }
196
+ else {
197
+ this.setUint32(offset, value | 0, LE);
198
+ this.setUint16(offset + 4, (value / 2 ** 32) | 0, LE);
199
+ }
200
+ }
201
+ int8(offset, next) {
202
+ if (next === undefined)
203
+ return this.getInt8(offset);
204
+ if (next >= -(2 ** 7) && next < 2 ** 7)
205
+ return this.setInt8(offset, next), next;
206
+ $mol_fail(new Error(`Wrong int8 value ${next}`));
207
+ }
208
+ uint8(offset, next) {
209
+ if (next === undefined)
210
+ return this.getUint8(offset);
211
+ if (next >= 0 && next < 2 ** 8)
212
+ return this.setUint8(offset, next), next;
213
+ $mol_fail(new Error(`Wrong uint8 value ${next}`));
214
+ }
215
+ int16(offset, next) {
216
+ if (next === undefined)
217
+ return this.getInt16(offset, true);
218
+ if (next >= -(2 ** 15) && next < 2 ** 15)
219
+ return this.setInt16(offset, next, true), next;
220
+ $mol_fail(new Error(`Wrong int16 value ${next}`));
221
+ }
222
+ uint16(offset, next) {
223
+ if (next === undefined)
224
+ return this.getUint16(offset, true);
225
+ if (next >= 0 && next < 2 ** 16)
226
+ return this.setUint16(offset, next, true), next;
227
+ $mol_fail(new Error(`Wrong uint16 value ${next}`));
228
+ }
229
+ int32(offset, next) {
230
+ if (next === undefined)
231
+ return this.getInt32(offset, true);
232
+ if (next >= -(2 ** 31) && next < 2 ** 31)
233
+ return this.setInt32(offset, next, true), next;
234
+ $mol_fail(new Error(`Wrong int32 value ${next}`));
235
+ }
236
+ uint32(offset, next) {
237
+ if (next === undefined)
238
+ return this.getUint32(offset, true);
239
+ if (next >= 0 && next < 2 ** 32)
240
+ return this.setUint32(offset, next, true), next;
241
+ $mol_fail(new Error(`Wrong uint32 value ${next}`));
242
+ }
243
+ int64(offset, next) {
244
+ if (next === undefined)
245
+ return this.getBigInt64(offset, true);
246
+ if (next >= -(2n ** 63n) && next < 2n ** 63n)
247
+ return this.setBigInt64(offset, next, true), next;
248
+ $mol_fail(new Error(`Wrong int64 value ${next}`));
249
+ }
250
+ uint48(offset, next) {
251
+ if (next === undefined)
252
+ return this.getUint48(offset, true);
253
+ if (next >= 0 && next < 2 ** 48)
254
+ return this.setUint48(offset, next, true), next;
255
+ $mol_fail(new Error(`Wrong uint48 value ${next}`));
256
+ }
257
+ uint64(offset, next) {
258
+ if (next === undefined)
259
+ return this.getBigUint64(offset, true);
260
+ if (next >= 0n && next < 2n ** 64n)
261
+ return this.setBigUint64(offset, next, true), next;
262
+ $mol_fail(new Error(`Wrong uint64 value ${next}`));
263
+ }
264
+ float16(offset, next) {
265
+ if (next !== undefined)
266
+ this.setFloat16(offset, next, true);
267
+ return this.getFloat16(offset, true);
268
+ }
269
+ float32(offset, next) {
270
+ if (next !== undefined)
271
+ this.setFloat32(offset, next, true);
272
+ return this.getFloat32(offset, true);
273
+ }
274
+ float64(offset, next) {
275
+ if (next !== undefined)
276
+ this.setFloat64(offset, next, true);
277
+ return this.getFloat64(offset, true);
278
+ }
279
+ asArray() {
280
+ return new Uint8Array(this.buffer, this.byteOffset, this.byteLength);
281
+ }
282
+ toString() {
283
+ return $mol_base64_ae_encode(this.asArray());
284
+ }
285
+ }
286
+ $.$mol_buffer = $mol_buffer;
287
+ })($ || ($ = {}));
288
+
289
+ ;
290
+ "use strict";
291
+ var $;
292
+ (function ($) {
293
+ function $mol_base64_url_encode(buffer) {
294
+ return buffer.toBase64({ alphabet: 'base64url', omitPadding: true });
295
+ }
296
+ $.$mol_base64_url_encode = $mol_base64_url_encode;
297
+ function $mol_base64_url_decode(str) {
298
+ return Uint8Array.fromBase64(str, { alphabet: 'base64url' });
299
+ }
300
+ $.$mol_base64_url_decode = $mol_base64_url_decode;
301
+ })($ || ($ = {}));
302
+
303
+ ;
304
+ "use strict";
305
+ var $;
306
+ (function ($) {
307
+ function $mol_base64_url_encode_web(buffer) {
308
+ return $mol_base64_encode(buffer).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
309
+ }
310
+ $.$mol_base64_url_encode_web = $mol_base64_url_encode_web;
311
+ if (!('toBase64' in Uint8Array.prototype)) {
312
+ $.$mol_base64_url_encode = $mol_base64_url_encode_web;
313
+ }
314
+ function $mol_base64_url_decode_web(str) {
315
+ return $mol_base64_decode(str.replace(/-/g, '+').replace(/_/g, '/'));
316
+ }
317
+ $.$mol_base64_url_decode_web = $mol_base64_url_decode_web;
318
+ if (!('fromBase64' in Uint8Array)) {
319
+ $.$mol_base64_url_decode = $mol_base64_url_decode_web;
320
+ }
321
+ })($ || ($ = {}));
322
+
323
+ ;
324
+ "use strict";
325
+ var $;
326
+ (function ($) {
327
+ $.$mol_ambient_ref = Symbol('$mol_ambient_ref');
328
+ function $mol_ambient(overrides) {
329
+ return Object.setPrototypeOf(overrides, this || $);
330
+ }
331
+ $.$mol_ambient = $mol_ambient;
332
+ })($ || ($ = {}));
333
+
334
+ ;
335
+ "use strict";
336
+ var $;
337
+ (function ($) {
338
+ const instances = new WeakSet();
339
+ function $mol_delegate(proto, target) {
340
+ const proxy = new Proxy(proto, {
341
+ get: (_, field) => {
342
+ const obj = target();
343
+ let val = Reflect.get(obj, field);
344
+ if (typeof val === 'function') {
345
+ val = val.bind(obj);
346
+ }
347
+ return val;
348
+ },
349
+ has: (_, field) => Reflect.has(target(), field),
350
+ set: (_, field, value) => Reflect.set(target(), field, value),
351
+ getOwnPropertyDescriptor: (_, field) => Reflect.getOwnPropertyDescriptor(target(), field),
352
+ ownKeys: () => Reflect.ownKeys(target()),
353
+ getPrototypeOf: () => Reflect.getPrototypeOf(target()),
354
+ setPrototypeOf: (_, donor) => Reflect.setPrototypeOf(target(), donor),
355
+ isExtensible: () => Reflect.isExtensible(target()),
356
+ preventExtensions: () => Reflect.preventExtensions(target()),
357
+ apply: (_, self, args) => Reflect.apply(target(), self, args),
358
+ construct: (_, args, retarget) => Reflect.construct(target(), args, retarget),
359
+ defineProperty: (_, field, descr) => Reflect.defineProperty(target(), field, descr),
360
+ deleteProperty: (_, field) => Reflect.deleteProperty(target(), field),
361
+ });
362
+ instances.add(proxy);
363
+ return proxy;
364
+ }
365
+ $.$mol_delegate = $mol_delegate;
366
+ Reflect.defineProperty($mol_delegate, Symbol.hasInstance, {
367
+ value: (obj) => instances.has(obj),
368
+ });
369
+ })($ || ($ = {}));
370
+
371
+ ;
372
+ "use strict";
373
+ var $;
374
+ (function ($) {
375
+ $.$mol_owning_map = new WeakMap();
376
+ function $mol_owning_allow(having) {
377
+ try {
378
+ if (!having)
379
+ return false;
380
+ if (typeof having !== 'object' && typeof having !== 'function')
381
+ return false;
382
+ if (having instanceof $mol_delegate)
383
+ return false;
384
+ if (typeof having['destructor'] !== 'function')
385
+ return false;
386
+ return true;
387
+ }
388
+ catch {
389
+ return false;
390
+ }
391
+ }
392
+ $.$mol_owning_allow = $mol_owning_allow;
393
+ function $mol_owning_get(having, Owner) {
394
+ if (!$mol_owning_allow(having))
395
+ return null;
396
+ while (true) {
397
+ const owner = $.$mol_owning_map.get(having);
398
+ if (!owner)
399
+ return owner;
400
+ if (!Owner)
401
+ return owner;
402
+ if (owner instanceof Owner)
403
+ return owner;
404
+ having = owner;
405
+ }
406
+ }
407
+ $.$mol_owning_get = $mol_owning_get;
408
+ function $mol_owning_check(owner, having) {
409
+ if (!$mol_owning_allow(having))
410
+ return false;
411
+ if ($.$mol_owning_map.get(having) !== owner)
412
+ return false;
413
+ return true;
414
+ }
415
+ $.$mol_owning_check = $mol_owning_check;
416
+ function $mol_owning_catch(owner, having) {
417
+ if (!$mol_owning_allow(having))
418
+ return false;
419
+ if ($.$mol_owning_map.get(having))
420
+ return false;
421
+ $.$mol_owning_map.set(having, owner);
422
+ return true;
423
+ }
424
+ $.$mol_owning_catch = $mol_owning_catch;
425
+ })($ || ($ = {}));
426
+
427
+ ;
428
+ "use strict";
429
+ var $;
430
+ (function ($) {
431
+ function $mol_fail_hidden(error) {
432
+ throw error;
433
+ }
434
+ $.$mol_fail_hidden = $mol_fail_hidden;
435
+ })($ || ($ = {}));
436
+
437
+ ;
438
+ "use strict";
439
+
440
+ ;
441
+ "use strict";
442
+ var $;
443
+ (function ($) {
444
+ $.$mol_key_handle = Symbol.for('$mol_key_handle');
445
+ $.$mol_key_store = new WeakMap();
446
+ })($ || ($ = {}));
447
+
448
+ ;
449
+ "use strict";
450
+ var $;
451
+ (function ($) {
452
+ if (!Symbol.dispose)
453
+ Symbol.dispose = Symbol('Symbol.dispose');
454
+ class $mol_object2 {
455
+ static $ = $;
456
+ [Symbol.toStringTag];
457
+ [$mol_ambient_ref] = null;
458
+ get $() {
459
+ if (this[$mol_ambient_ref])
460
+ return this[$mol_ambient_ref];
461
+ const owner = $mol_owning_get(this);
462
+ return this[$mol_ambient_ref] = owner?.$ || this.constructor.$ || $mol_object2.$;
463
+ }
464
+ set $(next) {
465
+ if (this[$mol_ambient_ref])
466
+ $mol_fail_hidden(new Error('Context already defined'));
467
+ this[$mol_ambient_ref] = next;
468
+ }
469
+ static create(init) {
470
+ const obj = new this;
471
+ if (init)
472
+ init(obj);
473
+ return obj;
474
+ }
475
+ static [Symbol.toPrimitive]() {
476
+ return this.toString();
477
+ }
478
+ static toString() {
479
+ return this[Symbol.toStringTag] || this.$.$mol_func_name(this);
480
+ }
481
+ static toJSON() {
482
+ return this.toString();
483
+ }
484
+ static [$mol_key_handle]() {
485
+ return this.toString();
486
+ }
487
+ destructor() { }
488
+ static destructor() { }
489
+ [Symbol.dispose]() {
490
+ this.destructor();
491
+ }
492
+ toString() {
493
+ return this[Symbol.toStringTag] || this.constructor.name + '<>';
494
+ }
495
+ }
496
+ $.$mol_object2 = $mol_object2;
497
+ })($ || ($ = {}));
498
+
499
+ ;
500
+ "use strict";
501
+ var $;
502
+ (function ($) {
503
+ class $mol_wrapper extends $mol_object2 {
504
+ static wrap;
505
+ static run(task) {
506
+ return this.func(task)();
507
+ }
508
+ static func(func) {
509
+ return this.wrap(func);
510
+ }
511
+ static get class() {
512
+ return (Class) => {
513
+ const construct = (target, args) => new Class(...args);
514
+ const handler = {
515
+ construct: this.func(construct)
516
+ };
517
+ handler[Symbol.toStringTag] = Class.name + '#';
518
+ return new Proxy(Class, handler);
519
+ };
520
+ }
521
+ static get method() {
522
+ return (obj, name, descr = Reflect.getOwnPropertyDescriptor(obj, name)) => {
523
+ descr.value = this.func(descr.value);
524
+ return descr;
525
+ };
526
+ }
527
+ static get field() {
528
+ return (obj, name, descr = Reflect.getOwnPropertyDescriptor(obj, name)) => {
529
+ descr.get = descr.set = this.func(descr.get);
530
+ return descr;
531
+ };
532
+ }
533
+ }
534
+ $.$mol_wrapper = $mol_wrapper;
535
+ })($ || ($ = {}));
536
+
537
+ ;
538
+ "use strict";
539
+ var $;
540
+ (function ($) {
541
+ class $mol_memo extends $mol_wrapper {
542
+ static wrap(task) {
543
+ const store = new WeakMap();
544
+ const fun = function (next) {
545
+ if (next === undefined && store.has(this))
546
+ return store.get(this);
547
+ const val = task.call(this, next) ?? next;
548
+ store.set(this, val);
549
+ return val;
550
+ };
551
+ Reflect.defineProperty(fun, 'name', { value: task.name + ' ' });
552
+ return fun;
553
+ }
554
+ }
555
+ $.$mol_memo = $mol_memo;
556
+ })($ || ($ = {}));
557
+
558
+ ;
559
+ "use strict";
560
+ var $;
561
+ (function ($) {
562
+ class $mol_crypto2_key extends $mol_buffer {
563
+ static size_str = 43;
564
+ static size_bin = 32;
565
+ static from(serial) {
566
+ if (typeof serial === 'string') {
567
+ serial = new Uint8Array(serial.match(/.{43}/g)
568
+ .flatMap(chunk => [...$mol_base64_url_decode(chunk)]));
569
+ }
570
+ return super.from(serial);
571
+ }
572
+ asArray() {
573
+ return new Uint8Array(this.buffer, this.byteOffset, this.constructor.size_bin);
574
+ }
575
+ toString() {
576
+ return $mol_base64_url_encode(this.asArray());
577
+ }
578
+ }
579
+ __decorate([
580
+ $mol_memo.method
581
+ ], $mol_crypto2_key.prototype, "toString", null);
582
+ $.$mol_crypto2_key = $mol_crypto2_key;
583
+ })($ || ($ = {}));
584
+
585
+ ;
586
+ "use strict";
587
+ var $;
588
+ (function ($) {
589
+ $.$mol_crypto_native = crypto;
590
+ })($ || ($ = {}));
591
+
592
+ ;
593
+ "use strict";
594
+ var $;
595
+ (function ($) {
596
+ function $mol_crypto_restack(error) {
597
+ error = new Error(error instanceof Error ? error.message : String(error), { cause: error });
598
+ $mol_fail_hidden(error);
599
+ }
600
+ $.$mol_crypto_restack = $mol_crypto_restack;
601
+ })($ || ($ = {}));
602
+
603
+ ;
604
+ "use strict";
605
+ var $;
606
+ (function ($) {
607
+ class $mol_crypto2_auditor extends $mol_crypto2_key {
608
+ async native() {
609
+ return $mol_crypto_native.subtle.importKey('jwk', {
610
+ crv: "Ed25519",
611
+ ext: true,
612
+ key_ops: ['verify'],
613
+ kty: "OKP",
614
+ x: this.toString(),
615
+ }, "Ed25519", Boolean('extractable'), ['verify']).catch($mol_crypto_restack);
616
+ }
617
+ async verify(data, sign) {
618
+ return await $mol_crypto_native.subtle.verify("Ed25519", await this.native(), sign, data).catch($mol_crypto_restack);
619
+ }
620
+ }
621
+ __decorate([
622
+ $mol_memo.method
623
+ ], $mol_crypto2_auditor.prototype, "native", null);
624
+ $.$mol_crypto2_auditor = $mol_crypto2_auditor;
625
+ })($ || ($ = {}));
626
+
627
+ ;
628
+ "use strict";
629
+ var $;
630
+ (function ($) {
631
+ class $mol_crypto2_signer extends $mol_crypto2_auditor {
632
+ static size_sign = 64;
633
+ static async generate() {
634
+ const pair = await $mol_crypto_native.subtle.generateKey("Ed25519", Boolean('extractable'), ['sign', 'verify']).catch($mol_crypto_restack);
635
+ const { x, d } = await $mol_crypto_native.subtle.exportKey('jwk', pair.privateKey).catch($mol_crypto_restack);
636
+ return this.from(x + d);
637
+ }
638
+ async nativePrivate() {
639
+ return await $mol_crypto_native.subtle.importKey('jwk', {
640
+ crv: "Ed25519",
641
+ ext: true,
642
+ key_ops: ['sign'],
643
+ kty: "OKP",
644
+ x: this.toString(),
645
+ d: this.toStringPrivate(),
646
+ }, "Ed25519", Boolean('extractable'), ['sign']).catch($mol_crypto_restack);
647
+ }
648
+ asArrayPrivate() {
649
+ return new Uint8Array(this.buffer, this.byteOffset + 32, 32);
650
+ }
651
+ toStringPrivate() {
652
+ return $mol_base64_url_encode(this.asArrayPrivate());
653
+ }
654
+ auditor() {
655
+ return $mol_crypto2_auditor.from(this.asArray());
656
+ }
657
+ async sign(data) {
658
+ return new Uint8Array(await $mol_crypto_native.subtle.sign("Ed25519", await this.nativePrivate(), data).catch($mol_crypto_restack));
659
+ }
660
+ }
661
+ __decorate([
662
+ $mol_memo.method
663
+ ], $mol_crypto2_signer.prototype, "nativePrivate", null);
664
+ __decorate([
665
+ $mol_memo.method
666
+ ], $mol_crypto2_signer.prototype, "toStringPrivate", null);
667
+ __decorate([
668
+ $mol_memo.method
669
+ ], $mol_crypto2_signer.prototype, "auditor", null);
670
+ $.$mol_crypto2_signer = $mol_crypto2_signer;
671
+ })($ || ($ = {}));
672
+
673
+ ;
674
+ "use strict";
675
+ var $;
676
+ (function ($) {
677
+ class $mol_crypto2_socket extends $mol_crypto2_key {
678
+ async native() {
679
+ return await $mol_crypto_native.subtle.importKey('jwk', {
680
+ crv: 'X25519',
681
+ ext: true,
682
+ kty: 'OKP',
683
+ key_ops: [],
684
+ x: this.toString(),
685
+ }, "X25519", true, []).catch($mol_crypto_restack);
686
+ }
687
+ }
688
+ __decorate([
689
+ $mol_memo.method
690
+ ], $mol_crypto2_socket.prototype, "native", null);
691
+ $.$mol_crypto2_socket = $mol_crypto2_socket;
692
+ })($ || ($ = {}));
693
+
694
+ ;
695
+ "use strict";
696
+ var $;
697
+ (function ($) {
698
+ function $mol_crypto_salt() {
699
+ return $mol_crypto_native.getRandomValues(new Uint8Array(16));
700
+ }
701
+ $.$mol_crypto_salt = $mol_crypto_salt;
702
+ $.$mol_crypto_salt_once = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6]);
703
+ })($ || ($ = {}));
704
+
705
+ ;
706
+ "use strict";
707
+ var $;
708
+ (function ($) {
709
+ class $mol_crypto_sacred extends $mol_buffer {
710
+ static size = 16;
711
+ static make() {
712
+ return this.from($mol_crypto_salt());
713
+ }
714
+ static from(serial) {
715
+ if (typeof serial === 'string') {
716
+ serial = new Uint8Array([
717
+ ...$mol_base64_url_decode(serial),
718
+ ]);
719
+ }
720
+ if (!(serial instanceof Uint8Array)) {
721
+ serial = new Uint8Array(serial.buffer, serial.byteOffset, serial.byteLength);
722
+ }
723
+ ;
724
+ serial[0] = 0xFF;
725
+ const sacred = super.from(serial);
726
+ return sacred;
727
+ }
728
+ static async from_native(native) {
729
+ const buf = await $mol_crypto_native.subtle.exportKey('raw', native).catch($mol_crypto_restack);
730
+ const sacred = this.from(new Uint8Array(buf));
731
+ sacred._native = native;
732
+ return sacred;
733
+ }
734
+ constructor(buffer, byteOffset, byteLength) {
735
+ super(buffer, byteOffset, byteLength);
736
+ if (this.getUint8(0) !== 0xFF)
737
+ $mol_fail(new Error('Buffer should starts with 0xFF byte'));
738
+ }
739
+ toString() {
740
+ return $mol_base64_url_encode(this.asArray());
741
+ }
742
+ _native;
743
+ async native() {
744
+ return this._native ?? (this._native = await $mol_crypto_native.subtle.importKey('raw', this, {
745
+ name: 'AES-CBC',
746
+ length: 128,
747
+ }, true, ['encrypt', 'decrypt']).catch($mol_crypto_restack));
748
+ }
749
+ async encrypt(open, salt) {
750
+ return new Uint8Array(await $mol_crypto_native.subtle.encrypt({
751
+ name: 'AES-CBC',
752
+ length: 128,
753
+ tagLength: 32,
754
+ iv: salt,
755
+ }, await this.native(), open).catch($mol_crypto_restack));
756
+ }
757
+ async decrypt(closed, salt) {
758
+ return new Uint8Array(await $mol_crypto_native.subtle.decrypt({
759
+ name: 'AES-CBC',
760
+ length: 128,
761
+ tagLength: 32,
762
+ iv: salt,
763
+ }, await this.native(), closed).catch($mol_crypto_restack));
764
+ }
765
+ async close(opened, salt) {
766
+ if (opened.getUint8(0) !== 0xFF)
767
+ throw new Error('Closable buffer should starts with 0xFF');
768
+ const trimed = new Uint8Array(opened.buffer, opened.byteOffset + 1, opened.byteLength - 1);
769
+ return this.encrypt(trimed, salt);
770
+ }
771
+ async open(closed, salt) {
772
+ const trimed = await this.decrypt(closed, salt);
773
+ if (trimed.byteLength !== closed.byteLength - 1)
774
+ throw new Error('Length of opened buffer should be ' + (closed.byteLength - 1));
775
+ const opened = new Uint8Array(closed.byteLength);
776
+ opened[0] = 0xFF;
777
+ opened.set(trimed, 1);
778
+ return opened;
779
+ }
780
+ }
781
+ __decorate([
782
+ $mol_memo.method
783
+ ], $mol_crypto_sacred.prototype, "toString", null);
784
+ $.$mol_crypto_sacred = $mol_crypto_sacred;
785
+ })($ || ($ = {}));
786
+
787
+ ;
788
+ "use strict";
789
+ var $;
790
+ (function ($) {
791
+ class $mol_crypto2_cipher extends $mol_crypto2_socket {
792
+ static size_secret = 16;
793
+ static async generate() {
794
+ const pair = await $mol_crypto_native.subtle.generateKey("X25519", Boolean('extractable'), ['deriveKey']).catch($mol_crypto_restack);
795
+ const { x, d } = await $mol_crypto_native.subtle.exportKey('jwk', pair.privateKey).catch($mol_crypto_restack);
796
+ return this.from(x + d);
797
+ }
798
+ async nativePrivate() {
799
+ return $mol_crypto_native.subtle.importKey('jwk', {
800
+ crv: 'X25519',
801
+ ext: true,
802
+ kty: 'OKP',
803
+ key_ops: ['deriveKey', 'deriveBits'],
804
+ x: this.toString(),
805
+ d: this.toStringPrivate(),
806
+ }, "X25519", Boolean('extractable'), ['deriveKey', 'deriveBits']).catch($mol_crypto_restack);
807
+ }
808
+ asArrayPrivate() {
809
+ return new Uint8Array(this.buffer, this.byteOffset + 32, 32);
810
+ }
811
+ toStringPrivate() {
812
+ return $mol_base64_url_encode(this.asArrayPrivate());
813
+ }
814
+ socket() {
815
+ return $mol_crypto2_socket.from(this.asArray());
816
+ }
817
+ async secret(pub) {
818
+ return $mol_crypto_sacred.from(new Uint8Array(await $mol_crypto_native.subtle.deriveBits({
819
+ name: "X25519",
820
+ public: await pub.native(),
821
+ }, await this.nativePrivate(), $mol_crypto_sacred.size * 8).catch($mol_crypto_restack)));
822
+ }
823
+ }
824
+ __decorate([
825
+ $mol_memo.method
826
+ ], $mol_crypto2_cipher.prototype, "nativePrivate", null);
827
+ __decorate([
828
+ $mol_memo.method
829
+ ], $mol_crypto2_cipher.prototype, "toStringPrivate", null);
830
+ __decorate([
831
+ $mol_memo.method
832
+ ], $mol_crypto2_cipher.prototype, "socket", null);
833
+ $.$mol_crypto2_cipher = $mol_crypto2_cipher;
834
+ })($ || ($ = {}));
835
+
836
+ ;
837
+ "use strict";
838
+ var $;
839
+ (function ($) {
840
+ class $mol_crypto2_public extends $mol_crypto2_key {
841
+ static size_str = 86;
842
+ static size_bin = 64;
843
+ auditor() {
844
+ return $mol_crypto2_auditor.from(this.asArray().subarray(0, 32));
845
+ }
846
+ socket() {
847
+ return $mol_crypto2_socket.from(this.asArray().subarray(32, 64));
848
+ }
849
+ toString() {
850
+ return this.auditor().toString() + this.socket().toString();
851
+ }
852
+ }
853
+ __decorate([
854
+ $mol_memo.method
855
+ ], $mol_crypto2_public.prototype, "auditor", null);
856
+ __decorate([
857
+ $mol_memo.method
858
+ ], $mol_crypto2_public.prototype, "socket", null);
859
+ __decorate([
860
+ $mol_memo.method
861
+ ], $mol_crypto2_public.prototype, "toString", null);
862
+ $.$mol_crypto2_public = $mol_crypto2_public;
863
+ })($ || ($ = {}));
864
+
865
+ ;
866
+ "use strict";
867
+ var $;
868
+ (function ($) {
869
+ class $mol_crypto2_private extends $mol_crypto2_public {
870
+ static async generate() {
871
+ const [signer, cipher] = await Promise.all([
872
+ $mol_crypto2_signer.generate(),
873
+ $mol_crypto2_cipher.generate(),
874
+ ]);
875
+ const key = $mol_crypto2_private.from($mol_crypto2_public.size_bin + $mol_crypto2_private.size_bin);
876
+ key.asArray().set(signer.asArray(), 0);
877
+ key.asArray().set(cipher.asArray(), 32);
878
+ key.asArrayPrivate().set(signer.asArrayPrivate(), 0);
879
+ key.asArrayPrivate().set(cipher.asArrayPrivate(), 32);
880
+ return key;
881
+ }
882
+ signer() {
883
+ const signer = $mol_crypto2_signer.from($mol_crypto2_auditor.size_bin + $mol_crypto2_signer.size_bin);
884
+ signer.asArray().set(this.asArray().subarray(0, 32));
885
+ signer.asArrayPrivate().set(this.asArrayPrivate().subarray(0, 32));
886
+ return signer;
887
+ }
888
+ cipher() {
889
+ const cipher = $mol_crypto2_cipher.from($mol_crypto2_socket.size_bin + $mol_crypto2_cipher.size_bin);
890
+ cipher.asArray().set(this.asArray().subarray(32, 64));
891
+ cipher.asArrayPrivate().set(this.asArrayPrivate().subarray(32, 64));
892
+ return cipher;
893
+ }
894
+ public() {
895
+ return $mol_crypto2_public.from(this.asArray());
896
+ }
897
+ asArrayPrivate() {
898
+ return new Uint8Array(this.buffer, this.byteOffset + 64, 64);
899
+ }
900
+ toStringPrivate() {
901
+ return this.signer().toStringPrivate() + this.cipher().toStringPrivate();
902
+ }
903
+ }
904
+ __decorate([
905
+ $mol_memo.method
906
+ ], $mol_crypto2_private.prototype, "signer", null);
907
+ __decorate([
908
+ $mol_memo.method
909
+ ], $mol_crypto2_private.prototype, "cipher", null);
910
+ __decorate([
911
+ $mol_memo.method
912
+ ], $mol_crypto2_private.prototype, "public", null);
913
+ __decorate([
914
+ $mol_memo.method
915
+ ], $mol_crypto2_private.prototype, "toStringPrivate", null);
916
+ $.$mol_crypto2_private = $mol_crypto2_private;
917
+ })($ || ($ = {}));
918
+
919
+
920
+ //# sourceMappingURL=web.js.map