@weblock-wallet/sdk 0.1.58 → 0.1.60

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.cjs CHANGED
@@ -104595,7 +104595,15 @@ var WalletService = class {
104595
104595
  method: "eth_sendRawTransaction" /* ETH_SEND_RAW_TRANSACTION */,
104596
104596
  params: [signedTx]
104597
104597
  });
104598
- return response.result;
104598
+ const txHash = response?.result;
104599
+ if (!txHash || typeof txHash !== "string") {
104600
+ throw new SDKError(
104601
+ "RPC returned empty tx hash",
104602
+ "TRANSACTION_FAILED" /* TRANSACTION_FAILED */,
104603
+ response
104604
+ );
104605
+ }
104606
+ return txHash;
104599
104607
  }
104600
104608
  async getTransactionReceipt(txHash, chainId) {
104601
104609
  const response = await this.rpcClient.sendRpc({
@@ -104676,10 +104684,33 @@ var WalletService = class {
104676
104684
  return s5;
104677
104685
  }
104678
104686
  };
104679
- const [share1, share2] = await Promise.all([
104680
- this.walletClient.getWallet().then((wallet2) => wallet2.share1),
104681
- LocalForage.get(STORAGE_KEYS.share2(this.orgHost))
104682
- ]);
104687
+ const walletInfo = await this.walletClient.getWallet();
104688
+ const share1 = walletInfo?.share1;
104689
+ let share2 = await LocalForage.get(
104690
+ STORAGE_KEYS.share2(this.orgHost)
104691
+ );
104692
+ if (!share2) {
104693
+ try {
104694
+ const firebaseId = await LocalForage.get(
104695
+ STORAGE_KEYS.firebaseId(this.orgHost)
104696
+ );
104697
+ const encryptedDevice = await LocalForage.get(
104698
+ STORAGE_KEYS.encryptedShare2Device(this.orgHost)
104699
+ );
104700
+ const deviceSecret = await LocalForage.get(
104701
+ STORAGE_KEYS.deviceSecret(this.orgHost)
104702
+ );
104703
+ if (firebaseId && encryptedDevice && deviceSecret) {
104704
+ share2 = Crypto.decryptShare(
104705
+ encryptedDevice,
104706
+ deviceSecret,
104707
+ firebaseId
104708
+ );
104709
+ await LocalForage.save(STORAGE_KEYS.share2(this.orgHost), share2);
104710
+ }
104711
+ } catch {
104712
+ }
104713
+ }
104683
104714
  if (!share1 || !share2) {
104684
104715
  throw new SDKError(
104685
104716
  "Wallet shares not found",
@@ -104705,27 +104736,28 @@ var WalletService = class {
104705
104736
  const buffered = Math.max(21e3, Math.ceil(est * 1.2));
104706
104737
  gasLimit = "0x" + buffered.toString(16);
104707
104738
  } catch (e7) {
104708
- const data = (params.data || "").toLowerCase();
104709
- const fallback = data.startsWith("0x095ea7b3") ? 12e4 : data && data !== "0x" ? 8e5 : 21e3;
104739
+ const data = (params.data || "0x").toLowerCase();
104740
+ const isApprove = data.startsWith("0x095ea7b3");
104741
+ const fallback = isApprove ? 12e4 : data !== "0x" ? 8e5 : 21e3;
104710
104742
  gasLimit = "0x" + fallback.toString(16);
104711
104743
  }
104712
104744
  }
104745
+ const value = params.value ?? "0";
104713
104746
  const signedTx = await wallet.signTransaction({
104714
104747
  to: params.to,
104715
- value: params.value ?? "0x0",
104748
+ value,
104716
104749
  data: params.data || "0x",
104717
104750
  chainId: params.chainId,
104718
104751
  nonce,
104719
104752
  gasPrice,
104720
104753
  gasLimit
104721
104754
  });
104722
- return this.sendRawTransaction(signedTx, params.chainId);
104755
+ const txHash = await this.sendRawTransaction(signedTx, params.chainId);
104756
+ await LocalForage.delete(STORAGE_KEYS.share2(this.orgHost));
104757
+ return txHash;
104723
104758
  } catch (error) {
104724
- const detail = String(
104725
- error?.shortMessage ?? error?.reason ?? error?.message ?? ""
104726
- ).trim();
104727
104759
  throw new SDKError(
104728
- detail ? `Transaction failed: ${detail}` : "Transaction failed",
104760
+ "Transaction failed",
104729
104761
  "TRANSACTION_FAILED" /* TRANSACTION_FAILED */,
104730
104762
  error
104731
104763
  );
@@ -105196,9 +105228,19 @@ var RpcClient = class {
105196
105228
  method: request.method,
105197
105229
  params: request.params
105198
105230
  };
105199
- return this.client.post(this.baseUrl, rpcRequest, {
105200
- needsAccessToken: true
105201
- });
105231
+ const res = await this.client.post(
105232
+ this.baseUrl,
105233
+ rpcRequest,
105234
+ {
105235
+ needsAccessToken: true
105236
+ }
105237
+ );
105238
+ if (res?.error) {
105239
+ const err = res.error;
105240
+ const msg = err?.message || "RPC error";
105241
+ throw new SDKError(msg, "REQUEST_FAILED" /* REQUEST_FAILED */, err);
105242
+ }
105243
+ return res;
105202
105244
  }
105203
105245
  };
105204
105246