@d13co/use-wallet 4.5.13 → 4.5.15
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 +58 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -10
- package/dist/index.d.ts +8 -10
- package/dist/index.js +58 -54
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -481,11 +481,11 @@ interface AlgoXEvmOptions {
|
|
|
481
481
|
};
|
|
482
482
|
}
|
|
483
483
|
/**
|
|
484
|
-
* Abstract base class for EVM-based wallets that use the
|
|
484
|
+
* Abstract base class for EVM-based wallets that use the xChain EVM system
|
|
485
485
|
* to derive Algorand addresses from EVM addresses.
|
|
486
486
|
*
|
|
487
487
|
* This class provides common functionality for:
|
|
488
|
-
* - Initializing the
|
|
488
|
+
* - Initializing the xChain EVM SDK
|
|
489
489
|
* - Deriving Algorand accounts from EVM addresses
|
|
490
490
|
* - Signing Algorand transactions using EVM signatures
|
|
491
491
|
* - Managing the mapping between EVM and Algorand addresses
|
|
@@ -503,7 +503,7 @@ declare abstract class AlgoXEvmBaseWallet extends BaseWallet {
|
|
|
503
503
|
protected store: Store<State>;
|
|
504
504
|
constructor(params: WalletConstructor<any>);
|
|
505
505
|
/**
|
|
506
|
-
* Default metadata for
|
|
506
|
+
* Default metadata for xChain EVM wallets.
|
|
507
507
|
* Subclasses MUST override this with their own metadata including isAlgoXEvm: "EVM"
|
|
508
508
|
*/
|
|
509
509
|
static defaultMetadata: AlgoXEvmMetadata;
|
|
@@ -530,7 +530,7 @@ declare abstract class AlgoXEvmBaseWallet extends BaseWallet {
|
|
|
530
530
|
*/
|
|
531
531
|
protected abstract signWithProvider(typedData: SignTypedDataParams, evmAddress: string): Promise<string>;
|
|
532
532
|
/**
|
|
533
|
-
* Initialize the
|
|
533
|
+
* Initialize the xChain EVM SDK for deriving Algorand addresses
|
|
534
534
|
*/
|
|
535
535
|
protected initializeEvmSdk(): Promise<AlgoXEvmSdk>;
|
|
536
536
|
/**
|
|
@@ -619,12 +619,10 @@ declare class RainbowKitWallet extends AlgoXEvmBaseWallet {
|
|
|
619
619
|
private static extractConnectorInfo;
|
|
620
620
|
/**
|
|
621
621
|
* Read connected EVM accounts from wagmi state.
|
|
622
|
-
* If
|
|
623
|
-
*
|
|
624
|
-
*
|
|
625
|
-
*
|
|
626
|
-
* selection UI). The callback is responsible for any disconnect/reconnect
|
|
627
|
-
* needed to present a fresh selection.
|
|
622
|
+
* If already connected (e.g. auto-reconnect on page refresh), uses the
|
|
623
|
+
* existing connection directly. Otherwise tries the getEvmAccounts
|
|
624
|
+
* callback (wallet picker UI), then falls back to connecting with the
|
|
625
|
+
* first available connector.
|
|
628
626
|
*/
|
|
629
627
|
private getConnectedEvmAddresses;
|
|
630
628
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -481,11 +481,11 @@ interface AlgoXEvmOptions {
|
|
|
481
481
|
};
|
|
482
482
|
}
|
|
483
483
|
/**
|
|
484
|
-
* Abstract base class for EVM-based wallets that use the
|
|
484
|
+
* Abstract base class for EVM-based wallets that use the xChain EVM system
|
|
485
485
|
* to derive Algorand addresses from EVM addresses.
|
|
486
486
|
*
|
|
487
487
|
* This class provides common functionality for:
|
|
488
|
-
* - Initializing the
|
|
488
|
+
* - Initializing the xChain EVM SDK
|
|
489
489
|
* - Deriving Algorand accounts from EVM addresses
|
|
490
490
|
* - Signing Algorand transactions using EVM signatures
|
|
491
491
|
* - Managing the mapping between EVM and Algorand addresses
|
|
@@ -503,7 +503,7 @@ declare abstract class AlgoXEvmBaseWallet extends BaseWallet {
|
|
|
503
503
|
protected store: Store<State>;
|
|
504
504
|
constructor(params: WalletConstructor<any>);
|
|
505
505
|
/**
|
|
506
|
-
* Default metadata for
|
|
506
|
+
* Default metadata for xChain EVM wallets.
|
|
507
507
|
* Subclasses MUST override this with their own metadata including isAlgoXEvm: "EVM"
|
|
508
508
|
*/
|
|
509
509
|
static defaultMetadata: AlgoXEvmMetadata;
|
|
@@ -530,7 +530,7 @@ declare abstract class AlgoXEvmBaseWallet extends BaseWallet {
|
|
|
530
530
|
*/
|
|
531
531
|
protected abstract signWithProvider(typedData: SignTypedDataParams, evmAddress: string): Promise<string>;
|
|
532
532
|
/**
|
|
533
|
-
* Initialize the
|
|
533
|
+
* Initialize the xChain EVM SDK for deriving Algorand addresses
|
|
534
534
|
*/
|
|
535
535
|
protected initializeEvmSdk(): Promise<AlgoXEvmSdk>;
|
|
536
536
|
/**
|
|
@@ -619,12 +619,10 @@ declare class RainbowKitWallet extends AlgoXEvmBaseWallet {
|
|
|
619
619
|
private static extractConnectorInfo;
|
|
620
620
|
/**
|
|
621
621
|
* Read connected EVM accounts from wagmi state.
|
|
622
|
-
* If
|
|
623
|
-
*
|
|
624
|
-
*
|
|
625
|
-
*
|
|
626
|
-
* selection UI). The callback is responsible for any disconnect/reconnect
|
|
627
|
-
* needed to present a fresh selection.
|
|
622
|
+
* If already connected (e.g. auto-reconnect on page refresh), uses the
|
|
623
|
+
* existing connection directly. Otherwise tries the getEvmAccounts
|
|
624
|
+
* callback (wallet picker UI), then falls back to connecting with the
|
|
625
|
+
* first available connector.
|
|
628
626
|
*/
|
|
629
627
|
private getConnectedEvmAddresses;
|
|
630
628
|
/**
|
package/dist/index.js
CHANGED
|
@@ -8608,16 +8608,16 @@ var AlgoXEvmBaseWallet = class extends BaseWallet {
|
|
|
8608
8608
|
this.store = params.store;
|
|
8609
8609
|
}
|
|
8610
8610
|
/**
|
|
8611
|
-
* Default metadata for
|
|
8611
|
+
* Default metadata for xChain EVM wallets.
|
|
8612
8612
|
* Subclasses MUST override this with their own metadata including isAlgoXEvm: "EVM"
|
|
8613
8613
|
*/
|
|
8614
8614
|
static defaultMetadata;
|
|
8615
8615
|
/**
|
|
8616
|
-
* Initialize the
|
|
8616
|
+
* Initialize the xChain EVM SDK for deriving Algorand addresses
|
|
8617
8617
|
*/
|
|
8618
8618
|
async initializeEvmSdk() {
|
|
8619
8619
|
if (!this.algoXEvmSdk) {
|
|
8620
|
-
this.logger.info("Initializing
|
|
8620
|
+
this.logger.info("Initializing xChain EVM SDK...");
|
|
8621
8621
|
if (!this.algorandClient) {
|
|
8622
8622
|
const { AlgorandClient } = await import("@algorandfoundation/algokit-utils");
|
|
8623
8623
|
const algodClient = this.getAlgodClient();
|
|
@@ -8627,7 +8627,7 @@ var AlgoXEvmBaseWallet = class extends BaseWallet {
|
|
|
8627
8627
|
}
|
|
8628
8628
|
const { AlgoXEvmSdk } = await import("algo-x-evm-sdk");
|
|
8629
8629
|
this.algoXEvmSdk = new AlgoXEvmSdk({ algorand: this.algorandClient });
|
|
8630
|
-
this.logger.info("
|
|
8630
|
+
this.logger.info("xChain EVM SDK initialized");
|
|
8631
8631
|
}
|
|
8632
8632
|
return this.algoXEvmSdk;
|
|
8633
8633
|
}
|
|
@@ -8703,23 +8703,33 @@ var AlgoXEvmBaseWallet = class extends BaseWallet {
|
|
|
8703
8703
|
const flatTxns = flattenTxnGroup(txnGroup);
|
|
8704
8704
|
txnsToSign = this.processEncodedTxns(flatTxns, indexesToSign);
|
|
8705
8705
|
}
|
|
8706
|
-
const
|
|
8707
|
-
|
|
8708
|
-
|
|
8709
|
-
|
|
8710
|
-
|
|
8711
|
-
|
|
8712
|
-
for (const account of walletState.accounts) {
|
|
8713
|
-
const addr = account.metadata?.evmAddress;
|
|
8714
|
-
if (addr) {
|
|
8715
|
-
this.evmAddressMap.set(account.address, addr);
|
|
8716
|
-
}
|
|
8706
|
+
const walletState = this.store.state.wallets[this.id];
|
|
8707
|
+
if (walletState) {
|
|
8708
|
+
for (const account of walletState.accounts) {
|
|
8709
|
+
const addr = account.metadata?.evmAddress;
|
|
8710
|
+
if (addr && !this.evmAddressMap.has(account.address)) {
|
|
8711
|
+
this.evmAddressMap.set(account.address, addr);
|
|
8717
8712
|
}
|
|
8718
|
-
evmAddress = this.evmAddressMap.get(algorandAddress);
|
|
8719
8713
|
}
|
|
8720
8714
|
}
|
|
8721
|
-
|
|
8722
|
-
|
|
8715
|
+
const allTxns = txnsToSign.map((t) => t.txn);
|
|
8716
|
+
const signIndexes = txnsToSign.reduce((acc, t, i) => {
|
|
8717
|
+
if (!("signers" in t)) acc.push(i);
|
|
8718
|
+
return acc;
|
|
8719
|
+
}, []);
|
|
8720
|
+
const evmGroups = /* @__PURE__ */ new Map();
|
|
8721
|
+
for (const idx of signIndexes) {
|
|
8722
|
+
const algorandAddress = allTxns[idx].sender.toString();
|
|
8723
|
+
const evmAddress = this.evmAddressMap.get(algorandAddress);
|
|
8724
|
+
if (!evmAddress) {
|
|
8725
|
+
throw new Error(`No EVM address found for Algorand address: ${algorandAddress}`);
|
|
8726
|
+
}
|
|
8727
|
+
const group = evmGroups.get(evmAddress);
|
|
8728
|
+
if (group) {
|
|
8729
|
+
group.push(idx);
|
|
8730
|
+
} else {
|
|
8731
|
+
evmGroups.set(evmAddress, [idx]);
|
|
8732
|
+
}
|
|
8723
8733
|
}
|
|
8724
8734
|
const onBeforeSign = this.options.uiHooks?.onBeforeSign ?? this.managerUIHooks?.onBeforeSign;
|
|
8725
8735
|
if (onBeforeSign) {
|
|
@@ -8727,16 +8737,18 @@ var AlgoXEvmBaseWallet = class extends BaseWallet {
|
|
|
8727
8737
|
const txnsAsUint8 = txnsToSign.map(({ txn }) => algosdk11.encodeUnsignedTransaction(txn));
|
|
8728
8738
|
await onBeforeSign(txnsAsUint8, indexesToSign);
|
|
8729
8739
|
}
|
|
8730
|
-
const
|
|
8731
|
-
|
|
8732
|
-
|
|
8733
|
-
|
|
8734
|
-
|
|
8735
|
-
|
|
8736
|
-
|
|
8737
|
-
|
|
8738
|
-
|
|
8739
|
-
|
|
8740
|
+
const signedResult = new Array(txnsToSign.length).fill(null);
|
|
8741
|
+
console.log("EVM Groups for signing:", evmGroups);
|
|
8742
|
+
for (const [evmAddress, indexes] of evmGroups) {
|
|
8743
|
+
const { signer: evmSigner } = await algoXEvmSdk.getSigner({
|
|
8744
|
+
evmAddress,
|
|
8745
|
+
signMessage: (typedData) => this.signWithProvider(typedData, evmAddress)
|
|
8746
|
+
});
|
|
8747
|
+
const signedBlobs = await evmSigner(allTxns, indexes);
|
|
8748
|
+
for (let i = 0; i < indexes.length; i++) {
|
|
8749
|
+
signedResult[indexes[i]] = signedBlobs[i];
|
|
8750
|
+
}
|
|
8751
|
+
}
|
|
8740
8752
|
const onAfterSign = this.options.uiHooks?.onAfterSign ?? this.managerUIHooks?.onAfterSign;
|
|
8741
8753
|
if (onAfterSign) {
|
|
8742
8754
|
this.logger.debug("Running onAfterSign hook");
|
|
@@ -8745,15 +8757,8 @@ var AlgoXEvmBaseWallet = class extends BaseWallet {
|
|
|
8745
8757
|
} catch (e) {
|
|
8746
8758
|
}
|
|
8747
8759
|
}
|
|
8748
|
-
|
|
8749
|
-
|
|
8750
|
-
if (signIndexes.includes(index)) {
|
|
8751
|
-
return signedBlobs[signedIdx++];
|
|
8752
|
-
}
|
|
8753
|
-
return null;
|
|
8754
|
-
});
|
|
8755
|
-
this.logger.debug("Transactions signed successfully", result);
|
|
8756
|
-
return result;
|
|
8760
|
+
this.logger.debug("Transactions signed successfully", signedResult);
|
|
8761
|
+
return signedResult;
|
|
8757
8762
|
} catch (error) {
|
|
8758
8763
|
try {
|
|
8759
8764
|
const onAfterSignCleanup = this.options.uiHooks?.onAfterSign ?? this.managerUIHooks?.onAfterSign;
|
|
@@ -8906,36 +8911,35 @@ var RainbowKitWallet = class _RainbowKitWallet extends AlgoXEvmBaseWallet {
|
|
|
8906
8911
|
}
|
|
8907
8912
|
/**
|
|
8908
8913
|
* Read connected EVM accounts from wagmi state.
|
|
8909
|
-
* If
|
|
8910
|
-
*
|
|
8911
|
-
*
|
|
8912
|
-
*
|
|
8913
|
-
* selection UI). The callback is responsible for any disconnect/reconnect
|
|
8914
|
-
* needed to present a fresh selection.
|
|
8914
|
+
* If already connected (e.g. auto-reconnect on page refresh), uses the
|
|
8915
|
+
* existing connection directly. Otherwise tries the getEvmAccounts
|
|
8916
|
+
* callback (wallet picker UI), then falls back to connecting with the
|
|
8917
|
+
* first available connector.
|
|
8915
8918
|
*/
|
|
8916
8919
|
async getConnectedEvmAddresses() {
|
|
8917
8920
|
const { getAccount, connect: wagmiConnect } = await import("@wagmi/core");
|
|
8921
|
+
const existing = getAccount(this.wagmiConfig);
|
|
8922
|
+
if (existing.isConnected && existing.address) {
|
|
8923
|
+
this.logger.info("Using existing wagmi connection");
|
|
8924
|
+
return {
|
|
8925
|
+
addresses: existing.addresses ? [...existing.addresses] : [existing.address],
|
|
8926
|
+
connectorInfo: _RainbowKitWallet.extractConnectorInfo(existing)
|
|
8927
|
+
};
|
|
8928
|
+
}
|
|
8918
8929
|
if (this.options.getEvmAccounts) {
|
|
8919
8930
|
const addresses = await this.options.getEvmAccounts();
|
|
8920
8931
|
if (addresses.length > 0) {
|
|
8921
|
-
const
|
|
8922
|
-
const connectorInfo = _RainbowKitWallet.extractConnectorInfo(
|
|
8923
|
-
if (
|
|
8932
|
+
const account = getAccount(this.wagmiConfig);
|
|
8933
|
+
const connectorInfo = _RainbowKitWallet.extractConnectorInfo(account);
|
|
8934
|
+
if (account.isConnected && account.address) {
|
|
8924
8935
|
return {
|
|
8925
|
-
addresses:
|
|
8936
|
+
addresses: account.addresses ? [...account.addresses] : [account.address],
|
|
8926
8937
|
connectorInfo
|
|
8927
8938
|
};
|
|
8928
8939
|
}
|
|
8929
8940
|
return { addresses, connectorInfo };
|
|
8930
8941
|
}
|
|
8931
8942
|
}
|
|
8932
|
-
const account = getAccount(this.wagmiConfig);
|
|
8933
|
-
if (account.isConnected && account.address) {
|
|
8934
|
-
return {
|
|
8935
|
-
addresses: account.addresses ? [...account.addresses] : [account.address],
|
|
8936
|
-
connectorInfo: _RainbowKitWallet.extractConnectorInfo(account)
|
|
8937
|
-
};
|
|
8938
|
-
}
|
|
8939
8943
|
const connectors = this.wagmiConfig.connectors;
|
|
8940
8944
|
if (connectors.length > 0) {
|
|
8941
8945
|
this.logger.info("Attempting connection with first available connector...");
|