@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,97 @@
|
|
|
1
|
+
import { AuditEventCrypto } from "./AuditEventCrypto.js";
|
|
2
|
+
import { CryptoBootstrap } from "./CryptoBootstrap.js";
|
|
3
|
+
import { TrustRecordHasher } from "./TrustRecordHasher.js";
|
|
4
|
+
/**
|
|
5
|
+
* Verifies one caller's full audit chain (SupabaseCallerAuditSink's
|
|
6
|
+
* per-caller chaining): each row's signature against its own
|
|
7
|
+
* recomputed content -- including the previousChainHash/chainPosition
|
|
8
|
+
* fields folded into what was actually signed -- and that each row's
|
|
9
|
+
* previousChainHash references the immediately-preceding row's own
|
|
10
|
+
* chainHash. No network call, no database, no running Parmana
|
|
11
|
+
* process: pass it rows already fetched from storage, in ascending
|
|
12
|
+
* chain_position order. The same standalone discipline
|
|
13
|
+
* docs/site/guides/verify-independently.mdx demonstrates for
|
|
14
|
+
* ExecutionTrustRecord, extended to the caller-audit trail.
|
|
15
|
+
*
|
|
16
|
+
* A deleted row breaks this: the row after it still carries the
|
|
17
|
+
* deleted row's chainHash as its own previousChainHash, but the
|
|
18
|
+
* row before it has a different chainHash -- the linkage check below
|
|
19
|
+
* catches the mismatch, which is exactly the gap this class closes
|
|
20
|
+
* (see docs/site/trust-and-claims/objections-and-evidence.mdx,
|
|
21
|
+
* Domain 3).
|
|
22
|
+
*
|
|
23
|
+
* Rows with no chain fields at all (no callerId at write time --
|
|
24
|
+
* the earliest possible rejection, or caller.rejected) are verified
|
|
25
|
+
* for signature only, never required to link -- the same "absent
|
|
26
|
+
* means unprotected, not broken" discipline
|
|
27
|
+
* ExecutionChainCrypto.verifyChain() already applies to legacy,
|
|
28
|
+
* pre-chain-feature Executions.
|
|
29
|
+
*/
|
|
30
|
+
export class CallerAuditChainVerifier {
|
|
31
|
+
crypto = new AuditEventCrypto();
|
|
32
|
+
hasher = new TrustRecordHasher(CryptoBootstrap.create());
|
|
33
|
+
/**
|
|
34
|
+
* `anchor`, when given, is the chain head (last chainPosition and its
|
|
35
|
+
* chainHash) recorded outside the database when the chain was last seen.
|
|
36
|
+
* The chain must end exactly there. Without an anchor, deleting the newest
|
|
37
|
+
* rows leaves a valid, shorter chain: that cannot be detected from the
|
|
38
|
+
* rows alone.
|
|
39
|
+
*/
|
|
40
|
+
async verifyChain(rows, anchor) {
|
|
41
|
+
let previousHash = null;
|
|
42
|
+
let position = 0;
|
|
43
|
+
for (const row of rows) {
|
|
44
|
+
position++;
|
|
45
|
+
const isChained = row.chainHash !== null && row.chainPosition !== null;
|
|
46
|
+
const signedContent = isChained
|
|
47
|
+
? {
|
|
48
|
+
...row.event,
|
|
49
|
+
previousChainHash: row.previousChainHash,
|
|
50
|
+
chainPosition: row.chainPosition,
|
|
51
|
+
}
|
|
52
|
+
: row.event;
|
|
53
|
+
const signatureValid = await this.crypto.verify(signedContent, row.signature);
|
|
54
|
+
if (!signatureValid) {
|
|
55
|
+
return {
|
|
56
|
+
valid: false,
|
|
57
|
+
brokenAtPosition: position,
|
|
58
|
+
reason: "signature does not match recomputed content.",
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (!isChained) {
|
|
62
|
+
previousHash = null;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const expectedHash = await this.hasher.hash(signedContent);
|
|
66
|
+
if (expectedHash !== row.chainHash) {
|
|
67
|
+
return {
|
|
68
|
+
valid: false,
|
|
69
|
+
brokenAtPosition: position,
|
|
70
|
+
reason: "chainHash does not match recomputed content.",
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (row.previousChainHash !== previousHash) {
|
|
74
|
+
return {
|
|
75
|
+
valid: false,
|
|
76
|
+
brokenAtPosition: position,
|
|
77
|
+
reason: "previousChainHash does not reference the prior event's chainHash.",
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
previousHash = row.chainHash;
|
|
81
|
+
}
|
|
82
|
+
if (anchor !== undefined) {
|
|
83
|
+
const last = rows[rows.length - 1];
|
|
84
|
+
if (last === undefined ||
|
|
85
|
+
last.chainPosition !== anchor.chainPosition ||
|
|
86
|
+
last.chainHash !== anchor.chainHash) {
|
|
87
|
+
return {
|
|
88
|
+
valid: false,
|
|
89
|
+
brokenAtPosition: position,
|
|
90
|
+
reason: "chain does not end at the anchored chain head (records missing or truncated).",
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return { valid: true };
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=CallerAuditChainVerifier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CallerAuditChainVerifier.js","sourceRoot":"","sources":["../src/CallerAuditChainVerifier.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAuB3D;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,wBAAwB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;iBACvD,CAAC;YACJ,CAAC;YAED,IAAI,GAAG,CAAC,iBAAiB,KAAK,YAAY,EAAE,CAAC;gBAC3C,OAAO;oBACL,KAAK,EAAE,KAAK;oBACZ,gBAAgB,EAAE,QAAQ;oBAC1B,MAAM,EACJ,mEAAmE;iBACtE,CAAC;YACJ,CAAC;YAED,YAAY,GAAG,GAAG,CAAC,SAAS,CAAC;QAC/B,CAAC;QAED,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YACzB,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAEnC,IACE,IAAI,KAAK,SAAS;gBAClB,IAAI,CAAC,aAAa,KAAK,MAAM,CAAC,aAAa;gBAC3C,IAAI,CAAC,SAAS,KAAK,MAAM,CAAC,SAAS,EACnC,CAAC;gBACD,OAAO;oBACL,KAAK,EAAE,KAAK;oBACZ,gBAAgB,EAAE,QAAQ;oBAC1B,MAAM,EACJ,+EAA+E;iBAClF,CAAC;YACJ,CAAC;QACH,CAAC;QAED,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;IACzB,CAAC;CACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical Serializer.
|
|
3
|
+
*
|
|
4
|
+
* Produces a deterministic byte representation of an
|
|
5
|
+
* immutable object.
|
|
6
|
+
*
|
|
7
|
+
* Every cryptographic operation in Parmana MUST operate
|
|
8
|
+
* on canonical serialized bytes produced by this class.
|
|
9
|
+
*
|
|
10
|
+
* This guarantees that hashing, signing, verification,
|
|
11
|
+
* replay, and receipts all operate over identical data.
|
|
12
|
+
*/
|
|
13
|
+
export declare class CanonicalSerializer {
|
|
14
|
+
/**
|
|
15
|
+
* Serializes an object into canonical UTF-8 bytes.
|
|
16
|
+
*
|
|
17
|
+
* Objects are recursively normalized by sorting keys
|
|
18
|
+
* lexicographically.
|
|
19
|
+
*/
|
|
20
|
+
serialize(value: unknown): Uint8Array;
|
|
21
|
+
/**
|
|
22
|
+
* Recursively normalizes values.
|
|
23
|
+
*/
|
|
24
|
+
private normalize;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=CanonicalSerializer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CanonicalSerializer.d.ts","sourceRoot":"","sources":["../src/CanonicalSerializer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,qBAAa,mBAAmB;IAC9B;;;;;OAKG;IACH,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAIpC;IAED;;OAEG;IACH,OAAO,CAAC,SAAS;CAwDlB"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical Serializer.
|
|
3
|
+
*
|
|
4
|
+
* Produces a deterministic byte representation of an
|
|
5
|
+
* immutable object.
|
|
6
|
+
*
|
|
7
|
+
* Every cryptographic operation in Parmana MUST operate
|
|
8
|
+
* on canonical serialized bytes produced by this class.
|
|
9
|
+
*
|
|
10
|
+
* This guarantees that hashing, signing, verification,
|
|
11
|
+
* replay, and receipts all operate over identical data.
|
|
12
|
+
*/
|
|
13
|
+
export class CanonicalSerializer {
|
|
14
|
+
/**
|
|
15
|
+
* Serializes an object into canonical UTF-8 bytes.
|
|
16
|
+
*
|
|
17
|
+
* Objects are recursively normalized by sorting keys
|
|
18
|
+
* lexicographically.
|
|
19
|
+
*/
|
|
20
|
+
serialize(value) {
|
|
21
|
+
const canonical = JSON.stringify(this.normalize(value));
|
|
22
|
+
return new TextEncoder().encode(canonical);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Recursively normalizes values.
|
|
26
|
+
*/
|
|
27
|
+
normalize(value) {
|
|
28
|
+
//
|
|
29
|
+
// null
|
|
30
|
+
//
|
|
31
|
+
if (value === null) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
//
|
|
35
|
+
// primitives
|
|
36
|
+
//
|
|
37
|
+
if (typeof value !== "object") {
|
|
38
|
+
return value;
|
|
39
|
+
}
|
|
40
|
+
//
|
|
41
|
+
// arrays preserve order
|
|
42
|
+
//
|
|
43
|
+
if (Array.isArray(value)) {
|
|
44
|
+
return value.map((item) => this.normalize(item));
|
|
45
|
+
}
|
|
46
|
+
//
|
|
47
|
+
// Date
|
|
48
|
+
//
|
|
49
|
+
if (value instanceof Date) {
|
|
50
|
+
return value.toISOString();
|
|
51
|
+
}
|
|
52
|
+
//
|
|
53
|
+
// objects
|
|
54
|
+
//
|
|
55
|
+
const object = value;
|
|
56
|
+
return Object.keys(object)
|
|
57
|
+
.sort()
|
|
58
|
+
.reduce((normalized, key) => {
|
|
59
|
+
//
|
|
60
|
+
// Object.defineProperty, not normalized[key] = ...: a decoded
|
|
61
|
+
// JSON object can carry a literal "__proto__" key, and plain
|
|
62
|
+
// assignment sends that key to the prototype setter instead of
|
|
63
|
+
// creating an own property, so it silently vanished from the
|
|
64
|
+
// signed bytes. Its content was then not covered by the hash or
|
|
65
|
+
// signature, and the output disagreed with the Python SDK and
|
|
66
|
+
// third-party verifiers, which both keep it.
|
|
67
|
+
//
|
|
68
|
+
Object.defineProperty(normalized, key, {
|
|
69
|
+
value: this.normalize(object[key]),
|
|
70
|
+
enumerable: true,
|
|
71
|
+
writable: true,
|
|
72
|
+
configurable: true,
|
|
73
|
+
});
|
|
74
|
+
return normalized;
|
|
75
|
+
}, {});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=CanonicalSerializer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CanonicalSerializer.js","sourceRoot":"","sources":["../src/CanonicalSerializer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,mBAAmB;IAC9B;;;;;OAKG;IACH,SAAS,CAAC,KAAc;QACtB,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC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AE,IAAI;aACnB,CAAC,CAAC;YAEH,OAAO,UAAU,CAAC;QACpB,CAAC,EAAE,EAAE,CAAC,CAAC;IACX,CAAC;CACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { HybridCryptoProvider } from "./models/HybridCryptoProvider.js";
|
|
2
|
+
import type { CryptoProvider } from "./providers/CryptoProvider.js";
|
|
3
|
+
/**
|
|
4
|
+
* Crypto Bootstrap.
|
|
5
|
+
*
|
|
6
|
+
* Composition root for the Parmana crypto subsystem.
|
|
7
|
+
*/
|
|
8
|
+
export declare class CryptoBootstrap {
|
|
9
|
+
private static provider;
|
|
10
|
+
private static hybrid;
|
|
11
|
+
/**
|
|
12
|
+
* Builds a CryptoProvider for a specific
|
|
13
|
+
* signature algorithm.
|
|
14
|
+
*/
|
|
15
|
+
private static buildProvider;
|
|
16
|
+
/**
|
|
17
|
+
* Creates the configured CryptoProvider.
|
|
18
|
+
*/
|
|
19
|
+
static create(): CryptoProvider;
|
|
20
|
+
/**
|
|
21
|
+
* Creates both configured providers.
|
|
22
|
+
*
|
|
23
|
+
* Used for hybrid migration scenarios.
|
|
24
|
+
*/
|
|
25
|
+
static createHybrid(): HybridCryptoProvider;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=CryptoBootstrap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CryptoBootstrap.d.ts","sourceRoot":"","sources":["../src/CryptoBootstrap.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AAC7E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAapE;;;;GAIG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAA6B;IAEpD,OAAO,CAAC,MAAM,CAAC,MAAM,CAAmC;IAExD;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,aAAa;IA8B5B;;OAEG;IACH,OAAc,MAAM,IAAI,cAAc,CAUrC;IAED;;;;OAIG;IACH,OAAc,YAAY,IAAI,oBAAoB,CAkBjD;CACF"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { loadConfig } from "@parmana/shared";
|
|
2
|
+
import { CryptoBuilder } from "./CryptoBuilder.js";
|
|
3
|
+
import { HashRegistry } from "./providers/HashRegistry.js";
|
|
4
|
+
import { SignatureRegistry } from "./providers/SignatureRegistry.js";
|
|
5
|
+
// Built-in Providers
|
|
6
|
+
import { SHA256HashProvider } from "./providers/hash/SHA256HashProvider.js";
|
|
7
|
+
import { Ed25519SignatureProvider } from "./providers/signature/Ed25519SignatureProvider.js";
|
|
8
|
+
import { Dilithium3SignatureProvider } from "./providers/signature/Dilithium3SignatureProvider.js";
|
|
9
|
+
/**
|
|
10
|
+
* Crypto Bootstrap.
|
|
11
|
+
*
|
|
12
|
+
* Composition root for the Parmana crypto subsystem.
|
|
13
|
+
*/
|
|
14
|
+
export class CryptoBootstrap {
|
|
15
|
+
static provider;
|
|
16
|
+
static hybrid;
|
|
17
|
+
/**
|
|
18
|
+
* Builds a CryptoProvider for a specific
|
|
19
|
+
* signature algorithm.
|
|
20
|
+
*/
|
|
21
|
+
static buildProvider(signatureAlgorithm) {
|
|
22
|
+
const config = loadConfig();
|
|
23
|
+
const hashRegistry = new HashRegistry();
|
|
24
|
+
const signatureRegistry = new SignatureRegistry();
|
|
25
|
+
//
|
|
26
|
+
// Register built-in hash providers.
|
|
27
|
+
//
|
|
28
|
+
hashRegistry.register(new SHA256HashProvider());
|
|
29
|
+
//
|
|
30
|
+
// Register built-in signature providers.
|
|
31
|
+
//
|
|
32
|
+
signatureRegistry.register(new Ed25519SignatureProvider());
|
|
33
|
+
signatureRegistry.register(new Dilithium3SignatureProvider());
|
|
34
|
+
return new CryptoBuilder()
|
|
35
|
+
.withHash(hashRegistry.get(config.crypto.hashProvider))
|
|
36
|
+
.withSignature(signatureRegistry.get(signatureAlgorithm))
|
|
37
|
+
.build();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Creates the configured CryptoProvider.
|
|
41
|
+
*/
|
|
42
|
+
static create() {
|
|
43
|
+
if (this.provider) {
|
|
44
|
+
return this.provider;
|
|
45
|
+
}
|
|
46
|
+
const config = loadConfig();
|
|
47
|
+
this.provider = this.buildProvider(config.crypto.primarySignatureProvider);
|
|
48
|
+
return this.provider;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Creates both configured providers.
|
|
52
|
+
*
|
|
53
|
+
* Used for hybrid migration scenarios.
|
|
54
|
+
*/
|
|
55
|
+
static createHybrid() {
|
|
56
|
+
if (this.hybrid) {
|
|
57
|
+
return this.hybrid;
|
|
58
|
+
}
|
|
59
|
+
const config = loadConfig();
|
|
60
|
+
if (!config.crypto.secondarySignatureProvider) {
|
|
61
|
+
throw new Error("Secondary signature provider is not configured.");
|
|
62
|
+
}
|
|
63
|
+
this.hybrid = {
|
|
64
|
+
primary: this.buildProvider(config.crypto.primarySignatureProvider),
|
|
65
|
+
secondary: this.buildProvider(config.crypto.secondarySignatureProvider),
|
|
66
|
+
};
|
|
67
|
+
return this.hybrid;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=CryptoBootstrap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CryptoBootstrap.js","sourceRoot":"","sources":["../src/CryptoBootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAK7C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAErE,qBAAqB;AACrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAE5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,mDAAmD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AC,MAAM,EAAE,CAAC;YAChB,OAAO,IAAI,CAAC,MAAM,CAAC;QACrB,CAAC;QAED,MAAM,MAAM,GAAG,UAAU,EAAE,CAAC;QAE5B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,0BAA0B,EAAE,CAAC;YAC9C,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACrE,CAAC;QAED,IAAI,CAAC,MAAM,GAAG;YACZ,OAAO,EAAE,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,wBAAwB,CAAC;YAEnE,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,0BAA0B,CAAC;SACxE,CAAC;QAEF,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CryptoProvider } from "./providers/CryptoProvider.js";
|
|
2
|
+
import type { HashProvider } from "./providers/HashProvider.js";
|
|
3
|
+
import type { SignatureProvider } from "./providers/SignatureProvider.js";
|
|
4
|
+
/**
|
|
5
|
+
* Builder for constructing a CryptoProvider.
|
|
6
|
+
*
|
|
7
|
+
* The builder is algorithm-agnostic.
|
|
8
|
+
* Provider selection is handled elsewhere
|
|
9
|
+
* (ProviderFactory / Registry).
|
|
10
|
+
*/
|
|
11
|
+
export declare class CryptoBuilder {
|
|
12
|
+
private hashProvider?;
|
|
13
|
+
private signatureProvider?;
|
|
14
|
+
/**
|
|
15
|
+
* Sets the hash provider.
|
|
16
|
+
*/
|
|
17
|
+
withHash(provider: HashProvider): this;
|
|
18
|
+
/**
|
|
19
|
+
* Sets the signature provider.
|
|
20
|
+
*/
|
|
21
|
+
withSignature(provider: SignatureProvider): this;
|
|
22
|
+
/**
|
|
23
|
+
* Builds the CryptoProvider.
|
|
24
|
+
*/
|
|
25
|
+
build(): CryptoProvider;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=CryptoBuilder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CryptoBuilder.d.ts","sourceRoot":"","sources":["../src/CryptoBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAEpE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAEhE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAI1E;;;;;;GAMG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,YAAY,CAAC,CAAe;IAEpC,OAAO,CAAC,iBAAiB,CAAC,CAAoB;IAE9C;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,YAAY,GAAG,IAAI,CAIrC;IAED;;OAEG;IACH,aAAa,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAI/C;IAED;;OAEG;IACH,KAAK,IAAI,cAAc,CActB;CACF"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { CryptoError } from "./errors/CryptoError.js";
|
|
2
|
+
/**
|
|
3
|
+
* Builder for constructing a CryptoProvider.
|
|
4
|
+
*
|
|
5
|
+
* The builder is algorithm-agnostic.
|
|
6
|
+
* Provider selection is handled elsewhere
|
|
7
|
+
* (ProviderFactory / Registry).
|
|
8
|
+
*/
|
|
9
|
+
export class CryptoBuilder {
|
|
10
|
+
hashProvider;
|
|
11
|
+
signatureProvider;
|
|
12
|
+
/**
|
|
13
|
+
* Sets the hash provider.
|
|
14
|
+
*/
|
|
15
|
+
withHash(provider) {
|
|
16
|
+
this.hashProvider = provider;
|
|
17
|
+
return this;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Sets the signature provider.
|
|
21
|
+
*/
|
|
22
|
+
withSignature(provider) {
|
|
23
|
+
this.signatureProvider = provider;
|
|
24
|
+
return this;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Builds the CryptoProvider.
|
|
28
|
+
*/
|
|
29
|
+
build() {
|
|
30
|
+
if (!this.hashProvider) {
|
|
31
|
+
throw new CryptoError("HashProvider has not been configured.");
|
|
32
|
+
}
|
|
33
|
+
if (!this.signatureProvider) {
|
|
34
|
+
throw new CryptoError("SignatureProvider has not been configured.");
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
hash: this.hashProvider,
|
|
38
|
+
signature: this.signatureProvider,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=CryptoBuilder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CryptoBuilder.js","sourceRoot":"","sources":["../src/CryptoBuilder.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD;;;;;;GAMG;AACH,MAAM,OAAO,aAAa;IAChB,YAAY,CAAgB;IAE5B,iBAAiB,CAAqB;IAE9C;;OAEG;IACH,QAAQ,CAAC,QAAsB;QAC7B,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC;QAE7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,aAAa,CAAC,QAA2B;QACvC,IAAI,CAAC,iBAAiB,GAAG,QAAQ,CAAC;QAElC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC;YACvB,MAAM,IAAI,WAAW,CAAC,uCAAuC,CAAC,CAAC;QACjE,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC;YAC5B,MAAM,IAAI,WAAW,CAAC,4CAA4C,CAAC,CAAC;QACtE,CAAC;QAED,OAAO;YACL,IAAI,EAAE,IAAI,CAAC,YAAY;YAEvB,SAAS,EAAE,IAAI,CAAC,iBAAiB;SAClC,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { CryptoProvider } from "./providers/CryptoProvider.js";
|
|
2
|
+
import type { ExecutableContent } from "@parmana/shared";
|
|
3
|
+
/**
|
|
4
|
+
* Executable Content Hasher.
|
|
5
|
+
*
|
|
6
|
+
* Produces the canonical content hash bound into an
|
|
7
|
+
* ExecutionAuthorizationPayload's businessTransactionHash field.
|
|
8
|
+
*
|
|
9
|
+
* Delegates to TrustRecordHasher so the signing side (this class)
|
|
10
|
+
* and the verifying side (the execution gateway) run the identical
|
|
11
|
+
* canonical serialization and hash algorithm — never two parallel
|
|
12
|
+
* implementations of the same computation.
|
|
13
|
+
*/
|
|
14
|
+
export declare class ExecutableContentHasher {
|
|
15
|
+
private readonly hasher;
|
|
16
|
+
constructor(crypto: CryptoProvider);
|
|
17
|
+
/**
|
|
18
|
+
* Hashes Executable Content.
|
|
19
|
+
*/
|
|
20
|
+
hash(content: ExecutableContent): Promise<string>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=ExecutableContentHasher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExecutableContentHasher.d.ts","sourceRoot":"","sources":["../src/ExecutableContentHasher.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAEpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEzD;;;;;;;;;;GAUG;AACH,qBAAa,uBAAuB;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAoB;IAE3C,YAAY,MAAM,EAAE,cAAc,EAEjC;IAED;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC,CAEhD;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { TrustRecordHasher } from "./TrustRecordHasher.js";
|
|
2
|
+
/**
|
|
3
|
+
* Executable Content Hasher.
|
|
4
|
+
*
|
|
5
|
+
* Produces the canonical content hash bound into an
|
|
6
|
+
* ExecutionAuthorizationPayload's businessTransactionHash field.
|
|
7
|
+
*
|
|
8
|
+
* Delegates to TrustRecordHasher so the signing side (this class)
|
|
9
|
+
* and the verifying side (the execution gateway) run the identical
|
|
10
|
+
* canonical serialization and hash algorithm — never two parallel
|
|
11
|
+
* implementations of the same computation.
|
|
12
|
+
*/
|
|
13
|
+
export class ExecutableContentHasher {
|
|
14
|
+
hasher;
|
|
15
|
+
constructor(crypto) {
|
|
16
|
+
this.hasher = new TrustRecordHasher(crypto);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Hashes Executable Content.
|
|
20
|
+
*/
|
|
21
|
+
hash(content) {
|
|
22
|
+
return this.hasher.hash(content);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=ExecutableContentHasher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExecutableContentHasher.js","sourceRoot":"","sources":["../src/ExecutableContentHasher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAM3D;;;;;;;;;;GAUG;AACH,MAAM,OAAO,uBAAuB;IACjB,MAAM,CAAoB;IAE3C,YAAY,MAAsB;QAChC,IAAI,CAAC,MAAM,GAAG,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,IAAI,CAAC,OAA0B;QAC7B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { Execution, Signature } from "@parmana/shared";
|
|
2
|
+
/**
|
|
3
|
+
* Result of computing one Execution's chain fields.
|
|
4
|
+
*/
|
|
5
|
+
export interface ExecutionChainFields {
|
|
6
|
+
readonly previousChainHash: string | null;
|
|
7
|
+
readonly chainHash: string;
|
|
8
|
+
readonly chainSignature: Signature;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Result of verifying a business transaction's full Execution chain.
|
|
12
|
+
*/
|
|
13
|
+
export interface ChainVerificationResult {
|
|
14
|
+
readonly valid: boolean;
|
|
15
|
+
readonly brokenAt?: string;
|
|
16
|
+
readonly reason?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Execution Chain cryptographic operations.
|
|
20
|
+
*
|
|
21
|
+
* Signs a hash chain over the Executions belonging to one
|
|
22
|
+
* business_transaction_id, reusing the same ArtifactSigner /
|
|
23
|
+
* FileKeyProvider / DEFAULT_KEY_ID stack as every other signed
|
|
24
|
+
* artifact (ReceiptCrypto, VerificationCrypto, PolicyChangeCrypto) --
|
|
25
|
+
* not a third key to manage.
|
|
26
|
+
*
|
|
27
|
+
* A plain SHA-256 hash stored alongside the content it hashes gives no
|
|
28
|
+
* protection against an actor who already has UPDATE rights on the
|
|
29
|
+
* executions row (they can recompute a fresh valid hash over tampered
|
|
30
|
+
* content in the same statement). Signing each chainHash with
|
|
31
|
+
* Parmana's private key closes that: an actor with DB write access but
|
|
32
|
+
* not the private key cannot forge a replacement chain link.
|
|
33
|
+
*/
|
|
34
|
+
export declare class ExecutionChainCrypto {
|
|
35
|
+
private readonly crypto;
|
|
36
|
+
private readonly signerPromise;
|
|
37
|
+
private readonly chainHasher;
|
|
38
|
+
private readonly signer;
|
|
39
|
+
private readonly verifier;
|
|
40
|
+
/**
|
|
41
|
+
* Creates the canonical immutable view of one Execution chain
|
|
42
|
+
* link used for hashing and signing. Deliberately excludes
|
|
43
|
+
* chainHash/chainSignature themselves -- the same discipline
|
|
44
|
+
* VerificationCrypto.canonicalRecord already applies to
|
|
45
|
+
* trustRecordHash/signature -- so the signed content never
|
|
46
|
+
* includes its own signature.
|
|
47
|
+
*
|
|
48
|
+
* previousChainHash IS included: it is the chain-linking element,
|
|
49
|
+
* and must be covered by the signature so an attacker cannot
|
|
50
|
+
* re-point this link at a different predecessor without
|
|
51
|
+
* invalidating chainSignature.
|
|
52
|
+
*/
|
|
53
|
+
private canonicalChainEntry;
|
|
54
|
+
/**
|
|
55
|
+
* Computes (chainHash, chainSignature) for one Execution given its
|
|
56
|
+
* fixed previousChainHash -- the chain predecessor's chainHash, or
|
|
57
|
+
* null for the first Execution in a business transaction's chain.
|
|
58
|
+
*/
|
|
59
|
+
chain(execution: Execution, previousChainHash: string | null): Promise<ExecutionChainFields>;
|
|
60
|
+
/**
|
|
61
|
+
* Verifies one Execution's own chainHash and chainSignature against
|
|
62
|
+
* its recomputed canonical content. Does not check chain linkage --
|
|
63
|
+
* see verifyChain() for that.
|
|
64
|
+
*/
|
|
65
|
+
verifyEntry(execution: Execution): Promise<boolean>;
|
|
66
|
+
/**
|
|
67
|
+
* Walks Executions in their already-established (created_at, seq)
|
|
68
|
+
* append order and verifies both per-entry authenticity and
|
|
69
|
+
* previousChainHash linkage to the prior entry's chainHash.
|
|
70
|
+
*
|
|
71
|
+
* An Execution with no chain fields at all is treated as
|
|
72
|
+
* unprotected legacy data -- neither verified nor required to
|
|
73
|
+
* link -- so historical rows and pre-feature test fixtures don't
|
|
74
|
+
* fail verification.
|
|
75
|
+
*/
|
|
76
|
+
verifyChain(executions: readonly Execution[]): Promise<ChainVerificationResult>;
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=ExecutionChainCrypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExecutionChainCrypto.d.ts","sourceRoot":"","sources":["../src/ExecutionChainCrypto.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAU5D;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,cAAc,EAAE,SAAS,CAAC;CACpC;AAED;;GAEG;AACH,MAAM,WAAW,uBAA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