@dynamic-labs/global-wallet-client 4.0.0-alpha.51 → 4.0.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.
- package/CHANGELOG.md +81 -1
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +11 -7
- package/src/lib/actions/connectAction/createConnectAction.cjs +24 -12
- package/src/lib/actions/connectAction/createConnectAction.d.ts +4 -3
- package/src/lib/actions/connectAction/createConnectAction.js +24 -12
- package/src/lib/createGlobalWalletClient.cjs +6 -6
- package/src/lib/createGlobalWalletClient.d.ts +11 -6
- package/src/lib/createGlobalWalletClient.js +6 -6
- package/src/lib/ethereum/functions/eip1193Provider/createEIP1193Provider.cjs +88 -56
- package/src/lib/ethereum/functions/eip1193Provider/createEIP1193Provider.js +89 -57
- package/src/lib/ethereum/functions/isNetworkSupported/index.d.ts +1 -0
- package/src/lib/ethereum/functions/isNetworkSupported/isNetworkSupported.cjs +8 -0
- package/src/lib/ethereum/functions/isNetworkSupported/isNetworkSupported.d.ts +3 -0
- package/src/lib/ethereum/functions/isNetworkSupported/isNetworkSupported.js +4 -0
- package/src/lib/functions/createEthereumModule/createEthereumModule.cjs +24 -0
- package/src/lib/functions/createEthereumModule/createEthereumModule.d.ts +11 -0
- package/src/lib/functions/createEthereumModule/createEthereumModule.js +20 -0
- package/src/lib/functions/createEthereumModule/index.d.ts +1 -0
- package/src/lib/functions/createPopupOpener/createPopupOpener.cjs +77 -38
- package/src/lib/functions/createPopupOpener/createPopupOpener.d.ts +2 -1
- package/src/lib/functions/createPopupOpener/createPopupOpener.js +77 -38
- package/src/lib/functions/createSolanaModule/createSolanaModule.cjs +17 -0
- package/src/lib/functions/createSolanaModule/createSolanaModule.d.ts +9 -0
- package/src/lib/functions/createSolanaModule/createSolanaModule.js +13 -0
- package/src/lib/functions/createSolanaModule/index.d.ts +1 -0
- package/src/lib/functions/mergeAndEncryptParams/mergeAndEncryptParams.d.ts +2 -2
- package/src/lib/solana/functions/convertBaseWalletToWalletAccount/convertBaseWalletToWalletAccount.cjs +36 -0
- package/src/lib/solana/functions/convertBaseWalletToWalletAccount/convertBaseWalletToWalletAccount.d.ts +4 -0
- package/src/lib/solana/functions/convertBaseWalletToWalletAccount/convertBaseWalletToWalletAccount.js +32 -0
- package/src/lib/solana/functions/convertBaseWalletToWalletAccount/index.d.ts +1 -0
- package/src/lib/solana/functions/createSolanaSignAndSendTransactionFeature/createSolanaSignAndSendTransactionFeature.cjs +14 -0
- package/src/lib/solana/functions/createSolanaSignAndSendTransactionFeature/createSolanaSignAndSendTransactionFeature.d.ts +2 -0
- package/src/lib/solana/functions/createSolanaSignAndSendTransactionFeature/createSolanaSignAndSendTransactionFeature.js +10 -0
- package/src/lib/solana/functions/createSolanaSignAndSendTransactionFeature/index.d.ts +1 -0
- package/src/lib/solana/functions/createSolanaSignMessageFeature/createSolanaSignMessageFeature.cjs +29 -0
- package/src/lib/solana/functions/createSolanaSignMessageFeature/createSolanaSignMessageFeature.d.ts +3 -0
- package/src/lib/solana/functions/createSolanaSignMessageFeature/createSolanaSignMessageFeature.js +25 -0
- package/src/lib/solana/functions/createSolanaSignMessageFeature/index.d.ts +1 -0
- package/src/lib/solana/functions/createSolanaSignTransactionFeature/createSolanaSignTransactionFeature.cjs +14 -0
- package/src/lib/solana/functions/createSolanaSignTransactionFeature/createSolanaSignTransactionFeature.d.ts +2 -0
- package/src/lib/solana/functions/createSolanaSignTransactionFeature/createSolanaSignTransactionFeature.js +10 -0
- package/src/lib/solana/functions/createSolanaSignTransactionFeature/index.d.ts +1 -0
- package/src/lib/solana/functions/createSolanaWallet/createSolanaWallet.cjs +47 -0
- package/src/lib/solana/functions/createSolanaWallet/createSolanaWallet.d.ts +17 -0
- package/src/lib/solana/functions/createSolanaWallet/createSolanaWallet.js +43 -0
- package/src/lib/solana/functions/createSolanaWallet/index.d.ts +1 -0
- package/src/lib/solana/functions/createStandardConnectFeature/createStandardConnectFeature.cjs +21 -0
- package/src/lib/solana/functions/createStandardConnectFeature/createStandardConnectFeature.d.ts +3 -0
- package/src/lib/solana/functions/createStandardConnectFeature/createStandardConnectFeature.js +17 -0
- package/src/lib/solana/functions/createStandardConnectFeature/index.d.ts +1 -0
- package/src/lib/solana/functions/createStandardDisconnectFeature/createStandardDisconnectFeature.cjs +13 -0
- package/src/lib/solana/functions/createStandardDisconnectFeature/createStandardDisconnectFeature.d.ts +3 -0
- package/src/lib/solana/functions/createStandardDisconnectFeature/createStandardDisconnectFeature.js +9 -0
- package/src/lib/solana/functions/createStandardDisconnectFeature/index.d.ts +1 -0
- package/src/lib/solana/functions/createStandardEventsFeature/createStandardEventsFeature.cjs +38 -0
- package/src/lib/solana/functions/createStandardEventsFeature/createStandardEventsFeature.d.ts +13 -0
- package/src/lib/solana/functions/createStandardEventsFeature/createStandardEventsFeature.js +34 -0
- package/src/lib/solana/functions/createStandardEventsFeature/index.d.ts +1 -0
- package/src/lib/solana/functions/getSolanaChains/getSolanaChains.cjs +13 -0
- package/src/lib/solana/functions/getSolanaChains/getSolanaChains.d.ts +2 -0
- package/src/lib/solana/functions/getSolanaChains/getSolanaChains.js +9 -0
- package/src/lib/solana/functions/getSolanaChains/index.d.ts +1 -0
- package/src/lib/solana/index.d.ts +1 -0
- package/src/lib/store/createClientStore.cjs +37 -15
- package/src/lib/store/createClientStore.d.ts +51 -13
- package/src/lib/store/createClientStore.js +37 -15
- package/src/lib/types.d.ts +0 -28
- package/src/solana.cjs +10 -0
- package/src/solana.d.ts +1 -0
- package/src/solana.js +2 -0
|
@@ -1,34 +1,72 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BaseWallet, GlobalWalletConnection } from '@dynamic-labs/types';
|
|
2
2
|
type CreateClientStoreProps = {
|
|
3
3
|
storage?: Storage;
|
|
4
4
|
};
|
|
5
|
+
type ClientStoreState = {
|
|
6
|
+
/**
|
|
7
|
+
* Connection data between client and popup
|
|
8
|
+
*/
|
|
9
|
+
connection: GlobalWalletConnection | null;
|
|
10
|
+
/**
|
|
11
|
+
* All EVM and Solana wallets connected to this Dapp
|
|
12
|
+
*/
|
|
13
|
+
wallets: BaseWallet[];
|
|
14
|
+
/**
|
|
15
|
+
* Ethereum specific state
|
|
16
|
+
*/
|
|
17
|
+
ethereum: {
|
|
18
|
+
supportedNetworks: {
|
|
19
|
+
chainId: number;
|
|
20
|
+
}[];
|
|
21
|
+
currentNetworkId: number;
|
|
22
|
+
} | null;
|
|
23
|
+
/**
|
|
24
|
+
* Solana specific state
|
|
25
|
+
*/
|
|
26
|
+
solana: {
|
|
27
|
+
currentNetwork: string;
|
|
28
|
+
} | null;
|
|
29
|
+
};
|
|
5
30
|
export declare const createClientStore: ({ storage, }?: CreateClientStoreProps) => {
|
|
6
31
|
/**
|
|
7
32
|
* Resets the store to its initial state
|
|
8
33
|
*/
|
|
9
34
|
clear: () => void;
|
|
35
|
+
/**
|
|
36
|
+
* Get all Ethereum state from the current connection
|
|
37
|
+
*/
|
|
38
|
+
readonly ethereum: {
|
|
39
|
+
supportedNetworks: {
|
|
40
|
+
chainId: number;
|
|
41
|
+
}[];
|
|
42
|
+
currentNetworkId: number;
|
|
43
|
+
} | null;
|
|
10
44
|
/**
|
|
11
45
|
* Retrieves the current active connection if it exists and hasn't expired
|
|
12
46
|
* @returns {Connection | null} The current connection or null if no connection exists or it has expired
|
|
13
47
|
*/
|
|
14
|
-
getActiveConnection: () =>
|
|
48
|
+
getActiveConnection: () => GlobalWalletConnection | null;
|
|
49
|
+
/**
|
|
50
|
+
* Updates current connection, wallets
|
|
51
|
+
* Used when the popup confirm a connection
|
|
52
|
+
* @param {GlobalWalletConnection | null} connection - The connection to store, or null to clear it
|
|
53
|
+
*/
|
|
54
|
+
setInitialConnectionState: ({ connection, wallets, ethereum, solana, }: Pick<ClientStoreState, 'connection' | 'wallets' | 'ethereum' | 'solana'>) => void;
|
|
15
55
|
/**
|
|
16
|
-
*
|
|
17
|
-
* @param {Connection | null} connection - The connection to store, or null to clear it
|
|
56
|
+
* Get all Solana wallets connected to the current connection
|
|
18
57
|
*/
|
|
19
|
-
|
|
58
|
+
readonly solana: {
|
|
59
|
+
currentNetwork: string;
|
|
60
|
+
} | null;
|
|
20
61
|
/**
|
|
21
|
-
*
|
|
22
|
-
* @
|
|
62
|
+
* Switches the Ethereum network
|
|
63
|
+
* @param {number} networkId - The network ID to switch to
|
|
23
64
|
*/
|
|
24
|
-
|
|
25
|
-
connection: Connection | null;
|
|
26
|
-
};
|
|
65
|
+
switchEthereumNetwork(networkId: number): void;
|
|
27
66
|
/**
|
|
28
|
-
*
|
|
29
|
-
* @returns The current user's wallets
|
|
67
|
+
* Get all wallets connected to the current connection
|
|
30
68
|
*/
|
|
31
|
-
readonly
|
|
69
|
+
readonly wallets: BaseWallet[];
|
|
32
70
|
};
|
|
33
71
|
export type ClientStore = ReturnType<typeof createClientStore>;
|
|
34
72
|
export {};
|
|
@@ -8,6 +8,9 @@ const createClientStore = ({ storage = localStorage, } = {}) => {
|
|
|
8
8
|
storage,
|
|
9
9
|
store: createStore(() => ({
|
|
10
10
|
connection: null,
|
|
11
|
+
ethereum: null,
|
|
12
|
+
solana: null,
|
|
13
|
+
wallets: [],
|
|
11
14
|
})),
|
|
12
15
|
});
|
|
13
16
|
return {
|
|
@@ -17,6 +20,13 @@ const createClientStore = ({ storage = localStorage, } = {}) => {
|
|
|
17
20
|
clear: () => {
|
|
18
21
|
store.setState(store.getInitialState());
|
|
19
22
|
},
|
|
23
|
+
/**
|
|
24
|
+
* Get all Ethereum state from the current connection
|
|
25
|
+
*/
|
|
26
|
+
get ethereum() {
|
|
27
|
+
this.getActiveConnection();
|
|
28
|
+
return store.getState().ethereum;
|
|
29
|
+
},
|
|
20
30
|
/**
|
|
21
31
|
* Retrieves the current active connection if it exists and hasn't expired
|
|
22
32
|
* @returns {Connection | null} The current connection or null if no connection exists or it has expired
|
|
@@ -34,28 +44,40 @@ const createClientStore = ({ storage = localStorage, } = {}) => {
|
|
|
34
44
|
return connection;
|
|
35
45
|
},
|
|
36
46
|
/**
|
|
37
|
-
* Updates
|
|
38
|
-
*
|
|
47
|
+
* Updates current connection, wallets
|
|
48
|
+
* Used when the popup confirm a connection
|
|
49
|
+
* @param {GlobalWalletConnection | null} connection - The connection to store, or null to clear it
|
|
39
50
|
*/
|
|
40
|
-
|
|
41
|
-
store.setState({ connection });
|
|
51
|
+
setInitialConnectionState: ({ connection, wallets, ethereum, solana, }) => {
|
|
52
|
+
store.setState({ connection, ethereum, solana, wallets });
|
|
42
53
|
},
|
|
43
54
|
/**
|
|
44
|
-
*
|
|
45
|
-
* @returns The complete store state
|
|
55
|
+
* Get all Solana wallets connected to the current connection
|
|
46
56
|
*/
|
|
47
|
-
get
|
|
48
|
-
|
|
57
|
+
get solana() {
|
|
58
|
+
this.getActiveConnection();
|
|
59
|
+
return store.getState().solana;
|
|
60
|
+
},
|
|
61
|
+
/**
|
|
62
|
+
* Switches the Ethereum network
|
|
63
|
+
* @param {number} networkId - The network ID to switch to
|
|
64
|
+
*/
|
|
65
|
+
switchEthereumNetwork(networkId) {
|
|
66
|
+
this.getActiveConnection();
|
|
67
|
+
const { ethereum } = store.getState();
|
|
68
|
+
if (!ethereum) {
|
|
69
|
+
throw new Error('No connection found');
|
|
70
|
+
}
|
|
71
|
+
store.setState({
|
|
72
|
+
ethereum: Object.assign(Object.assign({}, ethereum), { currentNetworkId: networkId }),
|
|
73
|
+
});
|
|
49
74
|
},
|
|
50
75
|
/**
|
|
51
|
-
*
|
|
52
|
-
* @returns The current user's wallets
|
|
76
|
+
* Get all wallets connected to the current connection
|
|
53
77
|
*/
|
|
54
|
-
get
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
const solana = (_e = (_d = store.getState().connection) === null || _d === void 0 ? void 0 : _d.solana) === null || _e === void 0 ? void 0 : _e.wallet;
|
|
58
|
-
return solana ? [...evm, solana] : evm;
|
|
78
|
+
get wallets() {
|
|
79
|
+
this.getActiveConnection();
|
|
80
|
+
return store.getState().wallets;
|
|
59
81
|
},
|
|
60
82
|
};
|
|
61
83
|
};
|
package/src/lib/types.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { BaseWallet } from '@dynamic-labs/types';
|
|
2
1
|
export type IconCode = `data:image/png;base64,${string}`;
|
|
3
2
|
export type PopupInfo = {
|
|
4
3
|
url: string;
|
|
@@ -8,30 +7,3 @@ export type PopupInfo = {
|
|
|
8
7
|
export type ConnectArgs = {
|
|
9
8
|
chain: 'evm' | 'solana';
|
|
10
9
|
};
|
|
11
|
-
/**
|
|
12
|
-
* Defines the current dapp connection
|
|
13
|
-
*/
|
|
14
|
-
export type Connection = {
|
|
15
|
-
/** Unix timestamp when the connection expires */
|
|
16
|
-
expiresAt: number;
|
|
17
|
-
/** EVM blockchain configuration */
|
|
18
|
-
evm: {
|
|
19
|
-
/** List of networks that can be switched to */
|
|
20
|
-
supportedNetworks: {
|
|
21
|
-
chainId: number;
|
|
22
|
-
}[];
|
|
23
|
-
/** Connected EVM wallets */
|
|
24
|
-
wallets: BaseWallet[];
|
|
25
|
-
/** Currently active network identifier */
|
|
26
|
-
network: string;
|
|
27
|
-
} | null;
|
|
28
|
-
/** Solana blockchain configuration */
|
|
29
|
-
solana: {
|
|
30
|
-
/** Connected Solana wallet */
|
|
31
|
-
wallet: BaseWallet;
|
|
32
|
-
/** Currently active network identifier */
|
|
33
|
-
network: string;
|
|
34
|
-
} | null;
|
|
35
|
-
/** Encryption key for secure communication */
|
|
36
|
-
sharedSecret: string;
|
|
37
|
-
};
|
package/src/solana.cjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
var createSolanaWallet = require('./lib/solana/functions/createSolanaWallet/createSolanaWallet.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
exports.createSolanaWallet = createSolanaWallet.createSolanaWallet;
|
package/src/solana.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createSolanaWallet } from './lib/solana';
|
package/src/solana.js
ADDED