@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,33 @@
1
+ import type { KeyObject } from "node:crypto";
2
+ import type { ApprovalScope, SignedApproval } from "@parmana/shared";
3
+ import type { CryptoProvider } from "./providers/CryptoProvider.js";
4
+ /**
5
+ * Approval Artifact keys belong to people (a manager, a finance lead),
6
+ * never to Parmana's runtime, so they are always Ed25519, whatever this
7
+ * server's own PRIMARY_SIGNATURE_PROVIDER is. The same reasoning as
8
+ * PolicyChangeStepUpAuthorizationCrypto.ts: the approver signs on their
9
+ * own machine and must not depend on the server's configuration, and
10
+ * the server must verify with the same algorithm the approver used.
11
+ *
12
+ * Pass this to ApprovalVerifier as its crypto provider.
13
+ */
14
+ export declare const APPROVAL_ARTIFACT_CRYPTO_PROVIDER: CryptoProvider;
15
+ export interface ApprovalArtifactSignInput {
16
+ readonly approverId: string;
17
+ readonly keyId: string;
18
+ readonly capability: string;
19
+ readonly resourceId: string;
20
+ readonly scope: ApprovalScope;
21
+ readonly ttlSeconds: number;
22
+ }
23
+ /**
24
+ * Signs an Approval Artifact (SignedApproval). Run by the approver on
25
+ * their own machine against their own private key, for example through
26
+ * scripts/sign-approval.ts; never runs server side. The caller supplies
27
+ * what is approved; this method supplies the id, nonce and timestamps.
28
+ */
29
+ export declare class ApprovalArtifactSigner {
30
+ private readonly signer;
31
+ sign(input: ApprovalArtifactSignInput, privateKey: KeyObject, now?: Date): Promise<SignedApproval>;
32
+ }
33
+ //# sourceMappingURL=ApprovalArtifactCrypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApprovalArtifactCrypto.d.ts","sourceRoot":"","sources":["../src/ApprovalArtifactCrypto.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,KAAK,EAEV,aAAa,EACb,cAAc,EACf,MAAM,iBAAiB,CAAC;AAKzB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAEpE;;;;;;;;;GASG;AACH,eAAO,MAAM,iCAAiC,EAAE,cAG/C,CAAC;AAEF,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;CAC7B;AAED;;;;;GAKG;AACH,qBAAa,sBAAsB;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAErB;IAEI,IAAI,CACR,KAAK,EAAE,yBAAyB,EAChC,UAAU,EAAE,SAAS,EACrB,GAAG,GAAE,IAAiB,GACrB,OAAO,CAAC,cAAc,CAAC,CA8BzB;CACF"}
@@ -0,0 +1,54 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { ArtifactSigner } from "./ArtifactSigner.js";
3
+ import { SHA256HashProvider } from "./providers/hash/SHA256HashProvider.js";
4
+ import { Ed25519SignatureProvider } from "./providers/signature/Ed25519SignatureProvider.js";
5
+ /**
6
+ * Approval Artifact keys belong to people (a manager, a finance lead),
7
+ * never to Parmana's runtime, so they are always Ed25519, whatever this
8
+ * server's own PRIMARY_SIGNATURE_PROVIDER is. The same reasoning as
9
+ * PolicyChangeStepUpAuthorizationCrypto.ts: the approver signs on their
10
+ * own machine and must not depend on the server's configuration, and
11
+ * the server must verify with the same algorithm the approver used.
12
+ *
13
+ * Pass this to ApprovalVerifier as its crypto provider.
14
+ */
15
+ export const APPROVAL_ARTIFACT_CRYPTO_PROVIDER = {
16
+ hash: new SHA256HashProvider(),
17
+ signature: new Ed25519SignatureProvider(),
18
+ };
19
+ /**
20
+ * Signs an Approval Artifact (SignedApproval). Run by the approver on
21
+ * their own machine against their own private key, for example through
22
+ * scripts/sign-approval.ts; never runs server side. The caller supplies
23
+ * what is approved; this method supplies the id, nonce and timestamps.
24
+ */
25
+ export class ApprovalArtifactSigner {
26
+ signer = new ArtifactSigner(APPROVAL_ARTIFACT_CRYPTO_PROVIDER);
27
+ async sign(input, privateKey, now = new Date()) {
28
+ if (!Number.isFinite(input.ttlSeconds) || input.ttlSeconds <= 0) {
29
+ throw new Error(`Invalid approval TTL: ${input.ttlSeconds}`);
30
+ }
31
+ const payload = {
32
+ version: 1,
33
+ approvalId: randomUUID(),
34
+ issuer: { approverId: input.approverId, keyId: input.keyId },
35
+ issuedAt: now.toISOString(),
36
+ expiresAt: new Date(now.getTime() + input.ttlSeconds * 1000).toISOString(),
37
+ capability: input.capability,
38
+ resourceId: input.resourceId,
39
+ scope: input.scope,
40
+ nonce: randomUUID(),
41
+ };
42
+ const value = await this.signer.sign(payload, privateKey);
43
+ return {
44
+ payload,
45
+ signature: {
46
+ algorithm: APPROVAL_ARTIFACT_CRYPTO_PROVIDER.signature.algorithm,
47
+ keyId: input.keyId,
48
+ value,
49
+ signedAt: now,
50
+ },
51
+ };
52
+ }
53
+ }
54
+ //# sourceMappingURL=ApprovalArtifactCrypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApprovalArtifactCrypto.js","sourceRoot":"","sources":["../src/ApprovalArtifactCrypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AASzC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,mDAAmD,CAAC;AAG7F;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAmB;IAC/D,IAAI,EAAE,IAAI,kBAAkB,EAAE;IAC9B,SAAS,EAAE,IAAI,wBAAwB,EAAE;CAC1C,CAAC;AAWF;;;;;GAKG;AACH,MAAM,OAAO,sBAAsB;IAChB,MAAM,GAAG,IAAI,cAAc,CAC1C,iCAAiC,CAClC,CAAC;IAEF,KAAK,CAAC,IAAI,CACR,KAAgC,EAChC,UAAqB,EACrB,GAAG,GAAS,IAAI,IAAI,EAAE;QAEtB,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC,UAAU,IAAI,CAAC,EAAE,CAAC;YAChE,MAAM,IAAI,KAAK,CAAC,yBAAyB,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC;QAC/D,CAAC;QAED,MAAM,OAAO,GAAoB;YAC/B,OAAO,EAAE,CAAC;YACV,UAAU,EAAE,UAAU,EAAE;YACxB,MAAM,EAAE,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,KAAK,EAAE;YAC5D,QAAQ,EAAE,GAAG,CAAC,WAAW,EAAE;YAC3B,SAAS,EAAE,IAAI,IAAI,CACjB,GAAG,CAAC,OAAO,EAAE,GAAG,KAAK,CAAC,UAAU,GAAG,IAAI,CACxC,CAAC,WAAW,EAAE;YACf,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,UAAU,EAAE,KAAK,CAAC,UAAU;YAC5B,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,KAAK,EAAE,UAAU,EAAE;SACpB,CAAC;QAEF,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QAE1D,OAAO;YACL,OAAO;YACP,SAAS,EAAE;gBACT,SAAS,EAAE,iCAAiC,CAAC,SAAS,CAAC,SAAS;gBAChE,KAAK,EAAE,KAAK,CAAC,KAAK;gBAClB,KAAK;gBACL,QAAQ,EAAE,GAAG;aACd;SACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,22 @@
1
+ import { type KeyObject } from "node:crypto";
2
+ import { CanonicalSerializer } from "./CanonicalSerializer.js";
3
+ import type { CryptoProvider } from "./providers/CryptoProvider.js";
4
+ import type { Signer } from "./Signer.js";
5
+ /**
6
+ * Artifact Signer.
7
+ */
8
+ export declare class ArtifactSigner {
9
+ private readonly crypto;
10
+ private readonly serializer;
11
+ constructor(crypto: CryptoProvider, serializer?: CanonicalSerializer);
12
+ sign(artifact: unknown, privateKey: KeyObject): Promise<string>;
13
+ /**
14
+ * Signs via a Signer (ADR-0009) instead of a raw private KeyObject
15
+ * -- the path that works against a sign-without-release backend
16
+ * (AWS KMS, HSM) as well as LocalFileSigner. Produces the exact same
17
+ * base64 signature format as sign() above; callers verify identically
18
+ * regardless of which method produced the signature.
19
+ */
20
+ signWithSigner(artifact: unknown, keyId: string, signer: Signer): Promise<string>;
21
+ }
22
+ //# sourceMappingURL=ArtifactSigner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArtifactSigner.d.ts","sourceRoot":"","sources":["../src/ArtifactSigner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C;;GAEG;AACH,qBAAa,cAAc;IAEvB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAF7B,YACmB,MAAM,EAAE,cAAc,EACtB,UAAU,sBAA4B,EACrD;IAEE,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAMpE;IAED;;;;;;OAMG;IACG,cAAc,CAClB,QAAQ,EAAE,OAAO,EACjB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CAIjB;CACF"}
@@ -0,0 +1,29 @@
1
+ import { CanonicalSerializer } from "./CanonicalSerializer.js";
2
+ /**
3
+ * Artifact Signer.
4
+ */
5
+ export class ArtifactSigner {
6
+ crypto;
7
+ serializer;
8
+ constructor(crypto, serializer = new CanonicalSerializer()) {
9
+ this.crypto = crypto;
10
+ this.serializer = serializer;
11
+ }
12
+ async sign(artifact, privateKey) {
13
+ const bytes = this.serializer.serialize(artifact);
14
+ const signature = await this.crypto.signature.sign(bytes, privateKey);
15
+ return signature;
16
+ }
17
+ /**
18
+ * Signs via a Signer (ADR-0009) instead of a raw private KeyObject
19
+ * -- the path that works against a sign-without-release backend
20
+ * (AWS KMS, HSM) as well as LocalFileSigner. Produces the exact same
21
+ * base64 signature format as sign() above; callers verify identically
22
+ * regardless of which method produced the signature.
23
+ */
24
+ async signWithSigner(artifact, keyId, signer) {
25
+ const bytes = this.serializer.serialize(artifact);
26
+ return signer.sign(keyId, bytes);
27
+ }
28
+ }
29
+ //# sourceMappingURL=ArtifactSigner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ArtifactSigner.js","sourceRoot":"","sources":["../src/ArtifactSigner.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAK/D;;GAEG;AACH,MAAM,OAAO,cAAc;IAEN,MAAM;IACN,UAAU;IAF7B,YACmB,MAAsB,EACtB,UAAU,GAAG,IAAI,mBAAmB,EAAE;sBADtC,MAAM;0BACN,UAAU;IAC1B,CAAC;IAEJ,KAAK,CAAC,IAAI,CAAC,QAAiB,EAAE,UAAqB;QACjD,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAElD,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QAEtE,OAAO,SAAS,CAAC;IACnB,CAAC;IAED;;;;;;OAMG;IACH,KAAK,CAAC,cAAc,CAClB,QAAiB,EACjB,KAAa,EACb,MAAc;QAEd,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAElD,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACnC,CAAC;CACF"}
@@ -0,0 +1,39 @@
1
+ import type { Signature } from "@parmana/shared";
2
+ /**
3
+ * Audit event cryptographic operations.
4
+ *
5
+ * Signs and verifies plain audit-trail events (CallerAuditEvent) with
6
+ * the exact same signing stack and
7
+ * DEFAULT_KEY_ID as ExecutionTrustRecord/RefusalRecord -- one root of
8
+ * trust across every signed artifact this codebase produces, not a
9
+ * third key.
10
+ *
11
+ * Deliberately simpler than VerificationCrypto/RefusalCrypto: audit
12
+ * events are flat, complete-at-write-time objects with no appendable
13
+ * sub-state and no separate hash-for-lookup convenience field, so
14
+ * there is nothing to exclude from the canonical view and no reason
15
+ * for a redundant hash() method -- the signature alone, over the
16
+ * event's own canonical bytes, is what a caller verifies against.
17
+ */
18
+ export declare class AuditEventCrypto {
19
+ private readonly crypto;
20
+ private readonly signerPromise;
21
+ private readonly signer;
22
+ private readonly verifier;
23
+ /**
24
+ * Signs an audit event. The event is signed exactly as given --
25
+ * callers must sign before adding any storage-only field (a
26
+ * database-generated id, an insert timestamp) that isn't part of
27
+ * the event itself, the same discipline VerificationCrypto's
28
+ * canonicalRecord() already applies by excluding non-signed fields.
29
+ */
30
+ sign(event: unknown): Promise<Signature>;
31
+ /**
32
+ * Verifies an audit event's signature against the event's own
33
+ * canonical bytes. The caller supplies both -- typically fetched
34
+ * back from storage as separate columns -- rather than this class
35
+ * assuming any particular storage shape.
36
+ */
37
+ verify(event: unknown, signature: Signature): Promise<boolean>;
38
+ }
39
+ //# sourceMappingURL=AuditEventCrypto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuditEventCrypto.d.ts","sourceRoot":"","sources":["../src/AuditEventCrypto.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAQjD;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA4B;IAEnD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA4B;IAE1D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmC;IAE1D,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAsC;IAE/D;;;;;;OAMG;IACG,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAgB7C;IAED;;;;;OAKG;IACG,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC,CAMnE;CACF"}
@@ -0,0 +1,57 @@
1
+ import { CryptoBootstrap } from "./CryptoBootstrap.js";
2
+ import { ArtifactSigner } from "./ArtifactSigner.js";
3
+ import { SignatureVerifier } from "./SignatureVerifier.js";
4
+ import { SignerBootstrap } from "./SignerBootstrap.js";
5
+ import { currentVerificationKeyId } from "./KeyProvider.js";
6
+ /**
7
+ * Audit event cryptographic operations.
8
+ *
9
+ * Signs and verifies plain audit-trail events (CallerAuditEvent) with
10
+ * the exact same signing stack and
11
+ * DEFAULT_KEY_ID as ExecutionTrustRecord/RefusalRecord -- one root of
12
+ * trust across every signed artifact this codebase produces, not a
13
+ * third key.
14
+ *
15
+ * Deliberately simpler than VerificationCrypto/RefusalCrypto: audit
16
+ * events are flat, complete-at-write-time objects with no appendable
17
+ * sub-state and no separate hash-for-lookup convenience field, so
18
+ * there is nothing to exclude from the canonical view and no reason
19
+ * for a redundant hash() method -- the signature alone, over the
20
+ * event's own canonical bytes, is what a caller verifies against.
21
+ */
22
+ export class AuditEventCrypto {
23
+ crypto = CryptoBootstrap.create();
24
+ signerPromise = SignerBootstrap.create();
25
+ signer = new ArtifactSigner(this.crypto);
26
+ verifier = new SignatureVerifier(this.crypto);
27
+ /**
28
+ * Signs an audit event. The event is signed exactly as given --
29
+ * callers must sign before adding any storage-only field (a
30
+ * database-generated id, an insert timestamp) that isn't part of
31
+ * the event itself, the same discipline VerificationCrypto's
32
+ * canonicalRecord() already applies by excluding non-signed fields.
33
+ */
34
+ async sign(event) {
35
+ const keyId = currentVerificationKeyId();
36
+ const signer = await this.signerPromise;
37
+ const value = await this.signer.signWithSigner(event, keyId, signer);
38
+ return {
39
+ algorithm: this.crypto.signature.algorithm,
40
+ keyId,
41
+ value,
42
+ signedAt: new Date(),
43
+ };
44
+ }
45
+ /**
46
+ * Verifies an audit event's signature against the event's own
47
+ * canonical bytes. The caller supplies both -- typically fetched
48
+ * back from storage as separate columns -- rather than this class
49
+ * assuming any particular storage shape.
50
+ */
51
+ async verify(event, signature) {
52
+ const signer = await this.signerPromise;
53
+ const publicKey = await signer.getPublicKey(signature.keyId);
54
+ return this.verifier.verify(event, signature.value, publicKey);
55
+ }
56
+ }
57
+ //# sourceMappingURL=AuditEventCrypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuditEventCrypto.js","sourceRoot":"","sources":["../src/AuditEventCrypto.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,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;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,gBAAgB;IACV,MAAM,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC;IAElC,aAAa,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC;IAEzC,MAAM,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEzC,QAAQ,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE/D;;;;;;OAMG;IACH,KAAK,CAAC,IAAI,CAAC,KAAc;QACvB,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,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAErE,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;;;;;OAKG;IACH,KAAK,CAAC,MAAM,CAAC,KAAc,EAAE,SAAoB;QAC/C,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC;QAExC,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAE7D,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,EAAE,SAAS,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IACjE,CAAC;CACF"}
@@ -0,0 +1,56 @@
1
+ import type { KeyObject } from "node:crypto";
2
+ import type { ExecutableContent, ExecutionAuthorizationPayload, SignedExecutionAuthorization } from "@parmana/shared";
3
+ import type { CryptoProvider } from "./providers/CryptoProvider.js";
4
+ import type { Signer } from "./Signer.js";
5
+ type AuthorizationInput = {
6
+ readonly decisionId: string;
7
+ readonly decisionOutcome?: "APPROVED";
8
+ readonly businessTransactionId: string;
9
+ readonly policyName: string;
10
+ readonly policyVersion: string;
11
+ readonly policyContentHash?: string;
12
+ readonly signalsHash?: string;
13
+ readonly submittedBy?: string;
14
+ readonly grantedCapability?: string;
15
+ readonly businessConditions?: ExecutionAuthorizationPayload["businessConditions"];
16
+ readonly authorityGrant?: ExecutionAuthorizationPayload["authorityGrant"];
17
+ readonly executableContent: ExecutableContent;
18
+ };
19
+ /**
20
+ * Authorization Signer.
21
+ *
22
+ * Produces a SignedExecutionAuthorization for an
23
+ * approved decision. Delegates all cryptography to
24
+ * ArtifactSigner over the CanonicalSerializer, and
25
+ * content hashing to ExecutableContentHasher (the
26
+ * same hasher the execution gateway uses to verify).
27
+ */
28
+ export declare class AuthorizationSigner {
29
+ private readonly crypto;
30
+ private readonly signer;
31
+ private readonly contentHasher;
32
+ constructor(crypto: CryptoProvider);
33
+ /**
34
+ * Signs an authorization payload.
35
+ *
36
+ * The caller supplies identity fields; this
37
+ * method supplies nonce, issue time, and
38
+ * expiry, then signs.
39
+ */
40
+ sign(input: AuthorizationInput, privateKey: KeyObject, keyId: string, ttlSeconds: number): Promise<SignedExecutionAuthorization>;
41
+ /**
42
+ * Signs via a Signer (ADR-0009) instead of a raw private KeyObject
43
+ * -- the path that works against a sign-without-release backend
44
+ * (AWS KMS, HSM) as well as LocalFileSigner. Same payload
45
+ * construction as sign() above; only the signing step differs.
46
+ */
47
+ signWithSigner(input: AuthorizationInput, keyId: string, signer: Signer, ttlSeconds: number): Promise<SignedExecutionAuthorization>;
48
+ /**
49
+ * Builds the unsigned authorization payload -- identical for both
50
+ * sign() and signWithSigner(); only how the resulting payload gets
51
+ * signed differs between them.
52
+ */
53
+ private buildPayload;
54
+ }
55
+ export {};
56
+ //# sourceMappingURL=AuthorizationSigner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthorizationSigner.d.ts","sourceRoot":"","sources":["../src/AuthorizationSigner.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,KAAK,EACV,iBAAiB,EACjB,6BAA6B,EAC7B,4BAA4B,EAC7B,MAAM,iBAAiB,CAAC;AAKzB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,KAAK,kBAAkB,GAAG;IACxB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,eAAe,CAAC,EAAE,UAAU,C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utableContentHasher.js";
4
+ /**
5
+ * Authorization Signer.
6
+ *
7
+ * Produces a SignedExecutionAuthorization for an
8
+ * approved decision. Delegates all cryptography to
9
+ * ArtifactSigner over the CanonicalSerializer, and
10
+ * content hashing to ExecutableContentHasher (the
11
+ * same hasher the execution gateway uses to verify).
12
+ */
13
+ export class AuthorizationSigner {
14
+ crypto;
15
+ signer;
16
+ contentHasher;
17
+ constructor(crypto) {
18
+ this.crypto = crypto;
19
+ this.signer = new ArtifactSigner(crypto);
20
+ this.contentHasher = new ExecutableContentHasher(crypto);
21
+ }
22
+ /**
23
+ * Signs an authorization payload.
24
+ *
25
+ * The caller supplies identity fields; this
26
+ * method supplies nonce, issue time, and
27
+ * expiry, then signs.
28
+ */
29
+ async sign(input, privateKey, keyId, ttlSeconds) {
30
+ const payload = await this.buildPayload(input, ttlSeconds);
31
+ const signature = await this.signer.sign(payload, privateKey);
32
+ return {
33
+ payload,
34
+ signature,
35
+ keyId,
36
+ algorithm: this.crypto.signature.algorithm,
37
+ };
38
+ }
39
+ /**
40
+ * Signs via a Signer (ADR-0009) instead of a raw private KeyObject
41
+ * -- the path that works against a sign-without-release backend
42
+ * (AWS KMS, HSM) as well as LocalFileSigner. Same payload
43
+ * construction as sign() above; only the signing step differs.
44
+ */
45
+ async signWithSigner(input, keyId, signer, ttlSeconds) {
46
+ const payload = await this.buildPayload(input, ttlSeconds);
47
+ const signature = await this.signer.signWithSigner(payload, keyId, signer);
48
+ return {
49
+ payload,
50
+ signature,
51
+ keyId,
52
+ algorithm: this.crypto.signature.algorithm,
53
+ };
54
+ }
55
+ /**
56
+ * Builds the unsigned authorization payload -- identical for both
57
+ * sign() and signWithSigner(); only how the resulting payload gets
58
+ * signed differs between them.
59
+ */
60
+ async buildPayload(input, ttlSeconds) {
61
+ if (!Number.isFinite(ttlSeconds) || ttlSeconds <= 0) {
62
+ throw new Error(`Invalid authorization TTL: ${ttlSeconds}`);
63
+ }
64
+ const issuedAt = new Date();
65
+ const expiresAt = new Date(issuedAt.getTime() + ttlSeconds * 1000);
66
+ const businessTransactionHash = await this.contentHasher.hash(input.executableContent);
67
+ return {
68
+ version: 1,
69
+ authorizationId: randomUUID(),
70
+ nonce: randomUUID(),
71
+ decisionId: input.decisionId,
72
+ ...(input.decisionOutcome !== undefined && {
73
+ decisionOutcome: input.decisionOutcome,
74
+ }),
75
+ businessTransactionId: input.businessTransactionId,
76
+ policyName: input.policyName,
77
+ policyVersion: input.policyVersion,
78
+ ...(input.policyContentHash !== undefined && {
79
+ policyContentHash: input.policyContentHash,
80
+ }),
81
+ ...(input.signalsHash !== undefined && {
82
+ signalsHash: input.signalsHash,
83
+ }),
84
+ ...(input.submittedBy !== undefined && {
85
+ submittedBy: input.submittedBy,
86
+ }),
87
+ ...(input.grantedCapability !== undefined && {
88
+ grantedCapability: input.grantedCapability,
89
+ }),
90
+ ...(input.businessConditions !== undefined &&
91
+ input.businessConditions.length > 0 && {
92
+ businessConditions: input.businessConditions,
93
+ }),
94
+ ...(input.authorityGrant !== undefined && {
95
+ authorityGrant: input.authorityGrant,
96
+ }),
97
+ authorizedAt: issuedAt.toISOString(),
98
+ expiresAt: expiresAt.toISOString(),
99
+ businessTransactionHash,
100
+ };
101
+ }
102
+ }
103
+ //# sourceMappingURL=AuthorizationSigner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthorizationSigner.js","sourceRoot":"","sources":["../src/AuthorizationSigner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AASzC,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAoBvE;;;;;;;;GAQG;AACH,MAAM,OAAO,mBAAmB;IAID,MAAM;IAHlB,MAAM,CAAiB;IACvB,aAAa,CAA0B;IAExD,YAA6B,MAAsB;sBAAtB,MAAM;QACjC,IAAI,CAAC,MAAM,GAAG,IAAI,cAAc,CAAC,M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,EAAE,QAAQ,CAAC,WAAW,EAAE;YAEpC,SAAS,EAAE,SAAS,CAAC,WAAW,EAAE;YAElC,uBAAuB;SACxB,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,53 @@
1
+ import type { KeyObject } from "node:crypto";
2
+ import type { SignedExecutionAuthorization } from "@parmana/shared";
3
+ import type { CryptoProvider } from "./providers/CryptoProvider.js";
4
+ /**
5
+ * Result of verifying a
6
+ * SignedExecutionAuthorization.
7
+ *
8
+ * versionSupported is checked first; when it
9
+ * fails, signatureVerified and notExpired are
10
+ * reported false without being evaluated, since a
11
+ * payload of an unrecognized version cannot be
12
+ * safely interpreted at all.
13
+ */
14
+ export interface AuthorizationVerificationResult {
15
+ readonly valid: boolean;
16
+ readonly checks: {
17
+ readonly versionSupported: boolean;
18
+ readonly signatureVerified: boolean;
19
+ readonly notExpired: boolean;
20
+ };
21
+ }
22
+ /**
23
+ * Authorization Verifier.
24
+ *
25
+ * Verifies a SignedExecutionAuthorization.
26
+ * Delegates signature verification to
27
+ * SignatureVerifier over the
28
+ * CanonicalSerializer.
29
+ *
30
+ * NOTE: nonce single-use enforcement is the
31
+ * responsibility of the receiving system's
32
+ * nonce store (Session 3). This class verifies
33
+ * signature and expiry only.
34
+ */
35
+ export declare class AuthorizationVerifier {
36
+ private readonly crypto;
37
+ private readonly verifier;
38
+ constructor(crypto: CryptoProvider);
39
+ /**
40
+ * Verifies payload version, signature, and
41
+ * expiry.
42
+ *
43
+ * The version check runs first and fails closed:
44
+ * an unrecognized version is not signature/secret
45
+ * dependent, so short-circuiting on it does not
46
+ * introduce a timing oracle. Once version is
47
+ * confirmed, signature and expiry both always run
48
+ * — no early return between them, to avoid a
49
+ * timing oracle on the expiry field.
50
+ */
51
+ verify(authorization: SignedExecutionAuthorization, publicKey: KeyObject, now?: Date): Promise<AuthorizationVerificationResult>;
52
+ }
53
+ //# sourceMappingURL=AuthorizationVerifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthorizationVerifier.d.ts","sourceRoot":"","sources":["../src/AuthorizationVerifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAIpE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAUpE;;;;;;;;;GASG;AACH,MAAM,WAAW,+BAA+B;IAC9C,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IAExB,QAAQ,CAAC,MAAM,EAAE;QACf,QAAQ,CAAC,gBAAgB,EAAE,OAAO,CAAC;QACnC,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAC;QACpC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;KAC9B,CAAC;CACH;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,qBAAqB;IAGpB,OAAO,CAAC,QAAQ,CAAC,MAAM;IAFnC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAoB;IAE7C,YAA6B,MAAM,EAAE,cAAc,EAElD;IAED;;;;;;;;;;;OAWG;IACG,MAAM,CACV,aAAa,EAAE,4BAA4B,EAC3C,SAAS,EAAE,SAAS,EACpB,GAAG,GAAE,IAAiB,GACrB,OAAO,CAAC,+BAA+B,CAAC,CAmC1C;CACF"}
@@ -0,0 +1,66 @@
1
+ import { SignatureVerifier } from "./SignatureVerifier.js";
2
+ /**
3
+ * Payload format version this verifier accepts.
4
+ * Fail-closed: any other value (including a
5
+ * missing field) is rejected before signature
6
+ * verification is attempted.
7
+ */
8
+ const SUPPORTED_PAYLOAD_VERSION = 1;
9
+ /**
10
+ * Authorization Verifier.
11
+ *
12
+ * Verifies a SignedExecutionAuthorization.
13
+ * Delegates signature verification to
14
+ * SignatureVerifier over the
15
+ * CanonicalSerializer.
16
+ *
17
+ * NOTE: nonce single-use enforcement is the
18
+ * responsibility of the receiving system's
19
+ * nonce store (Session 3). This class verifies
20
+ * signature and expiry only.
21
+ */
22
+ export class AuthorizationVerifier {
23
+ crypto;
24
+ verifier;
25
+ constructor(crypto) {
26
+ this.crypto = crypto;
27
+ this.verifier = new SignatureVerifier(crypto);
28
+ }
29
+ /**
30
+ * Verifies payload version, signature, and
31
+ * expiry.
32
+ *
33
+ * The version check runs first and fails closed:
34
+ * an unrecognized version is not signature/secret
35
+ * dependent, so short-circuiting on it does not
36
+ * introduce a timing oracle. Once version is
37
+ * confirmed, signature and expiry both always run
38
+ * — no early return between them, to avoid a
39
+ * timing oracle on the expiry field.
40
+ */
41
+ async verify(authorization, publicKey, now = new Date()) {
42
+ const versionSupported = authorization.payload.version === SUPPORTED_PAYLOAD_VERSION;
43
+ if (!versionSupported) {
44
+ return {
45
+ valid: false,
46
+ checks: {
47
+ versionSupported: false,
48
+ signatureVerified: false,
49
+ notExpired: false,
50
+ },
51
+ };
52
+ }
53
+ const signatureVerified = await this.verifier.verify(authorization.payload, authorization.signature, publicKey);
54
+ const expiry = Date.parse(authorization.payload.expiresAt);
55
+ const notExpired = Number.isFinite(expiry) && now.getTime() < expiry;
56
+ return {
57
+ valid: signatureVerified && notExpired,
58
+ checks: {
59
+ versionSupported,
60
+ signatureVerified,
61
+ notExpired,
62
+ },
63
+ };
64
+ }
65
+ }
66
+ //# sourceMappingURL=AuthorizationVerifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthorizationVerifier.js","sourceRoot":"","sources":["../src/AuthorizationVerifier.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAI3D;;;;;GAKG;AACH,MAAM,yBAAyB,GAAG,CAAC,CAAC;AAsBpC;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,qBAAqB;IAGH,MAAM;IAFlB,QAAQ,CAAoB;IAE7C,YAA6B,MAAsB;sBAAtB,MAAM;QACjC,IAAI,CAAC,QAAQ,GAAG,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAChD,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,MAAM,CACV,aAA2C,EAC3C,SAAoB,EACpB,GAAG,GAAS,IAAI,IAAI,EAAE;QAEtB,MAAM,gBAAgB,GACpB,aAAa,CAAC,OAAO,CAAC,OAAO,KAAK,yBAAyB,CAAC;QAE9D,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACtB,OAAO;gBACL,KAAK,EAAE,KAAK;gBAEZ,MAAM,EAAE;oBACN,gBAAgB,EAAE,KAAK;oBACvB,iBAAiB,EAAE,KAAK;oBACxB,UAAU,EAAE,KAAK;iBAClB;aACF,CAAC;QACJ,CAAC;QAED,MAAM,iBAAiB,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,CAClD,aAAa,CAAC,OAAO,EACrB,aAAa,CAAC,SAAS,EACvB,SAAS,CACV,CAAC;QAEF,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAE3D,MAAM,UAAU,GAAG,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC;QAErE,OAAO;YACL,KAAK,EAAE,iBAAiB,IAAI,UAAU;YAEtC,MAAM,EAAE;gBACN,gBAAgB;gBAChB,iBAAiB;gBACjB,UAAU;aACX;SACF,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,62 @@
1
+ import type { Signature } from "@parmana/shared";
2
+ /**
3
+ * One caller_audit_events row, in the shape a verifier reads it back:
4
+ * the original CallerAuditEvent-shaped fields (occurredAt, callerId,
5
+ * etc, exactly as SupabaseCallerAuditSink.record() received them —
6
+ * never including storage-only fields like a database row id), plus
7
+ * the signature and chain columns that sit alongside it.
8
+ */
9
+ export interface ChainedCallerAuditEventRow {
10
+ readonly event: Record<string, unknown>;
11
+ readonly signature: Signature;
12
+ readonly chainHash: string | null;
13
+ readonly previousChainHash: string | null;
14
+ readonly chainPosition: number | null;
15
+ }
16
+ export interface CallerAuditChainVerificationResult {
17
+ readonly valid: boolean;
18
+ readonly brokenAtPosition?: number;
19
+ readonly reason?: string;
20
+ }
21
+ /**
22
+ * Verifies one caller's full audit chain (SupabaseCallerAuditSink's
23
+ * per-caller chaining): each row's signature against its own
24
+ * recomputed content -- including the previousChainHash/chainPosition
25
+ * fields folded into what was actually signed -- and that each row's
26
+ * previousChainHash references the immediately-preceding row's own
27
+ * chainHash. No network call, no database, no running Parmana
28
+ * process: pass it rows already fetched from storage, in ascending
29
+ * chain_position order. The same standalone discipline
30
+ * docs/site/guides/verify-independently.mdx demonstrates for
31
+ * ExecutionTrustRecord, extended to the caller-audit trail.
32
+ *
33
+ * A deleted row breaks this: the row after it still carries the
34
+ * deleted row's chainHash as its own previousChainHash, but the
35
+ * row before it has a different chainHash -- the linkage check below
36
+ * catches the mismatch, which is exactly the gap this class closes
37
+ * (see docs/site/trust-and-claims/objections-and-evidence.mdx,
38
+ * Domain 3).
39
+ *
40
+ * Rows with no chain fields at all (no callerId at write time --
41
+ * the earliest possible rejection, or caller.rejected) are verified
42
+ * for signature only, never required to link -- the same "absent
43
+ * means unprotected, not broken" discipline
44
+ * ExecutionChainCrypto.verifyChain() already applies to legacy,
45
+ * pre-chain-feature Executions.
46
+ */
47
+ export declare class CallerAuditChainVerifier {
48
+ private readonly crypto;
49
+ private readonly hasher;
50
+ /**
51
+ * `anchor`, when given, is the chain head (last chainPosition and its
52
+ * chainHash) recorded outside the database when the chain was last seen.
53
+ * The chain must end exactly there. Without an anchor, deleting the newest
54
+ * rows leaves a valid, shorter chain: that cannot be detected from the
55
+ * rows alone.
56
+ */
57
+ verifyChain(rows: readonly ChainedCallerAuditEventRow[], anchor?: {
58
+ readonly chainPosition: number;
59
+ readonly chainHash: string;
60
+ }): Promise<CallerAuditChainVerificationResult>;
61
+ }
62
+ //# sourceMappingURL=CallerAuditChainVerifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CallerAuditChainVerifier.d.ts","sourceRoot":"","sources":["../src/CallerAuditChainVerifier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAMjD;;;;;;GAMG;AACH,MAAM,WAAW,0BAA0B;IACzC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACxC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAClC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,QAAQ,CAAC,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;CACvC;AAED,MAAM,WAAW,kCAAkC;IACjD,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,qBAAa,wBAAwB;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0B;IAEjD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAmD;IAE1E;;;;;;OAMG;IACG,WAAW,CACf,IAAI,EAAE,SAAS,0BAA0B,EAAE,EAC3C,MAAM,CAAC,EAAE;QAAE,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;KAAE,GACtE,OAAO,CAAC,kCAAkC,CAAC,CA2E7C;CACF"}