@parmana/crypto 0.0.0-stage → 0.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 (209) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +8 -0
  3. package/README.md +16 -2
  4. package/dist/.tsbuildinfo +1 -0
  5. package/dist/ApprovalArtifactCrypto.d.ts +33 -0
  6. package/dist/ApprovalArtifactCrypto.d.ts.map +1 -0
  7. package/dist/ApprovalArtifactCrypto.js +54 -0
  8. package/dist/ApprovalArtifactCrypto.js.map +1 -0
  9. package/dist/ArtifactSigner.d.ts +22 -0
  10. package/dist/ArtifactSigner.d.ts.map +1 -0
  11. package/dist/ArtifactSigner.js +29 -0
  12. package/dist/ArtifactSigner.js.map +1 -0
  13. package/dist/AuditEventCrypto.d.ts +39 -0
  14. package/dist/AuditEventCrypto.d.ts.map +1 -0
  15. package/dist/AuditEventCrypto.js +57 -0
  16. package/dist/AuditEventCrypto.js.map +1 -0
  17. package/dist/AuthorizationSigner.d.ts +56 -0
  18. package/dist/AuthorizationSigner.d.ts.map +1 -0
  19. package/dist/AuthorizationSigner.js +103 -0
  20. package/dist/AuthorizationSigner.js.map +1 -0
  21. package/dist/AuthorizationVerifier.d.ts +53 -0
  22. package/dist/AuthorizationVerifier.d.ts.map +1 -0
  23. package/dist/AuthorizationVerifier.js +66 -0
  24. package/dist/AuthorizationVerifier.js.map +1 -0
  25. package/dist/CallerAuditChainVerifier.d.ts +62 -0
  26. package/dist/CallerAuditChainVerifier.d.ts.map +1 -0
  27. package/dist/CallerAuditChainVerifier.js +97 -0
  28. package/dist/CallerAuditChainVerifier.js.map +1 -0
  29. package/dist/CanonicalSerializer.d.ts +26 -0
  30. package/dist/CanonicalSerializer.d.ts.map +1 -0
  31. package/dist/CanonicalSerializer.js +78 -0
  32. package/dist/CanonicalSerializer.js.map +1 -0
  33. package/dist/CryptoBootstrap.d.ts +27 -0
  34. package/dist/CryptoBootstrap.d.ts.map +1 -0
  35. package/dist/CryptoBootstrap.js +70 -0
  36. package/dist/CryptoBootstrap.js.map +1 -0
  37. package/dist/CryptoBuilder.d.ts +27 -0
  38. package/dist/CryptoBuilder.d.ts.map +1 -0
  39. package/dist/CryptoBuilder.js +42 -0
  40. package/dist/CryptoBuilder.js.map +1 -0
  41. package/dist/ExecutableContentHasher.d.ts +22 -0
  42. package/dist/ExecutableContentHasher.d.ts.map +1 -0
  43. package/dist/ExecutableContentHasher.js +25 -0
  44. package/dist/ExecutableContentHasher.js.map +1 -0
  45. package/dist/ExecutionChainCrypto.d.ts +78 -0
  46. package/dist/ExecutionChainCrypto.d.ts.map +1 -0
  47. package/dist/ExecutionChainCrypto.js +165 -0
  48. package/dist/ExecutionChainCrypto.js.map +1 -0
  49. package/dist/ExecutionChainHasher.d.ts +10 -0
  50. package/dist/ExecutionChainHasher.d.ts.map +1 -0
  51. package/dist/ExecutionChainHasher.js +13 -0
  52. package/dist/ExecutionChainHasher.js.map +1 -0
  53. package/dist/ExecutionIntentCanonicalView.d.ts +28 -0
  54. package/dist/ExecutionIntentCanonicalView.d.ts.map +1 -0
  55. package/dist/ExecutionIntentCanonicalView.js +29 -0
  56. package/dist/ExecutionIntentCanonicalView.js.map +1 -0
  57. package/dist/ExecutionIntentCrypto.d.ts +21 -0
  58. package/dist/ExecutionIntentCrypto.d.ts.map +1 -0
  59. package/dist/ExecutionIntentCrypto.js +47 -0
  60. package/dist/ExecutionIntentCrypto.js.map +1 -0
  61. package/dist/ExecutionTrustRecordCanonicalView.d.ts +89 -0
  62. package/dist/ExecutionTrustRecordCanonicalView.d.ts.map +1 -0
  63. package/dist/ExecutionTrustRecordCanonicalView.js +106 -0
  64. package/dist/ExecutionTrustRecordCanonicalView.js.map +1 -0
  65. package/dist/HybridSignatureProvider.d.ts +48 -0
  66. package/dist/HybridSignatureProvider.d.ts.map +1 -0
  67. package/dist/HybridSignatureProvider.js +90 -0
  68. package/dist/HybridSignatureProvider.js.map +1 -0
  69. package/dist/KeyBootstrap.d.ts +23 -0
  70. package/dist/KeyBootstrap.d.ts.map +1 -0
  71. package/dist/KeyBootstrap.js +37 -0
  72. package/dist/KeyBootstrap.js.map +1 -0
  73. package/dist/KeyExpiry.d.ts +34 -0
  74. package/dist/KeyExpiry.d.ts.map +1 -0
  75. package/dist/KeyExpiry.js +66 -0
  76. package/dist/KeyExpiry.js.map +1 -0
  77. package/dist/KeyPair.d.ts +25 -0
  78. package/dist/KeyPair.d.ts.map +1 -0
  79. package/dist/KeyPair.js +37 -0
  80. package/dist/KeyPair.js.map +1 -0
  81. package/dist/KeyProvider.d.ts +98 -0
  82. package/dist/KeyProvider.d.ts.map +1 -0
  83. package/dist/KeyProvider.js +57 -0
  84. package/dist/KeyProvider.js.map +1 -0
  85. package/dist/KeyStore.d.ts +35 -0
  86. package/dist/KeyStore.d.ts.map +1 -0
  87. package/dist/KeyStore.js +2 -0
  88. package/dist/KeyStore.js.map +1 -0
  89. package/dist/OfflineVerifier.d.ts +80 -0
  90. package/dist/OfflineVerifier.d.ts.map +1 -0
  91. package/dist/OfflineVerifier.js +271 -0
  92. package/dist/OfflineVerifier.js.map +1 -0
  93. package/dist/PolicyChangeCrypto.d.ts +44 -0
  94. package/dist/PolicyChangeCrypto.d.ts.map +1 -0
  95. package/dist/PolicyChangeCrypto.js +79 -0
  96. package/dist/PolicyChangeCrypto.js.map +1 -0
  97. package/dist/PolicyChangeStepUpAuthorizationCrypto.d.ts +55 -0
  98. package/dist/PolicyChangeStepUpAuthorizationCrypto.d.ts.map +1 -0
  99. package/dist/PolicyChangeStepUpAuthorizationCrypto.js +107 -0
  100. package/dist/PolicyChangeStepUpAuthorizationCrypto.js.map +1 -0
  101. package/dist/ReceiptCrypto.d.ts +44 -0
  102. package/dist/ReceiptCrypto.d.ts.map +1 -0
  103. package/dist/ReceiptCrypto.js +84 -0
  104. package/dist/ReceiptCrypto.js.map +1 -0
  105. package/dist/ReceiptHasher.d.ts +10 -0
  106. package/dist/ReceiptHasher.d.ts.map +1 -0
  107. package/dist/ReceiptHasher.js +13 -0
  108. package/dist/ReceiptHasher.js.map +1 -0
  109. package/dist/RefusalCrypto.d.ts +35 -0
  110. package/dist/RefusalCrypto.d.ts.map +1 -0
  111. package/dist/RefusalCrypto.js +73 -0
  112. package/dist/RefusalCrypto.js.map +1 -0
  113. package/dist/SignatureCommitment.d.ts +33 -0
  114. package/dist/SignatureCommitment.d.ts.map +1 -0
  115. package/dist/SignatureCommitment.js +42 -0
  116. package/dist/SignatureCommitment.js.map +1 -0
  117. package/dist/SignatureVerifier.d.ts +20 -0
  118. package/dist/SignatureVerifier.d.ts.map +1 -0
  119. package/dist/SignatureVerifier.js +25 -0
  120. package/dist/SignatureVerifier.js.map +1 -0
  121. package/dist/Signer.d.ts +49 -0
  122. package/dist/Signer.d.ts.map +1 -0
  123. package/dist/Signer.js +2 -0
  124. package/dist/Signer.js.map +1 -0
  125. package/dist/SignerBootstrap.d.ts +37 -0
  126. package/dist/SignerBootstrap.d.ts.map +1 -0
  127. package/dist/SignerBootstrap.js +52 -0
  128. package/dist/SignerBootstrap.js.map +1 -0
  129. package/dist/TrustRecordHasher.d.ts +18 -0
  130. package/dist/TrustRecordHasher.d.ts.map +1 -0
  131. package/dist/TrustRecordHasher.js +23 -0
  132. package/dist/TrustRecordHasher.js.map +1 -0
  133. package/dist/VerificationCrypto.d.ts +132 -0
  134. package/dist/VerificationCrypto.d.ts.map +1 -0
  135. package/dist/VerificationCrypto.js +229 -0
  136. package/dist/VerificationCrypto.js.map +1 -0
  137. package/dist/errors/CryptoError.d.ts +14 -0
  138. package/dist/errors/CryptoError.d.ts.map +1 -0
  139. package/dist/errors/CryptoError.js +18 -0
  140. package/dist/errors/CryptoError.js.map +1 -0
  141. package/dist/index.d.ts +49 -0
  142. package/dist/index.d.ts.map +1 -0
  143. package/dist/index.js +73 -0
  144. package/dist/index.js.map +1 -0
  145. package/dist/models/HybridCryptoProvider.d.ts +9 -0
  146. package/dist/models/HybridCryptoProvider.d.ts.map +1 -0
  147. package/dist/models/HybridCryptoProvider.js +2 -0
  148. package/dist/models/HybridCryptoProvider.js.map +1 -0
  149. package/dist/providers/CryptoProvider.d.ts +15 -0
  150. package/dist/providers/CryptoProvider.d.ts.map +1 -0
  151. package/dist/providers/CryptoProvider.js +2 -0
  152. package/dist/providers/CryptoProvider.js.map +1 -0
  153. package/dist/providers/HashProvider.d.ts +17 -0
  154. package/dist/providers/HashProvider.d.ts.map +1 -0
  155. package/dist/providers/HashProvider.js +2 -0
  156. package/dist/providers/HashProvider.js.map +1 -0
  157. package/dist/providers/HashRegistry.d.ts +11 -0
  158. package/dist/providers/HashRegistry.d.ts.map +1 -0
  159. package/dist/providers/HashRegistry.js +18 -0
  160. package/dist/providers/HashRegistry.js.map +1 -0
  161. package/dist/providers/ProviderFactory.d.ts +11 -0
  162. package/dist/providers/ProviderFactory.d.ts.map +1 -0
  163. package/dist/providers/ProviderFactory.js +13 -0
  164. package/dist/providers/ProviderFactory.js.map +1 -0
  165. package/dist/providers/SignatureProvider.d.ts +25 -0
  166. package/dist/providers/SignatureProvider.d.ts.map +1 -0
  167. package/dist/providers/SignatureProvider.js +2 -0
  168. package/dist/providers/SignatureProvider.js.map +1 -0
  169. package/dist/providers/SignatureRegistry.d.ts +11 -0
  170. package/dist/providers/SignatureRegistry.d.ts.map +1 -0
  171. package/dist/providers/SignatureRegistry.js +18 -0
  172. package/dist/providers/SignatureRegistry.js.map +1 -0
  173. package/dist/providers/SignerKeyProviderAdapter.d.ts +50 -0
  174. package/dist/providers/SignerKeyProviderAdapter.d.ts.map +1 -0
  175. package/dist/providers/SignerKeyProviderAdapter.js +66 -0
  176. package/dist/providers/SignerKeyProviderAdapter.js.map +1 -0
  177. package/dist/providers/hash/SHA256HashProvider.d.ts +10 -0
  178. package/dist/providers/hash/SHA256HashProvider.d.ts.map +1 -0
  179. package/dist/providers/hash/SHA256HashProvider.js +12 -0
  180. package/dist/providers/hash/SHA256HashProvider.js.map +1 -0
  181. package/dist/providers/key/FileKeyProvider.d.ts +85 -0
  182. package/dist/providers/key/FileKeyProvider.d.ts.map +1 -0
  183. package/dist/providers/key/FileKeyProvider.js +163 -0
  184. package/dist/providers/key/FileKeyProvider.js.map +1 -0
  185. package/dist/providers/signature/Dilithium3SignatureProvider.d.ts +23 -0
  186. package/dist/providers/signature/Dilithium3SignatureProvider.d.ts.map +1 -0
  187. package/dist/providers/signature/Dilithium3SignatureProvider.js +33 -0
  188. package/dist/providers/signature/Dilithium3SignatureProvider.js.map +1 -0
  189. package/dist/providers/signature/Ed25519SignatureProvider.d.ts +17 -0
  190. package/dist/providers/signature/Ed25519SignatureProvider.d.ts.map +1 -0
  191. package/dist/providers/signature/Ed25519SignatureProvider.js +40 -0
  192. package/dist/providers/signature/Ed25519SignatureProvider.js.map +1 -0
  193. package/dist/providers/signature/assertKeyType.d.ts +14 -0
  194. package/dist/providers/signature/assertKeyType.d.ts.map +1 -0
  195. package/dist/providers/signature/assertKeyType.js +19 -0
  196. package/dist/providers/signature/assertKeyType.js.map +1 -0
  197. package/dist/providers/signer/KmsSigner.d.ts +71 -0
  198. package/dist/providers/signer/KmsSigner.d.ts.map +1 -0
  199. package/dist/providers/signer/KmsSigner.js +270 -0
  200. package/dist/providers/signer/KmsSigner.js.map +1 -0
  201. package/dist/providers/signer/LocalFileSigner.d.ts +28 -0
  202. package/dist/providers/signer/LocalFileSigner.d.ts.map +1 -0
  203. package/dist/providers/signer/LocalFileSigner.js +38 -0
  204. package/dist/providers/signer/LocalFileSigner.js.map +1 -0
  205. package/dist/support/MlDsaSupport.d.ts +9 -0
  206. package/dist/support/MlDsaSupport.d.ts.map +1 -0
  207. package/dist/support/MlDsaSupport.js +23 -0
  208. package/dist/support/MlDsaSupport.js.map +1 -0
  209. package/package.json +45 -4
