@midnight-ntwrk/wallet-sdk-unshielded-wallet 1.0.0-beta.12 → 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.
Files changed (59) hide show
  1. package/dist/KeyStore.d.ts +3 -7
  2. package/dist/KeyStore.js +2 -2
  3. package/dist/UnshieldedWallet.d.ts +57 -0
  4. package/dist/UnshieldedWallet.js +120 -0
  5. package/dist/index.d.ts +3 -3
  6. package/dist/index.js +3 -2
  7. package/dist/{tx-history-storage → storage}/InMemoryTransactionHistoryStorage.d.ts +3 -7
  8. package/dist/{tx-history-storage → storage}/TransactionHistoryStorage.d.ts +3 -7
  9. package/dist/{tx-history-storage → storage}/TransactionHistoryStorage.js +3 -7
  10. package/dist/{tx-history-storage → storage}/index.d.ts +1 -0
  11. package/dist/{tx-history-storage → storage}/index.js +1 -0
  12. package/dist/v1/CoinsAndBalances.d.ts +13 -0
  13. package/dist/v1/CoinsAndBalances.js +36 -0
  14. package/dist/v1/CoreWallet.d.ts +24 -0
  15. package/dist/v1/CoreWallet.js +60 -0
  16. package/dist/v1/Keys.d.ts +8 -0
  17. package/dist/v1/Keys.js +23 -0
  18. package/dist/v1/RunningV1Variant.d.ts +41 -0
  19. package/dist/v1/RunningV1Variant.js +91 -0
  20. package/dist/v1/Serialization.d.ts +12 -0
  21. package/dist/v1/Serialization.js +64 -0
  22. package/dist/v1/Simulator.d.ts +22 -0
  23. package/dist/v1/Simulator.js +102 -0
  24. package/dist/v1/Sync.d.ts +32 -0
  25. package/dist/v1/Sync.js +85 -0
  26. package/dist/v1/SyncProgress.d.ts +18 -0
  27. package/dist/v1/SyncProgress.js +23 -0
  28. package/dist/v1/SyncSchema.d.ts +449 -0
  29. package/dist/v1/SyncSchema.js +123 -0
  30. package/dist/v1/Transacting.d.ts +45 -0
  31. package/dist/v1/Transacting.js +252 -0
  32. package/dist/v1/Transaction.d.ts +25 -0
  33. package/dist/v1/Transaction.js +155 -0
  34. package/dist/v1/TransactionHistory.d.ts +12 -0
  35. package/dist/v1/TransactionHistory.js +29 -0
  36. package/dist/v1/TransactionImbalances.d.ts +8 -0
  37. package/dist/v1/TransactionImbalances.js +21 -0
  38. package/dist/v1/UnshieldedState.d.ts +37 -0
  39. package/dist/v1/UnshieldedState.js +67 -0
  40. package/dist/v1/V1Builder.d.ts +97 -0
  41. package/dist/v1/V1Builder.js +160 -0
  42. package/dist/v1/WalletError.d.ts +89 -0
  43. package/dist/v1/WalletError.js +53 -0
  44. package/dist/v1/index.d.ts +15 -0
  45. package/dist/v1/index.js +27 -0
  46. package/package.json +8 -8
  47. package/dist/State.d.ts +0 -21
  48. package/dist/State.js +0 -43
  49. package/dist/SyncService.d.ts +0 -55
  50. package/dist/SyncService.js +0 -88
  51. package/dist/TransactionHistoryService.d.ts +0 -31
  52. package/dist/TransactionHistoryService.js +0 -49
  53. package/dist/TransactionService.d.ts +0 -43
  54. package/dist/TransactionService.js +0 -291
  55. package/dist/WalletBuilder.d.ts +0 -37
  56. package/dist/WalletBuilder.js +0 -137
  57. /package/dist/{tx-history-storage → storage}/InMemoryTransactionHistoryStorage.js +0 -0
  58. /package/dist/{tx-history-storage → storage}/NoOpTransactionHistoryStorage.d.ts +0 -0
  59. /package/dist/{tx-history-storage → storage}/NoOpTransactionHistoryStorage.js +0 -0
