@tetherto/wdk-wallet-evm 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 +50 -0
- package/README.md +171 -218
- package/bare.js +3 -3
- package/{hardhat.config.cjs → hardhat.config.js} +4 -3
- package/index.js +24 -1
- package/package.json +31 -14
- package/src/memory-safe/hd-node-wallet.js +5 -4
- package/src/memory-safe/signing-key.js +4 -3
- package/src/multicall.js +75 -0
- package/src/signers/bare.js +20 -0
- package/src/signers/index.js +18 -0
- package/src/signers/private-key-signer-evm.js +166 -0
- package/src/signers/seed-signer-evm.js +185 -0
- package/src/signers/signer-evm.js +69 -0
- package/src/wallet-account-evm.js +307 -68
- package/src/wallet-account-read-only-evm.js +509 -33
- package/src/wallet-manager-evm.js +142 -40
- package/types/index.d.ts +20 -1
- package/types/src/signers/index.d.ts +4 -0
- package/types/src/signers/private-key-signer-evm.d.ts +106 -0
- package/types/src/signers/seed-signer-evm.d.ts +126 -0
- package/types/src/signers/signer-evm.d.ts +41 -0
- package/types/src/wallet-account-evm.d.ts +166 -32
- package/types/src/wallet-account-read-only-evm.d.ts +260 -14
- package/types/src/wallet-manager-evm.d.ts +79 -17
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
/** @extends {WalletManager<ISignerEvm>} */
|
|
2
|
+
export default class WalletManagerEvm extends WalletManager<ISignerEvm> {
|
|
2
3
|
/**
|
|
3
4
|
* Multiplier for normal fee rate calculations (in %).
|
|
4
5
|
*
|
|
@@ -14,55 +15,116 @@ export default class WalletManagerEvm extends WalletManager {
|
|
|
14
15
|
*/
|
|
15
16
|
protected static _FEE_RATE_FAST_MULTIPLIER: bigint;
|
|
16
17
|
/**
|
|
17
|
-
* Creates a new wallet manager for evm blockchains.
|
|
18
|
+
* Creates a new wallet manager for evm blockchains from a BIP-39 seed.
|
|
18
19
|
*
|
|
19
|
-
* @param {string | Uint8Array} seed -
|
|
20
|
+
* @param {string | Uint8Array} seed - A BIP-39 mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes).
|
|
20
21
|
* @param {EvmWalletConfig} [config] - The configuration object.
|
|
22
|
+
* @throws {ValueError} If the seed phrase is invalid.
|
|
21
23
|
*/
|
|
22
24
|
constructor(seed: string | Uint8Array, config?: EvmWalletConfig);
|
|
23
25
|
/**
|
|
24
|
-
*
|
|
26
|
+
* Creates a new wallet manager for evm blockchains from a default signer.
|
|
27
|
+
*
|
|
28
|
+
* The default signer must be derivable (it must be able to derive child accounts);
|
|
29
|
+
* non-derivable signers (e.g. private-key signers) are not allowed as the default but
|
|
30
|
+
* may be registered by name via {@link addSigner}. To use a single non-derivable signer
|
|
31
|
+
* outside of the wallet manager, create a standalone account instead.
|
|
32
|
+
* **Warning:** the signer is kept exactly as given, not cloned -- if you still hold a
|
|
33
|
+
* reference to it and dispose it directly, every subsequent {@link getAccount}/
|
|
34
|
+
* {@link getAccountByPath} call that falls back to the default signer (i.e. without an
|
|
35
|
+
* explicit `signerName`) fails, since deriving from a disposed signer isn't possible.
|
|
36
|
+
* Conversely, the manager never disposes a signer you supplied: {@link dispose} wipes
|
|
37
|
+
* only the default signer it creates internally from a seed.
|
|
38
|
+
*
|
|
39
|
+
* @param {ISignerEvm} signer - The default signer.
|
|
40
|
+
* @param {EvmWalletConfig} [config] - The configuration object.
|
|
41
|
+
* @throws {InvalidSignerError} If the default signer does not support account derivation.
|
|
42
|
+
*/
|
|
43
|
+
constructor(signer: ISignerEvm, config?: EvmWalletConfig);
|
|
44
|
+
/**
|
|
45
|
+
* If true, disposes the default signer on calls to the 'dispose' method.
|
|
25
46
|
*
|
|
26
47
|
* @protected
|
|
27
|
-
* @type {
|
|
48
|
+
* @type {boolean}
|
|
28
49
|
*/
|
|
29
|
-
protected
|
|
50
|
+
protected _shouldWipeDefaultSignerOnDisposal: boolean;
|
|
30
51
|
/**
|
|
31
|
-
* An ethers provider to interact with a node of the blockchain.
|
|
52
|
+
* An ethers provider to interact with a node of the blockchain. Shared with every account
|
|
53
|
+
* this manager creates, so two accounts never open two clients for the same endpoint.
|
|
32
54
|
*
|
|
33
55
|
* @protected
|
|
34
56
|
* @type {Provider | undefined}
|
|
35
57
|
*/
|
|
36
58
|
protected _provider: Provider | undefined;
|
|
37
59
|
/**
|
|
38
|
-
* Returns the wallet account at a specific index
|
|
60
|
+
* Returns the wallet account at a specific index.
|
|
39
61
|
*
|
|
40
|
-
* @example
|
|
41
|
-
* // Returns the account with derivation path m/44'/60'/0'/0/1
|
|
42
|
-
* const account = await wallet.getAccount(1);
|
|
43
62
|
* @param {number} [index] - The index of the account to get (default: 0).
|
|
63
|
+
* @param {Object} [options] - Account options.
|
|
64
|
+
* @param {string} [options.signerName] - The signer name. Omit to use the default signer.
|
|
44
65
|
* @returns {Promise<WalletAccountEvm>} The account.
|
|
66
|
+
* @throws {NoSuchElementError} If a signer name is given but no signer exists with that name.
|
|
67
|
+
* @throws {InvalidSignerError} If the signer doesn't support account derivation.
|
|
45
68
|
*/
|
|
46
|
-
getAccount(index?: number
|
|
69
|
+
getAccount(index?: number, options?: {
|
|
70
|
+
signerName?: string;
|
|
71
|
+
}): Promise<WalletAccountEvm>;
|
|
47
72
|
/**
|
|
48
|
-
* Returns the wallet account
|
|
73
|
+
* Returns the wallet account associated with a registered signer.
|
|
74
|
+
*
|
|
75
|
+
* The registered signer is used exactly as given, wherever it happens to sit -- this
|
|
76
|
+
* overload never derives. For a private-key signer that's its one account; for a derivable
|
|
77
|
+
* signer, it's the account at that signer's own current path, unchanged. If you want a
|
|
78
|
+
* derived leaf from a derivable named signer (e.g. a second seed registered as a bank of
|
|
79
|
+
* accounts), use {@link getAccount}(index, { signerName }) or {@link getAccountByPath}(path,
|
|
80
|
+
* { signerName }) instead -- both of those always derive, and throw clearly if the named
|
|
81
|
+
* signer can't.
|
|
82
|
+
*
|
|
83
|
+
* **Warning:** the returned account wraps the registered signer itself, exactly where it
|
|
84
|
+
* sits -- e.g. a second seed registered at the intermediate path "m/44'/60'" yields the
|
|
85
|
+
* account AT "m/44'/60'", not at a derived leaf, which is rarely what you want to transact
|
|
86
|
+
* with. Disposing the returned account leaves the registered signer untouched.
|
|
87
|
+
*
|
|
88
|
+
* @param {string} signerName - The signer name registered via {@link addSigner}.
|
|
89
|
+
* @returns {Promise<WalletAccountEvm>} The account.
|
|
90
|
+
* @throws {NoSuchElementError} If no signer exists with the given name.
|
|
91
|
+
*/
|
|
92
|
+
getAccount(signerName: string): Promise<WalletAccountEvm>;
|
|
93
|
+
/**
|
|
94
|
+
* Returns the wallet account at a specific derivation path.
|
|
49
95
|
*
|
|
50
|
-
* @example
|
|
51
|
-
* // Returns the account with derivation path m/44'/60'/0'/0/1
|
|
52
|
-
* const account = await wallet.getAccountByPath("0'/0/1");
|
|
53
96
|
* @param {string} path - The derivation path (e.g. "0'/0/0").
|
|
97
|
+
* @param {Object} [options] - Account options.
|
|
98
|
+
* @param {string} [options.signerName] - The signer name. Omit to use the default signer.
|
|
54
99
|
* @returns {Promise<WalletAccountEvm>} The account.
|
|
100
|
+
* @throws {NoSuchElementError} If a signer name is given but no signer exists with that name.
|
|
101
|
+
* @throws {InvalidSignerError} If the signer doesn't support account derivation.
|
|
55
102
|
*/
|
|
56
|
-
getAccountByPath(path: string
|
|
103
|
+
getAccountByPath(path: string, options?: {
|
|
104
|
+
signerName?: string;
|
|
105
|
+
}): Promise<WalletAccountEvm>;
|
|
106
|
+
/** @private */
|
|
107
|
+
private _accountConfig;
|
|
57
108
|
/**
|
|
58
109
|
* Returns the current fee rates.
|
|
59
110
|
*
|
|
60
111
|
* @returns {Promise<FeeRates>} The fee rates (in weis).
|
|
61
112
|
*/
|
|
62
113
|
getFeeRates(): Promise<FeeRates>;
|
|
114
|
+
/**
|
|
115
|
+
* Disposes all the wallet accounts, erasing their private keys from the memory. If the
|
|
116
|
+
* manager was created from a seed, the internally created default signer is wiped too;
|
|
117
|
+
* a default signer supplied at construction is left untouched, as are signers registered
|
|
118
|
+
* via {@link addSigner}.
|
|
119
|
+
*/
|
|
120
|
+
dispose(): void;
|
|
63
121
|
}
|
|
122
|
+
export type ISignerEvm = import("./signers/signer-evm.js").ISignerEvm;
|
|
64
123
|
export type Provider = import("ethers").Provider;
|
|
65
124
|
export type FeeRates = import("@tetherto/wdk-wallet").FeeRates;
|
|
125
|
+
export type InvalidSignerError = import("@tetherto/wdk-wallet").InvalidSignerError;
|
|
126
|
+
export type NoSuchElementError = import("@tetherto/wdk-wallet").NoSuchElementError;
|
|
127
|
+
export type ValueError = import("@tetherto/wdk-wallet").ValueError;
|
|
66
128
|
export type EvmWalletConfig = import("./wallet-account-evm.js").EvmWalletConfig;
|
|
67
129
|
import WalletManager from '@tetherto/wdk-wallet';
|
|
68
130
|
import WalletAccountEvm from './wallet-account-evm.js';
|