@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.js CHANGED
@@ -104550,7 +104550,15 @@ var WalletService = class {
104550
104550
  method: "eth_sendRawTransaction" /* ETH_SEND_RAW_TRANSACTION */,
104551
104551
  params: [signedTx]
104552
104552
  });
104553
- return response.result;
104553
+ const txHash = response?.result;
104554
+ if (!txHash || typeof txHash !== "string") {
104555
+ throw new SDKError(
104556
+ "RPC returned empty tx hash",
104557
+ "TRANSACTION_FAILED" /* TRANSACTION_FAILED */,
104558
+ response
104559
+ );
104560
+ }
104561
+ return txHash;
104554
104562
  }
104555
104563
  async getTransactionReceipt(txHash, chainId) {
104556
104564
  const response = await this.rpcClient.sendRpc({
@@ -104631,10 +104639,33 @@ var WalletService = class {
104631
104639
  return s5;
104632
104640
  }
104633
104641
  };
104634
- const [share1, share2] = await Promise.all([
104635
- this.walletClient.getWallet().then((wallet2) => wallet2.share1),
104636
- LocalForage.get(STORAGE_KEYS.share2(this.orgHost))
104637
- ]);
104642
+ const walletInfo = await this.walletClient.getWallet();
104643
+ const share1 = walletInfo?.share1;
104644
+ let share2 = await LocalForage.get(
104645
+ STORAGE_KEYS.share2(this.orgHost)
104646
+ );
104647
+ if (!share2) {
104648
+ try {
104649
+ const firebaseId = await LocalForage.get(
104650
+ STORAGE_KEYS.firebaseId(this.orgHost)
104651
+ );
104652
+ const encryptedDevice = await LocalForage.get(
104653
+ STORAGE_KEYS.encryptedShare2Device(this.orgHost)
104654
+ );
104655
+ const deviceSecret = await LocalForage.get(
104656
+ STORAGE_KEYS.deviceSecret(this.orgHost)
104657
+ );
104658
+ if (firebaseId && encryptedDevice && deviceSecret) {
104659
+ share2 = Crypto.decryptShare(
104660
+ encryptedDevice,
104661
+ deviceSecret,
104662
+ firebaseId
104663
+ );
104664
+ await LocalForage.save(STORAGE_KEYS.share2(this.orgHost), share2);
104665
+ }
104666
+ } catch {
104667
+ }
104668
+ }
104638
104669
  if (!share1 || !share2) {
104639
104670
  throw new SDKError(
104640
104671
  "Wallet shares not found",
@@ -104660,27 +104691,28 @@ var WalletService = class {
104660
104691
  const buffered = Math.max(21e3, Math.ceil(est * 1.2));
104661
104692
  gasLimit = "0x" + buffered.toString(16);
104662
104693
  } catch (e7) {
104663
- const data = (params.data || "").toLowerCase();
104664
- const fallback = data.startsWith("0x095ea7b3") ? 12e4 : data && data !== "0x" ? 8e5 : 21e3;
104694
+ const data = (params.data || "0x").toLowerCase();
104695
+ const isApprove = data.startsWith("0x095ea7b3");
104696
+ const fallback = isApprove ? 12e4 : data !== "0x" ? 8e5 : 21e3;
104665
104697
  gasLimit = "0x" + fallback.toString(16);
104666
104698
  }
104667
104699
  }
104700
+ const value = params.value ?? "0";
104668
104701
  const signedTx = await wallet.signTransaction({
104669
104702
  to: params.to,
104670
- value: params.value ?? "0x0",
104703
+ value,
104671
104704
  data: params.data || "0x",
104672
104705
  chainId: params.chainId,
104673
104706
  nonce,
104674
104707
  gasPrice,
104675
104708
  gasLimit
104676
104709
  });
104677
- return this.sendRawTransaction(signedTx, params.chainId);
104710
+ const txHash = await this.sendRawTransaction(signedTx, params.chainId);
104711
+ await LocalForage.delete(STORAGE_KEYS.share2(this.orgHost));
104712
+ return txHash;
104678
104713
  } catch (error) {
104679
- const detail = String(
104680
- error?.shortMessage ?? error?.reason ?? error?.message ?? ""
104681
- ).trim();
104682
104714
  throw new SDKError(
104683
- detail ? `Transaction failed: ${detail}` : "Transaction failed",
104715
+ "Transaction failed",
104684
104716
  "TRANSACTION_FAILED" /* TRANSACTION_FAILED */,
104685
104717
  error
104686
104718
  );
@@ -105155,9 +105187,19 @@ var RpcClient = class {
105155
105187
  method: request.method,
105156
105188
  params: request.params
105157
105189
  };
105158
- return this.client.post(this.baseUrl, rpcRequest, {
105159
- needsAccessToken: true
105160
- });
105190
+ const res = await this.client.post(
105191
+ this.baseUrl,
105192
+ rpcRequest,
105193
+ {
105194
+ needsAccessToken: true
105195
+ }
105196
+ );
105197
+ if (res?.error) {
105198
+ const err = res.error;
105199
+ const msg = err?.message || "RPC error";
105200
+ throw new SDKError(msg, "REQUEST_FAILED" /* REQUEST_FAILED */, err);
105201
+ }
105202
+ return res;
105161
105203
  }
105162
105204
  };
105163
105205