btc-wallet 0.2.5 → 0.2.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/README.md +60 -6
- package/dist/components/signModal/index.d.ts +1 -1
- package/dist/config.d.ts +14 -0
- package/dist/context/index.d.ts +0 -2
- package/dist/core/bridgeSupplyUtils.d.ts +10 -0
- package/dist/{components → core}/btcWalletSelectorContext.d.ts +4 -1
- package/dist/{utils → core}/setupBTCWallet.d.ts +1 -1
- package/dist/evmSigner/index.d.ts +2737 -817
- package/dist/index.d.ts +3 -3
- package/dist/index.js +395 -228
- package/dist/index.js.map +4 -4
- package/dist/utils/ethereumUtils.d.ts +1 -4
- package/dist/utils/index.d.ts +0 -5
- package/dist/utils/request.d.ts +11 -0
- package/esm/index.js +391 -218
- package/esm/index.js.map +4 -4
- package/package.json +9 -7
- package/dist/components/hook.d.ts +0 -1
package/dist/index.js
CHANGED
@@ -83,13 +83,13 @@ __export(src_exports, {
|
|
83
83
|
BtcWalletSelectorContextProvider: () => BtcWalletSelectorContextProvider,
|
84
84
|
BybitConnector: () => BybitConnector,
|
85
85
|
ConnectProvider: () => ConnectProvider,
|
86
|
-
InitContextHook: () => InitContextHook,
|
87
86
|
InjectedConnector: () => InjectedConnector,
|
88
87
|
OKXConnector: () => OKXConnector,
|
89
88
|
TokenPocketConnector: () => TokenPocketConnector,
|
90
89
|
UnisatConnector: () => UnisatConnector,
|
91
90
|
WizzConnector: () => WizzConnector,
|
92
91
|
XverseConnector: () => XverseConnector,
|
92
|
+
executeBurrowSupply: () => executeBurrowSupply,
|
93
93
|
getVersion: () => getVersion,
|
94
94
|
setupBTCWallet: () => setupBTCWallet,
|
95
95
|
useAccountContract: () => useAccountContract,
|
@@ -134,6 +134,7 @@ var InjectedConnector = class extends BaseConnector {
|
|
134
134
|
requestAccounts() {
|
135
135
|
return __async(this, null, function* () {
|
136
136
|
const accounts = yield this.getProviderOrThrow().requestAccounts();
|
137
|
+
console.log("\u{1F680} ~ InjectedConnector ~ requestAccounts ~ accounts:", accounts);
|
137
138
|
return accounts;
|
138
139
|
});
|
139
140
|
}
|
@@ -534,7 +535,7 @@ var useAccounts = () => {
|
|
534
535
|
// src/hooks/useBTCProvider.ts
|
535
536
|
var import_react = require("react");
|
536
537
|
var useBTCProvider = () => {
|
537
|
-
const { connector, provider, accounts, getPublicKey, signMessage, getNetwork, switchNetwork, sendBitcoin } = useConnectProvider();
|
538
|
+
const { connector, provider, accounts, getPublicKey, signMessage, getNetwork, switchNetwork, sendBitcoin: sendBitcoin2 } = useConnectProvider();
|
538
539
|
const sendInscription = (0, import_react.useCallback)(
|
539
540
|
(address, inscriptionId, options) => __async(void 0, null, function* () {
|
540
541
|
if (!connector) {
|
@@ -545,7 +546,7 @@ var useBTCProvider = () => {
|
|
545
546
|
}),
|
546
547
|
[connector]
|
547
548
|
);
|
548
|
-
return { provider, accounts, getPublicKey, signMessage, getNetwork, switchNetwork, sendBitcoin, sendInscription, connector };
|
549
|
+
return { provider, accounts, getPublicKey, signMessage, getNetwork, switchNetwork, sendBitcoin: sendBitcoin2, sendInscription, connector };
|
549
550
|
};
|
550
551
|
|
551
552
|
// src/hooks/useConnectModal.ts
|
@@ -699,6 +700,7 @@ var WalletClientProvider = class {
|
|
699
700
|
}
|
700
701
|
}
|
701
702
|
if (method === "personal_sign" /* personalSign */) {
|
703
|
+
console.log("personal_sign ---- ", arg);
|
702
704
|
return new Promise((resolve, reject) => {
|
703
705
|
eventUtils_default.emit("personalSign" /* personalSign */, arg);
|
704
706
|
eventUtils_default.once("personalSignResult" /* personalSignResult */, ({ result, error }) => {
|
@@ -728,7 +730,7 @@ var WalletClientProvider = class {
|
|
728
730
|
|
729
731
|
// src/hooks/useETHProvider.ts
|
730
732
|
var useETHProvider = () => {
|
731
|
-
const { evmAccount, smartAccount
|
733
|
+
const { evmAccount, smartAccount } = useConnectProvider();
|
732
734
|
const [chainId, setChainId] = (0, import_react3.useState)();
|
733
735
|
(0, import_react3.useEffect)(() => {
|
734
736
|
if (smartAccount) {
|
@@ -822,7 +824,11 @@ var useETHProvider = () => {
|
|
822
824
|
return (smartAccount == null ? void 0 : smartAccount.provider).publicClient;
|
823
825
|
}, [smartAccount, chainId]);
|
824
826
|
const provider = (0, import_react3.useMemo)(() => {
|
825
|
-
const ethereumProvider = new EthereumProvider(
|
827
|
+
const ethereumProvider = new EthereumProvider(
|
828
|
+
sendUserOp,
|
829
|
+
smartAccount == null ? void 0 : smartAccount.provider,
|
830
|
+
evmAccount
|
831
|
+
);
|
826
832
|
return ethereumProvider;
|
827
833
|
}, [evmAccount, sendUserOp, smartAccount == null ? void 0 : smartAccount.provider]);
|
828
834
|
const walletClient = (0, import_react3.useMemo)(() => {
|
@@ -834,7 +840,6 @@ var useETHProvider = () => {
|
|
834
840
|
provider,
|
835
841
|
evmAccount,
|
836
842
|
account: evmAccount,
|
837
|
-
getSmartAccountInfo,
|
838
843
|
switchChain,
|
839
844
|
chainId,
|
840
845
|
getFeeQuotes,
|
@@ -1004,6 +1009,7 @@ var ConnectModal = ({ open, onClose }) => {
|
|
1004
1009
|
yield connect(connector.metadata.id);
|
1005
1010
|
closeConnectModal();
|
1006
1011
|
} catch (error) {
|
1012
|
+
console.error("onConnect error", error);
|
1007
1013
|
if (error.code === 4001) {
|
1008
1014
|
setRetryVisible(true);
|
1009
1015
|
}
|
@@ -1146,57 +1152,6 @@ var convertSignature = (signature) => {
|
|
1146
1152
|
function caculateNativeFee(userOp) {
|
1147
1153
|
return (BigInt(userOp.callGasLimit) + BigInt(userOp.verificationGasLimit) + BigInt(userOp.preVerificationGas)) * BigInt(userOp.maxFeePerGas);
|
1148
1154
|
}
|
1149
|
-
var getBTCAAAddress = (smartAccount, btcAddress, name, version) => __async(void 0, null, function* () {
|
1150
|
-
var _a;
|
1151
|
-
const addresses = yield smartAccount.provider.request({ method: "eth_accounts" });
|
1152
|
-
const owner = addresses[0];
|
1153
|
-
const localKey = `particle_${name}_${version}_${owner}`;
|
1154
|
-
if (typeof window !== "undefined" && localStorage) {
|
1155
|
-
const localAA = localStorage.getItem(localKey);
|
1156
|
-
if (localAA) {
|
1157
|
-
return localAA;
|
1158
|
-
}
|
1159
|
-
}
|
1160
|
-
const btcPublicKey = yield smartAccount.provider.getPublicKey();
|
1161
|
-
const accountInfo = yield smartAccount.sendRpc({
|
1162
|
-
method: "particle_aa_getBTCAccount",
|
1163
|
-
params: [
|
1164
|
-
{
|
1165
|
-
name,
|
1166
|
-
version,
|
1167
|
-
btcPublicKey,
|
1168
|
-
btcAddress
|
1169
|
-
}
|
1170
|
-
]
|
1171
|
-
});
|
1172
|
-
const address = (_a = accountInfo == null ? void 0 : accountInfo[0]) == null ? void 0 : _a.smartAccountAddress;
|
1173
|
-
if (typeof window !== "undefined" && localStorage && address) {
|
1174
|
-
localStorage.setItem(localKey, address);
|
1175
|
-
}
|
1176
|
-
return address;
|
1177
|
-
});
|
1178
|
-
var getBTCAccountInfo = (smartAccount, btcAddress, name, version) => __async(void 0, null, function* () {
|
1179
|
-
const btcPublicKey = yield smartAccount.provider.getPublicKey();
|
1180
|
-
const [accountInfo] = yield smartAccount.sendRpc({
|
1181
|
-
method: "particle_aa_getBTCAccount",
|
1182
|
-
params: [
|
1183
|
-
{
|
1184
|
-
name,
|
1185
|
-
version,
|
1186
|
-
btcPublicKey,
|
1187
|
-
btcAddress
|
1188
|
-
}
|
1189
|
-
]
|
1190
|
-
});
|
1191
|
-
const address = accountInfo.smartAccountAddress;
|
1192
|
-
const addresses = yield smartAccount.provider.request({ method: "eth_accounts" });
|
1193
|
-
const owner = addresses[0];
|
1194
|
-
const localKey = `particle_${name}_${version}_${owner}`;
|
1195
|
-
if (typeof window !== "undefined" && localStorage && address) {
|
1196
|
-
localStorage.setItem(localKey, address);
|
1197
|
-
}
|
1198
|
-
return accountInfo;
|
1199
|
-
});
|
1200
1155
|
|
1201
1156
|
// src/components/copyText/index.tsx
|
1202
1157
|
var import_react6 = require("react");
|
@@ -1466,7 +1421,11 @@ var sign_module_default = classes8;
|
|
1466
1421
|
|
1467
1422
|
// src/components/signModal/index.tsx
|
1468
1423
|
var import_jsx_runtime8 = require("react/jsx-runtime");
|
1469
|
-
var SignModal = ({
|
1424
|
+
var SignModal = ({
|
1425
|
+
open,
|
1426
|
+
onClose,
|
1427
|
+
onOpen
|
1428
|
+
}) => {
|
1470
1429
|
const [userOpBundle, setUserOpBundle] = (0, import_react8.useState)();
|
1471
1430
|
const [notRemindChecked, setNotRemindChecked] = (0, import_react8.useState)(false);
|
1472
1431
|
const [loading, setLoading] = (0, import_react8.useState)(false);
|
@@ -1546,10 +1505,13 @@ var SignModal = ({ open, onClose, onOpen }) => {
|
|
1546
1505
|
}), [userOpBundle, smartAccount, accountContract]);
|
1547
1506
|
(0, import_react8.useEffect)(() => {
|
1548
1507
|
if (userOpBundle && open) {
|
1508
|
+
console.log("deserializeUserOp start");
|
1549
1509
|
setDeserializeLoading(true);
|
1550
1510
|
deserializeUserOp().then((result) => {
|
1511
|
+
console.log("\u{1F680} ~ deserializeUserOp ~ result:", result);
|
1551
1512
|
setDeserializeResult(result);
|
1552
1513
|
}).catch((error) => {
|
1514
|
+
console.log("\u{1F680} ~ deserializeUserOp ~ error:", error);
|
1553
1515
|
eventUtils_default.emit("sendUserOpResult" /* sendUserOpResult */, {
|
1554
1516
|
error
|
1555
1517
|
});
|
@@ -1560,6 +1522,7 @@ var SignModal = ({ open, onClose, onOpen }) => {
|
|
1560
1522
|
(0, import_react8.useEffect)(() => {
|
1561
1523
|
if (open && publicClient && evmAccount && userOpBundle) {
|
1562
1524
|
publicClient.getBalance({ address: evmAccount }).then((result) => setNativeBalance(result)).catch((error) => {
|
1525
|
+
console.log("\u{1F680} ~ getBalance ~ error:", error);
|
1563
1526
|
eventUtils_default.emit("sendUserOpResult" /* sendUserOpResult */, {
|
1564
1527
|
error
|
1565
1528
|
});
|
@@ -1644,10 +1607,12 @@ var SignModal = ({ open, onClose, onOpen }) => {
|
|
1644
1607
|
var _a, _b;
|
1645
1608
|
return ((_b = (_a = item.estimatedChanges.natives) == null ? void 0 : _a[0]) == null ? void 0 : _b.nativeChange) && item.estimatedChanges.natives[0].nativeChange.startsWith("-");
|
1646
1609
|
}
|
1647
|
-
).map(
|
1648
|
-
|
1649
|
-
|
1650
|
-
|
1610
|
+
).map(
|
1611
|
+
(item) => {
|
1612
|
+
var _a, _b, _c, _d;
|
1613
|
+
return BigInt(((_d = (_c = (_b = (_a = item.estimatedChanges) == null ? void 0 : _a.natives) == null ? void 0 : _b[0]) == null ? void 0 : _c.nativeChange) == null ? void 0 : _d.replace("-", "")) || 0);
|
1614
|
+
}
|
1615
|
+
).reduce((accumulator, currentValue) => accumulator + currentValue, BigInt(0));
|
1651
1616
|
if (userOpBundle.userOp.paymasterAndData.length > 2) {
|
1652
1617
|
setDisabled(nativeBalance < nativeChange);
|
1653
1618
|
} else {
|
@@ -1669,37 +1634,52 @@ var SignModal = ({ open, onClose, onOpen }) => {
|
|
1669
1634
|
return JSON.stringify(obj, null, 2);
|
1670
1635
|
}
|
1671
1636
|
}, [requestArguments]);
|
1672
|
-
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
1673
|
-
|
1674
|
-
|
1675
|
-
|
1676
|
-
|
1677
|
-
|
1678
|
-
|
1679
|
-
|
1680
|
-
|
1681
|
-
|
1682
|
-
|
1683
|
-
|
1684
|
-
|
1685
|
-
|
1686
|
-
|
1687
|
-
|
1688
|
-
|
1689
|
-
|
1690
|
-
|
1691
|
-
|
1692
|
-
|
1693
|
-
|
1694
|
-
|
1695
|
-
|
1696
|
-
|
1697
|
-
|
1698
|
-
|
1699
|
-
|
1700
|
-
|
1701
|
-
|
1702
|
-
|
1637
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
1638
|
+
modal_default,
|
1639
|
+
{
|
1640
|
+
open,
|
1641
|
+
onClose,
|
1642
|
+
isDismissable: false,
|
1643
|
+
contentClassName: sign_module_default.modalContent,
|
1644
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
|
1645
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("img", { className: sign_module_default.closeBtn, src: close_default, onClick: closeModal }),
|
1646
|
+
requestArguments && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: sign_module_default.signTitle, children: requestArguments.method == "personal_sign" /* personalSign */ ? "Sign Message" : "Sign Typed Data" }),
|
1647
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: sign_module_default.chainInfo, children: [
|
1648
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("img", { src: chainInfo == null ? void 0 : chainInfo.icon }),
|
1649
|
+
chainInfo == null ? void 0 : chainInfo.fullname.replace("Mainnet", "")
|
1650
|
+
] }),
|
1651
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: sign_module_default.addressContainer, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(CopyText, { value: evmAccount, style: { textDecorationLine: "none" }, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: sign_module_default.addressInfo, children: [
|
1652
|
+
shortString(evmAccount),
|
1653
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("img", { src: copy_default })
|
1654
|
+
] }) }) }),
|
1655
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
|
1656
|
+
"div",
|
1657
|
+
{
|
1658
|
+
className: sign_module_default.detailsContent + (deserializeResult || requestArguments ? ` ${sign_module_default.fill}` : ""),
|
1659
|
+
children: [
|
1660
|
+
deserializeResult && deserializeResult.map((details, index) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(transactionDetails_default, { details }, `${details.type}-${index}`)),
|
1661
|
+
unsignedMessage && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: sign_module_default.unsignedMessage, children: unsignedMessage })
|
1662
|
+
]
|
1663
|
+
}
|
1664
|
+
),
|
1665
|
+
gasFee && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: sign_module_default.estimatedGas, children: `Estimated gas fee: ${(0, import_viem3.formatEther)(gasFee)} ${chainInfo == null ? void 0 : chainInfo.nativeCurrency.symbol}` }),
|
1666
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
1667
|
+
button_default,
|
1668
|
+
{
|
1669
|
+
onClick: confirmTx,
|
1670
|
+
className: sign_module_default.signBtn,
|
1671
|
+
isLoading: loading || deserializeLoading,
|
1672
|
+
isDisabled: disabled,
|
1673
|
+
children: deserializeLoading ? "LOADING" : disabled ? "INSUFFICIENT FEE" : "CONFIRM"
|
1674
|
+
}
|
1675
|
+
),
|
1676
|
+
showNotRemind && /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: sign_module_default.notRemind, onClick: toggleNotRemind, children: [
|
1677
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("img", { src: notRemindChecked ? check_box_default : check_box_blank_default }),
|
1678
|
+
"Do not remind me again"
|
1679
|
+
] })
|
1680
|
+
] })
|
1681
|
+
}
|
1682
|
+
);
|
1703
1683
|
};
|
1704
1684
|
var signModal_default = SignModal;
|
1705
1685
|
|
@@ -1724,6 +1704,7 @@ var AASignerProvider = class {
|
|
1724
1704
|
this.getPublicClient = () => {
|
1725
1705
|
var _a, _b;
|
1726
1706
|
const rpcUrl = ((_a = this == null ? void 0 : this.rpcUrls) == null ? void 0 : _a[this.chainId]) || ((_b = import_chains3.chains.getEVMChainInfoById(this.chainId || 1)) == null ? void 0 : _b.rpcUrl);
|
1707
|
+
console.log("rpcUrl", rpcUrl);
|
1727
1708
|
return (0, import_viem4.createPublicClient)({
|
1728
1709
|
transport: (0, import_viem4.http)(rpcUrl)
|
1729
1710
|
});
|
@@ -1758,8 +1739,10 @@ var AASignerProvider = class {
|
|
1758
1739
|
return `0x${this.chainId.toString(16)}`;
|
1759
1740
|
} else if (arg.method === "personal_sign" /* personalSign */) {
|
1760
1741
|
let message = (_a = arg.params) == null ? void 0 : _a[0];
|
1742
|
+
console.log("personal_sign message:", message);
|
1761
1743
|
if (message.length !== 66) {
|
1762
1744
|
const hash = (0, import_viem4.hashMessage)({ raw: message });
|
1745
|
+
console.log("personal_sign hash:", hash);
|
1763
1746
|
message = hash;
|
1764
1747
|
}
|
1765
1748
|
const result = yield this.personalSign(message || "");
|
@@ -1767,15 +1750,19 @@ var AASignerProvider = class {
|
|
1767
1750
|
if (!convertResult) {
|
1768
1751
|
throw new Error("sign error");
|
1769
1752
|
}
|
1753
|
+
console.log(`personal_sign result(${convertResult.length}): `, convertResult);
|
1770
1754
|
return convertResult;
|
1771
1755
|
} else if (arg.method === "eth_signTypedData" || arg.method === "eth_signTypedData_v4") {
|
1772
1756
|
const typedData = (_b = arg.params) == null ? void 0 : _b[1];
|
1757
|
+
console.log("signTypedData typedData", typedData);
|
1773
1758
|
const hash = (0, import_viem4.hashTypedData)(typeof typedData === "string" ? JSON.parse(typedData) : typedData);
|
1759
|
+
console.log("signTypedData hash", hash);
|
1774
1760
|
const result = yield this.personalSign(hash || "");
|
1775
1761
|
const convertResult = convertSignature(result);
|
1776
1762
|
if (!convertResult) {
|
1777
1763
|
throw new Error("sign error");
|
1778
1764
|
}
|
1765
|
+
console.log(`eth_signTypedData result(${convertResult.length}): `, convertResult);
|
1779
1766
|
return convertResult;
|
1780
1767
|
} else if (arg.method === "wallet_switchEthereumChain") {
|
1781
1768
|
if (arg.params && arg.params instanceof Array && arg.params[0] && arg.params[0].chainId) {
|
@@ -1846,7 +1833,11 @@ var ConnectProvider = ({
|
|
1846
1833
|
isModalOpen: connectModalOpen,
|
1847
1834
|
openModal: openConnectModal
|
1848
1835
|
} = useModalStateValue_default();
|
1849
|
-
const {
|
1836
|
+
const {
|
1837
|
+
closeModal: closeSignModal,
|
1838
|
+
isModalOpen: signModalOpen,
|
1839
|
+
openModal: openSignModal
|
1840
|
+
} = useModalStateValue_default();
|
1850
1841
|
const [connectorId, setConnectorId] = (0, import_react10.useState)();
|
1851
1842
|
const [accounts, setAccounts] = (0, import_react10.useState)([]);
|
1852
1843
|
const [evmAccount, setEVMAccount] = (0, import_react10.useState)();
|
@@ -1855,12 +1846,12 @@ var ConnectProvider = ({
|
|
1855
1846
|
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"
|
1856
1847
|
});
|
1857
1848
|
const setAccountContract = (0, import_react10.useCallback)(
|
1858
|
-
(
|
1859
|
-
if (!checkBTCVersion(options.aaOptions.accountContracts,
|
1849
|
+
(config) => {
|
1850
|
+
if (!checkBTCVersion(options.aaOptions.accountContracts, config.name, config.version)) {
|
1860
1851
|
throw new Error("Invalid Account Contract");
|
1861
1852
|
}
|
1862
|
-
localStorage.setItem(SAContractKey, JSON.stringify(
|
1863
|
-
_setAccountContract(
|
1853
|
+
localStorage.setItem(SAContractKey, JSON.stringify(config));
|
1854
|
+
_setAccountContract(config);
|
1864
1855
|
},
|
1865
1856
|
[options.aaOptions.accountContracts, _setAccountContract]
|
1866
1857
|
);
|
@@ -1899,7 +1890,7 @@ var ConnectProvider = ({
|
|
1899
1890
|
}),
|
1900
1891
|
[connector]
|
1901
1892
|
);
|
1902
|
-
const
|
1893
|
+
const sendBitcoin2 = (0, import_react10.useCallback)(
|
1903
1894
|
(toAddress, satoshis, options2) => __async(void 0, null, function* () {
|
1904
1895
|
if (!connector) {
|
1905
1896
|
throw new Error("Wallet not connected!");
|
@@ -1931,7 +1922,12 @@ var ConnectProvider = ({
|
|
1931
1922
|
}
|
1932
1923
|
if (!window.__bitcoinSmartAccount || (window == null ? void 0 : window.__bitcoinSmartAccount) && ((window == null ? void 0 : window.__bitcoinSmartAccount.smartAccountContract.version) !== accountContract.version || (window == null ? void 0 : window.__bitcoinSmartAccount.smartAccountContract.name) !== accountContract.name)) {
|
1933
1924
|
const smartAccount2 = new import_aa.SmartAccount(
|
1934
|
-
new AASignerProvider(
|
1925
|
+
new AASignerProvider(
|
1926
|
+
evmSupportChainIds,
|
1927
|
+
options.projectId,
|
1928
|
+
options.clientKey,
|
1929
|
+
options.rpcUrls
|
1930
|
+
),
|
1935
1931
|
options
|
1936
1932
|
);
|
1937
1933
|
smartAccount2.setSmartAccountContract(accountContract);
|
@@ -1941,30 +1937,6 @@ var ConnectProvider = ({
|
|
1941
1937
|
window.__bitcoinSmartAccount.provider.personalSign = signMessage;
|
1942
1938
|
return window.__bitcoinSmartAccount;
|
1943
1939
|
}, [options, evmSupportChainIds, getPublicKey, signMessage, accountContract]);
|
1944
|
-
(0, import_react10.useEffect)(() => {
|
1945
|
-
if (accounts.length > 0 && smartAccount) {
|
1946
|
-
getBTCAAAddress(smartAccount, accounts[0], accountContract.name, accountContract.version).then((res) => {
|
1947
|
-
setEVMAccount(res);
|
1948
|
-
}).catch((e) => {
|
1949
|
-
setEVMAccount(void 0);
|
1950
|
-
});
|
1951
|
-
} else {
|
1952
|
-
setEVMAccount(void 0);
|
1953
|
-
}
|
1954
|
-
}, [accountContract, accounts, smartAccount]);
|
1955
|
-
const getSmartAccountInfo = (0, import_react10.useCallback)(() => __async(void 0, null, function* () {
|
1956
|
-
if (accounts.length > 0 && smartAccount) {
|
1957
|
-
const accountInfo = yield getBTCAccountInfo(
|
1958
|
-
smartAccount,
|
1959
|
-
accounts[0],
|
1960
|
-
accountContract.name,
|
1961
|
-
accountContract.version
|
1962
|
-
);
|
1963
|
-
setEVMAccount(accountInfo.smartAccountAddress);
|
1964
|
-
return accountInfo;
|
1965
|
-
}
|
1966
|
-
return void 0;
|
1967
|
-
}), [accounts, smartAccount, accountContract, setEVMAccount]);
|
1968
1940
|
const requestAccount = (0, import_react10.useCallback)(
|
1969
1941
|
(connector2) => __async(void 0, null, function* () {
|
1970
1942
|
let accounts2 = yield connector2.getAccounts();
|
@@ -1975,20 +1947,18 @@ var ConnectProvider = ({
|
|
1975
1947
|
}),
|
1976
1948
|
[autoConnect]
|
1977
1949
|
);
|
1978
|
-
const requestDirectAccount = (0, import_react10.useCallback)(
|
1979
|
-
|
1980
|
-
|
1981
|
-
|
1982
|
-
|
1983
|
-
|
1984
|
-
|
1985
|
-
|
1986
|
-
}),
|
1987
|
-
[]
|
1988
|
-
);
|
1950
|
+
const requestDirectAccount = (0, import_react10.useCallback)((connector2) => __async(void 0, null, function* () {
|
1951
|
+
let accounts2 = yield connector2.getAccounts();
|
1952
|
+
if (accounts2.length === 0) {
|
1953
|
+
accounts2 = yield connector2.requestAccounts();
|
1954
|
+
}
|
1955
|
+
setAccounts(accounts2);
|
1956
|
+
return accounts2;
|
1957
|
+
}), []);
|
1989
1958
|
(0, import_react10.useEffect)(() => {
|
1990
1959
|
if (connector) {
|
1991
1960
|
requestAccount(connector).catch((e) => {
|
1961
|
+
console.error("get account error", e);
|
1992
1962
|
setAccounts([]);
|
1993
1963
|
});
|
1994
1964
|
} else {
|
@@ -2019,9 +1989,9 @@ var ConnectProvider = ({
|
|
2019
1989
|
setConnectorId(void 0);
|
2020
1990
|
}, [connector]);
|
2021
1991
|
(0, import_react10.useEffect)(() => {
|
2022
|
-
const
|
2023
|
-
if (
|
2024
|
-
_setAccountContract(
|
1992
|
+
const config = JSON.parse(localStorage.getItem(SAContractKey) || "{}");
|
1993
|
+
if (config.name && config.version && checkBTCVersion(options.aaOptions.accountContracts, config.name, config.version)) {
|
1994
|
+
_setAccountContract(config);
|
2025
1995
|
}
|
2026
1996
|
}, [options.aaOptions.accountContracts, _setAccountContract]);
|
2027
1997
|
(0, import_react10.useEffect)(() => {
|
@@ -2044,6 +2014,7 @@ var ConnectProvider = ({
|
|
2044
2014
|
})
|
2045
2015
|
})
|
2046
2016
|
);
|
2017
|
+
console.log("walletEntryPlugin init");
|
2047
2018
|
}
|
2048
2019
|
}, [options, evmSupportChainIds, accountContract]);
|
2049
2020
|
(0, import_react10.useEffect)(() => {
|
@@ -2052,6 +2023,7 @@ var ConnectProvider = ({
|
|
2052
2023
|
import_wallet.walletEntryPlugin.setWalletCore({
|
2053
2024
|
ethereum: smartAccount.provider
|
2054
2025
|
});
|
2026
|
+
console.log("walletEntryPlugin setWalletCore");
|
2055
2027
|
}
|
2056
2028
|
}, [smartAccount, options]);
|
2057
2029
|
(0, import_react10.useEffect)(() => {
|
@@ -2059,8 +2031,10 @@ var ConnectProvider = ({
|
|
2059
2031
|
if (((_a2 = options.walletOptions) == null ? void 0 : _a2.visible) !== false) {
|
2060
2032
|
if (evmAccount) {
|
2061
2033
|
import_wallet.walletEntryPlugin.walletEntryCreate();
|
2034
|
+
console.log("walletEntryPlugin walletEntryCreate");
|
2062
2035
|
} else {
|
2063
2036
|
import_wallet.walletEntryPlugin.walletEntryDestroy();
|
2037
|
+
console.log("walletEntryPlugin walletEntryDestroy");
|
2064
2038
|
}
|
2065
2039
|
}
|
2066
2040
|
}, [evmAccount, smartAccount, options]);
|
@@ -2112,10 +2086,9 @@ var ConnectProvider = ({
|
|
2112
2086
|
smartAccount,
|
2113
2087
|
getNetwork,
|
2114
2088
|
switchNetwork,
|
2115
|
-
sendBitcoin,
|
2089
|
+
sendBitcoin: sendBitcoin2,
|
2116
2090
|
accountContract,
|
2117
|
-
setAccountContract
|
2118
|
-
getSmartAccountInfo
|
2091
|
+
setAccountContract
|
2119
2092
|
},
|
2120
2093
|
children: [
|
2121
2094
|
children,
|
@@ -2130,8 +2103,8 @@ var useConnectProvider = () => {
|
|
2130
2103
|
return context;
|
2131
2104
|
};
|
2132
2105
|
|
2133
|
-
// src/
|
2134
|
-
var
|
2106
|
+
// src/core/btcWalletSelectorContext.tsx
|
2107
|
+
var import_react11 = __toESM(require("react"), 1);
|
2135
2108
|
|
2136
2109
|
// src/components/confirmBox/Modal.tsx
|
2137
2110
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
@@ -2185,22 +2158,15 @@ function ComfirmBox({ onClose, status = 1, fromChain = {
|
|
2185
2158
|
] });
|
2186
2159
|
}
|
2187
2160
|
|
2188
|
-
// src/
|
2189
|
-
var import_react11 = require("react");
|
2190
|
-
function InitContextHook() {
|
2191
|
-
const btcContext = useBtcWalletSelector();
|
2192
|
-
(0, import_react11.useEffect)(() => {
|
2193
|
-
window.btcContext = btcContext;
|
2194
|
-
}, [btcContext]);
|
2195
|
-
return null;
|
2196
|
-
}
|
2197
|
-
|
2198
|
-
// src/components/btcWalletSelectorContext.tsx
|
2161
|
+
// src/core/btcWalletSelectorContext.tsx
|
2199
2162
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
2200
|
-
var WalletSelectorContext =
|
2201
|
-
function BtcWalletSelectorContextProvider({
|
2202
|
-
|
2203
|
-
|
2163
|
+
var WalletSelectorContext = import_react11.default.createContext(null);
|
2164
|
+
function BtcWalletSelectorContextProvider({
|
2165
|
+
children,
|
2166
|
+
autoConnect = false
|
2167
|
+
}) {
|
2168
|
+
const [isProcessing, setIsProcessing] = (0, import_react11.useState)(false);
|
2169
|
+
const walletSelectorContextValue = (0, import_react11.useMemo)(() => {
|
2204
2170
|
const simpleFn = {};
|
2205
2171
|
return {
|
2206
2172
|
setIsProcessing,
|
@@ -2242,24 +2208,38 @@ function BtcWalletSelectorContextProvider({ children, autoConnect = false }) {
|
|
2242
2208
|
connectors: [new UnisatConnector()],
|
2243
2209
|
children: [
|
2244
2210
|
children,
|
2245
|
-
isProcessing && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
2246
|
-
|
2247
|
-
|
2248
|
-
|
2211
|
+
isProcessing && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
2212
|
+
ComfirmBox,
|
2213
|
+
{
|
2214
|
+
hash: "",
|
2215
|
+
status: 0,
|
2216
|
+
onClose: () => {
|
2217
|
+
setIsProcessing(false);
|
2218
|
+
}
|
2219
|
+
}
|
2220
|
+
),
|
2221
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(InitBtcWalletSelectorContext, {})
|
2249
2222
|
]
|
2250
2223
|
}
|
2251
2224
|
) });
|
2252
2225
|
}
|
2226
|
+
function InitBtcWalletSelectorContext() {
|
2227
|
+
const context = useBtcWalletSelector();
|
2228
|
+
(0, import_react11.useEffect)(() => {
|
2229
|
+
window.btcContext = context;
|
2230
|
+
}, [context]);
|
2231
|
+
return null;
|
2232
|
+
}
|
2253
2233
|
function useBtcWalletSelector() {
|
2254
2234
|
const { openConnectModal, openConnectModalAsync, disconnect, requestDirectAccount } = useConnectModal();
|
2255
|
-
const { accounts, sendBitcoin, getPublicKey, provider, signMessage, connector } = useBTCProvider();
|
2256
|
-
const publicKey = (0,
|
2257
|
-
const signMessageFn = (0,
|
2258
|
-
const connectorRef = (0,
|
2259
|
-
const providerRef = (0,
|
2260
|
-
const [updater, setUpdater] = (0,
|
2261
|
-
const context = (0,
|
2262
|
-
(0,
|
2235
|
+
const { accounts, sendBitcoin: sendBitcoin2, getPublicKey, provider, signMessage, connector } = useBTCProvider();
|
2236
|
+
const publicKey = (0, import_react11.useRef)(null);
|
2237
|
+
const signMessageFn = (0, import_react11.useRef)(null);
|
2238
|
+
const connectorRef = (0, import_react11.useRef)(null);
|
2239
|
+
const providerRef = (0, import_react11.useRef)(null);
|
2240
|
+
const [updater, setUpdater] = (0, import_react11.useState)(1);
|
2241
|
+
const context = (0, import_react11.useContext)(WalletSelectorContext);
|
2242
|
+
(0, import_react11.useEffect)(() => {
|
2263
2243
|
if (provider) {
|
2264
2244
|
getPublicKey().then((res) => {
|
2265
2245
|
publicKey.current = res;
|
@@ -2267,10 +2247,10 @@ function useBtcWalletSelector() {
|
|
2267
2247
|
providerRef.current = provider;
|
2268
2248
|
}
|
2269
2249
|
}, [provider, updater]);
|
2270
|
-
(0,
|
2250
|
+
(0, import_react11.useEffect)(() => {
|
2271
2251
|
signMessageFn.current = signMessage;
|
2272
2252
|
}, [signMessage]);
|
2273
|
-
(0,
|
2253
|
+
(0, import_react11.useEffect)(() => {
|
2274
2254
|
const fn = (account) => {
|
2275
2255
|
if (account) {
|
2276
2256
|
getPublicKey().then((res) => {
|
@@ -2304,7 +2284,7 @@ function useBtcWalletSelector() {
|
|
2304
2284
|
autoConnect: () => __async(this, null, function* () {
|
2305
2285
|
let times = 0;
|
2306
2286
|
while (!connectorRef.current) {
|
2307
|
-
yield
|
2287
|
+
yield delay(500);
|
2308
2288
|
if (times++ > 10) {
|
2309
2289
|
return null;
|
2310
2290
|
}
|
@@ -2321,7 +2301,7 @@ function useBtcWalletSelector() {
|
|
2321
2301
|
getPublicKey: () => __async(this, null, function* () {
|
2322
2302
|
let times = 0;
|
2323
2303
|
while (!publicKey.current) {
|
2324
|
-
yield
|
2304
|
+
yield delay(1e3);
|
2325
2305
|
if (times++ > 10) {
|
2326
2306
|
return null;
|
2327
2307
|
}
|
@@ -2337,28 +2317,24 @@ function useBtcWalletSelector() {
|
|
2337
2317
|
getBalance: () => __async(this, null, function* () {
|
2338
2318
|
let times = 0;
|
2339
2319
|
while (!providerRef.current) {
|
2340
|
-
yield
|
2320
|
+
yield delay(500);
|
2341
2321
|
if (times++ > 10) {
|
2342
2322
|
return null;
|
2343
2323
|
}
|
2344
2324
|
}
|
2345
2325
|
const { total } = yield providerRef.current.getBalance();
|
2346
2326
|
return total;
|
2347
|
-
})
|
2327
|
+
}),
|
2328
|
+
sendBitcoin: sendBitcoin2
|
2348
2329
|
};
|
2349
2330
|
}
|
2350
|
-
function sleep(time) {
|
2351
|
-
return new Promise(function(resolve) {
|
2352
|
-
setTimeout(resolve, time);
|
2353
|
-
});
|
2354
|
-
}
|
2355
2331
|
|
2356
|
-
// src/
|
2332
|
+
// src/core/setupBTCWallet.ts
|
2357
2333
|
var import_near_api_js = require("near-api-js");
|
2358
2334
|
var import_transactions = require("@near-js/transactions");
|
2359
2335
|
var import_key_pair = require("near-api-js/lib/utils/key_pair");
|
2360
2336
|
var import_transaction = require("near-api-js/lib/transaction");
|
2361
|
-
var
|
2337
|
+
var import_utils6 = require("@near-js/utils");
|
2362
2338
|
var import_bs58 = __toESM(require("bs58"), 1);
|
2363
2339
|
var import_js_sha256 = require("js-sha256");
|
2364
2340
|
|
@@ -2369,6 +2345,7 @@ var walletUrlConfig = {
|
|
2369
2345
|
mainnet: "https://wallet.satoshibridge.top"
|
2370
2346
|
};
|
2371
2347
|
function setupWalletButton(network, wallet, originalWallet) {
|
2348
|
+
console.log("setupWalletButton");
|
2372
2349
|
if (document.getElementById("satoshi-wallet-button")) {
|
2373
2350
|
return;
|
2374
2351
|
}
|
@@ -2445,7 +2422,8 @@ function createIframe({
|
|
2445
2422
|
zIndex: "100000",
|
2446
2423
|
boxShadow: "0 0 10px rgba(0, 0, 0, 0.1)",
|
2447
2424
|
borderRadius: "10px",
|
2448
|
-
display: "block"
|
2425
|
+
display: "block",
|
2426
|
+
border: "none"
|
2449
2427
|
}, iframeStyle));
|
2450
2428
|
document.body.appendChild(iframe);
|
2451
2429
|
return iframe;
|
@@ -2456,6 +2434,7 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
|
2456
2434
|
const accountId = (_a = yield wallet == null ? void 0 : wallet.getAccounts()) == null ? void 0 : _a[0].accountId;
|
2457
2435
|
const originalAccountId = originalWallet.account;
|
2458
2436
|
const originalPublicKey = yield originalWallet.getPublicKey();
|
2437
|
+
console.log({ accountId, originalAccountId, originalPublicKey });
|
2459
2438
|
const iframeSrc = new URL(iframe.src);
|
2460
2439
|
iframeSrc.searchParams.set("origin", window.location.origin);
|
2461
2440
|
accountId && iframeSrc.searchParams.set("accountId", accountId);
|
@@ -2468,8 +2447,10 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
|
2468
2447
|
return;
|
2469
2448
|
const { action, requestId, data } = event.data;
|
2470
2449
|
if (action === "signAndSendTransaction") {
|
2450
|
+
console.log("signAndSendTransaction message", event.data);
|
2471
2451
|
try {
|
2472
2452
|
const result = yield wallet.signAndSendTransaction(data);
|
2453
|
+
console.log("signAndSendTransaction result", result);
|
2473
2454
|
(_a2 = event.source) == null ? void 0 : _a2.postMessage(
|
2474
2455
|
{
|
2475
2456
|
requestId,
|
@@ -2479,6 +2460,7 @@ function setupButtonClickHandler(button, iframe, wallet, originalWallet) {
|
|
2479
2460
|
{ targetOrigin: event.origin }
|
2480
2461
|
);
|
2481
2462
|
} catch (error) {
|
2463
|
+
console.error("signAndSendTransaction error", error);
|
2482
2464
|
(_b = event.source) == null ? void 0 : _b.postMessage(
|
2483
2465
|
{
|
2484
2466
|
requestId,
|
@@ -2499,25 +2481,117 @@ function removeWalletButton() {
|
|
2499
2481
|
iframe == null ? void 0 : iframe.remove();
|
2500
2482
|
}
|
2501
2483
|
|
2502
|
-
// src/
|
2503
|
-
var
|
2504
|
-
var config = {
|
2484
|
+
// src/config.ts
|
2485
|
+
var walletConfig = {
|
2505
2486
|
dev: {
|
2506
|
-
base_url: "https://api.dev.satoshibridge.top
|
2487
|
+
base_url: "https://api.dev.satoshibridge.top",
|
2507
2488
|
token: "nbtc1-nsp.testnet",
|
2508
|
-
contractId: "dev1-nsp.testnet"
|
2489
|
+
contractId: "dev1-nsp.testnet",
|
2490
|
+
walletUrl: "https://wallet-dev.satoshibridge.top"
|
2509
2491
|
},
|
2510
2492
|
testnet: {
|
2511
|
-
base_url: "https://api.testnet.satoshibridge.top
|
2493
|
+
base_url: "https://api.testnet.satoshibridge.top",
|
2512
2494
|
token: "nbtc2-nsp.testnet",
|
2513
|
-
contractId: "dev2-nsp.testnet"
|
2495
|
+
contractId: "dev2-nsp.testnet",
|
2496
|
+
walletUrl: "https://wallet-test.satoshibridge.top"
|
2514
2497
|
},
|
2515
2498
|
mainnet: {
|
2516
|
-
base_url: "https://api.mainnet.satoshibridge.top
|
2499
|
+
base_url: "https://api.mainnet.satoshibridge.top",
|
2517
2500
|
token: "",
|
2518
|
-
contractId: ""
|
2501
|
+
contractId: "",
|
2502
|
+
walletUrl: "https://wallet.satoshibridge.top"
|
2519
2503
|
}
|
2520
2504
|
};
|
2505
|
+
var nearRpcUrls = {
|
2506
|
+
mainnet: [
|
2507
|
+
"https://near.lava.build",
|
2508
|
+
"https://rpc.mainnet.near.org",
|
2509
|
+
"https://free.rpc.fastnear.com",
|
2510
|
+
"https://near.drpc.org"
|
2511
|
+
],
|
2512
|
+
testnet: [
|
2513
|
+
"https://near-testnet.lava.build",
|
2514
|
+
"https://rpc.testnet.near.org",
|
2515
|
+
"https://near-testnet.drpc.org"
|
2516
|
+
]
|
2517
|
+
};
|
2518
|
+
var btcRpcUrls = {
|
2519
|
+
mainnet: "https://mempool.space/api",
|
2520
|
+
testnet: "https://mempool.space/testnet/api"
|
2521
|
+
};
|
2522
|
+
|
2523
|
+
// src/utils/request.ts
|
2524
|
+
var cache = /* @__PURE__ */ new Map();
|
2525
|
+
var defaultCacheTimeout = 3e3;
|
2526
|
+
function request(url, options) {
|
2527
|
+
return __async(this, null, function* () {
|
2528
|
+
var _a;
|
2529
|
+
const defaultHeaders = {
|
2530
|
+
"Content-Type": "application/json"
|
2531
|
+
};
|
2532
|
+
const cacheTimeout = (options == null ? void 0 : options.cacheTimeout) || defaultCacheTimeout;
|
2533
|
+
const headers = __spreadValues(__spreadValues({}, defaultHeaders), options == null ? void 0 : options.headers);
|
2534
|
+
let body = options == null ? void 0 : options.body;
|
2535
|
+
if (headers["Content-Type"] === "application/json" && body && typeof body !== "string") {
|
2536
|
+
body = JSON.stringify(body);
|
2537
|
+
}
|
2538
|
+
const method = (options == null ? void 0 : options.method) || "GET";
|
2539
|
+
const cacheKey = method.toUpperCase() === "GET" ? url : null;
|
2540
|
+
if (cacheKey) {
|
2541
|
+
const cached = cache.get(cacheKey);
|
2542
|
+
const isCacheValid = cached && Date.now() - cached.timestamp < cacheTimeout;
|
2543
|
+
if (isCacheValid) {
|
2544
|
+
return Promise.resolve(cached.data);
|
2545
|
+
}
|
2546
|
+
}
|
2547
|
+
const newOptions = __spreadProps(__spreadValues({}, options), {
|
2548
|
+
headers,
|
2549
|
+
body,
|
2550
|
+
method
|
2551
|
+
});
|
2552
|
+
const retryCount = (_a = options == null ? void 0 : options.retryCount) != null ? _a : 1;
|
2553
|
+
const controller = new AbortController();
|
2554
|
+
const timeout = (options == null ? void 0 : options.timeout) || 2e4;
|
2555
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
2556
|
+
try {
|
2557
|
+
const res = yield fetch(url, __spreadProps(__spreadValues({}, newOptions), { signal: controller.signal })).finally(
|
2558
|
+
() => clearTimeout(timeoutId)
|
2559
|
+
);
|
2560
|
+
if (!res.ok)
|
2561
|
+
throw new Error(res.statusText);
|
2562
|
+
const data = yield res.json();
|
2563
|
+
if (cacheKey) {
|
2564
|
+
cache.set(cacheKey, { timestamp: Date.now(), data });
|
2565
|
+
setTimeout(() => {
|
2566
|
+
cache.delete(cacheKey);
|
2567
|
+
}, cacheTimeout);
|
2568
|
+
}
|
2569
|
+
if ((options == null ? void 0 : options.shouldStopPolling) && options.shouldStopPolling(data)) {
|
2570
|
+
return data;
|
2571
|
+
}
|
2572
|
+
return data;
|
2573
|
+
} catch (err) {
|
2574
|
+
console.error(err);
|
2575
|
+
if (retryCount > 0) {
|
2576
|
+
console.log(`Retrying... attempts left: ${retryCount}`);
|
2577
|
+
return request(url, __spreadProps(__spreadValues({}, options), { retryCount: retryCount - 1 }));
|
2578
|
+
} else if ((options == null ? void 0 : options.pollingInterval) && (options == null ? void 0 : options.maxPollingAttempts)) {
|
2579
|
+
if (options.maxPollingAttempts > 0) {
|
2580
|
+
console.log(`Polling... attempts left: ${options.maxPollingAttempts}`);
|
2581
|
+
yield new Promise((resolve) => setTimeout(resolve, options.pollingInterval));
|
2582
|
+
return request(url, __spreadProps(__spreadValues({}, options), {
|
2583
|
+
maxPollingAttempts: options.maxPollingAttempts - 1,
|
2584
|
+
retryCount
|
2585
|
+
}));
|
2586
|
+
}
|
2587
|
+
}
|
2588
|
+
return Promise.reject(err);
|
2589
|
+
}
|
2590
|
+
});
|
2591
|
+
}
|
2592
|
+
|
2593
|
+
// src/core/setupBTCWallet.ts
|
2594
|
+
var { transfer, functionCall } = import_transactions.actionCreators;
|
2521
2595
|
var state = {
|
2522
2596
|
saveAccount(account) {
|
2523
2597
|
window.localStorage.setItem("btc-wallet-account", account);
|
@@ -2575,7 +2649,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2575
2649
|
signAndSendTransaction,
|
2576
2650
|
signAndSendTransactions
|
2577
2651
|
};
|
2578
|
-
const currentConfig = "isDev" in metadata && metadata.isDev ?
|
2652
|
+
const currentConfig = "isDev" in metadata && metadata.isDev ? walletConfig.dev : walletConfig[options.network.networkId];
|
2579
2653
|
const walletNetwork = "isDev" in metadata && metadata.isDev ? "dev" : options.network.networkId;
|
2580
2654
|
initWalletButton(walletNetwork, wallet);
|
2581
2655
|
if (!inter) {
|
@@ -2747,13 +2821,14 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2747
2821
|
transaction.receiverId,
|
2748
2822
|
BigInt(nearNonceNumber) + BigInt(index),
|
2749
2823
|
newActions,
|
2750
|
-
(0,
|
2824
|
+
(0, import_utils6.baseDecode)(header.hash)
|
2751
2825
|
);
|
2752
2826
|
const txBytes = (0, import_transaction.encodeTransaction)(_transaction);
|
2753
2827
|
const txHex = Array.from(
|
2754
2828
|
txBytes,
|
2755
2829
|
(byte) => ("0" + (byte & 255).toString(16)).slice(-2)
|
2756
2830
|
).join("");
|
2831
|
+
console.log("txHex:", txHex);
|
2757
2832
|
const hash = import_bs58.default.encode(new Uint8Array(import_js_sha256.sha256.array(txBytes)));
|
2758
2833
|
return { txBytes, txHex, hash };
|
2759
2834
|
});
|
@@ -2790,6 +2865,7 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2790
2865
|
});
|
2791
2866
|
if (result.result_code === 0) {
|
2792
2867
|
const hash = newTransactions.map((t) => t.hash);
|
2868
|
+
console.log("txHash:", hash);
|
2793
2869
|
const result2 = yield pollTransactionStatuses(options.network.networkId, hash);
|
2794
2870
|
return result2;
|
2795
2871
|
} else {
|
@@ -2802,6 +2878,10 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2802
2878
|
const checkAndSetupWalletButton = () => {
|
2803
2879
|
const accountId = state.getAccount();
|
2804
2880
|
const btcContext = window.btcContext;
|
2881
|
+
console.log("checkAndSetupWalletButton:", {
|
2882
|
+
nearAccountId: accountId,
|
2883
|
+
btcAccountId: btcContext.account
|
2884
|
+
});
|
2805
2885
|
if (accountId && btcContext.account) {
|
2806
2886
|
setupWalletButton(network, wallet2, btcContext);
|
2807
2887
|
} else {
|
@@ -2818,29 +2898,16 @@ var BTCWallet = (_0) => __async(void 0, [_0], function* ({
|
|
2818
2898
|
return wallet;
|
2819
2899
|
});
|
2820
2900
|
function getNonceFromApi(url, accountId) {
|
2821
|
-
return
|
2822
|
-
method: "GET",
|
2823
|
-
headers: {
|
2824
|
-
"Content-Type": "application/json"
|
2825
|
-
}
|
2826
|
-
}).then((res) => res.json());
|
2901
|
+
return request(`${url}/v1/nonce?csna=${accountId}`);
|
2827
2902
|
}
|
2828
2903
|
function getNearNonceFromApi(url, accountId) {
|
2829
|
-
return
|
2830
|
-
method: "GET",
|
2831
|
-
headers: {
|
2832
|
-
"Content-Type": "application/json"
|
2833
|
-
}
|
2834
|
-
}).then((res) => res.json());
|
2904
|
+
return request(`${url}/v1/nonceNear?csna=${accountId}`);
|
2835
2905
|
}
|
2836
2906
|
function uploadBTCTx(url, data) {
|
2837
|
-
return
|
2907
|
+
return request(`${url}/v1/receiveTransaction`, {
|
2838
2908
|
method: "POST",
|
2839
|
-
|
2840
|
-
|
2841
|
-
},
|
2842
|
-
body: JSON.stringify(data)
|
2843
|
-
}).then((res) => res.json());
|
2909
|
+
body: data
|
2910
|
+
});
|
2844
2911
|
}
|
2845
2912
|
function setupBTCWallet({
|
2846
2913
|
iconUrl = "https://assets.deltatrade.ai/assets/chain/btc.svg",
|
@@ -2877,23 +2944,10 @@ function toHex(originalString) {
|
|
2877
2944
|
hexString = hexString.replace(/(^0+)/g, "");
|
2878
2945
|
return hexString;
|
2879
2946
|
}
|
2880
|
-
var rcpUrls = {
|
2881
|
-
mainnet: [
|
2882
|
-
"https://near.lava.build",
|
2883
|
-
"https://rpc.mainnet.near.org",
|
2884
|
-
"https://free.rpc.fastnear.com",
|
2885
|
-
"https://near.drpc.org"
|
2886
|
-
],
|
2887
|
-
testnet: [
|
2888
|
-
"https://near-testnet.lava.build",
|
2889
|
-
"https://rpc.testnet.near.org",
|
2890
|
-
"https://near-testnet.drpc.org"
|
2891
|
-
]
|
2892
|
-
};
|
2893
2947
|
function pollTransactionStatuses(network, hashes) {
|
2894
2948
|
return __async(this, null, function* () {
|
2895
2949
|
const provider = new import_near_api_js.providers.FailoverRpcProvider(
|
2896
|
-
Object.values(
|
2950
|
+
Object.values(nearRpcUrls[network]).map(
|
2897
2951
|
(url) => new import_near_api_js.providers.JsonRpcProvider({ url })
|
2898
2952
|
)
|
2899
2953
|
);
|
@@ -2905,14 +2959,17 @@ function pollTransactionStatuses(network, hashes) {
|
|
2905
2959
|
try {
|
2906
2960
|
const result = yield provider.txStatus(hash, "unused", "FINAL");
|
2907
2961
|
if (result && result.status) {
|
2962
|
+
console.log(`Transaction ${hash} result:`, result);
|
2908
2963
|
return result;
|
2909
2964
|
}
|
2910
2965
|
} catch (error) {
|
2966
|
+
console.error(`Failed to fetch transaction status for ${hash}: ${error.message}`);
|
2911
2967
|
}
|
2912
2968
|
if (attempt === maxAttempts) {
|
2913
2969
|
throw new Error(`Transaction not found after max attempts: ${hash}`);
|
2914
2970
|
}
|
2915
2971
|
yield delay(1e4);
|
2972
|
+
console.log(`RPC request failed for ${hash}, retrying ${maxAttempts - attempt} more times`);
|
2916
2973
|
}
|
2917
2974
|
});
|
2918
2975
|
const results = yield Promise.all(hashes.map((hash) => pollStatus(hash)));
|
@@ -2920,9 +2977,119 @@ function pollTransactionStatuses(network, hashes) {
|
|
2920
2977
|
});
|
2921
2978
|
}
|
2922
2979
|
|
2980
|
+
// src/core/bridgeSupplyUtils.ts
|
2981
|
+
var import_near_api_js2 = require("near-api-js");
|
2982
|
+
var import_big = __toESM(require("big.js"), 1);
|
2983
|
+
function nearViewMethod(contractId, methodName, args, network) {
|
2984
|
+
return __async(this, null, function* () {
|
2985
|
+
const nearProvider = new import_near_api_js2.providers.FailoverRpcProvider(
|
2986
|
+
nearRpcUrls[network].map(
|
2987
|
+
(url) => new import_near_api_js2.providers.JsonRpcProvider({ url })
|
2988
|
+
)
|
2989
|
+
);
|
2990
|
+
const res = yield nearProvider.query({
|
2991
|
+
request_type: "call_function",
|
2992
|
+
account_id: contractId,
|
2993
|
+
method_name: methodName,
|
2994
|
+
args_base64: Buffer.from(JSON.stringify(args)).toString("base64"),
|
2995
|
+
finality: "optimistic"
|
2996
|
+
});
|
2997
|
+
return JSON.parse(Buffer.from(res.result).toString());
|
2998
|
+
});
|
2999
|
+
}
|
3000
|
+
function getDepositAddress(btcPublicKey, contractId, network) {
|
3001
|
+
return __async(this, null, function* () {
|
3002
|
+
const res = yield nearViewMethod(
|
3003
|
+
contractId,
|
3004
|
+
"get_user_dapp_deposit_address",
|
3005
|
+
{
|
3006
|
+
deposit_type: {
|
3007
|
+
BtcPublicKey: { btc_public_key: btcPublicKey, dapp_operation: "Burrowland->Supply" }
|
3008
|
+
}
|
3009
|
+
},
|
3010
|
+
network
|
3011
|
+
);
|
3012
|
+
return res;
|
3013
|
+
});
|
3014
|
+
}
|
3015
|
+
function getGasPrice(network) {
|
3016
|
+
return __async(this, null, function* () {
|
3017
|
+
const defaultFeeRate = 100;
|
3018
|
+
try {
|
3019
|
+
const btcRpcUrl = btcRpcUrls[network];
|
3020
|
+
const res = yield fetch(`${btcRpcUrl}/v1/fees/recommended`).then((res2) => res2.json());
|
3021
|
+
const feeRate = res.fastestFee;
|
3022
|
+
return feeRate || defaultFeeRate;
|
3023
|
+
} catch (error) {
|
3024
|
+
return defaultFeeRate;
|
3025
|
+
}
|
3026
|
+
});
|
3027
|
+
}
|
3028
|
+
function sendBitcoin(btcProvider, address, amount, feeRate) {
|
3029
|
+
return __async(this, null, function* () {
|
3030
|
+
const satoshis = new import_big.default(amount).mul(__pow(10, 8)).toNumber();
|
3031
|
+
const txHash = yield btcProvider.sendBitcoin(address, satoshis, { feeRate });
|
3032
|
+
return txHash;
|
3033
|
+
});
|
3034
|
+
}
|
3035
|
+
function receiveDepositMsg(_0, _1) {
|
3036
|
+
return __async(this, arguments, function* (baseUrl, {
|
3037
|
+
btcPublicKey,
|
3038
|
+
txHash,
|
3039
|
+
depositType = 1
|
3040
|
+
}) {
|
3041
|
+
const res = yield request(`${baseUrl}/v1/receiveDepositMsg`, {
|
3042
|
+
method: "POST",
|
3043
|
+
body: { btcPublicKey, txHash, depositType }
|
3044
|
+
});
|
3045
|
+
return res;
|
3046
|
+
});
|
3047
|
+
}
|
3048
|
+
function checkTransactionStatus(baseUrl, txHash) {
|
3049
|
+
return __async(this, null, function* () {
|
3050
|
+
const res = yield request(`${baseUrl}/v1/bridgeFromTx?fromTxHash=${txHash}`, {
|
3051
|
+
timeout: 6e4,
|
3052
|
+
pollingInterval: 5e3,
|
3053
|
+
maxPollingAttempts: 10,
|
3054
|
+
shouldStopPolling: (res2) => res2.result_code === 0
|
3055
|
+
});
|
3056
|
+
return res;
|
3057
|
+
});
|
3058
|
+
}
|
3059
|
+
function executeBurrowSupply(_0) {
|
3060
|
+
return __async(this, arguments, function* ({
|
3061
|
+
amount,
|
3062
|
+
feeRate,
|
3063
|
+
environment = "mainnet"
|
3064
|
+
}) {
|
3065
|
+
try {
|
3066
|
+
if (typeof window === "undefined" || !window.btcContext) {
|
3067
|
+
throw new Error("BTC Provider is not initialized.");
|
3068
|
+
}
|
3069
|
+
const btcProvider = window.btcContext;
|
3070
|
+
const network = environment === "dev" ? "testnet" : environment;
|
3071
|
+
const config = walletConfig[environment];
|
3072
|
+
const btcPublicKey = yield btcProvider.getPublicKey();
|
3073
|
+
if (!btcPublicKey) {
|
3074
|
+
throw new Error("BTC Public Key is not available.");
|
3075
|
+
}
|
3076
|
+
const address = yield getDepositAddress(btcPublicKey, config.contractId, network);
|
3077
|
+
const _feeRate = feeRate || (yield getGasPrice(network));
|
3078
|
+
console.log("feeRate", _feeRate);
|
3079
|
+
const txHash = yield sendBitcoin(btcProvider, address, amount, _feeRate);
|
3080
|
+
const receiveDepositMsgRes = yield receiveDepositMsg(config.base_url, { btcPublicKey, txHash });
|
3081
|
+
console.log("receiveDepositMsg resp:", receiveDepositMsgRes);
|
3082
|
+
const checkTransactionStatusRes = yield checkTransactionStatus(config.base_url, txHash);
|
3083
|
+
console.log("checkTransactionStatus resp:", checkTransactionStatusRes);
|
3084
|
+
} catch (error) {
|
3085
|
+
console.error("Error executing Bridge+BurrowSupply:", error);
|
3086
|
+
}
|
3087
|
+
});
|
3088
|
+
}
|
3089
|
+
|
2923
3090
|
// src/index.ts
|
2924
3091
|
var getVersion = () => {
|
2925
|
-
return "0.2.
|
3092
|
+
return "0.2.7";
|
2926
3093
|
};
|
2927
3094
|
if (typeof window !== "undefined") {
|
2928
3095
|
window.__PARTICLE_BTC_CONNECT_VERSION = getVersion();
|