@noble/post-quantum 0.2.0 → 0.3.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/README.md +70 -80
- package/_crystals.d.ts.map +1 -1
- package/_crystals.js +4 -0
- package/_crystals.js.map +1 -1
- package/esm/_crystals.d.ts.map +1 -1
- package/esm/_crystals.js +4 -0
- package/esm/_crystals.js.map +1 -1
- package/esm/index.js +6 -1
- package/esm/index.js.map +1 -1
- package/esm/ml-dsa.d.ts +14 -6
- package/esm/ml-dsa.d.ts.map +1 -1
- package/esm/ml-dsa.js +47 -14
- package/esm/ml-dsa.js.map +1 -1
- package/esm/ml-kem.d.ts +20 -41
- package/esm/ml-kem.d.ts.map +1 -1
- package/esm/ml-kem.js +25 -24
- package/esm/ml-kem.js.map +1 -1
- package/esm/slh-dsa.d.ts +16 -3
- package/esm/slh-dsa.d.ts.map +1 -1
- package/esm/slh-dsa.js +42 -4
- package/esm/slh-dsa.js.map +1 -1
- package/esm/utils.d.ts +7 -3
- package/esm/utils.d.ts.map +1 -1
- package/esm/utils.js +7 -2
- package/esm/utils.js.map +1 -1
- package/index.js +6 -1
- package/index.js.map +1 -1
- package/ml-dsa.d.ts +14 -6
- package/ml-dsa.d.ts.map +1 -1
- package/ml-dsa.js +46 -13
- package/ml-dsa.js.map +1 -1
- package/ml-kem.d.ts +20 -41
- package/ml-kem.d.ts.map +1 -1
- package/ml-kem.js +25 -24
- package/ml-kem.js.map +1 -1
- package/package.json +12 -11
- package/slh-dsa.d.ts +16 -3
- package/slh-dsa.d.ts.map +1 -1
- package/slh-dsa.js +42 -4
- package/slh-dsa.js.map +1 -1
- package/src/_crystals.ts +18 -3
- package/src/index.ts +6 -1
- package/src/ml-dsa.ts +63 -20
- package/src/ml-kem.ts +51 -31
- package/src/slh-dsa.ts +57 -47
- package/src/utils.ts +12 -7
- package/utils.d.ts +7 -3
- package/utils.d.ts.map +1 -1
- package/utils.js +8 -2
- package/utils.js.map +1 -1
package/src/ml-kem.ts
CHANGED
@@ -1,3 +1,24 @@
|
|
1
|
+
/**
|
2
|
+
* Module Lattice-based Key Encapsulation Mechanism (ML-KEM). A.k.a. CRYSTALS-Kyber.
|
3
|
+
* FIPS-203 is implemented.
|
4
|
+
*
|
5
|
+
* Key encapsulation is similar to DH / ECDH (think X25519), with important differences:
|
6
|
+
* * Unlike in ECDH, we can't verify if it was "Bob" who've sent the shared secret
|
7
|
+
* * Unlike ECDH, it is probabalistic and relies on quality of randomness (CSPRNG).
|
8
|
+
* * Decapsulation never throws an error, even when shared secret was
|
9
|
+
* encrypted by a different public key. It will just return a different shared secret.
|
10
|
+
*
|
11
|
+
* There are some concerns with regards to security: see
|
12
|
+
* [djb blog](https://blog.cr.yp.to/20231003-countcorrectly.html) and
|
13
|
+
* [mailing list](https://groups.google.com/a/list.nist.gov/g/pqc-forum/c/W2VOzy0wz_E).
|
14
|
+
*
|
15
|
+
* Has similar internals to ML-DSA, but their keys and params are different.
|
16
|
+
*
|
17
|
+
* Check out [official site](https://www.pq-crystals.org/kyber/resources.shtml),
|
18
|
+
* [repo](https://github.com/pq-crystals/kyber),
|
19
|
+
* [spec](https://datatracker.ietf.org/doc/draft-cfrg-schwabe-kyber/).
|
20
|
+
* @module
|
21
|
+
*/
|
1
22
|
/*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */
|
2
23
|
import { sha3_256, sha3_512, shake256 } from '@noble/hashes/sha3';
|
3
24
|
import { u32, wrapConstructor, wrapConstructorWithOpts } from '@noble/hashes/utils';
|
@@ -12,27 +33,23 @@ import {
|
|
12
33
|
vecCoder,
|
13
34
|
} from './utils.js';
|
14
35
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
[djb blog](https://blog.cr.yp.to/20231003-countcorrectly.html) and
|
33
|
-
[mailing list](https://groups.google.com/a/list.nist.gov/g/pqc-forum/c/W2VOzy0wz_E).
|
34
|
-
|
35
|
-
*/
|
36
|
+
/** Key encapsulation mechanism interface */
|
37
|
+
export type KEM = {
|
38
|
+
publicKeyLen: number;
|
39
|
+
msgLen: number;
|
40
|
+
keygen: (seed?: Uint8Array) => {
|
41
|
+
publicKey: Uint8Array;
|
42
|
+
secretKey: Uint8Array;
|
43
|
+
};
|
44
|
+
encapsulate: (
|
45
|
+
publicKey: Uint8Array,
|
46
|
+
msg?: Uint8Array
|
47
|
+
) => {
|
48
|
+
cipherText: Uint8Array;
|
49
|
+
sharedSecret: Uint8Array;
|
50
|
+
};
|
51
|
+
decapsulate: (cipherText: Uint8Array, secretKey: Uint8Array) => Uint8Array;
|
52
|
+
};
|
36
53
|
|
37
54
|
const N = 256; // Kyber (not FIPS-203) supports different lengths, but all std modes were using 256
|
38
55
|
const Q = 3329; // 13*(2**8)+1, modulo prime
|
@@ -48,8 +65,8 @@ const { mod, nttZetas, NTT, bitsCoder } = genCrystals({
|
|
48
65
|
isKyber: true,
|
49
66
|
});
|
50
67
|
|
51
|
-
|
52
|
-
type
|
68
|
+
/** FIPS 203: 7. Parameter Sets */
|
69
|
+
export type KEMParam = {
|
53
70
|
N: number;
|
54
71
|
K: number;
|
55
72
|
Q: number;
|
@@ -59,8 +76,9 @@ type ParameterSet = {
|
|
59
76
|
dv: number;
|
60
77
|
RBGstrength: number;
|
61
78
|
};
|
79
|
+
/** Internal params of ML-KEM versions */
|
62
80
|
// prettier-ignore
|
63
|
-
export const PARAMS: Record<string,
|
81
|
+
export const PARAMS: Record<string, KEMParam> = {
|
64
82
|
512: { N, Q, K: 2, ETA1: 3, ETA2: 2, du: 10, dv: 4, RBGstrength: 128 },
|
65
83
|
768: { N, Q, K: 3, ETA1: 2, ETA2: 2, du: 10, dv: 4, RBGstrength: 192 },
|
66
84
|
1024:{ N, Q, K: 4, ETA1: 2, ETA2: 2, du: 11, dv: 5, RBGstrength: 256 },
|
@@ -123,7 +141,7 @@ type Hash = ReturnType<typeof wrapConstructor>;
|
|
123
141
|
type HashWOpts = ReturnType<typeof wrapConstructorWithOpts>;
|
124
142
|
type XofGet = ReturnType<ReturnType<XOF>['get']>;
|
125
143
|
|
126
|
-
type KyberOpts =
|
144
|
+
type KyberOpts = KEMParam & {
|
127
145
|
HASH256: Hash;
|
128
146
|
HASH512: Hash;
|
129
147
|
KDF: Hash | HashWOpts;
|
@@ -327,18 +345,20 @@ const opts = {
|
|
327
345
|
PRF: shakePRF,
|
328
346
|
};
|
329
347
|
|
330
|
-
/**
|
331
|
-
|
332
|
-
*/
|
333
|
-
export const ml_kem512 = /* @__PURE__ */ createKyber({
|
348
|
+
/** ML-KEM-512 for 128-bit security level. As per ASD, not recommended after 2030. */
|
349
|
+
export const ml_kem512: KEM = /* @__PURE__ */ createKyber({
|
334
350
|
...opts,
|
335
351
|
...PARAMS[512],
|
336
352
|
});
|
337
|
-
|
353
|
+
|
354
|
+
/** ML-KEM-768, for 192-bit security level. As per ASD, not recommended after 2030. */
|
355
|
+
export const ml_kem768: KEM = /* @__PURE__ */ createKyber({
|
338
356
|
...opts,
|
339
357
|
...PARAMS[768],
|
340
358
|
});
|
341
|
-
|
359
|
+
|
360
|
+
/** ML-KEM-1024 for 256-bit security level. As per ASD, OK after 2030. */
|
361
|
+
export const ml_kem1024: KEM = /* @__PURE__ */ createKyber({
|
342
362
|
...opts,
|
343
363
|
...PARAMS[1024],
|
344
364
|
});
|
package/src/slh-dsa.ts
CHANGED
@@ -1,3 +1,31 @@
|
|
1
|
+
/**
|
2
|
+
* StateLess Hash-based Digital Signature Standard (SLH-DSA). A.k.a. Sphincs+.
|
3
|
+
* FIPS-205 (spec v3.1) is implemented.
|
4
|
+
*
|
5
|
+
* There are many different kinds of SLH, but basically `sha2` / `shake` indicate internal hash,
|
6
|
+
* `128` / `192` / `256` indicate security level, and `s` /`f` indicate trade-off (Small / Fast).
|
7
|
+
*
|
8
|
+
* Hashes function similarly to signatures. You hash a private key to get a public key,
|
9
|
+
* which can be used to verify the private key. However, this only works once since
|
10
|
+
* disclosing the pre-image invalidates the key.
|
11
|
+
*
|
12
|
+
* To address the "one-time" limitation, we can use a Merkle tree root hash:
|
13
|
+
* h(h(h(0) || h(1)) || h(h(2) || h(3))))
|
14
|
+
*
|
15
|
+
* This allows us to have the same public key output from the hash, but disclosing one
|
16
|
+
* path in the tree doesn't invalidate the others. By choosing a path related to the
|
17
|
+
* message, we can "sign" it.
|
18
|
+
*
|
19
|
+
* Limitation: Only a fixed number of signatures can be made. For instance, a Merkle tree
|
20
|
+
* with depth 8 allows 256 distinct messages. Using different trees for each node can
|
21
|
+
* prevent forgeries, but the key will still degrade over time.
|
22
|
+
*
|
23
|
+
* WOTS: One-time signatures (can be forged if same key used twice).
|
24
|
+
* FORS: Forest of Random Subsets
|
25
|
+
*
|
26
|
+
* Check out [official site](https://sphincs.org) & [repo](https://github.com/sphincs/sphincsplus).
|
27
|
+
* @module
|
28
|
+
*/
|
1
29
|
/*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */
|
2
30
|
import { HMAC } from '@noble/hashes/hmac';
|
3
31
|
import { sha256, sha512 } from '@noble/hashes/sha2';
|
@@ -14,35 +42,6 @@ import {
|
|
14
42
|
vecCoder,
|
15
43
|
} from './utils.js';
|
16
44
|
|
17
|
-
/*
|
18
|
-
Hash-based digital signature algorithm. See [official site](https://sphincs.org).
|
19
|
-
We implement spec v3.1 with latest FIPS-205 changes.
|
20
|
-
It's compatible with the latest version in the [official repo](https://github.com/sphincs/sphincsplus).
|
21
|
-
|
22
|
-
*/
|
23
|
-
|
24
|
-
/*
|
25
|
-
WOTS: One-time signatures (can be forged if same key used twice)
|
26
|
-
FORS: Forest of Random Subsets
|
27
|
-
|
28
|
-
Hashes are like signatures. You take private key, hash it, and share the result pubKey.
|
29
|
-
After that you can verify it was yours by also sharing the private key.
|
30
|
-
However, it will only work once: after pre-image was disclosed, it can't be used again.
|
31
|
-
It also doesn't sign the message: can be interceptd and message can be replaced.
|
32
|
-
|
33
|
-
How to solve "one-time" hashing? Instead of hash(k), we can provide merkle tree root hash:
|
34
|
-
|
35
|
-
h(h(h(0) || h(1)) || h(h(2) || h(3))))
|
36
|
-
|
37
|
-
Now, we have the same pubKey output of hash, but disclosing one path in tree doesn't
|
38
|
-
invalidate the others, since they are still unknown. By choosing path which is related
|
39
|
-
to the message, we can "sign" it.
|
40
|
-
|
41
|
-
There is a limitation: only a fixed amount of signatures can be made,
|
42
|
-
a merkle tree with depth: 8 would mean 2**8 (256) paths aka 256 distinct messages.
|
43
|
-
Attaching a different tree to each node will solve forgeries, but the key would still degrade.
|
44
|
-
*/
|
45
|
-
|
46
45
|
/**
|
47
46
|
* * N: Security parameter (in bytes). W: Winternitz parameter
|
48
47
|
* * H: Hypertree height. D: Hypertree layers
|
@@ -62,6 +61,7 @@ export type SphincsHashOpts = {
|
|
62
61
|
getContext: GetContext;
|
63
62
|
};
|
64
63
|
|
64
|
+
/** Winternitz signature params. */
|
65
65
|
export const PARAMS: Record<string, SphincsOpts> = {
|
66
66
|
'128f': { W: 16, N: 16, H: 66, D: 22, K: 33, A: 6 },
|
67
67
|
'128s': { W: 16, N: 16, H: 63, D: 7, K: 14, A: 12 },
|
@@ -81,9 +81,10 @@ const enum AddressType {
|
|
81
81
|
FORSPRF,
|
82
82
|
}
|
83
83
|
|
84
|
+
/** Address, byte array of size ADDR_BYTES */
|
84
85
|
export type ADRS = Uint8Array;
|
85
86
|
|
86
|
-
type Context = {
|
87
|
+
export type Context = {
|
87
88
|
PRFaddr: (addr: ADRS) => Uint8Array;
|
88
89
|
PRFmsg: (skPRF: Uint8Array, random: Uint8Array, msg: Uint8Array) => Uint8Array;
|
89
90
|
Hmsg: (R: Uint8Array, pk: Uint8Array, m: Uint8Array, outLen: number) => Uint8Array;
|
@@ -97,8 +98,7 @@ export type GetContext = (
|
|
97
98
|
|
98
99
|
function hexToNumber(hex: string): bigint {
|
99
100
|
if (typeof hex !== 'string') throw new Error('hex string expected, got ' + typeof hex);
|
100
|
-
// Big Endian
|
101
|
-
return BigInt(hex === '' ? '0' : `0x${hex}`);
|
101
|
+
return BigInt(hex === '' ? '0' : '0x' + hex); // Big Endian
|
102
102
|
}
|
103
103
|
|
104
104
|
// BE: Big Endian, LE: Little Endian
|
@@ -131,7 +131,7 @@ function getMaskBig(bits: number) {
|
|
131
131
|
return (1n << BigInt(bits)) - 1n; // 4 -> 0b1111
|
132
132
|
}
|
133
133
|
|
134
|
-
type SphincsSigner = Signer & { seedLen: number };
|
134
|
+
export type SphincsSigner = Signer & { seedLen: number };
|
135
135
|
|
136
136
|
function gen(opts: SphincsOpts, hashOpts: SphincsHashOpts): SphincsSigner {
|
137
137
|
const { N, W, H, D, K, A } = opts;
|
@@ -563,13 +563,18 @@ const genShake =
|
|
563
563
|
|
564
564
|
const SHAKE_SIMPLE = { getContext: genShake() };
|
565
565
|
|
566
|
-
|
567
|
-
export const slh_dsa_shake_128f = /* @__PURE__ */ gen(PARAMS['128f'], SHAKE_SIMPLE);
|
568
|
-
|
569
|
-
export const
|
570
|
-
|
571
|
-
export const
|
572
|
-
|
566
|
+
/** SLH-DSA: 128-bit fast SHAKE version. */
|
567
|
+
export const slh_dsa_shake_128f: SphincsSigner = /* @__PURE__ */ gen(PARAMS['128f'], SHAKE_SIMPLE);
|
568
|
+
/** SLH-DSA: 128-bit short SHAKE version. */
|
569
|
+
export const slh_dsa_shake_128s: SphincsSigner = /* @__PURE__ */ gen(PARAMS['128s'], SHAKE_SIMPLE);
|
570
|
+
/** SLH-DSA: 192-bit fast SHAKE version. */
|
571
|
+
export const slh_dsa_shake_192f: SphincsSigner = /* @__PURE__ */ gen(PARAMS['192f'], SHAKE_SIMPLE);
|
572
|
+
/** SLH-DSA: 192-bit short SHAKE version. */
|
573
|
+
export const slh_dsa_shake_192s: SphincsSigner = /* @__PURE__ */ gen(PARAMS['192s'], SHAKE_SIMPLE);
|
574
|
+
/** SLH-DSA: 256-bit fast SHAKE version. */
|
575
|
+
export const slh_dsa_shake_256f: SphincsSigner = /* @__PURE__ */ gen(PARAMS['256f'], SHAKE_SIMPLE);
|
576
|
+
/** SLH-DSA: 256-bit short SHAKE version. */
|
577
|
+
export const slh_dsa_shake_256s: SphincsSigner = /* @__PURE__ */ gen(PARAMS['256s'], SHAKE_SIMPLE);
|
573
578
|
|
574
579
|
type ShaType = typeof sha256 | typeof sha512;
|
575
580
|
const genSha =
|
@@ -669,10 +674,15 @@ const SHA512_SIMPLE = {
|
|
669
674
|
getContext: genSha(sha256, sha512),
|
670
675
|
};
|
671
676
|
|
672
|
-
|
673
|
-
export const slh_dsa_sha2_128f = /* @__PURE__ */ gen(PARAMS['128f'], SHA256_SIMPLE);
|
674
|
-
|
675
|
-
export const
|
676
|
-
|
677
|
-
export const
|
678
|
-
|
677
|
+
/** SLH-DSA: 128-bit fast SHA2 version. */
|
678
|
+
export const slh_dsa_sha2_128f: SphincsSigner = /* @__PURE__ */ gen(PARAMS['128f'], SHA256_SIMPLE);
|
679
|
+
/** SLH-DSA: 128-bit small SHA2 version. */
|
680
|
+
export const slh_dsa_sha2_128s: SphincsSigner = /* @__PURE__ */ gen(PARAMS['128s'], SHA256_SIMPLE);
|
681
|
+
/** SLH-DSA: 192-bit fast SHA2 version. */
|
682
|
+
export const slh_dsa_sha2_192f: SphincsSigner = /* @__PURE__ */ gen(PARAMS['192f'], SHA512_SIMPLE);
|
683
|
+
/** SLH-DSA: 192-bit small SHA2 version. */
|
684
|
+
export const slh_dsa_sha2_192s: SphincsSigner = /* @__PURE__ */ gen(PARAMS['192s'], SHA512_SIMPLE);
|
685
|
+
/** SLH-DSA: 256-bit fast SHA2 version. */
|
686
|
+
export const slh_dsa_sha2_256f: SphincsSigner = /* @__PURE__ */ gen(PARAMS['256f'], SHA512_SIMPLE);
|
687
|
+
/** SLH-DSA: 256-bit small SHA2 version. */
|
688
|
+
export const slh_dsa_sha2_256s: SphincsSigner = /* @__PURE__ */ gen(PARAMS['256s'], SHA512_SIMPLE);
|
package/src/utils.ts
CHANGED
@@ -1,12 +1,17 @@
|
|
1
|
+
/**
|
2
|
+
* Utilities for hex, bytearray and number handling.
|
3
|
+
* @module
|
4
|
+
*/
|
1
5
|
/*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */
|
2
|
-
import {
|
3
|
-
import { TypedArray, randomBytes as randb } from '@noble/hashes/utils';
|
6
|
+
import { abytes } from '@noble/hashes/_assert';
|
7
|
+
import { TypedArray, concatBytes, utf8ToBytes, randomBytes as randb } from '@noble/hashes/utils';
|
4
8
|
|
5
|
-
export const ensureBytes = abytes;
|
6
|
-
export const randomBytes = randb;
|
9
|
+
export const ensureBytes: typeof abytes = abytes;
|
10
|
+
export const randomBytes: typeof randb = randb;
|
11
|
+
export { concatBytes, utf8ToBytes };
|
7
12
|
|
8
13
|
// Compares 2 u8a-s in kinda constant time
|
9
|
-
export function equalBytes(a: Uint8Array, b: Uint8Array) {
|
14
|
+
export function equalBytes(a: Uint8Array, b: Uint8Array): boolean {
|
10
15
|
if (a.length !== b.length) return false;
|
11
16
|
let diff = 0;
|
12
17
|
for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i];
|
@@ -101,13 +106,13 @@ export function vecCoder<T>(c: BytesCoderLen<T>, vecLen: number): BytesCoderLen<
|
|
101
106
|
}
|
102
107
|
|
103
108
|
// cleanBytes(new Uint8Array(), [new Uint16Array(), new Uint32Array()])
|
104
|
-
export function cleanBytes(...list: (TypedArray | TypedArray[])[]) {
|
109
|
+
export function cleanBytes(...list: (TypedArray | TypedArray[])[]): void {
|
105
110
|
for (const t of list) {
|
106
111
|
if (Array.isArray(t)) for (const b of t) b.fill(0);
|
107
112
|
else t.fill(0);
|
108
113
|
}
|
109
114
|
}
|
110
115
|
|
111
|
-
export function getMask(bits: number) {
|
116
|
+
export function getMask(bits: number): number {
|
112
117
|
return (1 << bits) - 1; // 4 -> 0b1111
|
113
118
|
}
|
package/utils.d.ts
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
+
/**
|
2
|
+
* Utilities for hex, bytearray and number handling.
|
3
|
+
* @module
|
4
|
+
*/
|
1
5
|
/*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */
|
2
|
-
import {
|
3
|
-
import { TypedArray, randomBytes as randb } from '@noble/hashes/utils';
|
6
|
+
import { abytes } from '@noble/hashes/_assert';
|
7
|
+
import { TypedArray, concatBytes, utf8ToBytes, randomBytes as randb } from '@noble/hashes/utils';
|
4
8
|
export declare const ensureBytes: typeof abytes;
|
5
9
|
export declare const randomBytes: typeof randb;
|
10
|
+
export { concatBytes, utf8ToBytes };
|
6
11
|
export declare function equalBytes(a: Uint8Array, b: Uint8Array): boolean;
|
7
12
|
export type Signer = {
|
8
13
|
signRandBytes: number;
|
@@ -34,5 +39,4 @@ export declare function splitCoder<T extends (number | BytesCoderLen<any>)[]>(..
|
|
34
39
|
export declare function vecCoder<T>(c: BytesCoderLen<T>, vecLen: number): BytesCoderLen<T[]>;
|
35
40
|
export declare function cleanBytes(...list: (TypedArray | TypedArray[])[]): void;
|
36
41
|
export declare function getMask(bits: number): number;
|
37
|
-
export {};
|
38
42
|
//# 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":"AAAA,4EAA4E;AAC5E,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["src/utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,4EAA4E;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,IAAI,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAEjG,eAAO,MAAM,WAAW,EAAE,OAAO,MAAe,C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AC,SAAS,CAAC,MAAM,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI;KACxD,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACjE,CAAC;AACF,wBAAgB,UAAU,CAAC,CAAC,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"}
|
package/utils.js
CHANGED
@@ -1,15 +1,21 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.randomBytes = exports.ensureBytes = void 0;
|
3
|
+
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
|
+
/**
|
10
|
+
* Utilities for hex, bytearray and number handling.
|
11
|
+
* @module
|
12
|
+
*/
|
9
13
|
/*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */
|
10
14
|
const _assert_1 = require("@noble/hashes/_assert");
|
11
15
|
const utils_1 = require("@noble/hashes/utils");
|
12
|
-
exports
|
16
|
+
Object.defineProperty(exports, "concatBytes", { enumerable: true, get: function () { return utils_1.concatBytes; } });
|
17
|
+
Object.defineProperty(exports, "utf8ToBytes", { enumerable: true, get: function () { return utils_1.utf8ToBytes; } });
|
18
|
+
exports.ensureBytes = _assert_1.abytes;
|
13
19
|
exports.randomBytes = utils_1.randomBytes;
|
14
20
|
// Compares 2 u8a-s in kinda constant time
|
15
21
|
function equalBytes(a, b) {
|
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":";;;AAaA,gCAKC;AA6BD,gCAgCC;AAED,4BAwBC;AAGD,gCAKC;AAED,0BAEC;AArHD;;;GAGG;AACH,4EAA4E;AAC5E,mDAA+C;AAC/C,+CAAiG;AAIxF,4FAJY,mBAAW,OAIZ;AAAE,4FAJY,mBAAW,OAIZ;AAFpB,QAAA,WAAW,GAAkB,gBAAM,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;AA6BD,SAAgB,UAAU,CACxB,GAAG,OAAU;IAEb,MAAM,SAAS,GAA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