@tetherto/wdk-wallet-evm 1.0.0-beta.13 → 1.0.0-beta.15

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.
@@ -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 {SignerError} 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 - BIP-39 mnemonic or seed 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 {Error} If neither a seed nor a root is provided, or if both are provided.
132
+ * @throws {Error} 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 {Error} 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,84 @@
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
+ */
84
+ export function populateTransactionEvm(provider: Provider, from: string, tx: UnsignedEvmTransaction): Promise<UnsignedEvmTransaction>;
@@ -1,27 +1,38 @@
1
1
  /** @implements {IWalletAccount} */
2
2
  export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implements IWalletAccount {
3
3
  /**
4
- * Creates a new evm wallet account.
4
+ * Creates a new evm wallet account from a raw private key.
5
5
  *
6
- * @param {string | Uint8Array} seed - The wallet's [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) seed phrase.
6
+ * @param {string | Uint8Array} privateKey - The raw private key (hex string with or without 0x, or 32 bytes).
7
+ * @param {EvmWalletConfig} [config] - The configuration object.
8
+ * @returns {WalletAccountEvm} The wallet account.
9
+ */
10
+ static fromPrivateKey(privateKey: string | Uint8Array, config?: EvmWalletConfig): WalletAccountEvm;
11
+ /**
12
+ * Creates a new evm wallet account from a BIP-39 seed, deriving the account's key at the
13
+ * given BIP-44 path.
14
+ *
15
+ * @param {string | Uint8Array} seed - The wallet's BIP-39 seed phrase or seed bytes.
7
16
  * @param {string} path - The BIP-44 derivation path (e.g. "0'/0/0").
8
17
  * @param {EvmWalletConfig} [config] - The configuration object.
9
18
  */
10
19
  constructor(seed: string | Uint8Array, path: string, config?: EvmWalletConfig);
11
20
  /**
12
- * The wallet account configuration.
21
+ * Creates a new evm wallet account using a signer.
13
22
  *
14
- * @protected
15
- * @type {EvmWalletConfig}
23
+ * @param {ISignerEvm} signer - A signer implementing the EVM signer interface.
24
+ * @param {EvmWalletConfig} [config] - The configuration object.
16
25
  */
17
- protected _config: EvmWalletConfig;
26
+ constructor(signer: ISignerEvm, config?: EvmWalletConfig);
18
27
  /**
19
- * The account.
28
+ * The wallet account configuration.
20
29
  *
21
30
  * @protected
22
- * @type {HDNodeWallet}
31
+ * @type {EvmWalletConfig}
23
32
  */
24
- protected _account: HDNodeWallet;
33
+ protected _config: EvmWalletConfig;
34
+ /** @private */
35
+ private _signer;
25
36
  /**
26
37
  * The derivation path's index of this account.
27
38
  *
@@ -44,6 +55,13 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
44
55
  * @type {KeyPair}
45
56
  */
46
57
  get keyPair(): KeyPair;
58
+ /**
59
+ * Returns the account's address. If it wasn't resolved at construction time (e.g hardware signers), it asks the
60
+ * underlying signer to resolve it, then caches it locally.
61
+ *
62
+ * @returns {Promise<string>} The account's address.
63
+ */
64
+ getAddress(): Promise<string>;
47
65
  /**
48
66
  * Signs a message.
49
67
  *
@@ -61,8 +79,11 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
61
79
  /**
62
80
  * Signs a transaction.
63
81
  *
82
+ * If a provider is set, it also estimates the transaction's costs and checks them against the transaction max. fee option.
83
+ *
64
84
  * @param {EvmTransaction} tx - The transaction to sign.
65
85
  * @returns {Promise<string>} The signed transaction as a hex string.
86
+ * @throws {Error} If a provider is set, and the transaction's cost surpasses the transaction max. fee option.
66
87
  */
67
88
  signTransaction(tx: EvmTransaction): Promise<string>;
68
89
  /**
@@ -70,6 +91,7 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
70
91
  *
71
92
  * @param {EvmTransaction} tx - The transaction.
72
93
  * @returns {Promise<TransactionResult>} The transaction's result.
94
+ * @throws {Error} If the transaction's cost exceeds the maximum transaction fee option.
73
95
  */
74
96
  sendTransaction(tx: EvmTransaction): Promise<TransactionResult>;
75
97
  /**
@@ -77,6 +99,7 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
77
99
  *
78
100
  * @param {EvmTransferOptions} options - The transfer's options.
79
101
  * @returns {Promise<TransferResult>} The transfer's result.
102
+ * @throws {Error} If the transfer's cost exceeds the maximum transfer fee option.
80
103
  */
81
104
  transfer(options: EvmTransferOptions): Promise<TransferResult>;
82
105
  /**
@@ -122,6 +145,7 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
122
145
  */
123
146
  dispose(): void;
124
147
  }
