@tetherto/wdk-wallet 1.0.0-beta.2 → 1.0.0-beta.21
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/AGENTS.md +49 -0
- package/README.md +2 -2
- package/bare.js +3 -3
- package/index.js +14 -2
- package/package.json +18 -4
- package/src/disposable.js +26 -0
- package/src/errors.js +318 -3
- package/src/multisig/errors.js +54 -0
- package/src/multisig/index.js +42 -0
- package/src/multisig/multisig-message-signing-read-only.js +63 -0
- package/src/multisig/multisig-message-signing.js +64 -0
- package/src/multisig/multisig-owner-management.js +94 -0
- package/src/multisig/wallet-account-multisig.js +144 -0
- package/src/multisig/wallet-account-read-only-multisig.js +98 -0
- package/src/protocols/bridge-protocol.js +35 -1
- package/src/protocols/errors.js +510 -0
- package/src/protocols/fiat-protocol.js +401 -0
- package/src/protocols/index.js +76 -0
- package/src/protocols/lending-protocol.js +114 -2
- package/src/protocols/sda-protocol.js +643 -0
- package/src/protocols/swap-protocol.js +36 -1
- package/src/protocols/swidge-protocol.js +516 -0
- package/src/signer.js +89 -0
- package/src/wallet-account-read-only-simple.js +162 -0
- package/src/wallet-account-read-only.js +186 -40
- package/src/wallet-account.js +59 -22
- package/src/wallet-manager.js +152 -25
- package/types/index.d.ts +13 -4
- package/types/src/disposable.d.ts +7 -0
- package/types/src/errors.d.ts +220 -2
- package/types/src/multisig/errors.d.ts +33 -0
- package/types/src/multisig/index.d.ts +15 -0
- package/types/src/multisig/multisig-message-signing-read-only.d.ts +53 -0
- package/types/src/multisig/multisig-message-signing.d.ts +40 -0
- package/types/src/multisig/multisig-owner-management.d.ts +65 -0
- package/types/src/multisig/wallet-account-multisig.d.ts +101 -0
- package/types/src/multisig/wallet-account-read-only-multisig.d.ts +83 -0
- package/types/src/protocols/bridge-protocol.d.ts +39 -3
- package/types/src/protocols/errors.d.ts +366 -0
- package/types/src/protocols/fiat-protocol.d.ts +409 -0
- package/types/src/protocols/index.d.ts +64 -0
- package/types/src/protocols/lending-protocol.d.ts +118 -4
- package/types/src/protocols/sda-protocol.d.ts +737 -0
- package/types/src/protocols/swap-protocol.d.ts +44 -4
- package/types/src/protocols/swidge-protocol.d.ts +483 -0
- package/types/src/signer.d.ts +53 -0
- package/types/src/wallet-account-read-only-simple.d.ts +144 -0
- package/types/src/wallet-account-read-only.d.ts +104 -27
- package/types/src/wallet-account.d.ts +55 -20
- package/types/src/wallet-manager.d.ts +109 -17
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The read-only members shared by every wallet account, single-signer or multisig.
|
|
3
|
+
*
|
|
4
|
+
* This is an internal base interface: it is not exported from the package entry point.
|
|
5
|
+
* Consumers use {@link IWalletAccountReadOnly} or {@link IWalletAccountReadOnlyMultisig},
|
|
6
|
+
* which both extend it.
|
|
7
|
+
*
|
|
8
|
+
* @interface
|
|
9
|
+
*/
|
|
10
|
+
export interface IWalletAccountReadOnlySimple {
|
|
11
|
+
/**
|
|
12
|
+
* Returns the account's address.
|
|
13
|
+
*
|
|
14
|
+
* @returns {Promise<string>} The account's address.
|
|
15
|
+
*/
|
|
16
|
+
getAddress(): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Verifies a message's signature.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} message - The original message.
|
|
21
|
+
* @param {string} signature - The signature to verify.
|
|
22
|
+
* @returns {Promise<boolean>} True if the signature is valid.
|
|
23
|
+
* @throws {UnsupportedOperationError} If the read-only wallet account class is not able to provide an implementation for the method.
|
|
24
|
+
*/
|
|
25
|
+
verify(message: string, signature: string): Promise<boolean>;
|
|
26
|
+
/**
|
|
27
|
+
* Returns the account's native token balance.
|
|
28
|
+
*
|
|
29
|
+
* @returns {Promise<bigint>} The native token balance.
|
|
30
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
31
|
+
* @throws {ProviderError} If the provider fails to fetch the account's balance.
|
|
32
|
+
*/
|
|
33
|
+
getBalance(): Promise<bigint>;
|
|
34
|
+
/**
|
|
35
|
+
* Returns the account balance for a specific token.
|
|
36
|
+
*
|
|
37
|
+
* @param {string} tokenAddress - The smart contract address of the token.
|
|
38
|
+
* @returns {Promise<bigint>} The token balance.
|
|
39
|
+
* @throws {ValueError} If the token's address is not valid.
|
|
40
|
+
* @throws {InvalidTokenError} If the token's address doesn't match an existing ERC 20 token.
|
|
41
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
42
|
+
* @throws {ProviderError} If the provider fails to fetch the account's token balance.
|
|
43
|
+
*/
|
|
44
|
+
getTokenBalance(tokenAddress: string): Promise<bigint>;
|
|
45
|
+
/**
|
|
46
|
+
* Returns a transaction's receipt.
|
|
47
|
+
*
|
|
48
|
+
* @deprecated Use {@link getTransaction} instead, which returns a normalized, finality-based receipt. The native receipt fields remain available on each module's extended return type.
|
|
49
|
+
* @param {string} hash - The transaction's hash.
|
|
50
|
+
* @returns {Promise<unknown | null>} The receipt, or null if the transaction has not been included in a block yet.
|
|
51
|
+
* @throws {ValueError} If the hash is not valid.
|
|
52
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
53
|
+
* @throws {ProviderError} If the provider fails to fetch the transaction's receipt.
|
|
54
|
+
*/
|
|
55
|
+
getTransactionReceipt(hash: string): Promise<unknown | null>;
|
|
56
|
+
/**
|
|
57
|
+
* Returns a normalized, finality-based receipt for a transaction.
|
|
58
|
+
*
|
|
59
|
+
* @param {string} hash - The transaction's identifier (hash / signature / lt:hash).
|
|
60
|
+
* @returns {Promise<TransactionReceipt>} The normalized receipt.
|
|
61
|
+
* @throws {ValueError} If the hash is not a valid identifier.
|
|
62
|
+
* @throws {NoSuchElementError} If no transaction has been found for the given hash.
|
|
63
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
64
|
+
* @throws {ProviderError} If the provider fails to fetch the transaction.
|
|
65
|
+
*/
|
|
66
|
+
getTransaction(hash: string): Promise<TransactionReceipt>;
|
|
67
|
+
/**
|
|
68
|
+
* Blocks until a transaction reaches a terminal state (the requested finality target or `dropped`), or times out.
|
|
69
|
+
*
|
|
70
|
+
* @param {string} hash - The transaction's identifier.
|
|
71
|
+
* @param {WaitForTransactionOptions} [options] - The wait options.
|
|
72
|
+
* @returns {Promise<TransactionReceipt>} The terminal receipt: the finality target reached (inspect `success` to tell success from revert), or `dropped`.
|
|
73
|
+
* @throws {ValueError} If the hash is not a valid identifier.
|
|
74
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
75
|
+
* @throws {ProviderError} If the provider fails to fetch the transaction.
|
|
76
|
+
* @throws {TimeoutError} If the operation times out.
|
|
77
|
+
*/
|
|
78
|
+
waitForTransaction(hash: string, options?: WaitForTransactionOptions): Promise<TransactionReceipt>;
|
|
79
|
+
}
|
|
80
|
+
export type InvalidTokenError = import("./errors.js").InvalidTokenError;
|
|
81
|
+
export type NoSuchElementError = import("./errors.js").NoSuchElementError;
|
|
82
|
+
export type ProviderError = import("./errors.js").ProviderError;
|
|
83
|
+
export type ProviderRequiredError = import("./errors.js").ProviderRequiredError;
|
|
84
|
+
export type TimeoutError = import("./errors.js").TimeoutError;
|
|
85
|
+
export type ValueError = import("./errors.js").ValueError;
|
|
86
|
+
export type UnsupportedOperationError = import("./errors.js").UnsupportedOperationError;
|
|
87
|
+
/**
|
|
88
|
+
* A normalized, cross-chain transaction finality level.
|
|
89
|
+
*
|
|
90
|
+
* - `pending`: seen, not settled (mempool / processed / in-flight).
|
|
91
|
+
* - `confirmed`: settled, reversible only under extreme conditions.
|
|
92
|
+
* - `final`: irreversible per the chain's own guarantees.
|
|
93
|
+
* - `dropped`: evicted / replaced, never landed.
|
|
94
|
+
*/
|
|
95
|
+
export type Finality = "pending" | "confirmed" | "final" | "dropped";
|
|
96
|
+
/**
|
|
97
|
+
* A normalized, cross-chain transaction receipt. Blockchain modules extend this
|
|
98
|
+
* type with their own native receipt fields (e.g. `confirmations`, the raw
|
|
99
|
+
* transaction and receipt objects, etc.).
|
|
100
|
+
*/
|
|
101
|
+
export type TransactionReceipt = {
|
|
102
|
+
/**
|
|
103
|
+
* - The transaction's identifier (hash / signature / lt:hash).
|
|
104
|
+
*/
|
|
105
|
+
hash: string;
|
|
106
|
+
/**
|
|
107
|
+
* - The transaction's finality level.
|
|
108
|
+
*/
|
|
109
|
+
finality: Finality;
|
|
110
|
+
/**
|
|
111
|
+
* - The execution's result (not set if the transaction is still pending or it has been dropped).
|
|
112
|
+
*/
|
|
113
|
+
success?: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* - A reference to the including block (block number / height / slot / masterchain seqno).
|
|
116
|
+
*/
|
|
117
|
+
block?: number;
|
|
118
|
+
/**
|
|
119
|
+
* - The fee paid, when known.
|
|
120
|
+
*/
|
|
121
|
+
fee?: bigint;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* The finality level to wait for.
|
|
125
|
+
*/
|
|
126
|
+
export type WaitForTransactionTarget = "confirmed" | "final";
|
|
127
|
+
export type WaitForTransactionOptions = {
|
|
128
|
+
/**
|
|
129
|
+
* - The finality target to wait for (default: 'confirmed').
|
|
130
|
+
*/
|
|
131
|
+
target?: WaitForTransactionTarget;
|
|
132
|
+
/**
|
|
133
|
+
* - The total time budget in milliseconds before giving up. If omitted, the account's `defaultWaitTimeout` is used.
|
|
134
|
+
*/
|
|
135
|
+
timeout?: number;
|
|
136
|
+
/**
|
|
137
|
+
* - The poll cadence in milliseconds. If omitted, the account's `defaultWaitInterval` is used.
|
|
138
|
+
*/
|
|
139
|
+
interval?: number;
|
|
140
|
+
/**
|
|
141
|
+
* - How many consecutive getTransaction() failures to tolerate before rethrowing (default: 3).
|
|
142
|
+
*/
|
|
143
|
+
maxPollErrors?: number;
|
|
144
|
+
};
|
|
@@ -1,29 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enum that assigns a comparable ordinal to each finality level, used to check
|
|
3
|
+
* whether an observed finality satisfies a requested target.
|
|
4
|
+
*/
|
|
5
|
+
export type FINALITY = number;
|
|
6
|
+
export namespace FINALITY {
|
|
7
|
+
let pending: number;
|
|
8
|
+
let dropped: number;
|
|
9
|
+
let confirmed: number;
|
|
10
|
+
let final: number;
|
|
11
|
+
}
|
|
1
12
|
/** @interface */
|
|
2
|
-
export interface IWalletAccountReadOnly {
|
|
3
|
-
/**
|
|
4
|
-
* Returns the account's address.
|
|
5
|
-
*
|
|
6
|
-
* @returns {Promise<string>} The account's address.
|
|
7
|
-
*/
|
|
8
|
-
getAddress(): Promise<string>;
|
|
9
|
-
/**
|
|
10
|
-
* Returns the account's native token balance.
|
|
11
|
-
*
|
|
12
|
-
* @returns {Promise<bigint>} The native token balance.
|
|
13
|
-
*/
|
|
14
|
-
getBalance(): Promise<bigint>;
|
|
15
|
-
/**
|
|
16
|
-
* Returns the account balance for a specific token.
|
|
17
|
-
*
|
|
18
|
-
* @param {string} tokenAddress - The smart contract address of the token.
|
|
19
|
-
* @returns {Promise<bigint>} The token balance.
|
|
20
|
-
*/
|
|
21
|
-
getTokenBalance(tokenAddress: string): Promise<bigint>;
|
|
13
|
+
export interface IWalletAccountReadOnly extends IWalletAccountReadOnlySimple {
|
|
22
14
|
/**
|
|
23
15
|
* Quotes the costs of a send transaction operation.
|
|
24
16
|
*
|
|
25
17
|
* @param {Transaction} tx - The transaction.
|
|
26
18
|
* @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
|
|
19
|
+
* @throws {ValueError} If the transaction is not valid.
|
|
20
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
21
|
+
* @throws {ProviderError} If the provider fails to estimate the costs of the transaction.
|
|
22
|
+
* @throws {TransactionError} If the transaction fails with an error.
|
|
27
23
|
*/
|
|
28
24
|
quoteSendTransaction(tx: Transaction): Promise<Omit<TransactionResult, "hash">>;
|
|
29
25
|
/**
|
|
@@ -31,15 +27,13 @@ export interface IWalletAccountReadOnly {
|
|
|
31
27
|
*
|
|
32
28
|
* @param {TransferOptions} options - The transfer's options.
|
|
33
29
|
* @returns {Promise<Omit<TransferResult, 'hash'>>} The transfer's quotes.
|
|
30
|
+
* @throws {ValueError} If the transfer options are not valid.
|
|
31
|
+
* @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
|
|
32
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
33
|
+
* @throws {ProviderError} If the provider fails to estimate the costs of the transfer.
|
|
34
|
+
* @throws {TransferError} If the transfer fails with an error.
|
|
34
35
|
*/
|
|
35
36
|
quoteTransfer(options: TransferOptions): Promise<Omit<TransferResult, "hash">>;
|
|
36
|
-
/**
|
|
37
|
-
* Returns a transaction's receipt.
|
|
38
|
-
*
|
|
39
|
-
* @param {string} hash - The transaction's hash.
|
|
40
|
-
* @returns {Promise<unknown | null>} The receipt, or null if the transaction has not been included in a block yet.
|
|
41
|
-
*/
|
|
42
|
-
getTransactionReceipt(hash: string): Promise<unknown | null>;
|
|
43
37
|
}
|
|
44
38
|
/**
|
|
45
39
|
* @abstract
|
|
@@ -52,6 +46,22 @@ export default abstract class WalletAccountReadOnly implements IWalletAccountRea
|
|
|
52
46
|
* @param {string} [address] - The account's address.
|
|
53
47
|
*/
|
|
54
48
|
constructor(address?: string);
|
|
49
|
+
/**
|
|
50
|
+
* The default poll cadence for {@link waitForTransaction}, in milliseconds,
|
|
51
|
+
* applied when the caller doesn't provide an `interval`. Subclasses override
|
|
52
|
+
* it to match their chain's block time.
|
|
53
|
+
*
|
|
54
|
+
* @type {number}
|
|
55
|
+
*/
|
|
56
|
+
get defaultWaitInterval(): number;
|
|
57
|
+
/**
|
|
58
|
+
* The default time budget for {@link waitForTransaction}, in milliseconds,
|
|
59
|
+
* applied when the caller doesn't provide a `timeout`. Subclasses override it
|
|
60
|
+
* to match their chain's finality expectations.
|
|
61
|
+
*
|
|
62
|
+
* @type {number}
|
|
63
|
+
*/
|
|
64
|
+
get defaultWaitTimeout(): number;
|
|
55
65
|
/** @private */
|
|
56
66
|
private __address;
|
|
57
67
|
/**
|
|
@@ -67,11 +77,22 @@ export default abstract class WalletAccountReadOnly implements IWalletAccountRea
|
|
|
67
77
|
* @returns {Promise<string>} The account's address.
|
|
68
78
|
*/
|
|
69
79
|
getAddress(): Promise<string>;
|
|
80
|
+
/**
|
|
81
|
+
* Verifies a message's signature.
|
|
82
|
+
*
|
|
83
|
+
* @param {string} message - The original message.
|
|
84
|
+
* @param {string} signature - The signature to verify.
|
|
85
|
+
* @returns {Promise<boolean>} True if the signature is valid.
|
|
86
|
+
* @throws {UnsupportedOperationError} If the read-only wallet account class is not able to provide an implementation for the method.
|
|
87
|
+
*/
|
|
88
|
+
verify(message: string, signature: string): Promise<boolean>;
|
|
70
89
|
/**
|
|
71
90
|
* Returns the account's native token balance.
|
|
72
91
|
*
|
|
73
92
|
* @abstract
|
|
74
93
|
* @returns {Promise<bigint>} The native token balance.
|
|
94
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
95
|
+
* @throws {ProviderError} If the provider fails to fetch the account's balance.
|
|
75
96
|
*/
|
|
76
97
|
abstract getBalance(): Promise<bigint>;
|
|
77
98
|
/**
|
|
@@ -80,6 +101,10 @@ export default abstract class WalletAccountReadOnly implements IWalletAccountRea
|
|
|
80
101
|
* @abstract
|
|
81
102
|
* @param {string} tokenAddress - The smart contract address of the token.
|
|
82
103
|
* @returns {Promise<bigint>} The token balance.
|
|
104
|
+
* @throws {ValueError} If the token's address is not valid.
|
|
105
|
+
* @throws {InvalidTokenError} If the token's address doesn't match an existing ERC 20 token.
|
|
106
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
107
|
+
* @throws {ProviderError} If the provider fails to fetch the account's token balance.
|
|
83
108
|
*/
|
|
84
109
|
abstract getTokenBalance(tokenAddress: string): Promise<bigint>;
|
|
85
110
|
/**
|
|
@@ -88,6 +113,10 @@ export default abstract class WalletAccountReadOnly implements IWalletAccountRea
|
|
|
88
113
|
* @abstract
|
|
89
114
|
* @param {Transaction} tx - The transaction.
|
|
90
115
|
* @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
|
|
116
|
+
* @throws {ValueError} If the transaction is not valid.
|
|
117
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
118
|
+
* @throws {ProviderError} If the provider fails to estimate the costs of the transaction.
|
|
119
|
+
* @throws {TransactionError} If the transaction fails with an error.
|
|
91
120
|
*/
|
|
92
121
|
abstract quoteSendTransaction(tx: Transaction): Promise<Omit<TransactionResult, "hash">>;
|
|
93
122
|
/**
|
|
@@ -96,17 +125,64 @@ export default abstract class WalletAccountReadOnly implements IWalletAccountRea
|
|
|
96
125
|
* @abstract
|
|
97
126
|
* @param {TransferOptions} options - The transfer's options.
|
|
98
127
|
* @returns {Promise<Omit<TransferResult, 'hash'>>} The transfer's quotes.
|
|
128
|
+
* @throws {ValueError} If the transfer options are not valid.
|
|
129
|
+
* @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
|
|
130
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
131
|
+
* @throws {ProviderError} If the provider fails to estimate the costs of the transfer.
|
|
132
|
+
* @throws {TransferError} If the transfer fails with an error.
|
|
99
133
|
*/
|
|
100
134
|
abstract quoteTransfer(options: TransferOptions): Promise<Omit<TransferResult, "hash">>;
|
|
101
135
|
/**
|
|
102
136
|
* Returns a transaction's receipt.
|
|
103
137
|
*
|
|
138
|
+
* @deprecated Use {@link getTransaction} instead, which returns a normalized, finality-based receipt. The native receipt fields remain available on each module's extended return type.
|
|
104
139
|
* @abstract
|
|
105
140
|
* @param {string} hash - The transaction's hash.
|
|
106
141
|
* @returns {Promise<unknown | null>} The receipt, or null if the transaction has not been included in a block yet.
|
|
142
|
+
* @throws {ValueError} If the hash is not valid.
|
|
143
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
144
|
+
* @throws {ProviderError} If the provider fails to fetch the transaction's receipt.
|
|
107
145
|
*/
|
|
108
146
|
abstract getTransactionReceipt(hash: string): Promise<unknown | null>;
|
|
147
|
+
/**
|
|
148
|
+
* Returns a normalized, finality-based receipt for a transaction.
|
|
149
|
+
*
|
|
150
|
+
* @abstract
|
|
151
|
+
* @param {string} hash - The transaction's identifier (hash / signature / lt:hash).
|
|
152
|
+
* @returns {Promise<TransactionReceipt>} The normalized receipt.
|
|
153
|
+
* @throws {ValueError} If the hash is not a valid identifier.
|
|
154
|
+
* @throws {NoSuchElementError} If no transaction has been found for the given hash.
|
|
155
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
156
|
+
* @throws {ProviderError} If the provider fails to fetch the transaction.
|
|
157
|
+
*/
|
|
158
|
+
abstract getTransaction(hash: string): Promise<TransactionReceipt>;
|
|
159
|
+
/**
|
|
160
|
+
* Blocks until a transaction reaches a terminal state (the requested finality
|
|
161
|
+
* target or `dropped`), or times out.
|
|
162
|
+
*
|
|
163
|
+
* The polling loop and target resolution are chain-agnostic: this method only
|
|
164
|
+
* interprets the normalized receipt returned by {@link getTransaction}. A
|
|
165
|
+
* {@link NoSuchElementError} is treated as a transient not-found, so the loop
|
|
166
|
+
* keeps polling until the timeout.
|
|
167
|
+
*
|
|
168
|
+
* @param {string} hash - The transaction's identifier.
|
|
169
|
+
* @param {WaitForTransactionOptions} [options] - The wait options.
|
|
170
|
+
* @returns {Promise<TransactionReceipt>} The terminal receipt: the finality target reached (inspect `success` to tell success from revert), or `dropped`.
|
|
171
|
+
* @throws {ValueError} If the hash is not a valid identifier.
|
|
172
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
173
|
+
* @throws {ProviderError} If the provider fails to fetch the transaction.
|
|
174
|
+
* @throws {TimeoutError} If the operation times out.
|
|
175
|
+
*/
|
|
176
|
+
waitForTransaction(hash: string, options?: WaitForTransactionOptions): Promise<TransactionReceipt>;
|
|
109
177
|
}
|
|
178
|
+
export type Finality = import("./wallet-account-read-only-simple.js").Finality;
|
|
179
|
+
export type TransactionReceipt = import("./wallet-account-read-only-simple.js").TransactionReceipt;
|
|
180
|
+
export type WaitForTransactionOptions = import("./wallet-account-read-only-simple.js").WaitForTransactionOptions;
|
|
181
|
+
export type InvalidTokenError = import("./errors.js").InvalidTokenError;
|
|
182
|
+
export type ProviderRequiredError = import("./errors.js").ProviderRequiredError;
|
|
183
|
+
export type TransactionError = import("./errors.js").TransactionError;
|
|
184
|
+
export type TransferError = import("./errors.js").TransferError;
|
|
185
|
+
export type ValueError = import("./errors.js").ValueError;
|
|
110
186
|
export type Transaction = {
|
|
111
187
|
/**
|
|
112
188
|
* - The transaction's recipient.
|
|
@@ -151,3 +227,4 @@ export type TransferResult = {
|
|
|
151
227
|
*/
|
|
152
228
|
fee: bigint;
|
|
153
229
|
};
|
|
230
|
+
import { IWalletAccountReadOnlySimple } from './wallet-account-read-only-simple.js';
|
|
@@ -1,23 +1,24 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @interface
|
|
3
|
+
* @extends {IWalletAccountReadOnly}
|
|
4
|
+
* @extends {IDisposable}
|
|
5
|
+
* @template [TSignedTransaction=unknown]
|
|
6
|
+
*/
|
|
7
|
+
export interface IWalletAccount<TSignedTransaction = unknown> extends IWalletAccountReadOnly, IDisposable {
|
|
3
8
|
/**
|
|
4
|
-
* The derivation path
|
|
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).
|
|
5
11
|
*
|
|
6
|
-
* @type {
|
|
12
|
+
* @type {string | null}
|
|
7
13
|
*/
|
|
8
|
-
get
|
|
14
|
+
get path(): string | null;
|
|
9
15
|
/**
|
|
10
|
-
* The
|
|
16
|
+
* The account's key pair, or null if the account's signer does not allow
|
|
17
|
+
* retrieving key material (e.g. hardware signers).
|
|
11
18
|
*
|
|
12
|
-
* @type {
|
|
19
|
+
* @type {KeyPair | null}
|
|
13
20
|
*/
|
|
14
|
-
get
|
|
15
|
-
/**
|
|
16
|
-
* The account's key pair.
|
|
17
|
-
*
|
|
18
|
-
* @type {KeyPair}
|
|
19
|
-
*/
|
|
20
|
-
get keyPair(): KeyPair;
|
|
21
|
+
get keyPair(): KeyPair | null;
|
|
21
22
|
/**
|
|
22
23
|
* Signs a message.
|
|
23
24
|
*
|
|
@@ -25,6 +26,14 @@ export interface IWalletAccount extends IWalletAccountReadOnly {
|
|
|
25
26
|
* @returns {Promise<string>} The message's signature.
|
|
26
27
|
*/
|
|
27
28
|
sign(message: string): Promise<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Signs a transaction.
|
|
31
|
+
*
|
|
32
|
+
* @param {Transaction} tx - The transaction to sign.
|
|
33
|
+
* @returns {Promise<TSignedTransaction>} The signed transaction.
|
|
34
|
+
* @throws {ValueError} If the transaction is not valid.
|
|
35
|
+
*/
|
|
36
|
+
signTransaction(tx: Transaction): Promise<TSignedTransaction>;
|
|
28
37
|
/**
|
|
29
38
|
* Verifies a message's signature.
|
|
30
39
|
*
|
|
@@ -36,15 +45,37 @@ export interface IWalletAccount extends IWalletAccountReadOnly {
|
|
|
36
45
|
/**
|
|
37
46
|
* Sends a transaction.
|
|
38
47
|
*
|
|
39
|
-
* @param {Transaction} tx - The transaction.
|
|
48
|
+
* @param {Transaction | TSignedTransaction} tx - The transaction.
|
|
40
49
|
* @returns {Promise<TransactionResult>} The transaction's result.
|
|
50
|
+
* @throws {ValueError} If the transaction is not valid.
|
|
51
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
52
|
+
* @throws {ProviderError} If the provider fails to perform the transaction.
|
|
53
|
+
* @throws {TransactionError} If the transaction fails with an error.
|
|
54
|
+
* @throws {MaximumFeeExceededError} If the the costs of the transaction exceeds the transaction max. fee option.
|
|
41
55
|
*/
|
|
42
|
-
sendTransaction(tx: Transaction): Promise<TransactionResult>;
|
|
56
|
+
sendTransaction(tx: Transaction | TSignedTransaction): Promise<TransactionResult>;
|
|
57
|
+
/**
|
|
58
|
+
* Quotes the costs of a send transaction operation.
|
|
59
|
+
*
|
|
60
|
+
* @param {Transaction | TSignedTransaction} tx - The transaction.
|
|
61
|
+
* @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
|
|
62
|
+
* @throws {ValueError} If the transaction is not valid.
|
|
63
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
64
|
+
* @throws {ProviderError} If the provider fails to estimate the costs of the transaction.
|
|
65
|
+
* @throws {TransactionError} If the transaction fails with an error.
|
|
66
|
+
*/
|
|
67
|
+
quoteSendTransaction(tx: Transaction | TSignedTransaction): Promise<Omit<TransactionResult, "hash">>;
|
|
43
68
|
/**
|
|
44
69
|
* Transfers a token to another address.
|
|
45
70
|
*
|
|
46
71
|
* @param {TransferOptions} options - The transfer's options.
|
|
47
72
|
* @returns {Promise<TransferResult>} The transfer's result.
|
|
73
|
+
* @throws {ValueError} If the transfer options are not valid.
|
|
74
|
+
* @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
|
|
75
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
76
|
+
* @throws {ProviderError} If the provider fails to perform the transfer.
|
|
77
|
+
* @throws {TransferError} If the transfer fails with an error.
|
|
78
|
+
* @throws {MaximumFeeExceededError} If the the costs of the transfer exceeds the transfer max. fee option.
|
|
48
79
|
*/
|
|
49
80
|
transfer(options: TransferOptions): Promise<TransferResult>;
|
|
50
81
|
/**
|
|
@@ -53,15 +84,18 @@ export interface IWalletAccount extends IWalletAccountReadOnly {
|
|
|
53
84
|
* @returns {Promise<IWalletAccountReadOnly>} The read-only account.
|
|
54
85
|
*/
|
|
55
86
|
toReadOnlyAccount(): Promise<IWalletAccountReadOnly>;
|
|
56
|
-
/**
|
|
57
|
-
* Disposes the wallet account, erasing the private key from the memory.
|
|
58
|
-
*/
|
|
59
|
-
dispose(): void;
|
|
60
87
|
}
|
|
61
88
|
export type Transaction = import("./wallet-account-read-only.js").Transaction;
|
|
62
89
|
export type TransactionResult = import("./wallet-account-read-only.js").TransactionResult;
|
|
63
90
|
export type TransferOptions = import("./wallet-account-read-only.js").TransferOptions;
|
|
64
91
|
export type TransferResult = import("./wallet-account-read-only.js").TransferResult;
|
|
92
|
+
export type InvalidTokenError = import("./errors.js").InvalidTokenError;
|
|
93
|
+
export type MaximumFeeExceededError = import("./errors.js").MaximumFeeExceededError;
|
|
94
|
+
export type ProviderError = import("./errors.js").ProviderError;
|
|
95
|
+
export type ProviderRequiredError = import("./errors.js").ProviderRequiredError;
|
|
96
|
+
export type TransactionError = import("./errors.js").TransactionError;
|
|
97
|
+
export type TransferError = import("./errors.js").TransferError;
|
|
98
|
+
export type ValueError = import("./errors.js").ValueError;
|
|
65
99
|
export type KeyPair = {
|
|
66
100
|
/**
|
|
67
101
|
* - The public key.
|
|
@@ -73,3 +107,4 @@ export type KeyPair = {
|
|
|
73
107
|
privateKey: Uint8Array | null;
|
|
74
108
|
};
|
|
75
109
|
import { IWalletAccountReadOnly } from './wallet-account-read-only.js';
|
|
110
|
+
export type IDisposable = import("./disposable.js").IDisposable;
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
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
|
*
|
|
10
|
+
* @param {12 | 24} [wordCount] - The number of words in the seed phrase (default: 12).
|
|
6
11
|
* @returns {string} The seed phrase.
|
|
7
12
|
*/
|
|
8
|
-
static getRandomSeedPhrase(): string;
|
|
13
|
+
static getRandomSeedPhrase(wordCount?: 12 | 24): string;
|
|
9
14
|
/**
|
|
10
15
|
* Checks if a seed phrase is valid.
|
|
11
16
|
*
|
|
@@ -14,66 +19,152 @@ export default abstract class WalletManager {
|
|
|
14
19
|
*/
|
|
15
20
|
static isValidSeedPhrase(seedPhrase: string): boolean;
|
|
16
21
|
/**
|
|
17
|
-
* Creates a new wallet manager.
|
|
22
|
+
* Creates a new wallet manager from a seed.
|
|
18
23
|
*
|
|
19
|
-
* @
|
|
24
|
+
* @overload
|
|
25
|
+
* @param {string | Uint8Array} seed - A BIP-39 mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes).
|
|
20
26
|
* @param {WalletConfig} [config] - The wallet configuration.
|
|
27
|
+
* @throws {ValueError} If the seed is not a valid seed or BIP-39 seed phrase.
|
|
21
28
|
*/
|
|
22
29
|
constructor(seed: string | Uint8Array, config?: WalletConfig);
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new wallet manager from a default signer.
|
|
32
|
+
*
|
|
33
|
+
* @overload
|
|
34
|
+
* @param {TSigner} signer - The default signer.
|
|
35
|
+
* @param {WalletConfig} [config] - The wallet configuration.
|
|
36
|
+
* @throws {InvalidSignerError} If the given signer doesn't support account derivation.
|
|
37
|
+
*/
|
|
38
|
+
constructor(signer: TSigner, config?: WalletConfig);
|
|
23
39
|
/** @private */
|
|
24
40
|
private _seed;
|
|
25
41
|
/**
|
|
26
|
-
* The
|
|
42
|
+
* The default signer.
|
|
27
43
|
*
|
|
28
44
|
* @protected
|
|
29
|
-
* @type {
|
|
45
|
+
* @type {TSigner | undefined}
|
|
30
46
|
*/
|
|
31
|
-
protected
|
|
47
|
+
protected _defaultSigner: TSigner | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* A map between signer names and signers added via {@link addSigner}.
|
|
50
|
+
*
|
|
51
|
+
* @protected
|
|
52
|
+
* @type {Record<string, TSigner>}
|
|
53
|
+
*/
|
|
54
|
+
protected _signers: Record<string, TSigner>;
|
|
32
55
|
/**
|
|
33
56
|
* A map between derivation paths and wallet accounts. The {@link dispose} method will automatically dispose
|
|
34
57
|
* all the accounts in this map, so developers are encouraged to map all accounts accessed through the
|
|
35
58
|
* {@link getAccount} and {@link getAccountByPath} methods.
|
|
36
59
|
*
|
|
37
60
|
* @protected
|
|
38
|
-
* @type {
|
|
61
|
+
* @type {Record<string, IWalletAccount>}
|
|
62
|
+
*/
|
|
63
|
+
protected _accounts: Record<string, IWalletAccount>;
|
|
64
|
+
/**
|
|
65
|
+
* The wallet configuration.
|
|
66
|
+
*
|
|
67
|
+
* @protected
|
|
68
|
+
* @type {WalletConfig}
|
|
39
69
|
*/
|
|
40
|
-
protected
|
|
70
|
+
protected _config: WalletConfig;
|
|
41
71
|
/**
|
|
42
|
-
* The seed
|
|
72
|
+
* The seed of the wallet.
|
|
43
73
|
*
|
|
44
|
-
* @type {Uint8Array}
|
|
74
|
+
* @type {Uint8Array | undefined}
|
|
45
75
|
*/
|
|
46
|
-
get seed(): Uint8Array;
|
|
76
|
+
get seed(): Uint8Array | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Registers a signer with the given name.
|
|
79
|
+
*
|
|
80
|
+
* @param {string} signerName - The signer name.
|
|
81
|
+
* @param {TSigner} signer - The signer.
|
|
82
|
+
* @returns {this} The wallet manager.
|
|
83
|
+
* @throws {ValueError} If the signer name is an empty or blank string.
|
|
84
|
+
*/
|
|
85
|
+
addSigner(signerName: string, signer: TSigner): this;
|
|
86
|
+
/**
|
|
87
|
+
* Returns the default signer, or the signer with the given name.
|
|
88
|
+
*
|
|
89
|
+
* @param {string} [signerName] - If set, returns the signer with the given name.
|
|
90
|
+
* @returns {TSigner} The signer.
|
|
91
|
+
* @throws {NoSuchElementError} If the default signer is not set, or no signers are found for the given name.
|
|
92
|
+
*/
|
|
93
|
+
getSigner(signerName?: string): TSigner;
|
|
94
|
+
/**
|
|
95
|
+
* Returns a shallow copy of the map of signers registered via {@link addSigner}.
|
|
96
|
+
* The default signer is not included; use {@link getSigner} with no arguments
|
|
97
|
+
* to retrieve it.
|
|
98
|
+
*
|
|
99
|
+
* @returns {Record<string, TSigner>} A map of signer names to signers. Empty if no signers have been registered.
|
|
100
|
+
*/
|
|
101
|
+
getSigners(): Record<string, TSigner>;
|
|
47
102
|
/**
|
|
48
103
|
* Returns the wallet account at a specific index (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)).
|
|
49
104
|
*
|
|
50
|
-
* @
|
|
105
|
+
* @overload
|
|
51
106
|
* @param {number} [index] - The index of the account to get (default: 0).
|
|
107
|
+
* @param {Object} [options] - Account options.
|
|
108
|
+
* @param {string} [options.signerName] - The signer name.
|
|
109
|
+
* @returns {Promise<IWalletAccount>} The account.
|
|
110
|
+
* @throws {ValueError} If the index is not valid.
|
|
111
|
+
* @throws {NoSuchElementError} If a signer name is given but no signer exists with that name.
|
|
112
|
+
* @throws {InvalidSignerError} If the signer doesn't support account derivation.
|
|
113
|
+
*/
|
|
114
|
+
abstract getAccount(index?: number, options?: {
|
|
115
|
+
signerName?: string;
|
|
116
|
+
}): Promise<IWalletAccount>;
|
|
117
|
+
/**
|
|
118
|
+
* Returns the wallet account associated with a registered signer. For
|
|
119
|
+
* non-derivable signers (e.g., private-key signers), returns the signer's
|
|
120
|
+
* single account. For derivable signers, returns the wallet account at the
|
|
121
|
+
* signer's root, with no further derivation.
|
|
122
|
+
*
|
|
123
|
+
* @overload
|
|
124
|
+
* @param {string} signerName - The signer name registered via {@link addSigner}.
|
|
52
125
|
* @returns {Promise<IWalletAccount>} The account.
|
|
126
|
+
* @throws {NoSuchElementError} If no signer exists with the given name.
|
|
53
127
|
*/
|
|
54
|
-
abstract getAccount(
|
|
128
|
+
abstract getAccount(signerName: string): Promise<IWalletAccount>;
|
|
55
129
|
/**
|
|
56
130
|
* Returns the wallet account at a specific [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki) derivation path.
|
|
57
131
|
*
|
|
58
132
|
* @abstract
|
|
59
133
|
* @param {string} path - The derivation path (e.g. "0'/0/0").
|
|
134
|
+
* @param {Object} [options] - Account options.
|
|
135
|
+
* @param {string} [options.signerName] - The signer name. Omit to use the default signer.
|
|
60
136
|
* @returns {Promise<IWalletAccount>} The account.
|
|
137
|
+
* @throws {ValueError} If the path is not valid.
|
|
138
|
+
* @throws {NoSuchElementError} If a signer name is given but no signer exists with that name.
|
|
139
|
+
* @throws {InvalidSignerError} If the signer doesn't support account derivation.
|
|
61
140
|
*/
|
|
62
|
-
abstract getAccountByPath(path: string
|
|
141
|
+
abstract getAccountByPath(path: string, options?: {
|
|
142
|
+
signerName?: string;
|
|
143
|
+
}): Promise<IWalletAccount>;
|
|
63
144
|
/**
|
|
64
145
|
* Returns the current fee rates.
|
|
65
146
|
*
|
|
66
147
|
* @abstract
|
|
67
148
|
* @returns {Promise<FeeRates>} The fee rates (in base unit).
|
|
149
|
+
* @throws {ProviderRequiredError} If the method requires a provider.
|
|
150
|
+
* @throws {ProviderError} If the provider fails to fetch fee rates.
|
|
68
151
|
*/
|
|
69
152
|
abstract getFeeRates(): Promise<FeeRates>;
|
|
70
153
|
/**
|
|
71
|
-
* Disposes all
|
|
154
|
+
* Disposes all wallet accounts, clearing secret material from memory.
|
|
72
155
|
*/
|
|
73
156
|
dispose(): void;
|
|
74
157
|
}
|
|
75
158
|
export type IWalletAccount = import("./wallet-account.js").IWalletAccount;
|
|
159
|
+
export type ISigner = import("./signer.js").ISigner;
|
|
160
|
+
export type InvalidSignerError = import("./errors.js").InvalidSignerError;
|
|
161
|
+
export type ProviderError = import("./errors.js").ProviderError;
|
|
162
|
+
export type ProviderRequiredError = import("./errors.js").ProviderRequiredError;
|
|
76
163
|
export type WalletConfig = {
|
|
164
|
+
/**
|
|
165
|
+
* - The maximum fee amount for sending transactions.
|
|
166
|
+
*/
|
|
167
|
+
transactionMaxFee?: number | bigint;
|
|
77
168
|
/**
|
|
78
169
|
* - The maximum fee amount for transfer operations.
|
|
79
170
|
*/
|
|
@@ -89,3 +180,4 @@ export type FeeRates = {
|
|
|
89
180
|
*/
|
|
90
181
|
fast: bigint;
|
|
91
182
|
};
|
|
183
|
+
import { IDisposable } from "./disposable.js";
|