@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/LICENSE +48 -0
- package/README.md +15 -0
- package/dist/index.cjs +504 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +240 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +240 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.iife.js +506 -0
- package/dist/index.iife.js.map +1 -0
- package/dist/index.mjs +490 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +76 -0
- package/src/encoding.ts +326 -0
- package/src/error.ts +82 -0
- package/src/index.ts +60 -0
- package/src/secret.ts +90 -0
- package/src/share.ts +62 -0
- package/src/spec.ts +162 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { ShamirError } from "@bcts/shamir";
|
|
2
|
+
import { RandomNumberGenerator } from "@bcts/rand";
|
|
3
|
+
|
|
4
|
+
//#region src/error.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Error types for SSKR operations.
|
|
7
|
+
*/
|
|
8
|
+
declare enum SSKRErrorType {
|
|
9
|
+
DuplicateMemberIndex = "DuplicateMemberIndex",
|
|
10
|
+
GroupSpecInvalid = "GroupSpecInvalid",
|
|
11
|
+
GroupCountInvalid = "GroupCountInvalid",
|
|
12
|
+
GroupThresholdInvalid = "GroupThresholdInvalid",
|
|
13
|
+
MemberCountInvalid = "MemberCountInvalid",
|
|
14
|
+
MemberThresholdInvalid = "MemberThresholdInvalid",
|
|
15
|
+
NotEnoughGroups = "NotEnoughGroups",
|
|
16
|
+
SecretLengthNotEven = "SecretLengthNotEven",
|
|
17
|
+
SecretTooLong = "SecretTooLong",
|
|
18
|
+
SecretTooShort = "SecretTooShort",
|
|
19
|
+
ShareLengthInvalid = "ShareLengthInvalid",
|
|
20
|
+
ShareReservedBitsInvalid = "ShareReservedBitsInvalid",
|
|
21
|
+
SharesEmpty = "SharesEmpty",
|
|
22
|
+
ShareSetInvalid = "ShareSetInvalid",
|
|
23
|
+
ShamirError = "ShamirError",
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Error class for SSKR operations.
|
|
27
|
+
*/
|
|
28
|
+
declare class SSKRError extends Error {
|
|
29
|
+
readonly type: SSKRErrorType;
|
|
30
|
+
readonly shamirError?: ShamirError | undefined;
|
|
31
|
+
constructor(type: SSKRErrorType, message?: string, shamirError?: ShamirError);
|
|
32
|
+
private static defaultMessage;
|
|
33
|
+
static fromShamirError(error: ShamirError): SSKRError;
|
|
34
|
+
}
|
|
35
|
+
type SSKRResult<T> = T;
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/secret.d.ts
|
|
38
|
+
/**
|
|
39
|
+
* A secret to be split into shares.
|
|
40
|
+
*/
|
|
41
|
+
declare class Secret {
|
|
42
|
+
private readonly data;
|
|
43
|
+
private constructor();
|
|
44
|
+
/**
|
|
45
|
+
* Creates a new Secret instance with the given data.
|
|
46
|
+
*
|
|
47
|
+
* @param data - The secret data to be split into shares.
|
|
48
|
+
* @returns A new Secret instance.
|
|
49
|
+
* @throws SSKRError if the length of the secret is less than
|
|
50
|
+
* MIN_SECRET_LEN, greater than MAX_SECRET_LEN, or not even.
|
|
51
|
+
*/
|
|
52
|
+
static new(data: Uint8Array | string): Secret;
|
|
53
|
+
/**
|
|
54
|
+
* Returns the length of the secret.
|
|
55
|
+
*/
|
|
56
|
+
len(): number;
|
|
57
|
+
/**
|
|
58
|
+
* Returns true if the secret is empty.
|
|
59
|
+
*/
|
|
60
|
+
isEmpty(): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Returns a reference to the secret data.
|
|
63
|
+
*/
|
|
64
|
+
getData(): Uint8Array;
|
|
65
|
+
/**
|
|
66
|
+
* Returns the secret data as a Uint8Array.
|
|
67
|
+
*/
|
|
68
|
+
asRef(): Uint8Array;
|
|
69
|
+
/**
|
|
70
|
+
* Check equality with another Secret.
|
|
71
|
+
*/
|
|
72
|
+
equals(other: Secret): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Clone the secret.
|
|
75
|
+
*/
|
|
76
|
+
clone(): Secret;
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/spec.d.ts
|
|
80
|
+
/**
|
|
81
|
+
* A specification for a group of shares within an SSKR split.
|
|
82
|
+
*/
|
|
83
|
+
declare class GroupSpec {
|
|
84
|
+
private readonly _memberThreshold;
|
|
85
|
+
private readonly _memberCount;
|
|
86
|
+
private constructor();
|
|
87
|
+
/**
|
|
88
|
+
* Creates a new GroupSpec instance with the given member threshold and count.
|
|
89
|
+
*
|
|
90
|
+
* @param memberThreshold - The minimum number of member shares required to
|
|
91
|
+
* reconstruct the secret within the group.
|
|
92
|
+
* @param memberCount - The total number of member shares in the group.
|
|
93
|
+
* @returns A new GroupSpec instance.
|
|
94
|
+
* @throws SSKRError if the member count is zero, if the member count is
|
|
95
|
+
* greater than the maximum share count, or if the member threshold is
|
|
96
|
+
* greater than the member count.
|
|
97
|
+
*/
|
|
98
|
+
static new(memberThreshold: number, memberCount: number): GroupSpec;
|
|
99
|
+
/**
|
|
100
|
+
* Returns the member share threshold for this group.
|
|
101
|
+
*/
|
|
102
|
+
memberThreshold(): number;
|
|
103
|
+
/**
|
|
104
|
+
* Returns the number of member shares in this group.
|
|
105
|
+
*/
|
|
106
|
+
memberCount(): number;
|
|
107
|
+
/**
|
|
108
|
+
* Parses a group specification from a string.
|
|
109
|
+
* Format: "M-of-N" where M is the threshold and N is the count.
|
|
110
|
+
*/
|
|
111
|
+
static parse(s: string): GroupSpec;
|
|
112
|
+
/**
|
|
113
|
+
* Creates a default GroupSpec (1-of-1).
|
|
114
|
+
*/
|
|
115
|
+
static default(): GroupSpec;
|
|
116
|
+
/**
|
|
117
|
+
* Returns a string representation of the group spec.
|
|
118
|
+
*/
|
|
119
|
+
toString(): string;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* A specification for an SSKR split.
|
|
123
|
+
*/
|
|
124
|
+
declare class Spec {
|
|
125
|
+
private readonly _groupThreshold;
|
|
126
|
+
private readonly _groups;
|
|
127
|
+
private constructor();
|
|
128
|
+
/**
|
|
129
|
+
* Creates a new Spec instance with the given group threshold and groups.
|
|
130
|
+
*
|
|
131
|
+
* @param groupThreshold - The minimum number of groups required to
|
|
132
|
+
* reconstruct the secret.
|
|
133
|
+
* @param groups - The list of GroupSpec instances that define the groups
|
|
134
|
+
* and their members.
|
|
135
|
+
* @returns A new Spec instance.
|
|
136
|
+
* @throws SSKRError if the group threshold is zero, if the group threshold
|
|
137
|
+
* is greater than the number of groups, or if the number of groups is
|
|
138
|
+
* greater than the maximum share count.
|
|
139
|
+
*/
|
|
140
|
+
static new(groupThreshold: number, groups: GroupSpec[]): Spec;
|
|
141
|
+
/**
|
|
142
|
+
* Returns the group threshold.
|
|
143
|
+
*/
|
|
144
|
+
groupThreshold(): number;
|
|
145
|
+
/**
|
|
146
|
+
* Returns a slice of the group specifications.
|
|
147
|
+
*/
|
|
148
|
+
groups(): GroupSpec[];
|
|
149
|
+
/**
|
|
150
|
+
* Returns the number of groups.
|
|
151
|
+
*/
|
|
152
|
+
groupCount(): number;
|
|
153
|
+
/**
|
|
154
|
+
* Returns the total number of shares across all groups.
|
|
155
|
+
*/
|
|
156
|
+
shareCount(): number;
|
|
157
|
+
}
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/share.d.ts
|
|
160
|
+
/**
|
|
161
|
+
* A share in the SSKR scheme.
|
|
162
|
+
*/
|
|
163
|
+
declare class SSKRShare {
|
|
164
|
+
private readonly _identifier;
|
|
165
|
+
private readonly _groupIndex;
|
|
166
|
+
private readonly _groupThreshold;
|
|
167
|
+
private readonly _groupCount;
|
|
168
|
+
private readonly _memberIndex;
|
|
169
|
+
private readonly _memberThreshold;
|
|
170
|
+
private readonly _value;
|
|
171
|
+
constructor(identifier: number, groupIndex: number, groupThreshold: number, groupCount: number, memberIndex: number, memberThreshold: number, value: Secret);
|
|
172
|
+
identifier(): number;
|
|
173
|
+
groupIndex(): number;
|
|
174
|
+
groupThreshold(): number;
|
|
175
|
+
groupCount(): number;
|
|
176
|
+
memberIndex(): number;
|
|
177
|
+
memberThreshold(): number;
|
|
178
|
+
value(): Secret;
|
|
179
|
+
}
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region src/encoding.d.ts
|
|
182
|
+
/**
|
|
183
|
+
* Generates SSKR shares for the given Spec and Secret.
|
|
184
|
+
*
|
|
185
|
+
* @param spec - The Spec instance that defines the group and member thresholds.
|
|
186
|
+
* @param masterSecret - The Secret instance to be split into shares.
|
|
187
|
+
* @returns A vector of groups, each containing a vector of shares,
|
|
188
|
+
* each of which is a Uint8Array.
|
|
189
|
+
*/
|
|
190
|
+
declare function sskrGenerate(spec: Spec, masterSecret: Secret): Uint8Array[][];
|
|
191
|
+
/**
|
|
192
|
+
* Generates SSKR shares for the given Spec and Secret using the provided
|
|
193
|
+
* random number generator.
|
|
194
|
+
*
|
|
195
|
+
* @param spec - The Spec instance that defines the group and member thresholds.
|
|
196
|
+
* @param masterSecret - The Secret instance to be split into shares.
|
|
197
|
+
* @param randomGenerator - The random number generator to use for generating
|
|
198
|
+
* shares.
|
|
199
|
+
* @returns A vector of groups, each containing a vector of shares,
|
|
200
|
+
* each of which is a Uint8Array.
|
|
201
|
+
*/
|
|
202
|
+
declare function sskrGenerateUsing(spec: Spec, masterSecret: Secret, randomGenerator: RandomNumberGenerator): Uint8Array[][];
|
|
203
|
+
/**
|
|
204
|
+
* Combines the given SSKR shares into a Secret.
|
|
205
|
+
*
|
|
206
|
+
* @param shares - A array of SSKR shares to be combined.
|
|
207
|
+
* @returns The reconstructed Secret.
|
|
208
|
+
* @throws SSKRError if the shares do not meet the necessary quorum of groups
|
|
209
|
+
* and member shares within each group.
|
|
210
|
+
*/
|
|
211
|
+
declare function sskrCombine(shares: Uint8Array[]): Secret;
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/index.d.ts
|
|
214
|
+
/**
|
|
215
|
+
* The minimum length of a secret.
|
|
216
|
+
*/
|
|
217
|
+
declare const MIN_SECRET_LEN: any;
|
|
218
|
+
/**
|
|
219
|
+
* The maximum length of a secret.
|
|
220
|
+
*/
|
|
221
|
+
declare const MAX_SECRET_LEN: any;
|
|
222
|
+
/**
|
|
223
|
+
* The maximum number of shares that can be generated from a secret.
|
|
224
|
+
*/
|
|
225
|
+
declare const MAX_SHARE_COUNT: any;
|
|
226
|
+
/**
|
|
227
|
+
* The maximum number of groups in a split.
|
|
228
|
+
*/
|
|
229
|
+
declare const MAX_GROUPS_COUNT: any;
|
|
230
|
+
/**
|
|
231
|
+
* The number of bytes used to encode the metadata for a share.
|
|
232
|
+
*/
|
|
233
|
+
declare const METADATA_SIZE_BYTES = 5;
|
|
234
|
+
/**
|
|
235
|
+
* The minimum number of bytes required to encode a share.
|
|
236
|
+
*/
|
|
237
|
+
declare const MIN_SERIALIZE_SIZE_BYTES: any;
|
|
238
|
+
//#endregion
|
|
239
|
+
export { GroupSpec, MAX_GROUPS_COUNT, MAX_SECRET_LEN, MAX_SHARE_COUNT, METADATA_SIZE_BYTES, MIN_SECRET_LEN, MIN_SERIALIZE_SIZE_BYTES, SSKRError, SSKRErrorType, type SSKRResult, SSKRShare, Secret, Spec, sskrCombine, sskrGenerate, sskrGenerateUsing };
|
|
240
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/error.ts","../src/secret.ts","../src/spec.ts","../src/share.ts","../src/encoding.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;AAOY,aAAA,aAAA;EAqBC,oBAAU,GAAA,sBAAA;EACN,gBAAA,GAAA,kBAAA;EACQ,iBAAA,GAAA,mBAAA;EAEL,qBAAA,GAAA,uBAAA;EAA+C,kBAAA,GAAA,oBAAA;EA4CnC,sBAAA,GAAA,wBAAA;EAAc,eAAA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J1Bb;AAemB,cIgBN,mBAAA,GJhBM,CAAA;;;;AAgDH,cI3BH,wBJ2BG,EAAA,GAAA"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { ShamirError } from "@bcts/shamir";
|
|
2
|
+
import { RandomNumberGenerator } from "@bcts/rand";
|
|
3
|
+
|
|
4
|
+
//#region src/error.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Error types for SSKR operations.
|
|
7
|
+
*/
|
|
8
|
+
declare enum SSKRErrorType {
|
|
9
|
+
DuplicateMemberIndex = "DuplicateMemberIndex",
|
|
10
|
+
GroupSpecInvalid = "GroupSpecInvalid",
|
|
11
|
+
GroupCountInvalid = "GroupCountInvalid",
|
|
12
|
+
GroupThresholdInvalid = "GroupThresholdInvalid",
|
|
13
|
+
MemberCountInvalid = "MemberCountInvalid",
|
|
14
|
+
MemberThresholdInvalid = "MemberThresholdInvalid",
|
|
15
|
+
NotEnoughGroups = "NotEnoughGroups",
|
|
16
|
+
SecretLengthNotEven = "SecretLengthNotEven",
|
|
17
|
+
SecretTooLong = "SecretTooLong",
|
|
18
|
+
SecretTooShort = "SecretTooShort",
|
|
19
|
+
ShareLengthInvalid = "ShareLengthInvalid",
|
|
20
|
+
ShareReservedBitsInvalid = "ShareReservedBitsInvalid",
|
|
21
|
+
SharesEmpty = "SharesEmpty",
|
|
22
|
+
ShareSetInvalid = "ShareSetInvalid",
|
|
23
|
+
ShamirError = "ShamirError",
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Error class for SSKR operations.
|
|
27
|
+
*/
|
|
28
|
+
declare class SSKRError extends Error {
|
|
29
|
+
readonly type: SSKRErrorType;
|
|
30
|
+
readonly shamirError?: ShamirError | undefined;
|
|
31
|
+
constructor(type: SSKRErrorType, message?: string, shamirError?: ShamirError);
|
|
32
|
+
private static defaultMessage;
|
|
33
|
+
static fromShamirError(error: ShamirError): SSKRError;
|
|
34
|
+
}
|
|
35
|
+
type SSKRResult<T> = T;
|
|
36
|
+
//#endregion
|
|
37
|
+
//#region src/secret.d.ts
|
|
38
|
+
/**
|
|
39
|
+
* A secret to be split into shares.
|
|
40
|
+
*/
|
|
41
|
+
declare class Secret {
|
|
42
|
+
private readonly data;
|
|
43
|
+
private constructor();
|
|
44
|
+
/**
|
|
45
|
+
* Creates a new Secret instance with the given data.
|
|
46
|
+
*
|
|
47
|
+
* @param data - The secret data to be split into shares.
|
|
48
|
+
* @returns A new Secret instance.
|
|
49
|
+
* @throws SSKRError if the length of the secret is less than
|
|
50
|
+
* MIN_SECRET_LEN, greater than MAX_SECRET_LEN, or not even.
|
|
51
|
+
*/
|
|
52
|
+
static new(data: Uint8Array | string): Secret;
|
|
53
|
+
/**
|
|
54
|
+
* Returns the length of the secret.
|
|
55
|
+
*/
|
|
56
|
+
len(): number;
|
|
57
|
+
/**
|
|
58
|
+
* Returns true if the secret is empty.
|
|
59
|
+
*/
|
|
60
|
+
isEmpty(): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Returns a reference to the secret data.
|
|
63
|
+
*/
|
|
64
|
+
getData(): Uint8Array;
|
|
65
|
+
/**
|
|
66
|
+
* Returns the secret data as a Uint8Array.
|
|
67
|
+
*/
|
|
68
|
+
asRef(): Uint8Array;
|
|
69
|
+
/**
|
|
70
|
+
* Check equality with another Secret.
|
|
71
|
+
*/
|
|
72
|
+
equals(other: Secret): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Clone the secret.
|
|
75
|
+
*/
|
|
76
|
+
clone(): Secret;
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/spec.d.ts
|
|
80
|
+
/**
|
|
81
|
+
* A specification for a group of shares within an SSKR split.
|
|
82
|
+
*/
|
|
83
|
+
declare class GroupSpec {
|
|
84
|
+
private readonly _memberThreshold;
|
|
85
|
+
private readonly _memberCount;
|
|
86
|
+
private constructor();
|
|
87
|
+
/**
|
|
88
|
+
* Creates a new GroupSpec instance with the given member threshold and count.
|
|
89
|
+
*
|
|
90
|
+
* @param memberThreshold - The minimum number of member shares required to
|
|
91
|
+
* reconstruct the secret within the group.
|
|
92
|
+
* @param memberCount - The total number of member shares in the group.
|
|
93
|
+
* @returns A new GroupSpec instance.
|
|
94
|
+
* @throws SSKRError if the member count is zero, if the member count is
|
|
95
|
+
* greater than the maximum share count, or if the member threshold is
|
|
96
|
+
* greater than the member count.
|
|
97
|
+
*/
|
|
98
|
+
static new(memberThreshold: number, memberCount: number): GroupSpec;
|
|
99
|
+
/**
|
|
100
|
+
* Returns the member share threshold for this group.
|
|
101
|
+
*/
|
|
102
|
+
memberThreshold(): number;
|
|
103
|
+
/**
|
|
104
|
+
* Returns the number of member shares in this group.
|
|
105
|
+
*/
|
|
106
|
+
memberCount(): number;
|
|
107
|
+
/**
|
|
108
|
+
* Parses a group specification from a string.
|
|
109
|
+
* Format: "M-of-N" where M is the threshold and N is the count.
|
|
110
|
+
*/
|
|
111
|
+
static parse(s: string): GroupSpec;
|
|
112
|
+
/**
|
|
113
|
+
* Creates a default GroupSpec (1-of-1).
|
|
114
|
+
*/
|
|
115
|
+
static default(): GroupSpec;
|
|
116
|
+
/**
|
|
117
|
+
* Returns a string representation of the group spec.
|
|
118
|
+
*/
|
|
119
|
+
toString(): string;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* A specification for an SSKR split.
|
|
123
|
+
*/
|
|
124
|
+
declare class Spec {
|
|
125
|
+
private readonly _groupThreshold;
|
|
126
|
+
private readonly _groups;
|
|
127
|
+
private constructor();
|
|
128
|
+
/**
|
|
129
|
+
* Creates a new Spec instance with the given group threshold and groups.
|
|
130
|
+
*
|
|
131
|
+
* @param groupThreshold - The minimum number of groups required to
|
|
132
|
+
* reconstruct the secret.
|
|
133
|
+
* @param groups - The list of GroupSpec instances that define the groups
|
|
134
|
+
* and their members.
|
|
135
|
+
* @returns A new Spec instance.
|
|
136
|
+
* @throws SSKRError if the group threshold is zero, if the group threshold
|
|
137
|
+
* is greater than the number of groups, or if the number of groups is
|
|
138
|
+
* greater than the maximum share count.
|
|
139
|
+
*/
|
|
140
|
+
static new(groupThreshold: number, groups: GroupSpec[]): Spec;
|
|
141
|
+
/**
|
|
142
|
+
* Returns the group threshold.
|
|
143
|
+
*/
|
|
144
|
+
groupThreshold(): number;
|
|
145
|
+
/**
|
|
146
|
+
* Returns a slice of the group specifications.
|
|
147
|
+
*/
|
|
148
|
+
groups(): GroupSpec[];
|
|
149
|
+
/**
|
|
150
|
+
* Returns the number of groups.
|
|
151
|
+
*/
|
|
152
|
+
groupCount(): number;
|
|
153
|
+
/**
|
|
154
|
+
* Returns the total number of shares across all groups.
|
|
155
|
+
*/
|
|
156
|
+
shareCount(): number;
|
|
157
|
+
}
|
|
158
|
+
//#endregion
|
|
159
|
+
//#region src/share.d.ts
|
|
160
|
+
/**
|
|
161
|
+
* A share in the SSKR scheme.
|
|
162
|
+
*/
|
|
163
|
+
declare class SSKRShare {
|
|
164
|
+
private readonly _identifier;
|
|
165
|
+
private readonly _groupIndex;
|
|
166
|
+
private readonly _groupThreshold;
|
|
167
|
+
private readonly _groupCount;
|
|
168
|
+
private readonly _memberIndex;
|
|
169
|
+
private readonly _memberThreshold;
|
|
170
|
+
private readonly _value;
|
|
171
|
+
constructor(identifier: number, groupIndex: number, groupThreshold: number, groupCount: number, memberIndex: number, memberThreshold: number, value: Secret);
|
|
172
|
+
identifier(): number;
|
|
173
|
+
groupIndex(): number;
|
|
174
|
+
groupThreshold(): number;
|
|
175
|
+
groupCount(): number;
|
|
176
|
+
memberIndex(): number;
|
|
177
|
+
memberThreshold(): number;
|
|
178
|
+
value(): Secret;
|
|
179
|
+
}
|
|
180
|
+
//#endregion
|
|
181
|
+
//#region src/encoding.d.ts
|
|
182
|
+
/**
|
|
183
|
+
* Generates SSKR shares for the given Spec and Secret.
|
|
184
|
+
*
|
|
185
|
+
* @param spec - The Spec instance that defines the group and member thresholds.
|
|
186
|
+
* @param masterSecret - The Secret instance to be split into shares.
|
|
187
|
+
* @returns A vector of groups, each containing a vector of shares,
|
|
188
|
+
* each of which is a Uint8Array.
|
|
189
|
+
*/
|
|
190
|
+
declare function sskrGenerate(spec: Spec, masterSecret: Secret): Uint8Array[][];
|
|
191
|
+
/**
|
|
192
|
+
* Generates SSKR shares for the given Spec and Secret using the provided
|
|
193
|
+
* random number generator.
|
|
194
|
+
*
|
|
195
|
+
* @param spec - The Spec instance that defines the group and member thresholds.
|
|
196
|
+
* @param masterSecret - The Secret instance to be split into shares.
|
|
197
|
+
* @param randomGenerator - The random number generator to use for generating
|
|
198
|
+
* shares.
|
|
199
|
+
* @returns A vector of groups, each containing a vector of shares,
|
|
200
|
+
* each of which is a Uint8Array.
|
|
201
|
+
*/
|
|
202
|
+
declare function sskrGenerateUsing(spec: Spec, masterSecret: Secret, randomGenerator: RandomNumberGenerator): Uint8Array[][];
|
|
203
|
+
/**
|
|
204
|
+
* Combines the given SSKR shares into a Secret.
|
|
205
|
+
*
|
|
206
|
+
* @param shares - A array of SSKR shares to be combined.
|
|
207
|
+
* @returns The reconstructed Secret.
|
|
208
|
+
* @throws SSKRError if the shares do not meet the necessary quorum of groups
|
|
209
|
+
* and member shares within each group.
|
|
210
|
+
*/
|
|
211
|
+
declare function sskrCombine(shares: Uint8Array[]): Secret;
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/index.d.ts
|
|
214
|
+
/**
|
|
215
|
+
* The minimum length of a secret.
|
|
216
|
+
*/
|
|
217
|
+
declare const MIN_SECRET_LEN: any;
|
|
218
|
+
/**
|
|
219
|
+
* The maximum length of a secret.
|
|
220
|
+
*/
|
|
221
|
+
declare const MAX_SECRET_LEN: any;
|
|
222
|
+
/**
|
|
223
|
+
* The maximum number of shares that can be generated from a secret.
|
|
224
|
+
*/
|
|
225
|
+
declare const MAX_SHARE_COUNT: any;
|
|
226
|
+
/**
|
|
227
|
+
* The maximum number of groups in a split.
|
|
228
|
+
*/
|
|
229
|
+
declare const MAX_GROUPS_COUNT: any;
|
|
230
|
+
/**
|
|
231
|
+
* The number of bytes used to encode the metadata for a share.
|
|
232
|
+
*/
|
|
233
|
+
declare const METADATA_SIZE_BYTES = 5;
|
|
234
|
+
/**
|
|
235
|
+
* The minimum number of bytes required to encode a share.
|
|
236
|
+
*/
|
|
237
|
+
declare const MIN_SERIALIZE_SIZE_BYTES: any;
|
|
238
|
+
//#endregion
|
|
239
|
+
export { GroupSpec, MAX_GROUPS_COUNT, MAX_SECRET_LEN, MAX_SHARE_COUNT, METADATA_SIZE_BYTES, MIN_SECRET_LEN, MIN_SERIALIZE_SIZE_BYTES, SSKRError, SSKRErrorType, type SSKRResult, SSKRShare, Secret, Spec, sskrCombine, sskrGenerate, sskrGenerateUsing };
|
|
240
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/error.ts","../src/secret.ts","../src/spec.ts","../src/share.ts","../src/encoding.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;AAOY,aAAA,aAAA;EAqBC,oBAAU,GAAA,sBAAA;EACN,gBAAA,GAAA,kBAAA;EACQ,iBAAA,GAAA,mBAAA;EAEL,qBAAA,GAAA,uBAAA;EAA+C,kBAAA,GAAA,oBAAA;EA4CnC,sBAAA,GAAA,wBAAA;EAAc,eAAA,GAAA,iBAAA;EAhDf,mBAAA,GAAA,qBAAA;EAAK,aAAA,GAAA,eAAA;EAqDxB,cAAU,GAAA,gBAAO;;;;ECzEhB,eAAM,GAAA,iBAAA;EAeA,WAAA,GAAA,aAAA;;;;;AA+DR,cD1DE,SAAA,SAAkB,KAAA,CC0DpB;EAAM,SAAA,IAAA,EDzDA,aCyDA;yBDxDQ;oBAEL,+CAA+C;;EExBtD,OAAA,eAAS,CAAA,KAAA,EFoEU,WEpEV,CAAA,EFoEwB,SEpExB;;AAmDK,KFsBf,UEtBe,CAAA,CAAA,CAAA,GFsBC,CEtBD;;;;;;cDnDd,MAAA;EDDD,i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