@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.
Files changed (296) hide show
  1. package/README.md +15 -2
  2. package/dist/aid-settlement/application/reconciler.d.ts +13 -0
  3. package/dist/aid-settlement/application/reconciler.d.ts.map +1 -0
  4. package/dist/aid-settlement/application/reconciler.js +77 -0
  5. package/dist/aid-settlement/domain/entities.d.ts +24 -0
  6. package/dist/aid-settlement/domain/entities.d.ts.map +1 -0
  7. package/dist/aid-settlement/domain/entities.js +1 -0
  8. package/dist/aid-settlement/domain/ports.d.ts +10 -0
  9. package/dist/aid-settlement/domain/ports.d.ts.map +1 -0
  10. package/dist/aid-settlement/domain/ports.js +1 -0
  11. package/dist/aid-settlement/index.d.ts +19 -0
  12. package/dist/aid-settlement/index.d.ts.map +1 -0
  13. package/dist/aid-settlement/index.js +23 -0
  14. package/dist/aid-settlement/infrastructure/in-memory-store.d.ts +12 -0
  15. package/dist/aid-settlement/infrastructure/in-memory-store.d.ts.map +1 -0
  16. package/dist/aid-settlement/infrastructure/in-memory-store.js +17 -0
  17. package/dist/credentialing/application/clearance-evaluator.d.ts +10 -0
  18. package/dist/credentialing/application/clearance-evaluator.d.ts.map +1 -0
  19. package/dist/credentialing/application/clearance-evaluator.js +63 -0
  20. package/dist/credentialing/domain/entities.d.ts +28 -0
  21. package/dist/credentialing/domain/entities.d.ts.map +1 -0
  22. package/dist/credentialing/domain/entities.js +1 -0
  23. package/dist/credentialing/domain/ports.d.ts +9 -0
  24. package/dist/credentialing/domain/ports.d.ts.map +1 -0
  25. package/dist/credentialing/domain/ports.js +1 -0
  26. package/dist/credentialing/index.d.ts +19 -0
  27. package/dist/credentialing/index.d.ts.map +1 -0
  28. package/dist/credentialing/index.js +23 -0
  29. package/dist/credentialing/infrastructure/in-memory-store.d.ts +11 -0
  30. package/dist/credentialing/infrastructure/in-memory-store.d.ts.map +1 -0
  31. package/dist/credentialing/infrastructure/in-memory-store.js +14 -0
  32. package/dist/hsm/application/asymmetric-key-service.d.ts +23 -0
  33. package/dist/hsm/application/asymmetric-key-service.d.ts.map +1 -0
  34. package/dist/hsm/application/asymmetric-key-service.js +109 -0
  35. package/dist/hsm/application/envelope-encryption-service.d.ts +18 -0
  36. package/dist/hsm/application/envelope-encryption-service.d.ts.map +1 -0
  37. package/dist/hsm/application/envelope-encryption-service.js +59 -0
  38. package/dist/hsm/application/symmetric-key-service.d.ts +34 -0
  39. package/dist/hsm/application/symmetric-key-service.d.ts.map +1 -0
  40. package/dist/hsm/application/symmetric-key-service.js +107 -0
  41. package/dist/hsm/domain/entities.d.ts +104 -0
  42. package/dist/hsm/domain/entities.d.ts.map +1 -0
  43. package/dist/hsm/domain/entities.js +10 -0
  44. package/dist/hsm/domain/ports.d.ts +20 -0
  45. package/dist/hsm/domain/ports.d.ts.map +1 -0
  46. package/dist/hsm/domain/ports.js +1 -0
  47. package/dist/hsm/index.d.ts +48 -0
  48. package/dist/hsm/index.d.ts.map +1 -0
  49. package/dist/hsm/index.js +97 -0
  50. package/dist/hsm/infrastructure/audit-log-factory.d.ts +59 -0
  51. package/dist/hsm/infrastructure/audit-log-factory.d.ts.map +1 -0
  52. package/dist/hsm/infrastructure/audit-log-factory.js +95 -0
  53. package/dist/hsm/infrastructure/audit-log.d.ts +8 -0
  54. package/dist/hsm/infrastructure/audit-log.d.ts.map +1 -0
  55. package/dist/hsm/infrastructure/audit-log.js +18 -0
  56. package/dist/hsm/infrastructure/file-audit-log.d.ts +55 -0
  57. package/dist/hsm/infrastructure/file-audit-log.d.ts.map +1 -0
  58. package/dist/hsm/infrastructure/file-audit-log.js +128 -0
  59. package/dist/hsm/infrastructure/key-store.d.ts +9 -0
  60. package/dist/hsm/infrastructure/key-store.d.ts.map +1 -0
  61. package/dist/hsm/infrastructure/key-store.js +12 -0
  62. package/dist/hsm/infrastructure/syslog-audit-log.d.ts +64 -0
  63. package/dist/hsm/infrastructure/syslog-audit-log.d.ts.map +1 -0
  64. package/dist/hsm/infrastructure/syslog-audit-log.js +167 -0
  65. package/dist/index.d.ts +22 -0
  66. package/dist/index.d.ts.map +1 -0
  67. package/dist/index.js +37 -0
  68. package/dist/integrations/besu-client/error-mapper.d.ts +9 -0
  69. package/dist/integrations/besu-client/error-mapper.d.ts.map +1 -0
  70. package/dist/integrations/besu-client/error-mapper.js +22 -0
  71. package/dist/integrations/besu-client/index.d.ts +65 -0
  72. package/dist/integrations/besu-client/index.d.ts.map +1 -0
  73. package/dist/integrations/besu-client/index.js +276 -0
  74. package/dist/integrations/besu-client/ports.d.ts +44 -0
  75. package/dist/integrations/besu-client/ports.d.ts.map +1 -0
  76. package/dist/integrations/besu-client/ports.js +1 -0
  77. package/dist/integrations/corda-gateway/index.d.ts +37 -0
  78. package/dist/integrations/corda-gateway/index.d.ts.map +1 -0
  79. package/dist/integrations/corda-gateway/index.js +234 -0
  80. package/dist/integrations/corda-gateway/ports.d.ts +33 -0
  81. package/dist/integrations/corda-gateway/ports.d.ts.map +1 -0
  82. package/dist/integrations/corda-gateway/ports.js +1 -0
  83. package/dist/integrations/fabric-gateway/index.d.ts +78 -0
  84. package/dist/integrations/fabric-gateway/index.d.ts.map +1 -0
  85. package/dist/integrations/fabric-gateway/index.js +214 -0
  86. package/dist/integrations/fabric-gateway/ports.d.ts +50 -0
  87. package/dist/integrations/fabric-gateway/ports.d.ts.map +1 -0
  88. package/dist/integrations/fabric-gateway/ports.js +1 -0
  89. package/dist/integrations/index.d.ts +19 -0
  90. package/dist/integrations/index.d.ts.map +1 -0
  91. package/dist/integrations/index.js +19 -0
  92. package/dist/integrations/shared/env.d.ts +4 -0
  93. package/dist/integrations/shared/env.d.ts.map +1 -0
  94. package/dist/integrations/shared/env.js +24 -0
  95. package/dist/integrations/shared/retry.d.ts +79 -0
  96. package/dist/integrations/shared/retry.d.ts.map +1 -0
  97. package/dist/integrations/shared/retry.js +315 -0
  98. package/dist/mpc/adapters.d.ts +36 -0
  99. package/dist/mpc/adapters.d.ts.map +1 -0
  100. package/dist/mpc/adapters.js +46 -0
  101. package/dist/mpc/crypto.d.ts +2 -0
  102. package/dist/mpc/crypto.d.ts.map +1 -0
  103. package/dist/mpc/crypto.js +2 -0
  104. package/dist/mpc/dsa.d.ts +134 -0
  105. package/dist/mpc/dsa.d.ts.map +1 -0
  106. package/dist/mpc/dsa.js +127 -0
  107. package/dist/mpc/field.d.ts +127 -0
  108. package/dist/mpc/field.d.ts.map +1 -0
  109. package/dist/mpc/field.js +209 -0
  110. package/dist/mpc/hybrid-kem.d.ts +96 -0
  111. package/dist/mpc/hybrid-kem.d.ts.map +1 -0
  112. package/dist/mpc/hybrid-kem.js +136 -0
  113. package/dist/mpc/index.d.ts +135 -0
  114. package/dist/mpc/index.d.ts.map +1 -0
  115. package/dist/mpc/index.js +348 -0
  116. package/dist/mpc/kyber.d.ts +134 -0
  117. package/dist/mpc/kyber.d.ts.map +1 -0
  118. package/dist/mpc/kyber.js +143 -0
  119. package/dist/mpc/ports.d.ts +67 -0
  120. package/dist/mpc/ports.d.ts.map +1 -0
  121. package/dist/mpc/ports.js +9 -0
  122. package/dist/mpc/quantum.d.ts +80 -0
  123. package/dist/mpc/quantum.d.ts.map +1 -0
  124. package/dist/mpc/quantum.js +180 -0
  125. package/dist/p2mr/adapters.d.ts +31 -0
  126. package/dist/p2mr/adapters.d.ts.map +1 -0
  127. package/dist/p2mr/adapters.js +35 -0
  128. package/dist/p2mr/index.d.ts +63 -0
  129. package/dist/p2mr/index.d.ts.map +1 -0
  130. package/dist/p2mr/index.js +59 -0
  131. package/dist/p2mr/merkle-tree.d.ts +109 -0
  132. package/dist/p2mr/merkle-tree.d.ts.map +1 -0
  133. package/dist/p2mr/merkle-tree.js +239 -0
  134. package/dist/p2mr/p2mr-output.d.ts +142 -0
  135. package/dist/p2mr/p2mr-output.d.ts.map +1 -0
  136. package/dist/p2mr/p2mr-output.js +150 -0
  137. package/dist/p2mr/ports.d.ts +52 -0
  138. package/dist/p2mr/ports.d.ts.map +1 -0
  139. package/dist/p2mr/ports.js +9 -0
  140. package/dist/p2mr/script-interpreter.d.ts +92 -0
  141. package/dist/p2mr/script-interpreter.d.ts.map +1 -0
  142. package/dist/p2mr/script-interpreter.js +535 -0
  143. package/dist/p2mr/script-leaf.d.ts +70 -0
  144. package/dist/p2mr/script-leaf.d.ts.map +1 -0
  145. package/dist/p2mr/script-leaf.js +203 -0
  146. package/dist/p2mr/spend-proof.d.ts +95 -0
  147. package/dist/p2mr/spend-proof.d.ts.map +1 -0
  148. package/dist/p2mr/spend-proof.js +358 -0
  149. package/dist/p2mr/types.d.ts +209 -0
  150. package/dist/p2mr/types.d.ts.map +1 -0
  151. package/dist/p2mr/types.js +9 -0
  152. package/dist/privacy/application/view-projector.d.ts +13 -0
  153. package/dist/privacy/application/view-projector.d.ts.map +1 -0
  154. package/dist/privacy/application/view-projector.js +85 -0
  155. package/dist/privacy/domain/entities.d.ts +26 -0
  156. package/dist/privacy/domain/entities.d.ts.map +1 -0
  157. package/dist/privacy/domain/entities.js +1 -0
  158. package/dist/privacy/domain/ports.d.ts +7 -0
  159. package/dist/privacy/domain/ports.d.ts.map +1 -0
  160. package/dist/privacy/domain/ports.js +1 -0
  161. package/dist/privacy/index.d.ts +21 -0
  162. package/dist/privacy/index.d.ts.map +1 -0
  163. package/dist/privacy/index.js +25 -0
  164. package/dist/privacy/infrastructure/in-memory-store.d.ts +8 -0
  165. package/dist/privacy/infrastructure/in-memory-store.d.ts.map +1 -0
  166. package/dist/privacy/infrastructure/in-memory-store.js +7 -0
  167. package/dist/protocols/besu-port.d.ts +80 -0
  168. package/dist/protocols/besu-port.d.ts.map +1 -0
  169. package/dist/protocols/besu-port.js +1 -0
  170. package/dist/protocols/corda-port.d.ts +103 -0
  171. package/dist/protocols/corda-port.d.ts.map +1 -0
  172. package/dist/protocols/corda-port.js +9 -0
  173. package/dist/protocols/credentialing-port.d.ts +11 -0
  174. package/dist/protocols/credentialing-port.d.ts.map +1 -0
  175. package/dist/protocols/credentialing-port.js +1 -0
  176. package/dist/protocols/fabric-port.d.ts +89 -0
  177. package/dist/protocols/fabric-port.d.ts.map +1 -0
  178. package/dist/protocols/fabric-port.js +9 -0
  179. package/dist/protocols/index.d.ts +14 -0
  180. package/dist/protocols/index.d.ts.map +1 -0
  181. package/dist/protocols/index.js +7 -0
  182. package/dist/protocols/p2mr-port.d.ts +159 -0
  183. package/dist/protocols/p2mr-port.d.ts.map +1 -0
  184. package/dist/protocols/p2mr-port.js +12 -0
  185. package/dist/protocols/privacy-port.d.ts +9 -0
  186. package/dist/protocols/privacy-port.d.ts.map +1 -0
  187. package/dist/protocols/privacy-port.js +1 -0
  188. package/dist/protocols/traceability-port.d.ts +12 -0
  189. package/dist/protocols/traceability-port.d.ts.map +1 -0
  190. package/dist/protocols/traceability-port.js +1 -0
  191. package/dist/shared/collection-store.d.ts +12 -0
  192. package/dist/shared/collection-store.d.ts.map +1 -0
  193. package/dist/shared/collection-store.js +26 -0
  194. package/dist/shared/commit.d.ts +24 -0
  195. package/dist/shared/commit.d.ts.map +1 -0
  196. package/dist/shared/commit.js +50 -0
  197. package/dist/shared/crypto.d.ts +2 -0
  198. package/dist/shared/crypto.d.ts.map +1 -0
  199. package/dist/shared/crypto.js +4 -0
  200. package/dist/shared/date.d.ts +2 -0
  201. package/dist/shared/date.d.ts.map +1 -0
  202. package/dist/shared/date.js +3 -0
  203. package/dist/shared/index.d.ts +9 -0
  204. package/dist/shared/index.d.ts.map +1 -0
  205. package/dist/shared/index.js +11 -0
  206. package/dist/shared/logger.d.ts +37 -0
  207. package/dist/shared/logger.d.ts.map +1 -0
  208. package/dist/shared/logger.js +45 -0
  209. package/dist/shared/store.d.ts +25 -0
  210. package/dist/shared/store.d.ts.map +1 -0
  211. package/dist/shared/store.js +18 -0
  212. package/dist/shared/telemetry-sdk.d.ts +26 -0
  213. package/dist/shared/telemetry-sdk.d.ts.map +1 -0
  214. package/dist/shared/telemetry-sdk.js +97 -0
  215. package/dist/shared/telemetry.d.ts +86 -0
  216. package/dist/shared/telemetry.d.ts.map +1 -0
  217. package/dist/shared/telemetry.js +137 -0
  218. package/dist/stark-settlement/application/aggregator-service.d.ts +112 -0
  219. package/dist/stark-settlement/application/aggregator-service.d.ts.map +1 -0
  220. package/dist/stark-settlement/application/aggregator-service.js +256 -0
  221. package/dist/stark-settlement/application/ledger-service.d.ts +114 -0
  222. package/dist/stark-settlement/application/ledger-service.d.ts.map +1 -0
  223. package/dist/stark-settlement/application/ledger-service.js +318 -0
  224. package/dist/stark-settlement/application/settlement-service.d.ts +104 -0
  225. package/dist/stark-settlement/application/settlement-service.d.ts.map +1 -0
  226. package/dist/stark-settlement/application/settlement-service.js +251 -0
  227. package/dist/stark-settlement/domain/entities.d.ts +365 -0
  228. package/dist/stark-settlement/domain/entities.d.ts.map +1 -0
  229. package/dist/stark-settlement/domain/entities.js +29 -0
  230. package/dist/stark-settlement/domain/ports.d.ts +485 -0
  231. package/dist/stark-settlement/domain/ports.d.ts.map +1 -0
  232. package/dist/stark-settlement/domain/ports.js +14 -0
  233. package/dist/stark-settlement/domain/value-objects.d.ts +268 -0
  234. package/dist/stark-settlement/domain/value-objects.d.ts.map +1 -0
  235. package/dist/stark-settlement/domain/value-objects.js +500 -0
  236. package/dist/stark-settlement/index.d.ts +172 -0
  237. package/dist/stark-settlement/index.d.ts.map +1 -0
  238. package/dist/stark-settlement/index.js +193 -0
  239. package/dist/stark-settlement/infrastructure/adapters/audit-adapter.d.ts +52 -0
  240. package/dist/stark-settlement/infrastructure/adapters/audit-adapter.d.ts.map +1 -0
  241. package/dist/stark-settlement/infrastructure/adapters/audit-adapter.js +154 -0
  242. package/dist/stark-settlement/infrastructure/adapters/bitcoin-adapter.d.ts +88 -0
  243. package/dist/stark-settlement/infrastructure/adapters/bitcoin-adapter.d.ts.map +1 -0
  244. package/dist/stark-settlement/infrastructure/adapters/bitcoin-adapter.js +187 -0
  245. package/dist/stark-settlement/infrastructure/adapters/clock-adapter.d.ts +59 -0
  246. package/dist/stark-settlement/infrastructure/adapters/clock-adapter.d.ts.map +1 -0
  247. package/dist/stark-settlement/infrastructure/adapters/clock-adapter.js +85 -0
  248. package/dist/stark-settlement/infrastructure/adapters/dilithium-adapter.d.ts +60 -0
  249. package/dist/stark-settlement/infrastructure/adapters/dilithium-adapter.d.ts.map +1 -0
  250. package/dist/stark-settlement/infrastructure/adapters/dilithium-adapter.js +104 -0
  251. package/dist/stark-settlement/infrastructure/adapters/event-emitter-adapter.d.ts +115 -0
  252. package/dist/stark-settlement/infrastructure/adapters/event-emitter-adapter.d.ts.map +1 -0
  253. package/dist/stark-settlement/infrastructure/adapters/event-emitter-adapter.js +191 -0
  254. package/dist/stark-settlement/infrastructure/adapters/fiat-adapter.d.ts +65 -0
  255. package/dist/stark-settlement/infrastructure/adapters/fiat-adapter.d.ts.map +1 -0
  256. package/dist/stark-settlement/infrastructure/adapters/fiat-adapter.js +207 -0
  257. package/dist/stark-settlement/infrastructure/adapters/mock-stark-adapter.d.ts +73 -0
  258. package/dist/stark-settlement/infrastructure/adapters/mock-stark-adapter.d.ts.map +1 -0
  259. package/dist/stark-settlement/infrastructure/adapters/mock-stark-adapter.js +287 -0
  260. package/dist/stark-settlement/infrastructure/adapters/solana-adapter.d.ts +78 -0
  261. package/dist/stark-settlement/infrastructure/adapters/solana-adapter.d.ts.map +1 -0
  262. package/dist/stark-settlement/infrastructure/adapters/solana-adapter.js +172 -0
  263. package/dist/stark-settlement/infrastructure/adapters/starknet-proof-adapter.d.ts +56 -0
  264. package/dist/stark-settlement/infrastructure/adapters/starknet-proof-adapter.d.ts.map +1 -0
  265. package/dist/stark-settlement/infrastructure/adapters/starknet-proof-adapter.js +261 -0
  266. package/dist/stark-settlement/infrastructure/adapters/stone-proof-adapter.d.ts +125 -0
  267. package/dist/stark-settlement/infrastructure/adapters/stone-proof-adapter.d.ts.map +1 -0
  268. package/dist/stark-settlement/infrastructure/adapters/stone-proof-adapter.js +416 -0
  269. package/dist/stark-settlement/infrastructure/persistence/ledger-store.d.ts +68 -0
  270. package/dist/stark-settlement/infrastructure/persistence/ledger-store.d.ts.map +1 -0
  271. package/dist/stark-settlement/infrastructure/persistence/ledger-store.js +238 -0
  272. package/dist/stark-settlement/infrastructure/persistence/offset-store.d.ts +30 -0
  273. package/dist/stark-settlement/infrastructure/persistence/offset-store.d.ts.map +1 -0
  274. package/dist/stark-settlement/infrastructure/persistence/offset-store.js +57 -0
  275. package/dist/stark-settlement/infrastructure/persistence/outbox-store.d.ts +45 -0
  276. package/dist/stark-settlement/infrastructure/persistence/outbox-store.d.ts.map +1 -0
  277. package/dist/stark-settlement/infrastructure/persistence/outbox-store.js +171 -0
  278. package/dist/traceability/application/recall-assessor.d.ts +13 -0
  279. package/dist/traceability/application/recall-assessor.d.ts.map +1 -0
  280. package/dist/traceability/application/recall-assessor.js +74 -0
  281. package/dist/traceability/domain/entities.d.ts +23 -0
  282. package/dist/traceability/domain/entities.d.ts.map +1 -0
  283. package/dist/traceability/domain/entities.js +1 -0
  284. package/dist/traceability/domain/ports.d.ts +23 -0
  285. package/dist/traceability/domain/ports.d.ts.map +1 -0
  286. package/dist/traceability/domain/ports.js +1 -0
  287. package/dist/traceability/domain/recall.d.ts +12 -0
  288. package/dist/traceability/domain/recall.d.ts.map +1 -0
  289. package/dist/traceability/domain/recall.js +1 -0
  290. package/dist/traceability/index.d.ts +22 -0
  291. package/dist/traceability/index.d.ts.map +1 -0
  292. package/dist/traceability/index.js +26 -0
  293. package/dist/traceability/infrastructure/in-memory-store.d.ts +13 -0
  294. package/dist/traceability/infrastructure/in-memory-store.d.ts.map +1 -0
  295. package/dist/traceability/infrastructure/in-memory-store.js +24 -0
  296. package/package.json +12 -9
