@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.
- package/README.md +2 -2
- package/index.js +3 -1
- package/package.json +3 -2
- package/src/disposable.js +35 -0
- package/src/errors.js +16 -0
- package/src/protocols/bridge-protocol.js +3 -0
- package/src/protocols/errors.js +2 -2
- package/src/protocols/fiat-protocol.js +5 -0
- package/src/protocols/index.js +1 -1
- package/src/protocols/lending-protocol.js +9 -0
- package/src/protocols/sda-protocol.js +11 -0
- package/src/protocols/swap-protocol.js +3 -0
- package/src/protocols/swidge-protocol.js +5 -0
- package/src/signer.js +42 -4
- package/src/wallet-account.js +17 -23
- package/src/wallet-manager.js +40 -21
- package/types/index.d.ts +2 -1
- package/types/src/disposable.d.ts +13 -0
- package/types/src/errors.d.ts +11 -0
- package/types/src/protocols/bridge-protocol.d.ts +3 -0
- package/types/src/protocols/errors.d.ts +2 -1
- package/types/src/protocols/fiat-protocol.d.ts +5 -0
- package/types/src/protocols/index.d.ts +1 -1
- package/types/src/protocols/lending-protocol.d.ts +9 -0
- package/types/src/protocols/sda-protocol.d.ts +11 -0
- package/types/src/protocols/swap-protocol.d.ts +3 -0
- package/types/src/protocols/swidge-protocol.d.ts +5 -0
- package/types/src/signer.d.ts +31 -3
- package/types/src/wallet-account.d.ts +17 -17
- package/types/src/wallet-manager.d.ts +34 -16
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
## What This Does
|
|
4
4
|
|
|
5
|
-
Base classes for the wallet and protocol modules in the [Wallet Development Kit
|
|
5
|
+
Base classes for the wallet and protocol modules in the [WDK (Wallet Development Kit)](https://docs.wdk.tether.io/) by Tether.
|
|
6
6
|
|
|
7
7
|
## Who Should Use This
|
|
8
8
|
|
|
@@ -32,7 +32,7 @@ This module is for internal use only. If you want to build a wallet, use one of
|
|
|
32
32
|
|
|
33
33
|
## Learn More
|
|
34
34
|
|
|
35
|
-
For
|
|
35
|
+
For general WDK documentation, visit [docs.wdk.tether.io](https://docs.wdk.tether.io/)
|
|
36
36
|
|
|
37
37
|
## License
|
|
38
38
|
|
package/index.js
CHANGED
|
@@ -39,4 +39,6 @@ export { IWalletAccount } from './src/wallet-account.js'
|
|
|
39
39
|
|
|
40
40
|
export { ISigner } from './src/signer.js'
|
|
41
41
|
|
|
42
|
-
export {
|
|
42
|
+
export { IDisposable } from './src/disposable.js'
|
|
43
|
+
|
|
44
|
+
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'
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tetherto/wdk-wallet",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.0-beta.22",
|
|
4
|
+
"description": "Base wallet and protocol classes for WDK (Wallet Development Kit) by Tether. For internal use only.",
|
|
5
|
+
"homepage": "https://docs.wdk.tether.io/",
|
|
5
6
|
"keywords": [
|
|
6
7
|
"wdk",
|
|
7
8
|
"wallet",
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Copyright 2024 Tether Operations Limited
|
|
2
|
+
//
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
'use strict'
|
|
15
|
+
|
|
16
|
+
import { NotImplementedError } from './errors.js'
|
|
17
|
+
|
|
18
|
+
/** @interface */
|
|
19
|
+
export class IDisposable {
|
|
20
|
+
/**
|
|
21
|
+
* True if the object has been disposed.
|
|
22
|
+
*
|
|
23
|
+
* @type {boolean}
|
|
24
|
+
*/
|
|
25
|
+
get disposed () {
|
|
26
|
+
throw new NotImplementedError('disposed')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Disposes the object along with all its data (cleaning up any sensitive field from memory).
|
|
31
|
+
*/
|
|
32
|
+
dispose () {
|
|
33
|
+
throw new NotImplementedError('dispose()')
|
|
34
|
+
}
|
|
35
|
+
}
|
package/src/errors.js
CHANGED
|
@@ -340,3 +340,19 @@ export class TimeoutError extends WdkError {
|
|
|
340
340
|
this.name = 'TimeoutError'
|
|
341
341
|
}
|
|
342
342
|
}
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* Thrown when an operation is attempted on an object that has been disposed.
|
|
346
|
+
*/
|
|
347
|
+
export class DisposalError extends WdkError {
|
|
348
|
+
/**
|
|
349
|
+
* Creates a new disposal error.
|
|
350
|
+
*
|
|
351
|
+
* @param {string} message - The error's message.
|
|
352
|
+
*/
|
|
353
|
+
constructor (message) {
|
|
354
|
+
super(message)
|
|
355
|
+
|
|
356
|
+
this.name = 'DisposalError'
|
|
357
|
+
}
|
|
358
|
+
}
|
|
@@ -20,6 +20,7 @@ import { NotImplementedError } from './errors.js'
|
|
|
20
20
|
/** @typedef {import('../wallet-account.js').IWalletAccount} IWalletAccount */
|
|
21
21
|
|
|
22
22
|
/** @typedef {import('./errors.js').AccountRequiredError} AccountRequiredError */
|
|
23
|
+
/** @typedef {import('./errors.js').DisposalError} DisposalError */
|
|
23
24
|
/** @typedef {import('./errors.js').BridgeError} BridgeError */
|
|
24
25
|
/** @typedef {import('./errors.js').InvalidTokenError} InvalidTokenError */
|
|
25
26
|
/** @typedef {import('./errors.js').MaximumFeeExceededError} MaximumFeeExceededError */
|
|
@@ -56,6 +57,7 @@ export class IBridgeProtocol {
|
|
|
56
57
|
* @param {BridgeOptions} options - The bridge's options.
|
|
57
58
|
* @returns {Promise<BridgeResult>} The bridge's result.
|
|
58
59
|
* @throws {AccountRequiredError} If the protocol requires a full account to perform a bridge.
|
|
60
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
59
61
|
* @throws {ValueError} If the bridge options are not valid.
|
|
60
62
|
* @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
|
|
61
63
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
@@ -129,6 +131,7 @@ export default class BridgeProtocol {
|
|
|
129
131
|
* @param {BridgeOptions} options - The bridge's options.
|
|
130
132
|
* @returns {Promise<BridgeResult>} The bridge's result.
|
|
131
133
|
* @throws {AccountRequiredError} If the protocol requires a full account to perform a bridge.
|
|
134
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
132
135
|
* @throws {ValueError} If the bridge options are not valid.
|
|
133
136
|
* @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
|
|
134
137
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
package/src/protocols/errors.js
CHANGED
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
'use strict'
|
|
15
15
|
|
|
16
|
-
import { InvalidTokenError, MaximumFeeExceededError, NoSuchElementError, NotImplementedError, ProviderError, ProviderRequiredError, UnsupportedOperationError, ValueError, WdkError } from '../errors.js'
|
|
16
|
+
import { DisposalError, InvalidTokenError, MaximumFeeExceededError, NoSuchElementError, NotImplementedError, ProviderError, ProviderRequiredError, UnsupportedOperationError, ValueError, WdkError } from '../errors.js'
|
|
17
17
|
|
|
18
|
-
export { InvalidTokenError, MaximumFeeExceededError, NoSuchElementError, NotImplementedError, ProviderError, ProviderRequiredError, UnsupportedOperationError, ValueError, WdkError }
|
|
18
|
+
export { DisposalError, InvalidTokenError, MaximumFeeExceededError, NoSuchElementError, NotImplementedError, ProviderError, ProviderRequiredError, UnsupportedOperationError, ValueError, WdkError }
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* @typedef {Object} SwapErrorOptions
|
|
@@ -20,6 +20,7 @@ import { NotImplementedError } from './errors.js'
|
|
|
20
20
|
/** @typedef {import('../wallet-account.js').IWalletAccount} IWalletAccount */
|
|
21
21
|
|
|
22
22
|
/** @typedef {import('./errors.js').AccountRequiredError} AccountRequiredError */
|
|
23
|
+
/** @typedef {import('./errors.js').DisposalError} DisposalError */
|
|
23
24
|
/** @typedef {import('./errors.js').BuyError} BuyError */
|
|
24
25
|
/** @typedef {import('./errors.js').MaximumFeeExceededError} MaximumFeeExceededError */
|
|
25
26
|
/** @typedef {import('./errors.js').NoSuchElementError} NoSuchElementError */
|
|
@@ -160,6 +161,7 @@ export class IFiatProtocol {
|
|
|
160
161
|
* @param {BuyOptions} options - The options for the buy operation.
|
|
161
162
|
* @returns {Promise<BuyResult>} The operation's result.
|
|
162
163
|
* @throws {AccountRequiredError} If the protocol requires a full account to perform a purchase.
|
|
164
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
163
165
|
* @throws {ValueError} If the buy options are not valid.
|
|
164
166
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
165
167
|
* @throws {ProviderError} If the provider fails to perform the purchase.
|
|
@@ -191,6 +193,7 @@ export class IFiatProtocol {
|
|
|
191
193
|
* @param {SellOptions} options - The options for the sell operation.
|
|
192
194
|
* @returns {Promise<SellResult>} The operation's result.
|
|
193
195
|
* @throws {AccountRequiredError} If the protocol requires a full account to perform a sale.
|
|
196
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
194
197
|
* @throws {ValueError} If the buy options are not valid.
|
|
195
198
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
196
199
|
* @throws {ProviderError} If the provider fails to perform the sale.
|
|
@@ -305,6 +308,7 @@ export default class FiatProtocol {
|
|
|
305
308
|
* @param {BuyOptions} options - The options for the buy operation.
|
|
306
309
|
* @returns {Promise<BuyResult>} The URL for the user to complete the purchase.
|
|
307
310
|
* @throws {AccountRequiredError} If the protocol requires a full account to perform a purchase.
|
|
311
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
308
312
|
* @throws {ValueError} If the buy options are not valid.
|
|
309
313
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
310
314
|
* @throws {ProviderError} If the provider fails to perform the purchase.
|
|
@@ -338,6 +342,7 @@ export default class FiatProtocol {
|
|
|
338
342
|
* @param {SellOptions} options - The options for the sell operation.
|
|
339
343
|
* @returns {Promise<SellResult>} The URL for the user to complete the sale.
|
|
340
344
|
* @throws {AccountRequiredError} If the protocol requires a full account to perform a sale.
|
|
345
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
341
346
|
* @throws {ValueError} If the buy options are not valid.
|
|
342
347
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
343
348
|
* @throws {ProviderError} If the provider fails to perform the sale.
|
package/src/protocols/index.js
CHANGED
|
@@ -110,4 +110,4 @@ export { default as SwidgeProtocol, ISwidgeProtocol } from './swidge-protocol.js
|
|
|
110
110
|
|
|
111
111
|
export { default as SdaProtocol, ISdaProtocol } from './sda-protocol.js'
|
|
112
112
|
|
|
113
|
-
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'
|
|
113
|
+
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'
|
|
@@ -20,6 +20,7 @@ import { NotImplementedError } from './errors.js'
|
|
|
20
20
|
/** @typedef {import('../wallet-account.js').IWalletAccount} IWalletAccount */
|
|
21
21
|
|
|
22
22
|
/** @typedef {import('./errors.js').AccountRequiredError} AccountRequiredError */
|
|
23
|
+
/** @typedef {import('./errors.js').DisposalError} DisposalError */
|
|
23
24
|
/** @typedef {import('./errors.js').BorrowError} BorrowError */
|
|
24
25
|
/** @typedef {import('./errors.js').InvalidTokenError} InvalidTokenError */
|
|
25
26
|
/** @typedef {import('./errors.js').MaximumFeeExceededError} MaximumFeeExceededError */
|
|
@@ -91,6 +92,7 @@ export class ILendingProtocol {
|
|
|
91
92
|
* @param {SupplyOptions} options - The supply's options.
|
|
92
93
|
* @returns {Promise<SupplyResult>} The supply's result.
|
|
93
94
|
* @throws {AccountRequiredError} If the protocol requires a full account to perform a supply.
|
|
95
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
94
96
|
* @throws {ValueError} If the supply options are not valid.
|
|
95
97
|
* @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
|
|
96
98
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
@@ -124,6 +126,7 @@ export class ILendingProtocol {
|
|
|
124
126
|
* @param {WithdrawOptions} options - The withdraw's options.
|
|
125
127
|
* @returns {Promise<WithdrawResult>} The withdraw's result.
|
|
126
128
|
* @throws {AccountRequiredError} If the protocol requires a full account to perform a withdraw.
|
|
129
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
127
130
|
* @throws {ValueError} If the withdraw options are not valid.
|
|
128
131
|
* @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
|
|
129
132
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
@@ -157,6 +160,7 @@ export class ILendingProtocol {
|
|
|
157
160
|
* @param {BorrowOptions} options - The borrow's options.
|
|
158
161
|
* @returns {Promise<BorrowResult>} The borrow's result.
|
|
159
162
|
* @throws {AccountRequiredError} If the protocol requires a full account to perform a borrow.
|
|
163
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
160
164
|
* @throws {ValueError} If the borrow options are not valid.
|
|
161
165
|
* @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
|
|
162
166
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
@@ -190,6 +194,7 @@ export class ILendingProtocol {
|
|
|
190
194
|
* @param {RepayOptions} options - The repay's options.
|
|
191
195
|
* @returns {Promise<RepayResult>} The repay's result.
|
|
192
196
|
* @throws {AccountRequiredError} If the protocol requires a full account to perform a repay.
|
|
197
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
193
198
|
* @throws {ValueError} If the repay options are not valid.
|
|
194
199
|
* @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
|
|
195
200
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
@@ -253,6 +258,7 @@ export default class LendingProtocol {
|
|
|
253
258
|
* @param {SupplyOptions} options - The supply's options.
|
|
254
259
|
* @returns {Promise<SupplyResult>} The supply's result.
|
|
255
260
|
* @throws {AccountRequiredError} If the protocol requires a full account to perform a supply.
|
|
261
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
256
262
|
* @throws {ValueError} If the supply options are not valid.
|
|
257
263
|
* @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
|
|
258
264
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
@@ -287,6 +293,7 @@ export default class LendingProtocol {
|
|
|
287
293
|
* @param {WithdrawOptions} options - The withdraw's options.
|
|
288
294
|
* @returns {Promise<WithdrawResult>} The withdraw's result.
|
|
289
295
|
* @throws {AccountRequiredError} If the protocol requires a full account to perform a withdraw.
|
|
296
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
290
297
|
* @throws {ValueError} If the withdraw options are not valid.
|
|
291
298
|
* @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
|
|
292
299
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
@@ -321,6 +328,7 @@ export default class LendingProtocol {
|
|
|
321
328
|
* @param {BorrowOptions} options - The borrow's options.
|
|
322
329
|
* @returns {Promise<BorrowResult>} The borrow's result.
|
|
323
330
|
* @throws {AccountRequiredError} If the protocol requires a full account to perform a borrow.
|
|
331
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
324
332
|
* @throws {ValueError} If the borrow options are not valid.
|
|
325
333
|
* @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
|
|
326
334
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
@@ -355,6 +363,7 @@ export default class LendingProtocol {
|
|
|
355
363
|
* @param {RepayOptions} options - The borrow's options.
|
|
356
364
|
* @returns {Promise<RepayResult>} The repay's result.
|
|
357
365
|
* @throws {AccountRequiredError} If the protocol requires a full account to perform a repay.
|
|
366
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
358
367
|
* @throws {ValueError} If the repay options are not valid.
|
|
359
368
|
* @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
|
|
360
369
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
@@ -20,6 +20,7 @@ import { NotImplementedError, UnsupportedOperationError } from './errors.js'
|
|
|
20
20
|
/** @typedef {import('../wallet-account.js').IWalletAccount} IWalletAccount */
|
|
21
21
|
|
|
22
22
|
/** @typedef {import('./errors.js').AccountRequiredError} AccountRequiredError */
|
|
23
|
+
/** @typedef {import('./errors.js').DisposalError} DisposalError */
|
|
23
24
|
/** @typedef {import('./errors.js').InvalidTokenError} InvalidTokenError */
|
|
24
25
|
/** @typedef {import('./errors.js').NoSuchElementError} NoSuchElementError */
|
|
25
26
|
/** @typedef {import('./errors.js').ReadOnlyAccountRequiredError} ReadOnlyAccountRequiredError */
|
|
@@ -273,6 +274,7 @@ export class ISdaProtocol {
|
|
|
273
274
|
* @param {SdaCreateDepositAddressOptions} options - The address creation options.
|
|
274
275
|
* @returns {Promise<SdaDepositAddress[]>} The created deposit addresses, one per distinct address.
|
|
275
276
|
* @throws {AccountRequiredError} If the protocol requires a full account to create a new deposit address.
|
|
277
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
276
278
|
* @throws {ValueError} If the create deposit address options are not valid.
|
|
277
279
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
278
280
|
* @throws {ProviderError} If the provider fails to create a new deposit address.
|
|
@@ -292,6 +294,7 @@ export class ISdaProtocol {
|
|
|
292
294
|
* @returns {Promise<string>} The derived deposit address.
|
|
293
295
|
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
294
296
|
* @throws {AccountRequiredError} If the protocol requires a full account to derive a deposit address.
|
|
297
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
295
298
|
* @throws {ValueError} If the create deposit address options are not valid.
|
|
296
299
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
297
300
|
* @throws {ProviderError} If the provider fails to derive the deposit address.
|
|
@@ -325,6 +328,7 @@ export class ISdaProtocol {
|
|
|
325
328
|
* @returns {Promise<SdaDepositAddress>} The refreshed deposit address descriptor (with the new `expiry`).
|
|
326
329
|
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
327
330
|
* @throws {AccountRequiredError} If the protocol requires a full account to renew a deposit address.
|
|
331
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
328
332
|
* @throws {ValueError} If the id is not valid.
|
|
329
333
|
* @throws {NoSuchElementError} If no deposit address exists for the given id.
|
|
330
334
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
@@ -388,6 +392,7 @@ export class ISdaProtocol {
|
|
|
388
392
|
* @returns {Promise<SdaRecoveryResult>} The recovery outcome.
|
|
389
393
|
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
390
394
|
* @throws {AccountRequiredError} If the protocol requires a full account to recover a deposit address.
|
|
395
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
391
396
|
* @throws {ValueError} If the id is not valid.
|
|
392
397
|
* @throws {NoSuchElementError} If no deposit address exists for the given id or address.
|
|
393
398
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
@@ -406,6 +411,7 @@ export class ISdaProtocol {
|
|
|
406
411
|
* @returns {Promise<void>} Resolves once the address has been disabled.
|
|
407
412
|
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
408
413
|
* @throws {AccountRequiredError} If the protocol requires a full account to disable a deposit address.
|
|
414
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
409
415
|
* @throws {ValueError} If the id is not valid.
|
|
410
416
|
* @throws {NoSuchElementError} If no deposit address exists for the given id.
|
|
411
417
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
@@ -498,6 +504,7 @@ export default class SdaProtocol {
|
|
|
498
504
|
* @param {SdaCreateDepositAddressOptions} options - The address creation options.
|
|
499
505
|
* @returns {Promise<SdaDepositAddress[]>} The created deposit addresses, one per distinct address.
|
|
500
506
|
* @throws {AccountRequiredError} If the protocol requires a full account to create a new deposit address.
|
|
507
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
501
508
|
* @throws {ValueError} If the create deposit address options are not valid.
|
|
502
509
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
503
510
|
* @throws {ProviderError} If the provider fails to create a new deposit address.
|
|
@@ -517,6 +524,7 @@ export default class SdaProtocol {
|
|
|
517
524
|
* @returns {Promise<string>} The derived deposit address.
|
|
518
525
|
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
519
526
|
* @throws {AccountRequiredError} If the protocol requires a full account to derive a deposit address.
|
|
527
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
520
528
|
* @throws {ValueError} If the create deposit address options are not valid.
|
|
521
529
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
522
530
|
* @throws {ProviderError} If the provider fails to derive the deposit address.
|
|
@@ -550,6 +558,7 @@ export default class SdaProtocol {
|
|
|
550
558
|
* @returns {Promise<SdaDepositAddress>} The refreshed deposit address descriptor (with the new `expiry`).
|
|
551
559
|
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
552
560
|
* @throws {AccountRequiredError} If the protocol requires a full account to renew a deposit address.
|
|
561
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
553
562
|
* @throws {ValueError} If the id is not valid.
|
|
554
563
|
* @throws {NoSuchElementError} If no deposit address exists for the given id.
|
|
555
564
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
@@ -613,6 +622,7 @@ export default class SdaProtocol {
|
|
|
613
622
|
* @returns {Promise<SdaRecoveryResult>} The recovery outcome.
|
|
614
623
|
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
615
624
|
* @throws {AccountRequiredError} If the protocol requires a full account to recover a deposit address.
|
|
625
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
616
626
|
* @throws {ValueError} If the id is not valid.
|
|
617
627
|
* @throws {NoSuchElementError} If no deposit address exists for the given id or address.
|
|
618
628
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
@@ -631,6 +641,7 @@ export default class SdaProtocol {
|
|
|
631
641
|
* @returns {Promise<void>} Resolves once the address has been disabled.
|
|
632
642
|
* @throws {UnsupportedOperationError} If the protocol does not support this operation.
|
|
633
643
|
* @throws {AccountRequiredError} If the protocol requires a full account to disable a deposit address.
|
|
644
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
634
645
|
* @throws {ValueError} If the id is not valid.
|
|
635
646
|
* @throws {NoSuchElementError} If no deposit address exists for the given id.
|
|
636
647
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
@@ -20,6 +20,7 @@ import { NotImplementedError } from './errors.js'
|
|
|
20
20
|
/** @typedef {import('../wallet-account.js').IWalletAccount} IWalletAccount */
|
|
21
21
|
|
|
22
22
|
/** @typedef {import('./errors.js').AccountRequiredError} AccountRequiredError */
|
|
23
|
+
/** @typedef {import('./errors.js').DisposalError} DisposalError */
|
|
23
24
|
/** @typedef {import('./errors.js').InvalidTokenError} InvalidTokenError */
|
|
24
25
|
/** @typedef {import('./errors.js').MaximumFeeExceededError} MaximumFeeExceededError */
|
|
25
26
|
/** @typedef {import('./errors.js').ReadOnlyAccountRequiredError} ReadOnlyAccountRequiredError */
|
|
@@ -73,6 +74,7 @@ export class ISwapProtocol {
|
|
|
73
74
|
* @param {SwapOptions} options - The swap's options.
|
|
74
75
|
* @returns {Promise<SwapResult>} The swap's result.
|
|
75
76
|
* @throws {AccountRequiredError} If the protocol requires a full account to perform a swap.
|
|
77
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
76
78
|
* @throws {ValueError} If the swap options are not valid.
|
|
77
79
|
* @throws {InvalidTokenError} If the input or output tokens are not valid ERC 20 token's addresses.
|
|
78
80
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
@@ -146,6 +148,7 @@ export default class SwapProtocol {
|
|
|
146
148
|
* @param {SwapOptions} options - The swap's options.
|
|
147
149
|
* @returns {Promise<SwapResult>} The swap's result.
|
|
148
150
|
* @throws {AccountRequiredError} If the protocol requires a full account to perform a swap.
|
|
151
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
149
152
|
* @throws {ValueError} If the swap options are not valid.
|
|
150
153
|
* @throws {InvalidTokenError} If the input or output tokens are not valid ERC 20 token's addresses.
|
|
151
154
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
@@ -28,6 +28,7 @@ import { BridgeError, NotImplementedError, SwapError, SwidgeError } from './erro
|
|
|
28
28
|
/** @typedef {import('./bridge-protocol.js').BridgeResult} BridgeResult */
|
|
29
29
|
|
|
30
30
|
/** @typedef {import('./errors.js').AccountRequiredError} AccountRequiredError */
|
|
31
|
+
/** @typedef {import('./errors.js').DisposalError} DisposalError */
|
|
31
32
|
/** @typedef {import('./errors.js').InvalidTokenError} InvalidTokenError */
|
|
32
33
|
/** @typedef {import('./errors.js').MaximumFeeExceededError} MaximumFeeExceededError */
|
|
33
34
|
/** @typedef {import('./errors.js').NoSuchElementError} NoSuchElementError */
|
|
@@ -189,6 +190,7 @@ export class ISwidgeProtocol {
|
|
|
189
190
|
* @param {SwidgeProtocolConfig} [config] - Optional provider-specific execution configuration.
|
|
190
191
|
* @returns {Promise<SwidgeResult>} The swidge execution result.
|
|
191
192
|
* @throws {AccountRequiredError} If the protocol requires a full account to perform a swidge.
|
|
193
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
192
194
|
* @throws {ValueError} If the swidge options are not valid.
|
|
193
195
|
* @throws {InvalidTokenError} If the from or to tokens are not valid ERC 20 token's addresses.
|
|
194
196
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
@@ -293,6 +295,7 @@ export default class SwidgeProtocol {
|
|
|
293
295
|
* @param {SwapOptions} options - The swap's options.
|
|
294
296
|
* @returns {Promise<SwapResult>} The swap's result.
|
|
295
297
|
* @throws {AccountRequiredError} If the protocol requires a full account to perform a swap.
|
|
298
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
296
299
|
* @throws {ValueError} If the swap options are not valid.
|
|
297
300
|
* @throws {InvalidTokenError} If the input or output tokens are not valid ERC 20 token's addresses.
|
|
298
301
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
@@ -364,6 +367,7 @@ export default class SwidgeProtocol {
|
|
|
364
367
|
* @param {BridgeOptions} options - The bridge's options.
|
|
365
368
|
* @returns {Promise<BridgeResult>} The bridge's result.
|
|
366
369
|
* @throws {AccountRequiredError} If the protocol requires a full account to perform a bridge.
|
|
370
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
367
371
|
* @throws {ValueError} If the bridge options are not valid.
|
|
368
372
|
* @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
|
|
369
373
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
@@ -462,6 +466,7 @@ export default class SwidgeProtocol {
|
|
|
462
466
|
* @param {SwidgeProtocolConfig} [config] - Optional provider-specific execution configuration.
|
|
463
467
|
* @returns {Promise<SwidgeResult>} The swidge execution result.
|
|
464
468
|
* @throws {AccountRequiredError} If the protocol requires a full account to perform a swidge.
|
|
469
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
465
470
|
* @throws {ValueError} If the swidge options are not valid.
|
|
466
471
|
* @throws {InvalidTokenError} If the from or to tokens are not valid ERC 20 token's addresses.
|
|
467
472
|
* @throws {ProviderRequiredError} If the method requires a provider.
|
package/src/signer.js
CHANGED
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
|
|
16
16
|
import { NotImplementedError } from './errors.js'
|
|
17
17
|
|
|
18
|
+
import { IDisposable } from './disposable.js'
|
|
19
|
+
|
|
20
|
+
/** @typedef {import('./wallet-account.js').KeyPair} KeyPair */
|
|
21
|
+
/** @typedef {import('./errors.js').DisposalError} DisposalError */
|
|
18
22
|
/** @typedef {import('./errors.js').UnsupportedOperationError} UnsupportedOperationError */
|
|
19
23
|
/** @typedef {import('./errors.js').ValueError} ValueError */
|
|
20
24
|
|
|
@@ -23,7 +27,36 @@ import { NotImplementedError } from './errors.js'
|
|
|
23
27
|
*
|
|
24
28
|
* @interface
|
|
25
29
|
*/
|
|
26
|
-
export class ISigner {
|
|
30
|
+
export class ISigner extends IDisposable {
|
|
31
|
+
/**
|
|
32
|
+
* Whether the signer supports account derivation via {@link derive}.
|
|
33
|
+
*
|
|
34
|
+
* @type {boolean}
|
|
35
|
+
*/
|
|
36
|
+
get isDerivable () {
|
|
37
|
+
throw new NotImplementedError('isDerivable')
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The signer's key pair, or null if the signer does not allow retrieving
|
|
42
|
+
* key material (e.g. hardware signers).
|
|
43
|
+
*
|
|
44
|
+
* @type {KeyPair | null}
|
|
45
|
+
*/
|
|
46
|
+
get keyPair () {
|
|
47
|
+
throw new NotImplementedError('keyPair')
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The BIP 0032 derivation path, or null if the signer is not bound to a derivation position
|
|
52
|
+
* (e.g. private-key signers).
|
|
53
|
+
*
|
|
54
|
+
* @type {string | null}
|
|
55
|
+
*/
|
|
56
|
+
get path () {
|
|
57
|
+
throw new NotImplementedError('path')
|
|
58
|
+
}
|
|
59
|
+
|
|
27
60
|
/**
|
|
28
61
|
* Derive a child signer using a relative path (e.g., "0'/0/0").
|
|
29
62
|
*
|
|
@@ -31,6 +64,7 @@ export class ISigner {
|
|
|
31
64
|
* @returns {Promise<ISigner>} The derived signer.
|
|
32
65
|
* @throws {UnsupportedOperationError} If the signer does not support account derivation.
|
|
33
66
|
* @throws {ValueError} If the path is not valid.
|
|
67
|
+
* @throws {DisposalError} If the signer has been disposed.
|
|
34
68
|
*/
|
|
35
69
|
async derive (path) {
|
|
36
70
|
throw new NotImplementedError('derive(path)')
|
|
@@ -46,9 +80,13 @@ export class ISigner {
|
|
|
46
80
|
}
|
|
47
81
|
|
|
48
82
|
/**
|
|
49
|
-
*
|
|
83
|
+
* Signs a message.
|
|
84
|
+
*
|
|
85
|
+
* @param {string} message - The message to sign.
|
|
86
|
+
* @returns {Promise<string>} The message's signature.
|
|
87
|
+
* @throws {DisposalError} If the signer has been disposed.
|
|
50
88
|
*/
|
|
51
|
-
|
|
52
|
-
throw new NotImplementedError('
|
|
89
|
+
async sign (message) {
|
|
90
|
+
throw new NotImplementedError('sign(message)')
|
|
53
91
|
}
|
|
54
92
|
}
|
package/src/wallet-account.js
CHANGED
|
@@ -13,16 +13,16 @@
|
|
|
13
13
|
// limitations under the License.
|
|
14
14
|
'use strict'
|
|
15
15
|
|
|
16
|
-
import { IWalletAccountReadOnly } from './wallet-account-read-only.js'
|
|
17
|
-
|
|
18
16
|
import { NotImplementedError } from './errors.js'
|
|
19
17
|
|
|
18
|
+
/** @typedef {import('./wallet-account-read-only.js').IWalletAccountReadOnly} IWalletAccountReadOnly */
|
|
20
19
|
/** @typedef {import('./wallet-account-read-only.js').Transaction} Transaction */
|
|
21
20
|
/** @typedef {import('./wallet-account-read-only.js').TransactionResult} TransactionResult */
|
|
22
21
|
|
|
23
22
|
/** @typedef {import('./wallet-account-read-only.js').TransferOptions} TransferOptions */
|
|
24
23
|
/** @typedef {import('./wallet-account-read-only.js').TransferResult} TransferResult */
|
|
25
24
|
|
|
25
|
+
/** @typedef {import('./errors.js').DisposalError} DisposalError */
|
|
26
26
|
/** @typedef {import('./errors.js').InvalidTokenError} InvalidTokenError */
|
|
27
27
|
/** @typedef {import('./errors.js').MaximumFeeExceededError} MaximumFeeExceededError */
|
|
28
28
|
/** @typedef {import('./errors.js').ProviderError} ProviderError */
|
|
@@ -37,33 +37,30 @@ import { NotImplementedError } from './errors.js'
|
|
|
37
37
|
* @property {Uint8Array | null} privateKey - The private key (null if the account has been disposed).
|
|
38
38
|
*/
|
|
39
39
|
|
|
40
|
+
/** @typedef {import('./disposable.js').IDisposable} IDisposable */
|
|
41
|
+
|
|
40
42
|
/**
|
|
41
43
|
* @interface
|
|
44
|
+
* @extends {IWalletAccountReadOnly}
|
|
45
|
+
* @extends {IDisposable}
|
|
42
46
|
* @template [TSignedTransaction=unknown]
|
|
43
47
|
*/
|
|
44
|
-
export class IWalletAccount
|
|
48
|
+
export class IWalletAccount {
|
|
45
49
|
/**
|
|
46
|
-
* The derivation path
|
|
50
|
+
* The derivation path of this account (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)),
|
|
51
|
+
* or null if the account's signer is not bound to a BIP-44 position (e.g. private-key signers).
|
|
47
52
|
*
|
|
48
|
-
* @type {
|
|
49
|
-
*/
|
|
50
|
-
get index () {
|
|
51
|
-
throw new NotImplementedError('index')
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* The derivation path of this account (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)).
|
|
56
|
-
*
|
|
57
|
-
* @type {string}
|
|
53
|
+
* @type {string | null}
|
|
58
54
|
*/
|
|
59
55
|
get path () {
|
|
60
56
|
throw new NotImplementedError('path')
|
|
61
57
|
}
|
|
62
58
|
|
|
63
59
|
/**
|
|
64
|
-
* The account's key pair
|
|
60
|
+
* The account's key pair, or null if the account's signer does not allow
|
|
61
|
+
* retrieving key material (e.g. hardware signers).
|
|
65
62
|
*
|
|
66
|
-
* @type {KeyPair}
|
|
63
|
+
* @type {KeyPair | null}
|
|
67
64
|
*/
|
|
68
65
|
get keyPair () {
|
|
69
66
|
throw new NotImplementedError('keyPair')
|
|
@@ -74,6 +71,7 @@ export class IWalletAccount extends IWalletAccountReadOnly {
|
|
|
74
71
|
*
|
|
75
72
|
* @param {string} message - The message to sign.
|
|
76
73
|
* @returns {Promise<string>} The message's signature.
|
|
74
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
77
75
|
*/
|
|
78
76
|
async sign (message) {
|
|
79
77
|
throw new NotImplementedError('sign(message)')
|
|
@@ -85,6 +83,7 @@ export class IWalletAccount extends IWalletAccountReadOnly {
|
|
|
85
83
|
* @param {Transaction} tx - The transaction to sign.
|
|
86
84
|
* @returns {Promise<TSignedTransaction>} The signed transaction.
|
|
87
85
|
* @throws {ValueError} If the transaction is not valid.
|
|
86
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
88
87
|
*/
|
|
89
88
|
async signTransaction (tx) {
|
|
90
89
|
throw new NotImplementedError('signTransaction(tx)')
|
|
@@ -111,6 +110,7 @@ export class IWalletAccount extends IWalletAccountReadOnly {
|
|
|
111
110
|
* @throws {ProviderError} If the provider fails to perform the transaction.
|
|
112
111
|
* @throws {TransactionError} If the transaction fails with an error.
|
|
113
112
|
* @throws {MaximumFeeExceededError} If the the costs of the transaction exceeds the transaction max. fee option.
|
|
113
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
114
114
|
*/
|
|
115
115
|
async sendTransaction (tx) {
|
|
116
116
|
throw new NotImplementedError('sendTransaction(tx)')
|
|
@@ -141,6 +141,7 @@ export class IWalletAccount extends IWalletAccountReadOnly {
|
|
|
141
141
|
* @throws {ProviderError} If the provider fails to perform the transfer.
|
|
142
142
|
* @throws {TransferError} If the transfer fails with an error.
|
|
143
143
|
* @throws {MaximumFeeExceededError} If the the costs of the transfer exceeds the transfer max. fee option.
|
|
144
|
+
* @throws {DisposalError} If the account has been disposed.
|
|
144
145
|
*/
|
|
145
146
|
async transfer (options) {
|
|
146
147
|
throw new NotImplementedError('transfer(options)')
|
|
@@ -154,11 +155,4 @@ export class IWalletAccount extends IWalletAccountReadOnly {
|
|
|
154
155
|
async toReadOnlyAccount () {
|
|
155
156
|
throw new NotImplementedError('toReadOnlyAccount()')
|
|
156
157
|
}
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* Disposes the wallet account, erasing the private key from the memory.
|
|
160
|
-
*/
|
|
161
|
-
dispose () {
|
|
162
|
-
throw new NotImplementedError('dispose()')
|
|
163
|
-
}
|
|
164
158
|
}
|