@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.
- package/LICENSE +202 -0
- package/NOTICE +8 -0
- package/README.md +16 -2
- package/dist/.tsbuildinfo +1 -0
- package/dist/ApprovalArtifactCrypto.d.ts +33 -0
- package/dist/ApprovalArtifactCrypto.d.ts.map +1 -0
- package/dist/ApprovalArtifactCrypto.js +54 -0
- package/dist/ApprovalArtifactCrypto.js.map +1 -0
- package/dist/ArtifactSigner.d.ts +22 -0
- package/dist/ArtifactSigner.d.ts.map +1 -0
- package/dist/ArtifactSigner.js +29 -0
- package/dist/ArtifactSigner.js.map +1 -0
- package/dist/AuditEventCrypto.d.ts +39 -0
- package/dist/AuditEventCrypto.d.ts.map +1 -0
- package/dist/AuditEventCrypto.js +57 -0
- package/dist/AuditEventCrypto.js.map +1 -0
- package/dist/AuthorizationSigner.d.ts +56 -0
- package/dist/AuthorizationSigner.d.ts.map +1 -0
- package/dist/AuthorizationSigner.js +103 -0
- package/dist/AuthorizationSigner.js.map +1 -0
- package/dist/AuthorizationVerifier.d.ts +53 -0
- package/dist/AuthorizationVerifier.d.ts.map +1 -0
- package/dist/AuthorizationVerifier.js +66 -0
- package/dist/AuthorizationVerifier.js.map +1 -0
- package/dist/CallerAuditChainVerifier.d.ts +62 -0
- package/dist/CallerAuditChainVerifier.d.ts.map +1 -0
- package/dist/CallerAuditChainVerifier.js +97 -0
- package/dist/CallerAuditChainVerifier.js.map +1 -0
- package/dist/CanonicalSerializer.d.ts +26 -0
- package/dist/CanonicalSerializer.d.ts.map +1 -0
- package/dist/CanonicalSerializer.js +78 -0
- package/dist/CanonicalSerializer.js.map +1 -0
- package/dist/CryptoBootstrap.d.ts +27 -0
- package/dist/CryptoBootstrap.d.ts.map +1 -0
- package/dist/CryptoBootstrap.js +70 -0
- package/dist/CryptoBootstrap.js.map +1 -0
- package/dist/CryptoBuilder.d.ts +27 -0
- package/dist/CryptoBuilder.d.ts.map +1 -0
- package/dist/CryptoBuilder.js +42 -0
- package/dist/CryptoBuilder.js.map +1 -0
- package/dist/ExecutableContentHasher.d.ts +22 -0
- package/dist/ExecutableContentHasher.d.ts.map +1 -0
- package/dist/ExecutableContentHasher.js +25 -0
- package/dist/ExecutableContentHasher.js.map +1 -0
- package/dist/ExecutionChainCrypto.d.ts +78 -0
- package/dist/ExecutionChainCrypto.d.ts.map +1 -0
- package/dist/ExecutionChainCrypto.js +165 -0
- package/dist/ExecutionChainCrypto.js.map +1 -0
- package/dist/ExecutionChainHasher.d.ts +10 -0
- package/dist/ExecutionChainHasher.d.ts.map +1 -0
- package/dist/ExecutionChainHasher.js +13 -0
- package/dist/ExecutionChainHasher.js.map +1 -0
- package/dist/ExecutionIntentCanonicalView.d.ts +28 -0
- package/dist/ExecutionIntentCanonicalView.d.ts.map +1 -0
- package/dist/ExecutionIntentCanonicalView.js +29 -0
- package/dist/ExecutionIntentCanonicalView.js.map +1 -0
- package/dist/ExecutionIntentCrypto.d.ts +21 -0
- package/dist/ExecutionIntentCrypto.d.ts.map +1 -0
- package/dist/ExecutionIntentCrypto.js +47 -0
- package/dist/ExecutionIntentCrypto.js.map +1 -0
- package/dist/ExecutionTrustRecordCanonicalView.d.ts +89 -0
- package/dist/ExecutionTrustRecordCanonicalView.d.ts.map +1 -0
- package/dist/ExecutionTrustRecordCanonicalView.js +106 -0
- package/dist/ExecutionTrustRecordCanonicalView.js.map +1 -0
- package/dist/HybridSignatureProvider.d.ts +48 -0
- package/dist/HybridSignatureProvider.d.ts.map +1 -0
- package/dist/HybridSignatureProvider.js +90 -0
- package/dist/HybridSignatureProvider.js.map +1 -0
- package/dist/KeyBootstrap.d.ts +23 -0
- package/dist/KeyBootstrap.d.ts.map +1 -0
- package/dist/KeyBootstrap.js +37 -0
- package/dist/KeyBootstrap.js.map +1 -0
- package/dist/KeyExpiry.d.ts +34 -0
- package/dist/KeyExpiry.d.ts.map +1 -0
- package/dist/KeyExpiry.js +66 -0
- package/dist/KeyExpiry.js.map +1 -0
- package/dist/KeyPair.d.ts +25 -0
- package/dist/KeyPair.d.ts.map +1 -0
- package/dist/KeyPair.js +37 -0
- package/dist/KeyPair.js.map +1 -0
- package/dist/KeyProvider.d.ts +98 -0
- package/dist/KeyProvider.d.ts.map +1 -0
- package/dist/KeyProvider.js +57 -0
- package/dist/KeyProvider.js.map +1 -0
- package/dist/KeyStore.d.ts +35 -0
- package/dist/KeyStore.d.ts.map +1 -0
- package/dist/KeyStore.js +2 -0
- package/dist/KeyStore.js.map +1 -0
- package/dist/OfflineVerifier.d.ts +80 -0
- package/dist/OfflineVerifier.d.ts.map +1 -0
- package/dist/OfflineVerifier.js +271 -0
- package/dist/OfflineVerifier.js.map +1 -0
- package/dist/PolicyChangeCrypto.d.ts +44 -0
- package/dist/PolicyChangeCrypto.d.ts.map +1 -0
- package/dist/PolicyChangeCrypto.js +79 -0
- package/dist/PolicyChangeCrypto.js.map +1 -0
- package/dist/PolicyChangeStepUpAuthorizationCrypto.d.ts +55 -0
- package/dist/PolicyChangeStepUpAuthorizationCrypto.d.ts.map +1 -0
- package/dist/PolicyChangeStepUpAuthorizationCrypto.js +107 -0
- package/dist/PolicyChangeStepUpAuthorizationCrypto.js.map +1 -0
- package/dist/ReceiptCrypto.d.ts +44 -0
- package/dist/ReceiptCrypto.d.ts.map +1 -0
- package/dist/ReceiptCrypto.js +84 -0
- package/dist/ReceiptCrypto.js.map +1 -0
- package/dist/ReceiptHasher.d.ts +10 -0
- package/dist/ReceiptHasher.d.ts.map +1 -0
- package/dist/ReceiptHasher.js +13 -0
- package/dist/ReceiptHasher.js.map +1 -0
- package/dist/RefusalCrypto.d.ts +35 -0
- package/dist/RefusalCrypto.d.ts.map +1 -0
- package/dist/RefusalCrypto.js +73 -0
- package/dist/RefusalCrypto.js.map +1 -0
- package/dist/SignatureCommitment.d.ts +33 -0
- package/dist/SignatureCommitment.d.ts.map +1 -0
- package/dist/SignatureCommitment.js +42 -0
- package/dist/SignatureCommitment.js.map +1 -0
- package/dist/SignatureVerifier.d.ts +20 -0
- package/dist/SignatureVerifier.d.ts.map +1 -0
- package/dist/SignatureVerifier.js +25 -0
- package/dist/SignatureVerifier.js.map +1 -0
- package/dist/Signer.d.ts +49 -0
- package/dist/Signer.d.ts.map +1 -0
- package/dist/Signer.js +2 -0
- package/dist/Signer.js.map +1 -0
- package/dist/SignerBootstrap.d.ts +37 -0
- package/dist/SignerBootstrap.d.ts.map +1 -0
- package/dist/SignerBootstrap.js +52 -0
- package/dist/SignerBootstrap.js.map +1 -0
- package/dist/TrustRecordHasher.d.ts +18 -0
- package/dist/TrustRecordHasher.d.ts.map +1 -0
- package/dist/TrustRecordHasher.js +23 -0
- package/dist/TrustRecordHasher.js.map +1 -0
- package/dist/VerificationCrypto.d.ts +132 -0
- package/dist/VerificationCrypto.d.ts.map +1 -0
- package/dist/VerificationCrypto.js +229 -0
- package/dist/VerificationCrypto.js.map +1 -0
- package/dist/errors/CryptoError.d.ts +14 -0
- package/dist/errors/CryptoError.d.ts.map +1 -0
- package/dist/errors/CryptoError.js +18 -0
- package/dist/errors/CryptoError.js.map +1 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/index.js.map +1 -0
- package/dist/models/HybridCryptoProvider.d.ts +9 -0
- package/dist/models/HybridCryptoProvider.d.ts.map +1 -0
- package/dist/models/HybridCryptoProvider.js +2 -0
- package/dist/models/HybridCryptoProvider.js.map +1 -0
- package/dist/providers/CryptoProvider.d.ts +15 -0
- package/dist/providers/CryptoProvider.d.ts.map +1 -0
- package/dist/providers/CryptoProvider.js +2 -0
- package/dist/providers/CryptoProvider.js.map +1 -0
- package/dist/providers/HashProvider.d.ts +17 -0
- package/dist/providers/HashProvider.d.ts.map +1 -0
- package/dist/providers/HashProvider.js +2 -0
- package/dist/providers/HashProvider.js.map +1 -0
- package/dist/providers/HashRegistry.d.ts +11 -0
- package/dist/providers/HashRegistry.d.ts.map +1 -0
- package/dist/providers/HashRegistry.js +18 -0
- package/dist/providers/HashRegistry.js.map +1 -0
- package/dist/providers/ProviderFactory.d.ts +11 -0
- package/dist/providers/ProviderFactory.d.ts.map +1 -0
- package/dist/providers/ProviderFactory.js +13 -0
- package/dist/providers/ProviderFactory.js.map +1 -0
- package/dist/providers/SignatureProvider.d.ts +25 -0
- package/dist/providers/SignatureProvider.d.ts.map +1 -0
- package/dist/providers/SignatureProvider.js +2 -0
- package/dist/providers/SignatureProvider.js.map +1 -0
- package/dist/providers/SignatureRegistry.d.ts +11 -0
- package/dist/providers/SignatureRegistry.d.ts.map +1 -0
- package/dist/providers/SignatureRegistry.js +18 -0
- package/dist/providers/SignatureRegistry.js.map +1 -0
- package/dist/providers/SignerKeyProviderAdapter.d.ts +50 -0
- package/dist/providers/SignerKeyProviderAdapter.d.ts.map +1 -0
- package/dist/providers/SignerKeyProviderAdapter.js +66 -0
- package/dist/providers/SignerKeyProviderAdapter.js.map +1 -0
- package/dist/providers/hash/SHA256HashProvider.d.ts +10 -0
- package/dist/providers/hash/SHA256HashProvider.d.ts.map +1 -0
- package/dist/providers/hash/SHA256HashProvider.js +12 -0
- package/dist/providers/hash/SHA256HashProvider.js.map +1 -0
- package/dist/providers/key/FileKeyProvider.d.ts +85 -0
- package/dist/providers/key/FileKeyProvider.d.ts.map +1 -0
- package/dist/providers/key/FileKeyProvider.js +163 -0
- package/dist/providers/key/FileKeyProvider.js.map +1 -0
- package/dist/providers/signature/Dilithium3SignatureProvider.d.ts +23 -0
- package/dist/providers/signature/Dilithium3SignatureProvider.d.ts.map +1 -0
- package/dist/providers/signature/Dilithium3SignatureProvider.js +33 -0
- package/dist/providers/signature/Dilithium3SignatureProvider.js.map +1 -0
- package/dist/providers/signature/Ed25519SignatureProvider.d.ts +17 -0
- package/dist/providers/signature/Ed25519SignatureProvider.d.ts.map +1 -0
- package/dist/providers/signature/Ed25519SignatureProvider.js +40 -0
- package/dist/providers/signature/Ed25519SignatureProvider.js.map +1 -0
- package/dist/providers/signature/assertKeyType.d.ts +14 -0
- package/dist/providers/signature/assertKeyType.d.ts.map +1 -0
- package/dist/providers/signature/assertKeyType.js +19 -0
- package/dist/providers/signature/assertKeyType.js.map +1 -0
- package/dist/providers/signer/KmsSigner.d.ts +71 -0
- package/dist/providers/signer/KmsSigner.d.ts.map +1 -0
- package/dist/providers/signer/KmsSigner.js +270 -0
- package/dist/providers/signer/KmsSigner.js.map +1 -0
- package/dist/providers/signer/LocalFileSigner.d.ts +28 -0
- package/dist/providers/signer/LocalFileSigner.d.ts.map +1 -0
- package/dist/providers/signer/LocalFileSigner.js +38 -0
- package/dist/providers/signer/LocalFileSigner.js.map +1 -0
- package/dist/support/MlDsaSupport.d.ts +9 -0
- package/dist/support/MlDsaSupport.d.ts.map +1 -0
- package/dist/support/MlDsaSupport.js +23 -0
- package/dist/support/MlDsaSupport.js.map +1 -0
- package/package.json +45 -4
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { loadConfig } from "@parmana/shared";
|
|
2
|
+
import { CryptoBootstrap } from "./CryptoBootstrap.js";
|
|
3
|
+
import { HybridSignatureProvider } from "./HybridSignatureProvider.js";
|
|
4
|
+
import { ReceiptHasher } from "./ReceiptHasher.js";
|
|
5
|
+
import { ArtifactSigner } from "./ArtifactSigner.js";
|
|
6
|
+
import { TrustRecordHasher } from "./TrustRecordHasher.js";
|
|
7
|
+
import { SignerBootstrap } from "./SignerBootstrap.js";
|
|
8
|
+
import { FileKeyProvider } from "./providers/key/FileKeyProvider.js";
|
|
9
|
+
import { DEFAULT_KEY_ID, DEFAULT_SECONDARY_KEY_ID } from "./KeyProvider.js";
|
|
10
|
+
/**
|
|
11
|
+
* Schema version stamped on `signatures`-bearing Receipts. See the
|
|
12
|
+
* identical constant/rationale in VerificationCrypto.
|
|
13
|
+
*/
|
|
14
|
+
const HYBRID_SCHEMA_VERSION = 2;
|
|
15
|
+
/**
|
|
16
|
+
* Receipt cryptographic operations.
|
|
17
|
+
*
|
|
18
|
+
* Owns all receipt-related cryptographic
|
|
19
|
+
* operations for Parmana.
|
|
20
|
+
*/
|
|
21
|
+
export class ReceiptCrypto {
|
|
22
|
+
crypto = CryptoBootstrap.create();
|
|
23
|
+
config = loadConfig();
|
|
24
|
+
/**
|
|
25
|
+
* Signer (ADR-0009) -- LocalFileSigner or KmsSigner depending on
|
|
26
|
+
* KEY_PROVIDER.
|
|
27
|
+
*/
|
|
28
|
+
signerPromise = SignerBootstrap.create();
|
|
29
|
+
/**
|
|
30
|
+
* Hybrid mode's secondary signature stays local-file-backed; see
|
|
31
|
+
* the identical comment in VerificationCrypto.
|
|
32
|
+
*/
|
|
33
|
+
hybridKeys = new FileKeyProvider();
|
|
34
|
+
trustRecordHasher = new TrustRecordHasher(this.crypto);
|
|
35
|
+
receiptHasher = new ReceiptHasher(this.trustRecordHasher);
|
|
36
|
+
signer = new ArtifactSigner(this.crypto);
|
|
37
|
+
/**
|
|
38
|
+
* Computes the canonical receipt hash.
|
|
39
|
+
*/
|
|
40
|
+
async hash(trustRecord) {
|
|
41
|
+
return this.receiptHasher.hash(trustRecord);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Signs any canonical object.
|
|
45
|
+
*/
|
|
46
|
+
async sign(value) {
|
|
47
|
+
const signer = await this.signerPromise;
|
|
48
|
+
return this.signer.signWithSigner(value, DEFAULT_KEY_ID, signer);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates a signed Receipt.
|
|
52
|
+
*
|
|
53
|
+
* The legacy `signature`/`algorithm` are unchanged by hybrid mode:
|
|
54
|
+
* always signed by the configured primary provider alone, over
|
|
55
|
+
* exactly the same content as before this milestone (Hybrid
|
|
56
|
+
* Signature Support, Phase A). When CRYPTO_MODE=hybrid, an
|
|
57
|
+
* additional `signatures` array and `schemaVersion` are populated
|
|
58
|
+
* alongside them -- additive, never replacing the legacy fields.
|
|
59
|
+
*/
|
|
60
|
+
async createReceipt(payload) {
|
|
61
|
+
const unsignedReceipt = {
|
|
62
|
+
...payload,
|
|
63
|
+
algorithm: this.crypto.signature.algorithm,
|
|
64
|
+
};
|
|
65
|
+
const signature = await this.sign(unsignedReceipt);
|
|
66
|
+
if (this.config.crypto.mode !== "hybrid") {
|
|
67
|
+
return {
|
|
68
|
+
...unsignedReceipt,
|
|
69
|
+
signature,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const signatures = await new HybridSignatureProvider(CryptoBootstrap.createHybrid(), this.hybridKeys).sign({
|
|
73
|
+
...unsignedReceipt,
|
|
74
|
+
schemaVersion: HYBRID_SCHEMA_VERSION,
|
|
75
|
+
}, DEFAULT_KEY_ID, DEFAULT_SECONDARY_KEY_ID);
|
|
76
|
+
return {
|
|
77
|
+
...unsignedReceipt,
|
|
78
|
+
signature,
|
|
79
|
+
schemaVersion: HYBRID_SCHEMA_VERSION,
|
|
80
|
+
signatures,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=ReceiptCrypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReceiptCrypto.js","sourceRoot":"","sources":["../src/ReceiptCrypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAE5E;;;GAGG;AACH,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAEhC;;;;;GAKG;AACH,MAAM,OAAO,aAAa;IACP,MAAM,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC;IAElC,MAAM,GAAG,UAAU,EAAE,CAAC;IAEvC;;;OAGG;IACc,aAAa,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC;IAE1D;;;OAGG;IACc,UAAU,GAAG,IAAI,eAAe,EAAE,CAAC;IAEnC,iBAAiB,GAAG,IAAI,iBAAiB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAEvD,aAAa,GAAG,IAAI,aAAa,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;IAE1D,MAAM,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAE1D;;OAEG;IACH,KAAK,CAAC,IAAI,CAAC,WAAoB;QAC7B,OAAO,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI,CAAC,KAAc;QACvB,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC;QAExC,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;IACnE,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,aAAa,CACjB,OAGC;QAED,MAAM,eAAe,GAAG;YACtB,GAAG,OAAO;YAEV,SAAS,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS;SAC3C,CAAC;QAEF,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAEnD,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACzC,OAAO;gBACL,GAAG,eAAe;gBAElB,SAAS;aACV,CAAC;QACJ,CAAC;QAED,MAAM,UAAU,GAAG,MAAM,IAAI,uBAAuB,CAClD,eAAe,CAAC,YAAY,EAAE,EAC9B,IAAI,CAAC,UAAU,CAChB,CAAC,IAAI,CACJ;YACE,GAAG,eAAe;YAElB,aAAa,EAAE,qBAAqB;SACrC,EACD,cAAc,EACd,wBAAwB,CACzB,CAAC;QAEF,OAAO;YACL,GAAG,eAAe;YAElB,SAAS;YAET,aAAa,EAAE,qBAAqB;YAEpC,UAAU;SACX,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TrustRecordHasher } from "./TrustRecordHasher.js";
|
|
2
|
+
/**
|
|
3
|
+
* Receipt Hasher.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ReceiptHasher {
|
|
6
|
+
private readonly hasher;
|
|
7
|
+
constructor(hasher: TrustRecordHasher);
|
|
8
|
+
hash(receipt: unknown): Promise<string>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=ReceiptHasher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReceiptHasher.d.ts","sourceRoot":"","sources":["../src/ReceiptHasher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;GAEG;AACH,qBAAa,aAAa;IACZ,OAAO,CAAC,QAAQ,CAAC,MAAM;IAAnC,YAA6B,MAAM,EAAE,iBAAiB,EAAI;IAEpD,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAE5C;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReceiptHasher.js","sourceRoot":"","sources":["../src/ReceiptHasher.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,OAAO,aAAa;IACK,MAAM;IAAnC,YAA6B,MAAyB;sBAAzB,MAAM;IAAsB,CAAC;IAE1D,KAAK,CAAC,IAAI,CAAC,OAAgB;QACzB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { RefusalRecord, Signature } from "@parmana/shared";
|
|
2
|
+
/**
|
|
3
|
+
* Refusal cryptographic operations (RFC-0021).
|
|
4
|
+
*
|
|
5
|
+
* Parallel to VerificationCrypto, over Refusal Records instead of
|
|
6
|
+
* Execution Trust Records. Deliberately reuses the exact same
|
|
7
|
+
* signing stack and DEFAULT_KEY_ID as VerificationCrypto — RFC-0021
|
|
8
|
+
* §2's resolved decision is one root of trust for both approvals and
|
|
9
|
+
* refusals, not a second key to manage.
|
|
10
|
+
*/
|
|
11
|
+
export declare class RefusalCrypto {
|
|
12
|
+
private readonly crypto;
|
|
13
|
+
private readonly signerPromise;
|
|
14
|
+
private readonly hasher;
|
|
15
|
+
private readonly signer;
|
|
16
|
+
private readonly verifier;
|
|
17
|
+
/**
|
|
18
|
+
* Creates the canonical immutable view of a Refusal Record used
|
|
19
|
+
* for hashing and signing. Excludes the signature itself.
|
|
20
|
+
*/
|
|
21
|
+
private canonicalRecord;
|
|
22
|
+
/**
|
|
23
|
+
* Computes the canonical Refusal Record hash.
|
|
24
|
+
*/
|
|
25
|
+
hash(refusalRecord: RefusalRecord): Promise<string>;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a digital signature over the canonical Refusal Record.
|
|
28
|
+
*/
|
|
29
|
+
sign(refusalRecord: RefusalRecord): Promise<Signature>;
|
|
30
|
+
/**
|
|
31
|
+
* Verifies integrity and authenticity of a Refusal Record.
|
|
32
|
+
*/
|
|
33
|
+
verify(refusalRecord: RefusalRecord): Promise<boolean>;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=RefusalCrypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RefusalCrypto.d.ts","sourceRoot":"","sources":["../src/RefusalCrypto.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAShE;;;;;;;;GAQG;AACH,qBAAa,aAAa;IACxB,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;IAE/D;;;OAGG;IACH,OAAO,CAAC,eAAe;IAsBvB;;OAEG;IACG,IAAI,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,MAAM,CAAC,CAExD;IAED;;OAEG;IACG,IAAI,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,SAAS,CAAC,CAoB3D;IAED;;OAEG;IACG,MAAM,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC,CAgB3D;CACF"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { CryptoBootstrap } from "./CryptoBootstrap.js";
|
|
2
|
+
import { TrustRecordHasher } from "./TrustRecordHasher.js";
|
|
3
|
+
import { ArtifactSigner } from "./ArtifactSigner.js";
|
|
4
|
+
import { SignatureVerifier } from "./SignatureVerifier.js";
|
|
5
|
+
import { SignerBootstrap } from "./SignerBootstrap.js";
|
|
6
|
+
import { currentVerificationKeyId } from "./KeyProvider.js";
|
|
7
|
+
/**
|
|
8
|
+
* Refusal cryptographic operations (RFC-0021).
|
|
9
|
+
*
|
|
10
|
+
* Parallel to VerificationCrypto, over Refusal Records instead of
|
|
11
|
+
* Execution Trust Records. Deliberately reuses the exact same
|
|
12
|
+
* signing stack and DEFAULT_KEY_ID as VerificationCrypto — RFC-0021
|
|
13
|
+
* §2's resolved decision is one root of trust for both approvals and
|
|
14
|
+
* refusals, not a second key to manage.
|
|
15
|
+
*/
|
|
16
|
+
export class RefusalCrypto {
|
|
17
|
+
crypto = CryptoBootstrap.create();
|
|
18
|
+
signerPromise = SignerBootstrap.create();
|
|
19
|
+
hasher = new TrustRecordHasher(this.crypto);
|
|
20
|
+
signer = new ArtifactSigner(this.crypto);
|
|
21
|
+
verifier = new SignatureVerifier(this.crypto);
|
|
22
|
+
/**
|
|
23
|
+
* Creates the canonical immutable view of a Refusal Record used
|
|
24
|
+
* for hashing and signing. Excludes the signature itself.
|
|
25
|
+
*/
|
|
26
|
+
canonicalRecord(refusalRecord) {
|
|
27
|
+
return {
|
|
28
|
+
refusalRecordId: refusalRecord.refusalRecordId,
|
|
29
|
+
businessTransactionId: refusalRecord.businessTransactionId,
|
|
30
|
+
decision: refusalRecord.decision,
|
|
31
|
+
evaluatedIntent: refusalRecord.evaluatedIntent,
|
|
32
|
+
bindingViolations: refusalRecord.bindingViolations,
|
|
33
|
+
submittedBy: refusalRecord.submittedBy,
|
|
34
|
+
// Absent on records written before it existed; an absent key is
|
|
35
|
+
// left out of the canonical form, so those records still verify.
|
|
36
|
+
policyContentHash: refusalRecord.policyContentHash,
|
|
37
|
+
createdAt: refusalRecord.createdAt,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Computes the canonical Refusal Record hash.
|
|
42
|
+
*/
|
|
43
|
+
async hash(refusalRecord) {
|
|
44
|
+
return this.hasher.hash(this.canonicalRecord(refusalRecord));
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Creates a digital signature over the canonical Refusal Record.
|
|
48
|
+
*/
|
|
49
|
+
async sign(refusalRecord) {
|
|
50
|
+
const keyId = currentVerificationKeyId();
|
|
51
|
+
const signer = await this.signerPromise;
|
|
52
|
+
const value = await this.signer.signWithSigner(this.canonicalRecord(refusalRecord), keyId, signer);
|
|
53
|
+
return {
|
|
54
|
+
algorithm: this.crypto.signature.algorithm,
|
|
55
|
+
keyId,
|
|
56
|
+
value,
|
|
57
|
+
signedAt: new Date(),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Verifies integrity and authenticity of a Refusal Record.
|
|
62
|
+
*/
|
|
63
|
+
async verify(refusalRecord) {
|
|
64
|
+
const expectedHash = await this.hash(refusalRecord);
|
|
65
|
+
if (expectedHash !== refusalRecord.refusalRecordHash) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
const signer = await this.signerPromise;
|
|
69
|
+
const publicKey = await signer.getPublicKey(refusalRecord.signature.keyId);
|
|
70
|
+
return this.verifier.verify(this.canonicalRecord(refusalRecord), refusalRecord.signature.value, publicKey);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=RefusalCrypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RefusalCrypto.js","sourceRoot":"","sources":["../src/RefusalCrypto.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,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,aAAa;IACP,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;;;OAGG;IACK,eAAe,CAAC,aAA4B;QAClD,OAAO;YACL,eAAe,EAAE,aAAa,CAAC,eAAe;YAE9C,qBAAqB,EAAE,aAAa,CAAC,qBAAqB;YAE1D,QAAQ,EAAE,aAAa,CAAC,QAAQ;YAEhC,eAAe,EAAE,aAAa,CAAC,eAAe;YAE9C,iBAAiB,EAAE,aAAa,CAAC,iBAAiB;YAElD,WAAW,EAAE,aAAa,CAAC,WAAW;YAEtC,gEAAgE;YAChE,iEAAiE;YACjE,iBAAiB,EAAE,aAAa,CAAC,iBAAiB;YAElD,SAAS,EAAE,aAAa,CAAC,SAAS;SACnC,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI,CAAC,aAA4B;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CAAC;IAC/D,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,IAAI,CAAC,aAA4B;QACrC,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,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,EACnC,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;;OAEG;IACH,KAAK,CAAC,MAAM,CAAC,aAA4B;QACvC,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QAEpD,IAAI,YAAY,KAAK,aAAa,CAAC,iBAAiB,EAAE,CAAC;YACrD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC;QAExC,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,YAAY,CAAC,aAAa,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAE3E,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CACzB,IAAI,CAAC,eAAe,CAAC,aAAa,CAAC,EACnC,aAAa,CAAC,SAAS,CAAC,KAAK,EAC7B,SAAS,CACV,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AWS KMS caps the raw message it will sign with an Ed25519 key
|
|
3
|
+
* (ED25519_SHA_512, MessageType RAW) at 4096 bytes. A full Execution
|
|
4
|
+
* Trust Record, with its bound authorization, connector evidence and
|
|
5
|
+
* governance anchor, is larger than that, so signing it directly fails.
|
|
6
|
+
*
|
|
7
|
+
* Large message commitment (v1): a message longer than the limit is
|
|
8
|
+
* signed as a fixed size commitment, the domain separation prefix
|
|
9
|
+
* followed by the SHA-512 digest of the message. The signature is still
|
|
10
|
+
* a pure Ed25519 signature, so it needs no new algorithm and any
|
|
11
|
+
* standard Ed25519 library can verify it once it rebuilds the same
|
|
12
|
+
* commitment.
|
|
13
|
+
*
|
|
14
|
+
* The scheme is a pure function of message length, so no marker has to
|
|
15
|
+
* be stored on any record:
|
|
16
|
+
*
|
|
17
|
+
* - length <= limit: signed and verified raw, exactly as before, so
|
|
18
|
+
* every signature issued before this change stays valid.
|
|
19
|
+
* - length > limit: signed as the commitment. A verifier also accepts a
|
|
20
|
+
* raw signature over such a message, because a local key signer has
|
|
21
|
+
* always signed large messages raw and those records still exist.
|
|
22
|
+
*
|
|
23
|
+
* The prefix contains a NUL byte and never occurs at the start of a
|
|
24
|
+
* canonical JSON message (which starts with "{"), so a signature over a
|
|
25
|
+
* commitment cannot be replayed as a signature over a small raw message.
|
|
26
|
+
* A commitment signature over a message at or below the limit is not
|
|
27
|
+
* accepted, which prevents downgrading a small message to the
|
|
28
|
+
* commitment form.
|
|
29
|
+
*/
|
|
30
|
+
export declare const KMS_RAW_MESSAGE_LIMIT_BYTES = 4096;
|
|
31
|
+
export declare function requiresCommitment(data: Uint8Array): boolean;
|
|
32
|
+
export declare function commitmentMessage(data: Uint8Array): Uint8Array;
|
|
33
|
+
//# sourceMappingURL=SignatureCommitment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SignatureCommitment.d.ts","sourceRoot":"","sources":["../src/SignatureCommitment.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,2BAA2B,OAAO,CAAC;AAOhD,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAE5D;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAK9D"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
/**
|
|
3
|
+
* AWS KMS caps the raw message it will sign with an Ed25519 key
|
|
4
|
+
* (ED25519_SHA_512, MessageType RAW) at 4096 bytes. A full Execution
|
|
5
|
+
* Trust Record, with its bound authorization, connector evidence and
|
|
6
|
+
* governance anchor, is larger than that, so signing it directly fails.
|
|
7
|
+
*
|
|
8
|
+
* Large message commitment (v1): a message longer than the limit is
|
|
9
|
+
* signed as a fixed size commitment, the domain separation prefix
|
|
10
|
+
* followed by the SHA-512 digest of the message. The signature is still
|
|
11
|
+
* a pure Ed25519 signature, so it needs no new algorithm and any
|
|
12
|
+
* standard Ed25519 library can verify it once it rebuilds the same
|
|
13
|
+
* commitment.
|
|
14
|
+
*
|
|
15
|
+
* The scheme is a pure function of message length, so no marker has to
|
|
16
|
+
* be stored on any record:
|
|
17
|
+
*
|
|
18
|
+
* - length <= limit: signed and verified raw, exactly as before, so
|
|
19
|
+
* every signature issued before this change stays valid.
|
|
20
|
+
* - length > limit: signed as the commitment. A verifier also accepts a
|
|
21
|
+
* raw signature over such a message, because a local key signer has
|
|
22
|
+
* always signed large messages raw and those records still exist.
|
|
23
|
+
*
|
|
24
|
+
* The prefix contains a NUL byte and never occurs at the start of a
|
|
25
|
+
* canonical JSON message (which starts with "{"), so a signature over a
|
|
26
|
+
* commitment cannot be replayed as a signature over a small raw message.
|
|
27
|
+
* A commitment signature over a message at or below the limit is not
|
|
28
|
+
* accepted, which prevents downgrading a small message to the
|
|
29
|
+
* commitment form.
|
|
30
|
+
*/
|
|
31
|
+
export const KMS_RAW_MESSAGE_LIMIT_BYTES = 4096;
|
|
32
|
+
const COMMITMENT_PREFIX = Buffer.from("PARMANA-ED25519-LARGE-MESSAGE-V1\0", "utf8");
|
|
33
|
+
export function requiresCommitment(data) {
|
|
34
|
+
return data.length > KMS_RAW_MESSAGE_LIMIT_BYTES;
|
|
35
|
+
}
|
|
36
|
+
export function commitmentMessage(data) {
|
|
37
|
+
return Buffer.concat([
|
|
38
|
+
COMMITMENT_PREFIX,
|
|
39
|
+
createHash("sha512").update(data).digest(),
|
|
40
|
+
]);
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=SignatureCommitment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SignatureCommitment.js","sourceRoot":"","sources":["../src/SignatureCommitment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,IAAI,CAAC;AAEhD,MAAM,iBAAiB,GAAG,MAAM,CAAC,IAAI,CACnC,oCAAoC,EACpC,MAAM,CACP,CAAC;AAEF,MAAM,UAAU,kBAAkB,CAAC,IAAgB;IACjD,OAAO,IAAI,CAAC,MAAM,GAAG,2BAA2B,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,IAAgB;IAChD,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,iBAAiB;QACjB,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE;KAC3C,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type KeyObject } from "node:crypto";
|
|
2
|
+
import { CanonicalSerializer } from "./CanonicalSerializer.js";
|
|
3
|
+
import type { CryptoProvider } from "./providers/CryptoProvider.js";
|
|
4
|
+
/**
|
|
5
|
+
* Signature Verifier.
|
|
6
|
+
*
|
|
7
|
+
* Verifies signatures for canonical Parmana
|
|
8
|
+
* artifacts using the configured
|
|
9
|
+
* SignatureProvider.
|
|
10
|
+
*/
|
|
11
|
+
export declare class SignatureVerifier {
|
|
12
|
+
private readonly crypto;
|
|
13
|
+
private readonly serializer;
|
|
14
|
+
constructor(crypto: CryptoProvider, serializer?: CanonicalSerializer);
|
|
15
|
+
/**
|
|
16
|
+
* Verifies a canonical artifact.
|
|
17
|
+
*/
|
|
18
|
+
verify(artifact: unknown, signature: string, publicKey: KeyObject): Promise<boolean>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=SignatureVerifier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SignatureVerifier.d.ts","sourceRoot":"","sources":["../src/SignatureVerifier.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;AAEpE;;;;;;GAMG;AACH,qBAAa,iBAAiB;IAE1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAEvB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAH7B,YACmB,MAAM,EAAE,cAAc,EAEtB,UAAU,sBAA4B,EACrD;IAEJ;;OAEG;IACG,MAAM,CACV,QAAQ,EAAE,OAAO,EACjB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,SAAS,GACnB,OAAO,CAAC,OAAO,CAAC,CAUlB;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { CanonicalSerializer } from "./CanonicalSerializer.js";
|
|
2
|
+
/**
|
|
3
|
+
* Signature Verifier.
|
|
4
|
+
*
|
|
5
|
+
* Verifies signatures for canonical Parmana
|
|
6
|
+
* artifacts using the configured
|
|
7
|
+
* SignatureProvider.
|
|
8
|
+
*/
|
|
9
|
+
export class SignatureVerifier {
|
|
10
|
+
crypto;
|
|
11
|
+
serializer;
|
|
12
|
+
constructor(crypto, serializer = new CanonicalSerializer()) {
|
|
13
|
+
this.crypto = crypto;
|
|
14
|
+
this.serializer = serializer;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Verifies a canonical artifact.
|
|
18
|
+
*/
|
|
19
|
+
async verify(artifact, signature, publicKey) {
|
|
20
|
+
const bytes = this.serializer.serialize(artifact);
|
|
21
|
+
const verified = await this.crypto.signature.verify(bytes, signature, publicKey);
|
|
22
|
+
return verified;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=SignatureVerifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SignatureVerifier.js","sourceRoot":"","sources":["../src/SignatureVerifier.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAI/D;;;;;;GAMG;AACH,MAAM,OAAO,iBAAiB;IAET,MAAM;IAEN,UAAU;IAH7B,YACmB,MAAsB,EAEtB,UAAU,GAAG,IAAI,mBAAmB,EAAE;sBAFtC,MAAM;0BAEN,UAAU;IAC1B,CAAC;IAEJ;;OAEG;IACH,KAAK,CAAC,MAAM,CACV,QAAiB,EACjB,SAAiB,EACjB,SAAoB;QAEpB,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;QAElD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM,CACjD,KAAK,EACL,SAAS,EACT,SAAS,CACV,CAAC;QAEF,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF"}
|
package/dist/Signer.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { KeyObject } from "node:crypto";
|
|
2
|
+
import type { KeyMetadata } from "./KeyProvider.js";
|
|
3
|
+
/**
|
|
4
|
+
* Signer.
|
|
5
|
+
*
|
|
6
|
+
* Sibling to KeyProvider, for backends that can produce a signature
|
|
7
|
+
* without ever releasing private key material (AWS KMS, HSM, Vault
|
|
8
|
+
* Transit) -- KeyProvider.getPrivateKey() returning a KeyObject is
|
|
9
|
+
* cannot be implemented honestly against such a
|
|
10
|
+
* backend, since the whole point of those backends is that the
|
|
11
|
+
* private key never leaves them. ADR-0009
|
|
12
|
+
* (docs/adr/ADR-0009-KMS-Secrets-And-Connector-Signature-Hardening.md)
|
|
13
|
+
* is the design this interface exists for.
|
|
14
|
+
*
|
|
15
|
+
* Read operations (getPublicKey/getMetadata/hasKey/listKeys) are
|
|
16
|
+
* unchanged from KeyProvider -- verification never needed private key
|
|
17
|
+
* material, so nothing about the verify path changes when a Signer
|
|
18
|
+
* backend is swapped in.
|
|
19
|
+
*/
|
|
20
|
+
export interface Signer {
|
|
21
|
+
/**
|
|
22
|
+
* Signs already-canonicalized bytes and returns the signature in
|
|
23
|
+
* the same base64 string format every existing SignatureProvider
|
|
24
|
+
* implementation already produces (see Ed25519SignatureProvider.sign)
|
|
25
|
+
* -- callers that verify with SignatureVerifier/SignatureProvider.verify()
|
|
26
|
+
* need no changes regardless of which Signer produced the signature.
|
|
27
|
+
*/
|
|
28
|
+
sign(keyId: string, data: Uint8Array): Promise<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Returns the public key. Identical contract to KeyProvider.getPublicKey.
|
|
31
|
+
*/
|
|
32
|
+
getPublicKey(keyId: string): Promise<KeyObject>;
|
|
33
|
+
/**
|
|
34
|
+
* Returns metadata for the specified key. Identical contract to
|
|
35
|
+
* KeyProvider.getMetadata.
|
|
36
|
+
*/
|
|
37
|
+
getMetadata(keyId: string): Promise<KeyMetadata>;
|
|
38
|
+
/**
|
|
39
|
+
* Returns true if the key exists. Identical contract to
|
|
40
|
+
* KeyProvider.hasKey.
|
|
41
|
+
*/
|
|
42
|
+
hasKey(keyId: string): Promise<boolean>;
|
|
43
|
+
/**
|
|
44
|
+
* Lists every keyId this signer can currently produce a public key
|
|
45
|
+
* for. Identical contract to KeyProvider.listKeys.
|
|
46
|
+
*/
|
|
47
|
+
listKeys?(): Promise<string[]>;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=Signer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Signer.d.ts","sourceRoot":"","sources":["../src/Signer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,MAAM;IACrB;;;;;;OAMG;IACH,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEvD;;OAEG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAEhD;;;OAGG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAEjD;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAExC;;;OAGG;IACH,QAAQ,CAAC,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CAChC"}
|
package/dist/Signer.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Signer.js","sourceRoot":"","sources":["../src/Signer.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Signer } from "./Signer.js";
|
|
2
|
+
/**
|
|
3
|
+
* Signer Bootstrap.
|
|
4
|
+
*
|
|
5
|
+
* Composition root for the Signer abstraction (ADR-0009) -- the
|
|
6
|
+
* signing-capable sibling of KeyBootstrap/KeyProvider. Reuses the
|
|
7
|
+
* already-reserved KEY_PROVIDER=aws-kms value from
|
|
8
|
+
* packages/shared/src/config/KeyProviders.ts; KeyBootstrap.ts itself
|
|
9
|
+
* is unchanged (nothing in this codebase's production paths actually
|
|
10
|
+
* calls it today -- every existing signing call site constructed its
|
|
11
|
+
* own FileKeyProvider directly, which is exactly what this bootstrap
|
|
12
|
+
* replaces).
|
|
13
|
+
*
|
|
14
|
+
* async, unlike KeyBootstrap.create(): resolving KmsSigner's
|
|
15
|
+
* credentials may require a dynamic import of an optional peer
|
|
16
|
+
* dependency (see KmsSigner.create()'s own doc comment).
|
|
17
|
+
*
|
|
18
|
+
* Deliberately NOT memoized (unlike KeyBootstrap.create()'s static
|
|
19
|
+
* caching): every existing signing call site previously constructed
|
|
20
|
+
* its own fresh `new FileKeyProvider()` per instance, which re-reads
|
|
21
|
+
* `loadConfig().keys.keyDirectory` (and so the current
|
|
22
|
+
* PARMANA_KEY_DIR) fresh every time. A static singleton here broke
|
|
23
|
+
* that -- caught by a real CI failure
|
|
24
|
+
* (packages/api/tests/unit/supabase-caller-audit-sink.test.ts), where
|
|
25
|
+
* each test sets PARMANA_KEY_DIR to its own temp directory and tears
|
|
26
|
+
* it down in afterEach: the first test to run would permanently poison
|
|
27
|
+
* a process-wide cached signer pointing at a directory every
|
|
28
|
+
* subsequent test had already deleted. Reconstructing a
|
|
29
|
+
* KMSClient/FileKeyProvider per call is cheap (no network call happens
|
|
30
|
+
* until an actual sign/getPublicKey/etc. request), so there is no
|
|
31
|
+
* meaningful cost to matching the old per-instance-fresh-read
|
|
32
|
+
* semantics exactly.
|
|
33
|
+
*/
|
|
34
|
+
export declare class SignerBootstrap {
|
|
35
|
+
static create(): Promise<Signer>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=SignerBootstrap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SignerBootstrap.d.ts","sourceRoot":"","sources":["../src/SignerBootstrap.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAK1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,qBAAa,eAAe;IAC1B,OAAa,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC,CAiBrC;CACF"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { KeyProviders, loadConfig } from "@parmana/shared";
|
|
2
|
+
import { CryptoBootstrap } from "./CryptoBootstrap.js";
|
|
3
|
+
import { KmsSigner } from "./providers/signer/KmsSigner.js";
|
|
4
|
+
import { LocalFileSigner } from "./providers/signer/LocalFileSigner.js";
|
|
5
|
+
/**
|
|
6
|
+
* Signer Bootstrap.
|
|
7
|
+
*
|
|
8
|
+
* Composition root for the Signer abstraction (ADR-0009) -- the
|
|
9
|
+
* signing-capable sibling of KeyBootstrap/KeyProvider. Reuses the
|
|
10
|
+
* already-reserved KEY_PROVIDER=aws-kms value from
|
|
11
|
+
* packages/shared/src/config/KeyProviders.ts; KeyBootstrap.ts itself
|
|
12
|
+
* is unchanged (nothing in this codebase's production paths actually
|
|
13
|
+
* calls it today -- every existing signing call site constructed its
|
|
14
|
+
* own FileKeyProvider directly, which is exactly what this bootstrap
|
|
15
|
+
* replaces).
|
|
16
|
+
*
|
|
17
|
+
* async, unlike KeyBootstrap.create(): resolving KmsSigner's
|
|
18
|
+
* credentials may require a dynamic import of an optional peer
|
|
19
|
+
* dependency (see KmsSigner.create()'s own doc comment).
|
|
20
|
+
*
|
|
21
|
+
* Deliberately NOT memoized (unlike KeyBootstrap.create()'s static
|
|
22
|
+
* caching): every existing signing call site previously constructed
|
|
23
|
+
* its own fresh `new FileKeyProvider()` per instance, which re-reads
|
|
24
|
+
* `loadConfig().keys.keyDirectory` (and so the current
|
|
25
|
+
* PARMANA_KEY_DIR) fresh every time. A static singleton here broke
|
|
26
|
+
* that -- caught by a real CI failure
|
|
27
|
+
* (packages/api/tests/unit/supabase-caller-audit-sink.test.ts), where
|
|
28
|
+
* each test sets PARMANA_KEY_DIR to its own temp directory and tears
|
|
29
|
+
* it down in afterEach: the first test to run would permanently poison
|
|
30
|
+
* a process-wide cached signer pointing at a directory every
|
|
31
|
+
* subsequent test had already deleted. Reconstructing a
|
|
32
|
+
* KMSClient/FileKeyProvider per call is cheap (no network call happens
|
|
33
|
+
* until an actual sign/getPublicKey/etc. request), so there is no
|
|
34
|
+
* meaningful cost to matching the old per-instance-fresh-read
|
|
35
|
+
* semantics exactly.
|
|
36
|
+
*/
|
|
37
|
+
export class SignerBootstrap {
|
|
38
|
+
static async create() {
|
|
39
|
+
const configuredProvider = loadConfig().keys.provider;
|
|
40
|
+
if (configuredProvider === KeyProviders.LOCAL) {
|
|
41
|
+
return new LocalFileSigner(CryptoBootstrap.create());
|
|
42
|
+
}
|
|
43
|
+
if (configuredProvider === KeyProviders.AWS_KMS) {
|
|
44
|
+
return KmsSigner.create();
|
|
45
|
+
}
|
|
46
|
+
throw new Error(`KEY_PROVIDER=${configuredProvider} is not implemented. Only "${KeyProviders.LOCAL}" ` +
|
|
47
|
+
`and "${KeyProviders.AWS_KMS}" have a real Signer implementation today. Refusing to ` +
|
|
48
|
+
"start with a configured key custody model (azure-key-vault, gcp-kms, hsm) that would " +
|
|
49
|
+
"silently fall back to file-based keys instead of the custody the configuration requested.");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=SignerBootstrap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SignerBootstrap.js","sourceRoot":"","sources":["../src/SignerBootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAE3D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAGvD,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,OAAO,eAAe;IAC1B,MAAM,CAAC,KAAK,CAAC,MAAM;QACjB,MAAM,kBAAkB,GAAG,UAAU,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC;QAEtD,IAAI,kBAAkB,KAAK,YAAY,CAAC,KAAK,EAAE,CAAC;YAC9C,OAAO,IAAI,eAAe,CAAC,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC;QACvD,CAAC;QAED,IAAI,kBAAkB,KAAK,YAAY,CAAC,OAAO,EAAE,CAAC;YAChD,OAAO,SAAS,CAAC,MAAM,EAAE,CAAC;QAC5B,CAAC;QAED,MAAM,IAAI,KAAK,CACb,gBAAgB,kBAAkB,8BAA8B,YAAY,CAAC,KAAK,IAAI;YACpF,QAAQ,YAAY,CAAC,OAAO,yDAAyD;YACrF,uFAAuF;YACvF,2FAA2F,CAC9F,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CanonicalSerializer } from "./CanonicalSerializer.js";
|
|
2
|
+
import type { CryptoProvider } from "./providers/CryptoProvider.js";
|
|
3
|
+
/**
|
|
4
|
+
* Trust Record Hasher.
|
|
5
|
+
*
|
|
6
|
+
* Produces a deterministic cryptographic hash
|
|
7
|
+
* for immutable trust artifacts.
|
|
8
|
+
*/
|
|
9
|
+
export declare class TrustRecordHasher {
|
|
10
|
+
private readonly crypto;
|
|
11
|
+
private readonly serializer;
|
|
12
|
+
constructor(crypto: CryptoProvider, serializer?: CanonicalSerializer);
|
|
13
|
+
/**
|
|
14
|
+
* Hashes an immutable object.
|
|
15
|
+
*/
|
|
16
|
+
hash(value: unknown): Promise<string>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=TrustRecordHasher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TrustRecordHasher.d.ts","sourceRoot":"","sources":["../src/TrustRecordHasher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAE/D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAEpE;;;;;GAKG;AACH,qBAAa,iBAAiB;IAE1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAEvB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAH7B,YACmB,MAAM,EAAE,cAAc,EAEtB,UAAU,sBAA4B,EACrD;IAEJ;;OAEG;IACG,IAAI,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAI1C;CACF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CanonicalSerializer } from "./CanonicalSerializer.js";
|
|
2
|
+
/**
|
|
3
|
+
* Trust Record Hasher.
|
|
4
|
+
*
|
|
5
|
+
* Produces a deterministic cryptographic hash
|
|
6
|
+
* for immutable trust artifacts.
|
|
7
|
+
*/
|
|
8
|
+
export class TrustRecordHasher {
|
|
9
|
+
crypto;
|
|
10
|
+
serializer;
|
|
11
|
+
constructor(crypto, serializer = new CanonicalSerializer()) {
|
|
12
|
+
this.crypto = crypto;
|
|
13
|
+
this.serializer = serializer;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Hashes an immutable object.
|
|
17
|
+
*/
|
|
18
|
+
async hash(value) {
|
|
19
|
+
const bytes = this.serializer.serialize(value);
|
|
20
|
+
return this.crypto.hash.hash(bytes);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=TrustRecordHasher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TrustRecordHasher.js","sourceRoot":"","sources":["../src/TrustRecordHasher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAI/D;;;;;GAKG;AACH,MAAM,OAAO,iBAAiB;IAET,MAAM;IAEN,UAAU;IAH7B,YACmB,MAAsB,EAEtB,UAAU,GAAG,IAAI,mBAAmB,EAAE;sBAFtC,MAAM;0BAEN,UAAU;IAC1B,CAAC;IAEJ;;OAEG;IACH,KAAK,CAAC,IAAI,CAAC,KAAc;QACvB,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAE/C,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;CACF"}
|