@@ -0,0 +1,150 @@
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 { randomUUID } from "node:crypto";
9
+ import { InMemoryStore } from "../shared/store.js";
10
+ import { MerkleTree } from "./merkle-tree.js";
11
+ /**
12
+ * Create a P2MR output from spending conditions.
13
+ *
14
+ * The output stores only the Merkle root; the actual spending conditions
15
+ * (script leaves) are kept off-chain by the creator. This prevents
16
+ * quantum adversaries from harvesting public keys from unspent outputs.
17
+ *
18
+ * @param options - Output creation options.
19
+ * @returns The P2MR output and its Merkle tree.
20
+ * @throws Error if leaves array is empty or value is negative.
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * import { createP2MROutput, createSingleSigLeaf, createTimelockLeaf } from "@enterprise-blockchain/p2mr";
25
+ *
26
+ * const primaryKey = "a1b2c3..."; // SHA-256 hash of ML-DSA-65 public key
27
+ * const backupKey = "d4e5f6...";
28
+ *
29
+ * const { output, tree } = createP2MROutput({
30
+ * leaves: [
31
+ * createSingleSigLeaf(primaryKey), // Spend path 0: primary key
32
+ * createTimelockLeaf(backupKey, futureTime), // Spend path 1: backup after 1 year
33
+ * ],
34
+ * value: 1_000_000n,
35
+ * });
36
+ *
37
+ * // Store `output` on-chain (only merkleRoot exposed)
38
+ * // Keep `tree` off-chain for generating spend proofs
39
+ * ```
40
+ */
41
+ export function createP2MROutput(options) {
42
+ const { leaves, value, outputId, createdAt, metadataHash } = options;
43
+ if (leaves.length === 0) {
44
+ throw new Error("P2MR output requires at least one spending condition");
45
+ }
46
+ if (value < BigInt(0)) {
47
+ throw new Error("P2MR output value must be non-negative");
48
+ }
49
+ const tree = new MerkleTree(leaves);
50
+ const output = {
51
+ outputId: outputId ?? randomUUID(),
52
+ merkleRoot: tree.root,
53
+ value,
54
+ createdAt: createdAt ?? Date.now(),
55
+ };
56
+ if (metadataHash) {
57
+ output.metadataHash = metadataHash;
58
+ }
59
+ return { output, tree };
60
+ }
61
+ // ---------------------------------------------------------------------------
62
+ // P2MR Output Store
63
+ // ---------------------------------------------------------------------------
64
+ /**
65
+ * A store for P2MR outputs indexed by outputId.
66
+ *
67
+ * Provides methods for tracking unspent outputs (UTXOs).
68
+ */
69
+ export class P2MROutputStore {
70
+ #store;
71
+ #spentSet;
72
+ /**
73
+ * Create a new P2MR output store.
74
+ *
75
+ * @param store - Optional backing store. Defaults to in-memory.
76
+ */
77
+ constructor(store) {
78
+ this.#store = store ?? new InMemoryStore();
79
+ this.#spentSet = new Set();
80
+ }
81
+ /**
82
+ * Add an output to the store.
83
+ *
84
+ * @param output - The P2MR output to store.
85
+ * @throws Error if output with same ID already exists.
86
+ */
87
+ add(output) {
88
+ const existing = this.#store.get(output.outputId);
89
+ if (existing) {
90
+ throw new Error(`Output ${output.outputId} already exists`);
91
+ }
92
+ this.#store.set(output.outputId, output);
93
+ }
94
+ /**
95
+ * Get an output by ID.
96
+ *
97
+ * @param outputId - The output ID.
98
+ * @returns The output, or undefined if not found.
99
+ */
100
+ get(outputId) {
101
+ return this.#store.get(outputId);
102
+ }
103
+ /**
104
+ * Check if an output is unspent.
105
+ *
106
+ * @param outputId - The output ID.
107
+ * @returns true if the output exists and has not been spent.
108
+ */
109
+ isUnspent(outputId) {
110
+ if (this.#spentSet.has(outputId)) {
111
+ return false;
112
+ }
113
+ const output = this.#store.get(outputId);
114
+ return output !== undefined;
115
+ }
116
+ /**
117
+ * Mark an output as spent.
118
+ *
119
+ * @param outputId - The output ID.
120
+ * @throws Error if output does not exist or is already spent.
121
+ */
122
+ markSpent(outputId) {
123
+ const output = this.#store.get(outputId);
124
+ if (!output) {
125
+ throw new Error(`Output ${outputId} does not exist`);
126
+ }
127
+ if (this.#spentSet.has(outputId)) {
128
+ throw new Error(`Output ${outputId} is already spent`);
129
+ }
130
+ this.#spentSet.add(outputId);
131
+ }
132
+ /**
133
+ * Get all unspent outputs.
134
+ *
135
+ * @returns Array of unspent P2MR outputs.
136
+ */
137
+ getUnspent() {
138
+ const all = Array.from(this.#store.values());
139
+ return all.filter((output) => !this.#spentSet.has(output.outputId));
140
+ }
141
+ /**
142
+ * Get total value of all unspent outputs.
143
+ *
144
+ * @returns Sum of all unspent output values.
145
+ */
146
+ getUnspentBalance() {
147
+ const unspent = this.getUnspent();
148
+ return unspent.reduce((sum, output) => sum + output.value, BigInt(0));
149
+ }
150
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * P2MR Module Ports (Hexagonal Architecture)
3
+ *
4
+ * These ports define the boundaries between the P2MR domain and infrastructure.
5
+ * Domain code MUST only depend on these interfaces, never on concrete implementations.
6
+ *
7
+ * @see docs/adr/ADR-0001-hexagonal-architecture.md
8
+ */
9
+ /**
10
+ * Supported post-quantum signature algorithms.
11
+ */
12
+ export type SignatureAlgorithm = "ml-dsa-65" | "ml-dsa-44" | "ml-dsa-87";
13
+ /**
14
+ * Port for post-quantum signature verification.
15
+ *
16
+ * The P2MR domain requires signature verification for:
17
+ * - Single signature script leaves (ml-dsa-65-sig)
18
+ * - Timelock script leaves (signature + time condition)
19
+ * - Multisig script leaves (k-of-n threshold signatures)
20
+ * - HSM-attested signatures
21
+ *
22
+ * Implementations MUST use NIST-approved post-quantum algorithms.
23
+ */
24
+ export interface SignatureVerificationPort {
25
+ /**
26
+ * Verify a post-quantum signature.
27
+ *
28
+ * @param message The message that was signed.
29
+ * @param signature The signature bytes.
30
+ * @param publicKey The signer's public key.
31
+ * @param algorithm The signature algorithm used.
32
+ * @returns True if the signature is valid, false otherwise.
33
+ */
34
+ verify(message: Uint8Array, signature: Uint8Array, publicKey: Uint8Array, algorithm: SignatureAlgorithm): boolean;
35
+ }
36
+ /**
37
+ * Port for cryptographic hashing operations.
38
+ *
39
+ * The P2MR domain uses hashing for:
40
+ * - Computing public key hashes for script leaves
41
+ * - Building Merkle trees from script leaves
42
+ * - Creating spend transaction digests
43
+ */
44
+ export interface HashingPort {
45
+ /**
46
+ * Compute SHA-256 hash of a hex string.
47
+ * @param data Hex-encoded input data.
48
+ * @returns Hex-encoded hash.
49
+ */
50
+ sha256hex(data: string): string;
51
+ }
52
+ //# sourceMappingURL=ports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ports.d.ts","sourceRoot":"","sources":["../../src/p2mr/ports.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,WAAW,GAAG,WAAW,GAAG,WAAW,CAAC;AAEzE;;;;;;;;;;GAUG;AACH,MAAM,WAAW,yBAAyB;IACxC;;;;;;;;OAQG;IACH,MAAM,CACJ,OAAO,EAAE,UAAU,EACnB,SAAS,EAAE,UAAU,EACrB,SAAS,EAAE,UAAU,EACrB,SAAS,EAAE,kBAAkB,GAC5B,OAAO,CAAC;CACZ;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B;;;;OAIG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CACjC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * P2MR Module Ports (Hexagonal Architecture)
3
+ *
4
+ * These ports define the boundaries between the P2MR domain and infrastructure.
5
+ * Domain code MUST only depend on these interfaces, never on concrete implementations.
6
+ *
7
+ * @see docs/adr/ADR-0001-hexagonal-architecture.md
8
+ */
9
+ export {};
@@ -0,0 +1,92 @@
1
+ /**
2
+ * P2MR Script Interpreter
3
+ *
4
+ * Executes spending conditions by verifying witness data against script leaves.
5
+ * Each leaf type has specific verification rules:
6
+ *
7
+ * - ml-dsa-65-sig: Single ML-DSA-65 signature verification
8
+ * - timelock: ML-DSA-65 signature + timestamp >= locktime
9
+ * - multisig-ml-dsa: k-of-n threshold ML-DSA-65 signatures
10
+ * - hsm-attested-sig: ML-DSA-65 signature + HSM attestation (placeholder)
11
+ *
12
+ * The interpreter returns a detailed audit trail for compliance.
13
+ */
14
+ import type { SignatureVerificationPort, HashingPort } from "./ports.js";
15
+ import type { ScriptLeaf, SpendWitness, ScriptVerificationResult, VerificationStep } from "./types.js";
16
+ /**
17
+ * Configure the script interpreter with custom implementations.
18
+ * Primarily useful for testing with mock implementations.
19
+ *
20
+ * @param options Configuration options.
21
+ */
22
+ export declare function configureInterpreter(options: {
23
+ signatureVerifier?: SignatureVerificationPort;
24
+ hasher?: HashingPort;
25
+ }): void;
26
+ /**
27
+ * Reset interpreter to default implementations.
28
+ */
29
+ export declare function resetInterpreter(): void;
30
+ /**
31
+ * Options for script interpretation.
32
+ */
33
+ export interface InterpretScriptOptions {
34
+ /**
35
+ * The spending condition to verify.
36
+ */
37
+ leaf: ScriptLeaf;
38
+ /**
39
+ * Witness data (public keys, signatures, etc.).
40
+ */
41
+ witness: SpendWitness;
42
+ /**
43
+ * Message that was signed (typically a spend transaction hash).
44
+ */
45
+ message: Uint8Array;
46
+ /**
47
+ * Optional current block time for timelock verification.
48
+ * If not provided, uses the timestamp from the witness.
49
+ */
50
+ currentTime?: number;
51
+ }
52
+ /**
53
+ * Result of script interpretation with audit trail.
54
+ */
55
+ export interface InterpretScriptResult extends ScriptVerificationResult {
56
+ /** Detailed audit trail of verification steps. */
57
+ auditTrail: VerificationStep[];
58
+ }
59
+ /**
60
+ * Interpret (execute) a P2MR script leaf against witness data.
61
+ *
62
+ * This function performs full cryptographic verification of the spending
63
+ * condition using ML-DSA-65 signatures.
64
+ *
65
+ * @param options - Interpretation options.
66
+ * @returns Verification result with audit trail.
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * const result = interpretScript({
71
+ * leaf: singleSigLeaf,
72
+ * witness: {
73
+ * publicKeys: [myPublicKey],
74
+ * signatures: [mySignature],
75
+ * },
76
+ * message: transactionHash,
77
+ * });
78
+ *
79
+ * if (result.valid) {
80
+ * console.log("Spending condition satisfied");
81
+ * }
82
+ * ```
83
+ */
84
+ export declare function interpretScript(options: InterpretScriptOptions): InterpretScriptResult;
85
+ /**
86
+ * Compute SHA-256 hash of a public key.
87
+ *
88
+ * The public key is converted to hex, then hashed.
89
+ * This matches the format stored in ScriptLeaf.publicKeyHashes.
90
+ */
91
+ export declare function hashPublicKey(publicKey: Uint8Array): string;
92
+ //# sourceMappingURL=script-interpreter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script-interpreter.d.ts","sourceRoot":"","sources":["../../src/p2mr/script-interpreter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,yBAAyB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzE,OAAO,KAAK,EACV,UAAU,EACV,YAAY,EACZ,wBAAwB,EACxB,gBAAgB,EACjB,MAAM,YAAY,CAAC;AAMpB;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE;IAC5C,iBAAiB,CAAC,EAAE,yBAAyB,CAAC;IAC9C,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,GAAG,IAAI,CAOP;AAED;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAGvC;AAMD;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,IAAI,EAAE,UAAU,CAAC;IAEjB;;OAEG;IACH,OAAO,EAAE,YAAY,CAAC;IAEtB;;OAEG;IACH,OAAO,EAAE,UAAU,CAAC;IAEpB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,wBAAwB;IACrE,kDAAkD;IAClD,UAAU,EAAE,gBAAgB,EAAE,CAAC;CAChC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,sBAAsB,GAC9B,qBAAqB,CAiCvB;AAyhBD;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,UAAU,GAAG,MAAM,CAE3D"}