@noble/post-quantum 0.3.1 → 0.4.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/README.md +90 -64
- package/_crystals.d.ts +2 -1
- package/_crystals.d.ts.map +1 -1
- package/_crystals.js +3 -3
- package/_crystals.js.map +1 -1
- package/esm/_crystals.d.ts +2 -1
- package/esm/_crystals.d.ts.map +1 -1
- package/esm/_crystals.js +1 -1
- package/esm/_crystals.js.map +1 -1
- package/esm/ml-dsa.d.ts +1 -1
- package/esm/ml-dsa.d.ts.map +1 -1
- package/esm/ml-dsa.js +28 -16
- package/esm/ml-dsa.js.map +1 -1
- package/esm/ml-kem.d.ts.map +1 -1
- package/esm/ml-kem.js +3 -2
- package/esm/ml-kem.js.map +1 -1
- package/esm/slh-dsa.d.ts +4 -1
- package/esm/slh-dsa.d.ts.map +1 -1
- package/esm/slh-dsa.js +44 -15
- package/esm/slh-dsa.js.map +1 -1
- package/esm/utils.d.ts +4 -7
- package/esm/utils.d.ts.map +1 -1
- package/esm/utils.js +44 -2
- package/esm/utils.js.map +1 -1
- package/ml-dsa.d.ts +1 -1
- package/ml-dsa.d.ts.map +1 -1
- package/ml-dsa.js +49 -37
- package/ml-dsa.js.map +1 -1
- package/ml-kem.d.ts.map +1 -1
- package/ml-kem.js +26 -25
- package/ml-kem.js.map +1 -1
- package/package.json +34 -10
- package/slh-dsa.d.ts +4 -1
- package/slh-dsa.d.ts.map +1 -1
- package/slh-dsa.js +73 -34
- package/slh-dsa.js.map +1 -1
- package/src/_crystals.ts +2 -1
- package/src/ml-dsa.ts +30 -18
- package/src/ml-kem.ts +3 -2
- package/src/slh-dsa.ts +52 -16
- package/src/utils.ts +50 -1
- package/utils.d.ts +4 -7
- package/utils.d.ts.map +1 -1
- package/utils.js +47 -3
- package/utils.js.map +1 -1
package/src/slh-dsa.ts
CHANGED
@@ -27,20 +27,24 @@
|
|
27
27
|
* @module
|
28
28
|
*/
|
29
29
|
/*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */
|
30
|
+
import { setBigUint64 } from '@noble/hashes/_md';
|
30
31
|
import { HMAC } from '@noble/hashes/hmac';
|
31
32
|
import { sha256, sha512 } from '@noble/hashes/sha2';
|
32
33
|
import { shake256 } from '@noble/hashes/sha3';
|
33
34
|
import { bytesToHex, concatBytes, createView, hexToBytes } from '@noble/hashes/utils';
|
34
35
|
import {
|
36
|
+
EMPTY,
|
35
37
|
type Signer,
|
36
38
|
cleanBytes,
|
37
39
|
ensureBytes,
|
38
40
|
equalBytes,
|
39
41
|
getMask,
|
42
|
+
getMessage,
|
43
|
+
getMessagePrehash,
|
40
44
|
randomBytes,
|
41
45
|
splitCoder,
|
42
46
|
vecCoder,
|
43
|
-
} from './utils.
|
47
|
+
} from './utils.ts';
|
44
48
|
|
45
49
|
/**
|
46
50
|
* * N: Security parameter (in bytes). W: Winternitz parameter
|
@@ -71,15 +75,15 @@ export const PARAMS: Record<string, SphincsOpts> = {
|
|
71
75
|
'256s': { W: 16, N: 32, H: 64, D: 8, K: 22, A: 14 },
|
72
76
|
} as const;
|
73
77
|
|
74
|
-
const
|
75
|
-
WOTS,
|
76
|
-
WOTSPK,
|
77
|
-
HASHTREE,
|
78
|
-
FORSTREE,
|
79
|
-
FORSPK,
|
80
|
-
WOTSPRF,
|
81
|
-
FORSPRF,
|
82
|
-
}
|
78
|
+
const AddressType = {
|
79
|
+
WOTS: 0,
|
80
|
+
WOTSPK: 1,
|
81
|
+
HASHTREE: 2,
|
82
|
+
FORSTREE: 3,
|
83
|
+
FORSPK: 4,
|
84
|
+
WOTSPRF: 5,
|
85
|
+
FORSPRF: 6,
|
86
|
+
} as const;
|
83
87
|
|
84
88
|
/** Address, byte array of size ADDR_BYTES */
|
85
89
|
export type ADRS = Uint8Array;
|
@@ -131,7 +135,10 @@ function getMaskBig(bits: number) {
|
|
131
135
|
return (1n << BigInt(bits)) - 1n; // 4 -> 0b1111
|
132
136
|
}
|
133
137
|
|
134
|
-
export type SphincsSigner = Signer & { seedLen: number }
|
138
|
+
export type SphincsSigner = Signer & { seedLen: number } & {
|
139
|
+
internal: Signer;
|
140
|
+
prehash: (hashName: string) => Signer;
|
141
|
+
};
|
135
142
|
|
136
143
|
function gen(opts: SphincsOpts, hashOpts: SphincsHashOpts): SphincsSigner {
|
137
144
|
const { N, W, H, D, K, A } = opts;
|
@@ -166,7 +173,7 @@ function gen(opts: SphincsOpts, hashOpts: SphincsHashOpts): SphincsSigner {
|
|
166
173
|
|
167
174
|
const setAddr = (
|
168
175
|
opts: {
|
169
|
-
type?: AddressType;
|
176
|
+
type?: (typeof AddressType)[keyof typeof AddressType];
|
170
177
|
height?: number;
|
171
178
|
tree?: bigint;
|
172
179
|
index?: number;
|
@@ -190,7 +197,7 @@ function gen(opts: SphincsOpts, hashOpts: SphincsHashOpts): SphincsSigner {
|
|
190
197
|
if (hash !== undefined) addr[OFFSET_HASH_ADDR] = hash;
|
191
198
|
if (index !== undefined) v.setUint32(OFFSET_TREE_INDEX, index, false);
|
192
199
|
if (subtreeAddr) addr.set(subtreeAddr.subarray(0, OFFSET_TREE + 8));
|
193
|
-
if (tree !== undefined)
|
200
|
+
if (tree !== undefined) setBigUint64(v, OFFSET_TREE, tree, false);
|
194
201
|
if (keypair !== undefined) {
|
195
202
|
addr[OFFSET_KP_ADDR1] = keypair;
|
196
203
|
if (TREE_HEIGHT > 8) addr[OFFSET_KP_ADDR2] = keypair >>> 8;
|
@@ -373,10 +380,10 @@ function gen(opts: SphincsOpts, hashOpts: SphincsHashOpts): SphincsSigner {
|
|
373
380
|
const forsCoder = vecCoder(splitCoder(N, N * A), K);
|
374
381
|
const wotsCoder = vecCoder(splitCoder(WOTS_LEN * N, TREE_HEIGHT * N), D);
|
375
382
|
const sigCoder = splitCoder(N, forsCoder, wotsCoder); // random || fors || wots
|
376
|
-
|
377
|
-
seedLen: seedCoder.bytesLen,
|
383
|
+
const internal: Signer = {
|
378
384
|
signRandBytes: N,
|
379
|
-
keygen(seed
|
385
|
+
keygen(seed?: Uint8Array) {
|
386
|
+
seed = seed === undefined ? randomBytes(seedCoder.bytesLen) : seed.slice();
|
380
387
|
// Set SK.seed, SK.prf, and PK.seed to random n-byte
|
381
388
|
const [secretSeed, secretPRF, publicSeed] = seedCoder.decode(seed);
|
382
389
|
const context = getContext(publicSeed, secretSeed);
|
@@ -520,6 +527,35 @@ function gen(opts: SphincsOpts, hashOpts: SphincsHashOpts): SphincsSigner {
|
|
520
527
|
return equalBytes(root, pubRoot);
|
521
528
|
},
|
522
529
|
};
|
530
|
+
return {
|
531
|
+
internal,
|
532
|
+
seedLen: seedCoder.bytesLen,
|
533
|
+
keygen: internal.keygen,
|
534
|
+
signRandBytes: internal.signRandBytes,
|
535
|
+
sign: (secretKey: Uint8Array, msg: Uint8Array, ctx = EMPTY, random?: Uint8Array) => {
|
536
|
+
const M = getMessage(msg, ctx);
|
537
|
+
const res = internal.sign(secretKey, M, random);
|
538
|
+
M.fill(0);
|
539
|
+
return res;
|
540
|
+
},
|
541
|
+
verify: (publicKey: Uint8Array, msg: Uint8Array, sig: Uint8Array, ctx = EMPTY) => {
|
542
|
+
return internal.verify(publicKey, getMessage(msg, ctx), sig);
|
543
|
+
},
|
544
|
+
prehash: (hashName: string) => ({
|
545
|
+
seedLen: seedCoder.bytesLen,
|
546
|
+
keygen: internal.keygen,
|
547
|
+
signRandBytes: internal.signRandBytes,
|
548
|
+
sign: (secretKey: Uint8Array, msg: Uint8Array, ctx = EMPTY, random?: Uint8Array) => {
|
549
|
+
const M = getMessagePrehash(hashName, msg, ctx);
|
550
|
+
const res = internal.sign(secretKey, M, random);
|
551
|
+
M.fill(0);
|
552
|
+
return res;
|
553
|
+
},
|
554
|
+
verify: (publicKey: Uint8Array, msg: Uint8Array, sig: Uint8Array, ctx = EMPTY) => {
|
555
|
+
return internal.verify(publicKey, getMessagePrehash(hashName, msg, ctx), sig);
|
556
|
+
},
|
557
|
+
}),
|
558
|
+
};
|
523
559
|
}
|
524
560
|
|
525
561
|
const genShake =
|
package/src/utils.ts
CHANGED
@@ -3,10 +3,13 @@
|
|
3
3
|
* @module
|
4
4
|
*/
|
5
5
|
/*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */
|
6
|
-
import {
|
6
|
+
import { sha224, sha256, sha384, sha512, sha512_224, sha512_256 } from '@noble/hashes/sha2';
|
7
|
+
import { sha3_224, sha3_256, sha3_384, sha3_512, shake128, shake256 } from '@noble/hashes/sha3';
|
7
8
|
import {
|
8
9
|
type TypedArray,
|
10
|
+
abytes,
|
9
11
|
concatBytes,
|
12
|
+
hexToBytes,
|
10
13
|
randomBytes as randb,
|
11
14
|
utf8ToBytes,
|
12
15
|
} from '@noble/hashes/utils';
|
@@ -122,3 +125,49 @@ export function cleanBytes(...list: (TypedArray | TypedArray[])[]): void {
|
|
122
125
|
export function getMask(bits: number): number {
|
123
126
|
return (1 << bits) - 1; // 4 -> 0b1111
|
124
127
|
}
|
128
|
+
|
129
|
+
export const EMPTY: Uint8Array = new Uint8Array(0);
|
130
|
+
|
131
|
+
export function getMessage(msg: Uint8Array, ctx: Uint8Array = EMPTY): Uint8Array {
|
132
|
+
ensureBytes(msg);
|
133
|
+
ensureBytes(ctx);
|
134
|
+
if (ctx.length > 255) throw new Error('context should be less than 255 bytes');
|
135
|
+
return concatBytes(new Uint8Array([0, ctx.length]), ctx, msg);
|
136
|
+
}
|
137
|
+
|
138
|
+
// OIDS from https://csrc.nist.gov/projects/computer-security-objects-register/algorithm-registration
|
139
|
+
// TODO: maybe add 'OID' property to hashes themselves to improve tree-shaking?
|
140
|
+
const HASHES: Record<string, { oid: Uint8Array; hash: (msg: Uint8Array) => Uint8Array }> = {
|
141
|
+
'SHA2-256': { oid: hexToBytes('0609608648016503040201'), hash: sha256 },
|
142
|
+
'SHA2-384': { oid: hexToBytes('0609608648016503040202'), hash: sha384 },
|
143
|
+
'SHA2-512': { oid: hexToBytes('0609608648016503040203'), hash: sha512 },
|
144
|
+
'SHA2-224': { oid: hexToBytes('0609608648016503040204'), hash: sha224 },
|
145
|
+
'SHA2-512/224': { oid: hexToBytes('0609608648016503040205'), hash: sha512_224 },
|
146
|
+
'SHA2-512/256': { oid: hexToBytes('0609608648016503040206'), hash: sha512_256 },
|
147
|
+
'SHA3-224': { oid: hexToBytes('0609608648016503040207'), hash: sha3_224 },
|
148
|
+
'SHA3-256': { oid: hexToBytes('0609608648016503040208'), hash: sha3_256 },
|
149
|
+
'SHA3-384': { oid: hexToBytes('0609608648016503040209'), hash: sha3_384 },
|
150
|
+
'SHA3-512': { oid: hexToBytes('060960864801650304020A'), hash: sha3_512 },
|
151
|
+
'SHAKE-128': {
|
152
|
+
oid: hexToBytes('060960864801650304020B'),
|
153
|
+
hash: (msg) => shake128(msg, { dkLen: 32 }),
|
154
|
+
},
|
155
|
+
'SHAKE-256': {
|
156
|
+
oid: hexToBytes('060960864801650304020C'),
|
157
|
+
hash: (msg) => shake256(msg, { dkLen: 64 }),
|
158
|
+
},
|
159
|
+
};
|
160
|
+
|
161
|
+
export function getMessagePrehash(
|
162
|
+
hashName: string,
|
163
|
+
msg: Uint8Array,
|
164
|
+
ctx: Uint8Array = EMPTY
|
165
|
+
): Uint8Array {
|
166
|
+
ensureBytes(msg);
|
167
|
+
ensureBytes(ctx);
|
168
|
+
if (ctx.length > 255) throw new Error('context should be less than 255 bytes');
|
169
|
+
if (!HASHES[hashName]) throw new Error('unknown hash: ' + hashName);
|
170
|
+
const { oid, hash } = HASHES[hashName];
|
171
|
+
const hashed = hash(msg);
|
172
|
+
return concatBytes(new Uint8Array([1, ctx.length]), ctx, oid, hashed);
|
173
|
+
}
|
package/utils.d.ts
CHANGED
@@ -1,10 +1,4 @@
|
|
1
|
-
|
2
|
-
* Utilities for hex, bytearray and number handling.
|
3
|
-
* @module
|
4
|
-
*/
|
5
|
-
/*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */
|
6
|
-
import { abytes } from '@noble/hashes/_assert';
|
7
|
-
import { type TypedArray, concatBytes, randomBytes as randb, utf8ToBytes } from '@noble/hashes/utils';
|
1
|
+
import { type TypedArray, abytes, concatBytes, randomBytes as randb, utf8ToBytes } from '@noble/hashes/utils';
|
8
2
|
export declare const ensureBytes: typeof abytes;
|
9
3
|
export declare const randomBytes: typeof randb;
|
10
4
|
export { concatBytes, utf8ToBytes };
|
@@ -40,4 +34,7 @@ export declare function splitCoder<T extends (number | BytesCoderLen<any>)[]>(..
|
|
40
34
|
export declare function vecCoder<T>(c: BytesCoderLen<T>, vecLen: number): BytesCoderLen<T[]>;
|
41
35
|
export declare function cleanBytes(...list: (TypedArray | TypedArray[])[]): void;
|
42
36
|
export declare function getMask(bits: number): number;
|
37
|
+
export declare const EMPTY: Uint8Array;
|
38
|
+
export declare function getMessage(msg: Uint8Array, ctx?: Uint8Array): Uint8Array;
|
39
|
+
export declare function getMessagePrehash(hashName: string, msg: Uint8Array, ctx?: Uint8Array): Uint8Array;
|
43
40
|
//# sourceMappingURL=utils.d.ts.map
|
package/utils.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["src/utils.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["src/utils.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,UAAU,EACf,MAAM,EACN,WAAW,EAEX,WAAW,IAAI,KAAK,EACpB,WAAW,EACZ,MAAM,qBAAqB,CAAC;AAE7B,eAAO,MAAM,WAAW,EAAE,OAAO,MAAe,CAAC;AACjD,eAAO,MAAM,WAAW,EAAE,OAAO,KAAa,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC;AAGpC,wBAAgB,UAAU,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE,UAAU,GAAG,OAAO,CAKhE;AAED,qEAAqE;AACrE,MAAM,MAAM,MAAM,GAAG;IACnB,aAAa,EAAE,MAA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AC,SAAS,CAAC,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,EAAE,EAClE,GAAG,OAAO,EAAE,CAAC,GACZ,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CA8BhD;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CAAC,CAAC,EAAE,CAAC,CAwBnF;AAGD,wBAAgB,UAAU,CAAC,GAAG,IAAI,EAAE,CAAC,UAAU,GAAG,UAAU,EAAE,CAAC,EAAE,GAAG,IAAI,CAKvE;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE5C;AAED,eAAO,MAAM,KAAK,EAAE,UAA8B,CAAC;AAEnD,wBAAgB,UAAU,CAAC,GAAG,EAAE,UAAU,EAAE,GAAG,GAAE,UAAkB,GAAG,UAAU,CAK/E;AAyBD,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,UAAU,EACf,GAAG,GAAE,UAAkB,GACtB,UAAU,CAQZ"}
|
package/utils.js
CHANGED
@@ -1,21 +1,24 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.utf8ToBytes = exports.concatBytes = exports.randomBytes = exports.ensureBytes = void 0;
|
3
|
+
exports.EMPTY = exports.utf8ToBytes = exports.concatBytes = exports.randomBytes = exports.ensureBytes = void 0;
|
4
4
|
exports.equalBytes = equalBytes;
|
5
5
|
exports.splitCoder = splitCoder;
|
6
6
|
exports.vecCoder = vecCoder;
|
7
7
|
exports.cleanBytes = cleanBytes;
|
8
8
|
exports.getMask = getMask;
|
9
|
+
exports.getMessage = getMessage;
|
10
|
+
exports.getMessagePrehash = getMessagePrehash;
|
9
11
|
/**
|
10
12
|
* Utilities for hex, bytearray and number handling.
|
11
13
|
* @module
|
12
14
|
*/
|
13
15
|
/*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */
|
14
|
-
const
|
16
|
+
const sha2_1 = require("@noble/hashes/sha2");
|
17
|
+
const sha3_1 = require("@noble/hashes/sha3");
|
15
18
|
const utils_1 = require("@noble/hashes/utils");
|
16
19
|
Object.defineProperty(exports, "concatBytes", { enumerable: true, get: function () { return utils_1.concatBytes; } });
|
17
20
|
Object.defineProperty(exports, "utf8ToBytes", { enumerable: true, get: function () { return utils_1.utf8ToBytes; } });
|
18
|
-
exports.ensureBytes =
|
21
|
+
exports.ensureBytes = utils_1.abytes;
|
19
22
|
exports.randomBytes = utils_1.randomBytes;
|
20
23
|
// Compares 2 u8a-s in kinda constant time
|
21
24
|
function equalBytes(a, b) {
|
@@ -97,4 +100,45 @@ function cleanBytes(...list) {
|
|
97
100
|
function getMask(bits) {
|
98
101
|
return (1 << bits) - 1; // 4 -> 0b1111
|
99
102
|
}
|
103
|
+
exports.EMPTY = new Uint8Array(0);
|
104
|
+
function getMessage(msg, ctx = exports.EMPTY) {
|
105
|
+
(0, exports.ensureBytes)(msg);
|
106
|
+
(0, exports.ensureBytes)(ctx);
|
107
|
+
if (ctx.length > 255)
|
108
|
+
throw new Error('context should be less than 255 bytes');
|
109
|
+
return (0, utils_1.concatBytes)(new Uint8Array([0, ctx.length]), ctx, msg);
|
110
|
+
}
|
111
|
+
// OIDS from https://csrc.nist.gov/projects/computer-security-objects-register/algorithm-registration
|
112
|
+
// TODO: maybe add 'OID' property to hashes themselves to improve tree-shaking?
|
113
|
+
const HASHES = {
|
114
|
+
'SHA2-256': { oid: (0, utils_1.hexToBytes)('0609608648016503040201'), hash: sha2_1.sha256 },
|
115
|
+
'SHA2-384': { oid: (0, utils_1.hexToBytes)('0609608648016503040202'), hash: sha2_1.sha384 },
|
116
|
+
'SHA2-512': { oid: (0, utils_1.hexToBytes)('0609608648016503040203'), hash: sha2_1.sha512 },
|
117
|
+
'SHA2-224': { oid: (0, utils_1.hexToBytes)('0609608648016503040204'), hash: sha2_1.sha224 },
|
118
|
+
'SHA2-512/224': { oid: (0, utils_1.hexToBytes)('0609608648016503040205'), hash: sha2_1.sha512_224 },
|
119
|
+
'SHA2-512/256': { oid: (0, utils_1.hexToBytes)('0609608648016503040206'), hash: sha2_1.sha512_256 },
|
120
|
+
'SHA3-224': { oid: (0, utils_1.hexToBytes)('0609608648016503040207'), hash: sha3_1.sha3_224 },
|
121
|
+
'SHA3-256': { oid: (0, utils_1.hexToBytes)('0609608648016503040208'), hash: sha3_1.sha3_256 },
|
122
|
+
'SHA3-384': { oid: (0, utils_1.hexToBytes)('0609608648016503040209'), hash: sha3_1.sha3_384 },
|
123
|
+
'SHA3-512': { oid: (0, utils_1.hexToBytes)('060960864801650304020A'), hash: sha3_1.sha3_512 },
|
124
|
+
'SHAKE-128': {
|
125
|
+
oid: (0, utils_1.hexToBytes)('060960864801650304020B'),
|
126
|
+
hash: (msg) => (0, sha3_1.shake128)(msg, { dkLen: 32 }),
|
127
|
+
},
|
128
|
+
'SHAKE-256': {
|
129
|
+
oid: (0, utils_1.hexToBytes)('060960864801650304020C'),
|
130
|
+
hash: (msg) => (0, sha3_1.shake256)(msg, { dkLen: 64 }),
|
131
|
+
},
|
132
|
+
};
|
133
|
+
function getMessagePrehash(hashName, msg, ctx = exports.EMPTY) {
|
134
|
+
(0, exports.ensureBytes)(msg);
|
135
|
+
(0, exports.ensureBytes)(ctx);
|
136
|
+
if (ctx.length > 255)
|
137
|
+
throw new Error('context should be less than 255 bytes');
|
138
|
+
if (!HASHES[hashName])
|
139
|
+
throw new Error('unknown hash: ' + hashName);
|
140
|
+
const { oid, hash } = HASHES[hashName];
|
141
|
+
const hashed = hash(msg);
|
142
|
+
return (0, utils_1.concatBytes)(new Uint8Array([1, ctx.length]), ctx, oid, hashed);
|
143
|
+
}
|
100
144
|
//# sourceMappingURL=utils.js.map
|
package/utils.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["src/utils.ts"],"names":[],"mappings":";;;
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["src/utils.ts"],"names":[],"mappings":";;;AAqBA,gCAKC;AA8BD,gCAgCC;AAED,4BAwBC;AAGD,gCAKC;AAED,0BAEC;AAID,gCAKC;AAyBD,8CAYC;AA5KD;;;GAGG;AACH,4EAA4E;AAC5E,6CAA4F;AAC5F,6CAAgG;AAChG,+CAO6B;AAIpB,4FARP,mBAAW,OAQO;AAAE,4FALpB,mBAAW,OAKoB;AAFpB,QAAA,WAAW,GAAkB,cAAM,CAAC;AACpC,QAAA,WAAW,GAAiB,mBAAK,CAAC;AAG/C,0CAA0C;AAC1C,SAAgB,UAAU,CAAC,CAAa,EAAE,CAAa;IACrD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IACxC,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;IACvD,OAAO,IAAI,KAAK,CAAC,CAAC;AACpB,CAAC;AA8BD,SAAgB,UAAU,CACxB,GAAG,OAAU;IAEb,MAAM,SAAS,GAAG,CAAC,CAA8B,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;IAC/F,MAAM,QAAQ,GAAW,OAAO,CAAC,MAAM,CAAC,CAAC,GAAW,EAAE,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACnF,OAAO;QACL,QAAQ;QACR,MAAM,EAAE,C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