@@ -0,0 +1,97 @@
1
+ import * as ledger from '@midnight-ntwrk/ledger-v6';
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 { RunningV1Variant, V1Tag } from './RunningV1Variant.js';
6
+ import { SerializationCapability } from './Serialization.js';
7
+ import { DefaultSyncContext, DefaultSyncConfiguration, SyncCapability, SyncService } from './Sync.js';
8
+ import { WalletSyncUpdate, UnshieldedUpdate } from './SyncSchema.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 { CoinSelection } from '@midnight-ntwrk/wallet-sdk-capabilities';
14
+ import { CoreWallet } from './CoreWallet.js';
15
+ import { DefaultTransactionHistoryConfiguration, TransactionHistoryService } from './TransactionHistory.js';
16
+ export type BaseV1Configuration = {
17
+ networkId: NetworkId.NetworkId;
18
+ };
19
+ export type DefaultV1Configuration = BaseV1Configuration & DefaultSyncConfiguration & DefaultTransactingConfiguration & DefaultTransactionHistoryConfiguration;
20
+ declare const V1BuilderSymbol: {
21
+ readonly typeId: unique symbol;
22
+ };
23
+ export type V1Variant<TSerialized, TSyncUpdate, TTransaction> = Variant.Variant<typeof V1Tag, CoreWallet, null, RunningV1Variant<TSerialized, TSyncUpdate, TTransaction>> & {
24
+ deserializeState: (serialized: TSerialized) => Either.Either<CoreWallet, WalletError>;
25
+ coinsAndBalances: CoinsAndBalancesCapability<CoreWallet>;
26
+ keys: KeysCapability<CoreWallet>;
27
+ serialization: SerializationCapability<CoreWallet, TSerialized>;
28
+ transactionHistory: TransactionHistoryService<UnshieldedUpdate>;
29
+ };
30
+ export type AnyV1Variant = V1Variant<any, any, any>;
31
+ export type DefaultV1Variant = V1Variant<string, WalletSyncUpdate, ledger.Transaction<ledger.SignatureEnabled, ledger.Proofish, ledger.Bindingish>>;
32
+ export type TransactionOf<T extends AnyV1Variant> = T extends V1Variant<any, any, infer TTransaction> ? TTransaction : never;
33
+ export type SerializedStateOf<T extends AnyV1Variant> = T extends V1Variant<infer TSerialized, any, any> ? TSerialized : never;
34
+ export type DefaultV1Builder = V1Builder<DefaultV1Configuration, RunningV1Variant.Context<string, WalletSyncUpdate, ledger.Transaction<ledger.SignatureEnabled, ledger.Proofish, ledger.Bindingish>>, string, WalletSyncUpdate, ledger.Transaction<ledger.SignatureEnabled, ledger.Proofish, ledger.Bindingish>>;
35
+ export declare class V1Builder<TConfig extends BaseV1Configuration = BaseV1Configuration, TContext extends Partial<RunningV1Variant.AnyContext> = object, TSerialized = never, TSyncUpdate = never, TTransaction = never> implements VariantBuilder.VariantBuilder<V1Variant<TSerialized, TSyncUpdate, TTransaction>, TConfig> {
36
+ #private;
37
+ constructor(buildState?: V1Builder.PartialBuildState<TConfig, TContext, TSerialized, TSyncUpdate, TTransaction>);
38
+ withDefaults(): DefaultV1Builder;
39
+ withTransactionType<Transaction>(): V1Builder<TConfig, TContext, TSerialized, TSyncUpdate, Transaction>;
40
+ withDefaultTransactionType(): V1Builder<TConfig, TContext, TSerialized, TSyncUpdate, ledger.Transaction<ledger.SignatureEnabled, ledger.Proofish, ledger.Bindingish>>;
41
+ withSyncDefaults(): V1Builder<TConfig & DefaultSyncConfiguration, TContext & DefaultSyncContext, TSerialized, WalletSyncUpdate, TTransaction>;
42
+ withSync<TSyncConfig, TSyncContext extends Partial<RunningV1Variant.AnyContext>, TSyncUpdate>(syncService: (configuration: TSyncConfig, getContext: () => TSyncContext) => SyncService<CoreWallet, TSyncUpdate>, syncCapability: (configuration: TSyncConfig, getContext: () => TSyncContext) => SyncCapability<CoreWallet, TSyncUpdate>): V1Builder<TConfig & TSyncConfig, TContext & TSyncContext, TSerialized, TSyncUpdate, TTransaction>;
43
+ withSerializationDefaults(): V1Builder<TConfig, TContext, string, TSyncUpdate, TTransaction>;
44
+ withSerialization<TSerializationConfig, TSerializationContext extends Partial<RunningV1Variant.AnyContext>, TSerialized>(serializationCapability: (configuration: TSerializationConfig, getContext: () => TSerializationContext) => SerializationCapability<CoreWallet, TSerialized>): V1Builder<TConfig & TSerializationConfig, TContext & TSerializationContext, TSerialized, TSyncUpdate, TTransaction>;
45
+ withTransactingDefaults(this: V1Builder<TConfig, TContext, TSerialized, TSyncUpdate, ledger.Transaction<ledger.SignatureEnabled, ledger.Proofish, ledger.Bindingish>>): V1Builder<TConfig & DefaultTransactingConfiguration, TContext & DefaultTransactingContext, TSerialized, TSyncUpdate, ledger.Transaction<ledger.SignatureEnabled, ledger.Proofish, ledger.Bindingish>>;
46
+ withTransacting<TTransactingConfig, TTransactingContext extends Partial<RunningV1Variant.AnyContext>>(transactingCapability: (config: TTransactingConfig, getContext: () => TTransactingContext) => TransactingCapability<TTransaction, CoreWallet>): V1Builder<TConfig & TTransactingConfig, TContext & TTransactingContext, TSerialized, TSyncUpdate, TTransaction>;
47
+ withCoinSelection<TCoinSelectionConfig, TCoinSelectionContext extends Partial<RunningV1Variant.AnyContext>>(coinSelection: (config: TCoinSelectionConfig, getContext: () => TCoinSelectionContext) => CoinSelection<ledger.Utxo>): V1Builder<TConfig & TCoinSelectionConfig, TContext & TCoinSelectionContext, TSerialized, TSyncUpdate, TTransaction>;
48
+ withCoinSelectionDefaults(): V1Builder<TConfig, TContext, TSerialized, TSyncUpdate, TTransaction>;
49
+ withCoinsAndBalancesDefaults(): V1Builder<TConfig, TContext, TSerialized, TSyncUpdate, TTransaction>;
50
+ withCoinsAndBalances<TBalancesConfig, TBalancesContext extends Partial<RunningV1Variant.AnyContext>>(coinsAndBalancesCapability: (configuration: TBalancesConfig, getContext: () => TBalancesContext) => CoinsAndBalancesCapability<CoreWallet>): V1Builder<TConfig & TBalancesConfig, TContext & TBalancesContext, TSerialized, TSyncUpdate, TTransaction>;
51
+ withTransactionHistoryDefaults(this: V1Builder<TConfig, TContext, TSerialized, TSyncUpdate, ledger.FinalizedTransaction>): V1Builder<TConfig & DefaultTransactionHistoryConfiguration, TContext, TSerialized, TSyncUpdate, ledger.FinalizedTransaction>;
52
+ withTransactionHistory<TTransactionHistoryConfig, TTransactionHistoryContext extends Partial<RunningV1Variant.AnyContext>>(transactionHistoryService: (configuration: TTransactionHistoryConfig, getContext: () => TTransactionHistoryContext) => TransactionHistoryService<UnshieldedUpdate>): V1Builder<TConfig & TTransactionHistoryConfig, TContext & TTransactionHistoryContext, TSerialized, TSyncUpdate, TTransaction>;
53
+ withKeysDefaults(): V1Builder<TConfig, TContext, TSerialized, TSyncUpdate, TTransaction>;
54
+ withKeys<TKeysConfig, TKeysContext extends Partial<RunningV1Variant.AnyContext>>(keysCapability: (configuration: TKeysConfig, getContext: () => TKeysContext) => KeysCapability<CoreWallet>): V1Builder<TConfig & TKeysConfig, TContext & TKeysContext, TSerialized, TSyncUpdate, TTransaction>;
55
+ build(this: V1Builder<TConfig, RunningV1Variant.Context<TSerialized, TSyncUpdate, TTransaction>, TSerialized, TSyncUpdate, TTransaction>, configuration: TConfig): V1Variant<TSerialized, TSyncUpdate, TTransaction>;
56
+ }
57
+ /** @internal */
58
+ declare namespace V1Builder {
59
+ type HasSync<TConfig, TContext, TSyncUpdate> = {
60
+ readonly syncService: (configuration: TConfig, getContext: () => TContext) => SyncService<CoreWallet, TSyncUpdate>;
61
+ readonly syncCapability: (configuration: TConfig, getContext: () => TContext) => SyncCapability<CoreWallet, TSyncUpdate>;
62
+ };
63
+ type HasTransacting<TConfig, TContext, TTransaction> = {
64
+ readonly transactingCapability: (configuration: TConfig, getContext: () => TContext) => TransactingCapability<TTransaction, CoreWallet>;
65
+ };
66
+ type HasCoinSelection<TConfig, TContext> = {
67
+ readonly coinSelection: (configuration: TConfig, getContext: () => TContext) => CoinSelection<ledger.Utxo>;
68
+ };
69
+ type HasSerialization<TConfig, TContext, TSerialized> = {
70
+ readonly serializationCapability: (configuration: TConfig, getContext: () => TContext) => SerializationCapability<CoreWallet, TSerialized>;
71
+ };
72
+ type HasCoinsAndBalances<TConfig, TContext> = {
73
+ readonly coinsAndBalancesCapability: (configuration: TConfig, getContext: () => TContext) => CoinsAndBalancesCapability<CoreWallet>;
74
+ };
75
+ type HasTransactionHistory<TConfig, TContext> = {
76
+ readonly transactionHistoryService: (configuration: TConfig, getContext: () => TContext) => TransactionHistoryService<UnshieldedUpdate>;
77
+ };
78
+ type HasKeys<TConfig, TContext> = {
79
+ readonly keysCapability: (configuration: TConfig, getContext: () => TContext) => KeysCapability<CoreWallet>;
80
+ };
81
+ /**
82
+ * The internal build state of {@link V1Builder}.
83
+ */
84
+ type FullBuildState<TConfig, TContext, TSerialized, TSyncUpdate, TTransaction> = Types.Simplify<HasSync<TConfig, TContext, TSyncUpdate> & HasSerialization<TConfig, TContext, TSerialized> & HasTransacting<TConfig, TContext, TTransaction> & HasCoinSelection<TConfig, TContext> & HasCoinsAndBalances<TConfig, TContext> & HasKeys<TConfig, TContext> & HasTransactionHistory<TConfig, TContext>>;
85
+ type PartialBuildState<TConfig = object, TContext = object, TSerialized = never, TSyncUpdate = never, TTransaction = never> = {
86
+ [K in keyof FullBuildState<never, never, never, never, never>]?: FullBuildState<TConfig, TContext, TSerialized, TSyncUpdate, TTransaction>[K] | undefined;
87
+ };
88
+ /**
89
+ * Utility interface that manages the type variance of {@link V1Builder}.
90
+ */
91
+ interface Variance<R> {
92
+ readonly [V1BuilderSymbol.typeId]: {
93
+ readonly _R: Types.Covariant<R>;
94
+ };
95
+ }
96
+ }
97
+ export {};
@@ -0,0 +1,160 @@
1
+ import { Effect, Scope } from 'effect';
2
+ import { WalletSeed } from '@midnight-ntwrk/wallet-sdk-abstractions';
3
+ import { RunningV1Variant, V1Tag } from './RunningV1Variant.js';
4
+ import { makeDefaultV1SerializationCapability } from './Serialization.js';
5
+ import { makeDefaultSyncService, makeDefaultSyncCapability, } from './Sync.js';
6
+ import { makeDefaultTransactingCapability, } from './Transacting.js';
7
+ import { makeDefaultCoinsAndBalancesCapability } from './CoinsAndBalances.js';
8
+ import { makeDefaultKeysCapability } from './Keys.js';
9
+ import { chooseCoin } from '@midnight-ntwrk/wallet-sdk-capabilities';
10
+ import { CoreWallet } from './CoreWallet.js';
11
+ import { makeDefaultTransactionHistoryService, } from './TransactionHistory.js';
12
+ import { createKeystore, PublicKey } from '../KeyStore.js';
13
+ const V1BuilderSymbol = {
14
+ typeId: Symbol('@midnight-ntwrk/unshielded-wallet#V1Builder'),
15
+ };
16
+ export class V1Builder {
17
+ #buildState;
18
+ constructor(buildState = {}) {
19
+ this.#buildState = buildState;
20
+ }
21
+ withDefaults() {
22
+ return this.withDefaultTransactionType()
23
+ .withSyncDefaults()
24
+ .withSerializationDefaults()
25
+ .withTransactingDefaults()
26
+ .withCoinsAndBalancesDefaults()
27
+ .withTransactionHistoryDefaults()
28
+ .withKeysDefaults()
29
+ .withCoinSelectionDefaults();
30
+ }
31
+ withTransactionType() {
32
+ return new V1Builder({
33
+ ...this.#buildState,
34
+ transactingCapability: undefined,
35
+ transactionHistoryService: undefined,
36
+ });
37
+ }
38
+ withDefaultTransactionType() {
39
+ return this.withTransactionType();
40
+ }
41
+ withSyncDefaults() {
42
+ return this.withSync(makeDefaultSyncService, makeDefaultSyncCapability);
43
+ }
44
+ withSync(syncService, syncCapability) {
45
+ return new V1Builder({
46
+ ...this.#buildState,
47
+ syncService,
48
+ syncCapability,
49
+ });
50
+ }
51
+ withSerializationDefaults() {
52
+ return this.withSerialization(makeDefaultV1SerializationCapability);
53
+ }
54
+ withSerialization(serializationCapability) {
55
+ return new V1Builder({
56
+ ...this.#buildState,
57
+ serializationCapability,
58
+ });
59
+ }
60
+ withTransactingDefaults() {
61
+ return this.withTransacting(makeDefaultTransactingCapability);
62
+ }
63
+ withTransacting(transactingCapability) {
64
+ return new V1Builder({
65
+ ...this.#buildState,
66
+ transactingCapability,
67
+ });
68
+ }
69
+ withCoinSelection(coinSelection) {
70
+ return new V1Builder({
71
+ ...this.#buildState,
72
+ coinSelection,
73
+ });
74
+ }
75
+ withCoinSelectionDefaults() {
76
+ return this.withCoinSelection(() => chooseCoin);
77
+ }
78
+ withCoinsAndBalancesDefaults() {
79
+ return this.withCoinsAndBalances(makeDefaultCoinsAndBalancesCapability);
80
+ }
81
+ withCoinsAndBalances(coinsAndBalancesCapability) {
82
+ return new V1Builder({
83
+ ...this.#buildState,
84
+ coinsAndBalancesCapability,
85
+ });
86
+ }
87
+ withTransactionHistoryDefaults() {
88
+ return this.withTransactionHistory(makeDefaultTransactionHistoryService);
89
+ }
90
+ withTransactionHistory(transactionHistoryService) {
91
+ return new V1Builder({
92
+ ...this.#buildState,
93
+ transactionHistoryService,
94
+ });
95
+ }
96
+ withKeysDefaults() {
97
+ return this.withKeys(makeDefaultKeysCapability);
98
+ }
99
+ withKeys(keysCapability) {
100
+ return new V1Builder({
101
+ ...this.#buildState,
102
+ keysCapability,
103
+ });
104
+ }
105
+ build(configuration) {
106
+ const v1Context = this.#buildContextFromBuildState(configuration);
107
+ const { networkId } = configuration;
108
+ return {
109
+ __polyTag__: V1Tag,
110
+ coinsAndBalances: v1Context.coinsAndBalancesCapability,
111
+ keys: v1Context.keysCapability,
112
+ serialization: v1Context.serializationCapability,
113
+ transactionHistory: v1Context.transactionHistoryService,
114
+ start(context) {
115
+ return Effect.gen(function* () {
116
+ const scope = yield* Scope.Scope;
117
+ return new RunningV1Variant(scope, context, v1Context);
118
+ });
119
+ },
120
+ migrateState(_previousState) {
121
+ const seed = WalletSeed.fromString('0000000000000000000000000000000000000000000000000000000000000001');
122
+ return Effect.succeed(CoreWallet.init(PublicKey.fromKeyStore(createKeystore(seed, networkId)), networkId));
123
+ },
124
+ deserializeState: (serialized) => {
125
+ return v1Context.serializationCapability.deserialize(serialized);
126
+ },
127
+ };
128
+ }
129
+ #buildContextFromBuildState(configuration) {
130
+ if (!isBuildStateFull(this.#buildState)) {
131
+ throw new Error('Not all components are configured in V1 Builder');
132
+ }
133
+ const { syncCapability, syncService, transactingCapability, serializationCapability, coinSelection, coinsAndBalancesCapability, keysCapability, transactionHistoryService, } = this.#buildState;
134
+ const getContext = () => context;
135
+ const context = {
136
+ serializationCapability: serializationCapability(configuration, getContext),
137
+ syncCapability: syncCapability(configuration, getContext),
138
+ syncService: syncService(configuration, getContext),
139
+ transactingCapability: transactingCapability(configuration, getContext),
140
+ coinsAndBalancesCapability: coinsAndBalancesCapability(configuration, getContext),
141
+ keysCapability: keysCapability(configuration, getContext),
142
+ coinSelection: coinSelection(configuration, getContext),
143
+ transactionHistoryService: transactionHistoryService(configuration, getContext),
144
+ };
145
+ return context;
146
+ }
147
+ }
148
+ const isBuildStateFull = (buildState) => {
149
+ const allBuildStateKeys = [
150
+ 'syncService',
151
+ 'syncCapability',
152
+ 'transactingCapability',
153
+ 'coinSelection',
154
+ 'serializationCapability',
155
+ 'coinsAndBalancesCapability',
156
+ 'keysCapability',
157
+ 'transactionHistoryService',
158
+ ];
159
+ return allBuildStateKeys.every((key) => typeof buildState[key] == 'function');
160
+ };
@@ -0,0 +1,89 @@
1
+ import * as ledger from '@midnight-ntwrk/ledger-v6';
2
+ export declare const WalletError: {
3
+ other(err: unknown): WalletError;
4
+ };
5
+ export type WalletError = OtherWalletError | InsufficientFundsError | AddressError | SyncWalletError | TransactingError | SignError | ApplyTransactionError | RollbackUtxoError | SpendUtxoError;
6
+ declare const OtherWalletError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
7
+ readonly _tag: "Wallet.Other";
8
+ } & Readonly<A>;
9
+ export declare class OtherWalletError extends OtherWalletError_base<{
10
+ message: string;
11
+ cause?: unknown;
12
+ }> {
13
+ }
14
+ declare const SyncWalletError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
15
+ readonly _tag: "Wallet.Sync";
16
+ } & Readonly<A>;
17
+ export declare class SyncWalletError extends SyncWalletError_base<{
18
+ message: string;
19
+ cause?: unknown;
20
+ }> {
21
+ }
22
+ declare const InsufficientFundsError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
23
+ readonly _tag: "Wallet.InsufficientFunds";
24
+ } & Readonly<A>;
25
+ export declare class InsufficientFundsError extends InsufficientFundsError_base<{
26
+ message: string;
27
+ tokenType: ledger.RawTokenType;
28
+ amount: bigint;
29
+ }> {
30
+ }
31
+ declare const AddressError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
32
+ readonly _tag: "Wallet.Address";
33
+ } & Readonly<A>;
34
+ export declare class AddressError extends AddressError_base<{
35
+ message: string;
36
+ originalAddress: string;
37
+ cause?: unknown;
38
+ }> {
39
+ }
40
+ declare const TransactingError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
41
+ readonly _tag: "Wallet.Transacting";
42
+ } & Readonly<A>;
43
+ export declare class TransactingError extends TransactingError_base<{
44
+ message: string;
45
+ cause?: unknown;
46
+ }> {
47
+ }
48
+ declare const SignError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
49
+ readonly _tag: "Wallet.Sign";
50
+ } & Readonly<A>;
51
+ export declare class SignError extends SignError_base<{
52
+ message: string;
53
+ cause?: unknown;
54
+ }> {
55
+ }
56
+ declare const ApplyTransactionError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
57
+ readonly _tag: "Wallet.ApplyTransaction";
58
+ } & Readonly<A>;
59
+ export declare class ApplyTransactionError extends ApplyTransactionError_base<{
60
+ message: string;
61
+ cause?: unknown;
62
+ }> {
63
+ }
64
+ declare const RollbackUtxoError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
65
+ readonly _tag: "Wallet.RollbackUtxo";
66
+ } & Readonly<A>;
67
+ export declare class RollbackUtxoError extends RollbackUtxoError_base<{
68
+ message: string;
69
+ utxo: ledger.Utxo;
70
+ cause?: unknown;
71
+ }> {
72
+ }
73
+ declare const SpendUtxoError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
74
+ readonly _tag: "Wallet.SpendUtxo";
75
+ } & Readonly<A>;
76
+ export declare class SpendUtxoError extends SpendUtxoError_base<{
77
+ message: string;
78
+ utxo: ledger.Utxo;
79
+ cause?: unknown;
80
+ }> {
81
+ }
82
+ declare const UtxoNotFoundError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
83
+ readonly _tag: "UtxoNotFoundError";
84
+ } & Readonly<A>;
85
+ export declare class UtxoNotFoundError extends UtxoNotFoundError_base<{
86
+ readonly utxo: ledger.Utxo;
87
+ }> {
88
+ }
89
+ export {};
@@ -0,0 +1,53 @@
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 { Data } from 'effect';
14
+ export const WalletError = {
15
+ other(err) {
16
+ let message;
17
+ if (err) {
18
+ if (typeof err == 'object' && 'message' in err) {
19
+ message = String(err.message);
20
+ }
21
+ else if (typeof err == 'string') {
22
+ message = err;
23
+ }
24
+ else {
25
+ message = '';
26
+ }
27
+ }
28
+ else {
29
+ message = '';
30
+ }
31
+ return new OtherWalletError({ message: `Other wallet error: ${message}`, cause: err });
32
+ },
33
+ };
34
+ export class OtherWalletError extends Data.TaggedError('Wallet.Other') {
35
+ }
36
+ export class SyncWalletError extends Data.TaggedError('Wallet.Sync') {
37
+ }
38
+ export class InsufficientFundsError extends Data.TaggedError('Wallet.InsufficientFunds') {
39
+ }
40
+ export class AddressError extends Data.TaggedError('Wallet.Address') {
41
+ }
42
+ export class TransactingError extends Data.TaggedError('Wallet.Transacting') {
43
+ }
44
+ export class SignError extends Data.TaggedError('Wallet.Sign') {
45
+ }
46
+ export class ApplyTransactionError extends Data.TaggedError('Wallet.ApplyTransaction') {
47
+ }
48
+ export class RollbackUtxoError extends Data.TaggedError('Wallet.RollbackUtxo') {
49
+ }
50
+ export class SpendUtxoError extends Data.TaggedError('Wallet.SpendUtxo') {
51
+ }
52
+ export class UtxoNotFoundError extends Data.TaggedError('UtxoNotFoundError') {
53
+ }
@@ -0,0 +1,15 @@
1
+ export * from './V1Builder.js';
2
+ export * as Sync from './Sync.js';
3
+ export * as SyncProgress from './SyncProgress.js';
4
+ export * as Transacting from './Transacting.js';
5
+ export * as TransactionHistory from './TransactionHistory.js';
6
+ export * as Serialization from './Serialization.js';
7
+ export * as CoinsAndBalances from './CoinsAndBalances.js';
8
+ export * as Keys from './Keys.js';
9
+ export * from './RunningV1Variant.js';
10
+ export * as Simulator from './Simulator.js';
11
+ export * as WalletError from './WalletError.js';
12
+ export * from './CoreWallet.js';
13
+ export * from './Transaction.js';
14
+ export * as TransactionHistoryStorage from '../storage/index.js';
15
+ export * as UnshieldedState from './UnshieldedState.js';
@@ -0,0 +1,27 @@
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
+ export * from './V1Builder.js';
14
+ export * as Sync from './Sync.js';
15
+ export * as SyncProgress from './SyncProgress.js';
16
+ export * as Transacting from './Transacting.js';
17
+ export * as TransactionHistory from './TransactionHistory.js';
18
+ export * as Serialization from './Serialization.js';
19
+ export * as CoinsAndBalances from './CoinsAndBalances.js';
20
+ export * as Keys from './Keys.js';
21
+ export * from './RunningV1Variant.js';
22
+ export * as Simulator from './Simulator.js';
23
+ export * as WalletError from './WalletError.js';
24
+ export * from './CoreWallet.js';
25
+ export * from './Transaction.js';
26
+ export * as TransactionHistoryStorage from '../storage/index.js';
27
+ export * as UnshieldedState from './UnshieldedState.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midnight-ntwrk/wallet-sdk-unshielded-wallet",
3
- "version": "1.0.0-beta.12",
3
+ "version": "1.0.0-beta.14",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -23,13 +23,13 @@
23
23
  }