@@ -0,0 +1,165 @@
1
+ import { CryptoBootstrap } from "./CryptoBootstrap.js";
2
+ import { TrustRecordHasher } from "./TrustRecordHasher.js";
3
+ import { ExecutionChainHasher } from "./ExecutionChainHasher.js";
4
+ import { ArtifactSigner } from "./ArtifactSigner.js";
5
+ import { SignatureVerifier } from "./SignatureVerifier.js";
6
+ import { SignerBootstrap } from "./SignerBootstrap.js";
7
+ import { DEFAULT_KEY_ID } from "./KeyProvider.js";
8
+ /**
9
+ * Execution Chain cryptographic operations.
10
+ *
11
+ * Signs a hash chain over the Executions belonging to one
12
+ * business_transaction_id, reusing the same ArtifactSigner /
13
+ * FileKeyProvider / DEFAULT_KEY_ID stack as every other signed
14
+ * artifact (ReceiptCrypto, VerificationCrypto, PolicyChangeCrypto) --
15
+ * not a third key to manage.
16
+ *
17
+ * A plain SHA-256 hash stored alongside the content it hashes gives no
18
+ * protection against an actor who already has UPDATE rights on the
19
+ * executions row (they can recompute a fresh valid hash over tampered
20
+ * content in the same statement). Signing each chainHash with
21
+ * Parmana's private key closes that: an actor with DB write access but
22
+ * not the private key cannot forge a replacement chain link.
23
+ */
24
+ export class ExecutionChainCrypto {
25
+ crypto = CryptoBootstrap.create();
26
+ signerPromise = SignerBootstrap.create();
27
+ chainHasher = new ExecutionChainHasher(new TrustRecordHasher(this.crypto));
28
+ signer = new ArtifactSigner(this.crypto);
29
+ verifier = new SignatureVerifier(this.crypto);
30
+ /**
31
+ * Creates the canonical immutable view of one Execution chain
32
+ * link used for hashing and signing. Deliberately excludes
33
+ * chainHash/chainSignature themselves -- the same discipline
34
+ * VerificationCrypto.canonicalRecord already applies to
35
+ * trustRecordHash/signature -- so the signed content never
36
+ * includes its own signature.
37
+ *
38
+ * previousChainHash IS included: it is the chain-linking element,
39
+ * and must be covered by the signature so an attacker cannot
40
+ * re-point this link at a different predecessor without
41
+ * invalidating chainSignature.
42
+ */
43
+ canonicalChainEntry(execution, previousChainHash) {
44
+ return {
45
+ executionId: execution.executionId,
46
+ businessTransactionId: execution.businessTransactionId,
47
+ decision: execution.decision,
48
+ status: execution.status,
49
+ mode: execution.mode,
50
+ startedAt: execution.startedAt,
51
+ completedAt: execution.completedAt ?? null,
52
+ evidence: execution.evidence ?? null,
53
+ metadata: execution.metadata ?? null,
54
+ previousChainHash,
55
+ };
56
+ }
57
+ /**
58
+ * Computes (chainHash, chainSignature) for one Execution given its
59
+ * fixed previousChainHash -- the chain predecessor's chainHash, or
60
+ * null for the first Execution in a business transaction's chain.
61
+ */
62
+ async chain(execution, previousChainHash) {
63
+ const entry = this.canonicalChainEntry(execution, previousChainHash);
64
+ const chainHash = await this.chainHasher.hash(entry);
65
+ const keyId = DEFAULT_KEY_ID;
66
+ const signer = await this.signerPromise;
67
+ const value = await this.signer.signWithSigner(entry, keyId, signer);
68
+ const chainSignature = {
69
+ algorithm: this.crypto.signature.algorithm,
70
+ keyId,
71
+ value,
72
+ signedAt: new Date(),
73
+ };
74
+ return {
75
+ previousChainHash,
76
+ chainHash,
77
+ chainSignature,
78
+ };
79
+ }
80
+ /**
81
+ * Verifies one Execution's own chainHash and chainSignature against
82
+ * its recomputed canonical content. Does not check chain linkage --
83
+ * see verifyChain() for that.
84
+ */
85
+ async verifyEntry(execution) {
86
+ if (execution.chainHash === undefined ||
87
+ execution.chainSignature === undefined) {
88
+ return false;
89
+ }
90
+ const previousChainHash = execution.previousChainHash ?? null;
91
+ const entry = this.canonicalChainEntry(execution, previousChainHash);
92
+ const expectedHash = await this.chainHasher.hash(entry);
93
+ if (expectedHash !== execution.chainHash) {
94
+ return false;
95
+ }
96
+ const signer = await this.signerPromise;
97
+ const publicKey = await signer.getPublicKey(execution.chainSignature.keyId);
98
+ return this.verifier.verify(entry, execution.chainSignature.value, publicKey);
99
+ }
100
+ /**
101
+ * Walks Executions in their already-established (created_at, seq)
102
+ * append order and verifies both per-entry authenticity and
103
+ * previousChainHash linkage to the prior entry's chainHash.
104
+ *
105
+ * An Execution with no chain fields at all is treated as
106
+ * unprotected legacy data -- neither verified nor required to
107
+ * link -- so historical rows and pre-feature test fixtures don't
108
+ * fail verification.
109
+ */
110
+ async verifyChain(executions) {
111
+ let previous;
112
+ let chainStarted = false;
113
+ for (const execution of executions) {
114
+ const isChained = execution.chainHash !== undefined &&
115
+ execution.chainSignature !== undefined;
116
+ //
117
+ // chain() always writes chainHash and chainSignature together,
118
+ // so an Execution carrying only some chain fields was altered:
119
+ // removing chainSignature must not turn an edited Execution into
120
+ // "unprotected legacy data" that is skipped. Likewise, once the
121
+ // chain has started, a later Execution without chain fields is a
122
+ // break, not legacy data: legacy Executions predate chaining.
123
+ //
124
+ const hasAnyChainField = execution.chainHash !== undefined ||
125
+ execution.chainSignature !== undefined ||
126
+ (execution.previousChainHash ?? null) !== null;
127
+ if (!isChained && hasAnyChainField) {
128
+ return {
129
+ valid: false,
130
+ brokenAt: execution.executionId,
131
+ reason: "Execution carries only some chain fields; chainHash and chainSignature are always written together.",
132
+ };
133
+ }
134
+ if (!isChained && chainStarted) {
135
+ return {
136
+ valid: false,
137
+ brokenAt: execution.executionId,
138
+ reason: "Execution has no chain fields but follows a chained execution.",
139
+ };
140
+ }
141
+ if (isChained) {
142
+ chainStarted = true;
143
+ const entryValid = await this.verifyEntry(execution);
144
+ if (!entryValid) {
145
+ return {
146
+ valid: false,
147
+ brokenAt: execution.executionId,
148
+ reason: "chainHash or chainSignature does not match recomputed content.",
149
+ };
150
+ }
151
+ const expectedPrevious = previous?.chainHash ?? null;
152
+ if ((execution.previousChainHash ?? null) !== expectedPrevious) {
153
+ return {
154
+ valid: false,
155
+ brokenAt: execution.executionId,
156
+ reason: "previousChainHash does not reference the prior execution's chainHash.",
157
+ };
158
+ }
159
+ }
160
+ previous = execution;
161
+ }
162
+ return { valid: true };
163
+ }
164
+ }
165
+ //# sourceMappingURL=ExecutionChainCrypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExecutionChainCrypto.js","sourceRoot":"","sources":["../src/ExecutionChainCrypto.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,oBA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AW;wBAC/B,MAAM,EACJ,gEAAgE;qBACnE,CAAC;gBACJ,CAAC;gBAED,MAAM,gBAAgB,GAAG,QAAQ,EAAE,SAAS,IAAI,IAAI,CAAC;gBAErD,IAAI,CAAC,SAAS,CAAC,iBAAiB,IAAI,IAAI,CAAC,KAAK,gBAAgB,EAAE,CAAC;oBAC/D,OAAO;wBACL,KAAK,EAAE,KAAK;wBACZ,QAAQ,EAAE,SAAS,CAAC,WAAW;wBAC/B,MAAM,EACJ,uEAAuE;qBAC1E,CAAC;gBACJ,CAAC;YACH,CAAC;YAED,QAAQ,GAAG,SAAS,CAAC;QACvB,CAAC;QAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACzB,CAAC;CACF"}
@@ -0,0 +1,10 @@
1
+ import { TrustRecordHasher } from "./TrustRecordHasher.js";
2
+ /**
3
+ * Execution Chain Hasher.
4
+ */
5
+ export declare class ExecutionChainHasher {
6
+ private readonly hasher;
7
+ constructor(hasher: TrustRecordHasher);
8
+ hash(chainEntry: unknown): Promise<string>;
9
+ }
10
+ //# sourceMappingURL=ExecutionChainHasher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExecutionChainHasher.d.ts","sourceRoot":"","sources":["../src/ExecutionChainHasher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;GAEG;AACH,qBAAa,oBAAoB;IACnB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAAnC,YAA6B,MAAM,EAAE,iBAAiB,EAAI;IAEpD,IAAI,CAAC,UAAU,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAE/C;CACF"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Execution Chain Hasher.
3
+ */
4
+ export class ExecutionChainHasher {
5
+ hasher;
6
+ constructor(hasher) {
7
+ this.hasher = hasher;
8
+ }
9
+ async hash(chainEntry) {
10
+ return this.hasher.hash(chainEntry);
11
+ }
12
+ }
13
+ //# sourceMappingURL=ExecutionChainHasher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExecutionChainHasher.js","sourceRoot":"","sources":["../src/ExecutionChainHasher.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,oBAAoB;IACF,MAAM;IAAnC,YAA6B,MAAyB;sBAAzB,MAAM;IAAsB,CAAC;IAE1D,KAAK,CAAC,IAAI,CAAC,UAAmB;QAC5B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACtC,CAAC;CACF"}
@@ -0,0 +1,28 @@
1
+ import type { ExecutionIntent } from "@parmana/shared";
2
+ /**
3
+ * The exact projection of an Execution Intent that is hashed and signed
4
+ * (ADR-0012). It excludes `intentHash` and `signature`, which are computed
5
+ * from it.
6
+ *
7
+ * ExecutionIntentCrypto (signing and online verification) and
8
+ * verifyExecutionIntentOffline both use this one function, so the signer and
9
+ * every verifier can never disagree about what was signed. Changing what is
10
+ * included here changes what is signed, and invalidates every existing intent.
11
+ */
12
+ export declare function canonicalExecutionIntent(intent: ExecutionIntent): {
13
+ intentId: string;
14
+ businessTransactionId: string;
15
+ decisionId: string;
16
+ authorizationId: string;
17
+ policyName: string;
18
+ policyVersion: string;
19
+ policyContentHash: string | undefined;
20
+ signalsHash: string | undefined;
21
+ businessTransactionHash: string;
22
+ action: string;
23
+ target: string;
24
+ submittedBy: string | undefined;
25
+ grantedCapability: string | undefined;
26
+ createdAt: Date;
27
+ };
28
+ //# sourceMappingURL=ExecutionIntentCanonicalView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExecutionIntentCanonicalView.d.ts","sourceRoot":"","sources":["../src/ExecutionIntentCanonicalView.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAEvD;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,eAAe;IAE5D,QAAQ;IAER,qBAAqB;IAErB,UAAU;IAEV,eAAe;IAEf,UAAU;IAEV,aAAa;IAEb,iBAAiB;IAEjB,WAAW;IAEX,uBAAuB;IAEvB,MAAM;IAEN,MAAM;IAEN,WAAW;IAEX,iBAAiB;IAEjB,SAAS;EAEZ"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * The exact projection of an Execution Intent that is hashed and signed
3
+ * (ADR-0012). It excludes `intentHash` and `signature`, which are computed
4
+ * from it.
5
+ *
6
+ * ExecutionIntentCrypto (signing and online verification) and
7
+ * verifyExecutionIntentOffline both use this one function, so the signer and
8
+ * every verifier can never disagree about what was signed. Changing what is
9
+ * included here changes what is signed, and invalidates every existing intent.
10
+ */
11
+ export function canonicalExecutionIntent(intent) {
12
+ return {
13
+ intentId: intent.intentId,
14
+ businessTransactionId: intent.businessTransactionId,
15
+ decisionId: intent.decisionId,
16
+ authorizationId: intent.authorizationId,
17
+ policyName: intent.policyName,
18
+ policyVersion: intent.policyVersion,
19
+ policyContentHash: intent.policyContentHash,
20
+ signalsHash: intent.signalsHash,
21
+ businessTransactionHash: intent.businessTransactionHash,
22
+ action: intent.action,
23
+ target: intent.target,
24
+ submittedBy: intent.submittedBy,
25
+ grantedCapability: intent.grantedCapability,
26
+ createdAt: intent.createdAt,
27
+ };
28
+ }
29
+ //# sourceMappingURL=ExecutionIntentCanonicalView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExecutionIntentCanonicalView.js","sourceRoot":"","sources":["../src/ExecutionIntentCanonicalView.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,MAAM,UAAU,wBAAwB,CAAC,MAAuB;IAC9D,OAAO;QACL,QAAQ,EAAE,MAAM,CAAC,QAAQ;QAEzB,qBAAqB,EAAE,MAAM,CAAC,qBAAqB;QAEnD,UAAU,EAAE,MAAM,CAAC,UAAU;QAE7B,eAAe,EAAE,MAAM,CAAC,eAAe;QAEvC,UAAU,EAAE,MAAM,CAAC,UAAU;QAE7B,aAAa,EAAE,MAAM,CAAC,aAAa;QAEnC,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;QAE3C,WAAW,EAAE,MAAM,CAAC,WAAW;QAE/B,uBAAuB,EAAE,MAAM,CAAC,uBAAuB;QAEvD,MAAM,EAAE,MAAM,CAAC,MAAM;QAErB,MAAM,EAAE,MAAM,CAAC,MAAM;QAErB,WAAW,EAAE,MAAM,CAAC,WAAW;QAE/B,iBAAiB,EAAE,MAAM,CAAC,iBAAiB;QAE3C,SAAS,EAAE,MAAM,CAAC,SAAS;KAC5B,CAAC;AACJ,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { ExecutionIntent, Signature } from "@parmana/shared";
2
+ /**
3
+ * Hashes, signs and verifies an Execution Intent (ADR-0012).
4
+ *
5
+ * Same construction as RefusalCrypto: the signature covers a canonical
6
+ * projection of the intent that excludes `intentHash` and `signature`, it is
7
+ * made with the deployment's signing key (local or AWS KMS), and it verifies
8
+ * against the public key alone, so a third party can check an intent without
9
+ * access to the database.
10
+ */
11
+ export declare class ExecutionIntentCrypto {
12
+ private readonly crypto;
13
+ private readonly signerPromise;
14
+ private readonly hasher;
15
+ private readonly signer;
16
+ private readonly verifier;
17
+ hash(intent: ExecutionIntent): Promise<string>;
18
+ sign(intent: ExecutionIntent): Promise<Signature>;
19
+ verify(intent: ExecutionIntent): Promise<boolean>;
20
+ }
21
+ //# sourceMappingURL=ExecutionIntentCrypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExecutionIntentCrypto.d.ts","sourceRoot":"","sources":["../src/ExecutionIntentCrypto.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAUlE;;;;;;;;GAQG;AACH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4B;IAEnD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA4B;IAE1D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAsC;IAE7D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmC;IAE1D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAsC;IAEzD,IAAI,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAEnD;IAEK,IAAI,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,SAAS,CAAC,CAoBtD;IAEK,MAAM,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,CAgBtD;CACF"}
@@ -0,0 +1,47 @@
1
+ import { CryptoBootstrap } from "./CryptoBootstrap.js";
2
+ import { canonicalExecutionIntent } from "./ExecutionIntentCanonicalView.js";
3
+ import { TrustRecordHasher } from "./TrustRecordHasher.js";
4
+ import { ArtifactSigner } from "./ArtifactSigner.js";
5
+ import { SignatureVerifier } from "./SignatureVerifier.js";
6
+ import { SignerBootstrap } from "./SignerBootstrap.js";
7
+ import { currentVerificationKeyId } from "./KeyProvider.js";
8
+ /**
9
+ * Hashes, signs and verifies an Execution Intent (ADR-0012).
10
+ *
11
+ * Same construction as RefusalCrypto: the signature covers a canonical
12
+ * projection of the intent that excludes `intentHash` and `signature`, it is
13
+ * made with the deployment's signing key (local or AWS KMS), and it verifies
14
+ * against the public key alone, so a third party can check an intent without
15
+ * access to the database.
16
+ */
17
+ export class ExecutionIntentCrypto {
18
+ crypto = CryptoBootstrap.create();
19
+ signerPromise = SignerBootstrap.create();
20
+ hasher = new TrustRecordHasher(this.crypto);
21
+ signer = new ArtifactSigner(this.crypto);
22
+ verifier = new SignatureVerifier(this.crypto);
23
+ async hash(intent) {
24
+ return this.hasher.hash(canonicalExecutionIntent(intent));
25
+ }
26
+ async sign(intent) {
27
+ const keyId = currentVerificationKeyId();
28
+ const signer = await this.signerPromise;
29
+ const value = await this.signer.signWithSigner(canonicalExecutionIntent(intent), keyId, signer);
30
+ return {
31
+ algorithm: this.crypto.signature.algorithm,
32
+ keyId,
33
+ value,
34
+ signedAt: new Date(),
35
+ };
36
+ }
37
+ async verify(intent) {
38
+ const expectedHash = await this.hash(intent);
39
+ if (expectedHash !== intent.intentHash) {
40
+ return false;
41
+ }
42
+ const signer = await this.signerPromise;
43
+ const publicKey = await signer.getPublicKey(intent.signature.keyId);
44
+ return this.verifier.verify(canonicalExecutionIntent(intent), intent.signature.value, publicKey);
45
+ }
46
+ }
47
+ //# sourceMappingURL=ExecutionIntentCrypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExecutionIntentCrypto.js","sourceRoot":"","sources":["../src/ExecutionIntentCrypto.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAE5D;;;;;;;;GAQG;AACH,MAAM,OAAO,qBAAqB;IACf,MAAM,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC;IAElC,aAAa,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC;IAEzC,MAAM,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE5C,MAAM,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEzC,QAAQ,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE/D,KAAK,CAAC,IAAI,CAAC,MAAuB;QAChC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,wBAAwB,CAAC,MAAM,CAAC,CAAC,CAAC;IAC5D,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,MAAuB;QAChC,MAAM,KAAK,GAAG,wBAAwB,EAAE,CAAC;QAEzC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC;QAExC,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAC5C,wBAAwB,CAAC,MAAM,CAAC,EAChC,KAAK,EACL,MAAM,CACP,CAAC;QAEF,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS;YAE1C,KAAK;YAEL,KAAK;YAEL,QAAQ,EAAE,IAAI,IAAI,EAAE;SACrB,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,MAAuB;QAClC,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAE7C,IAAI,YAAY,KAAK,MAAM,CAAC,UAAU,EAAE,CAAC;YACvC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC;QAExC,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAEpE,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CACzB,wBAAwB,CAAC,MAAM,CAAC,EAChC,MAAM,CAAC,SAAS,CAAC,KAAK,EACtB,SAAS,CACV,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,89 @@
1
+ import type { ExecutionTrustRecord } from "@parmana/shared";
2
+ /**
3
+ * The exact canonical view of an Execution Trust Record that is
4
+ * hashed and signed -- extracted out of VerificationCrypto (which
5
+ * still delegates here, unchanged behavior) so there is exactly one
6
+ * implementation of "which fields participate in the signature,"
7
+ * shared by the online verifier (VerificationCrypto, which resolves
8
+ * keys via FileKeyProvider) and the offline verifier
9
+ * (OfflineVerifier.ts, which takes public keys directly and never
10
+ * touches disk, env vars, or the network). Two independent
11
+ * reimplementations of this field list would be a correctness risk in
12
+ * their own right -- exactly the kind of drift a third-party verifier
13
+ * must never have to guess at.
14
+ *
15
+ * PQC audit RED-1 (docs/VERIFICATION-GAPS.md): before this file
16
+ * existed, this mapping lived only as a private method on
17
+ * VerificationCrypto, so a third party had no way to reconstruct it
18
+ * without reading this repository's source directly. A separately
19
+ * published verifier now ships the same mapping (canonicalExecutionTrustRecord and
20
+ * hybridCanonicalExecutionTrustRecord); keep the two in sync.
21
+ */
22
+ export declare function canonicalExecutionTrustRecord(trustRecord: ExecutionTrustRecord): {
23
+ trustRecordId: string;
24
+ businessTransactionId: string;
25
+ transaction: import("@parmana/shared").BusinessTransaction;
26
+ authorization: import("@parmana/shared").SignedExecutionAuthorization | undefined;
27
+ overrides: readonly import("@parmana/shared").Override[];
28
+ executions: readonly import("@parmana/shared").Execution[];
29
+ createdAt: Date;
30
+ };
31
+ /**
32
+ * The canonical view signed/verified by the hybrid `signatures`
33
+ * array: the same content as canonicalExecutionTrustRecord(), plus
34
+ * schemaVersion. Kept separate so the legacy `signature` field's
35
+ * signed content -- and therefore its verifiability by pre-hybrid-era
36
+ * verifiers, including the published third-party verifier -- never changes.
37
+ */
38
+ export declare function hybridCanonicalExecutionTrustRecord(trustRecord: ExecutionTrustRecord, schemaVersion: number): {
39
+ trustRecordId: string;
40
+ businessTransactionId: string;
41
+ transaction: import("@parmana/shared").BusinessTransaction;
42
+ authorization: import("@parmana/shared").SignedExecutionAuthorization | undefined;
43
+ overrides: readonly import("@parmana/shared").Override[];
44
+ executions: readonly import("@parmana/shared").Execution[];
45
+ createdAt: Date;
46
+ schemaVersion: number;
47
+ };
48
+ /**
49
+ * Schema version of a hybrid envelope that signs the whole record
50
+ * (ADR-0016). Version 2 signs only the canonical fields plus schemaVersion.
51
+ */
52
+ export declare const WHOLE_RECORD_SCHEMA_VERSION = 3;
53
+ /**
54
+ * True when a record created at createdAt is at or after the cutover (ADR-0016,
55
+ * option 2). The instant itself is included. A record whose createdAt does not
56
+ * parse is not treated as after the cutover; its signatures fail on their own.
57
+ */
58
+ export declare function isAtOrAfterCutover(createdAt: Date | string, hybridRequiredFrom: string | undefined): boolean;
59
+ /**
60
+ * Hybrid schema versions this codebase can sign and verify. Anything else
61
+ * is rejected rather than canonicalized under a guessed view.
62
+ */
63
+ export declare const SUPPORTED_HYBRID_SCHEMA_VERSIONS: readonly [2, 3];
64
+ /**
65
+ * Selects the canonical view that a hybrid `signatures` array covers for
66
+ * a given schema version. Version 3 covers the whole record; every other
67
+ * version keeps the version 2 view, so existing records verify unchanged.
68
+ */
69
+ export declare function hybridSignedCanonicalView(trustRecord: ExecutionTrustRecord, schemaVersion: number): {
70
+ schemaVersion: number;
71
+ };
72
+ /**
73
+ * Top-level fields that a schema version 3 (whole-record) signature does
74
+ * not cover. The signature fields hold the signatures themselves.
75
+ * `verifications` and `receipts` are attached to the stored record after
76
+ * it is signed (ADR-0016); receipts carry their own signature.
77
+ */
78
+ export declare const WHOLE_RECORD_EXCLUDED_FIELDS: readonly ["signature", "signatures", "schemaVersion", "verifications", "receipts"];
79
+ /**
80
+ * The canonical view signed by a schema version 3 hybrid envelope: every
81
+ * top-level field of the record except WHOLE_RECORD_EXCLUDED_FIELDS, plus
82
+ * the schema version itself. `trustRecordHash` is covered, because it is
83
+ * set before the v3 signature is made. Built with Object.fromEntries, so a
84
+ * field named "__proto__" stays an ordinary covered field.
85
+ */
86
+ export declare function wholeRecordCanonicalView(trustRecord: ExecutionTrustRecord, schemaVersion: number): {
87
+ schemaVersion: number;
88
+ };
89
+ //# sourceMappingURL=ExecutionTrustRecordCanonicalView.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExecutionTrustRecordCanonicalView.d.ts","sourceRoot":"","sources":["../src/ExecutionTrustRecordCanonicalView.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,6BAA6B,CAC3C,WAAW,EAAE,oBAAoB;IAG/B,aAAa;IAEb,qBAAqB;IAErB,WAAW;IAEX,aAAa;IAEb,SAAS;IAET,UAAU;IAEV,SAAS;EAEZ;AAED;;;;;;GAMG;AACH,wBAAgB,mCAAmC,CACjD,WAAW,EAAE,oBAAoB,EACjC,aAAa,EAAE,MAAM;;;;;;;;;EAMtB;AAED;;;GAGG;AACH,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAE7C;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,IAAI,GAAG,MAAM,EACxB,kBAAkB,EAAE,MAAM,GAAG,SAAS,GACrC,OAAO,CAQT;AAED;;;GAGG;AACH,eAAO,MAAM,gCAAgC,YAAI,CAAC,EAAE,CAAC,CAAU,CAAC;AAEhE;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,WAAW,EAAE,oBAAoB,EACjC,aAAa,EAAE,MAAM;;EAOtB;AAED;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,YACvC,WAAW,EACX,YAAY,EACZ,eAAe,EACf,eAAe,EACf,UAAU,CACF,CAAC;AAEX;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,WAAW,EAAE,oBAAoB,EACjC,aAAa,EAAE,MAAM;;EAYtB"}
@@ -0,0 +1,106 @@
1
+ /**
2
+ * The exact canonical view of an Execution Trust Record that is
3
+ * hashed and signed -- extracted out of VerificationCrypto (which
4
+ * still delegates here, unchanged behavior) so there is exactly one
5
+ * implementation of "which fields participate in the signature,"
6
+ * shared by the online verifier (VerificationCrypto, which resolves
7
+ * keys via FileKeyProvider) and the offline verifier
8
+ * (OfflineVerifier.ts, which takes public keys directly and never
9
+ * touches disk, env vars, or the network). Two independent
10
+ * reimplementations of this field list would be a correctness risk in
11
+ * their own right -- exactly the kind of drift a third-party verifier
12
+ * must never have to guess at.
13
+ *
14
+ * PQC audit RED-1 (docs/VERIFICATION-GAPS.md): before this file
15
+ * existed, this mapping lived only as a private method on
16
+ * VerificationCrypto, so a third party had no way to reconstruct it
17
+ * without reading this repository's source directly. A separately
18
+ * published verifier now ships the same mapping (canonicalExecutionTrustRecord and
19
+ * hybridCanonicalExecutionTrustRecord); keep the two in sync.
20
+ */
21
+ export function canonicalExecutionTrustRecord(trustRecord) {
22
+ return {
23
+ trustRecordId: trustRecord.trustRecordId,
24
+ businessTransactionId: trustRecord.businessTransactionId,
25
+ transaction: trustRecord.transaction,
26
+ authorization: trustRecord.authorization,
27
+ overrides: trustRecord.overrides,
28
+ executions: trustRecord.executions,
29
+ createdAt: trustRecord.createdAt,
30
+ };
31
+ }
32
+ /**
33
+ * The canonical view signed/verified by the hybrid `signatures`
34
+ * array: the same content as canonicalExecutionTrustRecord(), plus
35
+ * schemaVersion. Kept separate so the legacy `signature` field's
36
+ * signed content -- and therefore its verifiability by pre-hybrid-era
37
+ * verifiers, including the published third-party verifier -- never changes.
38
+ */
39
+ export function hybridCanonicalExecutionTrustRecord(trustRecord, schemaVersion) {
40
+ return {
41
+ ...canonicalExecutionTrustRecord(trustRecord),
42
+ schemaVersion,
43
+ };
44
+ }
45
+ /**
46
+ * Schema version of a hybrid envelope that signs the whole record
47
+ * (ADR-0016). Version 2 signs only the canonical fields plus schemaVersion.
48
+ */
49
+ export const WHOLE_RECORD_SCHEMA_VERSION = 3;
50
+ /**
51
+ * True when a record created at createdAt is at or after the cutover (ADR-0016,
52
+ * option 2). The instant itself is included. A record whose createdAt does not
53
+ * parse is not treated as after the cutover; its signatures fail on their own.
54
+ */
55
+ export function isAtOrAfterCutover(createdAt, hybridRequiredFrom) {
56
+ if (hybridRequiredFrom === undefined) {
57
+ return false;
58
+ }
59
+ const created = new Date(createdAt).getTime();
60
+ return !Number.isNaN(created) && created >= Date.parse(hybridRequiredFrom);
61
+ }
62
+ /**
63
+ * Hybrid schema versions this codebase can sign and verify. Anything else
64
+ * is rejected rather than canonicalized under a guessed view.
65
+ */
66
+ export const SUPPORTED_HYBRID_SCHEMA_VERSIONS = [2, 3];
67
+ /**
68
+ * Selects the canonical view that a hybrid `signatures` array covers for
69
+ * a given schema version. Version 3 covers the whole record; every other
70
+ * version keeps the version 2 view, so existing records verify unchanged.
71
+ */
72
+ export function hybridSignedCanonicalView(trustRecord, schemaVersion) {
73
+ if (schemaVersion === WHOLE_RECORD_SCHEMA_VERSION) {
74
+ return wholeRecordCanonicalView(trustRecord, schemaVersion);
75
+ }
76
+ return hybridCanonicalExecutionTrustRecord(trustRecord, schemaVersion);
77
+ }
78
+ /**
79
+ * Top-level fields that a schema version 3 (whole-record) signature does
80
+ * not cover. The signature fields hold the signatures themselves.
81
+ * `verifications` and `receipts` are attached to the stored record after
82
+ * it is signed (ADR-0016); receipts carry their own signature.
83
+ */
84
+ export const WHOLE_RECORD_EXCLUDED_FIELDS = [
85
+ "signature",
86
+ "signatures",
87
+ "schemaVersion",
88
+ "verifications",
89
+ "receipts",
90
+ ];
91
+ /**
92
+ * The canonical view signed by a schema version 3 hybrid envelope: every
93
+ * top-level field of the record except WHOLE_RECORD_EXCLUDED_FIELDS, plus
94
+ * the schema version itself. `trustRecordHash` is covered, because it is
95
+ * set before the v3 signature is made. Built with Object.fromEntries, so a
96
+ * field named "__proto__" stays an ordinary covered field.
97
+ */
98
+ export function wholeRecordCanonicalView(trustRecord, schemaVersion) {
99
+ const excluded = WHOLE_RECORD_EXCLUDED_FIELDS;
100
+ const covered = Object.entries(trustRecord).filter(([key]) => !excluded.includes(key));
101
+ return {
102
+ ...Object.fromEntries(covered),
103
+ schemaVersion,
104
+ };
105
+ }
106
+ //# sourceMappingURL=ExecutionTrustRecordCanonicalView.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExecutionTrustRecordCanonicalView.js","sourceRoot":"","sources":["../src/ExecutionTrustRecordCanonicalView.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,6BAA6B,CAC3C,WAAiC;IAEjC,OAAO;QACL,aAAa,E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AG;IAC1C,WAAW;IACX,YAAY;IACZ,eAAe;IACf,eAAe;IACf,UAAU;CACF,CAAC;AAEX;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACtC,WAAiC,EACjC,aAAqB;IAErB,MAAM,QAAQ,GAAsB,4BAA4B,CAAC;IAEjE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,MAAM,CAChD,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,CACnC,CAAC;IAEF,OAAO;QACL,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC;QAC9B,aAAa;KACd,CAAC;AACJ,CAAC"}
@@ -0,0 +1,48 @@
1
+ import type { SignatureEntry } from "@parmana/shared";
2
+ import { CanonicalSerializer } from "./CanonicalSerializer.js";
3
+ import type { KeyProvider } from "./KeyProvider.js";
4
+ import type { HybridCryptoProvider } from "./models/HybridCryptoProvider.js";
5
+ /**
6
+ * Signs and verifies an artifact with two independent signature
7
+ * algorithms at once (Hybrid Signature Support milestone, Phase A):
8
+ * "harvest now, decrypt/forge later" defense for the classical-to-
9
+ * post-quantum transition -- if a future quantum computer breaks the
10
+ * primary (classical) algorithm, the secondary (post-quantum)
11
+ * signature alone still holds, and vice versa if any weakness is ever
12
+ * found in the newer PQ scheme.
13
+ *
14
+ * Not a SignatureProvider implementer: that interface signs/verifies
15
+ * with exactly one key in, one signature out. Hybrid fundamentally
16
+ * needs two keys and produces two independent signatures, so this is
17
+ * a purpose-built composition on top of two SignatureProviders
18
+ * (via HybridCryptoProvider) and a KeyProvider, mirroring how
19
+ * VerificationCrypto/ReceiptCrypto already resolve keys by id rather
20
+ * than requiring callers to pre-fetch raw KeyObjects.
21
+ */
22
+ export declare class HybridSignatureProvider {
23
+ private readonly crypto;
24
+ private readonly keys;
25
+ private readonly serializer;
26
+ constructor(crypto: HybridCryptoProvider, keys: KeyProvider, serializer?: CanonicalSerializer);
27
+ /**
28
+ * Signs the artifact with both configured algorithms, returning
29
+ * both entries in fixed [primary, secondary] order.
30
+ */
31
+ sign(artifact: unknown, primaryKeyId: string, secondaryKeyId: string): Promise<readonly SignatureEntry[]>;
32
+ /**
33
+ * Verifies every entry in `signatures`. Fail-closed: requires
34
+ * exactly one entry for the primary algorithm and one for the
35
+ * secondary algorithm -- a missing, extra, duplicated, or
36
+ * mismatched-algorithm entry is a rejection, never a partial pass.
37
+ * Both entries must independently verify against their own
38
+ * algorithm's public key (resolved by the entry's own keyId).
39
+ *
40
+ * Key lookup failures (missing/mismatched key material) are not
41
+ * caught here and propagate as thrown errors, mirroring
42
+ * VerificationCrypto.verifySignature()'s existing precedent: a
43
+ * malformed *signature* is a verification failure (returns false);
44
+ * missing *key infrastructure* is an operational error (throws).
45
+ */
46
+ verify(artifact: unknown, signatures: readonly SignatureEntry[]): Promise<boolean>;
47
+ }
48
+ //# sourceMappingURL=HybridSignatureProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HybridSignatureProvider.d.ts","sourceRoot":"","sources":["../src/HybridSignatureProvider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAG7E;;;;;;;;;;;;;;;;GAgBG;AACH,qBAAa,uBAAuB;IAEhC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAH7B,YACmB,MAAM,EAAE,oBAAoB,EAC5B,IAAI,EAAE,WAAW,EACjB,UAAU,sBAA4B,EACrD;IAEJ;;;OAGG;IACG,IAAI,CACR,QAAQ,EAAE,OAAO,EACjB,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,SAAS,cAAc,EAAE,CAAC,CA8BpC;IAED;;;;;;;;;;;;;OAaG;IACG,MAAM,CACV,QAAQ,EAAE,OAAO,EACjB,UAAU,EAAE,SAAS,cAAc,EAAE,GACpC,OAAO,CAAC,OAAO,CAAC,CA6ClB;CACF"}