@digitaldefiance/node-ecies-lib 4.7.14 → 4.8.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/package.json +3 -3
- package/src/builders/member-builder.d.ts +3 -2
- package/src/builders/member-builder.d.ts.map +1 -1
- package/src/builders/member-builder.js.map +1 -1
- package/src/constants.d.ts +10 -0
- package/src/constants.d.ts.map +1 -1
- package/src/constants.js +27 -0
- package/src/constants.js.map +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.d.ts.map +1 -1
- package/src/index.js +1 -0
- package/src/index.js.map +1 -1
- package/src/interfaces/configuration-provenance.d.ts +49 -0
- package/src/interfaces/configuration-provenance.d.ts.map +1 -0
- package/src/interfaces/{backend-member-operational.js → configuration-provenance.js} +1 -1
- package/src/interfaces/configuration-provenance.js.map +1 -0
- package/src/interfaces/id-provider.d.ts +86 -0
- package/src/interfaces/id-provider.d.ts.map +1 -0
- package/src/interfaces/id-provider.js +3 -0
- package/src/interfaces/id-provider.js.map +1 -0
- package/src/interfaces/index.d.ts +6 -1
- package/src/interfaces/index.d.ts.map +1 -1
- package/src/interfaces/index.js +8 -2
- package/src/interfaces/index.js.map +1 -1
- package/src/interfaces/isolated-keys.d.ts +70 -0
- package/src/interfaces/isolated-keys.d.ts.map +1 -0
- package/src/interfaces/isolated-keys.js +7 -0
- package/src/interfaces/isolated-keys.js.map +1 -0
- package/src/interfaces/member.d.ts +3 -2
- package/src/interfaces/member.d.ts.map +1 -1
- package/src/interfaces/platform-id.d.ts +4 -0
- package/src/interfaces/platform-id.d.ts.map +1 -0
- package/src/interfaces/platform-id.js +3 -0
- package/src/interfaces/platform-id.js.map +1 -0
- package/src/interfaces/voting-poll.d.ts +447 -0
- package/src/interfaces/voting-poll.d.ts.map +1 -0
- package/src/interfaces/voting-poll.js +47 -0
- package/src/interfaces/voting-poll.js.map +1 -0
- package/src/interfaces/voting-service.d.ts +130 -0
- package/src/interfaces/voting-service.d.ts.map +1 -0
- package/src/interfaces/voting-service.js +10 -0
- package/src/interfaces/voting-service.js.map +1 -0
- package/src/lib/voting/audit.d.ts +26 -15
- package/src/lib/voting/audit.d.ts.map +1 -1
- package/src/lib/voting/audit.js +4 -4
- package/src/lib/voting/audit.js.map +1 -1
- package/src/lib/voting/factory.d.ts +8 -7
- package/src/lib/voting/factory.d.ts.map +1 -1
- package/src/lib/voting/factory.js.map +1 -1
- package/src/lib/voting/poll-core.d.ts +7 -6
- package/src/lib/voting/poll-core.d.ts.map +1 -1
- package/src/lib/voting/poll-core.js +5 -5
- package/src/lib/voting/poll-core.js.map +1 -1
- package/src/member.d.ts +9 -7
- package/src/member.d.ts.map +1 -1
- package/src/member.js +11 -2
- package/src/member.js.map +1 -1
- package/src/secure-buffer.d.ts +62 -0
- package/src/secure-buffer.d.ts.map +1 -0
- package/src/secure-buffer.js +205 -0
- package/src/secure-buffer.js.map +1 -0
- package/src/test-mocks/mock-backend-member.d.ts +12 -6
- package/src/test-mocks/mock-backend-member.d.ts.map +1 -1
- package/src/test-mocks/mock-backend-member.js +24 -1
- package/src/test-mocks/mock-backend-member.js.map +1 -1
- package/src/interfaces/backend-member-operational.d.ts +0 -48
- package/src/interfaces/backend-member-operational.d.ts.map +0 -1
- package/src/interfaces/backend-member-operational.js.map +0 -1
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Voting Poll System Interfaces (Node.js Buffer version)
|
|
3
|
+
*
|
|
4
|
+
* Node.js-specific interfaces for the voting poll system using Buffer instead of Uint8Array.
|
|
5
|
+
* These interfaces ensure type safety and API consistency with the browser version.
|
|
6
|
+
*/
|
|
7
|
+
import type { PublicKey, PrivateKey, KeyPair } from 'paillier-bigint';
|
|
8
|
+
/**
|
|
9
|
+
* Voting methods supported by the poll system
|
|
10
|
+
*/
|
|
11
|
+
export declare enum VotingMethod {
|
|
12
|
+
Plurality = "plurality",
|
|
13
|
+
Approval = "approval",
|
|
14
|
+
Weighted = "weighted",
|
|
15
|
+
Borda = "borda",
|
|
16
|
+
Score = "score",
|
|
17
|
+
YesNo = "yes-no",
|
|
18
|
+
YesNoAbstain = "yes-no-abstain",
|
|
19
|
+
Supermajority = "supermajority",
|
|
20
|
+
RankedChoice = "ranked-choice",
|
|
21
|
+
TwoRound = "two-round",
|
|
22
|
+
STAR = "star",
|
|
23
|
+
STV = "stv",
|
|
24
|
+
Quadratic = "quadratic",
|
|
25
|
+
Consensus = "consensus",
|
|
26
|
+
ConsentBased = "consent-based"
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Vote receipt proving participation.
|
|
30
|
+
* Cryptographically signed proof that a vote was cast.
|
|
31
|
+
*/
|
|
32
|
+
export interface IVoteReceipt {
|
|
33
|
+
/** Unique identifier of the voter */
|
|
34
|
+
voterId: Buffer;
|
|
35
|
+
/** Unique identifier of the poll */
|
|
36
|
+
pollId: Buffer;
|
|
37
|
+
/** Unix timestamp when vote was cast */
|
|
38
|
+
timestamp: number;
|
|
39
|
+
/** Cryptographic signature from poll authority */
|
|
40
|
+
signature: Buffer;
|
|
41
|
+
/** Random nonce for uniqueness */
|
|
42
|
+
nonce: Buffer;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Encrypted vote data using Paillier homomorphic encryption.
|
|
46
|
+
* Structure varies by voting method.
|
|
47
|
+
*/
|
|
48
|
+
export interface IEncryptedVote {
|
|
49
|
+
/** Single choice index (for Plurality, Weighted, etc.) */
|
|
50
|
+
choiceIndex?: number;
|
|
51
|
+
/** Multiple choice indices (for Approval voting) */
|
|
52
|
+
choices?: number[];
|
|
53
|
+
/** Ranked choice indices in preference order (for RCV, Borda) */
|
|
54
|
+
rankings?: number[];
|
|
55
|
+
/** Vote weight (for Weighted voting) */
|
|
56
|
+
weight?: bigint;
|
|
57
|
+
/** Score value 0-10 (for Score voting) */
|
|
58
|
+
score?: number;
|
|
59
|
+
/** Array of encrypted vote values (one per choice) */
|
|
60
|
+
encrypted: bigint[];
|
|
61
|
+
/** Plaintext vote data (only for insecure methods) */
|
|
62
|
+
plaintext?: IPlaintextVote;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Plaintext vote data for insecure voting methods.
|
|
66
|
+
* WARNING: Only use for Quadratic, Consensus, or ConsentBased methods.
|
|
67
|
+
*/
|
|
68
|
+
export interface IPlaintextVote {
|
|
69
|
+
/** Unique identifier of the voter */
|
|
70
|
+
voterId: Buffer;
|
|
71
|
+
/** Single choice index */
|
|
72
|
+
choiceIndex?: number;
|
|
73
|
+
/** Multiple choice indices */
|
|
74
|
+
choices?: number[];
|
|
75
|
+
/** Vote weight */
|
|
76
|
+
weight?: bigint;
|
|
77
|
+
/** Objection text (for consent-based voting) */
|
|
78
|
+
objection?: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Results of a completed poll after tallying.
|
|
82
|
+
* Includes winner(s), tallies, and round-by-round data for multi-round methods.
|
|
83
|
+
*/
|
|
84
|
+
export interface IPollResults {
|
|
85
|
+
/** Voting method used */
|
|
86
|
+
method: VotingMethod;
|
|
87
|
+
/** Array of choice names */
|
|
88
|
+
choices: string[];
|
|
89
|
+
/** Index of winning choice (undefined if tie) */
|
|
90
|
+
winner?: number;
|
|
91
|
+
/** Indices of tied winners (for ties or multi-winner methods) */
|
|
92
|
+
winners?: number[];
|
|
93
|
+
/** Indices of eliminated choices (for RCV) */
|
|
94
|
+
eliminated?: number[];
|
|
95
|
+
/** Round-by-round results (for multi-round methods) */
|
|
96
|
+
rounds?: IRoundResult[];
|
|
97
|
+
/** Final vote tallies for each choice */
|
|
98
|
+
tallies: bigint[];
|
|
99
|
+
/** Total number of unique voters */
|
|
100
|
+
voterCount: number;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Results from a single round of multi-round voting.
|
|
104
|
+
* Used in RCV, Two-Round, STAR, and STV methods.
|
|
105
|
+
*/
|
|
106
|
+
export interface IRoundResult {
|
|
107
|
+
/** Round number (1-indexed) */
|
|
108
|
+
round: number;
|
|
109
|
+
/** Vote tallies for this round */
|
|
110
|
+
tallies: bigint[];
|
|
111
|
+
/** Index of choice eliminated this round (if any) */
|
|
112
|
+
eliminated?: number;
|
|
113
|
+
/** Index of winner determined this round (if any) */
|
|
114
|
+
winner?: number;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Configuration for supermajority voting.
|
|
118
|
+
* Defines the required threshold as a fraction (e.g., 2/3, 3/4).
|
|
119
|
+
*/
|
|
120
|
+
export interface ISupermajorityConfig {
|
|
121
|
+
/** Numerator of the fraction (e.g., 2 for 2/3) */
|
|
122
|
+
numerator: number;
|
|
123
|
+
/** Denominator of the fraction (e.g., 3 for 2/3) */
|
|
124
|
+
denominator: number;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Member interface for voting operations.
|
|
128
|
+
* Extends base member with voting-specific capabilities.
|
|
129
|
+
*/
|
|
130
|
+
export interface IVotingMember {
|
|
131
|
+
/** Unique identifier of the member */
|
|
132
|
+
readonly id: Buffer;
|
|
133
|
+
/** ECDSA public key for signing */
|
|
134
|
+
readonly publicKey: Buffer;
|
|
135
|
+
/** Paillier public key for vote encryption (optional) */
|
|
136
|
+
readonly votingPublicKey?: PublicKey;
|
|
137
|
+
/** Paillier private key for vote decryption (optional) */
|
|
138
|
+
readonly votingPrivateKey?: PrivateKey;
|
|
139
|
+
/**
|
|
140
|
+
* Sign data with member's private key.
|
|
141
|
+
* @param data - Data to sign
|
|
142
|
+
* @returns Signature
|
|
143
|
+
*/
|
|
144
|
+
sign(data: Buffer): Buffer;
|
|
145
|
+
/**
|
|
146
|
+
* Verify signature against data.
|
|
147
|
+
* @param signature - Signature to verify
|
|
148
|
+
* @param data - Original data
|
|
149
|
+
* @returns True if signature is valid
|
|
150
|
+
*/
|
|
151
|
+
verify(signature: Buffer, data: Buffer): boolean;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Poll interface for vote aggregation and management.
|
|
155
|
+
* Holds encrypted votes and issues receipts, but cannot decrypt votes.
|
|
156
|
+
*/
|
|
157
|
+
export interface IPoll {
|
|
158
|
+
/** Unique identifier of the poll */
|
|
159
|
+
readonly id: Buffer;
|
|
160
|
+
/** Array of choice names */
|
|
161
|
+
readonly choices: ReadonlyArray<string>;
|
|
162
|
+
/** Voting method used */
|
|
163
|
+
readonly method: VotingMethod;
|
|
164
|
+
/** Whether poll is closed to new votes */
|
|
165
|
+
readonly isClosed: boolean;
|
|
166
|
+
/** Total number of unique voters */
|
|
167
|
+
readonly voterCount: number;
|
|
168
|
+
/** Unix timestamp when poll was created */
|
|
169
|
+
readonly createdAt: number;
|
|
170
|
+
/** Unix timestamp when poll was closed (undefined if open) */
|
|
171
|
+
readonly closedAt: number | undefined;
|
|
172
|
+
/**
|
|
173
|
+
* Cast a vote in the poll.
|
|
174
|
+
* @param voter - Member casting the vote
|
|
175
|
+
* @param vote - Encrypted vote data
|
|
176
|
+
* @returns Vote receipt
|
|
177
|
+
* @throws Error if poll is closed or voter already voted
|
|
178
|
+
*/
|
|
179
|
+
vote(voter: IVotingMember, vote: IEncryptedVote): IVoteReceipt;
|
|
180
|
+
/**
|
|
181
|
+
* Verify a vote receipt is valid.
|
|
182
|
+
* @param voter - Member who cast the vote
|
|
183
|
+
* @param receipt - Receipt to verify
|
|
184
|
+
* @returns True if receipt is valid
|
|
185
|
+
*/
|
|
186
|
+
verifyReceipt(voter: IVotingMember, receipt: IVoteReceipt): boolean;
|
|
187
|
+
/**
|
|
188
|
+
* Close the poll to new votes.
|
|
189
|
+
* @throws Error if poll is already closed
|
|
190
|
+
*/
|
|
191
|
+
close(): void;
|
|
192
|
+
/**
|
|
193
|
+
* Get encrypted votes for tallying (read-only).
|
|
194
|
+
* @returns Map of voter ID to encrypted vote data
|
|
195
|
+
*/
|
|
196
|
+
getEncryptedVotes(): ReadonlyMap<string, readonly bigint[]>;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Vote encoder interface for encrypting votes.
|
|
200
|
+
* Converts vote choices into encrypted Paillier ciphertexts.
|
|
201
|
+
*/
|
|
202
|
+
export interface IVoteEncoder {
|
|
203
|
+
/**
|
|
204
|
+
* Encode a plurality vote (single choice).
|
|
205
|
+
* @param choiceIndex - Index of chosen option
|
|
206
|
+
* @param choiceCount - Total number of choices
|
|
207
|
+
* @returns Encrypted vote
|
|
208
|
+
*/
|
|
209
|
+
encodePlurality(choiceIndex: number, choiceCount: number): IEncryptedVote;
|
|
210
|
+
/**
|
|
211
|
+
* Encode an approval vote (multiple choices).
|
|
212
|
+
* @param choices - Indices of approved options
|
|
213
|
+
* @param choiceCount - Total number of choices
|
|
214
|
+
* @returns Encrypted vote
|
|
215
|
+
*/
|
|
216
|
+
encodeApproval(choices: number[], choiceCount: number): IEncryptedVote;
|
|
217
|
+
/**
|
|
218
|
+
* Encode a weighted vote.
|
|
219
|
+
* @param choiceIndex - Index of chosen option
|
|
220
|
+
* @param weight - Vote weight (must be positive)
|
|
221
|
+
* @param choiceCount - Total number of choices
|
|
222
|
+
* @returns Encrypted vote
|
|
223
|
+
*/
|
|
224
|
+
encodeWeighted(choiceIndex: number, weight: bigint, choiceCount: number): IEncryptedVote;
|
|
225
|
+
/**
|
|
226
|
+
* Encode a Borda count vote (ranked with points).
|
|
227
|
+
* @param rankings - Indices in preference order
|
|
228
|
+
* @param choiceCount - Total number of choices
|
|
229
|
+
* @returns Encrypted vote
|
|
230
|
+
*/
|
|
231
|
+
encodeBorda(rankings: number[], choiceCount: number): IEncryptedVote;
|
|
232
|
+
/**
|
|
233
|
+
* Encode a ranked choice vote (for IRV).
|
|
234
|
+
* @param rankings - Indices in preference order
|
|
235
|
+
* @param choiceCount - Total number of choices
|
|
236
|
+
* @returns Encrypted vote
|
|
237
|
+
*/
|
|
238
|
+
encodeRankedChoice(rankings: number[], choiceCount: number): IEncryptedVote;
|
|
239
|
+
/**
|
|
240
|
+
* Encode vote based on method.
|
|
241
|
+
* @param method - Voting method
|
|
242
|
+
* @param data - Vote data
|
|
243
|
+
* @param choiceCount - Total number of choices
|
|
244
|
+
* @returns Encrypted vote
|
|
245
|
+
*/
|
|
246
|
+
encode(method: VotingMethod, data: {
|
|
247
|
+
choiceIndex?: number;
|
|
248
|
+
choices?: number[];
|
|
249
|
+
rankings?: number[];
|
|
250
|
+
weight?: bigint;
|
|
251
|
+
}, choiceCount: number): IEncryptedVote;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Poll tallier interface for decrypting and tallying votes.
|
|
255
|
+
* Holds private key and can decrypt results after poll closes.
|
|
256
|
+
*/
|
|
257
|
+
export interface IPollTallier {
|
|
258
|
+
/**
|
|
259
|
+
* Tally votes and determine winner(s).
|
|
260
|
+
* @param poll - Poll to tally
|
|
261
|
+
* @returns Poll results
|
|
262
|
+
* @throws Error if poll is not closed
|
|
263
|
+
*/
|
|
264
|
+
tally(poll: IPoll): IPollResults;
|
|
265
|
+
/**
|
|
266
|
+
* Tally ranked choice votes using IRV algorithm.
|
|
267
|
+
* @param poll - Poll to tally
|
|
268
|
+
* @returns Poll results with elimination rounds
|
|
269
|
+
*/
|
|
270
|
+
tallyRankedChoice(poll: IPoll): IPollResults;
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Poll factory interface for creating polls.
|
|
274
|
+
*/
|
|
275
|
+
export interface IPollFactory {
|
|
276
|
+
/**
|
|
277
|
+
* Create a poll with specified method.
|
|
278
|
+
* @param choices - Array of choice names
|
|
279
|
+
* @param method - Voting method
|
|
280
|
+
* @param authority - Poll authority
|
|
281
|
+
* @param options - Optional configuration
|
|
282
|
+
* @returns New poll
|
|
283
|
+
*/
|
|
284
|
+
create(choices: string[], method: VotingMethod, authority: IVotingMember, options?: {
|
|
285
|
+
maxWeight?: bigint;
|
|
286
|
+
}): IPoll;
|
|
287
|
+
/**
|
|
288
|
+
* Create a plurality poll.
|
|
289
|
+
* @param choices - Array of choice names
|
|
290
|
+
* @param authority - Poll authority
|
|
291
|
+
* @returns New poll
|
|
292
|
+
*/
|
|
293
|
+
createPlurality(choices: string[], authority: IVotingMember): IPoll;
|
|
294
|
+
/**
|
|
295
|
+
* Create an approval voting poll.
|
|
296
|
+
* @param choices - Array of choice names
|
|
297
|
+
* @param authority - Poll authority
|
|
298
|
+
* @returns New poll
|
|
299
|
+
*/
|
|
300
|
+
createApproval(choices: string[], authority: IVotingMember): IPoll;
|
|
301
|
+
/**
|
|
302
|
+
* Create a weighted voting poll.
|
|
303
|
+
* @param choices - Array of choice names
|
|
304
|
+
* @param authority - Poll authority
|
|
305
|
+
* @param maxWeight - Maximum vote weight
|
|
306
|
+
* @returns New poll
|
|
307
|
+
*/
|
|
308
|
+
createWeighted(choices: string[], authority: IVotingMember, maxWeight: bigint): IPoll;
|
|
309
|
+
/**
|
|
310
|
+
* Create a Borda count poll.
|
|
311
|
+
* @param choices - Array of choice names
|
|
312
|
+
* @param authority - Poll authority
|
|
313
|
+
* @returns New poll
|
|
314
|
+
*/
|
|
315
|
+
createBorda(choices: string[], authority: IVotingMember): IPoll;
|
|
316
|
+
/**
|
|
317
|
+
* Create a ranked choice poll.
|
|
318
|
+
* @param choices - Array of choice names
|
|
319
|
+
* @param authority - Poll authority
|
|
320
|
+
* @returns New poll
|
|
321
|
+
*/
|
|
322
|
+
createRankedChoice(choices: string[], authority: IVotingMember): IPoll;
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* Options for deriving Paillier voting keys from ECDH keys.
|
|
326
|
+
*/
|
|
327
|
+
export interface IVotingKeyDerivationOptions {
|
|
328
|
+
/** Elliptic curve name (default: 'secp256k1') */
|
|
329
|
+
curveName?: string;
|
|
330
|
+
/** Public key magic byte (default: 0x04) */
|
|
331
|
+
publicKeyMagic?: number;
|
|
332
|
+
/** Raw public key length (default: 64) */
|
|
333
|
+
rawPublicKeyLength?: number;
|
|
334
|
+
/** Public key length with prefix (default: 65) */
|
|
335
|
+
publicKeyLength?: number;
|
|
336
|
+
/** HMAC algorithm (default: 'sha512') */
|
|
337
|
+
hmacAlgorithm?: string;
|
|
338
|
+
/** HKDF info string (default: 'PaillierPrimeGen') */
|
|
339
|
+
hkdfInfo?: string;
|
|
340
|
+
/** HKDF output length (default: 64) */
|
|
341
|
+
hkdfLength?: number;
|
|
342
|
+
/** Key pair bit length (default: 3072) */
|
|
343
|
+
keypairBitLength?: number;
|
|
344
|
+
/** Prime test iterations (default: 256) */
|
|
345
|
+
primeTestIterations?: number;
|
|
346
|
+
/** Max prime generation attempts (default: 20000) */
|
|
347
|
+
maxPrimeAttempts?: number;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* Security level classification for voting methods.
|
|
351
|
+
* Determines cryptographic security guarantees.
|
|
352
|
+
*/
|
|
353
|
+
export declare enum SecurityLevel {
|
|
354
|
+
/** Fully homomorphic - no intermediate decryption required */
|
|
355
|
+
FullyHomomorphic = "fully-homomorphic",
|
|
356
|
+
/** Multi-round - requires intermediate decryption between rounds */
|
|
357
|
+
MultiRound = "multi-round",
|
|
358
|
+
/** Insecure - cannot be made secure with Paillier encryption */
|
|
359
|
+
Insecure = "insecure"
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Voting security validator interface.
|
|
363
|
+
* Validates voting methods against security requirements.
|
|
364
|
+
*/
|
|
365
|
+
export interface IVotingSecurityValidator {
|
|
366
|
+
/**
|
|
367
|
+
* Check if voting method is fully secure (no intermediate decryption).
|
|
368
|
+
* @param method - Voting method to check
|
|
369
|
+
* @returns True if method is fully homomorphic
|
|
370
|
+
*/
|
|
371
|
+
isFullySecure(method: VotingMethod): boolean;
|
|
372
|
+
/**
|
|
373
|
+
* Check if voting method requires multiple rounds.
|
|
374
|
+
* @param method - Voting method to check
|
|
375
|
+
* @returns True if method requires intermediate decryption
|
|
376
|
+
*/
|
|
377
|
+
requiresMultipleRounds(method: VotingMethod): boolean;
|
|
378
|
+
/**
|
|
379
|
+
* Get security level for voting method.
|
|
380
|
+
* @param method - Voting method to check
|
|
381
|
+
* @returns Security level classification
|
|
382
|
+
*/
|
|
383
|
+
getSecurityLevel(method: VotingMethod): SecurityLevel;
|
|
384
|
+
/**
|
|
385
|
+
* Validate voting method against security requirements.
|
|
386
|
+
* Throws error if method doesn't meet requirements.
|
|
387
|
+
* @param method - Voting method to validate
|
|
388
|
+
* @param options - Validation options
|
|
389
|
+
* @throws Error if validation fails
|
|
390
|
+
*/
|
|
391
|
+
validate(method: VotingMethod, options?: {
|
|
392
|
+
requireFullySecure?: boolean;
|
|
393
|
+
allowInsecure?: boolean;
|
|
394
|
+
}): void;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* Integrated ECIES service with voting support.
|
|
398
|
+
* Provides access to voting key derivation and serialization.
|
|
399
|
+
*/
|
|
400
|
+
export interface IECIESServiceWithVoting {
|
|
401
|
+
/** Voting service accessor */
|
|
402
|
+
readonly voting: {
|
|
403
|
+
/**
|
|
404
|
+
* Derive Paillier voting keys from ECDH key pair.
|
|
405
|
+
* @param ecdhPrivateKey - ECDH private key
|
|
406
|
+
* @param ecdhPublicKey - ECDH public key
|
|
407
|
+
* @param options - Derivation options
|
|
408
|
+
* @returns Paillier key pair
|
|
409
|
+
*/
|
|
410
|
+
deriveVotingKeysFromECDH(ecdhPrivateKey: Buffer, ecdhPublicKey: Buffer, options?: IVotingKeyDerivationOptions): Promise<KeyPair>;
|
|
411
|
+
/**
|
|
412
|
+
* Generate deterministic key pair from seed.
|
|
413
|
+
* WARNING: For testing only!
|
|
414
|
+
* @param seed - Random seed (min 32 bytes)
|
|
415
|
+
* @param bitLength - Key bit length
|
|
416
|
+
* @param iterations - Prime test iterations
|
|
417
|
+
* @returns Paillier key pair
|
|
418
|
+
*/
|
|
419
|
+
generateDeterministicKeyPair(seed: Buffer, bitLength?: number, iterations?: number): Promise<KeyPair>;
|
|
420
|
+
/**
|
|
421
|
+
* Serialize public key to buffer.
|
|
422
|
+
* @param publicKey - Public key
|
|
423
|
+
* @returns Serialized buffer
|
|
424
|
+
*/
|
|
425
|
+
votingPublicKeyToBuffer(publicKey: PublicKey): Buffer | Promise<Buffer>;
|
|
426
|
+
/**
|
|
427
|
+
* Deserialize public key from buffer.
|
|
428
|
+
* @param buffer - Serialized buffer
|
|
429
|
+
* @returns Public key
|
|
430
|
+
*/
|
|
431
|
+
bufferToVotingPublicKey(buffer: Buffer): Promise<PublicKey>;
|
|
432
|
+
/**
|
|
433
|
+
* Serialize private key to buffer.
|
|
434
|
+
* @param privateKey - Private key
|
|
435
|
+
* @returns Serialized buffer
|
|
436
|
+
*/
|
|
437
|
+
votingPrivateKeyToBuffer(privateKey: PrivateKey): Buffer;
|
|
438
|
+
/**
|
|
439
|
+
* Deserialize private key from buffer.
|
|
440
|
+
* @param buffer - Serialized buffer
|
|
441
|
+
* @param publicKey - Corresponding public key
|
|
442
|
+
* @returns Private key
|
|
443
|
+
*/
|
|
444
|
+
bufferToVotingPrivateKey(buffer: Buffer, publicKey: PublicKey): Promise<PrivateKey>;
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
//# sourceMappingURL=voting-poll.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"voting-poll.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/interfaces/voting-poll.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAEtE;;GAEG;AACH,oBAAY,YAAY;IAEtB,SAAS,cAAc;IACvB,QAAQ,aAAa;IACrB,QAAQ,aAAa;IACrB,KAAK,UAAU;IACf,KAAK,UAAU;IACf,KAAK,WAAW;IAChB,YAAY,mBAAmB;IAC/B,aAAa,kBAAkB;IAG/B,YAAY,kBAAkB;IAC9B,QAAQ,cAAc;IACtB,IAAI,SAAS;IACb,GAAG,QAAQ;IAGX,SAAS,cAAc;IACvB,SAAS,cAAc;IACvB,YAAY,kBAAkB;CAC/B;AAED;;;G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rB,OAAO,CAAC,EAAE,2BAA2B,GACpC,OAAO,CAAC,OAAO,CAAC,CAAC;QAEpB;;;;;;;WAOG;QACH,4BAA4B,CAC1B,IAAI,EAAE,MAAM,EACZ,SAAS,CAAC,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,OAAO,CAAC,CAAC;QAEpB;;;;WAIG;QACH,uBAAuB,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QACxE;;;;WAIG;QACH,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;QAC5D;;;;WAIG;QACH,wBAAwB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAAC;QACzD;;;;;WAKG;QACH,wBAAwB,CACtB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,UAAU,CAAC,CAAC;KACxB,CAAC;CACH"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Voting Poll System Interfaces (Node.js Buffer version)
|
|
4
|
+
*
|
|
5
|
+
* Node.js-specific interfaces for the voting poll system using Buffer instead of Uint8Array.
|
|
6
|
+
* These interfaces ensure type safety and API consistency with the browser version.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.SecurityLevel = exports.VotingMethod = void 0;
|
|
10
|
+
/**
|
|
11
|
+
* Voting methods supported by the poll system
|
|
12
|
+
*/
|
|
13
|
+
var VotingMethod;
|
|
14
|
+
(function (VotingMethod) {
|
|
15
|
+
// Fully homomorphic (single-round, privacy-preserving)
|
|
16
|
+
VotingMethod["Plurality"] = "plurality";
|
|
17
|
+
VotingMethod["Approval"] = "approval";
|
|
18
|
+
VotingMethod["Weighted"] = "weighted";
|
|
19
|
+
VotingMethod["Borda"] = "borda";
|
|
20
|
+
VotingMethod["Score"] = "score";
|
|
21
|
+
VotingMethod["YesNo"] = "yes-no";
|
|
22
|
+
VotingMethod["YesNoAbstain"] = "yes-no-abstain";
|
|
23
|
+
VotingMethod["Supermajority"] = "supermajority";
|
|
24
|
+
// Multi-round (requires decryption between rounds)
|
|
25
|
+
VotingMethod["RankedChoice"] = "ranked-choice";
|
|
26
|
+
VotingMethod["TwoRound"] = "two-round";
|
|
27
|
+
VotingMethod["STAR"] = "star";
|
|
28
|
+
VotingMethod["STV"] = "stv";
|
|
29
|
+
// Insecure (requires non-additive operations)
|
|
30
|
+
VotingMethod["Quadratic"] = "quadratic";
|
|
31
|
+
VotingMethod["Consensus"] = "consensus";
|
|
32
|
+
VotingMethod["ConsentBased"] = "consent-based";
|
|
33
|
+
})(VotingMethod || (exports.VotingMethod = VotingMethod = {}));
|
|
34
|
+
/**
|
|
35
|
+
* Security level classification for voting methods.
|
|
36
|
+
* Determines cryptographic security guarantees.
|
|
37
|
+
*/
|
|
38
|
+
var SecurityLevel;
|
|
39
|
+
(function (SecurityLevel) {
|
|
40
|
+
/** Fully homomorphic - no intermediate decryption required */
|
|
41
|
+
SecurityLevel["FullyHomomorphic"] = "fully-homomorphic";
|
|
42
|
+
/** Multi-round - requires intermediate decryption between rounds */
|
|
43
|
+
SecurityLevel["MultiRound"] = "multi-round";
|
|
44
|
+
/** Insecure - cannot be made secure with Paillier encryption */
|
|
45
|
+
SecurityLevel["Insecure"] = "insecure";
|
|
46
|
+
})(SecurityLevel || (exports.SecurityLevel = SecurityLevel = {}));
|
|
47
|
+
//# sourceMappingURL=voting-poll.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"voting-poll.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/interfaces/voting-poll.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAIH;;GAEG;AACH,IAAY,YAqBX;AArBD,WAAY,YAAY;IACtB,uDAAuD;IACvD,uCAAuB,CAAA;IACvB,qCAAqB,CAAA;IACrB,qCAAqB,CAAA;IACrB,+BAAe,CAAA;IACf,+BAAe,CAAA;IACf,gCAAgB,CAAA;IAChB,+CAA+B,CAAA;IAC/B,+CAA+B,CAAA;IAE/B,mDAAmD;IACnD,8CAA8B,CAAA;IAC9B,sCAAsB,CAAA;IACtB,6BAAa,CAAA;IACb,2BAAW,CAAA;IAEX,8CAA8C;IAC9C,uCAAuB,CAAA;IACvB,uCAAuB,CAAA;IACvB,8CAA8B,CAAA;AAChC,CAAC,EArBW,YAAY,4BAAZ,YAAY,QAqBvB;AAkWD;;;GAGG;AACH,IAAY,aAOX;AAPD,WAAY,aAAa;IACvB,8DAA8D;IAC9D,uDAAsC,CAAA;IACtC,oEAAoE;IACpE,2CAA0B,CAAA;IAC1B,gEAAgE;IAChE,sCAAqB,CAAA;AACvB,CAAC,EAPW,aAAa,6BAAb,aAAa,QAOxB"}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common interface for VotingService across ecies-lib and node-ecies-lib (Node.js Buffer version)
|
|
3
|
+
*
|
|
4
|
+
* This interface defines the shared contract that both browser (Web Crypto)
|
|
5
|
+
* and Node.js (crypto module) implementations must adhere to, ensuring
|
|
6
|
+
* consistent behavior and cross-platform compatibility.
|
|
7
|
+
*/
|
|
8
|
+
import type { KeyPair, PrivateKey, PublicKey } from 'paillier-bigint';
|
|
9
|
+
import type { IsolatedPrivateKey } from '../isolated-private';
|
|
10
|
+
import type { IsolatedPublicKey } from '../isolated-public';
|
|
11
|
+
/**
|
|
12
|
+
* Common interface for VotingService implementations (Node.js Buffer version)
|
|
13
|
+
*/
|
|
14
|
+
export interface IVotingService {
|
|
15
|
+
/**
|
|
16
|
+
* Serialize a base Paillier public key with magic/version/keyId
|
|
17
|
+
* Format: [magic:4][version:1][keyId:32][n_length:4][n:variable]
|
|
18
|
+
*
|
|
19
|
+
* @param publicKey - Paillier public key to serialize
|
|
20
|
+
* @returns Buffer
|
|
21
|
+
*/
|
|
22
|
+
votingPublicKeyToBuffer(publicKey: PublicKey): Buffer | Promise<Buffer>;
|
|
23
|
+
/**
|
|
24
|
+
* Deserialize a base Paillier public key from buffer
|
|
25
|
+
* Format: [magic:4][version:1][keyId:32][n_length:4][n:variable]
|
|
26
|
+
*
|
|
27
|
+
* @param buffer - Serialized public key
|
|
28
|
+
* @returns Deserialized Paillier public key
|
|
29
|
+
*/
|
|
30
|
+
bufferToVotingPublicKey(buffer: Buffer): Promise<PublicKey>;
|
|
31
|
+
/**
|
|
32
|
+
* Serialize a base Paillier private key with magic/version
|
|
33
|
+
* Format: [magic:4][version:1][lambda_length:4][lambda:variable][mu_length:4][mu:variable]
|
|
34
|
+
*
|
|
35
|
+
* @param privateKey - Paillier private key to serialize
|
|
36
|
+
* @returns Buffer
|
|
37
|
+
*/
|
|
38
|
+
votingPrivateKeyToBuffer(privateKey: PrivateKey): Buffer;
|
|
39
|
+
/**
|
|
40
|
+
* Deserialize a base Paillier private key from buffer
|
|
41
|
+
* Format: [magic:4][version:1][lambda_length:4][lambda:variable][mu_length:4][mu:variable]
|
|
42
|
+
*
|
|
43
|
+
* @param buffer - Serialized private key
|
|
44
|
+
* @param publicKey - Corresponding public key
|
|
45
|
+
* @returns Deserialized Paillier private key
|
|
46
|
+
*/
|
|
47
|
+
bufferToVotingPrivateKey(buffer: Buffer, publicKey: PublicKey): Promise<PrivateKey>;
|
|
48
|
+
/**
|
|
49
|
+
* Serialize an IsolatedPublicKey with magic/version/keyId/instanceId
|
|
50
|
+
* Format: [magic:4][version:1][keyId:32][instanceId:32][n_length:4][n:variable]
|
|
51
|
+
*
|
|
52
|
+
* @param publicKey - Isolated public key to serialize
|
|
53
|
+
* @returns Buffer
|
|
54
|
+
*/
|
|
55
|
+
isolatedPublicKeyToBuffer(publicKey: IsolatedPublicKey): Buffer;
|
|
56
|
+
/**
|
|
57
|
+
* Deserialize an IsolatedPublicKey from buffer
|
|
58
|
+
* Format: [magic:4][version:1][keyId:32][instanceId:32][n_length:4][n:variable]
|
|
59
|
+
*
|
|
60
|
+
* @param buffer - Serialized isolated public key
|
|
61
|
+
* @returns Deserialized IsolatedPublicKey
|
|
62
|
+
*/
|
|
63
|
+
bufferToIsolatedPublicKey(buffer: Buffer): Promise<IsolatedPublicKey>;
|
|
64
|
+
/**
|
|
65
|
+
* Serialize an IsolatedPrivateKey
|
|
66
|
+
* Uses same format as base private key
|
|
67
|
+
*
|
|
68
|
+
* @param privateKey - Isolated private key to serialize
|
|
69
|
+
* @returns Buffer
|
|
70
|
+
*/
|
|
71
|
+
isolatedPrivateKeyToBuffer(privateKey: IsolatedPrivateKey): Buffer;
|
|
72
|
+
/**
|
|
73
|
+
* Deserialize an IsolatedPrivateKey from buffer
|
|
74
|
+
*
|
|
75
|
+
* @param buffer - Serialized isolated private key
|
|
76
|
+
* @param publicKey - Corresponding IsolatedPublicKey
|
|
77
|
+
* @returns Deserialized IsolatedPrivateKey
|
|
78
|
+
*/
|
|
79
|
+
bufferToIsolatedPrivateKey(buffer: Buffer, publicKey: IsolatedPublicKey): Promise<IsolatedPrivateKey>;
|
|
80
|
+
/**
|
|
81
|
+
* Derive Paillier voting keys from ECDH key pair
|
|
82
|
+
*
|
|
83
|
+
* SECURITY: This is the proper way to generate voting keys - they must be
|
|
84
|
+
* derived from ECDH keys to bind them to user identity.
|
|
85
|
+
*
|
|
86
|
+
* @param ecdhPrivateKey - ECDH private key
|
|
87
|
+
* @param ecdhPublicKey - ECDH public key
|
|
88
|
+
* @param options - Optional derivation parameters
|
|
89
|
+
* @returns Paillier key pair
|
|
90
|
+
*/
|
|
91
|
+
deriveVotingKeysFromECDH(ecdhPrivateKey: Buffer, ecdhPublicKey: Buffer, options?: Record<string, unknown>): Promise<KeyPair>;
|
|
92
|
+
/**
|
|
93
|
+
* Generate deterministic Paillier key pair from seed
|
|
94
|
+
*
|
|
95
|
+
* WARNING: For testing only! Production voting keys MUST be derived from
|
|
96
|
+
* ECDH keys using deriveVotingKeysFromECDH().
|
|
97
|
+
*
|
|
98
|
+
* @param seed - Random seed for deterministic generation
|
|
99
|
+
* @param bitLength - Key bit length (default: 3072)
|
|
100
|
+
* @param iterations - Prime test iterations (default: 256)
|
|
101
|
+
* @returns Paillier key pair
|
|
102
|
+
*/
|
|
103
|
+
generateDeterministicKeyPair(seed: Buffer, bitLength?: number, iterations?: number): Promise<KeyPair>;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Extended interface for IsolatedPublicKey with async methods (Node.js Buffer version)
|
|
107
|
+
* These are the actual methods used by the voting service implementations
|
|
108
|
+
*/
|
|
109
|
+
export interface IIsolatedPublicKeyAsync {
|
|
110
|
+
readonly keyId: Buffer;
|
|
111
|
+
getKeyId(): Buffer;
|
|
112
|
+
getInstanceId(): Buffer;
|
|
113
|
+
updateInstanceId(): Promise<void>;
|
|
114
|
+
verifyKeyIdAsync(): Promise<void>;
|
|
115
|
+
encryptAsync(m: bigint): Promise<bigint>;
|
|
116
|
+
multiplyAsync(ciphertext: bigint, constant: bigint): Promise<bigint>;
|
|
117
|
+
additionAsync(a: bigint, b: bigint): Promise<bigint>;
|
|
118
|
+
extractInstanceId(ciphertext: bigint): Promise<Buffer>;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Extended interface for IsolatedPrivateKey with async methods (Node.js Buffer version)
|
|
122
|
+
* These are the actual methods used by the voting service implementations
|
|
123
|
+
*/
|
|
124
|
+
export interface IIsolatedPrivateKeyAsync {
|
|
125
|
+
decryptAsync(taggedCiphertext: bigint): Promise<bigint>;
|
|
126
|
+
getOriginalKeyId(): Buffer;
|
|
127
|
+
getOriginalInstanceId(): Buffer;
|
|
128
|
+
getOriginalPublicKey(): IIsolatedPublicKeyAsync;
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=voting-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"voting-service.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-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AEpB;;;;;;;;;;OAUG;IACH,4BAA4B,CAC1B,IAAI,EAAE,MAAM,EACZ,SAAS,CAAC,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,OAAO,CAAC,CAAC;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,IAAI,MAAM,CAAC;IACnB,aAAa,IAAI,MAAM,CAAC;IACxB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAClC,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACzC,aAAa,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACrE,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACrD,iBAAiB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACxD;AAED;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC,YAAY,CAAC,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACxD,gBAAgB,IAAI,MAAM,CAAC;IAC3B,qBAAqB,IAAI,MAAM,CAAC;IAChC,oBAAoB,IAAI,uBAAuB,CAAC;CACjD"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Common interface for VotingService across ecies-lib and node-ecies-lib (Node.js Buffer version)
|
|
4
|
+
*
|
|
5
|
+
* This interface defines the shared contract that both browser (Web Crypto)
|
|
6
|
+
* and Node.js (crypto module) implementations must adhere to, ensuring
|
|
7
|
+
* consistent behavior and cross-platform compatibility.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
//# sourceMappingURL=voting-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"voting-service.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/interfaces/voting-service.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG"}
|