@dynamic-labs/global-wallet-client 4.0.0-alpha.52 → 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 +79 -1
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +11 -7
- package/src/lib/actions/connectAction/createConnectAction.cjs +17 -6
- package/src/lib/actions/connectAction/createConnectAction.d.ts +2 -1
- package/src/lib/actions/connectAction/createConnectAction.js +17 -6
- package/src/lib/createGlobalWalletClient.cjs +2 -0
- package/src/lib/createGlobalWalletClient.d.ts +5 -0
- package/src/lib/createGlobalWalletClient.js +2 -0
- package/src/lib/ethereum/functions/eip1193Provider/createEIP1193Provider.cjs +86 -57
- package/src/lib/ethereum/functions/eip1193Provider/createEIP1193Provider.js +87 -58
- 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 +3 -0
- package/src/lib/functions/createEthereumModule/createEthereumModule.d.ts +1 -0
- package/src/lib/functions/createEthereumModule/createEthereumModule.js +3 -0
- package/src/lib/functions/createPopupOpener/createPopupOpener.cjs +2 -1
- package/src/lib/functions/createPopupOpener/createPopupOpener.js +2 -1
- 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/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 +24 -2
- package/src/lib/store/createClientStore.d.ts +18 -1
- package/src/lib/store/createClientStore.js +24 -2
- package/src/solana.cjs +10 -0
- package/src/solana.d.ts +1 -0
- package/src/solana.js +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,82 @@
|
|
|
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
|
+
|
|
2
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)
|
|
3
81
|
|
|
4
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)
|
|
@@ -1350,7 +1428,7 @@ There are no code changes required on the Dynamic SDK side, however if you have
|
|
|
1350
1428
|
|
|
1351
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)
|
|
1352
1430
|
|
|
1353
|
-
- 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.
|
|
1354
1432
|
|
|
1355
1433
|
|
|
1356
1434
|
## Improvements
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/global-wallet-client",
|
|
3
|
-
"version": "4.0.0
|
|
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
|
|
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
|
|
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,20 +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 {
|
|
22
|
+
const { ethereum, solana, wallets } = JSON.parse(message);
|
|
23
23
|
store.setInitialConnectionState({
|
|
24
24
|
connection: {
|
|
25
25
|
expiresAt,
|
|
26
26
|
origin: window.location.origin,
|
|
27
27
|
sharedSecret,
|
|
28
28
|
},
|
|
29
|
-
ethereum:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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,
|
|
34
41
|
});
|
|
35
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
|
+
}
|
|
36
47
|
return wallet;
|
|
37
48
|
});
|
|
38
49
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BaseWallet } from '@dynamic-labs/types';
|
|
1
2
|
import { ClientStore } from '../../store';
|
|
2
3
|
import { OpenPopup } from '../../functions/createPopupOpener/createPopupOpener';
|
|
3
4
|
import { ConnectArgs } from '../../types';
|
|
@@ -6,5 +7,5 @@ type CreateConnectActionProps = {
|
|
|
6
7
|
openPopup: OpenPopup;
|
|
7
8
|
onConnect?: () => void;
|
|
8
9
|
};
|
|
9
|
-
export declare const createConnectAction: ({ store, openPopup, onConnect }: CreateConnectActionProps) => ({ chain }: ConnectArgs) => Promise<
|
|
10
|
+
export declare const createConnectAction: ({ store, openPopup, onConnect }: CreateConnectActionProps) => ({ chain }: ConnectArgs) => Promise<BaseWallet>;
|
|
10
11
|
export {};
|
|
@@ -15,20 +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 {
|
|
18
|
+
const { ethereum, solana, wallets } = JSON.parse(message);
|
|
19
19
|
store.setInitialConnectionState({
|
|
20
20
|
connection: {
|
|
21
21
|
expiresAt,
|
|
22
22
|
origin: window.location.origin,
|
|
23
23
|
sharedSecret,
|
|
24
24
|
},
|
|
25
|
-
ethereum:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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,
|
|
30
37
|
});
|
|
31
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
|
+
}
|
|
32
43
|
return wallet;
|
|
33
44
|
});
|
|
34
45
|
|
|
@@ -9,6 +9,7 @@ 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
11
|
var createEthereumModule = require('./functions/createEthereumModule/createEthereumModule.cjs');
|
|
12
|
+
var createSolanaModule = require('./functions/createSolanaModule/createSolanaModule.cjs');
|
|
12
13
|
|
|
13
14
|
const createGlobalWalletClient = ({ environmentId, popup: popupInfo, }) => {
|
|
14
15
|
const eventEmitter = createClientEventEmitter.createClientEventEmitter();
|
|
@@ -33,6 +34,7 @@ const createGlobalWalletClient = ({ environmentId, popup: popupInfo, }) => {
|
|
|
33
34
|
once: eventEmitter.once.bind(eventEmitter),
|
|
34
35
|
removeAllListeners: eventEmitter.removeAllListeners.bind(eventEmitter),
|
|
35
36
|
removeListener: eventEmitter.removeListener.bind(eventEmitter),
|
|
37
|
+
solana: createSolanaModule.createSolanaModule({ store }),
|
|
36
38
|
get wallets() {
|
|
37
39
|
return store.wallets;
|
|
38
40
|
},
|
|
@@ -11,6 +11,7 @@ export declare const createGlobalWalletClient: ({ environmentId, popup: popupInf
|
|
|
11
11
|
readonly supportedNetworks: {
|
|
12
12
|
chainId: number;
|
|
13
13
|
}[];
|
|
14
|
+
switchNetwork: (network: number) => void;
|
|
14
15
|
readonly wallets: import("dist/packages/types/src").BaseWallet[];
|
|
15
16
|
};
|
|
16
17
|
invoke: <TPopupAction extends import("dist/packages/types/src").IPopupAction>({ params, pathname, }: {
|
|
@@ -49,6 +50,10 @@ export declare const createGlobalWalletClient: ({ environmentId, popup: popupInf
|
|
|
49
50
|
connect: () => void;
|
|
50
51
|
disconnect: () => void;
|
|
51
52
|
}, any>;
|
|
53
|
+
solana: {
|
|
54
|
+
readonly currentNetwork: string | null;
|
|
55
|
+
readonly wallets: import("dist/packages/types/src").BaseWallet[];
|
|
56
|
+
};
|
|
52
57
|
readonly wallets: import("dist/packages/types/src").BaseWallet[];
|
|
53
58
|
};
|
|
54
59
|
export type GlobalWalletClient = ReturnType<typeof createGlobalWalletClient>;
|
|
@@ -5,6 +5,7 @@ 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
7
|
import { createEthereumModule } from './functions/createEthereumModule/createEthereumModule.js';
|
|
8
|
+
import { createSolanaModule } from './functions/createSolanaModule/createSolanaModule.js';
|
|
8
9
|
|
|
9
10
|
const createGlobalWalletClient = ({ environmentId, popup: popupInfo, }) => {
|
|
10
11
|
const eventEmitter = createClientEventEmitter();
|
|
@@ -29,6 +30,7 @@ const createGlobalWalletClient = ({ environmentId, popup: popupInfo, }) => {
|
|
|
29
30
|
once: eventEmitter.once.bind(eventEmitter),
|
|
30
31
|
removeAllListeners: eventEmitter.removeAllListeners.bind(eventEmitter),
|
|
31
32
|
removeListener: eventEmitter.removeListener.bind(eventEmitter),
|
|
33
|
+
solana: createSolanaModule({ store }),
|
|
32
34
|
get wallets() {
|
|
33
35
|
return store.wallets;
|
|
34
36
|
},
|
|
@@ -6,13 +6,12 @@ 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
|
-
|
|
15
|
-
const currentNetwork = (_a = client.ethereum) === null || _a === void 0 ? void 0 : _a.currentNetworkId;
|
|
14
|
+
const currentNetwork = client.ethereum.currentNetworkId;
|
|
16
15
|
if (!currentNetwork)
|
|
17
16
|
return;
|
|
18
17
|
eventEmitter.emit('connect', {
|
|
@@ -26,60 +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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
if ((_d = client.ethereum) === null || _d === void 0 ? void 0 : _d.currentNetworkId) {
|
|
59
|
-
return viem.toHex((_e = client.ethereum) === null || _e === void 0 ? void 0 : _e.currentNetworkId);
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Opens the popup to request user confirmation for the request
|
|
65
|
-
* and to execute the request
|
|
66
|
-
*/
|
|
67
|
-
if (methodsHandledByPopup.includes(method) && params) {
|
|
68
|
-
const { data } = yield client
|
|
69
|
-
.invoke({
|
|
70
|
-
params: {
|
|
71
|
-
method,
|
|
72
|
-
params,
|
|
73
|
-
},
|
|
74
|
-
pathname: 'eth-request',
|
|
75
|
-
})
|
|
76
|
-
.catch((err) => {
|
|
77
|
-
if (err.message === 'Popup closed') {
|
|
78
|
-
throw new viem.UserRejectedRequestError(err);
|
|
79
|
-
}
|
|
80
|
-
throw err;
|
|
81
|
-
});
|
|
82
|
-
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();
|
|
83
45
|
}
|
|
84
46
|
throw new viem.UnsupportedProviderMethodError(new Error('Method not implemented'), {
|
|
85
47
|
method,
|
|
@@ -87,5 +49,72 @@ const createEIP1193Provider = (client) => {
|
|
|
87
49
|
})),
|
|
88
50
|
};
|
|
89
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
|
+
});
|
|
90
119
|
|
|
91
120
|
exports.createEIP1193Provider = createEIP1193Provider;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../../../../../_virtual/_tslib.js';
|
|
3
|
-
import { toHex, ProviderDisconnectedError,
|
|
3
|
+
import { toHex, ProviderDisconnectedError, UnsupportedProviderMethodError, SwitchChainError, fromHex, UserRejectedRequestError } from 'viem';
|
|
4
4
|
import { EventEmitter } from 'eventemitter3';
|
|
5
|
+
import { isNetworkSupported } from '../isNetworkSupported/isNetworkSupported.js';
|
|
5
6
|
|
|
6
|
-
const methodsHandledByPopup = ['personal_sign', 'eth_sendTransaction'];
|
|
7
7
|
const createEIP1193Provider = (client) => {
|
|
8
8
|
const eventEmitter = new EventEmitter();
|
|
9
9
|
client.on('connect', () => {
|
|
10
|
-
|
|
11
|
-
const currentNetwork = (_a = client.ethereum) === null || _a === void 0 ? void 0 : _a.currentNetworkId;
|
|
10
|
+
const currentNetwork = client.ethereum.currentNetworkId;
|
|
12
11
|
if (!currentNetwork)
|
|
13
12
|
return;
|
|
14
13
|
eventEmitter.emit('connect', {
|
|
@@ -22,60 +21,23 @@ const createEIP1193Provider = (client) => {
|
|
|
22
21
|
on: eventEmitter.on.bind(eventEmitter),
|
|
23
22
|
removeListener: eventEmitter.removeListener.bind(eventEmitter),
|
|
24
23
|
request: ((_a) => __awaiter(void 0, [_a], void 0, function* ({ method, params }) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
client.disconnect();
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
if (method === 'wallet_requestPermissions') {
|
|
46
|
-
if (isConnected) {
|
|
47
|
-
return connectedAddresses;
|
|
48
|
-
}
|
|
49
|
-
return client
|
|
50
|
-
.connect({ chain: 'evm' })
|
|
51
|
-
.then(({ address }) => [address]);
|
|
52
|
-
}
|
|
53
|
-
if (method === 'eth_chainId') {
|
|
54
|
-
if ((_d = client.ethereum) === null || _d === void 0 ? void 0 : _d.currentNetworkId) {
|
|
55
|
-
return toHex((_e = client.ethereum) === null || _e === void 0 ? void 0 : _e.currentNetworkId);
|
|
56
|
-
}
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Opens the popup to request user confirmation for the request
|
|
61
|
-
* and to execute the request
|
|
62
|
-
*/
|
|
63
|
-
if (methodsHandledByPopup.includes(method) && params) {
|
|
64
|
-
const { data } = yield client
|
|
65
|
-
.invoke({
|
|
66
|
-
params: {
|
|
67
|
-
method,
|
|
68
|
-
params,
|
|
69
|
-
},
|
|
70
|
-
pathname: 'eth-request',
|
|
71
|
-
})
|
|
72
|
-
.catch((err) => {
|
|
73
|
-
if (err.message === 'Popup closed') {
|
|
74
|
-
throw new UserRejectedRequestError(err);
|
|
75
|
-
}
|
|
76
|
-
throw err;
|
|
77
|
-
});
|
|
78
|
-
return data;
|
|
24
|
+
const methodHandlerMap = {
|
|
25
|
+
eth_accounts: () => handleEthAccounts(client),
|
|
26
|
+
eth_chainId: () => handleEthChainId(client),
|
|
27
|
+
eth_requestAccounts: () => handleEthRequestAccounts(client),
|
|
28
|
+
eth_sendTransaction: () => handleMethodInPopup({
|
|
29
|
+
client,
|
|
30
|
+
method: 'eth_sendTransaction',
|
|
31
|
+
params,
|
|
32
|
+
}),
|
|
33
|
+
personal_sign: () => handleMethodInPopup({ client, method: 'personal_sign', params }),
|
|
34
|
+
wallet_requestPermissions: () => handleEthRequestAccounts(client),
|
|
35
|
+
wallet_revokePermissions: () => handleWalletRevokePermissions(client),
|
|
36
|
+
wallet_switchEthereumChain: () => handleWalletSwitchEthereumChain(client, eventEmitter, params),
|
|
37
|
+
};
|
|
38
|
+
const handler = methodHandlerMap[method];
|
|
39
|
+
if (handler) {
|
|
40
|
+
return handler();
|
|
79
41
|
}
|
|
80
42
|
throw new UnsupportedProviderMethodError(new Error('Method not implemented'), {
|
|
81
43
|
method,
|
|
@@ -83,5 +45,72 @@ const createEIP1193Provider = (client) => {
|
|
|
83
45
|
})),
|
|
84
46
|
};
|
|
85
47
|
};
|
|
48
|
+
// Utility functions
|
|
49
|
+
const isConnected = (client) => {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
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 : [];
|
|
52
|
+
return wallets.length > 0;
|
|
53
|
+
};
|
|
54
|
+
const getConnectedAddresses = (client) => {
|
|
55
|
+
var _a, _b;
|
|
56
|
+
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 : [];
|
|
57
|
+
return wallets.map((wallet) => wallet.address);
|
|
58
|
+
};
|
|
59
|
+
// Method handlers
|
|
60
|
+
const handleEthAccounts = (client) => isConnected(client) ? getConnectedAddresses(client) : [];
|
|
61
|
+
const handleEthRequestAccounts = (client) => {
|
|
62
|
+
if (isConnected(client)) {
|
|
63
|
+
return getConnectedAddresses(client);
|
|
64
|
+
}
|
|
65
|
+
return client.connect({ chain: 'evm' }).then(({ address }) => [address]);
|
|
66
|
+
};
|
|
67
|
+
const handleWalletRevokePermissions = (client) => {
|
|
68
|
+
client.disconnect();
|
|
69
|
+
return null;
|
|
70
|
+
};
|
|
71
|
+
const handleEthChainId = (client) => {
|
|
72
|
+
if (client.ethereum.currentNetworkId) {
|
|
73
|
+
return toHex(client.ethereum.currentNetworkId);
|
|
74
|
+
}
|
|
75
|
+
return null;
|
|
76
|
+
};
|
|
77
|
+
const handleWalletSwitchEthereumChain = (client, eventEmitter, params) => {
|
|
78
|
+
var _a, _b;
|
|
79
|
+
if (!Array.isArray(params) || params.length === 0 || !params[0].chainId) {
|
|
80
|
+
throw new Error('Invalid parameters for wallet_switchEthereumChain');
|
|
81
|
+
}
|
|
82
|
+
const [{ chainId }] = params;
|
|
83
|
+
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 : [];
|
|
84
|
+
if (supportedNetworks.length === 0) {
|
|
85
|
+
throw new SwitchChainError(new Error('No supported networks'));
|
|
86
|
+
}
|
|
87
|
+
if (!isNetworkSupported(fromHex(chainId, 'number'), supportedNetworks)) {
|
|
88
|
+
throw new SwitchChainError(new Error('Chain not supported'));
|
|
89
|
+
}
|
|
90
|
+
client.ethereum.switchNetwork(fromHex(chainId, 'number'));
|
|
91
|
+
eventEmitter.emit('chainChanged', chainId);
|
|
92
|
+
return null;
|
|
93
|
+
};
|
|
94
|
+
const handleMethodInPopup = (_a) => __awaiter(void 0, [_a], void 0, function* ({ client, method, params, }) {
|
|
95
|
+
if (!client.ethereum.currentNetworkId) {
|
|
96
|
+
throw new Error('No network id found');
|
|
97
|
+
}
|
|
98
|
+
const { data } = yield client
|
|
99
|
+
.invoke({
|
|
100
|
+
params: {
|
|
101
|
+
chainId: client.ethereum.currentNetworkId,
|
|
102
|
+
method,
|
|
103
|
+
params,
|
|
104
|
+
},
|
|
105
|
+
pathname: 'eth-request',
|
|
106
|
+
})
|
|
107
|
+
.catch((err) => {
|
|
108
|
+
if (err.message === 'Popup closed') {
|
|
109
|
+
throw new UserRejectedRequestError(err);
|
|
110
|
+
}
|
|
111
|
+
throw err;
|
|
112
|
+
});
|
|
113
|
+
return data;
|
|
114
|
+
});
|
|
86
115
|
|
|
87
116
|
export { createEIP1193Provider };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { isNetworkSupported } from './isNetworkSupported';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
+
|
|
6
|
+
const isNetworkSupported = (chainId, supportedNetworks) => supportedNetworks.some((network) => network.chainId === chainId);
|
|
7
|
+
|
|
8
|
+
exports.isNetworkSupported = isNetworkSupported;
|
|
@@ -12,6 +12,9 @@ const createEthereumModule = ({ store }) => ({
|
|
|
12
12
|
var _a, _b;
|
|
13
13
|
return (_b = (_a = store.ethereum) === null || _a === void 0 ? void 0 : _a.supportedNetworks) !== null && _b !== void 0 ? _b : [];
|
|
14
14
|
},
|
|
15
|
+
switchNetwork: (network) => {
|
|
16
|
+
store.switchEthereumNetwork(network);
|
|
17
|
+
},
|
|
15
18
|
get wallets() {
|
|
16
19
|
var _a;
|
|
17
20
|
return (_a = store.wallets.filter(({ chain }) => chain === 'EVM')) !== null && _a !== void 0 ? _a : [];
|