btc-wallet 0.5.47-beta → 0.5.49-beta
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/core/btcUtils.d.ts +2 -2
- package/dist/core/setupBTCWallet/index.d.ts +2 -1
- package/dist/evmSigner/index.d.ts +2 -6867
- package/dist/index.js +142 -59
- package/dist/index.js.map +2 -2
- package/dist/utils/initWalletButton.d.ts +1 -1
- package/dist/utils/nearUtils.d.ts +2 -3
- package/dist/utils/satoshi.d.ts +32 -11
- package/esm/index.js +142 -59
- package/esm/index.js.map +2 -2
- package/package.json +10 -28
package/dist/index.js
CHANGED
@@ -24,6 +24,18 @@ var __spreadValues = (a, b) => {
|
|
24
24
|
return a;
|
25
25
|
};
|
26
26
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
27
|
+
var __objRest = (source, exclude) => {
|
28
|
+
var target = {};
|
29
|
+
for (var prop in source)
|
30
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
31
|
+
target[prop] = source[prop];
|
32
|
+
if (source != null && __getOwnPropSymbols)
|
33
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
34
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
35
|
+
target[prop] = source[prop];
|
36
|
+
}
|
37
|
+
return target;
|
38
|
+
};
|
27
39
|
var __export = (target, all) => {
|
28
40
|
for (var name in all)
|
29
41
|
__defProp(target, name, { get: all[name], enumerable: true });
|
@@ -95,6 +107,7 @@ __export(src_exports, {
|
|
95
107
|
calculateGasFee: () => calculateGasFee,
|
96
108
|
calculateGasLimit: () => calculateGasLimit,
|
97
109
|
calculateWithdraw: () => calculateWithdraw,
|
110
|
+
checkBridgeTransactionStatus: () => checkBridgeTransactionStatus,
|
98
111
|
checkGasTokenDebt: () => checkGasTokenDebt,
|
99
112
|
checkSatoshiWhitelist: () => checkSatoshiWhitelist,
|
100
113
|
estimateDepositAmount: () => estimateDepositAmount,
|
@@ -3211,10 +3224,11 @@ var state_default = {
|
|
3211
3224
|
};
|
3212
3225
|
|
3213
3226
|
// src/utils/satoshi.ts
|
3214
|
-
function getNonce(
|
3215
|
-
return __async(this,
|
3227
|
+
function getNonce(_0) {
|
3228
|
+
return __async(this, arguments, function* ({ env, accountId }) {
|
3229
|
+
const config = getWalletConfig(env);
|
3216
3230
|
const { result_code, result_message, result_data } = yield request(
|
3217
|
-
`${
|
3231
|
+
`${config.base_url}/v1/nonce?csna=${accountId}`
|
3218
3232
|
);
|
3219
3233
|
if (result_code !== 0) {
|
3220
3234
|
throw new Error(result_message);
|
@@ -3222,10 +3236,11 @@ function getNonce(url, accountId) {
|
|
3222
3236
|
return result_data;
|
3223
3237
|
});
|
3224
3238
|
}
|
3225
|
-
function getNearNonce(
|
3226
|
-
return __async(this,
|
3239
|
+
function getNearNonce(_0) {
|
3240
|
+
return __async(this, arguments, function* ({ env, accountId }) {
|
3241
|
+
const config = getWalletConfig(env);
|
3227
3242
|
const { result_code, result_message, result_data } = yield request(
|
3228
|
-
`${
|
3243
|
+
`${config.base_url}/v1/nonceNear?csna=${accountId}`
|
3229
3244
|
);
|
3230
3245
|
if (result_code !== 0) {
|
3231
3246
|
throw new Error(result_message);
|
@@ -3233,10 +3248,12 @@ function getNearNonce(url, accountId) {
|
|
3233
3248
|
return result_data;
|
3234
3249
|
});
|
3235
3250
|
}
|
3236
|
-
function receiveTransaction(
|
3251
|
+
function receiveTransaction(_a) {
|
3237
3252
|
return __async(this, null, function* () {
|
3253
|
+
var _b = _a, { env } = _b, data = __objRest(_b, ["env"]);
|
3254
|
+
const config = getWalletConfig(env);
|
3238
3255
|
const { result_code, result_message, result_data } = yield request(
|
3239
|
-
`${
|
3256
|
+
`${config.base_url}/v1/receiveTransaction`,
|
3240
3257
|
{
|
3241
3258
|
method: "POST",
|
3242
3259
|
body: data
|
@@ -3248,10 +3265,17 @@ function receiveTransaction(url, data) {
|
|
3248
3265
|
return result_data;
|
3249
3266
|
});
|
3250
3267
|
}
|
3251
|
-
function preReceiveDepositMsg(_0
|
3252
|
-
return __async(this, arguments, function* (
|
3268
|
+
function preReceiveDepositMsg(_0) {
|
3269
|
+
return __async(this, arguments, function* ({
|
3270
|
+
env,
|
3271
|
+
btcPublicKey,
|
3272
|
+
depositType = 1,
|
3273
|
+
postActions,
|
3274
|
+
extraMsg
|
3275
|
+
}) {
|
3276
|
+
const config = getWalletConfig(env);
|
3253
3277
|
const { result_code, result_message, result_data } = yield request(
|
3254
|
-
`${
|
3278
|
+
`${config.base_url}/v1/preReceiveDepositMsg`,
|
3255
3279
|
{
|
3256
3280
|
method: "POST",
|
3257
3281
|
body: { btcPublicKey, depositType, postActions, extraMsg }
|
@@ -3264,10 +3288,18 @@ function preReceiveDepositMsg(_0, _1) {
|
|
3264
3288
|
return result_data;
|
3265
3289
|
});
|
3266
3290
|
}
|
3267
|
-
function receiveDepositMsg(_0
|
3268
|
-
return __async(this, arguments, function* (
|
3291
|
+
function receiveDepositMsg(_0) {
|
3292
|
+
return __async(this, arguments, function* ({
|
3293
|
+
env,
|
3294
|
+
btcPublicKey,
|
3295
|
+
txHash,
|
3296
|
+
depositType = 1,
|
3297
|
+
postActions,
|
3298
|
+
extraMsg
|
3299
|
+
}) {
|
3300
|
+
const config = getWalletConfig(env);
|
3269
3301
|
const { result_code, result_message, result_data } = yield request(
|
3270
|
-
`${
|
3302
|
+
`${config.base_url}/v1/receiveDepositMsg`,
|
3271
3303
|
{
|
3272
3304
|
method: "POST",
|
3273
3305
|
body: { btcPublicKey, txHash, depositType, postActions, extraMsg }
|
@@ -3280,28 +3312,41 @@ function receiveDepositMsg(_0, _1) {
|
|
3280
3312
|
return result_data;
|
3281
3313
|
});
|
3282
3314
|
}
|
3283
|
-
function checkBridgeTransactionStatus(
|
3284
|
-
return __async(this,
|
3285
|
-
|
3286
|
-
|
3287
|
-
|
3288
|
-
|
3289
|
-
|
3290
|
-
|
3291
|
-
|
3292
|
-
|
3315
|
+
function checkBridgeTransactionStatus(_0) {
|
3316
|
+
return __async(this, arguments, function* ({
|
3317
|
+
txHash,
|
3318
|
+
fromChain,
|
3319
|
+
env
|
3320
|
+
}) {
|
3321
|
+
const config = getWalletConfig(env);
|
3322
|
+
const { result_code, result_message, result_data } = yield request(
|
3323
|
+
`${config.base_url}/v1/bridgeFromTx?fromTxHash=${txHash}&fromChainId=${fromChain === "NEAR" ? 2 : 1}`,
|
3324
|
+
{
|
3325
|
+
timeout: 3 * 60 * 60 * 1e3,
|
3326
|
+
pollingInterval: 5e3,
|
3327
|
+
maxPollingAttempts: 3e3,
|
3328
|
+
shouldStopPolling: (res) => {
|
3329
|
+
var _a;
|
3330
|
+
const status = ((_a = res.result_data) == null ? void 0 : _a.Status) || 0;
|
3331
|
+
return res.result_code === 0 && (status === 4 || status >= 50);
|
3332
|
+
}
|
3293
3333
|
}
|
3294
|
-
|
3334
|
+
);
|
3295
3335
|
console.log("checkTransactionStatus resp:", { result_code, result_message, result_data });
|
3296
3336
|
if ((result_data == null ? void 0 : result_data.Status) !== 4) {
|
3297
3337
|
throw new Error(result_message || `Transaction failed, status: ${result_data == null ? void 0 : result_data.Status}`);
|
3298
3338
|
}
|
3339
|
+
console.log("checkBridgeTransactionStatus resp:", result_data);
|
3299
3340
|
return result_data;
|
3300
3341
|
});
|
3301
3342
|
}
|
3302
|
-
function checkBtcTransactionStatus(
|
3303
|
-
return __async(this,
|
3304
|
-
|
3343
|
+
function checkBtcTransactionStatus(_0) {
|
3344
|
+
return __async(this, arguments, function* ({
|
3345
|
+
signature,
|
3346
|
+
env
|
3347
|
+
}) {
|
3348
|
+
const config = getWalletConfig(env);
|
3349
|
+
const { result_code, result_message, result_data } = yield request(`${config.base_url}/v1/btcTx?sig=${toHex(signature)}`, {
|
3305
3350
|
timeout: 3e5,
|
3306
3351
|
pollingInterval: 5e3,
|
3307
3352
|
maxPollingAttempts: 60,
|
@@ -3311,16 +3356,17 @@ function checkBtcTransactionStatus(url, sig) {
|
|
3311
3356
|
return res.result_code === 0 && (status === 3 || status >= 10);
|
3312
3357
|
}
|
3313
3358
|
});
|
3314
|
-
console.log("checkBtcTransactionStatus resp:", { result_code, result_message, result_data });
|
3315
3359
|
if ((result_data == null ? void 0 : result_data.Status) !== 3) {
|
3316
3360
|
throw new Error(result_message || `Transaction failed, status: ${result_data == null ? void 0 : result_data.Status}`);
|
3317
3361
|
}
|
3362
|
+
console.log("checkBtcTransactionStatus resp:", { result_code, result_message, result_data });
|
3318
3363
|
return result_data;
|
3319
3364
|
});
|
3320
3365
|
}
|
3321
|
-
function getWhitelist(
|
3322
|
-
return __async(this,
|
3323
|
-
const
|
3366
|
+
function getWhitelist(_0) {
|
3367
|
+
return __async(this, arguments, function* ({ env }) {
|
3368
|
+
const config = getWalletConfig(env);
|
3369
|
+
const data = yield request(`${config.base_url}/v1/whitelist/users`).catch((error) => {
|
3324
3370
|
console.error("getWhitelist error:", error);
|
3325
3371
|
return [];
|
3326
3372
|
});
|
@@ -3434,7 +3480,7 @@ function convertTransactionToTxHex(_0) {
|
|
3434
3480
|
const accessKey = __spreadProps(__spreadValues({}, rawAccessKey), {
|
3435
3481
|
nonce: BigInt((rawAccessKey == null ? void 0 : rawAccessKey.nonce) || 0)
|
3436
3482
|
});
|
3437
|
-
const nearNonceFromApi = yield getNearNonce(
|
3483
|
+
const nearNonceFromApi = yield getNearNonce({ env, accountId });
|
3438
3484
|
let nearNonceNumber = accessKey.nonce + BigInt(1);
|
3439
3485
|
if (nearNonceFromApi) {
|
3440
3486
|
nearNonceNumber = BigInt(nearNonceFromApi) > nearNonceNumber ? BigInt(nearNonceFromApi) : nearNonceNumber;
|
@@ -3471,7 +3517,7 @@ function convertTransactionToTxHex(_0) {
|
|
3471
3517
|
function calculateGasLimit(params) {
|
3472
3518
|
return __async(this, null, function* () {
|
3473
3519
|
const trans = [...params.transactions];
|
3474
|
-
console.log("raw trans:", trans);
|
3520
|
+
console.log("calculateGasLimit raw trans:", trans);
|
3475
3521
|
const { gasLimit } = yield calculateGasStrategy(params);
|
3476
3522
|
return gasLimit;
|
3477
3523
|
});
|
@@ -3959,14 +4005,16 @@ function executeBTCDepositAndAction(_0) {
|
|
3959
4005
|
"Fee Rate": _feeRate
|
3960
4006
|
});
|
3961
4007
|
const postActionsStr = newActions.length > 0 ? JSON.stringify(newActions) : void 0;
|
3962
|
-
yield preReceiveDepositMsg(
|
4008
|
+
yield preReceiveDepositMsg({
|
4009
|
+
env,
|
3963
4010
|
btcPublicKey,
|
3964
4011
|
depositType: postActionsStr || depositMsg.extra_msg ? 1 : 0,
|
3965
4012
|
postActions: postActionsStr,
|
3966
4013
|
extraMsg: depositMsg.extra_msg
|
3967
4014
|
});
|
3968
4015
|
const txHash = yield sendBitcoin(userDepositAddress, depositAmount, _feeRate);
|
3969
|
-
yield receiveDepositMsg(
|
4016
|
+
yield receiveDepositMsg({
|
4017
|
+
env,
|
3970
4018
|
btcPublicKey,
|
3971
4019
|
txHash,
|
3972
4020
|
depositType: postActionsStr || depositMsg.extra_msg ? 1 : 0,
|
@@ -3976,8 +4024,11 @@ function executeBTCDepositAndAction(_0) {
|
|
3976
4024
|
if (!pollResult) {
|
3977
4025
|
return txHash;
|
3978
4026
|
}
|
3979
|
-
const checkTransactionStatusRes = yield checkBridgeTransactionStatus(
|
3980
|
-
|
4027
|
+
const checkTransactionStatusRes = yield checkBridgeTransactionStatus({
|
4028
|
+
txHash,
|
4029
|
+
fromChain: "BTC",
|
4030
|
+
env
|
4031
|
+
});
|
3981
4032
|
const network = yield getNetwork();
|
3982
4033
|
const result = yield pollTransactionStatuses(network, [checkTransactionStatusRes.ToTxHash]);
|
3983
4034
|
return result;
|
@@ -4001,8 +4052,7 @@ function checkSatoshiWhitelist(btcAccountId, env = "mainnet") {
|
|
4001
4052
|
}
|
4002
4053
|
if (!btcAccountId)
|
4003
4054
|
return;
|
4004
|
-
const
|
4005
|
-
const whitelist = yield getWhitelist(config.base_url);
|
4055
|
+
const whitelist = yield getWhitelist({ env });
|
4006
4056
|
if (!(whitelist == null ? void 0 : whitelist.length))
|
4007
4057
|
return;
|
4008
4058
|
const isWhitelisted = whitelist.includes(btcAccountId);
|
@@ -4316,13 +4366,13 @@ function uint8ArrayToHex(uint8Array) {
|
|
4316
4366
|
}
|
4317
4367
|
|
4318
4368
|
// src/utils/initWalletButton.ts
|
4319
|
-
function setupWalletButton(env, wallet, originalWallet) {
|
4320
|
-
console.log(
|
4369
|
+
function setupWalletButton(env, wallet, originalWallet, walletUrl) {
|
4370
|
+
console.log(`setupWalletButton ${walletUrl || ""}`);
|
4321
4371
|
if (document.getElementById("satoshi-wallet-button")) {
|
4322
4372
|
return;
|
4323
4373
|
}
|
4324
4374
|
const iframe = createIframe({
|
4325
|
-
iframeUrl: walletConfig[env].walletUrl,
|
4375
|
+
iframeUrl: walletUrl || walletConfig[env].walletUrl,
|
4326
4376
|
iframeStyle: { width: "400px", height: "650px" }
|
4327
4377
|
});
|
4328
4378
|
iframe.addEventListener("mouseenter", () => {
|
@@ -4367,7 +4417,8 @@ function createFloatingButtonWithIframe({
|
|
4367
4417
|
height: "60px",
|
4368
4418
|
cursor: "grab",
|
4369
4419
|
transition: "transform 0.15s ease",
|
4370
|
-
userSelect: "none"
|
4420
|
+
userSelect: "none",
|
4421
|
+
touchAction: "none"
|
4371
4422
|
});
|
4372
4423
|
document.body.appendChild(button);
|
4373
4424
|
updateIframePosition(iframe, right, bottom, windowWidth, windowHeight);
|
@@ -4378,21 +4429,41 @@ function createFloatingButtonWithIframe({
|
|
4378
4429
|
let initialBottom = 0;
|
4379
4430
|
let dragStartTime = 0;
|
4380
4431
|
button.addEventListener("mousedown", (e) => {
|
4432
|
+
startDrag(e.clientX, e.clientY);
|
4433
|
+
e.preventDefault();
|
4434
|
+
});
|
4435
|
+
button.addEventListener("touchstart", (e) => {
|
4436
|
+
if (e.touches.length === 1) {
|
4437
|
+
const touch = e.touches[0];
|
4438
|
+
startDrag(touch.clientX, touch.clientY);
|
4439
|
+
e.preventDefault();
|
4440
|
+
}
|
4441
|
+
});
|
4442
|
+
function startDrag(clientX, clientY) {
|
4381
4443
|
isDragging = true;
|
4382
|
-
startX =
|
4383
|
-
startY =
|
4444
|
+
startX = clientX;
|
4445
|
+
startY = clientY;
|
4384
4446
|
initialRight = parseInt(button.style.right);
|
4385
4447
|
initialBottom = parseInt(button.style.bottom);
|
4386
4448
|
dragStartTime = Date.now();
|
4387
4449
|
button.style.cursor = "grabbing";
|
4388
4450
|
button.style.transition = "none";
|
4389
|
-
|
4390
|
-
});
|
4451
|
+
}
|
4391
4452
|
document.addEventListener("mousemove", (e) => {
|
4392
4453
|
if (!isDragging)
|
4393
4454
|
return;
|
4394
|
-
|
4395
|
-
|
4455
|
+
moveButton(e.clientX, e.clientY);
|
4456
|
+
});
|
4457
|
+
document.addEventListener("touchmove", (e) => {
|
4458
|
+
if (!isDragging || e.touches.length !== 1)
|
4459
|
+
return;
|
4460
|
+
const touch = e.touches[0];
|
4461
|
+
moveButton(touch.clientX, touch.clientY);
|
4462
|
+
e.preventDefault();
|
4463
|
+
});
|
4464
|
+
function moveButton(clientX, clientY) {
|
4465
|
+
const deltaX = startX - clientX;
|
4466
|
+
const deltaY = startY - clientY;
|
4396
4467
|
let newRight = initialRight + deltaX;
|
4397
4468
|
let newBottom = initialBottom + deltaY;
|
4398
4469
|
newRight = Math.min(Math.max(20, newRight), windowWidth - 80);
|
@@ -4412,8 +4483,17 @@ function createFloatingButtonWithIframe({
|
|
4412
4483
|
button.style.right = `${newRight}px`;
|
4413
4484
|
button.style.bottom = `${newBottom}px`;
|
4414
4485
|
updateIframePosition(iframe, newRight, newBottom, windowWidth, windowHeight);
|
4415
|
-
}
|
4486
|
+
}
|
4416
4487
|
document.addEventListener("mouseup", () => {
|
4488
|
+
endDrag();
|
4489
|
+
});
|
4490
|
+
document.addEventListener("touchend", () => {
|
4491
|
+
endDrag();
|
4492
|
+
});
|
4493
|
+
document.addEventListener("touchcancel", () => {
|
4494
|
+
endDrag();
|
4495
|
+
});
|
4496
|
+
function endDrag() {
|
4417
4497
|
if (!isDragging)
|
4418
4498
|
return;
|
4419
4499
|
const dragEndTime = Date.now();
|
@@ -4431,7 +4511,7 @@ function createFloatingButtonWithIframe({
|
|
4431
4511
|
if (!isDragEvent) {
|
4432
4512
|
handleButtonClick();
|
4433
4513
|
}
|
4434
|
-
}
|
4514
|
+
}
|
4435
4515
|
const handleButtonClick = () => {
|
4436
4516
|
const isCurrentlyVisible = iframe.style.display === "block";
|
4437
4517
|
button.style.transform = "scale(0.8)";
|
@@ -4640,7 +4720,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
4640
4720
|
if (btcPublicKey) {
|
4641
4721
|
yield getNearAccountByBtcPublicKey(btcPublicKey);
|
4642
4722
|
removeWalletButton();
|
4643
|
-
setupWalletButton(env, wallet, btcContext);
|
4723
|
+
setupWalletButton(env, wallet, btcContext, metadata.walletUrl);
|
4644
4724
|
}
|
4645
4725
|
} else {
|
4646
4726
|
removeWalletButton();
|
@@ -4803,7 +4883,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
4803
4883
|
})
|
4804
4884
|
)
|
4805
4885
|
);
|
4806
|
-
const nonceFromApi = yield getNonce(
|
4886
|
+
const nonceFromApi = yield getNonce({ env, accountId: csna });
|
4807
4887
|
const nonceFromContract = (accountInfo == null ? void 0 : accountInfo.nonce) || 0;
|
4808
4888
|
const nonce = Number(nonceFromApi) > Number(nonceFromContract) ? String(nonceFromApi) : String(nonceFromContract);
|
4809
4889
|
const intention = {
|
@@ -4818,12 +4898,13 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
4818
4898
|
};
|
4819
4899
|
const strIntention = JSON.stringify(intention);
|
4820
4900
|
const signature = yield btcContext.signMessage(strIntention);
|
4821
|
-
yield receiveTransaction(
|
4901
|
+
yield receiveTransaction({
|
4902
|
+
env,
|
4822
4903
|
sig: signature,
|
4823
4904
|
btcPubKey: state_default.getBtcPublicKey(),
|
4824
4905
|
data: toHex(strIntention)
|
4825
4906
|
});
|
4826
|
-
yield checkBtcTransactionStatus(
|
4907
|
+
yield checkBtcTransactionStatus({ signature, env });
|
4827
4908
|
const hash = newTrans.slice(1).map((t) => t.hash);
|
4828
4909
|
console.log("txHash:", hash);
|
4829
4910
|
const result = yield pollTransactionStatuses(options.network.networkId, hash);
|
@@ -4852,7 +4933,8 @@ function setupBTCWallet({
|
|
4852
4933
|
deprecated = false,
|
4853
4934
|
autoConnect = true,
|
4854
4935
|
syncLogOut = true,
|
4855
|
-
env = "mainnet"
|
4936
|
+
env = "mainnet",
|
4937
|
+
walletUrl
|
4856
4938
|
} = {}) {
|
4857
4939
|
console.log("\u26A1\uFE0F BTC Wallet Version:", getVersion(), "env:", env);
|
4858
4940
|
const btcWallet = () => __async(this, null, function* () {
|
@@ -4868,7 +4950,8 @@ function setupBTCWallet({
|
|
4868
4950
|
available: true,
|
4869
4951
|
autoConnect,
|
4870
4952
|
syncLogOut,
|
4871
|
-
env
|
4953
|
+
env,
|
4954
|
+
walletUrl
|
4872
4955
|
},
|
4873
4956
|
init: BTCWallet
|
4874
4957
|
};
|
@@ -4950,7 +5033,7 @@ function getGroup(state) {
|
|
4950
5033
|
|
4951
5034
|
// src/index.ts
|
4952
5035
|
var getVersion = () => {
|
4953
|
-
return "0.5.
|
5036
|
+
return "0.5.49-beta";
|
4954
5037
|
};
|
4955
5038
|
if (typeof window !== "undefined") {
|
4956
5039
|
window.__BTC_WALLET_VERSION = getVersion();
|