@vleap/warps-adapter-evm 0.2.0-beta.64 → 0.2.0-beta.65

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/dist/index.d.cts CHANGED
@@ -262,8 +262,10 @@ declare class WarpEvmWallet implements AdapterWarpWallet {
262
262
  signMessage(message: string): Promise<string>;
263
263
  sendTransaction(tx: WarpAdapterGenericTransaction): Promise<string>;
264
264
  sendTransactions(txs: WarpAdapterGenericTransaction[]): Promise<string[]>;
265
- create(provider: WarpWalletProvider, mnemonic: string): WarpWalletDetails;
266
- generate(provider: WarpWalletProvider): WarpWalletDetails;
265
+ importFromMnemonic(provider: WarpWalletProvider, mnemonic: string): Promise<WarpWalletDetails>;
266
+ importFromPrivateKey(provider: WarpWalletProvider, privateKey: string): Promise<WarpWalletDetails>;
267
+ export(provider: WarpWalletProvider): Promise<WarpWalletDetails>;
268
+ generate(provider: WarpWalletProvider): Promise<WarpWalletDetails>;
267
269
  getAddress(): string | null;
268
270
  getPublicKey(): string | null;
269
271
  registerX402Handlers(client: unknown): Promise<Record<string, () => void>>;
package/dist/index.d.ts CHANGED
@@ -262,8 +262,10 @@ declare class WarpEvmWallet implements AdapterWarpWallet {
262
262
  signMessage(message: string): Promise<string>;
263
263
  sendTransaction(tx: WarpAdapterGenericTransaction): Promise<string>;
264
264
  sendTransactions(txs: WarpAdapterGenericTransaction[]): Promise<string[]>;
265
- create(provider: WarpWalletProvider, mnemonic: string): WarpWalletDetails;
266
- generate(provider: WarpWalletProvider): WarpWalletDetails;
265
+ importFromMnemonic(provider: WarpWalletProvider, mnemonic: string): Promise<WarpWalletDetails>;
266
+ importFromPrivateKey(provider: WarpWalletProvider, privateKey: string): Promise<WarpWalletDetails>;
267
+ export(provider: WarpWalletProvider): Promise<WarpWalletDetails>;
268
+ generate(provider: WarpWalletProvider): Promise<WarpWalletDetails>;
267
269
  getAddress(): string | null;
268
270
  getPublicKey(): string | null;
269
271
  registerX402Handlers(client: unknown): Promise<Record<string, () => void>>;
package/dist/index.js CHANGED
@@ -191,16 +191,39 @@ var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
191
191
  getWalletInstance() {
192
192
  return this.getWallet();
193
193
  }
194
- create(mnemonic) {
194
+ async importFromMnemonic(mnemonic) {
195
195
  const wallet = import_ethers.ethers.Wallet.fromPhrase(mnemonic);
196
- return {
196
+ const walletDetails = {
197
+ provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
198
+ address: wallet.address,
199
+ privateKey: wallet.privateKey,
200
+ mnemonic
201
+ };
202
+ (0, import_warps2.setWarpWalletInConfig)(this.config, this.chain.name, walletDetails);
203
+ return walletDetails;
204
+ }
205
+ async importFromPrivateKey(privateKey) {
206
+ const wallet = new import_ethers.ethers.Wallet(privateKey);
207
+ const walletDetails = {
197
208
  provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
198
209
  address: wallet.address,
199
210
  privateKey: wallet.privateKey,
200
211
  mnemonic: null
201
212
  };
213
+ (0, import_warps2.setWarpWalletInConfig)(this.config, this.chain.name, walletDetails);
214
+ return walletDetails;
215
+ }
216
+ async export() {
217
+ const wallet = this.getWallet();
218
+ const mnemonic = (0, import_warps2.getWarpWalletMnemonicFromConfig)(this.config, this.chain.name);
219
+ return {
220
+ provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
221
+ address: wallet.address,
222
+ privateKey: wallet.privateKey,
223
+ mnemonic: mnemonic || null
224
+ };
202
225
  }
203
- generate() {
226
+ async generate() {
204
227
  const wallet = import_ethers.ethers.Wallet.createRandom();
205
228
  return {
206
229
  provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
@@ -268,16 +291,40 @@ var _MnemonicWalletProvider = class _MnemonicWalletProvider {
268
291
  getWalletInstance() {
269
292
  return this.getWallet();
270
293
  }
271
- create(mnemonic) {
294
+ async importFromMnemonic(mnemonic) {
272
295
  const wallet = import_ethers2.ethers.Wallet.fromPhrase(mnemonic);
273
- return {
296
+ const walletDetails = {
274
297
  provider: _MnemonicWalletProvider.PROVIDER_NAME,
275
298
  address: wallet.address,
276
- privateKey: null,
299
+ privateKey: wallet.privateKey,
277
300
  mnemonic
278
301
  };
302
+ (0, import_warps3.setWarpWalletInConfig)(this.config, this.chain.name, walletDetails);
303
+ return walletDetails;
304
+ }
305
+ async importFromPrivateKey(privateKey) {
306
+ const wallet = new import_ethers2.ethers.Wallet(privateKey);
307
+ const walletDetails = {
308
+ provider: _MnemonicWalletProvider.PROVIDER_NAME,
309
+ address: wallet.address,
310
+ privateKey: wallet.privateKey,
311
+ mnemonic: null
312
+ };
313
+ (0, import_warps3.setWarpWalletInConfig)(this.config, this.chain.name, walletDetails);
314
+ return walletDetails;
279
315
  }
280
- generate() {
316
+ async export() {
317
+ const wallet = this.getWallet();
318
+ const mnemonic = (0, import_warps3.getWarpWalletMnemonicFromConfig)(this.config, this.chain.name);
319
+ const privateKey = (0, import_warps3.getWarpWalletPrivateKeyFromConfig)(this.config, this.chain.name);
320
+ return {
321
+ provider: _MnemonicWalletProvider.PROVIDER_NAME,
322
+ address: wallet.address,
323
+ privateKey: privateKey || null,
324
+ mnemonic: mnemonic || null
325
+ };
326
+ }
327
+ async generate() {
281
328
  const wallet = import_ethers2.ethers.Wallet.createRandom();
282
329
  return {
283
330
  provider: _MnemonicWalletProvider.PROVIDER_NAME,
@@ -318,11 +365,19 @@ var ReadOnlyWalletProvider = class {
318
365
  const address = await this.getAddress();
319
366
  throw new Error(`Wallet can not be used for signing: ${address}`);
320
367
  }
321
- create(mnemonic) {
368
+ async importFromMnemonic(mnemonic) {
369
+ const address = (0, import_warps4.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
370
+ throw new Error(`Wallet can not be used for signing: ${address}`);
371
+ }
372
+ async importFromPrivateKey(privateKey) {
373
+ const address = (0, import_warps4.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
374
+ throw new Error(`Wallet can not be used for signing: ${address}`);
375
+ }
376
+ async export() {
322
377
  const address = (0, import_warps4.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
323
378
  throw new Error(`Wallet can not be used for signing: ${address}`);
324
379
  }
325
- generate() {
380
+ async generate() {
326
381
  const address = (0, import_warps4.getWarpWalletAddressFromConfig)(this.config, this.chain.name);
327
382
  throw new Error(`Wallet can not be used for signing: ${address}`);
328
383
  }
@@ -1621,37 +1676,43 @@ var WarpEvmWallet = class {
1621
1676
  if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
1622
1677
  if (!this.walletProvider) throw new Error("No wallet provider available");
1623
1678
  if (this.walletProvider instanceof ReadOnlyWalletProvider) throw new Error(`Wallet (${this.chain.name}) is read-only`);
1679
+ if (tx.nonce === void 0) {
1680
+ const address = this.getAddress();
1681
+ if (address) {
1682
+ tx.nonce = await this.provider.getTransactionCount(address, "pending");
1683
+ }
1684
+ }
1624
1685
  return await this.walletProvider.signTransaction(tx);
1625
1686
  }
1626
1687
  async signTransactions(txs) {
1627
1688
  if (txs.length === 0) return [];
1628
1689
  if (!this.walletProvider) throw new Error("No wallet provider available");
1629
- if (this.walletProvider instanceof PrivateKeyWalletProvider || this.walletProvider instanceof MnemonicWalletProvider) {
1630
- const wallet = this.walletProvider.getWalletInstance();
1631
- const address = wallet.address;
1632
- if (txs.length > 1) {
1633
- const currentNonce = await this.provider.getTransactionCount(address, "pending");
1634
- const signedTxs2 = [];
1635
- for (let i = 0; i < txs.length; i++) {
1636
- const tx = { ...txs[i] };
1690
+ const address = this.getAddress();
1691
+ if (!address) throw new Error("No wallet address available");
1692
+ if (txs.length > 1) {
1693
+ const currentNonce = await this.provider.getTransactionCount(address, "pending");
1694
+ const signedTxs2 = [];
1695
+ for (let i = 0; i < txs.length; i++) {
1696
+ const tx = { ...txs[i] };
1697
+ if (tx.nonce === void 0) {
1637
1698
  tx.nonce = currentNonce + i;
1638
- if (i > 0) {
1639
- const priorityReduction = BigInt(i * 1e9);
1640
- const minGasPrice = BigInt(1e9);
1641
- if (tx.maxFeePerGas && tx.maxPriorityFeePerGas) {
1642
- tx.maxFeePerGas = tx.maxFeePerGas > priorityReduction ? tx.maxFeePerGas - priorityReduction : minGasPrice;
1643
- tx.maxPriorityFeePerGas = tx.maxPriorityFeePerGas > priorityReduction ? tx.maxPriorityFeePerGas - priorityReduction : minGasPrice;
1644
- delete tx.gasPrice;
1645
- } else if (tx.gasPrice) {
1646
- tx.gasPrice = tx.gasPrice > priorityReduction ? tx.gasPrice - priorityReduction : minGasPrice;
1647
- delete tx.maxFeePerGas;
1648
- delete tx.maxPriorityFeePerGas;
1649
- }
1699
+ }
1700
+ if (i > 0 && (this.walletProvider instanceof PrivateKeyWalletProvider || this.walletProvider instanceof MnemonicWalletProvider)) {
1701
+ const priorityReduction = BigInt(i * 1e9);
1702
+ const minGasPrice = BigInt(1e9);
1703
+ if (tx.maxFeePerGas && tx.maxPriorityFeePerGas) {
1704
+ tx.maxFeePerGas = tx.maxFeePerGas > priorityReduction ? tx.maxFeePerGas - priorityReduction : minGasPrice;
1705
+ tx.maxPriorityFeePerGas = tx.maxPriorityFeePerGas > priorityReduction ? tx.maxPriorityFeePerGas - priorityReduction : minGasPrice;
1706
+ delete tx.gasPrice;
1707
+ } else if (tx.gasPrice) {
1708
+ tx.gasPrice = tx.gasPrice > priorityReduction ? tx.gasPrice - priorityReduction : minGasPrice;
1709
+ delete tx.maxFeePerGas;
1710
+ delete tx.maxPriorityFeePerGas;
1650
1711
  }
1651
- signedTxs2.push(await this.signTransaction(tx));
1652
1712
  }
1653
- return signedTxs2;
1713
+ signedTxs2.push(await this.signTransaction(tx));
1654
1714
  }
1715
+ return signedTxs2;
1655
1716
  }
1656
1717
  const signedTxs = [];
1657
1718
  for (const tx of txs) {
@@ -1668,6 +1729,10 @@ var WarpEvmWallet = class {
1668
1729
  if (!tx || typeof tx !== "object") throw new Error("Invalid transaction object");
1669
1730
  if (!tx.signature) throw new Error("Transaction must be signed before sending");
1670
1731
  if (!this.walletProvider) throw new Error("No wallet provider available");
1732
+ if (typeof tx.signature === "string" && tx.signature.startsWith("0x")) {
1733
+ const txResponse = await this.provider.broadcastTransaction(tx.signature);
1734
+ return txResponse.hash;
1735
+ }
1671
1736
  if (this.walletProvider instanceof PrivateKeyWalletProvider || this.walletProvider instanceof MnemonicWalletProvider) {
1672
1737
  const wallet = this.walletProvider.getWalletInstance();
1673
1738
  const connectedWallet = wallet.connect(this.provider);
@@ -1679,13 +1744,21 @@ var WarpEvmWallet = class {
1679
1744
  async sendTransactions(txs) {
1680
1745
  return Promise.all(txs.map(async (tx) => this.sendTransaction(tx)));
1681
1746
  }
1682
- create(provider, mnemonic) {
1747
+ async importFromMnemonic(provider, mnemonic) {
1748
+ const walletProvider = this.createProviderForOperation(provider);
1749
+ return await walletProvider.importFromMnemonic(mnemonic);
1750
+ }
1751
+ async importFromPrivateKey(provider, privateKey) {
1752
+ const walletProvider = this.createProviderForOperation(provider);
1753
+ return await walletProvider.importFromPrivateKey(privateKey);
1754
+ }
1755
+ async export(provider) {
1683
1756
  const walletProvider = this.createProviderForOperation(provider);
1684
- return walletProvider.create(mnemonic);
1757
+ return await walletProvider.export();
1685
1758
  }
1686
- generate(provider) {
1759
+ async generate(provider) {
1687
1760
  const walletProvider = this.createProviderForOperation(provider);
1688
- return walletProvider.generate();
1761
+ return await walletProvider.generate();
1689
1762
  }
1690
1763
  getAddress() {
1691
1764
  return this.cachedAddress;