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