@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.
@@ -15,13 +15,14 @@
15
15
 
16
16
  import * as bip39 from 'bip39'
17
17
 
18
- import { NoSuchElementError, NotImplementedError, ValueError } from './errors.js'
18
+ import { InvalidSignerError, NoSuchElementError, NotImplementedError, ValueError } from './errors.js'
19
19
 
20
20
  /** @typedef {import('./wallet-account.js').IWalletAccount} IWalletAccount */
21
21
 
22
22
  /** @typedef {import('./signer.js').ISigner} ISigner */
23
+ /** @typedef {import('./disposable.js').IDisposable} IDisposable */
23
24
 
24
- /** @typedef {import('./errors.js').InvalidSignerError} InvalidSignerError */
25
+ /** @typedef {import('./errors.js').DisposalError} DisposalError */
25
26
  /** @typedef {import('./errors.js').ProviderError} ProviderError */
26
27
  /** @typedef {import('./errors.js').ProviderRequiredError} ProviderRequiredError */
27
28
 
@@ -37,7 +38,11 @@ import { NoSuchElementError, NotImplementedError, ValueError } from './errors.js
37
38
  * @property {bigint} fast - The fee rate for transaction sent with fast priority.
38
39
  */
39
40
 
40
- /** @abstract */
41
+ /**
42
+ * @abstract
43
+ * @template {ISigner} [TSigner=ISigner]
44
+ * @implements {IDisposable}
45
+ */
41
46
  export default class WalletManager {
42
47
  /**
43
48
  * Creates a new wallet manager from a seed.
@@ -52,13 +57,11 @@ export default class WalletManager {
52
57
  * Creates a new wallet manager from a default signer.
53
58
  *
54
59
  * @overload
55
- * @param {ISigner} signer - The default signer.
60
+ * @param {TSigner} signer - The default signer.
56
61
  * @param {WalletConfig} [config] - The wallet configuration.
57
62
  * @throws {InvalidSignerError} If the given signer doesn't support account derivation.
58
63
  */
59
64
  constructor (seedOrSigner, config = {}) {
60
- // TODO: Add check to assert that the default signer is derivable.
61
-
62
65
  if (typeof seedOrSigner === 'string') {
63
66
  if (!WalletManager.isValidSeedPhrase(seedOrSigner)) {
64
67
  throw new ValueError('Invalid seed phrase.')
@@ -69,6 +72,10 @@ export default class WalletManager {
69
72
 
70
73
  const isSeed = seedOrSigner instanceof Uint8Array
71
74
 
75
+ if (!isSeed && !seedOrSigner.isDerivable) {
76
+ throw new InvalidSignerError('The default signer must be derivable. Non-derivable signers (e.g. private-key signers) can only be registered by name via addSigner.')
77
+ }
78
+
72
79
  /** @private */
73
80
  this._seed = isSeed ? seedOrSigner : undefined
74
81
 
@@ -76,7 +83,7 @@ export default class WalletManager {
76
83
  * The default signer.
77
84
  *
78
85
  * @protected
79
- * @type {ISigner | undefined}
86
+ * @type {TSigner | undefined}
80
87
  */
81
88
  this._defaultSigner = isSeed ? undefined : seedOrSigner
82
89
 
@@ -84,7 +91,7 @@ export default class WalletManager {
84
91
  * A map between signer names and signers added via {@link addSigner}.
85
92
  *
86
93
  * @protected
87
- * @type {Record<string, ISigner>}
94
+ * @type {Record<string, TSigner>}
88
95
  */
89
96
  this._signers = {}
90
97
 
@@ -105,6 +112,18 @@ export default class WalletManager {
105
112
  * @type {WalletConfig}
106
113
  */
107
114
  this._config = config
115
+
116
+ /** @private */
117
+ this._disposed = false
118
+ }
119
+
120
+ /**
121
+ * True if the wallet manager has been disposed.
122
+ *
123
+ * @type {boolean}
124
+ */
125
+ get disposed () {
126
+ return this._disposed
108
127
  }
109
128
 
110
129
  /**
@@ -142,9 +161,10 @@ export default class WalletManager {
142
161
  * Registers a signer with the given name.
143
162
  *
144
163
  * @param {string} signerName - The signer name.
145
- * @param {ISigner} signer - The signer.
146
- * @returns {WalletManager} The wallet manager.
164
+ * @param {TSigner} signer - The signer.
165
+ * @returns {this} The wallet manager.
147
166
  * @throws {ValueError} If the signer name is an empty or blank string.
167
+ * @throws {DisposalError} If the wallet manager has been disposed.
148
168
  */
149
169
  addSigner (signerName, signer) {
150
170
  if (!signerName.trim()) {
@@ -160,7 +180,7 @@ export default class WalletManager {
160
180
  * Returns the default signer, or the signer with the given name.
161
181
  *
162
182
  * @param {string} [signerName] - If set, returns the signer with the given name.
163
- * @returns {ISigner} The signer.
183
+ * @returns {TSigner} The signer.
164
184
  * @throws {NoSuchElementError} If the default signer is not set, or no signers are found for the given name.
165
185
  */
166
186
  getSigner (signerName) {
@@ -186,7 +206,7 @@ export default class WalletManager {
186
206
  * The default signer is not included; use {@link getSigner} with no arguments
187
207
  * to retrieve it.
188
208
  *
189
- * @returns {Record<string, ISigner>} A map of signer names to signers. Empty if no signers have been registered.
209
+ * @returns {Record<string, TSigner>} A map of signer names to signers. Empty if no signers have been registered.
190
210
  */
191
211
  getSigners () {
192
212
  return { ...this._signers }
@@ -203,6 +223,7 @@ export default class WalletManager {
203
223
  * @throws {ValueError} If the index is not valid.
204
224
  * @throws {NoSuchElementError} If a signer name is given but no signer exists with that name.
205
225
  * @throws {InvalidSignerError} If the signer doesn't support account derivation.
226
+ * @throws {DisposalError} If the wallet manager or the given signer has been disposed.
206
227
  */
207
228
 
208
229
  /**
@@ -215,6 +236,7 @@ export default class WalletManager {
215
236
  * @param {string} signerName - The signer name registered via {@link addSigner}.
216
237
  * @returns {Promise<IWalletAccount>} The account.
217
238
  * @throws {NoSuchElementError} If no signer exists with the given name.
239
+ * @throws {DisposalError} If the wallet manager or the given signer has been disposed.
218
240
  */
219
241
 
220
242
  /** @abstract */
@@ -233,6 +255,7 @@ export default class WalletManager {
233
255
  * @throws {ValueError} If the path is not valid.
234
256
  * @throws {NoSuchElementError} If a signer name is given but no signer exists with that name.
235
257
  * @throws {InvalidSignerError} If the signer doesn't support account derivation.
258
+ * @throws {DisposalError} If the wallet manager or the given signer has been disposed.
236
259
  */
237
260
  async getAccountByPath (path, options = {}) {
238
261
  throw new NotImplementedError('getAccountByPath(path, options?)')
@@ -251,23 +274,19 @@ export default class WalletManager {
251
274
  }
252
275
 
253
276
  /**
254
- * Disposes all wallet accounts and signers, clearing secret material from memory.
277
+ * Disposes all wallet accounts, clearing secret material from memory.
255
278
  */
256
279
  dispose () {
280
+ if (this._disposed) return
281
+
257
282
  for (const account of Object.values(this._accounts)) {
258
283
  if (account.keyPair?.privateKey) {
259
284
  account.dispose()
260
285
  }
261
286
  }
262
287
 
263
- this._defaultSigner?.dispose()
264
-
265
- for (const signer of Object.values(this._signers)) {
266
- signer.dispose()
267
- }
268
-
269
288
  this._accounts = {}
270
- this._defaultSigner = undefined
271
- this._signers = {}
289
+
290
+ this._disposed = true
272
291
  }
273
292
  }
package/types/index.d.ts CHANGED
@@ -12,8 +12,9 @@ export type TransactionReceipt = import("./src/wallet-account-read-only-simple.j
12
12
  export type WaitForTransactionTarget = import("./src/wallet-account-read-only-simple.js").WaitForTransactionTarget;
13
13
  export type WaitForTransactionOptions = import("./src/wallet-account-read-only-simple.js").WaitForTransactionOptions;
14
14
  export type KeyPair = import("./src/wallet-account.js").KeyPair;
15
+ export { IDisposable } from "./src/disposable.js";
15
16
  export type ProviderErrorOptions = import("./src/errors.js").ProviderErrorOptions;
16
17
  export type TransactionErrorOptions = import("./src/errors.js").TransactionErrorOptions;
17
18
  export type TransferErrorOptions = import("./src/errors.js").TransferErrorOptions;
18
19
  export { default as WalletAccountReadOnly, IWalletAccountReadOnly, FINALITY } from "./src/wallet-account-read-only.js";
19
- export { AssertionError, InvalidTokenError, InvalidSignerError, InvalidSignerError as SignerError, MaximumFeeExceededError, NoSuchElementError, NotImplementedError, ProviderError, ProviderErrorReason, ProviderRequiredError, TimeoutError, TransactionError, TransactionErrorReason, TransferError, TransferErrorReason, UnsupportedOperationError, ValueError, WdkError } from "./src/errors.js";
20
+ export { AssertionError, DisposalError, InvalidTokenError, InvalidSignerError, InvalidSignerError as SignerError, MaximumFeeExceededError, NoSuchElementError, NotImplementedError, ProviderError, ProviderErrorReason, ProviderRequiredError, TimeoutError, TransactionError, TransactionErrorReason, TransferError, TransferErrorReason, UnsupportedOperationError, ValueError, WdkError } from "./src/errors.js";
@@ -0,0 +1,13 @@
1
+ /** @interface */
2
+ export class IDisposable {
3
+ /**
4
+ * True if the object has been disposed.
5
+ *
6
+ * @type {boolean}
7
+ */
8
+ get disposed(): boolean;
9
+ /**
10
+ * Disposes the object along with all its data (cleaning up any sensitive field from memory).
11
+ */
12
+ dispose(): void;
13
+ }
@@ -206,6 +206,17 @@ export class TimeoutError extends WdkError {
206
206
  */
207
207
  constructor(message: string);
208
208
  }
209
+ /**
210
+ * Thrown when an operation is attempted on an object that has been disposed.
211
+ */
212
+ export class DisposalError extends WdkError {
213
+ /**
214
+ * Creates a new disposal error.
215
+ *
216
+ * @param {string} message - The error's message.
217
+ */
218
+ constructor(message: string);
219
+ }
209
220
  export type ProviderErrorOptions = {
210
221
  /**
211
222
  * - The error's reason.
@@ -6,6 +6,7 @@ export interface IBridgeProtocol {
6
6
  * @param {BridgeOptions} options - The bridge's options.
7
7
  * @returns {Promise<BridgeResult>} The bridge's result.
8
8
  * @throws {AccountRequiredError} If the protocol requires a full account to perform a bridge.
9
+ * @throws {DisposalError} If the account has been disposed.
9
10
  * @throws {ValueError} If the bridge options are not valid.
10
11
  * @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
11
12
  * @throws {ProviderRequiredError} If the method requires a provider.
@@ -70,6 +71,7 @@ export default abstract class BridgeProtocol implements IBridgeProtocol {
70
71
  * @param {BridgeOptions} options - The bridge's options.
71
72
  * @returns {Promise<BridgeResult>} The bridge's result.
72
73
  * @throws {AccountRequiredError} If the protocol requires a full account to perform a bridge.
74
+ * @throws {DisposalError} If the account has been disposed.
73
75
  * @throws {ValueError} If the bridge options are not valid.
74
76
  * @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
75
77
  * @throws {ProviderRequiredError} If the method requires a provider.
@@ -95,6 +97,7 @@ export default abstract class BridgeProtocol implements IBridgeProtocol {
95
97
  export type IWalletAccountReadOnly = import("../wallet-account-read-only.js").IWalletAccountReadOnly;
96
98
  export type IWalletAccount = import("../wallet-account.js").IWalletAccount;
97
99
  export type AccountRequiredError = import("./errors.js").AccountRequiredError;
100
+ export type DisposalError = import("./errors.js").DisposalError;
98
101
  export type BridgeError = import("./errors.js").BridgeError;
99
102
  export type InvalidTokenError = import("./errors.js").InvalidTokenError;
100
103
  export type MaximumFeeExceededError = import("./errors.js").MaximumFeeExceededError;
@@ -354,6 +354,7 @@ export type SdaErrorOptions = {
354
354
  */
355
355
  reason: SdaErrorReason;
356
356
  };
357
+ import { DisposalError } from '../errors.js';
357
358
  import { InvalidTokenError } from '../errors.js';
358
359
  import { MaximumFeeExceededError } from '../errors.js';
359
360
  import { NoSuchElementError } from '../errors.js';
@@ -363,4 +364,4 @@ import { ProviderRequiredError } from '../errors.js';
363
364
  import { UnsupportedOperationError } from '../errors.js';
364
365
  import { ValueError } from '../errors.js';
365
366
  import { WdkError } from '../errors.js';
366
- export { InvalidTokenError, MaximumFeeExceededError, NoSuchElementError, NotImplementedError, ProviderError, ProviderRequiredError, UnsupportedOperationError, ValueError, WdkError };
367
+ export { DisposalError, InvalidTokenError, MaximumFeeExceededError, NoSuchElementError, NotImplementedError, ProviderError, ProviderRequiredError, UnsupportedOperationError, ValueError, WdkError };
@@ -18,6 +18,7 @@ export interface IFiatProtocol {
18
18
  * @param {BuyOptions} options - The options for the buy operation.
19
19
  * @returns {Promise<BuyResult>} The operation's result.
20
20
  * @throws {AccountRequiredError} If the protocol requires a full account to perform a purchase.
21
+ * @throws {DisposalError} If the account has been disposed.
21
22
  * @throws {ValueError} If the buy options are not valid.
22
23
  * @throws {ProviderRequiredError} If the method requires a provider.
23
24
  * @throws {ProviderError} If the provider fails to perform the purchase.
@@ -43,6 +44,7 @@ export interface IFiatProtocol {
43
44
  * @param {SellOptions} options - The options for the sell operation.
44
45
  * @returns {Promise<SellResult>} The operation's result.
45
46
  * @throws {AccountRequiredError} If the protocol requires a full account to perform a sale.
47
+ * @throws {DisposalError} If the account has been disposed.
46
48
  * @throws {ValueError} If the buy options are not valid.
47
49
  * @throws {ProviderRequiredError} If the method requires a provider.
48
50
  * @throws {ProviderError} If the provider fails to perform the sale.
@@ -139,6 +141,7 @@ export default abstract class FiatProtocol implements IFiatProtocol {
139
141
  * @param {BuyOptions} options - The options for the buy operation.
140
142
  * @returns {Promise<BuyResult>} The URL for the user to complete the purchase.
141
143
  * @throws {AccountRequiredError} If the protocol requires a full account to perform a purchase.
144
+ * @throws {DisposalError} If the account has been disposed.
142
145
  * @throws {ValueError} If the buy options are not valid.
143
146
  * @throws {ProviderRequiredError} If the method requires a provider.
144
147
  * @throws {ProviderError} If the provider fails to perform the purchase.
@@ -166,6 +169,7 @@ export default abstract class FiatProtocol implements IFiatProtocol {
166
169
  * @param {SellOptions} options - The options for the sell operation.
167
170
  * @returns {Promise<SellResult>} The URL for the user to complete the sale.
168
171
  * @throws {AccountRequiredError} If the protocol requires a full account to perform a sale.
172
+ * @throws {DisposalError} If the account has been disposed.
169
173
  * @throws {ValueError} If the buy options are not valid.
170
174
  * @throws {ProviderRequiredError} If the method requires a provider.
171
175
  * @throws {ProviderError} If the provider fails to perform the sale.
@@ -216,6 +220,7 @@ export default abstract class FiatProtocol implements IFiatProtocol {
216
220
  export type IWalletAccountReadOnly = import("../wallet-account-read-only.js").IWalletAccountReadOnly;
217
221
  export type IWalletAccount = import("../wallet-account.js").IWalletAccount;
218
222
  export type AccountRequiredError = import("./errors.js").AccountRequiredError;
223
+ export type DisposalError = import("./errors.js").DisposalError;
219
224
  export type BuyError = import("./errors.js").BuyError;
220
225
  export type MaximumFeeExceededError = import("./errors.js").MaximumFeeExceededError;
221
226
  export type NoSuchElementError = import("./errors.js").NoSuchElementError;
@@ -78,4 +78,4 @@ export { default as LendingProtocol, ILendingProtocol } from "./lending-protocol
78
78
  export { default as FiatProtocol, IFiatProtocol } from "./fiat-protocol.js";
79
79
  export { default as SwidgeProtocol, ISwidgeProtocol } from "./swidge-protocol.js";
80
80
  export { default as SdaProtocol, ISdaProtocol } from "./sda-protocol.js";
81
- export { AccountRequiredError, BorrowError, BorrowErrorReason, BridgeError, BridgeErrorReason, BuyError, BuyErrorReason, InvalidTokenError, MaximumFeeExceededError, NoSuchElementError, NotImplementedError, ProviderError, ProviderRequiredError, ReadOnlyAccountRequiredError, RepayError, RepayErrorReason, SdaError, SdaErrorReason, SellError, SellErrorReason, SupplyError, SupplyErrorReason, SwapError, SwapErrorReason, SwidgeError, SwidgeErrorReason, UnsupportedOperationError, ValueError, WdkError, WithdrawError, WithdrawErrorReason } from "./errors.js";
81
+ export { AccountRequiredError, BorrowError, BorrowErrorReason, BridgeError, BridgeErrorReason, BuyError, BuyErrorReason, DisposalError, InvalidTokenError, MaximumFeeExceededError, NoSuchElementError, NotImplementedError, ProviderError, ProviderRequiredError, ReadOnlyAccountRequiredError, RepayError, RepayErrorReason, SdaError, SdaErrorReason, SellError, SellErrorReason, SupplyError, SupplyErrorReason, SwapError, SwapErrorReason, SwidgeError, SwidgeErrorReason, UnsupportedOperationError, ValueError, WdkError, WithdrawError, WithdrawErrorReason } from "./errors.js";
@@ -6,6 +6,7 @@ export interface ILendingProtocol {
6
6
  * @param {SupplyOptions} options - The supply's options.
7
7
  * @returns {Promise<SupplyResult>} The supply's result.
8
8
  * @throws {AccountRequiredError} If the protocol requires a full account to perform a supply.
9
+ * @throws {DisposalError} If the account has been disposed.
9
10
  * @throws {ValueError} If the supply options are not valid.
10
11
  * @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
11
12
  * @throws {ProviderRequiredError} If the method requires a provider.
@@ -33,6 +34,7 @@ export interface ILendingProtocol {
33
34
  * @param {WithdrawOptions} options - The withdraw's options.
34
35
  * @returns {Promise<WithdrawResult>} The withdraw's result.
35
36
  * @throws {AccountRequiredError} If the protocol requires a full account to perform a withdraw.
37
+ * @throws {DisposalError} If the account has been disposed.
36
38
  * @throws {ValueError} If the withdraw options are not valid.
37
39
  * @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
38
40
  * @throws {ProviderRequiredError} If the method requires a provider.
@@ -60,6 +62,7 @@ export interface ILendingProtocol {
60
62
  * @param {BorrowOptions} options - The borrow's options.
61
63
  * @returns {Promise<BorrowResult>} The borrow's result.
62
64
  * @throws {AccountRequiredError} If the protocol requires a full account to perform a borrow.
65
+ * @throws {DisposalError} If the account has been disposed.
63
66
  * @throws {ValueError} If the borrow options are not valid.
64
67
  * @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
65
68
  * @throws {ProviderRequiredError} If the method requires a provider.
@@ -87,6 +90,7 @@ export interface ILendingProtocol {
87
90
  * @param {RepayOptions} options - The repay's options.
88
91
  * @returns {Promise<RepayResult>} The repay's result.
89
92
  * @throws {AccountRequiredError} If the protocol requires a full account to perform a repay.
93
+ * @throws {DisposalError} If the account has been disposed.
90
94
  * @throws {ValueError} If the repay options are not valid.
91
95
  * @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
92
96
  * @throws {ProviderRequiredError} If the method requires a provider.
@@ -142,6 +146,7 @@ export default abstract class LendingProtocol implements ILendingProtocol {
142
146
  * @param {SupplyOptions} options - The supply's options.
143
147
  * @returns {Promise<SupplyResult>} The supply's result.
144
148
  * @throws {AccountRequiredError} If the protocol requires a full account to perform a supply.
149
+ * @throws {DisposalError} If the account has been disposed.
145
150
  * @throws {ValueError} If the supply options are not valid.
146
151
  * @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
147
152
  * @throws {ProviderRequiredError} If the method requires a provider.
@@ -170,6 +175,7 @@ export default abstract class LendingProtocol implements ILendingProtocol {
170
175
  * @param {WithdrawOptions} options - The withdraw's options.
171
176
  * @returns {Promise<WithdrawResult>} The withdraw's result.
172
177
  * @throws {AccountRequiredError} If the protocol requires a full account to perform a withdraw.
178
+ * @throws {DisposalError} If the account has been disposed.
173
179
  * @throws {ValueError} If the withdraw options are not valid.
174
180
  * @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
175
181
  * @throws {ProviderRequiredError} If the method requires a provider.
@@ -198,6 +204,7 @@ export default abstract class LendingProtocol implements ILendingProtocol {
198
204
  * @param {BorrowOptions} options - The borrow's options.
199
205
  * @returns {Promise<BorrowResult>} The borrow's result.
200
206
  * @throws {AccountRequiredError} If the protocol requires a full account to perform a borrow.
207
+ * @throws {DisposalError} If the account has been disposed.
201
208
  * @throws {ValueError} If the borrow options are not valid.
202
209
  * @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
203
210
  * @throws {ProviderRequiredError} If the method requires a provider.
@@ -226,6 +233,7 @@ export default abstract class LendingProtocol implements ILendingProtocol {
226
233
  * @param {RepayOptions} options - The borrow's options.
227
234
  * @returns {Promise<RepayResult>} The repay's result.
228
235
  * @throws {AccountRequiredError} If the protocol requires a full account to perform a repay.
236
+ * @throws {DisposalError} If the account has been disposed.
229
237
  * @throws {ValueError} If the repay options are not valid.
230
238
  * @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
231
239
  * @throws {ProviderRequiredError} If the method requires a provider.
@@ -251,6 +259,7 @@ export default abstract class LendingProtocol implements ILendingProtocol {
251
259
  export type IWalletAccountReadOnly = import("../wallet-account-read-only.js").IWalletAccountReadOnly;
252
260
  export type IWalletAccount = import("../wallet-account.js").IWalletAccount;
253
261
  export type AccountRequiredError = import("./errors.js").AccountRequiredError;
262
+ export type DisposalError = import("./errors.js").DisposalError;
254
263
  export type BorrowError = import("./errors.js").BorrowError;
255
264
  export type InvalidTokenError = import("./errors.js").InvalidTokenError;
256
265
  export type MaximumFeeExceededError = import("./errors.js").MaximumFeeExceededError;
@@ -44,6 +44,7 @@ export interface ISdaProtocol {
44
44
  * @param {SdaCreateDepositAddressOptions} options - The address creation options.
45
45
  * @returns {Promise<SdaDepositAddress[]>} The created deposit addresses, one per distinct address.
46
46
  * @throws {AccountRequiredError} If the protocol requires a full account to create a new deposit address.
47
+ * @throws {DisposalError} If the account has been disposed.
47
48
  * @throws {ValueError} If the create deposit address options are not valid.
48
49
  * @throws {ProviderRequiredError} If the method requires a provider.
49
50
  * @throws {ProviderError} If the provider fails to create a new deposit address.
@@ -60,6 +61,7 @@ export interface ISdaProtocol {
60
61
  * @returns {Promise<string>} The derived deposit address.
61
62
  * @throws {UnsupportedOperationError} If the protocol does not support this operation.
62
63
  * @throws {AccountRequiredError} If the protocol requires a full account to derive a deposit address.
64
+ * @throws {DisposalError} If the account has been disposed.
63
65
  * @throws {ValueError} If the create deposit address options are not valid.
64
66
  * @throws {ProviderRequiredError} If the method requires a provider.
65
67
  * @throws {ProviderError} If the provider fails to derive the deposit address.
@@ -87,6 +89,7 @@ export interface ISdaProtocol {
87
89
  * @returns {Promise<SdaDepositAddress>} The refreshed deposit address descriptor (with the new `expiry`).
88
90
  * @throws {UnsupportedOperationError} If the protocol does not support this operation.
89
91
  * @throws {AccountRequiredError} If the protocol requires a full account to renew a deposit address.
92
+ * @throws {DisposalError} If the account has been disposed.
90
93
  * @throws {ValueError} If the id is not valid.
91
94
  * @throws {NoSuchElementError} If no deposit address exists for the given id.
92
95
  * @throws {ProviderRequiredError} If the method requires a provider.
@@ -138,6 +141,7 @@ export interface ISdaProtocol {
138
141
  * @returns {Promise<SdaRecoveryResult>} The recovery outcome.
139
142
  * @throws {UnsupportedOperationError} If the protocol does not support this operation.
140
143
  * @throws {AccountRequiredError} If the protocol requires a full account to recover a deposit address.
144
+ * @throws {DisposalError} If the account has been disposed.
141
145
  * @throws {ValueError} If the id is not valid.
142
146
  * @throws {NoSuchElementError} If no deposit address exists for the given id or address.
143
147
  * @throws {ProviderRequiredError} If the method requires a provider.
@@ -153,6 +157,7 @@ export interface ISdaProtocol {
153
157
  * @returns {Promise<void>} Resolves once the address has been disabled.
154
158
  * @throws {UnsupportedOperationError} If the protocol does not support this operation.
155
159
  * @throws {AccountRequiredError} If the protocol requires a full account to disable a deposit address.
160
+ * @throws {DisposalError} If the account has been disposed.
156
161
  * @throws {ValueError} If the id is not valid.
157
162
  * @throws {NoSuchElementError} If no deposit address exists for the given id.
158
163
  * @throws {ProviderRequiredError} If the method requires a provider.
@@ -234,6 +239,7 @@ export default abstract class SdaProtocol implements ISdaProtocol {
234
239
  * @param {SdaCreateDepositAddressOptions} options - The address creation options.
235
240
  * @returns {Promise<SdaDepositAddress[]>} The created deposit addresses, one per distinct address.
236
241
  * @throws {AccountRequiredError} If the protocol requires a full account to create a new deposit address.
242
+ * @throws {DisposalError} If the account has been disposed.
237
243
  * @throws {ValueError} If the create deposit address options are not valid.
238
244
  * @throws {ProviderRequiredError} If the method requires a provider.
239
245
  * @throws {ProviderError} If the provider fails to create a new deposit address.
@@ -250,6 +256,7 @@ export default abstract class SdaProtocol implements ISdaProtocol {
250
256
  * @returns {Promise<string>} The derived deposit address.
251
257
  * @throws {UnsupportedOperationError} If the protocol does not support this operation.
252
258
  * @throws {AccountRequiredError} If the protocol requires a full account to derive a deposit address.
259
+ * @throws {DisposalError} If the account has been disposed.
253
260
  * @throws {ValueError} If the create deposit address options are not valid.
254
261
  * @throws {ProviderRequiredError} If the method requires a provider.
255
262
  * @throws {ProviderError} If the provider fails to derive the deposit address.
@@ -277,6 +284,7 @@ export default abstract class SdaProtocol implements ISdaProtocol {
277
284
  * @returns {Promise<SdaDepositAddress>} The refreshed deposit address descriptor (with the new `expiry`).
278
285
  * @throws {UnsupportedOperationError} If the protocol does not support this operation.
279
286
  * @throws {AccountRequiredError} If the protocol requires a full account to renew a deposit address.
287
+ * @throws {DisposalError} If the account has been disposed.
280
288
  * @throws {ValueError} If the id is not valid.
281
289
  * @throws {NoSuchElementError} If no deposit address exists for the given id.
282
290
  * @throws {ProviderRequiredError} If the method requires a provider.
@@ -328,6 +336,7 @@ export default abstract class SdaProtocol implements ISdaProtocol {
328
336
  * @returns {Promise<SdaRecoveryResult>} The recovery outcome.
329
337
  * @throws {UnsupportedOperationError} If the protocol does not support this operation.
330
338
  * @throws {AccountRequiredError} If the protocol requires a full account to recover a deposit address.
339
+ * @throws {DisposalError} If the account has been disposed.
331
340
  * @throws {ValueError} If the id is not valid.
332
341
  * @throws {NoSuchElementError} If no deposit address exists for the given id or address.
333
342
  * @throws {ProviderRequiredError} If the method requires a provider.
@@ -343,6 +352,7 @@ export default abstract class SdaProtocol implements ISdaProtocol {
343
352
  * @returns {Promise<void>} Resolves once the address has been disabled.
344
353
  * @throws {UnsupportedOperationError} If the protocol does not support this operation.
345
354
  * @throws {AccountRequiredError} If the protocol requires a full account to disable a deposit address.
355
+ * @throws {DisposalError} If the account has been disposed.
346
356
  * @throws {ValueError} If the id is not valid.
347
357
  * @throws {NoSuchElementError} If no deposit address exists for the given id.
348
358
  * @throws {ProviderRequiredError} If the method requires a provider.
@@ -354,6 +364,7 @@ export default abstract class SdaProtocol implements ISdaProtocol {
354
364
  export type IWalletAccountReadOnly = import("../wallet-account-read-only.js").IWalletAccountReadOnly;
355
365
  export type IWalletAccount = import("../wallet-account.js").IWalletAccount;
356
366
  export type AccountRequiredError = import("./errors.js").AccountRequiredError;
367
+ export type DisposalError = import("./errors.js").DisposalError;
357
368
  export type InvalidTokenError = import("./errors.js").InvalidTokenError;
358
369
  export type NoSuchElementError = import("./errors.js").NoSuchElementError;
359
370
  export type ReadOnlyAccountRequiredError = import("./errors.js").ReadOnlyAccountRequiredError;
@@ -6,6 +6,7 @@ export interface ISwapProtocol {
6
6
  * @param {SwapOptions} options - The swap's options.
7
7
  * @returns {Promise<SwapResult>} The swap's result.
8
8
  * @throws {AccountRequiredError} If the protocol requires a full account to perform a swap.
9
+ * @throws {DisposalError} If the account has been disposed.
9
10
  * @throws {ValueError} If the swap options are not valid.
10
11
  * @throws {InvalidTokenError} If the input or output tokens are not valid ERC 20 token's addresses.
11
12
  * @throws {ProviderRequiredError} If the method requires a provider.
@@ -70,6 +71,7 @@ export default abstract class SwapProtocol implements ISwapProtocol {
70
71
  * @param {SwapOptions} options - The swap's options.
71
72
  * @returns {Promise<SwapResult>} The swap's result.
72
73
  * @throws {AccountRequiredError} If the protocol requires a full account to perform a swap.
74
+ * @throws {DisposalError} If the account has been disposed.
73
75
  * @throws {ValueError} If the swap options are not valid.
74
76
  * @throws {InvalidTokenError} If the input or output tokens are not valid ERC 20 token's addresses.
75
77
  * @throws {ProviderRequiredError} If the method requires a provider.
@@ -95,6 +97,7 @@ export default abstract class SwapProtocol implements ISwapProtocol {
95
97
  export type IWalletAccountReadOnly = import("../wallet-account-read-only.js").IWalletAccountReadOnly;
96
98
  export type IWalletAccount = import("../wallet-account.js").IWalletAccount;
97
99
  export type AccountRequiredError = import("./errors.js").AccountRequiredError;
100
+ export type DisposalError = import("./errors.js").DisposalError;
98
101
  export type InvalidTokenError = import("./errors.js").InvalidTokenError;
99
102
  export type MaximumFeeExceededError = import("./errors.js").MaximumFeeExceededError;
100
103
  export type ReadOnlyAccountRequiredError = import("./errors.js").ReadOnlyAccountRequiredError;
@@ -22,6 +22,7 @@ export interface ISwidgeProtocol extends ISwapProtocol, IBridgeProtocol {
22
22
  * @param {SwidgeProtocolConfig} [config] - Optional provider-specific execution configuration.
23
23
  * @returns {Promise<SwidgeResult>} The swidge execution result.
24
24
  * @throws {AccountRequiredError} If the protocol requires a full account to perform a swidge.
25
+ * @throws {DisposalError} If the account has been disposed.
25
26
  * @throws {ValueError} If the swidge options are not valid.
26
27
  * @throws {InvalidTokenError} If the from or to tokens are not valid ERC 20 token's addresses.
27
28
  * @throws {ProviderRequiredError} If the method requires a provider.
@@ -106,6 +107,7 @@ export default abstract class SwidgeProtocol implements ISwidgeProtocol, ISwapPr
106
107
  * @param {SwapOptions} options - The swap's options.
107
108
  * @returns {Promise<SwapResult>} The swap's result.
108
109
  * @throws {AccountRequiredError} If the protocol requires a full account to perform a swap.
110
+ * @throws {DisposalError} If the account has been disposed.
109
111
  * @throws {ValueError} If the swap options are not valid.
110
112
  * @throws {InvalidTokenError} If the input or output tokens are not valid ERC 20 token's addresses.
111
113
  * @throws {ProviderRequiredError} If the method requires a provider.
@@ -133,6 +135,7 @@ export default abstract class SwidgeProtocol implements ISwidgeProtocol, ISwapPr
133
135
  * @param {BridgeOptions} options - The bridge's options.
134
136
  * @returns {Promise<BridgeResult>} The bridge's result.
135
137
  * @throws {AccountRequiredError} If the protocol requires a full account to perform a bridge.
138
+ * @throws {DisposalError} If the account has been disposed.
136
139
  * @throws {ValueError} If the bridge options are not valid.
137
140
  * @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
138
141
  * @throws {ProviderRequiredError} If the method requires a provider.
@@ -178,6 +181,7 @@ export default abstract class SwidgeProtocol implements ISwidgeProtocol, ISwapPr
178
181
  * @param {SwidgeProtocolConfig} [config] - Optional provider-specific execution configuration.
179
182
  * @returns {Promise<SwidgeResult>} The swidge execution result.
180
183
  * @throws {AccountRequiredError} If the protocol requires a full account to perform a swidge.
184
+ * @throws {DisposalError} If the account has been disposed.
181
185
  * @throws {ValueError} If the swidge options are not valid.
182
186
  * @throws {InvalidTokenError} If the from or to tokens are not valid ERC 20 token's addresses.
183
187
  * @throws {ProviderRequiredError} If the method requires a provider.
@@ -228,6 +232,7 @@ export type IBridgeProtocol = import("./bridge-protocol.js").IBridgeProtocol;
228
232
  export type BridgeOptions = import("./bridge-protocol.js").BridgeOptions;
229
233
  export type BridgeResult = import("./bridge-protocol.js").BridgeResult;
230
234
  export type AccountRequiredError = import("./errors.js").AccountRequiredError;
235
+ export type DisposalError = import("./errors.js").DisposalError;
231
236
  export type InvalidTokenError = import("./errors.js").InvalidTokenError;
232
237
  export type MaximumFeeExceededError = import("./errors.js").MaximumFeeExceededError;
233
238
  export type NoSuchElementError = import("./errors.js").NoSuchElementError;
@@ -3,7 +3,27 @@
3
3
  *
4
4
  * @interface
5
5
  */
6
- export class ISigner {
6
+ export class ISigner extends IDisposable {
7
+ /**
8
+ * Whether the signer supports account derivation via {@link derive}.
9
+ *
10
+ * @type {boolean}
11
+ */
12
+ get isDerivable(): boolean;
13
+ /**
14
+ * The signer's key pair, or null if the signer does not allow retrieving
15
+ * key material (e.g. hardware signers).
16
+ *
17
+ * @type {KeyPair | null}
18
+ */
19
+ get keyPair(): KeyPair | null;
20
+ /**
21
+ * The BIP 0032 derivation path, or null if the signer is not bound to a derivation position
22
+ * (e.g. private-key signers).
23
+ *
24
+ * @type {string | null}
25
+ */
26
+ get path(): string | null;
7
27
  /**
8
28
  * Derive a child signer using a relative path (e.g., "0'/0/0").
9
29
  *
@@ -11,6 +31,7 @@ export class ISigner {
11
31
  * @returns {Promise<ISigner>} The derived signer.
12
32
  * @throws {UnsupportedOperationError} If the signer does not support account derivation.
13
33
  * @throws {ValueError} If the path is not valid.
34
+ * @throws {DisposalError} If the signer has been disposed.
14
35
  */
15
36
  derive(path: string): Promise<ISigner>;
16
37
  /**
@@ -20,9 +41,16 @@ export class ISigner {
20
41
  */
21
42
  getAddress(): Promise<string>;
22
43
  /**
23
- * Disposes the signer and clears any secret material from memory.
44
+ * Signs a message.
45
+ *
46
+ * @param {string} message - The message to sign.
47
+ * @returns {Promise<string>} The message's signature.
48
+ * @throws {DisposalError} If the signer has been disposed.
24
49
  */
25
- dispose(): void;
50
+ sign(message: string): Promise<string>;
26
51
  }
52
+ export type KeyPair = import("./wallet-account.js").KeyPair;
53
+ export type DisposalError = import("./errors.js").DisposalError;
54
+ import { IDisposable } from "./disposable.js";
27
55
  export type UnsupportedOperationError = import("./errors.js").UnsupportedOperationError;
28
56
  export type ValueError = import("./errors.js").ValueError;