@noble/post-quantum 0.6.0 → 0.6.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/src/utils.ts CHANGED
@@ -12,6 +12,111 @@ import {
12
12
  isLE,
13
13
  randomBytes as randb,
14
14
  } from '@noble/hashes/utils.js';
15
+ /**
16
+ * Bytes API type helpers for old + new TypeScript.
17
+ *
18
+ * TS 5.6 has `Uint8Array`, while TS 5.9+ made it generic `Uint8Array<ArrayBuffer>`.
19
+ * We can't use specific return type, because TS 5.6 will error.
20
+ * We can't use generic return type, because most TS 5.9 software will expect specific type.
21
+ *
22
+ * Maps typed-array input leaves to broad forms.
23
+ * These are compatibility adapters, not ownership guarantees.
24
+ *
25
+ * - `TArg` keeps byte inputs broad.
26
+ * - `TRet` marks byte outputs for TS 5.6 and TS 5.9+ compatibility.
27
+ */
28
+ export type TypedArg<T> = T extends BigInt64Array
29
+ ? BigInt64Array
30
+ : T extends BigUint64Array
31
+ ? BigUint64Array
32
+ : T extends Float32Array
33
+ ? Float32Array
34
+ : T extends Float64Array
35
+ ? Float64Array
36
+ : T extends Int16Array
37
+ ? Int16Array
38
+ : T extends Int32Array
39
+ ? Int32Array
40
+ : T extends Int8Array
41
+ ? Int8Array
42
+ : T extends Uint16Array
43
+ ? Uint16Array
44
+ : T extends Uint32Array
45
+ ? Uint32Array
46
+ : T extends Uint8ClampedArray
47
+ ? Uint8ClampedArray
48
+ : T extends Uint8Array
49
+ ? Uint8Array
50
+ : never;
51
+ /** Maps typed-array output leaves to narrow TS-compatible forms. */
52
+ export type TypedRet<T> = T extends BigInt64Array
53
+ ? ReturnType<typeof BigInt64Array.of>
54
+ : T extends BigUint64Array
55
+ ? ReturnType<typeof BigUint64Array.of>
56
+ : T extends Float32Array
57
+ ? ReturnType<typeof Float32Array.of>
58
+ : T extends Float64Array
59
+ ? ReturnType<typeof Float64Array.of>
60
+ : T extends Int16Array
61
+ ? ReturnType<typeof Int16Array.of>
62
+ : T extends Int32Array
63
+ ? ReturnType<typeof Int32Array.of>
64
+ : T extends Int8Array
65
+ ? ReturnType<typeof Int8Array.of>
66
+ : T extends Uint16Array
67
+ ? ReturnType<typeof Uint16Array.of>
68
+ : T extends Uint32Array
69
+ ? ReturnType<typeof Uint32Array.of>
70
+ : T extends Uint8ClampedArray
71
+ ? ReturnType<typeof Uint8ClampedArray.of>
72
+ : T extends Uint8Array
73
+ ? ReturnType<typeof Uint8Array.of>
74
+ : never;
75
+ /** Recursively adapts byte-carrying API input types. See {@link TypedArg}. */
76
+ export type TArg<T> =
77
+ | T
78
+ | ([TypedArg<T>] extends [never]
79
+ ? T extends (...args: infer A) => infer R
80
+ ? ((...args: { [K in keyof A]: TRet<A[K]> }) => TArg<R>) & {
81
+ [K in keyof T]: T[K] extends (...args: any) => any ? T[K] : TArg<T[K]>;
82
+ }
83
+ : T extends [infer A, ...infer R]
84
+ ? [TArg<A>, ...{ [K in keyof R]: TArg<R[K]> }]
85
+ : T extends readonly [infer A, ...infer R]
86
+ ? readonly [TArg<A>, ...{ [K in keyof R]: TArg<R[K]> }]
87
+ : T extends (infer A)[]
88
+ ? TArg<A>[]
89
+ : T extends readonly (infer A)[]
90
+ ? readonly TArg<A>[]
91
+ : T extends Promise<infer A>
92
+ ? Promise<TArg<A>>
93
+ : T extends object
94
+ ? { [K in keyof T]: TArg<T[K]> }
95
+ : T
96
+ : TypedArg<T>);
97
+ /** Recursively adapts byte-carrying API output types. See {@link TypedArg}. */
98
+ export type TRet<T> = T extends unknown
99
+ ? T &
100
+ ([TypedRet<T>] extends [never]
101
+ ? T extends (...args: infer A) => infer R
102
+ ? ((...args: { [K in keyof A]: TArg<A[K]> }) => TRet<R>) & {
103
+ [K in keyof T]: T[K] extends (...args: any) => any ? T[K] : TRet<T[K]>;
104
+ }
105
+ : T extends [infer A, ...infer R]
106
+ ? [TRet<A>, ...{ [K in keyof R]: TRet<R[K]> }]
107
+ : T extends readonly [infer A, ...infer R]
108
+ ? readonly [TRet<A>, ...{ [K in keyof R]: TRet<R[K]> }]
109
+ : T extends (infer A)[]
110
+ ? TRet<A>[]
111
+ : T extends readonly (infer A)[]
112
+ ? readonly TRet<A>[]
113
+ : T extends Promise<infer A>
114
+ ? Promise<TRet<A>>
115
+ : T extends object
116
+ ? { [K in keyof T]: TRet<T[K]> }
117
+ : T
118
+ : TypedRet<T>)
119
+ : never;
15
120
  /**
16
121
  * Asserts that a value is a byte array and optionally checks its length.
17
122
  * Returns the original reference unchanged on success, and currently also accepts Node `Buffer`
@@ -43,6 +148,8 @@ export { concatBytesDoc as concatBytes };
43
148
  * Requires `globalThis.crypto.getRandomValues` and throws if that API is unavailable.
44
149
  * `bytesLength` is validated by the upstream helper as a non-negative integer before allocation,
45
150
  * so negative and fractional values both throw instead of truncating through JS `ToIndex`.
151
+ * @param bytesLength - Number of random bytes to generate.
152
+ * @returns Fresh random bytes.
46
153
  * @example
47
154
  * Generate a fresh random seed.
48
155
  * ```ts
@@ -63,7 +170,7 @@ export const randomBytes: typeof randb = randb;
63
170
  * equalBytes(new Uint8Array([1]), new Uint8Array([1]));
64
171
  * ```
65
172
  */
