@tetherto/wdk-wallet-evm 1.0.0-beta.16 → 1.0.0-beta.17

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/index.js CHANGED
@@ -19,17 +19,23 @@
19
19
  /** @typedef {import('ethers').Authorization} Authorization */
20
20
  /** @typedef {import('ethers').AuthorizationLike} AuthorizationLike */
21
21
  /** @typedef {import('ethers').TransactionReceipt} EvmTransactionReceipt */
22
+ /** @typedef {import('ethers').TransactionResponse} EvmTransactionResponse */
22
23
 
23
24
  /** @typedef {import('@tetherto/wdk-wallet').FeeRates} FeeRates */
24
25
  /** @typedef {import('@tetherto/wdk-wallet').KeyPair} KeyPair */
25
26
  /** @typedef {import('@tetherto/wdk-wallet').TransactionResult} TransactionResult */
26
27
  /** @typedef {import('@tetherto/wdk-wallet').TransferResult} TransferResult */
28
+ /** @typedef {import('@tetherto/wdk-wallet').Finality} Finality */
29
+ /** @typedef {import('@tetherto/wdk-wallet').TransactionReceipt} TransactionReceipt */
30
+ /** @typedef {import('@tetherto/wdk-wallet').WaitForTransactionTarget} WaitForTransactionTarget */
31
+ /** @typedef {import('@tetherto/wdk-wallet').WaitForTransactionOptions} WaitForTransactionOptions */
27
32
 
28
33
  /** @typedef {import('./src/wallet-account-read-only-evm.js').TypedData} TypedData */
29
34
  /** @typedef {import('./src/wallet-account-read-only-evm.js').DelegationInfo} DelegationInfo */
30
35
  /** @typedef {import('./src/wallet-account-read-only-evm.js').EvmTransaction} EvmTransaction */
31
36
  /** @typedef {import('./src/wallet-account-read-only-evm.js').EvmTransferOptions} EvmTransferOptions */
32
37
  /** @typedef {import('./src/wallet-account-read-only-evm.js').EvmWalletConfig} EvmWalletConfig */
38
+ /** @typedef {import('./src/wallet-account-read-only-evm.js').EvmTransactionDetails} EvmTransactionDetails */
33
39
 
34
40
  /** @typedef {import('./src/wallet-account-evm.js').ApproveOptions} ApproveOptions */
35
41
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tetherto/wdk-wallet-evm",
3
- "version": "1.0.0-beta.16",
3
+ "version": "1.0.0-beta.17",
4
4
  "description": "A simple package to manage BIP-32 wallets for evm blockchains.",
