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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. package/AGENTS.md +49 -0
  2. package/bare.js +3 -3
  3. package/index.js +12 -2
  4. package/package.json +16 -3
  5. package/src/errors.js +318 -3
  6. package/src/multisig/errors.js +54 -0
  7. package/src/multisig/index.js +42 -0
  8. package/src/multisig/multisig-message-signing-read-only.js +63 -0
  9. package/src/multisig/multisig-message-signing.js +64 -0
  10. package/src/multisig/multisig-owner-management.js +94 -0
  11. package/src/multisig/wallet-account-multisig.js +144 -0
  12. package/src/multisig/wallet-account-read-only-multisig.js +98 -0
  13. package/src/protocols/bridge-protocol.js +35 -1
  14. package/src/protocols/errors.js +510 -0
  15. package/src/protocols/fiat-protocol.js +401 -0
  16. package/src/protocols/index.js +76 -0
  17. package/src/protocols/lending-protocol.js +114 -2
  18. package/src/protocols/sda-protocol.js +643 -0
  19. package/src/protocols/swap-protocol.js +36 -1
  20. package/src/protocols/swidge-protocol.js +516 -0
  21. package/src/signer.js +54 -0
  22. package/src/wallet-account-read-only-simple.js +162 -0
  23. package/src/wallet-account-read-only.js +186 -40
  24. package/src/wallet-account.js +49 -2
  25. package/src/wallet-manager.js +153 -24
  26. package/types/index.d.ts +12 -4
  27. package/types/src/errors.d.ts +220 -2
  28. package/types/src/multisig/errors.d.ts +33 -0
  29. package/types/src/multisig/index.d.ts +15 -0
  30. package/types/src/multisig/multisig-message-signing-read-only.d.ts +53 -0
  31. package/types/src/multisig/multisig-message-signing.d.ts +40 -0
  32. package/types/src/multisig/multisig-owner-management.d.ts +65 -0
  33. package/types/src/multisig/wallet-account-multisig.d.ts +101 -0
  34. package/types/src/multisig/wallet-account-read-only-multisig.d.ts +83 -0
  35. package/types/src/protocols/bridge-protocol.d.ts +39 -3
  36. package/types/src/protocols/errors.d.ts +366 -0
  37. package/types/src/protocols/fiat-protocol.d.ts +409 -0
  38. package/types/src/protocols/index.d.ts +64 -0
  39. package/types/src/protocols/lending-protocol.d.ts +118 -4
  40. package/types/src/protocols/sda-protocol.d.ts +737 -0
  41. package/types/src/protocols/swap-protocol.d.ts +44 -4
  42. package/types/src/protocols/swidge-protocol.d.ts +483 -0
  43. package/types/src/signer.d.ts +28 -0
  44. package/types/src/wallet-account-read-only-simple.d.ts +144 -0
  45. package/types/src/wallet-account-read-only.d.ts +104 -27
  46. package/types/src/wallet-account.d.ts +44 -4
  47. package/types/src/wallet-manager.d.ts +102 -15
