@weblock-wallet/sdk 0.1.57 → 0.1.59

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.js CHANGED
@@ -104619,25 +104619,40 @@ var WalletService = class {
104619
104619
  if (!from) {
104620
104620
  throw new SDKError("Wallet not found", "WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */);
104621
104621
  }
104622
- const toHexQuantity = (v5) => {
104623
- if (v5 === void 0 || v5 === null) return "0x0";
104624
- const s5 = String(v5).trim();
104625
- if (!s5) return "0x0";
104626
- if (s5.startsWith("0x") || s5.startsWith("0X")) return s5;
104627
- try {
104628
- const bi = BigInt(s5);
104629
- return "0x" + bi.toString(16);
104630
- } catch {
104631
- return s5;
104622
+ const walletInfo = await this.walletClient.getWallet();
104623
+ const share1 = walletInfo?.share1;
104624
+ let share2 = await LocalForage.get(
104625
+ STORAGE_KEYS.share2(this.orgHost)
104626
+ );
104627
+ if (!share2) {
104628
+ const [firebaseId, deviceSecret, encryptedShare2Device] = await Promise.all([
104629
+ LocalForage.get(STORAGE_KEYS.firebaseId(this.orgHost)),
104630
+ LocalForage.get(STORAGE_KEYS.deviceSecret(this.orgHost)),
104631
+ LocalForage.get(
104632
+ STORAGE_KEYS.encryptedShare2Device(this.orgHost)
104633
+ )
104634
+ ]);
104635
+ if (firebaseId && deviceSecret && encryptedShare2Device) {
104636
+ try {
104637
+ console.debug(
104638
+ "[WalletService] recovering share2 from encryptedShare2_device"
104639
+ );
104640
+ share2 = Crypto.decryptShare(
104641
+ encryptedShare2Device,
104642
+ deviceSecret,
104643
+ firebaseId
104644
+ );
104645
+ } catch (e7) {
104646
+ console.warn(
104647
+ "[WalletService] failed to decrypt encryptedShare2_device",
104648
+ e7
104649
+ );
104650
+ }
104632
104651
  }
104633
- };
104634
- const [share1, share2] = await Promise.all([
104635
- this.walletClient.getWallet().then((wallet2) => wallet2.share1),
104636
- LocalForage.get(STORAGE_KEYS.share2(this.orgHost))
104637
- ]);
104652
+ }
104638
104653
  if (!share1 || !share2) {
104639
104654
  throw new SDKError(
104640
- "Wallet shares not found",
104655
+ "Wallet shares not found. Please unlock the wallet by calling retrieveWallet(PIN) once on this device.",
104641
104656
  "WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */
104642
104657
  );
104643
104658
  }
@@ -104645,20 +104660,6 @@ var WalletService = class {
104645
104660
  const wallet = new Wallet(privateKey);
104646
104661
  const nonce = params.nonce ?? await this.getTransactionCount(from, params.chainId);
104647
104662
  const gasPrice = params.gasPrice ?? await this.getGasPrice(params.chainId);
104648
- let gasLimit = params.gasLimit;
104649
- if (!gasLimit) {
104650
- const est = await this.estimateGas(
104651
- {
104652
- from,
104653
- to: params.to,
104654
- value: toHexQuantity(params.value),
104655
- data: params.data || "0x"
104656
- },
104657
- params.chainId
104658
- );
104659
- const buffered = Math.max(21e3, Math.ceil(est * 1.2));
104660
- gasLimit = "0x" + buffered.toString(16);
104661
- }
104662
104663
  const signedTx = await wallet.signTransaction({
104663
104664
  to: params.to,
104664
104665
  value: params.value,
@@ -104666,7 +104667,7 @@ var WalletService = class {
104666
104667
  chainId: params.chainId,
104667
104668
  nonce,
104668
104669
  gasPrice,
104669
- gasLimit
104670
+ gasLimit: params.gasLimit
104670
104671
  });
104671
104672
  return this.sendRawTransaction(signedTx, params.chainId);
104672
104673
  } catch (error) {