@weblock-wallet/sdk 0.1.58 → 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.cjs +34 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +34 -42
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -104664,25 +104664,40 @@ var WalletService = class {
|
|
|
104664
104664
|
if (!from) {
|
|
104665
104665
|
throw new SDKError("Wallet not found", "WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */);
|
|
104666
104666
|
}
|
|
104667
|
-
const
|
|
104668
|
-
|
|
104669
|
-
|
|
104670
|
-
|
|
104671
|
-
|
|
104672
|
-
|
|
104673
|
-
|
|
104674
|
-
|
|
104675
|
-
|
|
104676
|
-
|
|
104667
|
+
const walletInfo = await this.walletClient.getWallet();
|
|
104668
|
+
const share1 = walletInfo?.share1;
|
|
104669
|
+
let share2 = await LocalForage.get(
|
|
104670
|
+
STORAGE_KEYS.share2(this.orgHost)
|
|
104671
|
+
);
|
|
104672
|
+
if (!share2) {
|
|
104673
|
+
const [firebaseId, deviceSecret, encryptedShare2Device] = await Promise.all([
|
|
104674
|
+
LocalForage.get(STORAGE_KEYS.firebaseId(this.orgHost)),
|
|
104675
|
+
LocalForage.get(STORAGE_KEYS.deviceSecret(this.orgHost)),
|
|
104676
|
+
LocalForage.get(
|
|
104677
|
+
STORAGE_KEYS.encryptedShare2Device(this.orgHost)
|
|
104678
|
+
)
|
|
104679
|
+
]);
|
|
104680
|
+
if (firebaseId && deviceSecret && encryptedShare2Device) {
|
|
104681
|
+
try {
|
|
104682
|
+
console.debug(
|
|
104683
|
+
"[WalletService] recovering share2 from encryptedShare2_device"
|
|
104684
|
+
);
|
|
104685
|
+
share2 = Crypto.decryptShare(
|
|
104686
|
+
encryptedShare2Device,
|
|
104687
|
+
deviceSecret,
|
|
104688
|
+
firebaseId
|
|
104689
|
+
);
|
|
104690
|
+
} catch (e7) {
|
|
104691
|
+
console.warn(
|
|
104692
|
+
"[WalletService] failed to decrypt encryptedShare2_device",
|
|
104693
|
+
e7
|
|
104694
|
+
);
|
|
104695
|
+
}
|
|
104677
104696
|
}
|
|
104678
|
-
}
|
|
104679
|
-
const [share1, share2] = await Promise.all([
|
|
104680
|
-
this.walletClient.getWallet().then((wallet2) => wallet2.share1),
|
|
104681
|
-
LocalForage.get(STORAGE_KEYS.share2(this.orgHost))
|
|
104682
|
-
]);
|
|
104697
|
+
}
|
|
104683
104698
|
if (!share1 || !share2) {
|
|
104684
104699
|
throw new SDKError(
|
|
104685
|
-
"Wallet shares not found",
|
|
104700
|
+
"Wallet shares not found. Please unlock the wallet by calling retrieveWallet(PIN) once on this device.",
|
|
104686
104701
|
"WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */
|
|
104687
104702
|
);
|
|
104688
104703
|
}
|
|
@@ -104690,42 +104705,19 @@ var WalletService = class {
|
|
|
104690
104705
|
const wallet = new import_ethers2.Wallet(privateKey);
|
|
104691
104706
|
const nonce = params.nonce ?? await this.getTransactionCount(from, params.chainId);
|
|
104692
104707
|
const gasPrice = params.gasPrice ?? await this.getGasPrice(params.chainId);
|
|
104693
|
-
let gasLimit = params.gasLimit;
|
|
104694
|
-
if (!gasLimit) {
|
|
104695
|
-
try {
|
|
104696
|
-
const est = await this.estimateGas(
|
|
104697
|
-
{
|
|
104698
|
-
from,
|
|
104699
|
-
to: params.to,
|
|
104700
|
-
value: toHexQuantity(params.value),
|
|
104701
|
-
data: params.data || "0x"
|
|
104702
|
-
},
|
|
104703
|
-
params.chainId
|
|
104704
|
-
);
|
|
104705
|
-
const buffered = Math.max(21e3, Math.ceil(est * 1.2));
|
|
104706
|
-
gasLimit = "0x" + buffered.toString(16);
|
|
104707
|
-
} catch (e7) {
|
|
104708
|
-
const data = (params.data || "").toLowerCase();
|
|
104709
|
-
const fallback = data.startsWith("0x095ea7b3") ? 12e4 : data && data !== "0x" ? 8e5 : 21e3;
|
|
104710
|
-
gasLimit = "0x" + fallback.toString(16);
|
|
104711
|
-
}
|
|
104712
|
-
}
|
|
104713
104708
|
const signedTx = await wallet.signTransaction({
|
|
104714
104709
|
to: params.to,
|
|
104715
|
-
value: params.value
|
|
104710
|
+
value: params.value,
|
|
104716
104711
|
data: params.data || "0x",
|
|
104717
104712
|
chainId: params.chainId,
|
|
104718
104713
|
nonce,
|
|
104719
104714
|
gasPrice,
|
|
104720
|
-
gasLimit
|
|
104715
|
+
gasLimit: params.gasLimit
|
|
104721
104716
|
});
|
|
104722
104717
|
return this.sendRawTransaction(signedTx, params.chainId);
|
|
104723
104718
|
} catch (error) {
|
|
104724
|
-
const detail = String(
|
|
104725
|
-
error?.shortMessage ?? error?.reason ?? error?.message ?? ""
|
|
104726
|
-
).trim();
|
|
104727
104719
|
throw new SDKError(
|
|
104728
|
-
|
|
104720
|
+
"Transaction failed",
|
|
104729
104721
|
"TRANSACTION_FAILED" /* TRANSACTION_FAILED */,
|
|
104730
104722
|
error
|
|
104731
104723
|
);
|