@midnightntwrk/wallet-sdk-capabilities 4.0.0-rc.1 → 4.0.0-rc.2
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 +10 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/liveness/livenessReads.js +11 -10
- package/dist/liveness/livenessService.js +4 -5
- package/dist/proving/index.d.ts +1 -0
- package/dist/proving/index.js +1 -0
- package/dist/proving/provingService.d.ts +15 -48
- package/dist/proving/provingService.js +1 -89
- package/dist/proving/v8ProvingService.d.ts +33 -6
- package/dist/proving/v8ProvingService.js +35 -5
- package/dist/proving/v9ProvingService.d.ts +108 -0
- package/dist/proving/v9ProvingService.js +146 -0
- package/dist/proving/versionedProving.d.ts +22 -4
- package/dist/proving/versionedProving.js +27 -1
- package/dist/simulation/index.d.ts +4 -6
- package/dist/simulation/index.js +4 -7
- package/dist/simulation/v8/Simulator.d.ts +0 -2
- package/dist/simulation/v8/Simulator.js +0 -2
- package/dist/simulation/v8/SimulatorState.d.ts +0 -9
- package/dist/simulation/v8/SimulatorState.js +0 -8
- package/dist/simulation/v8/index.d.ts +1 -1
- package/dist/simulation/v8/index.js +1 -1
- package/dist/simulation/v9/Simulator.d.ts +0 -2
- package/dist/simulation/v9/Simulator.js +0 -2
- package/dist/simulation/v9/SimulatorState.d.ts +0 -9
- package/dist/simulation/v9/SimulatorState.js +0 -8
- package/dist/simulation/v9/index.d.ts +1 -1
- package/dist/simulation/v9/index.js +1 -1
- package/dist/submission/submissionService.d.ts +57 -9
- package/dist/submission/submissionService.js +61 -15
- package/dist/transactionLifecycle/SnapshotFormat.d.ts +51 -0
- package/dist/transactionLifecycle/SnapshotFormat.js +120 -0
- package/dist/transactionLifecycle/index.d.ts +4 -0
- package/dist/{pendingTransactions → transactionLifecycle}/index.js +4 -2
- package/dist/transactionLifecycle/lifecycle.d.ts +402 -0
- package/dist/transactionLifecycle/lifecycle.js +407 -0
- package/dist/transactionLifecycle/lifecycleService.d.ts +448 -0
- package/dist/transactionLifecycle/lifecycleService.js +350 -0
- package/dist/transactionLifecycle/transactionTraits.d.ts +106 -0
- package/dist/transactionLifecycle/transactionTraits.js +53 -0
- package/dist/validation/blockData.d.ts +23 -4
- package/dist/validation/blockData.js +34 -10
- package/dist/validation/index.d.ts +1 -0
- package/dist/validation/index.js +1 -0
- package/dist/validation/promiseBoundary.d.ts +10 -0
- package/dist/validation/promiseBoundary.js +30 -0
- package/dist/validation/v8ValidationService.d.ts +5 -4
- package/dist/validation/v8ValidationService.js +10 -3
- package/dist/validation/v9ValidationService.d.ts +30 -0
- package/dist/validation/v9ValidationService.js +61 -0
- package/dist/validation/validationService.d.ts +53 -31
- package/dist/validation/validationService.js +29 -49
- package/dist/validation/versionedValidation.d.ts +5 -3
- package/dist/validation/versionedValidation.js +5 -3
- package/package.json +11 -11
- package/dist/pendingTransactions/index.d.ts +0 -2
- package/dist/pendingTransactions/pendingTransactions.d.ts +0 -266
- package/dist/pendingTransactions/pendingTransactions.js +0 -302
- package/dist/pendingTransactions/pendingTransactionsService.d.ts +0 -108
- package/dist/pendingTransactions/pendingTransactionsService.js +0 -186
package/README.md
CHANGED
|
@@ -105,10 +105,12 @@ wallets are built with:
|
|
|
105
105
|
```typescript
|
|
106
106
|
import { makeDefaultVersionedProvingService } from '@midnightntwrk/wallet-sdk-capabilities/proving';
|
|
107
107
|
|
|
108
|
+
// Either<VersionedProvingService<AnyVersionUnboundTransaction, AnyVersionUnprovenTransaction>,
|
|
109
|
+
// ProvingConfigurationError>
|
|
108
110
|
const service = makeDefaultVersionedProvingService(
|
|
109
111
|
{ provers: { v8: { kind: 'server', url: v8ProofServer }, v9: { kind: 'wasm' } } },
|
|
110
112
|
forks,
|
|
111
|
-
);
|
|
113
|
+
);
|
|
112
114
|
```
|
|
113
115
|
|
|
114
116
|
- `provers` wins over `provingServerUrl`; naming neither is a `ProvingConfigurationError`. `v9` is required and `v8` is
|
|
@@ -118,8 +120,13 @@ const service = makeDefaultVersionedProvingService(
|
|
|
118
120
|
operational fact about that server, not something the SDK enforces.
|
|
119
121
|
- Each registered backend refuses the other ledger version's transaction with `ProvingEpochMismatchError` rather than
|
|
120
122
|
handing it to a ledger that cannot read it.
|
|
121
|
-
- `makeV9ServerProvingServiceEffect` / `makeV9WasmProvingServiceEffect` build a single ledger-v9 backend
|
|
122
|
-
`
|
|
123
|
+
- `makeV9ServerProvingServiceEffect` / `makeV9WasmProvingServiceEffect` build a single ledger-v9 backend, a
|
|
124
|
+
`V9ProvingServiceEffect` over `V9UnprovenTransaction`; `makeV8ServerProvingServiceEffect` /
|
|
125
|
+
`makeV8WasmProvingServiceEffect` are their ledger-v8 twins (`V8ProvingServiceEffect`, `V8UnprovenTransaction`). The
|
|
126
|
+
facade's `provingService` takes a prover over both ledger versions; to prove with one ledger version's backend alone,
|
|
127
|
+
name it in `provers` (`{ v9: { kind: 'wasm' } }`) instead.
|
|
128
|
+
- `makeV9SimulatorProvingServiceEffect` / `makeV8SimulatorProvingServiceEffect` erase proofs instead of proving them,
|
|
129
|
+
for the in-memory simulator.
|
|
123
130
|
|
|
124
131
|
## Exports
|
|
125
132
|
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export * from './balancer/index.js';
|
|
|
2
2
|
export * from './chainVersion/index.js';
|
|
3
3
|
export * from './codecs/index.js';
|
|
4
4
|
export * from './liveness/index.js';
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './transactionLifecycle/index.js';
|
|
6
6
|
export * from './proving/index.js';
|
|
7
7
|
export * from './signatures/index.js';
|
|
8
8
|
export * from './simulation/index.js';
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ export * from './balancer/index.js';
|
|
|
14
14
|
export * from './chainVersion/index.js';
|
|
15
15
|
export * from './codecs/index.js';
|
|
16
16
|
export * from './liveness/index.js';
|
|
17
|
-
export * from './
|
|
17
|
+
export * from './transactionLifecycle/index.js';
|
|
18
18
|
export * from './proving/index.js';
|
|
19
19
|
export * from './signatures/index.js';
|
|
20
20
|
export * from './simulation/index.js';
|
|
@@ -25,9 +25,10 @@ import { LivenessReadError } from './livenessService.js';
|
|
|
25
25
|
* hangs instead.
|
|
26
26
|
*
|
|
27
27
|
* The bound applies twice within one connection build — once to the handshake, once to the close that follows it — so
|
|
28
|
-
* the build's worst case is double this value
|
|
29
|
-
*
|
|
30
|
-
*
|
|
28
|
+
* the build's worst case is double this value. The poll's own deadline does not depend on it: the service disconnects
|
|
29
|
+
* the read before applying its timeout, so the verdict lands on time. A poll that gives up abandons a handshake still
|
|
30
|
+
* in progress, and the next poll starts a new one; a build that has connected finishes its close in the background
|
|
31
|
+
* and its client is cached for the next poll.
|
|
31
32
|
*/
|
|
32
33
|
const NODE_CONNECTION_TIMEOUT = Duration.seconds(10);
|
|
33
34
|
/**
|
|
@@ -140,13 +141,13 @@ export const makeDefaultLivenessReads = (config, makeNodeClient = connectToNode)
|
|
|
140
141
|
* once.
|
|
141
142
|
*
|
|
142
143
|
* Uninterruptible, because the poll fails fast: when the sibling indexer read fails, the in-flight node read is
|
|
143
|
-
* interrupted.
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
* that
|
|
144
|
+
* interrupted. Without this the interrupt could land between the build completing and the cache write — stranding
|
|
145
|
+
* a fully-built client on the sync-lifetime scope with the cache still empty, once per poll for as long as the
|
|
146
|
+
* indexer stays down. It does not hold back the handshake: the client's bounded wait for the node runs in a child
|
|
147
|
+
* fiber, which takes the interrupt whatever this region's status, so a poll that fails fast abandons a handshake
|
|
148
|
+
* still in progress and its provider is disconnected. Once connected, the build defers the interrupt past its
|
|
149
|
+
* close and the cache write, at most the connection bound, so a built client is always cached. The poll does not
|
|
150
|
+
* wait for that — the service disconnects the read before applying its own timeout.
|
|
150
151
|
*/
|
|
151
152
|
const client = (nodeURL) => Effect.uninterruptible(SynchronizedRef.modifyEffect(cachedClient, (current) => Option.match(current, {
|
|
152
153
|
onSome: (existing) => Effect.succeed([existing, current]),
|
|
@@ -123,11 +123,10 @@ export class LivenessServiceImpl {
|
|
|
123
123
|
*/
|
|
124
124
|
#poll() {
|
|
125
125
|
return this.#compareOnce().pipe(Effect.map((verdict) => () => verdict),
|
|
126
|
-
// `disconnect` makes the deadline below a hard one. A timeout interrupts its loser and then waits for it,
|
|
127
|
-
// read
|
|
128
|
-
//
|
|
129
|
-
//
|
|
130
|
-
// caches its client for the next poll.
|
|
126
|
+
// `disconnect` makes the deadline below a hard one. A timeout interrupts its loser and then waits for it, and a
|
|
127
|
+
// node read that has connected defers the interrupt until its close and cache write finish, up to the connection
|
|
128
|
+
// bound. Disconnected, the read is interrupted in the background instead: the verdict lands on time, a handshake
|
|
129
|
+
// still in progress is abandoned with its provider disconnected, and a connected build still caches its client.
|
|
131
130
|
Effect.disconnect,
|
|
132
131
|
// A bound on the whole poll, not only on the reads' own deadlines: polls run one at a time, so a read that hangs
|
|
133
132
|
// — an endpoint that accepts a connection and never answers — would otherwise stop the loop forever, freezing
|
package/dist/proving/index.d.ts
CHANGED
package/dist/proving/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import * as ledger from '@midnightntwrk/ledger-v9';
|
|
2
1
|
import type { KeyMaterialProvider } from '@midnight-ntwrk/zkir-v2';
|
|
3
2
|
import { ProtocolVersion } from '@midnightntwrk/wallet-sdk-abstractions';
|
|
4
|
-
import { type InvalidProtocolSchemeError } from '@midnightntwrk/wallet-sdk-utilities/networking';
|
|
5
3
|
import { Effect, Either } from 'effect';
|
|
6
4
|
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 & {
|
|
7
5
|
readonly _tag: "Wallet.Proving";
|
|
@@ -35,16 +33,19 @@ export type ProvingFailure = ProvingError | ProvingEpochMismatchError;
|
|
|
35
33
|
/**
|
|
36
34
|
* Turns an unproven transaction into a proven one.
|
|
37
35
|
*
|
|
36
|
+
* @remarks
|
|
37
|
+
* `prove` is a property rather than a method so that the transaction is checked contravariantly: a backend over one
|
|
38
|
+
* ledger version is then no backend over both, which is what keeps a ledger-v8 transaction from reaching ledger-v9.
|
|
38
39
|
* @typeParam TProven The proven transaction this backend produces.
|
|
39
|
-
* @typeParam TUnproven The unproven transaction it accepts
|
|
40
|
-
*
|
|
41
|
-
* {@link VersionedProvingServiceEffect}'s job
|
|
40
|
+
* @typeParam TUnproven The unproven transaction it accepts, and so the one ledger version it is written against. It has
|
|
41
|
+
* no default: a backend that left it out would be ledger-v9's without saying so. Choosing between backends for
|
|
42
|
+
* different ledger versions is {@link VersionedProvingServiceEffect}'s job, not this interface's.
|
|
42
43
|
*/
|
|
43
|
-
export interface ProvingServiceEffect<TProven, TUnproven
|
|
44
|
-
prove(transaction: TUnproven)
|
|
44
|
+
export interface ProvingServiceEffect<TProven, TUnproven> {
|
|
45
|
+
readonly prove: (transaction: TUnproven) => Effect.Effect<TProven, ProvingFailure>;
|
|
45
46
|
}
|
|
46
|
-
export interface ProvingService<TProven, TUnproven
|
|
47
|
-
prove(transaction: TUnproven)
|
|
47
|
+
export interface ProvingService<TProven, TUnproven> {
|
|
48
|
+
readonly prove: (transaction: TUnproven) => Promise<TProven>;
|
|
48
49
|
}
|
|
49
50
|
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
51
|
readonly _tag: "@midnightntwrk/wallet-sdk-capabilities/proving/provingService/UnsupportedProvingVersionError";
|
|
@@ -64,14 +65,14 @@ export declare class UnsupportedProvingVersionError extends UnsupportedProvingVe
|
|
|
64
65
|
* the time proving happens. A fork can land between balancing and proving; the bytes the prover has to read were
|
|
65
66
|
* fixed before it did.
|
|
66
67
|
*/
|
|
67
|
-
export interface VersionedProvingServiceEffect<TProven, TUnproven
|
|
68
|
-
prove(transaction: TUnproven, protocolVersion: ProtocolVersion.ProtocolVersion)
|
|
68
|
+
export interface VersionedProvingServiceEffect<TProven, TUnproven> {
|
|
69
|
+
readonly prove: (transaction: TUnproven, protocolVersion: ProtocolVersion.ProtocolVersion) => Effect.Effect<TProven, ProvingFailure | UnsupportedProvingVersionError>;
|
|
69
70
|
}
|
|
70
|
-
export interface VersionedProvingService<TProven, TUnproven
|
|
71
|
-
prove(transaction: TUnproven, protocolVersion: ProtocolVersion.ProtocolVersion)
|
|
71
|
+
export interface VersionedProvingService<TProven, TUnproven> {
|
|
72
|
+
readonly prove: (transaction: TUnproven, protocolVersion: ProtocolVersion.ProtocolVersion) => Promise<TProven>;
|
|
72
73
|
}
|
|
73
74
|
/** The proving backends a wallet can use, keyed by the protocol version range each one serves. */
|
|
74
|
-
export type ProvingServices<TProven, TUnproven
|
|
75
|
+
export type ProvingServices<TProven, TUnproven> = ProtocolVersion.Registry<ProvingServiceEffect<TProven, TUnproven>>;
|
|
75
76
|
/**
|
|
76
77
|
* Builds a proving service that routes on the version a transaction was built for.
|
|
77
78
|
*
|
|
@@ -90,11 +91,8 @@ export declare const makeVersionedProvingServiceEffect: <TProven, TUnproven>(ser
|
|
|
90
91
|
* @returns The same backend, addressed by version.
|
|
91
92
|
*/
|
|
92
93
|
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
94
|
/** Adapts a version-routed proving service to the promise-facing surface the facade exposes. */
|
|
95
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>;
|
|
98
96
|
export type ServerProvingConfiguration = {
|
|
99
97
|
provingServerUrl: URL;
|
|
100
98
|
};
|
|
@@ -172,35 +170,4 @@ export declare class ProvingConfigurationError extends ProvingConfigurationError
|
|
|
172
170
|
* @returns The backend per ledger version, or the reason the configuration names none.
|
|
173
171
|
*/
|
|
174
172
|
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>;
|
|
200
|
-
export declare const makeSimulatorProvingServiceEffect: () => ProvingServiceEffect<ledger.ProofErasedTransaction>;
|
|
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>;
|
|
205
|
-
export declare const makeSimulatorProvingService: () => ProvingService<ledger.ProofErasedTransaction>;
|
|
206
173
|
export {};
|
|
@@ -1,20 +1,5 @@
|
|
|
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
|
-
import * as ledger from '@midnightntwrk/ledger-v9';
|
|
14
1
|
import { ProtocolVersion } from '@midnightntwrk/wallet-sdk-abstractions';
|
|
15
|
-
import {
|
|
16
|
-
import { ClientError, ServerError, } from '@midnightntwrk/wallet-sdk-utilities/networking';
|
|
17
|
-
import { Data, Effect, Either, Option, pipe } from 'effect';
|
|
2
|
+
import { Data, Effect, Either, Option } from 'effect';
|
|
18
3
|
export class ProvingError extends Data.TaggedError('Wallet.Proving') {
|
|
19
4
|
}
|
|
20
5
|
/**
|
|
@@ -60,31 +45,10 @@ export const makeVersionedProvingServiceEffect = (services) => ({
|
|
|
60
45
|
export const singleVersionProvingServiceEffect = (service) => ({
|
|
61
46
|
prove: (transaction) => service.prove(transaction),
|
|
62
47
|
});
|
|
63
|
-
const wrapEffectService = (effectService) => ({
|
|
64
|
-
prove: (transaction) => Effect.runPromise(effectService.prove(transaction)),
|
|
65
|
-
});
|
|
66
48
|
/** Adapts a version-routed proving service to the promise-facing surface the facade exposes. */
|
|
67
49
|
export const wrapVersionedEffectService = (effectService) => ({
|
|
68
50
|
prove: (transaction, protocolVersion) => Effect.runPromise(effectService.prove(transaction, protocolVersion)),
|
|
69
51
|
});
|
|
70
|
-
export const fromV9ProvingProviderEffect = (provider) => {
|
|
71
|
-
return {
|
|
72
|
-
prove(transaction) {
|
|
73
|
-
return pipe(provider, Effect.flatMap((provider) => Effect.tryPromise({
|
|
74
|
-
try: () => transaction.prove(provider, ledger.CostModel.initialCostModel()),
|
|
75
|
-
catch: (error) => error instanceof ClientError || error instanceof ServerError
|
|
76
|
-
? error
|
|
77
|
-
: new ClientError({ message: 'Failed to prove transaction', cause: error }),
|
|
78
|
-
})), Effect.catchAll((error) => Effect.fail(new ProvingError({
|
|
79
|
-
message: error.message,
|
|
80
|
-
cause: error,
|
|
81
|
-
}))));
|
|
82
|
-
},
|
|
83
|
-
};
|
|
84
|
-
};
|
|
85
|
-
export const fromV9ProvingProvider = (provider) => {
|
|
86
|
-
return fromV9ProvingProviderEffect(Effect.succeed(provider));
|
|
87
|
-
};
|
|
88
52
|
/** Raised when the proving configuration names no backend at all. */
|
|
89
53
|
export class ProvingConfigurationError extends Data.TaggedError('@midnightntwrk/wallet-sdk-capabilities/proving/provingService/ProvingConfigurationError') {
|
|
90
54
|
}
|
|
@@ -109,55 +73,3 @@ export const resolveProvingBackends = (configuration) => configuration.provers !
|
|
|
109
73
|
v9: { kind: 'server', url: configuration.provingServerUrl },
|
|
110
74
|
})
|
|
111
75
|
: 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) => {
|
|
134
|
-
return pipe(HttpProverClient.create({
|
|
135
|
-
url: configuration.provingServerUrl,
|
|
136
|
-
}), Effect.map((client) => client.asProvingProvider()), fromV9ProvingProviderEffect);
|
|
137
|
-
};
|
|
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) => {
|
|
148
|
-
return pipe(WasmProver.create({
|
|
149
|
-
keyMaterialProvider: configuration?.keyMaterialProvider ?? WasmProver.makeV9KeyMaterialProvider(),
|
|
150
|
-
}), Effect.map((prover) => prover.asProvingProvider()), fromV9ProvingProviderEffect);
|
|
151
|
-
};
|
|
152
|
-
export const makeSimulatorProvingServiceEffect = () => {
|
|
153
|
-
return {
|
|
154
|
-
prove(transaction) {
|
|
155
|
-
return Effect.succeed(transaction.eraseProofs());
|
|
156
|
-
},
|
|
157
|
-
};
|
|
158
|
-
};
|
|
159
|
-
export const makeDefaultProvingServiceEffect = (configuration) => makeV9ServerProvingServiceEffect(configuration);
|
|
160
|
-
export const makeDefaultProvingService = (configuration) => wrapEffectService(makeDefaultProvingServiceEffect(configuration));
|
|
161
|
-
export const makeV9ServerProvingService = (configuration) => wrapEffectService(makeV9ServerProvingServiceEffect(configuration));
|
|
162
|
-
export const makeV9WasmProvingService = (configuration) => wrapEffectService(makeV9WasmProvingServiceEffect(configuration));
|
|
163
|
-
export const makeSimulatorProvingService = () => wrapEffectService(makeSimulatorProvingServiceEffect());
|
|
@@ -2,22 +2,24 @@
|
|
|
2
2
|
* Proving on ledger-v8.
|
|
3
3
|
*
|
|
4
4
|
* @remarks
|
|
5
|
-
* The ledger-v8 twin of
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
5
|
+
* The ledger-v8 twin of `v9ProvingService.ts`: structurally the same three steps — obtain a proving provider, drive the
|
|
6
|
+
* transaction's own `prove` with that ledger version's cost model, report failures as a {@link ProvingError} — against
|
|
7
|
+
* a different ledger version's classes. It is the classes that make this a separate module: a ledger-v8 transaction
|
|
8
|
+
* handed ledger-v9's cost model fails at the wasm-bindgen boundary, and a proof-server request framed by ledger-v9 is
|
|
9
|
+
* not the request ledger-v8 would have sent.
|
|
10
10
|
*/
|
|
11
11
|
import * as ledger from '@midnight-ntwrk/ledger-v8';
|
|
12
12
|
import { type InvalidProtocolSchemeError } from '@midnightntwrk/wallet-sdk-utilities/networking';
|
|
13
13
|
import { Effect } from 'effect';
|
|
14
|
-
import { type ProvingServiceEffect, type ServerProvingConfiguration, type WasmProvingConfiguration } from './provingService.js';
|
|
14
|
+
import { type ProvingService, type ProvingServiceEffect, type ServerProvingConfiguration, type WasmProvingConfiguration } from './provingService.js';
|
|
15
15
|
/** A ledger-v8 transaction that has not been proved yet. */
|
|
16
16
|
export type V8UnprovenTransaction = ledger.UnprovenTransaction;
|
|
17
17
|
/** A ledger-v8 transaction that has been proved but not yet bound. */
|
|
18
18
|
export type V8UnboundTransaction = ledger.Transaction<ledger.SignatureEnabled, ledger.Proof, ledger.PreBinding>;
|
|
19
19
|
/** A proving backend written against ledger-v8. */
|
|
20
20
|
export type V8ProvingServiceEffect = ProvingServiceEffect<V8UnboundTransaction, V8UnprovenTransaction>;
|
|
21
|
+
/** The promise-facing surface of a {@link V8ProvingServiceEffect}. */
|
|
22
|
+
export type V8ProvingService = ProvingService<V8UnboundTransaction, V8UnprovenTransaction>;
|
|
21
23
|
/**
|
|
22
24
|
* Drives a ledger-v8 transaction's proving with a low-level proving provider.
|
|
23
25
|
*
|
|
@@ -51,3 +53,28 @@ export declare const makeV8ServerProvingServiceEffect: (configuration: ServerPro
|
|
|
51
53
|
* @returns A backend that proves ledger-v8 transactions in-process.
|
|
52
54
|
*/
|
|
53
55
|
export declare const makeV8WasmProvingServiceEffect: (configuration?: WasmProvingConfiguration) => V8ProvingServiceEffect;
|
|
56
|
+
/**
|
|
57
|
+
* Erases the proofs of ledger-v8 transactions instead of proving them, for the in-memory simulator.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const proving = makeV8SimulatorProvingServiceEffect();
|
|
62
|
+
* const proofErased = yield* proving.prove(unprovenTransaction);
|
|
63
|
+
* yield* simulator.submitTransaction(proofErased);
|
|
64
|
+
* ```;
|
|
65
|
+
*
|
|
66
|
+
* @returns A backend that hands back each ledger-v8 transaction proof-erased, which the simulator accepts.
|
|
67
|
+
*/
|
|
68
|
+
export declare const makeV8SimulatorProvingServiceEffect: () => ProvingServiceEffect<ledger.ProofErasedTransaction, V8UnprovenTransaction>;
|
|
69
|
+
/**
|
|
70
|
+
* The promise-facing surface of {@link makeV8SimulatorProvingServiceEffect}.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* ```typescript
|
|
74
|
+
* const proving = makeV8SimulatorProvingService();
|
|
75
|
+
* const proofErased = await proving.prove(unprovenTransaction);
|
|
76
|
+
* ```;
|
|
77
|
+
*
|
|
78
|
+
* @returns A backend that hands back each ledger-v8 transaction proof-erased, which the simulator accepts.
|
|
79
|
+
*/
|
|
80
|
+
export declare const makeV8SimulatorProvingService: () => ProvingService<ledger.ProofErasedTransaction, V8UnprovenTransaction>;
|
|
@@ -14,11 +14,11 @@
|
|
|
14
14
|
* Proving on ledger-v8.
|
|
15
15
|
*
|
|
16
16
|
* @remarks
|
|
17
|
-
* The ledger-v8 twin of
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
17
|
+
* The ledger-v8 twin of `v9ProvingService.ts`: structurally the same three steps — obtain a proving provider, drive the
|
|
18
|
+
* transaction's own `prove` with that ledger version's cost model, report failures as a {@link ProvingError} — against
|
|
19
|
+
* a different ledger version's classes. It is the classes that make this a separate module: a ledger-v8 transaction
|
|
20
|
+
* handed ledger-v9's cost model fails at the wasm-bindgen boundary, and a proof-server request framed by ledger-v9 is
|
|
21
|
+
* not the request ledger-v8 would have sent.
|
|
22
22
|
*/
|
|
23
23
|
import * as ledger from '@midnight-ntwrk/ledger-v8';
|
|
24
24
|
import { HttpProverClient, WasmProver } from '@midnightntwrk/wallet-sdk-prover-client/effect';
|
|
@@ -69,3 +69,33 @@ export const makeV8ServerProvingServiceEffect = (configuration) => pipe(HttpProv
|
|
|
69
69
|
export const makeV8WasmProvingServiceEffect = (configuration) => pipe(WasmProver.create({
|
|
70
70
|
keyMaterialProvider: configuration?.keyMaterialProvider ?? WasmProver.makeV8KeyMaterialProvider(),
|
|
71
71
|
}), Effect.map((prover) => prover.asProvingProvider()), fromV8ProvingProviderEffect);
|
|
72
|
+
/**
|
|
73
|
+
* Erases the proofs of ledger-v8 transactions instead of proving them, for the in-memory simulator.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* const proving = makeV8SimulatorProvingServiceEffect();
|
|
78
|
+
* const proofErased = yield* proving.prove(unprovenTransaction);
|
|
79
|
+
* yield* simulator.submitTransaction(proofErased);
|
|
80
|
+
* ```;
|
|
81
|
+
*
|
|
82
|
+
* @returns A backend that hands back each ledger-v8 transaction proof-erased, which the simulator accepts.
|
|
83
|
+
*/
|
|
84
|
+
export const makeV8SimulatorProvingServiceEffect = () => ({
|
|
85
|
+
prove: (transaction) => Effect.succeed(transaction.eraseProofs()),
|
|
86
|
+
});
|
|
87
|
+
/**
|
|
88
|
+
* The promise-facing surface of {@link makeV8SimulatorProvingServiceEffect}.
|
|
89
|
+
*
|
|
90
|
+
* @example
|
|
91
|
+
* ```typescript
|
|
92
|
+
* const proving = makeV8SimulatorProvingService();
|
|
93
|
+
* const proofErased = await proving.prove(unprovenTransaction);
|
|
94
|
+
* ```;
|
|
95
|
+
*
|
|
96
|
+
* @returns A backend that hands back each ledger-v8 transaction proof-erased, which the simulator accepts.
|
|
97
|
+
*/
|
|
98
|
+
export const makeV8SimulatorProvingService = () => {
|
|
99
|
+
const effectService = makeV8SimulatorProvingServiceEffect();
|
|
100
|
+
return { prove: (transaction) => Effect.runPromise(effectService.prove(transaction)) };
|
|
101
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proving on ledger-v9.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* The ledger-v9 twin of `v8ProvingService.ts`, built on the version-neutral contracts in `provingService.ts`: obtain a
|
|
6
|
+
* proving provider, drive the transaction's own `prove` with ledger-v9's cost model, report failures as a
|
|
7
|
+
* {@link ProvingError}.
|
|
8
|
+
*/
|
|
9
|
+
import * as ledger from '@midnightntwrk/ledger-v9';
|
|
10
|
+
import { type InvalidProtocolSchemeError } from '@midnightntwrk/wallet-sdk-utilities/networking';
|
|
11
|
+
import { Effect } from 'effect';
|
|
12
|
+
import { type ProvingService, type ProvingServiceEffect, type ServerProvingConfiguration, type WasmProvingConfiguration } from './provingService.js';
|
|
13
|
+
/** A ledger-v9 transaction that has not been proved yet. */
|
|
14
|
+
export type V9UnprovenTransaction = ledger.UnprovenTransaction;
|
|
15
|
+
/** A ledger-v9 transaction that has been proved but not yet bound. */
|
|
16
|
+
export type V9UnboundTransaction = ledger.Transaction<ledger.SignatureEnabled, ledger.Proof, ledger.PreBinding>;
|
|
17
|
+
/** A proving backend written against ledger-v9. */
|
|
18
|
+
export type V9ProvingServiceEffect = ProvingServiceEffect<V9UnboundTransaction, V9UnprovenTransaction>;
|
|
19
|
+
/** The promise-facing surface of a {@link V9ProvingServiceEffect}. */
|
|
20
|
+
export type V9ProvingService = ProvingService<V9UnboundTransaction, V9UnprovenTransaction>;
|
|
21
|
+
/**
|
|
22
|
+
* Drives a ledger-v9 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-v9 transactions.
|
|
26
|
+
*/
|
|
27
|
+
export declare const fromV9ProvingProviderEffect: (provider: Effect.Effect<ledger.ProvingProvider, InvalidProtocolSchemeError>) => V9ProvingServiceEffect;
|
|
28
|
+
/**
|
|
29
|
+
* Drives a ledger-v9 transaction's proving with a low-level proving provider.
|
|
30
|
+
*
|
|
31
|
+
* @param provider The proving provider.
|
|
32
|
+
* @returns A backend that proves ledger-v9 transactions.
|
|
33
|
+
*/
|
|
34
|
+
export declare const fromV9ProvingProvider: (provider: ledger.ProvingProvider) => V9ProvingServiceEffect;
|
|
35
|
+
/**
|
|
36
|
+
* Proves ledger-v9 transactions at a proof server.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const proving = makeV9ServerProvingServiceEffect({ provingServerUrl: new URL('http://localhost:6300') });
|
|
41
|
+
* const unbound = yield* proving.prove(unprovenTransaction);
|
|
42
|
+
* ```;
|
|
43
|
+
*
|
|
44
|
+
* @param configuration The proof server to send ledger-v9 proving requests to.
|
|
45
|
+
* @returns A backend that proves ledger-v9 transactions over HTTP.
|
|
46
|
+
*/
|
|
47
|
+
export declare const makeV9ServerProvingServiceEffect: (configuration: ServerProvingConfiguration) => V9ProvingServiceEffect;
|
|
48
|
+
/**
|
|
49
|
+
* Proves ledger-v9 transactions in this process.
|
|
50
|
+
*
|
|
51
|
+
* @remarks
|
|
52
|
+
* The ledger-v9 twin of `makeV8WasmProvingServiceEffect`: the same bundled prover, with ledger-v9's key material —
|
|
53
|
+
* circuit generation 10 ({@link WasmProver.makeV9KeyMaterialProvider}) — unless it is given key material of its own.
|
|
54
|
+
* @param configuration Optional key material override.
|
|
55
|
+
* @returns A backend that proves ledger-v9 transactions in-process.
|
|
56
|
+
*/
|
|
57
|
+
export declare const makeV9WasmProvingServiceEffect: (configuration?: WasmProvingConfiguration) => V9ProvingServiceEffect;
|
|
58
|
+
/**
|
|
59
|
+
* Erases the proofs of ledger-v9 transactions instead of proving them, for the in-memory simulator.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```typescript
|
|
63
|
+
* const proving = makeV9SimulatorProvingServiceEffect();
|
|
64
|
+
* const proofErased = yield* proving.prove(unprovenTransaction);
|
|
65
|
+
* yield* simulator.submitTransaction(proofErased);
|
|
66
|
+
* ```;
|
|
67
|
+
*
|
|
68
|
+
* @returns A backend that hands back each ledger-v9 transaction proof-erased, which the simulator accepts.
|
|
69
|
+
*/
|
|
70
|
+
export declare const makeV9SimulatorProvingServiceEffect: () => ProvingServiceEffect<ledger.ProofErasedTransaction, V9UnprovenTransaction>;
|
|
71
|
+
/**
|
|
72
|
+
* The promise-facing surface of {@link makeV9ServerProvingServiceEffect}.
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* const proving = makeV9ServerProvingService({ provingServerUrl: new URL('http://localhost:6300') });
|
|
77
|
+
* const unbound = await proving.prove(unprovenTransaction);
|
|
78
|
+
* ```;
|
|
79
|
+
*
|
|
80
|
+
* @param configuration The proof server to send ledger-v9 proving requests to.
|
|
81
|
+
* @returns A backend that proves ledger-v9 transactions over HTTP.
|
|
82
|
+
*/
|
|
83
|
+
export declare const makeV9ServerProvingService: (configuration: ServerProvingConfiguration) => V9ProvingService;
|
|
84
|
+
/**
|
|
85
|
+
* The promise-facing surface of {@link makeV9WasmProvingServiceEffect}.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const proving = makeV9WasmProvingService();
|
|
90
|
+
* const unbound = await proving.prove(unprovenTransaction);
|
|
91
|
+
* ```;
|
|
92
|
+
*
|
|
93
|
+
* @param configuration Optional key material override.
|
|
94
|
+
* @returns A backend that proves ledger-v9 transactions in-process.
|
|
95
|
+
*/
|
|
96
|
+
export declare const makeV9WasmProvingService: (configuration?: WasmProvingConfiguration) => V9ProvingService;
|
|
97
|
+
/**
|
|
98
|
+
* The promise-facing surface of {@link makeV9SimulatorProvingServiceEffect}.
|
|
99
|
+
*
|
|
100
|
+
* @example
|
|
101
|
+
* ```typescript
|
|
102
|
+
* const proving = makeV9SimulatorProvingService();
|
|
103
|
+
* const proofErased = await proving.prove(unprovenTransaction);
|
|
104
|
+
* ```;
|
|
105
|
+
*
|
|
106
|
+
* @returns A backend that hands back each ledger-v9 transaction proof-erased, which the simulator accepts.
|
|
107
|
+
*/
|
|
108
|
+
export declare const makeV9SimulatorProvingService: () => ProvingService<ledger.ProofErasedTransaction, V9UnprovenTransaction>;
|