@digitaldefiance/node-ecies-lib 4.8.2 → 4.10.7
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 +195 -13
- 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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
+
import type { PlatformID as BasePlatformID } from '@digitaldefiance/ecies-lib';
|
|
1
2
|
import { Types } from '@digitaldefiance/mongoose-types';
|
|
2
|
-
|
|
3
|
-
export type PlatformID = Uint8Array | Buffer | ObjectId | Types.ObjectId | string;
|
|
3
|
+
export type PlatformID = BasePlatformID | Buffer | Types.ObjectId;
|
|
4
4
|
//# sourceMappingURL=platform-id.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform-id.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/interfaces/platform-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"platform-id.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/interfaces/platform-id.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,IAAI,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,EAAE,KAAK,EAAE,MAAM,iCAAiC,CAAC;AAExD,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG,MAAM,GAAG,KAAK,CAAC,QAAQ,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { BaseIdProvider } from '@digitaldefiance/ecies-lib';
|
|
2
|
+
/**
|
|
3
|
+
* Buffer ID provider that accepts any fixed byte length.
|
|
4
|
+
*
|
|
5
|
+
* Use this when you need a non-standard ID size or custom validation logic with Node.js Buffers.
|
|
6
|
+
* For standard formats, prefer ObjectIdProvider, GuidV4Provider, or UuidProvider.
|
|
7
|
+
*
|
|
8
|
+
* Example:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* // 20-byte SHA-1 hash as recipient ID
|
|
11
|
+
* const provider = new BufferIdProvider(20, 'SHA1Hash');
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare class BufferIdProvider extends BaseIdProvider<Buffer> {
|
|
15
|
+
readonly byteLength: number;
|
|
16
|
+
readonly name: string;
|
|
17
|
+
constructor(byteLength: number, name?: string);
|
|
18
|
+
/**
|
|
19
|
+
* Generate a new random ID of the specified byte length.
|
|
20
|
+
*/
|
|
21
|
+
generate(): Buffer;
|
|
22
|
+
/**
|
|
23
|
+
* Validate an ID buffer.
|
|
24
|
+
* Only checks length - override this method for custom validation.
|
|
25
|
+
*/
|
|
26
|
+
validate(id: Buffer): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Serialize to hexadecimal string.
|
|
29
|
+
*/
|
|
30
|
+
serialize(id: Buffer): string;
|
|
31
|
+
/**
|
|
32
|
+
* Deserialize a hexadecimal string to buffer.
|
|
33
|
+
*/
|
|
34
|
+
deserialize(str: string): Buffer;
|
|
35
|
+
/**
|
|
36
|
+
* Create a defensive copy of an ID.
|
|
37
|
+
*/
|
|
38
|
+
clone(id: Buffer): Buffer;
|
|
39
|
+
/**
|
|
40
|
+
* Convert Buffer to the provider's native representation.
|
|
41
|
+
* For BufferIdProvider, the native type is Buffer, so this is a pass-through.
|
|
42
|
+
*/
|
|
43
|
+
fromBytes(bytes: Buffer): Buffer;
|
|
44
|
+
/**
|
|
45
|
+
* Convert the provider's native representation to Buffer.
|
|
46
|
+
* For BufferIdProvider, the native type is Buffer, so this is a pass-through.
|
|
47
|
+
*/
|
|
48
|
+
toBytes(id: Buffer): Buffer;
|
|
49
|
+
/**
|
|
50
|
+
* Compare two IDs for equality.
|
|
51
|
+
*/
|
|
52
|
+
equals(a: Buffer, b: Buffer): boolean;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=buffer-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer-provider.d.ts","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/id-providers/buffer-provider.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,cAAc,EACf,MAAM,4BAA4B,CAAC;AAEpC;;;;;;;;;;;GAWG;AACH,qBAAa,gBAAiB,SAAQ,cAAc,CAAC,MAAM,CAAC;IAC1D,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBAEV,UAAU,EAAE,MAAM,EAAE,IAAI,SAAW;IAgB/C;;OAEG;IACH,QAAQ,IAAI,MAAM;IAIlB;;;OAGG;IACH,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAI7B;;OAEG;IACH,SAAS,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM;IAK7B;;OAEG;IACH,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAsBhC;;OAEG;IACH,KAAK,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM;IAIzB;;;OAGG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAIhC;;;OAGG;IACH,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM;IAI3B;;OAEG;IACH,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO;CAGtC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BufferIdProvider = void 0;
|
|
4
|
+
const crypto_1 = require("crypto");
|
|
5
|
+
const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
|
|
6
|
+
/**
|
|
7
|
+
* Buffer ID provider that accepts any fixed byte length.
|
|
8
|
+
*
|
|
9
|
+
* Use this when you need a non-standard ID size or custom validation logic with Node.js Buffers.
|
|
10
|
+
* For standard formats, prefer ObjectIdProvider, GuidV4Provider, or UuidProvider.
|
|
11
|
+
*
|
|
12
|
+
* Example:
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // 20-byte SHA-1 hash as recipient ID
|
|
15
|
+
* const provider = new BufferIdProvider(20, 'SHA1Hash');
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
class BufferIdProvider extends ecies_lib_1.BaseIdProvider {
|
|
19
|
+
byteLength;
|
|
20
|
+
name;
|
|
21
|
+
constructor(byteLength, name = 'Buffer') {
|
|
22
|
+
super();
|
|
23
|
+
if (!Number.isInteger(byteLength) || byteLength < 1 || byteLength > 255) {
|
|
24
|
+
throw new ecies_lib_1.IdProviderError(ecies_lib_1.IdProviderErrorType.InvalidByteLengthParameter, undefined, undefined, { value: byteLength });
|
|
25
|
+
}
|
|
26
|
+
this.byteLength = byteLength;
|
|
27
|
+
this.name = name;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Generate a new random ID of the specified byte length.
|
|
31
|
+
*/
|
|
32
|
+
generate() {
|
|
33
|
+
return (0, crypto_1.randomBytes)(this.byteLength);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Validate an ID buffer.
|
|
37
|
+
* Only checks length - override this method for custom validation.
|
|
38
|
+
*/
|
|
39
|
+
validate(id) {
|
|
40
|
+
return id.length === this.byteLength;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Serialize to hexadecimal string.
|
|
44
|
+
*/
|
|
45
|
+
serialize(id) {
|
|
46
|
+
this.validateLength(id, `${this.name}.serialize`);
|
|
47
|
+
return id.toString('hex');
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Deserialize a hexadecimal string to buffer.
|
|
51
|
+
*/
|
|
52
|
+
deserialize(str) {
|
|
53
|
+
if (typeof str !== 'string') {
|
|
54
|
+
throw new ecies_lib_1.IdProviderError(ecies_lib_1.IdProviderErrorType.InputMustBeString);
|
|
55
|
+
}
|
|
56
|
+
const expectedLength = this.byteLength * 2;
|
|
57
|
+
if (str.length !== expectedLength) {
|
|
58
|
+
throw new ecies_lib_1.IdProviderError(ecies_lib_1.IdProviderErrorType.InvalidStringLength, undefined, undefined, { expected: expectedLength, actual: str.length });
|
|
59
|
+
}
|
|
60
|
+
if (!/^[0-9a-fA-F]+$/.test(str)) {
|
|
61
|
+
throw new ecies_lib_1.IdProviderError(ecies_lib_1.IdProviderErrorType.InvalidCharacters);
|
|
62
|
+
}
|
|
63
|
+
return Buffer.from(str, 'hex');
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Create a defensive copy of an ID.
|
|
67
|
+
*/
|
|
68
|
+
clone(id) {
|
|
69
|
+
return Buffer.from(id);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Convert Buffer to the provider's native representation.
|
|
73
|
+
* For BufferIdProvider, the native type is Buffer, so this is a pass-through.
|
|
74
|
+
*/
|
|
75
|
+
fromBytes(bytes) {
|
|
76
|
+
return bytes;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Convert the provider's native representation to Buffer.
|
|
80
|
+
* For BufferIdProvider, the native type is Buffer, so this is a pass-through.
|
|
81
|
+
*/
|
|
82
|
+
toBytes(id) {
|
|
83
|
+
return id;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Compare two IDs for equality.
|
|
87
|
+
*/
|
|
88
|
+
equals(a, b) {
|
|
89
|
+
return a.equals(b);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.BufferIdProvider = BufferIdProvider;
|
|
93
|
+
//# sourceMappingURL=buffer-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer-provider.js","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/id-providers/buffer-provider.ts"],"names":[],"mappings":";;;AAAA,mCAAqC;AAErC,0DAIoC;AAEpC;;;;;;;;;;;GAWG;AACH,MAAa,gBAAiB,S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,EAAE,cAAc,EAAE,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,CACjD,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;YAChC,MAAM,IAAI,2BAAe,CAAC,+BAAmB,CAAC,iBAAiB,CAAC,CAAC;QACnE,CAAC;QAED,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,EAAU;QACd,OAAO,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACzB,CAAC;IAED;;;OAGG;IACH,SAAS,CAAC,KAAa;QACrB,OAAO,KAAK,CAAC;IACf,CAAC;IAED;;;OAGG;IACH,OAAO,CAAC,EAAU;QAChB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,CAAS,EAAE,CAAS;QACzB,OAAO,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IACrB,CAAC;CACF;AAjGD,4CAiGC"}
|
package/src/lib/index.d.ts
CHANGED
package/src/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC;AACtC,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC"}
|
package/src/lib/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./crypto-container"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./id-providers/buffer-provider"), exports);
|
|
5
6
|
tslib_1.__exportStar(require("./invariant-validator"), exports);
|
|
6
7
|
tslib_1.__exportStar(require("./invariants"), exports);
|
|
7
8
|
tslib_1.__exportStar(require("./voting"), exports);
|
package/src/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,gEAAsC;AACtC,uDAA6B;AAC7B,mDAAyB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/index.ts"],"names":[],"mappings":";;;AAAA,6DAAmC;AACnC,yEAA+C;AAC/C,gEAAsC;AACtC,uDAA6B;AAC7B,mDAAyB"}
|
|
@@ -1,55 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Immutable Audit Log for Government-Grade Voting
|
|
3
|
+
* Node.js optimized - extends ecies-lib ImmutableAuditLog with Buffer support
|
|
4
|
+
*/
|
|
5
|
+
import { ImmutableAuditLog as BaseImmutableAuditLog } from '@digitaldefiance/ecies-lib';
|
|
1
6
|
import type { PlatformID } from '../../interfaces';
|
|
2
7
|
import type { IMember } from '../../interfaces/member';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
/** Microsecond-precision timestamp */
|
|
14
|
-
readonly timestamp: number;
|
|
15
|
-
/** Poll identifier */
|
|
16
|
-
readonly pollId: TID;
|
|
17
|
-
/** Hash of voter ID (for vote events) */
|
|
18
|
-
readonly voterIdHash?: Buffer;
|
|
19
|
-
/** Authority/creator ID (for creation/closure events) */
|
|
20
|
-
readonly authorityId?: TID;
|
|
21
|
-
/** Hash of previous entry (chain integrity) */
|
|
22
|
-
readonly previousHash: Buffer;
|
|
23
|
-
/** Hash of this entry's data */
|
|
24
|
-
readonly entryHash: Buffer;
|
|
25
|
-
/** Digital signature from authority */
|
|
26
|
-
readonly signature: Buffer;
|
|
27
|
-
/** Additional event metadata */
|
|
28
|
-
readonly metadata?: Record<string, unknown>;
|
|
29
|
-
}
|
|
30
|
-
export interface AuditLog<TID extends PlatformID = Buffer> {
|
|
31
|
-
getEntries(): readonly AuditEntry<TID>[];
|
|
32
|
-
getEntriesForPoll(pollId: TID): readonly AuditEntry<TID>[];
|
|
33
|
-
verifyChain(): boolean;
|
|
34
|
-
verifyEntry(entry: AuditEntry<TID>): boolean;
|
|
35
|
-
}
|
|
36
|
-
export declare class ImmutableAuditLog<TID extends PlatformID = Buffer> implements AuditLog<TID> {
|
|
37
|
-
private readonly entries;
|
|
38
|
-
private readonly authority;
|
|
39
|
-
private sequence;
|
|
8
|
+
import type { AuditEntry } from './interfaces';
|
|
9
|
+
export type { AuditEntry, AuditLog } from './interfaces';
|
|
10
|
+
/**
|
|
11
|
+
* Node.js ImmutableAuditLog that extends ecies-lib ImmutableAuditLog
|
|
12
|
+
* Keeps the generic TID parameter for flexibility, defaulting to Buffer
|
|
13
|
+
*
|
|
14
|
+
* The base class handles all the logic, we override methods to convert
|
|
15
|
+
* Uint8Array to Buffer for Node.js compatibility.
|
|
16
|
+
*/
|
|
17
|
+
export declare class ImmutableAuditLog<TID extends PlatformID = Buffer> extends BaseImmutableAuditLog<TID> {
|
|
40
18
|
constructor(authority: IMember<TID>);
|
|
19
|
+
/**
|
|
20
|
+
* Record poll creation event
|
|
21
|
+
* Overrides base method to convert Uint8Array to Buffer
|
|
22
|
+
*/
|
|
41
23
|
recordPollCreated(pollId: TID, metadata?: Record<string, unknown>): AuditEntry<TID>;
|
|
42
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Record vote cast event
|
|
26
|
+
* Overrides base method to convert Uint8Array to Buffer
|
|
27
|
+
* Note: voterIdHash is Uint8Array for compatibility with base class
|
|
28
|
+
*/
|
|
29
|
+
recordVoteCast(pollId: TID, voterIdHash: Uint8Array, metadata?: Record<string, unknown>): AuditEntry<TID>;
|
|
30
|
+
/**
|
|
31
|
+
* Record poll closed event
|
|
32
|
+
* Overrides base method to convert Uint8Array to Buffer
|
|
33
|
+
*/
|
|
43
34
|
recordPollClosed(pollId: TID, metadata?: Record<string, unknown>): AuditEntry<TID>;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Get all audit entries
|
|
37
|
+
* Overrides base method to convert Uint8Array to Buffer
|
|
38
|
+
*/
|
|
39
|
+
getEntries(): ReadonlyArray<AuditEntry<TID>>;
|
|
40
|
+
/**
|
|
41
|
+
* Get entries for a specific poll
|
|
42
|
+
* Overrides base method to convert Uint8Array to Buffer
|
|
43
|
+
*/
|
|
44
|
+
getEntriesForPoll(pollId: TID): ReadonlyArray<AuditEntry<TID>>;
|
|
54
45
|
}
|
|
55
46
|
//# sourceMappingURL=audit.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/voting/audit.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"audit.d.ts","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/voting/audit.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EACL,iBAAiB,IAAI,qBAAqB,EAE3C,MAAM,4BAA4B,CAAC;AAEpC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAEvD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG/C,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAiCzD;;;;;;GAMG;AACH,qBAAa,iBAAiB,CAC5B,GAAG,SAAS,UAAU,GAAG,MAAM,CAC/B,SAAQ,qBAAqB,CAAC,GAAG,CAAC;gBACtB,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC;IA0DnC;;;OAGG;IACH,iBAAiB,CACf,MAAM,EAAE,GAAG,EACX,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,UAAU,CAAC,GAAG,CAAC;IAKlB;;;;OAIG;IACH,cAAc,CACZ,MAAM,EAAE,GAAG,EACX,WAAW,EAAE,UAAU,EACvB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,UAAU,CAAC,GAAG,CAAC;IAKlB;;;OAGG;IACH,gBAAgB,CACd,MAAM,EAAE,GAAG,EACX,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,UAAU,CAAC,GAAG,CAAC;IAKlB;;;OAGG;IACH,UAAU,IAAI,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAK5C;;;OAGG;IACH,iBAAiB,CAAC,MAAM,EAAE,GAAG,GAAG,aAAa,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;CAI/D"}
|
package/src/lib/voting/audit.js
CHANGED
|
@@ -1,130 +1,122 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ImmutableAuditLog =
|
|
3
|
+
exports.ImmutableAuditLog = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* Immutable Audit Log for Government-Grade Voting
|
|
6
|
-
* Node.js optimized with
|
|
6
|
+
* Node.js optimized - extends ecies-lib ImmutableAuditLog with Buffer support
|
|
7
7
|
*/
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
|
|
9
|
+
/**
|
|
10
|
+
* Converts Uint8Array fields in an audit entry to Buffer
|
|
11
|
+
*/
|
|
12
|
+
function convertAuditEntryToBuffer(entry) {
|
|
13
|
+
return {
|
|
14
|
+
...entry,
|
|
15
|
+
previousHash: entry.previousHash instanceof Uint8Array &&
|
|
16
|
+
!(entry.previousHash instanceof Buffer)
|
|
17
|
+
? Buffer.from(entry.previousHash)
|
|
18
|
+
: entry.previousHash,
|
|
19
|
+
entryHash: entry.entryHash instanceof Uint8Array &&
|
|
20
|
+
!(entry.entryHash instanceof Buffer)
|
|
21
|
+
? Buffer.from(entry.entryHash)
|
|
22
|
+
: entry.entryHash,
|
|
23
|
+
signature: entry.signature instanceof Uint8Array &&
|
|
24
|
+
!(entry.signature instanceof Buffer)
|
|
25
|
+
? Buffer.from(entry.signature)
|
|
26
|
+
: entry.signature,
|
|
27
|
+
voterIdHash: entry.voterIdHash instanceof Uint8Array &&
|
|
28
|
+
!(entry.voterIdHash instanceof Buffer)
|
|
29
|
+
? Buffer.from(entry.voterIdHash)
|
|
30
|
+
: entry.voterIdHash,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Node.js ImmutableAuditLog that extends ecies-lib ImmutableAuditLog
|
|
35
|
+
* Keeps the generic TID parameter for flexibility, defaulting to Buffer
|
|
36
|
+
*
|
|
37
|
+
* The base class handles all the logic, we override methods to convert
|
|
38
|
+
* Uint8Array to Buffer for Node.js compatibility.
|
|
39
|
+
*/
|
|
40
|
+
class ImmutableAuditLog extends ecies_lib_1.ImmutableAuditLog {
|
|
19
41
|
constructor(authority) {
|
|
20
|
-
|
|
42
|
+
// Create an adapter that bridges the Buffer-based Member with Uint8Array-based ecies-lib
|
|
43
|
+
const authorityAdapter = {
|
|
44
|
+
...authority,
|
|
45
|
+
// Convert the sign method from Buffer-based to Uint8Array-based
|
|
46
|
+
sign: (data) => {
|
|
47
|
+
const bufferData = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
48
|
+
const signature = authority.sign(bufferData);
|
|
49
|
+
return signature instanceof Uint8Array
|
|
50
|
+
? signature
|
|
51
|
+
: new Uint8Array(signature);
|
|
52
|
+
},
|
|
53
|
+
// Convert the verify method from Buffer-based to Uint8Array-based
|
|
54
|
+
verify: (signature, data) => {
|
|
55
|
+
const bufferSignature = Buffer.isBuffer(signature)
|
|
56
|
+
? signature
|
|
57
|
+
: Buffer.from(signature);
|
|
58
|
+
const bufferData = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
59
|
+
// Type assertion is safe here as we know SignatureBuffer extends Buffer
|
|
60
|
+
return authority.verify(bufferSignature, bufferData);
|
|
61
|
+
},
|
|
62
|
+
// Ensure publicKey is Uint8Array
|
|
63
|
+
publicKey: authority.publicKey instanceof Uint8Array
|
|
64
|
+
? authority.publicKey
|
|
65
|
+
: new Uint8Array(authority.publicKey),
|
|
66
|
+
// Ensure idBytes is Uint8Array
|
|
67
|
+
idBytes: authority.idBytes instanceof Uint8Array
|
|
68
|
+
? authority.idBytes
|
|
69
|
+
: new Uint8Array(authority.idBytes),
|
|
70
|
+
// Type assertions are safe here as the methods won't be used in audit log context
|
|
71
|
+
// and the underlying implementations are compatible
|
|
72
|
+
encryptDataStream: authority.encryptDataStream,
|
|
73
|
+
decryptDataStream: authority.decryptDataStream,
|
|
74
|
+
// Cast the encrypt/decrypt methods to handle the sync/async differences
|
|
75
|
+
encryptData: authority.encryptData,
|
|
76
|
+
decryptData: authority.decryptData,
|
|
77
|
+
};
|
|
78
|
+
super(authorityAdapter);
|
|
21
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Record poll creation event
|
|
82
|
+
* Overrides base method to convert Uint8Array to Buffer
|
|
83
|
+
*/
|
|
22
84
|
recordPollCreated(pollId, metadata) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
pollId,
|
|
26
|
-
authorityId: this.authority.id,
|
|
27
|
-
metadata,
|
|
28
|
-
});
|
|
85
|
+
const entry = super.recordPollCreated(pollId, metadata);
|
|
86
|
+
return convertAuditEntryToBuffer(entry);
|
|
29
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Record vote cast event
|
|
90
|
+
* Overrides base method to convert Uint8Array to Buffer
|
|
91
|
+
* Note: voterIdHash is Uint8Array for compatibility with base class
|
|
92
|
+
*/
|
|
30
93
|
recordVoteCast(pollId, voterIdHash, metadata) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
pollId,
|
|
34
|
-
voterIdHash,
|
|
35
|
-
metadata,
|
|
36
|
-
});
|
|
94
|
+
const entry = super.recordVoteCast(pollId, voterIdHash, metadata);
|
|
95
|
+
return convertAuditEntryToBuffer(entry);
|
|
37
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Record poll closed event
|
|
99
|
+
* Overrides base method to convert Uint8Array to Buffer
|
|
100
|
+
*/
|
|
38
101
|
recordPollClosed(pollId, metadata) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
pollId,
|
|
42
|
-
authorityId: this.authority.id,
|
|
43
|
-
metadata,
|
|
44
|
-
});
|
|
102
|
+
const entry = super.recordPollClosed(pollId, metadata);
|
|
103
|
+
return convertAuditEntryToBuffer(entry);
|
|
45
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* Get all audit entries
|
|
107
|
+
* Overrides base method to convert Uint8Array to Buffer
|
|
108
|
+
*/
|
|
46
109
|
getEntries() {
|
|
47
|
-
|
|
110
|
+
const entries = super.getEntries();
|
|
111
|
+
return entries.map((entry) => convertAuditEntryToBuffer(entry));
|
|
48
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Get entries for a specific poll
|
|
115
|
+
* Overrides base method to convert Uint8Array to Buffer
|
|
116
|
+
*/
|
|
49
117
|
getEntriesForPoll(pollId) {
|
|
50
|
-
const
|
|
51
|
-
return
|
|
52
|
-
}
|
|
53
|
-
verifyChain() {
|
|
54
|
-
if (this.entries.length === 0)
|
|
55
|
-
return true;
|
|
56
|
-
for (let i = 0; i < this.entries.length; i++) {
|
|
57
|
-
const entry = this.entries[i];
|
|
58
|
-
const computedHash = this.computeEntryHash(entry);
|
|
59
|
-
if (!computedHash.equals(entry.entryHash))
|
|
60
|
-
return false;
|
|
61
|
-
if (!this.verifyEntry(entry))
|
|
62
|
-
return false;
|
|
63
|
-
if (i > 0) {
|
|
64
|
-
const prevEntry = this.entries[i - 1];
|
|
65
|
-
if (!entry.previousHash.equals(prevEntry.entryHash))
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
verifyEntry(entry) {
|
|
72
|
-
const data = this.serializeEntryForSigning(entry);
|
|
73
|
-
return this.authority.verify(entry.signature, data);
|
|
74
|
-
}
|
|
75
|
-
appendEntry(partial) {
|
|
76
|
-
const previousHash = this.entries.length > 0
|
|
77
|
-
? this.entries[this.entries.length - 1].entryHash
|
|
78
|
-
: Buffer.alloc(32);
|
|
79
|
-
const entry = {
|
|
80
|
-
sequence: this.sequence++,
|
|
81
|
-
timestamp: this.getMicrosecondTimestamp(),
|
|
82
|
-
previousHash,
|
|
83
|
-
...partial,
|
|
84
|
-
};
|
|
85
|
-
const entryHash = this.computeEntryHash(entry);
|
|
86
|
-
const data = this.serializeEntryForSigning({ ...entry, entryHash });
|
|
87
|
-
const signature = this.authority.sign(data);
|
|
88
|
-
const finalEntry = { ...entry, entryHash, signature };
|
|
89
|
-
this.entries.push(finalEntry);
|
|
90
|
-
return finalEntry;
|
|
91
|
-
}
|
|
92
|
-
computeEntryHash(entry) {
|
|
93
|
-
const data = this.serializeEntryForHashing(entry);
|
|
94
|
-
return (0, crypto_1.createHash)('sha256').update(data).digest();
|
|
95
|
-
}
|
|
96
|
-
serializeEntryForHashing(entry) {
|
|
97
|
-
const parts = [
|
|
98
|
-
this.encodeNumber(entry.sequence),
|
|
99
|
-
Buffer.from(entry.eventType, 'utf8'),
|
|
100
|
-
this.encodeNumber(entry.timestamp),
|
|
101
|
-
Buffer.from(entry.pollId),
|
|
102
|
-
entry.previousHash,
|
|
103
|
-
];
|
|
104
|
-
if (entry.voterIdHash)
|
|
105
|
-
parts.push(entry.voterIdHash);
|
|
106
|
-
if (entry.authorityId)
|
|
107
|
-
parts.push(Buffer.from(entry.authorityId));
|
|
108
|
-
if (entry.metadata)
|
|
109
|
-
parts.push(Buffer.from(JSON.stringify(entry.metadata), 'utf8'));
|
|
110
|
-
return Buffer.concat(parts);
|
|
111
|
-
}
|
|
112
|
-
serializeEntryForSigning(entry) {
|
|
113
|
-
return Buffer.concat([
|
|
114
|
-
this.serializeEntryForHashing(entry),
|
|
115
|
-
entry.entryHash,
|
|
116
|
-
]);
|
|
117
|
-
}
|
|
118
|
-
getMicrosecondTimestamp() {
|
|
119
|
-
// Get milliseconds since epoch and convert to microseconds
|
|
120
|
-
// performance.now() is relative to process start, not epoch, so we only use Date.now()
|
|
121
|
-
const now = Date.now();
|
|
122
|
-
return now * 1000;
|
|
123
|
-
}
|
|
124
|
-
encodeNumber(n) {
|
|
125
|
-
const buf = Buffer.alloc(8);
|
|
126
|
-
buf.writeBigUInt64BE(BigInt(n));
|
|
127
|
-
return buf;
|
|
118
|
+
const entries = super.getEntriesForPoll(pollId);
|
|
119
|
+
return entries.map((entry) => convertAuditEntryToBuffer(entry));
|
|
128
120
|
}
|
|
129
121
|
}
|
|
130
122
|
exports.ImmutableAuditLog = ImmutableAuditLog;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audit.js","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/voting/audit.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,
|
|
1
|
+
{"version":3,"file":"audit.js","sourceRoot":"","sources":["../../../../../../packages/digitaldefiance-node-ecies-lib/src/lib/voting/audit.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,0DAGoC;AAUpC;;GAEG;AACH,SAAS,yBAAyB,CAChC,KAAsB;IAEtB,OAAO;QACL,GAAG,KAAK;QACR,YAAY,EACV,KAAK,CAAC,YAAY,YAAY,UAAU;YACxC,CAAC,CAAC,KAAK,CAAC,YAAY,YAAY,MAAM,CAAC;YACrC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC;YACjC,CAAC,CAAC,KAAK,CAAC,YAAY;QACxB,SAAS,EACP,KAAK,CAAC,SAAS,YAAY,UAAU;YACrC,CAAC,CAAC,KAAK,CAAC,SAAS,YAAY,MAAM,CAAC;YAClC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;YAC9B,CAAC,CAAC,KAAK,CAAC,SAAS;QACrB,SAAS,EACP,KAAK,CAAC,SAAS,YAAY,UAAU;YACrC,CAAC,CAAC,KAAK,CAAC,SAAS,YAAY,MAAM,CAAC;YAClC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC;YAC9B,CAAC,CAAC,KAAK,CAAC,SAAS;QACrB,WAAW,EACT,KAAK,CAAC,WAAW,YAAY,UAAU;YACvC,CAAC,CAAC,KAAK,CAAC,WAAW,YAAY,MAAM,CAAC;YACpC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC;YAChC,CAAC,CAAC,KAAK,CAAC,WAAW;KACL,CAAC;AACvB,CAAC;AAED;;;;;;GAMG;AACH,MAAa,iBAEX,SAAQ,6BAA0B;IAClC,YAAY,SAAuB;QACjC,yFAAyF;QACzF,MAAM,gBAAgB,GAAiC;YACrD,GAAG,SAAS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