@0xsquid/react-hooks 8.10.0 → 8.10.1-beta-bitcoin-coralv2.0

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.
Files changed (25) hide show
  1. package/dist/core/connectors/bitcoin/wallets/keplr.d.ts +3 -0
  2. package/dist/core/connectors/bitcoin/wallets/phantom.d.ts +3 -1
  3. package/dist/core/connectors/bitcoin/wallets/unisat.d.ts +15 -0
  4. package/dist/core/types/bitcoin.d.ts +3 -0
  5. package/dist/{index-Dzir2lUQ.js → index-Cw1rn5LQ.js} +124 -46
  6. package/dist/index-Cw1rn5LQ.js.map +1 -0
  7. package/dist/{index-BlB3yIoX.js → index-Dykfm_Bt.js} +124 -46
  8. package/dist/index-Dykfm_Bt.js.map +1 -0
  9. package/dist/{index.es-BPXYaraD.js → index.es-DQyW9YL5.js} +2 -2
  10. package/dist/{index.es-BPXYaraD.js.map → index.es-DQyW9YL5.js.map} +1 -1
  11. package/dist/{index.es-DwtZr7bN.js → index.es-DspxF1i7.js} +2 -2
  12. package/dist/{index.es-DwtZr7bN.js.map → index.es-DspxF1i7.js.map} +1 -1
  13. package/dist/index.esm.js +1 -1
  14. package/dist/index.js +1 -1
  15. package/dist/{secretService-ICina23f.js → secretService-6H3XQVCV.js} +2 -2
  16. package/dist/{secretService-ICina23f.js.map → secretService-6H3XQVCV.js.map} +1 -1
  17. package/dist/{secretService-eiBnD7dI.js → secretService-C_gWAduF.js} +2 -2
  18. package/dist/{secretService-eiBnD7dI.js.map → secretService-C_gWAduF.js.map} +1 -1
  19. package/dist/{stellarService.client-VOmCOPzL.js → stellarService.client-BdMbbog4.js} +2 -2
  20. package/dist/{stellarService.client-VOmCOPzL.js.map → stellarService.client-BdMbbog4.js.map} +1 -1
  21. package/dist/{stellarService.client-Bjc92sC_.js → stellarService.client-CElL9N4g.js} +2 -2
  22. package/dist/{stellarService.client-Bjc92sC_.js.map → stellarService.client-CElL9N4g.js.map} +1 -1
  23. package/package.json +1 -1
  24. package/dist/index-BlB3yIoX.js.map +0 -1
  25. package/dist/index-Dzir2lUQ.js.map +0 -1
@@ -8,4 +8,7 @@ export declare class KeplrConnector implements BitcoinConnector {
8
8
  requestAccount(): Promise<{
9
9
  address: string;
10
10
  }>;
11
+ signPsbt(psbtHex: string): Promise<{
12
+ txHash: string;
13
+ }>;
11
14
  }
@@ -22,6 +22,8 @@ export declare class PhantomConnector implements BitcoinConnector {
22
22
  sendBTC(to: string, amount: number): Promise<{
23
23
  txHash: string;
24
24
  }>;
25
- private signPsbt;
25
+ signPsbt(psbtHex: string): Promise<{
26
+ txHash: string;
27
+ }>;
26
28
  }
27
29
  export {};
@@ -1,7 +1,19 @@
1
1
  import { BitcoinConnector } from "../../../../core/types/bitcoin";
2
+ interface UnisatSignPsbtOptions {
3
+ autoFinalized?: boolean;
4
+ toSignInputs?: Array<{
5
+ index: number;
6
+ address?: string;
7
+ publicKey?: string;
8
+ sighashTypes?: number[];
9
+ disableTweakSigner?: boolean;
10
+ }>;
11
+ }
2
12
  interface UnisatProvider {
3
13
  sendBitcoin: (to: string, amount: number) => Promise<string>;
4
14
  requestAccounts: () => Promise<string[]>;
15
+ signPsbt: (psbtHex: string, options?: UnisatSignPsbtOptions) => Promise<string>;
16
+ pushPsbt: (psbtHex: string) => Promise<string>;
5
17
  }
