@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
package/dist/prover.js
ADDED
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Default implementation of the MidnightProver interface.
|
|
3
|
+
*
|
|
4
|
+
* Location: packages/midnight-prover/src/prover.ts
|
|
5
|
+
*
|
|
6
|
+
* Summary:
|
|
7
|
+
* This module implements the DefaultMidnightProver class which provides a complete
|
|
8
|
+
* implementation of the MidnightProver interface. It coordinates all proof types
|
|
9
|
+
* (hash-chain, policy, disclosure, attestation, inference), manages connection
|
|
10
|
+
* lifecycle, and handles proof publication.
|
|
11
|
+
*
|
|
12
|
+
* Usage:
|
|
13
|
+
* - Primary entry point for ZK proof generation in the PoI system
|
|
14
|
+
* - Coordinates individual provers from src/proofs/
|
|
15
|
+
* - Manages connection to the Midnight proof server
|
|
16
|
+
* - Handles proof publication and verification
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```typescript
|
|
20
|
+
* import { createMidnightProver } from './prover.js';
|
|
21
|
+
*
|
|
22
|
+
* const prover = createMidnightProver({ debug: true });
|
|
23
|
+
*
|
|
24
|
+
* await prover.connect({
|
|
25
|
+
* proofServerUrl: 'https://proof.midnight.network',
|
|
26
|
+
* timeout: 300000,
|
|
27
|
+
* retries: 3,
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* const proof = await prover.proveHashChain(input);
|
|
31
|
+
* const result = await prover.publish(proof);
|
|
32
|
+
*
|
|
33
|
+
* await prover.disconnect();
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
import { MidnightProverError, MidnightProverException, } from "./types.js";
|
|
37
|
+
import { AbstractMidnightProver, proverRegistry, } from "./prover-interface.js";
|
|
38
|
+
import { HashChainProver } from "./proofs/hash-chain-proof.js";
|
|
39
|
+
import { PolicyComplianceProver } from "./proofs/policy-compliance-proof.js";
|
|
40
|
+
import { SelectiveDisclosureProver } from "./proofs/selective-disclosure.js";
|
|
41
|
+
import { ProofPublisher } from "./linking/proof-publication.js";
|
|
42
|
+
import { ProofServerClient } from "./midnight/proof-server-client.js";
|
|
43
|
+
// =============================================================================
|
|
44
|
+
// DEFAULT MIDNIGHT PROVER
|
|
45
|
+
// =============================================================================
|
|
46
|
+
/**
|
|
47
|
+
* DefaultMidnightProver provides a complete implementation of the MidnightProver interface.
|
|
48
|
+
*
|
|
49
|
+
* This class:
|
|
50
|
+
* - Coordinates all proof types (hash-chain, policy, disclosure)
|
|
51
|
+
* - Manages connection lifecycle with the Midnight proof server
|
|
52
|
+
* - Handles proof publication and verification
|
|
53
|
+
* - Uses individual provers from src/proofs/ for specific proof types
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const prover = new DefaultMidnightProver({ debug: true });
|
|
58
|
+
*
|
|
59
|
+
* await prover.connect({
|
|
60
|
+
* proofServerUrl: 'https://proof.midnight.network',
|
|
61
|
+
* apiKey: process.env.MIDNIGHT_API_KEY,
|
|
62
|
+
* timeout: 300000,
|
|
63
|
+
* retries: 3,
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* try {
|
|
67
|
+
* // Generate proofs
|
|
68
|
+
* const hashChainProof = await prover.proveHashChain(input);
|
|
69
|
+
* const policyProof = await prover.provePolicyCompliance(policyInput);
|
|
70
|
+
*
|
|
71
|
+
* // Publish to network
|
|
72
|
+
* const result = await prover.publish(hashChainProof);
|
|
73
|
+
* console.log('Published:', result.midnightTxHash);
|
|
74
|
+
* } finally {
|
|
75
|
+
* await prover.disconnect();
|
|
76
|
+
* }
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export class DefaultMidnightProver extends AbstractMidnightProver {
|
|
80
|
+
options;
|
|
81
|
+
// Individual provers
|
|
82
|
+
hashChainProver;
|
|
83
|
+
policyProver;
|
|
84
|
+
disclosureProver;
|
|
85
|
+
// Network clients
|
|
86
|
+
proofServerClient;
|
|
87
|
+
proofPublisher;
|
|
88
|
+
// Published proofs cache
|
|
89
|
+
publishedProofs = new Map();
|
|
90
|
+
/**
|
|
91
|
+
* Create a new DefaultMidnightProver instance.
|
|
92
|
+
*
|
|
93
|
+
* @param options - Configuration options
|
|
94
|
+
*/
|
|
95
|
+
constructor(options = {}) {
|
|
96
|
+
super();
|
|
97
|
+
this.options = {
|
|
98
|
+
debug: options.debug ?? false,
|
|
99
|
+
circuitsDir: options.circuitsDir ?? "./circuits",
|
|
100
|
+
enableInference: options.enableInference ?? false,
|
|
101
|
+
};
|
|
102
|
+
// Initialize individual provers
|
|
103
|
+
this.hashChainProver = new HashChainProver({
|
|
104
|
+
debug: this.options.debug,
|
|
105
|
+
simulatedProvingTimeMs: 50,
|
|
106
|
+
});
|
|
107
|
+
this.policyProver = new PolicyComplianceProver({
|
|
108
|
+
debug: this.options.debug,
|
|
109
|
+
});
|
|
110
|
+
this.disclosureProver = new SelectiveDisclosureProver({
|
|
111
|
+
debug: this.options.debug,
|
|
112
|
+
includeSpanData: true,
|
|
113
|
+
includeEventData: true,
|
|
114
|
+
});
|
|
115
|
+
// Initialize network clients
|
|
116
|
+
this.proofServerClient = new ProofServerClient({
|
|
117
|
+
debug: this.options.debug,
|
|
118
|
+
simulatedProvingTimeMs: 50,
|
|
119
|
+
});
|
|
120
|
+
this.proofPublisher = new ProofPublisher({
|
|
121
|
+
debug: this.options.debug,
|
|
122
|
+
maxRetries: 3,
|
|
123
|
+
pollIntervalMs: 1000, // Faster polling for tests
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
// ===========================================================================
|
|
127
|
+
// CONNECTION MANAGEMENT
|
|
128
|
+
// ===========================================================================
|
|
129
|
+
/**
|
|
130
|
+
* Connect to the Midnight proof server.
|
|
131
|
+
*/
|
|
132
|
+
async doConnect(config) {
|
|
133
|
+
this.debug(`Connecting to proof server at ${config.proofServerUrl}...`);
|
|
134
|
+
try {
|
|
135
|
+
// Connect proof server client
|
|
136
|
+
await this.proofServerClient.connect(config);
|
|
137
|
+
// Connect proof publisher
|
|
138
|
+
await this.proofPublisher.connect(config);
|
|
139
|
+
this.debug("Connected successfully");
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
// Disconnect any partially connected components
|
|
143
|
+
await this.doDisconnect();
|
|
144
|
+
if (error instanceof MidnightProverException) {
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
throw new MidnightProverException(MidnightProverError.CONNECTION_FAILED, `Failed to connect: ${String(error)}`, error instanceof Error ? error : undefined);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Disconnect from the proof server.
|
|
152
|
+
*/
|
|
153
|
+
async doDisconnect() {
|
|
154
|
+
this.debug("Disconnecting...");
|
|
155
|
+
// Disconnect components (ignore errors during cleanup)
|
|
156
|
+
try {
|
|
157
|
+
await this.proofServerClient.disconnect();
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
// Ignore disconnect errors
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
await this.proofPublisher.disconnect();
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
// Ignore disconnect errors
|
|
167
|
+
}
|
|
168
|
+
this.debug("Disconnected");
|
|
169
|
+
}
|
|
170
|
+
// ===========================================================================
|
|
171
|
+
// PROOF GENERATION
|
|
172
|
+
// ===========================================================================
|
|
173
|
+
/**
|
|
174
|
+
* Generate a hash-chain validity proof.
|
|
175
|
+
*/
|
|
176
|
+
async proveHashChain(input) {
|
|
177
|
+
this.ensureConnected();
|
|
178
|
+
this.debug(`Generating hash-chain proof for ${input.events.length} events`);
|
|
179
|
+
try {
|
|
180
|
+
const proof = await this.hashChainProver.generateProof(input);
|
|
181
|
+
this.debug(`Hash-chain proof generated: ${proof.proofId}`);
|
|
182
|
+
return proof;
|
|
183
|
+
}
|
|
184
|
+
catch (error) {
|
|
185
|
+
if (error instanceof MidnightProverException) {
|
|
186
|
+
throw error;
|
|
187
|
+
}
|
|
188
|
+
throw new MidnightProverException(MidnightProverError.PROOF_GENERATION_FAILED, `Hash-chain proof generation failed: ${String(error)}`, error instanceof Error ? error : undefined);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Generate a policy compliance proof.
|
|
193
|
+
*/
|
|
194
|
+
async provePolicyCompliance(input) {
|
|
195
|
+
this.ensureConnected();
|
|
196
|
+
this.debug(`Generating policy compliance proof for policy ${input.policy.id}`);
|
|
197
|
+
try {
|
|
198
|
+
const proof = await this.policyProver.generateProof(input);
|
|
199
|
+
this.debug(`Policy proof generated: ${proof.proofId}`);
|
|
200
|
+
return proof;
|
|
201
|
+
}
|
|
202
|
+
catch (error) {
|
|
203
|
+
if (error instanceof MidnightProverException) {
|
|
204
|
+
throw error;
|
|
205
|
+
}
|
|
206
|
+
throw new MidnightProverException(MidnightProverError.PROOF_GENERATION_FAILED, `Policy compliance proof generation failed: ${String(error)}`, error instanceof Error ? error : undefined);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Generate an attestation validity proof.
|
|
211
|
+
*
|
|
212
|
+
* Note: Attestation proof generation is not yet implemented.
|
|
213
|
+
* This method throws a not-implemented error.
|
|
214
|
+
*/
|
|
215
|
+
async proveAttestation(_input) {
|
|
216
|
+
this.ensureConnected();
|
|
217
|
+
this.debug("Attestation proofs not yet implemented");
|
|
218
|
+
throw new MidnightProverException(MidnightProverError.CIRCUIT_NOT_FOUND, "Attestation proof generation is not yet implemented");
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Generate a selective disclosure proof.
|
|
222
|
+
*/
|
|
223
|
+
async proveSelectiveDisclosure(input) {
|
|
224
|
+
this.ensureConnected();
|
|
225
|
+
this.debug(`Generating selective disclosure proof for span ${input.spanId}`);
|
|
226
|
+
try {
|
|
227
|
+
const proof = await this.disclosureProver.generateProof(input);
|
|
228
|
+
this.debug(`Disclosure proof generated: ${proof.proofId}`);
|
|
229
|
+
return proof;
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
if (error instanceof MidnightProverException) {
|
|
233
|
+
throw error;
|
|
234
|
+
}
|
|
235
|
+
throw new MidnightProverException(MidnightProverError.PROOF_GENERATION_FAILED, `Selective disclosure proof generation failed: ${String(error)}`, error instanceof Error ? error : undefined);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Generate a zkML inference proof.
|
|
240
|
+
*
|
|
241
|
+
* WARNING: zkML proofs are extremely expensive and not yet supported.
|
|
242
|
+
* This method throws a not-implemented error unless enableInference is true.
|
|
243
|
+
*/
|
|
244
|
+
proveInference(_input) {
|
|
245
|
+
this.ensureConnected();
|
|
246
|
+
if (!this.options.enableInference) {
|
|
247
|
+
throw new MidnightProverException(MidnightProverError.CIRCUIT_NOT_FOUND, "zkML inference proofs are disabled. Enable with { enableInference: true }");
|
|
248
|
+
}
|
|
249
|
+
// Even with enableInference, actual zkML is not yet implemented
|
|
250
|
+
throw new MidnightProverException(MidnightProverError.CIRCUIT_NOT_FOUND, "zkML inference proofs are not yet implemented");
|
|
251
|
+
}
|
|
252
|
+
// ===========================================================================
|
|
253
|
+
// PUBLICATION
|
|
254
|
+
// ===========================================================================
|
|
255
|
+
/**
|
|
256
|
+
* Publish a proof to the Midnight network.
|
|
257
|
+
*/
|
|
258
|
+
async publish(proof) {
|
|
259
|
+
this.ensureConnected();
|
|
260
|
+
this.debug(`Publishing proof: ${proof.proofId}`);
|
|
261
|
+
try {
|
|
262
|
+
const result = await this.proofPublisher.publish(proof);
|
|
263
|
+
// Cache the published proof
|
|
264
|
+
this.publishedProofs.set(proof.proofId, proof);
|
|
265
|
+
this.debug(`Proof published: ${result.midnightTxHash}`);
|
|
266
|
+
return result;
|
|
267
|
+
}
|
|
268
|
+
catch (error) {
|
|
269
|
+
if (error instanceof MidnightProverException) {
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
272
|
+
throw new MidnightProverException(MidnightProverError.PUBLICATION_FAILED, `Proof publication failed: ${String(error)}`, error instanceof Error ? error : undefined);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
// ===========================================================================
|
|
276
|
+
// VERIFICATION
|
|
277
|
+
// ===========================================================================
|
|
278
|
+
/**
|
|
279
|
+
* Verify a proof locally.
|
|
280
|
+
*/
|
|
281
|
+
async verify(proof) {
|
|
282
|
+
this.debug(`Verifying proof: ${proof.proofId}`);
|
|
283
|
+
const errors = [];
|
|
284
|
+
const warnings = [];
|
|
285
|
+
try {
|
|
286
|
+
// Verify based on proof type
|
|
287
|
+
let valid = false;
|
|
288
|
+
switch (proof.proofType) {
|
|
289
|
+
case "hash-chain":
|
|
290
|
+
valid = await this.hashChainProver.verifyProof(proof);
|
|
291
|
+
break;
|
|
292
|
+
case "policy-compliance":
|
|
293
|
+
valid = await this.policyProver.verifyProof(proof);
|
|
294
|
+
break;
|
|
295
|
+
case "selective-disclosure":
|
|
296
|
+
valid = await this.disclosureProver.verifyProof(proof);
|
|
297
|
+
break;
|
|
298
|
+
case "attestation-valid":
|
|
299
|
+
warnings.push("Attestation proof verification not yet implemented");
|
|
300
|
+
valid = false;
|
|
301
|
+
break;
|
|
302
|
+
case "zkml-inference":
|
|
303
|
+
warnings.push("zkML inference proof verification not yet implemented");
|
|
304
|
+
valid = false;
|
|
305
|
+
break;
|
|
306
|
+
default: {
|
|
307
|
+
const unknownProof = proof;
|
|
308
|
+
errors.push(`Unknown proof type: ${unknownProof.proofType}`);
|
|
309
|
+
valid = false;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
const result = {
|
|
313
|
+
valid,
|
|
314
|
+
proofType: proof.proofType,
|
|
315
|
+
publicInputs: this.extractPublicInputs(proof),
|
|
316
|
+
errors,
|
|
317
|
+
warnings,
|
|
318
|
+
verifiedAt: new Date().toISOString(),
|
|
319
|
+
};
|
|
320
|
+
this.debug(`Verification result: ${valid ? "VALID" : "INVALID"}`);
|
|
321
|
+
return result;
|
|
322
|
+
}
|
|
323
|
+
catch (error) {
|
|
324
|
+
errors.push(`Verification error: ${String(error)}`);
|
|
325
|
+
return {
|
|
326
|
+
valid: false,
|
|
327
|
+
proofType: proof.proofType,
|
|
328
|
+
publicInputs: {},
|
|
329
|
+
errors,
|
|
330
|
+
warnings,
|
|
331
|
+
verifiedAt: new Date().toISOString(),
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Fetch a proof from the Midnight network by ID.
|
|
337
|
+
*/
|
|
338
|
+
async fetchProof(proofId) {
|
|
339
|
+
this.ensureConnected();
|
|
340
|
+
this.debug(`Fetching proof: ${proofId}`);
|
|
341
|
+
// Check local cache first
|
|
342
|
+
const cached = this.publishedProofs.get(proofId);
|
|
343
|
+
if (cached) {
|
|
344
|
+
this.debug("Proof found in cache");
|
|
345
|
+
return cached;
|
|
346
|
+
}
|
|
347
|
+
// In a real implementation, this would query the Midnight network
|
|
348
|
+
// For now, return undefined (not found)
|
|
349
|
+
this.debug("Proof not found");
|
|
350
|
+
return undefined;
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Check if a proof has been published to Midnight.
|
|
354
|
+
*/
|
|
355
|
+
async isPublished(proofId) {
|
|
356
|
+
this.ensureConnected();
|
|
357
|
+
// Check publisher's status
|
|
358
|
+
const status = await this.proofPublisher.getProofStatus(proofId);
|
|
359
|
+
return status.status === "confirmed" || status.status === "pending";
|
|
360
|
+
}
|
|
361
|
+
// ===========================================================================
|
|
362
|
+
// UTILITY METHODS
|
|
363
|
+
// ===========================================================================
|
|
364
|
+
/**
|
|
365
|
+
* Get the genesis hash for hash-chain proofs.
|
|
366
|
+
*/
|
|
367
|
+
async getGenesisHash() {
|
|
368
|
+
return this.hashChainProver.getGenesisHash();
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Wait for a proof to be confirmed on the network.
|
|
372
|
+
*
|
|
373
|
+
* @param proofId - Proof identifier
|
|
374
|
+
* @param timeoutMs - Maximum wait time (default: 5 minutes)
|
|
375
|
+
* @returns True if confirmed, false if timeout
|
|
376
|
+
*/
|
|
377
|
+
async waitForConfirmation(proofId, timeoutMs) {
|
|
378
|
+
this.ensureConnected();
|
|
379
|
+
return this.proofPublisher.waitForConfirmation(proofId, timeoutMs);
|
|
380
|
+
}
|
|
381
|
+
// ===========================================================================
|
|
382
|
+
// PRIVATE METHODS
|
|
383
|
+
// ===========================================================================
|
|
384
|
+
/**
|
|
385
|
+
* Extract public inputs from a proof for verification result.
|
|
386
|
+
*/
|
|
387
|
+
extractPublicInputs(proof) {
|
|
388
|
+
const anyProof = proof;
|
|
389
|
+
return anyProof.publicInputs ?? {};
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Debug logging helper.
|
|
393
|
+
*/
|
|
394
|
+
debug(message) {
|
|
395
|
+
if (this.options.debug) {
|
|
396
|
+
console.log(`[DefaultMidnightProver] ${message}`);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
// =============================================================================
|
|
401
|
+
// FACTORY FUNCTION
|
|
402
|
+
// =============================================================================
|
|
403
|
+
/**
|
|
404
|
+
* Create a new DefaultMidnightProver instance.
|
|
405
|
+
*
|
|
406
|
+
* @param options - Configuration options
|
|
407
|
+
* @returns New DefaultMidnightProver instance
|
|
408
|
+
*/
|
|
409
|
+
export function createMidnightProver(options) {
|
|
410
|
+
return new DefaultMidnightProver(options);
|
|
411
|
+
}
|
|
412
|
+
// =============================================================================
|
|
413
|
+
// REGISTER DEFAULT PROVER
|
|
414
|
+
// =============================================================================
|
|
415
|
+
// Register the default prover in the global registry
|
|
416
|
+
proverRegistry.register("default", () => new DefaultMidnightProver());
|
|
417
|
+
//# sourceMappingURL=prover.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prover.js","sourceRoot":"","sources":["../src/prover.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAmBH,OAAO,EACL,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,sBAAsB,EAE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