@midnight-ntwrk/wallet-sdk-capabilities 4.0.0-beta.2 → 4.0.0-beta.4
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 +27 -3
- package/dist/chainVersion/chainVersionProbe.d.ts +95 -0
- package/dist/chainVersion/chainVersionProbe.js +83 -0
- package/dist/chainVersion/index.d.ts +1 -0
- package/dist/chainVersion/index.js +13 -0
- package/dist/codecs/index.d.ts +1 -0
- package/dist/codecs/index.js +13 -0
- package/dist/codecs/ledgerParameters.d.ts +81 -0
- package/dist/codecs/ledgerParameters.js +63 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/pendingTransactions/pendingTransactions.d.ts +113 -9
- package/dist/pendingTransactions/pendingTransactions.js +147 -30
- package/dist/pendingTransactions/pendingTransactionsService.d.ts +25 -9
- package/dist/pendingTransactions/pendingTransactionsService.js +33 -21
- package/dist/proving/index.d.ts +2 -0
- package/dist/proving/index.js +2 -0
- package/dist/proving/provingService.d.ts +184 -15
- package/dist/proving/provingService.js +114 -12
- package/dist/proving/v8ProvingService.d.ts +53 -0
- package/dist/proving/v8ProvingService.js +71 -0
- package/dist/proving/versionedProving.d.ts +42 -0
- package/dist/proving/versionedProving.js +103 -0
- package/dist/signatures/index.d.ts +2 -0
- package/dist/signatures/index.js +14 -0
- package/dist/signatures/signing.d.ts +37 -0
- package/dist/signatures/signing.js +13 -0
- package/dist/signatures/v8Signatures.d.ts +54 -0
- package/dist/signatures/v8Signatures.js +62 -0
- package/dist/simulation/ForkSimulator.d.ts +114 -0
- package/dist/simulation/ForkSimulator.js +209 -0
- package/dist/simulation/LedgerTranslation.d.ts +53 -0
- package/dist/simulation/LedgerTranslation.js +56 -0
- package/dist/simulation/core/VersionTimeline.d.ts +54 -0
- package/dist/simulation/core/VersionTimeline.js +56 -0
- package/dist/simulation/core/blocks.d.ts +38 -0
- package/dist/simulation/core/blocks.js +52 -0
- package/dist/simulation/core/index.d.ts +13 -0
- package/dist/simulation/core/index.js +25 -0
- package/dist/simulation/core/strictness.d.ts +29 -0
- package/dist/simulation/core/strictness.js +39 -0
- package/dist/simulation/index.d.ts +22 -2
- package/dist/simulation/index.js +25 -14
- package/dist/simulation/v8/Simulator.d.ts +231 -0
- package/dist/simulation/v8/Simulator.js +503 -0
- package/dist/simulation/{SimulatorState.d.ts → v8/SimulatorState.d.ts} +31 -44
- package/dist/simulation/v8/SimulatorState.js +290 -0
- package/dist/simulation/v8/index.d.ts +2 -0
- package/dist/simulation/v8/index.js +26 -0
- package/dist/simulation/{Simulator.d.ts → v9/Simulator.d.ts} +57 -6
- package/dist/simulation/{Simulator.js → v9/Simulator.js} +68 -18
- package/dist/simulation/v9/SimulatorState.d.ts +336 -0
- package/dist/simulation/{SimulatorState.js → v9/SimulatorState.js} +34 -67
- package/dist/simulation/v9/index.d.ts +2 -0
- package/dist/simulation/v9/index.js +26 -0
- package/dist/submission/submissionService.d.ts +2 -1
- package/dist/submission/submissionService.js +1 -1
- package/dist/validation/blockData.d.ts +42 -2
- package/dist/validation/blockData.js +55 -8
- package/dist/validation/index.d.ts +2 -0
- package/dist/validation/index.js +2 -0
- package/dist/validation/v8ValidationService.d.ts +29 -0
- package/dist/validation/v8ValidationService.js +48 -0
- package/dist/validation/validationService.d.ts +132 -17
- package/dist/validation/validationService.js +88 -42
- package/dist/validation/versionedValidation.d.ts +46 -0
- package/dist/validation/versionedValidation.js +55 -0
- package/package.json +28 -14
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as ledger from '@midnightntwrk/ledger-v9';
|
|
2
2
|
import type { KeyMaterialProvider } from '@midnight-ntwrk/zkir-v2';
|
|
3
|
+
import { ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
3
4
|
import { type InvalidProtocolSchemeError } from '@midnight-ntwrk/wallet-sdk-utilities/networking';
|
|
4
|
-
import { Effect } from 'effect';
|
|
5
|
+
import { Effect, Either } from 'effect';
|
|
5
6
|
declare const ProvingError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
6
7
|
readonly _tag: "Wallet.Proving";
|
|
7
8
|
} & Readonly<A>;
|
|
@@ -10,28 +11,196 @@ export declare class ProvingError extends ProvingError_base<{
|
|
|
10
11
|
cause: Error;
|
|
11
12
|
}> {
|
|
12
13
|
}
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
declare const ProvingEpochMismatchError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
15
|
+
readonly _tag: "@midnight-ntwrk/wallet-sdk-capabilities/proving/provingService/ProvingEpochMismatchError";
|
|
16
|
+
} & Readonly<A>;
|
|
17
|
+
/**
|
|
18
|
+
* Raised when a proving backend is handed a transaction from the other side of a protocol boundary.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* Every backend is written against exactly one ledger version, and the two ledger versions' transactions are different
|
|
22
|
+
* classes that neither can read. The router has already chosen a backend by the version stamped on the transaction,
|
|
23
|
+
* so reaching this error means the stamp and the bytes disagreed — which is worth saying out loud, and in terms of
|
|
24
|
+
* the epoch the backend serves, rather than letting a foreign object reach the wasm-bindgen boundary and fail there
|
|
25
|
+
* as something unreadable.
|
|
26
|
+
*/
|
|
27
|
+
export declare class ProvingEpochMismatchError extends ProvingEpochMismatchError_base<{
|
|
28
|
+
readonly message: string;
|
|
29
|
+
/** The range of protocol versions the backend that refused the transaction serves. */
|
|
30
|
+
readonly epoch: ProtocolVersion.ProtocolVersion.Range;
|
|
31
|
+
}> {
|
|
32
|
+
}
|
|
33
|
+
/** Everything a proving backend can fail with. */
|
|
34
|
+
export type ProvingFailure = ProvingError | ProvingEpochMismatchError;
|
|
35
|
+
/**
|
|
36
|
+
* Turns an unproven transaction into a proven one.
|
|
37
|
+
*
|
|
38
|
+
* @typeParam TProven The proven transaction this backend produces.
|
|
39
|
+
* @typeParam TUnproven The unproven transaction it accepts. Defaults to ledger-v9's, because a proving backend is only
|
|
40
|
+
* ever written against one ledger version — which is exactly why choosing between backends is
|
|
41
|
+
* {@link VersionedProvingServiceEffect}'s job and not this interface's.
|
|
42
|
+
*/
|
|
43
|
+
export interface ProvingServiceEffect<TProven, TUnproven = ledger.UnprovenTransaction> {
|
|
44
|
+
prove(transaction: TUnproven): Effect.Effect<TProven, ProvingFailure>;
|
|
45
|
+
}
|
|
46
|
+
export interface ProvingService<TProven, TUnproven = ledger.UnprovenTransaction> {
|
|
47
|
+
prove(transaction: TUnproven): Promise<TProven>;
|
|
48
|
+
}
|
|
49
|
+
declare const UnsupportedProvingVersionError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
50
|
+
readonly _tag: "@midnight-ntwrk/wallet-sdk-capabilities/proving/provingService/UnsupportedProvingVersionError";
|
|
51
|
+
} & Readonly<A>;
|
|
52
|
+
/** Raised when no proving backend is registered for the protocol version a transaction was built for. */
|
|
53
|
+
export declare class UnsupportedProvingVersionError extends UnsupportedProvingVersionError_base<{
|
|
54
|
+
readonly message: string;
|
|
55
|
+
/** The version the transaction was built for, which no registered backend serves. */
|
|
56
|
+
readonly protocolVersion: ProtocolVersion.ProtocolVersion;
|
|
57
|
+
}> {
|
|
15
58
|
}
|
|
16
|
-
|
|
17
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Proves a transaction with the backend registered for the protocol version it was built for.
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
63
|
+
* The version is the transaction's own stamp, taken when it was built, and never the version the chain has reached by
|
|
64
|
+
* the time proving happens. A fork can land between balancing and proving; the bytes the prover has to read were
|
|
65
|
+
* fixed before it did.
|
|
66
|
+
*/
|
|
67
|
+
export interface VersionedProvingServiceEffect<TProven, TUnproven = ledger.UnprovenTransaction> {
|
|
68
|
+
prove(transaction: TUnproven, protocolVersion: ProtocolVersion.ProtocolVersion): Effect.Effect<TProven, ProvingFailure | UnsupportedProvingVersionError>;
|
|
18
69
|
}
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
70
|
+
export interface VersionedProvingService<TProven, TUnproven = ledger.UnprovenTransaction> {
|
|
71
|
+
prove(transaction: TUnproven, protocolVersion: ProtocolVersion.ProtocolVersion): Promise<TProven>;
|
|
72
|
+
}
|
|
73
|
+
/** The proving backends a wallet can use, keyed by the protocol version range each one serves. */
|
|
74
|
+
export type ProvingServices<TProven, TUnproven = ledger.UnprovenTransaction> = ProtocolVersion.Registry<ProvingServiceEffect<TProven, TUnproven>>;
|
|
75
|
+
/**
|
|
76
|
+
* Builds a proving service that routes on the version a transaction was built for.
|
|
77
|
+
*
|
|
78
|
+
* @param services The backends and the version ranges they serve.
|
|
79
|
+
* @returns A proving service that fails with {@link UnsupportedProvingVersionError} for a version nothing serves.
|
|
80
|
+
*/
|
|
81
|
+
export declare const makeVersionedProvingServiceEffect: <TProven, TUnproven>(services: ProvingServices<TProven, TUnproven>) => VersionedProvingServiceEffect<TProven, TUnproven>;
|
|
82
|
+
/**
|
|
83
|
+
* Lets one backend answer for every protocol version.
|
|
84
|
+
*
|
|
85
|
+
* @remarks
|
|
86
|
+
* Says out loud what an unversioned proving service was implicitly claiming: that it can prove anything, whatever
|
|
87
|
+
* version produced it. True for a wallet on one side of a fork, and a lie the moment it crosses — so it has to be
|
|
88
|
+
* written down rather than assumed.
|
|
89
|
+
* @param service The backend to use for every version.
|
|
90
|
+
* @returns The same backend, addressed by version.
|
|
91
|
+
*/
|
|
92
|
+
export declare const singleVersionProvingServiceEffect: <TProven, TUnproven>(service: ProvingServiceEffect<TProven, TUnproven>) => VersionedProvingServiceEffect<TProven, TUnproven>;
|
|
93
|
+
export type V9UnboundTransaction = ledger.Transaction<ledger.SignatureEnabled, ledger.Proof, ledger.PreBinding>;
|
|
94
|
+
/** Adapts a version-routed proving service to the promise-facing surface the facade exposes. */
|
|
95
|
+
export declare const wrapVersionedEffectService: <TProven, TUnproven>(effectService: VersionedProvingServiceEffect<TProven, TUnproven>) => VersionedProvingService<TProven, TUnproven>;
|
|
96
|
+
export declare const fromV9ProvingProviderEffect: (provider: Effect.Effect<ledger.ProvingProvider, InvalidProtocolSchemeError>) => ProvingServiceEffect<V9UnboundTransaction>;
|
|
97
|
+
export declare const fromV9ProvingProvider: (provider: ledger.ProvingProvider) => ProvingServiceEffect<V9UnboundTransaction>;
|
|
22
98
|
export type ServerProvingConfiguration = {
|
|
23
99
|
provingServerUrl: URL;
|
|
24
100
|
};
|
|
25
101
|
export type WasmProvingConfiguration = {
|
|
26
102
|
keyMaterialProvider?: KeyMaterialProvider;
|
|
27
103
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
104
|
+
/**
|
|
105
|
+
* Where proving happens: at a proof server over HTTP, or in this process.
|
|
106
|
+
*
|
|
107
|
+
* @remarks
|
|
108
|
+
* Deliberately says nothing about a ledger version. Which ledger drives a backend follows from the key it is registered
|
|
109
|
+
* under in {@link ProvingBackends}, so the same description can be named for either side of a fork and mean the right
|
|
110
|
+
* thing both times.
|
|
111
|
+
*/
|
|
112
|
+
export type ProvingBackend = Readonly<{
|
|
113
|
+
kind: 'server';
|
|
114
|
+
url: URL;
|
|
115
|
+
}> | Readonly<{
|
|
116
|
+
kind: 'wasm';
|
|
117
|
+
keyMaterialProvider?: KeyMaterialProvider;
|
|
118
|
+
}>;
|
|
119
|
+
/**
|
|
120
|
+
* Which proving backend proves the transactions each ledger version authors.
|
|
121
|
+
*
|
|
122
|
+
* @remarks
|
|
123
|
+
* Keyed the way {@link ProtocolVersion.ForkSchedule} is, so a configuration states each boundary once: `v8` proves below
|
|
124
|
+
* `forks.v9` and `v9` from it, and where one ends and the next begins is read off the schedule rather than restated
|
|
125
|
+
* here. The newest ledger version's backend is required, because it is what every new transaction is proved with; an
|
|
126
|
+
* older one may be left out on a chain whose history below the boundary the wallet will never author for, and a
|
|
127
|
+
* transaction stamped there then fails with {@link UnsupportedProvingVersionError}. The next hard fork adds a key
|
|
128
|
+
* (`v10`) rather than changing this shape.
|
|
129
|
+
*/
|
|
130
|
+
export type ProvingBackends = Readonly<{
|
|
131
|
+
/** Proves the transactions ledger-v8 authored, below `forks.v9`. */
|
|
132
|
+
v8?: ProvingBackend;
|
|
133
|
+
/** Proves the transactions ledger-v9 authored, from `forks.v9`. */
|
|
134
|
+
v9: ProvingBackend;
|
|
135
|
+
}>;
|
|
136
|
+
/**
|
|
137
|
+
* Which proving backend serves which ledger version.
|
|
138
|
+
*
|
|
139
|
+
* @remarks
|
|
140
|
+
* The two settings are alternatives, not a set: `provers` is the general form and `provingServerUrl` the shorthand for
|
|
141
|
+
* "this one proof server, for every ledger version". Giving both is not an error — `provers` wins — but naming
|
|
142
|
+
* neither is, because there is then nothing to prove with.
|
|
143
|
+
*
|
|
144
|
+
* The single URL is registered once per ledger version and driven by each in turn, which is what makes it frame its
|
|
145
|
+
* requests correctly on both sides of a fork. Whether a given proof server can in fact serve both is an operational
|
|
146
|
+
* fact about that server, not something the SDK can know or enforce — today's images serve one side each, so a chain
|
|
147
|
+
* that spans a fork wants `provers` with a server per side.
|
|
148
|
+
*/
|
|
149
|
+
export type DefaultProvingConfiguration = {
|
|
150
|
+
/** One proof server for every ledger version. */
|
|
151
|
+
provingServerUrl?: URL;
|
|
152
|
+
/** A proving backend per ledger version. */
|
|
153
|
+
provers?: ProvingBackends;
|
|
154
|
+
};
|
|
155
|
+
declare const ProvingConfigurationError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").VoidIfEmpty<{ readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }>) => import("effect/Cause").YieldableError & {
|
|
156
|
+
readonly _tag: "@midnight-ntwrk/wallet-sdk-capabilities/proving/provingService/ProvingConfigurationError";
|
|
157
|
+
} & Readonly<A>;
|
|
158
|
+
/** Raised when the proving configuration names no backend at all. */
|
|
159
|
+
export declare class ProvingConfigurationError extends ProvingConfigurationError_base<{
|
|
160
|
+
readonly message: string;
|
|
161
|
+
readonly cause?: unknown;
|
|
162
|
+
}> {
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Reads a proving configuration as the backend it names for each ledger version.
|
|
166
|
+
*
|
|
167
|
+
* @remarks
|
|
168
|
+
* Where the precedence between the two settings is decided, once, so that reading a configuration and building services
|
|
169
|
+
* from it cannot disagree about which one was meant. Says nothing about protocol versions: which range each backend
|
|
170
|
+
* serves is the fork schedule's to say, and `makeDefaultProvingServices` reads it there.
|
|
171
|
+
* @param configuration The proving configuration.
|
|
172
|
+
* @returns The backend per ledger version, or the reason the configuration names none.
|
|
173
|
+
*/
|
|
174
|
+
export declare const resolveProvingBackends: (configuration: DefaultProvingConfiguration) => Either.Either<ProvingBackends, ProvingConfigurationError>;
|
|
175
|
+
/**
|
|
176
|
+
* Registers the in-process WASM prover, driven by ledger-v9, from a given protocol version upwards.
|
|
177
|
+
*
|
|
178
|
+
* @remarks
|
|
179
|
+
* Every entry here is ledger-v9's backend, so `sinceVersion` should not be below a protocol boundary: what a version
|
|
180
|
+
* below it needs is the ledger-v8 driver, which `makeDefaultProvingServices` registers for the epoch the fork
|
|
181
|
+
* schedule it is given places below `forks.v9`. Registering nothing below is what turns that into an
|
|
182
|
+
* {@link UnsupportedProvingVersionError} naming the version, rather than a ledger-v8 transaction handed to a ledger
|
|
183
|
+
* that cannot read it.
|
|
184
|
+
* @param sinceVersion The first protocol version to register the bundled prover for.
|
|
185
|
+
* @param configuration Optional key material override.
|
|
186
|
+
* @returns The proving backends, keyed by version.
|
|
187
|
+
*/
|
|
188
|
+
export declare const makeWasmProvingServices: (sinceVersion: ProtocolVersion.ProtocolVersion, configuration?: WasmProvingConfiguration) => ProvingServices<V9UnboundTransaction>;
|
|
189
|
+
export declare const makeV9ServerProvingServiceEffect: (configuration: ServerProvingConfiguration) => ProvingServiceEffect<V9UnboundTransaction>;
|
|
190
|
+
/**
|
|
191
|
+
* Proves ledger-v9 transactions in this process.
|
|
192
|
+
*
|
|
193
|
+
* @remarks
|
|
194
|
+
* The ledger-v9 twin of `makeV8WasmProvingServiceEffect`: the same bundled prover, with ledger-v9's key material —
|
|
195
|
+
* circuit generation 10 ({@link WasmProver.makeV9KeyMaterialProvider}) — unless it is given key material of its own.
|
|
196
|
+
* @param configuration Optional key material override.
|
|
197
|
+
* @returns A backend that proves ledger-v9 transactions in-process.
|
|
198
|
+
*/
|
|
199
|
+
export declare const makeV9WasmProvingServiceEffect: (configuration?: WasmProvingConfiguration) => ProvingServiceEffect<V9UnboundTransaction>;
|
|
31
200
|
export declare const makeSimulatorProvingServiceEffect: () => ProvingServiceEffect<ledger.ProofErasedTransaction>;
|
|
32
|
-
export declare const makeDefaultProvingServiceEffect: (configuration:
|
|
33
|
-
export declare const makeDefaultProvingService: (configuration:
|
|
34
|
-
export declare const
|
|
35
|
-
export declare const
|
|
201
|
+
export declare const makeDefaultProvingServiceEffect: (configuration: ServerProvingConfiguration) => ProvingServiceEffect<V9UnboundTransaction>;
|
|
202
|
+
export declare const makeDefaultProvingService: (configuration: ServerProvingConfiguration) => ProvingService<V9UnboundTransaction>;
|
|
203
|
+
export declare const makeV9ServerProvingService: (configuration: ServerProvingConfiguration) => ProvingService<V9UnboundTransaction>;
|
|
204
|
+
export declare const makeV9WasmProvingService: (configuration?: WasmProvingConfiguration) => ProvingService<V9UnboundTransaction>;
|
|
36
205
|
export declare const makeSimulatorProvingService: () => ProvingService<ledger.ProofErasedTransaction>;
|
|
37
206
|
export {};
|
|
@@ -11,15 +11,63 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import * as ledger from '@midnightntwrk/ledger-v9';
|
|
14
|
+
import { ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
14
15
|
import { HttpProverClient, WasmProver } from '@midnight-ntwrk/wallet-sdk-prover-client/effect';
|
|
15
16
|
import { ClientError, ServerError, } from '@midnight-ntwrk/wallet-sdk-utilities/networking';
|
|
16
|
-
import { Data, Effect, pipe } from 'effect';
|
|
17
|
+
import { Data, Effect, Either, Option, pipe } from 'effect';
|
|
17
18
|
export class ProvingError extends Data.TaggedError('Wallet.Proving') {
|
|
18
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Raised when a proving backend is handed a transaction from the other side of a protocol boundary.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* Every backend is written against exactly one ledger version, and the two ledger versions' transactions are different
|
|
25
|
+
* classes that neither can read. The router has already chosen a backend by the version stamped on the transaction,
|
|
26
|
+
* so reaching this error means the stamp and the bytes disagreed — which is worth saying out loud, and in terms of
|
|
27
|
+
* the epoch the backend serves, rather than letting a foreign object reach the wasm-bindgen boundary and fail there
|
|
28
|
+
* as something unreadable.
|
|
29
|
+
*/
|
|
30
|
+
export class ProvingEpochMismatchError extends Data.TaggedError('@midnight-ntwrk/wallet-sdk-capabilities/proving/provingService/ProvingEpochMismatchError') {
|
|
31
|
+
}
|
|
32
|
+
/** Raised when no proving backend is registered for the protocol version a transaction was built for. */
|
|
33
|
+
export class UnsupportedProvingVersionError extends Data.TaggedError('@midnight-ntwrk/wallet-sdk-capabilities/proving/provingService/UnsupportedProvingVersionError') {
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Builds a proving service that routes on the version a transaction was built for.
|
|
37
|
+
*
|
|
38
|
+
* @param services The backends and the version ranges they serve.
|
|
39
|
+
* @returns A proving service that fails with {@link UnsupportedProvingVersionError} for a version nothing serves.
|
|
40
|
+
*/
|
|
41
|
+
export const makeVersionedProvingServiceEffect = (services) => ({
|
|
42
|
+
prove: (transaction, protocolVersion) => Option.match(ProtocolVersion.select(services, protocolVersion), {
|
|
43
|
+
onNone: () => Effect.fail(new UnsupportedProvingVersionError({
|
|
44
|
+
message: `No proving backend is registered for protocol version ${protocolVersion}.`,
|
|
45
|
+
protocolVersion,
|
|
46
|
+
})),
|
|
47
|
+
onSome: (service) => service.prove(transaction),
|
|
48
|
+
}),
|
|
49
|
+
});
|
|
50
|
+
/**
|
|
51
|
+
* Lets one backend answer for every protocol version.
|
|
52
|
+
*
|
|
53
|
+
* @remarks
|
|
54
|
+
* Says out loud what an unversioned proving service was implicitly claiming: that it can prove anything, whatever
|
|
55
|
+
* version produced it. True for a wallet on one side of a fork, and a lie the moment it crosses — so it has to be
|
|
56
|
+
* written down rather than assumed.
|
|
57
|
+
* @param service The backend to use for every version.
|
|
58
|
+
* @returns The same backend, addressed by version.
|
|
59
|
+
*/
|
|
60
|
+
export const singleVersionProvingServiceEffect = (service) => ({
|
|
61
|
+
prove: (transaction) => service.prove(transaction),
|
|
62
|
+
});
|
|
19
63
|
const wrapEffectService = (effectService) => ({
|
|
20
64
|
prove: (transaction) => Effect.runPromise(effectService.prove(transaction)),
|
|
21
65
|
});
|
|
22
|
-
|
|
66
|
+
/** Adapts a version-routed proving service to the promise-facing surface the facade exposes. */
|
|
67
|
+
export const wrapVersionedEffectService = (effectService) => ({
|
|
68
|
+
prove: (transaction, protocolVersion) => Effect.runPromise(effectService.prove(transaction, protocolVersion)),
|
|
69
|
+
});
|
|
70
|
+
export const fromV9ProvingProviderEffect = (provider) => {
|
|
23
71
|
return {
|
|
24
72
|
prove(transaction) {
|
|
25
73
|
return pipe(provider, Effect.flatMap((provider) => Effect.tryPromise({
|
|
@@ -34,18 +82,72 @@ export const fromProvingProviderEffect = (provider) => {
|
|
|
34
82
|
},
|
|
35
83
|
};
|
|
36
84
|
};
|
|
37
|
-
export const
|
|
38
|
-
return
|
|
85
|
+
export const fromV9ProvingProvider = (provider) => {
|
|
86
|
+
return fromV9ProvingProviderEffect(Effect.succeed(provider));
|
|
39
87
|
};
|
|
40
|
-
|
|
88
|
+
/** Raised when the proving configuration names no backend at all. */
|
|
89
|
+
export class ProvingConfigurationError extends Data.TaggedError('@midnight-ntwrk/wallet-sdk-capabilities/proving/provingService/ProvingConfigurationError') {
|
|
90
|
+
}
|
|
91
|
+
const noBackendNamed = () => new ProvingConfigurationError({
|
|
92
|
+
message: "Missing required configuration: set 'provers' (or 'provingServerUrl'), or provide a custom provingService in init parameters.",
|
|
93
|
+
});
|
|
94
|
+
/**
|
|
95
|
+
* Reads a proving configuration as the backend it names for each ledger version.
|
|
96
|
+
*
|
|
97
|
+
* @remarks
|
|
98
|
+
* Where the precedence between the two settings is decided, once, so that reading a configuration and building services
|
|
99
|
+
* from it cannot disagree about which one was meant. Says nothing about protocol versions: which range each backend
|
|
100
|
+
* serves is the fork schedule's to say, and `makeDefaultProvingServices` reads it there.
|
|
101
|
+
* @param configuration The proving configuration.
|
|
102
|
+
* @returns The backend per ledger version, or the reason the configuration names none.
|
|
103
|
+
*/
|
|
104
|
+
export const resolveProvingBackends = (configuration) => configuration.provers !== undefined
|
|
105
|
+
? Either.right(configuration.provers)
|
|
106
|
+
: configuration.provingServerUrl !== undefined
|
|
107
|
+
? Either.right({
|
|
108
|
+
v8: { kind: 'server', url: configuration.provingServerUrl },
|
|
109
|
+
v9: { kind: 'server', url: configuration.provingServerUrl },
|
|
110
|
+
})
|
|
111
|
+
: Either.left(noBackendNamed());
|
|
112
|
+
/**
|
|
113
|
+
* Registers the in-process WASM prover, driven by ledger-v9, from a given protocol version upwards.
|
|
114
|
+
*
|
|
115
|
+
* @remarks
|
|
116
|
+
* Every entry here is ledger-v9's backend, so `sinceVersion` should not be below a protocol boundary: what a version
|
|
117
|
+
* below it needs is the ledger-v8 driver, which `makeDefaultProvingServices` registers for the epoch the fork
|
|
118
|
+
* schedule it is given places below `forks.v9`. Registering nothing below is what turns that into an
|
|
119
|
+
* {@link UnsupportedProvingVersionError} naming the version, rather than a ledger-v8 transaction handed to a ledger
|
|
120
|
+
* that cannot read it.
|
|
121
|
+
* @param sinceVersion The first protocol version to register the bundled prover for.
|
|
122
|
+
* @param configuration Optional key material override.
|
|
123
|
+
* @returns The proving backends, keyed by version.
|
|
124
|
+
*/
|
|
125
|
+
export const makeWasmProvingServices = (sinceVersion, configuration) => ({
|
|
126
|
+
entries: [
|
|
127
|
+
{
|
|
128
|
+
range: ProtocolVersion.makeRange(sinceVersion, ProtocolVersion.MaxSupportedVersion),
|
|
129
|
+
value: makeV9WasmProvingServiceEffect(configuration),
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
});
|
|
133
|
+
export const makeV9ServerProvingServiceEffect = (configuration) => {
|
|
41
134
|
return pipe(HttpProverClient.create({
|
|
42
135
|
url: configuration.provingServerUrl,
|
|
43
|
-
}), Effect.map((client) => client.asProvingProvider()),
|
|
136
|
+
}), Effect.map((client) => client.asProvingProvider()), fromV9ProvingProviderEffect);
|
|
44
137
|
};
|
|
45
|
-
|
|
138
|
+
/**
|
|
139
|
+
* Proves ledger-v9 transactions in this process.
|
|
140
|
+
*
|
|
141
|
+
* @remarks
|
|
142
|
+
* The ledger-v9 twin of `makeV8WasmProvingServiceEffect`: the same bundled prover, with ledger-v9's key material —
|
|
143
|
+
* circuit generation 10 ({@link WasmProver.makeV9KeyMaterialProvider}) — unless it is given key material of its own.
|
|
144
|
+
* @param configuration Optional key material override.
|
|
145
|
+
* @returns A backend that proves ledger-v9 transactions in-process.
|
|
146
|
+
*/
|
|
147
|
+
export const makeV9WasmProvingServiceEffect = (configuration) => {
|
|
46
148
|
return pipe(WasmProver.create({
|
|
47
|
-
keyMaterialProvider: configuration?.keyMaterialProvider ?? WasmProver.
|
|
48
|
-
}), Effect.map((prover) => prover.asProvingProvider()),
|
|
149
|
+
keyMaterialProvider: configuration?.keyMaterialProvider ?? WasmProver.makeV9KeyMaterialProvider(),
|
|
150
|
+
}), Effect.map((prover) => prover.asProvingProvider()), fromV9ProvingProviderEffect);
|
|
49
151
|
};
|
|
50
152
|
export const makeSimulatorProvingServiceEffect = () => {
|
|
51
153
|
return {
|
|
@@ -54,8 +156,8 @@ export const makeSimulatorProvingServiceEffect = () => {
|
|
|
54
156
|
},
|
|
55
157
|
};
|
|
56
158
|
};
|
|
57
|
-
export const makeDefaultProvingServiceEffect = (configuration) =>
|
|
159
|
+
export const makeDefaultProvingServiceEffect = (configuration) => makeV9ServerProvingServiceEffect(configuration);
|
|
58
160
|
export const makeDefaultProvingService = (configuration) => wrapEffectService(makeDefaultProvingServiceEffect(configuration));
|
|
59
|
-
export const
|
|
60
|
-
export const
|
|
161
|
+
export const makeV9ServerProvingService = (configuration) => wrapEffectService(makeV9ServerProvingServiceEffect(configuration));
|
|
162
|
+
export const makeV9WasmProvingService = (configuration) => wrapEffectService(makeV9WasmProvingServiceEffect(configuration));
|
|
61
163
|
export const makeSimulatorProvingService = () => wrapEffectService(makeSimulatorProvingServiceEffect());
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proving on ledger-v8.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* The ledger-v8 twin of the backends in `provingService.ts`: structurally the same three steps — obtain a proving
|
|
6
|
+
* provider, drive the transaction's own `prove` with that ledger version's cost model, report failures as a
|
|
7
|
+
* {@link ProvingError} — against a different ledger version's classes. It is the classes that make this a separate
|
|
8
|
+
* module: a ledger-v8 transaction handed ledger-v9's cost model fails at the wasm-bindgen boundary, and a
|
|
9
|
+
* proof-server request framed by ledger-v9 is not the request ledger-v8 would have sent.
|
|
10
|
+
*/
|
|
11
|
+
import * as ledger from '@midnight-ntwrk/ledger-v8';
|
|
12
|
+
import { type InvalidProtocolSchemeError } from '@midnight-ntwrk/wallet-sdk-utilities/networking';
|
|
13
|
+
import { Effect } from 'effect';
|
|
14
|
+
import { type ProvingServiceEffect, type ServerProvingConfiguration, type WasmProvingConfiguration } from './provingService.js';
|
|
15
|
+
/** A ledger-v8 transaction that has not been proved yet. */
|
|
16
|
+
export type V8UnprovenTransaction = ledger.UnprovenTransaction;
|
|
17
|
+
/** A ledger-v8 transaction that has been proved but not yet bound. */
|
|
18
|
+
export type V8UnboundTransaction = ledger.Transaction<ledger.SignatureEnabled, ledger.Proof, ledger.PreBinding>;
|
|
19
|
+
/** A proving backend written against ledger-v8. */
|
|
20
|
+
export type V8ProvingServiceEffect = ProvingServiceEffect<V8UnboundTransaction, V8UnprovenTransaction>;
|
|
21
|
+
/**
|
|
22
|
+
* Drives a ledger-v8 transaction's proving with a low-level proving provider.
|
|
23
|
+
*
|
|
24
|
+
* @param provider The proving provider, or the reason one could not be built.
|
|
25
|
+
* @returns A backend that proves ledger-v8 transactions.
|
|
26
|
+
*/
|
|
27
|
+
export declare const fromV8ProvingProviderEffect: (provider: Effect.Effect<ledger.ProvingProvider, InvalidProtocolSchemeError>) => V8ProvingServiceEffect;
|
|
28
|
+
/**
|
|
29
|
+
* Drives a ledger-v8 transaction's proving with a low-level proving provider.
|
|
30
|
+
*
|
|
31
|
+
* @param provider The proving provider.
|
|
32
|
+
* @returns A backend that proves ledger-v8 transactions.
|
|
33
|
+
*/
|
|
34
|
+
export declare const fromV8ProvingProvider: (provider: ledger.ProvingProvider) => V8ProvingServiceEffect;
|
|
35
|
+
/**
|
|
36
|
+
* Proves ledger-v8 transactions at a proof server.
|
|
37
|
+
*
|
|
38
|
+
* @param configuration The proof server to send ledger-v8 proving requests to.
|
|
39
|
+
* @returns A backend that proves ledger-v8 transactions over HTTP.
|
|
40
|
+
*/
|
|
41
|
+
export declare const makeV8ServerProvingServiceEffect: (configuration: ServerProvingConfiguration) => V8ProvingServiceEffect;
|
|
42
|
+
/**
|
|
43
|
+
* Proves ledger-v8 transactions in this process.
|
|
44
|
+
*
|
|
45
|
+
* @remarks
|
|
46
|
+
* The zkir runtime the bundled prover drives is shared by both ledger versions, so there is nothing version-specific
|
|
47
|
+
* about the proving loop — but there is about the key material. Ledger-v8's circuits are generation 9 and ledger-v9's
|
|
48
|
+
* generation 10, and a node rejects a Dust spend proved with the other version's, so this backend reads ledger-v8's
|
|
49
|
+
* own ({@link WasmProver.makeV8KeyMaterialProvider}) unless it is given key material of its own.
|
|
50
|
+
* @param configuration Optional key material override.
|
|
51
|
+
* @returns A backend that proves ledger-v8 transactions in-process.
|
|
52
|
+
*/
|
|
53
|
+
export declare const makeV8WasmProvingServiceEffect: (configuration?: WasmProvingConfiguration) => V8ProvingServiceEffect;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// This file is part of MIDNIGHT-WALLET-SDK.
|
|
2
|
+
// Copyright (C) Midnight Foundation
|
|
3
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
// You may not use this file except in compliance with the License.
|
|
6
|
+
// You may obtain a copy of the License at
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
/**
|
|
14
|
+
* Proving on ledger-v8.
|
|
15
|
+
*
|
|
16
|
+
* @remarks
|
|
17
|
+
* The ledger-v8 twin of the backends in `provingService.ts`: structurally the same three steps — obtain a proving
|
|
18
|
+
* provider, drive the transaction's own `prove` with that ledger version's cost model, report failures as a
|
|
19
|
+
* {@link ProvingError} — against a different ledger version's classes. It is the classes that make this a separate
|
|
20
|
+
* module: a ledger-v8 transaction handed ledger-v9's cost model fails at the wasm-bindgen boundary, and a
|
|
21
|
+
* proof-server request framed by ledger-v9 is not the request ledger-v8 would have sent.
|
|
22
|
+
*/
|
|
23
|
+
import * as ledger from '@midnight-ntwrk/ledger-v8';
|
|
24
|
+
import { HttpProverClient, WasmProver } from '@midnight-ntwrk/wallet-sdk-prover-client/effect';
|
|
25
|
+
import { ClientError, ServerError, } from '@midnight-ntwrk/wallet-sdk-utilities/networking';
|
|
26
|
+
import { Effect, pipe } from 'effect';
|
|
27
|
+
import { ProvingError, } from './provingService.js';
|
|
28
|
+
/**
|
|
29
|
+
* Drives a ledger-v8 transaction's proving with a low-level proving provider.
|
|
30
|
+
*
|
|
31
|
+
* @param provider The proving provider, or the reason one could not be built.
|
|
32
|
+
* @returns A backend that proves ledger-v8 transactions.
|
|
33
|
+
*/
|
|
34
|
+
export const fromV8ProvingProviderEffect = (provider) => ({
|
|
35
|
+
prove(transaction) {
|
|
36
|
+
return pipe(provider, Effect.flatMap((provider) => Effect.tryPromise({
|
|
37
|
+
try: () => transaction.prove(provider, ledger.CostModel.initialCostModel()),
|
|
38
|
+
catch: (error) => error instanceof ClientError || error instanceof ServerError
|
|
39
|
+
? error
|
|
40
|
+
: new ClientError({ message: 'Failed to prove transaction', cause: error }),
|
|
41
|
+
})), Effect.catchAll((error) => Effect.fail(new ProvingError({ message: error.message, cause: error }))));
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
/**
|
|
45
|
+
* Drives a ledger-v8 transaction's proving with a low-level proving provider.
|
|
46
|
+
*
|
|
47
|
+
* @param provider The proving provider.
|
|
48
|
+
* @returns A backend that proves ledger-v8 transactions.
|
|
49
|
+
*/
|
|
50
|
+
export const fromV8ProvingProvider = (provider) => fromV8ProvingProviderEffect(Effect.succeed(provider));
|
|
51
|
+
/**
|
|
52
|
+
* Proves ledger-v8 transactions at a proof server.
|
|
53
|
+
*
|
|
54
|
+
* @param configuration The proof server to send ledger-v8 proving requests to.
|
|
55
|
+
* @returns A backend that proves ledger-v8 transactions over HTTP.
|
|
56
|
+
*/
|
|
57
|
+
export const makeV8ServerProvingServiceEffect = (configuration) => pipe(HttpProverClient.create({ url: configuration.provingServerUrl }), Effect.map((client) => client.asV8ProvingProvider()), fromV8ProvingProviderEffect);
|
|
58
|
+
/**
|
|
59
|
+
* Proves ledger-v8 transactions in this process.
|
|
60
|
+
*
|
|
61
|
+
* @remarks
|
|
62
|
+
* The zkir runtime the bundled prover drives is shared by both ledger versions, so there is nothing version-specific
|
|
63
|
+
* about the proving loop — but there is about the key material. Ledger-v8's circuits are generation 9 and ledger-v9's
|
|
64
|
+
* generation 10, and a node rejects a Dust spend proved with the other version's, so this backend reads ledger-v8's
|
|
65
|
+
* own ({@link WasmProver.makeV8KeyMaterialProvider}) unless it is given key material of its own.
|
|
66
|
+
* @param configuration Optional key material override.
|
|
67
|
+
* @returns A backend that proves ledger-v8 transactions in-process.
|
|
68
|
+
*/
|
|
69
|
+
export const makeV8WasmProvingServiceEffect = (configuration) => pipe(WasmProver.create({
|
|
70
|
+
keyMaterialProvider: configuration?.keyMaterialProvider ?? WasmProver.makeV8KeyMaterialProvider(),
|
|
71
|
+
}), Effect.map((prover) => prover.asProvingProvider()), fromV8ProvingProviderEffect);
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as ledgerV9 from '@midnightntwrk/ledger-v9';
|
|
2
|
+
import { ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
3
|
+
import { Either } from 'effect';
|
|
4
|
+
import { type V8UnboundTransaction, type V8UnprovenTransaction } from './v8ProvingService.js';
|
|
5
|
+
import { type DefaultProvingConfiguration, type ProvingConfigurationError, type ProvingServiceEffect, type ProvingServices, type V9UnboundTransaction, type VersionedProvingService, type VersionedProvingServiceEffect } from './provingService.js';
|
|
6
|
+
/**
|
|
7
|
+
* Every unproven transaction either ledger version can be asked to prove.
|
|
8
|
+
*
|
|
9
|
+
* @remarks
|
|
10
|
+
* A genuine union: the two ledger versions' transaction types are nominally distinct, so a caller holding one of them
|
|
11
|
+
* is holding something the other version's backend provably cannot read.
|
|
12
|
+
*/
|
|
13
|
+
/** Ledger-v9's unproven transaction, named for symmetry with {@link V8UnprovenTransaction}. */
|
|
14
|
+
export type V9UnprovenTransaction = ledgerV9.UnprovenTransaction;
|
|
15
|
+
export type AnyVersionUnprovenTransaction = V9UnprovenTransaction | V8UnprovenTransaction;
|
|
16
|
+
/** Every proved-but-unbound transaction either ledger version can hand back. */
|
|
17
|
+
export type AnyVersionUnboundTransaction = V9UnboundTransaction | V8UnboundTransaction;
|
|
18
|
+
/** A backend registered in a two-version registry, whichever ledger version it was written against. */
|
|
19
|
+
export type VersionProvingServiceEffect = ProvingServiceEffect<AnyVersionUnboundTransaction, AnyVersionUnprovenTransaction>;
|
|
20
|
+
/**
|
|
21
|
+
* Registers a proving backend either side of the protocol boundary.
|
|
22
|
+
*
|
|
23
|
+
* @remarks
|
|
24
|
+
* The configuration names a backend per ledger version and the fork schedule says where each ledger version begins; the
|
|
25
|
+
* range a backend serves is the meeting of the two, computed here and nowhere else, so the wallets and their provers
|
|
26
|
+
* cannot place the boundary differently.
|
|
27
|
+
* @param configuration The proving configuration.
|
|
28
|
+
* @param forks Where each ledger version begins on the chain.
|
|
29
|
+
* @returns The backends and the version ranges they serve, or the reason the configuration names none.
|
|
30
|
+
*/
|
|
31
|
+
export declare const makeDefaultProvingServices: (configuration: DefaultProvingConfiguration, forks: ProtocolVersion.ForkSchedule) => Either.Either<ProvingServices<AnyVersionUnboundTransaction, AnyVersionUnprovenTransaction>, ProvingConfigurationError>;
|
|
32
|
+
/**
|
|
33
|
+
* Builds the version-routed proving service an SDK spanning a protocol boundary proves with.
|
|
34
|
+
*
|
|
35
|
+
* @param configuration The proving configuration.
|
|
36
|
+
* @param forks Where each ledger version begins on the chain.
|
|
37
|
+
* @returns A proving service that routes on the version a transaction was built for, or the reason the configuration
|
|
38
|
+
* names no backend.
|
|
39
|
+
*/
|
|
40
|
+
export declare const makeDefaultVersionedProvingServiceEffect: (configuration: DefaultProvingConfiguration, forks: ProtocolVersion.ForkSchedule) => Either.Either<VersionedProvingServiceEffect<AnyVersionUnboundTransaction, AnyVersionUnprovenTransaction>, ProvingConfigurationError>;
|
|
41
|
+
/** The promise-facing surface of {@link makeDefaultVersionedProvingServiceEffect}, for the facade to expose. */
|
|
42
|
+
export declare const makeDefaultVersionedProvingService: (configuration: DefaultProvingConfiguration, forks: ProtocolVersion.ForkSchedule) => Either.Either<VersionedProvingService<AnyVersionUnboundTransaction, AnyVersionUnprovenTransaction>, ProvingConfigurationError>;
|