@midnightntwrk/midnight-js-http-client-proof-provider 0.0.0-stage → 5.0.2-0-pre.d76c0cbe

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 CHANGED
@@ -1,3 +1,265 @@
1
- # Temporary Holding Version
1
+ # HTTP Client Proof Provider
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ HTTP client for interacting with Midnight proof servers to generate zero-knowledge proofs.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ yarn add @midnightntwrk/midnight-js-http-client-proof-provider
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { httpClientProofProvider } from '@midnightntwrk/midnight-js-http-client-proof-provider';
15
+ import { LedgerTransaction } from '@midnightntwrk/midnight-js-types';
16
+ import { Transaction } from '@midnightntwrk/ledger-v9';
17
+
18
+ const proofProvider = httpClientProofProvider(
19
+ 'http://localhost:6300',
20
+ zkConfigProvider
21
+ );
22
+
23
+ // A transaction is passed to a provider as a handle that carries its era.
24
+ // The proven handle comes back in the same era.
25
+ const unprovenTx = LedgerTransaction.seal('v9', 'Unproven', ledgerUnprovenTx);
26
+ const provenTx = await proofProvider.proveTx(unprovenTx);
27
+ const ledgerProvenTx = provenTx.deserialize({ v9: Transaction });
28
+ ```
29
+
30
+ ## Configuration
31
+
32
+ | Option | Required | Default | Description |
33
+ | ------------------ | -------- | -------- | ---------------------------------------------- |
34
+ | `url` | ✓ | - | Proof server URL (http/https only) |
35
+ | `zkConfigProvider` | ✓ | - | Provider for ZK configuration artifacts |
36
+ | `timeout` | | `300000` | Request timeout in milliseconds (5 minutes) |
37
+
38
+ ## Architecture
39
+
40
+ This package provides two abstraction levels for proof generation:
41
+
42
+ ```
43
+ ProofProvider (httpClientProofProvider) - Transaction-level
44
+ ↓ uses internally
45
+ ProvingProvider (httpClientProvingProvider) - Circuit-level
46
+ ↓ HTTP requests
47
+ Proof Server (/check, /prove endpoints)
48
+ ```
49
+
50
+ ### High-Level: Transaction Proving
51
+
52
+ Use `httpClientProofProvider` for most use cases. It handles complete transactions by orchestrating individual circuit proofs internally.
53
+
54
+ ```typescript
55
+ import { httpClientProofProvider } from '@midnightntwrk/midnight-js-http-client-proof-provider';
56
+
57
+ const proofProvider = httpClientProofProvider(
58
+ 'http://localhost:6300',
59
+ zkConfigProvider
60
+ );
61
+
62
+ const provenTx = await proofProvider.proveTx(unprovenTx);
63
+ ```
64
+
65
+ ### Low-Level: Circuit Proving
66
+
67
+ Use `httpClientProvingProvider` for advanced scenarios requiring fine-grained control over individual circuit proving operations.
68
+
69
+ ```typescript
70
+ import { httpClientProvingProvider } from '@midnightntwrk/midnight-js-http-client-proof-provider';
71
+
72
+ const provingProvider = httpClientProvingProvider(
73
+ 'http://localhost:6300',
74
+ zkConfigProvider
75
+ );
76
+
77
+ const checkResult = await provingProvider.check(serializedPreimage, circuitId);
78
+ const proof = await provingProvider.prove(serializedPreimage, circuitId);
79
+ ```
80
+
81
+ ## API
82
+
83
+ ### ProofProvider (High-Level)
84
+
85
+ ```typescript
86
+ proveTx(
87
+ unprovenTx: UnprovenTx,
88
+ proveTxConfig?: ProveTxConfig
89
+ ): Promise<UnboundTx>
90
+ ```
91
+
92
+ Proves all circuits in a transaction and returns the proven transaction.
93
+
94
+ The argument and the result are transaction handles from
95
+ `@midnightntwrk/midnight-js-types`. The result has the same era as the
96
+ argument. Read the ledger object with your own ledger copy:
97
+ `provenTx.deserialize({ v9: Transaction })`. This provider serves both
98
+ eras: `supportedEras` is `['v8', 'v9']`.
99
+
100
+ ### ProvingProvider (Low-Level)
101
+
102
+ ```typescript
103
+ check(serializedPreimage: Uint8Array, keyLocation: string): Promise<(bigint | undefined)[]>
104
+ ```
105
+
106
+ Validates circuit inputs before proof generation.
107
+
108
+ ```typescript
109
+ prove(serializedPreimage: Uint8Array, keyLocation: string, overwriteBindingInput?: bigint): Promise<Uint8Array>
110
+ ```
111
+
112
+ Generates a zero-knowledge proof for a circuit.
113
+
114
+ ## URL Configuration
115
+
116
+ The provider supports complex URL configurations including path prefixes and query parameters.
117
+
118
+ ### Path Prefix
119
+
120
+ ```typescript
121
+ const proofProvider = httpClientProofProvider(
122
+ 'http://localhost:6300/api/v1',
123
+ zkConfigProvider
124
+ );
125
+ // Endpoints: /api/v1/check, /api/v1/prove
126
+ ```
127
+
128
+ ### Query Parameters
129
+
130
+ ```typescript
131
+ const proofProvider = httpClientProofProvider(
132
+ 'http://localhost:6300?token=your-api-key',
133
+ zkConfigProvider
134
+ );
135
+ // Endpoints: /check?token=your-api-key, /prove?token=your-api-key
136
+ ```
137
+
138
+ ### Combined Path and Query
139
+
140
+ ```typescript
141
+ const proofProvider = httpClientProofProvider(
142
+ 'http://localhost:6300/api/v1?token=your-api-key&env=production',
143
+ zkConfigProvider
144
+ );
145
+ // Endpoints: /api/v1/check?token=your-api-key&env=production
146
+ ```
147
+
148
+ ### URL Behavior
149
+
150
+ | Base URL | /check Endpoint | /prove Endpoint |
151
+ | --------------------------------- | --------------------------------------- | --------------------------------------- |
152
+ | `http://localhost:6300` | `/check` | `/prove` |
153
+ | `http://localhost:6300/` | `/check` | `/prove` |
154
+ | `http://localhost:6300/api/v1` | `/api/v1/check` | `/api/v1/prove` |
155
+ | `http://localhost:6300/api/v1/` | `/api/v1/check` | `/api/v1/prove` |
156
+ | `http://localhost:6300?token=abc` | `/check?token=abc` | `/prove?token=abc` |
157
+
158
+ ## Timeout Configuration
159
+
160
+ ```typescript
161
+ const proofProvider = httpClientProofProvider(
162
+ 'http://localhost:6300',
163
+ zkConfigProvider,
164
+ { timeout: 60000 } // 60 seconds
165
+ );
166
+ ```
167
+
168
+ ## Retry Behavior
169
+
170
+ The provider automatically retries failed requests with exponential backoff:
171
+
172
+ | Attempt | Delay | Retried Status Codes |
173
+ | ------- | -------- | -------------------- |
174
+ | 1 | 1 second | 500, 503 |
175
+ | 2 | 2 seconds| 500, 503 |
176
+ | 3 | 4 seconds| 500, 503 |
177
+
178
+ ## Error Handling
179
+
180
+ ### Invalid Protocol
181
+
182
+ Only `http:` and `https:` protocols are supported.
183
+
184
+ ```typescript
185
+ // Throws InvalidProtocolSchemeError
186
+ httpClientProofProvider('ws://localhost:6300', zkConfigProvider);
187
+ ```
188
+
189
+ ### Server Errors
190
+
191
+ HTTP errors throw with details about the failed request:
192
+
193
+ ```
194
+ Failed Proof Server response: url="http://localhost:6300/prove", code="500", status="Internal Server Error"
195
+ ```
196
+
197
+ ## Exports
198
+
199
+ ```typescript
200
+ import {
201
+ // High-level: Transaction proving
202
+ httpClientProofProvider,
203
+ DEFAULT_CONFIG,
204
+
205
+ // Low-level: Circuit proving
206
+ httpClientProvingProvider,
207
+ DEFAULT_TIMEOUT,
208
+ type ProvingProviderConfig
209
+ } from '@midnightntwrk/midnight-js-http-client-proof-provider';
210
+ ```
211
+
212
+ ## Detailed
213
+
214
+ ### Server Endpoints
215
+
216
+ | Endpoint | Method | Description |
217
+ | -------- | ------ | ---------------------------------- |
218
+ | `/check` | POST | Validate circuit inputs |
219
+ | `/prove` | POST | Generate zero-knowledge proof |
220
+
221
+ ### Default Values
222
+
223
+ | Constant | Value | Description |
224
+ | ----------------- | -------- | ------------------------ |
225
+ | `DEFAULT_TIMEOUT` | `300000` | 5 minutes in ms |
226
+
227
+ ### Request Flow
228
+
229
+ ```
230
+ ┌─────────────────────────────────────────────────────────────────┐
231
+ │ httpClientProofProvider │
232
+ │ │
233
+ │ ┌──────────────────┐ │
234
+ │ │ proveTx() │ │
235
+ │ │ (transaction) │ │
236
+ │ └────────┬─────────┘ │
237
+ │ │ │
238
+ │ ▼ │
239
+ │ ┌──────────────────────────────────────────────────────┐ │
240
+ │ │ httpClientProvingProvider │ │
241
+ │ │ │ │
242
+ │ │ ┌─────────────┐ ┌─────────────┐ ┌──────────┐ │ │
243
+ │ │ │ ZKConfig │───►│ check() │───►│ /check │ │ │
244
+ │ │ │ Provider │ │ prove() │───►│ /prove │ │ │
245
+ │ │ └─────────────┘ └─────────────┘ └──────────┘ │ │
246
+ │ │ │ │ │ │
247
+ │ │ ▼ ▼ │ │
248
+ │ │ ┌─────────────────────────────┐ │ │
249
+ │ │ │ Retry Logic (3 attempts) │ │ │
250
+ │ │ │ Exponential backoff │ │ │
251
+ │ │ └─────────────────────────────┘ │ │
252
+ │ └──────────────────────────────────────────────────────┘ │
253
+ └─────────────────────────────────────────────────────────────────┘
254
+ ```
255
+
256
+ ## Resources
257
+
258
+ - [Midnight Network](https://midnight.network)
259
+ - [Developer Hub](https://midnight.network/developer-hub)
260
+
261
+ ## Terms & License
262
+
263
+ By using this package, you agree to [Midnight's Terms and Conditions](https://midnight.network/static/terms.pdf) and [Privacy Policy](https://midnight.network/static/privacy-policy.pdf).
264
+
265
+ Licensed under [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0).
@@ -0,0 +1,73 @@
1
+ import { ZKConfigProvider, ZKConfigRegistry, ProofProvider } from '@midnightntwrk/midnight-js-types';
2
+ import { ProvingProvider } from '@midnightntwrk/midnight-js-protocol/v9';
3
+
4
+ declare const DEFAULT_TIMEOUT = 300000;
5
+ interface ProvingProviderConfig {
6
+ readonly timeout?: number;
7
+ readonly headers?: Record<string, string>;
8
+ }
9
+ /**
10
+ * A {@link ProvingProvider} whose per-circuit `check`/`prove` calls accept an optional per-request
11
+ * timeout override. The extra parameter is optional and trailing, so this type stays assignable to
12
+ * `ProvingProvider`; callers that don't need per-request control can ignore it. Used by
13
+ * `httpClientProofProvider` to honor a per-`proveTx` timeout without rebuilding the underlying
14
+ * provider — see https://github.com/midnightntwrk/midnight-js/issues/974.
15
+ */
16
+ interface TimeoutAwareProvingProvider extends ProvingProvider {
17
+ check(serializedPreimage: Uint8Array, keyLocation: string, overrideTimeout?: number): Promise<(bigint | undefined)[]>;
18
+ prove(serializedPreimage: Uint8Array, keyLocation: string, overwriteBindingInput?: bigint, overrideTimeout?: number): Promise<Uint8Array>;
19
+ }
20
+ declare const httpClientProvingProvider: <K extends string>(url: string, zkConfigProvider: ZKConfigProvider<K> | ZKConfigRegistry, config?: ProvingProviderConfig) => TimeoutAwareProvingProvider;
21
+
22
+ declare const DEFAULT_CONFIG: {
23
+ timeout: number;
24
+ zkConfig: undefined;
25
+ };
26
+ /**
27
+ * Options for {@link httpClientProofProvider}. The connection fields (`url`, `zkConfigProvider`)
28
+ * are combined with the underlying {@link ProvingProviderConfig} into a single flat object.
29
+ */
30
+ interface HttpClientProofProviderOptions<K extends string> extends ProvingProviderConfig {
31
+ /** The URL of the proof server. */
32
+ readonly url: string;
33
+ /** Provider for zero-knowledge configuration artifacts. */
34
+ readonly zkConfigProvider: ZKConfigProvider<K> | ZKConfigRegistry;
35
+ }
36
+ /**
37
+ * Creates a high-level {@link ProofProvider} that implements transaction-level proving
38
+ * using the low-level circuit-by-circuit {@link ProvingProvider} as its foundation.
39
+ *
40
+ * This adapter bridges the gap between:
41
+ * - High-level ProofProvider interface (works with complete transactions)
42
+ * - Low-level ProvingProvider interface (works with individual circuits)
43
+ *
44
+ * @param options Connection and proving configuration — see {@link HttpClientProofProviderOptions}
45
+ * @returns A ProofProvider instance that uses ProvingProvider internally
46
+ *
47
+ * @remarks
48
+ * **Architecture:**
49
+ * ```
50
+ * ProofProvider (Transaction-level)
51
+ * ↓ (adapter)
52
+ * ProvingProvider (Circuit-level)
53
+ * ↓ (HTTP client)
54
+ * Proof Server (/check, /prove endpoints)
55
+ * ```
56
+ *
57
+ * **Note:** The /prove-tx endpoint is NOT used. All proving is done through
58
+ * individual circuit operations using /check and /prove endpoints.
59
+ */
60
+ declare function httpClientProofProvider<K extends string>(options: HttpClientProofProviderOptions<K>): ProofProvider;
61
+ /**
62
+ * @deprecated Use the {@link HttpClientProofProviderOptions} object form:
63
+ * `httpClientProofProvider({ url, zkConfigProvider })`.
64
+ *
65
+ * @param url The URL of the proof server
66
+ * @param zkConfigProvider Provider for zero-knowledge configuration artifacts
67
+ * @param config Optional configuration for the underlying ProvingProvider
68
+ * @returns A ProofProvider instance that uses ProvingProvider internally
69
+ */
70
+ declare function httpClientProofProvider<K extends string>(url: string, zkConfigProvider: ZKConfigProvider<K> | ZKConfigRegistry, config?: ProvingProviderConfig): ProofProvider;
71
+
72
+ export { DEFAULT_CONFIG, DEFAULT_TIMEOUT, httpClientProofProvider, httpClientProvingProvider };
73
+ export type { ProvingProviderConfig };
package/dist/index.js ADDED
@@ -0,0 +1,195 @@
1
+ import { loadLedger8Protocol } from '@midnightntwrk/midnight-js-protocol';
2
+ import { ConfigurationError } from '@midnightntwrk/midnight-js-protocol/errors';
3
+ import { proveLedger8Transaction } from '@midnightntwrk/midnight-js-protocol/prove';
4
+ import { createProvingPayload, createCheckPayload, parseCheckResult, Transaction, CostModel } from '@midnightntwrk/midnight-js-protocol/v9';
5
+ import { InvalidProtocolSchemeError, ZKConfigRegistry, zkConfigToProvingKeyMaterial, PROVIDER_ERROR_CODES, ProofServerError, createProofProviderFromHandlers } from '@midnightntwrk/midnight-js-types';
6
+ import { warnIfInsecureRemoteUrl, ZkArtifactIntegrityError, hasErrorCode } from '@midnightntwrk/midnight-js-utils';
7
+ import fetch from 'cross-fetch';
8
+ import fetchBuilder from 'fetch-retry';
9
+
10
+ /*
11
+ * This file is part of midnight-js.
12
+ * Copyright (C) Midnight Foundation
13
+ * SPDX-License-Identifier: Apache-2.0
14
+ * Licensed under the Apache License, Version 2.0 (the "License");
15
+ * You may not use this file except in compliance with the License.
16
+ * You may obtain a copy of the License at
17
+ * http://www.apache.org/licenses/LICENSE-2.0
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ */
24
+ const retryOptions = {
25
+ retries: 3,
26
+ retryDelay: (attempt) => 2 ** attempt * 1_000,
27
+ retryOn: [500, 503]
28
+ };
29
+ const fetchRetry = fetchBuilder(fetch, retryOptions);
30
+ const CHECK_PATH = '/check';
31
+ const PROVE_PATH = '/prove';
32
+ const buildEndpointUrl = (baseUrl, endpoint) => {
33
+ const url = new URL(baseUrl);
34
+ url.pathname = url.pathname.replace(/\/$/, '') + endpoint;
35
+ return url;
36
+ };
37
+ const DEFAULT_TIMEOUT = 300000;
38
+ /**
39
+ * Resolves the ZK key material for a proof preimage's key location.
40
+ *
41
+ * Canonical contract key locations (one per contract call; see `ZKConfigRegistry`) are resolved
42
+ * through the registry's verifier-key join — throwing the registry's artifact-drift error when no
43
+ * bundle matches, since proving would be guaranteed to fail. Other locations are protocol
44
+ * builtins (`midnight/...`), which resolve to `undefined` key material and are supplied by the
45
+ * proof server; when a single flat provider was given, a non-canonical location is also tried
46
+ * against it as a bare circuit name.
47
+ */
48
+ const makeKeyMaterialResolver = (zkConfigProvider) => {
49
+ const registry = zkConfigProvider instanceof ZKConfigRegistry ? zkConfigProvider : new ZKConfigRegistry([zkConfigProvider]);
50
+ const flatProvider = zkConfigProvider instanceof ZKConfigRegistry ? undefined : zkConfigProvider;
51
+ return async (keyLocation) => {
52
+ const resolved = await registry.resolveKeyLocation(keyLocation);
53
+ if (resolved !== undefined) {
54
+ return zkConfigToProvingKeyMaterial(resolved);
55
+ }
56
+ if (flatProvider === undefined) {
57
+ return undefined;
58
+ }
59
+ try {
60
+ return zkConfigToProvingKeyMaterial(await flatProvider.get(keyLocation));
61
+ }
62
+ catch (error) {
63
+ // A flat provider legitimately doesn't serve protocol builtins (or bare names it lacks); those
64
+ // resolve to `undefined` and are supplied by the proof server. A tampered artifact or an
65
+ // artifact source that is down says nothing about absence, so it must surface rather than be
66
+ // masked as "no key material" sent to the proof server.
67
+ if (error instanceof ZkArtifactIntegrityError || hasErrorCode(error, PROVIDER_ERROR_CODES.ZK_ARTIFACT_FETCH_FAILED)) {
68
+ throw error;
69
+ }
70
+ return undefined;
71
+ }
72
+ };
73
+ };
74
+ const makeHttpRequest = async (url, payload, timeout, headers = {}) => {
75
+ let response;
76
+ try {
77
+ response = await fetchRetry(url, {
78
+ method: 'POST',
79
+ body: new Uint8Array(payload),
80
+ headers: { 'Content-Type': 'application/octet-stream', ...headers },
81
+ signal: AbortSignal.timeout(timeout)
82
+ });
83
+ }
84
+ catch (cause) {
85
+ throw new ProofServerError(`Proof Server request failed: url="${url}"`, undefined, { cause });
86
+ }
87
+ if (!response.ok) {
88
+ throw new ProofServerError(`Failed Proof Server response: url="${response.url}", code="${response.status}", status="${response.statusText}"`, response.status);
89
+ }
90
+ try {
91
+ return new Uint8Array(await response.arrayBuffer());
92
+ }
93
+ catch (cause) {
94
+ throw new ProofServerError(`Proof Server response could not be read: url="${url}"`, undefined, { cause });
95
+ }
96
+ };
97
+ const httpClientProvingProvider = (url, zkConfigProvider, config) => {
98
+ const getKeyMaterial = makeKeyMaterialResolver(zkConfigProvider);
99
+ const checkUrl = buildEndpointUrl(url, CHECK_PATH);
100
+ const proveUrl = buildEndpointUrl(url, PROVE_PATH);
101
+ if (checkUrl.protocol !== 'http:' && checkUrl.protocol !== 'https:') {
102
+ throw new InvalidProtocolSchemeError(checkUrl.protocol, ['http:', 'https:']);
103
+ }
104
+ if (proveUrl.protocol !== 'http:' && proveUrl.protocol !== 'https:') {
105
+ throw new InvalidProtocolSchemeError(proveUrl.protocol, ['http:', 'https:']);
106
+ }
107
+ warnIfInsecureRemoteUrl(url, 'proof server URL');
108
+ const timeout = config?.timeout ?? DEFAULT_TIMEOUT;
109
+ const headers = config?.headers ?? {};
110
+ return {
111
+ async check(serializedPreimage, keyLocation, overrideTimeout) {
112
+ const keyMaterial = await getKeyMaterial(keyLocation);
113
+ const payload = createCheckPayload(serializedPreimage, keyMaterial?.ir);
114
+ const result = await makeHttpRequest(checkUrl, payload, overrideTimeout ?? timeout, headers);
115
+ return parseCheckResult(result);
116
+ },
117
+ async prove(serializedPreimage, keyLocation, overwriteBindingInput, overrideTimeout) {
118
+ const keyMaterial = await getKeyMaterial(keyLocation);
119
+ const payload = createProvingPayload(serializedPreimage, overwriteBindingInput, keyMaterial);
120
+ return makeHttpRequest(proveUrl, payload, overrideTimeout ?? timeout, headers);
121
+ },
122
+ lookupKey: getKeyMaterial
123
+ };
124
+ };
125
+
126
+ /*
127
+ * This file is part of midnight-js.
128
+ * Copyright (C) Midnight Foundation
129
+ * SPDX-License-Identifier: Apache-2.0
130
+ * Licensed under the Apache License, Version 2.0 (the "License");
131
+ * You may not use this file except in compliance with the License.
132
+ * You may obtain a copy of the License at
133
+ * http://www.apache.org/licenses/LICENSE-2.0
134
+ * Unless required by applicable law or agreed to in writing, software
135
+ * distributed under the License is distributed on an "AS IS" BASIS,
136
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137
+ * See the License for the specific language governing permissions and
138
+ * limitations under the License.
139
+ */
140
+ const DEFAULT_CONFIG = {
141
+ timeout: DEFAULT_TIMEOUT,
142
+ zkConfig: undefined
143
+ };
144
+ /**
145
+ * Resolves the timeout for a `proveTx` call. Precedence: per-call `proveTxConfig.timeout` >
146
+ * construction-time `config.timeout` > `DEFAULT_TIMEOUT`. The per-call value was previously
147
+ * discarded, so a caller-supplied timeout had no effect — see
148
+ * https://github.com/midnightntwrk/midnight-js/issues/974.
149
+ */
150
+ const resolveTimeout = (constructionConfig, proveTxConfig) => proveTxConfig?.timeout ?? constructionConfig?.timeout ?? DEFAULT_TIMEOUT;
151
+ function httpClientProofProvider(optionsOrUrl, zkConfigProvider, config) {
152
+ let url;
153
+ let resolvedZkConfigProvider;
154
+ let resolvedConfig;
155
+ if (typeof optionsOrUrl === 'string') {
156
+ if (zkConfigProvider === undefined) {
157
+ throw new ConfigurationError('zkConfigProvider is required when calling the positional httpClientProofProvider overload');
158
+ }
159
+ url = optionsOrUrl;
160
+ resolvedZkConfigProvider = zkConfigProvider;
161
+ resolvedConfig = config;
162
+ }
163
+ else {
164
+ const { url: optionsUrl, zkConfigProvider: optionsZkConfigProvider, ...rest } = optionsOrUrl;
165
+ url = optionsUrl;
166
+ resolvedZkConfigProvider = optionsZkConfigProvider;
167
+ resolvedConfig = rest;
168
+ }
169
+ // Build the underlying ProvingProvider once at construction time so URL validation
170
+ // (InvalidProtocolSchemeError) and the insecure-URL warning fire eagerly here — at wiring time —
171
+ // rather than being deferred to (and repeated on) every proveTx call.
172
+ const baseProvingProvider = httpClientProvingProvider(url, resolvedZkConfigProvider, resolvedConfig);
173
+ // Wraps the construction-time provider so every circuit-level check/prove in one `proveTx` uses
174
+ // that call's timeout, without rebuilding the underlying provider. The timeout override is
175
+ // exposed by TimeoutAwareProvingProvider, so this needs no cast. Shared by both era handlers because
176
+ // both drive the same proof server through the same per-call timeout — the proving protocol is
177
+ // per-circuit and era-independent.
178
+ const provingProviderFor = (proveTxConfig) => {
179
+ const perCallTimeout = resolveTimeout(resolvedConfig, proveTxConfig);
180
+ return {
181
+ check: (serializedPreimage, keyLocation) => baseProvingProvider.check(serializedPreimage, keyLocation, perCallTimeout),
182
+ prove: (serializedPreimage, keyLocation, overwriteBindingInput) => baseProvingProvider.prove(serializedPreimage, keyLocation, overwriteBindingInput, perCallTimeout),
183
+ lookupKey: (keyLocation) => baseProvingProvider.lookupKey(keyLocation)
184
+ };
185
+ };
186
+ // One handler per era, with the routing, the sealing of the answer in the era of the request and
187
+ // the refusal of an era with no handler all left to the factory.
188
+ return createProofProviderFromHandlers({
189
+ v8: async (tx, proveTxConfig) => proveLedger8Transaction(tx.deserialize({ v8: (await loadLedger8Protocol()).Transaction }), provingProviderFor(proveTxConfig)),
190
+ v9: (tx, proveTxConfig) => tx.deserialize({ v9: Transaction }).prove(provingProviderFor(proveTxConfig), CostModel.initialCostModel())
191
+ });
192
+ }
193
+
194
+ export { DEFAULT_CONFIG, DEFAULT_TIMEOUT, httpClientProofProvider, httpClientProvingProvider };
195
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/http-client-proving-provider.ts","../src/http-client-proof-provider.ts"],"sourcesContent":[null,null],"names":[],"m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wBAAwB,GAAG,uBAAuB;QAClD,cAAc,GAAG,IAAI;IACvB;;;;IAKA,MAAM,mBAAmB,GAAG,yBAAyB,CAAC,GAAG,EAAE,wBAAwB,EAAE,cAAc,CAAC;;;;;;AAOpG,IAAA,MAAM,kBAAkB,GAAG,CAAC,aAAwC,KAAqB;QACvF,MAAM,cAAc,GAAG,cAAc,CAAC,cAAc,EAAE,aAAa,CAAC;QACpE,OAAO;AACL,YAAA,KAAK,EAAE,CAAC,kBAAkB,EAAE,WAAW,KACrC,mBAAmB,CAAC,KAAK,CAAC,kBAAkB,EAAE,WAAW,EAAE,cAAc,CAAC;YAC5E,KAAK,EAAE,CAAC,kBAAkB,EAAE,WAAW,EAAE,qBAAqB,KAC5D,mBAAmB,CAAC,KAAK,CAAC,kBAAkB,EAAE,WAAW,EAAE,qBAAqB,EAAE,cAAc,CAAC;YACnG,SAAS,EAAE,CAAC,WAAW,KAAK,mBAAmB,CAAC,SAAS,CAAC,WAAW;SACtE;AACH,IAAA,CAAC;;;AAID,IAAA,OAAO,+BAA+B,CAAC;AACrC,QAAA,EAAE,EAAE,OAAO,EAAE,EAAE,aAAa,KAC1B,uBAAuB,CAAC,EAAE,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,CAAC,MAAM,mBAAmB,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE,kBAAkB,CAAC,aAAa,CAAC,CAAC;AAC/H,QAAA,EAAE,EAAE,CAAC,EAAE,EAAE,aAAa,KACpB,EAAE,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,kBAAkB,CAAC,aAAa,CAAC,EAAE,SAAS,CAAC,gBAAgB,EAAE;AAC5G,KAAA,CAAC;AACJ;;"}
package/package.json CHANGED
@@ -1,6 +1,53 @@
1
1
  {
2
2
  "name": "@midnightntwrk/midnight-js-http-client-proof-provider",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "5.0.2-0-pre.d76c0cbe",
4
+ "type": "module",
5
+ "description": "Implementation of proof provider based on the Midnight ledger proof server",
6
+ "types": "dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ }
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/midnightntwrk/midnight-js.git",
16
+ "directory": "packages/http-client-proof-provider"
17
+ },
18
+ "homepage": "https://github.com/midnightntwrk/midnight-js/tree/main/packages/http-client-proof-provider#readme",
19
+ "bugs": {
20
+ "url": "https://github.com/midnightntwrk/midnight-js/issues"
21
+ },
22
+ "author": "Midnight Foundation",
23
+ "packageManager": "yarn@4.14.1",
24
+ "license": "Apache-2.0",
25
+ "scripts": {
26
+ "clean": "rm -rf dist tsconfig.build.tsbuildinfo .rollup.cache reports coverage logs src/test/resources/compiled",
27
+ "compact": "yarn fetch-compactc && yarn compact-simple",
28
+ "compact-simple": "run-compactc src/test/resources/simple.compact ./src/test/resources/compiled/simple",
29
+ "build": "rollup -c rollup.config.mjs",
30
+ "test": "node ../../scripts/check-compiled.js src/test/resources/compiled && vitest run"
31
+ },
32
+ "files": [
33
+ "dist/"
34
+ ],
35
+ "dependencies": {
36
+ "@midnightntwrk/midnight-js-protocol": "5.0.2-0-pre.d76c0cbe",
37
+ "@midnightntwrk/midnight-js-types": "5.0.2-0-pre.d76c0cbe",
38
+ "@midnightntwrk/midnight-js-utils": "5.0.2-0-pre.d76c0cbe",
39
+ "cross-fetch": "^4.1.0",
40
+ "fetch-retry": "^6.0.0"
41
+ },
42
+ "devDependencies": {
43
+ "@midnightntwrk/midnight-js-compact": "5.0.2-0-pre.d76c0cbe",
44
+ "@midnightntwrk/midnight-js-contracts": "5.0.2-0-pre.d76c0cbe",
45
+ "rollup": "^4.68.2",
46
+ "vite": "^8.3.4",
47
+ "vitest": "^5.0.4"
48
+ },
49
+ "engines": {
50
+ "node": ">=22.12"
51
+ },
52
+ "stableVersion": "5.0.1"
6
53
  }