148
+ export type ISignerEvm = import("./signers/seed-signer-evm.js").ISignerEvm;
125
149
  export type HDNodeWallet = import("ethers").HDNodeWallet;
126
150
  export type AuthorizationRequest = import("ethers").AuthorizationRequest;
127
151
  export type Authorization = import("ethers").Authorization;
@@ -11,16 +11,16 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
11
11
  * Creates a new evm read-only wallet account.
12
12
  *
13
13
  * @param {string} address - The account's address.
14
- * @param {Omit<EvmWalletConfig, 'transferMaxFee'>} [config] - The configuration object.
14
+ * @param {Omit<EvmWalletConfig, 'transferMaxFee' | 'transactionMaxFee'>} [config] - The configuration object.
15
15
  */
16
- constructor(address: string, config?: Omit<EvmWalletConfig, "transferMaxFee">);
16
+ constructor(address: string, config?: Omit<EvmWalletConfig, "transferMaxFee" | "transactionMaxFee">);
17
17
  /**
18
18
  * The read-only wallet account configuration.
19
19
  *
20
20
  * @protected
21
- * @type {Omit<EvmWalletConfig, 'transferMaxFee'>}
21
+ * @type {Omit<EvmWalletConfig, 'transferMaxFee' | 'transactionMaxFee'>}
22
22
  */
23
- protected _config: Omit<EvmWalletConfig, "transferMaxFee">;
23
+ protected _config: Omit<EvmWalletConfig, "transferMaxFee" | "transactionMaxFee">;
24
24
  /**
25
25
  * An ethers provider to interact with a node of the blockchain.
26
26
  *
@@ -141,9 +141,9 @@ export type DelegationInfo = {
141
141
  };
142
142
  export type EvmTransaction = {
143
143
  /**
144
- * - The transaction's recipient.
144
+ * - The transaction's recipient. Omit or pass null to deploy a contract.
145
145
  */
146
- to: string;
146
+ to?: string | null;
147
147
  /**
148
148
  * - The amount of ethers to send to the recipient (in weis).
149
149
  */
@@ -220,5 +220,9 @@ export type EvmWalletConfig = {
220
220
  * - The maximum fee amount for transfer operations.
221
221
  */
222
222
  transferMaxFee?: number | bigint;
223
+ /**
224
+ * - The maximum fee amount for sendTransaction and signTransaction operations.
225
+ */
226
+ transactionMaxFee?: number | bigint;
223
227
  };
224
228
  import { WalletAccountReadOnly } from '@tetherto/wdk-wallet';
