@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
package/CHANGELOG.md CHANGED
@@ -1,4 +1,84 @@
1
1
 
2
+ ## [4.0.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.0.0-alpha.52...v4.0.0) (2025-01-09)
3
+
4
+
5
+ ### ⚠ BREAKING CHANGES
6
+ See [upgrade guide](https://docs.dynamic.xyz/react-sdk/upgrade/v4) for more details.
7
+ * change openFunding to openExternalFunding (#7684)
8
+ * stop exposing authToken and minAuthToken from dynamic context (#7629)
9
+ * Removes the `eventsCallbacks` prop which has been deprecated for a while. Use the `events` prop instead.
10
+ * remove usages of findWalletBookWallet when possible (#7455)
11
+ * remove `supportsSatsConnect` helper (#7453)
12
+ * moved `getWalletLinks` helper from `@dynamic-labs/wallet-book` to `@dynamic-labs/wallet-connector-core` (#7416
13
+ * change openFunding to openExternalFunding (#7684)
14
+ * upgrade zerodev to 5.4.x (#7670)
15
+
16
+ ### Features
17
+ * Support for multi-chain AA (#6829)
18
+ * Add account abstraction module to client (#7002)
19
+ * Add support for wallet events in RN (#7061)
20
+ * Add zerodev extension for react native (#7028)
21
+ * Global connectivity disconnect (#7008)
22
+ * Add isInstalledOnBrowser prop to wallet options (#6976)
23
+ * Add iconVariant prop to DynamicBridgeWidget (#6915)
24
+ * Allow creating extra embedded wallets in react-native (#6923)
25
+ * Add hide method for auth and userProfile UI modules (#6928)
26
+ * Blockaid website scanning for global connectivity (#6874)
27
+ * Add login with TikTok (#7360)
28
+ * New transaction modal and UI for sign/signAll (#7296)
29
+ * Allow adding connection configuration for Solana connectors (#7354)
30
+ * Allow deletion of embedded wallets (#7170)
31
+ * Add support for eclipse (#7255)
32
+ * Add passkey and social to web-extension (#7096, #7106)
33
+ * Add support for compass and leap wallets
34
+ * Add support for epicgames social (#7220)
35
+ * Add support for xverse account change event (#7114)
36
+ * Show wallet names when unknown (#7478)
37
+ * AA blockaid simulations (#7583)
38
+ * Add ethereum createConnector function (#7607)
39
+ * Add fundWithExternalWallet method to useFunding (#7688)
40
+ * Global wallet: add network switch to ethereum wallets (#7686)
41
+ * Global wallet: support Solana (#7732)
42
+ * Global wallet: support Solana sign message (#7739)
43
+
44
+ ### Bug Fixes
45
+ * Create v2 embedded wallet experience in manual mode (#6887)
46
+ * Solana pk export format (#6888)
47
+ * Deeplinking on ethereum and bitcoin sats connector (#6917)
48
+ * Solana and cosmos signers not working properly (#6898)
49
+ * Edge case where wallet book fails to load (#7148)
50
+ * Issues where native currency icons were incorrect (#7126)
51
+ * Eclipse and solana wallets getting mixed up in connect only (#7487)
52
+ * Eclipse wallets never get detected (#7479)
53
+ * Changing copy of linking same wallet (#7489)
54
+ * Don't allow user to connect wallet in bridge while SDK is still loading (#7506)
55
+ * SDKHasLoaded always false in cookie enabled env (#7516)
56
+ * Normalize user reject error from injected wallets (#7702)
57
+ * Fetch nonce when authenticating a user in connect-only mode (#7689)
58
+ * Filter out wallets for current network when using external wallet funding (#7694)
59
+ * Remove toaccount from signmessage and signtypeddata for zerodev (#7650)
60
+ * Save nonce to storage (#7698)
61
+ * Add timeout when getting connected accounts (#7697)
62
+ * Update auth token from new source (#7666)
63
+ * Update extension update_url endpoint (#7655)
64
+ * Zerodev confirmation UI closes properly (#7664)
65
+ * Normalize user reject error from Rainbow and BitGet (#7721)
66
+ * Map user reject error to viem user reject error (#7712)
67
+ * Allow selecting wallet directly without showing group view if wallet key is same as group key (#7744)
68
+ * Confirmation UI shows recipient if tx is native/token transfer (#7717)
69
+ * Force network change when secondary funding wallet is on different network (#7733)
70
+ * Some Solana standard wallets not being detected correctly as installed (#7759)
71
+ * Unexpected buy button disabled when onramp is available (#7746)
72
+ * UseRpcProviders race conditions (#7742)
73
+ * allow selecting wallet directly without showing group view if wallet key is the same as group key (#7744)
74
+ * confirmation ui shows recipient if tx is native/token transfer (#7717)
75
+ * force network change when secondary fundig wallet is on a different network (#7733)
76
+ * some solana standard wallets not being detected correctly as installed (#7759)
77
+ * unexpected buy button disabled when onramp is available (#7746)
78
+ * useRpcProviders race conditions (#7742)
79
+
80
+ ## [4.0.0-alpha.52](https://github.com/dynamic-labs/dynamic-auth/compare/v4.0.0-alpha.51...v4.0.0-alpha.52) (2025-01-02)
81
+
2
82
  ## [4.0.0-alpha.51](https://github.com/dynamic-labs/dynamic-auth/compare/v4.0.0-alpha.50...v4.0.0-alpha.51) (2024-12-30)
3
83
 
4
84
 
@@ -1348,7 +1428,7 @@ There are no code changes required on the Dynamic SDK side, however if you have
1348
1428
 
1349
1429
  - React Native - You can now build mobile-first onboarding experiences with the same Dynamic magic but for React Native, get started [here](https://docs.dynamic.xyz/react-native/introduction)
1350
1430
 
1351
- - Cookie Authentication - Dynamic can now be configured to set a secure, HttpOnly cookie that can be used for authenticating with Dynamic’s backend. This will contain a minified version of our JWT token.
1431
+ - Cookie Authentication - Dynamic can now be configured to set a secure, HttpOnly cookie that can be used for authenticating with Dynamic’s backend. This will contain a minified version of our JWT token.
1352
1432
 
1353
1433
 
1354
1434
  ## Improvements
package/package.cjs CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.0.0-alpha.51";
6
+ var version = "4.0.0";
7
7
 
8
8
  exports.version = version;
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "4.0.0-alpha.51";
2
+ var version = "4.0.0";
3
3
 
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/global-wallet-client",
3
- "version": "4.0.0-alpha.51",
3
+ "version": "4.0.0",
4
4
  "description": "Core package for building Dynamic's Global Wallet",
5
5
  "author": "Dynamic Labs, Inc.",
6
6
  "license": "MIT",
@@ -31,14 +31,18 @@
31
31
  },
32
32
  "homepage": "https://www.dynamic.xyz/",
33
33
  "dependencies": {
34
- "@dynamic-labs/assert-package-version": "4.0.0-alpha.51",
35
- "@dynamic-labs/logger": "4.0.0-alpha.51",
36
- "@dynamic-labs/store": "4.0.0-alpha.51",
37
- "@dynamic-labs/types": "4.0.0-alpha.51",
38
- "@dynamic-labs/utils": "4.0.0-alpha.51",
34
+ "@dynamic-labs/assert-package-version": "4.0.0",
35
+ "@dynamic-labs/logger": "4.0.0",
36
+ "@dynamic-labs/store": "4.0.0",
37
+ "@dynamic-labs/types": "4.0.0",
38
+ "@dynamic-labs/utils": "4.0.0",
39
39
  "eventemitter3": "5.0.1"
40
40
  },
41
41
  "peerDependencies": {
42
- "viem": "^2.7.12"
42
+ "viem": "^2.7.12",
43
+ "@solana/web3.js": "1.92.1",
44
+ "@solana/wallet-standard-features": "^1.2.0",
45
+ "@wallet-standard/features": "^1.0.3",
46
+ "@wallet-standard/base": "^1.0.1"
43
47
  }
44
48
  }
@@ -19,19 +19,31 @@ const createConnectAction = ({ store, openPopup, onConnect }) => (_a) => _tslib.
19
19
  const { encryptedMessage, expiresAt, iv, providerPublicKey } = data;
20
20
  const sharedSecret = yield utils.deriveSharedSecret(keyPair.privateKey, yield utils.convertPublicKeyHexToCryptoKey(providerPublicKey));
21
21
  const message = yield utils.decryptMessage(sharedSecret, encryptedMessage, iv);
22
- const { network, wallet } = JSON.parse(message);
23
- const connection = {
24
- evm: {
25
- network,
26
- supportedNetworks: [],
27
- wallets: [wallet],
22
+ const { ethereum, solana, wallets } = JSON.parse(message);
23
+ store.setInitialConnectionState({
24
+ connection: {
25
+ expiresAt,
26
+ origin: window.location.origin,
27
+ sharedSecret,
28
28
  },
29
- expiresAt,
30
- sharedSecret,
31
- solana: null,
32
- };
33
- store.setConnection(connection);
34
- onConnect === null || onConnect === void 0 ? void 0 : onConnect(connection);
29
+ ethereum: ethereum
30
+ ? {
31
+ currentNetworkId: ethereum.currentNetworkId,
32
+ supportedNetworks: ethereum.supportedNetworks,
33
+ }
34
+ : null,
35
+ solana: solana
36
+ ? {
37
+ currentNetwork: solana.currentNetwork,
38
+ }
39
+ : null,
40
+ wallets,
41
+ });
42
+ onConnect === null || onConnect === void 0 ? void 0 : onConnect();
43
+ const wallet = wallets.find((w) => w.chain === (chain === 'evm' ? 'EVM' : 'SOL'));
44
+ if (!wallet) {
45
+ throw new Error('Wallet not found');
46
+ }
35
47
  return wallet;
36
48
  });
37
49
 
@@ -1,10 +1,11 @@
1
+ import { BaseWallet } from '@dynamic-labs/types';
1
2
  import { ClientStore } from '../../store';
2
3
  import { OpenPopup } from '../../functions/createPopupOpener/createPopupOpener';
3
- import { ConnectArgs, Connection } from '../../types';
4
+ import { ConnectArgs } from '../../types';
4
5
  type CreateConnectActionProps = {
5
6
  store: ClientStore;
6
7
  openPopup: OpenPopup;
7
- onConnect?: (connection: Connection) => void;
8
+ onConnect?: () => void;
8
9
  };
9
- export declare const createConnectAction: ({ store, openPopup, onConnect }: CreateConnectActionProps) => ({ chain }: ConnectArgs) => Promise<import("@dynamic-labs/types").BaseWallet>;
10
+ export declare const createConnectAction: ({ store, openPopup, onConnect }: CreateConnectActionProps) => ({ chain }: ConnectArgs) => Promise<BaseWallet>;
10
11
  export {};
@@ -15,19 +15,31 @@ const createConnectAction = ({ store, openPopup, onConnect }) => (_a) => __await
15
15
  const { encryptedMessage, expiresAt, iv, providerPublicKey } = data;
16
16
  const sharedSecret = yield deriveSharedSecret(keyPair.privateKey, yield convertPublicKeyHexToCryptoKey(providerPublicKey));
17
17
  const message = yield decryptMessage(sharedSecret, encryptedMessage, iv);
18
- const { network, wallet } = JSON.parse(message);
19
- const connection = {
20
- evm: {
21
- network,
22
- supportedNetworks: [],
23
- wallets: [wallet],
18
+ const { ethereum, solana, wallets } = JSON.parse(message);
19
+ store.setInitialConnectionState({
20
+ connection: {
21
+ expiresAt,
22
+ origin: window.location.origin,
23
+ sharedSecret,
24
24
  },
25
- expiresAt,
26
- sharedSecret,
27
- solana: null,
28
- };
29
- store.setConnection(connection);
30
- onConnect === null || onConnect === void 0 ? void 0 : onConnect(connection);
25
+ ethereum: ethereum
26
+ ? {
27
+ currentNetworkId: ethereum.currentNetworkId,
28
+ supportedNetworks: ethereum.supportedNetworks,
29
+ }
30
+ : null,
31
+ solana: solana
32
+ ? {
33
+ currentNetwork: solana.currentNetwork,
34
+ }
35
+ : null,
36
+ wallets,
37
+ });
38
+ onConnect === null || onConnect === void 0 ? void 0 : onConnect();
39
+ const wallet = wallets.find((w) => w.chain === (chain === 'evm' ? 'EVM' : 'SOL'));
40
+ if (!wallet) {
41
+ throw new Error('Wallet not found');
42
+ }
31
43
  return wallet;
32
44
  });
33
45
 
@@ -8,6 +8,8 @@ var createPopupOpener = require('./functions/createPopupOpener/createPopupOpener
8
8
  var createClientStore = require('./store/createClientStore.cjs');
9
9
  var createClientEventEmitter = require('./functions/createClientEventEmitter/createClientEventEmitter.cjs');
10
10
  var createDisconnectAction = require('./actions/disconnectAction/createDisconnectAction.cjs');
11
+ var createEthereumModule = require('./functions/createEthereumModule/createEthereumModule.cjs');
12
+ var createSolanaModule = require('./functions/createSolanaModule/createSolanaModule.cjs');
11
13
 
12
14
  const createGlobalWalletClient = ({ environmentId, popup: popupInfo, }) => {
13
15
  const eventEmitter = createClientEventEmitter.createClientEventEmitter();
@@ -25,18 +27,16 @@ const createGlobalWalletClient = ({ environmentId, popup: popupInfo, }) => {
25
27
  return {
26
28
  connect,
27
29
  disconnect,
28
- get ethereum() {
29
- var _a, _b;
30
- return (_b = (_a = store.getActiveConnection()) === null || _a === void 0 ? void 0 : _a.evm) !== null && _b !== void 0 ? _b : null;
31
- },
30
+ ethereum: createEthereumModule.createEthereumModule({ store }),
32
31
  invoke: openPopup,
33
32
  off: eventEmitter.off.bind(eventEmitter),
34
33
  on: eventEmitter.on.bind(eventEmitter),
35
34
  once: eventEmitter.once.bind(eventEmitter),
36
35
  removeAllListeners: eventEmitter.removeAllListeners.bind(eventEmitter),
37
36
  removeListener: eventEmitter.removeListener.bind(eventEmitter),
38
- get userWallets() {
39
- return store.userWallets;
37
+ solana: createSolanaModule.createSolanaModule({ store }),
38
+ get wallets() {
39
+ return store.wallets;
40
40
  },
41
41
  };
42
42
  };
@@ -6,13 +6,14 @@ export type CreateGlobalWalletClientProps = {
6
6
  export declare const createGlobalWalletClient: ({ environmentId, popup: popupInfo, }: CreateGlobalWalletClientProps) => {
7
7
  connect: ({ chain }: import("./types").ConnectArgs) => Promise<import("dist/packages/types/src").BaseWallet>;
8
8
  disconnect: () => void;
9
- readonly ethereum: {
10
- supportedNetworks: {
9
+ ethereum: {
10
+ readonly currentNetworkId: number | null;
11
+ readonly supportedNetworks: {
11
12
  chainId: number;
12
13
  }[];
13
- wallets: import("dist/packages/types/src").BaseWallet[];
14
- network: string;
15
- } | null;
14
+ switchNetwork: (network: number) => void;
15
+ readonly wallets: import("dist/packages/types/src").BaseWallet[];
16
+ };
16
17
  invoke: <TPopupAction extends import("dist/packages/types/src").IPopupAction>({ params, pathname, }: {
17
18
  params: import("dist/packages/types/src").GetPopupActionFuncArgs<TPopupAction>;
18
19
  pathname: import("dist/packages/types/src").GetPopupActionName<TPopupAction>;
@@ -49,6 +50,10 @@ export declare const createGlobalWalletClient: ({ environmentId, popup: popupInf
49
50
  connect: () => void;
50
51
  disconnect: () => void;
51
52
  }, any>;
52
- readonly userWallets: import("dist/packages/types/src").BaseWallet[];
53
+ solana: {
54
+ readonly currentNetwork: string | null;
55
+ readonly wallets: import("dist/packages/types/src").BaseWallet[];
56
+ };
57
+ readonly wallets: import("dist/packages/types/src").BaseWallet[];
53
58
  };
54
59
  export type GlobalWalletClient = ReturnType<typeof createGlobalWalletClient>;
@@ -4,6 +4,8 @@ import { createPopupOpener } from './functions/createPopupOpener/createPopupOpen
4
4
  import { createClientStore } from './store/createClientStore.js';
5
5
  import { createClientEventEmitter } from './functions/createClientEventEmitter/createClientEventEmitter.js';
6
6
  import { createDisconnectAction } from './actions/disconnectAction/createDisconnectAction.js';
7
+ import { createEthereumModule } from './functions/createEthereumModule/createEthereumModule.js';
8
+ import { createSolanaModule } from './functions/createSolanaModule/createSolanaModule.js';
7
9
 
8
10
  const createGlobalWalletClient = ({ environmentId, popup: popupInfo, }) => {
9
11
  const eventEmitter = createClientEventEmitter();
@@ -21,18 +23,16 @@ const createGlobalWalletClient = ({ environmentId, popup: popupInfo, }) => {
21
23
  return {
22
24
  connect,
23
25
  disconnect,
24
- get ethereum() {
25
- var _a, _b;
26
- return (_b = (_a = store.getActiveConnection()) === null || _a === void 0 ? void 0 : _a.evm) !== null && _b !== void 0 ? _b : null;
27
- },
26
+ ethereum: createEthereumModule({ store }),
28
27
  invoke: openPopup,
29
28
  off: eventEmitter.off.bind(eventEmitter),
30
29
  on: eventEmitter.on.bind(eventEmitter),
31
30
  once: eventEmitter.once.bind(eventEmitter),
32
31
  removeAllListeners: eventEmitter.removeAllListeners.bind(eventEmitter),
33
32
  removeListener: eventEmitter.removeListener.bind(eventEmitter),
34
- get userWallets() {
35
- return store.userWallets;
33
+ solana: createSolanaModule({ store }),
34
+ get wallets() {
35
+ return store.wallets;
36
36
  },
37
37
  };
38
38
  };
@@ -6,17 +6,16 @@ Object.defineProperty(exports, '__esModule', { value: true });
6
6
  var _tslib = require('../../../../../_virtual/_tslib.cjs');
7
7
  var viem = require('viem');
8
8
  var eventemitter3 = require('eventemitter3');
9
+ var isNetworkSupported = require('../isNetworkSupported/isNetworkSupported.cjs');
9
10
 
10
- const methodsHandledByPopup = ['personal_sign', 'eth_sendTransaction'];
11
11
  const createEIP1193Provider = (client) => {
12
12
  const eventEmitter = new eventemitter3.EventEmitter();
13
13
  client.on('connect', () => {
14
- var _a;
15
- const chainId = (_a = client.ethereum) === null || _a === void 0 ? void 0 : _a.network;
16
- if (!chainId)
14
+ const currentNetwork = client.ethereum.currentNetworkId;
15
+ if (!currentNetwork)
17
16
  return;
18
17
  eventEmitter.emit('connect', {
19
- chainId: viem.toHex(parseInt(chainId, 10)),
18
+ chainId: viem.toHex(currentNetwork),
20
19
  });
21
20
  });
22
21
  client.on('disconnect', () => {
@@ -26,57 +25,23 @@ const createEIP1193Provider = (client) => {
26
25
  on: eventEmitter.on.bind(eventEmitter),
27
26
  removeListener: eventEmitter.removeListener.bind(eventEmitter),
28
27
  request: ((_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ method, params }) {
29
- var _b, _c, _d;
30
- const wallets = (_c = (_b = client === null || client === void 0 ? void 0 : client.ethereum) === null || _b === void 0 ? void 0 : _b.wallets) !== null && _c !== void 0 ? _c : [];
31
- const connectedAddresses = wallets.map((wallet) => wallet.address);
32
- // Define if user is connected with ethereum wallets
33
- const isConnected = connectedAddresses.length > 0;
34
- if (method === 'eth_accounts') {
35
- return isConnected ? connectedAddresses : [];
36
- }
37
- if (method === 'eth_requestAccounts') {
38
- if (isConnected) {
39
- return connectedAddresses;
40
- }
41
- return client
42
- .connect({ chain: 'evm' })
43
- .then(({ address }) => [address]);
44
- }
45
- if (method === 'wallet_revokePermissions') {
46
- client.disconnect();
47
- return null;
48
- }
49
- if (method === 'wallet_requestPermissions') {
50
- if (isConnected) {
51
- return connectedAddresses;
52
- }
53
- return client
54
- .connect({ chain: 'evm' })
55
- .then(({ address }) => [address]);
56
- }
57
- if (method === 'eth_chainId') {
58
- return (_d = client.ethereum) === null || _d === void 0 ? void 0 : _d.network;
59
- }
60
- /**
61
- * Opens the popup to request user confirmation for the request
62
- * and to execute the request
63
- */
64
- if (methodsHandledByPopup.includes(method) && params) {
65
- const { data } = yield client
66
- .invoke({
67
- params: {
68
- method,
69
- params,
70
- },
71
- pathname: 'eth-request',
72
- })
73
- .catch((err) => {
74
- if (err.message === 'Popup closed') {
75
- throw new viem.UserRejectedRequestError(err);
76
- }
77
- throw err;
78
- });
79
- return data;
28
+ const methodHandlerMap = {
29
+ eth_accounts: () => handleEthAccounts(client),
30
+ eth_chainId: () => handleEthChainId(client),
31
+ eth_requestAccounts: () => handleEthRequestAccounts(client),
32
+ eth_sendTransaction: () => handleMethodInPopup({
33
+ client,
34
+ method: 'eth_sendTransaction',
35
+ params,
36
+ }),
37
+ personal_sign: () => handleMethodInPopup({ client, method: 'personal_sign', params }),
38
+ wallet_requestPermissions: () => handleEthRequestAccounts(client),
39
+ wallet_revokePermissions: () => handleWalletRevokePermissions(client),
40
+ wallet_switchEthereumChain: () => handleWalletSwitchEthereumChain(client, eventEmitter, params),
41
+ };
42
+ const handler = methodHandlerMap[method];
43
+ if (handler) {
44
+ return handler();
80
45
  }
81
46
  throw new viem.UnsupportedProviderMethodError(new Error('Method not implemented'), {
82
47
  method,
@@ -84,5 +49,72 @@ const createEIP1193Provider = (client) => {
84
49
  })),
85
50
  };
86
51
  };
52
+ // Utility functions
53
+ const isConnected = (client) => {
54
+ var _a, _b;
55
+ const wallets = (_b = (_a = client === null || client === void 0 ? void 0 : client.ethereum) === null || _a === void 0 ? void 0 : _a.wallets) !== null && _b !== void 0 ? _b : [];
56
+ return wallets.length > 0;
57
+ };
58
+ const getConnectedAddresses = (client) => {
59
+ var _a, _b;
60
+ const wallets = (_b = (_a = client === null || client === void 0 ? void 0 : client.ethereum) === null || _a === void 0 ? void 0 : _a.wallets) !== null && _b !== void 0 ? _b : [];
61
+ return wallets.map((wallet) => wallet.address);
62
+ };
63
+ // Method handlers
64
+ const handleEthAccounts = (client) => isConnected(client) ? getConnectedAddresses(client) : [];
65
+ const handleEthRequestAccounts = (client) => {
66
+ if (isConnected(client)) {
67
+ return getConnectedAddresses(client);
68
+ }
69
+ return client.connect({ chain: 'evm' }).then(({ address }) => [address]);
70
+ };
71
+ const handleWalletRevokePermissions = (client) => {
72
+ client.disconnect();
73
+ return null;
74
+ };
75
+ const handleEthChainId = (client) => {
76
+ if (client.ethereum.currentNetworkId) {
77
+ return viem.toHex(client.ethereum.currentNetworkId);
78
+ }
79
+ return null;
80
+ };
81
+ const handleWalletSwitchEthereumChain = (client, eventEmitter, params) => {
82
+ var _a, _b;
83
+ if (!Array.isArray(params) || params.length === 0 || !params[0].chainId) {
84
+ throw new Error('Invalid parameters for wallet_switchEthereumChain');
85
+ }
86
+ const [{ chainId }] = params;
87
+ const supportedNetworks = (_b = (_a = client === null || client === void 0 ? void 0 : client.ethereum) === null || _a === void 0 ? void 0 : _a.supportedNetworks) !== null && _b !== void 0 ? _b : [];
88
+ if (supportedNetworks.length === 0) {
89
+ throw new viem.SwitchChainError(new Error('No supported networks'));
90
+ }
91
+ if (!isNetworkSupported.isNetworkSupported(viem.fromHex(chainId, 'number'), supportedNetworks)) {
92
+ throw new viem.SwitchChainError(new Error('Chain not supported'));
93
+ }
94
+ client.ethereum.switchNetwork(viem.fromHex(chainId, 'number'));
95
+ eventEmitter.emit('chainChanged', chainId);
96
+ return null;
97
+ };
98
+ const handleMethodInPopup = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ client, method, params, }) {
99
+ if (!client.ethereum.currentNetworkId) {
100
+ throw new Error('No network id found');
101
+ }
102
+ const { data } = yield client
103
+ .invoke({
104
+ params: {
105
+ chainId: client.ethereum.currentNetworkId,
106
+ method,
107
+ params,
108
+ },
109
+ pathname: 'eth-request',
110
+ })
111
+ .catch((err) => {
112
+ if (err.message === 'Popup closed') {
113
+ throw new viem.UserRejectedRequestError(err);
114
+ }
115
+ throw err;
116
+ });
117
+ return data;
118
+ });
87
119
 
88
120
  exports.createEIP1193Provider = createEIP1193Provider;