@midnight-ntwrk/wallet-sdk-prover-client 2.0.0-beta.2 → 2.0.0-beta.3

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
@@ -57,6 +57,34 @@ class HttpProverClient {
57
57
  }
58
58
  ```
59
59
 
60
+ ### Proving providers, per ledger version
61
+
62
+ A proof preimage is produced by the ledger version that built the transaction, and the request carrying it has to be
63
+ framed and read back by that same version. `HttpProverClient` therefore offers one provider per ledger version:
64
+
65
+ ```typescript
66
+ const client = await Effect.runPromise(HttpProverClient.create({ url: proofServerUrl }));
67
+
68
+ client.asV9ProvingProvider(); // frames with @midnightntwrk/ledger-v9; asProvingProvider() is the same provider
69
+ client.asV8ProvingProvider(); // frames with @midnight-ntwrk/ledger-v8
70
+ ```
71
+
72
+ `WasmProver` offers both names too, and returns the same provider for each: the in-process prover drives a zkir runtime
73
+ over bytes and never looks at a ledger version.
74
+
75
+ Its key material is read from a published bucket, one line per circuit generation rather than per ledger:
76
+
77
+ ```typescript
78
+ WasmProver.makeDefaultKeyMaterialProvider(); // the line both ledger versions accept
79
+ WasmProver.makeDefaultKeyMaterialProvider({ circuits: 8 }); // an explicit override
80
+ ```
81
+
82
+ The default is what both ledger versions accept today; `circuits` exists so an operator whose bucket says otherwise can
83
+ say so, not because a fork implies a change of line.
84
+
85
+ > This package depends on both ledger runtimes, `@midnight-ntwrk/ledger-v8` and `@midnightntwrk/ledger-v9`. Both are
86
+ > WASM modules, so a direct consumer bundling this package ships both.
87
+
60
88
  ## Exports
61
89
 
62
90
  ### Default Export
@@ -15,9 +15,20 @@ import { FetchHttpClient, HttpBody, HttpClient, HttpClientRequest } from '@effec
15
15
  import { ProverClient } from './ProverClient.js';
16
16
  import { ClientError, HttpURL, ServerError, } from '@midnight-ntwrk/wallet-sdk-utilities/networking';
17
17
  import { BlobOps, EitherOps } from '@midnight-ntwrk/wallet-sdk-utilities';
18
- import * as ledger from '@midnightntwrk/ledger-v9';
18
+ import * as ledgerV8 from '@midnight-ntwrk/ledger-v8';
19
+ import * as ledgerV9 from '@midnightntwrk/ledger-v9';
19
20
  const PROVE_TX_PATH = '/prove';
20
21
  const CHECK_TX_PATH = '/check';
22
+ const v9Framing = {
23
+ createProvingPayload: (preimage, binding) => ledgerV9.createProvingPayload(preimage, binding),
24
+ createCheckPayload: (preimage) => ledgerV9.createCheckPayload(preimage),
25
+ parseCheckResult: (result) => ledgerV9.parseCheckResult(result),
26
+ };
27
+ const v8Framing = {
28
+ createProvingPayload: (preimage, binding) => ledgerV8.createProvingPayload(preimage, binding),
29
+ createCheckPayload: (preimage) => ledgerV8.createCheckPayload(preimage),
30
+ parseCheckResult: (result) => ledgerV8.parseCheckResult(result),
31
+ };
21
32
  /**
22
33
  * Creates a layer for a {@link ProverClient} that sends requests to a Proof Server over HTTP.
23
34
  *
@@ -65,15 +76,15 @@ class HttpProverClientImpl {
65
76
  ResponseError: (err) => Effect.orElseSucceed(err.response.text, () => 'Unknown server error').pipe(Effect.flatMap((message) => new ServerError({ message }))),
66
77
  }), Effect.provide(FetchHttpClient.layer));
67
78
  }
68
- serverProverProvider = () => ({
69
- check: async (serializedPreimage, _keyLocation) => pipe(Effect.succeed(ledger.createCheckPayload(serializedPreimage)), Effect.flatMap((tx) => this.request(CHECK_TX_PATH, tx, 'Failed to check')), Effect.map((response) => ledger.parseCheckResult(response)), Effect.runPromise),
70
- prove: async (serializedPreimage, _keyLocation, overwriteBindingInput) => pipe(Effect.succeed(ledger.createProvingPayload(serializedPreimage, overwriteBindingInput)), Effect.flatMap((tx) => this.request(PROVE_TX_PATH, tx, 'Failed to prove')), Effect.runPromise),
79
+ serverProverProvider = (framing) => ({
80
+ check: async (serializedPreimage, _keyLocation) => pipe(Effect.succeed(framing.createCheckPayload(serializedPreimage)), Effect.flatMap((tx) => this.request(CHECK_TX_PATH, tx, 'Failed to check')), Effect.map((response) => framing.parseCheckResult(response)), Effect.runPromise),
81
+ prove: async (serializedPreimage, _keyLocation, overwriteBindingInput) => pipe(Effect.succeed(framing.createProvingPayload(serializedPreimage, overwriteBindingInput)), Effect.flatMap((tx) => this.request(PROVE_TX_PATH, tx, 'Failed to prove')), Effect.runPromise),
71
82
  // The proof server holds its own key material and resolves circuits from the
72
83
  // preimage's key location, so there is never local key material to provide.
73
84
  lookupKey: (_keyLocation) => Promise.resolve(undefined),
74
85
  });
75
86
  proveTransaction(transaction, costModel) {
76
- return pipe(Effect.succeed(this.serverProverProvider()), Effect.flatMap((provider) => Effect.tryPromise({
87
+ return pipe(Effect.succeed(this.serverProverProvider(v9Framing)), Effect.flatMap((provider) => Effect.tryPromise({
77
88
  try: () => transaction.prove(provider, costModel),
78
89
  catch: (error) => error instanceof ClientError || error instanceof ServerError
79
90
  ? error
@@ -81,6 +92,12 @@ class HttpProverClientImpl {
81
92
  })));
82
93
  }
83
94
  asProvingProvider() {
84
- return this.serverProverProvider();
95
+ return this.serverProverProvider(v9Framing);
96
+ }
97
+ asV9ProvingProvider() {
98
+ return this.asProvingProvider();
99
+ }
100
+ asV8ProvingProvider() {
101
+ return this.serverProverProvider(v8Framing);
85
102
  }
86
103
  }
@@ -1,5 +1,6 @@
1
1
  import { type Effect, Context } from 'effect';
2
- import type * as ledger from '@midnightntwrk/ledger-v9';
2
+ import type * as ledgerV8 from '@midnight-ntwrk/ledger-v8';
3
+ import type * as ledgerV9 from '@midnightntwrk/ledger-v9';
3
4
  import { type ClientError, type ServerError } from '@midnight-ntwrk/wallet-sdk-utilities/networking';
4
5
  import type { KeyMaterialProvider } from '@midnight-ntwrk/zkir-v2';
5
6
  declare const ProverClient_base: Context.TagClass<ProverClient, "@midnight-ntwrk/prover-client#ProverClient", ProverClient.Service>;
@@ -25,8 +26,21 @@ export declare namespace ProverClient {
25
26
  * @returns An `Effect` that yields with a serialized transaction representing the proven version of `transaction`;
26
27
  * or fails with a client or server side error.
27
28
  */
28
- proveTransaction<S extends ledger.Signaturish, B extends ledger.Bindingish>(tx: ledger.Transaction<S, ledger.PreProof, B>, costModel?: ledger.CostModel): Effect.Effect<ledger.Transaction<S, ledger.Proof, B>, ClientError | ServerError>;
29
- asProvingProvider(): ledger.ProvingProvider;
29
+ proveTransaction<S extends ledgerV9.Signaturish, B extends ledgerV9.Bindingish>(tx: ledgerV9.Transaction<S, ledgerV9.PreProof, B>, costModel?: ledgerV9.CostModel): Effect.Effect<ledgerV9.Transaction<S, ledgerV9.Proof, B>, ClientError | ServerError>;
30
+ /** A proving provider that frames its requests with ledger-v9. */
31
+ asProvingProvider(): ledgerV9.ProvingProvider;
32
+ /** The same provider as {@link asProvingProvider}, named for the ledger version it frames with. */
33
+ asV9ProvingProvider(): ledgerV9.ProvingProvider;
34
+ /**
35
+ * A proving provider that frames its requests with ledger-v8.
36
+ *
37
+ * @remarks
38
+ * A preimage is produced by the ledger version that built the transaction, and has to be framed and read back by
39
+ * that same version — so a client serving a ledger-v8 transaction is asked for this provider rather than the
40
+ * other. An in-process prover has nothing to distinguish: it works on bytes, and offers the same provider for
41
+ * both.
42
+ */
43
+ asV8ProvingProvider(): ledgerV8.ProvingProvider;
30
44
  }
31
45
  }
32
46
  export {};
@@ -44,4 +44,17 @@ export declare const GetParamsOperationResultSchema: Schema.Struct<{
44
44
  k: typeof Schema.Number;
45
45
  result: typeof Schema.Uint8Array;
46
46
  }>;
47
- export declare const makeDefaultKeyMaterialProvider: () => KeyMaterialProvider;
47
+ /** Which line of the key-material bucket to read: the circuits the keys were generated for. */
48
+ export type KeyMaterialConfig = {
49
+ /**
50
+ * The circuit line to read.
51
+ *
52
+ * @remarks
53
+ * Not a ledger version, despite reading like one. Line 9 is what both ledger versions the SDK carries accept today —
54
+ * ledger-v8's own line predates the zkir runtime they share and its verifier keys are rejected outright — which is
55
+ * why it is the default on both sides. The setting exists so an operator whose bucket says otherwise can say so,
56
+ * not because a fork implies a change of line.
57
+ */
58
+ circuits?: 8 | 9;
59
+ };
60
+ export declare const makeDefaultKeyMaterialProvider: (config?: KeyMaterialConfig) => KeyMaterialProvider;
@@ -142,11 +142,25 @@ class WasmProverImpl {
142
142
  asProvingProvider() {
143
143
  return this.wasmProverProvider();
144
144
  }
145
+ /**
146
+ * The same provider {@link asProvingProvider} returns.
147
+ *
148
+ * @remarks
149
+ * The in-process prover drives a zkir runtime over bytes and never looks at a ledger version, so there is nothing for
150
+ * a ledger-v8 variant to do differently. It is offered under both names because the caller choosing a backend for
151
+ * an epoch should not have to know which backends care about the epoch and which do not.
152
+ */
153
+ asV9ProvingProvider() {
154
+ return this.wasmProverProvider();
155
+ }
156
+ asV8ProvingProvider() {
157
+ return this.wasmProverProvider();
158
+ }
145
159
  }
146
- export const makeDefaultKeyMaterialProvider = () => {
160
+ export const makeDefaultKeyMaterialProvider = (config) => {
147
161
  const cache = new Map();
148
162
  const s3 = 'https://midnight-s3-fileshare-dev-eu-west-1.s3.eu-west-1.amazonaws.com';
149
- const ver = 9;
163
+ const ver = config?.circuits ?? 9;
150
164
  const fetchWithRetry = async (url, retries = 5) => {
151
165
  for (let i = 0; i < retries; i++) {
152
166
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midnight-ntwrk/wallet-sdk-prover-client",
3
- "version": "2.0.0-beta.2",
3
+ "version": "2.0.0-beta.3",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -31,9 +31,10 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@effect/platform": "^0.96.0",
34
+ "@midnight-ntwrk/ledger-v8": "^8.1.0",
34
35
  "@midnight-ntwrk/zkir-v2": "^2.1.0",
35
- "@midnightntwrk/ledger-v9": "1.0.0-rc.3",
36
- "@midnight-ntwrk/wallet-sdk-utilities": "1.2.0",
36
+ "@midnightntwrk/ledger-v9": "1.0.0-rc.4",
37
+ "@midnight-ntwrk/wallet-sdk-utilities": "1.2.2-beta.0",
37
38
  "effect": "^3.19.19",
38
39
  "web-worker": "^1.5.0"
39
40
  },