@tetherto/wdk-wallet-evm 1.0.0-beta.2 → 1.0.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +50 -0
- package/README.md +174 -224
- package/bare.js +3 -3
- package/{hardhat.config.cjs → hardhat.config.js} +4 -3
- package/index.js +23 -1
- package/package.json +29 -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/index.js +25 -0
- package/src/signers/private-key-signer-evm.js +156 -0
- package/src/signers/seed-signer-evm.js +314 -0
- package/src/utils/tx-populator-evm.js +202 -0
- package/src/wallet-account-evm.js +272 -63
- package/src/wallet-account-read-only-evm.js +470 -33
- package/src/wallet-manager-evm.js +96 -39
- package/types/index.d.ts +20 -1
- package/types/src/signers/index.d.ts +3 -0
- package/types/src/signers/private-key-signer-evm.d.ts +81 -0
- package/types/src/signers/seed-signer-evm.d.ts +187 -0
- package/types/src/utils/tx-populator-evm.d.ts +85 -0
- package/types/src/wallet-account-evm.d.ts +131 -22
- package/types/src/wallet-account-read-only-evm.d.ts +226 -14
- package/types/src/wallet-manager-evm.d.ts +43 -19
|
@@ -14,15 +14,17 @@
|
|
|
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 from './signers/seed-signer-evm.js'
|
|
22
21
|
|
|
22
|
+
/** @typedef {import('./signers/seed-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").ISigner} ISigner */
|
|
27
|
+
/** @typedef {import("@tetherto/wdk-wallet").NoSuchElementError} NoSuchElementError */
|
|
26
28
|
|
|
27
29
|
/** @typedef {import('./wallet-account-evm.js').EvmWalletConfig} EvmWalletConfig */
|
|
28
30
|
|
|
@@ -46,11 +48,24 @@ export default class WalletManagerEvm extends WalletManager {
|
|
|
46
48
|
/**
|
|
47
49
|
* Creates a new wallet manager for evm blockchains.
|
|
48
50
|
*
|
|
49
|
-
*
|
|
51
|
+
* Accepts either a BIP-39 seed (string/Uint8Array) for backwards compatibility, or a
|
|
52
|
+
* pre-built root signer object. The default signer must be derivable (it must be able to
|
|
53
|
+
* derive child accounts); non-derivable signers (e.g. private-key signers) are not allowed
|
|
54
|
+
* as the default but may be registered by name via {@link addSigner} - If not adding to your global account managment for using just one non derivable signer create a standalone account.
|
|
55
|
+
*
|
|
56
|
+
* @param {string|Uint8Array|ISigner} seedOrSigner - A BIP-39 mnemonic seed phrase, a raw BIP-32 master seed (16-64 bytes), or a root signer. Root signers must be derivable — non-derivable signers (e.g. private-key signers) can only be registered by name via {@link addSigner}.
|
|
50
57
|
* @param {EvmWalletConfig} [config] - The configuration object.
|
|
58
|
+
* @throws {InvalidSignerError} If the default signer doesn't support account derivation.
|
|
51
59
|
*/
|
|
52
|
-
constructor (
|
|
53
|
-
|
|
60
|
+
constructor (seedOrSigner, config = {}) {
|
|
61
|
+
let signer = seedOrSigner
|
|
62
|
+
if (typeof seedOrSigner === 'string' || seedOrSigner instanceof Uint8Array) {
|
|
63
|
+
signer = new SeedSignerEvm(seedOrSigner)
|
|
64
|
+
}
|
|
65
|
+
if (!signer.isDerivable) {
|
|
66
|
+
throw new InvalidSignerError('The default signer must be derivable. Non-derivable signers (e.g. private-key signers) can only be registered by name via addSigner.')
|
|
67
|
+
}
|
|
68
|
+
super(signer, config)
|
|
54
69
|
|
|
55
70
|
/**
|
|
56
71
|
* The evm wallet configuration.
|
|
@@ -60,68 +75,110 @@ export default class WalletManagerEvm extends WalletManager {
|
|
|
60
75
|
*/
|
|
61
76
|
this._config = config
|
|
62
77
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
*/
|
|
72
|
-
this._provider = typeof provider === 'string'
|
|
73
|
-
? new JsonRpcProvider(provider)
|
|
74
|
-
: new BrowserProvider(provider)
|
|
75
|
-
}
|
|
78
|
+
/**
|
|
79
|
+
* An ethers provider to interact with a node of the blockchain. Shared with every account
|
|
80
|
+
* this manager creates, so two accounts never open two clients for the same endpoint.
|
|
81
|
+
*
|
|
82
|
+
* @protected
|
|
83
|
+
* @type {Provider | undefined}
|
|
84
|
+
*/
|
|
85
|
+
this._provider = WalletAccountEvm._buildProvider(config)
|
|
76
86
|
}
|
|
77
87
|
|
|
78
88
|
/**
|
|
79
|
-
* Returns the wallet account at a specific index
|
|
89
|
+
* Returns the wallet account at a specific index.
|
|
80
90
|
*
|
|
81
|
-
* @
|
|
82
|
-
* // Returns the account with derivation path m/44'/60'/0'/0/1
|
|
83
|
-
* const account = await wallet.getAccount(1);
|
|
91
|
+
* @overload
|
|
84
92
|
* @param {number} [index] - The index of the account to get (default: 0).
|
|
93
|
+
* @param {Object} [options] - Account options.
|
|
94
|
+
* @param {string} [options.signerName] - The signer name. Omit to use the default signer.
|
|
85
95
|
* @returns {Promise<WalletAccountEvm>} The account.
|
|
96
|
+
* @throws {NoSuchElementError} If a signer name is given but no signer exists with that name.
|
|
97
|
+
* @throws {InvalidSignerError} If the signer doesn't support account derivation.
|
|
86
98
|
*/
|
|
87
|
-
|
|
88
|
-
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Returns the wallet account associated with a registered signer. Non-derivable
|
|
102
|
+
* signers (e.g. private-key signers) return the signer's single account; derivable signers
|
|
103
|
+
* derive a detached child at the signer's own account (the root is never handed out).
|
|
104
|
+
*
|
|
105
|
+
* @overload
|
|
106
|
+
* @param {string} signerName - The signer name registered via {@link addSigner}.
|
|
107
|
+
* @returns {Promise<WalletAccountEvm>} The account.
|
|
108
|
+
* @throws {NoSuchElementError} If no signer exists with the given name.
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
async getAccount (indexOrSignerName = 0, options = {}) {
|
|
112
|
+
if (typeof indexOrSignerName === 'string') {
|
|
113
|
+
const key = `${indexOrSignerName}#self`
|
|
114
|
+
if (this._accounts[key]) {
|
|
115
|
+
return this._accounts[key]
|
|
116
|
+
}
|
|
117
|
+
const signer = this.getSigner(indexOrSignerName)
|
|
118
|
+
const accountSigner = signer.isDerivable
|
|
119
|
+
? await signer.derive(signer.path.split('/').slice(-3).join('/'))
|
|
120
|
+
: signer
|
|
121
|
+
const account = new WalletAccountEvm(accountSigner, this._accountConfig())
|
|
122
|
+
this._accounts[key] = account
|
|
123
|
+
return account
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const { signerName } = options
|
|
127
|
+
return await this.getAccountByPath(`0'/0/${indexOrSignerName}`, { signerName })
|
|
89
128
|
}
|
|
90
129
|
|
|
91
130
|
/**
|
|
92
|
-
* Returns the wallet account at a specific
|
|
131
|
+
* Returns the wallet account at a specific derivation path.
|
|
93
132
|
*
|
|
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
133
|
* @param {string} path - The derivation path (e.g. "0'/0/0").
|
|
134
|
+
* @param {Object} [options] - Account options.
|
|
135
|
+
* @param {string} [options.signerName] - The signer name. Omit to use the default signer.
|
|
98
136
|
* @returns {Promise<WalletAccountEvm>} The account.
|
|
137
|
+
* @throws {NoSuchElementError} If a signer name is given but no signer exists with that name.
|
|
138
|
+
* @throws {InvalidSignerError} If the signer doesn't support account derivation.
|
|
99
139
|
*/
|
|
100
|
-
async getAccountByPath (path) {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
this._accounts[
|
|
140
|
+
async getAccountByPath (path, options = {}) {
|
|
141
|
+
const { signerName } = options
|
|
142
|
+
const key = `${signerName ?? ''}:${path}`
|
|
143
|
+
if (this._accounts[key]) {
|
|
144
|
+
return this._accounts[key]
|
|
105
145
|
}
|
|
146
|
+
const signer = this.getSigner(signerName)
|
|
147
|
+
const childSigner = await signer.derive(path)
|
|
148
|
+
const account = new WalletAccountEvm(childSigner, this._accountConfig())
|
|
149
|
+
this._accounts[key] = account
|
|
150
|
+
return account
|
|
151
|
+
}
|
|
106
152
|
|
|
107
|
-
|
|
153
|
+
/**
|
|
154
|
+
* Builds the account config, injecting the manager's shared provider so accounts reuse
|
|
155
|
+
* it instead of opening their own client.
|
|
156
|
+
*
|
|
157
|
+
* @private
|
|
158
|
+
* @returns {EvmWalletConfig} The account configuration.
|
|
159
|
+
*/
|
|
160
|
+
_accountConfig () {
|
|
161
|
+
return { ...this._config, provider: this._provider }
|
|
108
162
|
}
|
|
109
163
|
|
|
110
164
|
/**
|
|
111
165
|
* Returns the current fee rates.
|
|
112
166
|
*
|
|
113
167
|
* @returns {Promise<FeeRates>} The fee rates (in weis).
|
|
168
|
+
* @throws {ProviderRequiredError} If the wallet is not connected to a provider.
|
|
114
169
|
*/
|
|
115
170
|
async getFeeRates () {
|
|
116
171
|
if (!this._provider) {
|
|
117
|
-
throw new
|
|
172
|
+
throw new ProviderRequiredError('The wallet must be connected to a provider to get fee rates.')
|
|
118
173
|
}
|
|
119
174
|
|
|
120
|
-
const
|
|
175
|
+
const data = await this._provider.getFeeData()
|
|
176
|
+
|
|
177
|
+
const feeRate = data.maxFeePerGas || data.gasPrice
|
|
121
178
|
|
|
122
179
|
return {
|
|
123
|
-
normal:
|
|
124
|
-
fast:
|
|
180
|
+
normal: feeRate * WalletManagerEvm._FEE_RATE_NORMAL_MULTIPLIER / 100n,
|
|
181
|
+
fast: feeRate * WalletManagerEvm._FEE_RATE_FAST_MULTIPLIER / 100n
|
|
125
182
|
}
|
|
126
183
|
}
|
|
127
184
|
}
|
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 type TypedDataDomain = import("ethers").TypedDataDomain;
|
|
5
|
+
export type TypedDataField = import("ethers").TypedDataField;
|
|
6
|
+
export type AuthorizationRequest = import("ethers").AuthorizationRequest;
|
|
7
|
+
export type Authorization = import("ethers").Authorization;
|
|
8
|
+
export type AuthorizationLike = import("ethers").AuthorizationLike;
|
|
4
9
|
export type EvmTransactionReceipt = import("ethers").TransactionReceipt;
|
|
10
|
+
export type EvmTransactionResponse = import("ethers").TransactionResponse;
|
|
11
|
+
export type EvmTransactionRequest = import("ethers").TransactionRequest;
|
|
5
12
|
export type FeeRates = import("@tetherto/wdk-wallet").FeeRates;
|
|
6
13
|
export type KeyPair = import("@tetherto/wdk-wallet").KeyPair;
|
|
7
14
|
export type TransactionResult = import("@tetherto/wdk-wallet").TransactionResult;
|
|
8
|
-
export type TransferOptions = import("@tetherto/wdk-wallet").TransferOptions;
|
|
9
15
|
export type TransferResult = import("@tetherto/wdk-wallet").TransferResult;
|
|
16
|
+
export type TransferOptions = import("@tetherto/wdk-wallet").TransferOptions;
|
|
17
|
+
export type Finality = import("@tetherto/wdk-wallet").Finality;
|
|
18
|
+
export type TransactionReceipt = import("@tetherto/wdk-wallet").TransactionReceipt;
|
|
19
|
+
export type WaitForTransactionTarget = import("@tetherto/wdk-wallet").WaitForTransactionTarget;
|
|
20
|
+
export type WaitForTransactionOptions = import("@tetherto/wdk-wallet").WaitForTransactionOptions;
|
|
21
|
+
export type TypedData = import("./src/wallet-account-read-only-evm.js").TypedData;
|
|
22
|
+
export type DelegationInfo = import("./src/wallet-account-read-only-evm.js").DelegationInfo;
|
|
10
23
|
export type EvmTransaction = import("./src/wallet-account-read-only-evm.js").EvmTransaction;
|
|
24
|
+
export type EvmGasOverrides = import("./src/wallet-account-read-only-evm.js").EvmGasOverrides;
|
|
25
|
+
export type EvmTransferOptions = import("./src/wallet-account-read-only-evm.js").EvmTransferOptions;
|
|
11
26
|
export type EvmWalletConfig = import("./src/wallet-account-read-only-evm.js").EvmWalletConfig;
|
|
27
|
+
export type EvmTransactionDetails = import("./src/wallet-account-read-only-evm.js").EvmTransactionDetails;
|
|
28
|
+
export type ApproveOptions = import("./src/wallet-account-evm.js").ApproveOptions;
|
|
29
|
+
export type EvmApproveOptions = import("./src/wallet-account-evm.js").EvmApproveOptions;
|
|
30
|
+
export type UnsignedEvmTransaction = import("./src/utils/tx-populator-evm.js").UnsignedEvmTransaction;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { ISignerEvm } from "./seed-signer-evm.js";
|
|
2
|
+
/** @typedef {import('./seed-signer-evm.js').UnsignedEvmTransaction} UnsignedEvmTransaction */
|
|
3
|
+
/** @typedef {import('../wallet-account-read-only-evm.js').TypedData} TypedData */
|
|
4
|
+
/** @typedef {import('@tetherto/wdk-wallet').KeyPair} KeyPair */
|
|
5
|
+
/** @typedef {import('ethers').AuthorizationRequest} AuthorizationRequest */
|
|
6
|
+
/** @typedef {import('ethers').Authorization} Authorization */
|
|
7
|
+
/**
|
|
8
|
+
* @extends {ISignerEvm}
|
|
9
|
+
* Signer that wraps a raw private key in a memory-safe buffer, exposing a minimal
|
|
10
|
+
* interface for signing messages, transactions and typed data. This signer does
|
|
11
|
+
* not support derivation and always represents a single account.
|
|
12
|
+
*/
|
|
13
|
+
export default class PrivateKeySignerEvm extends ISignerEvm {
|
|
14
|
+
/**
|
|
15
|
+
* @param {string|Uint8Array} privateKey - Hex string (with/without 0x) or raw key bytes.
|
|
16
|
+
*/
|
|
17
|
+
constructor(privateKey: string | Uint8Array);
|
|
18
|
+
/** @private */
|
|
19
|
+
private _signingKey;
|
|
20
|
+
/** @private */
|
|
21
|
+
private _wallet;
|
|
22
|
+
/** @private */
|
|
23
|
+
private _address;
|
|
24
|
+
/** @private */
|
|
25
|
+
private _path;
|
|
26
|
+
/** @type {boolean} */
|
|
27
|
+
get isDerivable(): boolean;
|
|
28
|
+
/** @type {number|undefined} */
|
|
29
|
+
get index(): number | undefined;
|
|
30
|
+
/** @type {string|undefined} */
|
|
31
|
+
get path(): string | undefined;
|
|
32
|
+
/** @type {string} */
|
|
33
|
+
get address(): string;
|
|
34
|
+
/**
|
|
35
|
+
* The account's key pair (private and public key buffers).
|
|
36
|
+
* @type {KeyPair}
|
|
37
|
+
*/
|
|
38
|
+
get keyPair(): KeyPair;
|
|
39
|
+
/**
|
|
40
|
+
* PrivateKeySignerEvm is not a hierarchical signer and cannot derive.
|
|
41
|
+
* @returns {Promise<never>}
|
|
42
|
+
* @throws {InvalidSignerError} Always — private-key signers do not support derivation.
|
|
43
|
+
*/
|
|
44
|
+
derive(): Promise<never>;
|
|
45
|
+
/** @returns {Promise<string>} */
|
|
46
|
+
getAddress(): Promise<string>;
|
|
47
|
+
/**
|
|
48
|
+
* Signs a message.
|
|
49
|
+
*
|
|
50
|
+
* @param {string} message - The message to sign.
|
|
51
|
+
* @returns {Promise<string>} The message's signature.
|
|
52
|
+
*/
|
|
53
|
+
sign(message: string): Promise<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Signs a transaction and returns the serialized signed transaction hex.
|
|
56
|
+
*
|
|
57
|
+
* @param {UnsignedEvmTransaction} unsignedTx - The unsigned transaction object.
|
|
58
|
+
* @returns {Promise<string>}
|
|
59
|
+
*/
|
|
60
|
+
signTransaction(unsignedTx: UnsignedEvmTransaction): Promise<string>;
|
|
61
|
+
/**
|
|
62
|
+
* Signs typed data according to EIP-712.
|
|
63
|
+
*
|
|
64
|
+
* @param {TypedData} typedData - The typed data to sign.
|
|
65
|
+
* @returns {Promise<string>} The typed data signature.
|
|
66
|
+
*/
|
|
67
|
+
signTypedData({ domain, types, message }: TypedData): Promise<string>;
|
|
68
|
+
/**
|
|
69
|
+
* Sign an ERC-7702 authorization tuple.
|
|
70
|
+
* @param {AuthorizationRequest} auth
|
|
71
|
+
* @returns {Promise<Authorization>}
|
|
72
|
+
*/
|
|
73
|
+
signAuthorization(auth: AuthorizationRequest): Promise<Authorization>;
|
|
74
|
+
/** Dispose secrets from memory. */
|
|
75
|
+
dispose(): void;
|
|
76
|
+
}
|
|
77
|
+
export type UnsignedEvmTransaction = import("./seed-signer-evm.js").UnsignedEvmTransaction;
|
|
78
|
+
export type TypedData = import("../wallet-account-read-only-evm.js").TypedData;
|
|
79
|
+
export type KeyPair = import("@tetherto/wdk-wallet").KeyPair;
|
|
80
|
+
export type AuthorizationRequest = import("ethers").AuthorizationRequest;
|
|
81
|
+
export type Authorization = import("ethers").Authorization;
|
|
@@ -0,0 +1,187 @@
|
|
|
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
|
+
/**
|
|
8
|
+
* A fully-populated unsigned EVM transaction suitable for signing.
|
|
9
|
+
* Produced by the internal transaction populator and consumed by signer implementations.
|
|
10
|
+
*/
|
|
11
|
+
export type UnsignedEvmTransaction = {
|
|
12
|
+
chainId: number;
|
|
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`.
|
|
45
|
+
*
|
|
46
|
+
* @extends {ISigner}
|
|
47
|
+
* @interface
|
|
48
|
+
*/
|
|
49
|
+
export class ISignerEvm extends ISigner {
|
|
50
|
+
/**
|
|
51
|
+
* Whether this signer can derive child signers (i.e. it holds an HD root). Non-derivable
|
|
52
|
+
* signers (e.g. private-key signers) are bound directly to an account; derivable signers
|
|
53
|
+
* derive child accounts and keep the root for management only.
|
|
54
|
+
* @type {boolean}
|
|
55
|
+
*/
|
|
56
|
+
get isDerivable(): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* The last component index for the derivation path of this signer, when applicable.
|
|
59
|
+
* @type {number|undefined}
|
|
60
|
+
*/
|
|
61
|
+
get index(): number | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* The full derivation path if this is a child signer.
|
|
64
|
+
* @type {string|undefined}
|
|
65
|
+
*/
|
|
66
|
+
get path(): string | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* The account's address, if available.
|
|
69
|
+
* @type {string|undefined}
|
|
70
|
+
*/
|
|
71
|
+
get address(): string | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* The account's key pair.
|
|
74
|
+
* @type {KeyPair}
|
|
75
|
+
*/
|
|
76
|
+
get keyPair(): KeyPair;
|
|
77
|
+
/**
|
|
78
|
+
* Derive a child signer from this signer using a relative path (e.g. "0'/0/0").
|
|
79
|
+
*
|
|
80
|
+
* @param {string} relPath - The relative BIP-44 path segment.
|
|
81
|
+
* @returns {Promise<ISignerEvm>} The derived child signer.
|
|
82
|
+
* @throws {InvalidSignerError} If the signer does not support derivation (e.g. private-key signers).
|
|
83
|
+
*/
|
|
84
|
+
derive(relPath: string): Promise<ISignerEvm>;
|
|
85
|
+
/**
|
|
86
|
+
* Returns the account's address.
|
|
87
|
+
* @returns {Promise<string>}
|
|
88
|
+
*/
|
|
89
|
+
getAddress(): Promise<string>;
|
|
90
|
+
/**
|
|
91
|
+
* Sign a plain message.
|
|
92
|
+
* @param {string} message
|
|
93
|
+
* @returns {Promise<string>}
|
|
94
|
+
*/
|
|
95
|
+
sign(message: string): Promise<string>;
|
|
96
|
+
/**
|
|
97
|
+
* Sign a transaction-like object compatible with ethers Transaction.from.
|
|
98
|
+
* @param {UnsignedEvmTransaction} unsignedTx
|
|
99
|
+
* @returns {Promise<string>} The serialized signed transaction hex.
|
|
100
|
+
*/
|
|
101
|
+
signTransaction(unsignedTx: UnsignedEvmTransaction): Promise<string>;
|
|
102
|
+
/**
|
|
103
|
+
* Signs typed data according to EIP-712.
|
|
104
|
+
*
|
|
105
|
+
* @param {TypedData} typedData - The typed data to sign.
|
|
106
|
+
* @returns {Promise<string>} The typed data signature.
|
|
107
|
+
*/
|
|
108
|
+
signTypedData({ domain, types, message }: TypedData): Promise<string>;
|
|
109
|
+
/**
|
|
110
|
+
* Sign an ERC-7702 authorization tuple.
|
|
111
|
+
* @param {AuthorizationRequest} auth
|
|
112
|
+
* @returns {Promise<Authorization>}
|
|
113
|
+
*/
|
|
114
|
+
signAuthorization(auth: AuthorizationRequest): Promise<Authorization>;
|
|
115
|
+
/** Clear any secret material from memory. */
|
|
116
|
+
dispose(): void;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* @extends {ISignerEvm}
|
|
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.
|
|
123
|
+
*/
|
|
124
|
+
export default class SeedSignerEvm extends ISignerEvm {
|
|
125
|
+
/**
|
|
126
|
+
* Create a SeedSignerEvm.
|
|
127
|
+
* Provide a mnemonic/seed (children built via {@link derive} pass a shared root internally).
|
|
128
|
+
*
|
|
129
|
+
* @param {string|Uint8Array|null} seed - A BIP-39 mnemonic seed phrase, or a raw BIP-32 master seed (16-64 bytes). Omit when providing `opts.root`.
|
|
130
|
+
* @param {SeedSignerEvmOpts} [opts] - Construction options for root reuse, direct child derivation or path definition (default is index 0).
|
|
131
|
+
* @throws {ValueError} If neither a seed nor a root is provided, or if both are provided.
|
|
132
|
+
* @throws {ValueError} If a seed is provided but is not a valid BIP-39 mnemonic.
|
|
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. */
|
|
181
|
+
dispose(): void;
|
|
182
|
+
}
|
|
183
|
+
export type TypedData = import("../wallet-account-read-only-evm.js").TypedData;
|
|
184
|
+
export type KeyPair = import("@tetherto/wdk-wallet").KeyPair;
|
|
185
|
+
export type AuthorizationRequest = import("ethers").AuthorizationRequest;
|
|
186
|
+
export type Authorization = import("ethers").Authorization;
|
|
187
|
+
export type AuthorizationLike = import("ethers").AuthorizationLike;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A fully or partially specified EVM transaction, prior to signing.
|
|
3
|
+
*/
|
|
4
|
+
export type UnsignedEvmTransaction = {
|
|
5
|
+
/**
|
|
6
|
+
* - The id of the chain the transaction targets.
|
|
7
|
+
*/
|
|
8
|
+
chainId: number;
|
|
9
|
+
/**
|
|
10
|
+
* - The sender's transaction count, used to order transactions.
|
|
11
|
+
*/
|
|
12
|
+
nonce: number;
|
|
13
|
+
/**
|
|
14
|
+
* - The sender's address.
|
|
15
|
+
*/
|
|
16
|
+
from: string;
|
|
17
|
+
/**
|
|
18
|
+
* - The recipient's address, or null for contract creation.
|
|
19
|
+
*/
|
|
20
|
+
to: string | null;
|
|
21
|
+
/**
|
|
22
|
+
* - The transaction's calldata as a hex string.
|
|
23
|
+
*/
|
|
24
|
+
data: string;
|
|
25
|
+
/**
|
|
26
|
+
* - The amount of native currency (in wei) to transfer.
|
|
27
|
+
*/
|
|
28
|
+
value: number | bigint;
|
|
29
|
+
/**
|
|
30
|
+
* - The EIP-2718 transaction type (0/1 legacy, 2 EIP-1559, 3 EIP-4844, 4 EIP-7702).
|
|
31
|
+
*/
|
|
32
|
+
type: number;
|
|
33
|
+
/**
|
|
34
|
+
* - The maximum amount of gas the transaction may consume.
|
|
35
|
+
*/
|
|
36
|
+
gasLimit: number | bigint;
|
|
37
|
+
/**
|
|
38
|
+
* - The gas price (in wei) for legacy (type 0/1) transactions.
|
|
39
|
+
*/
|
|
40
|
+
gasPrice?: number | bigint;
|
|
41
|
+
/**
|
|
42
|
+
* - The maximum total fee (in wei) per gas for EIP-1559 transactions.
|
|
43
|
+
*/
|
|
44
|
+
maxFeePerGas?: number | bigint;
|
|
45
|
+
/**
|
|
46
|
+
* - The maximum priority fee (in wei) per gas for EIP-1559 transactions.
|
|
47
|
+
*/
|
|
48
|
+
maxPriorityFeePerGas?: number | bigint;
|
|
49
|
+
/**
|
|
50
|
+
* - The EIP-2930 access list of addresses and storage keys.
|
|
51
|
+
*/
|
|
52
|
+
accessList?: any[];
|
|
53
|
+
/**
|
|
54
|
+
* - The maximum fee (in wei) per blob gas for EIP-4844 transactions.
|
|
55
|
+
*/
|
|
56
|
+
maxFeePerBlobGas?: number | bigint;
|
|
57
|
+
/**
|
|
58
|
+
* - The blobs to include in an EIP-4844 transaction.
|
|
59
|
+
*/
|
|
60
|
+
blobs?: any[];
|
|
61
|
+
/**
|
|
62
|
+
* - The versioned hashes of the EIP-4844 blobs.
|
|
63
|
+
*/
|
|
64
|
+
blobVersionedHashes?: string[];
|
|
65
|
+
/**
|
|
66
|
+
* - The EIP-7702 authorization tuples.
|
|
67
|
+
*/
|
|
68
|
+
authorizationList?: AuthorizationLike[];
|
|
69
|
+
};
|
|
70
|
+
export type Provider = import("ethers").Provider;
|
|
71
|
+
export type AuthorizationLike = import("ethers").AuthorizationLike;
|
|
72
|
+
/**
|
|
73
|
+
* Build a fully populated unsigned transaction ready for signing.
|
|
74
|
+
*
|
|
75
|
+
* Resolves chain ID, nonce, gas limit and fee fields from the provider when not
|
|
76
|
+
* explicitly supplied in `tx`. Supports legacy (type 0/1), EIP-1559 (type 2),
|
|
77
|
+
* EIP-4844 (type 3) and EIP-7702 (type 4) transaction styles.
|
|
78
|
+
*
|
|
79
|
+
* @param {Provider} provider - An ethers-compatible JSON-RPC provider.
|
|
80
|
+
* @param {string} from - The sender address.
|
|
81
|
+
* @param {UnsignedEvmTransaction} tx - The partial transaction to populate.
|
|
82
|
+
* @returns {Promise<UnsignedEvmTransaction>} The fully populated unsigned transaction.
|
|
83
|
+
* @throws {ValueError} If the transaction mixes fee fields that its type doesn't support, or a type 3 transaction omits `maxFeePerBlobGas`.
|
|
84
|
+
*/
|
|
85
|
+
export function populateTransactionEvm(provider: Provider, from: string, tx: UnsignedEvmTransaction): Promise<UnsignedEvmTransaction>;
|