@midnight-ntwrk/wallet-sdk-shielded 2.1.0 → 3.0.1
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/dist/ShieldedWallet.d.ts +11 -13
- package/dist/ShieldedWallet.js +9 -12
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/v1/CoinsAndBalances.d.ts +2 -2
- package/dist/v1/CoreWallet.d.ts +2 -2
- package/dist/v1/CoreWallet.js +5 -3
- package/dist/v1/RunningV1Variant.d.ts +4 -4
- package/dist/v1/RunningV1Variant.js +10 -9
- package/dist/v1/Serialization.d.ts +1 -1
- package/dist/v1/Sync.d.ts +37 -10
- package/dist/v1/Sync.js +59 -11
- package/dist/v1/Transacting.d.ts +7 -7
- package/dist/v1/Transacting.js +23 -21
- package/dist/v1/TransactionHistory.d.ts +63 -8
- package/dist/v1/TransactionHistory.js +90 -23
- package/dist/v1/TransactionImbalances.d.ts +2 -2
- package/dist/v1/TransactionImbalances.js +3 -3
- package/dist/v1/TransactionOps.d.ts +3 -3
- package/dist/v1/TransactionOps.js +11 -14
- package/dist/v1/V1Builder.d.ts +13 -17
- package/dist/v1/V1Builder.js +9 -9
- package/dist/v1/WalletError.d.ts +17 -9
- package/dist/v1/WalletError.js +2 -0
- package/dist/v1/index.d.ts +1 -1
- package/dist/v1/index.js +1 -1
- package/package.json +8 -8
- package/dist/v1/Simulator.d.ts +0 -22
- package/dist/v1/Simulator.js +0 -103
|
@@ -1,31 +1,98 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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 { TransactionHistoryStorage } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
14
|
+
import { Duration, Array as EArray, Effect, Schedule, Schema } from 'effect';
|
|
15
|
+
import { TransactionHistoryDetail } from '@midnight-ntwrk/wallet-sdk-indexer-client';
|
|
16
|
+
import { HttpQueryClient } from '@midnight-ntwrk/wallet-sdk-indexer-client/effect';
|
|
17
|
+
import { TransactionHistoryError } from './WalletError.js';
|
|
18
|
+
export const QualifiedShieldedCoinInfoSchema = Schema.Struct({
|
|
19
|
+
type: Schema.String,
|
|
20
|
+
nonce: Schema.String,
|
|
21
|
+
value: Schema.BigInt,
|
|
22
|
+
mtIndex: Schema.BigInt,
|
|
23
|
+
});
|
|
24
|
+
export const ShieldedSectionSchema = Schema.Struct({
|
|
25
|
+
receivedCoins: Schema.Array(QualifiedShieldedCoinInfoSchema),
|
|
26
|
+
spentCoins: Schema.Array(QualifiedShieldedCoinInfoSchema),
|
|
27
|
+
});
|
|
28
|
+
export const ShieldedTransactionHistoryEntrySchema = Schema.Struct({
|
|
29
|
+
hash: TransactionHistoryStorage.TransactionHashSchema,
|
|
30
|
+
protocolVersion: Schema.Number,
|
|
31
|
+
status: TransactionHistoryStorage.TransactionHistoryStatusSchema,
|
|
32
|
+
shielded: ShieldedSectionSchema,
|
|
33
|
+
});
|
|
34
|
+
const coinEquals = Schema.equivalence(QualifiedShieldedCoinInfoSchema);
|
|
35
|
+
export const mergeShieldedSections = (existing, incoming) => ({
|
|
36
|
+
receivedCoins: EArray.unionWith(existing.receivedCoins, incoming.receivedCoins, coinEquals),
|
|
37
|
+
spentCoins: EArray.unionWith(existing.spentCoins, incoming.spentCoins, coinEquals),
|
|
38
|
+
});
|
|
39
|
+
const convertUpdateToStorageEntry = (changes, metadata, protocolVersion) => ({
|
|
40
|
+
hash: changes.source,
|
|
41
|
+
protocolVersion,
|
|
42
|
+
status: metadata.status,
|
|
43
|
+
shielded: {
|
|
44
|
+
receivedCoins: changes.receivedCoins.map(({ mt_index, ...rest }) => ({ ...rest, mtIndex: mt_index })),
|
|
45
|
+
spentCoins: changes.spentCoins.map(({ mt_index, ...rest }) => ({ ...rest, mtIndex: mt_index })),
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
const upsertShieldedEntry = (txHistoryStorage, entry) => Effect.tryPromise({
|
|
49
|
+
try: () => txHistoryStorage.upsert(entry),
|
|
50
|
+
catch: (e) => new TransactionHistoryError({ message: `Failed to upsert history entry for ${entry.hash}`, cause: e }),
|
|
51
|
+
});
|
|
52
|
+
export const makeDefaultTransactionHistoryService = (config, _getContext) => {
|
|
53
|
+
const txHistoryStorage = config.txHistoryStorage;
|
|
54
|
+
const queryClientLayer = HttpQueryClient.layer({ url: config.indexerClientConnection.indexerHttpUrl });
|
|
3
55
|
return {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
transactionHistory: (_state) => {
|
|
8
|
-
return [];
|
|
56
|
+
put: (changes, metadata, protocolVersion) => {
|
|
57
|
+
const entry = convertUpdateToStorageEntry(changes, metadata, protocolVersion);
|
|
58
|
+
return upsertShieldedEntry(txHistoryStorage, entry);
|
|
9
59
|
},
|
|
60
|
+
getTransactionDetails: (hash) => Effect.gen(function* () {
|
|
61
|
+
const statusQuery = yield* TransactionHistoryDetail;
|
|
62
|
+
const result = yield* statusQuery({ transactionHash: hash });
|
|
63
|
+
const tx = result.transactions[0];
|
|
64
|
+
const rawStatus = tx.__typename === 'RegularTransaction' ? tx.transactionResult.status : undefined;
|
|
65
|
+
const status = rawStatus === 'FAILURE' || rawStatus === 'PARTIAL_SUCCESS' ? rawStatus : 'SUCCESS';
|
|
66
|
+
return {
|
|
67
|
+
hash: tx.hash,
|
|
68
|
+
timestamp: tx.block.timestamp,
|
|
69
|
+
status,
|
|
70
|
+
};
|
|
71
|
+
}).pipe(Effect.provide(queryClientLayer), Effect.scoped, Effect.retry(Schedule.exponential(Duration.seconds(1)).pipe(Schedule.compose(Schedule.recurs(3)))), Effect.mapError((cause) => new TransactionHistoryError({
|
|
72
|
+
message: `Failed to fetch transaction metadata for ${hash}`,
|
|
73
|
+
cause,
|
|
74
|
+
}))),
|
|
10
75
|
};
|
|
11
76
|
};
|
|
12
|
-
export const
|
|
77
|
+
export const makeSimulatorTransactionHistoryService = (config, _getContext) => {
|
|
78
|
+
const txHistoryStorage = config.txHistoryStorage;
|
|
13
79
|
return {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
21
|
-
};
|
|
22
|
-
export const makeDiscardTransactionHistoryCapability = () => {
|
|
23
|
-
return {
|
|
24
|
-
updateTxHistory: (state) => {
|
|
25
|
-
return state;
|
|
26
|
-
},
|
|
27
|
-
transactionHistory: (_state) => {
|
|
28
|
-
return [];
|
|
80
|
+
put: (changes, metadata, protocolVersion) => {
|
|
81
|
+
const entry = convertUpdateToStorageEntry(changes, metadata, protocolVersion);
|
|
82
|
+
return upsertShieldedEntry(txHistoryStorage, {
|
|
83
|
+
...entry,
|
|
84
|
+
timestamp: new Date(metadata.timestamp),
|
|
85
|
+
});
|
|
29
86
|
},
|
|
87
|
+
getTransactionDetails: (hash) => Effect.tryPromise({
|
|
88
|
+
try: () => txHistoryStorage.get(hash),
|
|
89
|
+
catch: (e) => new TransactionHistoryError({ message: `Failed to get transaction details for ${hash}`, cause: e }),
|
|
90
|
+
}).pipe(Effect.flatMap((entry) => entry
|
|
91
|
+
? Effect.succeed({
|
|
92
|
+
hash: entry.hash,
|
|
93
|
+
timestamp: entry.timestamp ? entry.timestamp.getTime() : Date.now(),
|
|
94
|
+
status: entry.status,
|
|
95
|
+
})
|
|
96
|
+
: Effect.fail(new TransactionHistoryError({ message: `No transaction found in storage for hash: ${hash}` })))),
|
|
30
97
|
};
|
|
31
98
|
};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Imbalances, TransactionCostModel } from '@midnight-ntwrk/wallet-sdk-capabilities';
|
|
1
|
+
import { Imbalances, type TransactionCostModel } from '@midnight-ntwrk/wallet-sdk-capabilities';
|
|
2
2
|
export declare const ShieldedCostModel: TransactionCostModel;
|
|
3
3
|
export type TransactionImbalances = Readonly<{
|
|
4
4
|
guaranteed: Imbalances;
|
|
5
|
-
fallible: Imbalances
|
|
5
|
+
fallible: ReadonlyMap<number, Imbalances>;
|
|
6
6
|
}>;
|
|
7
7
|
export declare const TransactionImbalances: {
|
|
8
8
|
empty: () => TransactionImbalances;
|
|
@@ -19,12 +19,12 @@ export const TransactionImbalances = new (class {
|
|
|
19
19
|
empty = () => {
|
|
20
20
|
return {
|
|
21
21
|
guaranteed: Imbalances.empty(),
|
|
22
|
-
fallible:
|
|
22
|
+
fallible: new Map(),
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
25
|
areBalanced = (imbalances) => {
|
|
26
|
-
const areFallibleAllZeroes = imbalances.fallible.entries().every(([, value]) => value === 0n);
|
|
27
26
|
const areGuaranteedAllZeroes = imbalances.guaranteed.entries().every(([, value]) => value === 0n);
|
|
28
|
-
|
|
27
|
+
const areFallibleAllZeroes = Array.from(imbalances.fallible.values()).every((segmentImbalances) => segmentImbalances.entries().every(([, value]) => value === 0n));
|
|
28
|
+
return areGuaranteedAllZeroes && areFallibleAllZeroes;
|
|
29
29
|
};
|
|
30
30
|
})();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Imbalances } from '@midnight-ntwrk/wallet-sdk-capabilities';
|
|
2
|
-
import { TransactionImbalances } from './TransactionImbalances.js';
|
|
3
|
-
import * as ledger from '@midnight-ntwrk/ledger-v8';
|
|
2
|
+
import { type TransactionImbalances } from './TransactionImbalances.js';
|
|
3
|
+
import type * as ledger from '@midnight-ntwrk/ledger-v8';
|
|
4
4
|
export type TransactionOps<Tx> = {
|
|
5
5
|
getImbalances(tx: Tx): TransactionImbalances;
|
|
6
6
|
id(tx: Tx): string;
|
|
@@ -12,6 +12,6 @@ export declare const TransactionOps: {
|
|
|
12
12
|
shared: {
|
|
13
13
|
getImbalances(tx: ledger.FinalizedTransaction | ledger.UnprovenTransaction | ledger.ProofErasedTransaction): TransactionImbalances;
|
|
14
14
|
getGuaranteedImbalances: (tx: ledger.FinalizedTransaction | ledger.UnprovenTransaction | ledger.ProofErasedTransaction) => Imbalances;
|
|
15
|
-
getFallibleImbalances: (tx: ledger.FinalizedTransaction | ledger.UnprovenTransaction | ledger.ProofErasedTransaction) => Imbalances
|
|
15
|
+
getFallibleImbalances: (tx: ledger.FinalizedTransaction | ledger.UnprovenTransaction | ledger.ProofErasedTransaction) => ReadonlyMap<number, Imbalances>;
|
|
16
16
|
};
|
|
17
17
|
};
|
|
@@ -10,7 +10,6 @@
|
|
|
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 { pipe } from 'effect';
|
|
14
13
|
import { Imbalances } from '@midnight-ntwrk/wallet-sdk-capabilities';
|
|
15
14
|
export const TransactionOps = new (class {
|
|
16
15
|
default = {
|
|
@@ -41,11 +40,10 @@ export const TransactionOps = new (class {
|
|
|
41
40
|
getImbalances(tx) {
|
|
42
41
|
const guaranteedImbalances = TransactionOps.shared.getGuaranteedImbalances(tx);
|
|
43
42
|
const fallibleImbalances = TransactionOps.shared.getFallibleImbalances(tx);
|
|
44
|
-
return
|
|
43
|
+
return {
|
|
45
44
|
guaranteed: guaranteedImbalances,
|
|
46
45
|
fallible: fallibleImbalances,
|
|
47
|
-
|
|
48
|
-
});
|
|
46
|
+
};
|
|
49
47
|
},
|
|
50
48
|
getGuaranteedImbalances: (tx) => {
|
|
51
49
|
const rawGuaranteedImbalances = tx
|
|
@@ -53,24 +51,23 @@ export const TransactionOps = new (class {
|
|
|
53
51
|
.entries()
|
|
54
52
|
.filter(([token]) => token.tag === 'shielded')
|
|
55
53
|
.map(([token, value]) => {
|
|
56
|
-
return [token.raw
|
|
54
|
+
return [token.raw, value];
|
|
57
55
|
});
|
|
58
56
|
return Imbalances.fromEntries(rawGuaranteedImbalances);
|
|
59
57
|
},
|
|
60
58
|
getFallibleImbalances: (tx) => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
const segments = Array.from(tx.fallibleOffer?.keys() ?? []);
|
|
60
|
+
const fallibleImbalances = segments.flatMap((segment) => {
|
|
61
|
+
const rawImbalances = tx
|
|
62
|
+
.imbalances(segment)
|
|
64
63
|
.entries()
|
|
65
64
|
.filter(([token]) => token.tag === 'shielded')
|
|
66
65
|
.map(([token, value]) => {
|
|
67
|
-
return [token.raw
|
|
66
|
+
return [token.raw, value];
|
|
68
67
|
});
|
|
69
|
-
return Imbalances.fromEntries(
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return Imbalances.empty();
|
|
73
|
-
}
|
|
68
|
+
return [[segment, Imbalances.fromEntries(rawImbalances)]];
|
|
69
|
+
});
|
|
70
|
+
return new Map(fallibleImbalances);
|
|
74
71
|
},
|
|
75
72
|
};
|
|
76
73
|
})();
|
package/dist/v1/V1Builder.d.ts
CHANGED
|
@@ -4,18 +4,18 @@ import { type NetworkId } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
|
4
4
|
import { type Variant, type VariantBuilder } from '@midnight-ntwrk/wallet-sdk-runtime/abstractions';
|
|
5
5
|
import { RunningV1Variant, V1Tag } from './RunningV1Variant.js';
|
|
6
6
|
import { type SerializationCapability } from './Serialization.js';
|
|
7
|
-
import { type DefaultSyncContext, type DefaultSyncConfiguration, type SyncCapability, type SyncService, type WalletSyncUpdate } from './Sync.js';
|
|
7
|
+
import { type DefaultSyncContext, type DefaultSyncConfiguration, type ChangesResult, type SyncCapability, type SyncService, type WalletSyncUpdate } from './Sync.js';
|
|
8
8
|
import { type DefaultTransactingConfiguration, type DefaultTransactingContext, type TransactingCapability } from './Transacting.js';
|
|
9
9
|
import { type WalletError } from './WalletError.js';
|
|
10
10
|
import { type CoinsAndBalancesCapability } from './CoinsAndBalances.js';
|
|
11
11
|
import { type KeysCapability } from './Keys.js';
|
|
12
12
|
import { type CoinSelection } from '@midnight-ntwrk/wallet-sdk-capabilities';
|
|
13
13
|
import { CoreWallet } from './CoreWallet.js';
|
|
14
|
-
import { type
|
|
14
|
+
import { type DefaultTransactionHistoryConfiguration, type TransactionHistoryService } from './TransactionHistory.js';
|
|
15
15
|
export type BaseV1Configuration = {
|
|
16
16
|
networkId: NetworkId.NetworkId;
|
|
17
17
|
};
|
|
18
|
-
export type DefaultV1Configuration = BaseV1Configuration & DefaultSyncConfiguration & DefaultTransactingConfiguration;
|
|
18
|
+
export type DefaultV1Configuration = BaseV1Configuration & DefaultSyncConfiguration & DefaultTransactingConfiguration & DefaultTransactionHistoryConfiguration;
|
|
19
19
|
declare const V1BuilderSymbol: {
|
|
20
20
|
readonly typeId: unique symbol;
|
|
21
21
|
};
|
|
@@ -24,7 +24,7 @@ export type V1Variant<TSerialized, TSyncUpdate, TTransaction, TAuxData> = Varian
|
|
|
24
24
|
coinsAndBalances: CoinsAndBalancesCapability<CoreWallet>;
|
|
25
25
|
keys: KeysCapability<CoreWallet>;
|
|
26
26
|
serialization: SerializationCapability<CoreWallet, null, TSerialized>;
|
|
27
|
-
transactionHistory:
|
|
27
|
+
transactionHistory: TransactionHistoryService;
|
|
28
28
|
};
|
|
29
29
|
export type AnyV1Variant = V1Variant<any, any, any, any>;
|
|
30
30
|
export type DefaultV1Variant = V1Variant<string, WalletSyncUpdate, ledger.FinalizedTransaction, ledger.ZswapSecretKeys>;
|
|
@@ -39,7 +39,7 @@ export declare class V1Builder<TConfig extends BaseV1Configuration = BaseV1Confi
|
|
|
39
39
|
withTransactionType<Transaction>(): V1Builder<TConfig, TContext, TSerialized, TSyncUpdate, Transaction, TStartAux>;
|
|
40
40
|
withDefaultTransactionType(): V1Builder<TConfig, TContext, TSerialized, TSyncUpdate, ledger.FinalizedTransaction, TStartAux>;
|
|
41
41
|
withSyncDefaults(): V1Builder<TConfig & DefaultSyncConfiguration, TContext & DefaultSyncContext, TSerialized, WalletSyncUpdate, TTransaction, ledger.ZswapSecretKeys>;
|
|
42
|
-
withSync<TSyncConfig, TSyncContext extends Partial<RunningV1Variant.AnyContext>, TSyncUpdate, TStartAux extends object>(syncService: (configuration: TSyncConfig, getContext: () => TSyncContext) => SyncService<CoreWallet, TStartAux, TSyncUpdate>, syncCapability: (configuration: TSyncConfig, getContext: () => TSyncContext) => SyncCapability<CoreWallet, TSyncUpdate>): V1Builder<TConfig & TSyncConfig, TContext & TSyncContext, TSerialized, TSyncUpdate, TTransaction, TStartAux>;
|
|
42
|
+
withSync<TSyncConfig, TSyncContext extends Partial<RunningV1Variant.AnyContext>, TSyncUpdate, TStartAux extends object>(syncService: (configuration: TSyncConfig, getContext: () => TSyncContext) => SyncService<CoreWallet, TStartAux, TSyncUpdate>, syncCapability: (configuration: TSyncConfig, getContext: () => TSyncContext) => SyncCapability<CoreWallet, TSyncUpdate, ChangesResult>): V1Builder<TConfig & TSyncConfig, TContext & TSyncContext, TSerialized, TSyncUpdate, TTransaction, TStartAux>;
|
|
43
43
|
withSerializationDefaults(): V1Builder<TConfig, TContext, string, TSyncUpdate, TTransaction, TStartAux>;
|
|
44
44
|
withSerialization<TSerializationConfig, TSerializationContext extends Partial<RunningV1Variant.AnyContext>, TSerialized>(serializationCapability: (configuration: TSerializationConfig, getContext: () => TSerializationContext) => SerializationCapability<CoreWallet, null, TSerialized>): V1Builder<TConfig & TSerializationConfig, TContext & TSerializationContext, TSerialized, TSyncUpdate, TTransaction, TStartAux>;
|
|
45
45
|
withTransactingDefaults(this: V1Builder<TConfig, TContext, TSerialized, TSyncUpdate, ledger.FinalizedTransaction, TStartAux>): V1Builder<TConfig & DefaultTransactingConfiguration, TContext & DefaultTransactingContext, TSerialized, TSyncUpdate, ledger.FinalizedTransaction, TStartAux>;
|
|
@@ -48,8 +48,8 @@ export declare class V1Builder<TConfig extends BaseV1Configuration = BaseV1Confi
|
|
|
48
48
|
withCoinSelectionDefaults(): V1Builder<TConfig, TContext, TSerialized, TSyncUpdate, TTransaction, TStartAux>;
|
|
49
49
|
withCoinsAndBalancesDefaults(): V1Builder<TConfig, TContext, TSerialized, TSyncUpdate, TTransaction, TStartAux>;
|
|
50
50
|
withCoinsAndBalances<TBalancesConfig, TBalancesContext extends Partial<RunningV1Variant.AnyContext>>(coinsAndBalancesCapability: (configuration: TBalancesConfig, getContext: () => TBalancesContext) => CoinsAndBalancesCapability<CoreWallet>): V1Builder<TConfig & TBalancesConfig, TContext & TBalancesContext, TSerialized, TSyncUpdate, TTransaction, TStartAux>;
|
|
51
|
-
withTransactionHistoryDefaults(this: V1Builder<TConfig, TContext, TSerialized, TSyncUpdate, ledger.FinalizedTransaction, TStartAux>): V1Builder<TConfig, TContext, TSerialized, TSyncUpdate, ledger.FinalizedTransaction, TStartAux>;
|
|
52
|
-
withTransactionHistory<TTransactionHistoryConfig, TTransactionHistoryContext extends Partial<RunningV1Variant.AnyContext>>(
|
|
51
|
+
withTransactionHistoryDefaults(this: V1Builder<TConfig, TContext, TSerialized, TSyncUpdate, ledger.FinalizedTransaction, TStartAux>): V1Builder<TConfig & DefaultTransactionHistoryConfiguration, TContext, TSerialized, TSyncUpdate, ledger.FinalizedTransaction, TStartAux>;
|
|
52
|
+
withTransactionHistory<TTransactionHistoryConfig, TTransactionHistoryContext extends Partial<RunningV1Variant.AnyContext>>(transactionHistoryService: (configuration: TTransactionHistoryConfig, getContext: () => TTransactionHistoryContext) => TransactionHistoryService): V1Builder<TConfig & TTransactionHistoryConfig, TContext & TTransactionHistoryContext, TSerialized, TSyncUpdate, TTransaction, TStartAux>;
|
|
53
53
|
withKeysDefaults(): V1Builder<TConfig, TContext, TSerialized, TSyncUpdate, TTransaction, TStartAux>;
|
|
54
54
|
withKeys<TKeysConfig, TKeysContext extends Partial<RunningV1Variant.AnyContext>>(keysCapability: (configuration: TKeysConfig, getContext: () => TKeysContext) => KeysCapability<CoreWallet>): V1Builder<TConfig & TKeysConfig, TContext & TKeysContext, TSerialized, TSyncUpdate, TTransaction, TStartAux>;
|
|
55
55
|
build(this: V1Builder<TConfig, RunningV1Variant.Context<TSerialized, TSyncUpdate, TTransaction, TStartAux>, TSerialized, TSyncUpdate, TTransaction, TStartAux>, configuration: TConfig): V1Variant<TSerialized, TSyncUpdate, TTransaction, TStartAux>;
|
|
@@ -58,7 +58,7 @@ export declare class V1Builder<TConfig extends BaseV1Configuration = BaseV1Confi
|
|
|
58
58
|
declare namespace V1Builder {
|
|
59
59
|
type HasSync<TConfig, TContext, TSyncUpdate, TStartAux> = {
|
|
60
60
|
readonly syncService: (configuration: TConfig, getContext: () => TContext) => SyncService<CoreWallet, TStartAux, TSyncUpdate>;
|
|
61
|
-
readonly syncCapability: (configuration: TConfig, getContext: () => TContext) => SyncCapability<CoreWallet, TSyncUpdate>;
|
|
61
|
+
readonly syncCapability: (configuration: TConfig, getContext: () => TContext) => SyncCapability<CoreWallet, TSyncUpdate, ChangesResult>;
|
|
62
62
|
};
|
|
63
63
|
type HasTransacting<TConfig, TContext, TTransaction> = {
|
|
64
64
|
readonly transactingCapability: (configuration: TConfig, getContext: () => TContext) => TransactingCapability<ledger.ZswapSecretKeys, CoreWallet, TTransaction>;
|
|
@@ -72,22 +72,18 @@ declare namespace V1Builder {
|
|
|
72
72
|
type HasCoinsAndBalances<TConfig, TContext> = {
|
|
73
73
|
readonly coinsAndBalancesCapability: (configuration: TConfig, getContext: () => TContext) => CoinsAndBalancesCapability<CoreWallet>;
|
|
74
74
|
};
|
|
75
|
-
type HasTransactionHistory<TConfig, TContext
|
|
76
|
-
readonly
|
|
75
|
+
type HasTransactionHistory<TConfig, TContext> = {
|
|
76
|
+
readonly transactionHistoryService: (configuration: TConfig, getContext: () => TContext) => TransactionHistoryService;
|
|
77
77
|
};
|
|
78
78
|
type HasKeys<TConfig, TContext> = {
|
|
79
79
|
readonly keysCapability: (configuration: TConfig, getContext: () => TContext) => KeysCapability<CoreWallet>;
|
|
80
80
|
};
|
|
81
|
-
/**
|
|
82
|
-
|
|
83
|
-
*/
|
|
84
|
-
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> & HasCoinsAndBalances<TConfig, TContext> & HasKeys<TConfig, TContext> & HasTransactionHistory<TConfig, TContext, TTransaction>>;
|
|
81
|
+
/** The internal build state of {@link V1Builder}. */
|
|
82
|
+
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> & HasCoinsAndBalances<TConfig, TContext> & HasKeys<TConfig, TContext> & HasTransactionHistory<TConfig, TContext>>;
|
|
85
83
|
type PartialBuildState<TConfig = object, TContext = object, TSerialized = never, TSyncUpdate = never, TTransaction = never, TStartAux = object> = {
|
|
86
84
|
[K in keyof FullBuildState<never, never, never, never, never, never>]?: FullBuildState<TConfig, TContext, TSerialized, TSyncUpdate, TTransaction, TStartAux>[K] | undefined;
|
|
87
85
|
};
|
|
88
|
-
/**
|
|
89
|
-
* Utility interface that manages the type variance of {@link V1Builder}.
|
|
90
|
-
*/
|
|
86
|
+
/** Utility interface that manages the type variance of {@link V1Builder}. */
|
|
91
87
|
interface Variance<R> {
|
|
92
88
|
readonly [V1BuilderSymbol.typeId]: {
|
|
93
89
|
readonly _R: Types.Covariant<R>;
|
package/dist/v1/V1Builder.js
CHANGED
|
@@ -21,7 +21,7 @@ import { makeDefaultCoinsAndBalancesCapability } from './CoinsAndBalances.js';
|
|
|
21
21
|
import { makeDefaultKeysCapability } from './Keys.js';
|
|
22
22
|
import { chooseCoin } from '@midnight-ntwrk/wallet-sdk-capabilities';
|
|
23
23
|
import { CoreWallet, PublicKeys } from './CoreWallet.js';
|
|
24
|
-
import {
|
|
24
|
+
import { makeDefaultTransactionHistoryService, } from './TransactionHistory.js';
|
|
25
25
|
const V1BuilderSymbol = {
|
|
26
26
|
typeId: Symbol('@midnight-ntwrk/wallet#V1Builder'),
|
|
27
27
|
};
|
|
@@ -44,7 +44,7 @@ export class V1Builder {
|
|
|
44
44
|
return new V1Builder({
|
|
45
45
|
...this.#buildState,
|
|
46
46
|
transactingCapability: undefined,
|
|
47
|
-
|
|
47
|
+
transactionHistoryService: undefined,
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
50
|
withDefaultTransactionType() {
|
|
@@ -97,12 +97,12 @@ export class V1Builder {
|
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
99
|
withTransactionHistoryDefaults() {
|
|
100
|
-
return this.withTransactionHistory(
|
|
100
|
+
return this.withTransactionHistory(makeDefaultTransactionHistoryService);
|
|
101
101
|
}
|
|
102
|
-
withTransactionHistory(
|
|
102
|
+
withTransactionHistory(transactionHistoryService) {
|
|
103
103
|
return new V1Builder({
|
|
104
104
|
...this.#buildState,
|
|
105
|
-
|
|
105
|
+
transactionHistoryService,
|
|
106
106
|
});
|
|
107
107
|
}
|
|
108
108
|
withKeysDefaults() {
|
|
@@ -122,7 +122,7 @@ export class V1Builder {
|
|
|
122
122
|
coinsAndBalances: v1Context.coinsAndBalancesCapability,
|
|
123
123
|
keys: v1Context.keysCapability,
|
|
124
124
|
serialization: v1Context.serializationCapability,
|
|
125
|
-
transactionHistory: v1Context.
|
|
125
|
+
transactionHistory: v1Context.transactionHistoryService,
|
|
126
126
|
start(context) {
|
|
127
127
|
return Effect.gen(function* () {
|
|
128
128
|
const scope = yield* Scope.Scope;
|
|
@@ -142,7 +142,7 @@ export class V1Builder {
|
|
|
142
142
|
if (!isBuildStateFull(this.#buildState)) {
|
|
143
143
|
throw new Error('Not all components are configured in V1 Builder');
|
|
144
144
|
}
|
|
145
|
-
const { syncCapability, syncService, transactingCapability, serializationCapability, coinSelection, coinsAndBalancesCapability, keysCapability,
|
|
145
|
+
const { syncCapability, syncService, transactingCapability, serializationCapability, coinSelection, coinsAndBalancesCapability, keysCapability, transactionHistoryService, } = this.#buildState;
|
|
146
146
|
const getContext = () => context;
|
|
147
147
|
const context = {
|
|
148
148
|
serializationCapability: serializationCapability(configuration, getContext),
|
|
@@ -152,7 +152,7 @@ export class V1Builder {
|
|
|
152
152
|
coinsAndBalancesCapability: coinsAndBalancesCapability(configuration, getContext),
|
|
153
153
|
keysCapability: keysCapability(configuration, getContext),
|
|
154
154
|
coinSelection: coinSelection(configuration, getContext),
|
|
155
|
-
|
|
155
|
+
transactionHistoryService: transactionHistoryService(configuration, getContext),
|
|
156
156
|
};
|
|
157
157
|
return context;
|
|
158
158
|
}
|
|
@@ -166,7 +166,7 @@ const isBuildStateFull = (buildState) => {
|
|
|
166
166
|
'serializationCapability',
|
|
167
167
|
'coinsAndBalancesCapability',
|
|
168
168
|
'keysCapability',
|
|
169
|
-
'
|
|
169
|
+
'transactionHistoryService',
|
|
170
170
|
];
|
|
171
171
|
return allBuildStateKeys.every((key) => typeof buildState[key] == 'function');
|
|
172
172
|
};
|
package/dist/v1/WalletError.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import * as ledger from '@midnight-ntwrk/ledger-v8';
|
|
2
|
-
import { LedgerOps } from '@midnight-ntwrk/wallet-sdk-utilities';
|
|
1
|
+
import type * as ledger from '@midnight-ntwrk/ledger-v8';
|
|
2
|
+
import { type LedgerOps } from '@midnight-ntwrk/wallet-sdk-utilities';
|
|
3
3
|
export declare const WalletError: {
|
|
4
4
|
other(err: unknown): WalletError;
|
|
5
5
|
submission(err: unknown): WalletError;
|
|
6
6
|
};
|
|
7
7
|
export type WalletError = OtherWalletError | InsufficientFundsError | SubmissionError | AddressError | SyncWalletError | InvalidCoinHashesError | TransactingError | LedgerOps.LedgerError;
|
|
8
|
-
declare const OtherWalletError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").
|
|
8
|
+
declare const OtherWalletError_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 & {
|
|
9
9
|
readonly _tag: "Wallet.Other";
|
|
10
10
|
} & Readonly<A>;
|
|
11
11
|
export declare class OtherWalletError extends OtherWalletError_base<{
|
|
@@ -13,7 +13,7 @@ export declare class OtherWalletError extends OtherWalletError_base<{
|
|
|
13
13
|
cause?: unknown;
|
|
14
14
|
}> {
|
|
15
15
|
}
|
|
16
|
-
declare const SyncWalletError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").
|
|
16
|
+
declare const SyncWalletError_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 & {
|
|
17
17
|
readonly _tag: "Wallet.Sync";
|
|
18
18
|
} & Readonly<A>;
|
|
19
19
|
export declare class SyncWalletError extends SyncWalletError_base<{
|
|
@@ -21,7 +21,7 @@ export declare class SyncWalletError extends SyncWalletError_base<{
|
|
|
21
21
|
cause?: unknown;
|
|
22
22
|
}> {
|
|
23
23
|
}
|
|
24
|
-
declare const SubmissionError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").
|
|
24
|
+
declare const SubmissionError_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 & {
|
|
25
25
|
readonly _tag: "Wallet.SubmissionWalletError";
|
|
26
26
|
} & Readonly<A>;
|
|
27
27
|
export declare class SubmissionError extends SubmissionError_base<{
|
|
@@ -29,7 +29,7 @@ export declare class SubmissionError extends SubmissionError_base<{
|
|
|
29
29
|
cause?: unknown;
|
|
30
30
|
}> {
|
|
31
31
|
}
|
|
32
|
-
declare const InsufficientFundsError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").
|
|
32
|
+
declare const InsufficientFundsError_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 & {
|
|
33
33
|
readonly _tag: "Wallet.InsufficientFunds";
|
|
34
34
|
} & Readonly<A>;
|
|
35
35
|
export declare class InsufficientFundsError extends InsufficientFundsError_base<{
|
|
@@ -38,7 +38,7 @@ export declare class InsufficientFundsError extends InsufficientFundsError_base<
|
|
|
38
38
|
amount: bigint;
|
|
39
39
|
}> {
|
|
40
40
|
}
|
|
41
|
-
declare const AddressError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").
|
|
41
|
+
declare const AddressError_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 & {
|
|
42
42
|
readonly _tag: "Wallet.Address";
|
|
43
43
|
} & Readonly<A>;
|
|
44
44
|
export declare class AddressError extends AddressError_base<{
|
|
@@ -47,7 +47,7 @@ export declare class AddressError extends AddressError_base<{
|
|
|
47
47
|
cause?: unknown;
|
|
48
48
|
}> {
|
|
49
49
|
}
|
|
50
|
-
declare const InvalidCoinHashesError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").
|
|
50
|
+
declare const InvalidCoinHashesError_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 & {
|
|
51
51
|
readonly _tag: "Wallet.InvalidCoinHashes";
|
|
52
52
|
} & Readonly<A>;
|
|
53
53
|
export declare class InvalidCoinHashesError extends InvalidCoinHashesError_base<{
|
|
@@ -55,7 +55,7 @@ export declare class InvalidCoinHashesError extends InvalidCoinHashesError_base<
|
|
|
55
55
|
missingNonces: Set<ledger.Nonce>;
|
|
56
56
|
}> {
|
|
57
57
|
}
|
|
58
|
-
declare const TransactingError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").
|
|
58
|
+
declare const TransactingError_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 & {
|
|
59
59
|
readonly _tag: "Wallet.Transacting";
|
|
60
60
|
} & Readonly<A>;
|
|
61
61
|
export declare class TransactingError extends TransactingError_base<{
|
|
@@ -63,4 +63,12 @@ export declare class TransactingError extends TransactingError_base<{
|
|
|
63
63
|
cause?: unknown;
|
|
64
64
|
}> {
|
|
65
65
|
}
|
|
66
|
+
declare const TransactionHistoryError_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 & {
|
|
67
|
+
readonly _tag: "Wallet.TransactionHistory";
|
|
68
|
+
} & Readonly<A>;
|
|
69
|
+
export declare class TransactionHistoryError extends TransactionHistoryError_base<{
|
|
70
|
+
message: string;
|
|
71
|
+
cause?: unknown;
|
|
72
|
+
}> {
|
|
73
|
+
}
|
|
66
74
|
export {};
|
package/dist/v1/WalletError.js
CHANGED
|
@@ -49,3 +49,5 @@ export class InvalidCoinHashesError extends Data.TaggedError('Wallet.InvalidCoin
|
|
|
49
49
|
}
|
|
50
50
|
export class TransactingError extends Data.TaggedError('Wallet.Transacting') {
|
|
51
51
|
}
|
|
52
|
+
export class TransactionHistoryError extends Data.TaggedError('Wallet.TransactionHistory') {
|
|
53
|
+
}
|
package/dist/v1/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export * as Serialization from './Serialization.js';
|
|
|
6
6
|
export * as CoinsAndBalances from './CoinsAndBalances.js';
|
|
7
7
|
export * as Keys from './Keys.js';
|
|
8
8
|
export * from './RunningV1Variant.js';
|
|
9
|
-
export * as Simulator from '
|
|
9
|
+
export * as Simulator from '@midnight-ntwrk/wallet-sdk-capabilities/simulation';
|
|
10
10
|
export * as WalletError from './WalletError.js';
|
|
11
11
|
export * from './CoreWallet.js';
|
|
12
12
|
export * from './TransactionOps.js';
|
package/dist/v1/index.js
CHANGED
|
@@ -18,7 +18,7 @@ export * as Serialization from './Serialization.js';
|
|
|
18
18
|
export * as CoinsAndBalances from './CoinsAndBalances.js';
|
|
19
19
|
export * as Keys from './Keys.js';
|
|
20
20
|
export * from './RunningV1Variant.js';
|
|
21
|
-
export * as Simulator from '
|
|
21
|
+
export * as Simulator from '@midnight-ntwrk/wallet-sdk-capabilities/simulation';
|
|
22
22
|
export * as WalletError from './WalletError.js';
|
|
23
23
|
export * from './CoreWallet.js';
|
|
24
24
|
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": "3.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -28,13 +28,13 @@
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@midnight-ntwrk/ledger-v8": "^8.0
|
|
32
|
-
"@midnight-ntwrk/wallet-sdk-abstractions": "2.
|
|
33
|
-
"@midnight-ntwrk/wallet-sdk-address-format": "3.1.
|
|
34
|
-
"@midnight-ntwrk/wallet-sdk-capabilities": "3.
|
|
35
|
-
"@midnight-ntwrk/wallet-sdk-indexer-client": "1.2.
|
|
36
|
-
"@midnight-ntwrk/wallet-sdk-runtime": "1.0.
|
|
37
|
-
"@midnight-ntwrk/wallet-sdk-utilities": "1.
|
|
31
|
+
"@midnight-ntwrk/ledger-v8": "^8.1.0",
|
|
32
|
+
"@midnight-ntwrk/wallet-sdk-abstractions": "^2.1.0",
|
|
33
|
+
"@midnight-ntwrk/wallet-sdk-address-format": "^3.1.2",
|
|
34
|
+
"@midnight-ntwrk/wallet-sdk-capabilities": "^3.3.1",
|
|
35
|
+
"@midnight-ntwrk/wallet-sdk-indexer-client": "^1.2.2",
|
|
36
|
+
"@midnight-ntwrk/wallet-sdk-runtime": "^1.0.4",
|
|
37
|
+
"@midnight-ntwrk/wallet-sdk-utilities": "^1.2.0",
|
|
38
38
|
"effect": "^3.19.19",
|
|
39
39
|
"rxjs": "^7.8.2"
|
|
40
40
|
},
|
package/dist/v1/Simulator.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import * as ledger from '@midnight-ntwrk/ledger-v8';
|
|
2
|
-
import { Array as Arr, Effect, type Scope, Stream, SubscriptionRef } from 'effect';
|
|
3
|
-
export type SimulatorState = Readonly<{
|
|
4
|
-
ledger: ledger.LedgerState;
|
|
5
|
-
lastTxResult: ledger.TransactionResult;
|
|
6
|
-
lastTxNumber: bigint;
|
|
7
|
-
}>;
|
|
8
|
-
export declare class Simulator {
|
|
9
|
-
#private;
|
|
10
|
-
static nextBlockContext: (number: bigint) => Effect.Effect<ledger.BlockContext>;
|
|
11
|
-
static init(genesisMints: Readonly<Arr.NonEmptyArray<{
|
|
12
|
-
amount: bigint;
|
|
13
|
-
type: ledger.RawTokenType;
|
|
14
|
-
recipient: ledger.ZswapSecretKeys;
|
|
15
|
-
}>>): Effect.Effect<Simulator, never, Scope.Scope>;
|
|
16
|
-
readonly state$: Stream.Stream<SimulatorState>;
|
|
17
|
-
constructor(stateRef: SubscriptionRef.SubscriptionRef<SimulatorState>, state$: Stream.Stream<SimulatorState>);
|
|
18
|
-
submitTransaction(tx: ledger.ProofErasedTransaction): Effect.Effect<{
|
|
19
|
-
blockNumber: bigint;
|
|
20
|
-
blockHash: string;
|
|
21
|
-
}>;
|
|
22
|
-
}
|