@tetherto/wdk-wallet-evm 1.0.0-beta.12 → 1.0.0-beta.14
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tetherto/wdk-wallet-evm",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.14",
|
|
4
4
|
"description": "A simple package to manage BIP-32 wallets for evm blockchains.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wdk",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"@noble/hashes": "1.8.0",
|
|
32
32
|
"@noble/secp256k1": "2.2.3",
|
|
33
33
|
"@tetherto/wdk-failover-provider": "1.0.0-beta.2",
|
|
34
|
-
"@tetherto/wdk-wallet": "1.0.0-beta.
|
|
35
|
-
"bare-node-runtime": "^1.
|
|
34
|
+
"@tetherto/wdk-wallet": "1.0.0-beta.11",
|
|
35
|
+
"bare-node-runtime": "^1.5.0",
|
|
36
36
|
"bip39": "3.1.0",
|
|
37
37
|
"ethers": "6.14.4",
|
|
38
38
|
"sodium-universal": "5.0.1"
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
"typescript": "5.8.3"
|
|
47
47
|
},
|
|
48
48
|
"overrides": {
|
|
49
|
-
"brace-expansion": "1.1.
|
|
50
|
-
"cookie": "1.
|
|
49
|
+
"brace-expansion": "1.1.15",
|
|
50
|
+
"cookie": "1.1.1",
|
|
51
51
|
"immutable": "4.3.8",
|
|
52
52
|
"picomatch@2": "2.3.2",
|
|
53
53
|
"serialize-javascript": ">=7.0.5",
|
|
54
|
-
"tmp": "0.2.
|
|
55
|
-
"undici": "
|
|
54
|
+
"tmp": "0.2.6",
|
|
55
|
+
"undici": "8.3.0",
|
|
56
56
|
"uuid": "14.0.0"
|
|
57
57
|
},
|
|
58
58
|
"exports": {
|
|
@@ -118,11 +118,15 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
|
|
|
118
118
|
/**
|
|
119
119
|
* The account's key pair.
|
|
120
120
|
*
|
|
121
|
+
* The uint8 arrays are bound to the wallet account, so any external change will reflect to the internal representation. For this reason,
|
|
122
|
+
* 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
|
|
123
|
+
* content, client code should never do so.
|
|
124
|
+
*
|
|
121
125
|
* @type {KeyPair}
|
|
122
126
|
*/
|
|
123
127
|
get keyPair () {
|
|
124
128
|
return {
|
|
125
|
-
privateKey: this._account.privateKeyBuffer,
|
|
129
|
+
privateKey: this._account.privateKeyBuffer ?? null,
|
|
126
130
|
publicKey: this._account.publicKeyBuffer
|
|
127
131
|
}
|
|
128
132
|
}
|
|
@@ -150,10 +154,21 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
|
|
|
150
154
|
/**
|
|
151
155
|
* Signs a transaction.
|
|
152
156
|
*
|
|
157
|
+
* If a provider is set, it also estimates the transaction's costs and checks them against the transaction max. fee option.
|
|
158
|
+
*
|
|
153
159
|
* @param {EvmTransaction} tx - The transaction to sign.
|
|
154
160
|
* @returns {Promise<string>} The signed transaction as a hex string.
|
|
161
|
+
* @throws {Error} If a provider is set, and the transaction's cost surpasses the transaction max. fee option.
|
|
155
162
|
*/
|
|
156
163
|
async signTransaction (tx) {
|
|
164
|
+
if (this._account.provider && this._config.transactionMaxFee !== undefined) {
|
|
165
|
+
const { fee } = await this.quoteSendTransaction(tx)
|
|
166
|
+
|
|
167
|
+
if (fee > this._config.transactionMaxFee) {
|
|
168
|
+
throw new Error('Exceeded maximum fee cost for transaction operation.')
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
157
172
|
return await this._account.signTransaction({
|
|
158
173
|
from: await this.getAddress(),
|
|
159
174
|
...tx
|
|
@@ -165,6 +180,7 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
|
|
|
165
180
|
*
|
|
166
181
|
* @param {EvmTransaction} tx - The transaction.
|
|
167
182
|
* @returns {Promise<TransactionResult>} The transaction's result.
|
|
183
|
+
* @throws {Error} If the transaction's cost exceeds the maximum transaction fee option.
|
|
168
184
|
*/
|
|
169
185
|
async sendTransaction (tx) {
|
|
170
186
|
if (!this._account.provider) {
|
|
@@ -173,6 +189,10 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
|
|
|
173
189
|
|
|
174
190
|
const { fee } = await this.quoteSendTransaction(tx)
|
|
175
191
|
|
|
192
|
+
if (this._config.transactionMaxFee !== undefined && fee > this._config.transactionMaxFee) {
|
|
193
|
+
throw new Error('Exceeded maximum fee cost for transaction operation.')
|
|
194
|
+
}
|
|
195
|
+
|
|
176
196
|
const { hash } = await this._account.sendTransaction({
|
|
177
197
|
from: await this.getAddress(),
|
|
178
198
|
...tx
|
|
@@ -186,6 +206,7 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
|
|
|
186
206
|
*
|
|
187
207
|
* @param {EvmTransferOptions} options - The transfer's options.
|
|
188
208
|
* @returns {Promise<TransferResult>} The transfer's result.
|
|
209
|
+
* @throws {Error} If the transfer's cost exceeds the maximum transfer fee option.
|
|
189
210
|
*/
|
|
190
211
|
async transfer (options) {
|
|
191
212
|
if (!this._account.provider) {
|
|
@@ -196,7 +217,7 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm {
|
|
|
196
217
|
|
|
197
218
|
const { fee } = await this.quoteSendTransaction(tx)
|
|
198
219
|
|
|
199
|
-
if (this._config.transferMaxFee !== undefined && fee
|
|
220
|
+
if (this._config.transferMaxFee !== undefined && fee > this._config.transferMaxFee) {
|
|
200
221
|
throw new Error('Exceeded maximum fee cost for transfer operation.')
|
|
201
222
|
}
|
|
202
223
|
|
|
@@ -74,6 +74,7 @@ import FailoverProvider from '@tetherto/wdk-failover-provider'
|
|
|
74
74
|
* @property {number} [retries] - 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.
|
|
75
75
|
* @property {number} [chainId] - The chain ID of the network. When provided, skips automatic chain ID detection from the provider.
|
|
76
76
|
* @property {number | bigint} [transferMaxFee] - The maximum fee amount for transfer operations.
|
|
77
|
+
* @property {number | bigint} [transactionMaxFee] - The maximum fee amount for sendTransaction and signTransaction operations.
|
|
77
78
|
*/
|
|
78
79
|
|
|
79
80
|
const DELEGATION_DESIGNATOR_PREFIX = '0xef0100'
|
|
@@ -85,7 +86,7 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
85
86
|
* Creates a new evm read-only wallet account.
|
|
86
87
|
*
|
|
87
88
|
* @param {string} address - The account's address.
|
|
88
|
-
* @param {Omit<EvmWalletConfig, 'transferMaxFee'>} [config] - The configuration object.
|
|
89
|
+
* @param {Omit<EvmWalletConfig, 'transferMaxFee' | 'transactionMaxFee'>} [config] - The configuration object.
|
|
89
90
|
*/
|
|
90
91
|
constructor (address, config = { }) {
|
|
91
92
|
super(address)
|
|
@@ -94,7 +95,7 @@ export default class WalletAccountReadOnlyEvm extends WalletAccountReadOnly {
|
|
|
94
95
|
* The read-only wallet account configuration.
|
|
95
96
|
*
|
|
96
97
|
* @protected
|
|
97
|
-
* @type {Omit<EvmWalletConfig, 'transferMaxFee'>}
|
|
98
|
+
* @type {Omit<EvmWalletConfig, 'transferMaxFee' | 'transactionMaxFee'>}
|
|
98
99
|
*/
|
|
99
100
|
this._config = config
|
|
100
101
|
|
|
@@ -37,6 +37,10 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
|
|
|
37
37
|
/**
|
|
38
38
|
* The account's key pair.
|
|
39
39
|
*
|
|
40
|
+
* The uint8 arrays are bound to the wallet account, so any external change will reflect to the internal representation. For this reason,
|
|
41
|
+
* 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
|
|
42
|
+
* content, client code should never do so.
|
|
43
|
+
*
|
|
40
44
|
* @type {KeyPair}
|
|
41
45
|
*/
|
|
42
46
|
get keyPair(): KeyPair;
|
|
@@ -57,8 +61,11 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
|
|
|
57
61
|
/**
|
|
58
62
|
* Signs a transaction.
|
|
59
63
|
*
|
|
64
|
+
* If a provider is set, it also estimates the transaction's costs and checks them against the transaction max. fee option.
|
|
65
|
+
*
|
|
60
66
|
* @param {EvmTransaction} tx - The transaction to sign.
|
|
61
67
|
* @returns {Promise<string>} The signed transaction as a hex string.
|
|
68
|
+
* @throws {Error} If a provider is set, and the transaction's cost surpasses the transaction max. fee option.
|
|
62
69
|
*/
|
|
63
70
|
signTransaction(tx: EvmTransaction): Promise<string>;
|
|
64
71
|
/**
|
|
@@ -66,6 +73,7 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
|
|
|
66
73
|
*
|
|
67
74
|
* @param {EvmTransaction} tx - The transaction.
|
|
68
75
|
* @returns {Promise<TransactionResult>} The transaction's result.
|
|
76
|
+
* @throws {Error} If the transaction's cost exceeds the maximum transaction fee option.
|
|
69
77
|
*/
|
|
70
78
|
sendTransaction(tx: EvmTransaction): Promise<TransactionResult>;
|
|
71
79
|
/**
|
|
@@ -73,6 +81,7 @@ export default class WalletAccountEvm extends WalletAccountReadOnlyEvm implement
|
|
|
73
81
|
*
|
|
74
82
|
* @param {EvmTransferOptions} options - The transfer's options.
|
|
75
83
|
* @returns {Promise<TransferResult>} The transfer's result.
|
|
84
|
+
* @throws {Error} If the transfer's cost exceeds the maximum transfer fee option.
|
|
76
85
|
*/
|
|
77
86
|
transfer(options: EvmTransferOptions): Promise<TransferResult>;
|
|
78
87
|
/**
|
|
@@ -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
|
*
|
|
@@ -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';
|