@bcts/shamir 1.0.0-alpha.8 → 1.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,18 +1,39 @@
1
1
  import { RandomNumberGenerator } from "@bcts/rand";
2
2
 
3
3
  //#region src/error.d.ts
4
+ /**
5
+ * Copyright © 2023-2026 Blockchain Commons, LLC
6
+ * Copyright © 2025-2026 Parity Technologies
7
+ *
8
+ */
4
9
  /**
5
10
  * Error types for Shamir secret sharing operations.
11
+ *
12
+ * Each variant mirrors a corresponding `Error::*` enum in
13
+ * `bc-shamir-rust/src/error.rs` with the same trigger conditions and the
14
+ * same default `Display` strings.
15
+ *
16
+ * Note on `InterpolationFailure`: this variant is **reserved but
17
+ * unreachable** in both the Rust and TypeScript implementations.
18
+ * `interpolate()` in `interpolate.ts` never actually returns / throws an
19
+ * interpolation failure today — the Lagrange-basis math always succeeds
20
+ * for any well-formed input. The variant is kept for forward
21
+ * compatibility (e.g. should a future revision add input validation that
22
+ * could reject pathological cases) and to keep the TS error type a 1:1
23
+ * mirror of Rust's `Error` enum.
6
24
  */
7
25
  declare enum ShamirErrorType {
8
26
  SecretTooLong = "SecretTooLong",
9
27
  TooManyShares = "TooManyShares",
28
+ /**
29
+ * Reserved / unreachable in both Rust and TS today. See enum doc above.
30
+ */
10
31
  InterpolationFailure = "InterpolationFailure",
11
32
  ChecksumFailure = "ChecksumFailure",
12
33
  SecretTooShort = "SecretTooShort",
13
34
  SecretNotEvenLen = "SecretNotEvenLen",
14
35
  InvalidThreshold = "InvalidThreshold",
15
- SharesUnequalLength = "SharesUnequalLength",
36
+ SharesUnequalLength = "SharesUnequalLength"
16
37
  }
17
38
  /**
18
39
  * Error class for Shamir secret sharing operations.
@@ -22,6 +43,14 @@ declare class ShamirError extends Error {
22
43
  constructor(type: ShamirErrorType, message?: string);
23
44
  private static defaultMessage;
24
45
  }
46
+ /**
47
+ * Mirrors Rust's `Result<T, Error>` for API parity.
48
+ *
49
+ * The TypeScript port surfaces failures by throwing `ShamirError`
50
+ * instances rather than returning a sum type, so this alias is a no-op
51
+ * (`ShamirResult<T>` ≡ `T`). It is kept so signatures published in
52
+ * `@bcts/shamir` remain visually parallel to their Rust counterparts.
53
+ */
25
54
  type ShamirResult<T> = T;
26
55
  //#endregion
27
56
  //#region src/shamir.d.ts
