@d13co/use-wallet 4.5.5 → 4.5.6

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.cjs CHANGED
@@ -8668,7 +8668,9 @@ var LiquidEvmBaseWallet = class extends BaseWallet {
8668
8668
  if (currentChainId.toLowerCase() === ALGORAND_CHAIN_ID_HEX.toLowerCase()) {
8669
8669
  return;
8670
8670
  }
8671
- this.logger.info(`Wrong chain (${currentChainId}), switching to Algorand (${ALGORAND_CHAIN_ID_HEX})...`);
8671
+ this.logger.info(
8672
+ `Wrong chain (${currentChainId}), switching to Algorand (${ALGORAND_CHAIN_ID_HEX})...`
8673
+ );
8672
8674
  try {
8673
8675
  await provider.request({
8674
8676
  method: "wallet_switchEthereumChain",
@@ -8739,14 +8741,13 @@ var LiquidEvmBaseWallet = class extends BaseWallet {
8739
8741
  const signer = txn.sender.toString();
8740
8742
  const canSignTxn = this.addresses.includes(signer);
8741
8743
  if (isIndexMatch && canSignTxn) {
8742
- txnsToSign.push(txn);
8744
+ txnsToSign.push({ txn });
8745
+ } else {
8746
+ txnsToSign.push({ txn, signers: [] });
8743
8747
  }
8744
8748
  });
8745
8749
  return txnsToSign;
8746
8750
  }
8747
- /**
8748
- * Process encoded transaction group to extract transactions that need signing
8749
- */
8750
8751
  processEncodedTxns(txnGroup, indexesToSign) {
8751
8752
  const txnsToSign = [];
8752
8753
  txnGroup.forEach((txnBuffer, index) => {
@@ -8757,7 +8758,9 @@ var LiquidEvmBaseWallet = class extends BaseWallet {
8757
8758
  const signer = txn.sender.toString();
8758
8759
  const canSignTxn = !isSigned && this.addresses.includes(signer);
8759
8760
  if (isIndexMatch && canSignTxn) {
8760
- txnsToSign.push(txn);
8761
+ txnsToSign.push({ txn });
8762
+ } else {
8763
+ txnsToSign.push({ txn, signers: [] });
8761
8764
  }
8762
8765
  });
8763
8766
  return txnsToSign;
@@ -8768,25 +8771,17 @@ var LiquidEvmBaseWallet = class extends BaseWallet {
8768
8771
  signTransactions = async (txnGroup, indexesToSign) => {
8769
8772
  try {
8770
8773
  this.logger.debug("Signing transactions...", { txnGroup, indexesToSign });
8771
- const evmSdk = await this.initializeEvmSdk();
8772
- let flatTxns = [];
8774
+ const liquidEvmSdk = await this.initializeEvmSdk();
8775
+ let txnsToSign = [];
8773
8776
  if (isTransactionArray(txnGroup)) {
8774
- flatTxns = flattenTxnGroup(txnGroup);
8777
+ const flatTxns = flattenTxnGroup(txnGroup);
8778
+ txnsToSign = this.processTxns(flatTxns, indexesToSign);
8775
8779
  } else {
8776
- const flatEncoded = flattenTxnGroup(txnGroup);
8777
- flatTxns = flatEncoded.map((txnBuffer) => {
8778
- const decodedObj = import_algosdk11.default.msgpackRawDecode(txnBuffer);
8779
- const isSigned = isSignedTxn(decodedObj);
8780
- return isSigned ? import_algosdk11.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk11.default.decodeUnsignedTransaction(txnBuffer);
8781
- });
8782
- }
8783
- const txnsToSign = isTransactionArray(txnGroup) ? this.processTxns(flatTxns, indexesToSign) : this.processEncodedTxns(flattenTxnGroup(txnGroup), indexesToSign);
8784
- if (txnsToSign.length === 0) {
8785
- this.logger.debug("No transactions to sign");
8786
- return flatTxns.map(() => null);
8780
+ const flatTxns = flattenTxnGroup(txnGroup);
8781
+ txnsToSign = this.processEncodedTxns(flatTxns, indexesToSign);
8787
8782
  }
8788
8783
  const firstTxn = txnsToSign[0];
8789
- const algorandAddress = firstTxn.sender.toString();
8784
+ const algorandAddress = firstTxn.txn.sender.toString();
8790
8785
  let evmAddress = this.evmAddressMap.get(algorandAddress);
8791
8786
  if (!evmAddress) {
8792
8787
  const walletState = this.store.state.wallets[this.id];
@@ -8806,14 +8801,20 @@ var LiquidEvmBaseWallet = class extends BaseWallet {
8806
8801
  const onBeforeSign = this.options.uiHooks?.onBeforeSign ?? this.managerUIHooks?.onBeforeSign;
8807
8802
  if (onBeforeSign) {
8808
8803
  this.logger.debug("Running onBeforeSign hook", { txnGroup, indexesToSign });
8809
- await onBeforeSign(txnGroup, indexesToSign);
8804
+ const txnsAsUint8 = txnsToSign.map(({ txn }) => import_algosdk11.default.encodeUnsignedTransaction(txn));
8805
+ await onBeforeSign(txnsAsUint8, indexesToSign);
8810
8806
  }
8811
8807
  await this.ensureAlgorandChain();
8812
- const signedBlobs = await evmSdk.signTxn({
8808
+ const { signer: evmSigner } = await liquidEvmSdk.getSigner({
8813
8809
  evmAddress,
8814
- txns: flatTxns,
8815
8810
  signMessage: (typedData) => this.signWithProvider(typedData, evmAddress)
8816
8811
  });
8812
+ const allTxns = txnsToSign.map((t) => t.txn);
8813
+ const signIndexes = txnsToSign.reduce((acc, t, i) => {
8814
+ if (!("signers" in t)) acc.push(i);
8815
+ return acc;
8816
+ }, []);
8817
+ const signedBlobs = await evmSigner(allTxns, signIndexes);
8817
8818
  const onAfterSign = this.options.uiHooks?.onAfterSign ?? this.managerUIHooks?.onAfterSign;
8818
8819
  if (onAfterSign) {
8819
8820
  this.logger.debug("Running onAfterSign hook");
@@ -8822,12 +8823,10 @@ var LiquidEvmBaseWallet = class extends BaseWallet {
8822
8823
  } catch (e) {
8823
8824
  }
8824
8825
  }
8825
- const result = flatTxns.map((txn, index) => {
8826
- const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
8827
- const signer = txn.sender.toString();
8828
- const canSignTxn = this.addresses.includes(signer);
8829
- if (isIndexMatch && canSignTxn) {
8830
- return signedBlobs[index];
8826
+ let signedIdx = 0;
8827
+ const result = txnsToSign.map((_2, index) => {
8828
+ if (signIndexes.includes(index)) {
8829
+ return signedBlobs[signedIdx++];
8831
8830
  }
8832
8831
  return null;
8833
8832
  });