@jscv-solutions/node-crypto 0.0.0-stage → 1.0.0-rc.2

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.
Files changed (67) hide show
  1. package/LICENSE +373 -0
  2. package/README.md +92 -2
  3. package/dist/cjs/package.json +6 -0
  4. package/dist/cjs/packages/comparison/index.d.ts +5 -0
  5. package/dist/cjs/packages/comparison/index.js +8 -0
  6. package/dist/cjs/packages/digest/index.d.ts +5 -0
  7. package/dist/cjs/packages/digest/index.js +8 -0
  8. package/dist/cjs/packages/encryption/index.d.ts +5 -0
  9. package/dist/cjs/packages/encryption/index.js +8 -0
  10. package/dist/cjs/packages/key-derivation/index.d.ts +5 -0
  11. package/dist/cjs/packages/key-derivation/index.js +8 -0
  12. package/dist/cjs/packages/message-authentication/index.d.ts +5 -0
  13. package/dist/cjs/packages/message-authentication/index.js +8 -0
  14. package/dist/cjs/packages/password-hashing/index.d.ts +5 -0
  15. package/dist/cjs/packages/password-hashing/index.js +8 -0
  16. package/dist/cjs/packages/random/index.d.ts +5 -0
  17. package/dist/cjs/packages/random/index.js +8 -0
  18. package/dist/cjs/shared/algorithms.d.ts +8 -0
  19. package/dist/cjs/shared/algorithms.js +24 -0
  20. package/dist/cjs/shared/deprecation.d.ts +23 -0
  21. package/dist/cjs/shared/deprecation.js +38 -0
  22. package/dist/cjs/shared/encodings.d.ts +30 -0
  23. package/dist/cjs/shared/encodings.js +69 -0
  24. package/dist/cjs/shared/errors.d.ts +79 -0
  25. package/dist/cjs/shared/errors.js +89 -0
  26. package/dist/cjs/shared/inputs.d.ts +9 -0
  27. package/dist/cjs/shared/inputs.js +29 -0
  28. package/dist/cjs/shared/peer-loading.d.ts +16 -0
  29. package/dist/cjs/shared/peer-loading.js +129 -0
  30. package/dist/cjs/shared/require-sync-cjs.d.ts +11 -0
  31. package/dist/cjs/shared/require-sync-cjs.js +18 -0
  32. package/dist/cjs/shared/typings/encodings.d.ts +2 -0
  33. package/dist/cjs/shared/typings/errors.d.ts +10 -0
  34. package/dist/cjs/shared/typings/inputs.d.ts +2 -0
  35. package/dist/esm/package.json +6 -0
  36. package/dist/esm/packages/comparison/index.d.ts +5 -0
  37. package/dist/esm/packages/comparison/index.js +5 -0
  38. package/dist/esm/packages/digest/index.d.ts +5 -0
  39. package/dist/esm/packages/digest/index.js +5 -0
  40. package/dist/esm/packages/encryption/index.d.ts +5 -0
  41. package/dist/esm/packages/encryption/index.js +5 -0
  42. package/dist/esm/packages/key-derivation/index.d.ts +5 -0
  43. package/dist/esm/packages/key-derivation/index.js +5 -0
  44. package/dist/esm/packages/message-authentication/index.d.ts +5 -0
  45. package/dist/esm/packages/message-authentication/index.js +5 -0
  46. package/dist/esm/packages/password-hashing/index.d.ts +5 -0
  47. package/dist/esm/packages/password-hashing/index.js +5 -0
  48. package/dist/esm/packages/random/index.d.ts +5 -0
  49. package/dist/esm/packages/random/index.js +5 -0
  50. package/dist/esm/shared/algorithms.d.ts +8 -0
  51. package/dist/esm/shared/algorithms.js +21 -0
  52. package/dist/esm/shared/deprecation.d.ts +23 -0
  53. package/dist/esm/shared/deprecation.js +34 -0
  54. package/dist/esm/shared/encodings.d.ts +30 -0
  55. package/dist/esm/shared/encodings.js +64 -0
  56. package/dist/esm/shared/errors.d.ts +79 -0
  57. package/dist/esm/shared/errors.js +81 -0
  58. package/dist/esm/shared/inputs.d.ts +9 -0
  59. package/dist/esm/shared/inputs.js +26 -0
  60. package/dist/esm/shared/peer-loading.d.ts +16 -0
  61. package/dist/esm/shared/peer-loading.js +92 -0
  62. package/dist/esm/shared/require-sync-esm.d.ts +7 -0
  63. package/dist/esm/shared/require-sync-esm.js +20 -0
  64. package/dist/esm/shared/typings/encodings.d.ts +2 -0
  65. package/dist/esm/shared/typings/errors.d.ts +10 -0
  66. package/dist/esm/shared/typings/inputs.d.ts +2 -0
  67. package/package.json +157 -3
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ /**
3
+ * Deprecation signalling shared by every namespace.
4
+ *
5
+ * A deprecated algorithm is marked with the JSDoc `@deprecated` tag at
6
+ * its declaration site and calls `emitDeprecationWarning` on first use.
7
+ * Warnings go through `process.emitWarning` (never `console.warn`) so
8
+ * they honor `--no-warnings` and `--disable-warning`, and each stable
9
+ * warning code is emitted at most once per process. The algorithm name
10
+ * is public and safe to include in the message.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.deprecationCodeFor = deprecationCodeFor;
14
+ exports.emitDeprecationWarning = emitDeprecationWarning;
15
+ const emittedCodes = new Set();
16
+ /**
17
+ * Derives the stable process-warning code for a deprecated algorithm.
18
+ *
19
+ * @param algorithm - Lowercase kebab-case algorithm identifier.
20
+ * @returns The stable warning code for the algorithm.
21
+ */
22
+ function deprecationCodeFor(algorithm) {
23
+ const token = algorithm.toUpperCase().replace(/-/g, '_');
24
+ return `NODE_CRYPTO_DEPRECATED_${token}`;
25
+ }
26
+ /**
27
+ * Emits the deprecation warning for an algorithm, once per process.
28
+ *
29
+ * @param algorithm - Lowercase kebab-case algorithm identifier.
30
+ */
31
+ function emitDeprecationWarning(algorithm) {
32
+ const code = deprecationCodeFor(algorithm);
33
+ if (emittedCodes.has(code)) {
34
+ return;
35
+ }
36
+ emittedCodes.add(code);
37
+ process.emitWarning(`The '${algorithm}' algorithm is deprecated and will be removed in a future major release.`, { code, type: 'DeprecationWarning' });
38
+ }
@@ -0,0 +1,30 @@
1
+ import type { Encoding } from './typings/encodings.js';
2
+ /**
3
+ * Encodes bytes as text with the requested encoding.
4
+ *
5
+ * @param data - Bytes to encode.
6
+ * @param encoding - Target text encoding.
7
+ * @returns The encoded text (`base64url` output is unpadded).
8
+ */
9
+ export declare function encodeBytes(data: Uint8Array, encoding: Encoding): string;
10
+ /**
11
+ * Decodes text back into bytes, strictly validating the input.
12
+ *
13
+ * @param text - Encoded text to decode.
14
+ * @param encoding - Text encoding the input claims to use.
15
+ * @returns The decoded bytes.
16
+ * @throws {InvalidEncodingError} WHEN the text breaks the encoding rules.
17
+ */
18
+ export declare function decodeText(text: string, encoding: Encoding): Buffer;
19
+ /**
20
+ * Checks text against the alphabet and shape rules of an encoding.
21
+ *
22
+ * `base64` follows the padded canonical form. `base64url` accepts the
23
+ * unpadded form the encoder emits (whose length is never one past a
24
+ * multiple of four) as well as correctly padded input.
25
+ *
26
+ * @param text - Candidate encoded text.
27
+ * @param encoding - Encoding whose rules apply.
28
+ * @returns Whether the text is well formed for the encoding.
29
+ */
30
+ export declare function isWellFormed(text: string, encoding: Encoding): boolean;
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.encodeBytes = encodeBytes;
4
+ exports.decodeText = decodeText;
5
+ exports.isWellFormed = isWellFormed;
6
+ /**
7
+ * Binary-to-text encodings shared by every namespace.
8
+ *
9
+ * Supported encodings are `hex`, `base64` and `base64url`. Decoding is
10
+ * strict: input outside the encoding alphabet (or breaking its length
11
+ * and padding rules) throws an `InvalidEncodingError` instead of being
12
+ * silently truncated the way `Buffer.from` would on its own. Error
13
+ * messages never echo the offending input.
14
+ */
15
+ const errors_ts_1 = require("./errors.js");
16
+ const HEXPattern = /^[0-9a-fA-F]*$/;
17
+ const base64Pattern = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/;
18
+ const base64UrlPaddedPattern = /^(?:[A-Za-z0-9\-_]{4})*(?:[A-Za-z0-9\-_]{2}==|[A-Za-z0-9\-_]{3}=)?$/;
19
+ const base64UrlUnpaddedPattern = /^[A-Za-z0-9\-_]*$/;
20
+ /**
21
+ * Encodes bytes as text with the requested encoding.
22
+ *
23
+ * @param data - Bytes to encode.
24
+ * @param encoding - Target text encoding.
25
+ * @returns The encoded text (`base64url` output is unpadded).
26
+ */
27
+ function encodeBytes(data, encoding) {
28
+ const buffer = Buffer.from(data);
29
+ const text = buffer.toString(encoding);
30
+ return text;
31
+ }
32
+ /**
33
+ * Decodes text back into bytes, strictly validating the input.
34
+ *
35
+ * @param text - Encoded text to decode.
36
+ * @param encoding - Text encoding the input claims to use.
37
+ * @returns The decoded bytes.
38
+ * @throws {InvalidEncodingError} WHEN the text breaks the encoding rules.
39
+ */
40
+ function decodeText(text, encoding) {
41
+ if (!isWellFormed(text, encoding)) {
42
+ throw new errors_ts_1.InvalidEncodingError(`Invalid ${encoding} string: input breaks the ${encoding} rules.`);
43
+ }
44
+ const buffer = Buffer.from(text, encoding);
45
+ return buffer;
46
+ }
47
+ /**
48
+ * Checks text against the alphabet and shape rules of an encoding.
49
+ *
50
+ * `base64` follows the padded canonical form. `base64url` accepts the
51
+ * unpadded form the encoder emits (whose length is never one past a
52
+ * multiple of four) as well as correctly padded input.
53
+ *
54
+ * @param text - Candidate encoded text.
55
+ * @param encoding - Encoding whose rules apply.
56
+ * @returns Whether the text is well formed for the encoding.
57
+ */
58
+ function isWellFormed(text, encoding) {
59
+ if (encoding === 'hex') {
60
+ return text.length % 2 === 0 && HEXPattern.test(text);
61
+ }
62
+ if (encoding === 'base64') {
63
+ return text.length % 4 === 0 && base64Pattern.test(text);
64
+ }
65
+ if (text.includes('=')) {
66
+ return text.length % 4 === 0 && base64UrlPaddedPattern.test(text);
67
+ }
68
+ return text.length % 4 !== 1 && base64UrlUnpaddedPattern.test(text);
69
+ }
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Error model shared by every namespace of the library.
3
+ *
4
+ * Every error thrown by the library is an instance of `NodeCryptoError`
5
+ * (or a subclass) and carries a stable string `code` that callers can
6
+ * switch on. Codes are part of the public contract: never rename or
7
+ * remove one without a major release.
8
+ *
9
+ * Message hygiene: constructors accept a message built by the throwing
10
+ * code. Callers MUST NOT interpolate secrets, passwords, keys or
11
+ * plaintext into messages. Algorithm identifiers and package names are
12
+ * public and safe to include.
13
+ */
14
+ import type { ErrorCode } from './typings/errors.js';
15
+ /**
16
+ * Base class for every error thrown by the library.
17
+ */
18
+ export declare class NodeCryptoError extends Error {
19
+ /** Stable machine-readable failure identifier. */
20
+ readonly code: ErrorCode;
21
+ /**
22
+ * Creates a library error with a stable code.
23
+ *
24
+ * @param message - Human-readable description without secrets.
25
+ * @param code - Stable machine-readable failure identifier.
26
+ * @param options - Optional error options (for example `cause`).
27
+ */
28
+ constructor(message: string, code: ErrorCode, options?: ErrorOptions);
29
+ }
30
+ /**
31
+ * A function received an argument of the wrong type or range.
32
+ */
33
+ export declare class InvalidArgumentError extends NodeCryptoError {
34
+ /**
35
+ * Creates an invalid-argument error.
36
+ *
37
+ * @param message - Human-readable description without secrets.
38
+ * @param options - Optional error options (for example `cause`).
39
+ */
40
+ constructor(message: string, options?: ErrorOptions);
41
+ }
42
+ /**
43
+ * Encoded text contains characters outside its alphabet or breaks the
44
+ * encoding rules (for example odd-length hexadecimal).
45
+ */
46
+ export declare class InvalidEncodingError extends NodeCryptoError {
47
+ /**
48
+ * Creates an invalid-encoding error.
49
+ *
50
+ * @param message - Human-readable description without echoing the input.
51
+ * @param options - Optional error options (for example `cause`).
52
+ */
53
+ constructor(message: string, options?: ErrorOptions);
54
+ }
55
+ /**
56
+ * An optional peer dependency (for example `bcrypt`) is not installed,
57
+ * so the requested operation cannot run.
58
+ */
59
+ export declare class MissingPeerDependencyError extends NodeCryptoError {
60
+ /**
61
+ * Creates a missing-peer-dependency error.
62
+ *
63
+ * @param message - Description naming the package and how to install it.
64
+ * @param options - Optional error options (for example `cause`).
65
+ */
66
+ constructor(message: string, options?: ErrorOptions);
67
+ }
68
+ /**
69
+ * The caller passed an algorithm identifier the function does not support.
70
+ */
71
+ export declare class UnsupportedAlgorithmError extends NodeCryptoError {
72
+ /**
73
+ * Creates an unsupported-algorithm error.
74
+ *
75
+ * @param message - Description naming the received identifier.
76
+ * @param options - Optional error options (for example `cause`).
77
+ */
78
+ constructor(message: string, options?: ErrorOptions);
79
+ }
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnsupportedAlgorithmError = exports.MissingPeerDependencyError = exports.InvalidEncodingError = exports.InvalidArgumentError = exports.NodeCryptoError = void 0;
4
+ /**
5
+ * Base class for every error thrown by the library.
6
+ */
7
+ class NodeCryptoError extends Error {
8
+ /** Stable machine-readable failure identifier. */
9
+ code;
10
+ /**
11
+ * Creates a library error with a stable code.
12
+ *
13
+ * @param message - Human-readable description without secrets.
14
+ * @param code - Stable machine-readable failure identifier.
15
+ * @param options - Optional error options (for example `cause`).
16
+ */
17
+ constructor(message, code, options) {
18
+ super(message, options);
19
+ this.name = 'NodeCryptoError';
20
+ this.code = code;
21
+ }
22
+ }
23
+ exports.NodeCryptoError = NodeCryptoError;
24
+ /**
25
+ * A function received an argument of the wrong type or range.
26
+ */
27
+ class InvalidArgumentError extends NodeCryptoError {
28
+ /**
29
+ * Creates an invalid-argument error.
30
+ *
31
+ * @param message - Human-readable description without secrets.
32
+ * @param options - Optional error options (for example `cause`).
33
+ */
34
+ constructor(message, options) {
35
+ super(message, 'INVALID_ARGUMENT', options);
36
+ this.name = 'InvalidArgumentError';
37
+ }
38
+ }
39
+ exports.InvalidArgumentError = InvalidArgumentError;
40
+ /**
41
+ * Encoded text contains characters outside its alphabet or breaks the
42
+ * encoding rules (for example odd-length hexadecimal).
43
+ */
44
+ class InvalidEncodingError extends NodeCryptoError {
45
+ /**
46
+ * Creates an invalid-encoding error.
47
+ *
48
+ * @param message - Human-readable description without echoing the input.
49
+ * @param options - Optional error options (for example `cause`).
50
+ */
51
+ constructor(message, options) {
52
+ super(message, 'INVALID_ENCODING', options);
53
+ this.name = 'InvalidEncodingError';
54
+ }
55
+ }
56
+ exports.InvalidEncodingError = InvalidEncodingError;
57
+ /**
58
+ * An optional peer dependency (for example `bcrypt`) is not installed,
59
+ * so the requested operation cannot run.
60
+ */
61
+ class MissingPeerDependencyError extends NodeCryptoError {
62
+ /**
63
+ * Creates a missing-peer-dependency error.
64
+ *
65
+ * @param message - Description naming the package and how to install it.
66
+ * @param options - Optional error options (for example `cause`).
67
+ */
68
+ constructor(message, options) {
69
+ super(message, 'MISSING_PEER_DEPENDENCY', options);
70
+ this.name = 'MissingPeerDependencyError';
71
+ }
72
+ }
73
+ exports.MissingPeerDependencyError = MissingPeerDependencyError;
74
+ /**
75
+ * The caller passed an algorithm identifier the function does not support.
76
+ */
77
+ class UnsupportedAlgorithmError extends NodeCryptoError {
78
+ /**
79
+ * Creates an unsupported-algorithm error.
80
+ *
81
+ * @param message - Description naming the received identifier.
82
+ * @param options - Optional error options (for example `cause`).
83
+ */
84
+ constructor(message, options) {
85
+ super(message, 'UNSUPPORTED_ALGORITHM', options);
86
+ this.name = 'UnsupportedAlgorithmError';
87
+ }
88
+ }
89
+ exports.UnsupportedAlgorithmError = UnsupportedAlgorithmError;
@@ -0,0 +1,9 @@
1
+ import type { CryptoInput } from './typings/inputs.js';
2
+ /**
3
+ * Normalizes accepted input into a fresh Buffer of bytes.
4
+ *
5
+ * @param input - String (UTF-8), Buffer or Uint8Array holding the data.
6
+ * @returns A Buffer copy of the input bytes.
7
+ * @throws {InvalidArgumentError} WHEN the input has an unexpected type.
8
+ */
9
+ export declare function toBytes(input: CryptoInput): Buffer;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toBytes = toBytes;
4
+ /**
5
+ * Input handling shared by every namespace.
6
+ *
7
+ * Wherever a function accepts data it accepts `CryptoInput`: a UTF-8
8
+ * string, a Buffer or a Uint8Array. Normalization copies the bytes, so
9
+ * later mutation of a caller-provided view cannot affect the operation.
10
+ */
11
+ const errors_ts_1 = require("./errors.js");
12
+ /**
13
+ * Normalizes accepted input into a fresh Buffer of bytes.
14
+ *
15
+ * @param input - String (UTF-8), Buffer or Uint8Array holding the data.
16
+ * @returns A Buffer copy of the input bytes.
17
+ * @throws {InvalidArgumentError} WHEN the input has an unexpected type.
18
+ */
19
+ function toBytes(input) {
20
+ if (typeof input === 'string') {
21
+ const buffer = Buffer.from(input, 'utf8');
22
+ return buffer;
23
+ }
24
+ if (input instanceof Uint8Array) {
25
+ const buffer = Buffer.from(input);
26
+ return buffer;
27
+ }
28
+ throw new errors_ts_1.InvalidArgumentError('Invalid input: expected a string, Buffer or Uint8Array.');
29
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Loads a peer dependency asynchronously with dynamic `import`.
3
+ *
4
+ * @param specifier - Bare peer specifier to load (for example `bcrypt`).
5
+ * @returns The loaded peer module.
6
+ * @throws {MissingPeerDependencyError} WHEN the peer cannot be resolved.
7
+ */
8
+ export declare function loadPeer(specifier: string): Promise<unknown>;
9
+ /**
10
+ * Loads a peer dependency synchronously with the per-format loader.
11
+ *
12
+ * @param specifier - Bare peer specifier to load (for example `bcrypt`).
13
+ * @returns The loaded peer module.
14
+ * @throws {MissingPeerDependencyError} WHEN the peer cannot be resolved.
15
+ */
16
+ export declare function loadPeerSync(specifier: string): unknown;
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
36
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
37
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
38
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
39
+ });
40
+ }
41
+ return path;
42
+ };
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ exports.loadPeer = loadPeer;
45
+ exports.loadPeerSync = loadPeerSync;
46
+ /**
47
+ * Lazy loading for optional peer dependencies (currently `bcrypt`).
48
+ *
49
+ * Peers load only when an operation needing them is first invoked, so
50
+ * callers without the peer installed can still use every other
51
+ * namespace. Async callers use dynamic `import`; sync callers use the
52
+ * per-format `#sync-require` loader (native `require` in CJS,
53
+ * `createRequire` anchored at the loader file in ESM). A peer that
54
+ * cannot be resolved throws a `MissingPeerDependencyError` naming the
55
+ * package to install; any other load failure propagates unchanged.
56
+ */
57
+ const _sync_require_1 = require("#sync-require");
58
+ const errors_ts_1 = require("./errors.js");
59
+ /**
60
+ * Extracts the Node.js error code from an unknown load failure.
61
+ *
62
+ * @param error - Failure raised while loading the peer.
63
+ * @returns The error code when present, otherwise undefined.
64
+ */
65
+ function errorCodeOf(error) {
66
+ if (typeof error !== 'object' || error === null) {
67
+ return undefined;
68
+ }
69
+ if (!('code' in error)) {
70
+ return undefined;
71
+ }
72
+ const code = error.code;
73
+ return typeof code === 'string' ? code : undefined;
74
+ }
75
+ /**
76
+ * Reports whether a load failure means the peer is not installed.
77
+ *
78
+ * @param error - Failure raised while loading the peer.
79
+ * @returns Whether the peer module could not be resolved.
80
+ */
81
+ function isPeerMissing(error) {
82
+ const code = errorCodeOf(error);
83
+ return code === 'MODULE_NOT_FOUND' || code === 'ERR_MODULE_NOT_FOUND';
84
+ }
85
+ /**
86
+ * Builds the missing-peer error naming the package to install.
87
+ *
88
+ * @param specifier - Bare peer specifier that could not be resolved.
89
+ * @param error - Original resolution failure, kept as `cause`.
90
+ * @returns The missing-peer-dependency error.
91
+ */
92
+ function missingPeerError(specifier, error) {
93
+ return new errors_ts_1.MissingPeerDependencyError(`Optional peer dependency '${specifier}' is not installed. Install '${specifier}' to use this feature.`, { cause: error });
94
+ }
95
+ /**
96
+ * Loads a peer dependency asynchronously with dynamic `import`.
97
+ *
98
+ * @param specifier - Bare peer specifier to load (for example `bcrypt`).
99
+ * @returns The loaded peer module.
100
+ * @throws {MissingPeerDependencyError} WHEN the peer cannot be resolved.
101
+ */
102
+ function loadPeer(specifier) {
103
+ const peer = Promise.resolve(`${__rewriteRelativeImportExtension(specifier)}`).then(s => __importStar(require(s))).catch((error) => {
104
+ if (isPeerMissing(error)) {
105
+ throw missingPeerError(specifier, error);
106
+ }
107
+ throw error;
108
+ });
109
+ return peer;
110
+ }
111
+ /**
112
+ * Loads a peer dependency synchronously with the per-format loader.
113
+ *
114
+ * @param specifier - Bare peer specifier to load (for example `bcrypt`).
115
+ * @returns The loaded peer module.
116
+ * @throws {MissingPeerDependencyError} WHEN the peer cannot be resolved.
117
+ */
118
+ function loadPeerSync(specifier) {
119
+ try {
120
+ const peer = (0, _sync_require_1.loadSyncPeer)(specifier);
121
+ return peer;
122
+ }
123
+ catch (error) {
124
+ if (isPeerMissing(error)) {
125
+ throw missingPeerError(specifier, error);
126
+ }
127
+ throw error;
128
+ }
129
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Synchronous peer loader for CommonJS callers.
3
+ *
4
+ * This file is compiled only in the CJS build and the typecheck program
5
+ * (see the `#sync-require` mapping and the per-build `exclude` lists).
6
+ * The module-scoped `require` resolves the peer relative to this file.
7
+ *
8
+ * @param specifier - Bare peer specifier to load (for example `bcrypt`).
9
+ * @returns The loaded peer module.
10
+ */
11
+ export declare function loadSyncPeer(specifier: string): unknown;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadSyncPeer = loadSyncPeer;
4
+ /**
5
+ * Synchronous peer loader for CommonJS callers.
6
+ *
7
+ * This file is compiled only in the CJS build and the typecheck program
8
+ * (see the `#sync-require` mapping and the per-build `exclude` lists).
9
+ * The module-scoped `require` resolves the peer relative to this file.
10
+ *
11
+ * @param specifier - Bare peer specifier to load (for example `bcrypt`).
12
+ * @returns The loaded peer module.
13
+ */
14
+ function loadSyncPeer(specifier) {
15
+ // eslint-disable-next-line @typescript-eslint/no-require-imports -- this per-format file ships only in the CJS build, where require is the correct loader
16
+ const peer = require(specifier);
17
+ return peer;
18
+ }
@@ -0,0 +1,2 @@
1
+ /** Text encodings the library reads and writes. */
2
+ export type Encoding = 'hex' | 'base64' | 'base64url';
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Stable string codes identifying every failure of the library. Codes
3
+ * are part of the public contract: never rename or remove one without
4
+ * a major release.
5
+ */
6
+ export type ErrorCode =
7
+ | 'INVALID_ARGUMENT'
8
+ | 'INVALID_ENCODING'
9
+ | 'MISSING_PEER_DEPENDENCY'
10
+ | 'UNSUPPORTED_ALGORITHM';
@@ -0,0 +1,2 @@
1
+ /** Data accepted wherever a function takes input bytes. */
2
+ export type CryptoInput = string | Buffer | Uint8Array;
@@ -0,0 +1,6 @@
1
+ {
2
+ "type": "module",
3
+ "imports": {
4
+ "#sync-require": "./shared/require-sync-esm.js"
5
+ }
6
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Temporary scaffolding for the repository-tooling change.
3
+ * The real implementation lands in a later change.
4
+ */
5
+ export declare const namespace: string;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Temporary scaffolding for the repository-tooling change.
3
+ * The real implementation lands in a later change.
4
+ */
5
+ export const namespace = 'comparison';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Temporary scaffolding for the repository-tooling change.
3
+ * The real implementation lands in a later change.
4
+ */
5
+ export declare const namespace: string;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Temporary scaffolding for the repository-tooling change.
3
+ * The real implementation lands in a later change.
4
+ */
5
+ export const namespace = 'digest';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Temporary scaffolding for the repository-tooling change.
3
+ * The real implementation lands in a later change.
4
+ */
5
+ export declare const namespace: string;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Temporary scaffolding for the repository-tooling change.
3
+ * The real implementation lands in a later change.
4
+ */
5
+ export const namespace = 'encryption';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Temporary scaffolding for the repository-tooling change.
3
+ * The real implementation lands in a later change.
4
+ */
5
+ export declare const namespace: string;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Temporary scaffolding for the repository-tooling change.
3
+ * The real implementation lands in a later change.
4
+ */
5
+ export const namespace = 'key-derivation';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Temporary scaffolding for the repository-tooling change.
3
+ * The real implementation lands in a later change.
4
+ */
5
+ export declare const namespace: string;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Temporary scaffolding for the repository-tooling change.
3
+ * The real implementation lands in a later change.
4
+ */
5
+ export const namespace = 'message-authentication';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Temporary scaffolding for the repository-tooling change.
3
+ * The real implementation lands in a later change.
4
+ */
5
+ export declare const namespace: string;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Temporary scaffolding for the repository-tooling change.
3
+ * The real implementation lands in a later change.
4
+ */
5
+ export const namespace = 'password-hashing';
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Temporary scaffolding for the repository-tooling change.
3
+ * The real implementation lands in a later change.
4
+ */
5
+ export declare const namespace: string;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Temporary scaffolding for the repository-tooling change.
3
+ * The real implementation lands in a later change.
4
+ */
5
+ export const namespace = 'random';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Asserts the received identifier is one of the supported identifiers.
3
+ *
4
+ * @param algorithm - Identifier passed by the caller.
5
+ * @param supported - Identifiers the calling function supports.
6
+ * @throws {UnsupportedAlgorithmError} WHEN the identifier is unsupported.
7
+ */
8
+ export declare function assertSupportedAlgorithm(algorithm: string, supported: readonly string[]): void;