@digitaldefiance/node-ecies-lib 4.17.10 → 4.19.1
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/README.md +6 -1
- package/package.json +3 -3
- package/src/lib/voting/index.d.ts +1 -0
- package/src/lib/voting/index.d.ts.map +1 -1
- package/src/lib/voting/index.js +2 -0
- package/src/lib/voting/index.js.map +1 -1
- package/src/lib/voting/threshold/ceremony-coordinator.d.ts +25 -0
- package/src/lib/voting/threshold/ceremony-coordinator.d.ts.map +1 -0
- package/src/lib/voting/threshold/ceremony-coordinator.js +64 -0
- package/src/lib/voting/threshold/ceremony-coordinator.js.map +1 -0
- package/src/lib/voting/threshold/index.d.ts +16 -0
- package/src/lib/voting/threshold/index.d.ts.map +1 -1
- package/src/lib/voting/threshold/index.js +60 -1
- package/src/lib/voting/threshold/index.js.map +1 -1
- package/src/lib/voting/threshold/partial-decryption-service.d.ts +51 -0
- package/src/lib/voting/threshold/partial-decryption-service.d.ts.map +1 -0
- package/src/lib/voting/threshold/partial-decryption-service.js +65 -0
- package/src/lib/voting/threshold/partial-decryption-service.js.map +1 -0
- package/src/lib/voting/threshold/threshold-aggregators.d.ts +43 -0
- package/src/lib/voting/threshold/threshold-aggregators.d.ts.map +1 -0
- package/src/lib/voting/threshold/threshold-aggregators.js +53 -0
- package/src/lib/voting/threshold/threshold-aggregators.js.map +1 -0
- package/src/lib/voting/threshold/threshold-audit-log.d.ts +31 -0
- package/src/lib/voting/threshold/threshold-audit-log.d.ts.map +1 -0
- package/src/lib/voting/threshold/threshold-audit-log.js +101 -0
- package/src/lib/voting/threshold/threshold-audit-log.js.map +1 -0
- package/src/lib/voting/threshold/threshold-key-generator.d.ts +45 -0
- package/src/lib/voting/threshold/threshold-key-generator.d.ts.map +1 -0
- package/src/lib/voting/threshold/threshold-key-generator.js +60 -0
- package/src/lib/voting/threshold/threshold-key-generator.js.map +1 -0
- package/src/lib/voting/threshold/threshold-poll-factory.d.ts +16 -0
- package/src/lib/voting/threshold/threshold-poll-factory.d.ts.map +1 -0
- package/src/lib/voting/threshold/threshold-poll-factory.js +19 -0
- package/src/lib/voting/threshold/threshold-poll-factory.js.map +1 -0
- package/src/lib/voting/threshold/threshold-poll.d.ts +21 -0
- package/src/lib/voting/threshold/threshold-poll.d.ts.map +1 -0
- package/src/lib/voting/threshold/threshold-poll.js +22 -0
- package/src/lib/voting/threshold/threshold-poll.js.map +1 -0
- package/src/lib/voting/threshold-corporate-vote-example.d.ts +33 -0
- package/src/lib/voting/threshold-corporate-vote-example.d.ts.map +1 -0
- package/src/lib/voting/threshold-corporate-vote-example.js +206 -0
- package/src/lib/voting/threshold-corporate-vote-example.js.map +1 -0
- package/src/lib/voting/threshold-small-org-example.d.ts +38 -0
- package/src/lib/voting/threshold-small-org-example.d.ts.map +1 -0
- package/src/lib/voting/threshold-small-org-example.js +186 -0
- package/src/lib/voting/threshold-small-org-example.js.map +1 -0
- package/src/lib/voting/threshold-us-election-example.d.ts +33 -0
- package/src/lib/voting/threshold-us-election-example.d.ts.map +1 -0
- package/src/lib/voting/threshold-us-election-example.js +213 -0
- package/src/lib/voting/threshold-us-election-example.js.map +1 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Threshold Small Organization Vote Example
|
|
4
|
+
*
|
|
5
|
+
* Demonstrates a 2-of-3 Guardian threshold voting setup with a single
|
|
6
|
+
* decryption at poll close — backward-compatible behavior where no
|
|
7
|
+
* interval decryption occurs during voting.
|
|
8
|
+
*
|
|
9
|
+
* This is the simplest threshold configuration, suitable for:
|
|
10
|
+
* - Small nonprofits or clubs
|
|
11
|
+
* - Board elections
|
|
12
|
+
* - Committee decisions
|
|
13
|
+
* - Any scenario where real-time tallies aren't needed but distributed
|
|
14
|
+
* trust is still desired
|
|
15
|
+
*
|
|
16
|
+
* Key concepts shown:
|
|
17
|
+
* - Minimal threshold setup (2-of-3)
|
|
18
|
+
* - Single decryption at poll close (no intervals)
|
|
19
|
+
* - Backward-compatible behavior with threshold security
|
|
20
|
+
* - Simple ceremony flow
|
|
21
|
+
*
|
|
22
|
+
* NOTE: This example is for documentation purposes and demonstrates the
|
|
23
|
+
* intended API. Due to type incompatibilities between ecies-lib Member
|
|
24
|
+
* (Uint8Array) and node-ecies-lib voting system (Buffer), some type
|
|
25
|
+
* assertions may be needed in actual usage. See test files for working
|
|
26
|
+
* integration examples.
|
|
27
|
+
*/
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.runSmallOrgVote = runSmallOrgVote;
|
|
30
|
+
const threshold_1 = require("./threshold");
|
|
31
|
+
/**
|
|
32
|
+
* Run a simulated small organization vote with threshold decryption.
|
|
33
|
+
*
|
|
34
|
+
* Setup:
|
|
35
|
+
* - 3 Guardians (president, secretary, treasurer)
|
|
36
|
+
* - Threshold of 2 (any two officers can decrypt)
|
|
37
|
+
* - Single decryption at poll close (no interval decryption)
|
|
38
|
+
* - Behaves like a standard poll but with distributed trust
|
|
39
|
+
*/
|
|
40
|
+
async function runSmallOrgVote() {
|
|
41
|
+
console.log('=== Small Organization Board Election ===\n');
|
|
42
|
+
console.log('Configuration: 2-of-3 Guardian threshold');
|
|
43
|
+
console.log('Interval: Single decryption at poll close\n');
|
|
44
|
+
// ─── Step 1: Generate threshold keys ───────────────────────────
|
|
45
|
+
console.log('Step 1: Generating threshold keys (2-of-3)...');
|
|
46
|
+
const thresholdConfig = {
|
|
47
|
+
totalShares: 3,
|
|
48
|
+
threshold: 2,
|
|
49
|
+
keyBitLength: 512, // Small for demo; use 2048+ in production
|
|
50
|
+
};
|
|
51
|
+
const keyGen = new threshold_1.ThresholdKeyGenerator();
|
|
52
|
+
keyGen.validateConfig(thresholdConfig);
|
|
53
|
+
const keyPair = await keyGen.generate(thresholdConfig);
|
|
54
|
+
console.log(` ${keyPair.keyShares.length} key shares generated`);
|
|
55
|
+
console.log(` Any 2 of 3 officers can decrypt results\n`);
|
|
56
|
+
// ─── Step 2: Register Guardians (organization officers) ────────
|
|
57
|
+
console.log('Step 2: Registering organization officers as Guardians...');
|
|
58
|
+
const guardianNames = [
|
|
59
|
+
'President (Jane)',
|
|
60
|
+
'Secretary (Alex)',
|
|
61
|
+
'Treasurer (Sam)',
|
|
62
|
+
];
|
|
63
|
+
const registry = new threshold_1.GuardianRegistry(thresholdConfig.totalShares);
|
|
64
|
+
const guardianIds = [];
|
|
65
|
+
for (let i = 0; i < thresholdConfig.totalShares; i++) {
|
|
66
|
+
const id = Buffer.from([i + 1]);
|
|
67
|
+
guardianIds.push(id);
|
|
68
|
+
const guardian = {
|
|
69
|
+
id,
|
|
70
|
+
name: guardianNames[i],
|
|
71
|
+
shareIndex: keyPair.keyShares[i].index,
|
|
72
|
+
verificationKey: keyPair.keyShares[i].verificationKey,
|
|
73
|
+
status: threshold_1.GuardianStatus.Online,
|
|
74
|
+
};
|
|
75
|
+
registry.register(guardian);
|
|
76
|
+
console.log(` [${i + 1}] ${guardianNames[i]} — Online`);
|
|
77
|
+
}
|
|
78
|
+
console.log(` Total officers: ${registry.count}\n`);
|
|
79
|
+
// ─── Step 3: Configure for single decryption at close ──────────
|
|
80
|
+
console.log('Step 3: Configuring single-decryption mode...');
|
|
81
|
+
console.log(' (No interval decryption — results revealed only at close)\n');
|
|
82
|
+
// Use a very large time interval so no interval triggers fire.
|
|
83
|
+
// The only decryption happens via triggerFinal() at poll close.
|
|
84
|
+
const intervalConfig = {
|
|
85
|
+
triggerType: threshold_1.IntervalTriggerType.TimeBased,
|
|
86
|
+
timeIntervalMs: Number.MAX_SAFE_INTEGER, // Effectively disabled
|
|
87
|
+
minimumIntervalMs: 60 * 1000,
|
|
88
|
+
ceremonyTimeoutMs: 2 * 60 * 1000, // 2 min timeout
|
|
89
|
+
};
|
|
90
|
+
console.log(' Time interval: disabled (single decryption at close)');
|
|
91
|
+
console.log(` Ceremony timeout: ${intervalConfig.ceremonyTimeoutMs / 1000}s\n`);
|
|
92
|
+
// ─── Step 4: Simulate voting period ────────────────────────────
|
|
93
|
+
console.log('Step 4: Voting period (no results revealed)...');
|
|
94
|
+
const choices = ['Maria Garcia', 'David Chen', 'Lisa Patel'];
|
|
95
|
+
const pollId = Buffer.from([0, 1]);
|
|
96
|
+
// In production, members would cast encrypted votes here.
|
|
97
|
+
// The homomorphic aggregation accumulates encrypted tallies
|
|
98
|
+
// without anyone being able to see intermediate results.
|
|
99
|
+
console.log(' Ballot: Board Member Election');
|
|
100
|
+
console.log(` Candidates: ${choices.join(', ')}`);
|
|
101
|
+
console.log(' 25 members casting votes...');
|
|
102
|
+
console.log(' (All votes encrypted — no one can see results yet)\n');
|
|
103
|
+
// Simulated final encrypted tallies after all 25 members voted
|
|
104
|
+
const finalVotes = [12n, 8n, 5n]; // 25 total votes
|
|
105
|
+
const encryptedTally = finalVotes.map((v) => keyPair.publicKey.encrypt(v));
|
|
106
|
+
// ─── Step 5: Close poll and run final ceremony ─────────────────
|
|
107
|
+
console.log('Step 5: Poll closed — running final decryption ceremony...');
|
|
108
|
+
const coordinator = new threshold_1.CeremonyCoordinator(keyPair.publicKey, keyPair.verificationKeys, keyPair.theta, thresholdConfig, intervalConfig.ceremonyTimeoutMs);
|
|
109
|
+
// Final ceremony (intervalNumber = -1 indicates final)
|
|
110
|
+
const ceremony = coordinator.startCeremony(pollId, -1, encryptedTally);
|
|
111
|
+
console.log(` Final ceremony started: ${ceremony.id.slice(0, 16)}...`);
|
|
112
|
+
// Only 2 of 3 officers needed — Treasurer is traveling
|
|
113
|
+
console.log('\n Treasurer (Sam) is unavailable — only 2 officers needed:');
|
|
114
|
+
registry.updateStatus(guardianIds[2], threshold_1.GuardianStatus.Offline);
|
|
115
|
+
const partialService = new threshold_1.PartialDecryptionService(keyPair.publicKey);
|
|
116
|
+
// President and Secretary participate
|
|
117
|
+
const participatingIndices = [0, 1];
|
|
118
|
+
for (const idx of participatingIndices) {
|
|
119
|
+
const share = keyPair.keyShares[idx];
|
|
120
|
+
const partial = partialService.computePartial(encryptedTally, share, ceremony.nonce);
|
|
121
|
+
const accepted = coordinator.submitPartial(ceremony.id, partial);
|
|
122
|
+
console.log(` ${guardianNames[idx]}: ${accepted ? '✓ decryption submitted' : '✗ rejected'}`);
|
|
123
|
+
}
|
|
124
|
+
console.log(`\n Ceremony status: ${ceremony.status}`);
|
|
125
|
+
// ─── Step 6: Publish and verify final results ──────────────────
|
|
126
|
+
if (ceremony.result) {
|
|
127
|
+
console.log('\nStep 6: Publishing final results...');
|
|
128
|
+
const tallyFeed = new threshold_1.PublicTallyFeed();
|
|
129
|
+
const finalTally = {
|
|
130
|
+
pollId,
|
|
131
|
+
intervalNumber: -1, // Final tally
|
|
132
|
+
tallies: ceremony.result.tallies,
|
|
133
|
+
choices,
|
|
134
|
+
voteCount: 25,
|
|
135
|
+
cumulativeVoteCount: 25,
|
|
136
|
+
proof: ceremony.result.combinedProof,
|
|
137
|
+
participatingGuardians: ceremony.result.participatingGuardians,
|
|
138
|
+
timestamp: Date.now(),
|
|
139
|
+
isFinal: true,
|
|
140
|
+
};
|
|
141
|
+
tallyFeed.publish(finalTally);
|
|
142
|
+
// Display results
|
|
143
|
+
console.log('\n ╔══════════════════════════════════╗');
|
|
144
|
+
console.log(' ║ BOARD ELECTION RESULTS ║');
|
|
145
|
+
console.log(' ╠══════════════════════════════════╣');
|
|
146
|
+
choices.forEach((choice, i) => {
|
|
147
|
+
const votes = ceremony.result.tallies[i];
|
|
148
|
+
const pct = ((Number(votes) / 25) * 100).toFixed(0);
|
|
149
|
+
const bar = '█'.repeat(Math.round(Number(votes)));
|
|
150
|
+
console.log(` ║ ${choice.padEnd(15)} ${String(votes).padStart(3)} (${pct.padStart(2)}%) ${bar}`);
|
|
151
|
+
});
|
|
152
|
+
console.log(' ╠══════════════════════════════════╣');
|
|
153
|
+
console.log(` ║ Total votes: 25 ║`);
|
|
154
|
+
console.log(' ╚══════════════════════════════════╝');
|
|
155
|
+
// Determine winner
|
|
156
|
+
let maxVotes = 0n;
|
|
157
|
+
let winnerIdx = 0;
|
|
158
|
+
ceremony.result.tallies.forEach((v, i) => {
|
|
159
|
+
if (v > maxVotes) {
|
|
160
|
+
maxVotes = v;
|
|
161
|
+
winnerIdx = i;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
console.log(`\n Winner: ${choices[winnerIdx]} 🎉`);
|
|
165
|
+
// ─── Step 7: Verify results ────────────────────────────────
|
|
166
|
+
console.log('\nStep 7: Verifying results...');
|
|
167
|
+
const verifier = new threshold_1.TallyVerifier(keyPair.publicKey, keyPair.verificationKeys, thresholdConfig, keyPair.theta);
|
|
168
|
+
const registeredIndices = keyPair.keyShares.map((s) => s.index);
|
|
169
|
+
const result = verifier.verify(finalTally, encryptedTally, keyPair.verificationKeys, keyPair.publicKey, registeredIndices);
|
|
170
|
+
console.log(` Proof valid: ${result.checks.proofValid ? '✓' : '✗'}`);
|
|
171
|
+
console.log(` Guardians authorized: ${result.checks.guardiansAuthorized ? '✓' : '✗'}`);
|
|
172
|
+
console.log(` Tally consistent: ${result.checks.tallyMatchesEncrypted ? '✓' : '✗'}`);
|
|
173
|
+
console.log(` Overall: ${result.valid ? '✓ VERIFIED' : '✗ FAILED'}`);
|
|
174
|
+
}
|
|
175
|
+
console.log('\n=== Small organization vote complete ===');
|
|
176
|
+
console.log('Key takeaway:');
|
|
177
|
+
console.log(' - Same security as a full threshold setup');
|
|
178
|
+
console.log(' - No interval decryption — results only at close');
|
|
179
|
+
console.log(' - Only 2 of 3 officers needed (Treasurer was away)');
|
|
180
|
+
console.log(' - Behaves like a standard poll but no single point of trust');
|
|
181
|
+
}
|
|
182
|
+
// Run example
|
|
183
|
+
if (require.main === module) {
|
|
184
|
+
runSmallOrgVote().catch(console.error);
|
|
185
|
+
}
|
|
186
|
+
//# sourceMappingURL=threshold-small-org-example.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"threshold-small-org-example.js","sourceRoot":"","sources":["../../../../../../packages/digitaldef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C,CAAC,CAAC;IAC1D,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IAC7B,OAAO,CAAC,GAAG,CAAC,6CAA6C,CAAC,CAAC;IAC3D,OAAO,CAAC,GAAG,CAAC,oDAAoD,CAAC,CAAC;IAClE,OAAO,CAAC,GAAG,CAAC,sDAAsD,CAAC,CAAC;IACpE,OAAO,CAAC,GAAG,CAAC,+DAA+D,CAAC,CAAC;AAC/E,CAAC;AAED,cAAc;AACd,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;IAC5B,eAAe,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Threshold U.S. Election Example
|
|
3
|
+
*
|
|
4
|
+
* Demonstrates a 5-of-9 Guardian threshold voting setup with hourly
|
|
5
|
+
* interval decryption and public tally feed consumption — modeled
|
|
6
|
+
* after a U.S. presidential election with real-time CNN-style results.
|
|
7
|
+
*
|
|
8
|
+
* Key concepts shown:
|
|
9
|
+
* - Threshold key generation (5-of-9)
|
|
10
|
+
* - Guardian registration and management
|
|
11
|
+
* - Hourly interval decryption ceremonies
|
|
12
|
+
* - Public tally feed subscription for media/observers
|
|
13
|
+
* - Hierarchical aggregation with threshold decryption
|
|
14
|
+
* - Third-party tally verification
|
|
15
|
+
*
|
|
16
|
+
* NOTE: This example is for documentation purposes and demonstrates the
|
|
17
|
+
* intended API. Due to type incompatibilities between ecies-lib Member
|
|
18
|
+
* (Uint8Array) and node-ecies-lib voting system (Buffer), some type
|
|
19
|
+
* assertions may be needed in actual usage. See test files for working
|
|
20
|
+
* integration examples.
|
|
21
|
+
*/
|
|
22
|
+
/**
|
|
23
|
+
* Run a simulated U.S. presidential election with threshold decryption.
|
|
24
|
+
*
|
|
25
|
+
* Setup:
|
|
26
|
+
* - 9 Guardians (bipartisan election officials, judiciary, civil society)
|
|
27
|
+
* - Threshold of 5 (majority required to decrypt)
|
|
28
|
+
* - Hourly interval decryption during voting hours (6 AM – 8 PM)
|
|
29
|
+
* - Public tally feed for media consumption
|
|
30
|
+
*/
|
|
31
|
+
declare function runThresholdUSElection(): Promise<void>;
|
|
32
|
+
export { runThresholdUSElection };
|
|
33
|
+
//# sourceMappingURL=threshold-us-election-example.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"threshold-us-election-example.d.ts","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/voting/threshold-us-election-example.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAoBH;;;;;;;;GAQG;AACH,iBAAe,sBAAsB,IAAI,OAAO,CAAC,IAAI,CAAC,CAiRrD;AAOD,OAAO,EAAE,sBAAsB,EAAE,CAAC"}
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Threshold U.S. Election Example
|
|
4
|
+
*
|
|
5
|
+
* Demonstrates a 5-of-9 Guardian threshold voting setup with hourly
|
|
6
|
+
* interval decryption and public tally feed consumption — modeled
|
|
7
|
+
* after a U.S. presidential election with real-time CNN-style results.
|
|
8
|
+
*
|
|
9
|
+
* Key concepts shown:
|
|
10
|
+
* - Threshold key generation (5-of-9)
|
|
11
|
+
* - Guardian registration and management
|
|
12
|
+
* - Hourly interval decryption ceremonies
|
|
13
|
+
* - Public tally feed subscription for media/observers
|
|
14
|
+
* - Hierarchical aggregation with threshold decryption
|
|
15
|
+
* - Third-party tally verification
|
|
16
|
+
*
|
|
17
|
+
* NOTE: This example is for documentation purposes and demonstrates the
|
|
18
|
+
* intended API. Due to type incompatibilities between ecies-lib Member
|
|
19
|
+
* (Uint8Array) and node-ecies-lib voting system (Buffer), some type
|
|
20
|
+
* assertions may be needed in actual usage. See test files for working
|
|
21
|
+
* integration examples.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.runThresholdUSElection = runThresholdUSElection;
|
|
25
|
+
const threshold_1 = require("./threshold");
|
|
26
|
+
/**
|
|
27
|
+
* Run a simulated U.S. presidential election with threshold decryption.
|
|
28
|
+
*
|
|
29
|
+
* Setup:
|
|
30
|
+
* - 9 Guardians (bipartisan election officials, judiciary, civil society)
|
|
31
|
+
* - Threshold of 5 (majority required to decrypt)
|
|
32
|
+
* - Hourly interval decryption during voting hours (6 AM – 8 PM)
|
|
33
|
+
* - Public tally feed for media consumption
|
|
34
|
+
*/
|
|
35
|
+
async function runThresholdUSElection() {
|
|
36
|
+
console.log('=== Threshold U.S. Presidential Election ===\n');
|
|
37
|
+
console.log('Configuration: 5-of-9 Guardian threshold');
|
|
38
|
+
console.log('Interval: Hourly decryption ceremonies\n');
|
|
39
|
+
// ─── Step 1: Generate threshold keys ───────────────────────────
|
|
40
|
+
console.log('Step 1: Generating threshold Paillier keys...');
|
|
41
|
+
const thresholdConfig = {
|
|
42
|
+
totalShares: 9,
|
|
43
|
+
threshold: 5,
|
|
44
|
+
keyBitLength: 512, // Small for demo; use 2048+ in production
|
|
45
|
+
};
|
|
46
|
+
const keyGen = new threshold_1.ThresholdKeyGenerator();
|
|
47
|
+
keyGen.validateConfig(thresholdConfig);
|
|
48
|
+
const keyPair = await keyGen.generate(thresholdConfig);
|
|
49
|
+
console.log(` Public key generated (${thresholdConfig.keyBitLength}-bit)`);
|
|
50
|
+
console.log(` ${keyPair.keyShares.length} key shares created`);
|
|
51
|
+
console.log(` Threshold: ${thresholdConfig.threshold} of ${thresholdConfig.totalShares}\n`);
|
|
52
|
+
// ─── Step 2: Register Guardians ────────────────────────────────
|
|
53
|
+
console.log('Step 2: Registering 9 Guardians...');
|
|
54
|
+
const guardianNames = [
|
|
55
|
+
'Democratic Party Representative',
|
|
56
|
+
'Republican Party Representative',
|
|
57
|
+
'Federal Judge (Chief)',
|
|
58
|
+
'Federal Judge (Associate)',
|
|
59
|
+
'State Secretary of State',
|
|
60
|
+
'League of Women Voters',
|
|
61
|
+
'ACLU Observer',
|
|
62
|
+
'Academic Cryptographer',
|
|
63
|
+
'International Election Monitor',
|
|
64
|
+
];
|
|
65
|
+
const registry = new threshold_1.GuardianRegistry(thresholdConfig.totalShares);
|
|
66
|
+
const guardianIds = [];
|
|
67
|
+
for (let i = 0; i < thresholdConfig.totalShares; i++) {
|
|
68
|
+
const id = Buffer.from([i + 1]);
|
|
69
|
+
guardianIds.push(id);
|
|
70
|
+
const guardian = {
|
|
71
|
+
id,
|
|
72
|
+
name: guardianNames[i],
|
|
73
|
+
shareIndex: keyPair.keyShares[i].index,
|
|
74
|
+
verificationKey: keyPair.keyShares[i].verificationKey,
|
|
75
|
+
status: threshold_1.GuardianStatus.Online,
|
|
76
|
+
};
|
|
77
|
+
registry.register(guardian);
|
|
78
|
+
console.log(` [${i + 1}] ${guardianNames[i]} — Online`);
|
|
79
|
+
}
|
|
80
|
+
// Monitor Guardian status changes
|
|
81
|
+
registry.onStatusChange((event) => {
|
|
82
|
+
const guardian = registry.getGuardian(event.guardianId);
|
|
83
|
+
console.log(` ⚡ Guardian "${guardian?.name}" status: ${event.previousStatus} → ${event.newStatus}`);
|
|
84
|
+
});
|
|
85
|
+
console.log(` Total registered: ${registry.count}\n`);
|
|
86
|
+
// ─── Step 3: Configure interval scheduling ─────────────────────
|
|
87
|
+
console.log('Step 3: Configuring hourly interval decryption...');
|
|
88
|
+
const intervalConfig = {
|
|
89
|
+
triggerType: threshold_1.IntervalTriggerType.TimeBased,
|
|
90
|
+
timeIntervalMs: 60 * 60 * 1000, // 1 hour
|
|
91
|
+
minimumIntervalMs: 30 * 60 * 1000, // 30 min minimum between ceremonies
|
|
92
|
+
ceremonyTimeoutMs: 5 * 60 * 1000, // 5 min timeout per ceremony
|
|
93
|
+
};
|
|
94
|
+
console.log(` Trigger: ${intervalConfig.triggerType}`);
|
|
95
|
+
console.log(` Interval: ${(intervalConfig.timeIntervalMs ?? 0) / 60000} minutes`);
|
|
96
|
+
console.log(` Ceremony timeout: ${intervalConfig.ceremonyTimeoutMs / 60000} minutes\n`);
|
|
97
|
+
// ─── Step 4: Create threshold poll ─────────────────────────────
|
|
98
|
+
console.log('Step 4: Creating threshold-enabled poll...');
|
|
99
|
+
const thresholdPollConfig = {
|
|
100
|
+
thresholdConfig,
|
|
101
|
+
intervalConfig,
|
|
102
|
+
guardianRegistry: registry,
|
|
103
|
+
keyPair,
|
|
104
|
+
};
|
|
105
|
+
console.log(' Poll configuration created:');
|
|
106
|
+
console.log(` Threshold: ${thresholdPollConfig.thresholdConfig.threshold} of ${thresholdPollConfig.thresholdConfig.totalShares}`);
|
|
107
|
+
console.log(` Interval trigger: ${thresholdPollConfig.intervalConfig.triggerType}`);
|
|
108
|
+
console.log(` Guardians registered: ${thresholdPollConfig.guardianRegistry.count}`);
|
|
109
|
+
console.log(` Key pair provided: ${thresholdPollConfig.keyPair ? '✓' : '✗'}`);
|
|
110
|
+
console.log(' Choices: ["Alice Johnson", "Bob Smith", "Charlie Davis"]');
|
|
111
|
+
console.log(' In production: ThresholdPollFactory.createThresholdPoll(choices, method, authority, config)\n');
|
|
112
|
+
// ─── Step 5: Set up public tally feed ──────────────────────────
|
|
113
|
+
console.log('Step 5: Setting up public tally feed...');
|
|
114
|
+
const tallyFeed = new threshold_1.PublicTallyFeed();
|
|
115
|
+
const pollId = Buffer.from([0, 0, 0, 1]);
|
|
116
|
+
// Media subscriber (e.g., CNN)
|
|
117
|
+
const cnnSubscription = tallyFeed.subscribe(pollId, (tally) => {
|
|
118
|
+
console.log(` 📺 CNN BREAKING: Interval ${tally.intervalNumber} results:`);
|
|
119
|
+
tally.choices.forEach((choice, i) => {
|
|
120
|
+
const votes = tally.tallies[i];
|
|
121
|
+
const pct = tally.cumulativeVoteCount > 0
|
|
122
|
+
? ((Number(votes) / tally.cumulativeVoteCount) * 100).toFixed(1)
|
|
123
|
+
: '0.0';
|
|
124
|
+
console.log(` ${choice}: ${votes} votes (${pct}%)`);
|
|
125
|
+
});
|
|
126
|
+
console.log(` Total votes counted: ${tally.cumulativeVoteCount}`);
|
|
127
|
+
console.log(` Guardians participated: ${tally.participatingGuardians.length}/9`);
|
|
128
|
+
console.log(` Verified: ${tally.proof ? '✓' : '✗'}\n`);
|
|
129
|
+
});
|
|
130
|
+
// AP subscriber
|
|
131
|
+
const apSubscription = tallyFeed.subscribe(pollId, (tally) => {
|
|
132
|
+
console.log(` 📰 AP Wire: ${tally.isFinal ? 'FINAL' : `Update #${tally.intervalNumber}`} — ` +
|
|
133
|
+
`${tally.cumulativeVoteCount} votes tallied`);
|
|
134
|
+
});
|
|
135
|
+
console.log(' CNN subscription active');
|
|
136
|
+
console.log(' AP Wire subscription active\n');
|
|
137
|
+
// ─── Step 6: Simulate interval decryption ceremony ─────────────
|
|
138
|
+
console.log('Step 6: Simulating hourly decryption ceremony...');
|
|
139
|
+
console.log(' (In production, votes would be cast and encrypted first)\n');
|
|
140
|
+
// Create ceremony coordinator
|
|
141
|
+
const coordinator = new threshold_1.CeremonyCoordinator(keyPair.publicKey, keyPair.verificationKeys, keyPair.theta, thresholdConfig, intervalConfig.ceremonyTimeoutMs);
|
|
142
|
+
// Simulate encrypted tallies (3 candidates)
|
|
143
|
+
// In production these come from homomorphic aggregation of encrypted votes
|
|
144
|
+
const simulatedVotes = [42000n, 38000n, 20000n];
|
|
145
|
+
const encryptedTally = simulatedVotes.map((v) => keyPair.publicKey.encrypt(v));
|
|
146
|
+
console.log(' Starting ceremony for interval 1...');
|
|
147
|
+
const ceremony = coordinator.startCeremony(pollId, 1, encryptedTally);
|
|
148
|
+
console.log(` Ceremony ID: ${ceremony.id}`);
|
|
149
|
+
console.log(` Nonce: ${Buffer.from(ceremony.nonce).toString('hex').slice(0, 16)}...`);
|
|
150
|
+
// 5 of 9 Guardians submit partial decryptions
|
|
151
|
+
const partialService = new threshold_1.PartialDecryptionService(keyPair.publicKey);
|
|
152
|
+
const participatingIndices = [0, 1, 2, 3, 4]; // First 5 Guardians
|
|
153
|
+
console.log('\n Collecting partial decryptions:');
|
|
154
|
+
for (const idx of participatingIndices) {
|
|
155
|
+
const share = keyPair.keyShares[idx];
|
|
156
|
+
const partial = partialService.computePartial(encryptedTally, share, ceremony.nonce);
|
|
157
|
+
const accepted = coordinator.submitPartial(ceremony.id, partial);
|
|
158
|
+
console.log(` Guardian ${idx + 1} (${guardianNames[idx]}): ${accepted ? '✓ accepted' : '✗ rejected'}`);
|
|
159
|
+
}
|
|
160
|
+
console.log(`\n Ceremony status: ${ceremony.status}`);
|
|
161
|
+
// ─── Step 7: Combine and publish results ───────────────────────
|
|
162
|
+
if (ceremony.result) {
|
|
163
|
+
console.log('\nStep 7: Publishing interval tally...');
|
|
164
|
+
const intervalTally = {
|
|
165
|
+
pollId,
|
|
166
|
+
intervalNumber: 1,
|
|
167
|
+
tallies: ceremony.result.tallies,
|
|
168
|
+
choices: ['Alice Johnson', 'Bob Smith', 'Charlie Davis'],
|
|
169
|
+
voteCount: Number(simulatedVotes.reduce((a, b) => a + b, 0n)),
|
|
170
|
+
cumulativeVoteCount: Number(simulatedVotes.reduce((a, b) => a + b, 0n)),
|
|
171
|
+
proof: ceremony.result.combinedProof,
|
|
172
|
+
participatingGuardians: ceremony.result.participatingGuardians,
|
|
173
|
+
timestamp: Date.now(),
|
|
174
|
+
isFinal: false,
|
|
175
|
+
};
|
|
176
|
+
// Publishing triggers subscriber callbacks (CNN, AP)
|
|
177
|
+
tallyFeed.publish(intervalTally);
|
|
178
|
+
// ─── Step 8: Third-party verification ──────────────────────
|
|
179
|
+
console.log('Step 8: Third-party verification...');
|
|
180
|
+
const verifier = new threshold_1.TallyVerifier(keyPair.publicKey, keyPair.verificationKeys, thresholdConfig, keyPair.theta);
|
|
181
|
+
const registeredIndices = keyPair.keyShares.map((s) => s.index);
|
|
182
|
+
const verificationResult = verifier.verify(intervalTally, encryptedTally, keyPair.verificationKeys, keyPair.publicKey, registeredIndices);
|
|
183
|
+
console.log(` Proof valid: ${verificationResult.checks.proofValid ? '✓' : '✗'}`);
|
|
184
|
+
console.log(` Guardians authorized: ${verificationResult.checks.guardiansAuthorized ? '✓' : '✗'}`);
|
|
185
|
+
console.log(` Tally matches encrypted: ${verificationResult.checks.tallyMatchesEncrypted ? '✓' : '✗'}`);
|
|
186
|
+
console.log(` Timestamp valid: ${verificationResult.checks.timestampValid ? '✓' : '✗'}`);
|
|
187
|
+
console.log(` Overall: ${verificationResult.valid ? '✓ VERIFIED' : '✗ FAILED'}\n`);
|
|
188
|
+
}
|
|
189
|
+
// ─── Step 9: Query tally feed history ──────────────────────────
|
|
190
|
+
console.log('Step 9: Tally feed history...');
|
|
191
|
+
const history = tallyFeed.getHistory(pollId);
|
|
192
|
+
console.log(` Published intervals: ${history.length}`);
|
|
193
|
+
const current = tallyFeed.getCurrentTally(pollId);
|
|
194
|
+
if (current) {
|
|
195
|
+
console.log(` Latest interval: ${current.intervalNumber}`);
|
|
196
|
+
console.log(` Cumulative votes: ${current.cumulativeVoteCount}`);
|
|
197
|
+
}
|
|
198
|
+
// Cleanup subscriptions
|
|
199
|
+
cnnSubscription.unsubscribe();
|
|
200
|
+
apSubscription.unsubscribe();
|
|
201
|
+
console.log('\n=== Election simulation complete ===');
|
|
202
|
+
console.log('In production:');
|
|
203
|
+
console.log(' - 175,000 precincts aggregate votes homomorphically');
|
|
204
|
+
console.log(' - Hourly ceremonies decrypt aggregate tallies');
|
|
205
|
+
console.log(' - Media subscribers receive verified results in real-time');
|
|
206
|
+
console.log(' - Any third party can verify proofs independently');
|
|
207
|
+
console.log(' - Final ceremony at poll close produces certified results');
|
|
208
|
+
}
|
|
209
|
+
// Run example
|
|
210
|
+
if (require.main === module) {
|
|
211
|
+
runThresholdUSElection().catch(console.error);
|
|
212
|
+
}
|
|
213
|
+
//# sourceMappingURL=threshold-us-election-example.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"threshold-us-election-example.js","sourceRoot":"","sources":["../../../../../../packages/digita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