@helmetfire-labs/cartridge-common 0.6.0 → 0.7.0
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/README.md +10 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/zk-proof.d.ts +91 -0
- package/dist/zk-proof.js +151 -0
- package/dist/zk-proof.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -68,6 +68,15 @@ npm install @helmetfire-labs/cartridge-common
|
|
|
68
68
|
|--------|--------|-------------|
|
|
69
69
|
| `createLocalAnchorService`, `AnchorReceipt`, `AnchorService` | `anchor` | File-backed anchor store — same interface that will back a Base L2 contract |
|
|
70
70
|
|
|
71
|
+
### ZK Proofs (Patent N Phase 6)
|
|
72
|
+
|
|
73
|
+
| Export | Module | Description |
|
|
74
|
+
|--------|--------|-------------|
|
|
75
|
+
| `CommitmentProver` | `zk-proof` | Proves reducer replay correctness via HMAC-SHA256 commitment. Same interface as real ZK — swap for SP1/RISC Zero later. |
|
|
76
|
+
| `CommitmentVerifier` | `zk-proof` | Verifies commitment proofs without action log or reducer |
|
|
77
|
+
| `ZkProver`, `ZkVerifier` | `zk-proof` | Pluggable prover/verifier interfaces |
|
|
78
|
+
| `ZkProof`, `ZkPublicInputs`, `ZkVerifyResult` | `zk-proof` | Proof types — public inputs: chain head, entry count, reducer hash, final state hash |
|
|
79
|
+
|
|
71
80
|
### Action Schemas
|
|
72
81
|
|
|
73
82
|
| Export | Module | Description |
|
|
@@ -273,6 +282,6 @@ const store = state.getStore(transport.sessionId, "view_page");
|
|
|
273
282
|
```bash
|
|
274
283
|
npm run build # compile TypeScript
|
|
275
284
|
npm run typecheck # type-check only
|
|
276
|
-
npm test # run tests (
|
|
285
|
+
npm test # run tests (302 tests)
|
|
277
286
|
```
|
|
278
287
|
|
package/dist/index.d.ts
CHANGED
|
@@ -40,6 +40,8 @@ export { operatorAnchorReducer, operatorAnchorActionSchema } from './operator-re
|
|
|
40
40
|
export type { OperatorAnchorState, OperatorAnchorAction, AnchorChildEntry, } from './operator-reducer.js';
|
|
41
41
|
export { computeMerkleRoot, generateProof, verifyProof } from './merkle.js';
|
|
42
42
|
export type { MerkleProof } from './merkle.js';
|
|
43
|
+
export { CommitmentProver, CommitmentVerifier } from './zk-proof.js';
|
|
44
|
+
export type { ZkProof, ZkPublicInputs, ZkVerifyResult, ZkProver, ZkVerifier } from './zk-proof.js';
|
|
43
45
|
export { defineActionSchema, action, writeActionSchema, getSchemaHash, validateAction, } from './action-schema.js';
|
|
44
46
|
export type { ActionSchema, ActionVariant, FieldType, } from './action-schema.js';
|
|
45
47
|
export { hashPolicy, writePolicy, readPolicy, verifyPolicy, isNetworkAllowed, isFilesystemAllowed, isSpawnAllowed, DEFAULT_POLICY, INSTALL_POLICY, } from './policy.js';
|
package/dist/index.js
CHANGED
|
@@ -29,6 +29,7 @@ export { containerReducer, containerActionSchema } from './container-reducer.js'
|
|
|
29
29
|
export { agentReducer, agentActionSchema } from './agent-reducer.js';
|
|
30
30
|
export { operatorAnchorReducer, operatorAnchorActionSchema } from './operator-reducer.js';
|
|
31
31
|
export { computeMerkleRoot, generateProof, verifyProof } from './merkle.js';
|
|
32
|
+
export { CommitmentProver, CommitmentVerifier } from './zk-proof.js';
|
|
32
33
|
export { defineActionSchema, action, writeActionSchema, getSchemaHash, validateAction, } from './action-schema.js';
|
|
33
34
|
// ── Process Policy (Patent M §3.11) ─────────────────────────────────────────
|
|
34
35
|
export { hashPolicy, writePolicy, readPolicy, verifyPolicy, isNetworkAllowed, isFilesystemAllowed, isSpawnAllowed, DEFAULT_POLICY, INSTALL_POLICY, } from './policy.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,QAAQ,EAAE,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B,EAAE,MAAM,oBAAoB,CAAC;AAOrE,OAAO,EAAE,qBAAqB,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAO1F,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG5E,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAGrE,OAAO,EACL,kBAAkB,EAClB,MAAM,EACN,iBAAiB,EACjB,aAAa,EACb,cAAc,GACf,MAAM,oBAAoB,CAAC;AAO5B,+EAA+E;AAE/E,OAAO,EACL,UAAU,EACV,WAAW,EACX,UAAU,EACV,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,cAAc,EACd,cAAc,EACd,cAAc,GACf,MAAM,aAAa,CAAC;AAUrB,+EAA+E;AAE/E,OAAO,EACL,aAAa,EACb,OAAO,EACP,OAAO,GACR,MAAM,kBAAkB,CAAC;AAO1B,+EAA+E;AAE/E,OAAO,EACL,iBAAiB,EACjB,UAAU,EACV,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,EACV,sBAAsB,EACtB,aAAa,EACb,iBAAiB,EACjB,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EAClB,kBAAkB,EAClB,YAAY,EACZ,wBAAwB,EACxB,oBAAoB,EACpB,WAAW,GACZ,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zero-knowledge proof interface for reducer replay verification.
|
|
3
|
+
*
|
|
4
|
+
* Proves: "There exists an action log of length N governed by reducer R
|
|
5
|
+
* such that the hash chain is intact and the chain head is H."
|
|
6
|
+
*
|
|
7
|
+
* Without revealing: the action log entries, the state transitions,
|
|
8
|
+
* or any intermediate hashes.
|
|
9
|
+
*
|
|
10
|
+
* This module defines the proof format and provides two implementations:
|
|
11
|
+
*
|
|
12
|
+
* 1. CommitmentProver (built-in) — a cryptographic commitment scheme
|
|
13
|
+
* using HMAC-SHA256. Not a true zero-knowledge proof (the prover
|
|
14
|
+
* must be trusted not to forge), but structurally identical to the
|
|
15
|
+
* real thing. Suitable for development, testing, and single-operator
|
|
16
|
+
* deployments where the prover and verifier are the same entity.
|
|
17
|
+
*
|
|
18
|
+
* 2. ZkVmProver (future) — a real ZK proof via SP1 or RISC Zero.
|
|
19
|
+
* The reducer is compiled to a zkVM target and the proof is
|
|
20
|
+
* cryptographically sound. Drop-in replacement for CommitmentProver.
|
|
21
|
+
*
|
|
22
|
+
* Patent N: Hierarchical Anchor Chains for Verifiable Agent Accountability
|
|
23
|
+
*/
|
|
24
|
+
import type { DurableReducer } from "./durable-reducer.js";
|
|
25
|
+
export interface ZkPublicInputs {
|
|
26
|
+
/** Hash of the last action.log line */
|
|
27
|
+
chainHead: string;
|
|
28
|
+
/** Number of entries in the action log */
|
|
29
|
+
entryCount: number;
|
|
30
|
+
/** SHA-256 of the reducer's action schema (binds proof to a specific reducer) */
|
|
31
|
+
reducerHash: string;
|
|
32
|
+
/** SHA-256 of the final state after replay */
|
|
33
|
+
finalStateHash: string;
|
|
34
|
+
}
|
|
35
|
+
export interface ZkProof {
|
|
36
|
+
/** Proof system identifier */
|
|
37
|
+
system: "commitment-v1" | "sp1" | "risc-zero";
|
|
38
|
+
/** The public inputs (visible to verifier) */
|
|
39
|
+
publicInputs: ZkPublicInputs;
|
|
40
|
+
/** The proof bytes (opaque to everyone except the verifier) */
|
|
41
|
+
proof: string;
|
|
42
|
+
/** Timestamp of proof generation */
|
|
43
|
+
generatedAt: number;
|
|
44
|
+
}
|
|
45
|
+
export interface ZkVerifyResult {
|
|
46
|
+
ok: boolean;
|
|
47
|
+
system: string;
|
|
48
|
+
publicInputs: ZkPublicInputs;
|
|
49
|
+
failure?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface ZkProver {
|
|
52
|
+
/** Generate a proof that a reducer replay is correct. */
|
|
53
|
+
prove<S, A extends {
|
|
54
|
+
type: string;
|
|
55
|
+
}>(actionLog: string[], reducer: DurableReducer<S, A>, reducerHash: string): ZkProof;
|
|
56
|
+
}
|
|
57
|
+
export interface ZkVerifier {
|
|
58
|
+
/** Verify a proof. Does NOT need the action log or reducer. */
|
|
59
|
+
verify(proof: ZkProof): ZkVerifyResult;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* CommitmentProver — generates commitment-based proofs.
|
|
63
|
+
*
|
|
64
|
+
* Replays the action log through the reducer, verifies chain integrity,
|
|
65
|
+
* and produces a commitment (HMAC) over the result. The commitment key
|
|
66
|
+
* is derived from the reducer hash and chain head, so it can be verified
|
|
67
|
+
* without the action log.
|
|
68
|
+
*/
|
|
69
|
+
export declare class CommitmentProver implements ZkProver {
|
|
70
|
+
private secret;
|
|
71
|
+
/**
|
|
72
|
+
* @param secret A secret string known to both prover and verifier.
|
|
73
|
+
* In production, this would be replaced by a ZK proof
|
|
74
|
+
* that requires no shared secret.
|
|
75
|
+
*/
|
|
76
|
+
constructor(secret: string);
|
|
77
|
+
prove<S, A extends {
|
|
78
|
+
type: string;
|
|
79
|
+
}>(actionLog: string[], reducer: DurableReducer<S, A>, reducerHash: string): ZkProof;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* CommitmentVerifier — verifies commitment-based proofs.
|
|
83
|
+
*
|
|
84
|
+
* Checks that the HMAC commitment matches the public inputs.
|
|
85
|
+
* Does NOT need the action log, reducer, or any private data.
|
|
86
|
+
*/
|
|
87
|
+
export declare class CommitmentVerifier implements ZkVerifier {
|
|
88
|
+
private secret;
|
|
89
|
+
constructor(secret: string);
|
|
90
|
+
verify(proof: ZkProof): ZkVerifyResult;
|
|
91
|
+
}
|
package/dist/zk-proof.js
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zero-knowledge proof interface for reducer replay verification.
|
|
3
|
+
*
|
|
4
|
+
* Proves: "There exists an action log of length N governed by reducer R
|
|
5
|
+
* such that the hash chain is intact and the chain head is H."
|
|
6
|
+
*
|
|
7
|
+
* Without revealing: the action log entries, the state transitions,
|
|
8
|
+
* or any intermediate hashes.
|
|
9
|
+
*
|
|
10
|
+
* This module defines the proof format and provides two implementations:
|
|
11
|
+
*
|
|
12
|
+
* 1. CommitmentProver (built-in) — a cryptographic commitment scheme
|
|
13
|
+
* using HMAC-SHA256. Not a true zero-knowledge proof (the prover
|
|
14
|
+
* must be trusted not to forge), but structurally identical to the
|
|
15
|
+
* real thing. Suitable for development, testing, and single-operator
|
|
16
|
+
* deployments where the prover and verifier are the same entity.
|
|
17
|
+
*
|
|
18
|
+
* 2. ZkVmProver (future) — a real ZK proof via SP1 or RISC Zero.
|
|
19
|
+
* The reducer is compiled to a zkVM target and the proof is
|
|
20
|
+
* cryptographically sound. Drop-in replacement for CommitmentProver.
|
|
21
|
+
*
|
|
22
|
+
* Patent N: Hierarchical Anchor Chains for Verifiable Agent Accountability
|
|
23
|
+
*/
|
|
24
|
+
import { strict as assert } from "node:assert";
|
|
25
|
+
import { createHmac } from "node:crypto";
|
|
26
|
+
import { sha256, hashLine, hashState } from "./durable-reducer.js";
|
|
27
|
+
// ── Commitment-based proof (built-in) ───────────────────────────────────────
|
|
28
|
+
//
|
|
29
|
+
// This is NOT a real zero-knowledge proof. It's a cryptographic commitment
|
|
30
|
+
// scheme that provides the same interface. The prover commits to the replay
|
|
31
|
+
// result using an HMAC with a derived key. The verifier checks the HMAC.
|
|
32
|
+
//
|
|
33
|
+
// The "zero-knowledge" property is simulated: the verifier doesn't see the
|
|
34
|
+
// action log, but the proof could be forged by anyone who knows the HMAC key.
|
|
35
|
+
// In single-operator deployments (prover = verifier), this is fine.
|
|
36
|
+
//
|
|
37
|
+
// For multi-party verification, replace with SP1 or RISC Zero.
|
|
38
|
+
const COMMITMENT_VERSION = "commitment-v1";
|
|
39
|
+
/**
|
|
40
|
+
* Derive an HMAC key from the reducer hash and chain head.
|
|
41
|
+
* This binds the commitment to a specific reducer + chain state.
|
|
42
|
+
*/
|
|
43
|
+
function deriveCommitmentKey(reducerHash, chainHead) {
|
|
44
|
+
return sha256(reducerHash + ":" + chainHead);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Compute an HMAC-SHA256 commitment over the public inputs.
|
|
48
|
+
*/
|
|
49
|
+
function computeCommitment(inputs, key) {
|
|
50
|
+
const payload = JSON.stringify({
|
|
51
|
+
chainHead: inputs.chainHead,
|
|
52
|
+
entryCount: inputs.entryCount,
|
|
53
|
+
reducerHash: inputs.reducerHash,
|
|
54
|
+
finalStateHash: inputs.finalStateHash,
|
|
55
|
+
});
|
|
56
|
+
return createHmac("sha256", key).update(payload).digest("hex");
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* CommitmentProver — generates commitment-based proofs.
|
|
60
|
+
*
|
|
61
|
+
* Replays the action log through the reducer, verifies chain integrity,
|
|
62
|
+
* and produces a commitment (HMAC) over the result. The commitment key
|
|
63
|
+
* is derived from the reducer hash and chain head, so it can be verified
|
|
64
|
+
* without the action log.
|
|
65
|
+
*/
|
|
66
|
+
export class CommitmentProver {
|
|
67
|
+
secret;
|
|
68
|
+
/**
|
|
69
|
+
* @param secret A secret string known to both prover and verifier.
|
|
70
|
+
* In production, this would be replaced by a ZK proof
|
|
71
|
+
* that requires no shared secret.
|
|
72
|
+
*/
|
|
73
|
+
constructor(secret) {
|
|
74
|
+
assert(secret, "commitment prover requires a secret");
|
|
75
|
+
this.secret = secret;
|
|
76
|
+
}
|
|
77
|
+
prove(actionLog, reducer, reducerHash) {
|
|
78
|
+
assert(actionLog.length > 0, "cannot prove an empty action log");
|
|
79
|
+
// Replay the reducer and verify chain integrity
|
|
80
|
+
let state = reducer.init();
|
|
81
|
+
let prevHash = "genesis";
|
|
82
|
+
for (let i = 0; i < actionLog.length; i++) {
|
|
83
|
+
const line = actionLog[i];
|
|
84
|
+
const entry = JSON.parse(line);
|
|
85
|
+
// Verify chain link
|
|
86
|
+
assert(entry.prevHash === prevHash, `chain broken at entry ${i}: expected ${prevHash}, got ${entry.prevHash}`);
|
|
87
|
+
// Replay through reducer
|
|
88
|
+
state = reducer.reduce(state, entry.action);
|
|
89
|
+
// Verify state hash
|
|
90
|
+
const expectedStateHash = hashState(reducer.serialize(state));
|
|
91
|
+
assert(entry.stateHash === expectedStateHash, `state divergence at entry ${i}: expected ${expectedStateHash}, got ${entry.stateHash}`);
|
|
92
|
+
prevHash = hashLine(line);
|
|
93
|
+
}
|
|
94
|
+
const chainHead = prevHash;
|
|
95
|
+
const finalStateHash = hashState(reducer.serialize(state));
|
|
96
|
+
const publicInputs = {
|
|
97
|
+
chainHead,
|
|
98
|
+
entryCount: actionLog.length,
|
|
99
|
+
reducerHash,
|
|
100
|
+
finalStateHash,
|
|
101
|
+
};
|
|
102
|
+
// Generate commitment
|
|
103
|
+
const key = deriveCommitmentKey(reducerHash, this.secret);
|
|
104
|
+
const commitment = computeCommitment(publicInputs, key);
|
|
105
|
+
return {
|
|
106
|
+
system: COMMITMENT_VERSION,
|
|
107
|
+
publicInputs,
|
|
108
|
+
proof: commitment,
|
|
109
|
+
generatedAt: Date.now(),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* CommitmentVerifier — verifies commitment-based proofs.
|
|
115
|
+
*
|
|
116
|
+
* Checks that the HMAC commitment matches the public inputs.
|
|
117
|
+
* Does NOT need the action log, reducer, or any private data.
|
|
118
|
+
*/
|
|
119
|
+
export class CommitmentVerifier {
|
|
120
|
+
secret;
|
|
121
|
+
constructor(secret) {
|
|
122
|
+
assert(secret, "commitment verifier requires a secret");
|
|
123
|
+
this.secret = secret;
|
|
124
|
+
}
|
|
125
|
+
verify(proof) {
|
|
126
|
+
if (proof.system !== COMMITMENT_VERSION) {
|
|
127
|
+
return {
|
|
128
|
+
ok: false,
|
|
129
|
+
system: proof.system,
|
|
130
|
+
publicInputs: proof.publicInputs,
|
|
131
|
+
failure: `unsupported proof system: ${proof.system} (expected ${COMMITMENT_VERSION})`,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
const key = deriveCommitmentKey(proof.publicInputs.reducerHash, this.secret);
|
|
135
|
+
const expected = computeCommitment(proof.publicInputs, key);
|
|
136
|
+
if (proof.proof !== expected) {
|
|
137
|
+
return {
|
|
138
|
+
ok: false,
|
|
139
|
+
system: proof.system,
|
|
140
|
+
publicInputs: proof.publicInputs,
|
|
141
|
+
failure: "commitment verification failed — proof does not match public inputs",
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
ok: true,
|
|
146
|
+
system: proof.system,
|
|
147
|
+
publicInputs: proof.publicInputs,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=zk-proof.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zk-proof.js","sourceRoot":"","sources":["../src/zk-proof.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,MAAM,IAAI,MAAM,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAkDnE,+EAA+E;AAC/E,EAAE;AACF,2EAA2E;AAC3E,4EAA4E;AAC5E,yEAAyE;AACzE,EAAE;AACF,2EAA2E;AAC3E,8EAA8E;AAC9E,oEAAoE;AACpE,EAAE;AACF,+DAA+D;AAE/D,MAAM,kBAAkB,GAAG,eAAe,CAAC;AAE3C;;;GAGG;AACH,SAAS,mBAAmB,CAAC,WAAmB,EAAE,SAAiB;IACjE,OAAO,MAAM,CAAC,WAAW,GAAG,GAAG,GAAG,SAAS,CAAC,CAAC;AAC/C,CAAC;AAED;;GAEG;AACH,SAAS,iBAAiB,CAAC,MAAsB,EAAE,GAAW;IAC5D,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,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