@bcts/sskr 1.0.0-alpha.5

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/dist/index.mjs ADDED
@@ -0,0 +1,490 @@
1
+ import { MAX_SECRET_LEN as MAX_SECRET_LEN$1, MAX_SHARE_COUNT as MAX_SHARE_COUNT$1, MIN_SECRET_LEN as MIN_SECRET_LEN$1, ShamirError, recoverSecret, splitSecret } from "@bcts/shamir";
2
+ import { SecureRandomNumberGenerator } from "@bcts/rand";
3
+
4
+ //#region src/error.ts
5
+ /**
6
+ * Error types for SSKR operations.
7
+ */
8
+ let SSKRErrorType = /* @__PURE__ */ function(SSKRErrorType$1) {
9
+ SSKRErrorType$1["DuplicateMemberIndex"] = "DuplicateMemberIndex";
10
+ SSKRErrorType$1["GroupSpecInvalid"] = "GroupSpecInvalid";
11
+ SSKRErrorType$1["GroupCountInvalid"] = "GroupCountInvalid";
12
+ SSKRErrorType$1["GroupThresholdInvalid"] = "GroupThresholdInvalid";
13
+ SSKRErrorType$1["MemberCountInvalid"] = "MemberCountInvalid";
14
+ SSKRErrorType$1["MemberThresholdInvalid"] = "MemberThresholdInvalid";
15
+ SSKRErrorType$1["NotEnoughGroups"] = "NotEnoughGroups";
16
+ SSKRErrorType$1["SecretLengthNotEven"] = "SecretLengthNotEven";
17
+ SSKRErrorType$1["SecretTooLong"] = "SecretTooLong";
18
+ SSKRErrorType$1["SecretTooShort"] = "SecretTooShort";
19
+ SSKRErrorType$1["ShareLengthInvalid"] = "ShareLengthInvalid";
20
+ SSKRErrorType$1["ShareReservedBitsInvalid"] = "ShareReservedBitsInvalid";
21
+ SSKRErrorType$1["SharesEmpty"] = "SharesEmpty";
22
+ SSKRErrorType$1["ShareSetInvalid"] = "ShareSetInvalid";
23
+ SSKRErrorType$1["ShamirError"] = "ShamirError";
24
+ return SSKRErrorType$1;
25
+ }({});
26
+ /**
27
+ * Error class for SSKR operations.
28
+ */
29
+ var SSKRError = class SSKRError extends Error {
30
+ type;
31
+ shamirError;
32
+ constructor(type, message, shamirError) {
33
+ super(message ?? SSKRError.defaultMessage(type, shamirError));
34
+ this.type = type;
35
+ this.shamirError = shamirError;
36
+ this.name = "SSKRError";
37
+ }
38
+ static defaultMessage(type, shamirError) {
39
+ switch (type) {
40
+ case SSKRErrorType.DuplicateMemberIndex: return "When combining shares, the provided shares contained a duplicate member index";
41
+ case SSKRErrorType.GroupSpecInvalid: return "Invalid group specification";
42
+ case SSKRErrorType.GroupCountInvalid: return "When creating a split spec, the group count is invalid";
43
+ case SSKRErrorType.GroupThresholdInvalid: return "SSKR group threshold is invalid";
44
+ case SSKRErrorType.MemberCountInvalid: return "SSKR member count is invalid";
45
+ case SSKRErrorType.MemberThresholdInvalid: return "SSKR member threshold is invalid";
46
+ case SSKRErrorType.NotEnoughGroups: return "SSKR shares did not contain enough groups";
47
+ case SSKRErrorType.SecretLengthNotEven: return "SSKR secret is not of even length";
48
+ case SSKRErrorType.SecretTooLong: return "SSKR secret is too long";
49
+ case SSKRErrorType.SecretTooShort: return "SSKR secret is too short";
50
+ case SSKRErrorType.ShareLengthInvalid: return "SSKR shares did not contain enough serialized bytes";
51
+ case SSKRErrorType.ShareReservedBitsInvalid: return "SSKR shares contained invalid reserved bits";
52
+ case SSKRErrorType.SharesEmpty: return "SSKR shares were empty";
53
+ case SSKRErrorType.ShareSetInvalid: return "SSKR shares were invalid";
54
+ case SSKRErrorType.ShamirError: return shamirError != null ? `SSKR Shamir error: ${shamirError.message}` : "SSKR Shamir error";
55
+ }
56
+ }
57
+ static fromShamirError(error) {
58
+ return new SSKRError(SSKRErrorType.ShamirError, void 0, error);
59
+ }
60
+ };
61
+
62
+ //#endregion
63
+ //#region src/secret.ts
64
+ /**
65
+ * A secret to be split into shares.
66
+ */
67
+ var Secret = class Secret {
68
+ data;
69
+ constructor(data) {
70
+ this.data = data;
71
+ }
72
+ /**
73
+ * Creates a new Secret instance with the given data.
74
+ *
75
+ * @param data - The secret data to be split into shares.
76
+ * @returns A new Secret instance.
77
+ * @throws SSKRError if the length of the secret is less than
78
+ * MIN_SECRET_LEN, greater than MAX_SECRET_LEN, or not even.
79
+ */
80
+ static new(data) {
81
+ const bytes = typeof data === "string" ? new TextEncoder().encode(data) : data;
82
+ const len = bytes.length;
83
+ if (len < MIN_SECRET_LEN) throw new SSKRError(SSKRErrorType.SecretTooShort);
84
+ if (len > MAX_SECRET_LEN) throw new SSKRError(SSKRErrorType.SecretTooLong);
85
+ if ((len & 1) !== 0) throw new SSKRError(SSKRErrorType.SecretLengthNotEven);
86
+ return new Secret(new Uint8Array(bytes));
87
+ }
88
+ /**
89
+ * Returns the length of the secret.
90
+ */
91
+ len() {
92
+ return this.data.length;
93
+ }
94
+ /**
95
+ * Returns true if the secret is empty.
96
+ */
97
+ isEmpty() {
98
+ return this.len() === 0;
99
+ }
100
+ /**
101
+ * Returns a reference to the secret data.
102
+ */
103
+ getData() {
104
+ return this.data;
105
+ }
106
+ /**
107
+ * Returns the secret data as a Uint8Array.
108
+ */
109
+ asRef() {
110
+ return this.data;
111
+ }
112
+ /**
113
+ * Check equality with another Secret.
114
+ */
115
+ equals(other) {
116
+ if (this.data.length !== other.data.length) return false;
117
+ for (let i = 0; i < this.data.length; i++) if (this.data[i] !== other.data[i]) return false;
118
+ return true;
119
+ }
120
+ /**
121
+ * Clone the secret.
122
+ */
123
+ clone() {
124
+ return new Secret(new Uint8Array(this.data));
125
+ }
126
+ };
127
+
128
+ //#endregion
129
+ //#region src/spec.ts
130
+ /**
131
+ * A specification for a group of shares within an SSKR split.
132
+ */
133
+ var GroupSpec = class GroupSpec {
134
+ _memberThreshold;
135
+ _memberCount;
136
+ constructor(memberThreshold, memberCount) {
137
+ this._memberThreshold = memberThreshold;
138
+ this._memberCount = memberCount;
139
+ }
140
+ /**
141
+ * Creates a new GroupSpec instance with the given member threshold and count.
142
+ *
143
+ * @param memberThreshold - The minimum number of member shares required to
144
+ * reconstruct the secret within the group.
145
+ * @param memberCount - The total number of member shares in the group.
146
+ * @returns A new GroupSpec instance.
147
+ * @throws SSKRError if the member count is zero, if the member count is
148
+ * greater than the maximum share count, or if the member threshold is
149
+ * greater than the member count.
150
+ */
151
+ static new(memberThreshold, memberCount) {
152
+ if (memberCount === 0) throw new SSKRError(SSKRErrorType.MemberCountInvalid);
153
+ if (memberCount > MAX_SHARE_COUNT$1) throw new SSKRError(SSKRErrorType.MemberCountInvalid);
154
+ if (memberThreshold > memberCount) throw new SSKRError(SSKRErrorType.MemberThresholdInvalid);
155
+ return new GroupSpec(memberThreshold, memberCount);
156
+ }
157
+ /**
158
+ * Returns the member share threshold for this group.
159
+ */
160
+ memberThreshold() {
161
+ return this._memberThreshold;
162
+ }
163
+ /**
164
+ * Returns the number of member shares in this group.
165
+ */
166
+ memberCount() {
167
+ return this._memberCount;
168
+ }
169
+ /**
170
+ * Parses a group specification from a string.
171
+ * Format: "M-of-N" where M is the threshold and N is the count.
172
+ */
173
+ static parse(s) {
174
+ const parts = s.split("-");
175
+ if (parts.length !== 3) throw new SSKRError(SSKRErrorType.GroupSpecInvalid);
176
+ const memberThreshold = parseInt(parts[0], 10);
177
+ if (isNaN(memberThreshold)) throw new SSKRError(SSKRErrorType.GroupSpecInvalid);
178
+ if (parts[1] !== "of") throw new SSKRError(SSKRErrorType.GroupSpecInvalid);
179
+ const memberCount = parseInt(parts[2], 10);
180
+ if (isNaN(memberCount)) throw new SSKRError(SSKRErrorType.GroupSpecInvalid);
181
+ return GroupSpec.new(memberThreshold, memberCount);
182
+ }
183
+ /**
184
+ * Creates a default GroupSpec (1-of-1).
185
+ */
186
+ static default() {
187
+ return GroupSpec.new(1, 1);
188
+ }
189
+ /**
190
+ * Returns a string representation of the group spec.
191
+ */
192
+ toString() {
193
+ return `${this._memberThreshold}-of-${this._memberCount}`;
194
+ }
195
+ };
196
+ /**
197
+ * A specification for an SSKR split.
198
+ */
199
+ var Spec = class Spec {
200
+ _groupThreshold;
201
+ _groups;
202
+ constructor(groupThreshold, groups) {
203
+ this._groupThreshold = groupThreshold;
204
+ this._groups = groups;
205
+ }
206
+ /**
207
+ * Creates a new Spec instance with the given group threshold and groups.
208
+ *
209
+ * @param groupThreshold - The minimum number of groups required to
210
+ * reconstruct the secret.
211
+ * @param groups - The list of GroupSpec instances that define the groups
212
+ * and their members.
213
+ * @returns A new Spec instance.
214
+ * @throws SSKRError if the group threshold is zero, if the group threshold
215
+ * is greater than the number of groups, or if the number of groups is
216
+ * greater than the maximum share count.
217
+ */
218
+ static new(groupThreshold, groups) {
219
+ if (groupThreshold === 0) throw new SSKRError(SSKRErrorType.GroupThresholdInvalid);
220
+ if (groupThreshold > groups.length) throw new SSKRError(SSKRErrorType.GroupThresholdInvalid);
221
+ if (groups.length > MAX_SHARE_COUNT$1) throw new SSKRError(SSKRErrorType.GroupCountInvalid);
222
+ return new Spec(groupThreshold, groups);
223
+ }
224
+ /**
225
+ * Returns the group threshold.
226
+ */
227
+ groupThreshold() {
228
+ return this._groupThreshold;
229
+ }
230
+ /**
231
+ * Returns a slice of the group specifications.
232
+ */
233
+ groups() {
234
+ return this._groups;
235
+ }
236
+ /**
237
+ * Returns the number of groups.
238
+ */
239
+ groupCount() {
240
+ return this._groups.length;
241
+ }
242
+ /**
243
+ * Returns the total number of shares across all groups.
244
+ */
245
+ shareCount() {
246
+ return this._groups.reduce((sum, g) => sum + g.memberCount(), 0);
247
+ }
248
+ };
249
+
250
+ //#endregion
251
+ //#region src/share.ts
252
+ /**
253
+ * A share in the SSKR scheme.
254
+ */
255
+ var SSKRShare = class {
256
+ _identifier;
257
+ _groupIndex;
258
+ _groupThreshold;
259
+ _groupCount;
260
+ _memberIndex;
261
+ _memberThreshold;
262
+ _value;
263
+ constructor(identifier, groupIndex, groupThreshold, groupCount, memberIndex, memberThreshold, value) {
264
+ this._identifier = identifier;
265
+ this._groupIndex = groupIndex;
266
+ this._groupThreshold = groupThreshold;
267
+ this._groupCount = groupCount;
268
+ this._memberIndex = memberIndex;
269
+ this._memberThreshold = memberThreshold;
270
+ this._value = value;
271
+ }
272
+ identifier() {
273
+ return this._identifier;
274
+ }
275
+ groupIndex() {
276
+ return this._groupIndex;
277
+ }
278
+ groupThreshold() {
279
+ return this._groupThreshold;
280
+ }
281
+ groupCount() {
282
+ return this._groupCount;
283
+ }
284
+ memberIndex() {
285
+ return this._memberIndex;
286
+ }
287
+ memberThreshold() {
288
+ return this._memberThreshold;
289
+ }
290
+ value() {
291
+ return this._value;
292
+ }
293
+ };
294
+
295
+ //#endregion
296
+ //#region src/encoding.ts
297
+ /**
298
+ * Generates SSKR shares for the given Spec and Secret.
299
+ *
300
+ * @param spec - The Spec instance that defines the group and member thresholds.
301
+ * @param masterSecret - The Secret instance to be split into shares.
302
+ * @returns A vector of groups, each containing a vector of shares,
303
+ * each of which is a Uint8Array.
304
+ */
305
+ function sskrGenerate(spec, masterSecret) {
306
+ return sskrGenerateUsing(spec, masterSecret, new SecureRandomNumberGenerator());
307
+ }
308
+ /**
309
+ * Generates SSKR shares for the given Spec and Secret using the provided
310
+ * random number generator.
311
+ *
312
+ * @param spec - The Spec instance that defines the group and member thresholds.
313
+ * @param masterSecret - The Secret instance to be split into shares.
314
+ * @param randomGenerator - The random number generator to use for generating
315
+ * shares.
316
+ * @returns A vector of groups, each containing a vector of shares,
317
+ * each of which is a Uint8Array.
318
+ */
319
+ function sskrGenerateUsing(spec, masterSecret, randomGenerator) {
320
+ return generateShares(spec, masterSecret, randomGenerator).map((group) => group.map(serializeShare));
321
+ }
322
+ /**
323
+ * Combines the given SSKR shares into a Secret.
324
+ *
325
+ * @param shares - A array of SSKR shares to be combined.
326
+ * @returns The reconstructed Secret.
327
+ * @throws SSKRError if the shares do not meet the necessary quorum of groups
328
+ * and member shares within each group.
329
+ */
330
+ function sskrCombine(shares) {
331
+ const sskrShares = [];
332
+ for (const share of shares) {
333
+ const sskrShare = deserializeShare(share);
334
+ sskrShares.push(sskrShare);
335
+ }
336
+ return combineShares(sskrShares);
337
+ }
338
+ function serializeShare(share) {
339
+ const valueData = share.value().getData();
340
+ const result = new Uint8Array(valueData.length + METADATA_SIZE_BYTES);
341
+ const id = share.identifier();
342
+ const gt = share.groupThreshold() - 1 & 15;
343
+ const gc = share.groupCount() - 1 & 15;
344
+ const gi = share.groupIndex() & 15;
345
+ const mt = share.memberThreshold() - 1 & 15;
346
+ const mi = share.memberIndex() & 15;
347
+ const id1 = id >> 8;
348
+ const id2 = id & 255;
349
+ result[0] = id1;
350
+ result[1] = id2;
351
+ result[2] = gt << 4 | gc;
352
+ result[3] = gi << 4 | mt;
353
+ result[4] = mi;
354
+ result.set(valueData, METADATA_SIZE_BYTES);
355
+ return result;
356
+ }
357
+ function deserializeShare(source) {
358
+ if (source.length < METADATA_SIZE_BYTES) throw new SSKRError(SSKRErrorType.ShareLengthInvalid);
359
+ const groupThreshold = (source[2] >> 4) + 1;
360
+ const groupCount = (source[2] & 15) + 1;
361
+ if (groupThreshold > groupCount) throw new SSKRError(SSKRErrorType.GroupThresholdInvalid);
362
+ const identifier = source[0] << 8 | source[1];
363
+ const groupIndex = source[3] >> 4;
364
+ const memberThreshold = (source[3] & 15) + 1;
365
+ if (source[4] >> 4 !== 0) throw new SSKRError(SSKRErrorType.ShareReservedBitsInvalid);
366
+ return new SSKRShare(identifier, groupIndex, groupThreshold, groupCount, source[4] & 15, memberThreshold, Secret.new(source.subarray(METADATA_SIZE_BYTES)));
367
+ }
368
+ function generateShares(spec, masterSecret, randomGenerator) {
369
+ const identifierBytes = new Uint8Array(2);
370
+ randomGenerator.fillRandomData(identifierBytes);
371
+ const identifier = identifierBytes[0] << 8 | identifierBytes[1];
372
+ const groupsShares = [];
373
+ let groupSecrets;
374
+ try {
375
+ groupSecrets = splitSecret(spec.groupThreshold(), spec.groupCount(), masterSecret.getData(), randomGenerator);
376
+ } catch (e) {
377
+ if (e instanceof ShamirError) throw SSKRError.fromShamirError(e);
378
+ throw e;
379
+ }
380
+ for (let groupIndex = 0; groupIndex < spec.groups().length; groupIndex++) {
381
+ const group = spec.groups()[groupIndex];
382
+ const groupSecret = groupSecrets[groupIndex];
383
+ let memberSecrets;
384
+ try {
385
+ memberSecrets = splitSecret(group.memberThreshold(), group.memberCount(), groupSecret, randomGenerator);
386
+ } catch (e) {
387
+ if (e instanceof ShamirError) throw SSKRError.fromShamirError(e);
388
+ throw e;
389
+ }
390
+ const memberSSKRShares = memberSecrets.map((memberSecret, memberIndex) => {
391
+ const secret = Secret.new(memberSecret);
392
+ return new SSKRShare(identifier, groupIndex, spec.groupThreshold(), spec.groupCount(), memberIndex, group.memberThreshold(), secret);
393
+ });
394
+ groupsShares.push(memberSSKRShares);
395
+ }
396
+ return groupsShares;
397
+ }
398
+ function combineShares(shares) {
399
+ let identifier = 0;
400
+ let groupThreshold = 0;
401
+ let groupCount = 0;
402
+ if (shares.length === 0) throw new SSKRError(SSKRErrorType.SharesEmpty);
403
+ let nextGroup = 0;
404
+ const groups = [];
405
+ let secretLen = 0;
406
+ for (let i = 0; i < shares.length; i++) {
407
+ const share = shares[i];
408
+ if (i === 0) {
409
+ identifier = share.identifier();
410
+ groupCount = share.groupCount();
411
+ groupThreshold = share.groupThreshold();
412
+ secretLen = share.value().len();
413
+ } else if (share.identifier() !== identifier || share.groupThreshold() !== groupThreshold || share.groupCount() !== groupCount || share.value().len() !== secretLen) throw new SSKRError(SSKRErrorType.ShareSetInvalid);
414
+ let groupFound = false;
415
+ for (const group of groups) if (share.groupIndex() === group.groupIndex) {
416
+ groupFound = true;
417
+ if (share.memberThreshold() !== group.memberThreshold) throw new SSKRError(SSKRErrorType.MemberThresholdInvalid);
418
+ for (const memberIndex of group.memberIndexes) if (share.memberIndex() === memberIndex) throw new SSKRError(SSKRErrorType.DuplicateMemberIndex);
419
+ if (group.memberIndexes.length < group.memberThreshold) {
420
+ group.memberIndexes.push(share.memberIndex());
421
+ group.memberShares.push(share.value().clone());
422
+ }
423
+ }
424
+ if (!groupFound) {
425
+ const g = {
426
+ groupIndex: share.groupIndex(),
427
+ memberThreshold: share.memberThreshold(),
428
+ memberIndexes: [share.memberIndex()],
429
+ memberShares: [share.value().clone()]
430
+ };
431
+ groups.push(g);
432
+ nextGroup++;
433
+ }
434
+ }
435
+ if (nextGroup < groupThreshold) throw new SSKRError(SSKRErrorType.NotEnoughGroups);
436
+ const masterIndexes = [];
437
+ const masterShares = [];
438
+ for (const group of groups) {
439
+ if (group.memberIndexes.length < group.memberThreshold) continue;
440
+ try {
441
+ const memberSharesData = group.memberShares.map((s) => s.getData());
442
+ const groupSecret = recoverSecret(group.memberIndexes, memberSharesData);
443
+ masterIndexes.push(group.groupIndex);
444
+ masterShares.push(groupSecret);
445
+ } catch {
446
+ continue;
447
+ }
448
+ if (masterIndexes.length === groupThreshold) break;
449
+ }
450
+ if (masterIndexes.length < groupThreshold) throw new SSKRError(SSKRErrorType.NotEnoughGroups);
451
+ let masterSecretData;
452
+ try {
453
+ masterSecretData = recoverSecret(masterIndexes, masterShares);
454
+ } catch (e) {
455
+ if (e instanceof ShamirError) throw SSKRError.fromShamirError(e);
456
+ throw e;
457
+ }
458
+ return Secret.new(masterSecretData);
459
+ }
460
+
461
+ //#endregion
462
+ //#region src/index.ts
463
+ /**
464
+ * The minimum length of a secret.
465
+ */
466
+ const MIN_SECRET_LEN = MIN_SECRET_LEN$1;
467
+ /**
468
+ * The maximum length of a secret.
469
+ */
470
+ const MAX_SECRET_LEN = MAX_SECRET_LEN$1;
471
+ /**
472
+ * The maximum number of shares that can be generated from a secret.
473
+ */
474
+ const MAX_SHARE_COUNT = MAX_SHARE_COUNT$1;
475
+ /**
476
+ * The maximum number of groups in a split.
477
+ */
478
+ const MAX_GROUPS_COUNT = MAX_SHARE_COUNT;
479
+ /**
480
+ * The number of bytes used to encode the metadata for a share.
481
+ */
482
+ const METADATA_SIZE_BYTES = 5;
483
+ /**
484
+ * The minimum number of bytes required to encode a share.
485
+ */
486
+ const MIN_SERIALIZE_SIZE_BYTES = METADATA_SIZE_BYTES + MIN_SECRET_LEN;
487
+
488
+ //#endregion
489
+ export { GroupSpec, MAX_GROUPS_COUNT, MAX_SECRET_LEN, MAX_SHARE_COUNT, METADATA_SIZE_BYTES, MIN_SECRET_LEN, MIN_SERIALIZE_SIZE_BYTES, SSKRError, SSKRErrorType, SSKRShare, Secret, Spec, sskrCombine, sskrGenerate, sskrGenerateUsing };
490
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["MAX_SHARE_COUNT","sskrShares: SSKRShare[]","groupsShares: SSKRShare[][]","groupSecrets: Uint8Array[]","memberSecrets: Uint8Array[]","memberSSKRShares: SSKRShare[]","groups: Group[]","g: Group","masterIndexes: number[]","masterShares: Uint8Array[]","masterSecretData: Uint8Array","SHAMIR_MIN_SECRET_LEN","SHAMIR_MAX_SECRET_LEN","SHAMIR_MAX_SHARE_COUNT"],"sources":["../src/error.ts","../src/secret.ts","../src/spec.ts","../src/share.ts","../src/encoding.ts","../src/index.ts"],"sourcesContent":["// Ported from bc-sskr-rust/src/error.rs\n\nimport type { ShamirError } from \"@bcts/shamir\";\n\n/**\n * Error types for SSKR operations.\n */\nexport enum SSKRErrorType {\n DuplicateMemberIndex = \"DuplicateMemberIndex\",\n GroupSpecInvalid = \"GroupSpecInvalid\",\n GroupCountInvalid = \"GroupCountInvalid\",\n GroupThresholdInvalid = \"GroupThresholdInvalid\",\n MemberCountInvalid = \"MemberCountInvalid\",\n MemberThresholdInvalid = \"MemberThresholdInvalid\",\n NotEnoughGroups = \"NotEnoughGroups\",\n SecretLengthNotEven = \"SecretLengthNotEven\",\n SecretTooLong = \"SecretTooLong\",\n SecretTooShort = \"SecretTooShort\",\n ShareLengthInvalid = \"ShareLengthInvalid\",\n ShareReservedBitsInvalid = \"ShareReservedBitsInvalid\",\n SharesEmpty = \"SharesEmpty\",\n ShareSetInvalid = \"ShareSetInvalid\",\n ShamirError = \"ShamirError\",\n}\n\n/**\n * Error class for SSKR operations.\n */\nexport class SSKRError extends Error {\n readonly type: SSKRErrorType;\n readonly shamirError?: ShamirError | undefined;\n\n constructor(type: SSKRErrorType, message?: string, shamirError?: ShamirError) {\n super(message ?? SSKRError.defaultMessage(type, shamirError));\n this.type = type;\n this.shamirError = shamirError;\n this.name = \"SSKRError\";\n }\n\n private static defaultMessage(type: SSKRErrorType, shamirError?: ShamirError): string {\n switch (type) {\n case SSKRErrorType.DuplicateMemberIndex:\n return \"When combining shares, the provided shares contained a duplicate member index\";\n case SSKRErrorType.GroupSpecInvalid:\n return \"Invalid group specification\";\n case SSKRErrorType.GroupCountInvalid:\n return \"When creating a split spec, the group count is invalid\";\n case SSKRErrorType.GroupThresholdInvalid:\n return \"SSKR group threshold is invalid\";\n case SSKRErrorType.MemberCountInvalid:\n return \"SSKR member count is invalid\";\n case SSKRErrorType.MemberThresholdInvalid:\n return \"SSKR member threshold is invalid\";\n case SSKRErrorType.NotEnoughGroups:\n return \"SSKR shares did not contain enough groups\";\n case SSKRErrorType.SecretLengthNotEven:\n return \"SSKR secret is not of even length\";\n case SSKRErrorType.SecretTooLong:\n return \"SSKR secret is too long\";\n case SSKRErrorType.SecretTooShort:\n return \"SSKR secret is too short\";\n case SSKRErrorType.ShareLengthInvalid:\n return \"SSKR shares did not contain enough serialized bytes\";\n case SSKRErrorType.ShareReservedBitsInvalid:\n return \"SSKR shares contained invalid reserved bits\";\n case SSKRErrorType.SharesEmpty:\n return \"SSKR shares were empty\";\n case SSKRErrorType.ShareSetInvalid:\n return \"SSKR shares were invalid\";\n case SSKRErrorType.ShamirError:\n return shamirError != null\n ? `SSKR Shamir error: ${shamirError.message}`\n : \"SSKR Shamir error\";\n }\n }\n\n static fromShamirError(error: ShamirError): SSKRError {\n return new SSKRError(SSKRErrorType.ShamirError, undefined, error);\n }\n}\n\nexport type SSKRResult<T> = T;\n","// Ported from bc-sskr-rust/src/secret.rs\n\nimport { MIN_SECRET_LEN, MAX_SECRET_LEN } from \"./index.js\";\nimport { SSKRError, SSKRErrorType } from \"./error.js\";\n\n/**\n * A secret to be split into shares.\n */\nexport class Secret {\n private readonly data: Uint8Array;\n\n private constructor(data: Uint8Array) {\n this.data = data;\n }\n\n /**\n * Creates a new Secret instance with the given data.\n *\n * @param data - The secret data to be split into shares.\n * @returns A new Secret instance.\n * @throws SSKRError if the length of the secret is less than\n * MIN_SECRET_LEN, greater than MAX_SECRET_LEN, or not even.\n */\n static new(data: Uint8Array | string): Secret {\n const bytes = typeof data === \"string\" ? new TextEncoder().encode(data) : data;\n const len = bytes.length;\n\n if (len < MIN_SECRET_LEN) {\n throw new SSKRError(SSKRErrorType.SecretTooShort);\n }\n if (len > MAX_SECRET_LEN) {\n throw new SSKRError(SSKRErrorType.SecretTooLong);\n }\n if ((len & 1) !== 0) {\n throw new SSKRError(SSKRErrorType.SecretLengthNotEven);\n }\n\n return new Secret(new Uint8Array(bytes));\n }\n\n /**\n * Returns the length of the secret.\n */\n len(): number {\n return this.data.length;\n }\n\n /**\n * Returns true if the secret is empty.\n */\n isEmpty(): boolean {\n return this.len() === 0;\n }\n\n /**\n * Returns a reference to the secret data.\n */\n getData(): Uint8Array {\n return this.data;\n }\n\n /**\n * Returns the secret data as a Uint8Array.\n */\n asRef(): Uint8Array {\n return this.data;\n }\n\n /**\n * Check equality with another Secret.\n */\n equals(other: Secret): boolean {\n if (this.data.length !== other.data.length) {\n return false;\n }\n for (let i = 0; i < this.data.length; i++) {\n if (this.data[i] !== other.data[i]) {\n return false;\n }\n }\n return true;\n }\n\n /**\n * Clone the secret.\n */\n clone(): Secret {\n return new Secret(new Uint8Array(this.data));\n }\n}\n","// Ported from bc-sskr-rust/src/spec.rs\n\nimport { MAX_SHARE_COUNT } from \"@bcts/shamir\";\nimport { SSKRError, SSKRErrorType } from \"./error.js\";\n\n/**\n * A specification for a group of shares within an SSKR split.\n */\nexport class GroupSpec {\n private readonly _memberThreshold: number;\n private readonly _memberCount: number;\n\n private constructor(memberThreshold: number, memberCount: number) {\n this._memberThreshold = memberThreshold;\n this._memberCount = memberCount;\n }\n\n /**\n * Creates a new GroupSpec instance with the given member threshold and count.\n *\n * @param memberThreshold - The minimum number of member shares required to\n * reconstruct the secret within the group.\n * @param memberCount - The total number of member shares in the group.\n * @returns A new GroupSpec instance.\n * @throws SSKRError if the member count is zero, if the member count is\n * greater than the maximum share count, or if the member threshold is\n * greater than the member count.\n */\n static new(memberThreshold: number, memberCount: number): GroupSpec {\n if (memberCount === 0) {\n throw new SSKRError(SSKRErrorType.MemberCountInvalid);\n }\n if (memberCount > MAX_SHARE_COUNT) {\n throw new SSKRError(SSKRErrorType.MemberCountInvalid);\n }\n if (memberThreshold > memberCount) {\n throw new SSKRError(SSKRErrorType.MemberThresholdInvalid);\n }\n return new GroupSpec(memberThreshold, memberCount);\n }\n\n /**\n * Returns the member share threshold for this group.\n */\n memberThreshold(): number {\n return this._memberThreshold;\n }\n\n /**\n * Returns the number of member shares in this group.\n */\n memberCount(): number {\n return this._memberCount;\n }\n\n /**\n * Parses a group specification from a string.\n * Format: \"M-of-N\" where M is the threshold and N is the count.\n */\n static parse(s: string): GroupSpec {\n const parts = s.split(\"-\");\n if (parts.length !== 3) {\n throw new SSKRError(SSKRErrorType.GroupSpecInvalid);\n }\n\n const memberThreshold = parseInt(parts[0], 10);\n if (isNaN(memberThreshold)) {\n throw new SSKRError(SSKRErrorType.GroupSpecInvalid);\n }\n\n if (parts[1] !== \"of\") {\n throw new SSKRError(SSKRErrorType.GroupSpecInvalid);\n }\n\n const memberCount = parseInt(parts[2], 10);\n if (isNaN(memberCount)) {\n throw new SSKRError(SSKRErrorType.GroupSpecInvalid);\n }\n\n return GroupSpec.new(memberThreshold, memberCount);\n }\n\n /**\n * Creates a default GroupSpec (1-of-1).\n */\n static default(): GroupSpec {\n return GroupSpec.new(1, 1);\n }\n\n /**\n * Returns a string representation of the group spec.\n */\n toString(): string {\n return `${this._memberThreshold}-of-${this._memberCount}`;\n }\n}\n\n/**\n * A specification for an SSKR split.\n */\nexport class Spec {\n private readonly _groupThreshold: number;\n private readonly _groups: GroupSpec[];\n\n private constructor(groupThreshold: number, groups: GroupSpec[]) {\n this._groupThreshold = groupThreshold;\n this._groups = groups;\n }\n\n /**\n * Creates a new Spec instance with the given group threshold and groups.\n *\n * @param groupThreshold - The minimum number of groups required to\n * reconstruct the secret.\n * @param groups - The list of GroupSpec instances that define the groups\n * and their members.\n * @returns A new Spec instance.\n * @throws SSKRError if the group threshold is zero, if the group threshold\n * is greater than the number of groups, or if the number of groups is\n * greater than the maximum share count.\n */\n static new(groupThreshold: number, groups: GroupSpec[]): Spec {\n if (groupThreshold === 0) {\n throw new SSKRError(SSKRErrorType.GroupThresholdInvalid);\n }\n if (groupThreshold > groups.length) {\n throw new SSKRError(SSKRErrorType.GroupThresholdInvalid);\n }\n if (groups.length > MAX_SHARE_COUNT) {\n throw new SSKRError(SSKRErrorType.GroupCountInvalid);\n }\n return new Spec(groupThreshold, groups);\n }\n\n /**\n * Returns the group threshold.\n */\n groupThreshold(): number {\n return this._groupThreshold;\n }\n\n /**\n * Returns a slice of the group specifications.\n */\n groups(): GroupSpec[] {\n return this._groups;\n }\n\n /**\n * Returns the number of groups.\n */\n groupCount(): number {\n return this._groups.length;\n }\n\n /**\n * Returns the total number of shares across all groups.\n */\n shareCount(): number {\n return this._groups.reduce((sum, g) => sum + g.memberCount(), 0);\n }\n}\n","// Ported from bc-sskr-rust/src/share.rs\n\nimport type { Secret } from \"./secret.js\";\n\n/**\n * A share in the SSKR scheme.\n */\nexport class SSKRShare {\n private readonly _identifier: number;\n private readonly _groupIndex: number;\n private readonly _groupThreshold: number;\n private readonly _groupCount: number;\n private readonly _memberIndex: number;\n private readonly _memberThreshold: number;\n private readonly _value: Secret;\n\n constructor(\n identifier: number,\n groupIndex: number,\n groupThreshold: number,\n groupCount: number,\n memberIndex: number,\n memberThreshold: number,\n value: Secret,\n ) {\n this._identifier = identifier;\n this._groupIndex = groupIndex;\n this._groupThreshold = groupThreshold;\n this._groupCount = groupCount;\n this._memberIndex = memberIndex;\n this._memberThreshold = memberThreshold;\n this._value = value;\n }\n\n identifier(): number {\n return this._identifier;\n }\n\n groupIndex(): number {\n return this._groupIndex;\n }\n\n groupThreshold(): number {\n return this._groupThreshold;\n }\n\n groupCount(): number {\n return this._groupCount;\n }\n\n memberIndex(): number {\n return this._memberIndex;\n }\n\n memberThreshold(): number {\n return this._memberThreshold;\n }\n\n value(): Secret {\n return this._value;\n }\n}\n","// Ported from bc-sskr-rust/src/encoding.rs\n\nimport type { RandomNumberGenerator } from \"@bcts/rand\";\nimport { SecureRandomNumberGenerator } from \"@bcts/rand\";\nimport { splitSecret, recoverSecret, ShamirError } from \"@bcts/shamir\";\n\nimport { SSKRError, SSKRErrorType } from \"./error.js\";\nimport { Secret } from \"./secret.js\";\nimport type { Spec } from \"./spec.js\";\nimport { SSKRShare } from \"./share.js\";\nimport { METADATA_SIZE_BYTES } from \"./index.js\";\n\n/**\n * Generates SSKR shares for the given Spec and Secret.\n *\n * @param spec - The Spec instance that defines the group and member thresholds.\n * @param masterSecret - The Secret instance to be split into shares.\n * @returns A vector of groups, each containing a vector of shares,\n * each of which is a Uint8Array.\n */\nexport function sskrGenerate(spec: Spec, masterSecret: Secret): Uint8Array[][] {\n const rng = new SecureRandomNumberGenerator();\n return sskrGenerateUsing(spec, masterSecret, rng);\n}\n\n/**\n * Generates SSKR shares for the given Spec and Secret using the provided\n * random number generator.\n *\n * @param spec - The Spec instance that defines the group and member thresholds.\n * @param masterSecret - The Secret instance to be split into shares.\n * @param randomGenerator - The random number generator to use for generating\n * shares.\n * @returns A vector of groups, each containing a vector of shares,\n * each of which is a Uint8Array.\n */\nexport function sskrGenerateUsing(\n spec: Spec,\n masterSecret: Secret,\n randomGenerator: RandomNumberGenerator,\n): Uint8Array[][] {\n const groupsShares = generateShares(spec, masterSecret, randomGenerator);\n\n const result: Uint8Array[][] = groupsShares.map((group) => group.map(serializeShare));\n\n return result;\n}\n\n/**\n * Combines the given SSKR shares into a Secret.\n *\n * @param shares - A array of SSKR shares to be combined.\n * @returns The reconstructed Secret.\n * @throws SSKRError if the shares do not meet the necessary quorum of groups\n * and member shares within each group.\n */\nexport function sskrCombine(shares: Uint8Array[]): Secret {\n const sskrShares: SSKRShare[] = [];\n\n for (const share of shares) {\n const sskrShare = deserializeShare(share);\n sskrShares.push(sskrShare);\n }\n\n return combineShares(sskrShares);\n}\n\nfunction serializeShare(share: SSKRShare): Uint8Array {\n // pack the id, group and member data into 5 bytes:\n // 76543210 76543210 76543210\n // 76543210 76543210\n // ----------------====----====----====----\n // identifier: 16\n // group-threshold: 4\n // group-count: 4\n // group-index: 4\n // member-threshold: 4\n // reserved (MUST be zero): 4\n // member-index: 4\n\n const valueData = share.value().getData();\n const result = new Uint8Array(valueData.length + METADATA_SIZE_BYTES);\n\n const id = share.identifier();\n const gt = (share.groupThreshold() - 1) & 0xf;\n const gc = (share.groupCount() - 1) & 0xf;\n const gi = share.groupIndex() & 0xf;\n const mt = (share.memberThreshold() - 1) & 0xf;\n const mi = share.memberIndex() & 0xf;\n\n const id1 = id >> 8;\n const id2 = id & 0xff;\n\n result[0] = id1;\n result[1] = id2;\n result[2] = (gt << 4) | gc;\n result[3] = (gi << 4) | mt;\n result[4] = mi;\n result.set(valueData, METADATA_SIZE_BYTES);\n\n return result;\n}\n\nfunction deserializeShare(source: Uint8Array): SSKRShare {\n if (source.length < METADATA_SIZE_BYTES) {\n throw new SSKRError(SSKRErrorType.ShareLengthInvalid);\n }\n\n const groupThreshold = (source[2] >> 4) + 1;\n const groupCount = (source[2] & 0xf) + 1;\n\n if (groupThreshold > groupCount) {\n throw new SSKRError(SSKRErrorType.GroupThresholdInvalid);\n }\n\n const identifier = (source[0] << 8) | source[1];\n const groupIndex = source[3] >> 4;\n const memberThreshold = (source[3] & 0xf) + 1;\n const reserved = source[4] >> 4;\n if (reserved !== 0) {\n throw new SSKRError(SSKRErrorType.ShareReservedBitsInvalid);\n }\n const memberIndex = source[4] & 0xf;\n const value = Secret.new(source.subarray(METADATA_SIZE_BYTES));\n\n return new SSKRShare(\n identifier,\n groupIndex,\n groupThreshold,\n groupCount,\n memberIndex,\n memberThreshold,\n value,\n );\n}\n\nfunction generateShares(\n spec: Spec,\n masterSecret: Secret,\n randomGenerator: RandomNumberGenerator,\n): SSKRShare[][] {\n // assign a random identifier\n const identifierBytes = new Uint8Array(2);\n randomGenerator.fillRandomData(identifierBytes);\n const identifier = (identifierBytes[0] << 8) | identifierBytes[1];\n\n const groupsShares: SSKRShare[][] = [];\n\n let groupSecrets: Uint8Array[];\n try {\n groupSecrets = splitSecret(\n spec.groupThreshold(),\n spec.groupCount(),\n masterSecret.getData(),\n randomGenerator,\n );\n } catch (e) {\n if (e instanceof ShamirError) {\n throw SSKRError.fromShamirError(e);\n }\n throw e;\n }\n\n for (let groupIndex = 0; groupIndex < spec.groups().length; groupIndex++) {\n const group = spec.groups()[groupIndex];\n const groupSecret = groupSecrets[groupIndex];\n\n let memberSecrets: Uint8Array[];\n try {\n memberSecrets = splitSecret(\n group.memberThreshold(),\n group.memberCount(),\n groupSecret,\n randomGenerator,\n );\n } catch (e) {\n if (e instanceof ShamirError) {\n throw SSKRError.fromShamirError(e);\n }\n throw e;\n }\n\n const memberSSKRShares: SSKRShare[] = memberSecrets.map((memberSecret, memberIndex) => {\n const secret = Secret.new(memberSecret);\n return new SSKRShare(\n identifier,\n groupIndex,\n spec.groupThreshold(),\n spec.groupCount(),\n memberIndex,\n group.memberThreshold(),\n secret,\n );\n });\n\n groupsShares.push(memberSSKRShares);\n }\n\n return groupsShares;\n}\n\ninterface Group {\n groupIndex: number;\n memberThreshold: number;\n memberIndexes: number[];\n memberShares: Secret[];\n}\n\nfunction combineShares(shares: SSKRShare[]): Secret {\n let identifier = 0;\n let groupThreshold = 0;\n let groupCount = 0;\n\n if (shares.length === 0) {\n throw new SSKRError(SSKRErrorType.SharesEmpty);\n }\n\n let nextGroup = 0;\n const groups: Group[] = [];\n let secretLen = 0;\n\n for (let i = 0; i < shares.length; i++) {\n const share = shares[i];\n\n if (i === 0) {\n // on the first one, establish expected values for common metadata\n identifier = share.identifier();\n groupCount = share.groupCount();\n groupThreshold = share.groupThreshold();\n secretLen = share.value().len();\n } else {\n // on subsequent shares, check that common metadata matches\n if (\n share.identifier() !== identifier ||\n share.groupThreshold() !== groupThreshold ||\n share.groupCount() !== groupCount ||\n share.value().len() !== secretLen\n ) {\n throw new SSKRError(SSKRErrorType.ShareSetInvalid);\n }\n }\n\n // sort shares into member groups\n let groupFound = false;\n for (const group of groups) {\n if (share.groupIndex() === group.groupIndex) {\n groupFound = true;\n if (share.memberThreshold() !== group.memberThreshold) {\n throw new SSKRError(SSKRErrorType.MemberThresholdInvalid);\n }\n for (const memberIndex of group.memberIndexes) {\n if (share.memberIndex() === memberIndex) {\n throw new SSKRError(SSKRErrorType.DuplicateMemberIndex);\n }\n }\n if (group.memberIndexes.length < group.memberThreshold) {\n group.memberIndexes.push(share.memberIndex());\n group.memberShares.push(share.value().clone());\n }\n }\n }\n\n if (!groupFound) {\n const g: Group = {\n groupIndex: share.groupIndex(),\n memberThreshold: share.memberThreshold(),\n memberIndexes: [share.memberIndex()],\n memberShares: [share.value().clone()],\n };\n groups.push(g);\n nextGroup++;\n }\n }\n\n // Check that we have enough groups to recover the master secret\n if (nextGroup < groupThreshold) {\n throw new SSKRError(SSKRErrorType.NotEnoughGroups);\n }\n\n // Here, all of the shares are unpacked into member groups. Now we go\n // through each group and recover the group secret, and then use the\n // result to recover the master secret\n const masterIndexes: number[] = [];\n const masterShares: Uint8Array[] = [];\n\n for (const group of groups) {\n // Only attempt to recover the group secret if we have enough shares\n if (group.memberIndexes.length < group.memberThreshold) {\n continue;\n }\n\n // Recover the group secret\n try {\n const memberSharesData = group.memberShares.map((s) => s.getData());\n const groupSecret = recoverSecret(group.memberIndexes, memberSharesData);\n masterIndexes.push(group.groupIndex);\n masterShares.push(groupSecret);\n } catch {\n // If we can't recover this group, just skip it\n continue;\n }\n\n // Stop if we have enough groups to recover the master secret\n if (masterIndexes.length === groupThreshold) {\n break;\n }\n }\n\n // If we don't have enough groups to recover the master secret, return an error\n if (masterIndexes.length < groupThreshold) {\n throw new SSKRError(SSKRErrorType.NotEnoughGroups);\n }\n\n // Recover the master secret\n let masterSecretData: Uint8Array;\n try {\n masterSecretData = recoverSecret(masterIndexes, masterShares);\n } catch (e) {\n if (e instanceof ShamirError) {\n throw SSKRError.fromShamirError(e);\n }\n throw e;\n }\n\n return Secret.new(masterSecretData);\n}\n","// Blockchain Commons Sharded Secret Key Reconstruction (SSKR)\n// Ported from bc-sskr-rust\n//\n// Sharded Secret Key Reconstruction (SSKR) is a protocol for splitting a\n// secret into a set of shares across one or more groups, such that the\n// secret can be reconstructed from any combination of shares totaling or\n// exceeding a threshold number of shares within each group and across all\n// groups. SSKR is a generalization of Shamir's Secret Sharing (SSS) that\n// allows for multiple groups and multiple thresholds.\n\nimport {\n MIN_SECRET_LEN as SHAMIR_MIN_SECRET_LEN,\n MAX_SECRET_LEN as SHAMIR_MAX_SECRET_LEN,\n MAX_SHARE_COUNT as SHAMIR_MAX_SHARE_COUNT,\n} from \"@bcts/shamir\";\n\n/**\n * The minimum length of a secret.\n */\nexport const MIN_SECRET_LEN = SHAMIR_MIN_SECRET_LEN;\n\n/**\n * The maximum length of a secret.\n */\nexport const MAX_SECRET_LEN = SHAMIR_MAX_SECRET_LEN;\n\n/**\n * The maximum number of shares that can be generated from a secret.\n */\nexport const MAX_SHARE_COUNT = SHAMIR_MAX_SHARE_COUNT;\n\n/**\n * The maximum number of groups in a split.\n */\nexport const MAX_GROUPS_COUNT = MAX_SHARE_COUNT;\n\n/**\n * The number of bytes used to encode the metadata for a share.\n */\nexport const METADATA_SIZE_BYTES = 5;\n\n/**\n * The minimum number of bytes required to encode a share.\n */\nexport const MIN_SERIALIZE_SIZE_BYTES = METADATA_SIZE_BYTES + MIN_SECRET_LEN;\n\n// Error types\nexport { SSKRError, SSKRErrorType, type SSKRResult } from \"./error.js\";\n\n// Secret\nexport { Secret } from \"./secret.js\";\n\n// Specifications\nexport { GroupSpec, Spec } from \"./spec.js\";\n\n// Share\nexport { SSKRShare } from \"./share.js\";\n\n// Encoding/Decoding\nexport { sskrGenerate, sskrGenerateUsing, sskrCombine } from \"./encoding.js\";\n"],"mappings":";;;;;;;AAOA,IAAY,0DAAL;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;AAMF,IAAa,YAAb,MAAa,kBAAkB,MAAM;CACnC,AAAS;CACT,AAAS;CAET,YAAY,MAAqB,SAAkB,aAA2B;AAC5E,QAAM,WAAW,UAAU,eAAe,MAAM,YAAY,CAAC;AAC7D,OAAK,OAAO;AACZ,OAAK,cAAc;AACnB,OAAK,OAAO;;CAGd,OAAe,eAAe,MAAqB,aAAmC;AACpF,UAAQ,MAAR;GACE,KAAK,cAAc,qBACjB,QAAO;GACT,KAAK,cAAc,iBACjB,QAAO;GACT,KAAK,cAAc,kBACjB,QAAO;GACT,KAAK,cAAc,sBACjB,QAAO;GACT,KAAK,cAAc,mBACjB,QAAO;GACT,KAAK,cAAc,uBACjB,QAAO;GACT,KAAK,cAAc,gBACjB,QAAO;GACT,KAAK,cAAc,oBACjB,QAAO;GACT,KAAK,cAAc,cACjB,QAAO;GACT,KAAK,cAAc,eACjB,QAAO;GACT,KAAK,cAAc,mBACjB,QAAO;GACT,KAAK,cAAc,yBACjB,QAAO;GACT,KAAK,cAAc,YACjB,QAAO;GACT,KAAK,cAAc,gBACjB,QAAO;GACT,KAAK,cAAc,YACjB,QAAO,eAAe,OAClB,sBAAsB,YAAY,YAClC;;;CAIV,OAAO,gBAAgB,OAA+B;AACpD,SAAO,IAAI,UAAU,cAAc,aAAa,QAAW,MAAM;;;;;;;;;ACrErE,IAAa,SAAb,MAAa,OAAO;CAClB,AAAiB;CAEjB,AAAQ,YAAY,MAAkB;AACpC,OAAK,OAAO;;;;;;;;;;CAWd,OAAO,IAAI,MAAmC;EAC5C,MAAM,QAAQ,OAAO,SAAS,WAA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package.json ADDED
@@ -0,0 +1,76 @@
1
+ {
2
+ "name": "@bcts/sskr",
3
+ "version": "1.0.0-alpha.5",
4
+ "type": "module",
5
+ "description": "Blockchain Commons Sharded Secret Key Reconstruction (SSKR) for TypeScript",
6
+ "license": "BSD-2-Clause-Patent",
7
+ "author": "Leonardo Custodio <leonardo@custodio.me>",
8
+ "homepage": "https://github.com/leonardocustodio/blockchain-commons",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://github.com/leonardocustodio/blockchain-commons",
12
+ "directory": "packages/sskr"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/leonardocustodio/blockchain-commons/issues"
16
+ },
17
+ "main": "dist/index.cjs",
18
+ "module": "dist/index.mjs",
19
+ "types": "dist/index.d.mts",
20
+ "browser": "dist/index.iife.js",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.mts",
24
+ "import": "./dist/index.mjs",
25
+ "require": "./dist/index.cjs",
26
+ "browser": "./dist/index.iife.js",
27
+ "default": "./dist/index.mjs"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "src",
33
+ "README.md"
34
+ ],
35
+ "scripts": {
36
+ "build": "tsdown",
37
+ "dev": "tsdown --watch",
38
+ "test": "vitest run",
39
+ "test:watch": "vitest",
40
+ "lint": "eslint 'src/**/*.ts'",
41
+ "lint:fix": "eslint 'src/**/*.ts' --fix",
42
+ "typecheck": "tsc --noEmit",
43
+ "clean": "rm -rf dist",
44
+ "docs": "typedoc",
45
+ "prepublishOnly": "npm run clean && npm run build && npm test"
46
+ },
47
+ "keywords": [
48
+ "sskr",
49
+ "shamir",
50
+ "secret-sharing",
51
+ "sharded",
52
+ "blockchain-commons",
53
+ "cryptography",
54
+ "threshold",
55
+ "security"
56
+ ],
57
+ "engines": {
58
+ "node": ">=18.0.0"
59
+ },
60
+ "dependencies": {
61
+ "@bcts/rand": "workspace:*",
62
+ "@bcts/shamir": "workspace:*"
63
+ },
64
+ "devDependencies": {
65
+ "@bcts/eslint": "workspace:*",
66
+ "@bcts/tsconfig": "workspace:*",
67
+ "@eslint/js": "^9.39.1",
68
+ "@types/node": "^24.10.2",
69
+ "eslint": "^9.39.1",
70
+ "ts-node": "^10.9.2",
71
+ "tsdown": "^0.17.2",
72
+ "typedoc": "^0.28.15",
73
+ "typescript": "^5.9.3",
74
+ "vitest": "^3.2.4"
75
+ }
76
+ }