@digitaldefiance/ecies-lib 4.17.1 → 4.17.3

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.
Files changed (170) hide show
  1. package/README.md +36 -1
  2. package/package.json +1 -1
  3. package/src/i18n-setup.d.ts +7 -1
  4. package/src/i18n-setup.d.ts.map +1 -1
  5. package/src/i18n-setup.js +12 -0
  6. package/src/i18n-setup.js.map +1 -1
  7. package/src/index.d.ts +1 -1
  8. package/src/index.d.ts.map +1 -1
  9. package/src/index.js +2 -1
  10. package/src/index.js.map +1 -1
  11. package/src/lib/voting/index.d.ts +1 -0
  12. package/src/lib/voting/index.d.ts.map +1 -1
  13. package/src/lib/voting/index.js +2 -0
  14. package/src/lib/voting/index.js.map +1 -1
  15. package/src/lib/voting/threshold/decryption-combiner.d.ts +141 -0
  16. package/src/lib/voting/threshold/decryption-combiner.d.ts.map +1 -0
  17. package/src/lib/voting/threshold/decryption-combiner.js +343 -0
  18. package/src/lib/voting/threshold/decryption-combiner.js.map +1 -0
  19. package/src/lib/voting/threshold/enumerations/ceremony-status.d.ts +19 -0
  20. package/src/lib/voting/threshold/enumerations/ceremony-status.d.ts.map +1 -0
  21. package/src/lib/voting/threshold/enumerations/ceremony-status.js +23 -0
  22. package/src/lib/voting/threshold/enumerations/ceremony-status.js.map +1 -0
  23. package/src/lib/voting/threshold/enumerations/guardian-status.d.ts +18 -0
  24. package/src/lib/voting/threshold/enumerations/guardian-status.d.ts.map +1 -0
  25. package/src/lib/voting/threshold/enumerations/guardian-status.js +22 -0
  26. package/src/lib/voting/threshold/enumerations/guardian-status.js.map +1 -0
  27. package/src/lib/voting/threshold/enumerations/index.d.ts +8 -0
  28. package/src/lib/voting/threshold/enumerations/index.d.ts.map +1 -0
  29. package/src/lib/voting/threshold/enumerations/index.js +11 -0
  30. package/src/lib/voting/threshold/enumerations/index.js.map +1 -0
  31. package/src/lib/voting/threshold/enumerations/interval-trigger-type.d.ts +15 -0
  32. package/src/lib/voting/threshold/enumerations/interval-trigger-type.d.ts.map +1 -0
  33. package/src/lib/voting/threshold/enumerations/interval-trigger-type.js +19 -0
  34. package/src/lib/voting/threshold/enumerations/interval-trigger-type.js.map +1 -0
  35. package/src/lib/voting/threshold/enumerations/threshold-audit-event-type.d.ts +29 -0
  36. package/src/lib/voting/threshold/enumerations/threshold-audit-event-type.d.ts.map +1 -0
  37. package/src/lib/voting/threshold/enumerations/threshold-audit-event-type.js +33 -0
  38. package/src/lib/voting/threshold/enumerations/threshold-audit-event-type.js.map +1 -0
  39. package/src/lib/voting/threshold/guardian-registry.d.ts +120 -0
  40. package/src/lib/voting/threshold/guardian-registry.d.ts.map +1 -0
  41. package/src/lib/voting/threshold/guardian-registry.js +227 -0
  42. package/src/lib/voting/threshold/guardian-registry.js.map +1 -0
  43. package/src/lib/voting/threshold/index.d.ts +49 -0
  44. package/src/lib/voting/threshold/index.d.ts.map +1 -0
  45. package/src/lib/voting/threshold/index.js +69 -0
  46. package/src/lib/voting/threshold/index.js.map +1 -0
  47. package/src/lib/voting/threshold/interfaces/ceremony-coordinator.d.ts +19 -0
  48. package/src/lib/voting/threshold/interfaces/ceremony-coordinator.d.ts.map +1 -0
  49. package/src/lib/voting/threshold/interfaces/ceremony-coordinator.js +3 -0
  50. package/src/lib/voting/threshold/interfaces/ceremony-coordinator.js.map +1 -0
  51. package/src/lib/voting/threshold/interfaces/ceremony.d.ts +33 -0
  52. package/src/lib/voting/threshold/interfaces/ceremony.d.ts.map +1 -0
  53. package/src/lib/voting/threshold/interfaces/ceremony.js +3 -0
  54. package/src/lib/voting/threshold/interfaces/ceremony.js.map +1 -0
  55. package/src/lib/voting/threshold/interfaces/combined-decryption.d.ts +20 -0
  56. package/src/lib/voting/threshold/interfaces/combined-decryption.d.ts.map +1 -0
  57. package/src/lib/voting/threshold/interfaces/combined-decryption.js +3 -0
  58. package/src/lib/voting/threshold/interfaces/combined-decryption.js.map +1 -0
  59. package/src/lib/voting/threshold/interfaces/combined-zk-proof.d.ts +16 -0
  60. package/src/lib/voting/threshold/interfaces/combined-zk-proof.d.ts.map +1 -0
  61. package/src/lib/voting/threshold/interfaces/combined-zk-proof.js +3 -0
  62. package/src/lib/voting/threshold/interfaces/combined-zk-proof.js.map +1 -0
  63. package/src/lib/voting/threshold/interfaces/decryption-combiner.d.ts +14 -0
  64. package/src/lib/voting/threshold/interfaces/decryption-combiner.d.ts.map +1 -0
  65. package/src/lib/voting/threshold/interfaces/decryption-combiner.js +3 -0
  66. package/src/lib/voting/threshold/interfaces/decryption-combiner.js.map +1 -0
  67. package/src/lib/voting/threshold/interfaces/guardian-registry.d.ts +28 -0
  68. package/src/lib/voting/threshold/interfaces/guardian-registry.d.ts.map +1 -0
  69. package/src/lib/voting/threshold/interfaces/guardian-registry.js +3 -0
  70. package/src/lib/voting/threshold/interfaces/guardian-registry.js.map +1 -0
  71. package/src/lib/voting/threshold/interfaces/guardian-status-change-event.d.ts +16 -0
  72. package/src/lib/voting/threshold/interfaces/guardian-status-change-event.d.ts.map +1 -0
  73. package/src/lib/voting/threshold/interfaces/guardian-status-change-event.js +3 -0
  74. package/src/lib/voting/threshold/interfaces/guardian-status-change-event.js.map +1 -0
  75. package/src/lib/voting/threshold/interfaces/guardian.d.ts +25 -0
  76. package/src/lib/voting/threshold/interfaces/guardian.d.ts.map +1 -0
  77. package/src/lib/voting/threshold/interfaces/guardian.js +3 -0
  78. package/src/lib/voting/threshold/interfaces/guardian.js.map +1 -0
  79. package/src/lib/voting/threshold/interfaces/index.d.ts +32 -0
  80. package/src/lib/voting/threshold/interfaces/index.d.ts.map +1 -0
  81. package/src/lib/voting/threshold/interfaces/index.js +6 -0
  82. package/src/lib/voting/threshold/interfaces/index.js.map +1 -0
  83. package/src/lib/voting/threshold/interfaces/interval-config.d.ts +17 -0
  84. package/src/lib/voting/threshold/interfaces/interval-config.d.ts.map +1 -0
  85. package/src/lib/voting/threshold/interfaces/interval-config.js +3 -0
  86. package/src/lib/voting/threshold/interfaces/interval-config.js.map +1 -0
  87. package/src/lib/voting/threshold/interfaces/interval-scheduler.d.ts +23 -0
  88. package/src/lib/voting/threshold/interfaces/interval-scheduler.d.ts.map +1 -0
  89. package/src/lib/voting/threshold/interfaces/interval-scheduler.js +3 -0
  90. package/src/lib/voting/threshold/interfaces/interval-scheduler.js.map +1 -0
  91. package/src/lib/voting/threshold/interfaces/interval-tally.d.ts +30 -0
  92. package/src/lib/voting/threshold/interfaces/interval-tally.d.ts.map +1 -0
  93. package/src/lib/voting/threshold/interfaces/interval-tally.js +3 -0
  94. package/src/lib/voting/threshold/interfaces/interval-tally.js.map +1 -0
  95. package/src/lib/voting/threshold/interfaces/interval-trigger-event.d.ts +20 -0
  96. package/src/lib/voting/threshold/interfaces/interval-trigger-event.d.ts.map +1 -0
  97. package/src/lib/voting/threshold/interfaces/interval-trigger-event.js +3 -0
  98. package/src/lib/voting/threshold/interfaces/interval-trigger-event.js.map +1 -0
  99. package/src/lib/voting/threshold/interfaces/key-share.d.ts +15 -0
  100. package/src/lib/voting/threshold/interfaces/key-share.d.ts.map +1 -0
  101. package/src/lib/voting/threshold/interfaces/key-share.js +3 -0
  102. package/src/lib/voting/threshold/interfaces/key-share.js.map +1 -0
  103. package/src/lib/voting/threshold/interfaces/partial-decryption-service.d.ts +17 -0
  104. package/src/lib/voting/threshold/interfaces/partial-decryption-service.d.ts.map +1 -0
  105. package/src/lib/voting/threshold/interfaces/partial-decryption-service.js +3 -0
  106. package/src/lib/voting/threshold/interfaces/partial-decryption-service.js.map +1 -0
  107. package/src/lib/voting/threshold/interfaces/partial-decryption.d.ts +20 -0
  108. package/src/lib/voting/threshold/interfaces/partial-decryption.d.ts.map +1 -0
  109. package/src/lib/voting/threshold/interfaces/partial-decryption.js +3 -0
  110. package/src/lib/voting/threshold/interfaces/partial-decryption.js.map +1 -0
  111. package/src/lib/voting/threshold/interfaces/public-tally-feed.d.ts +19 -0
  112. package/src/lib/voting/threshold/interfaces/public-tally-feed.d.ts.map +1 -0
  113. package/src/lib/voting/threshold/interfaces/public-tally-feed.js +3 -0
  114. package/src/lib/voting/threshold/interfaces/public-tally-feed.js.map +1 -0
  115. package/src/lib/voting/threshold/interfaces/tally-subscription.d.ts +16 -0
  116. package/src/lib/voting/threshold/interfaces/tally-subscription.d.ts.map +1 -0
  117. package/src/lib/voting/threshold/interfaces/tally-subscription.js +3 -0
  118. package/src/lib/voting/threshold/interfaces/tally-subscription.js.map +1 -0
  119. package/src/lib/voting/threshold/interfaces/tally-verifier.d.ts +12 -0
  120. package/src/lib/voting/threshold/interfaces/tally-verifier.d.ts.map +1 -0
  121. package/src/lib/voting/threshold/interfaces/tally-verifier.js +3 -0
  122. package/src/lib/voting/threshold/interfaces/tally-verifier.js.map +1 -0
  123. package/src/lib/voting/threshold/interfaces/threshold-aggregator.d.ts +15 -0
  124. package/src/lib/voting/threshold/interfaces/threshold-aggregator.d.ts.map +1 -0
  125. package/src/lib/voting/threshold/interfaces/threshold-aggregator.js +3 -0
  126. package/src/lib/voting/threshold/interfaces/threshold-aggregator.js.map +1 -0
  127. package/src/lib/voting/threshold/interfaces/threshold-audit-entry.d.ts +28 -0
  128. package/src/lib/voting/threshold/interfaces/threshold-audit-entry.d.ts.map +1 -0
  129. package/src/lib/voting/threshold/interfaces/threshold-audit-entry.js +3 -0
  130. package/src/lib/voting/threshold/interfaces/threshold-audit-entry.js.map +1 -0
  131. package/src/lib/voting/threshold/interfaces/threshold-key-config.d.ts +12 -0
  132. package/src/lib/voting/threshold/interfaces/threshold-key-config.d.ts.map +1 -0
  133. package/src/lib/voting/threshold/interfaces/threshold-key-config.js +3 -0
  134. package/src/lib/voting/threshold/interfaces/threshold-key-config.js.map +1 -0
  135. package/src/lib/voting/threshold/interfaces/threshold-key-generator.d.ts +12 -0
  136. package/src/lib/voting/threshold/interfaces/threshold-key-generator.d.ts.map +1 -0
  137. package/src/lib/voting/threshold/interfaces/threshold-key-generator.js +3 -0
  138. package/src/lib/voting/threshold/interfaces/threshold-key-generator.js.map +1 -0
  139. package/src/lib/voting/threshold/interfaces/threshold-key-pair.d.ts +30 -0
  140. package/src/lib/voting/threshold/interfaces/threshold-key-pair.d.ts.map +1 -0
  141. package/src/lib/voting/threshold/interfaces/threshold-key-pair.js +3 -0
  142. package/src/lib/voting/threshold/interfaces/threshold-key-pair.js.map +1 -0
  143. package/src/lib/voting/threshold/interfaces/threshold-poll-config.d.ts +19 -0
  144. package/src/lib/voting/threshold/interfaces/threshold-poll-config.d.ts.map +1 -0
  145. package/src/lib/voting/threshold/interfaces/threshold-poll-config.js +3 -0
  146. package/src/lib/voting/threshold/interfaces/threshold-poll-config.js.map +1 -0
  147. package/src/lib/voting/threshold/interfaces/threshold-poll-factory.d.ts +16 -0
  148. package/src/lib/voting/threshold/interfaces/threshold-poll-factory.d.ts.map +1 -0
  149. package/src/lib/voting/threshold/interfaces/threshold-poll-factory.js +3 -0
  150. package/src/lib/voting/threshold/interfaces/threshold-poll-factory.js.map +1 -0
  151. package/src/lib/voting/threshold/interfaces/threshold-poll.d.ts +25 -0
  152. package/src/lib/voting/threshold/interfaces/threshold-poll.d.ts.map +1 -0
  153. package/src/lib/voting/threshold/interfaces/threshold-poll.js +3 -0
  154. package/src/lib/voting/threshold/interfaces/threshold-poll.js.map +1 -0
  155. package/src/lib/voting/threshold/interfaces/verification-result.d.ts +17 -0
  156. package/src/lib/voting/threshold/interfaces/verification-result.d.ts.map +1 -0
  157. package/src/lib/voting/threshold/interfaces/verification-result.js +3 -0
  158. package/src/lib/voting/threshold/interfaces/verification-result.js.map +1 -0
  159. package/src/lib/voting/threshold/interfaces/zk-proof.d.ts +15 -0
  160. package/src/lib/voting/threshold/interfaces/zk-proof.d.ts.map +1 -0
  161. package/src/lib/voting/threshold/interfaces/zk-proof.js +3 -0
  162. package/src/lib/voting/threshold/interfaces/zk-proof.js.map +1 -0
  163. package/src/lib/voting/threshold/partial-decryption-service.d.ts +130 -0
  164. package/src/lib/voting/threshold/partial-decryption-service.d.ts.map +1 -0
  165. package/src/lib/voting/threshold/partial-decryption-service.js +288 -0
  166. package/src/lib/voting/threshold/partial-decryption-service.js.map +1 -0
  167. package/src/lib/voting/threshold/threshold-key-generator.d.ts +114 -0
  168. package/src/lib/voting/threshold/threshold-key-generator.d.ts.map +1 -0
  169. package/src/lib/voting/threshold/threshold-key-generator.js +275 -0
  170. package/src/lib/voting/threshold/threshold-key-generator.js.map +1 -0
