@tetherto/wdk-wallet 1.0.0-beta.20 → 1.0.0-beta.22

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.
@@ -1,31 +1,30 @@
1
1
  /**
2
2
  * @interface
3
+ * @extends {IWalletAccountReadOnly}
4
+ * @extends {IDisposable}
3
5
  * @template [TSignedTransaction=unknown]
4
6
  */
5
- export interface IWalletAccount<TSignedTransaction = unknown> extends IWalletAccountReadOnly {
7
+ export interface IWalletAccount<TSignedTransaction = unknown> extends IWalletAccountReadOnly, IDisposable {
6
8
  /**
7
- * The derivation path's index of this account.
9
+ * The derivation path of this account (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)),
10
+ * or null if the account's signer is not bound to a BIP-44 position (e.g. private-key signers).
8
11
  *
9
- * @type {number}
12
+ * @type {string | null}
10
13
  */
11
- get index(): number;
14
+ get path(): string | null;
12
15
  /**
13
- * The derivation path of this account (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)).
16
+ * The account's key pair, or null if the account's signer does not allow
17
+ * retrieving key material (e.g. hardware signers).
14
18
  *
15
- * @type {string}
19
+ * @type {KeyPair | null}
16
20
  */
17
- get path(): string;
18
- /**
19
- * The account's key pair.
20
- *
21
- * @type {KeyPair}
22
- */
23
- get keyPair(): KeyPair;
21
+ get keyPair(): KeyPair | null;
24
22
  /**
25
23
  * Signs a message.
26
24
  *
27
25
  * @param {string} message - The message to sign.
28
26
  * @returns {Promise<string>} The message's signature.
27
+ * @throws {DisposalError} If the account has been disposed.
29
28
  */
30
29
  sign(message: string): Promise<string>;
31
30
  /**
@@ -34,6 +33,7 @@ export interface IWalletAccount<TSignedTransaction = unknown> extends IWalletAcc
34
33
  * @param {Transaction} tx - The transaction to sign.
35
34
  * @returns {Promise<TSignedTransaction>} The signed transaction.
36
35
  * @throws {ValueError} If the transaction is not valid.
36
+ * @throws {DisposalError} If the account has been disposed.
37
37
  */
38
38
  signTransaction(tx: Transaction): Promise<TSignedTransaction>;
39
39
  /**
@@ -54,6 +54,7 @@ export interface IWalletAccount<TSignedTransaction = unknown> extends IWalletAcc
54
54
  * @throws {ProviderError} If the provider fails to perform the transaction.
55
55
  * @throws {TransactionError} If the transaction fails with an error.
56
56
  * @throws {MaximumFeeExceededError} If the the costs of the transaction exceeds the transaction max. fee option.
57
+ * @throws {DisposalError} If the account has been disposed.
57
58
  */
58
59
  sendTransaction(tx: Transaction | TSignedTransaction): Promise<TransactionResult>;
59
60
  /**
@@ -78,6 +79,7 @@ export interface IWalletAccount<TSignedTransaction = unknown> extends IWalletAcc
78
79
  * @throws {ProviderError} If the provider fails to perform the transfer.
79
80
  * @throws {TransferError} If the transfer fails with an error.
80
81
  * @throws {MaximumFeeExceededError} If the the costs of the transfer exceeds the transfer max. fee option.
82
+ * @throws {DisposalError} If the account has been disposed.
81
83
  */
82
84
  transfer(options: TransferOptions): Promise<TransferResult>;
83
85
  /**
@@ -86,15 +88,12 @@ export interface IWalletAccount<TSignedTransaction = unknown> extends IWalletAcc
86
88
  * @returns {Promise<IWalletAccountReadOnly>} The read-only account.
87
89
  */
88
90
  toReadOnlyAccount(): Promise<IWalletAccountReadOnly>;
89
- /**
90
- * Disposes the wallet account, erasing the private key from the memory.
91
- */
92
- dispose(): void;
93
91
  }
94
92
  export type Transaction = import("./wallet-account-read-only.js").Transaction;
95
93
  export type TransactionResult = import("./wallet-account-read-only.js").TransactionResult;
96
94
  export type TransferOptions = import("./wallet-account-read-only.js").TransferOptions;
97
95
  export type TransferResult = import("./wallet-account-read-only.js").TransferResult;
96
+ export type DisposalError = import("./errors.js").DisposalError;
98
97
  export type InvalidTokenError = import("./errors.js").InvalidTokenError;
99
98
  export type MaximumFeeExceededError = import("./errors.js").MaximumFeeExceededError;
100
99
  export type ProviderError = import("./errors.js").ProviderError;
@@ -113,3 +112,4 @@ export type KeyPair = {
113
112
  privateKey: Uint8Array | null;
114
113
  };
115
114
  import { IWalletAccountReadOnly } from './wallet-account-read-only.js';
115
+ export type IDisposable = import("./disposable.js").IDisposable;
@@ -1,5 +1,9 @@
1
- /** @abstract */
2
- export default abstract class WalletManager {
1
+ /**
2
+ * @abstract
3
+ * @template {ISigner} [TSigner=ISigner]
4
+ * @implements {IDisposable}
5
+ */
6
+ export default abstract class WalletManager<TSigner extends ISigner = ISigner> implements IDisposable {
3
7
  /**
4
8
  * Returns a random [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) seed phrase.
5
9
  *
@@ -27,27 +31,27 @@ export default abstract class WalletManager {
27
31
  * Creates a new wallet manager from a default signer.
28
32
  *
29
33
  * @overload
30
- * @param {ISigner} signer - The default signer.
34
+ * @param {TSigner} signer - The default signer.
31
35
  * @param {WalletConfig} [config] - The wallet configuration.
32
36
  * @throws {InvalidSignerError} If the given signer doesn't support account derivation.
33
37
  */
34
- constructor(signer: ISigner, config?: WalletConfig);
38
+ constructor(signer: TSigner, config?: WalletConfig);
35
39
  /** @private */
36
40
  private _seed;
37
41
  /**
38
42
  * The default signer.
39
43
  *
40
44
  * @protected
41
- * @type {ISigner | undefined}
45
+ * @type {TSigner | undefined}
42
46
  */
43
- protected _defaultSigner: ISigner | undefined;
47
+ protected _defaultSigner: TSigner | undefined;
44
48
  /**
45
49
  * A map between signer names and signers added via {@link addSigner}.
46
50
  *
47
51
  * @protected
48
- * @type {Record<string, ISigner>}
52
+ * @type {Record<string, TSigner>}
49
53
  */
50
- protected _signers: Record<string, ISigner>;
54
+ protected _signers: Record<string, TSigner>;
51
55
  /**
52
56
  * A map between derivation paths and wallet accounts. The {@link dispose} method will automatically dispose
53
57
  * all the accounts in this map, so developers are encouraged to map all accounts accessed through the
@@ -64,6 +68,14 @@ export default abstract class WalletManager {
64
68
  * @type {WalletConfig}
65
69
  */
66
70
  protected _config: WalletConfig;
71
+ /** @private */
72
+ private _disposed;
73
+ /**
74
+ * True if the wallet manager has been disposed.
75
+ *
76
+ * @type {boolean}
77
+ */
78
+ get disposed(): boolean;
67
79
  /**
68
80
  * The seed of the wallet.
69
81
  *
@@ -74,27 +86,28 @@ export default abstract class WalletManager {
74
86
  * Registers a signer with the given name.
75
87
  *
76
88
  * @param {string} signerName - The signer name.
77
- * @param {ISigner} signer - The signer.
78
- * @returns {WalletManager} The wallet manager.
89
+ * @param {TSigner} signer - The signer.
90
+ * @returns {this} The wallet manager.
79
91
  * @throws {ValueError} If the signer name is an empty or blank string.
92
+ * @throws {DisposalError} If the wallet manager has been disposed.
80
93
  */
81
- addSigner(signerName: string, signer: ISigner): WalletManager;
94
+ addSigner(signerName: string, signer: TSigner): this;
82
95
  /**
83
96
  * Returns the default signer, or the signer with the given name.
84
97
  *
85
98
  * @param {string} [signerName] - If set, returns the signer with the given name.
86
- * @returns {ISigner} The signer.
99
+ * @returns {TSigner} The signer.
87
100
  * @throws {NoSuchElementError} If the default signer is not set, or no signers are found for the given name.
88
101
  */
89
- getSigner(signerName?: string): ISigner;
102
+ getSigner(signerName?: string): TSigner;
90
103
  /**
91
104
  * Returns a shallow copy of the map of signers registered via {@link addSigner}.
92
105
  * The default signer is not included; use {@link getSigner} with no arguments
93
106
  * to retrieve it.
94
107
  *
95
- * @returns {Record<string, ISigner>} A map of signer names to signers. Empty if no signers have been registered.
108
+ * @returns {Record<string, TSigner>} A map of signer names to signers. Empty if no signers have been registered.
96
109
  */
97
- getSigners(): Record<string, ISigner>;
110
+ getSigners(): Record<string, TSigner>;
98
111
  /**
99
112
  * Returns the wallet account at a specific index (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)).
100
113
  *
@@ -106,6 +119,7 @@ export default abstract class WalletManager {
106
119
  * @throws {ValueError} If the index is not valid.
107
120
  * @throws {NoSuchElementError} If a signer name is given but no signer exists with that name.
108
121
  * @throws {InvalidSignerError} If the signer doesn't support account derivation.
122
+ * @throws {DisposalError} If the wallet manager or the given signer has been disposed.
109
123
  */
110
124
  abstract getAccount(index?: number, options?: {
111
125
  signerName?: string;
@@ -120,6 +134,7 @@ export default abstract class WalletManager {
120
134
  * @param {string} signerName - The signer name registered via {@link addSigner}.
121
135
  * @returns {Promise<IWalletAccount>} The account.
122
136
  * @throws {NoSuchElementError} If no signer exists with the given name.
137
+ * @throws {DisposalError} If the wallet manager or the given signer has been disposed.
123
138
  */
124
139
  abstract getAccount(signerName: string): Promise<IWalletAccount>;
125
140
  /**
@@ -133,6 +148,7 @@ export default abstract class WalletManager {
133
148
  * @throws {ValueError} If the path is not valid.
134
149
  * @throws {NoSuchElementError} If a signer name is given but no signer exists with that name.
135
150
  * @throws {InvalidSignerError} If the signer doesn't support account derivation.
151
+ * @throws {DisposalError} If the wallet manager or the given signer has been disposed.
136
152
  */
137
153
  abstract getAccountByPath(path: string, options?: {
138
154
  signerName?: string;
@@ -147,12 +163,13 @@ export default abstract class WalletManager {
147
163
  */
148
164
  abstract getFeeRates(): Promise<FeeRates>;
149
165
  /**
150
- * Disposes all wallet accounts and signers, clearing secret material from memory.
166
+ * Disposes all wallet accounts, clearing secret material from memory.
151
167
  */
152
168
  dispose(): void;
153
169
  }
154
170
  export type IWalletAccount = import("./wallet-account.js").IWalletAccount;
155
171
  export type ISigner = import("./signer.js").ISigner;
172
+ export type DisposalError = import("./errors.js").DisposalError;
156
173
  export type InvalidSignerError = import("./errors.js").InvalidSignerError;
157
174
  export type ProviderError = import("./errors.js").ProviderError;
158
175
  export type ProviderRequiredError = import("./errors.js").ProviderRequiredError;
@@ -176,3 +193,4 @@ export type FeeRates = {
176
193
  */
177
194
  fast: bigint;
178
195
  };
196
+ import { IDisposable } from "./disposable.js";