@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,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @psavelis/enterprise-blockchain/p2mr
|
|
3
|
+
*
|
|
4
|
+
* BIP-360-inspired Pay-to-Merkle-Root quantum-safe outputs.
|
|
5
|
+
*
|
|
6
|
+
* P2MR eliminates the "harvest now, decrypt later" quantum threat by:
|
|
7
|
+
* 1. Storing ONLY a Merkle root on-chain (no public keys exposed)
|
|
8
|
+
* 2. Using post-quantum ML-DSA-65 signatures for spending
|
|
9
|
+
* 3. Revealing public keys only at spend time (minimizing exposure window)
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import {
|
|
14
|
+
* createP2MROutput,
|
|
15
|
+
* createSingleSigLeaf,
|
|
16
|
+
* createTimelockLeaf,
|
|
17
|
+
* buildSpendProof,
|
|
18
|
+
* verifySpendProofStructure,
|
|
19
|
+
* } from "@psavelis/enterprise-blockchain/p2mr";
|
|
20
|
+
*
|
|
21
|
+
* // Create an output with two spending paths
|
|
22
|
+
* const { output, tree } = createP2MROutput({
|
|
23
|
+
* leaves: [
|
|
24
|
+
* createSingleSigLeaf(primaryKeyHash), // Path 0: primary key
|
|
25
|
+
* createTimelockLeaf(backupKeyHash, locktime), // Path 1: backup after locktime
|
|
26
|
+
* ],
|
|
27
|
+
* value: 1_000_000n,
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* // Store `output` on-chain (only merkleRoot exposed)
|
|
31
|
+
* // Keep `tree` off-chain for generating spend proofs
|
|
32
|
+
*
|
|
33
|
+
* // Later, spend via path 0:
|
|
34
|
+
* const proof = buildSpendProof({
|
|
35
|
+
* outputId: output.outputId,
|
|
36
|
+
* tree,
|
|
37
|
+
* leafIndex: 0,
|
|
38
|
+
* witness: {
|
|
39
|
+
* publicKeys: [primaryKey],
|
|
40
|
+
* signatures: [signature],
|
|
41
|
+
* },
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // Verify proof structure and Merkle path
|
|
45
|
+
* const result = verifySpendProofStructure(proof, output);
|
|
46
|
+
* console.log(result.valid); // true
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @packageDocumentation
|
|
50
|
+
*/
|
|
51
|
+
// ---------------------------------------------------------------------------
|
|
52
|
+
// Merkle Tree
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
export { MerkleTree, canonicalJSON, hashScriptLeaf } from "./merkle-tree.js";
|
|
55
|
+
export { validateScriptLeaf, createSingleSigLeaf, createTimelockLeaf, createMultisigLeaf, createHsmAttestedLeaf, } from "./script-leaf.js";
|
|
56
|
+
export { createP2MROutput, P2MROutputStore } from "./p2mr-output.js";
|
|
57
|
+
export { buildSpendProof, validateSpendProofStructure, verifyMerkleProof, verifySpendProofStructure, } from "./spend-proof.js";
|
|
58
|
+
export { interpretScript, hashPublicKey, configureInterpreter, resetInterpreter, } from "./script-interpreter.js";
|
|
59
|
+
export { MlDsaSignatureVerifier, Sha256Hasher, defaultSignatureVerifier, defaultHasher, } from "./adapters.js";
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merkle Tree for P2MR Script Trees
|
|
3
|
+
*
|
|
4
|
+
* Constructs a binary Merkle tree from an array of ScriptLeaf nodes.
|
|
5
|
+
* Provides proof generation and verification for spending P2MR outputs.
|
|
6
|
+
*
|
|
7
|
+
* Construction algorithm:
|
|
8
|
+
* 1. Each leaf = SHA-256(canonicalJSON(ScriptLeaf)) → 64-char hex string
|
|
9
|
+
* 2. Internal nodes = SHA-256(leftHex + rightHex) where + is string concatenation
|
|
10
|
+
* (i.e., hashing the 128-char hex string, not raw 64 bytes)
|
|
11
|
+
* 3. Odd leaf count: duplicate last leaf for balanced tree
|
|
12
|
+
* 4. Root = final 32-byte hash (64 hex chars)
|
|
13
|
+
*
|
|
14
|
+
* NOTE: This implementation hashes hex-encoded strings, not raw bytes.
|
|
15
|
+
* For example, sha256hex("abc...def" + "012...345") hashes the 128-character
|
|
16
|
+
* hex string, producing deterministic results portable across platforms.
|
|
17
|
+
*/
|
|
18
|
+
import type { ScriptLeaf, MerkleProofNode } from "./types.js";
|
|
19
|
+
/**
|
|
20
|
+
* Serialize an object to canonical JSON (sorted keys).
|
|
21
|
+
*
|
|
22
|
+
* This ensures deterministic hashing regardless of object property order.
|
|
23
|
+
* Required for Merkle tree construction to be reproducible.
|
|
24
|
+
*/
|
|
25
|
+
export declare function canonicalJSON(obj: unknown): string;
|
|
26
|
+
/**
|
|
27
|
+
* Compute SHA-256 hash of a ScriptLeaf using canonical JSON.
|
|
28
|
+
*/
|
|
29
|
+
export declare function hashScriptLeaf(leaf: ScriptLeaf): string;
|
|
30
|
+
/**
|
|
31
|
+
* A Merkle tree constructed from an array of ScriptLeaf spending conditions.
|
|
32
|
+
*
|
|
33
|
+
* Usage:
|
|
34
|
+
* ```typescript
|
|
35
|
+
* const tree = new MerkleTree([
|
|
36
|
+
* { type: "ml-dsa-65-sig", publicKeyHashes: [hash1] },
|
|
37
|
+
* { type: "multisig-ml-dsa", publicKeyHashes: [hash2, hash3], threshold: 2 },
|
|
38
|
+
* { type: "timelock", publicKeyHashes: [hash4], locktime: futureTime },
|
|
39
|
+
* ]);
|
|
40
|
+
*
|
|
41
|
+
* const output: P2MROutput = {
|
|
42
|
+
* outputId: randomUUID(),
|
|
43
|
+
* merkleRoot: tree.root,
|
|
44
|
+
* value: 1000000n,
|
|
45
|
+
* createdAt: Date.now(),
|
|
46
|
+
* };
|
|
47
|
+
*
|
|
48
|
+
* // Later, to spend via leaf 0:
|
|
49
|
+
* const proof = tree.getProof(0);
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare class MerkleTree {
|
|
53
|
+
#private;
|
|
54
|
+
/**
|
|
55
|
+
* Construct a Merkle tree from an array of script leaves.
|
|
56
|
+
*
|
|
57
|
+
* @param leaves - Array of spending conditions. Must have at least 1 element.
|
|
58
|
+
* @throws Error if leaves array is empty.
|
|
59
|
+
*/
|
|
60
|
+
constructor(leaves: ScriptLeaf[]);
|
|
61
|
+
/**
|
|
62
|
+
* The Merkle root hash.
|
|
63
|
+
* Format: 64 hex characters (32 bytes SHA-256).
|
|
64
|
+
*/
|
|
65
|
+
get root(): string;
|
|
66
|
+
/**
|
|
67
|
+
* The original script leaves.
|
|
68
|
+
*/
|
|
69
|
+
get leaves(): readonly ScriptLeaf[];
|
|
70
|
+
/**
|
|
71
|
+
* The leaf hashes (SHA-256 of canonical JSON).
|
|
72
|
+
*/
|
|
73
|
+
get leafHashes(): readonly string[];
|
|
74
|
+
/**
|
|
75
|
+
* Number of leaves in the tree.
|
|
76
|
+
*/
|
|
77
|
+
get leafCount(): number;
|
|
78
|
+
/**
|
|
79
|
+
* Generate a Merkle proof for a specific leaf.
|
|
80
|
+
*
|
|
81
|
+
* @param leafIndex - Zero-based index of the leaf.
|
|
82
|
+
* @returns Array of MerkleProofNode from leaf to root.
|
|
83
|
+
* @throws Error if leafIndex is out of bounds.
|
|
84
|
+
*/
|
|
85
|
+
getProof(leafIndex: number): MerkleProofNode[];
|
|
86
|
+
/**
|
|
87
|
+
* Verify that a leaf hashes to the expected root via a proof.
|
|
88
|
+
*
|
|
89
|
+
* This is a static method so it can be used without the full tree.
|
|
90
|
+
*
|
|
91
|
+
* @param leaf - The script leaf to verify.
|
|
92
|
+
* @param proof - Merkle proof path.
|
|
93
|
+
* @param expectedRoot - Expected Merkle root.
|
|
94
|
+
* @returns true if the proof is valid.
|
|
95
|
+
*/
|
|
96
|
+
static verify(leaf: ScriptLeaf, proof: MerkleProofNode[], expectedRoot: string): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Verify a leaf hash (already computed) against a proof.
|
|
99
|
+
*
|
|
100
|
+
* Useful when you have the hash but not the original leaf data.
|
|
101
|
+
*
|
|
102
|
+
* @param leafHash - SHA-256 hash of the leaf.
|
|
103
|
+
* @param proof - Merkle proof path.
|
|
104
|
+
* @param expectedRoot - Expected Merkle root.
|
|
105
|
+
* @returns true if the proof is valid.
|
|
106
|
+
*/
|
|
107
|
+
static verifyHash(leafHash: string, proof: MerkleProofNode[], expectedRoot: string): boolean;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=merkle-tree.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merkle-tree.d.ts","sourceRoot":"","sources":["../../src/p2mr/merkle-tree.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAM9D;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAyBlD;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAEvD;AAMD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,UAAU;;IAiBrB;;;;;OAKG;gBACS,MAAM,EAAE,UAAU,EAAE;IAUhC;;;OAGG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACH,IAAI,MAAM,IAAI,SAAS,UAAU,EAAE,CAElC;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,SAAS,MAAM,EAAE,CAElC;IAED;;OAEG;IACH,IAAI,SAAS,IAAI,MAAM,CAEtB;IAED;;;;;;OAMG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,eAAe,EAAE;IAwC9C;;;;;;;;;OASG;IACH,MAAM,CAAC,MAAM,CACX,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,eAAe,EAAE,EACxB,YAAY,EAAE,MAAM,GACnB,OAAO;IAYV;;;;;;;;;OASG;IACH,MAAM,CAAC,UAAU,CACf,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,eAAe,EAAE,EACxB,YAAY,EAAE,MAAM,GACnB,OAAO;CA8CX"}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merkle Tree for P2MR Script Trees
|
|
3
|
+
*
|
|
4
|
+
* Constructs a binary Merkle tree from an array of ScriptLeaf nodes.
|
|
5
|
+
* Provides proof generation and verification for spending P2MR outputs.
|
|
6
|
+
*
|
|
7
|
+
* Construction algorithm:
|
|
8
|
+
* 1. Each leaf = SHA-256(canonicalJSON(ScriptLeaf)) → 64-char hex string
|
|
9
|
+
* 2. Internal nodes = SHA-256(leftHex + rightHex) where + is string concatenation
|
|
10
|
+
* (i.e., hashing the 128-char hex string, not raw 64 bytes)
|
|
11
|
+
* 3. Odd leaf count: duplicate last leaf for balanced tree
|
|
12
|
+
* 4. Root = final 32-byte hash (64 hex chars)
|
|
13
|
+
*
|
|
14
|
+
* NOTE: This implementation hashes hex-encoded strings, not raw bytes.
|
|
15
|
+
* For example, sha256hex("abc...def" + "012...345") hashes the 128-character
|
|
16
|
+
* hex string, producing deterministic results portable across platforms.
|
|
17
|
+
*/
|
|
18
|
+
import { sha256hex } from "../shared/crypto.js";
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
// Canonical JSON Serialization
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
/**
|
|
23
|
+
* Serialize an object to canonical JSON (sorted keys).
|
|
24
|
+
*
|
|
25
|
+
* This ensures deterministic hashing regardless of object property order.
|
|
26
|
+
* Required for Merkle tree construction to be reproducible.
|
|
27
|
+
*/
|
|
28
|
+
export function canonicalJSON(obj) {
|
|
29
|
+
if (obj === null || obj === undefined) {
|
|
30
|
+
return JSON.stringify(obj);
|
|
31
|
+
}
|
|
32
|
+
if (Array.isArray(obj)) {
|
|
33
|
+
return "[" + obj.map((item) => canonicalJSON(item)).join(",") + "]";
|
|
34
|
+
}
|
|
35
|
+
if (typeof obj === "object") {
|
|
36
|
+
const sorted = Object.keys(obj)
|
|
37
|
+
.sort()
|
|
38
|
+
.map((key) => {
|
|
39
|
+
const value = obj[key];
|
|
40
|
+
// Skip undefined values
|
|
41
|
+
if (value === undefined) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
return `${JSON.stringify(key)}:${canonicalJSON(value)}`;
|
|
45
|
+
})
|
|
46
|
+
.filter((item) => item !== null);
|
|
47
|
+
return "{" + sorted.join(",") + "}";
|
|
48
|
+
}
|
|
49
|
+
return JSON.stringify(obj);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Compute SHA-256 hash of a ScriptLeaf using canonical JSON.
|
|
53
|
+
*/
|
|
54
|
+
export function hashScriptLeaf(leaf) {
|
|
55
|
+
return sha256hex(canonicalJSON(leaf));
|
|
56
|
+
}
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
// MerkleTree Class
|
|
59
|
+
// ---------------------------------------------------------------------------
|
|
60
|
+
/**
|
|
61
|
+
* A Merkle tree constructed from an array of ScriptLeaf spending conditions.
|
|
62
|
+
*
|
|
63
|
+
* Usage:
|
|
64
|
+
* ```typescript
|
|
65
|
+
* const tree = new MerkleTree([
|
|
66
|
+
* { type: "ml-dsa-65-sig", publicKeyHashes: [hash1] },
|
|
67
|
+
* { type: "multisig-ml-dsa", publicKeyHashes: [hash2, hash3], threshold: 2 },
|
|
68
|
+
* { type: "timelock", publicKeyHashes: [hash4], locktime: futureTime },
|
|
69
|
+
* ]);
|
|
70
|
+
*
|
|
71
|
+
* const output: P2MROutput = {
|
|
72
|
+
* outputId: randomUUID(),
|
|
73
|
+
* merkleRoot: tree.root,
|
|
74
|
+
* value: 1000000n,
|
|
75
|
+
* createdAt: Date.now(),
|
|
76
|
+
* };
|
|
77
|
+
*
|
|
78
|
+
* // Later, to spend via leaf 0:
|
|
79
|
+
* const proof = tree.getProof(0);
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export class MerkleTree {
|
|
83
|
+
/**
|
|
84
|
+
* The original leaves (script conditions).
|
|
85
|
+
*/
|
|
86
|
+
#leaves;
|
|
87
|
+
/**
|
|
88
|
+
* Leaf hashes (SHA-256 of canonical JSON).
|
|
89
|
+
*/
|
|
90
|
+
#leafHashes;
|
|
91
|
+
/**
|
|
92
|
+
* All levels of the tree, from leaves (level 0) to root (last level).
|
|
93
|
+
* Each level is an array of hashes.
|
|
94
|
+
*/
|
|
95
|
+
#levels;
|
|
96
|
+
/**
|
|
97
|
+
* Construct a Merkle tree from an array of script leaves.
|
|
98
|
+
*
|
|
99
|
+
* @param leaves - Array of spending conditions. Must have at least 1 element.
|
|
100
|
+
* @throws Error if leaves array is empty.
|
|
101
|
+
*/
|
|
102
|
+
constructor(leaves) {
|
|
103
|
+
if (leaves.length === 0) {
|
|
104
|
+
throw new Error("MerkleTree requires at least one leaf");
|
|
105
|
+
}
|
|
106
|
+
this.#leaves = [...leaves];
|
|
107
|
+
this.#leafHashes = leaves.map(hashScriptLeaf);
|
|
108
|
+
this.#levels = this.#buildTree();
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* The Merkle root hash.
|
|
112
|
+
* Format: 64 hex characters (32 bytes SHA-256).
|
|
113
|
+
*/
|
|
114
|
+
get root() {
|
|
115
|
+
return this.#levels[this.#levels.length - 1][0];
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The original script leaves.
|
|
119
|
+
*/
|
|
120
|
+
get leaves() {
|
|
121
|
+
return this.#leaves;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The leaf hashes (SHA-256 of canonical JSON).
|
|
125
|
+
*/
|
|
126
|
+
get leafHashes() {
|
|
127
|
+
return this.#leafHashes;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Number of leaves in the tree.
|
|
131
|
+
*/
|
|
132
|
+
get leafCount() {
|
|
133
|
+
return this.#leaves.length;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Generate a Merkle proof for a specific leaf.
|
|
137
|
+
*
|
|
138
|
+
* @param leafIndex - Zero-based index of the leaf.
|
|
139
|
+
* @returns Array of MerkleProofNode from leaf to root.
|
|
140
|
+
* @throws Error if leafIndex is out of bounds.
|
|
141
|
+
*/
|
|
142
|
+
getProof(leafIndex) {
|
|
143
|
+
if (leafIndex < 0 || leafIndex >= this.#leaves.length) {
|
|
144
|
+
throw new Error(`Leaf index ${leafIndex} out of bounds [0, ${this.#leaves.length - 1}]`);
|
|
145
|
+
}
|
|
146
|
+
const proof = [];
|
|
147
|
+
let idx = leafIndex;
|
|
148
|
+
// Traverse from leaves up to (but not including) the root
|
|
149
|
+
for (let level = 0; level < this.#levels.length - 1; level++) {
|
|
150
|
+
const currentLevel = this.#levels[level];
|
|
151
|
+
const isLeftChild = idx % 2 === 0;
|
|
152
|
+
const siblingIdx = isLeftChild ? idx + 1 : idx - 1;
|
|
153
|
+
// When sibling doesn't exist (odd number at this level), the tree builder
|
|
154
|
+
// duplicates the last node to pair with itself. We must include this
|
|
155
|
+
// self-sibling in the proof for verification to work correctly.
|
|
156
|
+
if (siblingIdx < currentLevel.length) {
|
|
157
|
+
proof.push({
|
|
158
|
+
hash: currentLevel[siblingIdx],
|
|
159
|
+
position: isLeftChild ? "right" : "left",
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
// Sibling is out of bounds - this node was duplicated as its own pair
|
|
164
|
+
// Include the self-hash as the sibling
|
|
165
|
+
proof.push({
|
|
166
|
+
hash: currentLevel[idx],
|
|
167
|
+
position: "right",
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
// Move to parent index
|
|
171
|
+
idx = Math.floor(idx / 2);
|
|
172
|
+
}
|
|
173
|
+
return proof;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Verify that a leaf hashes to the expected root via a proof.
|
|
177
|
+
*
|
|
178
|
+
* This is a static method so it can be used without the full tree.
|
|
179
|
+
*
|
|
180
|
+
* @param leaf - The script leaf to verify.
|
|
181
|
+
* @param proof - Merkle proof path.
|
|
182
|
+
* @param expectedRoot - Expected Merkle root.
|
|
183
|
+
* @returns true if the proof is valid.
|
|
184
|
+
*/
|
|
185
|
+
static verify(leaf, proof, expectedRoot) {
|
|
186
|
+
let hash = hashScriptLeaf(leaf);
|
|
187
|
+
for (const node of proof) {
|
|
188
|
+
const combined = node.position === "left" ? node.hash + hash : hash + node.hash;
|
|
189
|
+
hash = sha256hex(combined);
|
|
190
|
+
}
|
|
191
|
+
return hash === expectedRoot;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Verify a leaf hash (already computed) against a proof.
|
|
195
|
+
*
|
|
196
|
+
* Useful when you have the hash but not the original leaf data.
|
|
197
|
+
*
|
|
198
|
+
* @param leafHash - SHA-256 hash of the leaf.
|
|
199
|
+
* @param proof - Merkle proof path.
|
|
200
|
+
* @param expectedRoot - Expected Merkle root.
|
|
201
|
+
* @returns true if the proof is valid.
|
|
202
|
+
*/
|
|
203
|
+
static verifyHash(leafHash, proof, expectedRoot) {
|
|
204
|
+
let hash = leafHash;
|
|
205
|
+
for (const node of proof) {
|
|
206
|
+
const combined = node.position === "left" ? node.hash + hash : hash + node.hash;
|
|
207
|
+
hash = sha256hex(combined);
|
|
208
|
+
}
|
|
209
|
+
return hash === expectedRoot;
|
|
210
|
+
}
|
|
211
|
+
// ---------------------------------------------------------------------------
|
|
212
|
+
// Private Methods
|
|
213
|
+
// ---------------------------------------------------------------------------
|
|
214
|
+
/**
|
|
215
|
+
* Build the tree from leaf hashes up to the root.
|
|
216
|
+
*/
|
|
217
|
+
#buildTree() {
|
|
218
|
+
const levels = [];
|
|
219
|
+
// Level 0: leaf hashes (possibly padded to even count)
|
|
220
|
+
let currentLevel = [...this.#leafHashes];
|
|
221
|
+
if (currentLevel.length % 2 === 1 && currentLevel.length > 1) {
|
|
222
|
+
// Duplicate last leaf for odd count
|
|
223
|
+
currentLevel.push(currentLevel[currentLevel.length - 1]);
|
|
224
|
+
}
|
|
225
|
+
levels.push(currentLevel);
|
|
226
|
+
// Build parent levels until we reach the root
|
|
227
|
+
while (currentLevel.length > 1) {
|
|
228
|
+
const parentLevel = [];
|
|
229
|
+
for (let i = 0; i < currentLevel.length; i += 2) {
|
|
230
|
+
const left = currentLevel[i];
|
|
231
|
+
const right = currentLevel[i + 1] ?? left; // Handle odd case
|
|
232
|
+
parentLevel.push(sha256hex(left + right));
|
|
233
|
+
}
|
|
234
|
+
levels.push(parentLevel);
|
|
235
|
+
currentLevel = parentLevel;
|
|
236
|
+
}
|
|
237
|
+
return levels;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* P2MR Output Management
|
|
3
|
+
*
|
|
4
|
+
* Provides factory functions and storage patterns for P2MR outputs.
|
|
5
|
+
* Outputs are created by committing to a Merkle root and tracked
|
|
6
|
+
* in an output store for spending.
|
|
7
|
+
*/
|
|
8
|
+
import type { Store } from "../shared/store.js";
|
|
9
|
+
import type { P2MROutput, ScriptLeaf } from "./types.js";
|
|
10
|
+
import { MerkleTree } from "./merkle-tree.js";
|
|
11
|
+
/** Alias for the P2MR output store type (outputId -> P2MROutput). */
|
|
12
|
+
type P2MRStore = Store<string, P2MROutput>;
|
|
13
|
+
/**
|
|
14
|
+
* Options for creating a P2MR output.
|
|
15
|
+
*/
|
|
16
|
+
export interface CreateP2MROutputOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Spending conditions for the output.
|
|
19
|
+
* These are hashed into a Merkle tree; only the root is stored on-chain.
|
|
20
|
+
*/
|
|
21
|
+
leaves: ScriptLeaf[];
|
|
22
|
+
/**
|
|
23
|
+
* Value locked in the output.
|
|
24
|
+
*/
|
|
25
|
+
value: bigint;
|
|
26
|
+
/**
|
|
27
|
+
* Optional output ID. If not provided, a UUID is generated.
|
|
28
|
+
*/
|
|
29
|
+
outputId?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Optional creation timestamp. Defaults to current time.
|
|
32
|
+
*/
|
|
33
|
+
createdAt?: number;
|
|
34
|
+
/**
|
|
35
|
+
* Optional metadata hash (SHA-256 of off-chain data).
|
|
36
|
+
*/
|
|
37
|
+
metadataHash?: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Result of creating a P2MR output.
|
|
41
|
+
*
|
|
42
|
+
* Returns both the output (for on-chain storage) and the Merkle tree
|
|
43
|
+
* (for generating spend proofs later).
|
|
44
|
+
*/
|
|
45
|
+
export interface CreateP2MROutputResult {
|
|
46
|
+
/**
|
|
47
|
+
* The P2MR output to store on-chain.
|
|
48
|
+
*/
|
|
49
|
+
output: P2MROutput;
|
|
50
|
+
/**
|
|
51
|
+
* The Merkle tree constructed from the spending conditions.
|
|
52
|
+
* Keep this off-chain for generating spend proofs.
|
|
53
|
+
*/
|
|
54
|
+
tree: MerkleTree;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Create a P2MR output from spending conditions.
|
|
58
|
+
*
|
|
59
|
+
* The output stores only the Merkle root; the actual spending conditions
|
|
60
|
+
* (script leaves) are kept off-chain by the creator. This prevents
|
|
61
|
+
* quantum adversaries from harvesting public keys from unspent outputs.
|
|
62
|
+
*
|
|
63
|
+
* @param options - Output creation options.
|
|
64
|
+
* @returns The P2MR output and its Merkle tree.
|
|
65
|
+
* @throws Error if leaves array is empty or value is negative.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* import { createP2MROutput, createSingleSigLeaf, createTimelockLeaf } from "@enterprise-blockchain/p2mr";
|
|
70
|
+
*
|
|
71
|
+
* const primaryKey = "a1b2c3..."; // SHA-256 hash of ML-DSA-65 public key
|
|
72
|
+
* const backupKey = "d4e5f6...";
|
|
73
|
+
*
|
|
74
|
+
* const { output, tree } = createP2MROutput({
|
|
75
|
+
* leaves: [
|
|
76
|
+
* createSingleSigLeaf(primaryKey), // Spend path 0: primary key
|
|
77
|
+
* createTimelockLeaf(backupKey, futureTime), // Spend path 1: backup after 1 year
|
|
78
|
+
* ],
|
|
79
|
+
* value: 1_000_000n,
|
|
80
|
+
* });
|
|
81
|
+
*
|
|
82
|
+
* // Store `output` on-chain (only merkleRoot exposed)
|
|
83
|
+
* // Keep `tree` off-chain for generating spend proofs
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export declare function createP2MROutput(options: CreateP2MROutputOptions): CreateP2MROutputResult;
|
|
87
|
+
/**
|
|
88
|
+
* A store for P2MR outputs indexed by outputId.
|
|
89
|
+
*
|
|
90
|
+
* Provides methods for tracking unspent outputs (UTXOs).
|
|
91
|
+
*/
|
|
92
|
+
export declare class P2MROutputStore {
|
|
93
|
+
#private;
|
|
94
|
+
/**
|
|
95
|
+
* Create a new P2MR output store.
|
|
96
|
+
*
|
|
97
|
+
* @param store - Optional backing store. Defaults to in-memory.
|
|
98
|
+
*/
|
|
99
|
+
constructor(store?: P2MRStore);
|
|
100
|
+
/**
|
|
101
|
+
* Add an output to the store.
|
|
102
|
+
*
|
|
103
|
+
* @param output - The P2MR output to store.
|
|
104
|
+
* @throws Error if output with same ID already exists.
|
|
105
|
+
*/
|
|
106
|
+
add(output: P2MROutput): void;
|
|
107
|
+
/**
|
|
108
|
+
* Get an output by ID.
|
|
109
|
+
*
|
|
110
|
+
* @param outputId - The output ID.
|
|
111
|
+
* @returns The output, or undefined if not found.
|
|
112
|
+
*/
|
|
113
|
+
get(outputId: string): P2MROutput | undefined;
|
|
114
|
+
/**
|
|
115
|
+
* Check if an output is unspent.
|
|
116
|
+
*
|
|
117
|
+
* @param outputId - The output ID.
|
|
118
|
+
* @returns true if the output exists and has not been spent.
|
|
119
|
+
*/
|
|
120
|
+
isUnspent(outputId: string): boolean;
|
|
121
|
+
/**
|
|
122
|
+
* Mark an output as spent.
|
|
123
|
+
*
|
|
124
|
+
* @param outputId - The output ID.
|
|
125
|
+
* @throws Error if output does not exist or is already spent.
|
|
126
|
+
*/
|
|
127
|
+
markSpent(outputId: string): void;
|
|
128
|
+
/**
|
|
129
|
+
* Get all unspent outputs.
|
|
130
|
+
*
|
|
131
|
+
* @returns Array of unspent P2MR outputs.
|
|
132
|
+
*/
|
|
133
|
+
getUnspent(): P2MROutput[];
|
|
134
|
+
/**
|
|
135
|
+
* Get total value of all unspent outputs.
|
|
136
|
+
*
|
|
137
|
+
* @returns Sum of all unspent output values.
|
|
138
|
+
*/
|
|
139
|
+
getUnspentBalance(): bigint;
|
|
140
|
+
}
|
|
141
|
+
export {};
|
|
142
|
+
//# sourceMappingURL=p2mr-output.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"p2mr-output.d.ts","sourceRoot":"","sources":["../../src/p2mr/p2mr-output.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,KAAK,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,qEAAqE;AACrE,KAAK,SAAS,GAAG,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AAM3C;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,MAAM,EAAE,UAAU,EAAE,CAAC;IAErB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;GAKG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,MAAM,EAAE,UAAU,CAAC;IAEnB;;;OAGG;IACH,IAAI,EAAE,UAAU,CAAC;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,uBAAuB,GAC/B,sBAAsB,CAyBxB;AAMD;;;;GAIG;AACH,qBAAa,eAAe;;IAI1B;;;;OAIG;gBACS,KAAK,CAAC,EAAE,SAAS;IAK7B;;;;;OAKG;IACH,GAAG,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAQ7B;;;;;OAKG;IACH,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,UAAU,GAAG,SAAS;IAI7C;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAQpC;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAWjC;;;;OAIG;IACH,UAAU,IAAI,UAAU,EAAE;IAK1B;;;;OAIG;IACH,iBAAiB,IAAI,MAAM;CAI5B"}
|