@midnight-ntwrk/wallet-sdk-unshielded-wallet 1.0.0-beta.13 → 1.0.0-beta.14
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/KeyStore.d.ts +3 -7
- package/dist/KeyStore.js +2 -2
- package/dist/UnshieldedWallet.d.ts +57 -0
- package/dist/UnshieldedWallet.js +120 -0
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -2
- package/dist/{tx-history-storage → storage}/InMemoryTransactionHistoryStorage.d.ts +3 -7
- package/dist/{tx-history-storage → storage}/TransactionHistoryStorage.d.ts +3 -7
- package/dist/{tx-history-storage → storage}/TransactionHistoryStorage.js +3 -7
- package/dist/{tx-history-storage → storage}/index.d.ts +1 -0
- package/dist/{tx-history-storage → storage}/index.js +1 -0
- package/dist/v1/CoinsAndBalances.d.ts +13 -0
- package/dist/v1/CoinsAndBalances.js +36 -0
- package/dist/v1/CoreWallet.d.ts +24 -0
- package/dist/v1/CoreWallet.js +60 -0
- package/dist/v1/Keys.d.ts +8 -0
- package/dist/v1/Keys.js +23 -0
- package/dist/v1/RunningV1Variant.d.ts +41 -0
- package/dist/v1/RunningV1Variant.js +91 -0
- package/dist/v1/Serialization.d.ts +12 -0
- package/dist/v1/Serialization.js +64 -0
- package/dist/v1/Simulator.d.ts +22 -0
- package/dist/v1/Simulator.js +102 -0
- package/dist/v1/Sync.d.ts +32 -0
- package/dist/v1/Sync.js +85 -0
- package/dist/v1/SyncProgress.d.ts +18 -0
- package/dist/v1/SyncProgress.js +23 -0
- package/dist/v1/SyncSchema.d.ts +449 -0
- package/dist/v1/SyncSchema.js +123 -0
- package/dist/v1/Transacting.d.ts +45 -0
- package/dist/v1/Transacting.js +252 -0
- package/dist/v1/Transaction.d.ts +25 -0
- package/dist/v1/Transaction.js +155 -0
- package/dist/v1/TransactionHistory.d.ts +12 -0
- package/dist/v1/TransactionHistory.js +29 -0
- package/dist/v1/TransactionImbalances.d.ts +8 -0
- package/dist/v1/TransactionImbalances.js +21 -0
- package/dist/v1/UnshieldedState.d.ts +37 -0
- package/dist/v1/UnshieldedState.js +67 -0
- package/dist/v1/V1Builder.d.ts +97 -0
- package/dist/v1/V1Builder.js +160 -0
- package/dist/v1/WalletError.d.ts +89 -0
- package/dist/v1/WalletError.js +53 -0
- package/dist/v1/index.d.ts +15 -0
- package/dist/v1/index.js +27 -0
- package/package.json +4 -4
- package/dist/State.d.ts +0 -21
- package/dist/State.js +0 -43
- package/dist/SyncService.d.ts +0 -55
- package/dist/SyncService.js +0 -88
- package/dist/TransactionHistoryService.d.ts +0 -31
- package/dist/TransactionHistoryService.js +0 -49
- package/dist/TransactionService.d.ts +0 -43
- package/dist/TransactionService.js +0 -291
- package/dist/WalletBuilder.d.ts +0 -37
- package/dist/WalletBuilder.js +0 -137
- /package/dist/{tx-history-storage → storage}/InMemoryTransactionHistoryStorage.js +0 -0
- /package/dist/{tx-history-storage → storage}/NoOpTransactionHistoryStorage.d.ts +0 -0
- /package/dist/{tx-history-storage → storage}/NoOpTransactionHistoryStorage.js +0 -0
package/dist/KeyStore.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MidnightBech32m } from '@midnight-ntwrk/wallet-sdk-address-format';
|
|
2
2
|
import { Signature, SignatureVerifyingKey, UserAddress } from '@midnight-ntwrk/ledger-v6';
|
|
3
3
|
import { NetworkId } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
4
4
|
export type PublicKey = {
|
|
5
5
|
publicKey: SignatureVerifyingKey;
|
|
6
|
-
|
|
6
|
+
addressHex: UserAddress;
|
|
7
|
+
address: string;
|
|
7
8
|
};
|
|
8
9
|
export declare const PublicKey: {
|
|
9
10
|
fromKeyStore: (keystore: UnshieldedKeystore) => PublicKey;
|
|
@@ -15,9 +16,4 @@ export interface UnshieldedKeystore {
|
|
|
15
16
|
getAddress(): UserAddress;
|
|
16
17
|
signData(data: Uint8Array): Signature;
|
|
17
18
|
}
|
|
18
|
-
export interface Keystore {
|
|
19
|
-
keystore: UnshieldedKeystore;
|
|
20
|
-
getBech32Address(): MidnightBech32m;
|
|
21
|
-
getPublicKey(): SignatureVerifyingKey;
|
|
22
|
-
}
|
|
23
19
|
export declare const createKeystore: (secretKey: Uint8Array<ArrayBufferLike>, networkId: NetworkId.NetworkId) => UnshieldedKeystore;
|
package/dist/KeyStore.js
CHANGED
|
@@ -12,12 +12,12 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { UnshieldedAddress } from '@midnight-ntwrk/wallet-sdk-address-format';
|
|
14
14
|
import { addressFromKey, signData, signatureVerifyingKey, } from '@midnight-ntwrk/ledger-v6';
|
|
15
|
-
import { pipe } from 'effect';
|
|
16
15
|
export const PublicKey = {
|
|
17
16
|
fromKeyStore: (keystore) => {
|
|
18
17
|
return {
|
|
19
18
|
publicKey: keystore.getPublicKey(),
|
|
20
|
-
|
|
19
|
+
addressHex: keystore.getAddress(),
|
|
20
|
+
address: keystore.getBech32Address().asString(),
|
|
21
21
|
};
|
|
22
22
|
},
|
|
23
23
|
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ProtocolState, ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
2
|
+
import { BaseV1Configuration, DefaultV1Configuration, V1Variant, CoreWallet } from './v1/index.js';
|
|
3
|
+
import * as ledger from '@midnight-ntwrk/ledger-v6';
|
|
4
|
+
import * as rx from 'rxjs';
|
|
5
|
+
import { SerializationCapability } from './v1/Serialization.js';
|
|
6
|
+
import { TransactionHistoryService } from './v1/TransactionHistory.js';
|
|
7
|
+
import { CoinsAndBalancesCapability } from './v1/CoinsAndBalances.js';
|
|
8
|
+
import { KeysCapability } from './v1/Keys.js';
|
|
9
|
+
import { TokenTransfer } from './v1/Transacting.js';
|
|
10
|
+
import { WalletSyncUpdate } from './v1/SyncSchema.js';
|
|
11
|
+
import { UtxoWithMeta } from './v1/UnshieldedState.js';
|
|
12
|
+
import { Variant, VariantBuilder, WalletLike } from '@midnight-ntwrk/wallet-sdk-runtime/abstractions';
|
|
13
|
+
import { PublicKey } from './KeyStore.js';
|
|
14
|
+
import { SyncProgress } from './v1/SyncProgress.js';
|
|
15
|
+
import { UnshieldedUpdate } from './v1/SyncSchema.js';
|
|
16
|
+
import { UnshieldedAddress } from '@midnight-ntwrk/wallet-sdk-address-format';
|
|
17
|
+
export type UnshieldedWalletCapabilities<TSerialized = string> = {
|
|
18
|
+
serialization: SerializationCapability<CoreWallet, TSerialized>;
|
|
19
|
+
coinsAndBalances: CoinsAndBalancesCapability<CoreWallet>;
|
|
20
|
+
keys: KeysCapability<CoreWallet>;
|
|
21
|
+
transactionHistory: TransactionHistoryService<UnshieldedUpdate>;
|
|
22
|
+
};
|
|
23
|
+
export declare class UnshieldedWalletState<TSerialized = string> {
|
|
24
|
+
static readonly mapState: <TSerialized_1 = string>(capabilities: UnshieldedWalletCapabilities<TSerialized_1>) => (state: ProtocolState.ProtocolState<CoreWallet>) => UnshieldedWalletState<TSerialized_1>;
|
|
25
|
+
readonly protocolVersion: ProtocolVersion.ProtocolVersion;
|
|
26
|
+
readonly state: CoreWallet;
|
|
27
|
+
readonly capabilities: UnshieldedWalletCapabilities<TSerialized>;
|
|
28
|
+
get balances(): Record<ledger.RawTokenType, bigint>;
|
|
29
|
+
get totalCoins(): readonly UtxoWithMeta[];
|
|
30
|
+
get availableCoins(): readonly UtxoWithMeta[];
|
|
31
|
+
get pendingCoins(): readonly UtxoWithMeta[];
|
|
32
|
+
get address(): UnshieldedAddress;
|
|
33
|
+
get progress(): SyncProgress;
|
|
34
|
+
get transactionHistory(): TransactionHistoryService<UnshieldedUpdate>;
|
|
35
|
+
constructor(state: ProtocolState.ProtocolState<CoreWallet>, capabilities: UnshieldedWalletCapabilities<TSerialized>);
|
|
36
|
+
serialize(): TSerialized;
|
|
37
|
+
}
|
|
38
|
+
export type UnshieldedWallet = CustomizedUnshieldedWallet<ledger.FinalizedTransaction, WalletSyncUpdate, string>;
|
|
39
|
+
export type UnshieldedWalletClass = CustomizedUnshieldedWalletClass<ledger.FinalizedTransaction, WalletSyncUpdate, string>;
|
|
40
|
+
export interface CustomizedUnshieldedWallet<TTransaction = ledger.Transaction<ledger.SignatureEnabled, ledger.Proofish, ledger.Bindingish>, TSyncUpdate = WalletSyncUpdate, TSerialized = string> extends WalletLike.WalletLike<[Variant.VersionedVariant<V1Variant<TSerialized, TSyncUpdate, TTransaction>>]> {
|
|
41
|
+
readonly state: rx.Observable<UnshieldedWalletState<TSerialized>>;
|
|
42
|
+
start(): Promise<void>;
|
|
43
|
+
balanceTransaction(tx: ledger.Transaction<ledger.SignatureEnabled, ledger.Proofish, ledger.Bindingish>): Promise<ledger.Transaction<ledger.SignatureEnabled, ledger.Proofish, ledger.Bindingish>>;
|
|
44
|
+
transferTransaction(outputs: readonly TokenTransfer[], ttl: Date): Promise<ledger.UnprovenTransaction>;
|
|
45
|
+
initSwap(desiredInputs: Record<ledger.RawTokenType, bigint>, desiredOutputs: readonly TokenTransfer[], ttl: Date): Promise<ledger.UnprovenTransaction>;
|
|
46
|
+
signTransaction(transaction: ledger.UnprovenTransaction, signSegment: (data: Uint8Array) => ledger.Signature): Promise<ledger.UnprovenTransaction>;
|
|
47
|
+
serializeState(): Promise<TSerialized>;
|
|
48
|
+
waitForSyncedState(allowedGap?: bigint): Promise<UnshieldedWalletState<TSerialized>>;
|
|
49
|
+
getAddress(): Promise<UnshieldedAddress>;
|
|
50
|
+
}
|
|
51
|
+
export interface CustomizedUnshieldedWalletClass<TTransaction = ledger.Transaction<ledger.SignatureEnabled, ledger.Proofish, ledger.Bindingish>, TSyncUpdate = WalletSyncUpdate, TSerialized = string, TConfig extends BaseV1Configuration = DefaultV1Configuration> extends WalletLike.BaseWalletClass<[Variant.VersionedVariant<V1Variant<TSerialized, TSyncUpdate, TTransaction>>]> {
|
|
52
|
+
configuration: TConfig;
|
|
53
|
+
startWithPublicKey(publicKey: PublicKey): CustomizedUnshieldedWallet<TTransaction, TSyncUpdate, TSerialized>;
|
|
54
|
+
restore(serializedState: TSerialized): CustomizedUnshieldedWallet<TTransaction, TSyncUpdate, TSerialized>;
|
|
55
|
+
}
|
|
56
|
+
export declare function UnshieldedWallet(configuration: DefaultV1Configuration): UnshieldedWalletClass;
|
|
57
|
+
export declare function CustomUnshieldedWallet<TConfig extends BaseV1Configuration = DefaultV1Configuration, TTransaction = ledger.Transaction<ledger.SignatureEnabled, ledger.Proofish, ledger.Bindingish>, TSyncUpdate = WalletSyncUpdate, TSerialized = string>(configuration: TConfig, builder: VariantBuilder.VariantBuilder<V1Variant<TSerialized, TSyncUpdate, TTransaction>, TConfig>): CustomizedUnshieldedWalletClass<TTransaction, TSyncUpdate, TSerialized, TConfig>;
|
|
@@ -0,0 +1,120 @@
|
|
|
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 { ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
14
|
+
import { V1Builder, V1Tag, CoreWallet } from './v1/index.js';
|
|
15
|
+
import { Effect, Either } from 'effect';
|
|
16
|
+
import * as rx from 'rxjs';
|
|
17
|
+
import { WalletBuilder } from '@midnight-ntwrk/wallet-sdk-runtime';
|
|
18
|
+
export class UnshieldedWalletState {
|
|
19
|
+
static mapState = (capabilities) => (state) => {
|
|
20
|
+
return new UnshieldedWalletState(state, capabilities);
|
|
21
|
+
};
|
|
22
|
+
protocolVersion;
|
|
23
|
+
state;
|
|
24
|
+
capabilities;
|
|
25
|
+
get balances() {
|
|
26
|
+
return this.capabilities.coinsAndBalances.getAvailableBalances(this.state);
|
|
27
|
+
}
|
|
28
|
+
get totalCoins() {
|
|
29
|
+
return this.capabilities.coinsAndBalances.getTotalCoins(this.state);
|
|
30
|
+
}
|
|
31
|
+
get availableCoins() {
|
|
32
|
+
return this.capabilities.coinsAndBalances.getAvailableCoins(this.state);
|
|
33
|
+
}
|
|
34
|
+
get pendingCoins() {
|
|
35
|
+
return this.capabilities.coinsAndBalances.getPendingCoins(this.state);
|
|
36
|
+
}
|
|
37
|
+
get address() {
|
|
38
|
+
return this.capabilities.keys.getAddress(this.state);
|
|
39
|
+
}
|
|
40
|
+
get progress() {
|
|
41
|
+
return this.state.progress;
|
|
42
|
+
}
|
|
43
|
+
get transactionHistory() {
|
|
44
|
+
return this.capabilities.transactionHistory;
|
|
45
|
+
}
|
|
46
|
+
constructor(state, capabilities) {
|
|
47
|
+
this.protocolVersion = state.version;
|
|
48
|
+
this.state = state.state;
|
|
49
|
+
this.capabilities = capabilities;
|
|
50
|
+
}
|
|
51
|
+
serialize() {
|
|
52
|
+
return this.capabilities.serialization.serialize(this.state);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export function UnshieldedWallet(configuration) {
|
|
56
|
+
return CustomUnshieldedWallet(configuration, new V1Builder().withDefaults());
|
|
57
|
+
}
|
|
58
|
+
export function CustomUnshieldedWallet(configuration, builder) {
|
|
59
|
+
const buildArgs = [configuration];
|
|
60
|
+
const BaseWallet = WalletBuilder.init()
|
|
61
|
+
.withVariant(ProtocolVersion.MinSupportedVersion, builder)
|
|
62
|
+
.build(...buildArgs);
|
|
63
|
+
return class CustomUnshieldedWalletImplementation extends BaseWallet {
|
|
64
|
+
static startWithPublicKey(publicKeys) {
|
|
65
|
+
return CustomUnshieldedWalletImplementation.startFirst(CustomUnshieldedWalletImplementation, CoreWallet.init(publicKeys, configuration.networkId));
|
|
66
|
+
}
|
|
67
|
+
static restore(serializedState) {
|
|
68
|
+
const deserialized = CustomUnshieldedWalletImplementation.allVariantsRecord()[V1Tag].variant.deserializeState(serializedState)
|
|
69
|
+
.pipe(Either.getOrThrow);
|
|
70
|
+
return CustomUnshieldedWalletImplementation.startFirst(CustomUnshieldedWalletImplementation, deserialized);
|
|
71
|
+
}
|
|
72
|
+
state;
|
|
73
|
+
constructor(runtime, scope) {
|
|
74
|
+
super(runtime, scope);
|
|
75
|
+
this.state = this.rawState.pipe(rx.map(UnshieldedWalletState.mapState(CustomUnshieldedWalletImplementation.allVariantsRecord()[V1Tag].variant)), rx.shareReplay({ refCount: true, bufferSize: 1 }));
|
|
76
|
+
}
|
|
77
|
+
start() {
|
|
78
|
+
return this.runtime.dispatch({ [V1Tag]: (v1) => v1.startSyncInBackground() }).pipe(Effect.runPromise);
|
|
79
|
+
}
|
|
80
|
+
balanceTransaction(tx) {
|
|
81
|
+
return this.runtime
|
|
82
|
+
.dispatch({
|
|
83
|
+
[V1Tag]: (v1) => v1.balanceTransaction(tx),
|
|
84
|
+
})
|
|
85
|
+
.pipe(Effect.runPromise);
|
|
86
|
+
}
|
|
87
|
+
transferTransaction(outputs, ttl) {
|
|
88
|
+
return this.runtime
|
|
89
|
+
.dispatch({
|
|
90
|
+
[V1Tag]: (v1) => v1.transferTransaction(outputs, ttl),
|
|
91
|
+
})
|
|
92
|
+
.pipe(Effect.runPromise);
|
|
93
|
+
}
|
|
94
|
+
initSwap(desiredInputs, desiredOutputs, ttl) {
|
|
95
|
+
return this.runtime
|
|
96
|
+
.dispatch({ [V1Tag]: (v1) => v1.initSwap(desiredInputs, desiredOutputs, ttl) })
|
|
97
|
+
.pipe(Effect.runPromise);
|
|
98
|
+
}
|
|
99
|
+
signTransaction(transaction, signSegment) {
|
|
100
|
+
return this.runtime
|
|
101
|
+
.dispatch({
|
|
102
|
+
[V1Tag]: (v1) => v1.signTransaction(transaction, signSegment),
|
|
103
|
+
})
|
|
104
|
+
.pipe(Effect.runPromise);
|
|
105
|
+
}
|
|
106
|
+
waitForSyncedState(allowedGap = 0n) {
|
|
107
|
+
return rx.firstValueFrom(this.state.pipe(rx.filter((state) => state.state.progress.isCompleteWithin(allowedGap))));
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Serializes the most recent state
|
|
111
|
+
* It's preferable to use [[UnshieldedWalletState.serialize]] instead, to know exactly, which state is serialized
|
|
112
|
+
*/
|
|
113
|
+
serializeState() {
|
|
114
|
+
return rx.firstValueFrom(this.state).then((state) => state.serialize());
|
|
115
|
+
}
|
|
116
|
+
getAddress() {
|
|
117
|
+
return rx.firstValueFrom(this.state).then((state) => state.address);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export
|
|
3
|
-
export
|
|
1
|
+
export * from './UnshieldedWallet.js';
|
|
2
|
+
export * from './storage/index.js';
|
|
3
|
+
export * from './KeyStore.js';
|
package/dist/index.js
CHANGED
|
@@ -10,5 +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
|
-
export * from './
|
|
14
|
-
export
|
|
13
|
+
export * from './UnshieldedWallet.js';
|
|
14
|
+
export * from './storage/index.js';
|
|
15
|
+
export * from './KeyStore.js';
|
|
@@ -5,13 +5,9 @@ declare const TransactionHistorySchema: Schema.Map$<typeof Schema.String, Schema
|
|
|
5
5
|
hash: typeof Schema.String;
|
|
6
6
|
protocolVersion: typeof Schema.Number;
|
|
7
7
|
identifiers: Schema.Array$<typeof Schema.String>;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
id: typeof Schema.String;
|
|
12
|
-
success: typeof Schema.Boolean;
|
|
13
|
-
}>>;
|
|
14
|
-
}>>;
|
|
8
|
+
timestamp: typeof Schema.Date;
|
|
9
|
+
fees: Schema.NullOr<typeof Schema.BigInt>;
|
|
10
|
+
status: Schema.Literal<["SUCCESS", "FAILURE", "PARTIAL_SUCCESS"]>;
|
|
15
11
|
}>>;
|
|
16
12
|
export type TransactionHistory = Schema.Schema.Type<typeof TransactionHistorySchema>;
|
|
17
13
|
/**
|
|
@@ -6,13 +6,9 @@ export declare const TransactionHistoryEntrySchema: Schema.Struct<{
|
|
|
6
6
|
hash: typeof Schema.String;
|
|
7
7
|
protocolVersion: typeof Schema.Number;
|
|
8
8
|
identifiers: Schema.Array$<typeof Schema.String>;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
id: typeof Schema.String;
|
|
13
|
-
success: typeof Schema.Boolean;
|
|
14
|
-
}>>;
|
|
15
|
-
}>>;
|
|
9
|
+
timestamp: typeof Schema.Date;
|
|
10
|
+
fees: Schema.NullOr<typeof Schema.BigInt>;
|
|
11
|
+
status: Schema.Literal<["SUCCESS", "FAILURE", "PARTIAL_SUCCESS"]>;
|
|
16
12
|
}>;
|
|
17
13
|
export type TransactionHistoryEntry = Schema.Schema.Type<typeof TransactionHistoryEntrySchema>;
|
|
18
14
|
export interface TransactionHistoryStorage {
|
|
@@ -17,11 +17,7 @@ export const TransactionHistoryEntrySchema = Schema.Struct({
|
|
|
17
17
|
hash: TransactionHashSchema,
|
|
18
18
|
protocolVersion: Schema.Number,
|
|
19
19
|
identifiers: Schema.Array(Schema.String),
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
id: Schema.String,
|
|
24
|
-
success: Schema.Boolean,
|
|
25
|
-
})),
|
|
26
|
-
})),
|
|
20
|
+
timestamp: Schema.Date,
|
|
21
|
+
fees: Schema.NullOr(Schema.BigInt),
|
|
22
|
+
status: Schema.Literal('SUCCESS', 'FAILURE', 'PARTIAL_SUCCESS'),
|
|
27
23
|
});
|
|
@@ -11,4 +11,5 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
export * from './InMemoryTransactionHistoryStorage.js';
|
|
14
|
+
export * from './NoOpTransactionHistoryStorage.js';
|
|
14
15
|
export * from './TransactionHistoryStorage.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CoreWallet } from './CoreWallet.js';
|
|
2
|
+
import * as ledger from '@midnight-ntwrk/ledger-v6';
|
|
3
|
+
import { UtxoWithMeta } from './UnshieldedState.js';
|
|
4
|
+
export type Balances = Record<ledger.RawTokenType, bigint>;
|
|
5
|
+
export type CoinsAndBalancesCapability<TState> = {
|
|
6
|
+
getAvailableBalances(state: TState): Balances;
|
|
7
|
+
getPendingBalances(state: TState): Balances;
|
|
8
|
+
getTotalBalances(state: TState): Balances;
|
|
9
|
+
getAvailableCoins(state: TState): readonly UtxoWithMeta[];
|
|
10
|
+
getPendingCoins(state: TState): readonly UtxoWithMeta[];
|
|
11
|
+
getTotalCoins(state: TState): ReadonlyArray<UtxoWithMeta>;
|
|
12
|
+
};
|
|
13
|
+
export declare const makeDefaultCoinsAndBalancesCapability: () => CoinsAndBalancesCapability<CoreWallet>;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { pipe } from 'effect';
|
|
2
|
+
import { RecordOps } from '@midnight-ntwrk/wallet-sdk-utilities';
|
|
3
|
+
import { UnshieldedState } from './UnshieldedState.js';
|
|
4
|
+
const calculateBalances = (utxos) => utxos.reduce((acc, { utxo }) => ({
|
|
5
|
+
...acc,
|
|
6
|
+
[utxo.type]: acc[utxo.type] === undefined ? utxo.value : acc[utxo.type] + utxo.value,
|
|
7
|
+
}), {});
|
|
8
|
+
export const makeDefaultCoinsAndBalancesCapability = () => {
|
|
9
|
+
const getAvailableBalances = (state) => {
|
|
10
|
+
const availableCoins = getAvailableCoins(state);
|
|
11
|
+
return calculateBalances(availableCoins);
|
|
12
|
+
};
|
|
13
|
+
const getPendingBalances = (state) => {
|
|
14
|
+
const pendingCoins = getPendingCoins(state);
|
|
15
|
+
return calculateBalances(pendingCoins);
|
|
16
|
+
};
|
|
17
|
+
const getTotalBalances = (state) => {
|
|
18
|
+
const availableBalances = getAvailableBalances(state);
|
|
19
|
+
const pendingBalances = getPendingBalances(state);
|
|
20
|
+
return pipe([availableBalances, pendingBalances], RecordOps.mergeWithAccumulator(0n, (a, b) => a + b));
|
|
21
|
+
};
|
|
22
|
+
const getAvailableCoins = (state) => UnshieldedState.toArrays(state.state).availableUtxos;
|
|
23
|
+
const getPendingCoins = (state) => UnshieldedState.toArrays(state.state).pendingUtxos;
|
|
24
|
+
const getTotalCoins = (state) => [
|
|
25
|
+
...getAvailableCoins(state),
|
|
26
|
+
...getPendingCoins(state),
|
|
27
|
+
];
|
|
28
|
+
return {
|
|
29
|
+
getAvailableBalances,
|
|
30
|
+
getPendingBalances,
|
|
31
|
+
getTotalBalances,
|
|
32
|
+
getAvailableCoins,
|
|
33
|
+
getPendingCoins,
|
|
34
|
+
getTotalCoins,
|
|
35
|
+
};
|
|
36
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
2
|
+
import { SyncProgress, SyncProgressData } from './SyncProgress.js';
|
|
3
|
+
import { PublicKey } from '../KeyStore.js';
|
|
4
|
+
import { UnshieldedState, UnshieldedUpdate } from './UnshieldedState.js';
|
|
5
|
+
import * as ledger from '@midnight-ntwrk/ledger-v6';
|
|
6
|
+
import { Either } from 'effect';
|
|
7
|
+
import { WalletError } from './WalletError.js';
|
|
8
|
+
export type CoreWallet = Readonly<{
|
|
9
|
+
state: UnshieldedState;
|
|
10
|
+
publicKey: PublicKey;
|
|
11
|
+
protocolVersion: ProtocolVersion.ProtocolVersion;
|
|
12
|
+
progress: SyncProgress;
|
|
13
|
+
networkId: string;
|
|
14
|
+
}>;
|
|
15
|
+
export declare const CoreWallet: {
|
|
16
|
+
init(publicKey: PublicKey, networkId: string): CoreWallet;
|
|
17
|
+
restore(state: UnshieldedState, publicKey: PublicKey, syncProgress: Omit<SyncProgressData, "isConnected">, protocolVersion: ProtocolVersion.ProtocolVersion, networkId: string): CoreWallet;
|
|
18
|
+
updateProgress(wallet: CoreWallet, { appliedId, highestTransactionId, isConnected }: Partial<SyncProgressData>): CoreWallet;
|
|
19
|
+
applyUpdate(coreWallet: CoreWallet, update: UnshieldedUpdate): Either.Either<CoreWallet, WalletError>;
|
|
20
|
+
applyFailedUpdate(coreWallet: CoreWallet, update: UnshieldedUpdate): Either.Either<CoreWallet, WalletError>;
|
|
21
|
+
rollbackUtxo(coreWallet: CoreWallet, utxo: ledger.Utxo): Either.Either<CoreWallet, WalletError>;
|
|
22
|
+
spend(coreWallet: CoreWallet, utxo: ledger.Utxo): Either.Either<CoreWallet, WalletError>;
|
|
23
|
+
spendUtxos(wallet: CoreWallet, utxos: ReadonlyArray<ledger.Utxo>): Either.Either<[ReadonlyArray<ledger.Utxo>, CoreWallet], WalletError>;
|
|
24
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
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 { ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
14
|
+
import { createSyncProgress } from './SyncProgress.js';
|
|
15
|
+
import { UnshieldedState } from './UnshieldedState.js';
|
|
16
|
+
import { Either, Array as Arr, pipe } from 'effect';
|
|
17
|
+
import { ApplyTransactionError, RollbackUtxoError, SpendUtxoError } from './WalletError.js';
|
|
18
|
+
export const CoreWallet = {
|
|
19
|
+
init(publicKey, networkId) {
|
|
20
|
+
return {
|
|
21
|
+
state: UnshieldedState.empty(),
|
|
22
|
+
publicKey,
|
|
23
|
+
protocolVersion: ProtocolVersion.MinSupportedVersion,
|
|
24
|
+
progress: createSyncProgress(),
|
|
25
|
+
networkId,
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
restore(state, publicKey, syncProgress, protocolVersion, networkId) {
|
|
29
|
+
return {
|
|
30
|
+
state,
|
|
31
|
+
publicKey,
|
|
32
|
+
protocolVersion,
|
|
33
|
+
progress: createSyncProgress(syncProgress),
|
|
34
|
+
networkId,
|
|
35
|
+
};
|
|
36
|
+
},
|
|
37
|
+
updateProgress(wallet, { appliedId, highestTransactionId, isConnected }) {
|
|
38
|
+
const progress = createSyncProgress({
|
|
39
|
+
appliedId: appliedId ?? wallet.progress.appliedId,
|
|
40
|
+
highestTransactionId: highestTransactionId ?? wallet.progress.highestTransactionId,
|
|
41
|
+
isConnected: isConnected ?? wallet.progress.isConnected,
|
|
42
|
+
});
|
|
43
|
+
return { ...wallet, progress };
|
|
44
|
+
},
|
|
45
|
+
applyUpdate(coreWallet, update) {
|
|
46
|
+
return UnshieldedState.applyUpdate(coreWallet.state, update).pipe(Either.map((state) => ({ ...coreWallet, state })), Either.mapLeft((error) => new ApplyTransactionError(error)));
|
|
47
|
+
},
|
|
48
|
+
applyFailedUpdate(coreWallet, update) {
|
|
49
|
+
return UnshieldedState.applyFailedUpdate(coreWallet.state, update).pipe(Either.map((state) => ({ ...coreWallet, state })), Either.mapLeft((error) => new ApplyTransactionError(error)));
|
|
50
|
+
},
|
|
51
|
+
rollbackUtxo(coreWallet, utxo) {
|
|
52
|
+
return UnshieldedState.rollbackSpendByUtxo(coreWallet.state, utxo).pipe(Either.map((state) => ({ ...coreWallet, state })), Either.mapLeft((error) => new RollbackUtxoError(error)));
|
|
53
|
+
},
|
|
54
|
+
spend(coreWallet, utxo) {
|
|
55
|
+
return UnshieldedState.spendByUtxo(coreWallet.state, utxo).pipe(Either.map((state) => ({ ...coreWallet, state })), Either.mapLeft((error) => new SpendUtxoError(error)));
|
|
56
|
+
},
|
|
57
|
+
spendUtxos(wallet, utxos) {
|
|
58
|
+
return pipe(utxos, Arr.reduce(Either.right([[], wallet.state]), (acc, utxoToSpend) => acc.pipe(Either.flatMap(([accUtxos, state]) => UnshieldedState.spendByUtxo(state, utxoToSpend).pipe(Either.map((nextState) => [accUtxos.concat([utxoToSpend]), nextState]), Either.mapLeft((error) => new SpendUtxoError(error)))))), Either.map(([spentUtxos, state]) => [spentUtxos, { ...wallet, state }]));
|
|
59
|
+
},
|
|
60
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { UnshieldedAddress } from '@midnight-ntwrk/wallet-sdk-address-format';
|
|
2
|
+
import type { CoreWallet } from './CoreWallet.js';
|
|
3
|
+
import { SignatureVerifyingKey } from '@midnight-ntwrk/ledger-v6';
|
|
4
|
+
export type KeysCapability<TState> = {
|
|
5
|
+
getPublicKey(state: TState): SignatureVerifyingKey;
|
|
6
|
+
getAddress(state: TState): UnshieldedAddress;
|
|
7
|
+
};
|
|
8
|
+
export declare const makeDefaultKeysCapability: () => KeysCapability<CoreWallet>;
|
package/dist/v1/Keys.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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 { UnshieldedAddress } from '@midnight-ntwrk/wallet-sdk-address-format';
|
|
14
|
+
export const makeDefaultKeysCapability = () => {
|
|
15
|
+
return {
|
|
16
|
+
getPublicKey: (state) => {
|
|
17
|
+
return state.publicKey.publicKey;
|
|
18
|
+
},
|
|
19
|
+
getAddress: (state) => {
|
|
20
|
+
return new UnshieldedAddress(Buffer.from(state.publicKey.addressHex, 'hex'));
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Effect, Scope, Stream } from 'effect';
|
|
2
|
+
import { WalletRuntimeError, Variant, StateChange } from '@midnight-ntwrk/wallet-sdk-runtime/abstractions';
|
|
3
|
+
import { SerializationCapability } from './Serialization.js';
|
|
4
|
+
import { SyncCapability, SyncService } from './Sync.js';
|
|
5
|
+
import { WalletSyncUpdate } from './SyncSchema.js';
|
|
6
|
+
import { TransactingCapability, TokenTransfer } from './Transacting.js';
|
|
7
|
+
import { WalletError } from './WalletError.js';
|
|
8
|
+
import { CoinsAndBalancesCapability } from './CoinsAndBalances.js';
|
|
9
|
+
import { KeysCapability } from './Keys.js';
|
|
10
|
+
import { CoinSelection } from '@midnight-ntwrk/wallet-sdk-capabilities';
|
|
11
|
+
import { CoreWallet } from './CoreWallet.js';
|
|
12
|
+
import { TransactionHistoryService } from './TransactionHistory.js';
|
|
13
|
+
import * as ledger from '@midnight-ntwrk/ledger-v6';
|
|
14
|
+
export declare namespace RunningV1Variant {
|
|
15
|
+
type Context<TSerialized, TSyncUpdate, TTransaction> = {
|
|
16
|
+
serializationCapability: SerializationCapability<CoreWallet, TSerialized>;
|
|
17
|
+
syncService: SyncService<CoreWallet, TSyncUpdate>;
|
|
18
|
+
syncCapability: SyncCapability<CoreWallet, TSyncUpdate>;
|
|
19
|
+
transactingCapability: TransactingCapability<TTransaction, CoreWallet>;
|
|
20
|
+
coinsAndBalancesCapability: CoinsAndBalancesCapability<CoreWallet>;
|
|
21
|
+
keysCapability: KeysCapability<CoreWallet>;
|
|
22
|
+
coinSelection: CoinSelection<ledger.Utxo>;
|
|
23
|
+
transactionHistoryService: TransactionHistoryService<WalletSyncUpdate>;
|
|
24
|
+
};
|
|
25
|
+
type AnyContext = Context<any, any, any>;
|
|
26
|
+
}
|
|
27
|
+
export declare const V1Tag: unique symbol;
|
|
28
|
+
export type DefaultRunningV1 = RunningV1Variant<string, WalletSyncUpdate, ledger.FinalizedTransaction>;
|
|
29
|
+
export declare class RunningV1Variant<TSerialized, TSyncUpdate, TTransaction> implements Variant.RunningVariant<typeof V1Tag, CoreWallet> {
|
|
30
|
+
#private;
|
|
31
|
+
readonly __polyTag__: typeof V1Tag;
|
|
32
|
+
readonly state: Stream.Stream<StateChange.StateChange<CoreWallet>, WalletRuntimeError>;
|
|
33
|
+
constructor(scope: Scope.Scope, context: Variant.VariantContext<CoreWallet>, v1Context: RunningV1Variant.Context<TSerialized, TSyncUpdate, TTransaction>);
|
|
34
|
+
startSyncInBackground(): Effect.Effect<void>;
|
|
35
|
+
startSync(): Stream.Stream<void, WalletError, Scope.Scope>;
|
|
36
|
+
balanceTransaction(tx: ledger.Transaction<ledger.SignatureEnabled, ledger.Proofish, ledger.Bindingish>): Effect.Effect<ledger.Transaction<ledger.SignatureEnabled, ledger.Proofish, ledger.Bindingish>, WalletError>;
|
|
37
|
+
transferTransaction(outputs: ReadonlyArray<TokenTransfer>, ttl: Date): Effect.Effect<ledger.UnprovenTransaction, WalletError>;
|
|
38
|
+
initSwap(desiredInputs: Record<string, bigint>, desiredOutputs: ReadonlyArray<TokenTransfer>, ttl: Date): Effect.Effect<ledger.UnprovenTransaction, WalletError>;
|
|
39
|
+
signTransaction(transaction: ledger.UnprovenTransaction, signSegment: (data: Uint8Array) => ledger.Signature): Effect.Effect<ledger.UnprovenTransaction, WalletError>;
|
|
40
|
+
serializeState(state: CoreWallet): TSerialized;
|
|
41
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
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 { Effect, pipe, Scope, Stream, SubscriptionRef, Schedule, Duration, Sink, Console } from 'effect';
|
|
14
|
+
import { ProtocolVersion } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
15
|
+
import { StateChange, VersionChangeType, } from '@midnight-ntwrk/wallet-sdk-runtime/abstractions';
|
|
16
|
+
import { EitherOps } from '@midnight-ntwrk/wallet-sdk-utilities';
|
|
17
|
+
const progress = (state) => {
|
|
18
|
+
const appliedId = state.progress?.appliedId ?? 0n;
|
|
19
|
+
const highestTransactionId = state.progress?.highestTransactionId ?? 0n;
|
|
20
|
+
const sourceGap = highestTransactionId - appliedId;
|
|
21
|
+
const applyGap = appliedId - appliedId;
|
|
22
|
+
return [StateChange.ProgressUpdate({ sourceGap, applyGap })];
|
|
23
|
+
};
|
|
24
|
+
const protocolVersionChange = (previous, current) => {
|
|
25
|
+
return previous.protocolVersion != current.protocolVersion
|
|
26
|
+
? [
|
|
27
|
+
StateChange.VersionChange({
|
|
28
|
+
change: VersionChangeType.Version({
|
|
29
|
+
version: ProtocolVersion.ProtocolVersion(current.protocolVersion),
|
|
30
|
+
}),
|
|
31
|
+
}),
|
|
32
|
+
]
|
|
33
|
+
: [];
|
|
34
|
+
};
|
|
35
|
+
export const V1Tag = Symbol('V1');
|
|
36
|
+
export class RunningV1Variant {
|
|
37
|
+
__polyTag__ = V1Tag;
|
|
38
|
+
#scope;
|
|
39
|
+
#context;
|
|
40
|
+
#v1Context;
|
|
41
|
+
state;
|
|
42
|
+
constructor(scope, context, v1Context) {
|
|
43
|
+
this.#scope = scope;
|
|
44
|
+
this.#context = context;
|
|
45
|
+
this.#v1Context = v1Context;
|
|
46
|
+
this.state = Stream.fromEffect(context.stateRef.get).pipe(Stream.flatMap((initialState) => context.stateRef.changes.pipe(Stream.mapAccum(initialState, (previous, current) => {
|
|
47
|
+
return [current, [previous, current]];
|
|
48
|
+
}))), Stream.mapConcat(([previous, current]) => {
|
|
49
|
+
// TODO: emit progress only upon actual change
|
|
50
|
+
return [
|
|
51
|
+
StateChange.State({ state: current }),
|
|
52
|
+
...progress(current),
|
|
53
|
+
...protocolVersionChange(previous, current),
|
|
54
|
+
];
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
startSyncInBackground() {
|
|
58
|
+
return this.startSync().pipe(Stream.runScoped(Sink.drain), Effect.forkScoped, Effect.provideService(Scope.Scope, this.#scope));
|
|
59
|
+
}
|
|
60
|
+
startSync() {
|
|
61
|
+
return pipe(SubscriptionRef.get(this.#context.stateRef), Stream.fromEffect, Stream.flatMap((state) => this.#v1Context.syncService.updates(state)), Stream.mapEffect((update) => {
|
|
62
|
+
return SubscriptionRef.updateEffect(this.#context.stateRef, (state) => pipe(this.#v1Context.syncCapability.applyUpdate(state, update), EitherOps.toEffect));
|
|
63
|
+
}), Stream.tapError((error) => Console.error(error)), Stream.retry(pipe(Schedule.exponential(Duration.seconds(1), 2), Schedule.map((delay) => {
|
|
64
|
+
const maxDelay = Duration.minutes(2);
|
|
65
|
+
const jitter = Duration.millis(Math.floor(Math.random() * 1000));
|
|
66
|
+
const delayWithJitter = Duration.toMillis(delay) + Duration.toMillis(jitter);
|
|
67
|
+
return Duration.millis(Math.min(delayWithJitter, Duration.toMillis(maxDelay)));
|
|
68
|
+
}))));
|
|
69
|
+
}
|
|
70
|
+
balanceTransaction(tx) {
|
|
71
|
+
return SubscriptionRef.modifyEffect(this.#context.stateRef, (state) => {
|
|
72
|
+
return pipe(this.#v1Context.transactingCapability.balanceTransaction(state, tx), EitherOps.toEffect, Effect.map(({ transaction, newState }) => [transaction, newState]));
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
transferTransaction(outputs, ttl) {
|
|
76
|
+
return SubscriptionRef.modifyEffect(this.#context.stateRef, (state) => {
|
|
77
|
+
return pipe(this.#v1Context.transactingCapability.makeTransfer(state, outputs, ttl), EitherOps.toEffect, Effect.flatMap(({ transaction, newState }) => pipe(this.#v1Context.transactingCapability.balanceTransaction(newState, transaction), EitherOps.toEffect, Effect.map(({ transaction, newState }) => [transaction, newState]))));
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
initSwap(desiredInputs, desiredOutputs, ttl) {
|
|
81
|
+
return SubscriptionRef.modifyEffect(this.#context.stateRef, (state) => {
|
|
82
|
+
return pipe(this.#v1Context.transactingCapability.initSwap(state, desiredInputs, desiredOutputs, ttl), Effect.map(({ transaction, newState }) => [transaction, newState]));
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
signTransaction(transaction, signSegment) {
|
|
86
|
+
return this.#v1Context.transactingCapability.signTransaction(transaction, signSegment);
|
|
87
|
+
}
|
|
88
|
+
serializeState(state) {
|
|
89
|
+
return this.#v1Context.serializationCapability.serialize(state);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Either } from 'effect';
|
|
2
|
+
import { WalletError } from './WalletError.js';
|
|
3
|
+
import { CoreWallet } from './CoreWallet.js';
|
|
4
|
+
import { NetworkId } from '@midnight-ntwrk/wallet-sdk-abstractions';
|
|
5
|
+
export type SerializationCapability<TWallet, TSerialized> = {
|
|
6
|
+
serialize(wallet: TWallet): TSerialized;
|
|
7
|
+
deserialize(data: TSerialized): Either.Either<TWallet, WalletError>;
|
|
8
|
+
};
|
|
9
|
+
export type DefaultSerializationConfiguration = {
|
|
10
|
+
networkId: NetworkId.NetworkId;
|
|
11
|
+
};
|
|
12
|
+
export declare const makeDefaultV1SerializationCapability: () => SerializationCapability<CoreWallet, string>;
|