@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,500 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Value Objects for Aggregated STARK Settlement Layer
|
|
3
|
+
*
|
|
4
|
+
* Immutable, self-validating value types that encapsulate domain concepts:
|
|
5
|
+
* - FieldElement: Arithmetic in the STARK prime field
|
|
6
|
+
* - IdempotencyKey: Collision-resistant exactly-once keys
|
|
7
|
+
* - ProofCommitment: Succinct commitment to a STARK proof
|
|
8
|
+
* - StateRoot: Merkle root of ledger state
|
|
9
|
+
*
|
|
10
|
+
* Value objects are equal if their values are equal (no identity).
|
|
11
|
+
* All validation happens at construction time.
|
|
12
|
+
*
|
|
13
|
+
* @see modules/mpc/src/field.ts for field arithmetic patterns
|
|
14
|
+
*/
|
|
15
|
+
import { createHash, randomBytes } from "node:crypto";
|
|
16
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
17
|
+
// STARK Field Constants
|
|
18
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
19
|
+
/**
|
|
20
|
+
* STARK prime field: 2^251 + 17 * 2^192 + 1
|
|
21
|
+
* This is the prime used by StarkNet/Cairo for field operations.
|
|
22
|
+
*/
|
|
23
|
+
export const STARK_PRIME = 0x800000000000011000000000000000000000000000000000000000000000001n;
|
|
24
|
+
/**
|
|
25
|
+
* Generator of the multiplicative group of the STARK field.
|
|
26
|
+
*/
|
|
27
|
+
export const STARK_GENERATOR = 3n;
|
|
28
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
29
|
+
// FieldElement
|
|
30
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
31
|
+
/**
|
|
32
|
+
* An element in the STARK prime field.
|
|
33
|
+
*
|
|
34
|
+
* Supports modular arithmetic operations and serialization.
|
|
35
|
+
* Immutable - all operations return new instances.
|
|
36
|
+
*/
|
|
37
|
+
export class FieldElement {
|
|
38
|
+
value;
|
|
39
|
+
prime;
|
|
40
|
+
constructor(value, prime = STARK_PRIME) {
|
|
41
|
+
this.value = value;
|
|
42
|
+
this.prime = prime;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Create a field element from a bigint.
|
|
46
|
+
* Value is automatically reduced modulo prime.
|
|
47
|
+
*/
|
|
48
|
+
static fromBigInt(value, prime = STARK_PRIME) {
|
|
49
|
+
const reduced = ((value % prime) + prime) % prime;
|
|
50
|
+
return new FieldElement(reduced, prime);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Create a field element from a hex string.
|
|
54
|
+
*/
|
|
55
|
+
static fromHex(hex, prime = STARK_PRIME) {
|
|
56
|
+
const cleanHex = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
57
|
+
return FieldElement.fromBigInt(BigInt("0x" + cleanHex), prime);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Create a field element from a byte array (big-endian).
|
|
61
|
+
*/
|
|
62
|
+
static fromBytes(bytes, prime = STARK_PRIME) {
|
|
63
|
+
let value = 0n;
|
|
64
|
+
for (const byte of bytes) {
|
|
65
|
+
value = (value << 8n) | BigInt(byte);
|
|
66
|
+
}
|
|
67
|
+
return FieldElement.fromBigInt(value, prime);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Generate a random field element.
|
|
71
|
+
*/
|
|
72
|
+
static random(prime = STARK_PRIME) {
|
|
73
|
+
const byteLength = Math.ceil(prime.toString(2).length / 8);
|
|
74
|
+
let value;
|
|
75
|
+
do {
|
|
76
|
+
const bytes = randomBytes(byteLength);
|
|
77
|
+
value = BigInt("0x" + bytes.toString("hex"));
|
|
78
|
+
} while (value >= prime);
|
|
79
|
+
return new FieldElement(value, prime);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Zero element in the field.
|
|
83
|
+
*/
|
|
84
|
+
static zero(prime = STARK_PRIME) {
|
|
85
|
+
return new FieldElement(0n, prime);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* One (multiplicative identity) in the field.
|
|
89
|
+
*/
|
|
90
|
+
static one(prime = STARK_PRIME) {
|
|
91
|
+
return new FieldElement(1n, prime);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Modular addition: (this + other) mod prime
|
|
95
|
+
*/
|
|
96
|
+
add(other) {
|
|
97
|
+
this.#assertSamePrime(other);
|
|
98
|
+
return FieldElement.fromBigInt(this.value + other.value, this.prime);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Modular subtraction: (this - other) mod prime
|
|
102
|
+
*/
|
|
103
|
+
sub(other) {
|
|
104
|
+
this.#assertSamePrime(other);
|
|
105
|
+
return FieldElement.fromBigInt(this.value - other.value, this.prime);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Modular multiplication: (this * other) mod prime
|
|
109
|
+
*/
|
|
110
|
+
mul(other) {
|
|
111
|
+
this.#assertSamePrime(other);
|
|
112
|
+
return FieldElement.fromBigInt(this.value * other.value, this.prime);
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Modular exponentiation: this^exp mod prime
|
|
116
|
+
* Uses square-and-multiply for O(log exp) complexity.
|
|
117
|
+
*/
|
|
118
|
+
pow(exp) {
|
|
119
|
+
let result = FieldElement.one(this.prime);
|
|
120
|
+
let base = FieldElement.fromBigInt(this.value, this.prime);
|
|
121
|
+
let e = exp;
|
|
122
|
+
while (e > 0n) {
|
|
123
|
+
if (e & 1n) {
|
|
124
|
+
result = result.mul(base);
|
|
125
|
+
}
|
|
126
|
+
e >>= 1n;
|
|
127
|
+
base = base.mul(base);
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Modular multiplicative inverse: this^(-1) mod prime
|
|
133
|
+
* Uses Fermat's little theorem: a^(-1) = a^(p-2) mod p
|
|
134
|
+
*/
|
|
135
|
+
inverse() {
|
|
136
|
+
if (this.value === 0n) {
|
|
137
|
+
throw new Error("Cannot compute inverse of zero");
|
|
138
|
+
}
|
|
139
|
+
return this.pow(this.prime - 2n);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Modular division: this / other mod prime
|
|
143
|
+
*/
|
|
144
|
+
div(other) {
|
|
145
|
+
return this.mul(other.inverse());
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Negation: -this mod prime
|
|
149
|
+
*/
|
|
150
|
+
neg() {
|
|
151
|
+
return FieldElement.fromBigInt(-this.value, this.prime);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Check if this is zero.
|
|
155
|
+
*/
|
|
156
|
+
isZero() {
|
|
157
|
+
return this.value === 0n;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Check equality with another field element.
|
|
161
|
+
*/
|
|
162
|
+
equals(other) {
|
|
163
|
+
return this.value === other.value && this.prime === other.prime;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Convert to hex string (64 characters, zero-padded).
|
|
167
|
+
*/
|
|
168
|
+
toHex() {
|
|
169
|
+
return this.value.toString(16).padStart(64, "0");
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Convert to byte array (big-endian, 32 bytes).
|
|
173
|
+
*/
|
|
174
|
+
toBytes() {
|
|
175
|
+
const hex = this.toHex();
|
|
176
|
+
const bytes = new Uint8Array(32);
|
|
177
|
+
for (let i = 0; i < 32; i++) {
|
|
178
|
+
bytes[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
179
|
+
}
|
|
180
|
+
return bytes;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* String representation for debugging.
|
|
184
|
+
*/
|
|
185
|
+
toString() {
|
|
186
|
+
return `FieldElement(0x${this.toHex()})`;
|
|
187
|
+
}
|
|
188
|
+
#assertSamePrime(other) {
|
|
189
|
+
if (this.prime !== other.prime) {
|
|
190
|
+
throw new Error("Cannot operate on field elements with different primes");
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
195
|
+
// IdempotencyKey
|
|
196
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
197
|
+
/**
|
|
198
|
+
* A collision-resistant idempotency key for exactly-once processing.
|
|
199
|
+
*
|
|
200
|
+
* Generated from a combination of source, transaction ID, and timestamp.
|
|
201
|
+
* SHA-256 hash ensures collision resistance.
|
|
202
|
+
*/
|
|
203
|
+
export class IdempotencyKey {
|
|
204
|
+
value;
|
|
205
|
+
constructor(value) {
|
|
206
|
+
this.value = value;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Create an idempotency key from source components.
|
|
210
|
+
*/
|
|
211
|
+
static create(source, txId, timestamp) {
|
|
212
|
+
const input = `${source}:${txId}:${timestamp}`;
|
|
213
|
+
const hash = createHash("sha256").update(input).digest("hex");
|
|
214
|
+
return new IdempotencyKey(hash);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Create from an existing key string (must be 64 hex chars).
|
|
218
|
+
*/
|
|
219
|
+
static fromString(value) {
|
|
220
|
+
if (!/^[a-f0-9]{64}$/i.test(value)) {
|
|
221
|
+
throw new Error("IdempotencyKey must be 64 hex characters");
|
|
222
|
+
}
|
|
223
|
+
return new IdempotencyKey(value.toLowerCase());
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Generate a random idempotency key.
|
|
227
|
+
*/
|
|
228
|
+
static random() {
|
|
229
|
+
const bytes = randomBytes(32);
|
|
230
|
+
return new IdempotencyKey(bytes.toString("hex"));
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Check equality with another key.
|
|
234
|
+
*/
|
|
235
|
+
equals(other) {
|
|
236
|
+
return this.value === other.value;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* String representation.
|
|
240
|
+
*/
|
|
241
|
+
toString() {
|
|
242
|
+
return this.value;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
246
|
+
// ProofCommitment
|
|
247
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
248
|
+
/**
|
|
249
|
+
* A succinct commitment to a STARK proof.
|
|
250
|
+
*
|
|
251
|
+
* Used for on-chain anchoring without storing the full proof.
|
|
252
|
+
* Computed as SHA-256(proofId || starkProof || publicInputs).
|
|
253
|
+
*/
|
|
254
|
+
export class ProofCommitment {
|
|
255
|
+
value;
|
|
256
|
+
constructor(value) {
|
|
257
|
+
this.value = value;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Create a commitment from proof components.
|
|
261
|
+
*/
|
|
262
|
+
static create(proofId, starkProof, publicInputs) {
|
|
263
|
+
const hash = createHash("sha256");
|
|
264
|
+
hash.update(proofId);
|
|
265
|
+
hash.update(starkProof);
|
|
266
|
+
hash.update(publicInputs.join(":"));
|
|
267
|
+
return new ProofCommitment(hash.digest("hex"));
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Create from an existing commitment string (must be 64 hex chars).
|
|
271
|
+
*/
|
|
272
|
+
static fromString(value) {
|
|
273
|
+
if (!/^[a-f0-9]{64}$/i.test(value)) {
|
|
274
|
+
throw new Error("ProofCommitment must be 64 hex characters");
|
|
275
|
+
}
|
|
276
|
+
return new ProofCommitment(value.toLowerCase());
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Check equality with another commitment.
|
|
280
|
+
*/
|
|
281
|
+
equals(other) {
|
|
282
|
+
return this.value === other.value;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* String representation.
|
|
286
|
+
*/
|
|
287
|
+
toString() {
|
|
288
|
+
return this.value;
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Convert to bytes for on-chain storage.
|
|
292
|
+
*/
|
|
293
|
+
toBytes() {
|
|
294
|
+
const bytes = new Uint8Array(32);
|
|
295
|
+
for (let i = 0; i < 32; i++) {
|
|
296
|
+
bytes[i] = parseInt(this.value.slice(i * 2, i * 2 + 2), 16);
|
|
297
|
+
}
|
|
298
|
+
return bytes;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
302
|
+
// StateRoot
|
|
303
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
304
|
+
/**
|
|
305
|
+
* A Merkle root representing the state of the ledger.
|
|
306
|
+
*
|
|
307
|
+
* Computed as the root of a Merkle tree over all account states.
|
|
308
|
+
* Used to prove state transitions in STARK proofs.
|
|
309
|
+
*/
|
|
310
|
+
export class StateRoot {
|
|
311
|
+
value;
|
|
312
|
+
constructor(value) {
|
|
313
|
+
this.value = value;
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Create a state root from a hex string.
|
|
317
|
+
*/
|
|
318
|
+
static fromHex(hex) {
|
|
319
|
+
const clean = hex.startsWith("0x") ? hex.slice(2) : hex;
|
|
320
|
+
if (!/^[a-f0-9]{64}$/i.test(clean)) {
|
|
321
|
+
throw new Error("StateRoot must be 64 hex characters");
|
|
322
|
+
}
|
|
323
|
+
return new StateRoot(clean.toLowerCase());
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Create the genesis (empty) state root.
|
|
327
|
+
*/
|
|
328
|
+
static genesis() {
|
|
329
|
+
// SHA-256 of empty string, represents empty state
|
|
330
|
+
const hash = createHash("sha256").update("").digest("hex");
|
|
331
|
+
return new StateRoot(hash);
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Compute a new state root by hashing with another value.
|
|
335
|
+
* Used for incremental state updates.
|
|
336
|
+
*/
|
|
337
|
+
hash(data) {
|
|
338
|
+
const hash = createHash("sha256");
|
|
339
|
+
hash.update(Buffer.from(this.value, "hex"));
|
|
340
|
+
hash.update(data);
|
|
341
|
+
return new StateRoot(hash.digest("hex"));
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Check equality with another state root.
|
|
345
|
+
*/
|
|
346
|
+
equals(other) {
|
|
347
|
+
return this.value === other.value;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
350
|
+
* String representation.
|
|
351
|
+
*/
|
|
352
|
+
toString() {
|
|
353
|
+
return `0x${this.value}`;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Convert to bytes.
|
|
357
|
+
*/
|
|
358
|
+
toBytes() {
|
|
359
|
+
const bytes = new Uint8Array(32);
|
|
360
|
+
for (let i = 0; i < 32; i++) {
|
|
361
|
+
bytes[i] = parseInt(this.value.slice(i * 2, i * 2 + 2), 16);
|
|
362
|
+
}
|
|
363
|
+
return bytes;
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Convert to field element for STARK circuits.
|
|
367
|
+
*/
|
|
368
|
+
toFieldElement() {
|
|
369
|
+
return FieldElement.fromHex(this.value);
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
373
|
+
// Amount
|
|
374
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
375
|
+
/**
|
|
376
|
+
* A validated amount with decimal conversion utilities.
|
|
377
|
+
*
|
|
378
|
+
* Stores value in atomic units (lamports, satoshis, cents).
|
|
379
|
+
* Provides conversion to/from human-readable format.
|
|
380
|
+
*/
|
|
381
|
+
export class Amount {
|
|
382
|
+
atomicValue;
|
|
383
|
+
decimals;
|
|
384
|
+
constructor(atomicValue, decimals) {
|
|
385
|
+
this.atomicValue = atomicValue;
|
|
386
|
+
this.decimals = decimals;
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Create from atomic units (e.g., lamports, satoshis, cents).
|
|
390
|
+
*/
|
|
391
|
+
static fromAtomic(value, decimals) {
|
|
392
|
+
if (value < 0n) {
|
|
393
|
+
throw new Error("Amount cannot be negative");
|
|
394
|
+
}
|
|
395
|
+
return new Amount(value, decimals);
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Create from a decimal string (e.g., "1.5" SOL = 1500000000 lamports).
|
|
399
|
+
*/
|
|
400
|
+
static fromDecimal(value, decimals) {
|
|
401
|
+
// Reject negative values
|
|
402
|
+
if (value.startsWith("-")) {
|
|
403
|
+
throw new Error("Amount cannot be negative");
|
|
404
|
+
}
|
|
405
|
+
const parts = value.split(".");
|
|
406
|
+
const wholePart = BigInt(parts[0] || "0");
|
|
407
|
+
const fracPart = parts[1] || "";
|
|
408
|
+
// Pad or truncate fractional part to match decimals
|
|
409
|
+
const paddedFrac = fracPart.padEnd(decimals, "0").slice(0, decimals);
|
|
410
|
+
const fracValue = BigInt(paddedFrac || "0");
|
|
411
|
+
const multiplier = 10n ** BigInt(decimals);
|
|
412
|
+
const atomicValue = wholePart * multiplier + fracValue;
|
|
413
|
+
return new Amount(atomicValue, decimals);
|
|
414
|
+
}
|
|
415
|
+
/**
|
|
416
|
+
* Add two amounts.
|
|
417
|
+
*/
|
|
418
|
+
add(other) {
|
|
419
|
+
this.#assertSameDecimals(other);
|
|
420
|
+
return new Amount(this.atomicValue + other.atomicValue, this.decimals);
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Subtract another amount.
|
|
424
|
+
*/
|
|
425
|
+
sub(other) {
|
|
426
|
+
this.#assertSameDecimals(other);
|
|
427
|
+
const result = this.atomicValue - other.atomicValue;
|
|
428
|
+
if (result < 0n) {
|
|
429
|
+
throw new Error("Amount subtraction would result in negative value");
|
|
430
|
+
}
|
|
431
|
+
return new Amount(result, this.decimals);
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Check if this amount is zero.
|
|
435
|
+
*/
|
|
436
|
+
isZero() {
|
|
437
|
+
return this.atomicValue === 0n;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* Compare with another amount.
|
|
441
|
+
* Returns -1 if this < other, 0 if equal, 1 if this > other.
|
|
442
|
+
*/
|
|
443
|
+
compare(other) {
|
|
444
|
+
this.#assertSameDecimals(other);
|
|
445
|
+
if (this.atomicValue < other.atomicValue)
|
|
446
|
+
return -1;
|
|
447
|
+
if (this.atomicValue > other.atomicValue)
|
|
448
|
+
return 1;
|
|
449
|
+
return 0;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Convert to decimal string (e.g., "1.500000000" for 1.5 SOL).
|
|
453
|
+
*/
|
|
454
|
+
toDecimal() {
|
|
455
|
+
const multiplier = 10n ** BigInt(this.decimals);
|
|
456
|
+
const wholePart = this.atomicValue / multiplier;
|
|
457
|
+
const fracPart = this.atomicValue % multiplier;
|
|
458
|
+
const fracStr = fracPart.toString().padStart(this.decimals, "0");
|
|
459
|
+
return `${wholePart}.${fracStr}`;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* String representation.
|
|
463
|
+
*/
|
|
464
|
+
toString() {
|
|
465
|
+
return this.toDecimal();
|
|
466
|
+
}
|
|
467
|
+
#assertSameDecimals(other) {
|
|
468
|
+
if (this.decimals !== other.decimals) {
|
|
469
|
+
throw new Error("Cannot operate on amounts with different decimal places");
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
474
|
+
// Hash Utilities
|
|
475
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
476
|
+
/**
|
|
477
|
+
* Compute SHA-256 hash of a string.
|
|
478
|
+
*/
|
|
479
|
+
export function sha256(input) {
|
|
480
|
+
return createHash("sha256").update(input).digest("hex");
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Compute SHA-256 hash of bytes.
|
|
484
|
+
*/
|
|
485
|
+
export function sha256Bytes(input) {
|
|
486
|
+
const hash = createHash("sha256").update(input).digest();
|
|
487
|
+
return new Uint8Array(hash);
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Compute Pedersen hash (placeholder - actual implementation would use Cairo's Pedersen).
|
|
491
|
+
* For now, uses SHA-256 as a stand-in.
|
|
492
|
+
*/
|
|
493
|
+
export function pedersenHash(a, b) {
|
|
494
|
+
const hash = createHash("sha256");
|
|
495
|
+
hash.update(a.toBytes());
|
|
496
|
+
hash.update(b.toBytes());
|
|
497
|
+
const result = hash.digest();
|
|
498
|
+
// Reduce to field element
|
|
499
|
+
return FieldElement.fromBytes(result);
|
|
500
|
+
}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @enterprise-blockchain/stark-settlement
|
|
3
|
+
*
|
|
4
|
+
* Aggregated STARK Settlement Layer with Recursive Proof Composition
|
|
5
|
+
*
|
|
6
|
+
* A production-grade, quantum-resistant settlement system that:
|
|
7
|
+
* - Uses zk-STARK proofs for verifiable state transitions
|
|
8
|
+
* - Aggregates thousands of transactions into single block proofs
|
|
9
|
+
* - Settles to multiple external chains (Solana, Bitcoin, Fiat)
|
|
10
|
+
* - Provides post-quantum security via ML-DSA-65 signatures
|
|
11
|
+
*
|
|
12
|
+
* Architecture:
|
|
13
|
+
* - Hexagonal (ports & adapters) with no SDK imports in domain layer
|
|
14
|
+
* - 3-tier recursive proof aggregation (Base → Tier-1 → Tier-2)
|
|
15
|
+
* - Exactly-once settlement semantics via idempotency keys
|
|
16
|
+
* - Full observability with OpenTelemetry
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import {
|
|
21
|
+
* LedgerService,
|
|
22
|
+
* AggregatorService,
|
|
23
|
+
* SettlementService,
|
|
24
|
+
* createDefaultContext,
|
|
25
|
+
* } from "@enterprise-blockchain/stark-settlement";
|
|
26
|
+
*
|
|
27
|
+
* // Create services with default adapters
|
|
28
|
+
* const ctx = createDefaultContext();
|
|
29
|
+
* const ledger = new LedgerService(ctx);
|
|
30
|
+
* const aggregator = new AggregatorService(ctx);
|
|
31
|
+
* const settler = new SettlementService(ctx);
|
|
32
|
+
*
|
|
33
|
+
* // Submit a transaction
|
|
34
|
+
* const tx = await ledger.submitTransaction({
|
|
35
|
+
* type: "transfer",
|
|
36
|
+
* fromAccountId: "alice",
|
|
37
|
+
* toAccountId: "bob",
|
|
38
|
+
* assetType: "SOL",
|
|
39
|
+
* amount: 1000000000n, // 1 SOL in lamports
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* // Generate proofs and settle
|
|
43
|
+
* const blockProof = await aggregator.processToBlockProof();
|
|
44
|
+
* const result = await settler.settleAllRails(blockProof);
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @packageDocumentation
|
|
48
|
+
*/
|
|
49
|
+
export type { AssetType, AssetConfig, MirrorAccount, TransactionType, TransactionStatus, LedgerTransaction, TransactionPayload, BaseProof, Tier1Proof, Tier2BlockProof, OutboxEntryStatus, OutboxEntry, NetTransfer, SolanaSettlementResult, BitcoinSettlementResult, FiatSettlementResult, DepositEvent, RaftState, RaftNode, AuditRecord, } from "./domain/entities.js";
|
|
50
|
+
export { ASSET_CONFIGS } from "./domain/entities.js";
|
|
51
|
+
export { STARK_PRIME, STARK_GENERATOR, FieldElement, IdempotencyKey, ProofCommitment, StateRoot, Amount, sha256, sha256Bytes, pedersenHash, } from "./domain/value-objects.js";
|
|
52
|
+
export type { StarkProofGeneratorPort, LedgerPersistencePort, OutboxPort, OffsetTrackingPort, SolanaSettlementPort, BitcoinSettlementPort, FiatSettlementPort, OutboxListenerPort, DilithiumSigningPort, TransactionSigningPort, AuditPort, RaftPort, ClockPort, SettlementEvent, EventEmitterPort, } from "./domain/ports.js";
|
|
53
|
+
export { InMemoryLedgerStore } from "./infrastructure/persistence/ledger-store.js";
|
|
54
|
+
export { InMemoryOutboxStore } from "./infrastructure/persistence/outbox-store.js";
|
|
55
|
+
export { InMemoryOffsetStore } from "./infrastructure/persistence/offset-store.js";
|
|
56
|
+
export { MockStarkAdapter, FlexibleMockStarkAdapter, } from "./infrastructure/adapters/mock-stark-adapter.js";
|
|
57
|
+
export type { MockStarkAdapterConfig } from "./infrastructure/adapters/mock-stark-adapter.js";
|
|
58
|
+
export { SystemClock, FixedClock, defaultClock, } from "./infrastructure/adapters/clock-adapter.js";
|
|
59
|
+
export { InMemoryEventEmitter, AsyncEventEmitter, defaultEventEmitter, } from "./infrastructure/adapters/event-emitter-adapter.js";
|
|
60
|
+
export { DilithiumSigningAdapter, TransactionSigningAdapter, MockDilithiumAdapter, defaultDilithiumAdapter, createTransactionSigningAdapter, } from "./infrastructure/adapters/dilithium-adapter.js";
|
|
61
|
+
export { InMemoryAuditLog, defaultAuditLog, } from "./infrastructure/adapters/audit-adapter.js";
|
|
62
|
+
export { StarknetProofAdapter, createStarknetProofAdapter, } from "./infrastructure/adapters/starknet-proof-adapter.js";
|
|
63
|
+
export type { StarknetProofAdapterConfig } from "./infrastructure/adapters/starknet-proof-adapter.js";
|
|
64
|
+
export { StoneProofAdapter, createStoneProofAdapter, } from "./infrastructure/adapters/stone-proof-adapter.js";
|
|
65
|
+
export type { StoneProofAdapterConfig } from "./infrastructure/adapters/stone-proof-adapter.js";
|
|
66
|
+
export { SolanaDevnetAdapter, MockSolanaAdapter, } from "./infrastructure/adapters/solana-adapter.js";
|
|
67
|
+
export type { SolanaAdapterConfig } from "./infrastructure/adapters/solana-adapter.js";
|
|
68
|
+
export { BitcoinTestnetAdapter, MockBitcoinAdapter, } from "./infrastructure/adapters/bitcoin-adapter.js";
|
|
69
|
+
export type { BitcoinAdapterConfig } from "./infrastructure/adapters/bitcoin-adapter.js";
|
|
70
|
+
export { FiatMockAdapter, MockFiatAdapter, } from "./infrastructure/adapters/fiat-adapter.js";
|
|
71
|
+
export type { FiatAdapterConfig } from "./infrastructure/adapters/fiat-adapter.js";
|
|
72
|
+
export { LedgerService } from "./application/ledger-service.js";
|
|
73
|
+
export type { CreateAccountOptions, SubmitTransactionOptions, SubmitTransactionResult, } from "./application/ledger-service.js";
|
|
74
|
+
export { AggregatorService } from "./application/aggregator-service.js";
|
|
75
|
+
export type { AggregationResult, AggregatorConfig, } from "./application/aggregator-service.js";
|
|
76
|
+
export { SettlementService } from "./application/settlement-service.js";
|
|
77
|
+
export type { SettlementRailResult, SettleAllRailsResult, SettlementServiceConfig, } from "./application/settlement-service.js";
|
|
78
|
+
import type { StarkProofGeneratorPort, LedgerPersistencePort, OutboxPort, OffsetTrackingPort, DilithiumSigningPort, TransactionSigningPort, AuditPort, ClockPort, EventEmitterPort } from "./domain/ports.js";
|
|
79
|
+
/**
|
|
80
|
+
* Context containing all dependencies for the settlement layer.
|
|
81
|
+
*
|
|
82
|
+
* Follows dependency injection pattern for testability.
|
|
83
|
+
*/
|
|
84
|
+
export interface SettlementContext {
|
|
85
|
+
readonly clock: ClockPort;
|
|
86
|
+
readonly ledgerStore: LedgerPersistencePort;
|
|
87
|
+
readonly outboxStore: OutboxPort;
|
|
88
|
+
readonly offsetStore: OffsetTrackingPort;
|
|
89
|
+
readonly starkProver: StarkProofGeneratorPort;
|
|
90
|
+
readonly dilithium: DilithiumSigningPort;
|
|
91
|
+
readonly transactionSigning: TransactionSigningPort;
|
|
92
|
+
readonly auditLog: AuditPort;
|
|
93
|
+
readonly events: EventEmitterPort;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Options for creating a settlement context.
|
|
97
|
+
*/
|
|
98
|
+
export interface CreateContextOptions {
|
|
99
|
+
/** Clock implementation (default: SystemClock) */
|
|
100
|
+
clock?: ClockPort;
|
|
101
|
+
/** Ledger store implementation (default: InMemoryLedgerStore) */
|
|
102
|
+
ledgerStore?: LedgerPersistencePort;
|
|
103
|
+
/** Outbox store implementation (default: InMemoryOutboxStore) */
|
|
104
|
+
outboxStore?: OutboxPort;
|
|
105
|
+
/** Offset store implementation (default: InMemoryOffsetStore) */
|
|
106
|
+
offsetStore?: OffsetTrackingPort;
|
|
107
|
+
/** STARK prover implementation (default: FlexibleMockStarkAdapter) */
|
|
108
|
+
starkProver?: StarkProofGeneratorPort;
|
|
109
|
+
/** Dilithium signing implementation (default: DilithiumSigningAdapter) */
|
|
110
|
+
dilithium?: DilithiumSigningPort;
|
|
111
|
+
/** Transaction signing implementation (default: TransactionSigningAdapter) */
|
|
112
|
+
transactionSigning?: TransactionSigningPort;
|
|
113
|
+
/** Audit log implementation (default: InMemoryAuditLog) */
|
|
114
|
+
auditLog?: AuditPort;
|
|
115
|
+
/** Event emitter implementation (default: InMemoryEventEmitter) */
|
|
116
|
+
events?: EventEmitterPort;
|
|
117
|
+
/** Tier-1 batch size for mock STARK adapter (default: 8) */
|
|
118
|
+
tier1BatchSize?: number;
|
|
119
|
+
/** Tier-2 batch size for mock STARK adapter (default: 4) */
|
|
120
|
+
tier2BatchSize?: number;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Create a settlement context with default or custom adapters.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```typescript
|
|
127
|
+
* // Default context (all in-memory, mock STARK)
|
|
128
|
+
* const ctx = createDefaultContext();
|
|
129
|
+
*
|
|
130
|
+
* // Custom batch sizes for demos
|
|
131
|
+
* const demoCtx = createDefaultContext({
|
|
132
|
+
* tier1BatchSize: 4,
|
|
133
|
+
* tier2BatchSize: 2,
|
|
134
|
+
* });
|
|
135
|
+
*
|
|
136
|
+
* // Custom adapters (clock must be passed to StarknetProofAdapter)
|
|
137
|
+
* const clock = new SystemClock();
|
|
138
|
+
* const prodCtx = createDefaultContext({
|
|
139
|
+
* clock,
|
|
140
|
+
* starkProver: new StarknetProofAdapter(clock),
|
|
141
|
+
* ledgerStore: new PostgresLedgerStore(connectionString),
|
|
142
|
+
* });
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
export declare function createDefaultContext(options?: CreateContextOptions): SettlementContext;
|
|
146
|
+
/**
|
|
147
|
+
* Options specific to production context.
|
|
148
|
+
*/
|
|
149
|
+
export interface ProductionContextOptions extends Omit<CreateContextOptions, "tier1BatchSize" | "tier2BatchSize"> {
|
|
150
|
+
/** Stone prover gRPC endpoint (default: localhost:10000) */
|
|
151
|
+
proverEndpoint?: string;
|
|
152
|
+
/** Path to compiled Cairo artifacts (default: ./cairo/artifacts) */
|
|
153
|
+
cairoArtifactsPath?: string;
|
|
154
|
+
/** Use mock adapter instead of Stone prover (default: false) */
|
|
155
|
+
useMockProver?: boolean;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Create a context for production with full batch sizes.
|
|
159
|
+
*
|
|
160
|
+
* By default, uses the StoneProofAdapter for real STARK proof generation.
|
|
161
|
+
* Set useMockProver: true to use the mock adapter for testing without Docker.
|
|
162
|
+
*
|
|
163
|
+
* Requires 128 * 64 = 8,192 transactions per block proof.
|
|
164
|
+
*/
|
|
165
|
+
export declare function createProductionContext(options?: ProductionContextOptions): SettlementContext;
|
|
166
|
+
/**
|
|
167
|
+
* Create a context for testing with minimal batch sizes.
|
|
168
|
+
*
|
|
169
|
+
* Requires only 2 * 2 = 4 transactions per block proof.
|
|
170
|
+
*/
|
|
171
|
+
export declare function createTestContext(options?: Omit<CreateContextOptions, "tier1BatchSize" | "tier2BatchSize">): SettlementContext;
|
|
172
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/stark-settlement/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAMH,YAAY,EACV,SAAS,EACT,WAAW,EACX,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,SAAS,EACT,UAAU,EACV,eAAe,E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