btc-wallet 0.0.6 → 0.0.7
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.js +43 -42
- package/dist/index.js.map +3 -3
- package/dist/utils/setupBTCWallet.d.ts +2 -2
- package/esm/index.js +45 -48
- package/esm/index.js.map +3 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1853,12 +1853,12 @@ var ConnectProvider = ({
|
|
|
1853
1853
|
version: ((_c = options.aaOptions.accountContracts[((_b = Object.keys(options.aaOptions.accountContracts)) == null ? void 0 : _b[0]) || "BTC"]) == null ? void 0 : _c[0].version) || "1.0.0"
|
|
1854
1854
|
});
|
|
1855
1855
|
const setAccountContract = (0, import_react10.useCallback)(
|
|
1856
|
-
(
|
|
1857
|
-
if (!checkBTCVersion(options.aaOptions.accountContracts,
|
|
1856
|
+
(config2) => {
|
|
1857
|
+
if (!checkBTCVersion(options.aaOptions.accountContracts, config2.name, config2.version)) {
|
|
1858
1858
|
throw new Error("Invalid Account Contract");
|
|
1859
1859
|
}
|
|
1860
|
-
localStorage.setItem(SAContractKey, JSON.stringify(
|
|
1861
|
-
_setAccountContract(
|
|
1860
|
+
localStorage.setItem(SAContractKey, JSON.stringify(config2));
|
|
1861
|
+
_setAccountContract(config2);
|
|
1862
1862
|
},
|
|
1863
1863
|
[options.aaOptions.accountContracts, _setAccountContract]
|
|
1864
1864
|
);
|
|
@@ -2017,9 +2017,9 @@ var ConnectProvider = ({
|
|
|
2017
2017
|
setConnectorId(void 0);
|
|
2018
2018
|
}, [connector]);
|
|
2019
2019
|
(0, import_react10.useEffect)(() => {
|
|
2020
|
-
const
|
|
2021
|
-
if (
|
|
2022
|
-
_setAccountContract(
|
|
2020
|
+
const config2 = JSON.parse(localStorage.getItem(SAContractKey) || "{}");
|
|
2021
|
+
if (config2.name && config2.version && checkBTCVersion(options.aaOptions.accountContracts, config2.name, config2.version)) {
|
|
2022
|
+
_setAccountContract(config2);
|
|
2023
2023
|
}
|
|
2024
2024
|
}, [options.aaOptions.accountContracts, _setAccountContract]);
|
|
2025
2025
|
(0, import_react10.useEffect)(() => {
|
|
@@ -2478,10 +2478,19 @@ function removeWalletButton() {
|
|
|
2478
2478
|
}
|
|
2479
2479
|
|
|
2480
2480
|
// src/utils/setupBTCWallet.ts
|
|
2481
|
-
var {
|
|
2482
|
-
var
|
|
2483
|
-
|
|
2484
|
-
|
|
2481
|
+
var { transfer, functionCall } = import_transactions.actionCreators;
|
|
2482
|
+
var config = {
|
|
2483
|
+
testnet: {
|
|
2484
|
+
base_url: "https://api.testnet.satoshibridge.top/v1",
|
|
2485
|
+
token: "nbtc2-nsp.testnet",
|
|
2486
|
+
contractId: "dev2-nsp.testnet"
|
|
2487
|
+
},
|
|
2488
|
+
mainnet: {
|
|
2489
|
+
base_url: "https://api.mainnet.satoshibridge.top/v1",
|
|
2490
|
+
token: "",
|
|
2491
|
+
contractId: ""
|
|
2492
|
+
}
|
|
2493
|
+
};
|
|
2485
2494
|
var state = {
|
|
2486
2495
|
saveAccount(account) {
|
|
2487
2496
|
window.localStorage.setItem("btc-wallet-account", account);
|
|
@@ -2551,11 +2560,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
|
2551
2560
|
const { nearTempAddress, nearTempPublicKey } = yield getNearAccountByBtcPublicKey(btcPublicKey);
|
|
2552
2561
|
removeWalletButton();
|
|
2553
2562
|
setTimeout(() => {
|
|
2554
|
-
initWalletButton(
|
|
2555
|
-
options.network.networkId,
|
|
2556
|
-
nearTempAddress,
|
|
2557
|
-
wallet
|
|
2558
|
-
);
|
|
2563
|
+
initWalletButton(options.network.networkId, nearTempAddress, wallet);
|
|
2559
2564
|
}, 1e3);
|
|
2560
2565
|
emitter.emit("accountsChanged", {
|
|
2561
2566
|
accounts: [
|
|
@@ -2578,13 +2583,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
|
2578
2583
|
}), 500);
|
|
2579
2584
|
}
|
|
2580
2585
|
function viewMethod(_02) {
|
|
2581
|
-
return __async(this, arguments, function* ({
|
|
2582
|
-
method,
|
|
2583
|
-
args = {}
|
|
2584
|
-
}) {
|
|
2586
|
+
return __async(this, arguments, function* ({ method, args = {} }) {
|
|
2585
2587
|
const res = yield provider.query({
|
|
2586
2588
|
request_type: "call_function",
|
|
2587
|
-
account_id: contractId,
|
|
2589
|
+
account_id: config[options.network.networkId].contractId,
|
|
2588
2590
|
method_name: method,
|
|
2589
2591
|
args_base64: Buffer.from(JSON.stringify(args)).toString("base64"),
|
|
2590
2592
|
finality: "optimistic"
|
|
@@ -2612,7 +2614,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
|
2612
2614
|
});
|
|
2613
2615
|
}
|
|
2614
2616
|
function signIn(_02) {
|
|
2615
|
-
return __async(this, arguments, function* ({ contractId
|
|
2617
|
+
return __async(this, arguments, function* ({ contractId, methodNames }) {
|
|
2616
2618
|
const accountId = state.getAccount();
|
|
2617
2619
|
const publicKey = state.getPublicKey();
|
|
2618
2620
|
const btcContext = window.btcContext;
|
|
@@ -2686,11 +2688,11 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
|
2686
2688
|
nonce: BigInt(rawAccessKey.nonce || 0)
|
|
2687
2689
|
});
|
|
2688
2690
|
const publicKeyFormat = import_key_pair.PublicKey.from(publicKey);
|
|
2689
|
-
const nearNonceApi = yield getNearNonceFromApi(accountId);
|
|
2691
|
+
const nearNonceApi = yield getNearNonceFromApi(options.network.networkId, accountId);
|
|
2690
2692
|
const newTransactions = params.transactions.map((transaction, index) => {
|
|
2691
2693
|
let nearNonceNumber = accessKey.nonce + BigInt(1);
|
|
2692
2694
|
if (nearNonceApi) {
|
|
2693
|
-
nearNonceNumber =
|
|
2695
|
+
nearNonceNumber = BigInt(nearNonceApi.result_data) > nearNonceNumber ? BigInt(nearNonceApi.result_data) : nearNonceNumber;
|
|
2694
2696
|
}
|
|
2695
2697
|
const newActions = transaction.actions.map((action) => {
|
|
2696
2698
|
switch (action.type) {
|
|
@@ -2714,8 +2716,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
|
2714
2716
|
(0, import_utils5.baseDecode)(header.hash)
|
|
2715
2717
|
);
|
|
2716
2718
|
const txBytes = (0, import_transaction.encodeTransaction)(_transaction);
|
|
2717
|
-
const txHex = Array.from(
|
|
2718
|
-
|
|
2719
|
+
const txHex = Array.from(
|
|
2720
|
+
txBytes,
|
|
2721
|
+
(byte) => ("0" + (byte & 255).toString(16)).slice(-2)
|
|
2722
|
+
).join("");
|
|
2719
2723
|
const hash = import_bs58.default.encode(new Uint8Array(import_js_sha256.sha256.array(txBytes)));
|
|
2720
2724
|
return { txBytes, txHex, hash };
|
|
2721
2725
|
});
|
|
@@ -2723,29 +2727,26 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
|
2723
2727
|
method: "get_account",
|
|
2724
2728
|
args: { account_id: accountId }
|
|
2725
2729
|
});
|
|
2726
|
-
const nonceApi = yield getNonceFromApi(accountId);
|
|
2727
|
-
const nonce = (nonceApi == null ? void 0 : nonceApi.result_data)
|
|
2730
|
+
const nonceApi = yield getNonceFromApi(options.network.networkId, accountId);
|
|
2731
|
+
const nonce = Number(nonceApi == null ? void 0 : nonceApi.result_data) > Number(accountInfo.nonce) ? String(nonceApi == null ? void 0 : nonceApi.result_data) : String(accountInfo.nonce);
|
|
2728
2732
|
const intention = {
|
|
2729
2733
|
chain_id: "397",
|
|
2730
2734
|
csna: accountId,
|
|
2731
2735
|
near_transactions: newTransactions.map((t) => t.txHex),
|
|
2732
|
-
gas_token: token,
|
|
2736
|
+
gas_token: config[options.network.networkId].token,
|
|
2733
2737
|
gas_limit: "3000",
|
|
2734
|
-
nonce
|
|
2738
|
+
nonce
|
|
2735
2739
|
};
|
|
2736
2740
|
const strIntention = JSON.stringify(intention);
|
|
2737
2741
|
const signature = yield btcContext.signMessage(strIntention);
|
|
2738
|
-
const result = yield uploadBTCTx({
|
|
2742
|
+
const result = yield uploadBTCTx(options.network.networkId, {
|
|
2739
2743
|
sig: signature,
|
|
2740
2744
|
btcPubKey: state.getBtcPublicKey(),
|
|
2741
2745
|
data: toHex(strIntention)
|
|
2742
2746
|
});
|
|
2743
2747
|
if (result.result_code === 0) {
|
|
2744
2748
|
const hash = newTransactions.map((t) => t.hash);
|
|
2745
|
-
const result2 = yield pollTransactionStatuses(
|
|
2746
|
-
options.network.networkId,
|
|
2747
|
-
hash
|
|
2748
|
-
);
|
|
2749
|
+
const result2 = yield pollTransactionStatuses(options.network.networkId, hash);
|
|
2749
2750
|
return result2;
|
|
2750
2751
|
} else {
|
|
2751
2752
|
return null;
|
|
@@ -2754,24 +2755,24 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
|
2754
2755
|
}
|
|
2755
2756
|
return wallet;
|
|
2756
2757
|
});
|
|
2757
|
-
function getNonceFromApi(accountId) {
|
|
2758
|
-
return fetch(`${base_url}/nonce?csna=${accountId}`, {
|
|
2758
|
+
function getNonceFromApi(network, accountId) {
|
|
2759
|
+
return fetch(`${config[network].base_url}/nonce?csna=${accountId}`, {
|
|
2759
2760
|
method: "GET",
|
|
2760
2761
|
headers: {
|
|
2761
2762
|
"Content-Type": "application/json"
|
|
2762
2763
|
}
|
|
2763
2764
|
}).then((res) => res.json());
|
|
2764
2765
|
}
|
|
2765
|
-
function getNearNonceFromApi(accountId) {
|
|
2766
|
-
return fetch(`${base_url}/nonceNear?csna=${accountId}`, {
|
|
2766
|
+
function getNearNonceFromApi(network, accountId) {
|
|
2767
|
+
return fetch(`${config[network].base_url}/nonceNear?csna=${accountId}`, {
|
|
2767
2768
|
method: "GET",
|
|
2768
2769
|
headers: {
|
|
2769
2770
|
"Content-Type": "application/json"
|
|
2770
2771
|
}
|
|
2771
2772
|
}).then((res) => res.json());
|
|
2772
2773
|
}
|
|
2773
|
-
function uploadBTCTx(data) {
|
|
2774
|
-
return fetch(`${base_url}/receiveTransaction`, {
|
|
2774
|
+
function uploadBTCTx(network, data) {
|
|
2775
|
+
return fetch(`${config[network].base_url}/receiveTransaction`, {
|
|
2775
2776
|
method: "POST",
|
|
2776
2777
|
headers: {
|
|
2777
2778
|
"Content-Type": "application/json"
|
|
@@ -2871,7 +2872,7 @@ function pollTransactionStatuses(network, hashes) {
|
|
|
2871
2872
|
|
|
2872
2873
|
// src/index.ts
|
|
2873
2874
|
var getVersion = () => {
|
|
2874
|
-
return "0.0.
|
|
2875
|
+
return "0.0.7";
|
|
2875
2876
|
};
|
|
2876
2877
|
if (typeof window !== "undefined") {
|
|
2877
2878
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|