@digitaldefiance/node-ecies-lib 4.8.2 → 4.10.6
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 +10 -5
- package/src/constants.d.ts.map +1 -1
- package/src/constants.js +31 -25
- package/src/constants.js.map +1 -1
- package/src/interfaces/index.d.ts +1 -2
- package/src/interfaces/index.d.ts.map +1 -1
- package/src/interfaces/index.js +6 -3
- package/src/interfaces/index.js.map +1 -1
- package/src/interfaces/member.d.ts +30 -12
- package/src/interfaces/member.d.ts.map +1 -1
- package/src/interfaces/platform-buffer.d.ts +9 -0
- package/src/interfaces/platform-buffer.d.ts.map +1 -0
- package/src/interfaces/platform-buffer.js +3 -0
- package/src/interfaces/platform-buffer.js.map +1 -0
- package/src/interfaces/platform-id.d.ts +2 -2
- package/src/interfaces/platform-id.d.ts.map +1 -1
- package/src/lib/id-providers/buffer-provider.d.ts +54 -0
- package/src/lib/id-providers/buffer-provider.d.ts.map +1 -0
- package/src/lib/id-providers/buffer-provider.js +93 -0
- package/src/lib/id-providers/buffer-provider.js.map +1 -0
- package/src/lib/index.d.ts +1 -0
- package/src/lib/index.d.ts.map +1 -1
- package/src/lib/index.js +1 -0
- package/src/lib/index.js.map +1 -1
- package/src/lib/voting/audit.d.ts +39 -48
- package/src/lib/voting/audit.d.ts.map +1 -1
- package/src/lib/voting/audit.js +103 -111
- package/src/lib/voting/audit.js.map +1 -1
- package/src/lib/voting/bulletin-board.d.ts +47 -81
- package/src/lib/voting/bulletin-board.d.ts.map +1 -1
- package/src/lib/voting/bulletin-board.js +95 -231
- package/src/lib/voting/bulletin-board.js.map +1 -1
- package/src/lib/voting/encoder.d.ts +7 -16
- package/src/lib/voting/encoder.d.ts.map +1 -1
- package/src/lib/voting/encoder.js +11 -107
- package/src/lib/voting/encoder.js.map +1 -1
- package/src/lib/voting/enumerations/index.d.ts +6 -0
- package/src/lib/voting/enumerations/index.d.ts.map +1 -0
- package/src/lib/voting/enumerations/index.js +14 -0
- package/src/lib/voting/enumerations/index.js.map +1 -0
- package/src/lib/voting/event-logger.d.ts +13 -74
- package/src/lib/voting/event-logger.d.ts.map +1 -1
- package/src/lib/voting/event-logger.js +19 -140
- package/src/lib/voting/event-logger.js.map +1 -1
- package/src/lib/voting/examples.d.ts +112 -0
- package/src/lib/voting/examples.d.ts.map +1 -0
- package/src/lib/voting/examples.js +386 -0
- package/src/lib/voting/examples.js.map +1 -0
- package/src/lib/voting/factory.d.ts +38 -9
- package/src/lib/voting/factory.d.ts.map +1 -1
- package/src/lib/voting/factory.js +42 -8
- package/src/lib/voting/factory.js.map +1 -1
- package/src/lib/voting/hierarchical-aggregator.d.ts +44 -0
- package/src/lib/voting/hierarchical-aggregator.d.ts.map +1 -0
- package/src/lib/voting/hierarchical-aggregator.js +56 -0
- package/src/lib/voting/hierarchical-aggregator.js.map +1 -0
- package/src/lib/voting/index.d.ts +43 -7
- package/src/lib/voting/index.d.ts.map +1 -1
- package/src/lib/voting/index.js +53 -10
- package/src/lib/voting/index.js.map +1 -1
- package/src/lib/voting/interfaces/aggregated-tally.d.ts +10 -0
- package/src/lib/voting/interfaces/aggregated-tally.d.ts.map +1 -0
- package/src/lib/voting/interfaces/aggregated-tally.js +3 -0
- package/src/lib/voting/interfaces/aggregated-tally.js.map +1 -0
- package/src/lib/voting/interfaces/audit-entry.d.ts +10 -0
- package/src/lib/voting/interfaces/audit-entry.d.ts.map +1 -0
- package/src/lib/voting/interfaces/audit-entry.js +3 -0
- package/src/lib/voting/interfaces/audit-entry.js.map +1 -0
- package/src/lib/voting/interfaces/audit-log.d.ts +10 -0
- package/src/lib/voting/interfaces/audit-log.d.ts.map +1 -0
- package/src/lib/voting/interfaces/audit-log.js +3 -0
- package/src/lib/voting/interfaces/audit-log.js.map +1 -0
- package/src/lib/voting/interfaces/bulletin-board-entry.d.ts +10 -0
- package/src/lib/voting/interfaces/bulletin-board-entry.d.ts.map +1 -0
- package/src/lib/voting/interfaces/bulletin-board-entry.js +3 -0
- package/src/lib/voting/interfaces/bulletin-board-entry.js.map +1 -0
- package/src/lib/voting/interfaces/bulletin-board.d.ts +10 -0
- package/src/lib/voting/interfaces/bulletin-board.d.ts.map +1 -0
- package/src/lib/voting/interfaces/bulletin-board.js +3 -0
- package/src/lib/voting/interfaces/bulletin-board.js.map +1 -0
- package/src/lib/voting/interfaces/checkpoint-manager-extended.d.ts +10 -0
- package/src/lib/voting/interfaces/checkpoint-manager-extended.d.ts.map +1 -0
- package/src/lib/voting/interfaces/checkpoint-manager-extended.js +3 -0
- package/src/lib/voting/interfaces/checkpoint-manager-extended.js.map +1 -0
- package/src/lib/voting/interfaces/checkpoint-manager.d.ts +9 -0
- package/src/lib/voting/interfaces/checkpoint-manager.d.ts.map +1 -0
- package/src/lib/voting/interfaces/checkpoint-manager.js +3 -0
- package/src/lib/voting/interfaces/checkpoint-manager.js.map +1 -0
- package/src/lib/voting/interfaces/checkpoint-metadata.d.ts +8 -0
- package/src/lib/voting/interfaces/checkpoint-metadata.d.ts.map +1 -0
- package/src/lib/voting/interfaces/checkpoint-metadata.js +3 -0
- package/src/lib/voting/interfaces/checkpoint-metadata.js.map +1 -0
- package/src/lib/voting/interfaces/ecies-service-with-voting.d.ts +8 -0
- package/src/lib/voting/interfaces/ecies-service-with-voting.d.ts.map +1 -0
- package/src/lib/voting/interfaces/ecies-service-with-voting.js +3 -0
- package/src/lib/voting/interfaces/ecies-service-with-voting.js.map +1 -0
- package/src/lib/voting/interfaces/encrypted-vote.d.ts +10 -0
- package/src/lib/voting/interfaces/encrypted-vote.d.ts.map +1 -0
- package/src/lib/voting/interfaces/encrypted-vote.js +3 -0
- package/src/lib/voting/interfaces/encrypted-vote.js.map +1 -0
- package/src/lib/voting/interfaces/event-log-entry.d.ts +10 -0
- package/src/lib/voting/interfaces/event-log-entry.d.ts.map +1 -0
- package/src/lib/voting/interfaces/event-log-entry.js +3 -0
- package/src/lib/voting/interfaces/event-log-entry.js.map +1 -0
- package/src/lib/voting/interfaces/event-logger.d.ts +10 -0
- package/src/lib/voting/interfaces/event-logger.d.ts.map +1 -0
- package/src/lib/voting/interfaces/event-logger.js +3 -0
- package/src/lib/voting/interfaces/event-logger.js.map +1 -0
- package/src/lib/voting/interfaces/index.d.ts +37 -0
- package/src/lib/voting/interfaces/index.d.ts.map +1 -0
- package/src/lib/voting/interfaces/index.js +9 -0
- package/src/lib/voting/interfaces/index.js.map +1 -0
- package/src/lib/voting/interfaces/jurisdiction-config.d.ts +10 -0
- package/src/lib/voting/interfaces/jurisdiction-config.d.ts.map +1 -0
- package/src/lib/voting/interfaces/jurisdiction-config.js +3 -0
- package/src/lib/voting/interfaces/jurisdiction-config.js.map +1 -0
- package/src/lib/voting/interfaces/plaintext-vote.d.ts +10 -0
- package/src/lib/voting/interfaces/plaintext-vote.d.ts.map +1 -0
- package/src/lib/voting/interfaces/plaintext-vote.js +3 -0
- package/src/lib/voting/interfaces/plaintext-vote.js.map +1 -0
- package/src/lib/voting/interfaces/poll-configuration.d.ts +8 -0
- package/src/lib/voting/interfaces/poll-configuration.d.ts.map +1 -0
- package/src/lib/voting/interfaces/poll-configuration.js +3 -0
- package/src/lib/voting/interfaces/poll-configuration.js.map +1 -0
- package/src/lib/voting/interfaces/poll-results.d.ts +8 -0
- package/src/lib/voting/interfaces/poll-results.d.ts.map +1 -0
- package/src/lib/voting/interfaces/poll-results.js +3 -0
- package/src/lib/voting/interfaces/poll-results.js.map +1 -0
- package/src/lib/voting/interfaces/poll-tallier.d.ts +10 -0
- package/src/lib/voting/interfaces/poll-tallier.d.ts.map +1 -0
- package/src/lib/voting/interfaces/poll-tallier.js +3 -0
- package/src/lib/voting/interfaces/poll-tallier.js.map +1 -0
- package/src/lib/voting/interfaces/poll.d.ts +10 -0
- package/src/lib/voting/interfaces/poll.d.ts.map +1 -0
- package/src/lib/voting/interfaces/poll.js +3 -0
- package/src/lib/voting/interfaces/poll.js.map +1 -0
- package/src/lib/voting/interfaces/round-result.d.ts +8 -0
- package/src/lib/voting/interfaces/round-result.d.ts.map +1 -0
- package/src/lib/voting/interfaces/round-result.js +3 -0
- package/src/lib/voting/interfaces/round-result.js.map +1 -0
- package/src/lib/voting/interfaces/state-snapshot.d.ts +15 -0
- package/src/lib/voting/interfaces/state-snapshot.d.ts.map +1 -0
- package/src/lib/voting/interfaces/state-snapshot.js +3 -0
- package/src/lib/voting/interfaces/state-snapshot.js.map +1 -0
- package/src/lib/voting/interfaces/supermajority-config.d.ts +8 -0
- package/src/lib/voting/interfaces/supermajority-config.d.ts.map +1 -0
- package/src/lib/voting/interfaces/supermajority-config.js +3 -0
- package/src/lib/voting/interfaces/supermajority-config.js.map +1 -0
- package/src/lib/voting/interfaces/tally-proof.d.ts +10 -0
- package/src/lib/voting/interfaces/tally-proof.d.ts.map +1 -0
- package/src/lib/voting/interfaces/tally-proof.js +3 -0
- package/src/lib/voting/interfaces/tally-proof.js.map +1 -0
- package/src/lib/voting/interfaces/vote-encoder.d.ts +10 -0
- package/src/lib/voting/interfaces/vote-encoder.d.ts.map +1 -0
- package/src/lib/voting/interfaces/vote-encoder.js +3 -0
- package/src/lib/voting/interfaces/vote-encoder.js.map +1 -0
- package/src/lib/voting/interfaces/vote-logger-extended.d.ts +10 -0
- package/src/lib/voting/interfaces/vote-logger-extended.d.ts.map +1 -0
- package/src/lib/voting/interfaces/vote-logger-extended.js +3 -0
- package/src/lib/voting/interfaces/vote-logger-extended.js.map +1 -0
- package/src/lib/voting/interfaces/vote-logger.d.ts +9 -0
- package/src/lib/voting/interfaces/vote-logger.d.ts.map +1 -0
- package/src/lib/voting/interfaces/vote-logger.js +3 -0
- package/src/lib/voting/interfaces/vote-logger.js.map +1 -0
- package/src/lib/voting/interfaces/voting-consts.d.ts +9 -0
- package/src/lib/voting/interfaces/voting-consts.d.ts.map +1 -0
- package/src/lib/voting/interfaces/voting-consts.js +3 -0
- package/src/lib/voting/interfaces/voting-consts.js.map +1 -0
- package/src/lib/voting/interfaces/voting-key-derivation-options.d.ts +7 -0
- package/src/lib/voting/interfaces/voting-key-derivation-options.d.ts.map +1 -0
- package/src/lib/voting/interfaces/voting-key-derivation-options.js +3 -0
- package/src/lib/voting/interfaces/voting-key-derivation-options.js.map +1 -0
- package/src/lib/voting/interfaces/voting-poll-results.d.ts +7 -0
- package/src/lib/voting/interfaces/voting-poll-results.d.ts.map +1 -0
- package/src/lib/voting/interfaces/voting-poll-results.js +3 -0
- package/src/lib/voting/interfaces/voting-poll-results.js.map +1 -0
- package/src/lib/voting/interfaces/voting-receipt.d.ts +10 -0
- package/src/lib/voting/interfaces/voting-receipt.d.ts.map +1 -0
- package/src/lib/voting/interfaces/voting-receipt.js +3 -0
- package/src/lib/voting/interfaces/voting-receipt.js.map +1 -0
- package/src/lib/voting/interfaces/voting-security-validator.d.ts +8 -0
- package/src/lib/voting/interfaces/voting-security-validator.d.ts.map +1 -0
- package/src/lib/voting/interfaces/voting-security-validator.js +3 -0
- package/src/lib/voting/interfaces/voting-security-validator.js.map +1 -0
- package/src/lib/voting/node-persistent-state.d.ts +40 -0
- package/src/lib/voting/node-persistent-state.d.ts.map +1 -0
- package/src/lib/voting/node-persistent-state.js +222 -0
- package/src/lib/voting/node-persistent-state.js.map +1 -0
- package/src/lib/voting/persistent-state.d.ts +44 -0
- package/src/lib/voting/persistent-state.d.ts.map +1 -0
- package/src/lib/voting/persistent-state.js +106 -0
- package/src/lib/voting/persistent-state.js.map +1 -0
- package/src/lib/voting/poll-core.d.ts +14 -29
- package/src/lib/voting/poll-core.d.ts.map +1 -1
- package/src/lib/voting/poll-core.js +13 -176
- package/src/lib/voting/poll-core.js.map +1 -1
- package/src/lib/voting/poll.js +3 -3
- package/src/lib/voting/poll.js.map +1 -1
- package/src/lib/voting/security.d.ts +9 -15
- package/src/lib/voting/security.d.ts.map +1 -1
- package/src/lib/voting/security.js +12 -44
- package/src/lib/voting/security.js.map +1 -1
- package/src/lib/voting/tallier.d.ts +11 -20
- package/src/lib/voting/tallier.d.ts.map +1 -1
- package/src/lib/voting/tallier.js +17 -366
- package/src/lib/voting/tallier.js.map +1 -1
- package/src/lib/voting/test-voter-pool.d.ts +16 -0
- package/src/lib/voting/test-voter-pool.d.ts.map +1 -0
- package/src/lib/voting/test-voter-pool.js +69 -0
- package/src/lib/voting/test-voter-pool.js.map +1 -0
- package/src/lib/voting/us-election-example.d.ts +2 -0
- package/src/lib/voting/us-election-example.d.ts.map +1 -0
- package/src/lib/voting/us-election-example.js +170 -0
- package/src/lib/voting/us-election-example.js.map +1 -0
- package/src/member.d.ts +4 -1
- package/src/member.d.ts.map +1 -1
- package/src/member.js +40 -16
- package/src/member.js.map +1 -1
- package/src/secure-buffer.d.ts +1 -2
- package/src/secure-buffer.d.ts.map +1 -1
- package/src/secure-buffer.js +3 -9
- package/src/secure-buffer.js.map +1 -1
- package/src/services/ecies/crypto-core.d.ts.map +1 -1
- package/src/services/ecies/crypto-core.js +24 -0
- package/src/services/ecies/crypto-core.js.map +1 -1
- package/src/services/ecies/multi-recipient.d.ts +9 -1
- package/src/services/ecies/multi-recipient.d.ts.map +1 -1
- package/src/services/ecies/multi-recipient.js +153 -21
- package/src/services/ecies/multi-recipient.js.map +1 -1
- package/src/services/ecies/service.d.ts +56 -15
- package/src/services/ecies/service.d.ts.map +1 -1
- package/src/services/ecies/service.js +196 -39
- package/src/services/ecies/service.js.map +1 -1
- package/src/services/ecies/single-recipient.d.ts.map +1 -1
- package/src/services/ecies/single-recipient.js +4 -2
- package/src/services/ecies/single-recipient.js.map +1 -1
- package/src/services/encryption-stream.d.ts +1 -1
- package/src/services/encryption-stream.d.ts.map +1 -1
- package/src/services/encryption-stream.js +4 -8
- package/src/services/encryption-stream.js.map +1 -1
- package/src/services/multi-recipient-processor.d.ts +5 -2
- package/src/services/multi-recipient-processor.d.ts.map +1 -1
- package/src/services/multi-recipient-processor.js +29 -14
- package/src/services/multi-recipient-processor.js.map +1 -1
- package/src/test-mocks/mock-backend-member.d.ts +22 -3
- package/src/test-mocks/mock-backend-member.d.ts.map +1 -1
- package/src/test-mocks/mock-backend-member.js +71 -0
- package/src/test-mocks/mock-backend-member.js.map +1 -1
- package/src/lib/voting/types.d.ts +0 -67
- package/src/lib/voting/types.d.ts.map +0 -1
- package/src/lib/voting/types.js +0 -29
- package/src/lib/voting/types.js.map +0 -1
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Voting System Usage Examples (Node.js)
|
|
4
|
+
* Shows how to use with node-ecies-lib Member class
|
|
5
|
+
*
|
|
6
|
+
* Note: This is the Node.js implementation using Buffer instead of Uint8Array.
|
|
7
|
+
* For the browser implementation, see @digitaldefiance/ecies-lib.
|
|
8
|
+
*
|
|
9
|
+
* IMPORTANT: These examples are for documentation purposes and demonstrate the API.
|
|
10
|
+
* Due to type incompatibilities between ecies-lib Member (Uint8Array) and
|
|
11
|
+
* node-ecies-lib voting system (Buffer), these examples may require type assertions
|
|
12
|
+
* or conversion utilities in actual usage. See the test files for working examples.
|
|
13
|
+
*
|
|
14
|
+
* These examples show the intended API usage but may not compile due to type
|
|
15
|
+
* incompatibilities. For working examples, see the test files in the test directory.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.examplePlurality = examplePlurality;
|
|
19
|
+
exports.exampleRankedChoice = exampleRankedChoice;
|
|
20
|
+
exports.exampleWeighted = exampleWeighted;
|
|
21
|
+
exports.exampleBorda = exampleBorda;
|
|
22
|
+
exports.exampleApproval = exampleApproval;
|
|
23
|
+
exports.exampleReceipts = exampleReceipts;
|
|
24
|
+
exports.exampleFilePersistence = exampleFilePersistence;
|
|
25
|
+
exports.exampleStreamProcessing = exampleStreamProcessing;
|
|
26
|
+
exports.exampleBufferCrypto = exampleBufferCrypto;
|
|
27
|
+
exports.exampleAuditLogExport = exampleAuditLogExport;
|
|
28
|
+
// Note: These imports are for documentation purposes
|
|
29
|
+
// import { Member, MemberType, EmailString, ECIESService } from '@digitaldefiance/ecies-lib';
|
|
30
|
+
// import {
|
|
31
|
+
// PollFactory,
|
|
32
|
+
// VoteEncoder,
|
|
33
|
+
// PollTallier,
|
|
34
|
+
// VotingMethod as _VotingMethod,
|
|
35
|
+
// } from './index';
|
|
36
|
+
/**
|
|
37
|
+
* Example 1: Simple Plurality Vote
|
|
38
|
+
*
|
|
39
|
+
* This example shows the intended API usage. For working examples,
|
|
40
|
+
* see the test files which handle type conversions properly.
|
|
41
|
+
*/
|
|
42
|
+
async function examplePlurality() {
|
|
43
|
+
// Note: This is pseudocode for documentation purposes
|
|
44
|
+
// Actual implementation requires proper type conversions between
|
|
45
|
+
// ecies-lib Member (Uint8Array) and node-ecies-lib voting (Buffer)
|
|
46
|
+
console.log(`
|
|
47
|
+
// Create authority (poll creator)
|
|
48
|
+
const authority = createMemberWithVotingKeys();
|
|
49
|
+
|
|
50
|
+
// Create poll
|
|
51
|
+
const poll = PollFactory.createPlurality(
|
|
52
|
+
['Alice', 'Bob', 'Charlie'],
|
|
53
|
+
authority.member, // Note: requires Buffer-compatible member
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
// Create voters and cast votes
|
|
57
|
+
const encoder = new VoteEncoder(authority.member.votingPublicKey!);
|
|
58
|
+
|
|
59
|
+
poll.vote(voter1.member, encoder.encodePlurality(0, 3)); // Alice
|
|
60
|
+
poll.vote(voter2.member, encoder.encodePlurality(0, 3)); // Alice
|
|
61
|
+
poll.vote(voter3.member, encoder.encodePlurality(1, 3)); // Bob
|
|
62
|
+
|
|
63
|
+
// Close and tally
|
|
64
|
+
poll.close();
|
|
65
|
+
const tallier = new PollTallier(
|
|
66
|
+
authority.member,
|
|
67
|
+
authority.member.votingPrivateKey!,
|
|
68
|
+
authority.member.votingPublicKey!,
|
|
69
|
+
);
|
|
70
|
+
const results = tallier.tally(poll);
|
|
71
|
+
|
|
72
|
+
console.log('Winner:', results.choices[results.winner!]); // Alice
|
|
73
|
+
console.log('Tallies:', results.tallies); // [2n, 1n, 0n]
|
|
74
|
+
`);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Example 2: Ranked Choice Voting (True IRV)
|
|
78
|
+
*
|
|
79
|
+
* This example shows the intended API usage. For working examples,
|
|
80
|
+
* see the test files which handle type conversions properly.
|
|
81
|
+
*/
|
|
82
|
+
async function exampleRankedChoice() {
|
|
83
|
+
console.log(`
|
|
84
|
+
const authority = createMemberWithVotingKeys();
|
|
85
|
+
|
|
86
|
+
const poll = PollFactory.createRankedChoice(
|
|
87
|
+
['Alice', 'Bob', 'Charlie', 'Diana'],
|
|
88
|
+
authority.member,
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
const encoder = new VoteEncoder(authority.member.votingPublicKey!);
|
|
92
|
+
|
|
93
|
+
// Voter 1: Alice > Bob > Charlie
|
|
94
|
+
poll.vote(voter1.member, encoder.encodeRankedChoice([0, 1, 2], 4));
|
|
95
|
+
|
|
96
|
+
// Voter 2: Bob > Alice > Diana
|
|
97
|
+
poll.vote(voter2.member, encoder.encodeRankedChoice([1, 0, 3], 4));
|
|
98
|
+
|
|
99
|
+
// Voter 3: Charlie > Diana > Bob
|
|
100
|
+
poll.vote(voter3.member, encoder.encodeRankedChoice([2, 3, 1], 4));
|
|
101
|
+
|
|
102
|
+
// Voter 4: Alice > Charlie
|
|
103
|
+
poll.vote(voter4.member, encoder.encodeRankedChoice([0, 2], 4));
|
|
104
|
+
|
|
105
|
+
poll.close();
|
|
106
|
+
const results = tallier.tally(poll);
|
|
107
|
+
|
|
108
|
+
console.log('Winner:', results.choices[results.winner!]);
|
|
109
|
+
console.log('Rounds:', results.rounds);
|
|
110
|
+
console.log('Eliminated:', results.eliminated);
|
|
111
|
+
`);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Example 3: Weighted Voting (Stakeholder)
|
|
115
|
+
*
|
|
116
|
+
* This example shows the intended API usage. For working examples,
|
|
117
|
+
* see the test files which handle type conversions properly.
|
|
118
|
+
*/
|
|
119
|
+
async function exampleWeighted() {
|
|
120
|
+
console.log(`
|
|
121
|
+
const authority = createMemberWithVotingKeys();
|
|
122
|
+
|
|
123
|
+
const poll = PollFactory.createWeighted(
|
|
124
|
+
['Proposal A', 'Proposal B'],
|
|
125
|
+
authority.member,
|
|
126
|
+
1000n, // Max weight
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const encoder = new VoteEncoder(authority.member.votingPublicKey!);
|
|
130
|
+
|
|
131
|
+
// Large stakeholder
|
|
132
|
+
poll.vote(whale.member, encoder.encodeWeighted(0, 500n, 2));
|
|
133
|
+
|
|
134
|
+
// Medium stakeholder
|
|
135
|
+
poll.vote(dolphin.member, encoder.encodeWeighted(1, 200n, 2));
|
|
136
|
+
|
|
137
|
+
// Small stakeholder
|
|
138
|
+
poll.vote(shrimp.member, encoder.encodeWeighted(1, 50n, 2));
|
|
139
|
+
|
|
140
|
+
poll.close();
|
|
141
|
+
const results = tallier.tally(poll);
|
|
142
|
+
|
|
143
|
+
console.log('Results:', results.tallies); // [500n, 250n]
|
|
144
|
+
`);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Example 4: Borda Count
|
|
148
|
+
*
|
|
149
|
+
* This example shows the intended API usage. For working examples,
|
|
150
|
+
* see the test files which handle type conversions properly.
|
|
151
|
+
*/
|
|
152
|
+
async function exampleBorda() {
|
|
153
|
+
console.log(`
|
|
154
|
+
const authority = createMemberWithVotingKeys();
|
|
155
|
+
|
|
156
|
+
const poll = PollFactory.createBorda(
|
|
157
|
+
['Option A', 'Option B', 'Option C'],
|
|
158
|
+
authority.member,
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const encoder = new VoteEncoder(authority.member.votingPublicKey!);
|
|
162
|
+
|
|
163
|
+
// Each voter ranks all options
|
|
164
|
+
poll.vote(voter1.member, encoder.encodeBorda([0, 1, 2], 3)); // A=3, B=2, C=1
|
|
165
|
+
poll.vote(voter2.member, encoder.encodeBorda([1, 0, 2], 3)); // B=3, A=2, C=1
|
|
166
|
+
poll.vote(voter3.member, encoder.encodeBorda([0, 2, 1], 3)); // A=3, C=2, B=1
|
|
167
|
+
|
|
168
|
+
poll.close();
|
|
169
|
+
const results = tallier.tally(poll);
|
|
170
|
+
|
|
171
|
+
console.log('Points:', results.tallies); // [8n, 6n, 4n]
|
|
172
|
+
console.log('Winner:', results.choices[results.winner!]); // Option A
|
|
173
|
+
`);
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Example 5: Approval Voting
|
|
177
|
+
*
|
|
178
|
+
* This example shows the intended API usage. For working examples,
|
|
179
|
+
* see the test files which handle type conversions properly.
|
|
180
|
+
*/
|
|
181
|
+
async function exampleApproval() {
|
|
182
|
+
console.log(`
|
|
183
|
+
const authority = createMemberWithVotingKeys();
|
|
184
|
+
|
|
185
|
+
const poll = PollFactory.createApproval(
|
|
186
|
+
['Red', 'Green', 'Blue', 'Yellow'],
|
|
187
|
+
authority.member,
|
|
188
|
+
);
|
|
189
|
+
|
|
190
|
+
const encoder = new VoteEncoder(authority.member.votingPublicKey!);
|
|
191
|
+
|
|
192
|
+
// Voter 1 approves Red and Blue
|
|
193
|
+
poll.vote(voter1.member, encoder.encodeApproval([0, 2], 4));
|
|
194
|
+
|
|
195
|
+
// Voter 2 approves Green and Blue
|
|
196
|
+
poll.vote(voter2.member, encoder.encodeApproval([1, 2], 4));
|
|
197
|
+
|
|
198
|
+
// Voter 3 approves only Blue
|
|
199
|
+
poll.vote(voter3.member, encoder.encodeApproval([2], 4));
|
|
200
|
+
|
|
201
|
+
poll.close();
|
|
202
|
+
const results = tallier.tally(poll);
|
|
203
|
+
|
|
204
|
+
console.log('Approvals:', results.tallies); // [1n, 1n, 3n, 0n]
|
|
205
|
+
console.log('Winner:', results.choices[results.winner!]); // Blue
|
|
206
|
+
`);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Example 6: Receipt Verification
|
|
210
|
+
*
|
|
211
|
+
* This example shows the intended API usage. For working examples,
|
|
212
|
+
* see the test files which handle type conversions properly.
|
|
213
|
+
*/
|
|
214
|
+
async function exampleReceipts() {
|
|
215
|
+
console.log(`
|
|
216
|
+
const authority = createMemberWithVotingKeys();
|
|
217
|
+
const poll = PollFactory.createPlurality(
|
|
218
|
+
['Yes', 'No'],
|
|
219
|
+
authority.member,
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
const voter = createMemberWithVotingKeys();
|
|
223
|
+
const encoder = new VoteEncoder(authority.member.votingPublicKey!);
|
|
224
|
+
|
|
225
|
+
// Cast vote and get receipt
|
|
226
|
+
const receipt = poll.vote(voter.member, encoder.encodePlurality(0, 2));
|
|
227
|
+
|
|
228
|
+
// Verify receipt
|
|
229
|
+
const isValid = poll.verifyReceipt(voter.member, receipt);
|
|
230
|
+
console.log('Receipt valid:', isValid); // true
|
|
231
|
+
|
|
232
|
+
// Try to verify with wrong voter
|
|
233
|
+
const otherVoter = createMemberWithVotingKeys();
|
|
234
|
+
const isInvalid = poll.verifyReceipt(otherVoter.member, receipt);
|
|
235
|
+
console.log('Wrong voter:', isInvalid); // false
|
|
236
|
+
`);
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Example 7: Node.js-Specific - File-Based Vote Persistence
|
|
240
|
+
*
|
|
241
|
+
* This example shows how to save encrypted votes to disk using Node.js fs module.
|
|
242
|
+
* For working examples, see the test files which handle type conversions properly.
|
|
243
|
+
*/
|
|
244
|
+
async function exampleFilePersistence() {
|
|
245
|
+
console.log(`
|
|
246
|
+
const authority = createMemberWithVotingKeys();
|
|
247
|
+
const poll = PollFactory.createPlurality(
|
|
248
|
+
['Option A', 'Option B'],
|
|
249
|
+
authority.member,
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
const encoder = new VoteEncoder(authority.member.votingPublicKey!);
|
|
253
|
+
|
|
254
|
+
// Cast some votes
|
|
255
|
+
poll.vote(voter1.member, encoder.encodePlurality(0, 2));
|
|
256
|
+
poll.vote(voter2.member, encoder.encodePlurality(1, 2));
|
|
257
|
+
|
|
258
|
+
// Save encrypted votes to disk (Node.js-specific)
|
|
259
|
+
const votes = Array.from(poll.getEncryptedVotes().entries());
|
|
260
|
+
const votesData = votes.map(([voterId, encrypted]) => ({
|
|
261
|
+
voterId: voterId.toString('hex'), // Convert Buffer to hex string
|
|
262
|
+
encrypted: encrypted.map(n => n.toString()),
|
|
263
|
+
}));
|
|
264
|
+
|
|
265
|
+
await fs.writeFile(
|
|
266
|
+
'encrypted-votes.json',
|
|
267
|
+
JSON.stringify(votesData, null, 2)
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
console.log('Votes saved to encrypted-votes.json');
|
|
271
|
+
|
|
272
|
+
// Load votes from disk
|
|
273
|
+
const loadedData = JSON.parse(
|
|
274
|
+
await fs.readFile('encrypted-votes.json', 'utf-8')
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
console.log(\`Loaded \${loadedData.length} votes from disk\`);
|
|
278
|
+
`);
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Example 8: Node.js-Specific - Streaming Large Voter Datasets
|
|
282
|
+
*
|
|
283
|
+
* This example shows how to process votes from a stream using Node.js.
|
|
284
|
+
* For working examples, see the test files which handle type conversions properly.
|
|
285
|
+
*/
|
|
286
|
+
async function exampleStreamProcessing() {
|
|
287
|
+
console.log(`
|
|
288
|
+
const authority = createMemberWithVotingKeys();
|
|
289
|
+
const poll = PollFactory.createPlurality(
|
|
290
|
+
['Candidate A', 'Candidate B', 'Candidate C'],
|
|
291
|
+
authority.member,
|
|
292
|
+
);
|
|
293
|
+
|
|
294
|
+
const encoder = new VoteEncoder(authority.member.votingPublicKey!);
|
|
295
|
+
|
|
296
|
+
// Simulate processing votes from a stream
|
|
297
|
+
console.log('Processing votes from stream...');
|
|
298
|
+
|
|
299
|
+
// In a real scenario, this would read from a file stream or network stream
|
|
300
|
+
const voteStream = Array.from({ length: 100 }, (_, i) => ({
|
|
301
|
+
voterId: i,
|
|
302
|
+
choice: i % 3, // Distribute votes across 3 candidates
|
|
303
|
+
}));
|
|
304
|
+
|
|
305
|
+
for (const voteData of voteStream) {
|
|
306
|
+
const voter = createMemberWithVotingKeys(\`Voter \${voteData.voterId}\`);
|
|
307
|
+
poll.vote(voter.member, encoder.encodePlurality(voteData.choice, 3));
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
poll.close();
|
|
311
|
+
const results = tallier.tally(poll);
|
|
312
|
+
|
|
313
|
+
console.log('Stream processing complete');
|
|
314
|
+
console.log('Results:', results.tallies);
|
|
315
|
+
console.log('Winner:', results.choices[results.winner!]);
|
|
316
|
+
`);
|
|
317
|
+
}
|
|
318
|
+
/**
|
|
319
|
+
* Example 9: Node.js-Specific - Cryptographic Operations with Buffer
|
|
320
|
+
*
|
|
321
|
+
* This example shows Node.js-specific cryptographic operations using Buffer.
|
|
322
|
+
*/
|
|
323
|
+
async function exampleBufferCrypto() {
|
|
324
|
+
console.log(`
|
|
325
|
+
// Generate random voter ID using Node.js crypto (returns Buffer)
|
|
326
|
+
const voterId = crypto.randomBytes(32);
|
|
327
|
+
console.log('Voter ID (Buffer):', voterId.toString('hex'));
|
|
328
|
+
|
|
329
|
+
// Hash voter ID using Node.js crypto
|
|
330
|
+
const voterIdHash = crypto.createHash('sha256').update(voterId).digest();
|
|
331
|
+
console.log('Voter ID Hash (Buffer):', voterIdHash.toString('hex'));
|
|
332
|
+
|
|
333
|
+
// Create poll ID using Buffer
|
|
334
|
+
const pollId = crypto.randomBytes(16);
|
|
335
|
+
console.log('Poll ID (Buffer):', pollId.toString('hex'));
|
|
336
|
+
|
|
337
|
+
// Demonstrate Buffer operations
|
|
338
|
+
const data1 = Buffer.from('Hello');
|
|
339
|
+
const data2 = Buffer.from('World');
|
|
340
|
+
const combined = Buffer.concat([data1, Buffer.from(' '), data2]);
|
|
341
|
+
console.log('Combined Buffer:', combined.toString()); // "Hello World"
|
|
342
|
+
`);
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Example 10: Node.js-Specific - Audit Log Export
|
|
346
|
+
*
|
|
347
|
+
* This example shows how to export audit logs to JSON files using Node.js.
|
|
348
|
+
* For working examples, see the test files which handle type conversions properly.
|
|
349
|
+
*/
|
|
350
|
+
async function exampleAuditLogExport() {
|
|
351
|
+
console.log(`
|
|
352
|
+
const authority = createMemberWithVotingKeys();
|
|
353
|
+
const poll = PollFactory.createPlurality(
|
|
354
|
+
['Yes', 'No'],
|
|
355
|
+
authority.member,
|
|
356
|
+
);
|
|
357
|
+
|
|
358
|
+
const encoder = new VoteEncoder(authority.member.votingPublicKey!);
|
|
359
|
+
|
|
360
|
+
// Cast votes
|
|
361
|
+
poll.vote(voter1.member, encoder.encodePlurality(0, 2));
|
|
362
|
+
poll.vote(voter2.member, encoder.encodePlurality(1, 2));
|
|
363
|
+
|
|
364
|
+
poll.close();
|
|
365
|
+
|
|
366
|
+
// Export audit log to file (Node.js-specific)
|
|
367
|
+
const auditEntries = poll.auditLog.getEntries();
|
|
368
|
+
const auditData = auditEntries.map(entry => ({
|
|
369
|
+
timestamp: entry.timestamp,
|
|
370
|
+
eventType: entry.eventType,
|
|
371
|
+
pollId: entry.pollId.toString('hex'), // Convert Buffer to hex
|
|
372
|
+
signature: entry.signature.toString('hex'), // Convert Buffer to hex
|
|
373
|
+
previousHash: entry.previousHash?.toString('hex'), // Convert Buffer to hex
|
|
374
|
+
}));
|
|
375
|
+
|
|
376
|
+
await fs.writeFile(
|
|
377
|
+
'audit-log.json',
|
|
378
|
+
JSON.stringify(auditData, null, 2)
|
|
379
|
+
);
|
|
380
|
+
|
|
381
|
+
console.log('Audit log exported to audit-log.json');
|
|
382
|
+
console.log(\`Total entries: \${auditEntries.length}\`);
|
|
383
|
+
console.log('Chain valid:', poll.auditLog.verifyChain());
|
|
384
|
+
`);
|
|
385
|
+
}
|
|
386
|
+
//# sourceMappingURL=examples.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"examples.js","sourceRoot":"","sources":["../../../../../../packages/digitaldef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;;;;;;;;;;;;;;;;;GAiCX,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,KAAK,UAAU,uBAAuB;IACpC,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BX,CAAC,CAAC;AACL,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,mBAAmB;IAChC,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;;;GAkBX,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,KAAK,UAAU,qBAAqB;IAClC,OAAO,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCX,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -1,15 +1,44 @@
|
|
|
1
|
+
import { PollFactory as BasePollFactory, Member } from '@digitaldefiance/ecies-lib';
|
|
1
2
|
import type { PlatformID } from '../../interfaces';
|
|
2
|
-
import
|
|
3
|
+
import { VotingMethod } from './enumerations';
|
|
3
4
|
import { Poll } from './poll-core';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Node.js PollFactory that extends ecies-lib PollFactory
|
|
7
|
+
* Overrides factory methods to return node-ecies-lib Poll instances
|
|
8
|
+
* which use Buffer instead of Uint8Array
|
|
9
|
+
*/
|
|
10
|
+
export declare class PollFactory extends BasePollFactory {
|
|
11
|
+
/**
|
|
12
|
+
* Create a new poll with specified method
|
|
13
|
+
* Overrides base implementation to return node-ecies-lib Poll
|
|
14
|
+
*/
|
|
15
|
+
static create<TID extends PlatformID = Buffer>(choices: string[], method: VotingMethod, authority: Member<TID>, options?: {
|
|
7
16
|
maxWeight?: bigint;
|
|
8
17
|
}): Poll<TID>;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
static
|
|
18
|
+
/**
|
|
19
|
+
* Create a plurality poll (simple majority)
|
|
20
|
+
* Returns node-ecies-lib Poll instance
|
|
21
|
+
*/
|
|
22
|
+
static createPlurality<TID extends PlatformID = Buffer>(choices: string[], authority: Member<TID>): Poll<TID>;
|
|
23
|
+
/**
|
|
24
|
+
* Create an approval voting poll
|
|
25
|
+
* Returns node-ecies-lib Poll instance
|
|
26
|
+
*/
|
|
27
|
+
static createApproval<TID extends PlatformID = Buffer>(choices: string[], authority: Member<TID>): Poll<TID>;
|
|
28
|
+
/**
|
|
29
|
+
* Create a weighted voting poll
|
|
30
|
+
* Returns node-ecies-lib Poll instance
|
|
31
|
+
*/
|
|
32
|
+
static createWeighted<TID extends PlatformID = Buffer>(choices: string[], authority: Member<TID>, maxWeight: bigint): Poll<TID>;
|
|
33
|
+
/**
|
|
34
|
+
* Create a Borda count poll
|
|
35
|
+
* Returns node-ecies-lib Poll instance
|
|
36
|
+
*/
|
|
37
|
+
static createBorda<TID extends PlatformID = Buffer>(choices: string[], authority: Member<TID>): Poll<TID>;
|
|
38
|
+
/**
|
|
39
|
+
* Create a ranked choice (IRV) poll
|
|
40
|
+
* Returns node-ecies-lib Poll instance
|
|
41
|
+
*/
|
|
42
|
+
static createRankedChoice<TID extends PlatformID = Buffer>(choices: string[], authority: Member<TID>): Poll<TID>;
|
|
14
43
|
}
|
|
15
44
|
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/voting/factory.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/voting/factory.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,WAAW,IAAI,eAAe,EAC9B,MAAM,EACP,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAInD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO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.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PollFactory = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Poll Factory - Node.js optimized
|
|
6
|
+
* Extends ecies-lib PollFactory to return node-ecies-lib Poll instances
|
|
6
7
|
*/
|
|
7
8
|
const crypto_1 = require("crypto");
|
|
9
|
+
const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
|
|
10
|
+
const enumerations_1 = require("./enumerations");
|
|
8
11
|
const poll_core_1 = require("./poll-core");
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Node.js PollFactory that extends ecies-lib PollFactory
|
|
14
|
+
* Overrides factory methods to return node-ecies-lib Poll instances
|
|
15
|
+
* which use Buffer instead of Uint8Array
|
|
16
|
+
*/
|
|
17
|
+
class PollFactory extends ecies_lib_1.PollFactory {
|
|
18
|
+
/**
|
|
19
|
+
* Create a new poll with specified method
|
|
20
|
+
* Overrides base implementation to return node-ecies-lib Poll
|
|
21
|
+
*/
|
|
11
22
|
static create(choices, method, authority, options) {
|
|
12
23
|
if (!authority.votingPublicKey)
|
|
13
24
|
throw new Error('Authority must have voting public key');
|
|
25
|
+
// Use Node.js crypto for ID generation
|
|
14
26
|
const id = (0, crypto_1.randomBytes)(16);
|
|
15
|
-
|
|
27
|
+
// Return node-ecies-lib Poll instance
|
|
28
|
+
return new poll_core_1.Poll(id, choices, method, authority, // Type assertion needed for compatibility between Member and IMember
|
|
29
|
+
authority.votingPublicKey, options?.maxWeight);
|
|
16
30
|
}
|
|
31
|
+
/**
|
|
32
|
+
* Create a plurality poll (simple majority)
|
|
33
|
+
* Returns node-ecies-lib Poll instance
|
|
34
|
+
*/
|
|
17
35
|
static createPlurality(choices, authority) {
|
|
18
|
-
return this.create(choices,
|
|
36
|
+
return this.create(choices, enumerations_1.VotingMethod.Plurality, authority);
|
|
19
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Create an approval voting poll
|
|
40
|
+
* Returns node-ecies-lib Poll instance
|
|
41
|
+
*/
|
|
20
42
|
static createApproval(choices, authority) {
|
|
21
|
-
return this.create(choices,
|
|
43
|
+
return this.create(choices, enumerations_1.VotingMethod.Approval, authority);
|
|
22
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Create a weighted voting poll
|
|
47
|
+
* Returns node-ecies-lib Poll instance
|
|
48
|
+
*/
|
|
23
49
|
static createWeighted(choices, authority, maxWeight) {
|
|
24
|
-
return this.create(choices,
|
|
50
|
+
return this.create(choices, enumerations_1.VotingMethod.Weighted, authority, {
|
|
25
51
|
maxWeight,
|
|
26
52
|
});
|
|
27
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Create a Borda count poll
|
|
56
|
+
* Returns node-ecies-lib Poll instance
|
|
57
|
+
*/
|
|
28
58
|
static createBorda(choices, authority) {
|
|
29
|
-
return this.create(choices,
|
|
59
|
+
return this.create(choices, enumerations_1.VotingMethod.Borda, authority);
|
|
30
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Create a ranked choice (IRV) poll
|
|
63
|
+
* Returns node-ecies-lib Poll instance
|
|
64
|
+
*/
|
|
31
65
|
static createRankedChoice(choices, authority) {
|
|
32
|
-
return this.create(choices,
|
|
66
|
+
return this.create(choices, enumerations_1.VotingMethod.RankedChoice, authority);
|
|
33
67
|
}
|
|
34
68
|
}
|
|
35
69
|
exports.PollFactory = PollFactory;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/voting/factory.ts"],"names":[],"mappings":";;;AAAA
|
|
1
|
+
{"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/voting/factory.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,mCAAqC;AAErC,0DAGoC;AAMpC,iDAA8C;AAC9C,2CAAmC;AAEnC;;;;GAIG;AACH,MAAa,WAAY,SAAQ,uBAAe;IAC9C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,CAAC,OAAO,EAAE,2BAAY,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC;IACpE,CAAC;CACF;AArFD,kCAqFC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js Hierarchical Vote Aggregator
|
|
3
|
+
* Extends ecies-lib aggregators with Buffer support
|
|
4
|
+
*/
|
|
5
|
+
import { PrecinctAggregator as BasePrecinctAggregator, CountyAggregator as BaseCountyAggregator, StateAggregator as BaseStateAggregator, NationalAggregator as BaseNationalAggregator } from '@digitaldefiance/ecies-lib';
|
|
6
|
+
import type { PublicKey } from 'paillier-bigint';
|
|
7
|
+
import type { PlatformID } from '../../interfaces';
|
|
8
|
+
import type { JurisdictionConfig, IVoteLogger, ICheckpointManager } from './interfaces';
|
|
9
|
+
import { Poll } from './poll-core';
|
|
10
|
+
/**
|
|
11
|
+
* Node.js Precinct-level aggregator
|
|
12
|
+
* Extends ecies-lib PrecinctAggregator with Buffer support
|
|
13
|
+
* Handles ~900 votes in memory with optional persistence
|
|
14
|
+
*/
|
|
15
|
+
export declare class PrecinctAggregator<TID extends PlatformID = Buffer> extends BasePrecinctAggregator<TID> {
|
|
16
|
+
constructor(poll: Poll<TID>, config: JurisdictionConfig<TID>, logger?: IVoteLogger<TID>, checkpointMgr?: ICheckpointManager<TID>);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Node.js County-level aggregator
|
|
20
|
+
* Extends ecies-lib CountyAggregator with Buffer support
|
|
21
|
+
* Combines precinct tallies
|
|
22
|
+
*/
|
|
23
|
+
export declare class CountyAggregator<TID extends PlatformID = Buffer> extends BaseCountyAggregator<TID> {
|
|
24
|
+
constructor(config: JurisdictionConfig<TID>, votingPublicKey: PublicKey);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Node.js State-level aggregator
|
|
28
|
+
* Extends ecies-lib StateAggregator with Buffer support
|
|
29
|
+
* Combines county tallies
|
|
30
|
+
*/
|
|
31
|
+
export declare class StateAggregator<TID extends PlatformID = Buffer> extends BaseStateAggregator<TID> {
|
|
32
|
+
constructor(config: JurisdictionConfig<TID>, votingPublicKey: PublicKey);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Node.js National-level aggregator
|
|
36
|
+
* Extends ecies-lib NationalAggregator with Buffer support
|
|
37
|
+
* Combines state tallies and decrypts final result
|
|
38
|
+
*/
|
|
39
|
+
export declare class NationalAggregator<TID extends PlatformID = Buffer> extends BaseNationalAggregator<TID> {
|
|
40
|
+
constructor(config: JurisdictionConfig<TID>, votingPublicKey: PublicKey);
|
|
41
|
+
}
|
|
42
|
+
export { JurisdictionLevel } from './enumerations';
|
|
43
|
+
export type { JurisdictionConfig, AggregatedTally } from './interfaces';
|
|
44
|
+
//# sourceMappingURL=hierarchical-aggregator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hierarchical-aggregator.d.ts","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/voting/hierarchical-aggregator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,kBAAkB,IAAI,sBAAsB,EAC5C,gBAAgB,IAAI,oBAAoB,EACxC,eAAe,IAAI,mBAAmB,EACtC,kBAAkB,IAAI,sBAAsB,EAC7C,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,KAAK,EACV,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EACnB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAEnC;;;;GAIG;AACH,qBAAa,kBAAkB,CAC7B,GAAG,SAAS,UAAU,GAAG,MAAM,CAC/B,SAAQ,sBAAsB,CAAC,GAAG,CAAC;gBAEjC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,EACf,MAAM,EAAE,kBAAkB,CAAC,GAAG,CAAC,EAC/B,MAAM,CAAC,EAAE,WAAW,CAAC,GAAG,CAAC,EACzB,aAAa,CAAC,EAAE,kBAAkB,CAAC,GAAG,CAAC;CAO1C;AAED;;;;GAIG;AACH,qBAAa,gBAAgB,CAC3B,GAAG,SAAS,UAAU,GAAG,MAAM,CAC/B,SAAQ,oBAAoB,CAAC,GAAG,CAAC;gBACrB,MAAM,EAAE,kBAAkB,CAAC,GAAG,CAAC,EAAE,eAAe,EAAE,SAAS;CAMxE;AAED;;;;GAIG;AACH,qBAAa,eAAe,CAC1B,GAAG,SAAS,UAAU,GAAG,MAAM,CAC/B,SAAQ,mBAAmB,CAAC,GAAG,CAAC;gBACpB,MAAM,EAAE,kBAAkB,CAAC,GAAG,CAAC,EAAE,eAAe,EAAE,SAAS;CAMxE;AAED;;;;GAIG;AACH,qBAAa,kBAAkB,CAC7B,GAAG,SAAS,UAAU,GAAG,MAAM,CAC/B,SAAQ,sBAAsB,CAAC,GAAG,CAAC;gBACvB,MAAM,EAAE,kBAAkB,CAAC,GAAG,CAAC,EAAE,eAAe,EAAE,SAAS;CAMxE;AAGD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,YAAY,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JurisdictionLevel = exports.NationalAggregator = exports.StateAggregator = exports.CountyAggregator = exports.PrecinctAggregator = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Node.js Hierarchical Vote Aggregator
|
|
6
|
+
* Extends ecies-lib aggregators with Buffer support
|
|
7
|
+
*/
|
|
8
|
+
const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
|
|
9
|
+
/**
|
|
10
|
+
* Node.js Precinct-level aggregator
|
|
11
|
+
* Extends ecies-lib PrecinctAggregator with Buffer support
|
|
12
|
+
* Handles ~900 votes in memory with optional persistence
|
|
13
|
+
*/
|
|
14
|
+
class PrecinctAggregator extends ecies_lib_1.PrecinctAggregator {
|
|
15
|
+
constructor(poll, config, logger, checkpointMgr) {
|
|
16
|
+
super(poll, config, logger, checkpointMgr);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.PrecinctAggregator = PrecinctAggregator;
|
|
20
|
+
/**
|
|
21
|
+
* Node.js County-level aggregator
|
|
22
|
+
* Extends ecies-lib CountyAggregator with Buffer support
|
|
23
|
+
* Combines precinct tallies
|
|
24
|
+
*/
|
|
25
|
+
class CountyAggregator extends ecies_lib_1.CountyAggregator {
|
|
26
|
+
constructor(config, votingPublicKey) {
|
|
27
|
+
super(config, votingPublicKey);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
exports.CountyAggregator = CountyAggregator;
|
|
31
|
+
/**
|
|
32
|
+
* Node.js State-level aggregator
|
|
33
|
+
* Extends ecies-lib StateAggregator with Buffer support
|
|
34
|
+
* Combines county tallies
|
|
35
|
+
*/
|
|
36
|
+
class StateAggregator extends ecies_lib_1.StateAggregator {
|
|
37
|
+
constructor(config, votingPublicKey) {
|
|
38
|
+
super(config, votingPublicKey);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.StateAggregator = StateAggregator;
|
|
42
|
+
/**
|
|
43
|
+
* Node.js National-level aggregator
|
|
44
|
+
* Extends ecies-lib NationalAggregator with Buffer support
|
|
45
|
+
* Combines state tallies and decrypts final result
|
|
46
|
+
*/
|
|
47
|
+
class NationalAggregator extends ecies_lib_1.NationalAggregator {
|
|
48
|
+
constructor(config, votingPublicKey) {
|
|
49
|
+
super(config, votingPublicKey);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.NationalAggregator = NationalAggregator;
|
|
53
|
+
// Re-export types and enums for convenience
|
|
54
|
+
var enumerations_1 = require("./enumerations");
|
|
55
|
+
Object.defineProperty(exports, "JurisdictionLevel", { enumerable: true, get: function () { return enumerations_1.JurisdictionLevel; } });
|
|
56
|
+
//# sourceMappingURL=hierarchical-aggregator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hierarchical-aggregator.js","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/voting/hierarchical-aggregator.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,0DAKoC;AAYpC;;;;GAIG;AACH,MAAa,kBAEX,SAAQ,8BAA2B;IACnC,YACE,IAAe,EACf,MAA+B,EAC/B,MAAyB,EACzB,aAAuC;QAEvC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC;IAC7C,CAAC;CAIF;AAdD,gDAcC;AAED;;;;GAIG;AACH,MAAa,gBAEX,SAAQ,4BAAyB;IACjC,YAAY,MAA+B,EAAE,eAA0B;QACrE,KAAK,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACjC,CAAC;CAIF;AATD,4CASC;AAED;;;;GAIG;AACH,MAAa,eAEX,SAAQ,2BAAwB;IAChC,YAAY,MAA+B,EAAE,eAA0B;QACrE,KAAK,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACjC,CAAC;CAIF;AATD,0CASC;AAED;;;;GAIG;AACH,MAAa,kBAEX,SAAQ,8BAA2B;IACnC,YAAY,MAA+B,EAAE,eAA0B;QACrE,KAAK,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACjC,CAAC;CAIF;AATD,gDASC;AAED,4CAA4C;AAC5C,+CAAmD;AAA1C,iHAAA,iBAAiB,OAAA"}
|