mol_crypto_lib 0.1.1646 → 0.1.1647

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.mjs CHANGED
@@ -33,7 +33,7 @@ $.$$ = $
33
33
  var $;
34
34
  (function ($) {
35
35
  function $mol_base64_encode(src) {
36
- throw new Error('Not implemented');
36
+ return src.toBase64();
37
37
  }
38
38
  $.$mol_base64_encode = $mol_base64_encode;
39
39
  })($ || ($ = {}));
@@ -77,7 +77,9 @@ var $;
77
77
  return $mol_dom_context.btoa(binary_string(str));
78
78
  }
79
79
  $.$mol_base64_encode_web = $mol_base64_encode_web;
80
- $.$mol_base64_encode = $mol_base64_encode_web;
80
+ if (!('toBase64' in Uint8Array.prototype)) {
81
+ $.$mol_base64_encode = $mol_base64_encode_web;
82
+ }
81
83
  })($ || ($ = {}));
82
84
 
83
85
  ;
@@ -85,7 +87,7 @@ var $;
85
87
  var $;
86
88
  (function ($) {
87
89
  function $mol_base64_decode(base64) {
88
- throw new Error('Not implemented');
90
+ return Uint8Array.fromBase64(base64);
89
91
  }
90
92
  $.$mol_base64_decode = $mol_base64_decode;
91
93
  })($ || ($ = {}));
@@ -95,10 +97,13 @@ var $;
95
97
  var $;
96
98
  (function ($) {
97
99
  function $mol_base64_decode_web(base64Str) {
98
- return new Uint8Array($mol_dom_context.atob(base64Str).split('').map(c => c.charCodeAt(0)));
100
+ const buf = Uint8Array.from($mol_dom_context.atob(base64Str), c => c.charCodeAt(0));
101
+ return buf;
99
102
  }
100
103
  $.$mol_base64_decode_web = $mol_base64_decode_web;
101
- $.$mol_base64_decode = $mol_base64_decode_web;
104
+ if (!('fromBase64' in Uint8Array)) {
105
+ $.$mol_base64_decode = $mol_base64_decode_web;
106
+ }
102
107
  })($ || ($ = {}));
103
108
 
104
109
  ;
@@ -297,15 +302,35 @@ var $;
297
302
  var $;
298
303
  (function ($) {
299
304
  function $mol_base64_url_encode(buffer) {
300
- return $mol_base64_encode(buffer).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
305
+ return buffer.toBase64({ alphabet: 'base64url', omitPadding: true });
301
306
  }
302
307
  $.$mol_base64_url_encode = $mol_base64_url_encode;
303
308
  function $mol_base64_url_decode(str) {
304
- return $mol_base64_decode(str.replace(/-/g, '+').replace(/_/g, '/'));
309
+ return Uint8Array.fromBase64(str, { alphabet: 'base64url' });
305
310
  }
306
311
  $.$mol_base64_url_decode = $mol_base64_url_decode;
307
312
  })($ || ($ = {}));
308
313
 
314
+ ;
315
+ "use strict";
316
+ var $;
317
+ (function ($) {
318
+ function $mol_base64_url_encode_web(buffer) {
319
+ return $mol_base64_encode(buffer).replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
320
+ }
321
+ $.$mol_base64_url_encode_web = $mol_base64_url_encode_web;
322
+ if (!('toBase64' in Uint8Array.prototype)) {
323
+ $.$mol_base64_url_encode = $mol_base64_url_encode_web;
324
+ }
325
+ function $mol_base64_url_decode_web(str) {
326
+ return $mol_base64_decode(str.replace(/-/g, '+').replace(/_/g, '/'));
327
+ }
328
+ $.$mol_base64_url_decode_web = $mol_base64_url_decode_web;
329
+ if (!('fromBase64' in Uint8Array)) {
330
+ $.$mol_base64_url_decode = $mol_base64_url_decode_web;
331
+ }
332
+ })($ || ($ = {}));
333
+
309
334
  ;
310
335
  "use strict";
311
336
  var $;
package/web.test.js CHANGED
@@ -1289,6 +1289,19 @@ var $;
1289
1289
  });
