@txnlab/use-wallet 1.2.5 → 1.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 +67 -90
- package/dist/cjs/algod/index.d.ts +3 -3
- package/dist/cjs/clients/algosigner/client.d.ts +11 -6
- package/dist/cjs/clients/algosigner/types.d.ts +21 -17
- package/dist/cjs/index.js +81 -64
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/wallet.d.ts +9 -7
- package/dist/esm/algod/index.d.ts +3 -3
- package/dist/esm/clients/algosigner/client.d.ts +11 -6
- package/dist/esm/clients/algosigner/types.d.ts +21 -17
- package/dist/esm/index.js +81 -64
- package/dist/esm/types/wallet.d.ts +9 -7
- package/dist/index.d.ts +59 -20
- package/package.json +8 -1
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { PROVIDER_ID } from
|
|
2
|
-
import type BaseWallet from
|
|
1
|
+
import { PROVIDER_ID } from '../constants';
|
|
2
|
+
import type BaseWallet from '../clients/base';
|
|
3
3
|
export interface Account {
|
|
4
4
|
providerId: PROVIDER_ID;
|
|
5
5
|
name: string;
|
|
6
6
|
address: string;
|
|
7
|
+
authAddr?: string;
|
|
7
8
|
}
|
|
8
9
|
export declare type Provider = {
|
|
9
10
|
accounts: Account[];
|
|
@@ -18,17 +19,18 @@ export declare type Provider = {
|
|
|
18
19
|
};
|
|
19
20
|
export declare type Asset = {
|
|
20
21
|
amount: number;
|
|
21
|
-
|
|
22
|
+
'asset-id': number;
|
|
22
23
|
creator: string;
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
'is-frozen': boolean;
|
|
25
|
+
'unit-name': string;
|
|
25
26
|
name: string;
|
|
26
27
|
};
|
|
27
28
|
export declare type AccountInfo = {
|
|
28
29
|
address: string;
|
|
29
30
|
amount: number;
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
'min-balance': number;
|
|
32
|
+
'auth-addr'?: string;
|
|
33
|
+
assets?: Asset[];
|
|
32
34
|
};
|
|
33
35
|
export declare type WalletProvider = {
|
|
34
36
|
id: PROVIDER_ID;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type _algosdk from
|
|
2
|
-
import type { AlgodClientOptions } from
|
|
1
|
+
import type _algosdk from 'algosdk';
|
|
2
|
+
import type { AlgodClientOptions } from '../types';
|
|
3
3
|
export declare const getAlgosdk: () => Promise<typeof _algosdk>;
|
|
4
|
-
export declare const getAlgodClient: (algosdk: typeof _algosdk, algodClientOptions?: AlgodClientOptions) =>
|
|
4
|
+
export declare const getAlgodClient: (algosdk: typeof _algosdk, algodClientOptions?: AlgodClientOptions) => _algosdk.Algodv2;
|
|
5
5
|
export default class Algod {
|
|
6
6
|
algosdk: typeof _algosdk;
|
|
7
7
|
algodClient: _algosdk.Algodv2;
|
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
import BaseWallet from
|
|
2
|
-
import { PROVIDER_ID } from
|
|
3
|
-
import type { Network } from
|
|
4
|
-
import type { AlgoSignerClientConstructor, InitParams } from
|
|
1
|
+
import BaseWallet from '../base';
|
|
2
|
+
import { PROVIDER_ID } from '../../constants';
|
|
3
|
+
import type { Network } from '../../types';
|
|
4
|
+
import type { AlgoSignerClientConstructor, InitParams } from './types';
|
|
5
|
+
import { useWalletStore } from '../../store';
|
|
5
6
|
declare class AlgoSignerClient extends BaseWallet {
|
|
6
7
|
#private;
|
|
7
8
|
network: Network;
|
|
8
|
-
|
|
9
|
+
walletStore: typeof useWalletStore;
|
|
10
|
+
constructor({ metadata, client, algosdk, algodClient, network }: AlgoSignerClientConstructor);
|
|
9
11
|
static metadata: {
|
|
10
12
|
id: PROVIDER_ID;
|
|
11
13
|
name: string;
|
|
12
14
|
icon: string;
|
|
13
15
|
isWalletConnect: boolean;
|
|
14
16
|
};
|
|
15
|
-
static init({ algodOptions, algosdkStatic, network
|
|
17
|
+
static init({ algodOptions, algosdkStatic, network }: InitParams): Promise<AlgoSignerClient | null>;
|
|
16
18
|
connect(): Promise<{
|
|
17
19
|
accounts: {
|
|
20
|
+
authAddr?: string | undefined;
|
|
18
21
|
name: string;
|
|
19
22
|
address: string;
|
|
20
23
|
providerId: PROVIDER_ID;
|
|
@@ -27,5 +30,7 @@ declare class AlgoSignerClient extends BaseWallet {
|
|
|
27
30
|
reconnect(onDisconnect: () => void): Promise<null>;
|
|
28
31
|
disconnect(): Promise<void>;
|
|
29
32
|
signTransactions(connectedAccounts: string[], transactions: Uint8Array[], indexesToSign?: number[], returnGroup?: boolean): Promise<Uint8Array[]>;
|
|
33
|
+
getGenesisID(): string;
|
|
34
|
+
getAuthAddress(address: string): string | undefined;
|
|
30
35
|
}
|
|
31
36
|
export default AlgoSignerClient;
|
|
@@ -1,26 +1,30 @@
|
|
|
1
|
-
import type _algosdk from
|
|
2
|
-
import { PROVIDER_ID } from
|
|
3
|
-
import type { AlgodClientOptions, Network, Metadata } from
|
|
1
|
+
import type _algosdk from 'algosdk';
|
|
2
|
+
import { PROVIDER_ID } from '../../constants';
|
|
3
|
+
import type { AlgodClientOptions, Network, Metadata } from '../../types';
|
|
4
4
|
export declare type WindowExtended = {
|
|
5
|
-
|
|
5
|
+
algorand: AlgoSigner;
|
|
6
6
|
} & Window & typeof globalThis;
|
|
7
|
+
export declare type GenesisId = 'betanet-v1.0' | 'testnet-v1.0' | 'mainnet-v1.0' | string;
|
|
8
|
+
export declare type EnableParams = {
|
|
9
|
+
genesisID?: GenesisId;
|
|
10
|
+
genesisHash?: string;
|
|
11
|
+
accounts?: string[];
|
|
12
|
+
};
|
|
13
|
+
export declare type EnableResponse = {
|
|
14
|
+
genesisID: GenesisId;
|
|
15
|
+
genesisHash: string;
|
|
16
|
+
accounts: string[];
|
|
17
|
+
};
|
|
7
18
|
export declare type AlgoSignerTransaction = {
|
|
8
19
|
txn: string;
|
|
9
|
-
signers?: [];
|
|
20
|
+
signers?: string[];
|
|
21
|
+
stxn?: string;
|
|
10
22
|
multisig?: string;
|
|
23
|
+
authAddr?: string;
|
|
11
24
|
};
|
|
12
|
-
export declare type SupportedLedgers = "MainNet" | "TestNet" | "BetaNet" | string;
|
|
13
25
|
export declare type AlgoSigner = {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
ledger: SupportedLedgers;
|
|
17
|
-
}) => Promise<{
|
|
18
|
-
address: string;
|
|
19
|
-
}[]>;
|
|
20
|
-
signTxn: (transactions: AlgoSignerTransaction[]) => Promise<{
|
|
21
|
-
txID: string;
|
|
22
|
-
blob: string;
|
|
23
|
-
}[]>;
|
|
26
|
+
enable: (params?: EnableParams) => Promise<EnableResponse>;
|
|
27
|
+
signTxns: (transactions: AlgoSignerTransaction[]) => Promise<string[]>;
|
|
24
28
|
encoding: {
|
|
25
29
|
msgpackToBase64(transaction: Uint8Array): string;
|
|
26
30
|
byteArrayToString(transaction: Uint8Array): string;
|
|
@@ -32,7 +36,7 @@ export declare type AlgoSignerClientConstructor = {
|
|
|
32
36
|
id: PROVIDER_ID;
|
|
33
37
|
algosdk: typeof _algosdk;
|
|
34
38
|
algodClient: _algosdk.Algodv2;
|
|
35
|
-
network:
|
|
39
|
+
network: Network;
|
|
36
40
|
};
|
|
37
41
|
export declare type InitParams = {
|
|
38
42
|
algodOptions?: AlgodClientOptions;
|
package/dist/esm/index.js
CHANGED
|
@@ -21,8 +21,8 @@ const DEFAULT_NODE_PORT = "";
|
|
|
21
21
|
const getAlgosdk = async () => {
|
|
22
22
|
return (await import('algosdk')).default;
|
|
23
23
|
};
|
|
24
|
-
const getAlgodClient =
|
|
25
|
-
const [tokenOrBaseClient = DEFAULT_NODE_TOKEN, baseServer = DEFAULT_NODE_BASEURL, port = DEFAULT_NODE_PORT, headers
|
|
24
|
+
const getAlgodClient = (algosdk, algodClientOptions) => {
|
|
25
|
+
const [tokenOrBaseClient = DEFAULT_NODE_TOKEN, baseServer = DEFAULT_NODE_BASEURL, port = DEFAULT_NODE_PORT, headers] = algodClientOptions || [];
|
|
26
26
|
return new algosdk.Algodv2(tokenOrBaseClient, baseServer, port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YgNTQuNzUwOVoiIGZpbGw9IiNENjQ1MDAiLz4KPC9zdmc+Cg==";
|
|
1576
1576
|
|
|
1577
|
-
const getNetwork = (network) => {
|
|
1578
|
-
if (network === "betanet") {
|
|
1579
|
-
return "BetaNet";
|
|
1580
|
-
}
|
|
1581
|
-
if (network === "testnet") {
|
|
1582
|
-
return "TestNet";
|
|
1583
|
-
}
|
|
1584
|
-
if (network === "mainnet") {
|
|
1585
|
-
return "MainNet";
|
|
1586
|
-
}
|
|
1587
|
-
return network;
|
|
1588
|
-
};
|
|
1589
1577
|
class AlgoSignerClient extends BaseClient {
|
|
1590
1578
|
#client;
|
|
1591
1579
|
network;
|
|
1592
|
-
|
|
1580
|
+
walletStore;
|
|
1581
|
+
constructor({ metadata, client, algosdk, algodClient, network }) {
|
|
1593
1582
|
super(metadata, algosdk, algodClient);
|
|
1594
1583
|
this.#client = client;
|
|
1595
1584
|
this.network = network;
|
|
1585
|
+
this.walletStore = useWalletStore;
|
|
1596
1586
|
}
|
|
1597
1587
|
static metadata = {
|
|
1598
1588
|
id: PROVIDER_ID.ALGOSIGNER,
|
|
1599
|
-
name:
|
|
1589
|
+
name: 'AlgoSigner',
|
|
1600
1590
|
icon: ICON$3,
|
|
1601
|
-
isWalletConnect: false
|
|
1591
|
+
isWalletConnect: false
|
|
1602
1592
|
};
|
|
1603
|
-
static async init({ algodOptions, algosdkStatic, network = DEFAULT_NETWORK$1
|
|
1593
|
+
static async init({ algodOptions, algosdkStatic, network = DEFAULT_NETWORK$1 }) {
|
|
1604
1594
|
try {
|
|
1605
|
-
if (typeof window ==
|
|
1606
|
-
|
|
1607
|
-
throw new Error("AlgoSigner is not available.");
|
|
1595
|
+
if (typeof window == 'undefined' || window.algorand === undefined) {
|
|
1596
|
+
throw new Error('AlgoSigner is not available.');
|
|
1608
1597
|
}
|
|
1609
1598
|
const algosdk = algosdkStatic || (await Algod.init(algodOptions)).algosdk;
|
|
1610
|
-
const algodClient =
|
|
1611
|
-
const algosigner = window.
|
|
1599
|
+
const algodClient = getAlgodClient(algosdk, algodOptions);
|
|
1600
|
+
const algosigner = window.algorand;
|
|
1612
1601
|
return new AlgoSignerClient({
|
|
1613
1602
|
metadata: AlgoSignerClient.metadata,
|
|
1614
1603
|
id: PROVIDER_ID.ALGOSIGNER,
|
|
1615
1604
|
client: algosigner,
|
|
1616
1605
|
algosdk: algosdk,
|
|
1617
1606
|
algodClient: algodClient,
|
|
1618
|
-
network
|
|
1607
|
+
network
|
|
1619
1608
|
});
|
|
1620
1609
|
}
|
|
1621
1610
|
catch (e) {
|
|
1622
1611
|
console.warn(e);
|
|
1623
|
-
console.warn(`Error initializing ${AlgoSignerClient.metadata.name}.`,
|
|
1612
|
+
console.warn(`Error initializing ${AlgoSignerClient.metadata.name}.`, 'Do you have the extension installed?', 'https://www.purestake.com/technology/algosigner');
|
|
1624
1613
|
return null;
|
|
1625
1614
|
}
|
|
1626
1615
|
}
|
|
1627
1616
|
async connect() {
|
|
1628
|
-
await this.#client.
|
|
1629
|
-
const accounts = await this.#client.accounts({
|
|
1630
|
-
ledger: getNetwork(this.network),
|
|
1631
|
-
});
|
|
1617
|
+
const { accounts } = await this.#client.enable({ genesisID: this.getGenesisID() });
|
|
1632
1618
|
if (accounts.length === 0) {
|
|
1633
1619
|
throw new Error(`No accounts found for ${AlgoSignerClient.metadata.id}`);
|
|
1634
1620
|
}
|
|
1635
|
-
const mappedAccounts = accounts.map((
|
|
1636
|
-
|
|
1637
|
-
address
|
|
1638
|
-
|
|
1621
|
+
const mappedAccounts = await Promise.all(accounts.map(async (address, index) => {
|
|
1622
|
+
// check to see if this is a rekeyed account
|
|
1623
|
+
const { 'auth-addr': authAddr } = await this.getAccountInfo(address);
|
|
1624
|
+
return {
|
|
1625
|
+
name: `AlgoSigner ${index + 1}`,
|
|
1626
|
+
address,
|
|
1627
|
+
providerId: AlgoSignerClient.metadata.id,
|
|
1628
|
+
...(authAddr && { authAddr })
|
|
1629
|
+
};
|
|
1639
1630
|
}));
|
|
1631
|
+
// sort the accounts in the order they were returned by AlgoSigner
|
|
1632
|
+
mappedAccounts.sort((a, b) => accounts.indexOf(a.address) - accounts.indexOf(b.address));
|
|
1640
1633
|
return {
|
|
1641
1634
|
...AlgoSignerClient.metadata,
|
|
1642
|
-
accounts: mappedAccounts
|
|
1635
|
+
accounts: mappedAccounts
|
|
1643
1636
|
};
|
|
1644
1637
|
}
|
|
1638
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
1645
1639
|
async reconnect(onDisconnect) {
|
|
1646
|
-
if (window === undefined ||
|
|
1647
|
-
window.AlgoSigner === undefined) {
|
|
1640
|
+
if (window === undefined || window.algorand === undefined) {
|
|
1648
1641
|
onDisconnect();
|
|
1649
1642
|
}
|
|
1650
1643
|
return null;
|
|
1651
1644
|
}
|
|
1645
|
+
// eslint-disable-next-line @typescript-eslint/require-await
|
|
1652
1646
|
async disconnect() {
|
|
1653
1647
|
return;
|
|
1654
1648
|
}
|
|
@@ -1657,49 +1651,70 @@ class AlgoSignerClient extends BaseClient {
|
|
|
1657
1651
|
const decodedTxns = transactions.map((txn) => {
|
|
1658
1652
|
return this.algosdk.decodeObj(txn);
|
|
1659
1653
|
});
|
|
1654
|
+
const signedIndexes = [];
|
|
1660
1655
|
// Marshal the transactions,
|
|
1661
1656
|
// and add the signers property if they shouldn't be signed.
|
|
1662
1657
|
const txnsToSign = decodedTxns.reduce((acc, txn, i) => {
|
|
1663
|
-
const isSigned =
|
|
1664
|
-
const
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1658
|
+
const isSigned = 'txn' in txn;
|
|
1659
|
+
const sender = this.algosdk.encodeAddress(isSigned ? txn.txn.snd : txn.snd);
|
|
1660
|
+
const authAddress = this.getAuthAddress(sender); // rekeyed-to account, or undefined
|
|
1661
|
+
if (indexesToSign && indexesToSign.length && indexesToSign.includes(i)) {
|
|
1662
|
+
signedIndexes.push(i);
|
|
1663
|
+
acc.push({
|
|
1664
|
+
txn: this.#client.encoding.msgpackToBase64(transactions[i]),
|
|
1665
|
+
...(authAddress && { authAddr: authAddress })
|
|
1666
|
+
});
|
|
1667
|
+
}
|
|
1668
|
+
else if (!isSigned && connectedAccounts.includes(sender)) {
|
|
1669
|
+
signedIndexes.push(i);
|
|
1670
|
+
acc.push({
|
|
1671
|
+
txn: this.#client.encoding.msgpackToBase64(transactions[i]),
|
|
1672
|
+
...(authAddress && { authAddr: authAddress })
|
|
1673
|
+
});
|
|
1676
1674
|
}
|
|
1677
|
-
else
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
.decodeSignedTransaction(transactions[i])
|
|
1681
|
-
.
|
|
1682
|
-
:
|
|
1683
|
-
|
|
1675
|
+
else {
|
|
1676
|
+
acc.push({
|
|
1677
|
+
txn: this.#client.encoding.msgpackToBase64(isSigned
|
|
1678
|
+
? this.algosdk.decodeSignedTransaction(transactions[i]).txn.toByte()
|
|
1679
|
+
: this.algosdk.decodeUnsignedTransaction(transactions[i]).toByte()),
|
|
1680
|
+
signers: []
|
|
1681
|
+
});
|
|
1684
1682
|
}
|
|
1685
|
-
acc.push(txnObj);
|
|
1686
1683
|
return acc;
|
|
1687
1684
|
}, []);
|
|
1688
1685
|
// Sign them with the client.
|
|
1689
|
-
const result = await this.#client.
|
|
1686
|
+
const result = await this.#client.signTxns(txnsToSign);
|
|
1690
1687
|
// Join the newly signed transactions with the original group of transactions
|
|
1691
|
-
// if
|
|
1692
|
-
const signedTxns =
|
|
1693
|
-
if (
|
|
1694
|
-
|
|
1688
|
+
// if `returnGroup` is true
|
|
1689
|
+
const signedTxns = transactions.reduce((acc, txn, i) => {
|
|
1690
|
+
if (signedIndexes.includes(i)) {
|
|
1691
|
+
const signedByUser = result[i];
|
|
1692
|
+
signedByUser && acc.push(new Uint8Array(Buffer.from(signedByUser, 'base64')));
|
|
1695
1693
|
}
|
|
1696
1694
|
else if (returnGroup) {
|
|
1697
|
-
acc.push(
|
|
1695
|
+
acc.push(txn);
|
|
1698
1696
|
}
|
|
1699
1697
|
return acc;
|
|
1700
1698
|
}, []);
|
|
1701
1699
|
return signedTxns;
|
|
1702
1700
|
}
|
|
1701
|
+
getGenesisID() {
|
|
1702
|
+
if (this.network === 'betanet') {
|
|
1703
|
+
return 'betanet-v1.0';
|
|
1704
|
+
}
|
|
1705
|
+
if (this.network === 'testnet') {
|
|
1706
|
+
return 'testnet-v1.0';
|
|
1707
|
+
}
|
|
1708
|
+
if (this.network === 'mainnet') {
|
|
1709
|
+
return 'mainnet-v1.0';
|
|
1710
|
+
}
|
|
1711
|
+
return this.network;
|
|
1712
|
+
}
|
|
1713
|
+
getAuthAddress(address) {
|
|
1714
|
+
const accounts = this.walletStore.getState().accounts;
|
|
1715
|
+
const account = accounts.find((acct) => acct.address === address && acct.providerId === this.metadata.id);
|
|
1716
|
+
return account?.authAddr;
|
|
1717
|
+
}
|
|
1703
1718
|
}
|
|
1704
1719
|
|
|
1705
1720
|
const ICON$2 = "data:image/svg+xml;base64," +
|
|
@@ -1858,10 +1873,12 @@ class WalletConnectClient extends BaseClient {
|
|
|
1858
1873
|
// Sign them with the client.
|
|
1859
1874
|
const result = await this.#client.sendCustomRequest(request);
|
|
1860
1875
|
this.keepWCAliveStop();
|
|
1876
|
+
// Check if the result is the same length as the transactions
|
|
1877
|
+
const lengthsMatch = result.length === transactions.length;
|
|
1861
1878
|
// Join the newly signed transactions with the original group of transactions.
|
|
1862
1879
|
const signedTxns = transactions.reduce((acc, txn, i) => {
|
|
1863
1880
|
if (signedIndexes.includes(i)) {
|
|
1864
|
-
const signedByUser = result[i];
|
|
1881
|
+
const signedByUser = lengthsMatch ? result[i] : result.shift();
|
|
1865
1882
|
signedByUser && acc.push(new Uint8Array(Buffer.from(signedByUser, 'base64')));
|
|
1866
1883
|
}
|
|
1867
1884
|
else if (returnGroup) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { PROVIDER_ID } from
|
|
2
|
-
import type BaseWallet from
|
|
1
|
+
import { PROVIDER_ID } from '../constants';
|
|
2
|
+
import type BaseWallet from '../clients/base';
|
|
3
3
|
export interface Account {
|
|
4
4
|
providerId: PROVIDER_ID;
|
|
5
5
|
name: string;
|
|
6
6
|
address: string;
|
|
7
|
+
authAddr?: string;
|
|
7
8
|
}
|
|
8
9
|
export declare type Provider = {
|
|
9
10
|
accounts: Account[];
|
|
@@ -18,17 +19,18 @@ export declare type Provider = {
|
|
|
18
19
|
};
|
|
19
20
|
export declare type Asset = {
|
|
20
21
|
amount: number;
|
|
21
|
-
|
|
22
|
+
'asset-id': number;
|
|
22
23
|
creator: string;
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
'is-frozen': boolean;
|
|
25
|
+
'unit-name': string;
|
|
25
26
|
name: string;
|
|
26
27
|
};
|
|
27
28
|
export declare type AccountInfo = {
|
|
28
29
|
address: string;
|
|
29
30
|
amount: number;
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
'min-balance': number;
|
|
32
|
+
'auth-addr'?: string;
|
|
33
|
+
assets?: Asset[];
|
|
32
34
|
};
|
|
33
35
|
export declare type WalletProvider = {
|
|
34
36
|
id: PROVIDER_ID;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,9 @@ import * as react from 'react';
|
|
|
3
3
|
import { PeraWalletConnect } from '@perawallet/connect';
|
|
4
4
|
import _MyAlgoConnect from '@randlabs/myalgo-connect';
|
|
5
5
|
import { DeflyWalletConnect } from '@blockshake/defly-connect';
|
|
6
|
+
import * as zustand_middleware from 'zustand/middleware';
|
|
7
|
+
import * as immer_dist_internal from 'immer/dist/internal';
|
|
8
|
+
import * as zustand from 'zustand';
|
|
6
9
|
import WalletConnect from '@walletconnect/client';
|
|
7
10
|
import QRCodeModal from 'algorand-walletconnect-qrcode-modal';
|
|
8
11
|
|
|
@@ -121,6 +124,7 @@ interface Account {
|
|
|
121
124
|
providerId: PROVIDER_ID;
|
|
122
125
|
name: string;
|
|
123
126
|
address: string;
|
|
127
|
+
authAddr?: string;
|
|
124
128
|
}
|
|
125
129
|
declare type Provider = {
|
|
126
130
|
accounts: Account[];
|
|
@@ -135,17 +139,18 @@ declare type Provider = {
|
|
|
135
139
|
};
|
|
136
140
|
declare type Asset = {
|
|
137
141
|
amount: number;
|
|
138
|
-
|
|
142
|
+
'asset-id': number;
|
|
139
143
|
creator: string;
|
|
140
|
-
|
|
141
|
-
|
|
144
|
+
'is-frozen': boolean;
|
|
145
|
+
'unit-name': string;
|
|
142
146
|
name: string;
|
|
143
147
|
};
|
|
144
148
|
declare type AccountInfo = {
|
|
145
149
|
address: string;
|
|
146
150
|
amount: number;
|
|
147
|
-
|
|
148
|
-
|
|
151
|
+
'min-balance': number;
|
|
152
|
+
'auth-addr'?: string;
|
|
153
|
+
assets?: Asset[];
|
|
149
154
|
};
|
|
150
155
|
declare type WalletProvider = {
|
|
151
156
|
id: PROVIDER_ID;
|
|
@@ -224,6 +229,32 @@ declare const reconnectProviders: (providers: SupportedProviders) => Promise<voi
|
|
|
224
229
|
declare type NFDTransactionsArray = ["u" | "s", string][];
|
|
225
230
|
declare function encodeNFDTransactionsArray(transactionsArray: NFDTransactionsArray): Uint8Array[];
|
|
226
231
|
|
|
232
|
+
declare type WalletStore = {
|
|
233
|
+
accounts: Account[];
|
|
234
|
+
activeAccount: Account | null | undefined;
|
|
235
|
+
setActiveAccount: (account: Account) => void;
|
|
236
|
+
clearActiveAccount: (id: PROVIDER_ID) => void;
|
|
237
|
+
addAccounts: (accounts: Account[]) => void;
|
|
238
|
+
removeAccounts: (providerId: PROVIDER_ID) => void;
|
|
239
|
+
};
|
|
240
|
+
declare const useWalletStore: zustand.UseBoundStore<Omit<Omit<Omit<zustand.StoreApi<WalletStore>, "setState"> & {
|
|
241
|
+
setState(nextStateOrUpdater: WalletStore | Partial<WalletStore> | ((state: immer_dist_internal.WritableDraft<WalletStore>) => void), shouldReplace?: boolean | undefined): void;
|
|
242
|
+
}, "persist"> & {
|
|
243
|
+
persist: {
|
|
244
|
+
setOptions: (options: Partial<zustand_middleware.PersistOptions<WalletStore, WalletStore>>) => void;
|
|
245
|
+
clearStorage: () => void;
|
|
246
|
+
rehydrate: () => Promise<void>;
|
|
247
|
+
hasHydrated: () => boolean;
|
|
248
|
+
onHydrate: (fn: (state: WalletStore) => void) => () => void;
|
|
249
|
+
onFinishHydration: (fn: (state: WalletStore) => void) => () => void;
|
|
250
|
+
getOptions: () => Partial<zustand_middleware.PersistOptions<WalletStore, WalletStore>>;
|
|
251
|
+
};
|
|
252
|
+
}, "setState"> & {
|
|
253
|
+
setState<A extends string | {
|
|
254
|
+
type: unknown;
|
|
255
|
+
}>(nextStateOrUpdater: WalletStore | Partial<WalletStore> | ((state: immer_dist_internal.WritableDraft<WalletStore>) => void), shouldReplace?: boolean | undefined, action?: A | undefined): void;
|
|
256
|
+
}>;
|
|
257
|
+
|
|
227
258
|
declare const _default: react.Provider<Partial<{
|
|
228
259
|
kmd: Promise<BaseClient | null>;
|
|
229
260
|
pera: Promise<BaseClient | null>;
|
|
@@ -450,23 +481,27 @@ declare class ExodusClient extends BaseClient {
|
|
|
450
481
|
signTransactions(connectedAccounts: string[], transactions: Array<Uint8Array>, indexesToSign?: number[], returnGroup?: boolean): Promise<Uint8Array[]>;
|
|
451
482
|
}
|
|
452
483
|
|
|
484
|
+
declare type GenesisId = 'betanet-v1.0' | 'testnet-v1.0' | 'mainnet-v1.0' | string;
|
|
485
|
+
declare type EnableParams = {
|
|
486
|
+
genesisID?: GenesisId;
|
|
487
|
+
genesisHash?: string;
|
|
488
|
+
accounts?: string[];
|
|
489
|
+
};
|
|
490
|
+
declare type EnableResponse = {
|
|
491
|
+
genesisID: GenesisId;
|
|
492
|
+
genesisHash: string;
|
|
493
|
+
accounts: string[];
|
|
494
|
+
};
|
|
453
495
|
declare type AlgoSignerTransaction = {
|
|
454
496
|
txn: string;
|
|
455
|
-
signers?: [];
|
|
497
|
+
signers?: string[];
|
|
498
|
+
stxn?: string;
|
|
456
499
|
multisig?: string;
|
|
500
|
+
authAddr?: string;
|
|
457
501
|
};
|
|
458
|
-
declare type SupportedLedgers = "MainNet" | "TestNet" | "BetaNet" | string;
|
|
459
502
|
declare type AlgoSigner = {
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
ledger: SupportedLedgers;
|
|
463
|
-
}) => Promise<{
|
|
464
|
-
address: string;
|
|
465
|
-
}[]>;
|
|
466
|
-
signTxn: (transactions: AlgoSignerTransaction[]) => Promise<{
|
|
467
|
-
txID: string;
|
|
468
|
-
blob: string;
|
|
469
|
-
}[]>;
|
|
503
|
+
enable: (params?: EnableParams) => Promise<EnableResponse>;
|
|
504
|
+
signTxns: (transactions: AlgoSignerTransaction[]) => Promise<string[]>;
|
|
470
505
|
encoding: {
|
|
471
506
|
msgpackToBase64(transaction: Uint8Array): string;
|
|
472
507
|
byteArrayToString(transaction: Uint8Array): string;
|
|
@@ -478,7 +513,7 @@ declare type AlgoSignerClientConstructor = {
|
|
|
478
513
|
id: PROVIDER_ID;
|
|
479
514
|
algosdk: typeof _algosdk;
|
|
480
515
|
algodClient: _algosdk.Algodv2;
|
|
481
|
-
network:
|
|
516
|
+
network: Network;
|
|
482
517
|
};
|
|
483
518
|
declare type InitParams$3 = {
|
|
484
519
|
algodOptions?: AlgodClientOptions;
|
|
@@ -489,16 +524,18 @@ declare type InitParams$3 = {
|
|
|
489
524
|
declare class AlgoSignerClient extends BaseClient {
|
|
490
525
|
#private;
|
|
491
526
|
network: Network;
|
|
492
|
-
|
|
527
|
+
walletStore: typeof useWalletStore;
|
|
528
|
+
constructor({ metadata, client, algosdk, algodClient, network }: AlgoSignerClientConstructor);
|
|
493
529
|
static metadata: {
|
|
494
530
|
id: PROVIDER_ID;
|
|
495
531
|
name: string;
|
|
496
532
|
icon: string;
|
|
497
533
|
isWalletConnect: boolean;
|
|
498
534
|
};
|
|
499
|
-
static init({ algodOptions, algosdkStatic, network
|
|
535
|
+
static init({ algodOptions, algosdkStatic, network }: InitParams$3): Promise<AlgoSignerClient | null>;
|
|
500
536
|
connect(): Promise<{
|
|
501
537
|
accounts: {
|
|
538
|
+
authAddr?: string | undefined;
|
|
502
539
|
name: string;
|
|
503
540
|
address: string;
|
|
504
541
|
providerId: PROVIDER_ID;
|
|
@@ -511,6 +548,8 @@ declare class AlgoSignerClient extends BaseClient {
|
|
|
511
548
|
reconnect(onDisconnect: () => void): Promise<null>;
|
|
512
549
|
disconnect(): Promise<void>;
|
|
513
550
|
signTransactions(connectedAccounts: string[], transactions: Uint8Array[], indexesToSign?: number[], returnGroup?: boolean): Promise<Uint8Array[]>;
|
|
551
|
+
getGenesisID(): string;
|
|
552
|
+
getAuthAddress(address: string): string | undefined;
|
|
514
553
|
}
|
|
515
554
|
|
|
516
555
|
interface IClientMeta {
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"url": "https://github.com/txnlab/use-wallet/issues"
|
|
13
13
|
},
|
|
14
14
|
"homepage": "https://txnlab.github.io/use-wallet",
|
|
15
|
-
"version": "1.2.
|
|
15
|
+
"version": "1.2.7",
|
|
16
16
|
"description": "React hooks for using Algorand compatible wallets in dApps.",
|
|
17
17
|
"scripts": {
|
|
18
18
|
"dev": "yarn storybook",
|
|
@@ -49,12 +49,19 @@
|
|
|
49
49
|
"@types/big.js": "^6.1.6",
|
|
50
50
|
"@types/jest": "^29.1.2",
|
|
51
51
|
"@types/react": "^18.0.15",
|
|
52
|
+
"@typescript-eslint/eslint-plugin": "^5.55.0",
|
|
53
|
+
"@typescript-eslint/parser": "^5.55.0",
|
|
52
54
|
"@walletconnect/client": "^1.8.0",
|
|
53
55
|
"algorand-walletconnect-qrcode-modal": "^1.8.0",
|
|
54
56
|
"algosdk": "^2.1.0",
|
|
55
57
|
"babel-jest": "^29.1.2",
|
|
56
58
|
"babel-loader": "^8.2.3",
|
|
57
59
|
"css-loader": "^6.5.1",
|
|
60
|
+
"eslint": "^8.36.0",
|
|
61
|
+
"eslint-config-prettier": "^8.7.0",
|
|
62
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
63
|
+
"eslint-plugin-react": "^7.32.2",
|
|
64
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
58
65
|
"gh-pages": "^4.0.0",
|
|
59
66
|
"html-webpack-plugin": "^5.5.0",
|
|
60
67
|
"identity-obj-proxy": "^3.0.0",
|