@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.
Files changed (82) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.d.ts +78 -0
  3. package/dist/index.d.ts.map +1 -0
  4. package/dist/index.js +89 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/linking/cardano-anchor-link.d.ts +250 -0
  7. package/dist/linking/cardano-anchor-link.d.ts.map +1 -0
  8. package/dist/linking/cardano-anchor-link.js +447 -0
  9. package/dist/linking/cardano-anchor-link.js.map +1 -0
  10. package/dist/linking/index.d.ts +33 -0
  11. package/dist/linking/index.d.ts.map +1 -0
  12. package/dist/linking/index.js +31 -0
  13. package/dist/linking/index.js.map +1 -0
  14. package/dist/linking/proof-publication.d.ts +217 -0
  15. package/dist/linking/proof-publication.d.ts.map +1 -0
  16. package/dist/linking/proof-publication.js +385 -0
  17. package/dist/linking/proof-publication.js.map +1 -0
  18. package/dist/midnight/index.d.ts +30 -0
  19. package/dist/midnight/index.d.ts.map +1 -0
  20. package/dist/midnight/index.js +27 -0
  21. package/dist/midnight/index.js.map +1 -0
  22. package/dist/midnight/proof-server-client.d.ts +236 -0
  23. package/dist/midnight/proof-server-client.d.ts.map +1 -0
  24. package/dist/midnight/proof-server-client.js +422 -0
  25. package/dist/midnight/proof-server-client.js.map +1 -0
  26. package/dist/midnight/public-inputs.d.ts +134 -0
  27. package/dist/midnight/public-inputs.d.ts.map +1 -0
  28. package/dist/midnight/public-inputs.js +338 -0
  29. package/dist/midnight/public-inputs.js.map +1 -0
  30. package/dist/midnight/witness-builder.d.ts +119 -0
  31. package/dist/midnight/witness-builder.d.ts.map +1 -0
  32. package/dist/midnight/witness-builder.js +238 -0
  33. package/dist/midnight/witness-builder.js.map +1 -0
  34. package/dist/proofs/hash-chain-proof.d.ts +171 -0
  35. package/dist/proofs/hash-chain-proof.d.ts.map +1 -0
  36. package/dist/proofs/hash-chain-proof.js +437 -0
  37. package/dist/proofs/hash-chain-proof.js.map +1 -0
  38. package/dist/proofs/index.d.ts +35 -0
  39. package/dist/proofs/index.d.ts.map +1 -0
  40. package/dist/proofs/index.js +34 -0
  41. package/dist/proofs/index.js.map +1 -0
  42. package/dist/proofs/policy-compliance-proof.d.ts +165 -0
  43. package/dist/proofs/policy-compliance-proof.d.ts.map +1 -0
  44. package/dist/proofs/policy-compliance-proof.js +514 -0
  45. package/dist/proofs/policy-compliance-proof.js.map +1 -0
  46. package/dist/proofs/selective-disclosure.d.ts +213 -0
  47. package/dist/proofs/selective-disclosure.d.ts.map +1 -0
  48. package/dist/proofs/selective-disclosure.js +629 -0
  49. package/dist/proofs/selective-disclosure.js.map +1 -0
  50. package/dist/prover-interface.d.ts +288 -0
  51. package/dist/prover-interface.d.ts.map +1 -0
  52. package/dist/prover-interface.js +114 -0
  53. package/dist/prover-interface.js.map +1 -0
  54. package/dist/prover.d.ts +163 -0
  55. package/dist/prover.d.ts.map +1 -0
  56. package/dist/prover.js +417 -0
  57. package/dist/prover.js.map +1 -0
  58. package/dist/types.d.ts +410 -0
  59. package/dist/types.d.ts.map +1 -0
  60. package/dist/types.js +128 -0
  61. package/dist/types.js.map +1 -0
  62. package/package.json +59 -0
  63. package/src/__tests__/hash-chain-proof.test.ts +709 -0
  64. package/src/__tests__/midnight-prover.test.ts +716 -0
  65. package/src/__tests__/policy-compliance.test.ts +567 -0
  66. package/src/__tests__/proof-publication.test.ts +644 -0
  67. package/src/__tests__/selective-disclosure.test.ts +921 -0
  68. package/src/index.ts +260 -0
  69. package/src/linking/cardano-anchor-link.ts +682 -0
  70. package/src/linking/index.ts +58 -0
  71. package/src/linking/proof-publication.ts +557 -0
  72. package/src/midnight/index.ts +73 -0
  73. package/src/midnight/proof-server-client.ts +595 -0
  74. package/src/midnight/public-inputs.ts +590 -0
  75. package/src/midnight/witness-builder.ts +341 -0
  76. package/src/proofs/hash-chain-proof.ts +610 -0
  77. package/src/proofs/index.ts +77 -0
  78. package/src/proofs/policy-compliance-proof.ts +717 -0
  79. package/src/proofs/selective-disclosure.ts +839 -0
  80. package/src/prover-interface.ts +410 -0
  81. package/src/prover.ts +537 -0
  82. package/src/types.ts +551 -0