6
18
  export declare class UnisatConnector implements BitcoinConnector {
7
19
  get getProvider(): UnisatProvider;
@@ -11,5 +23,8 @@ export declare class UnisatConnector implements BitcoinConnector {
11
23
  requestAccount(): Promise<{
12
24
  address: string;
13
25
  }>;
26
+ signPsbt(psbtHex: string): Promise<{
27
+ txHash: string;
28
+ }>;
14
29
  }
15
30
  export {};
@@ -2,6 +2,9 @@ export interface BitcoinConnector {
2
2
  sendBTC(to: string, amount: number): Promise<{
3
3
  txHash: string;
4
4
  }>;
5
+ signPsbt(psbtHex: string): Promise<{
6
+ txHash: string;
7
+ }>;
5
8
  requestAccount(): Promise<{
6
9
  address: string;
7
10
  }>;
@@ -4764,6 +4764,25 @@ class KeplrConnector {
4764
4764
  address: account,
4765
4765
  };
4766
4766
  }
4767
+ async signPsbt(psbtHex) {
4768
+ // Keplr follows the UniSat-style Bitcoin provider API: `signPsbt` signs and,
4769
+ // with `autoFinalized` (the default), finalizes every input, returning the
4770
+ // signed PSBT as a hex string.
4771
+ // https://docs.keplr.app/api/bitcoin
4772
+ const signedPsbtHex = await this.getProvider.signPsbt(psbtHex, {
4773
+ autoFinalized: true,
4774
+ });
4775
+ // Keplr only exposes `pushTx`, so extract the finalized raw transaction from
4776
+ // the signed PSBT before broadcasting it.
4777
+ const rawTxHex = bitcoin__namespace.Psbt.fromHex(signedPsbtHex)
4778
+ .extractTransaction()
4779
+ .toHex();
4780
+ const txHash = await this.getProvider.pushTx(rawTxHex);
4781
+ if (!txHash) {
4782
+ throw new BitcoinConnectorTransactionFailedError();
4783
+ }
4784
+ return { txHash };
4785
+ }
4767
4786
  }
4768
4787
 
4769
4788
  bitcoin__namespace.initEccLib(ecc__namespace);
@@ -4878,10 +4897,8 @@ class PhantomConnector {
4878
4897
  async sendBTC(to, amount) {
4879
4898
  const { address } = await this.requestAccount();
4880
4899
  const { psbtHex } = await createSendBtcPsbt(address, to, amount);
4881
- const { txId } = await this.signPsbt(psbtHex);
4882
- if (!txId)
4883
- throw new BitcoinConnectorTransactionFailedError();
4884
- return { txHash: txId };
4900
+ const { txHash } = await this.signPsbt(psbtHex);
4901
+ return { txHash };
4885
4902
  }
4886
4903
  async signPsbt(psbtHex) {
4887
4904
  const { address: paymentAddress } = await this.requestAccount();
@@ -4902,8 +4919,10 @@ class PhantomConnector {
4902
4919
  const signedPsbt = bitcoin__namespace.Psbt.fromBuffer(signedPsbtBytes);
4903
4920
  signedPsbt.finalizeAllInputs();
4904
4921
  const tx = signedPsbt.extractTransaction();
4905
- const txId = await broadcastTx(tx.toHex());
4906
- return { txId };
4922
+ const txHash = await broadcastTx(tx.toHex());
4923
+ if (!txHash)
4924
+ throw new BitcoinConnectorTransactionFailedError();
4925
+ return { txHash };
4907
4926
  }
4908
4927
  }
4909
4928
 
@@ -4932,6 +4951,21 @@ class UnisatConnector {
4932
4951
  address: account,
4933
4952
  };
4934
4953
  }
4954
+ async signPsbt(psbtHex) {
4955
+ // UniSat signs and, with `autoFinalized` (the default), finalizes every
4956
+ // input, returning the signed PSBT as a hex string.
4957
+ // https://docs.unisat.io/dev/unisat-developer-center/unisat-wallet/api-list
4958
+ const signedPsbtHex = await this.getProvider.signPsbt(psbtHex, {
4959
+ autoFinalized: true,
4960
+ });
4961
+ // `pushPsbt` extracts the finalized transaction from the signed PSBT and
4962
+ // broadcasts it, returning the transaction id.
4963
+ const txHash = await this.getProvider.pushPsbt(signedPsbtHex);
4964
+ if (!txHash) {
4965
+ throw new BitcoinConnectorTransactionFailedError();
4966
+ }
4967
+ return { txHash };
4968
+ }
4935
4969
  }
4936
4970
 
4937
4971
  var XrplTransactionType;
