@peac/audit 0.16.1 → 0.16.2
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/dist/index.cjs +240 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +236 -2
- package/dist/index.mjs.map +1 -1
- package/dist/merkle.d.ts +91 -0
- package/dist/merkle.d.ts.map +1 -0
- package/package.json +4 -4
package/dist/merkle.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @peac/audit - Merkle commitment helpers for workflow receipt sets.
|
|
3
|
+
*
|
|
4
|
+
* Executes the deferred WORKFLOW-CORRELATION section 7 Merkle commitment as
|
|
5
|
+
* deterministic, offline helpers. This is a CT-style Merkle Tree Hash following
|
|
6
|
+
* the RFC 9162 section 2.1.1 formulas (RFC 9162 obsoletes RFC 6962), adapted as
|
|
7
|
+
* a sorted-set commitment over PEAC `receipt_ref` digests. It is NOT a
|
|
8
|
+
* Certificate Transparency append-only log and PEAC does not operate a log or
|
|
9
|
+
* anchor these roots anywhere.
|
|
10
|
+
*
|
|
11
|
+
* Proves inclusion in the committed set; it does NOT prove chronology,
|
|
12
|
+
* completeness, payment finality, payment validity, privacy, or legal validity.
|
|
13
|
+
* Callers must still verify each PEAC record independently.
|
|
14
|
+
*
|
|
15
|
+
* Inputs are `receipt_ref` strings (`sha256:<hex64>`, DD-129) only. Callers that
|
|
16
|
+
* start from compact JWS bytes use `@peac/schema` `computeReceiptRef(jws)` first;
|
|
17
|
+
* this module does not re-implement digest computation.
|
|
18
|
+
*/
|
|
19
|
+
import type { ReceiptRef } from '@peac/kernel';
|
|
20
|
+
/** Algorithm identifier for this sorted-set commitment construction. */
|
|
21
|
+
export declare const MERKLE_TREE_ALG: "peac.merkle.ct-sorted-set-sha256-v1";
|
|
22
|
+
/** Hash algorithm used for leaves and internal nodes. */
|
|
23
|
+
export declare const MERKLE_HASH_ALG: "sha256";
|
|
24
|
+
/**
|
|
25
|
+
* A `sha256:<hex64>` digest reference. Shares its grammar with `ReceiptRef` but
|
|
26
|
+
* carries different semantics (a Merkle hash, not a PEAC record reference).
|
|
27
|
+
*/
|
|
28
|
+
export type Sha256DigestRef = `sha256:${string}`;
|
|
29
|
+
/** A Merkle root digest (NOT a receipt reference). */
|
|
30
|
+
export type ReceiptMerkleRoot = Sha256DigestRef;
|
|
31
|
+
/** A Merkle inclusion-proof sibling hash (NOT a receipt reference). */
|
|
32
|
+
export type MerkleNodeHash = Sha256DigestRef;
|
|
33
|
+
/** Self-describing commitment over a sorted set of receipt references. */
|
|
34
|
+
export interface ReceiptMerkleCommitment {
|
|
35
|
+
readonly tree_alg: typeof MERKLE_TREE_ALG;
|
|
36
|
+
readonly hash_alg: typeof MERKLE_HASH_ALG;
|
|
37
|
+
readonly root: ReceiptMerkleRoot;
|
|
38
|
+
readonly tree_size: number;
|
|
39
|
+
}
|
|
40
|
+
/** Inclusion proof for a single receipt reference against a committed root. */
|
|
41
|
+
export interface ReceiptMerkleInclusionProof {
|
|
42
|
+
readonly tree_alg: typeof MERKLE_TREE_ALG;
|
|
43
|
+
readonly hash_alg: typeof MERKLE_HASH_ALG;
|
|
44
|
+
/** Index of the target within the SORTED leaf order. */
|
|
45
|
+
readonly leaf_index: number;
|
|
46
|
+
readonly tree_size: number;
|
|
47
|
+
/** Sibling path, leaf -> root order, each `sha256:<hex64>`. */
|
|
48
|
+
readonly hashes: readonly MerkleNodeHash[];
|
|
49
|
+
}
|
|
50
|
+
export type MerkleInputErrorCode = 'audit.merkle.empty_input' | 'audit.merkle.invalid_receipt_ref' | 'audit.merkle.duplicate_receipt_ref' | 'audit.merkle.target_not_found' | 'audit.merkle.invalid_commitment' | 'audit.merkle.invalid_merkle_root' | 'audit.merkle.invalid_proof' | 'audit.merkle.invalid_proof_hash' | 'audit.merkle.unsupported_tree_alg' | 'audit.merkle.unsupported_hash_alg';
|
|
51
|
+
/**
|
|
52
|
+
* Thrown ONLY on malformed input (bad grammar, empty/duplicate input,
|
|
53
|
+
* unsupported algorithm, out-of-range index, target not found). A well-formed
|
|
54
|
+
* but cryptographically wrong proof returns `false` from
|
|
55
|
+
* {@link verifyReceiptMerkleInclusion} and does not throw. These are
|
|
56
|
+
* package-local errors; they are not kernel protocol errors.
|
|
57
|
+
*/
|
|
58
|
+
export declare class MerkleInputError extends Error {
|
|
59
|
+
readonly code: MerkleInputErrorCode;
|
|
60
|
+
constructor(code: MerkleInputErrorCode, message: string);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Build a Merkle commitment over a sorted set of receipt references.
|
|
64
|
+
*
|
|
65
|
+
* Rejects empty input and duplicate refs. The returned `root`/`tree_size` map
|
|
66
|
+
* directly to a workflow summary's `receipt_merkle_root`/`receipt_count`.
|
|
67
|
+
* @throws {MerkleInputError} on empty input, malformed ref, or duplicate ref.
|
|
68
|
+
*/
|
|
69
|
+
export declare function buildReceiptMerkleCommitment(refs: readonly ReceiptRef[]): ReceiptMerkleCommitment;
|
|
70
|
+
/**
|
|
71
|
+
* Generate an offline inclusion proof for `targetRef` against the committed set.
|
|
72
|
+
* `leaf_index` in the returned proof is the index within the SORTED leaf order.
|
|
73
|
+
* @throws {MerkleInputError} on empty input, malformed ref, duplicate ref, or
|
|
74
|
+
* when `targetRef` is not present in `refs`.
|
|
75
|
+
*/
|
|
76
|
+
export declare function generateReceiptMerkleInclusionProof(refs: readonly ReceiptRef[], targetRef: ReceiptRef): ReceiptMerkleInclusionProof;
|
|
77
|
+
/**
|
|
78
|
+
* Verify an inclusion proof offline against a full commitment.
|
|
79
|
+
*
|
|
80
|
+
* Verifying against the {@link ReceiptMerkleCommitment} (not a naked root) binds
|
|
81
|
+
* the proof to the commitment's `tree_size` as well as its `root`, so a proof
|
|
82
|
+
* whose `tree_size` disagrees with the commitment is rejected up front.
|
|
83
|
+
*
|
|
84
|
+
* Returns `false` for a well-formed but cryptographically wrong proof (wrong
|
|
85
|
+
* root, wrong sibling, wrong target, mismatched tree_size, truncated/extra path).
|
|
86
|
+
* @throws {MerkleInputError} on malformed input: a structurally invalid
|
|
87
|
+
* commitment/proof, bad root/target/sibling grammar, unsupported
|
|
88
|
+
* `tree_alg`/`hash_alg`, or non-integer/out-of-range `leaf_index`/`tree_size`.
|
|
89
|
+
*/
|
|
90
|
+
export declare function verifyReceiptMerkleInclusion(commitment: ReceiptMerkleCommitment, targetRef: ReceiptRef, proof: ReceiptMerkleInclusionProof): boolean;
|
|
91
|
+
//# sourceMappingURL=merkle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merkle.d.ts","sourceRoot":"","sources":["../src/merkle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C,wEAAwE;AACxE,eAAO,MAAM,eAAe,EAAG,qCAA8C,CAAC;AAC9E,yDAAyD;AACzD,eAAO,MAAM,eAAe,EAAG,QAAiB,CAAC;AAEjD;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,UAAU,MAAM,EAAE,CAAC;AACjD,sDAAsD;AACtD,MAAM,MAAM,iBAAiB,GAAG,eAAe,CAAC;AAChD,uEAAuE;AACvE,MAAM,MAAM,cAAc,GAAG,eAAe,CAAC;AAE7C,0EAA0E;AAC1E,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,QAAQ,EAAE,OAAO,eAAe,CAAC;IAC1C,QAAQ,CAAC,QAAQ,EAAE,OAAO,eAAe,CAAC;IAC1C,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAC;IACjC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,+EAA+E;AAC/E,MAAM,WAAW,2BAA2B;IAC1C,QAAQ,CAAC,QAAQ,EAAE,OAAO,eAAe,CAAC;IAC1C,QAAQ,CAAC,QAAQ,EAAE,OAAO,eAAe,CAAC;IAC1C,wDAAwD;IACxD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,+DAA+D;IAC/D,QAAQ,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,CAAC;CAC5C;AAED,MAAM,MAAM,oBAAoB,GAC5B,0BAA0B,GAC1B,kCAAkC,GAClC,oCAAoC,GACpC,+BAA+B,GAC/B,iCAAiC,GACjC,kCAAkC,GAClC,4BAA4B,GAC5B,iCAAiC,GACjC,mCAAmC,GACnC,mCAAmC,CAAC;AAExC;;;;;;GAMG;AACH,qBAAa,gBAAiB,SAAQ,KAAK;IACzC,QAAQ,CAAC,IAAI,EAAE,oBAAoB,CAAC;gBACxB,IAAI,EAAE,oBAAoB,EAAE,OAAO,EAAE,MAAM;CAKxD;AA8LD;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,SAAS,UAAU,EAAE,GAAG,uBAAuB,CAQjG;AAED;;;;;GAKG;AACH,wBAAgB,mCAAmC,CACjD,IAAI,EAAE,SAAS,UAAU,EAAE,EAC3B,SAAS,EAAE,UAAU,GACpB,2BAA2B,CAiB7B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,uBAAuB,EACnC,SAAS,EAAE,UAAU,EACrB,KAAK,EAAE,2BAA2B,GACjC,OAAO,CAqET"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peac/audit",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.2",
|
|
4
4
|
"description": "Audit logging and case bundle generation for PEAC protocol disputes",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"yazl": "^3.3.1",
|
|
32
32
|
"yauzl": "^2.10.0",
|
|
33
|
-
"@peac/
|
|
34
|
-
"@peac/
|
|
35
|
-
"@peac/
|
|
33
|
+
"@peac/kernel": "0.16.2",
|
|
34
|
+
"@peac/crypto": "0.16.2",
|
|
35
|
+
"@peac/schema": "0.16.2"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/node": "^22.19.11",
|