@@ -0,0 +1,162 @@
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
+ /** @typedef {import('./errors.js').InvalidTokenError} InvalidTokenError */
19
+ /** @typedef {import('./errors.js').NoSuchElementError} NoSuchElementError */
20
+ /** @typedef {import('./errors.js').ProviderError} ProviderError */
21
+ /** @typedef {import('./errors.js').ProviderRequiredError} ProviderRequiredError */
22
+ /** @typedef {import('./errors.js').TimeoutError} TimeoutError */
23
+ /** @typedef {import('./errors.js').ValueError} ValueError */
24
+ /** @typedef {import('./errors.js').UnsupportedOperationError} UnsupportedOperationError */
25
+
26
+ /**
27
+ * A normalized, cross-chain transaction finality level.
28
+ *
29
+ * - `pending`: seen, not settled (mempool / processed / in-flight).
30
+ * - `confirmed`: settled, reversible only under extreme conditions.
31
+ * - `final`: irreversible per the chain's own guarantees.
32
+ * - `dropped`: evicted / replaced, never landed.
33
+ *
34
+ * @typedef {'pending' | 'confirmed' | 'final' | 'dropped'} Finality
35
+ */
36
+
37
+ /**
38
+ * A normalized, cross-chain transaction receipt. Blockchain modules extend this
39
+ * type with their own native receipt fields (e.g. `confirmations`, the raw
40
+ * transaction and receipt objects, etc.).
41
+ *
42
+ * @typedef {Object} TransactionReceipt
43
+ * @property {string} hash - The transaction's identifier (hash / signature / lt:hash).
44
+ * @property {Finality} finality - The transaction's finality level.
45
+ * @property {boolean} [success] - The execution's result (not set if the transaction is still pending or it has been dropped).
46
+ * @property {number} [block] - A reference to the including block (block number / height / slot / masterchain seqno).
47
+ * @property {bigint} [fee] - The fee paid, when known.
48
+ */
49
+
50
+ /**
51
+ * The finality level to wait for.
52
+ *
53
+ * @typedef {'confirmed' | 'final'} WaitForTransactionTarget
54
+ */
55
+
56
+ /**
57
+ * @typedef {Object} WaitForTransactionOptions
58
+ * @property {WaitForTransactionTarget} [target] - The finality target to wait for (default: 'confirmed').
59
+ * @property {number} [timeout] - The total time budget in milliseconds before giving up. If omitted, the account's `defaultWaitTimeout` is used.
60
+ * @property {number} [interval] - The poll cadence in milliseconds. If omitted, the account's `defaultWaitInterval` is used.
61
+ * @property {number} [maxPollErrors] - How many consecutive getTransaction() failures to tolerate before rethrowing (default: 3).
62
+ */
63
+
64
+ /**
65
+ * The read-only members shared by every wallet account, single-signer or multisig.
66
+ *
67
+ * This is an internal base interface: it is not exported from the package entry point.
68
+ * Consumers use {@link IWalletAccountReadOnly} or {@link IWalletAccountReadOnlyMultisig},
69
+ * which both extend it.
70
+ *
71
+ * @interface
72
+ */
73
+ export class IWalletAccountReadOnlySimple {
74
+ /**
75
+ * Returns the account's address.
76
+ *
77
+ * @returns {Promise<string>} The account's address.
78
+ */
79
+ async getAddress () {
80
+ throw new NotImplementedError('getAddress()')
81
+ }
82
+
83
+ /**
84
+ * Verifies a message's signature.
85
+ *
86
+ * @param {string} message - The original message.
87
+ * @param {string} signature - The signature to verify.
88
+ * @returns {Promise<boolean>} True if the signature is valid.
89
+ * @throws {UnsupportedOperationError} If the read-only wallet account class is not able to provide an implementation for the method.
90
+ */
91
+ async verify (message, signature) {
92
+ throw new NotImplementedError('verify(message, signature)')
93
+ }
94
+
95
+ /**
96
+ * Returns the account's native token balance.
97
+ *
98
+ * @returns {Promise<bigint>} The native token balance.
99
+ * @throws {ProviderRequiredError} If the method requires a provider.
100
+ * @throws {ProviderError} If the provider fails to fetch the account's balance.
101
+ */
102
+ async getBalance () {
103
+ throw new NotImplementedError('getBalance()')
104
+ }
105
+
106
+ /**
107
+ * Returns the account balance for a specific token.
108
+ *
109
+ * @param {string} tokenAddress - The smart contract address of the token.
110
+ * @returns {Promise<bigint>} The token balance.
111
+ * @throws {ValueError} If the token's address is not valid.
112
+ * @throws {InvalidTokenError} If the token's address doesn't match an existing ERC 20 token.
113
+ * @throws {ProviderRequiredError} If the method requires a provider.
114
+ * @throws {ProviderError} If the provider fails to fetch the account's token balance.
115
+ */
116
+ async getTokenBalance (tokenAddress) {
117
+ throw new NotImplementedError('getTokenBalance(tokenAddress)')
118
+ }
119
+
120
+ /**
121
+ * Returns a transaction's receipt.
122
+ *
123
+ * @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.
124
+ * @param {string} hash - The transaction's hash.
125
+ * @returns {Promise<unknown | null>} The receipt, or null if the transaction has not been included in a block yet.
126
+ * @throws {ValueError} If the hash is not valid.
127
+ * @throws {ProviderRequiredError} If the method requires a provider.
128
+ * @throws {ProviderError} If the provider fails to fetch the transaction's receipt.
129
+ */
130
+ async getTransactionReceipt (hash) {
131
+ throw new NotImplementedError('getTransactionReceipt(hash)')
132
+ }
133
+
134
+ /**
135
+ * Returns a normalized, finality-based receipt for a transaction.
136
+ *
137
+ * @param {string} hash - The transaction's identifier (hash / signature / lt:hash).
138
+ * @returns {Promise<TransactionReceipt>} The normalized receipt.
139
+ * @throws {ValueError} If the hash is not a valid identifier.
140
+ * @throws {NoSuchElementError} If no transaction has been found for the given hash.
141
+ * @throws {ProviderRequiredError} If the method requires a provider.
142
+ * @throws {ProviderError} If the provider fails to fetch the transaction.
143
+ */
144
+ async getTransaction (hash) {
145
+ throw new NotImplementedError('getTransaction(hash)')
146
+ }
147
+
148
+ /**
149
+ * Blocks until a transaction reaches a terminal state (the requested finality target or `dropped`), or times out.
150
+ *
151
+ * @param {string} hash - The transaction's identifier.
152
+ * @param {WaitForTransactionOptions} [options] - The wait options.
153
+ * @returns {Promise<TransactionReceipt>} The terminal receipt: the finality target reached (inspect `success` to tell success from revert), or `dropped`.
154
+ * @throws {ValueError} If the hash is not a valid identifier.
155
+ * @throws {ProviderRequiredError} If the method requires a provider.
156
+ * @throws {ProviderError} If the provider fails to fetch the transaction.
157
+ * @throws {TimeoutError} If the operation times out.
158
+ */
159
+ async waitForTransaction (hash, options) {
160
+ throw new NotImplementedError('waitForTransaction(hash, options)')
161
+ }
162
+ }
@@ -13,7 +13,19 @@
13
13
  // limitations under the License.
