@vleap/warps-adapter-fastset 0.1.0-beta.52 → 0.1.0-beta.53

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.mjs CHANGED
@@ -1942,7 +1942,11 @@ import {
1942
1942
  // src/providers/MnemonicWalletProvider.ts
1943
1943
  import * as bip39 from "@scure/bip39";
1944
1944
  import { wordlist } from "@scure/bip39/wordlists/english.js";
1945
- import { getWarpWalletMnemonicFromConfig } from "@vleap/warps";
1945
+ import {
1946
+ getWarpWalletMnemonicFromConfig,
1947
+ getWarpWalletPrivateKeyFromConfig,
1948
+ setWarpWalletInConfig
1949
+ } from "@vleap/warps";
1946
1950
 
1947
1951
  // src/sdk/ed25519-setup.ts
1948
1952
  import * as ed25519 from "@noble/ed25519";
@@ -2401,19 +2405,47 @@ var _MnemonicWalletProvider = class _MnemonicWalletProvider {
2401
2405
  const signature = ed.sign(messageBytes, privateKey);
2402
2406
  return uint8ArrayToHex(signature);
2403
2407
  }
2404
- create(mnemonic) {
2408
+ async importFromMnemonic(mnemonic) {
2405
2409
  const seed = bip39.mnemonicToSeedSync(mnemonic);
2406
2410
  const privateKey = seed.slice(0, 32);
2407
2411
  const publicKey = ed.getPublicKey(privateKey);
2408
2412
  const address = FastsetClient.encodeBech32Address(publicKey);
2409
- return {
2413
+ const walletDetails = {
2410
2414
  provider: _MnemonicWalletProvider.PROVIDER_NAME,
2411
2415
  address,
2412
- privateKey: null,
2416
+ privateKey: uint8ArrayToHex(privateKey),
2413
2417
  mnemonic
2414
2418
  };
2419
+ setWarpWalletInConfig(this.config, this.chain.name, walletDetails);
2420
+ return walletDetails;
2415
2421
  }
2416
- generate() {
2422
+ async importFromPrivateKey(privateKey) {
2423
+ const privateKeyBytes = Buffer.from(privateKey, "hex");
2424
+ const publicKey = ed.getPublicKey(new Uint8Array(privateKeyBytes));
2425
+ const address = FastsetClient.encodeBech32Address(publicKey);
2426
+ const walletDetails = {
2427
+ provider: _MnemonicWalletProvider.PROVIDER_NAME,
2428
+ address,
2429
+ privateKey,
2430
+ mnemonic: null
2431
+ };
2432
+ setWarpWalletInConfig(this.config, this.chain.name, walletDetails);
2433
+ return walletDetails;
2434
+ }
2435
+ async export() {
2436
+ const privateKey = this.getPrivateKey();
2437
+ const mnemonic = getWarpWalletMnemonicFromConfig(this.config, this.chain.name);
2438
+ const privateKeyHex = getWarpWalletPrivateKeyFromConfig(this.config, this.chain.name);
2439
+ const publicKey = ed.getPublicKey(privateKey);
2440
+ const address = FastsetClient.encodeBech32Address(publicKey);
2441
+ return {
2442
+ provider: _MnemonicWalletProvider.PROVIDER_NAME,
2443
+ address,
2444
+ privateKey: privateKeyHex || null,
2445
+ mnemonic: mnemonic || null
2446
+ };
2447
+ }
2448
+ async generate() {
2417
2449
  const mnemonic = bip39.generateMnemonic(wordlist);
2418
2450
  const seed = bip39.mnemonicToSeedSync(mnemonic);
2419
2451
  const privateKey = seed.slice(0, 32);
@@ -2439,7 +2471,11 @@ _MnemonicWalletProvider.PROVIDER_NAME = "mnemonic";
2439
2471
  var MnemonicWalletProvider = _MnemonicWalletProvider;
2440
2472
 
2441
2473
  // src/providers/PrivateKeyWalletProvider.ts
2442
- import { getWarpWalletPrivateKeyFromConfig } from "@vleap/warps";
2474
+ import {
2475
+ getWarpWalletMnemonicFromConfig as getWarpWalletMnemonicFromConfig2,
2476
+ getWarpWalletPrivateKeyFromConfig as getWarpWalletPrivateKeyFromConfig2,
2477
+ setWarpWalletInConfig as setWarpWalletInConfig2
2478
+ } from "@vleap/warps";
2443
2479
  import * as bip392 from "@scure/bip39";
2444
2480
  var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
2445
2481
  constructor(config, chain2) {
@@ -2482,19 +2518,47 @@ var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
2482
2518
  const signature = ed.sign(messageBytes, privateKey);
2483
2519
  return uint8ArrayToHex(signature);
2484
2520
  }
2485
- create(mnemonic) {
2521
+ async importFromMnemonic(mnemonic) {
2486
2522
  const seed = bip392.mnemonicToSeedSync(mnemonic);
2487
2523
  const privateKey = seed.slice(0, 32);
2488
2524
  const publicKey = ed.getPublicKey(privateKey);
2489
2525
  const address = FastsetClient.encodeBech32Address(publicKey);
2490
- return {
2526
+ const walletDetails = {
2491
2527
  provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
2492
2528
  address,
2493
2529
  privateKey: uint8ArrayToHex(privateKey),
2530
+ mnemonic
2531
+ };
2532
+ setWarpWalletInConfig2(this.config, this.chain.name, walletDetails);
2533
+ return walletDetails;
2534
+ }
2535
+ async importFromPrivateKey(privateKey) {
2536
+ const privateKeyBytes = hexToUint8Array(privateKey);
2537
+ const publicKey = ed.getPublicKey(privateKeyBytes);
2538
+ const address = FastsetClient.encodeBech32Address(publicKey);
2539
+ const walletDetails = {
2540
+ provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
2541
+ address,
2542
+ privateKey,
2494
2543
  mnemonic: null
2495
2544
  };
2545
+ setWarpWalletInConfig2(this.config, this.chain.name, walletDetails);
2546
+ return walletDetails;
2547
+ }
2548
+ async export() {
2549
+ const privateKey = this.getPrivateKey();
2550
+ const privateKeyHex = getWarpWalletPrivateKeyFromConfig2(this.config, this.chain.name);
2551
+ const mnemonic = getWarpWalletMnemonicFromConfig2(this.config, this.chain.name);
2552
+ const publicKey = ed.getPublicKey(privateKey);
2553
+ const address = FastsetClient.encodeBech32Address(publicKey);
2554
+ return {
2555
+ provider: _PrivateKeyWalletProvider.PROVIDER_NAME,
2556
+ address,
2557
+ privateKey: privateKeyHex || null,
2558
+ mnemonic: mnemonic || null
2559
+ };
2496
2560
  }
2497
- generate() {
2561
+ async generate() {
2498
2562
  const privateKey = ed.utils.randomSecretKey();
2499
2563
  const publicKey = ed.getPublicKey(privateKey);
2500
2564
  const address = FastsetClient.encodeBech32Address(publicKey);
@@ -2507,7 +2571,7 @@ var _PrivateKeyWalletProvider = class _PrivateKeyWalletProvider {
2507
2571
  }
2508
2572
  getPrivateKey() {
2509
2573
  if (this.privateKey) return this.privateKey;
2510
- const privateKeyHex = getWarpWalletPrivateKeyFromConfig(this.config, this.chain.name);
2574
+ const privateKeyHex = getWarpWalletPrivateKeyFromConfig2(this.config, this.chain.name);
2511
2575
  if (!privateKeyHex) throw new Error("No private key provided");
2512
2576
  this.privateKey = hexToUint8Array(privateKeyHex);
2513
2577
  return this.privateKey;
@@ -2537,11 +2601,19 @@ var ReadOnlyWalletProvider = class {
2537
2601
  const address = await this.getAddress();
2538
2602
  throw new Error(`Wallet can not be used for signing: ${address}`);
2539
2603
  }
2540
- create(mnemonic) {
2604
+ async importFromMnemonic(mnemonic) {
2605
+ const address = getWarpWalletAddressFromConfig3(this.config, this.chain.name);
2606
+ throw new Error(`Wallet can not be used for signing: ${address}`);
2607
+ }
2608
+ async importFromPrivateKey(privateKey) {
2609
+ const address = getWarpWalletAddressFromConfig3(this.config, this.chain.name);
2610
+ throw new Error(`Wallet can not be used for signing: ${address}`);
2611
+ }
2612
+ async export() {
2541
2613
  const address = getWarpWalletAddressFromConfig3(this.config, this.chain.name);
2542
2614
  throw new Error(`Wallet can not be used for signing: ${address}`);
2543
2615
  }
2544
- generate() {
2616
+ async generate() {
2545
2617
  const address = getWarpWalletAddressFromConfig3(this.config, this.chain.name);
2546
2618
  throw new Error(`Wallet can not be used for signing: ${address}`);
2547
2619
  }
@@ -2585,13 +2657,21 @@ var WarpFastsetWallet = class {
2585
2657
  async sendTransactions(txs) {
2586
2658
  return Promise.all(txs.map(async (tx) => this.sendTransaction(tx)));
2587
2659
  }
2588
- create(provider, mnemonic) {
2660
+ async importFromMnemonic(provider, mnemonic) {
2661
+ const walletProvider = this.createProviderForOperation(provider);
2662
+ return await walletProvider.importFromMnemonic(mnemonic);
2663
+ }
2664
+ async importFromPrivateKey(provider, privateKey) {
2665
+ const walletProvider = this.createProviderForOperation(provider);
2666
+ return await walletProvider.importFromPrivateKey(privateKey);
2667
+ }
2668
+ async export(provider) {
2589
2669
  const walletProvider = this.createProviderForOperation(provider);
2590
- return walletProvider.create(mnemonic);
2670
+ return await walletProvider.export();
2591
2671
  }
2592
- generate(provider) {
2672
+ async generate(provider) {
2593
2673
  const walletProvider = this.createProviderForOperation(provider);
2594
- return walletProvider.generate();
2674
+ return await walletProvider.generate();
2595
2675
  }
2596
2676
  getAddress() {
2597
2677
  return this.cachedAddress;