@@ -83,85 +112,12 @@ declare function splitSecret(threshold: number, shareCount: number, secret: Uint
83
112
  */
84
113
  declare function recoverSecret(indexes: number[], shares: Uint8Array[]): Uint8Array;
85
114
  //#endregion
86
- //#region src/hazmat.d.ts
87
- /**
88
- * Convert an array of bytes into a bitsliced representation.
89
- * Takes the first 32 bytes from x and produces 8 u32 values.
90
- *
91
- * @param r - Output array of 8 u32 values (bitsliced representation)
92
- * @param x - Input array of at least 32 bytes
93
- */
94
- declare function bitslice(r: Uint32Array, x: Uint8Array): void;
95
- /**
96
- * Convert a bitsliced representation back to bytes.
97
- *
98
- * @param r - Output array of at least 32 bytes
99
- * @param x - Input array of 8 u32 values (bitsliced representation)
100
- */
101
- declare function unbitslice(r: Uint8Array, x: Uint32Array): void;
102
- /**
103
- * Set all 32 positions in a bitsliced array to the same byte value.
104
- *
105
- * @param r - Output array of 8 u32 values
106
- * @param x - Byte value to set in all positions
107
- */
108
- declare function bitsliceSetall(r: Uint32Array, x: number): void;
109
- /**
110
- * Add (XOR) r with x and store the result in r.
111
- * In GF(2^8), addition is XOR.
112
- *
113
- * @param r - First operand and result
114
- * @param x - Second operand
115
- */
116
- declare function gf256Add(r: Uint32Array, x: Uint32Array): void;
117
- /**
118
- * Safely multiply two bitsliced polynomials in GF(2^8) reduced by
119
- * x^8 + x^4 + x^3 + x + 1. r and a may overlap, but overlapping of r
120
- * and b will produce an incorrect result! If you need to square a polynomial
121
- * use gf256Square instead.
122
- *
123
- * @param r - Result array (8 u32 values)
124
- * @param a - First operand (may overlap with r)
125
- * @param b - Second operand (must NOT overlap with r)
126
- */
127
- declare function gf256Mul(r: Uint32Array, a: Uint32Array, b: Uint32Array): void;
128
- /**
129
- * Square x in GF(2^8) and write the result to r.
130
- * r and x may overlap.
131
- *
132
- * @param r - Result array (8 u32 values)
133
- * @param x - Value to square
134
- */
135
- declare function gf256Square(r: Uint32Array, x: Uint32Array): void;
136
- /**
137
- * Invert x in GF(2^8) and write the result to r.
138
- *
139
- * @param r - Result array (8 u32 values)
140
- * @param x - Value to invert (will be modified)
141
- */
142
- declare function gf256Inv(r: Uint32Array, x: Uint32Array): void;
143
- //#endregion
144
- //#region src/interpolate.d.ts
115
+ //#region src/index.d.ts
145
116
  /**
146
- * Safely interpolate the polynomial going through
147
- * the points (x0 [y0_0 y0_1 y0_2 ... y0_31]) , (x1 [y1_0 ...]), ...
148
- *
149
- * where
150
- * xi points to [x0 x1 ... xn-1 ]
151
- * y contains an array of pointers to 32-bit arrays of y values
152
- * y contains [y0 y1 y2 ... yn-1]
153
- * and each of the yi arrays contain [yi_0 yi_i ... yi_31].
117
+ * Copyright © 2023-2026 Blockchain Commons, LLC
118
+ * Copyright © 2025-2026 Parity Technologies
154
119
  *
155
- * @param n - Number of points to interpolate
156
- * @param xi - x coordinates for points (array of length n)
157
- * @param yl - Length of y coordinate arrays
158
- * @param yij - Array of n arrays of length yl
159
- * @param x - Coordinate to interpolate at
160
- * @returns The interpolated result of length yl
161
120
  */
162
- declare function interpolate(n: number, xi: Uint8Array, yl: number, yij: Uint8Array[], x: number): Uint8Array;
163
- //#endregion
164
- //#region src/index.d.ts
165
121
  /**
166
122
  * The minimum length of a secret.
167
123
  */
@@ -175,5 +131,5 @@ declare const MAX_SECRET_LEN = 32;
175
131
  */
176
132
  declare const MAX_SHARE_COUNT = 16;
177
133
  //#endregion
178
- export { MAX_SECRET_LEN, MAX_SHARE_COUNT, MIN_SECRET_LEN, ShamirError, ShamirErrorType, type ShamirResult, bitslice, bitsliceSetall, gf256Add, gf256Inv, gf256Mul, gf256Square, interpolate, recoverSecret, splitSecret, unbitslice };
134
+ export { MAX_SECRET_LEN, MAX_SHARE_COUNT, MIN_SECRET_LEN, ShamirError, ShamirErrorType, type ShamirResult, recoverSecret, splitSecret };
179
135
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/error.ts","../src/shamir.ts","../src/hazmat.ts","../src/interpolate.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;AAKY,aAAA,eAAA;EAcC,aAAA,GAAY,eAAA;EACR,aAAA,GAAA,eAAA;EAEG,oBAAA,GAAA,sBAAA;EAHa,eAAA,GAAA,iBAAA;EAAK,cAAA,GAAA,gBAAA;EA+B1B,gBAAY,GAAA,kBAAO;;;;ACU/B;;;AAKG,cD9CU,WAAA,SAAoB,KAAA,CC8C9B;EAAU,SAAA,IAAA,ED7CI,eC6CJ;EAkFG,WAAA,CAAA,IAAa,ED7HT,eC6HqC,EAAA,OAAyB,CAAV,EAAA,MAAU;;;KDjGtE,kBAAkB;;;;;AA7C9B;AAcA;;;;;AA+BA;;;;ACUA;;;;;AAuFA;;;;ACvIA;AAyBA;AAyBA;AAsBA;AAoBA;;;;;AA6GgB,iBDzJA,WAAA,CCyJe,SAAgB,EAAA,MAAA,EAAW,UAAA,EAAA,MAAA,EAAA,MAAA,EDtJhD,UCsJgD,EAAA,eAAA,EDrJvC,qBCqJuC,CAAA,EDpJvD,UCoJuD,EAAA;AA+C1D;;;;AC3JA;;;;;;;;AC3FA;AAKA;AAKA;;;;;;;;;;;iBH2HgB,aAAA,4BAAyC,eAAe;;;;;;AD9IxE;AAcA;;;AAAiC,iBEPjB,QAAA,CFOiB,CAAA,EEPL,WFOK,EAAA,CAAA,EEPW,UFOX,CAAA,EAAA,IAAA;;AA+BjC;;;;ACUA;AAGU,iBC1BM,UAAA,CD0BN,CAAA,EC1BoB,UD0BpB,EAAA,CAAA,EC1BmC,WD0BnC,CAAA,EAAA,IAAA;;;;AAoFV;;;iBCrFgB,cAAA,IAAkB;AAlDlC;AAyBA;AAyBA;AAsBA;AAoBA;;;AAA4D,iBApB5C,QAAA,CAoB4C,CAAA,EApBhC,WAoBgC,EAAA,CAAA,EApBhB,WAoBgB,CAAA,EAAA,IAAA;;AA6G5D;AA+CA;;;;AC3JA;;;;AAMa,iBDPG,QAAA,CCOH,CAAA,EDPe,WCOf,EAAA,CAAA,EDP+B,WCO/B,EAAA,CAAA,EDP+C,WCO/C,CAAA,EAAA,IAAA;;;;ACjGb;AAKA;AAKA;;iBF6LgB,WAAA,IAAe,gBAAgB;;;;;;;iBA+C/B,QAAA,IAAY,gBAAgB;;;;;;AF/P5C;AAcA;;;;;AA+BA;;;;ACUA;;;;AAKa,iBEwCG,WAAA,CFxCH,CAAA,EAAA,MAAA,EAAA,EAAA,EE0CP,UF1CO,EAAA,EAAA,EAAA,MAAA,EAAA,GAAA,EE4CN,UF5CM,EAAA,EAAA,CAAA,EAAA,MAAA,CAAA,EE8CV,UF9CU;;;;;;AD5DD,cISC,cAAA,GJTc,EAAA;AAc3B;;;AAAiC,cIApB,cAAA,GJAoB,EAAA;;AA+BjC;;cI1Ba,eAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/error.ts","../src/shamir.ts","../src/index.ts"],"mappings":";;;;;;AAwBA;;;;;;;;;;;;;;AAiBA;;;;aAjBY,eAAA;EACV,aAAA;EACA,aAAA;EAeoC;;;EAXpC,oBAAA;EACA,eAAA;EACA,cAAA;EACA,gBAAA;EACA,gBAAA;EACA,mBAAA;AAAA;;AA6CF;;cAvCa,WAAA,SAAoB,KAAA;EAAA,SACtB,IAAA,EAAM,eAAA;cAEH,IAAA,EAAM,eAAA,EAAiB,OAAA;EAAA,eAMpB,cAAA;AAAA;;ACgBjB;;;;;;;KDcY,YAAA,MAAkB,CAAA;;;;;;;;;;;;;;AAvC9B;;;;;;;;;;;;;;;;;;AAuCA;iBCdgB,WAAA,CACd,SAAA,UACA,UAAA,UACA,MAAA,EAAQ,UAAA,EACR,eAAA,EAAiB,qBAAA,GAChB,UAAA;;;;;;;AALH;;;;;;;;;;;;;;;;;AAuFA;;iBAAgB,aAAA,CAAc,OAAA,YAAmB,MAAA,EAAQ,UAAA,KAAe,UAAA;;;;;;ADjIxE;;;;;cEJa,cAAA;;;;cAKA,cAAA;;;;cAKA,eAAA"}
@@ -1,20 +1,40 @@
1
- var BCShamir = (function(exports, __bcts_crypto) {
2
-
3
-
4
- //#region src/error.ts
5
- /**
1
+ var bctsShamir = (function(exports, _bcts_crypto) {
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ //#region src/error.ts
4
+ /**
5
+ * Copyright © 2023-2026 Blockchain Commons, LLC
6
+ * Copyright © 2025-2026 Parity Technologies
7
+ *
8
+ */
9
+ /**
6
10
  * Error types for Shamir secret sharing operations.
11
+ *
12
+ * Each variant mirrors a corresponding `Error::*` enum in
13
+ * `bc-shamir-rust/src/error.rs` with the same trigger conditions and the
14
+ * same default `Display` strings.
15
+ *
16
+ * Note on `InterpolationFailure`: this variant is **reserved but
17
+ * unreachable** in both the Rust and TypeScript implementations.
18
+ * `interpolate()` in `interpolate.ts` never actually returns / throws an
19
+ * interpolation failure today — the Lagrange-basis math always succeeds
20
+ * for any well-formed input. The variant is kept for forward
21
+ * compatibility (e.g. should a future revision add input validation that
22
+ * could reject pathological cases) and to keep the TS error type a 1:1
23
+ * mirror of Rust's `Error` enum.
7
24
  */
8
- let ShamirErrorType = /* @__PURE__ */ function(ShamirErrorType$1) {
9
- ShamirErrorType$1["SecretTooLong"] = "SecretTooLong";
10
- ShamirErrorType$1["TooManyShares"] = "TooManyShares";
11
- ShamirErrorType$1["InterpolationFailure"] = "InterpolationFailure";
12
- ShamirErrorType$1["ChecksumFailure"] = "ChecksumFailure";
13
- ShamirErrorType$1["SecretTooShort"] = "SecretTooShort";
14
- ShamirErrorType$1["SecretNotEvenLen"] = "SecretNotEvenLen";
15
- ShamirErrorType$1["InvalidThreshold"] = "InvalidThreshold";
16
- ShamirErrorType$1["SharesUnequalLength"] = "SharesUnequalLength";
17
- return ShamirErrorType$1;
25
+ let ShamirErrorType = /* @__PURE__ */ function(ShamirErrorType) {
26
+ ShamirErrorType["SecretTooLong"] = "SecretTooLong";
27
+ ShamirErrorType["TooManyShares"] = "TooManyShares";
28
+ /**
29
+ * Reserved / unreachable in both Rust and TS today. See enum doc above.
30
+ */
31
+ ShamirErrorType["InterpolationFailure"] = "InterpolationFailure";
32
+ ShamirErrorType["ChecksumFailure"] = "ChecksumFailure";
33
+ ShamirErrorType["SecretTooShort"] = "SecretTooShort";
34
+ ShamirErrorType["SecretNotEvenLen"] = "SecretNotEvenLen";
35
+ ShamirErrorType["InvalidThreshold"] = "InvalidThreshold";
36
+ ShamirErrorType["SharesUnequalLength"] = "SharesUnequalLength";
37
+ return ShamirErrorType;
18
38
  }({});
19
39
  /**
20
40
  * Error class for Shamir secret sharing operations.
@@ -28,21 +48,33 @@ var BCShamir = (function(exports, __bcts_crypto) {
28
48
  }
29
49
  static defaultMessage(type) {
30
50
  switch (type) {
31
- case ShamirErrorType.SecretTooLong: return "secret is too long";
32
- case ShamirErrorType.TooManyShares: return "too many shares";
33
- case ShamirErrorType.InterpolationFailure: return "interpolation failed";
34
- case ShamirErrorType.ChecksumFailure: return "checksum failure";
35
- case ShamirErrorType.SecretTooShort: return "secret is too short";
36
- case ShamirErrorType.SecretNotEvenLen: return "secret is not of even length";
37
- case ShamirErrorType.InvalidThreshold: return "invalid threshold";
38
- case ShamirErrorType.SharesUnequalLength: return "shares have unequal length";
51
+ case "SecretTooLong": return "secret is too long";
52
+ case "TooManyShares": return "too many shares";
53
+ case "InterpolationFailure": return "interpolation failed";
54
+ case "ChecksumFailure": return "checksum failure";
55
+ case "SecretTooShort": return "secret is too short";
56
+ case "SecretNotEvenLen": return "secret is not of even length";
57
+ case "InvalidThreshold": return "invalid threshold";
58
+ case "SharesUnequalLength": return "shares have unequal length";
39
59
  }
40
60
  }
41
61
  };
42
-
43
- //#endregion
44
- //#region src/hazmat.ts
45
- /**
62
+ //#endregion
63
+ //#region src/hazmat.ts
64
+ /**
65
+ * Copyright © 2023-2026 Blockchain Commons, LLC
66
+ * Copyright © 2025-2026 Parity Technologies
67
+ *
68
+ */
69
+ /**
70
+ * Internal contract guard. Mirrors a Rust `assert!(condition, message)`
71
+ * panic on the boundary between hazmat helpers — kept as a bare `Error`
72
+ * so it cannot be confused with a `ShamirError` from the public API.
73
+ */
74
+ function assertContract(condition, message) {
75
+ if (!condition) throw new Error(message);
76
+ }
77
+ /**
46
78
  * Convert an array of bytes into a bitsliced representation.
47
79
  * Takes the first 32 bytes from x and produces 8 u32 values.
48
80
  *
@@ -50,9 +82,9 @@ var BCShamir = (function(exports, __bcts_crypto) {
50
82
  * @param x - Input array of at least 32 bytes
51
83
  */
52
84
  function bitslice(r, x) {
53
- if (x.length < 32) throw new Error("bitslice: input must be at least 32 bytes");
54
- if (r.length !== 8) throw new Error("bitslice: output must have 8 elements");
55
- (0, __bcts_crypto.memzero)(r);
85
+ assertContract(x.length >= 32, "bitslice: input must be at least 32 bytes");
86
+ assertContract(r.length === 8, "bitslice: output must have 8 elements");
87
+ (0, _bcts_crypto.memzero)(r);
56
88
  for (let arrIdx = 0; arrIdx < 32; arrIdx++) {
57
89
  const cur = x[arrIdx];
58
90
  for (let bitIdx = 0; bitIdx < 8; bitIdx++) r[bitIdx] |= (cur & 1 << bitIdx) >>> bitIdx << arrIdx;
@@ -65,9 +97,9 @@ var BCShamir = (function(exports, __bcts_crypto) {
65
97
  * @param x - Input array of 8 u32 values (bitsliced representation)
66
98
  */
67
99
  function unbitslice(r, x) {
68
- if (r.length < 32) throw new Error("unbitslice: output must be at least 32 bytes");
69
- if (x.length !== 8) throw new Error("unbitslice: input must have 8 elements");
70
- (0, __bcts_crypto.memzero)(r.subarray(0, 32));
100
+ assertContract(r.length >= 32, "unbitslice: output must be at least 32 bytes");
101
+ assertContract(x.length === 8, "unbitslice: input must have 8 elements");
102
+ (0, _bcts_crypto.memzero)(r.subarray(0, 32));
71
103
  for (let bitIdx = 0; bitIdx < 8; bitIdx++) {
72
104
  const cur = x[bitIdx];
73
105
  for (let arrIdx = 0; arrIdx < 32; arrIdx++) r[arrIdx] |= (cur & 1 << arrIdx) >>> arrIdx << bitIdx;
@@ -80,7 +112,7 @@ var BCShamir = (function(exports, __bcts_crypto) {
80
112
  * @param x - Byte value to set in all positions
81
113
  */
82
114
  function bitsliceSetall(r, x) {
83
- if (r.length !== 8) throw new Error("bitsliceSetall: output must have 8 elements");
115
+ assertContract(r.length === 8, "bitsliceSetall: output must have 8 elements");
84
116
  for (let idx = 0; idx < 8; idx++) r[idx] = (x >>> idx & 1) === 1 ? 4294967295 : 0;
85
117
  }
86
118
  /**
@@ -91,7 +123,7 @@ var BCShamir = (function(exports, __bcts_crypto) {
91
123
  * @param x - Second operand
92
124
  */
93
125
  function gf256Add(r, x) {
94
- if (r.length !== 8 || x.length !== 8) throw new Error("gf256Add: arrays must have 8 elements");
126
+ assertContract(r.length === 8 && x.length === 8, "gf256Add: arrays must have 8 elements");
95
127
  for (let i = 0; i < 8; i++) r[i] ^= x[i];
96
128
  }
97
129
  /**
@@ -105,7 +137,7 @@ var BCShamir = (function(exports, __bcts_crypto) {
105
137
  * @param b - Second operand (must NOT overlap with r)
106
138
  */
107
139
  function gf256Mul(r, a, b) {
108
- if (r.length !== 8 || a.length !== 8 || b.length !== 8) throw new Error("gf256Mul: arrays must have 8 elements");
140
+ assertContract(r.length === 8 && a.length === 8 && b.length === 8, "gf256Mul: arrays must have 8 elements");
109
141
  const a2 = new Uint32Array(a);
110
142
  r[0] = a2[0] & b[0];
111
143
  r[1] = a2[1] & b[0];
@@ -201,7 +233,7 @@ var BCShamir = (function(exports, __bcts_crypto) {
201
233
  * @param x - Value to square
202
234
  */
203
235
  function gf256Square(r, x) {
204
- if (r.length !== 8 || x.length !== 8) throw new Error("gf256Square: arrays must have 8 elements");
236
+ assertContract(r.length === 8 && x.length === 8, "gf256Square: arrays must have 8 elements");
205
237
  const r14 = x[7];
206
238
  const r12 = x[6];
207
239
  let r10 = x[5];
@@ -237,7 +269,7 @@ var BCShamir = (function(exports, __bcts_crypto) {
237
269
  * @param x - Value to invert (will be modified)
238
270
  */
239
271
  function gf256Inv(r, x) {
240
- if (r.length !== 8 || x.length !== 8) throw new Error("gf256Inv: arrays must have 8 elements");
272
+ assertContract(r.length === 8 && x.length === 8, "gf256Inv: arrays must have 8 elements");
241
273
  const y = new Uint32Array(8);
242
274
  const z = new Uint32Array(8);
243
275
  gf256Square(y, x);
@@ -252,10 +284,14 @@ var BCShamir = (function(exports, __bcts_crypto) {
252
284
  gf256Mul(r, new Uint32Array(r), z);
253
285
  gf256Mul(r, new Uint32Array(r), y);
254
286
  }
255
-
256
- //#endregion
257
- //#region src/interpolate.ts
258
- /**
287
+ //#endregion
288
+ //#region src/interpolate.ts
289
+ /**
290
+ * Copyright © 2023-2026 Blockchain Commons, LLC
291
+ * Copyright © 2025-2026 Parity Technologies
292
+ *
293
+ */
294
+ /**
259
295
  * Calculate the lagrange basis coefficients for the lagrange polynomial
260
296
  * defined by the x coordinates xc at the value x.
261
297
  *
@@ -317,8 +353,8 @@ var BCShamir = (function(exports, __bcts_crypto) {
317
353
  */
318
354
  function interpolate(n, xi, yl, yij, x) {
319
355
  const y = [];
320
- for (let i = 0; i < n; i++) y.push(new Uint8Array(MAX_SECRET_LEN));
321
- const values = new Uint8Array(MAX_SECRET_LEN);
356
+ for (let i = 0; i < n; i++) y.push(new Uint8Array(32));
357
+ const values = new Uint8Array(32);
322
358
  for (let i = 0; i < n; i++) y[i].set(yij[i].subarray(0, yl), 0);
323
359
  const lagrange = new Uint8Array(n);
324
360
  const ySlice = new Uint32Array(8);
@@ -335,28 +371,32 @@ var BCShamir = (function(exports, __bcts_crypto) {
335
371
  unbitslice(values, resultSlice);
336
372
  const result = new Uint8Array(yl);
337
373
  result.set(values.subarray(0, yl), 0);
338
- (0, __bcts_crypto.memzero)(lagrange);
339
- (0, __bcts_crypto.memzero)(ySlice);
340
- (0, __bcts_crypto.memzero)(resultSlice);
341
- (0, __bcts_crypto.memzero)(temp);
342
- (0, __bcts_crypto.memzeroVecVecU8)(y);
343
- (0, __bcts_crypto.memzero)(values);
374
+ (0, _bcts_crypto.memzero)(lagrange);
375
+ (0, _bcts_crypto.memzero)(ySlice);
376
+ (0, _bcts_crypto.memzero)(resultSlice);
377
+ (0, _bcts_crypto.memzero)(temp);
378
+ (0, _bcts_crypto.memzeroVecVecU8)(y);
379
+ (0, _bcts_crypto.memzero)(values);
344
380
  return result;
345
381
  }
346
-
347
- //#endregion
348
- //#region src/shamir.ts
382
+ //#endregion
383
+ //#region src/shamir.ts
384
+ /**
385
+ * Copyright © 2023-2026 Blockchain Commons, LLC
386
+ * Copyright © 2025-2026 Parity Technologies
387
+ *
388
+ */
349
389
  const SECRET_INDEX = 255;
350
390
  const DIGEST_INDEX = 254;
351
391
  function createDigest(randomData, sharedSecret) {
352
- return (0, __bcts_crypto.hmacSha256)(randomData, sharedSecret);
392
+ return (0, _bcts_crypto.hmacSha256)(randomData, sharedSecret);
353
393
  }
354
394
  function validateParameters(threshold, shareCount, secretLength) {
355
- if (shareCount > MAX_SHARE_COUNT) throw new ShamirError(ShamirErrorType.TooManyShares);
356
- else if (threshold < 1 || threshold > shareCount) throw new ShamirError(ShamirErrorType.InvalidThreshold);
357
- else if (secretLength > MAX_SECRET_LEN) throw new ShamirError(ShamirErrorType.SecretTooLong);
358
- else if (secretLength < MIN_SECRET_LEN) throw new ShamirError(ShamirErrorType.SecretTooShort);
359
- else if ((secretLength & 1) !== 0) throw new ShamirError(ShamirErrorType.SecretNotEvenLen);
395
+ if (shareCount > 16) throw new ShamirError("TooManyShares");
396
+ else if (threshold < 1 || threshold > shareCount) throw new ShamirError("InvalidThreshold");
397
+ else if (secretLength > 32) throw new ShamirError("SecretTooLong");
398
+ else if (secretLength < 16) throw new ShamirError("SecretTooShort");
399
+ else if ((secretLength & 1) !== 0) throw new ShamirError("SecretNotEvenLen");
360
400
  }
361
401
  /**
362
402
  * Splits a secret into shares using the Shamir secret sharing algorithm.
@@ -421,9 +461,9 @@ var BCShamir = (function(exports, __bcts_crypto) {
421
461
  const v = interpolate(n, x, secret.length, y, index);
422
462
  result[index].set(v);
423
463
  }
424
- (0, __bcts_crypto.memzero)(digest);
425
- (0, __bcts_crypto.memzero)(x);
426
- (0, __bcts_crypto.memzeroVecVecU8)(y);
464
+ (0, _bcts_crypto.memzero)(digest);
465
+ (0, _bcts_crypto.memzero)(x);
466
+ (0, _bcts_crypto.memzeroVecVecU8)(y);
427
467
  return result;
428
468
  }
429
469
  }
@@ -454,10 +494,10 @@ var BCShamir = (function(exports, __bcts_crypto) {
454
494
  */
455
495
  function recoverSecret(indexes, shares) {
456
496
  const threshold = shares.length;
457
- if (threshold === 0 || indexes.length !== threshold) throw new ShamirError(ShamirErrorType.InvalidThreshold);
497
+ if (threshold === 0 || indexes.length !== threshold) throw new ShamirError("InvalidThreshold");
458
498
  const shareLength = shares[0].length;
459
499
  validateParameters(threshold, threshold, shareLength);
460
- if (!shares.every((share) => share.length === shareLength)) throw new ShamirError(ShamirErrorType.SharesUnequalLength);
500
+ if (!shares.every((share) => share.length === shareLength)) throw new ShamirError("SharesUnequalLength");
461
501
  if (threshold === 1) return new Uint8Array(shares[0]);
462
502
  else {
463
503
  const indexesU8 = new Uint8Array(indexes);
@@ -466,16 +506,20 @@ var BCShamir = (function(exports, __bcts_crypto) {
466
506
  const verify = createDigest(digest.subarray(4), secret);
467
507
  let valid = true;
468
508
  for (let i = 0; i < 4; i++) valid = valid && digest[i] === verify[i];
469
- (0, __bcts_crypto.memzero)(digest);
470
- (0, __bcts_crypto.memzero)(verify);
471
- if (!valid) throw new ShamirError(ShamirErrorType.ChecksumFailure);
509
+ (0, _bcts_crypto.memzero)(digest);
510
+ (0, _bcts_crypto.memzero)(verify);
511
+ if (!valid) throw new ShamirError("ChecksumFailure");
472
512
  return secret;
473
513
  }
474
514
  }
475
-
476
- //#endregion
477
- //#region src/index.ts
478
- /**
515
+ //#endregion
516
+ //#region src/index.ts
517
+ /**
518
+ * Copyright © 2023-2026 Blockchain Commons, LLC
519
+ * Copyright © 2025-2026 Parity Technologies
520
+ *
521
+ */
522
+ /**
479
523
  * The minimum length of a secret.
480
524
  */
481
525
  const MIN_SECRET_LEN = 16;
@@ -487,23 +531,15 @@ var BCShamir = (function(exports, __bcts_crypto) {
487
531
  * The maximum number of shares that can be generated from a secret.
488
532
  */
489
533
  const MAX_SHARE_COUNT = 16;
534
+ //#endregion
535
+ exports.MAX_SECRET_LEN = MAX_SECRET_LEN;
536
+ exports.MAX_SHARE_COUNT = MAX_SHARE_COUNT;
537
+ exports.MIN_SECRET_LEN = MIN_SECRET_LEN;
538
+ exports.ShamirError = ShamirError;
539
+ exports.ShamirErrorType = ShamirErrorType;
540
+ exports.recoverSecret = recoverSecret;
541
+ exports.splitSecret = splitSecret;
542
+ return exports;
543
+ })({}, bctsCrypto);
490
544
 
491
- //#endregion
492
- exports.MAX_SECRET_LEN = MAX_SECRET_LEN;
493
- exports.MAX_SHARE_COUNT = MAX_SHARE_COUNT;
494
- exports.MIN_SECRET_LEN = MIN_SECRET_LEN;
495
- exports.ShamirError = ShamirError;
496
- exports.ShamirErrorType = ShamirErrorType;
497
- exports.bitslice = bitslice;
498
- exports.bitsliceSetall = bitsliceSetall;
499
- exports.gf256Add = gf256Add;
500
- exports.gf256Inv = gf256Inv;
501
- exports.gf256Mul = gf256Mul;
502
- exports.gf256Square = gf256Square;
503
- exports.interpolate = interpolate;
504
- exports.recoverSecret = recoverSecret;
505
- exports.splitSecret = splitSecret;
506
- exports.unbitslice = unbitslice;
507
- return exports;
508
- })({}, BCCrypto);
509
545
  //# sourceMappingURL=index.iife.js.map