@@ -1,3 +1,7 @@
1
+ /** @typedef {import('ethers').Provider} Provider */
2
+ /** @typedef {import("@tetherto/wdk-wallet").FeeRates} FeeRates */
3
+ /** @typedef {import("@tetherto/wdk-wallet").ISigner} ISigner */
4
+ /** @typedef {import('./wallet-account-evm.js').EvmWalletConfig} EvmWalletConfig */
1
5
  export default class WalletManagerEvm extends WalletManager {
2
6
  /**
3
7
  * Multiplier for normal fee rate calculations (in %).
@@ -16,17 +20,15 @@ export default class WalletManagerEvm extends WalletManager {
16
20
  /**
17
21
  * Creates a new wallet manager for evm blockchains.
18
22
  *
19
- * @param {string | Uint8Array} seed - The wallet's [BIP-39](https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki) seed phrase.
20
- * @param {EvmWalletConfig} [config] - The configuration object.
21
- */
22
- constructor(seed: string | Uint8Array, config?: EvmWalletConfig);
23
- /**
24
- * The evm wallet configuration.
23
+ * Accepts either a BIP-39 seed (string/Uint8Array) for backwards compatibility, or a
24
+ * pre-built root signer object. The default signer must be derivable (it must be able to
25
+ * derive child accounts); non-derivable signers (e.g. private-key signers) are not allowed
26
+ * 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.
25
27
  *
26
- * @protected
27
- * @type {EvmWalletConfig}
28
+ * @param {string|Uint8Array|ISigner} seedOrSigner - A BIP-39 seed phrase, seed 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}.
29
+ * @param {EvmWalletConfig} [config] - The configuration object.
28
30
  */
29
- protected _config: EvmWalletConfig;
31
+ constructor(seedOrSigner: string | Uint8Array | ISigner, config?: EvmWalletConfig);
30
32
  /**
31
33
  * An ethers provider to interact with a node of the blockchain.
32
34
  *
@@ -35,25 +37,41 @@ export default class WalletManagerEvm extends WalletManager {
35
37
  */
36
38
  protected _provider: Provider | undefined;
37
39
  /**
38
- * Returns the wallet account at a specific index (see [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki)).
40
+ * Returns the wallet account at a specific index.
39
41
  *
40
- * @example
41
- * // Returns the account with derivation path m/44'/60'/0'/0/1
42
- * const account = await wallet.getAccount(1);
43
42
  * @param {number} [index] - The index of the account to get (default: 0).
43
+ * @param {Object} [options] - Account options.
44
+ * @param {string} [options.signerName] - The signer name. Omit to use the default signer.
45
+ * @returns {Promise<WalletAccountEvm>} The account.
46
+ * @throws {Error} If a signer name is given but no signer exists with that name.
47
+ * @throws {SignerError} If the signer doesn't support account derivation.
48
+ */
49
+ getAccount(index?: number, options?: {
50
+ signerName?: string;
51
+ }): Promise<WalletAccountEvm>;
52
+ /**
53
+ * Returns the wallet account associated with a registered signer. Non-derivable
54
+ * signers (e.g. private-key signers) return the signer's single account; derivable signers
55
+ * derive a detached child at the signer's own account (the root is never handed out).
56
+ *
57
+ * @param {string} signerName - The signer name registered via {@link addSigner}.
44
58
  * @returns {Promise<WalletAccountEvm>} The account.
59
+ * @throws {Error} If no signer exists with the given name.
45
60
  */
46
- getAccount(index?: number): Promise<WalletAccountEvm>;
61
+ getAccount(signerName: string): Promise<WalletAccountEvm>;
47
62
  /**
48
- * Returns the wallet account at a specific BIP-44 derivation path.
63
+ * Returns the wallet account at a specific derivation path.
49
64
  *
50
- * @example
51
- * // Returns the account with derivation path m/44'/60'/0'/0/1
52
- * const account = await wallet.getAccountByPath("0'/0/1");
53
65
  * @param {string} path - The derivation path (e.g. "0'/0/0").
66
+ * @param {Object} [options] - Account options.
67
+ * @param {string} [options.signerName] - The signer name. Omit to use the default signer.
54
68
  * @returns {Promise<WalletAccountEvm>} The account.
69
+ * @throws {Error} If a signer name is given but no signer exists with that name.
70
+ * @throws {SignerError} If the signer doesn't support account derivation.
55
71
  */
56
- getAccountByPath(path: string): Promise<WalletAccountEvm>;
72
+ getAccountByPath(path: string, options?: {
73
+ signerName?: string;
74
+ }): Promise<WalletAccountEvm>;
57
75
  /**
58
76
  * Returns the current fee rates.
59
77
  *
@@ -61,8 +79,10 @@ export default class WalletManagerEvm extends WalletManager {
61
79
  */
62
80
  getFeeRates(): Promise<FeeRates>;
63
81
  }
82
+ export type ISignerEvm = import("./signers/seed-signer-evm.js").ISignerEvm;
64
83
  export type Provider = import("ethers").Provider;
65
84
  export type FeeRates = import("@tetherto/wdk-wallet").FeeRates;
85
+ export type ISigner = import("@tetherto/wdk-wallet").ISigner;
66
86
  export type EvmWalletConfig = import("./wallet-account-evm.js").EvmWalletConfig;
67
87
  import WalletManager from '@tetherto/wdk-wallet';
68
88
  import WalletAccountEvm from './wallet-account-evm.js';