66
- export function equalBytes(a: Uint8Array, b: Uint8Array): boolean {
173
+ export function equalBytes(a: TArg<Uint8Array>, b: TArg<Uint8Array>): boolean {
67
174
  if (a.length !== b.length) return false;
68
175
  let diff = 0;
69
176
  for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i];
@@ -72,8 +179,7 @@ export function equalBytes(a: Uint8Array, b: Uint8Array): boolean {
72
179
 
73
180
  /**
74
181
  * Copies bytes into a fresh `Uint8Array`.
75
- * Returns a detached plain `Uint8Array`, and currently accepts broader array-like / iterable
76
- * inputs because it delegates directly to `Uint8Array.from(...)`.
182
+ * Returns a detached plain `Uint8Array` after validating that the input is real bytes.
77
183
  * @param bytes - Source bytes.
78
184
  * @returns Copy of the input bytes.
79
185
  * @example
@@ -82,8 +188,10 @@ export function equalBytes(a: Uint8Array, b: Uint8Array): boolean {
82
188
  * copyBytes(new Uint8Array([1, 2]));
83
189
  * ```
84
190
  */
85
- export function copyBytes(bytes: Uint8Array): Uint8Array {
86
- return Uint8Array.from(bytes);
191
+ export function copyBytes(bytes: TArg<Uint8Array>): TRet<Uint8Array> {
192
+ // `Uint8Array.from(...)` would also accept arrays / other typed arrays. Keep this helper strict
193
+ // because callers use it at byte-validation boundaries before mutating the detached copy.
194
+ return Uint8Array.from(abytes(bytes)) as TRet<Uint8Array>;
87
195
  }
88
196
 
89
197
  /**
@@ -92,6 +200,11 @@ export function copyBytes(bytes: Uint8Array): Uint8Array {
92
200
  * this boundary helper before aliasing them as host `Float64Array` lanes.
93
201
  * @param arr - Byte buffer whose length is a multiple of 8.
94
202
  * @returns The same buffer after in-place 64-bit lane byte swaps.
203
+ * @example
204
+ * Byte-swap one 64-bit lane in place.
205
+ * ```ts
206
+ * byteSwap64(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]));
207
+ * ```
95
208
  */
96
209
  export function byteSwap64<T extends ArrayBufferView>(arr: T): T {
97
210
  const bytes = new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
@@ -111,6 +224,18 @@ export function byteSwap64<T extends ArrayBufferView>(arr: T): T {
111
224
  }
112
225
  return arr;
113
226
  }
227
+ /**
228
+ * Byte-swaps 64-bit lanes on big-endian runtimes and returns the input unchanged on little-endian.
229
+ * This keeps Falcon's binary64 tables in canonical little-endian order before aliasing them as
230
+ * `Float64Array` lanes on the current host.
231
+ * @param arr - Buffer to pass through or swap in place.
232
+ * @returns The same buffer, normalized for Falcon's little-endian table layout.
233
+ * @example
234
+ * Normalize one host-endian buffer for Falcon's float tables.
235
+ * ```ts
236
+ * baswap64If(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]));
237
+ * ```
238
+ */
114
239
  export const baswap64If: <T extends ArrayBufferView>(arr: T) => T = isLE
115
240
  ? (arr) => arr
116
241
  : byteSwap64;
@@ -126,13 +251,16 @@ export type CryptoKeys = {
126
251
  * @param seed - Optional seed bytes for deterministic key generation.
127
252
  * @returns Fresh secret/public keypair.
128
253
  */
129
- keygen: (seed?: Uint8Array) => { secretKey: Uint8Array; publicKey: Uint8Array };
254
+ keygen: (seed?: TArg<Uint8Array>) => {
255
+ secretKey: TRet<Uint8Array>;
256
+ publicKey: TRet<Uint8Array>;
257
+ };
130
258
  /**
131
259
  * Derive one public key from a secret key.
132
260
  * @param secretKey - Secret key bytes.
133
261
  * @returns Public key bytes.
134
262
  */
135
- getPublicKey: (secretKey: Uint8Array) => Uint8Array;
263
+ getPublicKey: (secretKey: TArg<Uint8Array>) => TRet<Uint8Array>;
136
264
  };
137
265
 
138
266
  /** Verification options shared by the signature APIs. */
@@ -175,7 +303,7 @@ export function validateOpts(opts: object): void {
175
303
  * validateVerOpts({ context: new Uint8Array([1]) });
176
304
  * ```
177
305
  */
178
- export function validateVerOpts(opts: VerOpts): void {
306
+ export function validateVerOpts(opts: TArg<VerOpts>): void {
179
307
  validateOpts(opts);
180
308
  if (opts.context !== undefined) abytes(opts.context, undefined, 'opts.context');
181
309
  }
@@ -192,7 +320,7 @@ export function validateVerOpts(opts: VerOpts): void {
192
320
  * validateSigOpts({ extraEntropy: new Uint8Array([1]) });
193
321
  * ```
194
322
  */
195
- export function validateSigOpts(opts: SigOpts): void {
323
+ export function validateSigOpts(opts: TArg<SigOpts>): void {
196
324
  validateVerOpts(opts);
197
325
  if (opts.extraEntropy !== false && opts.extraEntropy !== undefined)
198
326
  abytes(opts.extraEntropy, undefined, 'opts.extraEntropy');
@@ -209,7 +337,11 @@ export type Signer = CryptoKeys & {
209
337
  * @param opts - Optional signing options.
210
338
  * @returns Signature bytes.
211
339
  */
212
- sign: (msg: Uint8Array, secretKey: Uint8Array, opts?: SigOpts) => Uint8Array;
340
+ sign: (
341
+ msg: TArg<Uint8Array>,
342
+ secretKey: TArg<Uint8Array>,
343
+ opts?: TArg<SigOpts>
344
+ ) => TRet<Uint8Array>;
213
345
  /**
214
346
  * Verify one signature.
215
347
  * @param sig - Signature bytes.
@@ -221,7 +353,12 @@ export type Signer = CryptoKeys & {
221
353
  * a verification failure and return `false`.
222
354
  * @throws On malformed API arguments or unsupported verification options.
223
355
  */
224
- verify: (sig: Uint8Array, msg: Uint8Array, publicKey: Uint8Array, opts?: VerOpts) => boolean;
356
+ verify: (
357
+ sig: TArg<Uint8Array>,
358
+ msg: TArg<Uint8Array>,
359
+ publicKey: TArg<Uint8Array>,
360
+ opts?: TArg<VerOpts>
361
+ ) => boolean;
225
362
  };
226
363
 
227
364
  /** Generic key encapsulation mechanism interface. */
@@ -235,11 +372,11 @@ export type KEM = CryptoKeys & {
235
372
  * @returns Ciphertext plus shared secret.
236
373
  */
237
374
  encapsulate: (
238
- publicKey: Uint8Array,
239
- msg?: Uint8Array
375
+ publicKey: TArg<Uint8Array>,
376
+ msg?: TArg<Uint8Array>
240
377
  ) => {
241
- cipherText: Uint8Array;
242
- sharedSecret: Uint8Array;
378
+ cipherText: TRet<Uint8Array>;
379
+ sharedSecret: TRet<Uint8Array>;
243
380
  };
244
381
  /**
245
382
  * Recover the shared secret from a ciphertext and recipient secret key.
@@ -247,7 +384,7 @@ export type KEM = CryptoKeys & {
247
384
  * @param secretKey - Recipient secret key bytes.
248
385
  * @returns Decapsulated shared secret.
249
386
  */
250
- decapsulate: (cipherText: Uint8Array, secretKey: Uint8Array) => Uint8Array;
387
+ decapsulate: (cipherText: TArg<Uint8Array>, secretKey: TArg<Uint8Array>) => TRet<Uint8Array>;
251
388
  };
252
389
 
253
390
  /** Bidirectional encoder/decoder interface. */
@@ -308,8 +445,9 @@ type SplitOut<T extends (number | BytesCoderLen<any>)[]> = {
308
445
  export function splitCoder<T extends (number | BytesCoderLen<any>)[]>(
309
446
  label: string,
310
447
  ...lengths: T
311
- ): BytesCoder<SplitOut<T>> & { bytesLen: number } {
312
- const getLength = (c: number | BytesCoderLen<any>) => (typeof c === 'number' ? c : c.bytesLen);
448
+ ): TRet<BytesCoder<SplitOut<T>> & { bytesLen: number }> {
449
+ const getLength = (c: TArg<number | BytesCoderLen<any>>) =>
450
+ typeof c === 'number' ? c : (c as BytesCoderLen<any>).bytesLen;
313
451
  const bytesLen: number = lengths.reduce((sum: number, a) => sum + getLength(a), 0);
314
452
  return {
315
453
  bytesLen,
@@ -326,7 +464,7 @@ export function splitCoder<T extends (number | BytesCoderLen<any>)[]>(
326
464
  }
327
465
  return res;
328
466
  },
329
- decode: (buf: Uint8Array) => {
467
+ decode: (buf: TArg<Uint8Array>) => {
330
468
  abytes_(buf, bytesLen, label);
331
469
  const res = [];
332
470
  for (const c of lengths) {
@@ -359,30 +497,31 @@ export function splitCoder<T extends (number | BytesCoderLen<any>)[]>(
359
497
  * ).encode([1, 2]);
360
498
  * ```
361
499
  */
362
- export function vecCoder<T>(c: BytesCoderLen<T>, vecLen: number): BytesCoderLen<T[]> {
363
- const bytesLen = vecLen * c.bytesLen;
500
+ export function vecCoder<T>(c: TArg<BytesCoderLen<T>>, vecLen: number): TRet<BytesCoderLen<T[]>> {
501
+ const coder = c as BytesCoderLen<T>;
502
+ const bytesLen = vecLen * coder.bytesLen;
364
503
  return {
365
504
  bytesLen,
366
- encode: (u: T[]): Uint8Array => {
505
+ encode: (u: TArg<T[]>): TRet<Uint8Array> => {
367
506
  if (u.length !== vecLen)
368
507
  throw new RangeError(`vecCoder.encode: wrong length=${u.length}. Expected: ${vecLen}`);
369
508
  const res = new Uint8Array(bytesLen);
370
509
  for (let i = 0, pos = 0; i < u.length; i++) {
371
- const b = c.encode(u[i]);
510
+ const b = coder.encode(u[i] as T);
372
511
  res.set(b, pos);
373
512
  b.fill(0); // clean
374
513
  pos += b.length;
375
514
  }
376
- return res;
515
+ return res as TRet<Uint8Array>;
377
516
  },
378
- decode: (a: Uint8Array): T[] => {
517
+ decode: (a: TArg<Uint8Array>): TRet<T[]> => {
379
518
  abytes_(a, bytesLen);
380
519
  const r: T[] = [];
381
- for (let i = 0; i < a.length; i += c.bytesLen)
382
- r.push(c.decode(a.subarray(i, i + c.bytesLen)));
383
- return r;
520
+ for (let i = 0; i < a.length; i += coder.bytesLen)
521
+ r.push(coder.decode(a.subarray(i, i + coder.bytesLen)));
522
+ return r as TRet<T[]>;
384
523
  },
385
- };
524
+ } as any;
386
525
  }
387
526
 
388
527
  /**
@@ -407,6 +546,7 @@ export function cleanBytes(...list: (TypedArray | TypedArray[])[]): void {
407
546
  * Creates a 32-bit mask with the lowest `bits` bits set.
408
547
  * @param bits - Number of low bits to keep.
409
548
  * @returns Bit mask with `bits` ones.
549
+ * @throws On wrong argument ranges or values. {@link RangeError}
410
550
  * @example
411
551
  * Create a low-bit mask for packed-field operations.
412
552
  * ```ts
@@ -421,7 +561,7 @@ export function getMask(bits: number): number {
421
561
  }
422
562
 
423
563
  /** Shared empty byte array used as the default context. */
424
- export const EMPTY: Uint8Array = /* @__PURE__ */ Uint8Array.of();
564
+ export const EMPTY: TRet<Uint8Array> = /* @__PURE__ */ Uint8Array.of();
425
565
 
426
566
  /**
427
567
  * Builds the domain-separated message payload for the pure sign/verify paths.
@@ -436,7 +576,7 @@ export const EMPTY: Uint8Array = /* @__PURE__ */ Uint8Array.of();
436
576
  * const payload = getMessage(new Uint8Array([1, 2]));
437
577
  * ```
438
578
  */
439
- export function getMessage(msg: Uint8Array, ctx: Uint8Array = EMPTY): Uint8Array {
579
+ export function getMessage(msg: TArg<Uint8Array>, ctx: TArg<Uint8Array> = EMPTY): TRet<Uint8Array> {
440
580
  abytes_(msg);
441
581
  abytes_(ctx);
442
582
  if (ctx.length > 255) throw new RangeError('context should be 255 bytes or less');
@@ -503,9 +643,9 @@ export function checkHash(hash: CHash, requiredStrength: number = 0): void {
503
643
  */
504
644
  export function getMessagePrehash(
505
645
  hash: CHash,
506
- msg: Uint8Array,
507
- ctx: Uint8Array = EMPTY
508
- ): Uint8Array {
646
+ msg: TArg<Uint8Array>,
647
+ ctx: TArg<Uint8Array> = EMPTY
648
+ ): TRet<Uint8Array> {
509
649
  abytes_(msg);
510
650
  abytes_(ctx);
511
651
  if (ctx.length > 255) throw new RangeError('context should be 255 bytes or less');
package/utils.d.ts CHANGED
@@ -4,6 +4,46 @@
4
4
  */
5
5
  /*! noble-post-quantum - MIT License (c) 2024 Paul Miller (paulmillr.com) */
6
6
  import { type CHash, type TypedArray, abytes, concatBytes, randomBytes as randb } from '@noble/hashes/utils.js';
7
+ /**
8
+ * Bytes API type helpers for old + new TypeScript.
9
+ *
10
+ * TS 5.6 has `Uint8Array`, while TS 5.9+ made it generic `Uint8Array<ArrayBuffer>`.
11
+ * We can't use specific return type, because TS 5.6 will error.
12
+ * We can't use generic return type, because most TS 5.9 software will expect specific type.
13
+ *
14
+ * Maps typed-array input leaves to broad forms.
15
+ * These are compatibility adapters, not ownership guarantees.
16
+ *
17
+ * - `TArg` keeps byte inputs broad.
18
+ * - `TRet` marks byte outputs for TS 5.6 and TS 5.9+ compatibility.
19
+ */
20
+ export type TypedArg<T> = T extends BigInt64Array ? BigInt64Array : T extends BigUint64Array ? BigUint64Array : T extends Float32Array ? Float32Array : T extends Float64Array ? Float64Array : T extends Int16Array ? Int16Array : T extends Int32Array ? Int32Array : T extends Int8Array ? Int8Array : T extends Uint16Array ? Uint16Array : T extends Uint32Array ? Uint32Array : T extends Uint8ClampedArray ? Uint8ClampedArray : T extends Uint8Array ? Uint8Array : never;
21
+ /** Maps typed-array output leaves to narrow TS-compatible forms. */
22
+ export type TypedRet<T> = T extends BigInt64Array ? ReturnType<typeof BigInt64Array.of> : T extends BigUint64Array ? ReturnType<typeof BigUint64Array.of> : T extends Float32Array ? ReturnType<typeof Float32Array.of> : T extends Float64Array ? ReturnType<typeof Float64Array.of> : T extends Int16Array ? ReturnType<typeof Int16Array.of> : T extends Int32Array ? ReturnType<typeof Int32Array.of> : T extends Int8Array ? ReturnType<typeof Int8Array.of> : T extends Uint16Array ? ReturnType<typeof Uint16Array.of> : T extends Uint32Array ? ReturnType<typeof Uint32Array.of> : T extends Uint8ClampedArray ? ReturnType<typeof Uint8ClampedArray.of> : T extends Uint8Array ? ReturnType<typeof Uint8Array.of> : never;
23
+ /** Recursively adapts byte-carrying API input types. See {@link TypedArg}. */
24
+ export type TArg<T> = T | ([TypedArg<T>] extends [never] ? T extends (...args: infer A) => infer R ? ((...args: {
25
+ [K in keyof A]: TRet<A[K]>;
26
+ }) => TArg<R>) & {
27
+ [K in keyof T]: T[K] extends (...args: any) => any ? T[K] : TArg<T[K]>;
28
+ } : T extends [infer A, ...infer R] ? [TArg<A>, ...{
29
+ [K in keyof R]: TArg<R[K]>;
30
+ }] : T extends readonly [infer A, ...infer R] ? readonly [TArg<A>, ...{
31
+ [K in keyof R]: TArg<R[K]>;
32
+ }] : T extends (infer A)[] ? TArg<A>[] : T extends readonly (infer A)[] ? readonly TArg<A>[] : T extends Promise<infer A> ? Promise<TArg<A>> : T extends object ? {
33
+ [K in keyof T]: TArg<T[K]>;
34
+ } : T : TypedArg<T>);
35
+ /** Recursively adapts byte-carrying API output types. See {@link TypedArg}. */
36
+ export type TRet<T> = T extends unknown ? T & ([TypedRet<T>] extends [never] ? T extends (...args: infer A) => infer R ? ((...args: {
37
+ [K in keyof A]: TArg<A[K]>;
38
+ }) => TRet<R>) & {
39
+ [K in keyof T]: T[K] extends (...args: any) => any ? T[K] : TRet<T[K]>;
40
+ } : T extends [infer A, ...infer R] ? [TRet<A>, ...{
41
+ [K in keyof R]: TRet<R[K]>;
42
+ }] : T extends readonly [infer A, ...infer R] ? readonly [TRet<A>, ...{
43
+ [K in keyof R]: TRet<R[K]>;
44
+ }] : T extends (infer A)[] ? TRet<A>[] : T extends readonly (infer A)[] ? readonly TRet<A>[] : T extends Promise<infer A> ? Promise<TRet<A>> : T extends object ? {
45
+ [K in keyof T]: TRet<T[K]>;
46
+ } : T : TypedRet<T>) : never;
7
47
  /**
8
48
  * Asserts that a value is a byte array and optionally checks its length.
9
49
  * Returns the original reference unchanged on success, and currently also accepts Node `Buffer`
@@ -35,6 +75,8 @@ export { concatBytesDoc as concatBytes };
35
75
  * Requires `globalThis.crypto.getRandomValues` and throws if that API is unavailable.
36
76
  * `bytesLength` is validated by the upstream helper as a non-negative integer before allocation,
37
77
  * so negative and fractional values both throw instead of truncating through JS `ToIndex`.
78
+ * @param bytesLength - Number of random bytes to generate.
79
+ * @returns Fresh random bytes.
38
80
  * @example
39
81
  * Generate a fresh random seed.
40
82
  * ```ts
@@ -54,11 +96,10 @@ export declare const randomBytes: typeof randb;
54
96
  * equalBytes(new Uint8Array([1]), new Uint8Array([1]));
55
97
  * ```
56
98
  */
57
- export declare function equalBytes(a: Uint8Array, b: Uint8Array): boolean;
99
+ export declare function equalBytes(a: TArg<Uint8Array>, b: TArg<Uint8Array>): boolean;
58
100
  /**
59
101
  * Copies bytes into a fresh `Uint8Array`.
60
- * Returns a detached plain `Uint8Array`, and currently accepts broader array-like / iterable
61
- * inputs because it delegates directly to `Uint8Array.from(...)`.
102
+ * Returns a detached plain `Uint8Array` after validating that the input is real bytes.
62
103
  * @param bytes - Source bytes.
63
104
  * @returns Copy of the input bytes.
64
105
  * @example
@@ -67,15 +108,32 @@ export declare function equalBytes(a: Uint8Array, b: Uint8Array): boolean;
67
108
  * copyBytes(new Uint8Array([1, 2]));
68
109
  * ```
69
110
  */
70
- export declare function copyBytes(bytes: Uint8Array): Uint8Array;
111
+ export declare function copyBytes(bytes: TArg<Uint8Array>): TRet<Uint8Array>;
71
112
  /**
72
113
  * Byte-swaps each 64-bit lane in place.
73
114
  * Falcon's exact binary64 tables are stored as little-endian byte payloads, so BE runtimes need
74
115
  * this boundary helper before aliasing them as host `Float64Array` lanes.
75
116
  * @param arr - Byte buffer whose length is a multiple of 8.
76
117
  * @returns The same buffer after in-place 64-bit lane byte swaps.
118
+ * @example
119
+ * Byte-swap one 64-bit lane in place.
120
+ * ```ts
121
+ * byteSwap64(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]));
122
+ * ```
77
123
  */
78
124
  export declare function byteSwap64<T extends ArrayBufferView>(arr: T): T;
125
+ /**
126
+ * Byte-swaps 64-bit lanes on big-endian runtimes and returns the input unchanged on little-endian.
127
+ * This keeps Falcon's binary64 tables in canonical little-endian order before aliasing them as
128
+ * `Float64Array` lanes on the current host.
129
+ * @param arr - Buffer to pass through or swap in place.
130
+ * @returns The same buffer, normalized for Falcon's little-endian table layout.
131
+ * @example
132
+ * Normalize one host-endian buffer for Falcon's float tables.
133
+ * ```ts
134
+ * baswap64If(new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]));
135
+ * ```
136
+ */
79
137
  export declare const baswap64If: <T extends ArrayBufferView>(arr: T) => T;
80
138
  /** Shared key-generation surface for signers and KEMs. */
81
139
  export type CryptoKeys = {
@@ -94,16 +152,16 @@ export type CryptoKeys = {
94
152
  * @param seed - Optional seed bytes for deterministic key generation.
95
153
  * @returns Fresh secret/public keypair.
96
154
  */
97
- keygen: (seed?: Uint8Array) => {
98
- secretKey: Uint8Array;
99
- publicKey: Uint8Array;
155
+ keygen: (seed?: TArg<Uint8Array>) => {
156
+ secretKey: TRet<Uint8Array>;
157
+ publicKey: TRet<Uint8Array>;
100
158
  };
101
159
  /**
102
160
  * Derive one public key from a secret key.
103
161
  * @param secretKey - Secret key bytes.
104
162
  * @returns Public key bytes.
105
163
  */
106
- getPublicKey: (secretKey: Uint8Array) => Uint8Array;
164
+ getPublicKey: (secretKey: TArg<Uint8Array>) => TRet<Uint8Array>;
107
165
  };
108
166
  /** Verification options shared by the signature APIs. */
109
167
  export type VerOpts = {
@@ -138,7 +196,7 @@ export declare function validateOpts(opts: object): void;
138
196
  * validateVerOpts({ context: new Uint8Array([1]) });
139
197
  * ```
140
198
  */
141
- export declare function validateVerOpts(opts: VerOpts): void;
199
+ export declare function validateVerOpts(opts: TArg<VerOpts>): void;
142
200
  /**
143
201
  * Validates common signing options.
144
202
  * `extraEntropy` is validated with `abytes(...)`; exact lengths and extra algorithm-specific
@@ -151,7 +209,7 @@ export declare function validateVerOpts(opts: VerOpts): void;
151
209
  * validateSigOpts({ extraEntropy: new Uint8Array([1]) });
152
210
  * ```
153
211
  */
154
- export declare function validateSigOpts(opts: SigOpts): void;
212
+ export declare function validateSigOpts(opts: TArg<SigOpts>): void;
155
213
  /** Generic signature interface with key generation, signing, and verification. */
156
214
  export type Signer = CryptoKeys & {
157
215
  /** Public byte lengths for signatures and signing randomness. */
@@ -166,7 +224,7 @@ export type Signer = CryptoKeys & {
166
224
  * @param opts - Optional signing options.
167
225
  * @returns Signature bytes.
168
226
  */
169
- sign: (msg: Uint8Array, secretKey: Uint8Array, opts?: SigOpts) => Uint8Array;
227
+ sign: (msg: TArg<Uint8Array>, secretKey: TArg<Uint8Array>, opts?: TArg<SigOpts>) => TRet<Uint8Array>;
170
228
  /**
171
229
  * Verify one signature.
172
230
  * @param sig - Signature bytes.
@@ -178,7 +236,7 @@ export type Signer = CryptoKeys & {
178
236
  * a verification failure and return `false`.
179
237
  * @throws On malformed API arguments or unsupported verification options.
180
238
  */
181
- verify: (sig: Uint8Array, msg: Uint8Array, publicKey: Uint8Array, opts?: VerOpts) => boolean;
239
+ verify: (sig: TArg<Uint8Array>, msg: TArg<Uint8Array>, publicKey: TArg<Uint8Array>, opts?: TArg<VerOpts>) => boolean;
182
240
  };
183
241
  /** Generic key encapsulation mechanism interface. */
184
242
  export type KEM = CryptoKeys & {
@@ -194,9 +252,9 @@ export type KEM = CryptoKeys & {
194
252
  * @param msg - Optional caller-provided randomness/message seed.
195
253
  * @returns Ciphertext plus shared secret.
196
254
  */
197
- encapsulate: (publicKey: Uint8Array, msg?: Uint8Array) => {
198
- cipherText: Uint8Array;
199
- sharedSecret: Uint8Array;
255
+ encapsulate: (publicKey: TArg<Uint8Array>, msg?: TArg<Uint8Array>) => {
256
+ cipherText: TRet<Uint8Array>;
257
+ sharedSecret: TRet<Uint8Array>;
200
258
  };
201
259
  /**
202
260
  * Recover the shared secret from a ciphertext and recipient secret key.
@@ -204,7 +262,7 @@ export type KEM = CryptoKeys & {
204
262
  * @param secretKey - Recipient secret key bytes.
205
263
  * @returns Decapsulated shared secret.
206
264
  */
207
- decapsulate: (cipherText: Uint8Array, secretKey: Uint8Array) => Uint8Array;
265
+ decapsulate: (cipherText: TArg<Uint8Array>, secretKey: TArg<Uint8Array>) => TRet<Uint8Array>;
208
266
  };
209
267
  /** Bidirectional encoder/decoder interface. */
210
268
  export interface Coder<F, T> {
@@ -259,9 +317,9 @@ type SplitOut<T extends (number | BytesCoderLen<any>)[]> = {
259
317
  * splitCoder('demo', 1, 2).encode([new Uint8Array([1]), new Uint8Array([2, 3])]);
260
318
  * ```
261
319
  */
262
- export declare function splitCoder<T extends (number | BytesCoderLen<any>)[]>(label: string, ...lengths: T): BytesCoder<SplitOut<T>> & {
320
+ export declare function splitCoder<T extends (number | BytesCoderLen<any>)[]>(label: string, ...lengths: T): TRet<BytesCoder<SplitOut<T>> & {
263
321
  bytesLen: number;
264
- };
322
+ }>;
265
323
  /**
266
324
  * Builds a fixed-length vector coder from another fixed-length coder.
267
325
  * Element decoding receives `subarray(...)` views, so aliasing depends on the element coder.
@@ -281,7 +339,7 @@ export declare function splitCoder<T extends (number | BytesCoderLen<any>)[]>(la
281
339
  * ).encode([1, 2]);
282
340
  * ```
283
341
  */
284
- export declare function vecCoder<T>(c: BytesCoderLen<T>, vecLen: number): BytesCoderLen<T[]>;
342
+ export declare function vecCoder<T>(c: TArg<BytesCoderLen<T>>, vecLen: number): TRet<BytesCoderLen<T[]>>;
285
343
  /**
286
344
  * Overwrites supported typed-array inputs with zeroes in place.
287
345
  * Accepts direct typed arrays and one-level arrays of them.
@@ -298,6 +356,7 @@ export declare function cleanBytes(...list: (TypedArray | TypedArray[])[]): void
298
356
  * Creates a 32-bit mask with the lowest `bits` bits set.
299
357
  * @param bits - Number of low bits to keep.
300
358
  * @returns Bit mask with `bits` ones.
359
+ * @throws On wrong argument ranges or values. {@link RangeError}
301
360
  * @example
302
361
  * Create a low-bit mask for packed-field operations.
303
362
  * ```ts
@@ -306,7 +365,7 @@ export declare function cleanBytes(...list: (TypedArray | TypedArray[])[]): void
306
365
  */
307
366
  export declare function getMask(bits: number): number;
308
367
  /** Shared empty byte array used as the default context. */
309
- export declare const EMPTY: Uint8Array;
368
+ export declare const EMPTY: TRet<Uint8Array>;
310
369
  /**
311
370
  * Builds the domain-separated message payload for the pure sign/verify paths.
312
371
  * Context length `255` is valid; only `ctx.length > 255` is rejected.
@@ -320,7 +379,7 @@ export declare const EMPTY: Uint8Array;
320
379
  * const payload = getMessage(new Uint8Array([1, 2]));
321
380
  * ```
322
381
  */
323
- export declare function getMessage(msg: Uint8Array, ctx?: Uint8Array): Uint8Array;
382
+ export declare function getMessage(msg: TArg<Uint8Array>, ctx?: TArg<Uint8Array>): TRet<Uint8Array>;
324
383
  /**
325
384
  * Validates that a hash exposes a NIST hash OID and enough collision resistance.
326
385
  * Current accepted surface is broader than the FIPS algorithm tables: any hash/XOF under the NIST
@@ -357,5 +416,5 @@ export declare function checkHash(hash: CHash, requiredStrength?: number): void;
357
416
  * getMessagePrehash(sha256, new Uint8Array([1, 2]));
358
417
  * ```
359
418
  */
360
- export declare function getMessagePrehash(hash: CHash, msg: Uint8Array, ctx?: Uint8Array): Uint8Array;
419
+ export declare function getMessagePrehash(hash: CHash, msg: TArg<Uint8Array>, ctx?: TArg<Uint8Array>): TRet<Uint8Array>;
361
420
  //# 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;;;GAGG;AACH,4EAA4E;AAC5E,OAAO,EACL,KAAK,KAAK,EACV,KAAK,UAAU,EACf,MAAM,EAEN,WAAW,EAEX,WAAW,IAAI,KAAK,EACrB,MAAM,wBAAwB,CAAC;AAChC;;;;;;;;;;;GAWG;AACH,QAAA,MAAM,SAAS,EAAE,OAAO,MAAe,CAAC;AACxC,OAAO,EAAE,SAAS,IAAI,MAAM,EAAE,CAAC;AAC/B;;;;;;;;;GASG;AACH,QAAA,MAAM,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