@weblock-wallet/sdk 0.1.61 → 0.1.63

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
@@ -104668,10 +104668,6 @@ var WalletService = class {
104668
104668
  }
104669
104669
  async sendTransaction(params) {
104670
104670
  try {
104671
- const from = await this.getAddress();
104672
- if (!from) {
104673
- throw new SDKError("Wallet not found", "WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */);
104674
- }
104675
104671
  const toHexQuantity = (v5) => {
104676
104672
  if (v5 === void 0 || v5 === null) return "0x0";
104677
104673
  const s5 = String(v5).trim();
@@ -104719,8 +104715,47 @@ var WalletService = class {
104719
104715
  }
104720
104716
  const privateKey = await Secrets.combine([share1, share2]);
104721
104717
  const wallet = new import_ethers2.Wallet(privateKey);
104722
- const nonce = params.nonce ?? await this.getTransactionCount(from, params.chainId);
104723
- const gasPrice = params.gasPrice ?? await this.getGasPrice(params.chainId);
104718
+ const from = wallet.address;
104719
+ const cachedAddress = await LocalForage.get(
104720
+ STORAGE_KEYS.walletAddress(this.orgHost)
104721
+ );
104722
+ if (cachedAddress && cachedAddress.toLowerCase() !== from.toLowerCase()) {
104723
+ console.warn(
104724
+ "[WalletService] walletAddress mismatch detected. cached=",
104725
+ cachedAddress,
104726
+ "derived=",
104727
+ from
104728
+ );
104729
+ this.walletAddress = from;
104730
+ await LocalForage.save(STORAGE_KEYS.walletAddress(this.orgHost), from);
104731
+ }
104732
+ const nativeBal = await this.rpcClient.sendRpc({
104733
+ chainId: params.chainId,
104734
+ method: "eth_getBalance" /* ETH_GET_BALANCE */,
104735
+ params: [from, "latest"]
104736
+ });
104737
+ if (!nativeBal?.result || BigInt(nativeBal.result) === BigInt(0)) {
104738
+ throw new SDKError(
104739
+ `Insufficient native balance for gas. sender=${from} balance=${nativeBal?.result ?? "0x0"}`,
104740
+ "TRANSACTION_FAILED" /* TRANSACTION_FAILED */
104741
+ );
104742
+ }
104743
+ const pendingNonceHex = await this.rpcClient.sendRpc({
104744
+ chainId: params.chainId,
104745
+ method: "eth_getTransactionCount" /* ETH_GET_TRANSACTION_COUNT */,
104746
+ params: [from, "pending"]
104747
+ });
104748
+ const pendingNonce = parseInt(
104749
+ pendingNonceHex?.result ?? "0x0",
104750
+ 16
104751
+ );
104752
+ const nonce = params.nonce ?? pendingNonce;
104753
+ let gasPrice = params.gasPrice ?? await this.getGasPrice(params.chainId);
104754
+ try {
104755
+ const bumped = BigInt(gasPrice) * 12n / 10n;
104756
+ gasPrice = "0x" + bumped.toString(16);
104757
+ } catch {
104758
+ }
104724
104759
  let gasLimit = params.gasLimit;
104725
104760
  if (!gasLimit) {
104726
104761
  try {
@@ -104752,6 +104787,19 @@ var WalletService = class {
104752
104787
  gasPrice,
104753
104788
  gasLimit
104754
104789
  });
104790
+ try {
104791
+ const parsed = import_ethers2.Transaction.from(signedTx);
104792
+ const derivedFrom = parsed?.from;
104793
+ if (derivedFrom && String(derivedFrom).toLowerCase() !== from.toLowerCase()) {
104794
+ console.warn(
104795
+ "[WalletService] signedTx sender mismatch. wallet=",
104796
+ from,
104797
+ "txFrom=",
104798
+ derivedFrom
104799
+ );
104800
+ }
104801
+ } catch {
104802
+ }
104755
104803
  const txHash = await this.sendRawTransaction(signedTx, params.chainId);
104756
104804
  await LocalForage.delete(STORAGE_KEYS.share2(this.orgHost));
104757
104805
  return txHash;
@@ -104759,10 +104807,16 @@ var WalletService = class {
104759
104807
  if (error instanceof SDKError) {
104760
104808
  throw error;
104761
104809
  }
104762
- const anyErr = error;
104763
- const causeMsg = anyErr?.shortMessage || anyErr?.reason || anyErr?.message || anyErr?.error?.message || "Unknown error";
104810
+ const msg = (() => {
104811
+ try {
104812
+ const anyErr = error;
104813
+ return anyErr?.shortMessage || anyErr?.reason || anyErr?.message || String(error);
104814
+ } catch {
104815
+ return "Unknown error";
104816
+ }
104817
+ })();
104764
104818
  throw new SDKError(
104765
- `Transaction failed: ${causeMsg}`,
104819
+ `Transaction failed: ${msg}`,
104766
104820
  "TRANSACTION_FAILED" /* TRANSACTION_FAILED */,
104767
104821
  error
104768
104822
  );