@digitaldefiance/secrets 2.0.3
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/LICENSE +8 -0
- package/README.md +445 -0
- package/dist/.tsbuildinfo +1 -0
- package/dist/browser-types.d.ts +112 -0
- package/dist/browser-types.d.ts.map +1 -0
- package/dist/browser-types.js +242 -0
- package/dist/browser-types.js.map +1 -0
- package/dist/errors.d.ts +33 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +92 -0
- package/dist/errors.js.map +1 -0
- package/dist/esm/.tsbuildinfo +1 -0
- package/dist/esm/browser-types.d.ts +112 -0
- package/dist/esm/browser-types.d.ts.map +1 -0
- package/dist/esm/browser-types.js +201 -0
- package/dist/esm/browser-types.js.map +1 -0
- package/dist/esm/errors.d.ts +33 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/errors.js +54 -0
- package/dist/esm/errors.js.map +1 -0
- package/dist/esm/node-types.d.ts +87 -0
- package/dist/esm/node-types.d.ts.map +1 -0
- package/dist/esm/node-types.js +157 -0
- package/dist/esm/node-types.js.map +1 -0
- package/dist/esm/secrets.d.ts +262 -0
- package/dist/esm/secrets.d.ts.map +1 -0
- package/dist/esm/secrets.js +894 -0
- package/dist/esm/secrets.js.map +1 -0
- package/dist/esm/types.d.ts +249 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +61 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/validation.d.ts +34 -0
- package/dist/esm/validation.d.ts.map +1 -0
- package/dist/esm/validation.js +72 -0
- package/dist/esm/validation.js.map +1 -0
- package/dist/node-types.d.ts +87 -0
- package/dist/node-types.d.ts.map +1 -0
- package/dist/node-types.js +191 -0
- package/dist/node-types.js.map +1 -0
- package/dist/secrets.d.ts +262 -0
- package/dist/secrets.d.ts.map +1 -0
- package/dist/secrets.js +897 -0
- package/dist/secrets.js.map +1 -0
- package/dist/types.d.ts +249 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +67 -0
- package/dist/types.js.map +1 -0
- package/dist/umd/.tsbuildinfo +1 -0
- package/dist/umd/browser-types.d.ts +112 -0
- package/dist/umd/browser-types.d.ts.map +1 -0
- package/dist/umd/browser-types.js +252 -0
- package/dist/umd/browser-types.js.map +1 -0
- package/dist/umd/errors.d.ts +33 -0
- package/dist/umd/errors.d.ts.map +1 -0
- package/dist/umd/errors.js +102 -0
- package/dist/umd/errors.js.map +1 -0
- package/dist/umd/node-types.d.ts +87 -0
- package/dist/umd/node-types.d.ts.map +1 -0
- package/dist/umd/node-types.js +201 -0
- package/dist/umd/node-types.js.map +1 -0
- package/dist/umd/secrets.d.ts +262 -0
- package/dist/umd/secrets.d.ts.map +1 -0
- package/dist/umd/secrets.js +907 -0
- package/dist/umd/secrets.js.map +1 -0
- package/dist/umd/secrets.min.js +2 -0
- package/dist/umd/types.d.ts +249 -0
- package/dist/umd/types.d.ts.map +1 -0
- package/dist/umd/types.js +77 -0
- package/dist/umd/types.js.map +1 -0
- package/dist/umd/validation.d.ts +34 -0
- package/dist/umd/validation.d.ts.map +1 -0
- package/dist/umd/validation.js +92 -0
- package/dist/umd/validation.js.map +1 -0
- package/dist/validation.d.ts +34 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +82 -0
- package/dist/validation.js.map +1 -0
- package/package.json +181 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-types.js","sourceRoot":"","sources":["../../src/node-types.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,qFAAqF;AAGrF,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AA2BvC;;GAEG;AACH,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,QAAQ;QACzB,QAAQ,IAAI,KAAK;QACjB,OAAQ,KAAa,CAAC,SAAS,KAAK,UAAU,CAAC;AACxD,CAAC;AAED,+EAA+E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,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import type { BinaryString, CSPRNGType, HexString, RNGFunction, SecretsConfig, Share, ShareComponents, Shares } from './types';
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
secrets: typeof SecretsLibrary;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
declare function reset(): void;
|
|
8
|
+
declare function isSetRNG(): boolean;
|
|
9
|
+
declare function padLeft(str: string, multipleOfBits?: number): string;
|
|
10
|
+
declare function hex2bin(str: string): BinaryString;
|
|
11
|
+
declare function bin2hex(str: BinaryString): HexString;
|
|
12
|
+
declare function bytesToHex(bytes: Uint8Array | Buffer): HexString;
|
|
13
|
+
declare function hasCryptoGetRandomValues(): boolean;
|
|
14
|
+
declare function hasCryptoRandomBytes(): boolean;
|
|
15
|
+
declare function getRNG(type?: CSPRNGType): RNGFunction | undefined;
|
|
16
|
+
declare function splitNumStringToIntArray(str: string, padLength?: number): number[];
|
|
17
|
+
declare function horner(x: number, coeffs: number[]): number;
|
|
18
|
+
declare function lagrange(at: number, x: number[], y: number[]): number;
|
|
19
|
+
declare function getShares(secret: number, numShares: number, threshold: number): Share[];
|
|
20
|
+
declare function constructPublicShareString(bits: number | string, id: number | string, data: string): string;
|
|
21
|
+
declare const SecretsLibrary: {
|
|
22
|
+
/**
|
|
23
|
+
* Initialize the secrets library with specified bit length and RNG type.
|
|
24
|
+
*
|
|
25
|
+
* This function sets up the Galois Field arithmetic tables (logs and exps)
|
|
26
|
+
* required for Shamir's Secret Sharing. It must be called before using
|
|
27
|
+
* share() or combine() operations.
|
|
28
|
+
*
|
|
29
|
+
* @param bits - Number of bits for the Galois Field (between 3 and 20, default 8).
|
|
30
|
+
* Determines the maximum number of shares (2^bits - 1).
|
|
31
|
+
* @param rngType - Type of cryptographically secure random number generator to use.
|
|
32
|
+
* If not specified, automatically detects the best available CSPRNG.
|
|
33
|
+
* @throws {Error} If bits is not an integer between 3 and 20, inclusive.
|
|
34
|
+
* @throws {Error} If rngType is invalid or RNG initialization fails.
|
|
35
|
+
* @throws {Error} If initialization fails for any reason.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* // Initialize with default 8 bits (max 255 shares)
|
|
40
|
+
* secrets.init();
|
|
41
|
+
*
|
|
42
|
+
* // Initialize with 10 bits (max 1023 shares)
|
|
43
|
+
* secrets.init(10);
|
|
44
|
+
*
|
|
45
|
+
* // Initialize with specific RNG type
|
|
46
|
+
* secrets.init(8, 'nodeCryptoRandomBytes');
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
init(bits?: number, rngType?: CSPRNGType): void;
|
|
50
|
+
/**
|
|
51
|
+
* Combine shares to reconstruct the original secret.
|
|
52
|
+
*
|
|
53
|
+
* Uses Lagrange interpolation to reconstruct the secret from a threshold
|
|
54
|
+
* number of shares. The shares must have been created with the same bit
|
|
55
|
+
* configuration.
|
|
56
|
+
*
|
|
57
|
+
* @param shares - Array of share strings to combine. Must contain at least
|
|
58
|
+
* the threshold number of shares used during secret creation.
|
|
59
|
+
* @param at - Point at which to evaluate the polynomial (default 0 for secret recovery).
|
|
60
|
+
* Use non-zero values to generate new shares.
|
|
61
|
+
* @returns The reconstructed secret as a hexadecimal string.
|
|
62
|
+
* @throws {Error} If shares have mismatched bit settings.
|
|
63
|
+
* @throws {Error} If share format is invalid.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const shares = secrets.share('deadbeef', 5, 3);
|
|
68
|
+
* const secret = secrets.combine(shares.slice(0, 3));
|
|
69
|
+
* console.log(secret); // 'deadbeef'
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
combine(shares: Shares | string[], at?: number): string;
|
|
73
|
+
/**
|
|
74
|
+
* Get the current configuration of the secrets library.
|
|
75
|
+
*
|
|
76
|
+
* Returns information about the current Galois Field configuration,
|
|
77
|
+
* including bit length, radix, maximum shares, and RNG status.
|
|
78
|
+
*
|
|
79
|
+
* @returns Configuration object with current settings.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const config = secrets.getConfig();
|
|
84
|
+
* console.log(`Max shares: ${config.maxShares}`);
|
|
85
|
+
* console.log(`Has CSPRNG: ${config.hasCSPRNG}`);
|
|
86
|
+
* console.log(`RNG Type: ${config.typeCSPRNG}`);
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
getConfig(): SecretsConfig;
|
|
90
|
+
/**
|
|
91
|
+
* Extract the components from a public share string.
|
|
92
|
+
*
|
|
93
|
+
* Parses a share string to extract the bit configuration, share ID,
|
|
94
|
+
* and share data. Useful for inspecting shares or validating share format.
|
|
95
|
+
*
|
|
96
|
+
* @param share - The share string to parse.
|
|
97
|
+
* @returns Object containing bits, id, and data components.
|
|
98
|
+
* @throws {Error} If share format is invalid.
|
|
99
|
+
* @throws {Error} If share ID is out of valid range.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```typescript
|
|
103
|
+
* const shares = secrets.share('abc123', 5, 3);
|
|
104
|
+
* const components = secrets.extractShareComponents(shares[0]);
|
|
105
|
+
* console.log(`Bits: ${components.bits}`);
|
|
106
|
+
* console.log(`ID: ${components.id}`);
|
|
107
|
+
* console.log(`Data: ${components.data}`);
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
extractShareComponents(share: string): ShareComponents;
|
|
111
|
+
/**
|
|
112
|
+
* Set the random number generator to use for share generation.
|
|
113
|
+
*
|
|
114
|
+
* Allows specifying a custom RNG or selecting a specific CSPRNG type.
|
|
115
|
+
* If no argument is provided, automatically detects and uses the best
|
|
116
|
+
* available CSPRNG for the current environment.
|
|
117
|
+
*
|
|
118
|
+
* @param rng - Either a CSPRNG type string or a custom RNG function.
|
|
119
|
+
* Custom functions must return a binary string of specified length.
|
|
120
|
+
* @returns True if RNG was successfully set.
|
|
121
|
+
* @throws {Error} If RNG type is invalid.
|
|
122
|
+
* @throws {Error} If custom RNG function fails validation tests.
|
|
123
|
+
*
|
|
124
|
+
* @example
|
|
125
|
+
* ```typescript
|
|
126
|
+
* // Use specific CSPRNG type
|
|
127
|
+
* secrets.setRNG('nodeCryptoRandomBytes');
|
|
128
|
+
*
|
|
129
|
+
* // Use custom RNG function
|
|
130
|
+
* secrets.setRNG((bits) => {
|
|
131
|
+
* // Return binary string of specified length
|
|
132
|
+
* return customRandomBits(bits);
|
|
133
|
+
* });
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
setRNG(rng?: CSPRNGType | RNGFunction): boolean;
|
|
137
|
+
/**
|
|
138
|
+
* Convert a UTF-16 string to hexadecimal representation.
|
|
139
|
+
*
|
|
140
|
+
* Each character is represented by bytesPerChar bytes in the output.
|
|
141
|
+
* Useful for converting text secrets to hex format before sharing.
|
|
142
|
+
*
|
|
143
|
+
* @param str - The string to convert to hexadecimal.
|
|
144
|
+
* @param bytesPerChar - Number of bytes per character (1-6, default 2).
|
|
145
|
+
* Higher values support larger character codes.
|
|
146
|
+
* @returns Hexadecimal string representation.
|
|
147
|
+
* @throws {Error} If input is not a string.
|
|
148
|
+
* @throws {Error} If bytesPerChar is not an integer between 1 and 6.
|
|
149
|
+
* @throws {Error} If character code exceeds maximum for bytesPerChar.
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* const hex = secrets.str2hex('Hello');
|
|
154
|
+
* const shares = secrets.share(hex, 5, 3);
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
str2hex(str: string, bytesPerChar?: number): HexString;
|
|
158
|
+
/**
|
|
159
|
+
* Convert a hexadecimal string to UTF-16 string representation.
|
|
160
|
+
*
|
|
161
|
+
* Reverses the str2hex operation. Each bytesPerChar bytes in the input
|
|
162
|
+
* represents one character in the output.
|
|
163
|
+
*
|
|
164
|
+
* @param str - The hexadecimal string to convert.
|
|
165
|
+
* @param bytesPerChar - Number of bytes per character (1-6, default 2).
|
|
166
|
+
* Must match the value used in str2hex.
|
|
167
|
+
* @returns UTF-16 string representation.
|
|
168
|
+
* @throws {Error} If input is not a hexadecimal string.
|
|
169
|
+
* @throws {Error} If bytesPerChar is not an integer between 1 and 6.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* const shares = secrets.share(secrets.str2hex('Hello'), 5, 3);
|
|
174
|
+
* const recovered = secrets.hex2str(secrets.combine(shares));
|
|
175
|
+
* console.log(recovered); // 'Hello'
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
hex2str(str: string, bytesPerChar?: number): string;
|
|
179
|
+
/**
|
|
180
|
+
* Generate a random hexadecimal string of specified bit length.
|
|
181
|
+
*
|
|
182
|
+
* Uses the configured CSPRNG to generate cryptographically secure
|
|
183
|
+
* random numbers. Useful for generating random secrets.
|
|
184
|
+
*
|
|
185
|
+
* @param bits - Number of random bits to generate (2-65536).
|
|
186
|
+
* @returns Random hexadecimal string.
|
|
187
|
+
* @throws {Error} If bits is not an integer between 2 and 65536.
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* const randomSecret = secrets.random(128);
|
|
192
|
+
* const shares = secrets.share(randomSecret, 5, 3);
|
|
193
|
+
* ```
|
|
194
|
+
*/
|
|
195
|
+
random(bits: number): HexString;
|
|
196
|
+
/**
|
|
197
|
+
* Split a secret into shares using Shamir's Secret Sharing.
|
|
198
|
+
*
|
|
199
|
+
* Creates numShares shares such that any threshold number of shares
|
|
200
|
+
* can reconstruct the original secret, but fewer shares reveal no
|
|
201
|
+
* information about the secret.
|
|
202
|
+
*
|
|
203
|
+
* @param secret - The secret to split, as a hexadecimal string.
|
|
204
|
+
* @param numShares - Total number of shares to generate (2 to 2^bits-1).
|
|
205
|
+
* @param threshold - Minimum number of shares needed to reconstruct (2 to numShares).
|
|
206
|
+
* @param padLength - Zero-pad the secret to a multiple of this length (0-1024, default 128).
|
|
207
|
+
* @returns Array of share strings.
|
|
208
|
+
* @throws {Error} If secret is not a string.
|
|
209
|
+
* @throws {Error} If numShares or threshold are invalid.
|
|
210
|
+
* @throws {Error} If threshold exceeds numShares.
|
|
211
|
+
* @throws {Error} If padLength is invalid.
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```typescript
|
|
215
|
+
* // Split a hex secret into 5 shares, requiring 3 to reconstruct
|
|
216
|
+
* const shares = secrets.share('deadbeef', 5, 3);
|
|
217
|
+
*
|
|
218
|
+
* // Any 3 shares can reconstruct the secret
|
|
219
|
+
* const recovered = secrets.combine([shares[0], shares[2], shares[4]]);
|
|
220
|
+
* console.log(recovered); // 'deadbeef'
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
share(secret: string, numShares: number, threshold: number, padLength?: number): string[];
|
|
224
|
+
/**
|
|
225
|
+
* Generate a new share with a specific ID from existing shares.
|
|
226
|
+
*
|
|
227
|
+
* Uses Lagrange interpolation to create a new share at the specified
|
|
228
|
+
* ID point. Useful for generating additional shares without access to
|
|
229
|
+
* the original secret.
|
|
230
|
+
*
|
|
231
|
+
* @param id - The ID for the new share (1 to 2^bits-1).
|
|
232
|
+
* @param shares - Array of existing shares (at least threshold number).
|
|
233
|
+
* @returns New share string with the specified ID.
|
|
234
|
+
* @throws {Error} If id is invalid.
|
|
235
|
+
* @throws {Error} If shares array is invalid or empty.
|
|
236
|
+
*
|
|
237
|
+
* @example
|
|
238
|
+
* ```typescript
|
|
239
|
+
* const shares = secrets.share('abc123', 5, 3);
|
|
240
|
+
* // Generate a new share with ID 10
|
|
241
|
+
* const newShare = secrets.newShare(10, shares.slice(0, 3));
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
newShare(id: number | string, shares: Shares | string[]): string;
|
|
245
|
+
_reset: typeof reset;
|
|
246
|
+
_padLeft: typeof padLeft;
|
|
247
|
+
_hex2bin: typeof hex2bin;
|
|
248
|
+
_bin2hex: typeof bin2hex;
|
|
249
|
+
_bytesToHex: typeof bytesToHex;
|
|
250
|
+
_hasCryptoGetRandomValues: typeof hasCryptoGetRandomValues;
|
|
251
|
+
_hasCryptoRandomBytes: typeof hasCryptoRandomBytes;
|
|
252
|
+
_getRNG: typeof getRNG;
|
|
253
|
+
_isSetRNG: typeof isSetRNG;
|
|
254
|
+
_splitNumStringToIntArray: typeof splitNumStringToIntArray;
|
|
255
|
+
_horner: typeof horner;
|
|
256
|
+
_lagrange: typeof lagrange;
|
|
257
|
+
_getShares: typeof getShares;
|
|
258
|
+
_constructPublicShareString: typeof constructPublicShareString;
|
|
259
|
+
};
|
|
260
|
+
export default SecretsLibrary;
|
|
261
|
+
export declare const init: (bits?: number, rngType?: CSPRNGType) => void, combine: (shares: Shares | string[], at?: number) => string, getConfig: () => SecretsConfig, extractShareComponents: (share: string) => ShareComponents, setRNG: (rng?: CSPRNGType | RNGFunction) => boolean, str2hex: (str: string, bytesPerChar?: number) => HexString, hex2str: (str: string, bytesPerChar?: number) => string, random: (bits: number) => HexString, share: (secret: string, numShares: number, threshold: number, padLength?: number) => string[], newShare: (id: number | string, shares: Shares | string[]) => string;
|
|
262
|
+
//# sourceMappingURL=secrets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"secrets.d.ts","sourceRoot":"","sources":["../../src/secrets.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAER,YAAY,EACZ,UAAU,EAEV,SAAS,EAET,WAAW,EACX,aAAa,EACb,KAAK,EACL,eAAe,EACf,MAAM,EACT,MAAM,SAAS,CAAC;AAGjB,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd,OAAO,EAAE,OAAO,cAAc,CAAC;KAChC;CACF;AAiBD,iBAAS,KAAK,IAAI,IAAI,CAiCrB;AAED,iBAAS,QAAQ,IAAI,OAAO,CAK3B;AAMD,iBAAS,OAAO,CAA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