@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.
Files changed (72) hide show
  1. package/CHANGELOG.md +81 -1
  2. package/package.cjs +1 -1
  3. package/package.js +1 -1
  4. package/package.json +11 -7
  5. package/src/lib/actions/connectAction/createConnectAction.cjs +24 -12
  6. package/src/lib/actions/connectAction/createConnectAction.d.ts +4 -3
  7. package/src/lib/actions/connectAction/createConnectAction.js +24 -12
  8. package/src/lib/createGlobalWalletClient.cjs +6 -6
  9. package/src/lib/createGlobalWalletClient.d.ts +11 -6
  10. package/src/lib/createGlobalWalletClient.js +6 -6
  11. package/src/lib/ethereum/functions/eip1193Provider/createEIP1193Provider.cjs +88 -56
  12. package/src/lib/ethereum/functions/eip1193Provider/createEIP1193Provider.js +89 -57
  13. package/src/lib/ethereum/functions/isNetworkSupported/index.d.ts +1 -0
  14. package/src/lib/ethereum/functions/isNetworkSupported/isNetworkSupported.cjs +8 -0
  15. package/src/lib/ethereum/functions/isNetworkSupported/isNetworkSupported.d.ts +3 -0
  16. package/src/lib/ethereum/functions/isNetworkSupported/isNetworkSupported.js +4 -0
  17. package/src/lib/functions/createEthereumModule/createEthereumModule.cjs +24 -0
  18. package/src/lib/functions/createEthereumModule/createEthereumModule.d.ts +11 -0
  19. package/src/lib/functions/createEthereumModule/createEthereumModule.js +20 -0
  20. package/src/lib/functions/createEthereumModule/index.d.ts +1 -0
  21. package/src/lib/functions/createPopupOpener/createPopupOpener.cjs +77 -38
  22. package/src/lib/functions/createPopupOpener/createPopupOpener.d.ts +2 -1
  23. package/src/lib/functions/createPopupOpener/createPopupOpener.js +77 -38
  24. package/src/lib/functions/createSolanaModule/createSolanaModule.cjs +17 -0
  25. package/src/lib/functions/createSolanaModule/createSolanaModule.d.ts +9 -0
  26. package/src/lib/functions/createSolanaModule/createSolanaModule.js +13 -0
  27. package/src/lib/functions/createSolanaModule/index.d.ts +1 -0
  28. package/src/lib/functions/mergeAndEncryptParams/mergeAndEncryptParams.d.ts +2 -2
  29. package/src/lib/solana/functions/convertBaseWalletToWalletAccount/convertBaseWalletToWalletAccount.cjs +36 -0
  30. package/src/lib/solana/functions/convertBaseWalletToWalletAccount/convertBaseWalletToWalletAccount.d.ts +4 -0
  31. package/src/lib/solana/functions/convertBaseWalletToWalletAccount/convertBaseWalletToWalletAccount.js +32 -0
  32. package/src/lib/solana/functions/convertBaseWalletToWalletAccount/index.d.ts +1 -0
  33. package/src/lib/solana/functions/createSolanaSignAndSendTransactionFeature/createSolanaSignAndSendTransactionFeature.cjs +14 -0
  34. package/src/lib/solana/functions/createSolanaSignAndSendTransactionFeature/createSolanaSignAndSendTransactionFeature.d.ts +2 -0
  35. package/src/lib/solana/functions/createSolanaSignAndSendTransactionFeature/createSolanaSignAndSendTransactionFeature.js +10 -0
  36. package/src/lib/solana/functions/createSolanaSignAndSendTransactionFeature/index.d.ts +1 -0
  37. package/src/lib/solana/functions/createSolanaSignMessageFeature/createSolanaSignMessageFeature.cjs +29 -0
  38. package/src/lib/solana/functions/createSolanaSignMessageFeature/createSolanaSignMessageFeature.d.ts +3 -0
  39. package/src/lib/solana/functions/createSolanaSignMessageFeature/createSolanaSignMessageFeature.js +25 -0
  40. package/src/lib/solana/functions/createSolanaSignMessageFeature/index.d.ts +1 -0
  41. package/src/lib/solana/functions/createSolanaSignTransactionFeature/createSolanaSignTransactionFeature.cjs +14 -0
  42. package/src/lib/solana/functions/createSolanaSignTransactionFeature/createSolanaSignTransactionFeature.d.ts +2 -0
  43. package/src/lib/solana/functions/createSolanaSignTransactionFeature/createSolanaSignTransactionFeature.js +10 -0
  44. package/src/lib/solana/functions/createSolanaSignTransactionFeature/index.d.ts +1 -0
  45. package/src/lib/solana/functions/createSolanaWallet/createSolanaWallet.cjs +47 -0
  46. package/src/lib/solana/functions/createSolanaWallet/createSolanaWallet.d.ts +17 -0
  47. package/src/lib/solana/functions/createSolanaWallet/createSolanaWallet.js +43 -0
  48. package/src/lib/solana/functions/createSolanaWallet/index.d.ts +1 -0
  49. package/src/lib/solana/functions/createStandardConnectFeature/createStandardConnectFeature.cjs +21 -0
  50. package/src/lib/solana/functions/createStandardConnectFeature/createStandardConnectFeature.d.ts +3 -0
  51. package/src/lib/solana/functions/createStandardConnectFeature/createStandardConnectFeature.js +17 -0
  52. package/src/lib/solana/functions/createStandardConnectFeature/index.d.ts +1 -0
  53. package/src/lib/solana/functions/createStandardDisconnectFeature/createStandardDisconnectFeature.cjs +13 -0
  54. package/src/lib/solana/functions/createStandardDisconnectFeature/createStandardDisconnectFeature.d.ts +3 -0
  55. package/src/lib/solana/functions/createStandardDisconnectFeature/createStandardDisconnectFeature.js +9 -0
  56. package/src/lib/solana/functions/createStandardDisconnectFeature/index.d.ts +1 -0
  57. package/src/lib/solana/functions/createStandardEventsFeature/createStandardEventsFeature.cjs +38 -0
  58. package/src/lib/solana/functions/createStandardEventsFeature/createStandardEventsFeature.d.ts +13 -0
  59. package/src/lib/solana/functions/createStandardEventsFeature/createStandardEventsFeature.js +34 -0
  60. package/src/lib/solana/functions/createStandardEventsFeature/index.d.ts +1 -0
  61. package/src/lib/solana/functions/getSolanaChains/getSolanaChains.cjs +13 -0
  62. package/src/lib/solana/functions/getSolanaChains/getSolanaChains.d.ts +2 -0
  63. package/src/lib/solana/functions/getSolanaChains/getSolanaChains.js +9 -0
  64. package/src/lib/solana/functions/getSolanaChains/index.d.ts +1 -0
  65. package/src/lib/solana/index.d.ts +1 -0
  66. package/src/lib/store/createClientStore.cjs +37 -15
  67. package/src/lib/store/createClientStore.d.ts +51 -13
  68. package/src/lib/store/createClientStore.js +37 -15
  69. package/src/lib/types.d.ts +0 -28
  70. package/src/solana.cjs +10 -0
  71. package/src/solana.d.ts +1 -0
  72. package/src/solana.js +2 -0
