@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 +63 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +64 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1890,7 +1890,7 @@ var AuthService = class {
|
|
|
1890
1890
|
};
|
|
1891
1891
|
|
|
1892
1892
|
// src/core/services/wallet.ts
|
|
1893
|
-
import { Wallet, Interface } from "ethers";
|
|
1893
|
+
import { Wallet, Interface, Transaction as EthersTx } from "ethers";
|
|
1894
1894
|
import { generateMnemonic, mnemonicToSeed } from "bip39";
|
|
1895
1895
|
|
|
1896
1896
|
// src/utils/secrets.ts
|
|
@@ -104623,10 +104623,6 @@ var WalletService = class {
|
|
|
104623
104623
|
}
|
|
104624
104624
|
async sendTransaction(params) {
|
|
104625
104625
|
try {
|
|
104626
|
-
const from = await this.getAddress();
|
|
104627
|
-
if (!from) {
|
|
104628
|
-
throw new SDKError("Wallet not found", "WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */);
|
|
104629
|
-
}
|
|
104630
104626
|
const toHexQuantity = (v5) => {
|
|
104631
104627
|
if (v5 === void 0 || v5 === null) return "0x0";
|
|
104632
104628
|
const s5 = String(v5).trim();
|
|
@@ -104674,8 +104670,47 @@ var WalletService = class {
|
|
|
104674
104670
|
}
|
|
104675
104671
|
const privateKey = await Secrets.combine([share1, share2]);
|
|
104676
104672
|
const wallet = new Wallet(privateKey);
|
|
104677
|
-
const
|
|
104678
|
-
const
|
|
104673
|
+
const from = wallet.address;
|
|
104674
|
+
const cachedAddress = await LocalForage.get(
|
|
104675
|
+
STORAGE_KEYS.walletAddress(this.orgHost)
|
|
104676
|
+
);
|
|
104677
|
+
if (cachedAddress && cachedAddress.toLowerCase() !== from.toLowerCase()) {
|
|
104678
|
+
console.warn(
|
|
104679
|
+
"[WalletService] walletAddress mismatch detected. cached=",
|
|
104680
|
+
cachedAddress,
|
|
104681
|
+
"derived=",
|
|
104682
|
+
from
|
|
104683
|
+
);
|
|
104684
|
+
this.walletAddress = from;
|
|
104685
|
+
await LocalForage.save(STORAGE_KEYS.walletAddress(this.orgHost), from);
|
|
104686
|
+
}
|
|
104687
|
+
const nativeBal = await this.rpcClient.sendRpc({
|
|
104688
|
+
chainId: params.chainId,
|
|
104689
|
+
method: "eth_getBalance" /* ETH_GET_BALANCE */,
|
|
104690
|
+
params: [from, "latest"]
|
|
104691
|
+
});
|
|
104692
|
+
if (!nativeBal?.result || BigInt(nativeBal.result) === BigInt(0)) {
|
|
104693
|
+
throw new SDKError(
|
|
104694
|
+
`Insufficient native balance for gas. sender=${from} balance=${nativeBal?.result ?? "0x0"}`,
|
|
104695
|
+
"TRANSACTION_FAILED" /* TRANSACTION_FAILED */
|
|
104696
|
+
);
|
|
104697
|
+
}
|
|
104698
|
+
const pendingNonceHex = await this.rpcClient.sendRpc({
|
|
104699
|
+
chainId: params.chainId,
|
|
104700
|
+
method: "eth_getTransactionCount" /* ETH_GET_TRANSACTION_COUNT */,
|
|
104701
|
+
params: [from, "pending"]
|
|
104702
|
+
});
|
|
104703
|
+
const pendingNonce = parseInt(
|
|
104704
|
+
pendingNonceHex?.result ?? "0x0",
|
|
104705
|
+
16
|
|
104706
|
+
);
|
|
104707
|
+
const nonce = params.nonce ?? pendingNonce;
|
|
104708
|
+
let gasPrice = params.gasPrice ?? await this.getGasPrice(params.chainId);
|
|
104709
|
+
try {
|
|
104710
|
+
const bumped = BigInt(gasPrice) * 12n / 10n;
|
|
104711
|
+
gasPrice = "0x" + bumped.toString(16);
|
|
104712
|
+
} catch {
|
|
104713
|
+
}
|
|
104679
104714
|
let gasLimit = params.gasLimit;
|
|
104680
104715
|
if (!gasLimit) {
|
|
104681
104716
|
try {
|
|
@@ -104707,6 +104742,19 @@ var WalletService = class {
|
|
|
104707
104742
|
gasPrice,
|
|
104708
104743
|
gasLimit
|
|
104709
104744
|
});
|
|
104745
|
+
try {
|
|
104746
|
+
const parsed = EthersTx.from(signedTx);
|
|
104747
|
+
const derivedFrom = parsed?.from;
|
|
104748
|
+
if (derivedFrom && String(derivedFrom).toLowerCase() !== from.toLowerCase()) {
|
|
104749
|
+
console.warn(
|
|
104750
|
+
"[WalletService] signedTx sender mismatch. wallet=",
|
|
104751
|
+
from,
|
|
104752
|
+
"txFrom=",
|
|
104753
|
+
derivedFrom
|
|
104754
|
+
);
|
|
104755
|
+
}
|
|
104756
|
+
} catch {
|
|
104757
|
+
}
|
|
104710
104758
|
const txHash = await this.sendRawTransaction(signedTx, params.chainId);
|
|
104711
104759
|
await LocalForage.delete(STORAGE_KEYS.share2(this.orgHost));
|
|
104712
104760
|
return txHash;
|
|
@@ -104714,10 +104762,16 @@ var WalletService = class {
|
|
|
104714
104762
|
if (error instanceof SDKError) {
|
|
104715
104763
|
throw error;
|
|
104716
104764
|
}
|
|
104717
|
-
const
|
|
104718
|
-
|
|
104765
|
+
const msg = (() => {
|
|
104766
|
+
try {
|
|
104767
|
+
const anyErr = error;
|
|
104768
|
+
return anyErr?.shortMessage || anyErr?.reason || anyErr?.message || String(error);
|
|
104769
|
+
} catch {
|
|
104770
|
+
return "Unknown error";
|
|
104771
|
+
}
|
|
104772
|
+
})();
|
|
104719
104773
|
throw new SDKError(
|
|
104720
|
-
`Transaction failed: ${
|
|
104774
|
+
`Transaction failed: ${msg}`,
|
|
104721
104775
|
"TRANSACTION_FAILED" /* TRANSACTION_FAILED */,
|
|
104722
104776
|
error
|
|
104723
104777
|
);
|