sm-crypto-v2 1.11.0 → 1.13.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/CHANGELOG.md +14 -0
- package/dist/index.js +78 -40
- package/dist/index.mjs +72 -34
- package/miniprogram_dist/index.js +31 -7
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -2,6 +2,20 @@
|
|
2
2
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
4
4
|
|
5
|
+
## [1.13.0](https://github.com/Cubelrti/sm-crypto-v2/compare/v1.12.0...v1.13.0) (2025-07-15)
|
6
|
+
|
7
|
+
|
8
|
+
### Features
|
9
|
+
|
10
|
+
* downgrade to es2020 target ([3058285](https://github.com/Cubelrti/sm-crypto-v2/commit/305828570dc15fd686d04f3d85c37b978e8893c8))
|
11
|
+
|
12
|
+
## [1.12.0](https://github.com/Cubelrti/sm-crypto-v2/compare/v1.11.0...v1.12.0) (2025-06-05)
|
13
|
+
|
14
|
+
|
15
|
+
### Features
|
16
|
+
|
17
|
+
* **utils:** ensure sm2 runs in environment don't have TextEncoder ([6b74b8d](https://github.com/Cubelrti/sm-crypto-v2/commit/6b74b8d4df3ead8e2c01587e3c13cdbbf9a27701))
|
18
|
+
|
5
19
|
## [1.11.0](https://github.com/Cubelrti/sm-crypto-v2/compare/v1.10.1...v1.11.0) (2025-04-28)
|
6
20
|
|
7
21
|
|
package/dist/index.js
CHANGED
@@ -5,6 +5,7 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
8
9
|
var __export = (target, all) => {
|
9
10
|
for (var name in all)
|
10
11
|
__defProp(target, name, { get: all[name], enumerable: true });
|
@@ -26,6 +27,10 @@ var __toESM = (mod2, isNodeMode, target) => (target = mod2 != null ? __create(__
|
|
26
27
|
mod2
|
27
28
|
));
|
28
29
|
var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
|
30
|
+
var __publicField = (obj, key, value) => {
|
31
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
32
|
+
return value;
|
33
|
+
};
|
29
34
|
|
30
35
|
// src/index.ts
|
31
36
|
var src_exports = {};
|
@@ -145,11 +150,11 @@ var DEROctetString = class extends ASN1Object {
|
|
145
150
|
constructor(s) {
|
146
151
|
super();
|
147
152
|
this.s = s;
|
153
|
+
__publicField(this, "hV", "");
|
148
154
|
this.t = "04";
|
149
155
|
if (s)
|
150
156
|
this.v = s.toLowerCase();
|
151
157
|
}
|
152
|
-
hV = "";
|
153
158
|
getValue() {
|
154
159
|
return this.v;
|
155
160
|
}
|
@@ -158,8 +163,8 @@ var DERSequence = class extends ASN1Object {
|
|
158
163
|
constructor(asn1Array) {
|
159
164
|
super();
|
160
165
|
this.asn1Array = asn1Array;
|
166
|
+
__publicField(this, "t", "30");
|
161
167
|
}
|
162
|
-
t = "30";
|
163
168
|
getValue() {
|
164
169
|
this.v = this.asn1Array.map((asn1Object) => asn1Object.getEncodedHex()).join("");
|
165
170
|
return this.v;
|
@@ -304,7 +309,10 @@ var createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLengt
|
|
304
309
|
var isLE = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
305
310
|
if (!isLE)
|
306
311
|
throw new Error("Non little-endian hardware is not supported");
|
307
|
-
var hexes = Array.from(
|
312
|
+
var hexes = Array.from(
|
313
|
+
{ length: 256 },
|
314
|
+
(v, i) => i.toString(16).padStart(2, "0")
|
315
|
+
);
|
308
316
|
function bytesToHex(bytes) {
|
309
317
|
if (!u8a(bytes))
|
310
318
|
throw new Error("Uint8Array expected");
|
@@ -314,14 +322,44 @@ function bytesToHex(bytes) {
|
|
314
322
|
}
|
315
323
|
return hex;
|
316
324
|
}
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
325
|
+
var te = typeof TextEncoder != "undefined" && /* @__PURE__ */ new TextEncoder();
|
326
|
+
var slc = (v, s, e) => {
|
327
|
+
if (s == null || s < 0)
|
328
|
+
s = 0;
|
329
|
+
if (e == null || e > v.length)
|
330
|
+
e = v.length;
|
331
|
+
return new Uint8Array(v.subarray(s, e));
|
332
|
+
};
|
333
|
+
function strToU8(str) {
|
334
|
+
if (te)
|
335
|
+
return te.encode(str);
|
336
|
+
const l = str.length;
|
337
|
+
let ar = new Uint8Array(str.length + (str.length >> 1));
|
338
|
+
let ai = 0;
|
339
|
+
const w = (v) => {
|
340
|
+
ar[ai++] = v;
|
341
|
+
};
|
342
|
+
for (let i = 0; i < l; ++i) {
|
343
|
+
if (ai + 5 > ar.length) {
|
344
|
+
const n = new Uint8Array(ai + 8 + (l - i << 1));
|
345
|
+
n.set(ar);
|
346
|
+
ar = n;
|
347
|
+
}
|
348
|
+
let c = str.charCodeAt(i);
|
349
|
+
if (c < 128)
|
350
|
+
w(c);
|
351
|
+
else if (c < 2048)
|
352
|
+
w(192 | c >> 6), w(128 | c & 63);
|
353
|
+
else if (c > 55295 && c < 57344)
|
354
|
+
c = 65536 + (c & 1023 << 10) | str.charCodeAt(++i) & 1023, w(240 | c >> 18), w(128 | c >> 12 & 63), w(128 | c >> 6 & 63), w(128 | c & 63);
|
355
|
+
else
|
356
|
+
w(224 | c >> 12), w(128 | c >> 6 & 63), w(128 | c & 63);
|
357
|
+
}
|
358
|
+
return slc(ar, 0, ai);
|
321
359
|
}
|
322
360
|
function toBytes(data) {
|
323
361
|
if (typeof data === "string")
|
324
|
-
data =
|
362
|
+
data = strToU8(data);
|
325
363
|
if (!u8a(data))
|
326
364
|
throw new Error(`expected Uint8Array, got ${typeof data}`);
|
327
365
|
return data;
|
@@ -374,16 +412,16 @@ var SHA2 = class extends Hash {
|
|
374
412
|
this.outputLen = outputLen;
|
375
413
|
this.padOffset = padOffset;
|
376
414
|
this.isLE = isLE2;
|
415
|
+
// For partial updates less than block size
|
416
|
+
__publicField(this, "buffer");
|
417
|
+
__publicField(this, "view");
|
418
|
+
__publicField(this, "finished", false);
|
419
|
+
__publicField(this, "length", 0);
|
420
|
+
__publicField(this, "pos", 0);
|
421
|
+
__publicField(this, "destroyed", false);
|
377
422
|
this.buffer = new Uint8Array(blockLen);
|
378
423
|
this.view = createView(this.buffer);
|
379
424
|
}
|
380
|
-
// For partial updates less than block size
|
381
|
-
buffer;
|
382
|
-
view;
|
383
|
-
finished = false;
|
384
|
-
length = 0;
|
385
|
-
pos = 0;
|
386
|
-
destroyed = false;
|
387
425
|
update(data) {
|
388
426
|
const { view, buffer, blockLen } = this;
|
389
427
|
data = toBytes(data);
|
@@ -441,7 +479,7 @@ var SHA2 = class extends Hash {
|
|
441
479
|
return res;
|
442
480
|
}
|
443
481
|
_cloneInto(to) {
|
444
|
-
to
|
482
|
+
to || (to = new this.constructor());
|
445
483
|
to.set(...this.get());
|
446
484
|
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
447
485
|
to.length = length;
|
@@ -459,18 +497,18 @@ var SM3_M = new Uint32Array(64);
|
|
459
497
|
var T1 = 2043430169;
|
460
498
|
var T2 = 2055708042;
|
461
499
|
var SM3 = class extends SHA2 {
|
462
|
-
// We cannot use array here since array allows indexing by variable
|
463
|
-
// which means optimizer/compiler cannot use registers.
|
464
|
-
A = IV[0] | 0;
|
465
|
-
B = IV[1] | 0;
|
466
|
-
C = IV[2] | 0;
|
467
|
-
D = IV[3] | 0;
|
468
|
-
E = IV[4] | 0;
|
469
|
-
F = IV[5] | 0;
|
470
|
-
G = IV[6] | 0;
|
471
|
-
H = IV[7] | 0;
|
472
500
|
constructor() {
|
473
501
|
super(64, 32, 8, false);
|
502
|
+
// We cannot use array here since array allows indexing by variable
|
503
|
+
// which means optimizer/compiler cannot use registers.
|
504
|
+
__publicField(this, "A", IV[0] | 0);
|
505
|
+
__publicField(this, "B", IV[1] | 0);
|
506
|
+
__publicField(this, "C", IV[2] | 0);
|
507
|
+
__publicField(this, "D", IV[3] | 0);
|
508
|
+
__publicField(this, "E", IV[4] | 0);
|
509
|
+
__publicField(this, "F", IV[5] | 0);
|
510
|
+
__publicField(this, "G", IV[6] | 0);
|
511
|
+
__publicField(this, "H", IV[7] | 0);
|
474
512
|
}
|
475
513
|
get() {
|
476
514
|
const { A, B, C, D, E, F, G, H } = this;
|
@@ -535,14 +573,14 @@ var sm3 = wrapConstructor(() => new SM3());
|
|
535
573
|
|
536
574
|
// src/sm2/hmac.ts
|
537
575
|
var HMAC = class extends Hash {
|
538
|
-
oHash;
|
539
|
-
iHash;
|
540
|
-
blockLen;
|
541
|
-
outputLen;
|
542
|
-
finished = false;
|
543
|
-
destroyed = false;
|
544
576
|
constructor(hash, _key) {
|
545
577
|
super();
|
578
|
+
__publicField(this, "oHash");
|
579
|
+
__publicField(this, "iHash");
|
580
|
+
__publicField(this, "blockLen");
|
581
|
+
__publicField(this, "outputLen");
|
582
|
+
__publicField(this, "finished", false);
|
583
|
+
__publicField(this, "destroyed", false);
|
546
584
|
const key = toBytes(_key);
|
547
585
|
this.iHash = hash.create();
|
548
586
|
if (typeof this.iHash.update !== "function")
|
@@ -578,7 +616,7 @@ var HMAC = class extends Hash {
|
|
578
616
|
return out;
|
579
617
|
}
|
580
618
|
_cloneInto(to) {
|
581
|
-
to
|
619
|
+
to || (to = Object.create(Object.getPrototypeOf(this), {}));
|
582
620
|
const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
|
583
621
|
to = to;
|
584
622
|
to.finished = finished;
|
@@ -637,7 +675,7 @@ function compressPublicKeyHex(s) {
|
|
637
675
|
return prefix + xHex;
|
638
676
|
}
|
639
677
|
function utf8ToHex(input) {
|
640
|
-
const bytes =
|
678
|
+
const bytes = strToU8(input);
|
641
679
|
return utils2.bytesToHex(bytes);
|
642
680
|
}
|
643
681
|
function leftPad(input, num) {
|
@@ -989,7 +1027,7 @@ __export(sm4_exports, {
|
|
989
1027
|
sm4: () => sm4
|
990
1028
|
});
|
991
1029
|
var import_polyval = require("@noble/ciphers/_polyval");
|
992
|
-
var
|
1030
|
+
var import_utils12 = require("@noble/ciphers/utils");
|
993
1031
|
var DECRYPT = 0;
|
994
1032
|
var ROUND = 32;
|
995
1033
|
var BLOCK = 16;
|
@@ -1401,8 +1439,8 @@ function sm4Gcm(inArray, key, ivArray, aadArray, cryptFlag, tagArray) {
|
|
1401
1439
|
const g = import_polyval.ghash.create(h2);
|
1402
1440
|
g.update(ivArray);
|
1403
1441
|
const lenIv = new Uint8Array(16);
|
1404
|
-
const view = (0,
|
1405
|
-
(0,
|
1442
|
+
const view = (0, import_utils12.createView)(lenIv);
|
1443
|
+
(0, import_utils12.setBigUint64)(view, 8, BigInt(ivArray.length * 8), false);
|
1406
1444
|
g.update(lenIv);
|
1407
1445
|
j02 = g.digest();
|
1408
1446
|
}
|
@@ -1421,9 +1459,9 @@ function sm4Gcm(inArray, key, ivArray, aadArray, cryptFlag, tagArray) {
|
|
1421
1459
|
}
|
1422
1460
|
g.update(data);
|
1423
1461
|
const lenBlock = new Uint8Array(16);
|
1424
|
-
const view = (0,
|
1425
|
-
(0,
|
1426
|
-
(0,
|
1462
|
+
const view = (0, import_utils12.createView)(lenBlock);
|
1463
|
+
(0, import_utils12.setBigUint64)(view, 0, BigInt(aadLength * 8), false);
|
1464
|
+
(0, import_utils12.setBigUint64)(view, 8, BigInt(dataLength * 8), false);
|
1427
1465
|
g.update(lenBlock);
|
1428
1466
|
return g.digest();
|
1429
1467
|
}
|
package/dist/index.mjs
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
var __defProp = Object.defineProperty;
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
2
3
|
var __export = (target, all) => {
|
3
4
|
for (var name in all)
|
4
5
|
__defProp(target, name, { get: all[name], enumerable: true });
|
5
6
|
};
|
7
|
+
var __publicField = (obj, key, value) => {
|
8
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
9
|
+
return value;
|
10
|
+
};
|
6
11
|
|
7
12
|
// src/sm2/index.ts
|
8
13
|
var sm2_exports = {};
|
@@ -112,11 +117,11 @@ var DEROctetString = class extends ASN1Object {
|
|
112
117
|
constructor(s) {
|
113
118
|
super();
|
114
119
|
this.s = s;
|
120
|
+
__publicField(this, "hV", "");
|
115
121
|
this.t = "04";
|
116
122
|
if (s)
|
117
123
|
this.v = s.toLowerCase();
|
118
124
|
}
|
119
|
-
hV = "";
|
120
125
|
getValue() {
|
121
126
|
return this.v;
|
122
127
|
}
|
@@ -125,8 +130,8 @@ var DERSequence = class extends ASN1Object {
|
|
125
130
|
constructor(asn1Array) {
|
126
131
|
super();
|
127
132
|
this.asn1Array = asn1Array;
|
133
|
+
__publicField(this, "t", "30");
|
128
134
|
}
|
129
|
-
t = "30";
|
130
135
|
getValue() {
|
131
136
|
this.v = this.asn1Array.map((asn1Object) => asn1Object.getEncodedHex()).join("");
|
132
137
|
return this.v;
|
@@ -271,7 +276,10 @@ var createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLengt
|
|
271
276
|
var isLE = new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68;
|
272
277
|
if (!isLE)
|
273
278
|
throw new Error("Non little-endian hardware is not supported");
|
274
|
-
var hexes = Array.from(
|
279
|
+
var hexes = Array.from(
|
280
|
+
{ length: 256 },
|
281
|
+
(v, i) => i.toString(16).padStart(2, "0")
|
282
|
+
);
|
275
283
|
function bytesToHex(bytes) {
|
276
284
|
if (!u8a(bytes))
|
277
285
|
throw new Error("Uint8Array expected");
|
@@ -281,14 +289,44 @@ function bytesToHex(bytes) {
|
|
281
289
|
}
|
282
290
|
return hex;
|
283
291
|
}
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
292
|
+
var te = typeof TextEncoder != "undefined" && /* @__PURE__ */ new TextEncoder();
|
293
|
+
var slc = (v, s, e) => {
|
294
|
+
if (s == null || s < 0)
|
295
|
+
s = 0;
|
296
|
+
if (e == null || e > v.length)
|
297
|
+
e = v.length;
|
298
|
+
return new Uint8Array(v.subarray(s, e));
|
299
|
+
};
|
300
|
+
function strToU8(str) {
|
301
|
+
if (te)
|
302
|
+
return te.encode(str);
|
303
|
+
const l = str.length;
|
304
|
+
let ar = new Uint8Array(str.length + (str.length >> 1));
|
305
|
+
let ai = 0;
|
306
|
+
const w = (v) => {
|
307
|
+
ar[ai++] = v;
|
308
|
+
};
|
309
|
+
for (let i = 0; i < l; ++i) {
|
310
|
+
if (ai + 5 > ar.length) {
|
311
|
+
const n = new Uint8Array(ai + 8 + (l - i << 1));
|
312
|
+
n.set(ar);
|
313
|
+
ar = n;
|
314
|
+
}
|
315
|
+
let c = str.charCodeAt(i);
|
316
|
+
if (c < 128)
|
317
|
+
w(c);
|
318
|
+
else if (c < 2048)
|
319
|
+
w(192 | c >> 6), w(128 | c & 63);
|
320
|
+
else if (c > 55295 && c < 57344)
|
321
|
+
c = 65536 + (c & 1023 << 10) | str.charCodeAt(++i) & 1023, w(240 | c >> 18), w(128 | c >> 12 & 63), w(128 | c >> 6 & 63), w(128 | c & 63);
|
322
|
+
else
|
323
|
+
w(224 | c >> 12), w(128 | c >> 6 & 63), w(128 | c & 63);
|
324
|
+
}
|
325
|
+
return slc(ar, 0, ai);
|
288
326
|
}
|
289
327
|
function toBytes(data) {
|
290
328
|
if (typeof data === "string")
|
291
|
-
data =
|
329
|
+
data = strToU8(data);
|
292
330
|
if (!u8a(data))
|
293
331
|
throw new Error(`expected Uint8Array, got ${typeof data}`);
|
294
332
|
return data;
|
@@ -341,16 +379,16 @@ var SHA2 = class extends Hash {
|
|
341
379
|
this.outputLen = outputLen;
|
342
380
|
this.padOffset = padOffset;
|
343
381
|
this.isLE = isLE2;
|
382
|
+
// For partial updates less than block size
|
383
|
+
__publicField(this, "buffer");
|
384
|
+
__publicField(this, "view");
|
385
|
+
__publicField(this, "finished", false);
|
386
|
+
__publicField(this, "length", 0);
|
387
|
+
__publicField(this, "pos", 0);
|
388
|
+
__publicField(this, "destroyed", false);
|
344
389
|
this.buffer = new Uint8Array(blockLen);
|
345
390
|
this.view = createView(this.buffer);
|
346
391
|
}
|
347
|
-
// For partial updates less than block size
|
348
|
-
buffer;
|
349
|
-
view;
|
350
|
-
finished = false;
|
351
|
-
length = 0;
|
352
|
-
pos = 0;
|
353
|
-
destroyed = false;
|
354
392
|
update(data) {
|
355
393
|
const { view, buffer, blockLen } = this;
|
356
394
|
data = toBytes(data);
|
@@ -408,7 +446,7 @@ var SHA2 = class extends Hash {
|
|
408
446
|
return res;
|
409
447
|
}
|
410
448
|
_cloneInto(to) {
|
411
|
-
to
|
449
|
+
to || (to = new this.constructor());
|
412
450
|
to.set(...this.get());
|
413
451
|
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
414
452
|
to.length = length;
|
@@ -426,18 +464,18 @@ var SM3_M = new Uint32Array(64);
|
|
426
464
|
var T1 = 2043430169;
|
427
465
|
var T2 = 2055708042;
|
428
466
|
var SM3 = class extends SHA2 {
|
429
|
-
// We cannot use array here since array allows indexing by variable
|
430
|
-
// which means optimizer/compiler cannot use registers.
|
431
|
-
A = IV[0] | 0;
|
432
|
-
B = IV[1] | 0;
|
433
|
-
C = IV[2] | 0;
|
434
|
-
D = IV[3] | 0;
|
435
|
-
E = IV[4] | 0;
|
436
|
-
F = IV[5] | 0;
|
437
|
-
G = IV[6] | 0;
|
438
|
-
H = IV[7] | 0;
|
439
467
|
constructor() {
|
440
468
|
super(64, 32, 8, false);
|
469
|
+
// We cannot use array here since array allows indexing by variable
|
470
|
+
// which means optimizer/compiler cannot use registers.
|
471
|
+
__publicField(this, "A", IV[0] | 0);
|
472
|
+
__publicField(this, "B", IV[1] | 0);
|
473
|
+
__publicField(this, "C", IV[2] | 0);
|
474
|
+
__publicField(this, "D", IV[3] | 0);
|
475
|
+
__publicField(this, "E", IV[4] | 0);
|
476
|
+
__publicField(this, "F", IV[5] | 0);
|
477
|
+
__publicField(this, "G", IV[6] | 0);
|
478
|
+
__publicField(this, "H", IV[7] | 0);
|
441
479
|
}
|
442
480
|
get() {
|
443
481
|
const { A, B, C, D, E, F, G, H } = this;
|
@@ -502,14 +540,14 @@ var sm3 = wrapConstructor(() => new SM3());
|
|
502
540
|
|
503
541
|
// src/sm2/hmac.ts
|
504
542
|
var HMAC = class extends Hash {
|
505
|
-
oHash;
|
506
|
-
iHash;
|
507
|
-
blockLen;
|
508
|
-
outputLen;
|
509
|
-
finished = false;
|
510
|
-
destroyed = false;
|
511
543
|
constructor(hash, _key) {
|
512
544
|
super();
|
545
|
+
__publicField(this, "oHash");
|
546
|
+
__publicField(this, "iHash");
|
547
|
+
__publicField(this, "blockLen");
|
548
|
+
__publicField(this, "outputLen");
|
549
|
+
__publicField(this, "finished", false);
|
550
|
+
__publicField(this, "destroyed", false);
|
513
551
|
const key = toBytes(_key);
|
514
552
|
this.iHash = hash.create();
|
515
553
|
if (typeof this.iHash.update !== "function")
|
@@ -545,7 +583,7 @@ var HMAC = class extends Hash {
|
|
545
583
|
return out;
|
546
584
|
}
|
547
585
|
_cloneInto(to) {
|
548
|
-
to
|
586
|
+
to || (to = Object.create(Object.getPrototypeOf(this), {}));
|
549
587
|
const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
|
550
588
|
to = to;
|
551
589
|
to.finished = finished;
|
@@ -604,7 +642,7 @@ function compressPublicKeyHex(s) {
|
|
604
642
|
return prefix + xHex;
|
605
643
|
}
|
606
644
|
function utf8ToHex(input) {
|
607
|
-
const bytes =
|
645
|
+
const bytes = strToU8(input);
|
608
646
|
return utils2.bytesToHex(bytes);
|
609
647
|
}
|
610
648
|
function leftPad(input, num) {
|
@@ -2499,12 +2499,36 @@ function bytesToHex2(bytes) {
|
|
2499
2499
|
}
|
2500
2500
|
return hex;
|
2501
2501
|
}
|
2502
|
-
|
2503
|
-
|
2504
|
-
|
2502
|
+
var te = typeof TextEncoder != "undefined" && /* @__PURE__ */ new TextEncoder();
|
2503
|
+
var slc = function(v, s, e) {
|
2504
|
+
if (s == null || s < 0) s = 0;
|
2505
|
+
if (e == null || e > v.length) e = v.length;
|
2506
|
+
return new Uint8Array(v.subarray(s, e));
|
2507
|
+
};
|
2508
|
+
function strToU8(str) {
|
2509
|
+
if (te) return te.encode(str);
|
2510
|
+
var l = str.length;
|
2511
|
+
var ar = new Uint8Array(str.length + (str.length >> 1));
|
2512
|
+
var ai = 0;
|
2513
|
+
var w = function(v) {
|
2514
|
+
ar[ai++] = v;
|
2515
|
+
};
|
2516
|
+
for(var i = 0; i < l; ++i){
|
2517
|
+
if (ai + 5 > ar.length) {
|
2518
|
+
var n = new Uint8Array(ai + 8 + (l - i << 1));
|
2519
|
+
n.set(ar);
|
2520
|
+
ar = n;
|
2521
|
+
}
|
2522
|
+
var c = str.charCodeAt(i);
|
2523
|
+
if (c < 128) w(c);
|
2524
|
+
else if (c < 2048) w(192 | c >> 6), w(128 | c & 63);
|
2525
|
+
else if (c > 55295 && c < 57344) c = 65536 + (c & 1023 << 10) | str.charCodeAt(++i) & 1023, w(240 | c >> 18), w(128 | c >> 12 & 63), w(128 | c >> 6 & 63), w(128 | c & 63);
|
2526
|
+
else w(224 | c >> 12), w(128 | c >> 6 & 63), w(128 | c & 63);
|
2527
|
+
}
|
2528
|
+
return slc(ar, 0, ai);
|
2505
2529
|
}
|
2506
2530
|
function toBytes(data) {
|
2507
|
-
if (typeof data === "string") data =
|
2531
|
+
if (typeof data === "string") data = strToU8(data);
|
2508
2532
|
if (!u8a2(data)) throw new Error("expected Uint8Array, got ".concat(typeof data === "undefined" ? "undefined" : _type_of(data)));
|
2509
2533
|
return data;
|
2510
2534
|
}
|
@@ -2918,7 +2942,7 @@ function compressPublicKeyHex(s) {
|
|
2918
2942
|
return prefix + xHex;
|
2919
2943
|
}
|
2920
2944
|
function utf8ToHex(input) {
|
2921
|
-
var bytes =
|
2945
|
+
var bytes = strToU8(input);
|
2922
2946
|
return bytesToHex(bytes);
|
2923
2947
|
}
|
2924
2948
|
function leftPad(input, num) {
|
@@ -3297,12 +3321,12 @@ var isLE2 = new Uint8Array(new Uint32Array([
|
|
3297
3321
|
287454020
|
3298
3322
|
]).buffer)[0] === 68;
|
3299
3323
|
if (!isLE2) throw new Error("Non little-endian hardware is not supported");
|
3300
|
-
function
|
3324
|
+
function utf8ToBytes2(str) {
|
3301
3325
|
if (typeof str !== "string") throw new Error("string expected");
|
3302
3326
|
return new Uint8Array(new TextEncoder().encode(str));
|
3303
3327
|
}
|
3304
3328
|
function toBytes2(data) {
|
3305
|
-
if (typeof data === "string") data =
|
3329
|
+
if (typeof data === "string") data = utf8ToBytes2(data);
|
3306
3330
|
else if (isBytes(data)) data = copyBytes(data);
|
3307
3331
|
else throw new Error("Uint8Array expected, got " + (typeof data === "undefined" ? "undefined" : _type_of(data)));
|
3308
3332
|
return data;
|