@tetherto/wdk-wallet-evm 1.0.0-beta.20 → 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/README.md +30 -27
- package/index.js +3 -2
- package/package.json +4 -2
- package/src/signers/bare.js +20 -0
- package/src/signers/index.js +3 -10
- package/src/signers/private-key-signer-evm.js +62 -52
- package/src/signers/seed-signer-evm.js +73 -202
- package/src/signers/signer-evm.js +69 -0
- package/src/wallet-account-evm.js +63 -33
- package/src/wallet-account-read-only-evm.js +41 -2
- package/src/wallet-manager-evm.js +70 -25
- package/types/index.d.ts +1 -1
- package/types/src/signers/index.d.ts +3 -2
- package/types/src/signers/private-key-signer-evm.d.ts +59 -34
- package/types/src/signers/seed-signer-evm.d.ts +83 -144
- package/types/src/signers/signer-evm.d.ts +41 -0
- package/types/src/wallet-account-evm.d.ts +44 -19
- package/types/src/wallet-account-read-only-evm.d.ts +39 -5
- package/types/src/wallet-manager-evm.d.ts +59 -21
- package/src/utils/tx-populator-evm.js +0 -202
- package/types/src/utils/tx-populator-evm.d.ts +0 -85
|
@@ -1,187 +1,126 @@
|
|
|
1
|
-
import { ISigner } from "@tetherto/wdk-wallet";
|
|
2
|
-
/** @typedef {import('../wallet-account-read-only-evm.js').TypedData} TypedData */
|
|
3
|
-
/** @typedef {import('@tetherto/wdk-wallet').KeyPair} KeyPair */
|
|
4
|
-
/** @typedef {import('ethers').AuthorizationRequest} AuthorizationRequest */
|
|
5
|
-
/** @typedef {import('ethers').Authorization} Authorization */
|
|
6
|
-
/** @typedef {import('ethers').AuthorizationLike} AuthorizationLike */
|
|
7
1
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
nonce: number;
|
|
14
|
-
from: string;
|
|
15
|
-
to: string | null;
|
|
16
|
-
data: string;
|
|
17
|
-
value: number | bigint;
|
|
18
|
-
type: number;
|
|
19
|
-
gasLimit: number | bigint;
|
|
20
|
-
gasPrice?: number | bigint;
|
|
21
|
-
maxFeePerGas?: number | bigint;
|
|
22
|
-
maxPriorityFeePerGas?: number | bigint;
|
|
23
|
-
accessList?: any[];
|
|
24
|
-
maxFeePerBlobGas?: number | bigint;
|
|
25
|
-
blobs?: any[];
|
|
26
|
-
blobVersionedHashes?: string[];
|
|
27
|
-
authorizationList?: AuthorizationLike[];
|
|
28
|
-
};
|
|
29
|
-
export type SeedSignerEvmOpts = {
|
|
30
|
-
/**
|
|
31
|
-
* An existing HD node wallet root to derive from (internal; set by {@link SeedSignerEvm#derive}).
|
|
32
|
-
*/
|
|
33
|
-
root?: object;
|
|
34
|
-
/**
|
|
35
|
-
* Relative BIP-44 path segment (e.g. "0'/0/0"). Defaults to the account at index 0.
|
|
36
|
-
*/
|
|
37
|
-
path?: string;
|
|
38
|
-
/**
|
|
39
|
-
* Internal. When true, the signer is a derived child and does not retain the root (set by {@link SeedSignerEvm#derive}).
|
|
40
|
-
*/
|
|
41
|
-
isChild?: boolean;
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Interface for EVM signers, extending the base `ISigner` from `@tetherto/wdk-wallet`.
|
|
2
|
+
* Signer implementation that derives keys from a BIP-39 seed using an HD path. Every signer
|
|
3
|
+
* holds exactly one HD node (the Ethereum BIP-44 coin node "m/44'/60'" by default, ready to
|
|
4
|
+
* derive accounts below it) and can derive child signers below its own path. Each signer owns
|
|
5
|
+
* an independent copy of its key, so disposing one never affects its parent, children or
|
|
6
|
+
* siblings.
|
|
45
7
|
*
|
|
46
|
-
* @
|
|
47
|
-
* @interface
|
|
8
|
+
* @implements {ISignerEvm}
|
|
48
9
|
*/
|
|
49
|
-
export class
|
|
10
|
+
export default class SeedSignerEvm implements ISignerEvm {
|
|
50
11
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* @
|
|
12
|
+
* Create a SeedSignerEvm from a BIP-39 seed.
|
|
13
|
+
*
|
|
14
|
+
* @param {string|Uint8Array} seed - A BIP-39 mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes).
|
|
15
|
+
* @param {string} [path] - A BIP-32 path (default: "m/44'/60'").
|
|
16
|
+
* @throws {ValueError} If the given seed phrase is invalid.
|
|
55
17
|
*/
|
|
56
|
-
|
|
18
|
+
constructor(seed: string | Uint8Array, path?: string);
|
|
19
|
+
/** @private */
|
|
20
|
+
private _account;
|
|
57
21
|
/**
|
|
58
|
-
*
|
|
59
|
-
*
|
|
22
|
+
* Whether this signer can derive child signers. Always true: every seed signer holds an
|
|
23
|
+
* HD node with a private key and can derive below its own path.
|
|
24
|
+
*
|
|
25
|
+
* @type {true}
|
|
60
26
|
*/
|
|
61
|
-
get
|
|
27
|
+
get isDerivable(): true;
|
|
62
28
|
/**
|
|
63
|
-
* The
|
|
64
|
-
*
|
|
29
|
+
* The signer's absolute derivation path.
|
|
30
|
+
*
|
|
31
|
+
* @type {string}
|
|
65
32
|
*/
|
|
66
|
-
get path(): string
|
|
33
|
+
get path(): string;
|
|
67
34
|
/**
|
|
68
|
-
* The account's address
|
|
69
|
-
*
|
|
35
|
+
* The account's derived address.
|
|
36
|
+
*
|
|
37
|
+
* @deprecated Use {@link getAddress} instead. This property will be removed in an upcoming
|
|
38
|
+
* release: not all signers (e.g. hardware signers) can expose the address synchronously.
|
|
39
|
+
* @type {string}
|
|
70
40
|
*/
|
|
71
|
-
get address(): string
|
|
41
|
+
get address(): string;
|
|
72
42
|
/**
|
|
73
|
-
* The account's key pair.
|
|
43
|
+
* The account's key pair (private and public key buffers).
|
|
44
|
+
*
|
|
74
45
|
* @type {KeyPair}
|
|
75
46
|
*/
|
|
76
47
|
get keyPair(): KeyPair;
|
|
77
48
|
/**
|
|
78
|
-
* Derive a child signer
|
|
49
|
+
* Derive a child signer relative to this signer's own path (e.g. calling derive("0'/0/1") on
|
|
50
|
+
* a signer at "m/44'/60'" yields a child at "m/44'/60'/0'/0/1"). Purely self-relative: no
|
|
51
|
+
* coin-specific prefix is ever assumed or injected. The child owns an independent copy of
|
|
52
|
+
* its key and can itself derive further.
|
|
79
53
|
*
|
|
80
|
-
* @param {string} relPath - The relative
|
|
81
|
-
* @returns {Promise<
|
|
82
|
-
* @throws {InvalidSignerError} If the signer does not support derivation (e.g. private-key signers).
|
|
54
|
+
* @param {string} relPath - The path segment to derive, relative to this signer's own path.
|
|
55
|
+
* @returns {Promise<SeedSignerEvm>} The derived child signer.
|
|
83
56
|
*/
|
|
84
|
-
derive(relPath: string): Promise<
|
|
57
|
+
derive(relPath: string): Promise<SeedSignerEvm>;
|
|
85
58
|
/**
|
|
86
|
-
* Returns the account's address.
|
|
87
|
-
*
|
|
59
|
+
* Returns the account's derived address.
|
|
60
|
+
*
|
|
61
|
+
* @returns {Promise<string>} The account's address.
|
|
88
62
|
*/
|
|
89
63
|
getAddress(): Promise<string>;
|
|
90
64
|
/**
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
* @
|
|
65
|
+
* Signs a message.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} message - The message to sign.
|
|
68
|
+
* @returns {Promise<string>} The message's signature.
|
|
94
69
|
*/
|
|
95
70
|
sign(message: string): Promise<string>;
|
|
96
71
|
/**
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
* @
|
|
72
|
+
* Signs a transaction.
|
|
73
|
+
*
|
|
74
|
+
* @param {TransactionLike} tx - The transaction to sign.
|
|
75
|
+
* @returns {Promise<string>} The signed transaction as a hex string.
|
|
100
76
|
*/
|
|
101
|
-
signTransaction(
|
|
77
|
+
signTransaction(tx: TransactionLike): Promise<string>;
|
|
102
78
|
/**
|
|
103
79
|
* Signs typed data according to EIP-712.
|
|
104
80
|
*
|
|
105
81
|
* @param {TypedData} typedData - The typed data to sign.
|
|
106
82
|
* @returns {Promise<string>} The typed data signature.
|
|
107
83
|
*/
|
|
108
|
-
signTypedData(
|
|
84
|
+
signTypedData(typedData: TypedData): Promise<string>;
|
|
109
85
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
* @
|
|
86
|
+
* Signs an ERC-7702 authorization tuple.
|
|
87
|
+
*
|
|
88
|
+
* @param {AuthorizationRequest} auth - The authorization request.
|
|
89
|
+
* @returns {Promise<Authorization>} The signed authorization.
|
|
113
90
|
*/
|
|
114
91
|
signAuthorization(auth: AuthorizationRequest): Promise<Authorization>;
|
|
115
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* Disposes the signer, erasing its secrets from memory.
|
|
94
|
+
*/
|
|
116
95
|
dispose(): void;
|
|
117
96
|
}
|
|
118
97
|
/**
|
|
119
|
-
*
|
|
120
|
-
* Signer implementation that derives keys from a BIP-39 seed using the BIP-44 Ethereum path.
|
|
121
|
-
* Always holds a derived account (index 0 by default). A root signer also retains the HD root
|
|
122
|
-
* and can derive child signers; a derived child holds only its own account.
|
|
98
|
+
* Memory-safe BIP-32 HD node (implemented by the internal src/memory-safe/hd-node-wallet.js)
|
|
123
99
|
*/
|
|
124
|
-
export
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
constructor(seed: string | Uint8Array | null, opts?: SeedSignerEvmOpts);
|
|
135
|
-
/** @private */
|
|
136
|
-
private _account;
|
|
137
|
-
/** @private */
|
|
138
|
-
private _address;
|
|
139
|
-
/** @private */
|
|
140
|
-
private _path;
|
|
141
|
-
/** @private */
|
|
142
|
-
private _root;
|
|
143
|
-
get isDerivable(): boolean;
|
|
144
|
-
get index(): number | undefined;
|
|
145
|
-
get path(): string | undefined;
|
|
146
|
-
get address(): string;
|
|
147
|
-
get keyPair(): KeyPair;
|
|
148
|
-
/**
|
|
149
|
-
* Derive a child signer using the provided relative path (e.g. "0'/0/0").
|
|
150
|
-
* @param {string} relPath
|
|
151
|
-
* @returns {Promise<SeedSignerEvm>}
|
|
152
|
-
* @throws {InvalidSignerError} If called on a derived child signer, which does not retain the root.
|
|
153
|
-
*/
|
|
154
|
-
derive(relPath: string): Promise<SeedSignerEvm>;
|
|
155
|
-
/**
|
|
156
|
-
* Sign a plain message string.
|
|
157
|
-
* @param {string} message
|
|
158
|
-
* @returns {Promise<string>}
|
|
159
|
-
*/
|
|
160
|
-
sign(message: string): Promise<string>;
|
|
161
|
-
/**
|
|
162
|
-
* Sign a transaction object and return its serialized form.
|
|
163
|
-
* @param {UnsignedEvmTransaction} unsignedTx
|
|
164
|
-
* @returns {Promise<string>}
|
|
165
|
-
*/
|
|
166
|
-
signTransaction(unsignedTx: UnsignedEvmTransaction): Promise<string>;
|
|
167
|
-
/**
|
|
168
|
-
* Signs typed data according to EIP-712.
|
|
169
|
-
*
|
|
170
|
-
* @param {TypedData} typedData - The typed data to sign.
|
|
171
|
-
* @returns {Promise<string>} The typed data signature.
|
|
172
|
-
*/
|
|
173
|
-
signTypedData({ domain, types, message }: TypedData): Promise<string>;
|
|
174
|
-
/**
|
|
175
|
-
* Sign an ERC-7702 authorization tuple.
|
|
176
|
-
* @param {AuthorizationRequest} auth
|
|
177
|
-
* @returns {Promise<Authorization>}
|
|
178
|
-
*/
|
|
179
|
-
signAuthorization(auth: AuthorizationRequest): Promise<Authorization>;
|
|
180
|
-
/** Disposes secrets from memory. */
|
|
100
|
+
export type MemorySafeHDNodeWallet = {
|
|
101
|
+
readonly address: string;
|
|
102
|
+
readonly path: string | null;
|
|
103
|
+
readonly index: number;
|
|
104
|
+
readonly depth: number;
|
|
105
|
+
readonly publicKey: string;
|
|
106
|
+
readonly privateKeyBuffer: Uint8Array | undefined;
|
|
107
|
+
readonly publicKeyBuffer: Uint8Array;
|
|
108
|
+
deriveChild(index: number): MemorySafeHDNodeWallet;
|
|
109
|
+
derivePath(path: string): MemorySafeHDNodeWallet;
|
|
181
110
|
dispose(): void;
|
|
182
|
-
}
|
|
183
|
-
export type
|
|
111
|
+
};
|
|
112
|
+
export type ISignerEvm = import("./signer-evm.js").ISignerEvm;
|
|
184
113
|
export type KeyPair = import("@tetherto/wdk-wallet").KeyPair;
|
|
114
|
+
export type ValueError = import("@tetherto/wdk-wallet").ValueError;
|
|
115
|
+
export type TransactionLike = import("ethers").TransactionLike;
|
|
185
116
|
export type AuthorizationRequest = import("ethers").AuthorizationRequest;
|
|
186
117
|
export type Authorization = import("ethers").Authorization;
|
|
187
|
-
export type
|
|
118
|
+
export type TypedData = import("../wallet-account-read-only-evm.js").TypedData;
|
|
119
|
+
/**
|
|
120
|
+
* Absolute BIP-44 prefix for Ethereum (m/purpose'/coin_type'). Exported so callers that want
|
|
121
|
+
* "the standard Ethereum path" (WalletAccountEvm's seed overload, WalletManagerEvm's own
|
|
122
|
+
* internal default signer) can compose an absolute path without hardcoding it themselves.
|
|
123
|
+
*
|
|
124
|
+
* @internal
|
|
125
|
+
*/
|
|
126
|
+
export const BIP_44_ETH_DERIVATION_PATH_PREFIX: "m/44'/60'";
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for EVM signers, extending the base `ISigner` from `@tetherto/wdk-wallet`.
|
|
3
|
+
*
|
|
4
|
+
* @interface
|
|
5
|
+
*/
|
|
6
|
+
export class ISignerEvm extends ISigner {
|
|
7
|
+
/**
|
|
8
|
+
* The account's address, if available.
|
|
9
|
+
*
|
|
10
|
+
* @deprecated Use {@link getAddress} instead. This property will be removed in an upcoming
|
|
11
|
+
* release: not all signers (e.g. hardware signers) can expose the address synchronously.
|
|
12
|
+
* @type {string | undefined}
|
|
13
|
+
*/
|
|
14
|
+
get address(): string | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Signs a transaction.
|
|
17
|
+
*
|
|
18
|
+
* @param {TransactionLike} tx - The transaction to sign.
|
|
19
|
+
* @returns {Promise<string>} The signed transaction as a hex string.
|
|
20
|
+
*/
|
|
21
|
+
signTransaction(tx: TransactionLike): Promise<string>;
|
|
22
|
+
/**
|
|
23
|
+
* Signs typed data according to EIP-712.
|
|
24
|
+
*
|
|
25
|
+
* @param {TypedData} typedData - The typed data to sign.
|
|
26
|
+
* @returns {Promise<string>} The typed data signature.
|
|
27
|
+
*/
|
|
28
|
+
signTypedData(typedData: TypedData): Promise<string>;
|
|
29
|
+
/**
|
|
30
|
+
* Signs an ERC-7702 authorization tuple.
|
|
31
|
+
*
|
|
32
|
+
* @param {AuthorizationRequest} auth - The authorization request.
|
|
33
|
+
* @returns {Promise<Authorization>} The signed authorization.
|
|
34
|
+
*/
|
|
35
|
+
signAuthorization(auth: AuthorizationRequest): Promise<Authorization>;
|
|
36
|
+
}
|
|
37
|
+
export type TransactionLike = import("ethers").TransactionLike;
|
|
38
|
+
export type AuthorizationRequest = import("ethers").AuthorizationRequest;
|
|
39
|
+
export type Authorization = import("ethers").Authorization;
|
|
40
|
+
export type TypedData = import("../wallet-account-read-only-evm.js").TypedData;
|
|
41
|
+
import { ISigner } from "@tetherto/wdk-wallet";
|
|
@@ -13,17 +13,34 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
|
|
|
13
13
|
* given BIP-44 path.
|
|
14
14
|
*
|
|
15
15
|
* @param {string | Uint8Array} seed - A BIP-39 mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes).
|
|
16
|
-
* @param {string} path - The BIP-44
|
|
16
|
+
* @param {string} path - The BIP-44 account path, relative to "m/44'/60'" (e.g. "0'/0/0").
|
|
17
17
|
* @param {EvmWalletConfig} [config] - The configuration object.
|
|
18
|
+
* @throws {ValueError} If the given seed phrase is invalid.
|
|
18
19
|
*/
|
|
19
20
|
constructor(seed: string | Uint8Array, path: string, config?: EvmWalletConfig);
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new evm wallet account from a BIP-39 seed at path m/44'/60'/0'/0/0.
|
|
23
|
+
*
|
|
24
|
+
* @param {string | Uint8Array} seed - A BIP-39 mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes).
|
|
25
|
+
* @param {EvmWalletConfig} [config] - The configuration object.
|
|
26
|
+
* @throws {ValueError} If the given seed phrase is invalid.
|
|
27
|
+
*/
|
|
28
|
+
constructor(seed: string | Uint8Array, config?: EvmWalletConfig);
|
|
20
29
|
/**
|
|
21
30
|
* Creates a new evm wallet account using a signer.
|
|
22
31
|
*
|
|
23
32
|
* @param {ISignerEvm} signer - A signer implementing the EVM signer interface.
|
|
24
|
-
* @param {EvmWalletConfig} [config] - The configuration object.
|
|
33
|
+
* @param {EvmWalletConfig & SignerOptions} [config] - The configuration object.
|
|
34
|
+
*/
|
|
35
|
+
constructor(signer: ISignerEvm, config?: EvmWalletConfig & SignerOptions);
|
|
36
|
+
/**
|
|
37
|
+
* If true, disposes the signer on calls to the 'dispose' method. Always true for an
|
|
38
|
+
* account created from a seed, which owns its internally created signer.
|
|
39
|
+
*
|
|
40
|
+
* @protected
|
|
41
|
+
* @type {boolean}
|
|
25
42
|
*/
|
|
26
|
-
|
|
43
|
+
protected _shouldWipeSignerOnDisposal: boolean;
|
|
27
44
|
/**
|
|
28
45
|
* The wallet account configuration.
|
|
29
46
|
*
|
|
@@ -34,17 +51,12 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
|
|
|
34
51
|
/** @private */
|
|
35
52
|
private _signer;
|
|
36
53
|
/**
|
|
37
|
-
* The derivation path
|
|
54
|
+
* The derivation path of this account (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)),
|
|
55
|
+
* or null if the account's signer is not bound to a BIP-44 position (e.g. private-key signers).
|
|
38
56
|
*
|
|
39
|
-
* @type {
|
|
57
|
+
* @type {string | null}
|
|
40
58
|
*/
|
|
41
|
-
get
|
|
42
|
-
/**
|
|
43
|
-
* The derivation path of this account (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)).
|
|
44
|
-
*
|
|
45
|
-
* @type {string}
|
|
46
|
-
*/
|
|
47
|
-
get path(): string;
|
|
59
|
+
get path(): string | null;
|
|
48
60
|
/**
|
|
49
61
|
* The account's key pair.
|
|
50
62
|
*
|
|
@@ -52,12 +64,11 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
|
|
|
52
64
|
* it's strongly recommended to treat the key pair as a read-only view of the keys. While it's still technically possible to alter their
|
|
53
65
|
* content, client code should never do so.
|
|
54
66
|
*
|
|
55
|
-
* @type {KeyPair}
|
|
67
|
+
* @type {KeyPair | null}
|
|
56
68
|
*/
|
|
57
|
-
get keyPair(): KeyPair;
|
|
69
|
+
get keyPair(): KeyPair | null;
|
|
58
70
|
/**
|
|
59
|
-
* Returns the account's address.
|
|
60
|
-
* underlying signer to resolve it, then caches it locally.
|
|
71
|
+
* Returns the account's address.
|
|
61
72
|
*
|
|
62
73
|
* @returns {Promise<string>} The account's address.
|
|
63
74
|
*/
|
|
@@ -89,7 +100,7 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
|
|
|
89
100
|
/**
|
|
90
101
|
* Sends a transaction.
|
|
91
102
|
*
|
|
92
|
-
* @param {EvmTransaction | string} tx - The transaction.
|
|
103
|
+
* @param {EvmTransaction | string} tx - The transaction, or a signed raw transaction as a hex string.
|
|
93
104
|
* @returns {Promise<TransactionResult>} The transaction's result.
|
|
94
105
|
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
95
106
|
* @throws {MaximumFeeExceededError} If the transaction's cost exceeds the maximum transaction fee option.
|
|
@@ -108,6 +119,7 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
|
|
|
108
119
|
* @param {EvmTransaction | string} tx - The transaction, or a signed raw transaction as a hex string.
|
|
109
120
|
* @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
|
|
110
121
|
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
122
|
+
* @throws {ValueError} If the transaction mixes fee fields that its type doesn't support, or a type 3 transaction omits `maxFeePerBlobGas`.
|
|
111
123
|
* @throws {Error} If the simulation of the transaction reverts, as an ethers error with code `CALL_EXCEPTION`.
|
|
112
124
|
*/
|
|
113
125
|
quoteSendTransaction(tx: EvmTransaction | string): Promise<Omit<TransactionResult, "hash">>;
|
|
@@ -138,8 +150,11 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
|
|
|
138
150
|
/**
|
|
139
151
|
* Signs an ERC-7702 authorization tuple.
|
|
140
152
|
*
|
|
153
|
+
* The chainId and nonce are populated from the provider when not explicitly provided.
|
|
154
|
+
*
|
|
141
155
|
* @param {AuthorizationRequest} auth - The authorization request.
|
|
142
156
|
* @returns {Promise<Authorization>} The signed authorization.
|
|
157
|
+
* @throws {ProviderRequiredError} If the chainId or nonce are not provided and the wallet is not connected to a provider.
|
|
143
158
|
*/
|
|
144
159
|
signAuthorization(auth: AuthorizationRequest): Promise<Authorization>;
|
|
145
160
|
/**
|
|
@@ -161,17 +176,21 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
|
|
|
161
176
|
*/
|
|
162
177
|
revokeDelegation(): Promise<TransactionResult>;
|
|
163
178
|
/**
|
|
164
|
-
* Disposes the wallet account, erasing the private key from the memory.
|
|
179
|
+
* Disposes the wallet account, erasing the private key from the memory. The signer is
|
|
180
|
+
* wiped only if the account owns it: always for an account created from a seed, otherwise
|
|
181
|
+
* only when `shouldWipeSignerOnDisposal` was set in the config -- a caller-supplied signer
|
|
182
|
+
* is left untouched by default.
|
|
165
183
|
*/
|
|
166
184
|
dispose(): void;
|
|
167
185
|
}
|
|
168
|
-
export type ISignerEvm = import("./signers/
|
|
186
|
+
export type ISignerEvm = import("./signers/signer-evm.js").ISignerEvm;
|
|
169
187
|
export type HDNodeWallet = import("ethers").HDNodeWallet;
|
|
170
188
|
export type AuthorizationRequest = import("ethers").AuthorizationRequest;
|
|
171
189
|
export type Authorization = import("ethers").Authorization;
|
|
172
190
|
export type AuthorizationLike = import("ethers").AuthorizationLike;
|
|
173
191
|
export type IWalletAccount<TSignedTransaction> = import("@tetherto/wdk-wallet").IWalletAccount<TSignedTransaction>;
|
|
174
192
|
export type KeyPair = import("@tetherto/wdk-wallet").KeyPair;
|
|
193
|
+
export type ProviderRequiredError = import("@tetherto/wdk-wallet").ProviderRequiredError;
|
|
175
194
|
export type TransactionResult = import("@tetherto/wdk-wallet").TransactionResult;
|
|
176
195
|
export type TransferResult = import("@tetherto/wdk-wallet").TransferResult;
|
|
177
196
|
export type TypedData = import("./wallet-account-read-only-evm.js").TypedData;
|
|
@@ -193,6 +212,12 @@ export type ApproveOptions = {
|
|
|
193
212
|
*/
|
|
194
213
|
amount: number | bigint;
|
|
195
214
|
};
|
|
215
|
+
export type SignerOptions = {
|
|
216
|
+
/**
|
|
217
|
+
* - If true, wipes the signer given at construction on calls to the 'dispose' method.
|
|
218
|
+
*/
|
|
219
|
+
shouldWipeSignerOnDisposal?: boolean;
|
|
220
|
+
};
|
|
196
221
|
/**
|
|
197
222
|
* The options of a token approval, extended with the optional gas overrides of an evm transaction.
|
|
198
223
|
*/
|
|
@@ -7,6 +7,34 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
7
7
|
* @returns {EvmGasOverrides} Only the gas and fee fields that are set on the options.
|
|
8
8
|
*/
|
|
9
9
|
protected static _getGasOverrides(options: EvmGasOverrides): EvmGasOverrides;
|
|
10
|
+
/**
|
|
11
|
+
* Whether a value is an EIP-1193 provider (e.g. a browser wallet).
|
|
12
|
+
*
|
|
13
|
+
* @protected
|
|
14
|
+
* @param {string | Eip1193Provider | Provider} value - The value to inspect.
|
|
15
|
+
* @returns {boolean} True if the value is an EIP-1193 provider.
|
|
16
|
+
*/
|
|
17
|
+
protected static _isEip1193Provider(value: string | Eip1193Provider | Provider): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Builds an ethers provider from the wallet configuration:
|
|
20
|
+
* - a url string -> a new `JsonRpcProvider`
|
|
21
|
+
* - an already-built ethers provider (or failover wrapper) -> reused as-is
|
|
22
|
+
* - anything else (EIP-1193 / browser wallet) -> wrapped in a `BrowserProvider`
|
|
23
|
+
* - an array of the above -> a `FailoverProvider` across each entry
|
|
24
|
+
*
|
|
25
|
+
* @protected
|
|
26
|
+
* @param {Omit<EvmWalletConfig, 'transferMaxFee' | 'transactionMaxFee'>} [config] - The configuration object.
|
|
27
|
+
* @returns {Provider | undefined} The provider, or undefined if none is configured.
|
|
28
|
+
*/
|
|
29
|
+
protected static _buildProvider(config?: Omit<EvmWalletConfig, "transferMaxFee" | "transactionMaxFee">): Provider | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Validates that a transaction does not mix fee fields its type doesn't support.
|
|
32
|
+
*
|
|
33
|
+
* @protected
|
|
34
|
+
* @param {EvmTransaction} tx - The transaction to validate.
|
|
35
|
+
* @throws {ValueError} If the transaction mixes fee fields that its type doesn't support, or a type 3 transaction omits `maxFeePerBlobGas`.
|
|
36
|
+
*/
|
|
37
|
+
protected static _validateFeeFields(tx: EvmTransaction): void;
|
|
10
38
|
/**
|
|
11
39
|
* Returns an evm transaction to execute the given token transfer.
|
|
12
40
|
*
|
|
@@ -37,11 +65,14 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
37
65
|
*/
|
|
38
66
|
protected _provider: Provider | undefined;
|
|
39
67
|
/**
|
|
40
|
-
* The account's address
|
|
68
|
+
* The account's address, or undefined if the account's signer doesn't expose its address
|
|
69
|
+
* synchronously.
|
|
41
70
|
*
|
|
42
|
-
* @
|
|
71
|
+
* @deprecated Use {@link getAddress} instead. This property will be removed in an upcoming
|
|
72
|
+
* release: not all signers (e.g. hardware signers) can expose the address synchronously.
|
|
73
|
+
* @type {string | undefined}
|
|
43
74
|
*/
|
|
44
|
-
get address(): string;
|
|
75
|
+
get address(): string | undefined;
|
|
45
76
|
/**
|
|
46
77
|
* Returns the account's eth balance.
|
|
47
78
|
*
|
|
@@ -76,6 +107,7 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
76
107
|
* @param {EvmTransaction} tx - The transaction.
|
|
77
108
|
* @returns {Promise<Omit<TransactionResult, 'hash'>>} The transaction's quotes.
|
|
78
109
|
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
110
|
+
* @throws {ValueError} If the transaction mixes fee fields that its type doesn't support, or a type 3 transaction omits `maxFeePerBlobGas`.
|
|
79
111
|
* @throws {Error} If the simulation of the transaction reverts, as an ethers error with code `CALL_EXCEPTION`.
|
|
80
112
|
*/
|
|
81
113
|
quoteSendTransaction(tx: EvmTransaction): Promise<Omit<TransactionResult, "hash">>;
|
|
@@ -85,6 +117,8 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
85
117
|
* @param {EvmTransferOptions} options - The transfer's options, including any gas overrides to carry onto the transaction.
|
|
86
118
|
* @returns {Promise<Omit<TransferResult, 'hash'>>} The transfer's quotes.
|
|
87
119
|
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
120
|
+
* @throws {ValueError} If the options mix gas override fields that the transaction's type doesn't support.
|
|
121
|
+
* @throws {Error} If the simulation of the transfer reverts, as an ethers error with code `CALL_EXCEPTION`.
|
|
88
122
|
*/
|
|
89
123
|
quoteTransfer(options: EvmTransferOptions): Promise<Omit<TransferResult, "hash">>;
|
|
90
124
|
/**
|
|
@@ -301,9 +335,9 @@ export type EvmGasOverrides = Pick<EvmTransaction, "gasLimit" | "gasPrice" | "ma
|
|
|
301
335
|
export type EvmTransferOptions = TransferOptions & EvmGasOverrides & Pick<EvmTransaction, "authorizationList">;
|
|
302
336
|
export type EvmWalletConfig = {
|
|
303
337
|
/**
|
|
304
|
-
* - The url of the rpc provider, or an instance of a class that implements eip-1193. It's also possible to provide an array of
|
|
338
|
+
* - The url of the rpc provider, an already-built ethers provider (e.g. a `JsonRpcProvider` or a failover wrapper), or an instance of a class that implements eip-1193. It's also possible to provide an array of these instead. In such case, connection errors will cause the wallet to automatically fallback on the next provider in the list. An already-built provider is reused as-is, which lets a manager share a single provider across all the accounts it creates.
|
|
305
339
|
*/
|
|
306
|
-
provider?: string | Eip1193Provider | Array<string | Eip1193Provider>;
|
|
340
|
+
provider?: string | Provider | Eip1193Provider | Array<string | Provider | Eip1193Provider>;
|
|
307
341
|
/**
|
|
308
342
|
* - If set and if 'provider' is a list of urls or EIP 1193 providers, the number of additional retry attempts after the initial call fails. Total attempts = `1 + retries`. For example, `retries: 3` with 4 providers will try each provider once before throwing. If `retries` exceeds the number of providers, the failover will loop back and retry already-failed providers in round-robin order. Default: 3.
|
|
309
343
|
*/
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
/** @
|
|
2
|
-
|
|
3
|
-
/** @typedef {import("@tetherto/wdk-wallet").ISigner} ISigner */
|
|
4
|
-
/** @typedef {import("@tetherto/wdk-wallet").NoSuchElementError} NoSuchElementError */
|
|
5
|
-
/** @typedef {import('./wallet-account-evm.js').EvmWalletConfig} EvmWalletConfig */
|
|
6
|
-
export default class WalletManagerEvm extends WalletManager {
|
|
1
|
+
/** @extends {WalletManager<ISignerEvm>} */
|
|
2
|
+
export default class WalletManagerEvm extends WalletManager<ISignerEvm> {
|
|
7
3
|
/**
|
|
8
4
|
* Multiplier for normal fee rate calculations (in %).
|
|
9
5
|
*
|
|
@@ -19,20 +15,42 @@ export default class WalletManagerEvm extends WalletManager {
|
|
|
19
15
|
*/
|
|
20
16
|
protected static _FEE_RATE_FAST_MULTIPLIER: bigint;
|
|
21
17
|
/**
|
|
22
|
-
* Creates a new wallet manager for evm blockchains.
|
|
18
|
+
* Creates a new wallet manager for evm blockchains from a BIP-39 seed.
|
|
23
19
|
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
|
|
20
|
+
* @param {string | Uint8Array} seed - A BIP-39 mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes).
|
|
21
|
+
* @param {EvmWalletConfig} [config] - The configuration object.
|
|
22
|
+
* @throws {ValueError} If the seed phrase is invalid.
|
|
23
|
+
*/
|
|
24
|
+
constructor(seed: string | Uint8Array, config?: EvmWalletConfig);
|
|
25
|
+
/**
|
|
26
|
+
* Creates a new wallet manager for evm blockchains from a default signer.
|
|
28
27
|
*
|
|
29
|
-
*
|
|
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.
|
|
30
40
|
* @param {EvmWalletConfig} [config] - The configuration object.
|
|
31
|
-
* @throws {InvalidSignerError} If the default signer
|
|
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.
|
|
46
|
+
*
|
|
47
|
+
* @protected
|
|
48
|
+
* @type {boolean}
|
|
32
49
|
*/
|
|
33
|
-
|
|
50
|
+
protected _shouldWipeDefaultSignerOnDisposal: boolean;
|
|
34
51
|
/**
|
|
35
|
-
* 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.
|
|
36
54
|
*
|
|
37
55
|
* @protected
|
|
38
56
|
* @type {Provider | undefined}
|
|
@@ -52,9 +70,20 @@ export default class WalletManagerEvm extends WalletManager {
|
|
|
52
70
|
signerName?: string;
|
|
53
71
|
}): Promise<WalletAccountEvm>;
|
|
54
72
|
/**
|
|
55
|
-
* Returns the wallet account associated with a registered signer.
|
|
56
|
-
*
|
|
57
|
-
*
|
|
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.
|
|
58
87
|
*
|
|
59
88
|
* @param {string} signerName - The signer name registered via {@link addSigner}.
|
|
60
89
|
* @returns {Promise<WalletAccountEvm>} The account.
|
|
@@ -74,19 +103,28 @@ export default class WalletManagerEvm extends WalletManager {
|
|
|
74
103
|
getAccountByPath(path: string, options?: {
|
|
75
104
|
signerName?: string;
|
|
76
105
|
}): Promise<WalletAccountEvm>;
|
|
106
|
+
/** @private */
|
|
107
|
+
private _accountConfig;
|
|
77
108
|
/**
|
|
78
109
|
* Returns the current fee rates.
|
|
79
110
|
*
|
|
80
111
|
* @returns {Promise<FeeRates>} The fee rates (in weis).
|
|
81
|
-
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
82
112
|
*/
|
|
83
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;
|
|
84
121
|
}
|
|
85
|
-
export type ISignerEvm = import("./signers/
|
|
122
|
+
export type ISignerEvm = import("./signers/signer-evm.js").ISignerEvm;
|
|
86
123
|
export type Provider = import("ethers").Provider;
|
|
87
124
|
export type FeeRates = import("@tetherto/wdk-wallet").FeeRates;
|
|
88
|
-
export type
|
|
125
|
+
export type InvalidSignerError = import("@tetherto/wdk-wallet").InvalidSignerError;
|
|
89
126
|
export type NoSuchElementError = import("@tetherto/wdk-wallet").NoSuchElementError;
|
|
127
|
+
export type ValueError = import("@tetherto/wdk-wallet").ValueError;
|
|
90
128
|
export type EvmWalletConfig = import("./wallet-account-evm.js").EvmWalletConfig;
|
|
91
129
|
import WalletManager from '@tetherto/wdk-wallet';
|
|
92
130
|
import WalletAccountEvm from './wallet-account-evm.js';
|