@@ -0,0 +1,217 @@
1
+ /**
2
+ * @fileoverview Proof publication to the Midnight network.
3
+ *
4
+ * Location: packages/midnight-prover/src/linking/proof-publication.ts
5
+ *
6
+ * Summary:
7
+ * This module implements the ProofPublisher class which handles submitting ZK proofs
8
+ * to the Midnight network and monitoring their publication status. It provides retry
9
+ * logic for resilient publication and confirmation waiting for transaction finality.
10
+ *
11
+ * Usage:
12
+ * - Used by the MidnightProver to publish proofs to the Midnight network
13
+ * - Integrates with proof-server-client.ts for network communication
14
+ * - Returns PublicationResult with midnightTxHash for cross-chain linking
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { ProofPublisher } from './proof-publication.js';
19
+ *
20
+ * const publisher = new ProofPublisher({ maxRetries: 3 });
21
+ * await publisher.connect(config);
22
+ *
23
+ * const result = await publisher.publish(proof);
24
+ * console.log('Published:', result.midnightTxHash);
25
+ *
26
+ * const confirmed = await publisher.waitForConfirmation(result.proofId);
27
+ * console.log('Confirmed:', confirmed);
28
+ * ```
29
+ */
30
+ import type { Proof, PublicationResult, ProofServerConfig } from "../types.js";
31
+ /**
32
+ * Status of a proof publication.
33
+ */
34
+ export type ProofStatus = "pending" | "confirmed" | "failed" | "not_found";
35
+ /**
36
+ * Detailed status information for a proof.
37
+ */
38
+ export interface ProofStatusInfo {
39
+ status: ProofStatus;
40
+ proofId: string;
41
+ midnightTxHash: string | undefined;
42
+ blockNumber: number | undefined;
43
+ confirmations: number;
44
+ timestamp: string | undefined;
45
+ error: string | undefined;
46
+ }
47
+ /**
48
+ * Options for the ProofPublisher.
49
+ */
50
+ export interface ProofPublisherOptions {
51
+ /**
52
+ * Maximum number of retry attempts for publication.
53
+ * Default: 3
54
+ */
55
+ maxRetries?: number;
56
+ /**
57
+ * Base delay between retries in milliseconds (exponential backoff).
58
+ * Default: 1000
59
+ */
60
+ retryDelayMs?: number;
61
+ /**
62
+ * Maximum delay between retries in milliseconds.
63
+ * Default: 30000
64
+ */
65
+ maxRetryDelayMs?: number;
66
+ /**
67
+ * Default timeout for confirmation waiting in milliseconds.
68
+ * Default: 300000 (5 minutes)
69
+ */
70
+ defaultConfirmationTimeoutMs?: number;
71
+ /**
72
+ * Polling interval for status checks in milliseconds.
73
+ * Default: 5000
74
+ */
75
+ pollIntervalMs?: number;
76
+ /**
77
+ * Enable debug logging.
78
+ */
79
+ debug?: boolean;
80
+ }
81
+ /**
82
+ * ProofPublisher handles submitting ZK proofs to the Midnight network.
83
+ *
84
+ * This class provides:
85
+ * - Resilient proof publication with retry logic
86
+ * - Status monitoring for submitted proofs
87
+ * - Confirmation waiting with timeout support
88
+ *
89
+ * Current implementation is a mock that simulates network interaction.
90
+ * Real Midnight integration will be added when the network SDK is available.
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * const publisher = new ProofPublisher({ maxRetries: 3, debug: true });
95
+ * await publisher.connect(config);
96
+ *
97
+ * const result = await publisher.publish(hashChainProof);
98
+ * console.log('Transaction:', result.midnightTxHash);
99
+ *
100
+ * // Wait for confirmation
101
+ * const confirmed = await publisher.waitForConfirmation(result.proofId, 60000);
102
+ * if (confirmed) {
103
+ * console.log('Proof confirmed on Midnight network');
104
+ * }
105
+ * ```
106
+ */
107
+ export declare class ProofPublisher {
108
+ private readonly options;
109
+ private config;
110
+ private connected;
111
+ private readonly publishedProofs;
112
+ /**
113
+ * Create a new ProofPublisher instance.
114
+ *
115
+ * @param options - Configuration options
116
+ */
117
+ constructor(options?: ProofPublisherOptions);
118
+ /**
119
+ * Connect to the Midnight network.
120
+ *
121
+ * @param config - Proof server configuration
122
+ * @throws MidnightProverException on connection failure
123
+ */
124
+ connect(config: ProofServerConfig): Promise<void>;
125
+ /**
126
+ * Disconnect from the Midnight network.
127
+ */
128
+ disconnect(): Promise<void>;
129
+ /**
130
+ * Check if connected to the network.
131
+ */
132
+ isConnected(): boolean;
133
+ /**
134
+ * Get the current configuration.
135
+ */
136
+ getConfig(): ProofServerConfig | undefined;
137
+ /**
138
+ * Publish a proof to the Midnight network.
139
+ *
140
+ * This method:
141
+ * 1. Validates the proof structure
142
+ * 2. Serializes the proof for transmission
143
+ * 3. Submits to the network with retry logic
144
+ * 4. Returns the publication result with transaction hash
145
+ *
146
+ * @param proof - The proof to publish
147
+ * @returns Publication result with Midnight transaction hash
148
+ * @throws MidnightProverException on failure after all retries
149
+ */
150
+ publish(proof: Proof): Promise<PublicationResult>;
151
+ /**
152
+ * Get the status of a published proof.
153
+ *
154
+ * @param proofId - Unique proof identifier
155
+ * @returns Promise resolving to the proof status
156
+ */
157
+ getProofStatus(proofId: string): Promise<ProofStatusInfo>;
158
+ /**
159
+ * Wait for a proof to be confirmed on the network.
160
+ *
161
+ * @param proofId - Unique proof identifier
162
+ * @param timeoutMs - Maximum time to wait in milliseconds (default: 5 minutes)
163
+ * @returns Promise resolving to true if confirmed, false if timeout
164
+ */
165
+ waitForConfirmation(proofId: string, timeoutMs?: number): Promise<boolean>;
166
+ /**
167
+ * Get the publication result for a proof.
168
+ *
169
+ * @param proofId - Unique proof identifier
170
+ * @returns The publication result if found, undefined otherwise
171
+ */
172
+ getPublicationResult(proofId: string): PublicationResult | undefined;
173
+ /**
174
+ * Ensure connected before operations.
175
+ */
176
+ private ensureConnected;
177
+ /**
178
+ * Validate a proof before publication.
179
+ */
180
+ private validateProof;
181
+ /**
182
+ * Extract Cardano anchor transaction hash from proof public inputs.
183
+ */
184
+ private extractCardanoAnchorTxHash;
185
+ /**
186
+ * Attempt to publish a proof (single attempt).
187
+ */
188
+ private attemptPublish;
189
+ /**
190
+ * Hash proof bytes for transaction identification.
191
+ */
192
+ private hashProofBytes;
193
+ /**
194
+ * Calculate retry delay with exponential backoff.
195
+ */
196
+ private calculateRetryDelay;
197
+ /**
198
+ * Simulate network delay for mock operations.
199
+ */
200
+ private simulateNetworkDelay;
201
+ /**
202
+ * Delay helper.
203
+ */
204
+ private delay;
205
+ /**
206
+ * Debug logging helper.
207
+ */
208
+ private debug;
209
+ }
210
+ /**
211
+ * Create a new ProofPublisher instance.
212
+ *
213
+ * @param options - Configuration options
214
+ * @returns New ProofPublisher instance
215
+ */
216
+ export declare function createProofPublisher(options?: ProofPublisherOptions): ProofPublisher;
217
+ //# sourceMappingURL=proof-publication.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proof-publication.d.ts","sourceRoot":"","sources":["../../src/linking/proof-publication.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EACV,KAAK,EACL,iBAAiB,EACjB,iBAAiB,EAElB,MAAM,aAAa,CAAC;AAarB;;GAEG;AACH,MAAM,MAAM,WAAW,GACnB,SAAS,GACT,WAAW,GACX,QAAQ,GACR,WAAW,CAAC;AAEhB;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,WAAW,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,WAAW,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,aAAa,EAAE,MAAM,CAAC;IACtB,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;;OAGG;IACH,4BAA4B,CAAC,EAAE,MAAM,CAAC;IAEtC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,CAA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,CAAC,EAAE,qBAAqB,GAC9B,cAAc,CAEhB"}
@@ -0,0 +1,385 @@
1
+ /**
2
+ * @fileoverview Proof publication to the Midnight network.
3
+ *
4
+ * Location: packages/midnight-prover/src/linking/proof-publication.ts
5
+ *
6
+ * Summary:
7
+ * This module implements the ProofPublisher class which handles submitting ZK proofs
8
+ * to the Midnight network and monitoring their publication status. It provides retry
9
+ * logic for resilient publication and confirmation waiting for transaction finality.
10
+ *
11
+ * Usage:
12
+ * - Used by the MidnightProver to publish proofs to the Midnight network
13
+ * - Integrates with proof-server-client.ts for network communication
14
+ * - Returns PublicationResult with midnightTxHash for cross-chain linking
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { ProofPublisher } from './proof-publication.js';
19
+ *
20
+ * const publisher = new ProofPublisher({ maxRetries: 3 });
21
+ * await publisher.connect(config);
22
+ *
23
+ * const result = await publisher.publish(proof);
24
+ * console.log('Published:', result.midnightTxHash);
25
+ *
26
+ * const confirmed = await publisher.waitForConfirmation(result.proofId);
27
+ * console.log('Confirmed:', confirmed);
28
+ * ```
29
+ */
30
+ import { MidnightProverError, MidnightProverException, } from "../types.js";
31
+ import { sha256StringHex, canonicalize } from "@fluxpointstudios/orynq-sdk-core/utils";
32
+ /**
33
+ * Domain separation prefixes for proof publication.
34
+ */
35
+ const PUBLICATION_DOMAIN_PREFIXES = {
36
+ txHash: "poi-midnight:tx:v1|",
37
+ proofId: "poi-midnight:proof:v1|",
38
+ };
39
+ // =============================================================================
40
+ // PROOF PUBLISHER
41
+ // =============================================================================
42
+ /**
43
+ * ProofPublisher handles submitting ZK proofs to the Midnight network.
44
+ *
45
+ * This class provides:
46
+ * - Resilient proof publication with retry logic
47
+ * - Status monitoring for submitted proofs
48
+ * - Confirmation waiting with timeout support
49
+ *
50
+ * Current implementation is a mock that simulates network interaction.
51
+ * Real Midnight integration will be added when the network SDK is available.
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * const publisher = new ProofPublisher({ maxRetries: 3, debug: true });
56
+ * await publisher.connect(config);
57
+ *
58
+ * const result = await publisher.publish(hashChainProof);
59
+ * console.log('Transaction:', result.midnightTxHash);
60
+ *
61
+ * // Wait for confirmation
62
+ * const confirmed = await publisher.waitForConfirmation(result.proofId, 60000);
63
+ * if (confirmed) {
64
+ * console.log('Proof confirmed on Midnight network');
65
+ * }
66
+ * ```
67
+ */
68
+ export class ProofPublisher {
69
+ options;
70
+ config;
71
+ connected = false;
72
+ // Mock storage for simulated proofs (would be replaced with network state)
73
+ publishedProofs = new Map();
74
+ /**
75
+ * Create a new ProofPublisher instance.
76
+ *
77
+ * @param options - Configuration options
78
+ */
79
+ constructor(options = {}) {
80
+ this.options = {
81
+ maxRetries: options.maxRetries ?? 3,
82
+ retryDelayMs: options.retryDelayMs ?? 1000,
83
+ maxRetryDelayMs: options.maxRetryDelayMs ?? 30000,
84
+ defaultConfirmationTimeoutMs: options.defaultConfirmationTimeoutMs ?? 300000,
85
+ pollIntervalMs: options.pollIntervalMs ?? 5000,
86
+ debug: options.debug ?? false,
87
+ };
88
+ }
89
+ /**
90
+ * Connect to the Midnight network.
91
+ *
92
+ * @param config - Proof server configuration
93
+ * @throws MidnightProverException on connection failure
94
+ */
95
+ async connect(config) {
96
+ this.debug("Connecting to Midnight network...");
97
+ try {
98
+ // Validate configuration
99
+ if (!config.proofServerUrl) {
100
+ throw new MidnightProverException(MidnightProverError.INVALID_INPUT, "Proof server URL is required");
101
+ }
102
+ // Mock connection - in production, this would establish network connection
103
+ await this.simulateNetworkDelay(50);
104
+ this.config = config;
105
+ this.connected = true;
106
+ this.debug(`Connected to ${config.proofServerUrl}`);
107
+ }
108
+ catch (error) {
109
+ if (error instanceof MidnightProverException) {
110
+ throw error;
111
+ }
112
+ throw new MidnightProverException(MidnightProverError.CONNECTION_FAILED, `Failed to connect to Midnight network: ${String(error)}`, error instanceof Error ? error : undefined);
113
+ }
114
+ }
115
+ /**
116
+ * Disconnect from the Midnight network.
117
+ */
118
+ async disconnect() {
119
+ if (this.connected) {
120
+ this.debug("Disconnecting from Midnight network...");
121
+ await this.simulateNetworkDelay(20);
122
+ this.connected = false;
123
+ this.config = undefined;
124
+ }
125
+ }
126
+ /**
127
+ * Check if connected to the network.
128
+ */
129
+ isConnected() {
130
+ return this.connected;
131
+ }
132
+ /**
133
+ * Get the current configuration.
134
+ */
135
+ getConfig() {
136
+ return this.config;
137
+ }
138
+ /**
139
+ * Publish a proof to the Midnight network.
140
+ *
141
+ * This method:
142
+ * 1. Validates the proof structure
143
+ * 2. Serializes the proof for transmission
144
+ * 3. Submits to the network with retry logic
145
+ * 4. Returns the publication result with transaction hash
146
+ *
147
+ * @param proof - The proof to publish
148
+ * @returns Publication result with Midnight transaction hash
149
+ * @throws MidnightProverException on failure after all retries
150
+ */
151
+ async publish(proof) {
152
+ this.ensureConnected();
153
+ this.debug(`Publishing proof: ${proof.proofId}`);
154
+ // Validate proof
155
+ this.validateProof(proof);
156
+ // Extract cardano anchor tx hash from proof if it has public inputs
157
+ const cardanoAnchorTxHash = this.extractCardanoAnchorTxHash(proof);
158
+ let lastError;
159
+ for (let attempt = 0; attempt < this.options.maxRetries; attempt++) {
160
+ try {
161
+ const result = await this.attemptPublish(proof, cardanoAnchorTxHash, attempt);
162
+ return result;
163
+ }
164
+ catch (error) {
165
+ lastError = error instanceof Error ? error : new Error(String(error));
166
+ this.debug(`Publication attempt ${attempt + 1} failed: ${lastError.message}`);
167
+ if (attempt < this.options.maxRetries - 1) {
168
+ const delay = this.calculateRetryDelay(attempt);
169
+ this.debug(`Retrying in ${delay}ms...`);
170
+ await this.delay(delay);
171
+ }
172
+ }
173
+ }
174
+ throw new MidnightProverException(MidnightProverError.PUBLICATION_FAILED, `Failed to publish proof after ${this.options.maxRetries} attempts`, lastError);
175
+ }
176
+ /**
177
+ * Get the status of a published proof.
178
+ *
179
+ * @param proofId - Unique proof identifier
180
+ * @returns Promise resolving to the proof status
181
+ */
182
+ async getProofStatus(proofId) {
183
+ this.ensureConnected();
184
+ await this.simulateNetworkDelay(30);
185
+ const record = this.publishedProofs.get(proofId);
186
+ if (!record) {
187
+ return {
188
+ status: "not_found",
189
+ proofId,
190
+ midnightTxHash: undefined,
191
+ blockNumber: undefined,
192
+ confirmations: 0,
193
+ timestamp: undefined,
194
+ error: undefined,
195
+ };
196
+ }
197
+ // Simulate confirmation progression over time
198
+ const elapsed = Date.now() - record.submittedAt;
199
+ if (record.status === "pending" && elapsed > 10000) {
200
+ record.status = "confirmed";
201
+ record.confirmations = Math.min(Math.floor(elapsed / 5000), 10);
202
+ }
203
+ else if (record.status === "confirmed") {
204
+ record.confirmations = Math.min(Math.floor(elapsed / 5000), 100);
205
+ }
206
+ return {
207
+ status: record.status,
208
+ proofId,
209
+ midnightTxHash: record.result.midnightTxHash,
210
+ blockNumber: record.result.blockNumber,
211
+ confirmations: record.confirmations,
212
+ timestamp: record.result.timestamp,
213
+ error: undefined,
214
+ };
215
+ }
216
+ /**
217
+ * Wait for a proof to be confirmed on the network.
218
+ *
219
+ * @param proofId - Unique proof identifier
220
+ * @param timeoutMs - Maximum time to wait in milliseconds (default: 5 minutes)
221
+ * @returns Promise resolving to true if confirmed, false if timeout
222
+ */
223
+ async waitForConfirmation(proofId, timeoutMs) {
224
+ this.ensureConnected();
225
+ const timeout = timeoutMs ?? this.options.defaultConfirmationTimeoutMs;
226
+ const startTime = Date.now();
227
+ this.debug(`Waiting for confirmation of proof ${proofId} (timeout: ${timeout}ms)`);
228
+ while (Date.now() - startTime < timeout) {
229
+ const status = await this.getProofStatus(proofId);
230
+ if (status.status === "confirmed") {
231
+ this.debug(`Proof ${proofId} confirmed with ${status.confirmations} confirmations`);
232
+ return true;
233
+ }
234
+ if (status.status === "failed") {
235
+ this.debug(`Proof ${proofId} failed: ${status.error ?? "unknown error"}`);
236
+ return false;
237
+ }
238
+ if (status.status === "not_found") {
239
+ this.debug(`Proof ${proofId} not found on network`);
240
+ return false;
241
+ }
242
+ // Wait before next poll
243
+ await this.delay(this.options.pollIntervalMs);
244
+ }
245
+ this.debug(`Confirmation timeout for proof ${proofId}`);
246
+ return false;
247
+ }
248
+ /**
249
+ * Get the publication result for a proof.
250
+ *
251
+ * @param proofId - Unique proof identifier
252
+ * @returns The publication result if found, undefined otherwise
253
+ */
254
+ getPublicationResult(proofId) {
255
+ return this.publishedProofs.get(proofId)?.result;
256
+ }
257
+ // ===========================================================================
258
+ // PRIVATE METHODS
259
+ // ===========================================================================
260
+ /**
261
+ * Ensure connected before operations.
262
+ */
263
+ ensureConnected() {
264
+ if (!this.connected) {
265
+ throw new MidnightProverException(MidnightProverError.CONNECTION_FAILED, "Not connected to Midnight network. Call connect() first.");
266
+ }
267
+ }
268
+ /**
269
+ * Validate a proof before publication.
270
+ */
271
+ validateProof(proof) {
272
+ if (!proof.proofId) {
273
+ throw new MidnightProverException(MidnightProverError.INVALID_INPUT, "Proof ID is required");
274
+ }
275
+ if (!proof.proof || proof.proof.length === 0) {
276
+ throw new MidnightProverException(MidnightProverError.INVALID_PROOF_FORMAT, "Proof data is empty");
277
+ }
278
+ if (!proof.proofType) {
279
+ throw new MidnightProverException(MidnightProverError.INVALID_INPUT, "Proof type is required");
280
+ }
281
+ }
282
+ /**
283
+ * Extract Cardano anchor transaction hash from proof public inputs.
284
+ */
285
+ extractCardanoAnchorTxHash(proof) {
286
+ // Type-safe access to publicInputs.cardanoAnchorTxHash
287
+ const anyProof = proof;
288
+ const txHash = anyProof.publicInputs?.cardanoAnchorTxHash;
289
+ if (!txHash) {
290
+ throw new MidnightProverException(MidnightProverError.MISSING_REQUIRED_FIELD, "Proof must have cardanoAnchorTxHash in public inputs for cross-chain linking");
291
+ }
292
+ return txHash;
293
+ }
294
+ /**
295
+ * Attempt to publish a proof (single attempt).
296
+ */
297
+ async attemptPublish(proof, cardanoAnchorTxHash, _attempt) {
298
+ // Simulate network submission
299
+ await this.simulateNetworkDelay(100 + Math.random() * 100);
300
+ // Generate mock transaction hash
301
+ const txInputData = canonicalize({
302
+ proofId: proof.proofId,
303
+ proofType: proof.proofType,
304
+ proofHash: await this.hashProofBytes(proof.proof),
305
+ timestamp: new Date().toISOString(),
306
+ });
307
+ const midnightTxHash = await sha256StringHex(PUBLICATION_DOMAIN_PREFIXES.txHash + txInputData);
308
+ // Simulate occasional network failures (10% failure rate on first attempt only)
309
+ // This ensures retries work but doesn't cause flaky tests
310
+ if (Math.random() < 0.1 && _attempt === 0) {
311
+ throw new Error("Simulated network failure");
312
+ }
313
+ const result = {
314
+ midnightTxHash,
315
+ proofId: proof.proofId,
316
+ timestamp: new Date().toISOString(),
317
+ cardanoAnchorTxHash,
318
+ blockNumber: Math.floor(100000 + Math.random() * 10000),
319
+ fee: BigInt(Math.floor(1000 + Math.random() * 500)),
320
+ };
321
+ // Store in mock registry
322
+ this.publishedProofs.set(proof.proofId, {
323
+ result,
324
+ status: "pending",
325
+ confirmations: 0,
326
+ submittedAt: Date.now(),
327
+ });
328
+ this.debug(`Proof published: ${midnightTxHash}`);
329
+ return result;
330
+ }
331
+ /**
332
+ * Hash proof bytes for transaction identification.
333
+ */
334
+ async hashProofBytes(proofBytes) {
335
+ // Create a copy to ensure ArrayBuffer type compatibility
336
+ const buffer = new ArrayBuffer(proofBytes.length);
337
+ new Uint8Array(buffer).set(proofBytes);
338
+ const hashBuffer = await crypto.subtle.digest("SHA-256", buffer);
339
+ const hashArray = new Uint8Array(hashBuffer);
340
+ return Array.from(hashArray)
341
+ .map((b) => b.toString(16).padStart(2, "0"))
342
+ .join("");
343
+ }
344
+ /**
345
+ * Calculate retry delay with exponential backoff.
346
+ */
347
+ calculateRetryDelay(attempt) {
348
+ const delay = this.options.retryDelayMs * Math.pow(2, attempt);
349
+ return Math.min(delay, this.options.maxRetryDelayMs);
350
+ }
351
+ /**
352
+ * Simulate network delay for mock operations.
353
+ */
354
+ async simulateNetworkDelay(baseMs) {
355
+ const jitter = Math.random() * baseMs * 0.2;
356
+ await this.delay(baseMs + jitter);
357
+ }
358
+ /**
359
+ * Delay helper.
360
+ */
361
+ delay(ms) {
362
+ return new Promise((resolve) => setTimeout(resolve, ms));
363
+ }
364
+ /**
365
+ * Debug logging helper.
366
+ */
367
+ debug(message) {
368
+ if (this.options.debug) {
369
+ console.log(`[ProofPublisher] ${message}`);
370
+ }
371
+ }
372
+ }
373
+ // =============================================================================
374
+ // FACTORY FUNCTION
375
+ // =============================================================================
376
+ /**
377
+ * Create a new ProofPublisher instance.
378
+ *
379
+ * @param options - Configuration options
380
+ * @returns New ProofPublisher instance
381
+ */
382
+ export function createProofPublisher(options) {
383
+ return new ProofPublisher(options);
384
+ }
385
+ //# sourceMappingURL=proof-publication.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proof-publication.js","sourceRoot":"","sources":["../../src/linking/proof-publication.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AASH,OAAO,EACL,mBAAmB,EACnB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AAoEvF;;GAEG;AACH,MAAM,2BAA2B,GAAG;IAClC,MAAM,EAAE,qBAAqB;IAC7B,OAAO,EAAE,wBAAwB;CACzB,CAAC;AAEX,gFAAgF;AAChF,kBAAkB;AAClB,gFAAgF;AAEhF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,OAAO,cAAc;IACR,OAAO,CAAkC;IAClD,MAAM,CAAgC;IACtC,SAAS,GAAG,KAAK,CAAC;IAE1B,2EAA2E;IAC1D,eAAe,GAAG,IAAI,GAAG,EAKtC,CAAC;IAEL;;;;OAIG;IACH,YAAY,UAAiC,EAAE;QAC7C,IAAI,CAAC,OAAO,GAAG;YACb,UAAU,EAAE,OAAO,CAAC,UAAU,IAAI,CAAC;YACnC,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,IAAI;YAC1C,eAAe,EAAE,OAAO,CAAC,eAAe,IAAI,KAAK;YACjD,4BAA4B,EAAE,OAAO,CAA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AAe,CAAC,CAAC;IACvD,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,oBAAoB,CAAC,MAAc;QAC/C,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,MAAM,GAAG,GAAG,CAAC;QAC5C,MAAM,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IACpC,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,EAAU;QACtB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,OAAe;QAC3B,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACvB,OAAO,CAAC,GAAG,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC;CACF;AAED,gFAAgF;AAChF,mBAAmB;AACnB,gFAAgF;AAEhF;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAA+B;IAE/B,OAAO,IAAI,cAAc,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @fileoverview Midnight circuit utilities exports.
3
+ *
4
+ * Location: packages/midnight-prover/src/midnight/index.ts
5
+ *
6
+ * Summary:
7
+ * This file exports all Midnight-specific utilities for witness building
8
+ * and public input construction. These components prepare data for
9
+ * submission to Midnight's Compact circuits.
10
+ *
11
+ * Usage:
12
+ * ```typescript
13
+ * import {
14
+ * buildHashChainWitness,
15
+ * buildPublicInputs,
16
+ * serializeWitness,
17
+ * } from "@fluxpointstudios/orynq-sdk-midnight-prover";
18
+ * ```
19
+ *
20
+ * Related files:
21
+ * - witness-builder.ts: Converts trace events to circuit-compatible witnesses
22
+ * - public-inputs.ts: Builds and serializes public inputs for proofs
23
+ */
24
+ export type { EventWitness, HashChainWitness, } from "./witness-builder.js";
25
+ export { buildHashChainWitness, serializeWitness, computeWitnessSize, validateWitness, } from "./witness-builder.js";
26
+ export type { HashChainPublicInputData, PolicyPublicInputData, AttestationPublicInputData, DisclosurePublicInputData, InferencePublicInputData, AnyPublicInputData, } from "./public-inputs.js";
27
+ export { buildPublicInputs, serializePublicInputs, hashPublicInputs, } from "./public-inputs.js";
28
+ export type { ProofResult, CircuitInfo, ProofServerClientOptions, } from "./proof-server-client.js";
29
+ export { ProofServerClient, createProofServerClient, } from "./proof-server-client.js";
30
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/midnight/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAMH,YAAY,EACV,YAAY,EACZ,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,GAChB,MAAM,sBAAsB,CAAC;AAM9B,YAAY,EACV,wBAAwB,EACxB,qBAAqB,EACrB,0BAA0B,EAC1B,yBAAyB,EACzB,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,oBAAoB,CAAC;AAM5B,YAAY,EACV,WAAW,EACX,WAAW,EACX,wBAAwB,GACzB,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,0BAA0B,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @fileoverview Midnight circuit utilities exports.
3
+ *
4
+ * Location: packages/midnight-prover/src/midnight/index.ts
5
+ *
6
+ * Summary:
7
+ * This file exports all Midnight-specific utilities for witness building
8
+ * and public input construction. These components prepare data for
9
+ * submission to Midnight's Compact circuits.
10
+ *
11
+ * Usage:
12
+ * ```typescript
13
+ * import {
14
+ * buildHashChainWitness,
15
+ * buildPublicInputs,
16
+ * serializeWitness,
17
+ * } from "@fluxpointstudios/orynq-sdk-midnight-prover";
18
+ * ```
19
+ *
20
+ * Related files:
21
+ * - witness-builder.ts: Converts trace events to circuit-compatible witnesses
22
+ * - public-inputs.ts: Builds and serializes public inputs for proofs
23
+ */
24
+ export { buildHashChainWitness, serializeWitness, computeWitnessSize, validateWitness, } from "./witness-builder.js";
25
+ export { buildPublicInputs, serializePublicInputs, hashPublicInputs, } from "./public-inputs.js";
26
+ export { ProofServerClient, createProofServerClient, } from "./proof-server-client.js";
27
+ //# sourceMappingURL=index.js.map