24
24
  },
25
25
  "dependencies": {
26
- "@midnight-ntwrk/ledger-v6": "6.1.0-alpha.5",
26
+ "@midnight-ntwrk/ledger-v6": "6.1.0-alpha.6",
27
27
  "@midnight-ntwrk/wallet-sdk-abstractions": "1.0.0-beta.9",
28
- "@midnight-ntwrk/wallet-sdk-address-format": "3.0.0-beta.8",
29
- "@midnight-ntwrk/wallet-sdk-capabilities": "3.0.0-beta.8",
28
+ "@midnight-ntwrk/wallet-sdk-address-format": "3.0.0-beta.9",
29
+ "@midnight-ntwrk/wallet-sdk-capabilities": "3.0.0-beta.9",
30
30
  "@midnight-ntwrk/wallet-sdk-hd": "3.0.0-beta.7",
31
- "@midnight-ntwrk/wallet-sdk-indexer-client": "1.0.0-beta.12",
32
- "@midnight-ntwrk/wallet-sdk-unshielded-state": "1.0.0-beta.10",
31
+ "@midnight-ntwrk/wallet-sdk-indexer-client": "1.0.0-beta.13",
32
+ "@midnight-ntwrk/wallet-sdk-unshielded-state": "1.0.0-beta.11",
33
33
  "@midnight-ntwrk/wallet-sdk-utilities": "1.0.0-beta.7",
34
34
  "effect": "^3.17.3",
35
35
  "rxjs": "^7.5"
@@ -38,8 +38,8 @@
38
38
  "typecheck": "tsc -b ./tsconfig.json --noEmit",
39
39
  "test": "vitest run",
40
40
  "lint": "eslint --max-warnings 0",
41
- "format": "prettier --write \"**/*.{ts,js,json,yaml,yml}\"",
42
- "format:check": "prettier --check \"**/*.{ts,js,json,yaml,yml}\"",
41
+ "format": "prettier --write \"**/*.{ts,js,json,yaml,yml,md}\"",
42
+ "format:check": "prettier --check \"**/*.{ts,js,json,yaml,yml,md}\"",
43
43
  "dist": "tsc -b ./tsconfig.build.json",
44
44
  "dist:publish": "tsc -b ./tsconfig.publish.json",
45
45
  "clean": "rimraf --glob dist 'tsconfig.*.tsbuildinfo' && date +%s > .clean-timestamp",
package/dist/State.d.ts DELETED
@@ -1,21 +0,0 @@
1
- import { Effect, Stream } from 'effect';
2
- import { UnshieldedStateAPI, Utxo } from '@midnight-ntwrk/wallet-sdk-unshielded-state';
3
- import { ParseError } from 'effect/ParseResult';
4
- export interface State {
5
- address: string;
6
- balances: Map<string, bigint>;
7
- pendingCoins: readonly Utxo[];
8
- availableCoins: readonly Utxo[];
9
- totalCoins: readonly Utxo[];
10
- syncProgress: {
11
- applyGap: number;
12
- synced: boolean;
13
- } | undefined;
14
- }
15
- export declare class StateImpl {
16
- unshieldedState: UnshieldedStateAPI;
17
- address: string;
18
- constructor(unshieldedState: UnshieldedStateAPI, address: string);
19
- updates(): Stream.Stream<State>;
20
- serialize(): Effect.Effect<string, ParseError>;
21
- }
package/dist/State.js DELETED
@@ -1,43 +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 { Effect, HashSet, pipe, Stream } from 'effect';
14
- import { UnshieldedStateEncoder } from '@midnight-ntwrk/wallet-sdk-unshielded-state';
15
- export class StateImpl {
16
- unshieldedState;
17
- address;
18
- constructor(unshieldedState, address) {
19
- this.unshieldedState = unshieldedState;
20
- this.address = address;
21
- }
22
- updates() {
23
- return this.unshieldedState.state.pipe(Stream.map((state) => ({
24
- address: this.address,
25
- balances: HashSet.reduce(state.utxos, new Map(), (acc, utxo) => {
26
- acc.set(utxo.type, (acc.get(utxo.type) || 0n) + utxo.value);
27
- return acc;
28
- }),
29
- pendingCoins: HashSet.toValues(state.pendingUtxos),
30
- availableCoins: HashSet.toValues(state.utxos),
31
- totalCoins: HashSet.toValues(HashSet.union(state.utxos, state.pendingUtxos)),
32
- syncProgress: state.syncProgress
33
- ? {
34
- applyGap: (state.syncProgress?.highestTransactionId ?? 0) - (state.syncProgress?.currentTransactionId ?? 0),
35
- synced: state.syncProgress?.highestTransactionId === state.syncProgress?.currentTransactionId,
36
- }
37
- : undefined,
38
- })));
39
- }
40
- serialize() {
41
- return pipe(this.unshieldedState.getLatestState(), Effect.flatMap((state) => UnshieldedStateEncoder(state)), Effect.map((encoded) => JSON.stringify(encoded)));
42
- }
43
- }
@@ -1,55 +0,0 @@
1
- import { Layer, Context, Stream, Schema, Scope } from 'effect';
2
- export declare const UnshieldedUpdateSchema: Schema.Union<[Schema.Struct<{
3
- type: Schema.Literal<["UnshieldedTransaction"]>;
4
- transaction: Schema.Data<Schema.Struct<{
5
- id: typeof Schema.Number;
6
- hash: typeof Schema.String;
7
- type: Schema.Literal<["RegularTransaction", "SystemTransaction"]>;
8
- protocolVersion: typeof Schema.Number;
9
- identifiers: Schema.Array$<typeof Schema.String>;
10
- transactionResult: Schema.NullOr<Schema.Struct<{
11
- status: typeof Schema.String;
12
- segments: Schema.NullOr<Schema.Array$<Schema.Struct<{
13
- id: typeof Schema.String;
14
- success: typeof Schema.Boolean;
15
- }>>>;
16
- }>>;
17
- createdUtxos: Schema.Array$<Schema.Data<Schema.Struct<{
18
- value: Schema.Schema<bigint, string, never>;
19
- owner: typeof Schema.String;
20
- type: typeof Schema.String;
21
- intentHash: typeof Schema.String;
22
- outputNo: typeof Schema.Number;
23
- ctime: typeof Schema.Number;
24
- registeredForDustGeneration: typeof Schema.Boolean;
25
- }>>>;
26
- spentUtxos: Schema.Array$<Schema.Data<Schema.Struct<{
27
- value: Schema.Schema<bigint, string, never>;
28
- owner: typeof Schema.String;
29
- type: typeof Schema.String;
30
- intentHash: typeof Schema.String;
31
- outputNo: typeof Schema.Number;
32
- ctime: typeof Schema.Number;
33
- registeredForDustGeneration: typeof Schema.Boolean;
34
- }>>>;
35
- }>>;
36
- }>, Schema.Struct<{
37
- type: Schema.Literal<["UnshieldedTransactionsProgress"]>;
38
- highestTransactionId: typeof Schema.Number;
39
- }>]>;
40
- export type UnshieldedUpdate = Schema.Schema.Type<typeof UnshieldedUpdateSchema>;
41
- declare const SyncServiceError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
42
- readonly _tag: "SyncServiceError";
43
- } & Readonly<A>;
44
- export declare class SyncServiceError extends SyncServiceError_base<{
45
- readonly error?: unknown;
46
- }> {
47
- }
48
- export interface SyncServiceLive {
49
- readonly startSync: (address: string, transactionId: number) => Stream.Stream<UnshieldedUpdate, SyncServiceError, Scope.Scope>;
50
- }
51
- declare const SyncService_base: Context.TagClass<SyncService, "@midnight-ntwrk/wallet-sdk-unshielded-wallet/SyncService", SyncServiceLive>;
52
- export declare class SyncService extends SyncService_base {
53
- static readonly LiveWithIndexer: (indexerUrl: string) => Layer.Layer<SyncService>;
54
- }
55
- export {};