5
5
  "keywords": [
6
6
  "wdk",
@@ -31,8 +31,8 @@
31
31
  "dependencies": {
32
32
  "@noble/hashes": "1.8.0",
33
33
  "@noble/secp256k1": "2.2.3",
34
- "@tetherto/wdk-wallet": "1.0.0-beta.13",
35
34
  "@tetherto/wdk-failover-provider": "1.0.0-beta.2",
35
+ "@tetherto/wdk-wallet": "1.0.0-beta.17",
36
36
  "bare-node-runtime": "^1.5.0",
37
37
  "bip39": "3.1.0",
38
38
  "ethers": "6.17.0",
@@ -41,7 +41,7 @@
41
41
  "devDependencies": {
42
42
  "concurrently": "9.2.0",
43
43
  "cross-env": "7.0.3",
44
- "hardhat": "3.9.1",
44
+ "hardhat": "3.12.0",
45
45
  "jest": "29.7.0",
46
46
  "standard": "17.1.2",
47
47
  "typescript": "5.8.3",
@@ -15,7 +15,7 @@
15
15
 
16
16
  import { BaseWallet } from 'ethers'
17
17
 
18
- import { SignerError } from '@tetherto/wdk-wallet'
18
+ import { InvalidSignerError } from '@tetherto/wdk-wallet'
19
19
 
20
20
  import MemorySafeSigningKey from '../memory-safe/signing-key.js'
21
21
  import { ISignerEvm } from './seed-signer-evm.js'
@@ -97,10 +97,10 @@ export default class PrivateKeySignerEvm extends ISignerEvm {
97
97
  /**
98
98
  * PrivateKeySignerEvm is not a hierarchical signer and cannot derive.
99
99
  * @returns {Promise<never>}
100
- * @throws {SignerError} Always — private-key signers do not support derivation.
100
+ * @throws {InvalidSignerError} Always — private-key signers do not support derivation.
101
101
  */
102
102
  async derive () {
103
- throw new SignerError('PrivateKeySignerEvm does not support derivation.')
103
+ throw new InvalidSignerError('PrivateKeySignerEvm does not support derivation.')
104
104
  }
105
105
 
106
106
  /** @returns {Promise<string>} */
@@ -25,7 +25,7 @@ const DEFAULT_ACCOUNT_PATH = "0'/0/0"
25
25
 
26
26
  /** @typedef {import('../utils/tx-populator-evm.js').UnsignedEvmTransaction} UnsignedEvmTransaction */
27
27
  /** @typedef {import('@tetherto/wdk-wallet').ISigner} ISigner */
28
- /** @typedef {import('@tetherto/wdk-wallet').SignerError} SignerError */
28
+ /** @typedef {import('@tetherto/wdk-wallet').InvalidSignerError} InvalidSignerError */
29
29
  /** @typedef {import('@tetherto/wdk-wallet').KeyPair} KeyPair */
30
30
  /** @typedef {import('ethers').AuthorizationRequest} AuthorizationRequest */
31
31
  /** @typedef {import('ethers').Authorization} Authorization */
@@ -93,7 +93,7 @@ export class ISignerEvm extends ISigner {
93
93
  *
94
94
  * @param {string} relPath - The relative BIP-44 path segment.
95
95
  * @returns {Promise<ISignerEvm>} The derived child signer.
96
- * @throws {SignerError} If the signer does not support derivation (e.g. private-key signers).
96
+ * @throws {InvalidSignerError} If the signer does not support derivation (e.g. private-key signers).
97
97
  */
98
98
  async derive (relPath) {
99
99
  throw new NotImplementedError('derive(relPath)')
@@ -14,9 +14,9 @@
14
14
 
15
15
  'use strict'
16
16
 
17
- import { WalletAccountReadOnly } from '@tetherto/wdk-wallet'
17
+ import { WalletAccountReadOnly, NoSuchElementError, ValueError } from '@tetherto/wdk-wallet'
18
18
 
19
- import { BrowserProvider, Contract, Interface, JsonRpcProvider, Network, Signature, toQuantity, verifyMessage, verifyTypedData } from 'ethers'
19
+ import { BrowserProvider, Contract, Interface, isError, isHexString, JsonRpcProvider, Network, Signature, toQuantity, verifyMessage, verifyTypedData } from 'ethers'
20
20
 
21
21
  import { multicall } from './multicall.js'
22
22
 
@@ -28,9 +28,20 @@ import FailoverProvider from '@tetherto/wdk-failover-provider'
28
28
  /** @typedef {import('ethers').TypedDataField} TypedDataField */
29
29
  /** @typedef {import('ethers').AuthorizationLike} AuthorizationLike */
30
30
  /** @typedef {import('ethers').TransactionReceipt} EvmTransactionReceipt */
31
+ /** @typedef {import('ethers').TransactionResponse} EvmTransactionResponse */
31
32
 
32
33
  /** @typedef {import('@tetherto/wdk-wallet').TransactionResult} TransactionResult */
33
34
  /** @typedef {import('@tetherto/wdk-wallet').TransferResult} TransferResult */
35
+ /** @typedef {import('@tetherto/wdk-wallet').TransactionReceipt} TransactionReceipt */
36
+ /** @typedef {import('@tetherto/wdk-wallet').WaitForTransactionOptions} WaitForTransactionOptions */
37
+
38
+ /**
39
+ * The EVM-specific fields added to a normalized transaction receipt.
40
+ *
41
+ * @typedef {Object} EvmTransactionDetails
42
+ * @property {number} confirmations - The number of confirmations (0 while pending or dropped).
43
+ * @property {EvmTransactionReceipt | null} receipt - The native ethers receipt, or null while the transaction is pending or dropped.
44
+ */
34
45
 
35
46
  /**
36
47
  * @typedef {Object} TypedData
@@ -260,6 +271,7 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
260
271
  /**
261
272
  * Returns a transaction's receipt.
262
273
  *
274
+ * @deprecated Use {@link getTransaction} instead, which returns a normalized, finality-based receipt. The raw ethers receipt remains available on its `receipt` property.
263
275
  * @param {string} hash - The transaction's hash.
264
276
  * @returns {Promise<EvmTransactionReceipt | null>} – The receipt, or null if the transaction has not been included in a block yet.
265
277
  */
@@ -271,6 +283,115 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
271
283
  return await this._provider.getTransactionReceipt(hash)
272
284
  }
273
285
 
286
+ /**
287
+ * Returns a normalized, finality-based receipt for a transaction.
288
+ *
289
+ * @param {string} hash - The transaction's hash.
290
+ * @returns {Promise<TransactionReceipt & EvmTransactionDetails>} The normalized receipt.
291
+ * @throws {ValueError} If the hash is not a valid transaction hash.
292
+ * @throws {NoSuchElementError} If no transaction has been found for the given hash.
293
+ */
294
+ async getTransaction (hash) {
295
+ if (!this._provider) {
296
+ throw new Error('The wallet must be connected to a provider to fetch transactions.')
297
+ }
298
+
299
+ if (!isHexString(hash, 32)) {
300
+ throw new ValueError(`Invalid transaction hash: '${hash}'.`)
301
+ }
302
+
303
+ const [transaction, receipt] = await Promise.all([
304
+ this._provider.getTransaction(hash),
305
+ this._provider.getTransactionReceipt(hash)
306
+ ])
307
+
308
+ if (!transaction && !receipt) {
309
+ throw new NoSuchElementError(`No transaction found for '${hash}'.`)
310
+ }
311
+
312
+ if (!receipt) {
313
+ const dropped = transaction
314
+ ? await this._isReplaced(transaction)
315
+ : false
316
+
317
+ return {
318
+ hash,
319
+ finality: dropped ? 'dropped' : 'pending',
320
+ confirmations: 0,
321
+ receipt: null
322
+ }
323
+ }
324
+
325
+ const confirmations = await receipt.confirmations()
326
+ const finalized = await this._isFinalized(receipt.blockNumber)
327
+
328
+ return {
329
+ hash,
330
+ finality: finalized ? 'final' : 'confirmed',
331
+ success: receipt.status === 1,
332
+ block: receipt.blockNumber,
333
+ fee: receipt.fee,
334
+ confirmations,
335
+ receipt
336
+ }
337
+ }
338
+
339
+ /**
340
+ * Blocks until a transaction reaches a terminal state (the requested finality target or `dropped`), or times out.
341
+ *
342
+ * @param {string} hash - The transaction's hash.
343
+ * @param {WaitForTransactionOptions} [options] - The wait options.
344
+ * @returns {Promise<TransactionReceipt & EvmTransactionDetails>} The terminal receipt: the finality target reached (inspect `success` to tell success from revert), or `dropped`.
345
+ * @throws {TimeoutError} If the target is not reached before the timeout.
346
+ */
347
+ async waitForTransaction (hash, options = {}) {
348
+ return await super.waitForTransaction(hash, options)
349
+ }
350
+
351
+ /**
352
+ * Returns whether a block is at or below the chain's `finalized` block. Chains that don't support the tag are treated as not finalized.
353
+ *
354
+ * @protected
355
+ * @param {number} blockNumber - The block number to check.
356
+ * @returns {Promise<boolean>} True if the block is finalized.
357
+ */
358
+ async _isFinalized (blockNumber) {
359
+ try {
360
+ const finalizedBlock = await this._provider.getBlock('finalized')
361
+ return !!finalizedBlock && blockNumber <= finalizedBlock.number
362
+ } catch (error) {
363
+ // Treat an unsupported 'finalized' block tag as not-finalized; let real failures propagate.
364
+ const rpcCode = error?.info?.error?.code
365
+
366
+ if (isError(error, 'UNSUPPORTED_OPERATION') || rpcCode === -32601 || rpcCode === -32602) {
367
+ return false
368
+ }
369
+
370
+ throw error
371
+ }
372
+ }
373
+
374
+ /**
375
+ * Returns whether an unmined transaction has been replaced, i.e. its sender's mined nonce has already advanced past the transaction's nonce.
376
+ *
377
+ * @protected
378
+ * @param {EvmTransactionResponse} transaction - The unmined transaction.
379
+ * @returns {Promise<boolean>} True if the transaction's nonce slot is already taken.
380
+ */
381
+ async _isReplaced (transaction) {
382
+ const accountNonce = await this._provider.getTransactionCount(transaction.from, 'latest')
383
+ return accountNonce > transaction.nonce
384
+ }
385
+
386
+ /**
387
+ * Overrides the base default to allow for slower EVM inclusion and confirmation.
388
+ *
389
+ * @type {number}
390
+ */
391
+ get defaultWaitTimeout () {
392
+ return 120000
393
+ }
394
+
274
395
  /**
275
396
  * Returns the current allowance for the given token and spender.
276
397
  * @param {string} token The token's address.
@@ -28,7 +28,7 @@ import SeedSignerEvm from './signers/seed-signer-evm.js'
28
28
 
29
29
  /** @typedef {import("@tetherto/wdk-wallet").FeeRates} FeeRates */
30
30
  /** @typedef {import("@tetherto/wdk-wallet").ISigner} ISigner */
31
- /** @typedef {import("@tetherto/wdk-wallet").SignerError} SignerError */
31
+ /** @typedef {import("@tetherto/wdk-wallet").InvalidSignerError} InvalidSignerError */
32
32
 
33
33
  /** @typedef {import('./wallet-account-evm.js').EvmWalletConfig} EvmWalletConfig */
34
34
 
@@ -118,7 +118,7 @@ export default class WalletManagerEvm extends WalletManager {
118
118
  * @param {string} [options.signerName] - The signer name. Omit to use the default signer.
119
119
  * @returns {Promise<WalletAccountEvm>} The account.
120
120
  * @throws {Error} If a signer name is given but no signer exists with that name.
121
- * @throws {SignerError} If the signer doesn't support account derivation.
121
+ * @throws {InvalidSignerError} If the signer doesn't support account derivation.
122
122
  */
123
123
 
124
124
  /**
@@ -159,7 +159,7 @@ export default class WalletManagerEvm extends WalletManager {
159
159
  * @param {string} [options.signerName] - The signer name. Omit to use the default signer.
160
160
  * @returns {Promise<WalletAccountEvm>} The account.
161
161
  * @throws {Error} If a signer name is given but no signer exists with that name.
162
- * @throws {SignerError} If the signer doesn't support account derivation.
162
+ * @throws {InvalidSignerError} If the signer doesn't support account derivation.
163
163
  */
164
164
  async getAccountByPath (path, options = {}) {
165
165
  const { signerName } = options
package/types/index.d.ts CHANGED
@@ -7,14 +7,20 @@ export type AuthorizationRequest = import("ethers").AuthorizationRequest;
7
7
  export type Authorization = import("ethers").Authorization;
8
8
  export type AuthorizationLike = import("ethers").AuthorizationLike;
9
9
  export type EvmTransactionReceipt = import("ethers").TransactionReceipt;
10
+ export type EvmTransactionResponse = import("ethers").TransactionResponse;
10
11
  export type FeeRates = import("@tetherto/wdk-wallet").FeeRates;
11
12
  export type KeyPair = import("@tetherto/wdk-wallet").KeyPair;
12
13
  export type TransactionResult = import("@tetherto/wdk-wallet").TransactionResult;
13
14
  export type TransferResult = import("@tetherto/wdk-wallet").TransferResult;
15
+ export type Finality = import("@tetherto/wdk-wallet").Finality;
16
+ export type TransactionReceipt = import("@tetherto/wdk-wallet").TransactionReceipt;
17
+ export type WaitForTransactionTarget = import("@tetherto/wdk-wallet").WaitForTransactionTarget;
18
+ export type WaitForTransactionOptions = import("@tetherto/wdk-wallet").WaitForTransactionOptions;
14
19
  export type TypedData = import("./src/wallet-account-read-only-evm.js").TypedData;
15
20
  export type DelegationInfo = import("./src/wallet-account-read-only-evm.js").DelegationInfo;
16
21
  export type EvmTransaction = import("./src/wallet-account-read-only-evm.js").EvmTransaction;
17
22
  export type EvmTransferOptions = import("./src/wallet-account-read-only-evm.js").EvmTransferOptions;
18
23
  export type EvmWalletConfig = import("./src/wallet-account-read-only-evm.js").EvmWalletConfig;
24
+ export type EvmTransactionDetails = import("./src/wallet-account-read-only-evm.js").EvmTransactionDetails;
19
25
  export type ApproveOptions = import("./src/wallet-account-evm.js").ApproveOptions;
20
26
  export type UnsignedEvmTransaction = import("./src/utils/tx-populator-evm.js").UnsignedEvmTransaction;
@@ -39,7 +39,7 @@ export default class PrivateKeySignerEvm extends ISignerEvm {
39
39
  /**
40
40
  * PrivateKeySignerEvm is not a hierarchical signer and cannot derive.
41
41
  * @returns {Promise<never>}
42
- * @throws {SignerError} Always — private-key signers do not support derivation.
42
+ * @throws {InvalidSignerError} Always — private-key signers do not support derivation.
43
43
  */
44
44
  derive(): Promise<never>;
45
45
  /** @returns {Promise<string>} */
@@ -79,7 +79,7 @@ export class ISignerEvm extends ISigner {
79
79
  *
80
80
  * @param {string} relPath - The relative BIP-44 path segment.
81
81
  * @returns {Promise<ISignerEvm>} The derived child signer.
82
- * @throws {SignerError} If the signer does not support derivation (e.g. private-key signers).
82
+ * @throws {InvalidSignerError} If the signer does not support derivation (e.g. private-key signers).
83
83
  */
84
84
  derive(relPath: string): Promise<ISignerEvm>;
85
85
  /**
@@ -71,10 +71,51 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
71
71
  /**
72
72
  * Returns a transaction's receipt.
73
73
  *
74
+ * @deprecated Use {@link getTransaction} instead, which returns a normalized, finality-based receipt. The raw ethers receipt remains available on its `receipt` property.
74
75
  * @param {string} hash - The transaction's hash.
75
76
  * @returns {Promise<EvmTransactionReceipt | null>} – The receipt, or null if the transaction has not been included in a block yet.
76
77
  */
77
78
  getTransactionReceipt(hash: string): Promise<EvmTransactionReceipt | null>;
79
+ /**
80
+ * Returns a normalized, finality-based receipt for a transaction.
81
+ *
82
+ * @param {string} hash - The transaction's hash.
83
+ * @returns {Promise<TransactionReceipt & EvmTransactionDetails>} The normalized receipt.
84
+ * @throws {ValueError} If the hash is not a valid transaction hash.
85
+ * @throws {NoSuchElementError} If no transaction has been found for the given hash.
86
+ */
87
+ getTransaction(hash: string): Promise<TransactionReceipt & EvmTransactionDetails>;
88
+ /**
89
+ * Blocks until a transaction reaches a terminal state (the requested finality target or `dropped`), or times out.
90
+ *
91
+ * @param {string} hash - The transaction's hash.
92
+ * @param {WaitForTransactionOptions} [options] - The wait options.
93
+ * @returns {Promise<TransactionReceipt & EvmTransactionDetails>} The terminal receipt: the finality target reached (inspect `success` to tell success from revert), or `dropped`.
94
+ * @throws {TimeoutError} If the target is not reached before the timeout.
95
+ */
96
+ waitForTransaction(hash: string, options?: WaitForTransactionOptions): Promise<TransactionReceipt & EvmTransactionDetails>;
97
+ /**
98
+ * Returns whether a block is at or below the chain's `finalized` block. Chains that don't support the tag are treated as not finalized.
99
+ *
100
+ * @protected
101
+ * @param {number} blockNumber - The block number to check.
102
+ * @returns {Promise<boolean>} True if the block is finalized.
103
+ */
104
+ protected _isFinalized(blockNumber: number): Promise<boolean>;
105
+ /**
106
+ * Returns whether an unmined transaction has been replaced, i.e. its sender's mined nonce has already advanced past the transaction's nonce.
107
+ *
108
+ * @protected
109
+ * @param {EvmTransactionResponse} transaction - The unmined transaction.
110
+ * @returns {Promise<boolean>} True if the transaction's nonce slot is already taken.
111
+ */
112
+ protected _isReplaced(transaction: EvmTransactionResponse): Promise<boolean>;
113
+ /**
114
+ * Overrides the base default to allow for slower EVM inclusion and confirmation.
115
+ *
116
+ * @type {number}
117
+ */
118
+ get defaultWaitTimeout(): number;
78
119
  /**
79
120
  * Returns the current allowance for the given token and spender.
80
121
  * @param {string} token The token's address.
@@ -113,8 +154,24 @@ export type TypedDataDomain = import("ethers").TypedDataDomain;
113
154
  export type TypedDataField = import("ethers").TypedDataField;
114
155
  export type AuthorizationLike = import("ethers").AuthorizationLike;
115
156
  export type EvmTransactionReceipt = import("ethers").TransactionReceipt;
157
+ export type EvmTransactionResponse = import("ethers").TransactionResponse;
116
158
  export type TransactionResult = import("@tetherto/wdk-wallet").TransactionResult;
117
159
  export type TransferResult = import("@tetherto/wdk-wallet").TransferResult;
160
+ export type TransactionReceipt = import("@tetherto/wdk-wallet").TransactionReceipt;
161
+ export type WaitForTransactionOptions = import("@tetherto/wdk-wallet").WaitForTransactionOptions;
162
+ /**
163
+ * The EVM-specific fields added to a normalized transaction receipt.
164
+ */
165
+ export type EvmTransactionDetails = {
166
+ /**
167
+ * - The number of confirmations (0 while pending or dropped).
168
+ */
169
+ confirmations: number;
170
+ /**
171
+ * - The native ethers receipt, or null while the transaction is pending or dropped.
172
+ */
173
+ receipt: EvmTransactionReceipt | null;
174
+ };
118
175
  export type TypedData = {
119
176
  /**
120
177
  * - The domain separator.
@@ -44,7 +44,7 @@ export default class WalletManagerEvm extends WalletManager {
44
44
  * @param {string} [options.signerName] - The signer name. Omit to use the default signer.
45
45
  * @returns {Promise<WalletAccountEvm>} The account.
46
46
  * @throws {Error} If a signer name is given but no signer exists with that name.
47
- * @throws {SignerError} If the signer doesn't support account derivation.
47
+ * @throws {InvalidSignerError} If the signer doesn't support account derivation.
48
48
  */
49
49
  getAccount(index?: number, options?: {
50
50
  signerName?: string;
@@ -67,7 +67,7 @@ export default class WalletManagerEvm extends WalletManager {
67
67
  * @param {string} [options.signerName] - The signer name. Omit to use the default signer.
68
68
  * @returns {Promise<WalletAccountEvm>} The account.
69
69
  * @throws {Error} If a signer name is given but no signer exists with that name.
70
- * @throws {SignerError} If the signer doesn't support account derivation.
70
+ * @throws {InvalidSignerError} If the signer doesn't support account derivation.
71
71
  */
72
72
  getAccountByPath(path: string, options?: {
73
73
  signerName?: string;