@midnight-ntwrk/wallet-sdk-shielded 1.0.0 → 2.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/ShieldedWallet.d.ts +24 -27
- package/dist/ShieldedWallet.js +12 -6
- package/dist/v1/CoreWallet.d.ts +4 -5
- package/dist/v1/CoreWallet.js +9 -10
- package/dist/v1/Proving.d.ts +12 -2
- package/dist/v1/Proving.js +15 -5
- package/dist/v1/RunningV1Variant.d.ts +13 -15
- package/dist/v1/RunningV1Variant.js +5 -5
- package/dist/v1/Serialization.js +1 -25
- package/dist/v1/Simulator.d.ts +2 -2
- package/dist/v1/Simulator.js +1 -1
- package/dist/v1/Transacting.d.ts +4 -3
- package/dist/v1/Transacting.js +24 -33
- package/dist/v1/TransactionHistory.js +6 -6
- package/dist/v1/V1Builder.d.ts +14 -20
- package/dist/v1/V1Builder.js +1 -16
- package/dist/v1/index.d.ts +0 -1
- package/dist/v1/index.js +0 -1
- package/package.json +6 -5
- package/dist/v1/Submission.d.ts +0 -31
- package/dist/v1/Submission.js +0 -69
package/README.md
CHANGED
|
@@ -54,7 +54,7 @@ await shieldedWallet.start(shieldedSecretKeys);
|
|
|
54
54
|
|
|
55
55
|
```typescript
|
|
56
56
|
// Start directly with a shielded seed
|
|
57
|
-
const shieldedWallet = ShieldedWallet(configuration).
|
|
57
|
+
const shieldedWallet = ShieldedWallet(configuration).startWithSeed(seed);
|
|
58
58
|
await shieldedWallet.start(ledger.ZswapSecretKeys.fromSeed(seed));
|
|
59
59
|
```
|
|
60
60
|
|
package/dist/ShieldedWallet.d.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import { ProtocolState, ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
2
|
-
import { BaseV1Configuration, DefaultV1Configuration, V1Variant, CoreWallet } from './v1/index.js';
|
|
1
|
+
import { type ProtocolState, ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
2
|
+
import { type BaseV1Configuration, type DefaultV1Configuration, type V1Variant, CoreWallet } from './v1/index.js';
|
|
3
3
|
import * as ledger from '@midnight-ntwrk/ledger-v7';
|
|
4
4
|
import * as rx from 'rxjs';
|
|
5
|
-
import { BalancingResult } from './v1/Transacting.js';
|
|
6
|
-
import { SerializationCapability } from './v1/Serialization.js';
|
|
7
|
-
import { ProgressUpdate, TransactionHistoryCapability } from './v1/TransactionHistory.js';
|
|
8
|
-
import { AvailableCoin, CoinsAndBalancesCapability, PendingCoin } from './v1/CoinsAndBalances.js';
|
|
9
|
-
import { KeysCapability } from './v1/Keys.js';
|
|
10
|
-
import { ShieldedAddress, ShieldedCoinPublicKey, ShieldedEncryptionPublicKey } from '@midnight-ntwrk/wallet-sdk-address-format';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { Variant, VariantBuilder, WalletLike } from '@midnight-ntwrk/wallet-sdk-runtime/abstractions';
|
|
5
|
+
import { type BalancingResult } from './v1/Transacting.js';
|
|
6
|
+
import { type SerializationCapability } from './v1/Serialization.js';
|
|
7
|
+
import { type ProgressUpdate, type TransactionHistoryCapability } from './v1/TransactionHistory.js';
|
|
8
|
+
import { type AvailableCoin, type CoinsAndBalancesCapability, type PendingCoin } from './v1/CoinsAndBalances.js';
|
|
9
|
+
import { type KeysCapability } from './v1/Keys.js';
|
|
10
|
+
import { type ShieldedAddress, type ShieldedCoinPublicKey, type ShieldedEncryptionPublicKey } from '@midnight-ntwrk/wallet-sdk-address-format';
|
|
11
|
+
import { type TokenTransfer } from './v1/Transacting.js';
|
|
12
|
+
import { type WalletSyncUpdate } from './v1/Sync.js';
|
|
13
|
+
import { type Variant, type VariantBuilder, type WalletLike } from '@midnight-ntwrk/wallet-sdk-runtime/abstractions';
|
|
15
14
|
export type ShieldedWalletCapabilities<TSerialized = string, TTransaction = ledger.FinalizedTransaction> = {
|
|
16
15
|
serialization: SerializationCapability<CoreWallet, null, TSerialized>;
|
|
17
16
|
coinsAndBalances: CoinsAndBalancesCapability<CoreWallet>;
|
|
@@ -32,38 +31,36 @@ export declare class ShieldedWalletState<TSerialized = string, TTransaction = le
|
|
|
32
31
|
get encryptionPublicKey(): ShieldedEncryptionPublicKey;
|
|
33
32
|
get address(): ShieldedAddress;
|
|
34
33
|
get progress(): ProgressUpdate;
|
|
35
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Transaction history for the wallet.
|
|
36
|
+
* @throws Error - Not yet implemented
|
|
37
|
+
*/
|
|
38
|
+
get transactionHistory(): never;
|
|
36
39
|
constructor(state: ProtocolState.ProtocolState<CoreWallet>, capabilities: ShieldedWalletCapabilities<TSerialized, TTransaction>);
|
|
37
40
|
serialize(): TSerialized;
|
|
38
41
|
}
|
|
39
|
-
export type SubmitTransactionMethod<TTransaction> = {
|
|
40
|
-
(transaction: TTransaction, waitForStatus: 'Submitted'): Promise<SubmissionEventCases.Submitted>;
|
|
41
|
-
(transaction: TTransaction, waitForStatus: 'InBlock'): Promise<SubmissionEventCases.InBlock>;
|
|
42
|
-
(transaction: TTransaction, waitForStatus: 'Finalized'): Promise<SubmissionEventCases.Finalized>;
|
|
43
|
-
(transaction: TTransaction): Promise<SubmissionEventCases.InBlock>;
|
|
44
|
-
(transaction: TTransaction, waitForStatus?: 'Submitted' | 'InBlock' | 'Finalized'): Promise<SubmissionEvent>;
|
|
45
|
-
};
|
|
46
42
|
export type ShieldedWallet = CustomizedShieldedWallet<ledger.ZswapSecretKeys, ledger.FinalizedTransaction, WalletSyncUpdate, string>;
|
|
47
43
|
export type ShieldedWalletClass = CustomizedShieldedWalletClass<ledger.ZswapSecretKeys, ledger.FinalizedTransaction, WalletSyncUpdate, string>;
|
|
48
|
-
export
|
|
49
|
-
Variant.VersionedVariant<V1Variant<TSerialized, TSyncUpdate, TTransaction, TStartAux>>
|
|
50
|
-
]> {
|
|
44
|
+
export type ShieldedWalletAPI<TStartAux = ledger.ZswapSecretKeys, TTransaction = ledger.FinalizedTransaction, TSerialized = string> = {
|
|
51
45
|
readonly state: rx.Observable<ShieldedWalletState<TSerialized, TTransaction>>;
|
|
52
46
|
start(secretKeys: TStartAux): Promise<void>;
|
|
53
47
|
balanceTransaction(secretKeys: ledger.ZswapSecretKeys, tx: ledger.Transaction<ledger.Signaturish, ledger.Proofish, ledger.Bindingish>): Promise<BalancingResult>;
|
|
54
48
|
transferTransaction(secretKeys: ledger.ZswapSecretKeys, outputs: readonly TokenTransfer[]): Promise<ledger.UnprovenTransaction>;
|
|
55
49
|
initSwap(secretKeys: ledger.ZswapSecretKeys, desiredInputs: Record<ledger.RawTokenType, bigint>, desiredOutputs: readonly TokenTransfer[]): Promise<ledger.UnprovenTransaction>;
|
|
56
50
|
finalizeTransaction(transaction: ledger.UnprovenTransaction): Promise<TTransaction>;
|
|
57
|
-
readonly submitTransaction: SubmitTransactionMethod<TTransaction>;
|
|
58
51
|
serializeState(): Promise<TSerialized>;
|
|
59
52
|
waitForSyncedState(allowedGap?: bigint): Promise<ShieldedWalletState<TSerialized, TTransaction>>;
|
|
60
53
|
getAddress(): Promise<ShieldedAddress>;
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
revertTransaction(transaction: ledger.Transaction<ledger.Signaturish, ledger.Proofish, ledger.Bindingish>): Promise<void>;
|
|
55
|
+
stop(): Promise<void>;
|
|
56
|
+
};
|
|
57
|
+
export type CustomizedShieldedWallet<TStartAux = ledger.ZswapSecretKeys, TTransaction = ledger.FinalizedTransaction, TSyncUpdate = WalletSyncUpdate, TSerialized = string> = ShieldedWalletAPI<TStartAux, TTransaction, TSerialized> & WalletLike.WalletLike<[Variant.VersionedVariant<V1Variant<TSerialized, TSyncUpdate, TTransaction, TStartAux>>]>;
|
|
58
|
+
export type DefaultShieldedConfiguration = DefaultV1Configuration;
|
|
59
|
+
export interface CustomizedShieldedWalletClass<TStartAux = ledger.ZswapSecretKeys, TTransaction = ledger.FinalizedTransaction, TSyncUpdate = WalletSyncUpdate, TSerialized = string, TConfig extends BaseV1Configuration = DefaultShieldedConfiguration> extends WalletLike.BaseWalletClass<[
|
|
63
60
|
Variant.VersionedVariant<V1Variant<TSerialized, TSyncUpdate, TTransaction, TStartAux>>
|
|
64
61
|
]> {
|
|
65
62
|
configuration: TConfig;
|
|
66
|
-
|
|
63
|
+
startWithSeed(seed: Uint8Array): CustomizedShieldedWallet<TStartAux, TTransaction, TSyncUpdate, TSerialized>;
|
|
67
64
|
startWithSecretKeys(secretKeys: ledger.ZswapSecretKeys): CustomizedShieldedWallet<TStartAux, TTransaction, TSyncUpdate, TSerialized>;
|
|
68
65
|
restore(serializedState: TSerialized): CustomizedShieldedWallet<TStartAux, TTransaction, TSyncUpdate, TSerialized>;
|
|
69
66
|
}
|
package/dist/ShieldedWallet.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
14
|
-
import { V1Builder, V1Tag, CoreWallet } from './v1/index.js';
|
|
14
|
+
import { V1Builder, V1Tag, CoreWallet, } from './v1/index.js';
|
|
15
15
|
import * as ledger from '@midnight-ntwrk/ledger-v7';
|
|
16
16
|
import { Effect, Either } from 'effect';
|
|
17
17
|
import * as rx from 'rxjs';
|
|
@@ -47,8 +47,12 @@ export class ShieldedWalletState {
|
|
|
47
47
|
get progress() {
|
|
48
48
|
return this.capabilities.transactionHistory.progress(this.state);
|
|
49
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Transaction history for the wallet.
|
|
52
|
+
* @throws Error - Not yet implemented
|
|
53
|
+
*/
|
|
50
54
|
get transactionHistory() {
|
|
51
|
-
|
|
55
|
+
throw new Error('Transaction history is not yet implemented for ShieldedWallet');
|
|
52
56
|
}
|
|
53
57
|
constructor(state, capabilities) {
|
|
54
58
|
this.protocolVersion = state.version;
|
|
@@ -71,7 +75,7 @@ export function CustomShieldedWallet(configuration, builder) {
|
|
|
71
75
|
static startWithSecretKeys(secretKeys) {
|
|
72
76
|
return CustomShieldedWalletImplementation.startFirst(CustomShieldedWalletImplementation, CoreWallet.initEmpty(secretKeys, CustomShieldedWalletImplementation.configuration.networkId));
|
|
73
77
|
}
|
|
74
|
-
static
|
|
78
|
+
static startWithSeed(seed) {
|
|
75
79
|
const secretKeys = ledger.ZswapSecretKeys.fromSeed(seed);
|
|
76
80
|
return CustomShieldedWalletImplementation.startWithSecretKeys(secretKeys);
|
|
77
81
|
}
|
|
@@ -114,11 +118,13 @@ export function CustomShieldedWallet(configuration, builder) {
|
|
|
114
118
|
})
|
|
115
119
|
.pipe(Effect.runPromise);
|
|
116
120
|
}
|
|
117
|
-
|
|
121
|
+
revertTransaction(transaction) {
|
|
118
122
|
return this.runtime
|
|
119
|
-
.dispatch({
|
|
123
|
+
.dispatch({
|
|
124
|
+
[V1Tag]: (v1) => v1.revertTransaction(transaction),
|
|
125
|
+
})
|
|
120
126
|
.pipe(Effect.runPromise);
|
|
121
|
-
}
|
|
127
|
+
}
|
|
122
128
|
waitForSyncedState(allowedGap = 0n) {
|
|
123
129
|
return rx.firstValueFrom(this.state.pipe(rx.filter((state) => state.state.progress.isCompleteWithin(allowedGap))));
|
|
124
130
|
}
|
package/dist/v1/CoreWallet.d.ts
CHANGED
|
@@ -28,22 +28,21 @@ export type CoreWallet = Readonly<{
|
|
|
28
28
|
protocolVersion: ProtocolVersion.ProtocolVersion;
|
|
29
29
|
progress: SyncProgress;
|
|
30
30
|
networkId: string;
|
|
31
|
-
txHistoryArray: readonly ledger.FinalizedTransaction[];
|
|
32
31
|
coinHashes: CoinHashesMap;
|
|
33
32
|
}>;
|
|
34
33
|
export declare const CoreWallet: {
|
|
35
34
|
init(localState: ledger.ZswapLocalState, secretKeys: ledger.ZswapSecretKeys, networkId: string): CoreWallet;
|
|
36
35
|
empty(publicKeys: PublicKeys, networkId: string): CoreWallet;
|
|
37
|
-
restore(localState: ledger.ZswapLocalState, secretKeys: ledger.ZswapSecretKeys,
|
|
38
|
-
restoreWithCoinHashes(publicKeys: PublicKeys, localState: ledger.ZswapLocalState,
|
|
36
|
+
restore(localState: ledger.ZswapLocalState, secretKeys: ledger.ZswapSecretKeys, syncProgress: Omit<SyncProgressData, "isConnected">, protocolVersion: bigint, networkId: string): CoreWallet;
|
|
37
|
+
restoreWithCoinHashes(publicKeys: PublicKeys, localState: ledger.ZswapLocalState, coinHashes: CoinHashesMap, syncProgress: SyncProgressData, protocolVersion: bigint, networkId: string): Either.Either<CoreWallet, WalletError>;
|
|
39
38
|
initEmpty(keys: ledger.ZswapSecretKeys, networkId: string): CoreWallet;
|
|
40
39
|
applyCollapsedUpdate(wallet: CoreWallet, collapsed: ledger.MerkleTreeCollapsedUpdate): CoreWallet;
|
|
41
40
|
apply<TOffer extends ledger.ZswapOffer<ledger.Proofish>>(wallet: CoreWallet, secretKeys: ledger.ZswapSecretKeys, offer: TOffer): CoreWallet;
|
|
42
41
|
replayEvents(wallet: CoreWallet, secretKeys: ledger.ZswapSecretKeys, events: ledger.Event[]): CoreWallet;
|
|
43
42
|
updateProgress(wallet: CoreWallet, { appliedIndex, highestRelevantWalletIndex, highestIndex, highestRelevantIndex, isConnected, }: Partial<SyncProgressData>): CoreWallet;
|
|
44
|
-
addTransaction(wallet: CoreWallet,
|
|
43
|
+
addTransaction(wallet: CoreWallet, _tx: ledger.FinalizedTransaction): CoreWallet;
|
|
45
44
|
revertTransaction<TTx extends ledger.Transaction<ledger.Signaturish, ledger.Proofish, ledger.Bindingish>>(wallet: CoreWallet, _tx: TTx): CoreWallet;
|
|
46
|
-
updateTxHistory(wallet: CoreWallet,
|
|
45
|
+
updateTxHistory(wallet: CoreWallet, _newTxs: readonly ledger.FinalizedTransaction[]): CoreWallet;
|
|
47
46
|
spendCoins(wallet: CoreWallet, secretKeys: ledger.ZswapSecretKeys, coins: ReadonlyArray<ledger.QualifiedShieldedCoinInfo>, segment: number): [ReadonlyArray<ledger.ZswapOffer<ledger.PreProof>>, CoreWallet];
|
|
48
47
|
watchCoins(wallet: CoreWallet, secretKeys: ledger.ZswapSecretKeys, coins: ReadonlyArray<ledger.ShieldedCoinInfo>): CoreWallet;
|
|
49
48
|
};
|
package/dist/v1/CoreWallet.js
CHANGED
|
@@ -58,7 +58,7 @@ export const CoreWallet = {
|
|
|
58
58
|
const coinHashes = CoinHashesMap.init(secretKeys, CoinHashesMap.pickAllCoins(localState));
|
|
59
59
|
const progress = createSyncProgress();
|
|
60
60
|
const protocolVersion = ProtocolVersion.MinSupportedVersion;
|
|
61
|
-
return { state: localState, publicKeys, networkId, coinHashes,
|
|
61
|
+
return { state: localState, publicKeys, networkId, coinHashes, progress, protocolVersion };
|
|
62
62
|
},
|
|
63
63
|
empty(publicKeys, networkId) {
|
|
64
64
|
return {
|
|
@@ -66,12 +66,11 @@ export const CoreWallet = {
|
|
|
66
66
|
publicKeys,
|
|
67
67
|
networkId,
|
|
68
68
|
coinHashes: CoinHashesMap.empty,
|
|
69
|
-
txHistoryArray: [],
|
|
70
69
|
progress: createSyncProgress(),
|
|
71
70
|
protocolVersion: ProtocolVersion.MinSupportedVersion,
|
|
72
71
|
};
|
|
73
72
|
},
|
|
74
|
-
restore(localState, secretKeys,
|
|
73
|
+
restore(localState, secretKeys, syncProgress, protocolVersion, networkId) {
|
|
75
74
|
const publicKeys = PublicKeys.fromSecretKeys(secretKeys);
|
|
76
75
|
const coinHashes = CoinHashesMap.init(secretKeys, CoinHashesMap.pickAllCoins(localState));
|
|
77
76
|
return {
|
|
@@ -79,12 +78,11 @@ export const CoreWallet = {
|
|
|
79
78
|
publicKeys,
|
|
80
79
|
networkId,
|
|
81
80
|
coinHashes,
|
|
82
|
-
txHistoryArray: txHistory,
|
|
83
81
|
progress: createSyncProgress(syncProgress),
|
|
84
82
|
protocolVersion: ProtocolVersion.ProtocolVersion(protocolVersion),
|
|
85
83
|
};
|
|
86
84
|
},
|
|
87
|
-
restoreWithCoinHashes(publicKeys, localState,
|
|
85
|
+
restoreWithCoinHashes(publicKeys, localState, coinHashes, syncProgress, protocolVersion, networkId) {
|
|
88
86
|
return CoinHashesMap.assertValid(coinHashes, localState).pipe(Either.mapBoth({
|
|
89
87
|
onLeft: (missingNonces) => new InvalidCoinHashesError({ message: 'Missing coin hashes for coins present in the state', missingNonces }),
|
|
90
88
|
onRight: () => ({
|
|
@@ -92,7 +90,6 @@ export const CoreWallet = {
|
|
|
92
90
|
publicKeys,
|
|
93
91
|
networkId,
|
|
94
92
|
coinHashes,
|
|
95
|
-
txHistoryArray: txHistory,
|
|
96
93
|
progress: createSyncProgress(syncProgress),
|
|
97
94
|
protocolVersion: ProtocolVersion.ProtocolVersion(protocolVersion),
|
|
98
95
|
}),
|
|
@@ -125,15 +122,17 @@ export const CoreWallet = {
|
|
|
125
122
|
});
|
|
126
123
|
return { ...wallet, progress: updatedProgress };
|
|
127
124
|
},
|
|
128
|
-
|
|
129
|
-
|
|
125
|
+
// TODO: Remove after tx history is implemented
|
|
126
|
+
addTransaction(wallet, _tx) {
|
|
127
|
+
return wallet;
|
|
130
128
|
},
|
|
131
129
|
/* not implemented until this is done https://shielded.atlassian.net/browse/PM-19678 */
|
|
132
130
|
revertTransaction(wallet, _tx) {
|
|
133
131
|
return wallet;
|
|
134
132
|
},
|
|
135
|
-
|
|
136
|
-
|
|
133
|
+
// TODO: Remove after tx history is implemented
|
|
134
|
+
updateTxHistory(wallet, _newTxs) {
|
|
135
|
+
return wallet;
|
|
137
136
|
},
|
|
138
137
|
spendCoins(wallet, secretKeys, coins, segment) {
|
|
139
138
|
const [offers, newLocalState] = pipe(coins, Arr.reduce([[], wallet.state], ([accOffers, localState], coinToSpend) => {
|
package/dist/v1/Proving.d.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
import * as ledger from '@midnight-ntwrk/ledger-v7';
|
|
2
|
-
import {
|
|
2
|
+
import type { KeyMaterialProvider } from '@midnight-ntwrk/zkir-v2';
|
|
3
|
+
import { ProverClient } from '@midnight-ntwrk/wallet-sdk-prover-client/effect';
|
|
4
|
+
import { InvalidProtocolSchemeError } from '@midnight-ntwrk/wallet-sdk-utilities/networking';
|
|
5
|
+
import { Effect, Layer } from 'effect';
|
|
3
6
|
import { WalletError } from './WalletError.js';
|
|
4
7
|
export interface ProvingService<TTransaction> {
|
|
5
8
|
prove(transaction: ledger.UnprovenTransaction): Effect.Effect<TTransaction, WalletError>;
|
|
6
9
|
}
|
|
7
|
-
export
|
|
10
|
+
export declare const makeProvingService: (clientLayer: Layer.Layer<ProverClient.ProverClient, InvalidProtocolSchemeError>) => ProvingService<ledger.FinalizedTransaction>;
|
|
11
|
+
export type WasmProvingConfiguration = {
|
|
12
|
+
keyMaterialProvider?: KeyMaterialProvider;
|
|
13
|
+
};
|
|
14
|
+
export type ProvingServerConfiguration = {
|
|
8
15
|
provingServerUrl: URL;
|
|
9
16
|
};
|
|
17
|
+
export type DefaultProvingConfiguration = ProvingServerConfiguration;
|
|
10
18
|
export declare const makeDefaultProvingService: (configuration: DefaultProvingConfiguration) => ProvingService<ledger.FinalizedTransaction>;
|
|
19
|
+
export declare const makeServerProvingService: (configuration: ProvingServerConfiguration) => ProvingService<ledger.FinalizedTransaction>;
|
|
20
|
+
export declare const makeWasmProvingService: (configuration: WasmProvingConfiguration) => ProvingService<ledger.FinalizedTransaction>;
|
|
11
21
|
export declare const makeSimulatorProvingService: () => ProvingService<ledger.ProofErasedTransaction>;
|
package/dist/v1/Proving.js
CHANGED
|
@@ -10,14 +10,11 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import { HttpProverClient, ProverClient } from '@midnight-ntwrk/wallet-sdk-prover-client/effect';
|
|
14
13
|
import * as ledger from '@midnight-ntwrk/ledger-v7';
|
|
14
|
+
import { HttpProverClient, WasmProver, ProverClient } from '@midnight-ntwrk/wallet-sdk-prover-client/effect';
|
|
15
15
|
import { Effect, pipe } from 'effect';
|
|
16
16
|
import { ProvingError } from './WalletError.js';
|
|
17
|
-
export const
|
|
18
|
-
const clientLayer = HttpProverClient.layer({
|
|
19
|
-
url: configuration.provingServerUrl,
|
|
20
|
-
});
|
|
17
|
+
export const makeProvingService = (clientLayer) => {
|
|
21
18
|
return {
|
|
22
19
|
prove(transaction) {
|
|
23
20
|
return pipe(ProverClient.ProverClient, Effect.flatMap((client) => client.proveTransaction(transaction, ledger.CostModel.initialCostModel())), Effect.map((transaction) => transaction.bind()), Effect.provide(clientLayer), Effect.catchAll((error) => Effect.fail(new ProvingError({
|
|
@@ -27,6 +24,19 @@ export const makeDefaultProvingService = (configuration) => {
|
|
|
27
24
|
},
|
|
28
25
|
};
|
|
29
26
|
};
|
|
27
|
+
export const makeDefaultProvingService = (configuration) => makeServerProvingService(configuration);
|
|
28
|
+
export const makeServerProvingService = (configuration) => {
|
|
29
|
+
const clientLayer = HttpProverClient.layer({
|
|
30
|
+
url: configuration.provingServerUrl,
|
|
31
|
+
});
|
|
32
|
+
return makeProvingService(clientLayer);
|
|
33
|
+
};
|
|
34
|
+
export const makeWasmProvingService = (configuration) => {
|
|
35
|
+
const proverLayer = WasmProver.layer({
|
|
36
|
+
keyMaterialProvider: configuration.keyMaterialProvider ?? WasmProver.makeDefaultKeyMaterialProvider(),
|
|
37
|
+
});
|
|
38
|
+
return makeProvingService(proverLayer);
|
|
39
|
+
};
|
|
30
40
|
export const makeSimulatorProvingService = () => {
|
|
31
41
|
return {
|
|
32
42
|
prove(transaction) {
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import * as ledger from '@midnight-ntwrk/ledger-v7';
|
|
1
|
+
import type * as ledger from '@midnight-ntwrk/ledger-v7';
|
|
2
2
|
import { Effect, Scope, Stream } from 'effect';
|
|
3
|
-
import { WalletRuntimeError, Variant, StateChange } from '@midnight-ntwrk/wallet-sdk-runtime/abstractions';
|
|
4
|
-
import { ProvingService } from './Proving.js';
|
|
5
|
-
import { SerializationCapability } from './Serialization.js';
|
|
6
|
-
import { EventsSyncUpdate, SyncCapability, SyncService } from './Sync.js';
|
|
7
|
-
import { TransactingCapability, TokenTransfer, BalancingResult } from './Transacting.js';
|
|
8
|
-
import { WalletError } from './WalletError.js';
|
|
9
|
-
import { CoinsAndBalancesCapability } from './CoinsAndBalances.js';
|
|
10
|
-
import { KeysCapability } from './Keys.js';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { TransactionHistoryCapability } from './TransactionHistory.js';
|
|
3
|
+
import { type WalletRuntimeError, type Variant, StateChange } from '@midnight-ntwrk/wallet-sdk-runtime/abstractions';
|
|
4
|
+
import { type ProvingService } from './Proving.js';
|
|
5
|
+
import { type SerializationCapability } from './Serialization.js';
|
|
6
|
+
import { type EventsSyncUpdate, type SyncCapability, type SyncService } from './Sync.js';
|
|
7
|
+
import { type TransactingCapability, type TokenTransfer, type BalancingResult } from './Transacting.js';
|
|
8
|
+
import { type WalletError } from './WalletError.js';
|
|
9
|
+
import { type CoinsAndBalancesCapability } from './CoinsAndBalances.js';
|
|
10
|
+
import { type KeysCapability } from './Keys.js';
|
|
11
|
+
import { type CoinSelection } from '@midnight-ntwrk/wallet-sdk-capabilities';
|
|
12
|
+
import { type CoreWallet } from './CoreWallet.js';
|
|
13
|
+
import { type TransactionHistoryCapability } from './TransactionHistory.js';
|
|
15
14
|
export declare namespace RunningV1Variant {
|
|
16
15
|
type Context<TSerialized, TSyncUpdate, TTransaction, TStartAux> = {
|
|
17
16
|
serializationCapability: SerializationCapability<CoreWallet, null, TSerialized>;
|
|
@@ -21,7 +20,6 @@ export declare namespace RunningV1Variant {
|
|
|
21
20
|
provingService: ProvingService<TTransaction>;
|
|
22
21
|
coinsAndBalancesCapability: CoinsAndBalancesCapability<CoreWallet>;
|
|
23
22
|
keysCapability: KeysCapability<CoreWallet>;
|
|
24
|
-
submissionService: SubmissionService<TTransaction>;
|
|
25
23
|
coinSelection: CoinSelection<ledger.QualifiedShieldedCoinInfo>;
|
|
26
24
|
transactionHistoryCapability: TransactionHistoryCapability<CoreWallet, TTransaction>;
|
|
27
25
|
};
|
|
@@ -40,6 +38,6 @@ export declare class RunningV1Variant<TSerialized, TSyncUpdate, TTransaction, TS
|
|
|
40
38
|
transferTransaction(secretKeys: ledger.ZswapSecretKeys, outputs: ReadonlyArray<TokenTransfer>): Effect.Effect<ledger.UnprovenTransaction, WalletError>;
|
|
41
39
|
initSwap(secretKeys: ledger.ZswapSecretKeys, desiredInputs: Record<ledger.RawTokenType, bigint>, desiredOutputs: ReadonlyArray<TokenTransfer>): Effect.Effect<ledger.UnprovenTransaction, WalletError>;
|
|
42
40
|
finalizeTransaction(transaction: ledger.UnprovenTransaction): Effect.Effect<TTransaction, WalletError>;
|
|
43
|
-
|
|
41
|
+
revertTransaction(transaction: ledger.Transaction<ledger.Signaturish, ledger.Proofish, ledger.Bindingish>): Effect.Effect<void, WalletError>;
|
|
44
42
|
serializeState(state: CoreWallet): TSerialized;
|
|
45
43
|
}
|
|
@@ -84,11 +84,11 @@ export class RunningV1Variant {
|
|
|
84
84
|
.prove(transaction)
|
|
85
85
|
.pipe(Effect.tapError(() => SubscriptionRef.updateEffect(this.#context.stateRef, (state) => EitherOps.toEffect(this.#v1Context.transactingCapability.revertTransaction(state, transaction)))));
|
|
86
86
|
}
|
|
87
|
-
|
|
88
|
-
return this.#
|
|
89
|
-
.
|
|
90
|
-
|
|
91
|
-
}
|
|
87
|
+
revertTransaction(transaction) {
|
|
88
|
+
return SubscriptionRef.updateEffect(this.#context.stateRef, (state) => {
|
|
89
|
+
return pipe(this.#v1Context.transactingCapability.revertTransaction(state, transaction), EitherOps.toEffect);
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
92
|
serializeState(state) {
|
|
93
93
|
return this.#v1Context.serializationCapability.serialize(state);
|
|
94
94
|
}
|
package/dist/v1/Serialization.js
CHANGED
|
@@ -14,33 +14,12 @@ import { Effect, ParseResult, Either, pipe, Schema } from 'effect';
|
|
|
14
14
|
import { WalletError } from './WalletError.js';
|
|
15
15
|
import * as ledger from '@midnight-ntwrk/ledger-v7';
|
|
16
16
|
import { CoreWallet } from './CoreWallet.js';
|
|
17
|
-
const TxSchema = Schema.declare((input) => input instanceof ledger.Transaction).annotations({
|
|
18
|
-
identifier: 'ledger.Transaction',
|
|
19
|
-
});
|
|
20
17
|
const StateSchema = Schema.declare((input) => input instanceof ledger.ZswapLocalState).annotations({
|
|
21
18
|
identifier: 'ledger.ZswapLocalState',
|
|
22
19
|
});
|
|
23
20
|
const Uint8ArraySchema = Schema.declare((input) => input instanceof Uint8Array).annotations({
|
|
24
21
|
identifier: 'Uint8Array',
|
|
25
22
|
});
|
|
26
|
-
const TxFromUint8Array = () => Schema.asSchema(Schema.transformOrFail(Uint8ArraySchema, TxSchema, {
|
|
27
|
-
encode: (tx) => {
|
|
28
|
-
return Effect.try({
|
|
29
|
-
try: () => {
|
|
30
|
-
return tx.serialize();
|
|
31
|
-
},
|
|
32
|
-
catch: (err) => {
|
|
33
|
-
return new ParseResult.Unexpected(err, 'Could not serialize transaction');
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
},
|
|
37
|
-
decode: (bytes) => Effect.try({
|
|
38
|
-
try: () => ledger.Transaction.deserialize('signature', 'proof', 'binding', bytes),
|
|
39
|
-
catch: (err) => {
|
|
40
|
-
return new ParseResult.Unexpected(err, 'Could not deserialize transaction');
|
|
41
|
-
},
|
|
42
|
-
}),
|
|
43
|
-
}));
|
|
44
23
|
const StateFromUInt8Array = () => Schema.asSchema(Schema.transformOrFail(Uint8ArraySchema, StateSchema, {
|
|
45
24
|
encode: (state) => {
|
|
46
25
|
return Effect.try({
|
|
@@ -59,7 +38,6 @@ const StateFromUInt8Array = () => Schema.asSchema(Schema.transformOrFail(Uint8Ar
|
|
|
59
38
|
},
|
|
60
39
|
}),
|
|
61
40
|
}));
|
|
62
|
-
const HexedTx = () => pipe(Schema.Uint8ArrayFromHex, Schema.compose(TxFromUint8Array()));
|
|
63
41
|
const HexedState = () => pipe(Schema.Uint8ArrayFromHex, Schema.compose(StateFromUInt8Array()));
|
|
64
42
|
export const makeDefaultV1SerializationCapability = () => {
|
|
65
43
|
const SnapshotSchema = Schema.Struct({
|
|
@@ -67,7 +45,6 @@ export const makeDefaultV1SerializationCapability = () => {
|
|
|
67
45
|
coinPublicKey: Schema.String,
|
|
68
46
|
encryptionPublicKey: Schema.String,
|
|
69
47
|
}),
|
|
70
|
-
txHistory: Schema.Array(HexedTx()),
|
|
71
48
|
state: HexedState(),
|
|
72
49
|
protocolVersion: Schema.BigInt,
|
|
73
50
|
offset: Schema.optional(Schema.BigInt),
|
|
@@ -81,7 +58,6 @@ export const makeDefaultV1SerializationCapability = () => {
|
|
|
81
58
|
serialize: (wallet) => {
|
|
82
59
|
const buildSnapshot = (w) => ({
|
|
83
60
|
publicKeys: w.publicKeys,
|
|
84
|
-
txHistory: w.txHistoryArray,
|
|
85
61
|
state: w.state,
|
|
86
62
|
protocolVersion: w.protocolVersion,
|
|
87
63
|
networkId: w.networkId,
|
|
@@ -91,7 +67,7 @@ export const makeDefaultV1SerializationCapability = () => {
|
|
|
91
67
|
return pipe(wallet, buildSnapshot, Schema.encodeSync(SnapshotSchema), JSON.stringify);
|
|
92
68
|
},
|
|
93
69
|
deserialize: (aux, serialized) => {
|
|
94
|
-
return pipe(serialized, Schema.decodeUnknownEither(Schema.parseJson(SnapshotSchema)), Either.mapLeft((err) => WalletError.other(err)), Either.flatMap((snapshot) => CoreWallet.restoreWithCoinHashes(snapshot.publicKeys, snapshot.state, snapshot.
|
|
70
|
+
return pipe(serialized, Schema.decodeUnknownEither(Schema.parseJson(SnapshotSchema)), Either.mapLeft((err) => WalletError.other(err)), Either.flatMap((snapshot) => CoreWallet.restoreWithCoinHashes(snapshot.publicKeys, snapshot.state, snapshot.coinHashes, {
|
|
95
71
|
appliedIndex: snapshot.offset ?? 0n,
|
|
96
72
|
highestRelevantWalletIndex: 0n,
|
|
97
73
|
highestIndex: 0n,
|
package/dist/v1/Simulator.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as ledger from '@midnight-ntwrk/ledger-v7';
|
|
2
|
-
import { Array as Arr, Effect, Scope, Stream, SubscriptionRef } from 'effect';
|
|
2
|
+
import { Array as Arr, Effect, type Scope, Stream, SubscriptionRef } from 'effect';
|
|
3
3
|
export type SimulatorState = Readonly<{
|
|
4
4
|
ledger: ledger.LedgerState;
|
|
5
5
|
lastTxResult: ledger.TransactionResult;
|
|
@@ -15,7 +15,7 @@ export declare class Simulator {
|
|
|
15
15
|
}>>): Effect.Effect<Simulator, never, Scope.Scope>;
|
|
16
16
|
readonly state$: Stream.Stream<SimulatorState>;
|
|
17
17
|
constructor(stateRef: SubscriptionRef.SubscriptionRef<SimulatorState>, state$: Stream.Stream<SimulatorState>);
|
|
18
|
-
|
|
18
|
+
submitTransaction(tx: ledger.ProofErasedTransaction): Effect.Effect<{
|
|
19
19
|
blockNumber: bigint;
|
|
20
20
|
blockHash: string;
|
|
21
21
|
}>;
|
package/dist/v1/Simulator.js
CHANGED
|
@@ -76,7 +76,7 @@ export class Simulator {
|
|
|
76
76
|
this.#stateRef = stateRef;
|
|
77
77
|
this.state$ = state$;
|
|
78
78
|
}
|
|
79
|
-
|
|
79
|
+
submitTransaction(tx) {
|
|
80
80
|
return pipe(this.#stateRef, SubscriptionRef.modifyEffect((simulatorState) => Effect.gen(function* () {
|
|
81
81
|
const nextNumber = simulatorState.lastTxNumber + 1n;
|
|
82
82
|
const context = yield* Simulator.nextBlockContext(nextNumber);
|
package/dist/v1/Transacting.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { Array as Arr, Either } from 'effect';
|
|
|
4
4
|
import { CoreWallet } from './CoreWallet.js';
|
|
5
5
|
import { WalletError } from './WalletError.js';
|
|
6
6
|
import { CoinSelection } from '@midnight-ntwrk/wallet-sdk-capabilities';
|
|
7
|
+
import { ShieldedAddress } from '@midnight-ntwrk/wallet-sdk-address-format';
|
|
7
8
|
import { TransactionImbalances } from './TransactionImbalances.js';
|
|
8
9
|
import { TransactionOps } from './TransactionOps.js';
|
|
9
10
|
import { CoinsAndBalancesCapability } from './CoinsAndBalances.js';
|
|
@@ -11,14 +12,14 @@ import { KeysCapability } from './Keys.js';
|
|
|
11
12
|
export interface TokenTransfer {
|
|
12
13
|
readonly amount: bigint;
|
|
13
14
|
readonly type: ledger.RawTokenType;
|
|
14
|
-
readonly receiverAddress:
|
|
15
|
+
readonly receiverAddress: ShieldedAddress;
|
|
15
16
|
}
|
|
16
17
|
export type BalancingResult = ledger.UnprovenTransaction | undefined;
|
|
17
|
-
export interface TransactingCapability<TSecrets, TState,
|
|
18
|
+
export interface TransactingCapability<TSecrets, TState, _TTransaction> {
|
|
18
19
|
balanceTransaction(secrets: TSecrets, state: TState, tx: ledger.Transaction<ledger.Signaturish, ledger.Proofish, ledger.Bindingish>): Either.Either<[BalancingResult, TState], WalletError>;
|
|
19
20
|
makeTransfer(secrets: TSecrets, state: TState, outputs: ReadonlyArray<TokenTransfer>): Either.Either<[ledger.UnprovenTransaction, TState], WalletError>;
|
|
20
21
|
initSwap(secrets: TSecrets, state: TState, desiredInputs: Record<ledger.RawTokenType, bigint>, desiredOutputs: ReadonlyArray<TokenTransfer>): Either.Either<[ledger.UnprovenTransaction, TState], WalletError>;
|
|
21
|
-
revertTransaction(state: TState, transaction:
|
|
22
|
+
revertTransaction(state: TState, transaction: ledger.Transaction<ledger.Signaturish, ledger.Proofish, ledger.Bindingish>): Either.Either<TState, WalletError>;
|
|
22
23
|
}
|
|
23
24
|
export type DefaultTransactingConfiguration = {
|
|
24
25
|
networkId: NetworkId.NetworkId;
|
package/dist/v1/Transacting.js
CHANGED
|
@@ -14,9 +14,8 @@ import * as ledger from '@midnight-ntwrk/ledger-v7';
|
|
|
14
14
|
import { Array as Arr, Either, Option, pipe, Record } from 'effect';
|
|
15
15
|
import { ArrayOps } from '@midnight-ntwrk/wallet-sdk-utilities';
|
|
16
16
|
import { CoreWallet } from './CoreWallet.js';
|
|
17
|
-
import {
|
|
17
|
+
import { InsufficientFundsError, OtherWalletError } from './WalletError.js';
|
|
18
18
|
import { getBalanceRecipe, Imbalances, InsufficientFundsError as BalancingInsufficientFundsError, } from '@midnight-ntwrk/wallet-sdk-capabilities';
|
|
19
|
-
import { MidnightBech32m, ShieldedAddress } from '@midnight-ntwrk/wallet-sdk-address-format';
|
|
20
19
|
import { ShieldedCostModel, TransactionImbalances } from './TransactionImbalances.js';
|
|
21
20
|
import { TransactionOps } from './TransactionOps.js';
|
|
22
21
|
export const makeDefaultTransactingCapability = (config, getContext) => {
|
|
@@ -197,44 +196,36 @@ export class TransactingCapabilityImplementation {
|
|
|
197
196
|
}));
|
|
198
197
|
});
|
|
199
198
|
}
|
|
200
|
-
#
|
|
199
|
+
#processDesiredOutputs(state, transfers) {
|
|
201
200
|
return Either.try({
|
|
202
201
|
try: () => {
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
message: `Address parsing error: ${addr}`,
|
|
209
|
-
originalAddress: addr,
|
|
210
|
-
cause: err,
|
|
211
|
-
});
|
|
212
|
-
},
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
#processDesiredOutputs(state, transfers) {
|
|
216
|
-
return Either.gen(this, function* () {
|
|
217
|
-
const initialOffersAndCoins = yield* pipe(transfers, Arr.map((transfer) => {
|
|
218
|
-
return pipe(this.#parseAddress(transfer.receiverAddress), Either.map((address) => {
|
|
219
|
-
const coin = ledger.createShieldedCoinInfo(transfer.type, transfer.amount);
|
|
220
|
-
const output = ledger.ZswapOutput.new(coin, 0, address.coinPublicKey.toHexString(), address.encryptionPublicKey.toHexString());
|
|
221
|
-
const outputOffer = ledger.ZswapOffer.fromOutput(output, transfer.type, transfer.amount);
|
|
202
|
+
const initialOffersAndCoins = pipe(transfers, Arr.map((transfer) => {
|
|
203
|
+
const { receiverAddress, type, amount } = transfer;
|
|
204
|
+
const coin = ledger.createShieldedCoinInfo(type, amount);
|
|
205
|
+
const output = ledger.ZswapOutput.new(coin, 0, receiverAddress.coinPublicKey.toHexString(), receiverAddress.encryptionPublicKey.toHexString());
|
|
206
|
+
const outputOffer = ledger.ZswapOffer.fromOutput(output, type, amount);
|
|
222
207
|
return {
|
|
223
208
|
coin,
|
|
224
209
|
outputOffer,
|
|
225
|
-
isForSelf:
|
|
210
|
+
isForSelf: receiverAddress.coinPublicKey.equals(this.getKeys().getCoinPublicKey(state)),
|
|
226
211
|
};
|
|
227
212
|
}));
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
|
|
213
|
+
const selfCoins = Arr.flatMap(initialOffersAndCoins, ({ coin, isForSelf }) => {
|
|
214
|
+
if (isForSelf) {
|
|
215
|
+
return [coin];
|
|
216
|
+
}
|
|
217
|
+
else {
|
|
218
|
+
return [];
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
return { initialOffersAndCoins, selfCoins };
|
|
222
|
+
},
|
|
223
|
+
catch: (err) => {
|
|
224
|
+
return new OtherWalletError({
|
|
225
|
+
message: 'Failed to process desired outputs',
|
|
226
|
+
cause: err,
|
|
227
|
+
});
|
|
228
|
+
},
|
|
238
229
|
});
|
|
239
230
|
}
|
|
240
231
|
#processDesiredOutputsPossiblyEmpty(state, desiredOutputs) {
|
|
@@ -4,8 +4,8 @@ export const makeDefaultTransactionHistoryCapability = () => {
|
|
|
4
4
|
updateTxHistory: (state, newTxs) => {
|
|
5
5
|
return newTxs.reduce((acc, tx) => CoreWallet.addTransaction(acc, tx), state);
|
|
6
6
|
},
|
|
7
|
-
transactionHistory: (
|
|
8
|
-
return
|
|
7
|
+
transactionHistory: (_state) => {
|
|
8
|
+
return [];
|
|
9
9
|
},
|
|
10
10
|
progress: (state) => {
|
|
11
11
|
return {
|
|
@@ -22,8 +22,8 @@ export const makeSimulatorTransactionHistoryCapability = () => {
|
|
|
22
22
|
updateTxHistory: (state, newTxs) => {
|
|
23
23
|
return CoreWallet.updateTxHistory(state, newTxs); // @TODO fix this cast
|
|
24
24
|
},
|
|
25
|
-
transactionHistory: (
|
|
26
|
-
return
|
|
25
|
+
transactionHistory: (_state) => {
|
|
26
|
+
return [];
|
|
27
27
|
},
|
|
28
28
|
progress: (state) => {
|
|
29
29
|
return {
|
|
@@ -40,8 +40,8 @@ export const makeDiscardTransactionHistoryCapability = () => {
|
|
|
40
40
|
updateTxHistory: (state) => {
|
|
41
41
|
return state;
|
|
42
42
|
},
|
|
43
|
-
transactionHistory: (
|
|
44
|
-
return
|
|
43
|
+
transactionHistory: (_state) => {
|
|
44
|
+
return [];
|
|
45
45
|
},
|
|
46
46
|
progress: (state) => {
|
|
47
47
|
return {
|
package/dist/v1/V1Builder.d.ts
CHANGED
|
@@ -1,23 +1,22 @@
|
|
|
1
1
|
import * as ledger from '@midnight-ntwrk/ledger-v7';
|
|
2
|
-
import { Either, Types } from 'effect';
|
|
3
|
-
import { NetworkId } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
4
|
-
import { Variant, VariantBuilder } from '@midnight-ntwrk/wallet-sdk-runtime/abstractions';
|
|
5
|
-
import { DefaultProvingConfiguration, ProvingService } from './Proving.js';
|
|
2
|
+
import { type Either, type Types } from 'effect';
|
|
3
|
+
import { type NetworkId } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
4
|
+
import { type Variant, type VariantBuilder } from '@midnight-ntwrk/wallet-sdk-runtime/abstractions';
|
|
5
|
+
import { type DefaultProvingConfiguration, type ProvingService } from './Proving.js';
|
|
6
6
|
import { RunningV1Variant, V1Tag } from './RunningV1Variant.js';
|
|
7
|
-
import { SerializationCapability } from './Serialization.js';
|
|
8
|
-
import { DefaultSyncContext, DefaultSyncConfiguration, SyncCapability, SyncService, WalletSyncUpdate } from './Sync.js';
|
|
9
|
-
import { DefaultTransactingConfiguration, DefaultTransactingContext, TransactingCapability } from './Transacting.js';
|
|
10
|
-
import { WalletError } from './WalletError.js';
|
|
11
|
-
import { CoinsAndBalancesCapability } from './CoinsAndBalances.js';
|
|
12
|
-
import { KeysCapability } from './Keys.js';
|
|
13
|
-
import {
|
|
14
|
-
import { CoinSelection } from '@midnight-ntwrk/wallet-sdk-capabilities';
|
|
7
|
+
import { type SerializationCapability } from './Serialization.js';
|
|
8
|
+
import { type DefaultSyncContext, type DefaultSyncConfiguration, type SyncCapability, type SyncService, type WalletSyncUpdate } from './Sync.js';
|
|
9
|
+
import { type DefaultTransactingConfiguration, type DefaultTransactingContext, type TransactingCapability } from './Transacting.js';
|
|
10
|
+
import { type WalletError } from './WalletError.js';
|
|
11
|
+
import { type CoinsAndBalancesCapability } from './CoinsAndBalances.js';
|
|
12
|
+
import { type KeysCapability } from './Keys.js';
|
|
13
|
+
import { type CoinSelection } from '@midnight-ntwrk/wallet-sdk-capabilities';
|
|
15
14
|
import { CoreWallet } from './CoreWallet.js';
|
|
16
|
-
import { TransactionHistoryCapability } from './TransactionHistory.js';
|
|
15
|
+
import { type TransactionHistoryCapability } from './TransactionHistory.js';
|
|
17
16
|
export type BaseV1Configuration = {
|
|
18
17
|
networkId: NetworkId.NetworkId;
|
|
19
18
|
};
|
|
20
|
-
export type DefaultV1Configuration = BaseV1Configuration & DefaultSyncConfiguration & DefaultProvingConfiguration & DefaultTransactingConfiguration
|
|
19
|
+
export type DefaultV1Configuration = BaseV1Configuration & DefaultSyncConfiguration & DefaultProvingConfiguration & DefaultTransactingConfiguration;
|
|
21
20
|
declare const V1BuilderSymbol: {
|
|
22
21
|
readonly typeId: unique symbol;
|
|
23
22
|
};
|
|
@@ -56,8 +55,6 @@ export declare class V1Builder<TConfig extends BaseV1Configuration = BaseV1Confi
|
|
|
56
55
|
withTransactionHistory<TTransactionHistoryConfig, TTransactionHistoryContext extends Partial<RunningV1Variant.AnyContext>>(transactionHistoryCapability: (configuration: TTransactionHistoryConfig, getContext: () => TTransactionHistoryContext) => TransactionHistoryCapability<CoreWallet, TTransaction>): V1Builder<TConfig & TTransactionHistoryConfig, TContext & TTransactionHistoryContext, TSerialized, TSyncUpdate, TTransaction, TStartAux>;
|
|
57
56
|
withKeysDefaults(): V1Builder<TConfig, TContext, TSerialized, TSyncUpdate, TTransaction, TStartAux>;
|
|
58
57
|
withKeys<TKeysConfig, TKeysContext extends Partial<RunningV1Variant.AnyContext>>(keysCapability: (configuration: TKeysConfig, getContext: () => TKeysContext) => KeysCapability<CoreWallet>): V1Builder<TConfig & TKeysConfig, TContext & TKeysContext, TSerialized, TSyncUpdate, TTransaction, TStartAux>;
|
|
59
|
-
withSubmission<TSubmissionConfig, TSubmissionContext extends Partial<RunningV1Variant.AnyContext>>(submissionService: (config: TSubmissionConfig, getContext: () => TSubmissionContext) => SubmissionService<TTransaction>): V1Builder<TConfig & TSubmissionConfig, TContext & TSubmissionContext, TSerialized, TSyncUpdate, TTransaction, TStartAux>;
|
|
60
|
-
withSubmissionDefaults(this: V1Builder<TConfig, TContext, TSerialized, TSyncUpdate, ledger.FinalizedTransaction, TStartAux>): V1Builder<TConfig & DefaultSubmissionConfiguration, TContext, TSerialized, TSyncUpdate, ledger.FinalizedTransaction, TStartAux>;
|
|
61
58
|
build(this: V1Builder<TConfig, RunningV1Variant.Context<TSerialized, TSyncUpdate, TTransaction, TStartAux>, TSerialized, TSyncUpdate, TTransaction, TStartAux>, configuration: TConfig): V1Variant<TSerialized, TSyncUpdate, TTransaction, TStartAux>;
|
|
62
59
|
}
|
|
63
60
|
/** @internal */
|
|
@@ -87,13 +84,10 @@ declare namespace V1Builder {
|
|
|
87
84
|
type HasKeys<TConfig, TContext> = {
|
|
88
85
|
readonly keysCapability: (configuration: TConfig, getContext: () => TContext) => KeysCapability<CoreWallet>;
|
|
89
86
|
};
|
|
90
|
-
type HasSubmission<TConfig, TContext, TTransaction> = {
|
|
91
|
-
readonly submissionService: (configuration: TConfig, getContext: () => TContext) => SubmissionService<TTransaction>;
|
|
92
|
-
};
|
|
93
87
|
/**
|
|
94
88
|
* The internal build state of {@link V1Builder}.
|
|
95
89
|
*/
|
|
96
|
-
type FullBuildState<TConfig, TContext, TSerialized, TSyncUpdate, TTransaction, TStartAux> = Types.Simplify<HasSync<TConfig, TContext, TSyncUpdate, TStartAux> & HasSerialization<TConfig, TContext, TSerialized> & HasTransacting<TConfig, TContext, TTransaction> & HasCoinSelection<TConfig, TContext> & HasProving<TConfig, TContext, TTransaction> &
|
|
90
|
+
type FullBuildState<TConfig, TContext, TSerialized, TSyncUpdate, TTransaction, TStartAux> = Types.Simplify<HasSync<TConfig, TContext, TSyncUpdate, TStartAux> & HasSerialization<TConfig, TContext, TSerialized> & HasTransacting<TConfig, TContext, TTransaction> & HasCoinSelection<TConfig, TContext> & HasProving<TConfig, TContext, TTransaction> & HasCoinsAndBalances<TConfig, TContext> & HasKeys<TConfig, TContext> & HasTransactionHistory<TConfig, TContext, TTransaction>>;
|
|
97
91
|
type PartialBuildState<TConfig = object, TContext = object, TSerialized = never, TSyncUpdate = never, TTransaction = never, TStartAux = object> = {
|
|
98
92
|
[K in keyof FullBuildState<never, never, never, never, never, never>]?: FullBuildState<TConfig, TContext, TSerialized, TSyncUpdate, TTransaction, TStartAux>[K] | undefined;
|
|
99
93
|
};
|
package/dist/v1/V1Builder.js
CHANGED
|
@@ -20,7 +20,6 @@ import { makeEventsSyncService, makeEventsSyncCapability, } from './Sync.js';
|
|
|
20
20
|
import { makeDefaultTransactingCapability, } from './Transacting.js';
|
|
21
21
|
import { makeDefaultCoinsAndBalancesCapability } from './CoinsAndBalances.js';
|
|
22
22
|
import { makeDefaultKeysCapability } from './Keys.js';
|
|
23
|
-
import { makeDefaultSubmissionService } from './Submission.js';
|
|
24
23
|
import { chooseCoin } from '@midnight-ntwrk/wallet-sdk-capabilities';
|
|
25
24
|
import { CoreWallet, PublicKeys } from './CoreWallet.js';
|
|
26
25
|
import { makeDefaultTransactionHistoryCapability } from './TransactionHistory.js';
|
|
@@ -41,7 +40,6 @@ export class V1Builder {
|
|
|
41
40
|
.withTransactionHistoryDefaults()
|
|
42
41
|
.withKeysDefaults()
|
|
43
42
|
.withProvingDefaults()
|
|
44
|
-
.withSubmissionDefaults()
|
|
45
43
|
.withCoinSelectionDefaults();
|
|
46
44
|
}
|
|
47
45
|
withTransactionType() {
|
|
@@ -49,7 +47,6 @@ export class V1Builder {
|
|
|
49
47
|
...this.#buildState,
|
|
50
48
|
provingService: undefined,
|
|
51
49
|
transactingCapability: undefined,
|
|
52
|
-
submissionService: undefined,
|
|
53
50
|
transactionHistoryCapability: undefined,
|
|
54
51
|
});
|
|
55
52
|
}
|
|
@@ -129,15 +126,6 @@ export class V1Builder {
|
|
|
129
126
|
keysCapability,
|
|
130
127
|
});
|
|
131
128
|
}
|
|
132
|
-
withSubmission(submissionService) {
|
|
133
|
-
return new V1Builder({
|
|
134
|
-
...this.#buildState,
|
|
135
|
-
submissionService,
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
withSubmissionDefaults() {
|
|
139
|
-
return this.withSubmission(makeDefaultSubmissionService);
|
|
140
|
-
}
|
|
141
129
|
build(configuration) {
|
|
142
130
|
const v1Context = this.#buildContextFromBuildState(configuration);
|
|
143
131
|
const { networkId } = configuration;
|
|
@@ -149,7 +137,6 @@ export class V1Builder {
|
|
|
149
137
|
transactionHistory: v1Context.transactionHistoryCapability,
|
|
150
138
|
start(context) {
|
|
151
139
|
return Effect.gen(function* () {
|
|
152
|
-
yield* Effect.addFinalizer(() => v1Context.submissionService.close());
|
|
153
140
|
const scope = yield* Scope.Scope;
|
|
154
141
|
return new RunningV1Variant(scope, context, v1Context);
|
|
155
142
|
});
|
|
@@ -167,7 +154,7 @@ export class V1Builder {
|
|
|
167
154
|
if (!isBuildStateFull(this.#buildState)) {
|
|
168
155
|
throw new Error('Not all components are configured in V1 Builder');
|
|
169
156
|
}
|
|
170
|
-
const { syncCapability, syncService, transactingCapability, serializationCapability, provingService, coinSelection, coinsAndBalancesCapability, keysCapability,
|
|
157
|
+
const { syncCapability, syncService, transactingCapability, serializationCapability, provingService, coinSelection, coinsAndBalancesCapability, keysCapability, transactionHistoryCapability, } = this.#buildState;
|
|
171
158
|
const getContext = () => context;
|
|
172
159
|
const context = {
|
|
173
160
|
serializationCapability: serializationCapability(configuration, getContext),
|
|
@@ -178,7 +165,6 @@ export class V1Builder {
|
|
|
178
165
|
keysCapability: keysCapability(configuration, getContext),
|
|
179
166
|
provingService: provingService(configuration, getContext),
|
|
180
167
|
coinSelection: coinSelection(configuration, getContext),
|
|
181
|
-
submissionService: submissionService(configuration, getContext),
|
|
182
168
|
transactionHistoryCapability: transactionHistoryCapability(configuration, getContext),
|
|
183
169
|
};
|
|
184
170
|
return context;
|
|
@@ -194,7 +180,6 @@ const isBuildStateFull = (buildState) => {
|
|
|
194
180
|
'provingService',
|
|
195
181
|
'coinsAndBalancesCapability',
|
|
196
182
|
'keysCapability',
|
|
197
|
-
'submissionService',
|
|
198
183
|
'transactionHistoryCapability',
|
|
199
184
|
];
|
|
200
185
|
return allBuildStateKeys.every((key) => typeof buildState[key] == 'function');
|
package/dist/v1/index.d.ts
CHANGED
|
@@ -9,7 +9,6 @@ export * as CoinsAndBalances from './CoinsAndBalances.js';
|
|
|
9
9
|
export * as Keys from './Keys.js';
|
|
10
10
|
export * from './RunningV1Variant.js';
|
|
11
11
|
export * as Simulator from './Simulator.js';
|
|
12
|
-
export * as Submission from './Submission.js';
|
|
13
12
|
export * as WalletError from './WalletError.js';
|
|
14
13
|
export * from './CoreWallet.js';
|
|
15
14
|
export * from './TransactionOps.js';
|
package/dist/v1/index.js
CHANGED
|
@@ -21,7 +21,6 @@ export * as CoinsAndBalances from './CoinsAndBalances.js';
|
|
|
21
21
|
export * as Keys from './Keys.js';
|
|
22
22
|
export * from './RunningV1Variant.js';
|
|
23
23
|
export * as Simulator from './Simulator.js';
|
|
24
|
-
export * as Submission from './Submission.js';
|
|
25
24
|
export * as WalletError from './WalletError.js';
|
|
26
25
|
export * from './CoreWallet.js';
|
|
27
26
|
export * from './TransactionOps.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midnight-ntwrk/wallet-sdk-shielded",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-rc.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -31,12 +31,13 @@
|
|
|
31
31
|
"@midnight-ntwrk/ledger-v7": "7.0.0",
|
|
32
32
|
"@midnight-ntwrk/wallet-sdk-abstractions": "1.0.0",
|
|
33
33
|
"@midnight-ntwrk/wallet-sdk-address-format": "3.0.0",
|
|
34
|
-
"@midnight-ntwrk/wallet-sdk-capabilities": "3.0.0",
|
|
35
|
-
"@midnight-ntwrk/wallet-sdk-indexer-client": "1.0.0",
|
|
34
|
+
"@midnight-ntwrk/wallet-sdk-capabilities": "3.1.0-rc.0",
|
|
35
|
+
"@midnight-ntwrk/wallet-sdk-indexer-client": "1.1.0-rc.0",
|
|
36
36
|
"@midnight-ntwrk/wallet-sdk-node-client": "1.0.0",
|
|
37
|
-
"@midnight-ntwrk/wallet-sdk-prover-client": "1.0.0",
|
|
37
|
+
"@midnight-ntwrk/wallet-sdk-prover-client": "1.1.0-rc.0",
|
|
38
38
|
"@midnight-ntwrk/wallet-sdk-runtime": "1.0.0",
|
|
39
39
|
"@midnight-ntwrk/wallet-sdk-utilities": "1.0.0",
|
|
40
|
+
"@midnight-ntwrk/zkir-v2": "2.1.0",
|
|
40
41
|
"@scure/base": "^1.1.9",
|
|
41
42
|
"effect": "^3.19.14",
|
|
42
43
|
"isomorphic-ws": "^5.0.0",
|
|
@@ -46,7 +47,7 @@
|
|
|
46
47
|
"ws": "^8.18.3"
|
|
47
48
|
},
|
|
48
49
|
"scripts": {
|
|
49
|
-
"typecheck": "tsc -b ./tsconfig.json --noEmit",
|
|
50
|
+
"typecheck": "tsc -b ./tsconfig.json --noEmit --force",
|
|
50
51
|
"test": "vitest run",
|
|
51
52
|
"lint": "eslint --max-warnings 0",
|
|
52
53
|
"format": "prettier --write \"**/*.{ts,js,json,yaml,yml,md}\"",
|
package/dist/v1/Submission.d.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Effect } from 'effect';
|
|
2
|
-
import * as ledger from '@midnight-ntwrk/ledger-v7';
|
|
3
|
-
import { WalletError } from './WalletError.js';
|
|
4
|
-
import { Simulator } from './Simulator.js';
|
|
5
|
-
import { SubmissionEvent as SubmissionEventImported } from '@midnight-ntwrk/wallet-sdk-node-client/effect';
|
|
6
|
-
export declare const SubmissionEvent: typeof SubmissionEventImported;
|
|
7
|
-
export type SubmissionEvent = SubmissionEventImported.SubmissionEvent;
|
|
8
|
-
export declare namespace SubmissionEventCases {
|
|
9
|
-
type Finalized = SubmissionEventImported.Cases.Finalized;
|
|
10
|
-
type Submitted = SubmissionEventImported.Cases.Submitted;
|
|
11
|
-
type InBlock = SubmissionEventImported.Cases.InBlock;
|
|
12
|
-
}
|
|
13
|
-
export type SubmitTransactionMethod<TTransaction> = {
|
|
14
|
-
(transaction: TTransaction, waitForStatus: 'Submitted'): Effect.Effect<SubmissionEventCases.Submitted, WalletError>;
|
|
15
|
-
(transaction: TTransaction, waitForStatus: 'InBlock'): Effect.Effect<SubmissionEventCases.InBlock, WalletError>;
|
|
16
|
-
(transaction: TTransaction, waitForStatus: 'Finalized'): Effect.Effect<SubmissionEventCases.Finalized, WalletError>;
|
|
17
|
-
(transaction: TTransaction): Effect.Effect<SubmissionEventCases.InBlock, WalletError>;
|
|
18
|
-
(transaction: TTransaction, waitForStatus?: 'Submitted' | 'InBlock' | 'Finalized'): Effect.Effect<SubmissionEvent, WalletError>;
|
|
19
|
-
};
|
|
20
|
-
export interface SubmissionService<TTransaction> {
|
|
21
|
-
submitTransaction: SubmitTransactionMethod<TTransaction>;
|
|
22
|
-
close(): Effect.Effect<void>;
|
|
23
|
-
}
|
|
24
|
-
export type DefaultSubmissionConfiguration = {
|
|
25
|
-
relayURL: URL;
|
|
26
|
-
};
|
|
27
|
-
export declare const makeDefaultSubmissionService: (config: DefaultSubmissionConfiguration) => SubmissionService<ledger.FinalizedTransaction>;
|
|
28
|
-
export type SimulatorSubmissionConfiguration = {
|
|
29
|
-
simulator: Simulator;
|
|
30
|
-
};
|
|
31
|
-
export declare const makeSimulatorSubmissionService: (waitForStatus?: "Submitted" | "InBlock" | "Finalized") => (config: SimulatorSubmissionConfiguration) => SubmissionService<ledger.ProofErasedTransaction>;
|
package/dist/v1/Submission.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
// This file is part of MIDNIGHT-WALLET-SDK.
|
|
2
|
-
// Copyright (C) 2025 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 { Deferred, Effect, Encoding, Exit, pipe, Scope } from 'effect';
|
|
14
|
-
import { WalletError } from './WalletError.js';
|
|
15
|
-
import { NodeClient, PolkadotNodeClient, SubmissionEvent as SubmissionEventImported, } from '@midnight-ntwrk/wallet-sdk-node-client/effect';
|
|
16
|
-
export const SubmissionEvent = SubmissionEventImported;
|
|
17
|
-
export const makeDefaultSubmissionService = (config) => {
|
|
18
|
-
const scopeAndClientDeferred = Deferred.make().pipe(Effect.runSync);
|
|
19
|
-
const makeScopeAndClient = Effect.gen(function* () {
|
|
20
|
-
const scope = yield* Scope.make();
|
|
21
|
-
const client = yield* PolkadotNodeClient.make({
|
|
22
|
-
nodeURL: config.relayURL,
|
|
23
|
-
}).pipe(Effect.provideService(Scope.Scope, scope));
|
|
24
|
-
return { scope, client };
|
|
25
|
-
});
|
|
26
|
-
void pipe(scopeAndClientDeferred, Deferred.complete(makeScopeAndClient), Effect.runPromise);
|
|
27
|
-
const submit = (transaction, waitForStatus = 'InBlock') => {
|
|
28
|
-
return pipe(NodeClient.sendMidnightTransactionAndWait(transaction.serialize(), waitForStatus), Effect.provideServiceEffect(NodeClient.NodeClient, pipe(scopeAndClientDeferred, Deferred.await, Effect.map(({ client }) => client))), Effect.mapError((err) => WalletError.submission(err)));
|
|
29
|
-
};
|
|
30
|
-
return {
|
|
31
|
-
submitTransaction: submit,
|
|
32
|
-
close() {
|
|
33
|
-
return pipe(scopeAndClientDeferred, Deferred.await, Effect.flatMap(({ scope }) => Scope.close(scope, Exit.void)), Effect.ignoreLogged);
|
|
34
|
-
},
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
export const makeSimulatorSubmissionService = (waitForStatus = 'InBlock') => (config) => {
|
|
38
|
-
const submit = (transaction) => {
|
|
39
|
-
const serializedTx = transaction.serialize();
|
|
40
|
-
return config.simulator.submitRegularTx(transaction).pipe(Effect.map((output) => {
|
|
41
|
-
// Let's mimic node's client behavior here
|
|
42
|
-
switch (waitForStatus) {
|
|
43
|
-
case 'Submitted':
|
|
44
|
-
return SubmissionEvent.Submitted({
|
|
45
|
-
tx: serializedTx,
|
|
46
|
-
txHash: Encoding.encodeHex(serializedTx.subarray(0, 32)),
|
|
47
|
-
});
|
|
48
|
-
case 'InBlock':
|
|
49
|
-
return SubmissionEvent.InBlock({
|
|
50
|
-
tx: serializedTx,
|
|
51
|
-
blockHash: output.blockHash,
|
|
52
|
-
blockHeight: output.blockNumber,
|
|
53
|
-
txHash: Encoding.encodeHex(serializedTx.subarray(0, 32)),
|
|
54
|
-
});
|
|
55
|
-
case 'Finalized':
|
|
56
|
-
return SubmissionEvent.Finalized({
|
|
57
|
-
tx: serializedTx,
|
|
58
|
-
blockHash: output.blockHash,
|
|
59
|
-
blockHeight: output.blockNumber,
|
|
60
|
-
txHash: Encoding.encodeHex(serializedTx.subarray(0, 32)),
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
}));
|
|
64
|
-
};
|
|
65
|
-
return {
|
|
66
|
-
submitTransaction: submit,
|
|
67
|
-
close: () => Effect.void,
|
|
68
|
-
};
|
|
69
|
-
};
|