@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.js
CHANGED
|
@@ -104619,25 +104619,40 @@ var WalletService = class {
|
|
|
104619
104619
|
if (!from) {
|
|
104620
104620
|
throw new SDKError("Wallet not found", "WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */);
|
|
104621
104621
|
}
|
|
104622
|
-
const
|
|
104623
|
-
|
|
104624
|
-
|
|
104625
|
-
|
|
104626
|
-
|
|
104627
|
-
|
|
104628
|
-
|
|
104629
|
-
|
|
104630
|
-
|
|
104631
|
-
|
|
104622
|
+
const walletInfo = await this.walletClient.getWallet();
|
|
104623
|
+
const share1 = walletInfo?.share1;
|
|
104624
|
+
let share2 = await LocalForage.get(
|
|
104625
|
+
STORAGE_KEYS.share2(this.orgHost)
|
|
104626
|
+
);
|
|
104627
|
+
if (!share2) {
|
|
104628
|
+
const [firebaseId, deviceSecret, encryptedShare2Device] = await Promise.all([
|
|
104629
|
+
LocalForage.get(STORAGE_KEYS.firebaseId(this.orgHost)),
|
|
104630
|
+
LocalForage.get(STORAGE_KEYS.deviceSecret(this.orgHost)),
|
|
104631
|
+
LocalForage.get(
|
|
104632
|
+
STORAGE_KEYS.encryptedShare2Device(this.orgHost)
|
|
104633
|
+
)
|
|
104634
|
+
]);
|
|
104635
|
+
if (firebaseId && deviceSecret && encryptedShare2Device) {
|
|
104636
|
+
try {
|
|
104637
|
+
console.debug(
|
|
104638
|
+
"[WalletService] recovering share2 from encryptedShare2_device"
|
|
104639
|
+
);
|
|
104640
|
+
share2 = Crypto.decryptShare(
|
|
104641
|
+
encryptedShare2Device,
|
|
104642
|
+
deviceSecret,
|
|
104643
|
+
firebaseId
|
|
104644
|
+
);
|
|
104645
|
+
} catch (e7) {
|
|
104646
|
+
console.warn(
|
|
104647
|
+
"[WalletService] failed to decrypt encryptedShare2_device",
|
|
104648
|
+
e7
|
|
104649
|
+
);
|
|
104650
|
+
}
|
|
104632
104651
|
}
|
|
104633
|
-
}
|
|
104634
|
-
const [share1, share2] = await Promise.all([
|
|
104635
|
-
this.walletClient.getWallet().then((wallet2) => wallet2.share1),
|
|
104636
|
-
LocalForage.get(STORAGE_KEYS.share2(this.orgHost))
|
|
104637
|
-
]);
|
|
104652
|
+
}
|
|
104638
104653
|
if (!share1 || !share2) {
|
|
104639
104654
|
throw new SDKError(
|
|
104640
|
-
"Wallet shares not found",
|
|
104655
|
+
"Wallet shares not found. Please unlock the wallet by calling retrieveWallet(PIN) once on this device.",
|
|
104641
104656
|
"WALLET_NOT_FOUND" /* WALLET_NOT_FOUND */
|
|
104642
104657
|
);
|
|
104643
104658
|
}
|
|
@@ -104645,42 +104660,19 @@ var WalletService = class {
|
|
|
104645
104660
|
const wallet = new Wallet(privateKey);
|
|
104646
104661
|
const nonce = params.nonce ?? await this.getTransactionCount(from, params.chainId);
|
|
104647
104662
|
const gasPrice = params.gasPrice ?? await this.getGasPrice(params.chainId);
|
|
104648
|
-
let gasLimit = params.gasLimit;
|
|
104649
|
-
if (!gasLimit) {
|
|
104650
|
-
try {
|
|
104651
|
-
const est = await this.estimateGas(
|
|
104652
|
-
{
|
|
104653
|
-
from,
|
|
104654
|
-
to: params.to,
|
|
104655
|
-
value: toHexQuantity(params.value),
|
|
104656
|
-
data: params.data || "0x"
|
|
104657
|
-
},
|
|
104658
|
-
params.chainId
|
|
104659
|
-
);
|
|
104660
|
-
const buffered = Math.max(21e3, Math.ceil(est * 1.2));
|
|
104661
|
-
gasLimit = "0x" + buffered.toString(16);
|
|
104662
|
-
} catch (e7) {
|
|
104663
|
-
const data = (params.data || "").toLowerCase();
|
|
104664
|
-
const fallback = data.startsWith("0x095ea7b3") ? 12e4 : data && data !== "0x" ? 8e5 : 21e3;
|
|
104665
|
-
gasLimit = "0x" + fallback.toString(16);
|
|
104666
|
-
}
|
|
104667
|
-
}
|
|
104668
104663
|
const signedTx = await wallet.signTransaction({
|
|
104669
104664
|
to: params.to,
|
|
104670
|
-
value: params.value
|
|
104665
|
+
value: params.value,
|
|
104671
104666
|
data: params.data || "0x",
|
|
104672
104667
|
chainId: params.chainId,
|
|
104673
104668
|
nonce,
|
|
104674
104669
|
gasPrice,
|
|
104675
|
-
gasLimit
|
|
104670
|
+
gasLimit: params.gasLimit
|
|
104676
104671
|
});
|
|
104677
104672
|
return this.sendRawTransaction(signedTx, params.chainId);
|
|
104678
104673
|
} catch (error) {
|
|
104679
|
-
const detail = String(
|
|
104680
|
-
error?.shortMessage ?? error?.reason ?? error?.message ?? ""
|
|
104681
|
-
).trim();
|
|
104682
104674
|
throw new SDKError(
|
|
104683
|
-
|
|
104675
|
+
"Transaction failed",
|
|
104684
104676
|
"TRANSACTION_FAILED" /* TRANSACTION_FAILED */,
|
|
104685
104677
|
error
|
|
104686
104678
|
);
|