@fluxpointstudios/orynq-sdk-midnight-prover 0.1.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/LICENSE +21 -0
- package/dist/index.d.ts +78 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +89 -0
- package/dist/index.js.map +1 -0
- package/dist/linking/cardano-anchor-link.d.ts +250 -0
- package/dist/linking/cardano-anchor-link.d.ts.map +1 -0
- package/dist/linking/cardano-anchor-link.js +447 -0
- package/dist/linking/cardano-anchor-link.js.map +1 -0
- package/dist/linking/index.d.ts +33 -0
- package/dist/linking/index.d.ts.map +1 -0
- package/dist/linking/index.js +31 -0
- package/dist/linking/index.js.map +1 -0
- package/dist/linking/proof-publication.d.ts +217 -0
- package/dist/linking/proof-publication.d.ts.map +1 -0
- package/dist/linking/proof-publication.js +385 -0
- package/dist/linking/proof-publication.js.map +1 -0
- package/dist/midnight/index.d.ts +30 -0
- package/dist/midnight/index.d.ts.map +1 -0
- package/dist/midnight/index.js +27 -0
- package/dist/midnight/index.js.map +1 -0
- package/dist/midnight/proof-server-client.d.ts +236 -0
- package/dist/midnight/proof-server-client.d.ts.map +1 -0
- package/dist/midnight/proof-server-client.js +422 -0
- package/dist/midnight/proof-server-client.js.map +1 -0
- package/dist/midnight/public-inputs.d.ts +134 -0
- package/dist/midnight/public-inputs.d.ts.map +1 -0
- package/dist/midnight/public-inputs.js +338 -0
- package/dist/midnight/public-inputs.js.map +1 -0
- package/dist/midnight/witness-builder.d.ts +119 -0
- package/dist/midnight/witness-builder.d.ts.map +1 -0
- package/dist/midnight/witness-builder.js +238 -0
- package/dist/midnight/witness-builder.js.map +1 -0
- package/dist/proofs/hash-chain-proof.d.ts +171 -0
- package/dist/proofs/hash-chain-proof.d.ts.map +1 -0
- package/dist/proofs/hash-chain-proof.js +437 -0
- package/dist/proofs/hash-chain-proof.js.map +1 -0
- package/dist/proofs/index.d.ts +35 -0
- package/dist/proofs/index.d.ts.map +1 -0
- package/dist/proofs/index.js +34 -0
- package/dist/proofs/index.js.map +1 -0
- package/dist/proofs/policy-compliance-proof.d.ts +165 -0
- package/dist/proofs/policy-compliance-proof.d.ts.map +1 -0
- package/dist/proofs/policy-compliance-proof.js +514 -0
- package/dist/proofs/policy-compliance-proof.js.map +1 -0
- package/dist/proofs/selective-disclosure.d.ts +213 -0
- package/dist/proofs/selective-disclosure.d.ts.map +1 -0
- package/dist/proofs/selective-disclosure.js +629 -0
- package/dist/proofs/selective-disclosure.js.map +1 -0
- package/dist/prover-interface.d.ts +288 -0
- package/dist/prover-interface.d.ts.map +1 -0
- package/dist/prover-interface.js +114 -0
- package/dist/prover-interface.js.map +1 -0
- package/dist/prover.d.ts +163 -0
- package/dist/prover.d.ts.map +1 -0
- package/dist/prover.js +417 -0
- package/dist/prover.js.map +1 -0
- package/dist/types.d.ts +410 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +128 -0
- package/dist/types.js.map +1 -0
- package/package.json +59 -0
- package/src/__tests__/hash-chain-proof.test.ts +709 -0
- package/src/__tests__/midnight-prover.test.ts +716 -0
- package/src/__tests__/policy-compliance.test.ts +567 -0
- package/src/__tests__/proof-publication.test.ts +644 -0
- package/src/__tests__/selective-disclosure.test.ts +921 -0
- package/src/index.ts +260 -0
- package/src/linking/cardano-anchor-link.ts +682 -0
- package/src/linking/index.ts +58 -0
- package/src/linking/proof-publication.ts +557 -0
- package/src/midnight/index.ts +73 -0
- package/src/midnight/proof-server-client.ts +595 -0
- package/src/midnight/public-inputs.ts +590 -0
- package/src/midnight/witness-builder.ts +341 -0
- package/src/proofs/hash-chain-proof.ts +610 -0
- package/src/proofs/index.ts +77 -0
- package/src/proofs/policy-compliance-proof.ts +717 -0
- package/src/proofs/selective-disclosure.ts +839 -0
- package/src/prover-interface.ts +410 -0
- package/src/prover.ts +537 -0
- package/src/types.ts +551 -0
|
@@ -0,0 +1,437 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Hash-chain validity proof generator.
|
|
3
|
+
*
|
|
4
|
+
* Location: packages/midnight-prover/src/proofs/hash-chain-proof.ts
|
|
5
|
+
*
|
|
6
|
+
* Summary:
|
|
7
|
+
* This module implements the HashChainProver class which generates and verifies
|
|
8
|
+
* ZK proofs that a sequence of trace events produces an expected rolling hash.
|
|
9
|
+
* The proof is bound to a Cardano anchor transaction for cross-chain verification.
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* The HashChainProver is the primary prover for PoI trace verification:
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const prover = new HashChainProver();
|
|
15
|
+
* const proof = await prover.generateProof({
|
|
16
|
+
* events: traceBundle.privateRun.events,
|
|
17
|
+
* genesisHash: await getGenesisHash(),
|
|
18
|
+
* expectedRootHash: traceBundle.rootHash,
|
|
19
|
+
* cardanoAnchorTxHash: anchorTxHash,
|
|
20
|
+
* });
|
|
21
|
+
* const isValid = await prover.verifyProof(proof);
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* Related files:
|
|
25
|
+
* - witness-builder.ts: Builds witnesses for this prover
|
|
26
|
+
* - public-inputs.ts: Builds public inputs for this prover
|
|
27
|
+
* - prover-interface.ts: Abstract interface this implements
|
|
28
|
+
* - types.ts: Type definitions for inputs and outputs
|
|
29
|
+
*/
|
|
30
|
+
import { randomUUID } from "node:crypto";
|
|
31
|
+
import { MidnightProverError, MidnightProverException, } from "../types.js";
|
|
32
|
+
import { buildHashChainWitness, serializeWitness, computeWitnessSize, validateWitness, } from "../midnight/witness-builder.js";
|
|
33
|
+
import { buildPublicInputs, serializePublicInputs, } from "../midnight/public-inputs.js";
|
|
34
|
+
import { sha256StringHex } from "@fluxpointstudios/orynq-sdk-core/utils";
|
|
35
|
+
// =============================================================================
|
|
36
|
+
// CONSTANTS
|
|
37
|
+
// =============================================================================
|
|
38
|
+
/**
|
|
39
|
+
* Maximum number of events allowed in a single hash-chain proof.
|
|
40
|
+
* This limit is imposed by circuit constraints.
|
|
41
|
+
*/
|
|
42
|
+
const MAX_EVENTS_PER_PROOF = 10_000;
|
|
43
|
+
/**
|
|
44
|
+
* Maximum witness size in bytes (50 MB).
|
|
45
|
+
*/
|
|
46
|
+
const MAX_WITNESS_SIZE_BYTES = 50 * 1024 * 1024;
|
|
47
|
+
/**
|
|
48
|
+
* Hash domain prefix for rolling hash (matching process-trace).
|
|
49
|
+
*/
|
|
50
|
+
const HASH_DOMAIN_ROLL = "poi-trace:roll:v1|";
|
|
51
|
+
/**
|
|
52
|
+
* Genesis seed for initial rolling hash state.
|
|
53
|
+
*/
|
|
54
|
+
const GENESIS_SEED = "genesis";
|
|
55
|
+
/**
|
|
56
|
+
* HashChainProver generates and verifies ZK proofs for trace hash chains.
|
|
57
|
+
*
|
|
58
|
+
* This prover demonstrates that:
|
|
59
|
+
* 1. A sequence of events exists (private witness)
|
|
60
|
+
* 2. Processing them produces a specific rolling hash (public input)
|
|
61
|
+
* 3. This hash matches what was anchored on Cardano (cross-chain binding)
|
|
62
|
+
*
|
|
63
|
+
* Current implementation is a mock that simulates proof generation.
|
|
64
|
+
* Real Midnight integration will be added when the Compact runtime is available.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```typescript
|
|
68
|
+
* const prover = new HashChainProver({ debug: true });
|
|
69
|
+
*
|
|
70
|
+
* const proof = await prover.generateProof({
|
|
71
|
+
* events: bundle.privateRun.events,
|
|
72
|
+
* genesisHash: "abc123...",
|
|
73
|
+
* expectedRootHash: bundle.rootHash,
|
|
74
|
+
* cardanoAnchorTxHash: "def456...",
|
|
75
|
+
* });
|
|
76
|
+
*
|
|
77
|
+
* console.log("Proof generated:", proof.proofId);
|
|
78
|
+
* console.log("Proving time:", proof.provingTimeMs, "ms");
|
|
79
|
+
*
|
|
80
|
+
* const isValid = await prover.verifyProof(proof);
|
|
81
|
+
* console.log("Proof valid:", isValid);
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export class HashChainProver {
|
|
85
|
+
options;
|
|
86
|
+
/**
|
|
87
|
+
* Create a new HashChainProver.
|
|
88
|
+
*
|
|
89
|
+
* @param options - Configuration options
|
|
90
|
+
*/
|
|
91
|
+
constructor(options = {}) {
|
|
92
|
+
this.options = {
|
|
93
|
+
debug: options.debug ?? false,
|
|
94
|
+
maxEvents: options.maxEvents ?? MAX_EVENTS_PER_PROOF,
|
|
95
|
+
simulatedProvingTimeMs: options.simulatedProvingTimeMs ?? 100,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Generate a hash-chain validity proof.
|
|
100
|
+
*
|
|
101
|
+
* This method:
|
|
102
|
+
* 1. Validates the input
|
|
103
|
+
* 2. Builds a witness from the events
|
|
104
|
+
* 3. Verifies the computed hash matches expected
|
|
105
|
+
* 4. Generates a mock ZK proof
|
|
106
|
+
* 5. Returns the proof with metrics
|
|
107
|
+
*
|
|
108
|
+
* @param input - Hash chain input with events and expected hash
|
|
109
|
+
* @returns Promise resolving to the generated proof
|
|
110
|
+
* @throws MidnightProverException on validation or generation failure
|
|
111
|
+
*/
|
|
112
|
+
async generateProof(input) {
|
|
113
|
+
const startTime = Date.now();
|
|
114
|
+
this.debug("Starting hash-chain proof generation");
|
|
115
|
+
this.debug(`Events: ${input.events.length}`);
|
|
116
|
+
// Validate input
|
|
117
|
+
this.validateInput(input);
|
|
118
|
+
// Build witness
|
|
119
|
+
const witness = await this.buildWitness(input);
|
|
120
|
+
// Verify hash matches expected
|
|
121
|
+
await this.verifyHashMatch(witness, input);
|
|
122
|
+
// Build public inputs
|
|
123
|
+
const publicInputs = this.buildPublicInputs(witness, input);
|
|
124
|
+
// Generate mock proof
|
|
125
|
+
const proofBytes = await this.generateMockProof(witness, publicInputs);
|
|
126
|
+
// Calculate metrics
|
|
127
|
+
const provingTimeMs = Date.now() - startTime + this.options.simulatedProvingTimeMs;
|
|
128
|
+
// Simulate proving delay
|
|
129
|
+
if (this.options.simulatedProvingTimeMs > 0) {
|
|
130
|
+
await this.delay(this.options.simulatedProvingTimeMs);
|
|
131
|
+
}
|
|
132
|
+
const proof = {
|
|
133
|
+
proofType: "hash-chain",
|
|
134
|
+
proofId: randomUUID(),
|
|
135
|
+
proof: proofBytes,
|
|
136
|
+
createdAt: new Date().toISOString(),
|
|
137
|
+
provingTimeMs,
|
|
138
|
+
proofSizeBytes: proofBytes.length,
|
|
139
|
+
publicInputs,
|
|
140
|
+
};
|
|
141
|
+
this.debug(`Proof generated: ${proof.proofId}`);
|
|
142
|
+
this.debug(`Proving time: ${proof.provingTimeMs}ms`);
|
|
143
|
+
this.debug(`Proof size: ${proof.proofSizeBytes} bytes`);
|
|
144
|
+
return proof;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Verify a hash-chain proof.
|
|
148
|
+
*
|
|
149
|
+
* This method checks:
|
|
150
|
+
* 1. Proof format is valid
|
|
151
|
+
* 2. Public inputs are consistent
|
|
152
|
+
* 3. Mock proof data is correctly structured
|
|
153
|
+
*
|
|
154
|
+
* Note: In production, this would verify the actual ZK proof.
|
|
155
|
+
* Current mock implementation verifies structural integrity.
|
|
156
|
+
*
|
|
157
|
+
* @param proof - The proof to verify
|
|
158
|
+
* @returns Promise resolving to true if valid, false otherwise
|
|
159
|
+
*/
|
|
160
|
+
async verifyProof(proof) {
|
|
161
|
+
this.debug(`Verifying proof: ${proof.proofId}`);
|
|
162
|
+
try {
|
|
163
|
+
// Validate proof structure
|
|
164
|
+
if (proof.proofType !== "hash-chain") {
|
|
165
|
+
this.debug("Invalid proof type");
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
if (!proof.proof || proof.proof.length === 0) {
|
|
169
|
+
this.debug("Empty proof data");
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
// Validate public inputs
|
|
173
|
+
const { publicInputs } = proof;
|
|
174
|
+
if (!isValidHexHash(publicInputs.rootHash)) {
|
|
175
|
+
this.debug("Invalid rootHash format");
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
if (!isValidHexHash(publicInputs.cardanoAnchorTxHash)) {
|
|
179
|
+
this.debug("Invalid cardanoAnchorTxHash format");
|
|
180
|
+
return false;
|
|
181
|
+
}
|
|
182
|
+
if (!Number.isInteger(publicInputs.eventCount) || publicInputs.eventCount < 0) {
|
|
183
|
+
this.debug("Invalid eventCount");
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
// Verify mock proof structure
|
|
187
|
+
const isValidMockProof = await this.verifyMockProofStructure(proof);
|
|
188
|
+
if (!isValidMockProof) {
|
|
189
|
+
this.debug("Mock proof structure invalid");
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
this.debug("Proof verified successfully");
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
this.debug(`Verification error: ${error}`);
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Compute the genesis hash for the rolling hash chain.
|
|
202
|
+
* This matches the algorithm in process-trace/rolling-hash.ts
|
|
203
|
+
*
|
|
204
|
+
* @returns Promise resolving to the genesis hash
|
|
205
|
+
*/
|
|
206
|
+
async getGenesisHash() {
|
|
207
|
+
const genesisInput = HASH_DOMAIN_ROLL + GENESIS_SEED;
|
|
208
|
+
return sha256StringHex(genesisInput);
|
|
209
|
+
}
|
|
210
|
+
// ===========================================================================
|
|
211
|
+
// PRIVATE METHODS
|
|
212
|
+
// ===========================================================================
|
|
213
|
+
/**
|
|
214
|
+
* Validate the input for proof generation.
|
|
215
|
+
*/
|
|
216
|
+
validateInput(input) {
|
|
217
|
+
// Check events array
|
|
218
|
+
if (!Array.isArray(input.events)) {
|
|
219
|
+
throw new MidnightProverException(MidnightProverError.INVALID_INPUT, "events must be an array");
|
|
220
|
+
}
|
|
221
|
+
if (input.events.length === 0) {
|
|
222
|
+
throw new MidnightProverException(MidnightProverError.INVALID_INPUT, "events array is empty");
|
|
223
|
+
}
|
|
224
|
+
if (input.events.length > this.options.maxEvents) {
|
|
225
|
+
throw new MidnightProverException(MidnightProverError.WITNESS_TOO_LARGE, `Too many events: ${input.events.length} exceeds maximum ${this.options.maxEvents}`);
|
|
226
|
+
}
|
|
227
|
+
// Check hash formats
|
|
228
|
+
if (!isValidHexHash(input.genesisHash)) {
|
|
229
|
+
throw new MidnightProverException(MidnightProverError.INVALID_INPUT, `Invalid genesisHash format: ${input.genesisHash}`);
|
|
230
|
+
}
|
|
231
|
+
if (!isValidHexHash(input.expectedRootHash)) {
|
|
232
|
+
throw new MidnightProverException(MidnightProverError.INVALID_INPUT, `Invalid expectedRootHash format: ${input.expectedRootHash}`);
|
|
233
|
+
}
|
|
234
|
+
if (!isValidHexHash(input.cardanoAnchorTxHash)) {
|
|
235
|
+
throw new MidnightProverException(MidnightProverError.INVALID_INPUT, `Invalid cardanoAnchorTxHash format: ${input.cardanoAnchorTxHash}`);
|
|
236
|
+
}
|
|
237
|
+
// Validate events have required fields
|
|
238
|
+
for (let i = 0; i < input.events.length; i++) {
|
|
239
|
+
const event = input.events[i];
|
|
240
|
+
if (event === undefined) {
|
|
241
|
+
throw new MidnightProverException(MidnightProverError.INVALID_INPUT, `Event at index ${i} is undefined`);
|
|
242
|
+
}
|
|
243
|
+
if (typeof event.seq !== "number") {
|
|
244
|
+
throw new MidnightProverException(MidnightProverError.INVALID_INPUT, `Event at index ${i} missing seq number`);
|
|
245
|
+
}
|
|
246
|
+
if (typeof event.kind !== "string") {
|
|
247
|
+
throw new MidnightProverException(MidnightProverError.INVALID_INPUT, `Event at index ${i} missing kind`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Build the witness from input.
|
|
253
|
+
*/
|
|
254
|
+
async buildWitness(input) {
|
|
255
|
+
this.debug("Building witness...");
|
|
256
|
+
const witness = await buildHashChainWitness(input.events, normalizeHash(input.genesisHash));
|
|
257
|
+
// Validate witness
|
|
258
|
+
const validationErrors = validateWitness(witness);
|
|
259
|
+
if (validationErrors.length > 0) {
|
|
260
|
+
throw new MidnightProverException(MidnightProverError.INVALID_WITNESS, `Witness validation failed: ${validationErrors.join(", ")}`);
|
|
261
|
+
}
|
|
262
|
+
// Check witness size
|
|
263
|
+
const witnessSize = computeWitnessSize(witness);
|
|
264
|
+
if (witnessSize > MAX_WITNESS_SIZE_BYTES) {
|
|
265
|
+
throw new MidnightProverException(MidnightProverError.WITNESS_TOO_LARGE, `Witness size ${witnessSize} bytes exceeds maximum ${MAX_WITNESS_SIZE_BYTES}`);
|
|
266
|
+
}
|
|
267
|
+
this.debug(`Witness built: ${witness.eventCount} events, ${witnessSize} bytes`);
|
|
268
|
+
return witness;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Verify that the computed rolling hash matches the expected root hash.
|
|
272
|
+
*/
|
|
273
|
+
async verifyHashMatch(witness, input) {
|
|
274
|
+
const computedHash = normalizeHash(witness.computedRollingHash);
|
|
275
|
+
const expectedHash = normalizeHash(input.expectedRootHash);
|
|
276
|
+
if (computedHash !== expectedHash) {
|
|
277
|
+
throw new MidnightProverException(MidnightProverError.HASH_MISMATCH, `Rolling hash mismatch: computed ${computedHash}, expected ${expectedHash}`);
|
|
278
|
+
}
|
|
279
|
+
this.debug("Hash match verified");
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Build public inputs for the proof.
|
|
283
|
+
*/
|
|
284
|
+
buildPublicInputs(witness, input) {
|
|
285
|
+
return buildPublicInputs("hash-chain", {
|
|
286
|
+
rootHash: witness.computedRollingHash,
|
|
287
|
+
eventCount: witness.eventCount,
|
|
288
|
+
cardanoAnchorTxHash: input.cardanoAnchorTxHash,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Generate a mock ZK proof.
|
|
293
|
+
*
|
|
294
|
+
* This creates a simulated proof structure that includes:
|
|
295
|
+
* - A magic header identifying it as a mock proof
|
|
296
|
+
* - Hash of the witness (for integrity)
|
|
297
|
+
* - Serialized public inputs
|
|
298
|
+
* - Random "proof" bytes (placeholder for real proof data)
|
|
299
|
+
*
|
|
300
|
+
* In production, this would call the Midnight proof server.
|
|
301
|
+
*/
|
|
302
|
+
async generateMockProof(witness, publicInputs) {
|
|
303
|
+
// Magic header for mock proofs: "MOCK-POI-HC-PROOF-V1"
|
|
304
|
+
const magicHeader = new TextEncoder().encode("MOCK-POI-HC-PROOF-V1");
|
|
305
|
+
// Compute witness hash for integrity
|
|
306
|
+
const serializedWitness = serializeWitness(witness);
|
|
307
|
+
// Copy to a fresh ArrayBuffer to ensure compatibility with crypto.subtle.digest
|
|
308
|
+
const witnessBuffer = new ArrayBuffer(serializedWitness.byteLength);
|
|
309
|
+
new Uint8Array(witnessBuffer).set(serializedWitness);
|
|
310
|
+
const witnessHashBuffer = await crypto.subtle.digest("SHA-256", witnessBuffer);
|
|
311
|
+
const witnessHash = new Uint8Array(witnessHashBuffer);
|
|
312
|
+
// Serialize public inputs
|
|
313
|
+
const serializedPublicInputs = serializePublicInputs("hash-chain", publicInputs);
|
|
314
|
+
// Generate random "proof" data (256 bytes)
|
|
315
|
+
const randomProofData = new Uint8Array(256);
|
|
316
|
+
crypto.getRandomValues(randomProofData);
|
|
317
|
+
// Combine all parts
|
|
318
|
+
const proof = new Uint8Array(magicHeader.length + // 20 bytes
|
|
319
|
+
4 + // witness hash length (4 bytes, always 32)
|
|
320
|
+
witnessHash.length + // 32 bytes
|
|
321
|
+
4 + // public inputs length
|
|
322
|
+
serializedPublicInputs.length +
|
|
323
|
+
4 + // proof data length
|
|
324
|
+
randomProofData.length);
|
|
325
|
+
let offset = 0;
|
|
326
|
+
// Write magic header
|
|
327
|
+
proof.set(magicHeader, offset);
|
|
328
|
+
offset += magicHeader.length;
|
|
329
|
+
// Write witness hash
|
|
330
|
+
const view = new DataView(proof.buffer);
|
|
331
|
+
view.setUint32(offset, witnessHash.length, false);
|
|
332
|
+
offset += 4;
|
|
333
|
+
proof.set(witnessHash, offset);
|
|
334
|
+
offset += witnessHash.length;
|
|
335
|
+
// Write public inputs
|
|
336
|
+
view.setUint32(offset, serializedPublicInputs.length, false);
|
|
337
|
+
offset += 4;
|
|
338
|
+
proof.set(serializedPublicInputs, offset);
|
|
339
|
+
offset += serializedPublicInputs.length;
|
|
340
|
+
// Write random proof data
|
|
341
|
+
view.setUint32(offset, randomProofData.length, false);
|
|
342
|
+
offset += 4;
|
|
343
|
+
proof.set(randomProofData, offset);
|
|
344
|
+
return proof;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Verify the structure of a mock proof.
|
|
348
|
+
*/
|
|
349
|
+
async verifyMockProofStructure(proof) {
|
|
350
|
+
const data = proof.proof;
|
|
351
|
+
// Check minimum length
|
|
352
|
+
if (data.length < 20 + 4 + 32 + 4 + 1 + 4 + 1) {
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
// Check magic header
|
|
356
|
+
const magicHeader = new TextDecoder().decode(data.slice(0, 20));
|
|
357
|
+
if (magicHeader !== "MOCK-POI-HC-PROOF-V1") {
|
|
358
|
+
return false;
|
|
359
|
+
}
|
|
360
|
+
// Verify structure can be parsed
|
|
361
|
+
try {
|
|
362
|
+
let offset = 20;
|
|
363
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
364
|
+
// Witness hash
|
|
365
|
+
const witnessHashLen = view.getUint32(offset, false);
|
|
366
|
+
offset += 4;
|
|
367
|
+
if (witnessHashLen !== 32 || offset + witnessHashLen > data.length) {
|
|
368
|
+
return false;
|
|
369
|
+
}
|
|
370
|
+
offset += witnessHashLen;
|
|
371
|
+
// Public inputs
|
|
372
|
+
const publicInputsLen = view.getUint32(offset, false);
|
|
373
|
+
offset += 4;
|
|
374
|
+
if (offset + publicInputsLen > data.length) {
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
offset += publicInputsLen;
|
|
378
|
+
// Proof data
|
|
379
|
+
const proofDataLen = view.getUint32(offset, false);
|
|
380
|
+
offset += 4;
|
|
381
|
+
if (offset + proofDataLen > data.length) {
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
return true;
|
|
385
|
+
}
|
|
386
|
+
catch {
|
|
387
|
+
return false;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Debug logging helper.
|
|
392
|
+
*/
|
|
393
|
+
debug(message) {
|
|
394
|
+
if (this.options.debug) {
|
|
395
|
+
console.log(`[HashChainProver] ${message}`);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Delay helper for simulated proving time.
|
|
400
|
+
*/
|
|
401
|
+
delay(ms) {
|
|
402
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
// =============================================================================
|
|
406
|
+
// UTILITY FUNCTIONS
|
|
407
|
+
// =============================================================================
|
|
408
|
+
/**
|
|
409
|
+
* Validate a hex hash string (64 characters, with or without 0x prefix).
|
|
410
|
+
*/
|
|
411
|
+
function isValidHexHash(value) {
|
|
412
|
+
if (typeof value !== "string") {
|
|
413
|
+
return false;
|
|
414
|
+
}
|
|
415
|
+
const cleanHex = value.startsWith("0x") ? value.slice(2) : value;
|
|
416
|
+
return /^[0-9a-fA-F]{64}$/.test(cleanHex);
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Normalize a hash to lowercase without 0x prefix.
|
|
420
|
+
*/
|
|
421
|
+
function normalizeHash(hash) {
|
|
422
|
+
const cleanHex = hash.startsWith("0x") ? hash.slice(2) : hash;
|
|
423
|
+
return cleanHex.toLowerCase();
|
|
424
|
+
}
|
|
425
|
+
// =============================================================================
|
|
426
|
+
// FACTORY FUNCTION
|
|
427
|
+
// =============================================================================
|
|
428
|
+
/**
|
|
429
|
+
* Create a new HashChainProver instance.
|
|
430
|
+
*
|
|
431
|
+
* @param options - Configuration options
|
|
432
|
+
* @returns A new HashChainProver instance
|
|
433
|
+
*/
|
|
434
|
+
export function createHashChainProver(options) {
|
|
435
|
+
return new HashChainProver(options);
|
|
436
|
+
}
|
|
437
|
+
//# sourceMappingURL=hash-chain-proof.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hash-chain-proof.js","sourceRoot":"","sources":["../../src/proofs/hash-chain-proof.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAQzC,OAAO,EACL,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AAErB,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,GAEhB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EACL,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,eAAe,EAAE,MAAM,wCAAwC,CAAC;AAEzE,gFAAgF;AAChF,YAAY;AACZ,gFAAgF;AAEhF;;;GAGG;AACH,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAEpC;;GAEG;AACH,MAAM,sBAAsB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAEhD;;GAEG;AACH,MAAM,gBAAgB,GAAG,oBAAoB,CAAC;AAE9C;;GAEG;AACH,MAAM,YAAY,GAAG,SAAS,CAAC;AA2B/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,OAAO,eAAe;IACT,OAAO,CAAmC;IAE3D;;;;OAIG;IACH,YAAY,UAAkC,EAAE;QAC9C,IAAI,CAAC,OAAO,GAAG;YACb,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,KAAK;YAC7B,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,oBAAoB;YACpD,sBAAsB,EAAE,OAAO,CAAC,sBAAsB,IAAI,GAAG;SAC9D,CAAC;IACJ,CAAC;IAED;;;;;;;;;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AACnB,gFAAgF;AAEhF;;;;;GAKG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAAgC;IAEhC,OAAO,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Proof generators exports.
|
|
3
|
+
*
|
|
4
|
+
* Location: packages/midnight-prover/src/proofs/index.ts
|
|
5
|
+
*
|
|
6
|
+
* Summary:
|
|
7
|
+
* This file exports all proof generator classes and factory functions.
|
|
8
|
+
* Each prover handles a specific type of ZK proof for the PoI system.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import {
|
|
13
|
+
* HashChainProver,
|
|
14
|
+
* PolicyComplianceProver,
|
|
15
|
+
* SelectiveDisclosureProver,
|
|
16
|
+
* createHashChainProver,
|
|
17
|
+
* } from "@fluxpointstudios/orynq-sdk-midnight-prover";
|
|
18
|
+
*
|
|
19
|
+
* const prover = createHashChainProver({ debug: true });
|
|
20
|
+
* const proof = await prover.generateProof(input);
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* Related files:
|
|
24
|
+
* - hash-chain-proof.ts: Hash chain validity proofs
|
|
25
|
+
* - policy-compliance-proof.ts: Policy compliance proofs
|
|
26
|
+
* - selective-disclosure.ts: Selective disclosure proofs with Merkle utilities
|
|
27
|
+
* - (future) attestation-proof.ts: TEE attestation proofs
|
|
28
|
+
*/
|
|
29
|
+
export type { HashChainProverOptions } from "./hash-chain-proof.js";
|
|
30
|
+
export { HashChainProver, createHashChainProver, } from "./hash-chain-proof.js";
|
|
31
|
+
export type { PolicyComplianceProverOptions, RuleEvaluationResult, PolicyEvaluationResult, RuleEvaluator, } from "./policy-compliance-proof.js";
|
|
32
|
+
export { PolicyComplianceProver, createPolicyComplianceProver, } from "./policy-compliance-proof.js";
|
|
33
|
+
export type { SelectiveDisclosureProverOptions, MerkleInclusionResult, } from "./selective-disclosure.js";
|
|
34
|
+
export { SelectiveDisclosureProver, createSelectiveDisclosureProver, computeSpanHash, computeLeafHash, computeNodeHash, computeMerkleRoot, generateMerkleInclusionProof, verifyMerkleProof, verifySpanInclusion, } from "./selective-disclosure.js";
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/proofs/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAMH,YAAY,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAEpE,OAAO,EACL,eAAe,EACf,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAM/B,YAAY,EACV,6BAA6B,EAC7B,oBAAoB,EACpB,sBAAsB,EACtB,aAAa,GACd,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,sBAAsB,EACtB,4BAA4B,GAC7B,MAAM,8BAA8B,CAAC;AAMtC,YAAY,EACV,gCAAgC,EAChC,qBAAqB,GACtB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EACL,yBAAyB,EACzB,+BAA+B,EAE/B,eAAe,EACf,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,4BAA4B,EAC5B,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Proof generators exports.
|
|
3
|
+
*
|
|
4
|
+
* Location: packages/midnight-prover/src/proofs/index.ts
|
|
5
|
+
*
|
|
6
|
+
* Summary:
|
|
7
|
+
* This file exports all proof generator classes and factory functions.
|
|
8
|
+
* Each prover handles a specific type of ZK proof for the PoI system.
|
|
9
|
+
*
|
|
10
|
+
* Usage:
|
|
11
|
+
* ```typescript
|
|
12
|
+
* import {
|
|
13
|
+
* HashChainProver,
|
|
14
|
+
* PolicyComplianceProver,
|
|
15
|
+
* SelectiveDisclosureProver,
|
|
16
|
+
* createHashChainProver,
|
|
17
|
+
* } from "@fluxpointstudios/orynq-sdk-midnight-prover";
|
|
18
|
+
*
|
|
19
|
+
* const prover = createHashChainProver({ debug: true });
|
|
20
|
+
* const proof = await prover.generateProof(input);
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* Related files:
|
|
24
|
+
* - hash-chain-proof.ts: Hash chain validity proofs
|
|
25
|
+
* - policy-compliance-proof.ts: Policy compliance proofs
|
|
26
|
+
* - selective-disclosure.ts: Selective disclosure proofs with Merkle utilities
|
|
27
|
+
* - (future) attestation-proof.ts: TEE attestation proofs
|
|
28
|
+
*/
|
|
29
|
+
export { HashChainProver, createHashChainProver, } from "./hash-chain-proof.js";
|
|
30
|
+
export { PolicyComplianceProver, createPolicyComplianceProver, } from "./policy-compliance-proof.js";
|
|
31
|
+
export { SelectiveDisclosureProver, createSelectiveDisclosureProver,
|
|
32
|
+
// Merkle utilities
|
|
33
|
+
computeSpanHash, computeLeafHash, computeNodeHash, computeMerkleRoot, generateMerkleInclusionProof, verifyMerkleProof, verifySpanInclusion, } from "./selective-disclosure.js";
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/proofs/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAQH,OAAO,EACL,eAAe,EACf,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAa/B,OAAO,EACL,sBAAsB,EACtB,4BAA4B,GAC7B,MAAM,8BAA8B,CAAC;AAWtC,OAAO,EACL,yBAAyB,EACzB,+BAA+B;AAC/B,mBAAmB;AACnB,eAAe,EACf,eAAe,EACf,eAAe,EACf,iBAAiB,EACjB,4BAA4B,EAC5B,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,2BAA2B,CAAC"}
|