@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
|
@@ -14,18 +14,21 @@
|
|
|
14
14
|
|
|
15
15
|
'use strict'
|
|
16
16
|
|
|
17
|
-
import WalletManager from '@tetherto/wdk-wallet'
|
|
18
|
-
|
|
19
|
-
import { BrowserProvider, JsonRpcProvider } from 'ethers'
|
|
17
|
+
import WalletManager, { InvalidSignerError, ProviderRequiredError } from '@tetherto/wdk-wallet'
|
|
20
18
|
|
|
21
19
|
import WalletAccountEvm from './wallet-account-evm.js'
|
|
20
|
+
import SeedSignerEvm, { BIP_44_ETH_DERIVATION_PATH_PREFIX } from './signers/seed-signer-evm.js'
|
|
22
21
|
|
|
22
|
+
/** @typedef {import('./signers/signer-evm.js').ISignerEvm} ISignerEvm */
|
|
23
23
|
/** @typedef {import('ethers').Provider} Provider */
|
|
24
24
|
|
|
25
25
|
/** @typedef {import("@tetherto/wdk-wallet").FeeRates} FeeRates */
|
|
26
|
+
/** @typedef {import("@tetherto/wdk-wallet").NoSuchElementError} NoSuchElementError */
|
|
27
|
+
/** @typedef {import("@tetherto/wdk-wallet").ValueError} ValueError */
|
|
26
28
|
|
|
27
29
|
/** @typedef {import('./wallet-account-evm.js').EvmWalletConfig} EvmWalletConfig */
|
|
28
30
|
|
|
31
|
+
/** @extends {WalletManager<ISignerEvm>} */
|
|
29
32
|
export default class WalletManagerEvm extends WalletManager {
|
|
30
33
|
/**
|
|
31
34
|
* Multiplier for normal fee rate calculations (in %).
|
|
@@ -44,13 +47,48 @@ export default class WalletManagerEvm extends WalletManager {
|
|
|
44
47
|
static _FEE_RATE_FAST_MULTIPLIER = 200n
|
|
45
48
|
|
|
46
49
|
/**
|
|
47
|
-
* Creates a new wallet manager for evm blockchains.
|
|
50
|
+
* Creates a new wallet manager for evm blockchains from a BIP-39 seed.
|
|
48
51
|
*
|
|
49
|
-
* @
|
|
52
|
+
* @overload
|
|
53
|
+
* @param {string | Uint8Array} seed - A BIP-39 mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes).
|
|
50
54
|
* @param {EvmWalletConfig} [config] - The configuration object.
|
|
55
|
+
* @throws {ValueError} If the seed phrase is invalid.
|
|
51
56
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new wallet manager for evm blockchains from a default signer.
|
|
60
|
+
*
|
|
61
|
+
* The default signer must be derivable (it must be able to derive child accounts);
|
|
62
|
+
* non-derivable signers (e.g. private-key signers) are not allowed as the default but
|
|
63
|
+
* may be registered by name via {@link addSigner}. To use a single non-derivable signer
|
|
64
|
+
* outside of the wallet manager, create a standalone account instead.
|
|
65
|
+
* **Warning:** the signer is kept exactly as given, not cloned -- if you still hold a
|
|
66
|
+
* reference to it and dispose it directly, every subsequent {@link getAccount}/
|
|
67
|
+
* {@link getAccountByPath} call that falls back to the default signer (i.e. without an
|
|
68
|
+
* explicit `signerName`) fails, since deriving from a disposed signer isn't possible.
|
|
69
|
+
* Conversely, the manager never disposes a signer you supplied: {@link dispose} wipes
|
|
70
|
+
* only the default signer it creates internally from a seed.
|
|
71
|
+
*
|
|
72
|
+
* @overload
|
|
73
|
+
* @param {ISignerEvm} signer - The default signer.
|
|
74
|
+
* @param {EvmWalletConfig} [config] - The configuration object.
|
|
75
|
+
* @throws {InvalidSignerError} If the default signer does not support account derivation.
|
|
76
|
+
*/
|
|
77
|
+
constructor (seedOrSigner, config = {}) {
|
|
78
|
+
const isSeed = typeof seedOrSigner === 'string' || seedOrSigner instanceof Uint8Array
|
|
79
|
+
let signer = seedOrSigner
|
|
80
|
+
if (isSeed) {
|
|
81
|
+
signer = new SeedSignerEvm(seedOrSigner, BIP_44_ETH_DERIVATION_PATH_PREFIX)
|
|
82
|
+
}
|
|
83
|
+
super(signer, config)
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* If true, disposes the default signer on calls to the 'dispose' method.
|
|
87
|
+
*
|
|
88
|
+
* @protected
|
|
89
|
+
* @type {boolean}
|
|
90
|
+
*/
|
|
91
|
+
this._shouldWipeDefaultSignerOnDisposal = isSeed
|
|
54
92
|
|
|
55
93
|
/**
|
|
56
94
|
* The evm wallet configuration.
|
|
@@ -60,68 +98,132 @@ export default class WalletManagerEvm extends WalletManager {
|
|
|
60
98
|
*/
|
|
61
99
|
this._config = config
|
|
62
100
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
*/
|
|
72
|
-
this._provider = typeof provider === 'string'
|
|
73
|
-
? new JsonRpcProvider(provider)
|
|
74
|
-
: new BrowserProvider(provider)
|
|
75
|
-
}
|
|
101
|
+
/**
|
|
102
|
+
* An ethers provider to interact with a node of the blockchain. Shared with every account
|
|
103
|
+
* this manager creates, so two accounts never open two clients for the same endpoint.
|
|
104
|
+
*
|
|
105
|
+
* @protected
|
|
106
|
+
* @type {Provider | undefined}
|
|
107
|
+
*/
|
|
108
|
+
this._provider = WalletAccountEvm._buildProvider(config)
|
|
76
109
|
}
|
|
77
110
|
|
|
78
111
|
/**
|
|
79
|
-
* Returns the wallet account at a specific index
|
|
112
|
+
* Returns the wallet account at a specific index.
|
|
80
113
|
*
|
|
81
|
-
* @
|
|
82
|
-
* // Returns the account with derivation path m/44'/60'/0'/0/1
|
|
83
|
-
* const account = await wallet.getAccount(1);
|
|
114
|
+
* @overload
|
|
84
115
|
* @param {number} [index] - The index of the account to get (default: 0).
|
|
116
|
+
* @param {Object} [options] - Account options.
|
|
117
|
+
* @param {string} [options.signerName] - The signer name. Omit to use the default signer.
|
|
85
118
|
* @returns {Promise<WalletAccountEvm>} The account.
|
|
119
|
+
* @throws {NoSuchElementError} If a signer name is given but no signer exists with that name.
|
|
120
|
+
* @throws {InvalidSignerError} If the signer doesn't support account derivation.
|
|
86
121
|
*/
|
|
87
|
-
|
|
88
|
-
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Returns the wallet account associated with a registered signer.
|
|
125
|
+
*
|
|
126
|
+
* The registered signer is used exactly as given, wherever it happens to sit -- this
|
|
127
|
+
* overload never derives. For a private-key signer that's its one account; for a derivable
|
|
128
|
+
* signer, it's the account at that signer's own current path, unchanged. If you want a
|
|
129
|
+
* derived leaf from a derivable named signer (e.g. a second seed registered as a bank of
|
|
130
|
+
* accounts), use {@link getAccount}(index, { signerName }) or {@link getAccountByPath}(path,
|
|
131
|
+
* { signerName }) instead -- both of those always derive, and throw clearly if the named
|
|
132
|
+
* signer can't.
|
|
133
|
+
*
|
|
134
|
+
* **Warning:** the returned account wraps the registered signer itself, exactly where it
|
|
135
|
+
* sits -- e.g. a second seed registered at the intermediate path "m/44'/60'" yields the
|
|
136
|
+
* account AT "m/44'/60'", not at a derived leaf, which is rarely what you want to transact
|
|
137
|
+
* with. Disposing the returned account leaves the registered signer untouched.
|
|
138
|
+
*
|
|
139
|
+
* @overload
|
|
140
|
+
* @param {string} signerName - The signer name registered via {@link addSigner}.
|
|
141
|
+
* @returns {Promise<WalletAccountEvm>} The account.
|
|
142
|
+
* @throws {NoSuchElementError} If no signer exists with the given name.
|
|
143
|
+
*/
|
|
144
|
+
|
|
145
|
+
async getAccount (indexOrSignerName = 0, options = {}) {
|
|
146
|
+
if (typeof indexOrSignerName === 'string') {
|
|
147
|
+
const key = indexOrSignerName
|
|
148
|
+
if (this._accounts[key]) {
|
|
149
|
+
return this._accounts[key]
|
|
150
|
+
}
|
|
151
|
+
const signer = this.getSigner(indexOrSignerName)
|
|
152
|
+
const account = new WalletAccountEvm(signer, this._accountConfig())
|
|
153
|
+
this._accounts[key] = account
|
|
154
|
+
return account
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const { signerName } = options
|
|
158
|
+
return await this.getAccountByPath(`0'/0/${indexOrSignerName}`, { signerName })
|
|
89
159
|
}
|
|
90
160
|
|
|
91
161
|
/**
|
|
92
|
-
* Returns the wallet account at a specific
|
|
162
|
+
* Returns the wallet account at a specific derivation path.
|
|
93
163
|
*
|
|
94
|
-
* @example
|
|
95
|
-
* // Returns the account with derivation path m/44'/60'/0'/0/1
|
|
96
|
-
* const account = await wallet.getAccountByPath("0'/0/1");
|
|
97
164
|
* @param {string} path - The derivation path (e.g. "0'/0/0").
|
|
165
|
+
* @param {Object} [options] - Account options.
|
|
166
|
+
* @param {string} [options.signerName] - The signer name. Omit to use the default signer.
|
|
98
167
|
* @returns {Promise<WalletAccountEvm>} The account.
|
|
168
|
+
* @throws {NoSuchElementError} If a signer name is given but no signer exists with that name.
|
|
169
|
+
* @throws {InvalidSignerError} If the signer doesn't support account derivation.
|
|
99
170
|
*/
|
|
100
|
-
async getAccountByPath (path) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
this._accounts[
|
|
171
|
+
async getAccountByPath (path, options = {}) {
|
|
172
|
+
const { signerName } = options
|
|
173
|
+
const key = signerName ? `${signerName}:${path}` : path
|
|
174
|
+
if (this._accounts[key]) {
|
|
175
|
+
return this._accounts[key]
|
|
105
176
|
}
|
|
177
|
+
const signer = this.getSigner(signerName)
|
|
178
|
+
if (!signer.isDerivable) {
|
|
179
|
+
throw new InvalidSignerError('The signer does not support account derivation.')
|
|
180
|
+
}
|
|
181
|
+
const childSigner = await signer.derive(path)
|
|
182
|
+
const account = new WalletAccountEvm(childSigner, { ...this._accountConfig(), shouldWipeSignerOnDisposal: true })
|
|
183
|
+
this._accounts[key] = account
|
|
184
|
+
return account
|
|
185
|
+
}
|
|
106
186
|
|
|
107
|
-
|
|
187
|
+
/**
|
|
188
|
+
* Builds the account config, injecting the manager's shared provider so accounts reuse
|
|
189
|
+
* it instead of opening their own client.
|
|
190
|
+
*
|
|
191
|
+
* @private
|
|
192
|
+
* @returns {EvmWalletConfig} The account configuration.
|
|
193
|
+
*/
|
|
194
|
+
_accountConfig () {
|
|
195
|
+
return { ...this._config, provider: this._provider }
|
|
108
196
|
}
|
|
109
197
|
|
|
110
198
|
/**
|
|
111
199
|
* Returns the current fee rates.
|
|
112
200
|
*
|
|
113
201
|
* @returns {Promise<FeeRates>} The fee rates (in weis).
|
|
202
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
114
203
|
*/
|
|
115
204
|
async getFeeRates () {
|
|
116
205
|
if (!this._provider) {
|
|
117
|
-
throw new
|
|
206
|
+
throw new ProviderRequiredError('The wallet must be connected to a provider to get fee rates.')
|
|
118
207
|
}
|
|
119
208
|
|
|
120
|
-
const
|
|
209
|
+
const data = await this._provider.getFeeData()
|
|
210
|
+
|
|
211
|
+
const feeRate = data.maxFeePerGas || data.gasPrice
|
|
121
212
|
|
|
122
213
|
return {
|
|
123
|
-
normal:
|
|
124
|
-
fast:
|
|
214
|
+
normal: feeRate * WalletManagerEvm._FEE_RATE_NORMAL_MULTIPLIER / 100n,
|
|
215
|
+
fast: feeRate * WalletManagerEvm._FEE_RATE_FAST_MULTIPLIER / 100n
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Disposes all the wallet accounts, erasing their private keys from the memory.
|
|
221
|
+
*/
|
|
222
|
+
dispose () {
|
|
223
|
+
if (this._shouldWipeDefaultSignerOnDisposal) {
|
|
224
|
+
this._defaultSigner.dispose()
|
|
125
225
|
}
|
|
226
|
+
|
|
227
|
+
super.dispose()
|
|
126
228
|
}
|
|
127
229
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,11 +1,30 @@
|
|
|
1
1
|
export { default } from "./src/wallet-manager-evm.js";
|
|
2
2
|
export { default as WalletAccountReadOnlyEvm } from "./src/wallet-account-read-only-evm.js";
|
|
3
3
|
export { default as WalletAccountEvm } from "./src/wallet-account-evm.js";
|
|
4
|
+
export { ISigner } from "@tetherto/wdk-wallet";
|
|
5
|
+
export type TypedDataDomain = import("ethers").TypedDataDomain;
|
|
6
|
+
export type TypedDataField = import("ethers").TypedDataField;
|
|
7
|
+
export type AuthorizationRequest = import("ethers").AuthorizationRequest;
|
|
8
|
+
export type Authorization = import("ethers").Authorization;
|
|
9
|
+
export type AuthorizationLike = import("ethers").AuthorizationLike;
|
|
4
10
|
export type EvmTransactionReceipt = import("ethers").TransactionReceipt;
|
|
11
|
+
export type EvmTransactionResponse = import("ethers").TransactionResponse;
|
|
12
|
+
export type EvmTransactionRequest = import("ethers").TransactionRequest;
|
|
5
13
|
export type FeeRates = import("@tetherto/wdk-wallet").FeeRates;
|
|
6
14
|
export type KeyPair = import("@tetherto/wdk-wallet").KeyPair;
|
|
7
15
|
export type TransactionResult = import("@tetherto/wdk-wallet").TransactionResult;
|
|
8
|
-
export type TransferOptions = import("@tetherto/wdk-wallet").TransferOptions;
|
|
9
16
|
export type TransferResult = import("@tetherto/wdk-wallet").TransferResult;
|
|
17
|
+
export type TransferOptions = import("@tetherto/wdk-wallet").TransferOptions;
|
|
18
|
+
export type Finality = import("@tetherto/wdk-wallet").Finality;
|
|
19
|
+
export type TransactionReceipt = import("@tetherto/wdk-wallet").TransactionReceipt;
|
|
20
|
+
export type WaitForTransactionTarget = import("@tetherto/wdk-wallet").WaitForTransactionTarget;
|
|
21
|
+
export type WaitForTransactionOptions = import("@tetherto/wdk-wallet").WaitForTransactionOptions;
|
|
22
|
+
export type TypedData = import("./src/wallet-account-read-only-evm.js").TypedData;
|
|
23
|
+
export type DelegationInfo = import("./src/wallet-account-read-only-evm.js").DelegationInfo;
|
|
10
24
|
export type EvmTransaction = import("./src/wallet-account-read-only-evm.js").EvmTransaction;
|
|
25
|
+
export type EvmGasOverrides = import("./src/wallet-account-read-only-evm.js").EvmGasOverrides;
|
|
26
|
+
export type EvmTransferOptions = import("./src/wallet-account-read-only-evm.js").EvmTransferOptions;
|
|
11
27
|
export type EvmWalletConfig = import("./src/wallet-account-read-only-evm.js").EvmWalletConfig;
|
|
28
|
+
export type EvmTransactionDetails = import("./src/wallet-account-read-only-evm.js").EvmTransactionDetails;
|
|
29
|
+
export type ApproveOptions = import("./src/wallet-account-evm.js").ApproveOptions;
|
|
30
|
+
export type EvmApproveOptions = import("./src/wallet-account-evm.js").EvmApproveOptions;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { ISignerEvm } from "./signer-evm.js";
|
|
2
|
+
export { default, default as SeedSignerEvm } from "./seed-signer-evm.js";
|
|
3
|
+
export { default as PrivateKeySignerEvm } from "./private-key-signer-evm.js";
|
|
4
|
+
export type TransactionLike = import("./signer-evm.js").TransactionLike;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signer that wraps a raw private key in a memory-safe buffer, exposing a minimal
|
|
3
|
+
* interface for signing messages, transactions and typed data. This signer does
|
|
4
|
+
* not support derivation and always represents a single account.
|
|
5
|
+
*
|
|
6
|
+
* @implements {ISignerEvm}
|
|
7
|
+
*/
|
|
8
|
+
export default class PrivateKeySignerEvm implements ISignerEvm {
|
|
9
|
+
/**
|
|
10
|
+
* Create a signer from a raw private key.
|
|
11
|
+
*
|
|
12
|
+
* The supplied key is copied: the signer keeps its own internal copy alive until
|
|
13
|
+
* {@link dispose} zeroes it, and never wipes the supplied key, whose disposal
|
|
14
|
+
* remains the caller's responsibility.
|
|
15
|
+
*
|
|
16
|
+
* @param {string | Uint8Array} privateKey - The private key's hex string (with or without 0x) or byte sequence.
|
|
17
|
+
*/
|
|
18
|
+
constructor(privateKey: string | Uint8Array);
|
|
19
|
+
/** @private */
|
|
20
|
+
private _signingKey;
|
|
21
|
+
/** @private */
|
|
22
|
+
private _wallet;
|
|
23
|
+
/** @private */
|
|
24
|
+
private _address;
|
|
25
|
+
/**
|
|
26
|
+
* Whether this signer can derive child signers.
|
|
27
|
+
*
|
|
28
|
+
* @type {false}
|
|
29
|
+
*/
|
|
30
|
+
get isDerivable(): false;
|
|
31
|
+
/**
|
|
32
|
+
* The BIP 0044 derivation path.
|
|
33
|
+
*
|
|
34
|
+
* @type {string | null}
|
|
35
|
+
*/
|
|
36
|
+
get path(): string | null;
|
|
37
|
+
/**
|
|
38
|
+
* The account's address.
|
|
39
|
+
*
|
|
40
|
+
* @deprecated Use {@link getAddress} instead. This property will be removed in an upcoming
|
|
41
|
+
* release: not all signers (e.g. hardware signers) can expose the address synchronously.
|
|
42
|
+
* @type {string}
|
|
43
|
+
*/
|
|
44
|
+
get address(): string;
|
|
45
|
+
/**
|
|
46
|
+
* The account's key pair (private and public key buffers).
|
|
47
|
+
*
|
|
48
|
+
* @type {KeyPair}
|
|
49
|
+
*/
|
|
50
|
+
get keyPair(): KeyPair;
|
|
51
|
+
/**
|
|
52
|
+
* Derive a child signer using a relative path (e.g., "0'/0/0").
|
|
53
|
+
*
|
|
54
|
+
* @param {string} path - The relative derivation path.
|
|
55
|
+
* @returns {Promise<never>} The derived signer.
|
|
56
|
+
* @throws {UnsupportedOperationError} If the signer does not support account derivation.
|
|
57
|
+
* @throws {ValueError} If the path is not valid.
|
|
58
|
+
*/
|
|
59
|
+
derive(path: string): Promise<never>;
|
|
60
|
+
/**
|
|
61
|
+
* Returns the account's address.
|
|
62
|
+
*
|
|
63
|
+
* @returns {Promise<string>} The account's address.
|
|
64
|
+
*/
|
|
65
|
+
getAddress(): Promise<string>;
|
|
66
|
+
/**
|
|
67
|
+
* Signs a message.
|
|
68
|
+
*
|
|
69
|
+
* @param {string} message - The message to sign.
|
|
70
|
+
* @returns {Promise<string>} The message's signature.
|
|
71
|
+
*/
|
|
72
|
+
sign(message: string): Promise<string>;
|
|
73
|
+
/**
|
|
74
|
+
* Signs a transaction.
|
|
75
|
+
*
|
|
76
|
+
* @param {TransactionLike} tx - The transaction to sign.
|
|
77
|
+
* @returns {Promise<string>} The signed transaction as a hex string.
|
|
78
|
+
*/
|
|
79
|
+
signTransaction(tx: TransactionLike): Promise<string>;
|
|
80
|
+
/**
|
|
81
|
+
* Signs typed data according to EIP-712.
|
|
82
|
+
*
|
|
83
|
+
* @param {TypedData} typedData - The typed data to sign.
|
|
84
|
+
* @returns {Promise<string>} The typed data signature.
|
|
85
|
+
*/
|
|
86
|
+
signTypedData(typedData: TypedData): Promise<string>;
|
|
87
|
+
/**
|
|
88
|
+
* Signs an ERC-7702 authorization tuple.
|
|
89
|
+
*
|
|
90
|
+
* @param {AuthorizationRequest} auth - The authorization request.
|
|
91
|
+
* @returns {Promise<Authorization>} The signed authorization.
|
|
92
|
+
*/
|
|
93
|
+
signAuthorization(auth: AuthorizationRequest): Promise<Authorization>;
|
|
94
|
+
/**
|
|
95
|
+
* Disposes the signer, securely erasing its internal copy of the private key from memory.
|
|
96
|
+
*/
|
|
97
|
+
dispose(): void;
|
|
98
|
+
}
|
|
99
|
+
export type ISignerEvm = import("./signer-evm.js").ISignerEvm;
|
|
100
|
+
export type KeyPair = import("@tetherto/wdk-wallet").KeyPair;
|
|
101
|
+
export type UnsupportedOperationError = import("@tetherto/wdk-wallet").UnsupportedOperationError;
|
|
102
|
+
export type ValueError = import("@tetherto/wdk-wallet").ValueError;
|
|
103
|
+
export type TransactionLike = import("ethers").TransactionLike;
|
|
104
|
+
export type AuthorizationRequest = import("ethers").AuthorizationRequest;
|
|
105
|
+
export type Authorization = import("ethers").Authorization;
|
|
106
|
+
export type TypedData = import("../wallet-account-read-only-evm.js").TypedData;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
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.
|
|
7
|
+
*
|
|
8
|
+
* @implements {ISignerEvm}
|
|
9
|
+
*/
|
|
10
|
+
export default class SeedSignerEvm implements ISignerEvm {
|
|
11
|
+
/**
|
|
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.
|
|
17
|
+
*/
|
|
18
|
+
constructor(seed: string | Uint8Array, path?: string);
|
|
19
|
+
/** @private */
|
|
20
|
+
private _account;
|
|
21
|
+
/**
|
|
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}
|
|
26
|
+
*/
|
|
27
|
+
get isDerivable(): true;
|
|
28
|
+
/**
|
|
29
|
+
* The signer's absolute derivation path.
|
|
30
|
+
*
|
|
31
|
+
* @type {string}
|
|
32
|
+
*/
|
|
33
|
+
get path(): string;
|
|
34
|
+
/**
|
|
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}
|
|
40
|
+
*/
|
|
41
|
+
get address(): string;
|
|
42
|
+
/**
|
|
43
|
+
* The account's key pair (private and public key buffers).
|
|
44
|
+
*
|
|
45
|
+
* @type {KeyPair}
|
|
46
|
+
*/
|
|
47
|
+
get keyPair(): KeyPair;
|
|
48
|
+
/**
|
|
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.
|
|
53
|
+
*
|
|
54
|
+
* @param {string} relPath - The path segment to derive, relative to this signer's own path.
|
|
55
|
+
* @returns {Promise<SeedSignerEvm>} The derived child signer.
|
|
56
|
+
*/
|
|
57
|
+
derive(relPath: string): Promise<SeedSignerEvm>;
|
|
58
|
+
/**
|
|
59
|
+
* Returns the account's derived address.
|
|
60
|
+
*
|
|
61
|
+
* @returns {Promise<string>} The account's address.
|
|
62
|
+
*/
|
|
63
|
+
getAddress(): Promise<string>;
|
|
64
|
+
/**
|
|
65
|
+
* Signs a message.
|
|
66
|
+
*
|
|
67
|
+
* @param {string} message - The message to sign.
|
|
68
|
+
* @returns {Promise<string>} The message's signature.
|
|
69
|
+
*/
|
|
70
|
+
sign(message: string): Promise<string>;
|
|
71
|
+
/**
|
|
72
|
+
* Signs a transaction.
|
|
73
|
+
*
|
|
74
|
+
* @param {TransactionLike} tx - The transaction to sign.
|
|
75
|
+
* @returns {Promise<string>} The signed transaction as a hex string.
|
|
76
|
+
*/
|
|
77
|
+
signTransaction(tx: TransactionLike): Promise<string>;
|
|
78
|
+
/**
|
|
79
|
+
* Signs typed data according to EIP-712.
|
|
80
|
+
*
|
|
81
|
+
* @param {TypedData} typedData - The typed data to sign.
|
|
82
|
+
* @returns {Promise<string>} The typed data signature.
|
|
83
|
+
*/
|
|
84
|
+
signTypedData(typedData: TypedData): Promise<string>;
|
|
85
|
+
/**
|
|
86
|
+
* Signs an ERC-7702 authorization tuple.
|
|
87
|
+
*
|
|
88
|
+
* @param {AuthorizationRequest} auth - The authorization request.
|
|
89
|
+
* @returns {Promise<Authorization>} The signed authorization.
|
|
90
|
+
*/
|
|
91
|
+
signAuthorization(auth: AuthorizationRequest): Promise<Authorization>;
|
|
92
|
+
/**
|
|
93
|
+
* Disposes the signer, erasing its secrets from memory.
|
|
94
|
+
*/
|
|
95
|
+
dispose(): void;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Memory-safe BIP-32 HD node (implemented by the internal src/memory-safe/hd-node-wallet.js)
|
|
99
|
+
*/
|
|
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;
|
|
110
|
+
dispose(): void;
|
|
111
|
+
};
|
|
112
|
+
export type ISignerEvm = import("./signer-evm.js").ISignerEvm;
|
|
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;
|
|
116
|
+
export type AuthorizationRequest = import("ethers").AuthorizationRequest;
|
|
117
|
+
export type Authorization = import("ethers").Authorization;
|
|
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";
|