@@ -23605,7 +23639,7 @@ const filterViewableTokens = (tokens, config, direction) => {
23605
23639
  };
23606
23640
  const getSecretNetworkBalances = async (chainData, cosmosAddress, squidTokens, keplrTypeWallet) => {
23607
23641
  const squidSecretTokens = squidTokens.filter((t) => t.chainId === CHAIN_IDS.SECRET);
23608
- const { fetchAllSecretBalances } = await Promise.resolve().then(function () { return require('./secretService-ICina23f.js'); });
23642
+ const { fetchAllSecretBalances } = await Promise.resolve().then(function () { return require('./secretService-6H3XQVCV.js'); });
23609
23643
  return fetchAllSecretBalances(chainData, cosmosAddress, squidSecretTokens, keplrTypeWallet);
23610
23644
  };
23611
23645
  function getTokenAssetsKey(token) {
@@ -27279,7 +27313,7 @@ function useStellarWallets() {
27279
27313
  try {
27280
27314
  const { allowAllModules: initializeAllModules } = await import('@creit.tech/stellar-wallets-kit');
27281
27315
  const { LedgerModule } = await import('@creit.tech/stellar-wallets-kit/modules/ledger.module.mjs');
27282
- const { formatStellarWallet } = await Promise.resolve().then(function () { return require('./stellarService.client-Bjc92sC_.js'); });
27316
+ const { formatStellarWallet } = await Promise.resolve().then(function () { return require('./stellarService.client-CElL9N4g.js'); });
27283
27317
  const modules = [...initializeAllModules(), new LedgerModule()];
27284
27318
  const promises = modules.map(async (module) => {
27285
27319
  const isAvailable = await module.isAvailable();
@@ -30738,7 +30772,7 @@ function hederaWalletConnect(parameters) {
30738
30772
  const optionalChains = config.chains.map((x) => x.id);
30739
30773
  if (!optionalChains.length)
30740
30774
  return;
30741
- const { EthereumProvider } = await Promise.resolve().then(function () { return require('./index.es-BPXYaraD.js'); });
30775
+ const { EthereumProvider } = await Promise.resolve().then(function () { return require('./index.es-DQyW9YL5.js'); });
30742
30776
  const rawProvider = await EthereumProvider.init({
30743
30777
  ...restParameters,
30744
30778
  disableProviderPing: true,
@@ -37465,47 +37499,91 @@ const useExecuteTransaction = (squidRoute) => {
37465
37499
  }
37466
37500
  });
37467
37501
  const swapMutationBitcoin = reactQuery.useMutation(async ({ id, route }) => {
37468
- const { depositAddress, amount: sendAmount, statusTrackingId, } = useDepositAddressStore.getState().deposit ?? {};
37469
- if (!depositAddress) {
37470
- throw new Error(`Invalid deposit address: ${depositAddress}`);
37471
- }
37472
- if (!sendAmount) {
37473
- throw new Error(`Invalid send amount: ${sendAmount}`);
37502
+ console.log("Validating route", {
37503
+ bitcoinSigner,
37504
+ route,
37505
+ });
37506
+ if (!bitcoinSigner || !route?.transactionRequest) {
37507
+ throw new Error("Need all parameters");
37474
37508
  }
37475
- const allParamsValid = route && bitcoinSigner && depositAddress && sendAmount;
37476
- await changeNetworkIfNeeded.mutateAsync();
37477
- if (allParamsValid) {
37478
- dispatchSignatureRequestEvent(route);
37479
- const { txHash } = await bitcoinSigner.sendBTC(depositAddress, Number(sendAmount));
37480
- if (txHash) {
37481
- resetQueriesAfterTxSigned();
37509
+ switch (route.transactionRequest.type) {
37510
+ case squidTypes.SquidDataType.ChainflipDepositAddress: {
37511
+ const { depositAddress, amount: sendAmount, statusTrackingId, } = useDepositAddressStore.getState().deposit ?? {};
37512
+ const allParamsValid = route && bitcoinSigner && depositAddress && sendAmount;
37513
+ if (!allParamsValid) {
37514
+ throw new Error("Need all parameters");
37515
+ }
37516
+ await changeNetworkIfNeeded.mutateAsync();
37517
+ dispatchSignatureRequestEvent(route);
37518
+ const { txHash } = await bitcoinSigner.sendBTC(depositAddress, Number(sendAmount));
37519
+ if (txHash) {
37520
+ resetQueriesAfterTxSigned();
37521
+ }
37522
+ // Dispatch event so it can be listened from outside the widget
37523
+ WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
37524
+ if (route.transactionRequest) {
37525
+ const txParams = setTransactionState({
37526
+ route,
37527
+ txHash,
37528
+ // When bridging from Bitcoin we need to send the chainflipId to the status endpoint
37529
+ // instead of the Bitcoin transaction hash
37530
+ transactionIdForStatus: statusTrackingId,
37531
+ userAddress: sourceUserAddress,
37532
+ status: exports.TransactionStatus.INITIAL_LOADING,
37533
+ sourceStatus: exports.TransactionStatus.ONGOING,
37534
+ axelarUrl: undefined,
37535
+ id,
37536
+ });
37537
+ if (txParams) {
37538
+ addSwapTransaction({
37539
+ ...txParams,
37540
+ params: route.params,
37541
+ estimate: route.estimate,
37542
+ });
37543
+ }
37544
+ }
37545
+ break;
37482
37546
  }
37483
- // Dispatch event so it can be listened from outside the widget
37484
- WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
37485
- if (route.transactionRequest) {
37486
- const txParams = setTransactionState({
37487
- route,
37488
- txHash,
37489
- // When bridging from Bitcoin we need to send the chainflipId to the status endpoint
37490
- // instead of the Bitcoin transaction hash
37491
- transactionIdForStatus: statusTrackingId,
37492
- userAddress: sourceUserAddress,
37493
- status: exports.TransactionStatus.INITIAL_LOADING,
37494
- sourceStatus: exports.TransactionStatus.ONGOING,
37495
- axelarUrl: undefined,
37496
- id,
37497
- });
37498
- if (txParams) {
37499
- addSwapTransaction({
37500
- ...txParams,
37501
- params: route.params,
37502
- estimate: route.estimate,
37547
+ case squidTypes.SquidDataType.DepositAddressCalldata: {
37548
+ console.log(`Route type: ${route.transactionRequest?.type}`);
37549
+ if (!isOnChainTxData(route.transactionRequest)) {
37550
+ console.log("Invalid route data", route.transactionRequest);
37551
+ throw new Error("Invalid route data");
37552
+ }
37553
+ const { data: transactionHex } = route.transactionRequest;
37554
+ await changeNetworkIfNeeded.mutateAsync();
37555
+ dispatchSignatureRequestEvent(route);
37556
+ console.log("Signing psbt", { transactionHex });
37557
+ const { txHash } = await bitcoinSigner.signPsbt(transactionHex);
37558
+ console.log("Signed psbt", { txHash });
37559
+ if (txHash) {
37560
+ resetQueriesAfterTxSigned();
37561
+ }
37562
+ // Dispatch event so it can be listened from outside the widget
37563
+ WidgetEvents.getInstance().dispatchSwapExecuteCall(route, txHash);
37564
+ if (route.transactionRequest) {
37565
+ const txParams = setTransactionState({
37566
+ route,
37567
+ txHash,
37568
+ userAddress: sourceUserAddress,
37569
+ status: exports.TransactionStatus.INITIAL_LOADING,
37570
+ sourceStatus: exports.TransactionStatus.ONGOING,
37571
+ axelarUrl: undefined,
37572
+ id,
37503
37573
  });
37574
+ if (txParams) {
37575
+ addSwapTransaction({
37576
+ ...txParams,
37577
+ params: route.params,
37578
+ estimate: route.estimate,
37579
+ });
37580
+ }
37504
37581
  }
37582
+ break;
37583
+ }
37584
+ default: {
37585
+ throw new Error(`Unhandled route type ${route.transactionRequest.type}`);
37505
37586
  }
37506
- }
37507
- else {
37508
- throw new Error("Need all parameters");
37509
37587
  }
37510
37588
  });
37511
37589
  const swapMutationXrpl = reactQuery.useMutation(async ({ id, route }) => {
@@ -38932,4 +39010,4 @@ exports.useXrplTrustLine = useXrplTrustLine;
38932
39010
  exports.waitForReceiptWithRetry = waitForReceiptWithRetry;
38933
39011
  exports.walletIconBaseUrl = walletIconBaseUrl;
38934
39012
  exports.walletSupportsChainType = walletSupportsChainType;
38935
- //# sourceMappingURL=index-Dzir2lUQ.js.map
39013
+ //# sourceMappingURL=index-Cw1rn5LQ.js.map