@@ -0,0 +1,343 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DecryptionCombiner = exports.CombineFailedError = exports.InvalidPartialInCombineError = exports.InsufficientPartialsError = void 0;
4
+ const partial_decryption_service_1 = require("./partial-decryption-service");
5
+ /**
6
+ * Error thrown when there are insufficient partial decryptions.
7
+ */
8
+ class InsufficientPartialsError extends Error {
9
+ constructor(message) {
10
+ super(message);
11
+ this.name = 'InsufficientPartialsError';
12
+ }
13
+ }
14
+ exports.InsufficientPartialsError = InsufficientPartialsError;
15
+ /**
16
+ * Error thrown when a partial decryption's ZK proof is invalid during combining.
17
+ */
18
+ class InvalidPartialInCombineError extends Error {
19
+ constructor(message) {
20
+ super(message);
21
+ this.name = 'InvalidPartialInCombineError';
22
+ }
23
+ }
24
+ exports.InvalidPartialInCombineError = InvalidPartialInCombineError;
25
+ /**
26
+ * Error thrown when decryption combining fails.
27
+ */
28
+ class CombineFailedError extends Error {
29
+ constructor(message) {
30
+ super(message);
31
+ this.name = 'CombineFailedError';
32
+ }
33
+ }
34
+ exports.CombineFailedError = CombineFailedError;
35
+ /**
36
+ * Combines k partial decryptions into the final plaintext using
37
+ * Lagrange interpolation over the Paillier ciphertext space.
38
+ *
39
+ * @example
40
+ * ```typescript
41
+ * const combiner = new DecryptionCombiner(publicKey, verificationKeys);
42
+ *
43
+ * const result = combiner.combine(
44
+ * partials,
45
+ * encryptedTally,
46
+ * publicKey,
47
+ * { totalShares: 9, threshold: 5 }
48
+ * );
49
+ *
50
+ * console.log(result.tallies); // decrypted vote counts
51
+ * ```
52
+ */
53
+ class DecryptionCombiner {
54
+ verificationKeys;
55
+ partialService;
56
+ theta;
57
+ constructor(publicKey, verificationKeys, theta) {
58
+ this.verificationKeys = verificationKeys;
59
+ this.partialService = new partial_decryption_service_1.PartialDecryptionService(publicKey);
60
+ this.theta = theta;
61
+ }
62
+ /**
63
+ * Combine k partial decryptions into the final plaintext.
64
+ *
65
+ * @param partials - The partial decryptions from k Guardians
66
+ * @param encryptedTally - The encrypted tally ciphertexts
67
+ * @param publicKey - The Paillier public key
68
+ * @param config - The threshold configuration
69
+ * @returns The combined decryption with plaintext tallies and proof
70
+ * @throws InsufficientPartialsError if fewer than k partials provided
71
+ * @throws InvalidPartialInCombineError if any partial's ZK proof is invalid
72
+ * @throws CombineFailedError if the combining operation fails
73
+ */
74
+ combine(partials, encryptedTally, publicKey, config) {
75
+ const { threshold: k } = config;
76
+ // Enforce minimum k partials requirement
77
+ if (partials.length < k) {
78
+ throw new InsufficientPartialsError(`Need at least ${k} partial decryptions, got ${partials.length}`);
79
+ }
80
+ if (encryptedTally.length === 0) {
81
+ throw new CombineFailedError('Encrypted tally must not be empty');
82
+ }
83
+ // Verify each partial's ZK proof before combining
84
+ for (const partial of partials) {
85
+ const vkIndex = partial.guardianIndex - 1; // 1-indexed to 0-indexed
86
+ if (vkIndex < 0 || vkIndex >= this.verificationKeys.length) {
87
+ throw new InvalidPartialInCombineError(`Guardian index ${partial.guardianIndex} is out of range [1, ${this.verificationKeys.length}]`);
88
+ }
89
+ const isValid = this.partialService.verifyPartial(partial, encryptedTally, this.verificationKeys[vkIndex], publicKey);
90
+ if (!isValid) {
91
+ throw new InvalidPartialInCombineError(`ZK proof verification failed for Guardian ${partial.guardianIndex}`);
92
+ }
93
+ }
94
+ // Use only the first k partials (in case more than k were provided)
95
+ const usedPartials = partials.slice(0, k);
96
+ const participatingGuardians = usedPartials.map((p) => p.guardianIndex);
97
+ try {
98
+ const n = publicKey.n;
99
+ const n2 = n * n;
100
+ // Compute the tallies by combining partial decryptions for each ciphertext
101
+ const tallies = encryptedTally.map((ciphertext) => this.combineSingleCiphertext(ciphertext, usedPartials, n, n2, config));
102
+ // Build the combined ZK proof
103
+ const combinedProof = this.buildCombinedProof(usedPartials, encryptedTally, n2);
104
+ return {
105
+ tallies,
106
+ combinedProof,
107
+ participatingGuardians,
108
+ ceremonyId: this.generateCeremonyId(usedPartials),
109
+ timestamp: Date.now(),
110
+ };
111
+ }
112
+ catch (error) {
113
+ if (error instanceof InsufficientPartialsError ||
114
+ error instanceof InvalidPartialInCombineError) {
115
+ throw error;
116
+ }
117
+ throw new CombineFailedError(`Failed to combine partial decryptions: ${error instanceof Error ? error.message : String(error)}`);
118
+ }
119
+ }
120
+ /**
121
+ * Verify a combined decryption result.
122
+ *
123
+ * Checks that:
124
+ * 1. All individual partial proofs are valid
125
+ * 2. The participating Guardians are authorized (have valid verification keys)
126
+ * 3. The aggregated commitment is consistent
127
+ */
128
+ verifyCombined(combined, encryptedTally, verificationKeys, publicKey) {
129
+ if (encryptedTally.length === 0 || combined.tallies.length === 0) {
130
+ return false;
131
+ }
132
+ // Verify each participating Guardian's index is valid
133
+ for (const guardianIndex of combined.participatingGuardians) {
134
+ const vkIndex = guardianIndex - 1;
135
+ if (vkIndex < 0 || vkIndex >= verificationKeys.length) {
136
+ return false;
137
+ }
138
+ }
139
+ // Verify the input hash matches
140
+ const n2 = publicKey.n * publicKey.n;
141
+ const expectedInputHash = this.computeInputHash(encryptedTally, n2);
142
+ if (!this.uint8ArrayEquals(combined.combinedProof.inputHash, expectedInputHash)) {
143
+ return false;
144
+ }
145
+ // Verify the aggregated commitment is non-zero
146
+ if (combined.combinedProof.aggregatedCommitment === 0n) {
147
+ return false;
148
+ }
149
+ // Verify we have the right number of partial proofs
150
+ if (combined.combinedProof.partialProofs.length !==
151
+ combined.participatingGuardians.length) {
152
+ return false;
153
+ }
154
+ return true;
155
+ }
156
+ /**
157
+ * Combine partial decryptions for a single ciphertext.
158
+ *
159
+ * Each partial_i = c^(2·s_i) mod n² (computed by PartialDecryptionService).
160
+ *
161
+ * Using integer Lagrange coefficients λ_i' = Δ · Π_{j≠i} j/(j-i):
162
+ * combined = Π partial_i^(2·λ_i') mod n²
163
+ * = c^(4·Δ·λ) mod n²
164
+ *
165
+ * where λ is the original Paillier secret key.
166
+ *
167
+ * By the Paillier L-function property: L(c^(4·Δ·λ)) = 4·Δ·λ·m mod n
168
+ * So: plaintext = L(combined) · (4·Δ)^(-1) mod n
169
+ */
170
+ combineSingleCiphertext(_ciphertext, partials, n, n2, config) {
171
+ const indices = partials.map((p) => p.guardianIndex);
172
+ const delta = this.factorial(BigInt(config.totalShares));
173
+ // Compute combined value using Lagrange interpolation in the exponent:
174
+ // combined = Π partial_i^(2·λ_i') mod n²
175
+ // where λ_i' = Δ · Π_{j≠i} j/(j-i) are integer Lagrange coefficients
176
+ let combined = 1n;
177
+ for (const partial of partials) {
178
+ const partialValue = partial.value;
179
+ const lambda = this.lagrangeCoefficientInteger(partial.guardianIndex, indices, delta);
180
+ // combined *= partial_i^(2·lambda) mod n²
181
+ // The exponent can be negative, so we handle that with modular inverse
182
+ if (lambda >= 0n) {
183
+ combined = this.mod(combined * this.modPow(partialValue, 2n * lambda, n2), n2);
184
+ }
185
+ else {
186
+ const posExp = -lambda;
187
+ const partialPow = this.modPow(partialValue, 2n * posExp, n2);
188
+ const partialInv = this.modInverse(partialPow, n2);
189
+ combined = this.mod(combined * partialInv, n2);
190
+ }
191
+ }
192
+ // Apply L-function: L(x) = (x - 1) / n
193
+ const lValue = (combined - 1n) / n;
194
+ // Divide by θ to get the plaintext.
195
+ // θ = L(g^(4·Δ·λ) mod n²) mod n was precomputed during key generation.
196
+ // m = L(combined) · θ⁻¹ mod n
197
+ const thetaInv = this.modInverse(this.mod(this.theta, n), n);
198
+ const plaintext = this.mod(lValue * thetaInv, n);
199
+ return plaintext;
200
+ }
201
+ /**
202
+ * Compute integer Lagrange coefficient scaled by delta.
203
+ *
204
+ * λ_i = Δ · Π_{j≠i} (j / (j - i))
205
+ *
206
+ * Since we scale by Δ = n!, the result is always an integer.
207
+ */
208
+ lagrangeCoefficientInteger(i, indices, delta) {
209
+ let numerator = delta;
210
+ let denominator = 1n;
211
+ for (const j of indices) {
212
+ if (j !== i) {
213
+ numerator = numerator * BigInt(j);
214
+ denominator = denominator * BigInt(j - i);
215
+ }
216
+ }
217
+ // Since delta = n!, the division is exact (integer result)
218
+ return numerator / denominator;
219
+ }
220
+ /**
221
+ * Build the combined ZK proof from individual partial proofs.
222
+ */
223
+ buildCombinedProof(partials, encryptedTally, n2) {
224
+ const partialProofs = partials.map((p) => p.proof);
225
+ // Aggregate commitments by multiplying them together mod n²
226
+ let aggregatedCommitment = 1n;
227
+ for (const proof of partialProofs) {
228
+ aggregatedCommitment = this.mod(aggregatedCommitment * proof.commitment, n2);
229
+ }
230
+ const inputHash = this.computeInputHash(encryptedTally, n2);
231
+ return {
232
+ partialProofs,
233
+ aggregatedCommitment,
234
+ inputHash,
235
+ };
236
+ }
237
+ /**
238
+ * Compute a hash of the encrypted tally inputs.
239
+ */
240
+ computeInputHash(encryptedTally, n2) {
241
+ let hash = 0n;
242
+ for (const ct of encryptedTally) {
243
+ const bytes = this.bigintToUint8Array(ct);
244
+ for (const byte of bytes) {
245
+ hash = (hash * 256n + BigInt(byte)) % n2;
246
+ }
247
+ }
248
+ return this.bigintToUint8Array(hash);
249
+ }
250
+ /**
251
+ * Generate a ceremony ID from the partials' nonces.
252
+ */
253
+ generateCeremonyId(partials) {
254
+ if (partials.length === 0)
255
+ return 'empty';
256
+ // Use the first partial's nonce as the ceremony identifier
257
+ const nonce = partials[0].ceremonyNonce;
258
+ return Array.from(nonce)
259
+ .map((b) => b.toString(16).padStart(2, '0'))
260
+ .join('');
261
+ }
262
+ /**
263
+ * Compute n! (factorial).
264
+ */
265
+ factorial(n) {
266
+ let result = 1n;
267
+ for (let i = 2n; i <= n; i++) {
268
+ result *= i;
269
+ }
270
+ return result;
271
+ }
272
+ /**
273
+ * Compute a mod m, handling negative numbers correctly.
274
+ */
275
+ mod(a, m) {
276
+ const result = a % m;
277
+ return result >= 0n ? result : result + m;
278
+ }
279
+ /**
280
+ * Compute base^exp mod m using square-and-multiply.
281
+ */
282
+ modPow(base, exp, m) {
283
+ if (m === 1n)
284
+ return 0n;
285
+ let result = 1n;
286
+ base = this.mod(base, m);
287
+ while (exp > 0n) {
288
+ if (exp % 2n === 1n) {
289
+ result = this.mod(result * base, m);
290
+ }
291
+ exp = exp >> 1n;
292
+ base = this.mod(base * base, m);
293
+ }
294
+ return result;
295
+ }
296
+ /**
297
+ * Compute modular inverse using extended Euclidean algorithm.
298
+ */
299
+ modInverse(a, m) {
300
+ const originalM = m;
301
+ a = this.mod(a, m);
302
+ let [old_r, r] = [a, m];
303
+ let [old_s, s] = [1n, 0n];
304
+ while (r !== 0n) {
305
+ const quotient = old_r / r;
306
+ [old_r, r] = [r, old_r - quotient * r];
307
+ [old_s, s] = [s, old_s - quotient * s];
308
+ }
309
+ if (old_r !== 1n) {
310
+ throw new CombineFailedError(`Modular inverse does not exist for ${a} mod ${m}`);
311
+ }
312
+ return ((old_s % originalM) + originalM) % originalM;
313
+ }
314
+ /**
315
+ * Convert a bigint to Uint8Array.
316
+ */
317
+ bigintToUint8Array(value) {
318
+ if (value === 0n) {
319
+ return new Uint8Array([0]);
320
+ }
321
+ const hex = value.toString(16);
322
+ const paddedHex = hex.length % 2 === 0 ? hex : '0' + hex;
323
+ const bytes = new Uint8Array(paddedHex.length / 2);
324
+ for (let i = 0; i < bytes.length; i++) {
325
+ bytes[i] = parseInt(paddedHex.slice(i * 2, i * 2 + 2), 16);
326
+ }
327
+ return bytes;
328
+ }
329
+ /**
330
+ * Compare two Uint8Arrays for equality.
331
+ */
332
+ uint8ArrayEquals(a, b) {
333
+ if (a.length !== b.length)
334
+ return false;
335
+ for (let i = 0; i < a.length; i++) {
336
+ if (a[i] !== b[i])
337
+ return false;
338
+ }
339
+ return true;
340
+ }
341
+ }
342
+ exports.DecryptionCombiner = DecryptionCombiner;
343
+ //# sourceMappingURL=decryption-combiner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decryption-combiner.js","sourceRoot":"","sources":["../../../../../../../packages/digitaldefiance-ecies-lib/src/lib/voting/threshold/decryption-combiner.ts"],"names":[],"mappings":";;;AAuBA,6EAAwE;AAExE;;GAEG;AACH,MAAa,yBAA0B,SAAQ,KAAK;IAClD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IAC1C,CAAC;CACF;AALD,8DAKC;AAED;;GAEG;AACH,MAAa,4BAA6B,SAAQ,KAAK;IACrD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,8BAA8B,CAAC;IAC7C,CAAC;CACF;AALD,oEAKC;AAED;;GAEG;AACH,MAAa,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AALD,gDAKC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAa,kBAAkB;IACZ,gBAAgB,CAAwB;IACxC,cAAc,CAA2B;IACzC,KAAK,CAAS;IAE/B,YACE,SAAoB,EACpB,gBAAuC,EACvC,KAAa;QAEb,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,cAAc,GAAG,IAAI,qDAAwB,CAAC,SAAS,CAAC,CAAC;QAC9D,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;;;;;;;;;OAWG;IACH,OAAO,CACL,QAAsC,EACtC,cAAwB,EACxB,SAAoB,EACpB,MAA0B;QAE1B,MAAM,EAAE,SAAS,EAAE,CAAC,EAAE,GAAG,MAAM,CAAC;QAEhC,yCAAyC;QACzC,IAAI,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C,QAAQ,CAAC,EAAE,CAAC,CAAC;QAC/B,MAAM,SAAS,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC;QACzD,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QACnD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,KAAK,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC7D,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;OAEG;IACK,gBAAgB,CAAC,CAAa,EAAE,CAAa;QACnD,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM;YAAE,OAAO,KAAK,CAAC;QACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAClC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;gBAAE,OAAO,KAAK,CAAC;QAClC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA3YD,gDA2YC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Status of a threshold decryption ceremony.
3
+ *
4
+ * A ceremony is the coordinated process where k-of-n Guardians submit
5
+ * their partial decryptions to reveal an aggregate tally.
6
+ */
7
+ export declare enum CeremonyStatus {
8
+ /** Ceremony created but not yet started */
9
+ Pending = "pending",
10
+ /** Ceremony is actively collecting partial decryptions */
11
+ InProgress = "in-progress",
12
+ /** Ceremony completed successfully with k valid partials */
13
+ Completed = "completed",
14
+ /** Ceremony failed due to invalid partials or other errors */
15
+ Failed = "failed",
16
+ /** Ceremony timed out before receiving k valid partials */
17
+ TimedOut = "timed-out"
18
+ }
19
+ //# sourceMappingURL=ceremony-status.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ceremony-status.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/digitaldefiance-ecies-lib/src/lib/voting/threshold/enumerations/ceremony-status.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,oBAAY,cAAc;IACxB,2CAA2C;IAC3C,OAAO,YAAY;IACnB,0DAA0D;IAC1D,UAAU,gBAAgB;IAC1B,4DAA4D;IAC5D,SAAS,cAAc;IACvB,8DAA8D;IAC9D,MAAM,WAAW;IACjB,2DAA2D;IAC3D,QAAQ,cAAc;CACvB"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CeremonyStatus = void 0;
4
+ /**
5
+ * Status of a threshold decryption ceremony.
6
+ *
7
+ * A ceremony is the coordinated process where k-of-n Guardians submit
8
+ * their partial decryptions to reveal an aggregate tally.
9
+ */
10
+ var CeremonyStatus;
11
+ (function (CeremonyStatus) {
12
+ /** Ceremony created but not yet started */
13
+ CeremonyStatus["Pending"] = "pending";
14
+ /** Ceremony is actively collecting partial decryptions */
15
+ CeremonyStatus["InProgress"] = "in-progress";
16
+ /** Ceremony completed successfully with k valid partials */
17
+ CeremonyStatus["Completed"] = "completed";
18
+ /** Ceremony failed due to invalid partials or other errors */
19
+ CeremonyStatus["Failed"] = "failed";
20
+ /** Ceremony timed out before receiving k valid partials */
21
+ CeremonyStatus["TimedOut"] = "timed-out";
22
+ })(CeremonyStatus || (exports.CeremonyStatus = CeremonyStatus = {}));
23
+ //# sourceMappingURL=ceremony-status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ceremony-status.js","sourceRoot":"","sources":["../../../../../../../../packages/digitaldefiance-ecies-lib/src/lib/voting/threshold/enumerations/ceremony-status.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,IAAY,cAWX;AAXD,WAAY,cAAc;IACxB,2CAA2C;IAC3C,qCAAmB,CAAA;IACnB,0DAA0D;IAC1D,4CAA0B,CAAA;IAC1B,4DAA4D;IAC5D,yCAAuB,CAAA;IACvB,8DAA8D;IAC9D,mCAAiB,CAAA;IACjB,2DAA2D;IAC3D,wCAAsB,CAAA;AACxB,CAAC,EAXW,cAAc,8BAAd,cAAc,QAWzB"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Guardian availability status for threshold voting.
3
+ *
4
+ * Guardians are trusted key holders who possess shares of the threshold
5
+ * decryption key. Their status is tracked to ensure sufficient Guardians
6
+ * are available for decryption ceremonies.
7
+ */
8
+ export declare enum GuardianStatus {
9
+ /** Guardian is registered but not yet confirmed online */
10
+ Registered = "registered",
11
+ /** Guardian is online and available for ceremonies */
12
+ Online = "online",
13
+ /** Guardian is temporarily offline */
14
+ Offline = "offline",
15
+ /** Guardian is permanently unavailable (requires backup activation) */
16
+ Unavailable = "unavailable"
17
+ }
18
+ //# sourceMappingURL=guardian-status.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardian-status.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/digitaldefiance-ecies-lib/src/lib/voting/threshold/enumerations/guardian-status.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,oBAAY,cAAc;IACxB,0DAA0D;IAC1D,UAAU,eAAe;IACzB,sDAAsD;IACtD,MAAM,WAAW;IACjB,sCAAsC;IACtC,OAAO,YAAY;IACnB,uEAAuE;IACvE,WAAW,gBAAgB;CAC5B"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuardianStatus = void 0;
4
+ /**
5
+ * Guardian availability status for threshold voting.
6
+ *
7
+ * Guardians are trusted key holders who possess shares of the threshold
8
+ * decryption key. Their status is tracked to ensure sufficient Guardians
9
+ * are available for decryption ceremonies.
10
+ */
11
+ var GuardianStatus;
12
+ (function (GuardianStatus) {
13
+ /** Guardian is registered but not yet confirmed online */
14
+ GuardianStatus["Registered"] = "registered";
15
+ /** Guardian is online and available for ceremonies */
16
+ GuardianStatus["Online"] = "online";
17
+ /** Guardian is temporarily offline */
18
+ GuardianStatus["Offline"] = "offline";
19
+ /** Guardian is permanently unavailable (requires backup activation) */
20
+ GuardianStatus["Unavailable"] = "unavailable";
21
+ })(GuardianStatus || (exports.GuardianStatus = GuardianStatus = {}));
22
+ //# sourceMappingURL=guardian-status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardian-status.js","sourceRoot":"","sources":["../../../../../../../../packages/digitaldefiance-ecies-lib/src/lib/voting/threshold/enumerations/guardian-status.ts"],"names":[],"mappings":";;;AAAA;;;;;;GAMG;AACH,IAAY,cASX;AATD,WAAY,cAAc;IACxB,0DAA0D;IAC1D,2CAAyB,CAAA;IACzB,sDAAsD;IACtD,mCAAiB,CAAA;IACjB,sCAAsC;IACtC,qCAAmB,CAAA;IACnB,uEAAuE;IACvE,6CAA2B,CAAA;AAC7B,CAAC,EATW,cAAc,8BAAd,cAAc,QASzB"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Threshold voting enumerations export module.
3
+ */
4
+ export * from './ceremony-status';
5
+ export * from './guardian-status';
6
+ export * from './interval-trigger-type';
7
+ export * from './threshold-audit-event-type';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/digitaldefiance-ecies-lib/src/lib/voting/threshold/enumerations/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,yBAAyB,CAAC;AACxC,cAAc,8BAA8B,CAAC"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ /**
5
+ * Threshold voting enumerations export module.
6
+ */
7
+ tslib_1.__exportStar(require("./ceremony-status"), exports);
8
+ tslib_1.__exportStar(require("./guardian-status"), exports);
9
+ tslib_1.__exportStar(require("./interval-trigger-type"), exports);
10
+ tslib_1.__exportStar(require("./threshold-audit-event-type"), exports);
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../../packages/digitaldefiance-ecies-lib/src/lib/voting/threshold/enumerations/index.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,4DAAkC;AAClC,4DAAkC;AAClC,kEAAwC;AACxC,uEAA6C"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Types of interval triggers for threshold decryption scheduling.
3
+ *
4
+ * Interval decryption allows real-time vote tallies during voting
5
+ * without compromising individual vote privacy.
6
+ */
7
+ export declare enum IntervalTriggerType {
8
+ /** Trigger decryption at fixed time intervals (e.g., hourly) */
9
+ TimeBased = "time-based",
10
+ /** Trigger decryption after a certain number of votes */
11
+ VoteCountBased = "vote-count-based",
12
+ /** Trigger on either time or vote count, whichever comes first */
13
+ Hybrid = "hybrid"
14
+ }
15
+ //# sourceMappingURL=interval-trigger-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interval-trigger-type.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/digitaldefiance-ecies-lib/src/lib/voting/threshold/enumerations/interval-trigger-type.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,oBAAY,mBAAmB;IAC7B,gEAAgE;IAChE,SAAS,eAAe;IACxB,yDAAyD;IACzD,cAAc,qBAAqB;IACnC,kEAAkE;IAClE,MAAM,WAAW;CAClB"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IntervalTriggerType = void 0;
4
+ /**
5
+ * Types of interval triggers for threshold decryption scheduling.
6
+ *
7
+ * Interval decryption allows real-time vote tallies during voting
8
+ * without compromising individual vote privacy.
9
+ */
10
+ var IntervalTriggerType;
11
+ (function (IntervalTriggerType) {
12
+ /** Trigger decryption at fixed time intervals (e.g., hourly) */
13
+ IntervalTriggerType["TimeBased"] = "time-based";
14
+ /** Trigger decryption after a certain number of votes */
15
+ IntervalTriggerType["VoteCountBased"] = "vote-count-based";
16
+ /** Trigger on either time or vote count, whichever comes first */
17
+ IntervalTriggerType["Hybrid"] = "hybrid";
18
+ })(IntervalTriggerType || (exports.IntervalTriggerType = IntervalTriggerType = {}));
19
+ //# sourceMappingURL=interval-trigger-type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interval-trigger-type.js","sourceRoot":"","sources":["../../../../../../../../packages/digitaldefiance-ecies-lib/src/lib/voting/threshold/enumerations/interval-trigger-type.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,IAAY,mBAOX;AAPD,WAAY,mBAAmB;IAC7B,gEAAgE;IAChE,+CAAwB,CAAA;IACxB,yDAAyD;IACzD,0DAAmC,CAAA;IACnC,kEAAkE;IAClE,wCAAiB,CAAA;AACnB,CAAC,EAPW,mBAAmB,mCAAnB,mBAAmB,QAO9B"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Audit event types specific to threshold voting operations.
3
+ *
4
+ * These events extend the base audit system to track all threshold-related
5
+ * operations for complete auditability.
6
+ */
7
+ export declare enum ThresholdAuditEventType {
8
+ /** Threshold keys were generated */
9
+ KeyGeneration = "threshold-key-generation",
10
+ /** A key share was distributed to a Guardian */
11
+ KeyShareDistribution = "threshold-key-share-distribution",
12
+ /** A Guardian was registered in the system */
13
+ GuardianRegistration = "guardian-registration",
14
+ /** A Guardian's status changed */
15
+ GuardianStatusChange = "guardian-status-change",
16
+ /** A decryption ceremony was started */
17
+ CeremonyStarted = "ceremony-started",
18
+ /** A partial decryption was submitted */
19
+ PartialSubmitted = "partial-submitted",
20
+ /** A decryption ceremony completed successfully */
21
+ CeremonyCompleted = "ceremony-completed",
22
+ /** A decryption ceremony failed */
23
+ CeremonyFailed = "ceremony-failed",
24
+ /** A tally was published to the public feed */
25
+ TallyPublished = "tally-published",
26
+ /** A key share was rotated */
27
+ KeyShareRotation = "key-share-rotation"
28
+ }
29
+ //# sourceMappingURL=threshold-audit-event-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"threshold-audit-event-type.d.ts","sourceRoot":"","sources":["../../../../../../../../packages/digitaldefiance-ecies-lib/src/lib/voting/threshold/enumerations/threshold-audit-event-type.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,oBAAY,uBAAuB;IACjC,oCAAoC;IACpC,aAAa,6BAA6B;IAC1C,gDAAgD;IAChD,oBAAoB,qCAAqC;IACzD,8CAA8C;IAC9C,oBAAoB,0BAA0B;IAC9C,kCAAkC;IAClC,oBAAoB,2BAA2B;IAC/C,wCAAwC;IACxC,eAAe,qBAAqB;IACpC,yCAAyC;IACzC,gBAAgB,sBAAsB;IACtC,mDAAmD;IACnD,iBAAiB,uBAAuB;IACxC,mCAAmC;IACnC,cAAc,oBAAoB;IAClC,+CAA+C;IAC/C,cAAc,oBAAoB;IAClC,8BAA8B;IAC9B,gBAAgB,uBAAuB;CACxC"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ThresholdAuditEventType = void 0;
4
+ /**
5
+ * Audit event types specific to threshold voting operations.
6
+ *
7
+ * These events extend the base audit system to track all threshold-related
8
+ * operations for complete auditability.
9
+ */
10
+ var ThresholdAuditEventType;
11
+ (function (ThresholdAuditEventType) {
12
+ /** Threshold keys were generated */
13
+ ThresholdAuditEventType["KeyGeneration"] = "threshold-key-generation";
14
+ /** A key share was distributed to a Guardian */
15
+ ThresholdAuditEventType["KeyShareDistribution"] = "threshold-key-share-distribution";
16
+ /** A Guardian was registered in the system */
17
+ ThresholdAuditEventType["GuardianRegistration"] = "guardian-registration";
18
+ /** A Guardian's status changed */
19
+ ThresholdAuditEventType["GuardianStatusChange"] = "guardian-status-change";
20
+ /** A decryption ceremony was started */
21
+ ThresholdAuditEventType["CeremonyStarted"] = "ceremony-started";
22
+ /** A partial decryption was submitted */
23
+ ThresholdAuditEventType["PartialSubmitted"] = "partial-submitted";
24
+ /** A decryption ceremony completed successfully */
25
+ ThresholdAuditEventType["CeremonyCompleted"] = "ceremony-completed";
26
+ /** A decryption ceremony failed */
27
+ ThresholdAuditEventType["CeremonyFailed"] = "ceremony-failed";
28
+ /** A tally was published to the public feed */
29
+ ThresholdAuditEventType["TallyPublished"] = "tally-published";
30
+ /** A key share was rotated */
31
+ ThresholdAuditEventType["KeyShareRotation"] = "key-share-rotation";
32
+ })(ThresholdAuditEventType || (exports.ThresholdAuditEventType = ThresholdAuditEventType = {}));
33
+ //# sourceMappingURL=threshold-audit-event-type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"threshold-audit-event-type.js","sourceRoot":"","sources":["../../../../../../../../packages/digitaldefiance-ecies-lib/src/lib/voting/threshold/enumerations/threshold-audit-event-type.ts"],"names":[],"mappings":";;;AAAA;;;;;GAKG;AACH,IAAY,uBAqBX;AArBD,WAAY,uBAAuB;IACjC,oCAAoC;IACpC,qEAA0C,CAAA;IAC1C,gDAAgD;IAChD,oFAAyD,CAAA;IACzD,8CAA8C;IAC9C,yEAA8C,CAAA;IAC9C,kCAAkC;IAClC,0EAA+C,CAAA;IAC/C,wCAAwC;IACxC,+DAAoC,CAAA;IACpC,yCAAyC;IACzC,iEAAsC,CAAA;IACtC,mDAAmD;IACnD,mEAAwC,CAAA;IACxC,mCAAmC;IACnC,6DAAkC,CAAA;IAClC,+CAA+C;IAC/C,6DAAkC,CAAA;IAClC,8BAA8B;IAC9B,kEAAuC,CAAA;AACzC,CAAC,EArBW,uBAAuB,uCAAvB,uBAAuB,QAqBlC"}