@@ -1,34 +1,72 @@
1
- import { Connection } from '../types';
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: () => Connection | null;
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
- * Updates the connection in the store
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
- setConnection: (connection: Connection | null) => void;
58
+ readonly solana: {
59
+ currentNetwork: string;
60
+ } | null;
20
61
  /**
21
- * Gets the current state of the store
22
- * @returns The complete store state
62
+ * Switches the Ethereum network
63
+ * @param {number} networkId - The network ID to switch to
23
64
  */
24
- readonly state: {
25
- connection: Connection | null;
26
- };
65
+ switchEthereumNetwork(networkId: number): void;
27
66
  /**
28
- * Gets the current user's wallets
29
- * @returns The current user's wallets
67
+ * Get all wallets connected to the current connection
30
68
  */
31
- readonly userWallets: import("dist/packages/types/src").BaseWallet[];
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 the connection in the store
38
- * @param {Connection | null} connection - The connection to store, or null to clear it
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
- setConnection: (connection) => {
41
- store.setState({ connection });
51
+ setInitialConnectionState: ({ connection, wallets, ethereum, solana, }) => {
52
+ store.setState({ connection, ethereum, solana, wallets });
42
53
  },
43
54
  /**
44
- * Gets the current state of the store
45
- * @returns The complete store state
55
+ * Get all Solana wallets connected to the current connection
46
56
  */
47
- get state() {
48
- return store.getState();
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
- * Gets the current user's wallets
52
- * @returns The current user's wallets
76
+ * Get all wallets connected to the current connection
53
77
  */
54
- get userWallets() {
55
- var _a, _b, _c, _d, _e;
56
- const evm = (_c = (_b = (_a = store.getState().connection) === null || _a === void 0 ? void 0 : _a.evm) === null || _b === void 0 ? void 0 : _b.wallets) !== null && _c !== void 0 ? _c : [];
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
  };
@@ -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;
@@ -0,0 +1 @@
1
+ export { createSolanaWallet } from './lib/solana';
package/src/solana.js ADDED
@@ -0,0 +1,2 @@
1
+ 'use client'
2
+ export { createSolanaWallet } from './lib/solana/functions/createSolanaWallet/createSolanaWallet.js';