14
14
  'use strict'
15
15
 
16
- import { NotImplementedError } from './errors.js'
16
+ import { IWalletAccountReadOnlySimple } from './wallet-account-read-only-simple.js'
17
+
18
+ import { AssertionError, NoSuchElementError, NotImplementedError, ProviderError, TimeoutError, UnsupportedOperationError } from './errors.js'
19
+
20
+ /** @typedef {import('./wallet-account-read-only-simple.js').Finality} Finality */
21
+ /** @typedef {import('./wallet-account-read-only-simple.js').TransactionReceipt} TransactionReceipt */
22
+ /** @typedef {import('./wallet-account-read-only-simple.js').WaitForTransactionOptions} WaitForTransactionOptions */
23
+
24
+ /** @typedef {import('./errors.js').InvalidTokenError} InvalidTokenError */
25
+ /** @typedef {import('./errors.js').ProviderRequiredError} ProviderRequiredError */
26
+ /** @typedef {import('./errors.js').TransactionError} TransactionError */
27
+ /** @typedef {import('./errors.js').TransferError} TransferError */
28
+ /** @typedef {import('./errors.js').ValueError} ValueError */
17
29
 
18
30
  /**
19
31
  * @typedef {Object} Transaction
@@ -40,41 +52,41 @@ import { NotImplementedError } from './errors.js'
40
52
  * @property {bigint} fee - The gas cost.
41
53
  */
42
54
 
