@psavelis/enterprise-blockchain 0.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -2
- package/dist/aid-settlement/application/reconciler.d.ts +13 -0
- package/dist/aid-settlement/application/reconciler.d.ts.map +1 -0
- package/dist/aid-settlement/application/reconciler.js +77 -0
- package/dist/aid-settlement/domain/entities.d.ts +24 -0
- package/dist/aid-settlement/domain/entities.d.ts.map +1 -0
- package/dist/aid-settlement/domain/entities.js +1 -0
- package/dist/aid-settlement/domain/ports.d.ts +10 -0
- package/dist/aid-settlement/domain/ports.d.ts.map +1 -0
- package/dist/aid-settlement/domain/ports.js +1 -0
- package/dist/aid-settlement/index.d.ts +19 -0
- package/dist/aid-settlement/index.d.ts.map +1 -0
- package/dist/aid-settlement/index.js +23 -0
- package/dist/aid-settlement/infrastructure/in-memory-store.d.ts +12 -0
- package/dist/aid-settlement/infrastructure/in-memory-store.d.ts.map +1 -0
- package/dist/aid-settlement/infrastructure/in-memory-store.js +17 -0
- package/dist/credentialing/application/clearance-evaluator.d.ts +10 -0
- package/dist/credentialing/application/clearance-evaluator.d.ts.map +1 -0
- package/dist/credentialing/application/clearance-evaluator.js +63 -0
- package/dist/credentialing/domain/entities.d.ts +28 -0
- package/dist/credentialing/domain/entities.d.ts.map +1 -0
- package/dist/credentialing/domain/entities.js +1 -0
- package/dist/credentialing/domain/ports.d.ts +9 -0
- package/dist/credentialing/domain/ports.d.ts.map +1 -0
- package/dist/credentialing/domain/ports.js +1 -0
- package/dist/credentialing/index.d.ts +19 -0
- package/dist/credentialing/index.d.ts.map +1 -0
- package/dist/credentialing/index.js +23 -0
- package/dist/credentialing/infrastructure/in-memory-store.d.ts +11 -0
- package/dist/credentialing/infrastructure/in-memory-store.d.ts.map +1 -0
- package/dist/credentialing/infrastructure/in-memory-store.js +14 -0
- package/dist/hsm/application/asymmetric-key-service.d.ts +23 -0
- package/dist/hsm/application/asymmetric-key-service.d.ts.map +1 -0
- package/dist/hsm/application/asymmetric-key-service.js +109 -0
- package/dist/hsm/application/envelope-encryption-service.d.ts +18 -0
- package/dist/hsm/application/envelope-encryption-service.d.ts.map +1 -0
- package/dist/hsm/application/envelope-encryption-service.js +59 -0
- package/dist/hsm/application/symmetric-key-service.d.ts +34 -0
- package/dist/hsm/application/symmetric-key-service.d.ts.map +1 -0
- package/dist/hsm/application/symmetric-key-service.js +107 -0
- package/dist/hsm/domain/entities.d.ts +104 -0
- package/dist/hsm/domain/entities.d.ts.map +1 -0
- package/dist/hsm/domain/entities.js +10 -0
- package/dist/hsm/domain/ports.d.ts +20 -0
- package/dist/hsm/domain/ports.d.ts.map +1 -0
- package/dist/hsm/domain/ports.js +1 -0
- package/dist/hsm/index.d.ts +48 -0
- package/dist/hsm/index.d.ts.map +1 -0
- package/dist/hsm/index.js +97 -0
- package/dist/hsm/infrastructure/audit-log-factory.d.ts +59 -0
- package/dist/hsm/infrastructure/audit-log-factory.d.ts.map +1 -0
- package/dist/hsm/infrastructure/audit-log-factory.js +95 -0
- package/dist/hsm/infrastructure/audit-log.d.ts +8 -0
- package/dist/hsm/infrastructure/audit-log.d.ts.map +1 -0
- package/dist/hsm/infrastructure/audit-log.js +18 -0
- package/dist/hsm/infrastructure/file-audit-log.d.ts +55 -0
- package/dist/hsm/infrastructure/file-audit-log.d.ts.map +1 -0
- package/dist/hsm/infrastructure/file-audit-log.js +128 -0
- package/dist/hsm/infrastructure/key-store.d.ts +9 -0
- package/dist/hsm/infrastructure/key-store.d.ts.map +1 -0
- package/dist/hsm/infrastructure/key-store.js +12 -0
- package/dist/hsm/infrastructure/syslog-audit-log.d.ts +64 -0
- package/dist/hsm/infrastructure/syslog-audit-log.d.ts.map +1 -0
- package/dist/hsm/infrastructure/syslog-audit-log.js +167 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/integrations/besu-client/error-mapper.d.ts +9 -0
- package/dist/integrations/besu-client/error-mapper.d.ts.map +1 -0
- package/dist/integrations/besu-client/error-mapper.js +22 -0
- package/dist/integrations/besu-client/index.d.ts +65 -0
- package/dist/integrations/besu-client/index.d.ts.map +1 -0
- package/dist/integrations/besu-client/index.js +276 -0
- package/dist/integrations/besu-client/ports.d.ts +44 -0
- package/dist/integrations/besu-client/ports.d.ts.map +1 -0
- package/dist/integrations/besu-client/ports.js +1 -0
- package/dist/integrations/corda-gateway/index.d.ts +37 -0
- package/dist/integrations/corda-gateway/index.d.ts.map +1 -0
- package/dist/integrations/corda-gateway/index.js +234 -0
- package/dist/integrations/corda-gateway/ports.d.ts +33 -0
- package/dist/integrations/corda-gateway/ports.d.ts.map +1 -0
- package/dist/integrations/corda-gateway/ports.js +1 -0
- package/dist/integrations/fabric-gateway/index.d.ts +78 -0
- package/dist/integrations/fabric-gateway/index.d.ts.map +1 -0
- package/dist/integrations/fabric-gateway/index.js +214 -0
- package/dist/integrations/fabric-gateway/ports.d.ts +50 -0
- package/dist/integrations/fabric-gateway/ports.d.ts.map +1 -0
- package/dist/integrations/fabric-gateway/ports.js +1 -0
- package/dist/integrations/index.d.ts +19 -0
- package/dist/integrations/index.d.ts.map +1 -0
- package/dist/integrations/index.js +19 -0
- package/dist/integrations/shared/env.d.ts +4 -0
- package/dist/integrations/shared/env.d.ts.map +1 -0
- package/dist/integrations/shared/env.js +24 -0
- package/dist/integrations/shared/retry.d.ts +79 -0
- package/dist/integrations/shared/retry.d.ts.map +1 -0
- package/dist/integrations/shared/retry.js +315 -0
- package/dist/mpc/adapters.d.ts +36 -0
- package/dist/mpc/adapters.d.ts.map +1 -0
- package/dist/mpc/adapters.js +46 -0
- package/dist/mpc/crypto.d.ts +2 -0
- package/dist/mpc/crypto.d.ts.map +1 -0
- package/dist/mpc/crypto.js +2 -0
- package/dist/mpc/dsa.d.ts +134 -0
- package/dist/mpc/dsa.d.ts.map +1 -0
- package/dist/mpc/dsa.js +127 -0
- package/dist/mpc/field.d.ts +127 -0
- package/dist/mpc/field.d.ts.map +1 -0
- package/dist/mpc/field.js +209 -0
- package/dist/mpc/hybrid-kem.d.ts +96 -0
- package/dist/mpc/hybrid-kem.d.ts.map +1 -0
- package/dist/mpc/hybrid-kem.js +136 -0
- package/dist/mpc/index.d.ts +135 -0
- package/dist/mpc/index.d.ts.map +1 -0
- package/dist/mpc/index.js +348 -0
- package/dist/mpc/kyber.d.ts +134 -0
- package/dist/mpc/kyber.d.ts.map +1 -0
- package/dist/mpc/kyber.js +143 -0
- package/dist/mpc/ports.d.ts +67 -0
- package/dist/mpc/ports.d.ts.map +1 -0
- package/dist/mpc/ports.js +9 -0
- package/dist/mpc/quantum.d.ts +80 -0
- package/dist/mpc/quantum.d.ts.map +1 -0
- package/dist/mpc/quantum.js +180 -0
- package/dist/p2mr/adapters.d.ts +31 -0
- package/dist/p2mr/adapters.d.ts.map +1 -0
- package/dist/p2mr/adapters.js +35 -0
- package/dist/p2mr/index.d.ts +63 -0
- package/dist/p2mr/index.d.ts.map +1 -0
- package/dist/p2mr/index.js +59 -0
- package/dist/p2mr/merkle-tree.d.ts +109 -0
- package/dist/p2mr/merkle-tree.d.ts.map +1 -0
- package/dist/p2mr/merkle-tree.js +239 -0
- package/dist/p2mr/p2mr-output.d.ts +142 -0
- package/dist/p2mr/p2mr-output.d.ts.map +1 -0
- package/dist/p2mr/p2mr-output.js +150 -0
- package/dist/p2mr/ports.d.ts +52 -0
- package/dist/p2mr/ports.d.ts.map +1 -0
- package/dist/p2mr/ports.js +9 -0
- package/dist/p2mr/script-interpreter.d.ts +92 -0
- package/dist/p2mr/script-interpreter.d.ts.map +1 -0
- package/dist/p2mr/script-interpreter.js +535 -0
- package/dist/p2mr/script-leaf.d.ts +70 -0
- package/dist/p2mr/script-leaf.d.ts.map +1 -0
- package/dist/p2mr/script-leaf.js +203 -0
- package/dist/p2mr/spend-proof.d.ts +95 -0
- package/dist/p2mr/spend-proof.d.ts.map +1 -0
- package/dist/p2mr/spend-proof.js +358 -0
- package/dist/p2mr/types.d.ts +209 -0
- package/dist/p2mr/types.d.ts.map +1 -0
- package/dist/p2mr/types.js +9 -0
- package/dist/privacy/application/view-projector.d.ts +13 -0
- package/dist/privacy/application/view-projector.d.ts.map +1 -0
- package/dist/privacy/application/view-projector.js +85 -0
- package/dist/privacy/domain/entities.d.ts +26 -0
- package/dist/privacy/domain/entities.d.ts.map +1 -0
- package/dist/privacy/domain/entities.js +1 -0
- package/dist/privacy/domain/ports.d.ts +7 -0
- package/dist/privacy/domain/ports.d.ts.map +1 -0
- package/dist/privacy/domain/ports.js +1 -0
- package/dist/privacy/index.d.ts +21 -0
- package/dist/privacy/index.d.ts.map +1 -0
- package/dist/privacy/index.js +25 -0
- package/dist/privacy/infrastructure/in-memory-store.d.ts +8 -0
- package/dist/privacy/infrastructure/in-memory-store.d.ts.map +1 -0
- package/dist/privacy/infrastructure/in-memory-store.js +7 -0
- package/dist/protocols/besu-port.d.ts +80 -0
- package/dist/protocols/besu-port.d.ts.map +1 -0
- package/dist/protocols/besu-port.js +1 -0
- package/dist/protocols/corda-port.d.ts +103 -0
- package/dist/protocols/corda-port.d.ts.map +1 -0
- package/dist/protocols/corda-port.js +9 -0
- package/dist/protocols/credentialing-port.d.ts +11 -0
- package/dist/protocols/credentialing-port.d.ts.map +1 -0
- package/dist/protocols/credentialing-port.js +1 -0
- package/dist/protocols/fabric-port.d.ts +89 -0
- package/dist/protocols/fabric-port.d.ts.map +1 -0
- package/dist/protocols/fabric-port.js +9 -0
- package/dist/protocols/index.d.ts +14 -0
- package/dist/protocols/index.d.ts.map +1 -0
- package/dist/protocols/index.js +7 -0
- package/dist/protocols/p2mr-port.d.ts +159 -0
- package/dist/protocols/p2mr-port.d.ts.map +1 -0
- package/dist/protocols/p2mr-port.js +12 -0
- package/dist/protocols/privacy-port.d.ts +9 -0
- package/dist/protocols/privacy-port.d.ts.map +1 -0
- package/dist/protocols/privacy-port.js +1 -0
- package/dist/protocols/traceability-port.d.ts +12 -0
- package/dist/protocols/traceability-port.d.ts.map +1 -0
- package/dist/protocols/traceability-port.js +1 -0
- package/dist/shared/collection-store.d.ts +12 -0
- package/dist/shared/collection-store.d.ts.map +1 -0
- package/dist/shared/collection-store.js +26 -0
- package/dist/shared/commit.d.ts +24 -0
- package/dist/shared/commit.d.ts.map +1 -0
- package/dist/shared/commit.js +50 -0
- package/dist/shared/crypto.d.ts +2 -0
- package/dist/shared/crypto.d.ts.map +1 -0
- package/dist/shared/crypto.js +4 -0
- package/dist/shared/date.d.ts +2 -0
- package/dist/shared/date.d.ts.map +1 -0
- package/dist/shared/date.js +3 -0
- package/dist/shared/index.d.ts +9 -0
- package/dist/shared/index.d.ts.map +1 -0
- package/dist/shared/index.js +11 -0
- package/dist/shared/logger.d.ts +37 -0
- package/dist/shared/logger.d.ts.map +1 -0
- package/dist/shared/logger.js +45 -0
- package/dist/shared/store.d.ts +25 -0
- package/dist/shared/store.d.ts.map +1 -0
- package/dist/shared/store.js +18 -0
- package/dist/shared/telemetry-sdk.d.ts +26 -0
- package/dist/shared/telemetry-sdk.d.ts.map +1 -0
- package/dist/shared/telemetry-sdk.js +97 -0
- package/dist/shared/telemetry.d.ts +86 -0
- package/dist/shared/telemetry.d.ts.map +1 -0
- package/dist/shared/telemetry.js +137 -0
- package/dist/stark-settlement/application/aggregator-service.d.ts +112 -0
- package/dist/stark-settlement/application/aggregator-service.d.ts.map +1 -0
- package/dist/stark-settlement/application/aggregator-service.js +256 -0
- package/dist/stark-settlement/application/ledger-service.d.ts +114 -0
- package/dist/stark-settlement/application/ledger-service.d.ts.map +1 -0
- package/dist/stark-settlement/application/ledger-service.js +318 -0
- package/dist/stark-settlement/application/settlement-service.d.ts +104 -0
- package/dist/stark-settlement/application/settlement-service.d.ts.map +1 -0
- package/dist/stark-settlement/application/settlement-service.js +251 -0
- package/dist/stark-settlement/domain/entities.d.ts +365 -0
- package/dist/stark-settlement/domain/entities.d.ts.map +1 -0
- package/dist/stark-settlement/domain/entities.js +29 -0
- package/dist/stark-settlement/domain/ports.d.ts +485 -0
- package/dist/stark-settlement/domain/ports.d.ts.map +1 -0
- package/dist/stark-settlement/domain/ports.js +14 -0
- package/dist/stark-settlement/domain/value-objects.d.ts +268 -0
- package/dist/stark-settlement/domain/value-objects.d.ts.map +1 -0
- package/dist/stark-settlement/domain/value-objects.js +500 -0
- package/dist/stark-settlement/index.d.ts +172 -0
- package/dist/stark-settlement/index.d.ts.map +1 -0
- package/dist/stark-settlement/index.js +193 -0
- package/dist/stark-settlement/infrastructure/adapters/audit-adapter.d.ts +52 -0
- package/dist/stark-settlement/infrastructure/adapters/audit-adapter.d.ts.map +1 -0
- package/dist/stark-settlement/infrastructure/adapters/audit-adapter.js +154 -0
- package/dist/stark-settlement/infrastructure/adapters/bitcoin-adapter.d.ts +88 -0
- package/dist/stark-settlement/infrastructure/adapters/bitcoin-adapter.d.ts.map +1 -0
- package/dist/stark-settlement/infrastructure/adapters/bitcoin-adapter.js +187 -0
- package/dist/stark-settlement/infrastructure/adapters/clock-adapter.d.ts +59 -0
- package/dist/stark-settlement/infrastructure/adapters/clock-adapter.d.ts.map +1 -0
- package/dist/stark-settlement/infrastructure/adapters/clock-adapter.js +85 -0
- package/dist/stark-settlement/infrastructure/adapters/dilithium-adapter.d.ts +60 -0
- package/dist/stark-settlement/infrastructure/adapters/dilithium-adapter.d.ts.map +1 -0
- package/dist/stark-settlement/infrastructure/adapters/dilithium-adapter.js +104 -0
- package/dist/stark-settlement/infrastructure/adapters/event-emitter-adapter.d.ts +115 -0
- package/dist/stark-settlement/infrastructure/adapters/event-emitter-adapter.d.ts.map +1 -0
- package/dist/stark-settlement/infrastructure/adapters/event-emitter-adapter.js +191 -0
- package/dist/stark-settlement/infrastructure/adapters/fiat-adapter.d.ts +65 -0
- package/dist/stark-settlement/infrastructure/adapters/fiat-adapter.d.ts.map +1 -0
- package/dist/stark-settlement/infrastructure/adapters/fiat-adapter.js +207 -0
- package/dist/stark-settlement/infrastructure/adapters/mock-stark-adapter.d.ts +73 -0
- package/dist/stark-settlement/infrastructure/adapters/mock-stark-adapter.d.ts.map +1 -0
- package/dist/stark-settlement/infrastructure/adapters/mock-stark-adapter.js +287 -0
- package/dist/stark-settlement/infrastructure/adapters/solana-adapter.d.ts +78 -0
- package/dist/stark-settlement/infrastructure/adapters/solana-adapter.d.ts.map +1 -0
- package/dist/stark-settlement/infrastructure/adapters/solana-adapter.js +172 -0
- package/dist/stark-settlement/infrastructure/adapters/starknet-proof-adapter.d.ts +56 -0
- package/dist/stark-settlement/infrastructure/adapters/starknet-proof-adapter.d.ts.map +1 -0
- package/dist/stark-settlement/infrastructure/adapters/starknet-proof-adapter.js +261 -0
- package/dist/stark-settlement/infrastructure/adapters/stone-proof-adapter.d.ts +125 -0
- package/dist/stark-settlement/infrastructure/adapters/stone-proof-adapter.d.ts.map +1 -0
- package/dist/stark-settlement/infrastructure/adapters/stone-proof-adapter.js +416 -0
- package/dist/stark-settlement/infrastructure/persistence/ledger-store.d.ts +68 -0
- package/dist/stark-settlement/infrastructure/persistence/ledger-store.d.ts.map +1 -0
- package/dist/stark-settlement/infrastructure/persistence/ledger-store.js +238 -0
- package/dist/stark-settlement/infrastructure/persistence/offset-store.d.ts +30 -0
- package/dist/stark-settlement/infrastructure/persistence/offset-store.d.ts.map +1 -0
- package/dist/stark-settlement/infrastructure/persistence/offset-store.js +57 -0
- package/dist/stark-settlement/infrastructure/persistence/outbox-store.d.ts +45 -0
- package/dist/stark-settlement/infrastructure/persistence/outbox-store.d.ts.map +1 -0
- package/dist/stark-settlement/infrastructure/persistence/outbox-store.js +171 -0
- package/dist/traceability/application/recall-assessor.d.ts +13 -0
- package/dist/traceability/application/recall-assessor.d.ts.map +1 -0
- package/dist/traceability/application/recall-assessor.js +74 -0
- package/dist/traceability/domain/entities.d.ts +23 -0
- package/dist/traceability/domain/entities.d.ts.map +1 -0
- package/dist/traceability/domain/entities.js +1 -0
- package/dist/traceability/domain/ports.d.ts +23 -0
- package/dist/traceability/domain/ports.d.ts.map +1 -0
- package/dist/traceability/domain/ports.js +1 -0
- package/dist/traceability/domain/recall.d.ts +12 -0
- package/dist/traceability/domain/recall.d.ts.map +1 -0
- package/dist/traceability/domain/recall.js +1 -0
- package/dist/traceability/index.d.ts +22 -0
- package/dist/traceability/index.d.ts.map +1 -0
- package/dist/traceability/index.js +26 -0
- package/dist/traceability/infrastructure/in-memory-store.d.ts +13 -0
- package/dist/traceability/infrastructure/in-memory-store.d.ts.map +1 -0
- package/dist/traceability/infrastructure/in-memory-store.js +24 -0
- package/package.json +12 -9
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { HsmAuditEntry } from "../domain/entities.js";
|
|
2
|
+
import type { AuditLog } from "../domain/ports.js";
|
|
3
|
+
export declare class InMemoryAuditLog implements AuditLog {
|
|
4
|
+
private readonly log;
|
|
5
|
+
record(operation: string, keyLabel: string, result: "success" | "failed", detail?: string): void;
|
|
6
|
+
entries(): readonly HsmAuditEntry[];
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=audit-log.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"audit-log.d.ts","sourceRoot":"","sources":["../../../src/hsm/infrastructure/audit-log.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD,qBAAa,gBAAiB,YAAW,QAAQ;IAC/C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAuB;IAE3C,MAAM,CACJ,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,SAAS,GAAG,QAAQ,EAC5B,MAAM,CAAC,EAAE,MAAM,GACd,IAAI;IAaP,OAAO,IAAI,SAAS,aAAa,EAAE;CAGpC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export class InMemoryAuditLog {
|
|
2
|
+
log = [];
|
|
3
|
+
record(operation, keyLabel, result, detail) {
|
|
4
|
+
const entry = {
|
|
5
|
+
timestamp: new Date().toISOString(),
|
|
6
|
+
operation,
|
|
7
|
+
keyLabel,
|
|
8
|
+
result,
|
|
9
|
+
};
|
|
10
|
+
if (detail !== undefined) {
|
|
11
|
+
entry.detail = detail;
|
|
12
|
+
}
|
|
13
|
+
this.log.push(entry);
|
|
14
|
+
}
|
|
15
|
+
entries() {
|
|
16
|
+
return [...this.log];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { HsmAuditEntry } from "../domain/entities.js";
|
|
2
|
+
import type { AuditLog } from "../domain/ports.js";
|
|
3
|
+
/**
|
|
4
|
+
* Chained audit entry with cryptographic integrity.
|
|
5
|
+
* Each entry includes a hash of the previous entry, creating a tamper-evident chain.
|
|
6
|
+
*/
|
|
7
|
+
export interface ChainedAuditEntry extends HsmAuditEntry {
|
|
8
|
+
/** SHA-256 hash of the previous entry (hex). First entry uses "genesis". */
|
|
9
|
+
previousHash: string;
|
|
10
|
+
/** SHA-256 hash of this entry including previousHash (hex). */
|
|
11
|
+
entryHash: string;
|
|
12
|
+
/** Monotonic sequence number starting at 1. */
|
|
13
|
+
sequenceNumber: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Persistent audit log with append-only writes and cryptographic chaining.
|
|
17
|
+
*
|
|
18
|
+
* Each entry includes:
|
|
19
|
+
* - SHA-256 hash of the previous entry (tamper-evidence)
|
|
20
|
+
* - Monotonic sequence number (gap detection)
|
|
21
|
+
* - Entry hash for integrity verification
|
|
22
|
+
*
|
|
23
|
+
* File format: NDJSON (newline-delimited JSON) for append-only writes.
|
|
24
|
+
*
|
|
25
|
+
* Ref: NIST SP 800-57 Part 1, §8.1 — key management lifecycle auditing
|
|
26
|
+
*/
|
|
27
|
+
export declare class FileAuditLog implements AuditLog {
|
|
28
|
+
private readonly filePath;
|
|
29
|
+
private lastHash;
|
|
30
|
+
private sequenceNumber;
|
|
31
|
+
private readonly cache;
|
|
32
|
+
constructor(filePath: string);
|
|
33
|
+
record(operation: string, keyLabel: string, result: "success" | "failed", detail?: string): void;
|
|
34
|
+
entries(): readonly HsmAuditEntry[];
|
|
35
|
+
/**
|
|
36
|
+
* Get all chained entries including integrity metadata.
|
|
37
|
+
*/
|
|
38
|
+
chainedEntries(): readonly ChainedAuditEntry[];
|
|
39
|
+
/**
|
|
40
|
+
* Verify the integrity of the entire audit chain.
|
|
41
|
+
* Returns true if all hashes are valid and sequence is unbroken.
|
|
42
|
+
*/
|
|
43
|
+
verifyIntegrity(): {
|
|
44
|
+
valid: boolean;
|
|
45
|
+
errors: string[];
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Get the current chain tip hash for external anchoring.
|
|
49
|
+
*/
|
|
50
|
+
getChainTipHash(): string;
|
|
51
|
+
private computeHash;
|
|
52
|
+
private appendToFile;
|
|
53
|
+
private loadExistingEntries;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=file-audit-log.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-audit-log.d.ts","sourceRoot":"","sources":["../../../src/hsm/infrastructure/file-audit-log.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;GAGG;AACH,MAAM,WAAW,iBAAkB,SAAQ,aAAa;IACtD,4EAA4E;IAC5E,YAAY,EAAE,MAAM,CAAC;IACrB,+DAA+D;IAC/D,SAAS,EAAE,MAAM,CAAC;IAClB,+CAA+C;IAC/C,cAAc,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,YAAa,YAAW,QAAQ;IAC3C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,cAAc,CAAa;IACnC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA2B;gBAErC,QAAQ,EAAE,MAAM;IAK5B,MAAM,CACJ,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,SAAS,GAAG,QAAQ,EAC5B,MAAM,CAAC,EAAE,MAAM,GACd,IAAI;IA2BP,OAAO,IAAI,SAAS,aAAa,EAAE;IAenC;;OAEG;IACH,cAAc,IAAI,SAAS,iBAAiB,EAAE;IAI9C;;;OAGG;IACH,eAAe,IAAI;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,MAAM,EAAE,MAAM,EAAE,CAAA;KAAE;IAmCvD;;OAEG;IACH,eAAe,IAAI,MAAM;IAIzB,OAAO,CAAC,WAAW;IAanB,OAAO,CAAC,YAAY;IAKpB,OAAO,CAAC,mBAAmB;CAgB5B"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import { appendFileSync, existsSync, readFileSync, writeFileSync, } from "node:fs";
|
|
3
|
+
/**
|
|
4
|
+
* Persistent audit log with append-only writes and cryptographic chaining.
|
|
5
|
+
*
|
|
6
|
+
* Each entry includes:
|
|
7
|
+
* - SHA-256 hash of the previous entry (tamper-evidence)
|
|
8
|
+
* - Monotonic sequence number (gap detection)
|
|
9
|
+
* - Entry hash for integrity verification
|
|
10
|
+
*
|
|
11
|
+
* File format: NDJSON (newline-delimited JSON) for append-only writes.
|
|
12
|
+
*
|
|
13
|
+
* Ref: NIST SP 800-57 Part 1, §8.1 — key management lifecycle auditing
|
|
14
|
+
*/
|
|
15
|
+
export class FileAuditLog {
|
|
16
|
+
filePath;
|
|
17
|
+
lastHash = "genesis";
|
|
18
|
+
sequenceNumber = 0;
|
|
19
|
+
cache = [];
|
|
20
|
+
constructor(filePath) {
|
|
21
|
+
this.filePath = filePath;
|
|
22
|
+
this.loadExistingEntries();
|
|
23
|
+
}
|
|
24
|
+
record(operation, keyLabel, result, detail) {
|
|
25
|
+
this.sequenceNumber++;
|
|
26
|
+
const baseEntry = {
|
|
27
|
+
timestamp: new Date().toISOString(),
|
|
28
|
+
operation,
|
|
29
|
+
keyLabel,
|
|
30
|
+
result,
|
|
31
|
+
};
|
|
32
|
+
if (detail !== undefined) {
|
|
33
|
+
baseEntry.detail = detail;
|
|
34
|
+
}
|
|
35
|
+
const chainedEntry = {
|
|
36
|
+
...baseEntry,
|
|
37
|
+
previousHash: this.lastHash,
|
|
38
|
+
sequenceNumber: this.sequenceNumber,
|
|
39
|
+
entryHash: "", // Computed below
|
|
40
|
+
};
|
|
41
|
+
chainedEntry.entryHash = this.computeHash(chainedEntry);
|
|
42
|
+
this.lastHash = chainedEntry.entryHash;
|
|
43
|
+
this.appendToFile(chainedEntry);
|
|
44
|
+
this.cache.push(chainedEntry);
|
|
45
|
+
}
|
|
46
|
+
entries() {
|
|
47
|
+
return this.cache.map((e) => {
|
|
48
|
+
const entry = {
|
|
49
|
+
timestamp: e.timestamp,
|
|
50
|
+
operation: e.operation,
|
|
51
|
+
keyLabel: e.keyLabel,
|
|
52
|
+
result: e.result,
|
|
53
|
+
};
|
|
54
|
+
if (e.detail !== undefined) {
|
|
55
|
+
entry.detail = e.detail;
|
|
56
|
+
}
|
|
57
|
+
return entry;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get all chained entries including integrity metadata.
|
|
62
|
+
*/
|
|
63
|
+
chainedEntries() {
|
|
64
|
+
return [...this.cache];
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Verify the integrity of the entire audit chain.
|
|
68
|
+
* Returns true if all hashes are valid and sequence is unbroken.
|
|
69
|
+
*/
|
|
70
|
+
verifyIntegrity() {
|
|
71
|
+
const errors = [];
|
|
72
|
+
let expectedPreviousHash = "genesis";
|
|
73
|
+
for (let i = 0; i < this.cache.length; i++) {
|
|
74
|
+
const entry = this.cache[i];
|
|
75
|
+
// Verify sequence number
|
|
76
|
+
if (entry.sequenceNumber !== i + 1) {
|
|
77
|
+
errors.push(`Entry ${i}: sequence number mismatch (expected ${i + 1}, got ${entry.sequenceNumber})`);
|
|
78
|
+
}
|
|
79
|
+
// Verify previous hash chain
|
|
80
|
+
if (entry.previousHash !== expectedPreviousHash) {
|
|
81
|
+
errors.push(`Entry ${i}: previous hash mismatch (expected ${expectedPreviousHash.slice(0, 16)}..., got ${entry.previousHash.slice(0, 16)}...)`);
|
|
82
|
+
}
|
|
83
|
+
// Verify entry hash
|
|
84
|
+
const computedHash = this.computeHash(entry);
|
|
85
|
+
if (entry.entryHash !== computedHash) {
|
|
86
|
+
errors.push(`Entry ${i}: entry hash mismatch (computed ${computedHash.slice(0, 16)}..., stored ${entry.entryHash.slice(0, 16)}...)`);
|
|
87
|
+
}
|
|
88
|
+
expectedPreviousHash = entry.entryHash;
|
|
89
|
+
}
|
|
90
|
+
return { valid: errors.length === 0, errors };
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Get the current chain tip hash for external anchoring.
|
|
94
|
+
*/
|
|
95
|
+
getChainTipHash() {
|
|
96
|
+
return this.lastHash;
|
|
97
|
+
}
|
|
98
|
+
computeHash(entry) {
|
|
99
|
+
const payload = JSON.stringify({
|
|
100
|
+
timestamp: entry.timestamp,
|
|
101
|
+
operation: entry.operation,
|
|
102
|
+
keyLabel: entry.keyLabel,
|
|
103
|
+
result: entry.result,
|
|
104
|
+
detail: entry.detail,
|
|
105
|
+
previousHash: entry.previousHash,
|
|
106
|
+
sequenceNumber: entry.sequenceNumber,
|
|
107
|
+
});
|
|
108
|
+
return createHash("sha256").update(payload).digest("hex");
|
|
109
|
+
}
|
|
110
|
+
appendToFile(entry) {
|
|
111
|
+
const line = JSON.stringify(entry) + "\n";
|
|
112
|
+
appendFileSync(this.filePath, line, "utf-8");
|
|
113
|
+
}
|
|
114
|
+
loadExistingEntries() {
|
|
115
|
+
if (!existsSync(this.filePath)) {
|
|
116
|
+
writeFileSync(this.filePath, "", "utf-8");
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const content = readFileSync(this.filePath, "utf-8");
|
|
120
|
+
const lines = content.trim().split("\n").filter(Boolean);
|
|
121
|
+
for (const line of lines) {
|
|
122
|
+
const entry = JSON.parse(line);
|
|
123
|
+
this.cache.push(entry);
|
|
124
|
+
this.lastHash = entry.entryHash;
|
|
125
|
+
this.sequenceNumber = entry.sequenceNumber;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { KeyEntry } from "../domain/entities.js";
|
|
2
|
+
import type { KeyStore } from "../domain/ports.js";
|
|
3
|
+
export declare class InMemoryKeyStore implements KeyStore {
|
|
4
|
+
private readonly data;
|
|
5
|
+
has(label: string): boolean;
|
|
6
|
+
get(label: string): KeyEntry | undefined;
|
|
7
|
+
set(label: string, entry: KeyEntry): void;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=key-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key-store.d.ts","sourceRoot":"","sources":["../../../src/hsm/infrastructure/key-store.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD,qBAAa,gBAAiB,YAAW,QAAQ;IAC/C,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA+B;IAEpD,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAI3B,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAIxC,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI;CAG1C"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { HsmAuditEntry } from "../domain/entities.js";
|
|
2
|
+
import type { AuditLog } from "../domain/ports.js";
|
|
3
|
+
/**
|
|
4
|
+
* Syslog severity levels per RFC 5424.
|
|
5
|
+
*/
|
|
6
|
+
export type SyslogSeverity = "emergency" | "alert" | "critical" | "error" | "warning" | "notice" | "info" | "debug";
|
|
7
|
+
/**
|
|
8
|
+
* Syslog facility codes per RFC 5424.
|
|
9
|
+
*/
|
|
10
|
+
export type SyslogFacility = "kern" | "user" | "mail" | "daemon" | "auth" | "syslog" | "lpr" | "news" | "uucp" | "cron" | "authpriv" | "ftp" | "local0" | "local1" | "local2" | "local3" | "local4" | "local5" | "local6" | "local7";
|
|
11
|
+
export interface SyslogConfig {
|
|
12
|
+
/** Syslog server hostname or IP address. Default: "127.0.0.1" */
|
|
13
|
+
host: string;
|
|
14
|
+
/** Syslog server port. Default: 514 */
|
|
15
|
+
port: number;
|
|
16
|
+
/** Syslog facility. Default: "auth" (security/authorization) */
|
|
17
|
+
facility: SyslogFacility;
|
|
18
|
+
/** Application name for syslog messages. Default: "hsm-audit" */
|
|
19
|
+
appName: string;
|
|
20
|
+
/** Protocol: UDP or TCP. Default: "udp" */
|
|
21
|
+
protocol: "udp" | "tcp";
|
|
22
|
+
}
|
|
23
|
+
export declare const DEFAULT_SYSLOG_CONFIG: SyslogConfig;
|
|
24
|
+
/**
|
|
25
|
+
* Syslog audit log adapter for enterprise SIEM integration.
|
|
26
|
+
*
|
|
27
|
+
* Sends HSM audit entries to a syslog server using RFC 5424 format.
|
|
28
|
+
* Also maintains an in-memory cache for the entries() API contract.
|
|
29
|
+
*
|
|
30
|
+
* Severity mapping:
|
|
31
|
+
* - "success" → info
|
|
32
|
+
* - "failed" → warning
|
|
33
|
+
*
|
|
34
|
+
* Ref: RFC 5424 — The Syslog Protocol
|
|
35
|
+
* Ref: NIST SP 800-57 Part 1, §8.1 — key management lifecycle auditing
|
|
36
|
+
*/
|
|
37
|
+
export declare class SyslogAuditLog implements AuditLog {
|
|
38
|
+
private readonly config;
|
|
39
|
+
private readonly cache;
|
|
40
|
+
private socket;
|
|
41
|
+
private sequenceNumber;
|
|
42
|
+
constructor(config?: Partial<SyslogConfig>);
|
|
43
|
+
record(operation: string, keyLabel: string, result: "success" | "failed", detail?: string): void;
|
|
44
|
+
entries(): readonly HsmAuditEntry[];
|
|
45
|
+
/**
|
|
46
|
+
* Close the UDP socket if open.
|
|
47
|
+
*/
|
|
48
|
+
close(): void;
|
|
49
|
+
private sendToSyslog;
|
|
50
|
+
private formatSyslogMessage;
|
|
51
|
+
/**
|
|
52
|
+
* Escape structured-data parameter values per RFC 5424 §6.3.3.
|
|
53
|
+
* Must escape: " (double-quote), ] (right bracket), \ (backslash)
|
|
54
|
+
*/
|
|
55
|
+
private escapeStructuredDataValue;
|
|
56
|
+
/**
|
|
57
|
+
* Sanitize message text to prevent log injection.
|
|
58
|
+
* Removes control characters that could manipulate log parsing.
|
|
59
|
+
*/
|
|
60
|
+
private sanitizeMessageText;
|
|
61
|
+
private computeEntryHash;
|
|
62
|
+
private sendUdp;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=syslog-audit-log.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"syslog-audit-log.d.ts","sourceRoot":"","sources":["../../../src/hsm/infrastructure/syslog-audit-log.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB,WAAW,GACX,OAAO,GACP,UAAU,GACV,OAAO,GACP,SAAS,GACT,QAAQ,GACR,MAAM,GACN,OAAO,CAAC;AAEZ;;GAEG;AACH,MAAM,MAAM,cAAc,GACtB,MAAM,GACN,MAAM,GACN,MAAM,GACN,QAAQ,GACR,MAAM,GACN,QAAQ,GACR,KAAK,GACL,MAAM,GACN,MAAM,GACN,MAAM,GACN,UAAU,GACV,KAAK,GACL,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,QAAQ,GACR,QAAQ,CAAC;AAoCb,MAAM,WAAW,YAAY;IAC3B,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAC;IACb,uCAAuC;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,gEAAgE;IAChE,QAAQ,EAAE,cAAc,CAAC;IACzB,iEAAiE;IACjE,OAAO,EAAE,MAAM,CAAC;IAChB,2CAA2C;IAC3C,QAAQ,EAAE,KAAK,GAAG,KAAK,CAAC;CACzB;AAED,eAAO,MAAM,qBAAqB,EAAE,YAMnC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,qBAAa,cAAe,YAAW,QAAQ;IAC7C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAuB;IAC7C,OAAO,CAAC,MAAM,CAA6B;IAC3C,OAAO,CAAC,cAAc,CAAK;gBAEf,MAAM,GAAE,OAAO,CAAC,YAAY,CAAM;IAI9C,MAAM,CACJ,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,SAAS,GAAG,QAAQ,EAC5B,MAAM,CAAC,EAAE,MAAM,GACd,IAAI;IAiBP,OAAO,IAAI,SAAS,aAAa,EAAE;IAInC;;OAEG;IACH,KAAK,IAAI,IAAI;IAOb,OAAO,CAAC,YAAY;IAWpB,OAAO,CAAC,mBAAmB;IAuC3B;;;OAGG;IACH,OAAO,CAAC,yBAAyB;IAOjC;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAM3B,OAAO,CAAC,gBAAgB;IAYxB,OAAO,CAAC,OAAO;CAsBhB"}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import * as dgram from "node:dgram";
|
|
3
|
+
const FACILITY_CODES = {
|
|
4
|
+
kern: 0,
|
|
5
|
+
user: 1,
|
|
6
|
+
mail: 2,
|
|
7
|
+
daemon: 3,
|
|
8
|
+
auth: 4,
|
|
9
|
+
syslog: 5,
|
|
10
|
+
lpr: 6,
|
|
11
|
+
news: 7,
|
|
12
|
+
uucp: 8,
|
|
13
|
+
cron: 9,
|
|
14
|
+
authpriv: 10,
|
|
15
|
+
ftp: 11,
|
|
16
|
+
local0: 16,
|
|
17
|
+
local1: 17,
|
|
18
|
+
local2: 18,
|
|
19
|
+
local3: 19,
|
|
20
|
+
local4: 20,
|
|
21
|
+
local5: 21,
|
|
22
|
+
local6: 22,
|
|
23
|
+
local7: 23,
|
|
24
|
+
};
|
|
25
|
+
const SEVERITY_CODES = {
|
|
26
|
+
emergency: 0,
|
|
27
|
+
alert: 1,
|
|
28
|
+
critical: 2,
|
|
29
|
+
error: 3,
|
|
30
|
+
warning: 4,
|
|
31
|
+
notice: 5,
|
|
32
|
+
info: 6,
|
|
33
|
+
debug: 7,
|
|
34
|
+
};
|
|
35
|
+
export const DEFAULT_SYSLOG_CONFIG = {
|
|
36
|
+
host: "127.0.0.1",
|
|
37
|
+
port: 514,
|
|
38
|
+
facility: "auth",
|
|
39
|
+
appName: "hsm-audit",
|
|
40
|
+
protocol: "udp",
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Syslog audit log adapter for enterprise SIEM integration.
|
|
44
|
+
*
|
|
45
|
+
* Sends HSM audit entries to a syslog server using RFC 5424 format.
|
|
46
|
+
* Also maintains an in-memory cache for the entries() API contract.
|
|
47
|
+
*
|
|
48
|
+
* Severity mapping:
|
|
49
|
+
* - "success" → info
|
|
50
|
+
* - "failed" → warning
|
|
51
|
+
*
|
|
52
|
+
* Ref: RFC 5424 — The Syslog Protocol
|
|
53
|
+
* Ref: NIST SP 800-57 Part 1, §8.1 — key management lifecycle auditing
|
|
54
|
+
*/
|
|
55
|
+
export class SyslogAuditLog {
|
|
56
|
+
config;
|
|
57
|
+
cache = [];
|
|
58
|
+
socket = null;
|
|
59
|
+
sequenceNumber = 0;
|
|
60
|
+
constructor(config = {}) {
|
|
61
|
+
this.config = { ...DEFAULT_SYSLOG_CONFIG, ...config };
|
|
62
|
+
}
|
|
63
|
+
record(operation, keyLabel, result, detail) {
|
|
64
|
+
this.sequenceNumber++;
|
|
65
|
+
const entry = {
|
|
66
|
+
timestamp: new Date().toISOString(),
|
|
67
|
+
operation,
|
|
68
|
+
keyLabel,
|
|
69
|
+
result,
|
|
70
|
+
};
|
|
71
|
+
if (detail !== undefined) {
|
|
72
|
+
entry.detail = detail;
|
|
73
|
+
}
|
|
74
|
+
this.cache.push(entry);
|
|
75
|
+
this.sendToSyslog(entry);
|
|
76
|
+
}
|
|
77
|
+
entries() {
|
|
78
|
+
return [...this.cache];
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Close the UDP socket if open.
|
|
82
|
+
*/
|
|
83
|
+
close() {
|
|
84
|
+
if (this.socket) {
|
|
85
|
+
this.socket.close();
|
|
86
|
+
this.socket = null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
sendToSyslog(entry) {
|
|
90
|
+
const severity = entry.result === "success" ? "info" : "warning";
|
|
91
|
+
const message = this.formatSyslogMessage(entry, severity);
|
|
92
|
+
if (this.config.protocol === "udp") {
|
|
93
|
+
this.sendUdp(message);
|
|
94
|
+
}
|
|
95
|
+
// TCP support can be added later if needed
|
|
96
|
+
}
|
|
97
|
+
formatSyslogMessage(entry, severity) {
|
|
98
|
+
const priority = FACILITY_CODES[this.config.facility] * 8 + SEVERITY_CODES[severity];
|
|
99
|
+
const timestamp = entry.timestamp;
|
|
100
|
+
const hostname = "-"; // NILVALUE per RFC 5424
|
|
101
|
+
const appName = this.config.appName;
|
|
102
|
+
const procId = process.pid.toString();
|
|
103
|
+
const msgId = `HSM_${entry.operation.toUpperCase()}`;
|
|
104
|
+
// Escape values per RFC 5424 §6.3.3 - SD-PARAM values must escape ", ], and \
|
|
105
|
+
const escapedOperation = this.escapeStructuredDataValue(entry.operation);
|
|
106
|
+
const escapedKeyLabel = this.escapeStructuredDataValue(entry.keyLabel);
|
|
107
|
+
// Sanitize message text to prevent log injection
|
|
108
|
+
const messageOperation = this.sanitizeMessageText(entry.operation);
|
|
109
|
+
const messageKeyLabel = this.sanitizeMessageText(entry.keyLabel);
|
|
110
|
+
const messageDetail = entry.detail
|
|
111
|
+
? this.sanitizeMessageText(entry.detail)
|
|
112
|
+
: undefined;
|
|
113
|
+
// Structured data with audit details
|
|
114
|
+
const entryHash = this.computeEntryHash(entry);
|
|
115
|
+
const structuredData = `[hsm-audit@32473 operation="${escapedOperation}" ` +
|
|
116
|
+
`keyLabel="${escapedKeyLabel}" result="${entry.result}" ` +
|
|
117
|
+
`sequence="${this.sequenceNumber}" hash="${entryHash.slice(0, 16)}"]`;
|
|
118
|
+
// Human-readable message
|
|
119
|
+
const message = messageDetail
|
|
120
|
+
? `${messageOperation} ${messageKeyLabel}: ${entry.result} - ${messageDetail}`
|
|
121
|
+
: `${messageOperation} ${messageKeyLabel}: ${entry.result}`;
|
|
122
|
+
// RFC 5424 format: <PRI>VERSION TIMESTAMP HOSTNAME APP-NAME PROCID MSGID SD MSG
|
|
123
|
+
return `<${priority}>1 ${timestamp} ${hostname} ${appName} ${procId} ${msgId} ${structuredData} ${message}`;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Escape structured-data parameter values per RFC 5424 §6.3.3.
|
|
127
|
+
* Must escape: " (double-quote), ] (right bracket), \ (backslash)
|
|
128
|
+
*/
|
|
129
|
+
escapeStructuredDataValue(value) {
|
|
130
|
+
return value
|
|
131
|
+
.replace(/\\/g, "\\\\")
|
|
132
|
+
.replace(/"/g, '\\"')
|
|
133
|
+
.replace(/]/g, "\\]");
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Sanitize message text to prevent log injection.
|
|
137
|
+
* Removes control characters that could manipulate log parsing.
|
|
138
|
+
*/
|
|
139
|
+
sanitizeMessageText(value) {
|
|
140
|
+
// Remove C0 control chars (0x00-0x1F) except tab/newline, and DEL (0x7F)
|
|
141
|
+
// eslint-disable-next-line no-control-regex
|
|
142
|
+
return value.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g, " ").trim();
|
|
143
|
+
}
|
|
144
|
+
computeEntryHash(entry) {
|
|
145
|
+
const payload = JSON.stringify({
|
|
146
|
+
timestamp: entry.timestamp,
|
|
147
|
+
operation: entry.operation,
|
|
148
|
+
keyLabel: entry.keyLabel,
|
|
149
|
+
result: entry.result,
|
|
150
|
+
detail: entry.detail,
|
|
151
|
+
sequenceNumber: this.sequenceNumber,
|
|
152
|
+
});
|
|
153
|
+
return createHash("sha256").update(payload).digest("hex");
|
|
154
|
+
}
|
|
155
|
+
sendUdp(message) {
|
|
156
|
+
if (!this.socket) {
|
|
157
|
+
this.socket = dgram.createSocket("udp4");
|
|
158
|
+
}
|
|
159
|
+
const buffer = Buffer.from(message, "utf-8");
|
|
160
|
+
this.socket.send(buffer, 0, buffer.length, this.config.port, this.config.host, (err) => {
|
|
161
|
+
if (err) {
|
|
162
|
+
// Log to stderr but don't throw — audit logging shouldn't break HSM operations
|
|
163
|
+
console.error(`SyslogAuditLog: failed to send to ${this.config.host}:${this.config.port}: ${err.message}`);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @psavelis/enterprise-blockchain
|
|
3
|
+
*
|
|
4
|
+
* Production-grade enterprise blockchain modules:
|
|
5
|
+
* - MPC (Multiparty Computation) with post-quantum cryptography
|
|
6
|
+
* - HSM (Hardware Security Module) key management
|
|
7
|
+
* - STARK settlement with recursive proof aggregation
|
|
8
|
+
* - Protocol adapters for Fabric, Besu, and Corda
|
|
9
|
+
*
|
|
10
|
+
* @license Apache-2.0
|
|
11
|
+
*/
|
|
12
|
+
export * from "./shared/index.js";
|
|
13
|
+
export * from "./mpc/index.js";
|
|
14
|
+
export * from "./hsm/index.js";
|
|
15
|
+
export * from "./p2mr/index.js";
|
|
16
|
+
export { type AssetType, type AssetConfig, type MirrorAccount, type TransactionType, type TransactionStatus, type LedgerTransaction, type TransactionPayload, type BaseProof, type Tier1Proof, type Tier2BlockProof, type OutboxEntryStatus, type OutboxEntry, type NetTransfer, type SolanaSettlementResult, type BitcoinSettlementResult, type FiatSettlementResult, type DepositEvent, type RaftState, type RaftNode, type AuditRecord, ASSET_CONFIGS, STARK_PRIME, STARK_GENERATOR, FieldElement, IdempotencyKey, ProofCommitment, StateRoot, Amount, sha256, sha256Bytes, pedersenHash, type StarkProofGeneratorPort, type LedgerPersistencePort, type OutboxPort, type OffsetTrackingPort, type SolanaSettlementPort, type BitcoinSettlementPort, type FiatSettlementPort, type OutboxListenerPort, type DilithiumSigningPort, type TransactionSigningPort, type AuditPort, type RaftPort, type ClockPort, type SettlementEvent, type EventEmitterPort, InMemoryLedgerStore, InMemoryOutboxStore, InMemoryOffsetStore, MockStarkAdapter, FlexibleMockStarkAdapter, type MockStarkAdapterConfig, SystemClock, FixedClock, defaultClock, InMemoryEventEmitter, AsyncEventEmitter, defaultEventEmitter, DilithiumSigningAdapter, TransactionSigningAdapter, MockDilithiumAdapter, defaultDilithiumAdapter, createTransactionSigningAdapter, InMemoryAuditLog as StarkInMemoryAuditLog, defaultAuditLog as starkDefaultAuditLog, StarknetProofAdapter, createStarknetProofAdapter, type StarknetProofAdapterConfig, StoneProofAdapter, createStoneProofAdapter, type StoneProofAdapterConfig, SolanaDevnetAdapter, MockSolanaAdapter, type SolanaAdapterConfig, BitcoinTestnetAdapter, MockBitcoinAdapter, type BitcoinAdapterConfig, FiatMockAdapter, MockFiatAdapter, type FiatAdapterConfig, LedgerService, type CreateAccountOptions, type SubmitTransactionOptions, type SubmitTransactionResult, AggregatorService, type AggregationResult, type AggregatorConfig, SettlementService, type SettlementRailResult, type SettleAllRailsResult, type SettlementServiceConfig, type SettlementContext, type CreateContextOptions, createDefaultContext, type ProductionContextOptions, createProductionContext, createTestContext, } from "./stark-settlement/index.js";
|
|
17
|
+
export * from "./credentialing/index.js";
|
|
18
|
+
export * from "./privacy/index.js";
|
|
19
|
+
export * from "./traceability/index.js";
|
|
20
|
+
export * from "./aid-settlement/index.js";
|
|
21
|
+
export * from "./protocols/index.js";
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,cAAc,mBAAmB,CAAC;AAGlC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAGhC,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,EACvB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,aAAa,EAEb,WAAW,EACX,eAAe,EACf,YAAY,EACZ,cAAc,EACd,eAAe,EACf,SAAS,EACT,MAAM,EACN,MAAM,EACN,WAAW,EACX,YAAY,EAEZ,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,sBAAsB,EAC3B,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,gBAAgB,EAErB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,gBAAgB,EAChB,wBAAwB,EACxB,KAAK,sBAAsB,EAC3B,WAAW,EACX,UAAU,EACV,YAAY,EACZ,oBAAoB,EACpB,iBAAiB,EACjB,mBAAmB,EACnB,uBAAuB,EACvB,yBAAyB,EACzB,oBAAoB,EACpB,uBAAuB,EACvB,+BAA+B,EAE/B,gBAAgB,IAAI,qBAAqB,EACzC,eAAe,IAAI,oBAAoB,EACvC,oBAAoB,EACpB,0BAA0B,EAC1B,KAAK,0BAA0B,EAC/B,iBAAiB,EACjB,uBAAuB,EACvB,KAAK,uBAAuB,EAC5B,mBAAmB,EACnB,iBAAiB,EACjB,KAAK,mBAAmB,EACxB,qBAAqB,EACrB,kBAAkB,EAClB,KAAK,oBAAoB,EACzB,eAAe,EACf,eAAe,EACf,KAAK,iBAAiB,EAEtB,aAAa,EACb,KAAK,oBAAoB,EACzB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,iBAAiB,EACjB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,iBAAiB,EACjB,KAAK,oBAAoB,EACzB,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAE5B,KAAK,iBAAiB,EACtB,KAAK,oBAAoB,EACzB,oBAAoB,EACpB,KAAK,wBAAwB,EAC7B,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,6BAA6B,CAAC;AAGrC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,yBAAyB,CAAC;AACxC,cAAc,2BAA2B,CAAC;AAG1C,cAAc,sBAAsB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @psavelis/enterprise-blockchain
|
|
3
|
+
*
|
|
4
|
+
* Production-grade enterprise blockchain modules:
|
|
5
|
+
* - MPC (Multiparty Computation) with post-quantum cryptography
|
|
6
|
+
* - HSM (Hardware Security Module) key management
|
|
7
|
+
* - STARK settlement with recursive proof aggregation
|
|
8
|
+
* - Protocol adapters for Fabric, Besu, and Corda
|
|
9
|
+
*
|
|
10
|
+
* @license Apache-2.0
|
|
11
|
+
*/
|
|
12
|
+
// Core utilities
|
|
13
|
+
export * from "./shared/index.js";
|
|
14
|
+
// Cryptography
|
|
15
|
+
export * from "./mpc/index.js";
|
|
16
|
+
export * from "./hsm/index.js";
|
|
17
|
+
export * from "./p2mr/index.js";
|
|
18
|
+
// Settlement - exclude InMemoryAuditLog to avoid conflict with HSM module
|
|
19
|
+
export { ASSET_CONFIGS,
|
|
20
|
+
// Value Objects
|
|
21
|
+
STARK_PRIME, STARK_GENERATOR, FieldElement, IdempotencyKey, ProofCommitment, StateRoot, Amount, sha256, sha256Bytes, pedersenHash,
|
|
22
|
+
// Infrastructure Adapters
|
|
23
|
+
InMemoryLedgerStore, InMemoryOutboxStore, InMemoryOffsetStore, MockStarkAdapter, FlexibleMockStarkAdapter, SystemClock, FixedClock, defaultClock, InMemoryEventEmitter, AsyncEventEmitter, defaultEventEmitter, DilithiumSigningAdapter, TransactionSigningAdapter, MockDilithiumAdapter, defaultDilithiumAdapter, createTransactionSigningAdapter,
|
|
24
|
+
// Rename STARK InMemoryAuditLog to avoid conflict with HSM
|
|
25
|
+
InMemoryAuditLog as StarkInMemoryAuditLog, defaultAuditLog as starkDefaultAuditLog, StarknetProofAdapter, createStarknetProofAdapter, StoneProofAdapter, createStoneProofAdapter, SolanaDevnetAdapter, MockSolanaAdapter, BitcoinTestnetAdapter, MockBitcoinAdapter, FiatMockAdapter, MockFiatAdapter,
|
|
26
|
+
// Application Services
|
|
27
|
+
LedgerService, AggregatorService, SettlementService, createDefaultContext, createProductionContext, createTestContext, } from "./stark-settlement/index.js";
|
|
28
|
+
// Domain modules
|
|
29
|
+
export * from "./credentialing/index.js";
|
|
30
|
+
export * from "./privacy/index.js";
|
|
31
|
+
export * from "./traceability/index.js";
|
|
32
|
+
export * from "./aid-settlement/index.js";
|
|
33
|
+
// Protocol adapters (types only - no runtime dependencies)
|
|
34
|
+
export * from "./protocols/index.js";
|
|
35
|
+
// NOTE: Integrations are NOT re-exported from the package root to preserve
|
|
36
|
+
// optional peer dependencies. Import them via their dedicated subpath:
|
|
37
|
+
// import { ... } from "@psavelis/enterprise-blockchain/integrations";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts and normalizes error codes from ethers.js error objects.
|
|
3
|
+
* See: https://docs.ethers.org/v6/api/utils/#errors
|
|
4
|
+
*/
|
|
5
|
+
export declare function extractErrorCode(err: unknown): string;
|
|
6
|
+
export declare function extractErrorMessage(err: unknown): string;
|
|
7
|
+
export declare function isInsufficientFunds(err: unknown): boolean;
|
|
8
|
+
export declare function isNonceTooLow(err: unknown): boolean;
|
|
9
|
+
//# sourceMappingURL=error-mapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-mapper.d.ts","sourceRoot":"","sources":["../../../src/integrations/besu-client/error-mapper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAarD;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAExD;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAIzD;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAInD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts and normalizes error codes from ethers.js error objects.
|
|
3
|
+
* See: https://docs.ethers.org/v6/api/utils/#errors
|
|
4
|
+
*/
|
|
5
|
+
export function extractErrorCode(err) {
|
|
6
|
+
const anyErr = err;
|
|
7
|
+
const rawCode = anyErr?.code ?? anyErr?.error?.code ?? anyErr?.info?.error?.code;
|
|
8
|
+
return typeof rawCode === "string" ? rawCode.toUpperCase() : "";
|
|
9
|
+
}
|
|
10
|
+
export function extractErrorMessage(err) {
|
|
11
|
+
return err instanceof Error ? err.message : String(err);
|
|
12
|
+
}
|
|
13
|
+
export function isInsufficientFunds(err) {
|
|
14
|
+
const code = extractErrorCode(err);
|
|
15
|
+
const msg = extractErrorMessage(err).toLowerCase();
|
|
16
|
+
return code === "INSUFFICIENT_FUNDS" || msg.includes("insufficient funds");
|
|
17
|
+
}
|
|
18
|
+
export function isNonceTooLow(err) {
|
|
19
|
+
const code = extractErrorCode(err);
|
|
20
|
+
const msg = extractErrorMessage(err).toLowerCase();
|
|
21
|
+
return code === "NONCE_TOO_LOW" || msg.includes("nonce too low");
|
|
22
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Contract, JsonRpcProvider, NonceManager, Wallet, type ContractRunner, type TransactionRequest } from "ethers";
|
|
2
|
+
import type { PurchaseOrder, SharedOrderView } from "../../privacy/domain/entities.js";
|
|
3
|
+
import { type CircuitBreakerOptions } from "../shared/retry.js";
|
|
4
|
+
import type { BesuPrivateTransactionRequest, BesuHealthStatus, BesuRpcProfile, IBesuGasEstimator, IBesuHealthChecker, IBesuProfileFactory, IBesuProviderFactory, IBesuTransactionBuilder, IBesuTransactionSender } from "./ports.js";
|
|
5
|
+
export type { BesuRpcProfile, BesuPrivateTransactionRequest, BesuHealthStatus, } from "./ports.js";
|
|
6
|
+
export declare class BesuProfileFactory implements IBesuProfileFactory {
|
|
7
|
+
createProfileFromEnv(env?: NodeJS.ProcessEnv): BesuRpcProfile;
|
|
8
|
+
createProfile(profile: BesuRpcProfile): BesuRpcProfile;
|
|
9
|
+
}
|
|
10
|
+
export declare class BesuProviderFactory implements IBesuProviderFactory {
|
|
11
|
+
createProvider(profile: BesuRpcProfile): JsonRpcProvider;
|
|
12
|
+
createSigner(profile: BesuRpcProfile): Wallet;
|
|
13
|
+
createManagedSigner(profile: BesuRpcProfile): NonceManager;
|
|
14
|
+
createContract(profile: BesuRpcProfile, runner?: ContractRunner): Contract;
|
|
15
|
+
}
|
|
16
|
+
export declare class BesuGasEstimator implements IBesuGasEstimator {
|
|
17
|
+
private readonly providerFactory;
|
|
18
|
+
constructor(providerFactory: IBesuProviderFactory);
|
|
19
|
+
estimateGas(profile: BesuRpcProfile, tx: TransactionRequest, gasLimitOverride?: bigint): Promise<bigint>;
|
|
20
|
+
}
|
|
21
|
+
export declare class BesuTransactionBuilder implements IBesuTransactionBuilder {
|
|
22
|
+
buildAnchorOrderTransaction(profile: BesuRpcProfile, order: PurchaseOrder, auditProof: string, gasLimit?: bigint): TransactionRequest;
|
|
23
|
+
buildAudienceViewTransaction(profile: BesuRpcProfile, view: SharedOrderView, gasLimit?: bigint): BesuPrivateTransactionRequest;
|
|
24
|
+
}
|
|
25
|
+
export declare class BesuTransactionSender implements IBesuTransactionSender {
|
|
26
|
+
sendTransaction(signer: NonceManager, tx: TransactionRequest): Promise<string>;
|
|
27
|
+
}
|
|
28
|
+
export declare class BesuHealthChecker implements IBesuHealthChecker {
|
|
29
|
+
private readonly providerFactory;
|
|
30
|
+
constructor(providerFactory: IBesuProviderFactory);
|
|
31
|
+
checkHealth(profile: BesuRpcProfile): Promise<BesuHealthStatus>;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Resilient Besu client with circuit breaker and retry support.
|
|
35
|
+
*
|
|
36
|
+
* Circuit breaker prevents cascading failures when Besu RPC is unavailable.
|
|
37
|
+
* Retry policy handles transient errors (SERVER_ERROR, TIMEOUT) with backoff.
|
|
38
|
+
*
|
|
39
|
+
* NOTE: sketch only — do not store key material as plain strings in production
|
|
40
|
+
*/
|
|
41
|
+
export declare class BesuEthersClientSketch implements IBesuProfileFactory, IBesuProviderFactory, IBesuGasEstimator, IBesuTransactionBuilder, IBesuTransactionSender, IBesuHealthChecker {
|
|
42
|
+
private readonly profileFactory;
|
|
43
|
+
private readonly providerFactory;
|
|
44
|
+
private readonly txBuilder;
|
|
45
|
+
private readonly txSender;
|
|
46
|
+
private readonly healthChecker;
|
|
47
|
+
private readonly circuitBreaker;
|
|
48
|
+
constructor(circuitBreakerOptions?: Partial<CircuitBreakerOptions>);
|
|
49
|
+
createProfileFromEnv(env?: NodeJS.ProcessEnv): BesuRpcProfile;
|
|
50
|
+
createProfile(profile: BesuRpcProfile): BesuRpcProfile;
|
|
51
|
+
createProvider(profile: BesuRpcProfile): JsonRpcProvider;
|
|
52
|
+
createSigner(profile: BesuRpcProfile): Wallet;
|
|
53
|
+
createManagedSigner(profile: BesuRpcProfile): NonceManager;
|
|
54
|
+
createContract(profile: BesuRpcProfile, runner?: ContractRunner): Contract;
|
|
55
|
+
estimateGas(profile: BesuRpcProfile, tx: TransactionRequest, gasLimitOverride?: bigint): Promise<bigint>;
|
|
56
|
+
buildAnchorOrderTransaction(profile: BesuRpcProfile, order: PurchaseOrder, auditProof: string, gasLimit?: bigint): TransactionRequest;
|
|
57
|
+
buildAudienceViewTransaction(profile: BesuRpcProfile, view: SharedOrderView, gasLimit?: bigint): BesuPrivateTransactionRequest;
|
|
58
|
+
sendTransaction(signer: NonceManager, tx: TransactionRequest): Promise<string>;
|
|
59
|
+
checkHealth(profile: BesuRpcProfile): Promise<BesuHealthStatus>;
|
|
60
|
+
/** Get circuit breaker state for monitoring dashboards. */
|
|
61
|
+
getCircuitBreakerHealth(): import("../shared/retry.js").CircuitBreakerHealth;
|
|
62
|
+
/** Reset circuit breaker (use after resolving underlying issues). */
|
|
63
|
+
resetCircuitBreaker(): void;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=index.d.ts.map
|