1290
1290
  })($ || ($ = {}));
1291
1291
 
1292
+ ;
1293
+ "use strict";
1294
+ var $;
1295
+ (function ($) {
1296
+ $mol_test({
1297
+ 'encode utf8 string'() {
1298
+ const str = 'Hello, ΧΨΩЫ';
1299
+ const encoded = new Uint8Array([72, 101, 108, 108, 111, 44, 32, 206, 167, 206, 168, 206, 169, 208, 171]);
1300
+ $mol_assert_like($mol_charset_encode(str), encoded);
1301
+ },
1302
+ });
1303
+ })($ || ($ = {}));
1304
+
1292
1305
  ;
1293
1306
  "use strict";
1294
1307
  var $;
@@ -1389,11 +1402,14 @@ var $;
1389
1402
  const png = new Uint8Array([0x1a, 0x0a, 0x00, 0x49, 0x48, 0x78, 0xda]);
1390
1403
  $mol_test({
1391
1404
  'base64 encode string'() {
1392
- $mol_assert_equal($mol_base64_encode('Hello, ΧΨΩЫ'), 'SGVsbG8sIM6nzqjOqdCr');
1405
+ $mol_assert_equal($mol_base64_encode($mol_charset_encode('Hello, ΧΨΩЫ')), 'SGVsbG8sIM6nzqjOqdCr');
1393
1406
  },
1394
1407
  'base64 encode binary'() {
1395
1408
  $mol_assert_equal($mol_base64_encode(png), 'GgoASUh42g==');
1396
1409
  },
1410
+ 'base64 encode string with plus'() {
1411
+ $mol_assert_equal($mol_base64_encode($mol_charset_encode('шоешпо')), '0YjQvtC10YjQv9C+');
1412
+ },
1397
1413
  });
1398
1414
  })($ || ($ = {}));
1399
1415
 
@@ -1402,12 +1418,19 @@ var $;
1402
1418
  var $;
1403
1419
  (function ($) {
1404
1420
  const png = new Uint8Array([0x1a, 0x0a, 0x00, 0x49, 0x48, 0x78, 0xda]);
1421
+ const with_plus = new TextEncoder().encode('шоешпо');
1405
1422
  $mol_test({
1406
1423
  'base64 decode string'() {
1407
- $mol_assert_like($mol_base64_decode('SGVsbG8sIM6nzqjOqdCr'), new TextEncoder().encode('Hello, ΧΨΩЫ'));
1424
+ $mol_assert_equal($mol_base64_decode('SGVsbG8sIM6nzqjOqdCr'), new TextEncoder().encode('Hello, ΧΨΩЫ'));
1408
1425
  },
1409
1426
  'base64 decode binary'() {
1410
- $mol_assert_like($mol_base64_decode('GgoASUh42g=='), png);
1427
+ $mol_assert_equal($mol_base64_decode('GgoASUh42g=='), png);
1428
+ },
1429
+ 'base64 decode binary - without equals'() {
1430
+ $mol_assert_equal($mol_base64_decode('GgoASUh42g'), png);
1431
+ },
1432
+ 'base64 decode with plus'() {
1433
+ $mol_assert_equal($mol_base64_decode('0YjQvtC10YjQv9C+'), with_plus);
1411
1434
  },
1412
1435
  });
1413
1436
  })($ || ($ = {}));
@@ -1657,19 +1680,6 @@ var $;
1657
1680
  });
1658
1681
  })($ || ($ = {}));
1659
1682
 
1660
- ;
1661
- "use strict";
1662
- var $;
1663
- (function ($) {
1664
- $mol_test({
1665
- 'encode utf8 string'() {
1666
- const str = 'Hello, ΧΨΩЫ';
1667
- const encoded = new Uint8Array([72, 101, 108, 108, 111, 44, 32, 206, 167, 206, 168, 206, 169, 208, 171]);
1668
- $mol_assert_like($mol_charset_encode(str), encoded);
1669
- },
1670
- });
1671
- })($ || ($ = {}));
1672
-
1673
1683
  ;
1674
1684
  "use strict";
1675
1685
  var $;