43
- /** @interface */
44
- export class IWalletAccountReadOnly {
45
- /**
46
- * Returns the account's address.
47
- *
48
- * @returns {Promise<string>} The account's address.
49
- */
50
- async getAddress () {
51
- throw new NotImplementedError('getAddress()')
52
- }
53
-
54
- /**
55
- * Returns the account's native token balance.
56
- *
57
- * @returns {Promise<bigint>} The native token balance.
58
- */
59
- async getBalance () {
60
- throw new NotImplementedError('getBalance()')
61
- }
55
+ /**
56
+ * Enum that assigns a comparable ordinal to each finality level, used to check
57
+ * whether an observed finality satisfies a requested target.
58
+ *
59
+ * @readonly
60
+ * @enum {number}
61
+ */
62
+ export const FINALITY = {
63
+ pending: 0,
64
+ dropped: 1,
65
+ confirmed: 2,
66
+ final: 3
67
+ }
62
68
 
63
- /**
64
- * Returns the account balance for a specific token.
65
- *
66
- * @param {string} tokenAddress - The smart contract address of the token.
67
- * @returns {Promise<bigint>} The token balance.
68
- */
69
- async getTokenBalance (tokenAddress) {
70
- throw new NotImplementedError('getTokenBalance(tokenAddress)')
71
- }
69
+ /**
70
+ * Resolves after the given number of milliseconds.
71
+ *
72
+ * @param {number} amount - The delay, in milliseconds.
73
+ * @returns {Promise<void>} A promise that resolves once the delay elapses.
74
+ */
75
+ async function sleep (amount) {
76
+ await new Promise(resolve => setTimeout(resolve, amount))
77
+ }
72
78
 
79
+ /** @interface */
80
+ export class IWalletAccountReadOnly extends IWalletAccountReadOnlySimple {
73
81
  /**
74
82
  * Quotes the costs of a send transaction operation.
75
83
  *
76
84
  * @param {Transaction} tx - The transaction.
77
85
  * @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
86
+ * @throws {ValueError} If the transaction is not valid.
87
+ * @throws {ProviderRequiredError} If the method requires a provider.
88
+ * @throws {ProviderError} If the provider fails to estimate the costs of the transaction.
89
+ * @throws {TransactionError} If the transaction fails with an error.
78
90
  */
79
91
  async quoteSendTransaction (tx) {
80
92
  throw new NotImplementedError('quoteSendTransaction(tx)')
@@ -85,20 +97,15 @@ export class IWalletAccountReadOnly {
85
97
  *
86
98
  * @param {TransferOptions} options - The transfer's options.
87
99
  * @returns {Promise<Omit<TransferResult, 'hash'>>} The transfer's quotes.
100
+ * @throws {ValueError} If the transfer options are not valid.
101
+ * @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
102
+ * @throws {ProviderRequiredError} If the method requires a provider.
103
+ * @throws {ProviderError} If the provider fails to estimate the costs of the transfer.
104
+ * @throws {TransferError} If the transfer fails with an error.
88
105
  */
89
106
  async quoteTransfer (options) {
90
107
  throw new NotImplementedError('quoteTransfer(options)')
91
108
  }
92
-
93
- /**
94
- * Returns a transaction's receipt.
95
- *
96
- * @param {string} hash - The transaction's hash.
97
- * @returns {Promise<unknown | null>} The receipt, or null if the transaction has not been included in a block yet.
98
- */
99
- async getTransactionReceipt (hash) {
100
- throw new NotImplementedError('getTransactionReceipt(hash)')
101
- }
102
109
  }
103
110
 
104
111
  /**
@@ -106,6 +113,28 @@ export class IWalletAccountReadOnly {
106
113
  * @implements {IWalletAccountReadOnly}
107
114
  */
108
115
  export default class WalletAccountReadOnly {
116
+ /**
117
+ * The default poll cadence for {@link waitForTransaction}, in milliseconds,
118
+ * applied when the caller doesn't provide an `interval`. Subclasses override
119
+ * it to match their chain's block time.
120
+ *
121
+ * @type {number}
122
+ */
123
+ get defaultWaitInterval () {
124
+ return 4000
125
+ }
126
+
127
+ /**
128
+ * The default time budget for {@link waitForTransaction}, in milliseconds,
129
+ * applied when the caller doesn't provide a `timeout`. Subclasses override it
130
+ * to match their chain's finality expectations.
131
+ *
132
+ * @type {number}
133
+ */
134
+ get defaultWaitTimeout () {
135
+ return 60000
136
+ }
137
+
109
138
  /**
110
139
  * Creates a new read-only wallet account.
111
140
  *
@@ -133,17 +162,31 @@ export default class WalletAccountReadOnly {
133
162
  */
134
163
  async getAddress () {
135
164
  if (!this._address) {
136
- throw new Error("The account's address must be set to perform this operation.")
165
+ throw new AssertionError("The account's address must be set to perform this operation.")
137
166
  }
138
167
 
139
168
  return this._address
140
169
  }
141
170
 
171
+ /**
172
+ * Verifies a message's signature.
173
+ *
174
+ * @param {string} message - The original message.
175
+ * @param {string} signature - The signature to verify.
176
+ * @returns {Promise<boolean>} True if the signature is valid.
177
+ * @throws {UnsupportedOperationError} If the read-only wallet account class is not able to provide an implementation for the method.
178
+ */
179
+ async verify (message, signature) {
180
+ throw new UnsupportedOperationError('verify(message, signature)')
181
+ }
182
+
142
183
  /**
143
184
  * Returns the account's native token balance.
144
185
  *
145
186
  * @abstract
146
187
  * @returns {Promise<bigint>} The native token balance.
188
+ * @throws {ProviderRequiredError} If the method requires a provider.
189
+ * @throws {ProviderError} If the provider fails to fetch the account's balance.
147
190
  */
148
191
  async getBalance () {
149
192
  throw new NotImplementedError('getBalance()')
@@ -155,6 +198,10 @@ export default class WalletAccountReadOnly {
155
198
  * @abstract
156
199
  * @param {string} tokenAddress - The smart contract address of the token.
157
200
  * @returns {Promise<bigint>} The token balance.
201
+ * @throws {ValueError} If the token's address is not valid.
202
+ * @throws {InvalidTokenError} If the token's address doesn't match an existing ERC 20 token.
203
+ * @throws {ProviderRequiredError} If the method requires a provider.
204
+ * @throws {ProviderError} If the provider fails to fetch the account's token balance.
158
205
  */
159
206
  async getTokenBalance (tokenAddress) {
160
207
  throw new NotImplementedError('getTokenBalance(tokenAddress)')
@@ -166,6 +213,10 @@ export default class WalletAccountReadOnly {
166
213
  * @abstract
167
214
  * @param {Transaction} tx - The transaction.
168
215
  * @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
216
+ * @throws {ValueError} If the transaction is not valid.
217
+ * @throws {ProviderRequiredError} If the method requires a provider.
218
+ * @throws {ProviderError} If the provider fails to estimate the costs of the transaction.
219
+ * @throws {TransactionError} If the transaction fails with an error.
169
220
  */
170
221
  async quoteSendTransaction (tx) {
171
222
  throw new NotImplementedError('quoteSendTransaction(tx)')
@@ -177,6 +228,11 @@ export default class WalletAccountReadOnly {
177
228
  * @abstract
178
229
  * @param {TransferOptions} options - The transfer's options.
179
230
  * @returns {Promise<Omit<TransferResult, 'hash'>>} The transfer's quotes.
231
+ * @throws {ValueError} If the transfer options are not valid.
232
+ * @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
233
+ * @throws {ProviderRequiredError} If the method requires a provider.
234
+ * @throws {ProviderError} If the provider fails to estimate the costs of the transfer.
235
+ * @throws {TransferError} If the transfer fails with an error.
180
236
  */
181
237
  async quoteTransfer (options) {
182
238
  throw new NotImplementedError('quoteTransfer(options)')
@@ -185,11 +241,101 @@ export default class WalletAccountReadOnly {
185
241
  /**
186
242
  * Returns a transaction's receipt.
187
243
  *
244
+ * @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.
188
245
  * @abstract
189
246
  * @param {string} hash - The transaction's hash.
190
247
  * @returns {Promise<unknown | null>} The receipt, or null if the transaction has not been included in a block yet.
248
+ * @throws {ValueError} If the hash is not valid.
249
+ * @throws {ProviderRequiredError} If the method requires a provider.
250
+ * @throws {ProviderError} If the provider fails to fetch the transaction's receipt.
191
251
  */
192
252
  async getTransactionReceipt (hash) {
193
253
  throw new NotImplementedError('getTransactionReceipt(hash)')
194
254
  }
255
+
256
+ /**
257
+ * Returns a normalized, finality-based receipt for a transaction.
258
+ *
259
+ * @abstract
260
+ * @param {string} hash - The transaction's identifier (hash / signature / lt:hash).
261
+ * @returns {Promise<TransactionReceipt>} The normalized receipt.
262
+ * @throws {ValueError} If the hash is not a valid identifier.
263
+ * @throws {NoSuchElementError} If no transaction has been found for the given hash.
264
+ * @throws {ProviderRequiredError} If the method requires a provider.
265
+ * @throws {ProviderError} If the provider fails to fetch the transaction.
266
+ */
267
+ async getTransaction (hash) {
268
+ throw new NotImplementedError('getTransaction(hash)')
269
+ }
270
+
271
+ /**
272
+ * Blocks until a transaction reaches a terminal state (the requested finality
273
+ * target or `dropped`), or times out.
274
+ *
275
+ * The polling loop and target resolution are chain-agnostic: this method only
276
+ * interprets the normalized receipt returned by {@link getTransaction}. A
277
+ * {@link NoSuchElementError} is treated as a transient not-found, so the loop
278
+ * keeps polling until the timeout.
279
+ *
280
+ * @param {string} hash - The transaction's identifier.
281
+ * @param {WaitForTransactionOptions} [options] - The wait options.
282
+ * @returns {Promise<TransactionReceipt>} The terminal receipt: the finality target reached (inspect `success` to tell success from revert), or `dropped`.
283
+ * @throws {ValueError} If the hash is not a valid identifier.
284
+ * @throws {ProviderRequiredError} If the method requires a provider.
285
+ * @throws {ProviderError} If the provider fails to fetch the transaction.
286
+ * @throws {TimeoutError} If the operation times out.
287
+ */
288
+ async waitForTransaction (hash, options = {}) {
289
+ const {
290
+ target = 'confirmed',
291
+ interval = this.defaultWaitInterval,
292
+ timeout = this.defaultWaitTimeout,
293
+ maxPollErrors = 3
294
+ } = options
295
+
296
+ const deadline = Date.now() + timeout
297
+ let droppedStreak = 0
298
+ let errorStreak = 0
299
+
300
+ while (true) {
301
+ let receipt = null
302
+
303
+ try {
304
+ receipt = await this.getTransaction(hash)
305
+ errorStreak = 0
306
+ } catch (error) {
307
+ if (error instanceof NoSuchElementError) {
308
+ errorStreak = 0
309
+ } else if (error instanceof ProviderError) {
310
+ if (++errorStreak > maxPollErrors) {
311
+ throw error
312
+ }
313
+ } else {
314
+ throw error
315
+ }
316
+ }
317
+
318
+ if (receipt) {
319
+ if (receipt.finality === 'dropped') {
320
+ if (++droppedStreak >= 2) {
321
+ return receipt
322
+ }
323
+ } else {
324
+ droppedStreak = 0
325
+
326
+ if (FINALITY[receipt.finality] >= FINALITY[target]) {
327
+ return receipt
328
+ }
329
+ }
330
+ } else {
331
+ droppedStreak = 0
332
+ }
333
+
334
+ if (Date.now() >= deadline) {
335
+ throw new TimeoutError(`Transaction '${hash}' did not reach '${target}' within the timeout.`)
336
+ }
337
+
338
+ await sleep(interval)
339
+ }
340
+ }
195
341
  }
@@ -23,13 +23,24 @@ import { NotImplementedError } from './errors.js'
23
23
  /** @typedef {import('./wallet-account-read-only.js').TransferOptions} TransferOptions */
24
24
  /** @typedef {import('./wallet-account-read-only.js').TransferResult} TransferResult */
25
25
 
26
+ /** @typedef {import('./errors.js').InvalidTokenError} InvalidTokenError */
27
+ /** @typedef {import('./errors.js').MaximumFeeExceededError} MaximumFeeExceededError */
28
+ /** @typedef {import('./errors.js').ProviderError} ProviderError */
29
+ /** @typedef {import('./errors.js').ProviderRequiredError} ProviderRequiredError */
30
+ /** @typedef {import('./errors.js').TransactionError} TransactionError */
31
+ /** @typedef {import('./errors.js').TransferError} TransferError */
32
+ /** @typedef {import('./errors.js').ValueError} ValueError */
33
+
26
34
  /**
27
35
  * @typedef {Object} KeyPair
28
36
  * @property {Uint8Array} publicKey - The public key.
29
37
  * @property {Uint8Array | null} privateKey - The private key (null if the account has been disposed).
30
38
  */
31
39
 
32
- /** @interface */
40
+ /**
41
+ * @interface
42
+ * @template [TSignedTransaction=unknown]
43
+ */
33
44
  export class IWalletAccount extends IWalletAccountReadOnly {
34
45
  /**
35
46
  * The derivation path's index of this account.
@@ -68,6 +79,17 @@ export class IWalletAccount extends IWalletAccountReadOnly {
68
79
  throw new NotImplementedError('sign(message)')
69
80
  }
70
81
 
82
+ /**
83
+ * Signs a transaction.
84
+ *
85
+ * @param {Transaction} tx - The transaction to sign.
86
+ * @returns {Promise<TSignedTransaction>} The signed transaction.
87
+ * @throws {ValueError} If the transaction is not valid.
88
+ */
89
+ async signTransaction (tx) {
90
+ throw new NotImplementedError('signTransaction(tx)')
91
+ }
92
+
71
93
  /**
72
94
  * Verifies a message's signature.
73
95
  *
@@ -82,18 +104,43 @@ export class IWalletAccount extends IWalletAccountReadOnly {
82
104
  /**
83
105
  * Sends a transaction.
84
106
  *
85
- * @param {Transaction} tx - The transaction.
107
+ * @param {Transaction | TSignedTransaction} tx - The transaction.
86
108
  * @returns {Promise<TransactionResult>} The transaction's result.
109
+ * @throws {ValueError} If the transaction is not valid.
110
+ * @throws {ProviderRequiredError} If the method requires a provider.
111
+ * @throws {ProviderError} If the provider fails to perform the transaction.
112
+ * @throws {TransactionError} If the transaction fails with an error.
113
+ * @throws {MaximumFeeExceededError} If the the costs of the transaction exceeds the transaction max. fee option.
87
114
  */
88
115
  async sendTransaction (tx) {
89
116
  throw new NotImplementedError('sendTransaction(tx)')
90
117
  }
91
118
 
119
+ /**
120
+ * Quotes the costs of a send transaction operation.
121
+ *
122
+ * @param {Transaction | TSignedTransaction} tx - The transaction.
123
+ * @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
124
+ * @throws {ValueError} If the transaction is not valid.
125
+ * @throws {ProviderRequiredError} If the method requires a provider.
126
+ * @throws {ProviderError} If the provider fails to estimate the costs of the transaction.
127
+ * @throws {TransactionError} If the transaction fails with an error.
128
+ */
129
+ async quoteSendTransaction (tx) {
130
+ throw new NotImplementedError('quoteSendTransaction(tx)')
131
+ }
132
+
92
133
  /**
93
134
  * Transfers a token to another address.
94
135
  *
95
136
  * @param {TransferOptions} options - The transfer's options.
96
137
  * @returns {Promise<TransferResult>} The transfer's result.
138
+ * @throws {ValueError} If the transfer options are not valid.
139
+ * @throws {InvalidTokenError} If the token is not a valid ERC 20 token's address.
140
+ * @throws {ProviderRequiredError} If the method requires a provider.
141
+ * @throws {ProviderError} If the provider fails to perform the transfer.
142
+ * @throws {TransferError} If the transfer fails with an error.
143
+ * @throws {MaximumFeeExceededError} If the the costs of the transfer exceeds the transfer max. fee option.
97
144
  */
98
145
  async transfer (options) {
99
146
  throw new NotImplementedError('transfer(options)')