@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
|
@@ -3,255 +3,119 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PublicBulletinBoard = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Public Bulletin Board for Government-Grade Voting
|
|
6
|
-
* Node.js optimized with
|
|
6
|
+
* Node.js optimized - extends ecies-lib PublicBulletinBoard with Buffer support
|
|
7
7
|
* Implements requirement 1.2: Append-only, publicly verifiable vote publication
|
|
8
8
|
*/
|
|
9
|
-
const
|
|
10
|
-
const constants_1 = require("../../constants");
|
|
11
|
-
const Constants = (0, constants_1.getNodeRuntimeConfiguration)();
|
|
9
|
+
const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
|
|
12
10
|
/**
|
|
13
|
-
*
|
|
11
|
+
* Node.js PublicBulletinBoard that extends ecies-lib PublicBulletinBoard
|
|
12
|
+
* Uses Buffer for binary data instead of Uint8Array
|
|
13
|
+
*
|
|
14
|
+
* The base class handles all the logic, we just provide Node.js-specific defaults
|
|
15
|
+
* and ensure Buffer is used by default instead of Uint8Array.
|
|
14
16
|
*/
|
|
15
|
-
class PublicBulletinBoard {
|
|
16
|
-
entries = [];
|
|
17
|
-
tallyProofs = new Map();
|
|
18
|
-
authority;
|
|
19
|
-
sequence = 0;
|
|
17
|
+
class PublicBulletinBoard extends ecies_lib_1.PublicBulletinBoard {
|
|
20
18
|
constructor(authority) {
|
|
21
|
-
|
|
19
|
+
// Cast to the ecies-lib IMember type which has a different signature
|
|
20
|
+
// The node-ecies-lib IMember is compatible but has a different signature
|
|
21
|
+
super(authority);
|
|
22
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Override publishVote to ensure Buffer types are returned
|
|
25
|
+
*/
|
|
23
26
|
publishVote(pollId, encryptedVote, voterIdHash) {
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
pollId: Buffer.from(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const entryHash = this.sha256(entryData);
|
|
35
|
-
const signature = this.authority.sign(entryHash);
|
|
36
|
-
const entry = {
|
|
37
|
-
sequence: this.sequence++,
|
|
38
|
-
timestamp,
|
|
39
|
-
pollId,
|
|
40
|
-
encryptedVote,
|
|
41
|
-
voterIdHash,
|
|
42
|
-
merkleRoot,
|
|
43
|
-
entryHash,
|
|
44
|
-
signature,
|
|
27
|
+
// Convert Buffer arguments to Uint8Array for parent class
|
|
28
|
+
const entry = super.publishVote(new Uint8Array(pollId), encryptedVote, new Uint8Array(voterIdHash));
|
|
29
|
+
// Convert Uint8Array fields to Buffer
|
|
30
|
+
return {
|
|
31
|
+
...entry,
|
|
32
|
+
pollId: Buffer.from(entry.pollId),
|
|
33
|
+
voterIdHash: Buffer.from(entry.voterIdHash),
|
|
34
|
+
entryHash: Buffer.from(entry.entryHash),
|
|
35
|
+
signature: Buffer.from(entry.signature),
|
|
36
|
+
merkleRoot: Buffer.from(entry.merkleRoot),
|
|
45
37
|
};
|
|
46
|
-
this.entries.push(entry);
|
|
47
|
-
return entry;
|
|
48
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* Override publishTally to ensure Buffer types are returned
|
|
41
|
+
*/
|
|
49
42
|
publishTally(pollId, tallies, choices, encryptedVotes) {
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
decryptionProof,
|
|
60
|
-
});
|
|
61
|
-
const signature = this.authority.sign(proofData);
|
|
62
|
-
const proof = {
|
|
63
|
-
pollId,
|
|
64
|
-
tallies,
|
|
65
|
-
choices,
|
|
66
|
-
timestamp,
|
|
67
|
-
votesHash,
|
|
68
|
-
decryptionProof,
|
|
69
|
-
signature,
|
|
43
|
+
// Convert Buffer argument to Uint8Array for parent class
|
|
44
|
+
const proof = super.publishTally(new Uint8Array(pollId), tallies, choices, encryptedVotes);
|
|
45
|
+
// Convert Uint8Array fields to Buffer
|
|
46
|
+
return {
|
|
47
|
+
...proof,
|
|
48
|
+
pollId: Buffer.from(proof.pollId),
|
|
49
|
+
votesHash: Buffer.from(proof.votesHash),
|
|
50
|
+
decryptionProof: Buffer.from(proof.decryptionProof),
|
|
51
|
+
signature: Buffer.from(proof.signature),
|
|
70
52
|
};
|
|
71
|
-
this.tallyProofs.set(pollId.toString('hex'), proof);
|
|
72
|
-
return proof;
|
|
73
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Override getEntries to ensure Buffer types are returned and array is immutable
|
|
56
|
+
*/
|
|
74
57
|
getEntries(pollId) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
58
|
+
// Convert Buffer argument to Uint8Array for parent class
|
|
59
|
+
const entries = super.getEntries(new Uint8Array(pollId));
|
|
60
|
+
const bufferEntries = entries.map((entry) => ({
|
|
61
|
+
...entry,
|
|
62
|
+
pollId: Buffer.from(entry.pollId),
|
|
63
|
+
voterIdHash: Buffer.from(entry.voterIdHash),
|
|
64
|
+
entryHash: Buffer.from(entry.entryHash),
|
|
65
|
+
signature: Buffer.from(entry.signature),
|
|
66
|
+
merkleRoot: Buffer.from(entry.merkleRoot),
|
|
67
|
+
}));
|
|
68
|
+
return Object.freeze(bufferEntries);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Override getAllEntries to ensure Buffer types are returned and array is immutable
|
|
72
|
+
*/
|
|
78
73
|
getAllEntries() {
|
|
79
|
-
|
|
80
|
-
|
|
74
|
+
const entries = super.getAllEntries();
|
|
75
|
+
const bufferEntries = entries.map((entry) => ({
|
|
76
|
+
...entry,
|
|
77
|
+
pollId: Buffer.from(entry.pollId),
|
|
78
|
+
voterIdHash: Buffer.from(entry.voterIdHash),
|
|
79
|
+
entryHash: Buffer.from(entry.entryHash),
|
|
80
|
+
signature: Buffer.from(entry.signature),
|
|
81
|
+
merkleRoot: Buffer.from(entry.merkleRoot),
|
|
82
|
+
}));
|
|
83
|
+
return Object.freeze(bufferEntries);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Override getTallyProof to ensure Buffer types are returned
|
|
87
|
+
*/
|
|
81
88
|
getTallyProof(pollId) {
|
|
82
|
-
|
|
89
|
+
// Convert Buffer argument to Uint8Array for parent class
|
|
90
|
+
const proof = super.getTallyProof(new Uint8Array(pollId));
|
|
91
|
+
if (!proof)
|
|
92
|
+
return undefined;
|
|
93
|
+
return {
|
|
94
|
+
...proof,
|
|
95
|
+
pollId: Buffer.from(proof.pollId),
|
|
96
|
+
votesHash: Buffer.from(proof.votesHash),
|
|
97
|
+
decryptionProof: Buffer.from(proof.decryptionProof),
|
|
98
|
+
signature: Buffer.from(proof.signature),
|
|
99
|
+
};
|
|
83
100
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Override export method to return Buffer instead of Uint8Array
|
|
103
|
+
*/
|
|
104
|
+
export() {
|
|
105
|
+
const exported = super.export();
|
|
106
|
+
return Buffer.from(exported);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get all votes published to the bulletin board
|
|
110
|
+
* Returns the encrypted votes for verification
|
|
111
|
+
*/
|
|
112
|
+
getVotes() {
|
|
113
|
+
const entries = this.getAllEntries();
|
|
114
|
+
return entries.map((entry) => ({
|
|
88
115
|
pollId: entry.pollId,
|
|
89
116
|
encryptedVote: entry.encryptedVote,
|
|
90
|
-
voterIdHash: entry.voterIdHash,
|
|
91
|
-
|
|
92
|
-
});
|
|
93
|
-
const computedHash = this.sha256(entryData);
|
|
94
|
-
if (!computedHash.equals(entry.entryHash)) {
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
|
-
return this.authority.verify(entry.signature, entry.entryHash);
|
|
98
|
-
}
|
|
99
|
-
verifyTallyProof(proof) {
|
|
100
|
-
const pollIdBytes = Buffer.from(Constants.idProvider.toBytes(proof.pollId));
|
|
101
|
-
const proofData = this.serializeTallyProof({
|
|
102
|
-
pollId: pollIdBytes,
|
|
103
|
-
tallies: proof.tallies,
|
|
104
|
-
choices: proof.choices,
|
|
105
|
-
timestamp: proof.timestamp,
|
|
106
|
-
votesHash: proof.votesHash,
|
|
107
|
-
decryptionProof: proof.decryptionProof,
|
|
108
|
-
});
|
|
109
|
-
return this.authority.verify(proof.signature, proofData);
|
|
110
|
-
}
|
|
111
|
-
verifyMerkleTree() {
|
|
112
|
-
for (let i = 0; i < this.entries.length; i++) {
|
|
113
|
-
const entry = this.entries[i];
|
|
114
|
-
const expectedRoot = this.computeMerkleRoot(this.entries.slice(0, i));
|
|
115
|
-
if (!entry.merkleRoot.equals(expectedRoot)) {
|
|
116
|
-
return false;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return true;
|
|
120
|
-
}
|
|
121
|
-
export() {
|
|
122
|
-
const parts = [];
|
|
123
|
-
// Export entries
|
|
124
|
-
parts.push(this.encodeNumber(this.entries.length));
|
|
125
|
-
for (const entry of this.entries) {
|
|
126
|
-
parts.push(this.serializeEntry(entry));
|
|
127
|
-
}
|
|
128
|
-
// Export tally proofs
|
|
129
|
-
parts.push(this.encodeNumber(this.tallyProofs.size));
|
|
130
|
-
for (const proof of this.tallyProofs.values()) {
|
|
131
|
-
parts.push(this.serializeTallyProofFull(proof));
|
|
132
|
-
}
|
|
133
|
-
return Buffer.concat(parts);
|
|
134
|
-
}
|
|
135
|
-
computeMerkleRoot(entries) {
|
|
136
|
-
if (entries.length === 0) {
|
|
137
|
-
return Buffer.alloc(32);
|
|
138
|
-
}
|
|
139
|
-
let hashes = entries.map((e) => e.entryHash);
|
|
140
|
-
while (hashes.length > 1) {
|
|
141
|
-
const nextLevel = [];
|
|
142
|
-
for (let i = 0; i < hashes.length; i += 2) {
|
|
143
|
-
if (i + 1 < hashes.length) {
|
|
144
|
-
nextLevel.push(this.sha256(Buffer.concat([hashes[i], hashes[i + 1]])));
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
nextLevel.push(hashes[i]);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
hashes = nextLevel;
|
|
151
|
-
}
|
|
152
|
-
return hashes[0];
|
|
153
|
-
}
|
|
154
|
-
hashEncryptedVotes(votes) {
|
|
155
|
-
const parts = [];
|
|
156
|
-
for (const vote of votes) {
|
|
157
|
-
for (const value of vote) {
|
|
158
|
-
parts.push(this.encodeBigInt(value));
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
return this.sha256(Buffer.concat(parts));
|
|
162
|
-
}
|
|
163
|
-
generateDecryptionProof(encryptedVotes, tallies) {
|
|
164
|
-
// Simplified proof: hash of encrypted votes + tallies
|
|
165
|
-
// In production, use ZK-SNARK or similar
|
|
166
|
-
const parts = [];
|
|
167
|
-
for (const vote of encryptedVotes) {
|
|
168
|
-
for (const value of vote) {
|
|
169
|
-
parts.push(this.encodeBigInt(value));
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
for (const tally of tallies) {
|
|
173
|
-
parts.push(this.encodeBigInt(tally));
|
|
174
|
-
}
|
|
175
|
-
return this.sha256(Buffer.concat(parts));
|
|
176
|
-
}
|
|
177
|
-
serializeEntryData(data) {
|
|
178
|
-
const parts = [
|
|
179
|
-
this.encodeNumber(data.sequence),
|
|
180
|
-
this.encodeNumber(data.timestamp),
|
|
181
|
-
data.pollId,
|
|
182
|
-
data.voterIdHash,
|
|
183
|
-
data.merkleRoot,
|
|
184
|
-
];
|
|
185
|
-
for (const value of data.encryptedVote) {
|
|
186
|
-
parts.push(this.encodeBigInt(value));
|
|
187
|
-
}
|
|
188
|
-
return Buffer.concat(parts);
|
|
189
|
-
}
|
|
190
|
-
serializeTallyProof(data) {
|
|
191
|
-
const parts = [
|
|
192
|
-
data.pollId,
|
|
193
|
-
this.encodeNumber(data.timestamp),
|
|
194
|
-
data.votesHash,
|
|
195
|
-
data.decryptionProof,
|
|
196
|
-
];
|
|
197
|
-
for (const tally of data.tallies) {
|
|
198
|
-
parts.push(this.encodeBigInt(tally));
|
|
199
|
-
}
|
|
200
|
-
for (const choice of data.choices) {
|
|
201
|
-
parts.push(Buffer.from(choice, 'utf8'));
|
|
202
|
-
}
|
|
203
|
-
return Buffer.concat(parts);
|
|
204
|
-
}
|
|
205
|
-
serializeEntry(entry) {
|
|
206
|
-
const pollIdBytes = Buffer.from(Constants.idProvider.toBytes(entry.pollId));
|
|
207
|
-
const parts = [
|
|
208
|
-
this.encodeNumber(entry.sequence),
|
|
209
|
-
this.encodeNumber(entry.timestamp),
|
|
210
|
-
this.encodeNumber(pollIdBytes.length),
|
|
211
|
-
pollIdBytes,
|
|
212
|
-
this.encodeNumber(entry.encryptedVote.length),
|
|
213
|
-
];
|
|
214
|
-
for (const value of entry.encryptedVote) {
|
|
215
|
-
parts.push(this.encodeBigInt(value));
|
|
216
|
-
}
|
|
217
|
-
parts.push(this.encodeNumber(entry.voterIdHash.length), entry.voterIdHash, this.encodeNumber(entry.merkleRoot.length), entry.merkleRoot, this.encodeNumber(entry.entryHash.length), entry.entryHash, this.encodeNumber(entry.signature.length), entry.signature);
|
|
218
|
-
return Buffer.concat(parts);
|
|
219
|
-
}
|
|
220
|
-
serializeTallyProofFull(proof) {
|
|
221
|
-
const pollIdBytes = Buffer.from(Constants.idProvider.toBytes(proof.pollId));
|
|
222
|
-
const parts = [
|
|
223
|
-
this.encodeNumber(pollIdBytes.length),
|
|
224
|
-
pollIdBytes,
|
|
225
|
-
this.encodeNumber(proof.tallies.length),
|
|
226
|
-
];
|
|
227
|
-
for (const tally of proof.tallies) {
|
|
228
|
-
parts.push(this.encodeBigInt(tally));
|
|
229
|
-
}
|
|
230
|
-
parts.push(this.encodeNumber(proof.choices.length));
|
|
231
|
-
for (const choice of proof.choices) {
|
|
232
|
-
const encoded = Buffer.from(choice, 'utf8');
|
|
233
|
-
parts.push(this.encodeNumber(encoded.length), encoded);
|
|
234
|
-
}
|
|
235
|
-
parts.push(this.encodeNumber(proof.timestamp), this.encodeNumber(proof.votesHash.length), proof.votesHash, this.encodeNumber(proof.decryptionProof.length), proof.decryptionProof, this.encodeNumber(proof.signature.length), proof.signature);
|
|
236
|
-
return Buffer.concat(parts);
|
|
237
|
-
}
|
|
238
|
-
getMicrosecondTimestamp() {
|
|
239
|
-
// Get milliseconds since epoch and convert to microseconds
|
|
240
|
-
// performance.now() is relative to process start, not epoch, so we only use Date.now()
|
|
241
|
-
const now = Date.now();
|
|
242
|
-
return now * 1000;
|
|
243
|
-
}
|
|
244
|
-
sha256(data) {
|
|
245
|
-
return (0, crypto_1.createHash)('sha256').update(data).digest();
|
|
246
|
-
}
|
|
247
|
-
encodeNumber(n) {
|
|
248
|
-
const buffer = Buffer.alloc(8);
|
|
249
|
-
buffer.writeBigUInt64BE(BigInt(n));
|
|
250
|
-
return buffer;
|
|
251
|
-
}
|
|
252
|
-
encodeBigInt(n) {
|
|
253
|
-
const hex = n.toString(16).padStart(64, '0');
|
|
254
|
-
return Buffer.from(hex, 'hex');
|
|
117
|
+
voterIdHash: Buffer.from(entry.voterIdHash), // Convert Uint8Array to Buffer
|
|
118
|
+
}));
|
|
255
119
|
}
|
|
256
120
|
}
|
|
257
121
|
exports.PublicBulletinBoard = PublicBulletinBoard;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bulletin-board.js","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/voting/bulletin-board.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,
|
|
1
|
+
{"version":3,"file":"bulletin-board.js","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/voting/bulletin-board.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,0DA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|
-
* Node.js optimized
|
|
3
|
+
* Node.js optimized - extends ecies-lib VoteEncoder with Buffer support
|
|
4
4
|
*/
|
|
5
|
+
import { VoteEncoder as BaseVoteEncoder } from '@digitaldefiance/ecies-lib';
|
|
5
6
|
import type { PublicKey } from 'paillier-bigint';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Node.js VoteEncoder that extends ecies-lib VoteEncoder
|
|
9
|
+
* Specializes the generic TID parameter to Buffer for Node.js compatibility
|
|
10
|
+
*/
|
|
11
|
+
export declare class VoteEncoder extends BaseVoteEncoder<Buffer> {
|
|
10
12
|
constructor(votingPublicKey: PublicKey);
|
|
11
|
-
encodePlurality(choiceIndex: number, choiceCount: number): EncryptedVote<TID>;
|
|
12
|
-
encodeApproval(choices: number[], choiceCount: number): EncryptedVote<TID>;
|
|
13
|
-
encodeWeighted(choiceIndex: number, weight: bigint, choiceCount: number): EncryptedVote<TID>;
|
|
14
|
-
encodeBorda(rankings: number[], choiceCount: number): EncryptedVote<TID>;
|
|
15
|
-
encodeRankedChoice(rankings: number[], choiceCount: number): EncryptedVote<TID>;
|
|
16
|
-
encode(method: VotingMethod, data: {
|
|
17
|
-
choiceIndex?: number;
|
|
18
|
-
choices?: number[];
|
|
19
|
-
rankings?: number[];
|
|
20
|
-
weight?: bigint;
|
|
21
|
-
}, choiceCount: number): EncryptedVote<TID>;
|
|
22
13
|
}
|
|
23
14
|
//# sourceMappingURL=encoder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encoder.d.ts","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/voting/encoder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,
|
|
1
|
+
{"version":3,"file":"encoder.d.ts","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/voting/encoder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,WAAW,IAAI,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC5E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAEjD;;;GAGG;AACH,qBAAa,WAAY,SAAQ,eAAe,CAAC,MAAM,CAAC;gBAC1C,eAAe,EAAE,SAAS;CAOvC"}
|
|
@@ -1,114 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.VoteEncoder = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Vote Encoder - Encrypts votes using Paillier homomorphic encryption
|
|
6
|
+
* Node.js optimized - extends ecies-lib VoteEncoder with Buffer support
|
|
7
|
+
*/
|
|
8
|
+
const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
|
|
9
|
+
/**
|
|
10
|
+
* Node.js VoteEncoder that extends ecies-lib VoteEncoder
|
|
11
|
+
* Specializes the generic TID parameter to Buffer for Node.js compatibility
|
|
12
|
+
*/
|
|
13
|
+
class VoteEncoder extends ecies_lib_1.VoteEncoder {
|
|
7
14
|
constructor(votingPublicKey) {
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
encodePlurality(choiceIndex, choiceCount) {
|
|
11
|
-
const encrypted = [];
|
|
12
|
-
for (let i = 0; i < choiceCount; i++) {
|
|
13
|
-
encrypted.push(i === choiceIndex
|
|
14
|
-
? this.votingPublicKey.encrypt(1n)
|
|
15
|
-
: this.votingPublicKey.encrypt(0n));
|
|
16
|
-
}
|
|
17
|
-
return { choiceIndex, encrypted };
|
|
18
|
-
}
|
|
19
|
-
encodeApproval(choices, choiceCount) {
|
|
20
|
-
const choiceSet = new Set(choices);
|
|
21
|
-
const encrypted = [];
|
|
22
|
-
for (let i = 0; i < choiceCount; i++) {
|
|
23
|
-
encrypted.push(choiceSet.has(i)
|
|
24
|
-
? this.votingPublicKey.encrypt(1n)
|
|
25
|
-
: this.votingPublicKey.encrypt(0n));
|
|
26
|
-
}
|
|
27
|
-
return { choices, encrypted };
|
|
28
|
-
}
|
|
29
|
-
encodeWeighted(choiceIndex, weight, choiceCount) {
|
|
30
|
-
const encrypted = [];
|
|
31
|
-
for (let i = 0; i < choiceCount; i++) {
|
|
32
|
-
encrypted.push(i === choiceIndex
|
|
33
|
-
? this.votingPublicKey.encrypt(weight)
|
|
34
|
-
: this.votingPublicKey.encrypt(0n));
|
|
35
|
-
}
|
|
36
|
-
return { choiceIndex, weight, encrypted };
|
|
37
|
-
}
|
|
38
|
-
encodeBorda(rankings, choiceCount) {
|
|
39
|
-
const encrypted = new Array(choiceCount);
|
|
40
|
-
const points = BigInt(rankings.length);
|
|
41
|
-
for (let i = 0; i < choiceCount; i++) {
|
|
42
|
-
encrypted[i] = this.votingPublicKey.encrypt(0n);
|
|
43
|
-
}
|
|
44
|
-
for (let rank = 0; rank < rankings.length; rank++) {
|
|
45
|
-
const choiceIndex = rankings[rank];
|
|
46
|
-
const choicePoints = points - BigInt(rank);
|
|
47
|
-
encrypted[choiceIndex] = this.votingPublicKey.encrypt(choicePoints);
|
|
48
|
-
}
|
|
49
|
-
return { rankings, encrypted };
|
|
50
|
-
}
|
|
51
|
-
encodeRankedChoice(rankings, choiceCount) {
|
|
52
|
-
const encrypted = new Array(choiceCount);
|
|
53
|
-
for (let i = 0; i < choiceCount; i++) {
|
|
54
|
-
encrypted[i] = this.votingPublicKey.encrypt(0n);
|
|
55
|
-
}
|
|
56
|
-
for (let rank = 0; rank < rankings.length; rank++) {
|
|
57
|
-
const choiceIndex = rankings[rank];
|
|
58
|
-
encrypted[choiceIndex] = this.votingPublicKey.encrypt(BigInt(rank + 1));
|
|
59
|
-
}
|
|
60
|
-
return { rankings, encrypted };
|
|
61
|
-
}
|
|
62
|
-
encode(method, data, choiceCount) {
|
|
63
|
-
switch (method) {
|
|
64
|
-
case types_1.VotingMethod.Plurality:
|
|
65
|
-
if (data.choiceIndex === undefined)
|
|
66
|
-
throw new Error('Choice required');
|
|
67
|
-
return this.encodePlurality(data.choiceIndex, choiceCount);
|
|
68
|
-
case types_1.VotingMethod.Approval:
|
|
69
|
-
if (!data.choices)
|
|
70
|
-
throw new Error('Choices required');
|
|
71
|
-
return this.encodeApproval(data.choices, choiceCount);
|
|
72
|
-
case types_1.VotingMethod.Weighted:
|
|
73
|
-
if (data.choiceIndex === undefined || !data.weight) {
|
|
74
|
-
throw new Error('Choice and weight required');
|
|
75
|
-
}
|
|
76
|
-
return this.encodeWeighted(data.choiceIndex, data.weight, choiceCount);
|
|
77
|
-
case types_1.VotingMethod.Borda:
|
|
78
|
-
if (!data.rankings)
|
|
79
|
-
throw new Error('Rankings required');
|
|
80
|
-
return this.encodeBorda(data.rankings, choiceCount);
|
|
81
|
-
case types_1.VotingMethod.RankedChoice:
|
|
82
|
-
if (!data.rankings)
|
|
83
|
-
throw new Error('Rankings required');
|
|
84
|
-
return this.encodeRankedChoice(data.rankings, choiceCount);
|
|
85
|
-
case types_1.VotingMethod.Quadratic:
|
|
86
|
-
if (data.choiceIndex === undefined || !data.weight) {
|
|
87
|
-
throw new Error('Choice and weight required');
|
|
88
|
-
}
|
|
89
|
-
return this.encodeWeighted(data.choiceIndex, data.weight, choiceCount);
|
|
90
|
-
case types_1.VotingMethod.Consensus:
|
|
91
|
-
if (data.choiceIndex === undefined)
|
|
92
|
-
throw new Error('Choice required');
|
|
93
|
-
return this.encodePlurality(data.choiceIndex, choiceCount);
|
|
94
|
-
case types_1.VotingMethod.ConsentBased: {
|
|
95
|
-
if (data.choiceIndex === undefined)
|
|
96
|
-
throw new Error('Choice required');
|
|
97
|
-
const encrypted = [];
|
|
98
|
-
for (let i = 0; i < choiceCount; i++) {
|
|
99
|
-
encrypted.push(i === data.choiceIndex
|
|
100
|
-
? this.votingPublicKey.encrypt(data.weight || 1n)
|
|
101
|
-
: this.votingPublicKey.encrypt(0n));
|
|
102
|
-
}
|
|
103
|
-
return {
|
|
104
|
-
choiceIndex: data.choiceIndex,
|
|
105
|
-
weight: data.weight,
|
|
106
|
-
encrypted,
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
default:
|
|
110
|
-
throw new Error('Unknown voting method');
|
|
111
|
-
}
|
|
15
|
+
super(votingPublicKey);
|
|
112
16
|
}
|
|
113
17
|
}
|
|
114
18
|
exports.VoteEncoder = VoteEncoder;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encoder.js","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/voting/encoder.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"encoder.js","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/voting/encoder.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,0DAA4E;AAG5E;;;GAGG;AACH,MAAa,WAAY,SAAQ,uBAAuB;IACtD,YAAY,eAA0B;QACpC,KAAK,CAAC,eAAe,CAAC,CAAC;IACzB,CAAC;CAKF;AARD,kCAQC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-export all enumerations from ecies-lib
|
|
3
|
+
* This ensures enumeration parity between browser and Node.js implementations
|
|
4
|
+
*/
|
|
5
|
+
export { VotingMethod, SecurityLevel, EventType, AuditEventType, JurisdictionLevel, } from '@digitaldefiance/ecies-lib';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/voting/enumerations/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,YAAY,EACZ,aAAa,EACb,SAAS,EACT,cAAc,EACd,iBAAiB,GAClB,MAAM,4BAA4B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.JurisdictionLevel = exports.AuditEventType = exports.EventType = exports.SecurityLevel = exports.VotingMethod = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Re-export all enumerations from ecies-lib
|
|
6
|
+
* This ensures enumeration parity between browser and Node.js implementations
|
|
7
|
+
*/
|
|
8
|
+
var ecies_lib_1 = require("@digitaldefiance/ecies-lib");
|
|
9
|
+
Object.defineProperty(exports, "VotingMethod", { enumerable: true, get: function () { return ecies_lib_1.VotingMethod; } });
|
|
10
|
+
Object.defineProperty(exports, "SecurityLevel", { enumerable: true, get: function () { return ecies_lib_1.SecurityLevel; } });
|
|
11
|
+
Object.defineProperty(exports, "EventType", { enumerable: true, get: function () { return ecies_lib_1.EventType; } });
|
|
12
|
+
Object.defineProperty(exports, "AuditEventType", { enumerable: true, get: function () { return ecies_lib_1.AuditEventType; } });
|
|
13
|
+
Object.defineProperty(exports, "JurisdictionLevel", { enumerable: true, get: function () { return ecies_lib_1.JurisdictionLevel; } });
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/voting/enumerations/index.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,wDAMoC;AALlC,yGAAA,YAAY,OAAA;AACZ,0GAAA,aAAa,OAAA;AACb,sGAAA,SAAS,OAAA;AACT,2GAAA,cAAc,OAAA;AACd,8GAAA,iBAAiB,OAAA"}
|