@dynamic-labs/embedded-wallet-solana 4.7.2 → 4.8.1
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 +21 -0
- package/package.cjs +4 -4
- package/package.js +4 -4
- package/package.json +11 -11
- package/src/lib/TurnkeySolanaWalletConnector/TurnkeySolanaWalletConnector.cjs +70 -25
- package/src/lib/TurnkeySolanaWalletConnector/TurnkeySolanaWalletConnector.d.ts +6 -2
- package/src/lib/TurnkeySolanaWalletConnector/TurnkeySolanaWalletConnector.js +71 -26
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,25 @@
|
|
|
1
1
|
|
|
2
|
+
### [4.8.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.8.0...v4.8.1) (2025-02-25)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Bug Fixes
|
|
6
|
+
|
|
7
|
+
* wc redirect for safari inside iframe ([#8131](https://github.com/dynamic-labs/dynamic-auth/issues/8131)) ([8c74bea](https://github.com/dynamic-labs/dynamic-auth/commit/8c74beae505014eb85be4fd211909709d0a339dd))
|
|
8
|
+
|
|
9
|
+
## [4.8.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.7.2...v4.8.0) (2025-02-25)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* add support for network switching for SOL wallets ([#8095](https://github.com/dynamic-labs/dynamic-auth/issues/8095)) ([8997b39](https://github.com/dynamic-labs/dynamic-auth/commit/8997b399e1e5cd294aad8b719d39928eed5e911d))
|
|
15
|
+
* add support for solNetworks override ([#8138](https://github.com/dynamic-labs/dynamic-auth/issues/8138)) ([8c3f374](https://github.com/dynamic-labs/dynamic-auth/commit/8c3f374a9b2b451f984aed98e7ce506552e2a6c5))
|
|
16
|
+
* **react-native:** add account abstraction multi-chain ([#8132](https://github.com/dynamic-labs/dynamic-auth/issues/8132)) ([c64a26e](https://github.com/dynamic-labs/dynamic-auth/commit/c64a26e16943d913edf4683084f59592a9aeedfc))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Bug Fixes
|
|
20
|
+
|
|
21
|
+
* ensure zero dev network cache use project id ([#8133](https://github.com/dynamic-labs/dynamic-auth/issues/8133)) ([408c4ed](https://github.com/dynamic-labs/dynamic-auth/commit/408c4ed764a623b6d870cd24973320e5ca4a74c7))
|
|
22
|
+
|
|
2
23
|
### [4.7.2](https://github.com/dynamic-labs/dynamic-auth/compare/v4.7.1...v4.7.2) (2025-02-22)
|
|
3
24
|
|
|
4
25
|
### Features
|
package/package.cjs
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
5
|
|
|
6
|
-
var version = "4.
|
|
6
|
+
var version = "4.8.1";
|
|
7
7
|
var dependencies = {
|
|
8
|
-
"@dynamic-labs/utils": "4.
|
|
9
|
-
"@dynamic-labs/logger": "4.
|
|
10
|
-
"@dynamic-labs/types": "4.
|
|
8
|
+
"@dynamic-labs/utils": "4.8.1",
|
|
9
|
+
"@dynamic-labs/logger": "4.8.1",
|
|
10
|
+
"@dynamic-labs/types": "4.8.1",
|
|
11
11
|
"@dynamic-labs/sdk-api-core": "0.0.628",
|
|
12
12
|
eventemitter3: "5.0.1",
|
|
13
13
|
"@solana/web3.js": "1.92.1",
|
package/package.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client'
|
|
2
|
-
var version = "4.
|
|
2
|
+
var version = "4.8.1";
|
|
3
3
|
var dependencies = {
|
|
4
|
-
"@dynamic-labs/utils": "4.
|
|
5
|
-
"@dynamic-labs/logger": "4.
|
|
6
|
-
"@dynamic-labs/types": "4.
|
|
4
|
+
"@dynamic-labs/utils": "4.8.1",
|
|
5
|
+
"@dynamic-labs/logger": "4.8.1",
|
|
6
|
+
"@dynamic-labs/types": "4.8.1",
|
|
7
7
|
"@dynamic-labs/sdk-api-core": "0.0.628",
|
|
8
8
|
eventemitter3: "5.0.1",
|
|
9
9
|
"@solana/web3.js": "1.92.1",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/embedded-wallet-solana",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.8.1",
|
|
4
4
|
"description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
|
|
5
5
|
"author": "Dynamic Labs, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,22 +18,22 @@
|
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://www.dynamic.xyz/",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dynamic-labs/utils": "4.
|
|
22
|
-
"@dynamic-labs/logger": "4.
|
|
23
|
-
"@dynamic-labs/types": "4.
|
|
21
|
+
"@dynamic-labs/utils": "4.8.1",
|
|
22
|
+
"@dynamic-labs/logger": "4.8.1",
|
|
23
|
+
"@dynamic-labs/types": "4.8.1",
|
|
24
24
|
"@dynamic-labs/sdk-api-core": "0.0.628",
|
|
25
25
|
"eventemitter3": "5.0.1",
|
|
26
26
|
"@solana/web3.js": "1.92.1",
|
|
27
27
|
"@turnkey/iframe-stamper": "2.0.0",
|
|
28
28
|
"@turnkey/solana": "1.0.1",
|
|
29
29
|
"@turnkey/webauthn-stamper": "0.5.0",
|
|
30
|
-
"@dynamic-labs/assert-package-version": "4.
|
|
31
|
-
"@dynamic-labs/embedded-wallet": "4.
|
|
32
|
-
"@dynamic-labs/rpc-providers": "4.
|
|
33
|
-
"@dynamic-labs/solana-core": "4.
|
|
34
|
-
"@dynamic-labs/wallet-book": "4.
|
|
35
|
-
"@dynamic-labs/wallet-connector-core": "4.
|
|
36
|
-
"@dynamic-labs/webauthn": "4.
|
|
30
|
+
"@dynamic-labs/assert-package-version": "4.8.1",
|
|
31
|
+
"@dynamic-labs/embedded-wallet": "4.8.1",
|
|
32
|
+
"@dynamic-labs/rpc-providers": "4.8.1",
|
|
33
|
+
"@dynamic-labs/solana-core": "4.8.1",
|
|
34
|
+
"@dynamic-labs/wallet-book": "4.8.1",
|
|
35
|
+
"@dynamic-labs/wallet-connector-core": "4.8.1",
|
|
36
|
+
"@dynamic-labs/webauthn": "4.8.1",
|
|
37
37
|
"react-dom": "18.2.0",
|
|
38
38
|
"viem": "2.21.57"
|
|
39
39
|
},
|
|
@@ -45,61 +45,97 @@ class TurnkeySolanaWalletConnector extends embeddedWallet.TurnkeyWalletConnector
|
|
|
45
45
|
this.solNetworks = solanaCore.getBackwardsCompatibleSolNetworks(props.solNetworks, props.connectionConfig);
|
|
46
46
|
this.walletUiUtils = props.walletUiUtils;
|
|
47
47
|
this._turnkeyAccount = undefined;
|
|
48
|
-
this._connectionClient = undefined;
|
|
49
48
|
this.connectionConfig = props.connectionConfig;
|
|
50
49
|
this.chainRpcProviders = props.chainRpcProviders;
|
|
51
50
|
(_a = this.chainRpcProviders) === null || _a === void 0 ? void 0 : _a.registerSolanaProviders(this.connectionConfig);
|
|
52
51
|
this.__turnkeyClient = this.getTurnkeyClient();
|
|
53
52
|
}
|
|
54
53
|
getRpcUrl() {
|
|
55
|
-
const
|
|
54
|
+
const network = this.getSelectedNetwork();
|
|
56
55
|
if (!network) {
|
|
57
56
|
throw new utils.DynamicError('No enabled networks');
|
|
58
57
|
}
|
|
59
58
|
return solanaCore.getOverrideRpcUrlForNetwork(this.connectionConfig, network);
|
|
60
59
|
}
|
|
61
60
|
getConnection(commitmentOrConfig) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
this._connectionClient = createSolanaConnection.createSolanaConnection(rpcUrl, config);
|
|
69
|
-
}
|
|
70
|
-
return this._connectionClient;
|
|
61
|
+
const rpcUrl = this.getRpcUrl();
|
|
62
|
+
if (!rpcUrl)
|
|
63
|
+
throw new utils.DynamicError('No rpcUrl');
|
|
64
|
+
const config = typeof commitmentOrConfig === 'string'
|
|
65
|
+
? Object.assign(Object.assign({}, this.connectionConfig), { commitment: commitmentOrConfig }) : Object.assign(Object.assign({}, this.connectionConfig), commitmentOrConfig);
|
|
66
|
+
return createSolanaConnection.createSolanaConnection(rpcUrl, config);
|
|
71
67
|
}
|
|
72
68
|
getWalletClient() {
|
|
73
69
|
return this.getConnection();
|
|
74
70
|
}
|
|
71
|
+
getNetworkId() {
|
|
72
|
+
var _a;
|
|
73
|
+
const defaultChainId = (_a = this.solNetworks[0]) === null || _a === void 0 ? void 0 : _a.networkId.toString();
|
|
74
|
+
const storedChainId = localStorage.getItem(solanaCore.DYNAMIC_SVM_NETWORK_ID_LS_KEY);
|
|
75
|
+
return storedChainId !== null && storedChainId !== void 0 ? storedChainId : defaultChainId;
|
|
76
|
+
}
|
|
77
|
+
setNetworkId(networkId) {
|
|
78
|
+
if (!networkId) {
|
|
79
|
+
localStorage.removeItem(solanaCore.DYNAMIC_SVM_NETWORK_ID_LS_KEY);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
localStorage.setItem(solanaCore.DYNAMIC_SVM_NETWORK_ID_LS_KEY, networkId);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
getSelectedNetwork() {
|
|
86
|
+
const selectedNetwork = this.solNetworks.find((network) => network.networkId.toString() === this.getNetworkId());
|
|
87
|
+
return selectedNetwork;
|
|
88
|
+
}
|
|
75
89
|
/**
|
|
76
90
|
* @param returnDynamicNetworkId - If true, the dynamic network ID will be returned instead of the network cluster
|
|
77
91
|
* @returns The network cluster (e.g. 'mainnet', 'testnet', 'devnet') or dynamic network (used for switching networks)
|
|
78
92
|
*/
|
|
79
93
|
getNetwork() {
|
|
80
94
|
return _tslib.__awaiter(this, arguments, void 0, function* (returnDynamicNetworkId = false) {
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
95
|
+
const network = this.getSelectedNetwork();
|
|
96
|
+
if (!network) {
|
|
97
|
+
return '';
|
|
98
|
+
}
|
|
99
|
+
const { networkId, genesisHash } = network;
|
|
100
|
+
if (returnDynamicNetworkId) {
|
|
101
|
+
return networkId.toString();
|
|
86
102
|
}
|
|
87
|
-
|
|
88
|
-
// see: https://github.com/ChainAgnostic/namespaces/blob/main/solana/caip2.md
|
|
103
|
+
// to keep backward compatibility with old network values
|
|
89
104
|
if (genesisHash === '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp') {
|
|
90
|
-
return
|
|
105
|
+
return 'mainnet';
|
|
106
|
+
}
|
|
107
|
+
if (genesisHash === '4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2K') {
|
|
108
|
+
return 'testnet';
|
|
91
109
|
}
|
|
92
110
|
if (genesisHash === 'EtWTRABZaYq6iMfeYKouRu166VU2xqa1') {
|
|
93
|
-
return
|
|
111
|
+
return 'devnet';
|
|
94
112
|
}
|
|
95
|
-
|
|
113
|
+
// if it's not one of the main solana networks, return the network id
|
|
114
|
+
// this should be ok because we didn't have support for other SVM networks before
|
|
115
|
+
return networkId.toString();
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
switchNetwork(_a) {
|
|
119
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ networkChainId, }) {
|
|
120
|
+
if (!networkChainId)
|
|
121
|
+
return;
|
|
122
|
+
const networkIdString = networkChainId.toString();
|
|
123
|
+
const isNetworkIdValid = this.solNetworks.some((network) => network.networkId.toString() === networkIdString);
|
|
124
|
+
if (!isNetworkIdValid) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
this.setNetworkId(networkIdString);
|
|
128
|
+
this.emit('chainChange', { chain: networkIdString });
|
|
96
129
|
});
|
|
97
130
|
}
|
|
98
131
|
getPublicClient() {
|
|
99
132
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
100
133
|
var _a;
|
|
101
|
-
|
|
134
|
+
const network = this.getSelectedNetwork();
|
|
135
|
+
if (!network) {
|
|
102
136
|
return;
|
|
137
|
+
}
|
|
138
|
+
const networkId = network.networkId.toString();
|
|
103
139
|
const configurations = {
|
|
104
140
|
cosmos: [],
|
|
105
141
|
evm: undefined,
|
|
@@ -109,11 +145,11 @@ class TurnkeySolanaWalletConnector extends embeddedWallet.TurnkeyWalletConnector
|
|
|
109
145
|
if (!this.chainRpcProviders)
|
|
110
146
|
return undefined;
|
|
111
147
|
const providers = this.chainRpcProviders.getProviders(configurations);
|
|
112
|
-
return (_a = this.chainRpcProviders.getSolanaProviderByChainId(providers,
|
|
148
|
+
return (_a = this.chainRpcProviders.getSolanaProviderByChainId(providers, networkId)) === null || _a === void 0 ? void 0 : _a.provider;
|
|
113
149
|
});
|
|
114
150
|
}
|
|
115
151
|
supportsNetworkSwitching() {
|
|
116
|
-
return
|
|
152
|
+
return true;
|
|
117
153
|
}
|
|
118
154
|
setVerifiedCredentials(verifiedCredentials) {
|
|
119
155
|
const turnkeyVerifiedCredentials = embeddedWallet.findTurnkeyVerifiedCredentials(verifiedCredentials, solanaCore.ProviderChain.SOLANA);
|
|
@@ -147,7 +183,7 @@ class TurnkeySolanaWalletConnector extends embeddedWallet.TurnkeyWalletConnector
|
|
|
147
183
|
}
|
|
148
184
|
endSession() {
|
|
149
185
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
150
|
-
|
|
186
|
+
this.setNetworkId(null);
|
|
151
187
|
});
|
|
152
188
|
}
|
|
153
189
|
refreshTurnkeyAccount() {
|
|
@@ -452,6 +488,15 @@ class TurnkeySolanaWalletConnector extends embeddedWallet.TurnkeyWalletConnector
|
|
|
452
488
|
return optimizedTransaction;
|
|
453
489
|
});
|
|
454
490
|
}
|
|
491
|
+
getBlockExplorerUrlsForCurrentNetwork() {
|
|
492
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
493
|
+
const network = this.getSelectedNetwork();
|
|
494
|
+
if (!network) {
|
|
495
|
+
return [];
|
|
496
|
+
}
|
|
497
|
+
return network.blockExplorerUrls;
|
|
498
|
+
});
|
|
499
|
+
}
|
|
455
500
|
getEnabledNetworks() {
|
|
456
501
|
return this.solNetworks;
|
|
457
502
|
}
|
|
@@ -3,7 +3,7 @@ import { GenericNetwork, IUITransaction, WalletUiUtils } from '@dynamic-labs/typ
|
|
|
3
3
|
import { Chain, ISendBalanceWalletConnector, InternalWalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
4
4
|
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
5
5
|
import { JwtVerifiedCredential } from '@dynamic-labs/sdk-api-core';
|
|
6
|
-
import { IChainRpcProviders, SolanaWallet } from '@dynamic-labs/solana-core';
|
|
6
|
+
import { IChainRpcProviders, SolanaWallet, SwitchNetworkOps } from '@dynamic-labs/solana-core';
|
|
7
7
|
import { TurnkeyWalletConnectorBase, TurnkeyWalletConnectorNameAndKey } from '@dynamic-labs/embedded-wallet';
|
|
8
8
|
import { TurnkeySolanaSigner } from './TurnkeySolanaSigner';
|
|
9
9
|
type SendTransactionOptions = ConfirmOptions & {
|
|
@@ -25,17 +25,20 @@ export declare class TurnkeySolanaWalletConnector extends TurnkeyWalletConnector
|
|
|
25
25
|
verifiedCredentialChain: string;
|
|
26
26
|
private walletUiUtils;
|
|
27
27
|
private _turnkeyAccount;
|
|
28
|
-
private _connectionClient;
|
|
29
28
|
private connectionConfig;
|
|
30
29
|
constructor(nameAndKey: TurnkeyWalletConnectorNameAndKey, props: TurnkeySolanaConnectorProps);
|
|
31
30
|
getRpcUrl(): string;
|
|
32
31
|
getConnection(commitmentOrConfig?: Commitment | ConnectionConfig): Connection;
|
|
33
32
|
getWalletClient(): Connection;
|
|
33
|
+
getNetworkId(): string;
|
|
34
|
+
setNetworkId(networkId: string | null): void;
|
|
35
|
+
getSelectedNetwork(): GenericNetwork | undefined;
|
|
34
36
|
/**
|
|
35
37
|
* @param returnDynamicNetworkId - If true, the dynamic network ID will be returned instead of the network cluster
|
|
36
38
|
* @returns The network cluster (e.g. 'mainnet', 'testnet', 'devnet') or dynamic network (used for switching networks)
|
|
37
39
|
*/
|
|
38
40
|
getNetwork(returnDynamicNetworkId?: boolean): Promise<string>;
|
|
41
|
+
switchNetwork({ networkChainId, }: SwitchNetworkOps): Promise<void>;
|
|
39
42
|
getPublicClient(): Promise<Connection | undefined>;
|
|
40
43
|
supportsNetworkSwitching(): boolean;
|
|
41
44
|
setVerifiedCredentials(verifiedCredentials: JwtVerifiedCredential[]): void;
|
|
@@ -60,6 +63,7 @@ export declare class TurnkeySolanaWalletConnector extends TurnkeyWalletConnector
|
|
|
60
63
|
sendTransaction<T extends Transaction | VersionedTransaction>(transaction: T, connection: Connection, options?: SendTransactionOptions): Promise<string>;
|
|
61
64
|
private lamportsToSol;
|
|
62
65
|
private optimizeTransaction;
|
|
66
|
+
getBlockExplorerUrlsForCurrentNetwork(): Promise<string[]>;
|
|
63
67
|
getEnabledNetworks(): GenericNetwork[];
|
|
64
68
|
}
|
|
65
69
|
export {};
|
|
@@ -6,7 +6,7 @@ import { TurnkeySigner } from '@turnkey/solana';
|
|
|
6
6
|
import { IframeStamper } from '@turnkey/iframe-stamper';
|
|
7
7
|
import { isSameAddress } from '@dynamic-labs/wallet-connector-core';
|
|
8
8
|
import { DynamicError, bufferToBase64 } from '@dynamic-labs/utils';
|
|
9
|
-
import { SolanaWallet, getBackwardsCompatibleSolNetworks, getOverrideRpcUrlForNetwork,
|
|
9
|
+
import { SolanaWallet, getBackwardsCompatibleSolNetworks, getOverrideRpcUrlForNetwork, DYNAMIC_SVM_NETWORK_ID_LS_KEY, ProviderChain, SolanaUiTransaction, isTxAlreadySigned } from '@dynamic-labs/solana-core';
|
|
10
10
|
import { TurnkeyWalletConnectorBase, findTurnkeyVerifiedCredentials, TURNKEY_SDK_SESSION_KEY_RETRYABLE_ERRORS, logger } from '@dynamic-labs/embedded-wallet';
|
|
11
11
|
import { createSolanaConnection } from '../utils/createSolanaConnection/createSolanaConnection.js';
|
|
12
12
|
import { optimizeSolanaTransaction } from '../utils/api/api.js';
|
|
@@ -41,61 +41,97 @@ class TurnkeySolanaWalletConnector extends TurnkeyWalletConnectorBase {
|
|
|
41
41
|
this.solNetworks = getBackwardsCompatibleSolNetworks(props.solNetworks, props.connectionConfig);
|
|
42
42
|
this.walletUiUtils = props.walletUiUtils;
|
|
43
43
|
this._turnkeyAccount = undefined;
|
|
44
|
-
this._connectionClient = undefined;
|
|
45
44
|
this.connectionConfig = props.connectionConfig;
|
|
46
45
|
this.chainRpcProviders = props.chainRpcProviders;
|
|
47
46
|
(_a = this.chainRpcProviders) === null || _a === void 0 ? void 0 : _a.registerSolanaProviders(this.connectionConfig);
|
|
48
47
|
this.__turnkeyClient = this.getTurnkeyClient();
|
|
49
48
|
}
|
|
50
49
|
getRpcUrl() {
|
|
51
|
-
const
|
|
50
|
+
const network = this.getSelectedNetwork();
|
|
52
51
|
if (!network) {
|
|
53
52
|
throw new DynamicError('No enabled networks');
|
|
54
53
|
}
|
|
55
54
|
return getOverrideRpcUrlForNetwork(this.connectionConfig, network);
|
|
56
55
|
}
|
|
57
56
|
getConnection(commitmentOrConfig) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
this._connectionClient = createSolanaConnection(rpcUrl, config);
|
|
65
|
-
}
|
|
66
|
-
return this._connectionClient;
|
|
57
|
+
const rpcUrl = this.getRpcUrl();
|
|
58
|
+
if (!rpcUrl)
|
|
59
|
+
throw new DynamicError('No rpcUrl');
|
|
60
|
+
const config = typeof commitmentOrConfig === 'string'
|
|
61
|
+
? Object.assign(Object.assign({}, this.connectionConfig), { commitment: commitmentOrConfig }) : Object.assign(Object.assign({}, this.connectionConfig), commitmentOrConfig);
|
|
62
|
+
return createSolanaConnection(rpcUrl, config);
|
|
67
63
|
}
|
|
68
64
|
getWalletClient() {
|
|
69
65
|
return this.getConnection();
|
|
70
66
|
}
|
|
67
|
+
getNetworkId() {
|
|
68
|
+
var _a;
|
|
69
|
+
const defaultChainId = (_a = this.solNetworks[0]) === null || _a === void 0 ? void 0 : _a.networkId.toString();
|
|
70
|
+
const storedChainId = localStorage.getItem(DYNAMIC_SVM_NETWORK_ID_LS_KEY);
|
|
71
|
+
return storedChainId !== null && storedChainId !== void 0 ? storedChainId : defaultChainId;
|
|
72
|
+
}
|
|
73
|
+
setNetworkId(networkId) {
|
|
74
|
+
if (!networkId) {
|
|
75
|
+
localStorage.removeItem(DYNAMIC_SVM_NETWORK_ID_LS_KEY);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
localStorage.setItem(DYNAMIC_SVM_NETWORK_ID_LS_KEY, networkId);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
getSelectedNetwork() {
|
|
82
|
+
const selectedNetwork = this.solNetworks.find((network) => network.networkId.toString() === this.getNetworkId());
|
|
83
|
+
return selectedNetwork;
|
|
84
|
+
}
|
|
71
85
|
/**
|
|
72
86
|
* @param returnDynamicNetworkId - If true, the dynamic network ID will be returned instead of the network cluster
|
|
73
87
|
* @returns The network cluster (e.g. 'mainnet', 'testnet', 'devnet') or dynamic network (used for switching networks)
|
|
74
88
|
*/
|
|
75
89
|
getNetwork() {
|
|
76
90
|
return __awaiter(this, arguments, void 0, function* (returnDynamicNetworkId = false) {
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
91
|
+
const network = this.getSelectedNetwork();
|
|
92
|
+
if (!network) {
|
|
93
|
+
return '';
|
|
94
|
+
}
|
|
95
|
+
const { networkId, genesisHash } = network;
|
|
96
|
+
if (returnDynamicNetworkId) {
|
|
97
|
+
return networkId.toString();
|
|
82
98
|
}
|
|
83
|
-
|
|
84
|
-
// see: https://github.com/ChainAgnostic/namespaces/blob/main/solana/caip2.md
|
|
99
|
+
// to keep backward compatibility with old network values
|
|
85
100
|
if (genesisHash === '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp') {
|
|
86
|
-
return
|
|
101
|
+
return 'mainnet';
|
|
102
|
+
}
|
|
103
|
+
if (genesisHash === '4uhcVJyU9pJkvQyS88uRDiswHXSCkY3zQawwpjk2K') {
|
|
104
|
+
return 'testnet';
|
|
87
105
|
}
|
|
88
106
|
if (genesisHash === 'EtWTRABZaYq6iMfeYKouRu166VU2xqa1') {
|
|
89
|
-
return
|
|
107
|
+
return 'devnet';
|
|
90
108
|
}
|
|
91
|
-
|
|
109
|
+
// if it's not one of the main solana networks, return the network id
|
|
110
|
+
// this should be ok because we didn't have support for other SVM networks before
|
|
111
|
+
return networkId.toString();
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
switchNetwork(_a) {
|
|
115
|
+
return __awaiter(this, arguments, void 0, function* ({ networkChainId, }) {
|
|
116
|
+
if (!networkChainId)
|
|
117
|
+
return;
|
|
118
|
+
const networkIdString = networkChainId.toString();
|
|
119
|
+
const isNetworkIdValid = this.solNetworks.some((network) => network.networkId.toString() === networkIdString);
|
|
120
|
+
if (!isNetworkIdValid) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
this.setNetworkId(networkIdString);
|
|
124
|
+
this.emit('chainChange', { chain: networkIdString });
|
|
92
125
|
});
|
|
93
126
|
}
|
|
94
127
|
getPublicClient() {
|
|
95
128
|
return __awaiter(this, void 0, void 0, function* () {
|
|
96
129
|
var _a;
|
|
97
|
-
|
|
130
|
+
const network = this.getSelectedNetwork();
|
|
131
|
+
if (!network) {
|
|
98
132
|
return;
|
|
133
|
+
}
|
|
134
|
+
const networkId = network.networkId.toString();
|
|
99
135
|
const configurations = {
|
|
100
136
|
cosmos: [],
|
|
101
137
|
evm: undefined,
|
|
@@ -105,11 +141,11 @@ class TurnkeySolanaWalletConnector extends TurnkeyWalletConnectorBase {
|
|
|
105
141
|
if (!this.chainRpcProviders)
|
|
106
142
|
return undefined;
|
|
107
143
|
const providers = this.chainRpcProviders.getProviders(configurations);
|
|
108
|
-
return (_a = this.chainRpcProviders.getSolanaProviderByChainId(providers,
|
|
144
|
+
return (_a = this.chainRpcProviders.getSolanaProviderByChainId(providers, networkId)) === null || _a === void 0 ? void 0 : _a.provider;
|
|
109
145
|
});
|
|
110
146
|
}
|
|
111
147
|
supportsNetworkSwitching() {
|
|
112
|
-
return
|
|
148
|
+
return true;
|
|
113
149
|
}
|
|
114
150
|
setVerifiedCredentials(verifiedCredentials) {
|
|
115
151
|
const turnkeyVerifiedCredentials = findTurnkeyVerifiedCredentials(verifiedCredentials, ProviderChain.SOLANA);
|
|
@@ -143,7 +179,7 @@ class TurnkeySolanaWalletConnector extends TurnkeyWalletConnectorBase {
|
|
|
143
179
|
}
|
|
144
180
|
endSession() {
|
|
145
181
|
return __awaiter(this, void 0, void 0, function* () {
|
|
146
|
-
|
|
182
|
+
this.setNetworkId(null);
|
|
147
183
|
});
|
|
148
184
|
}
|
|
149
185
|
refreshTurnkeyAccount() {
|
|
@@ -448,6 +484,15 @@ class TurnkeySolanaWalletConnector extends TurnkeyWalletConnectorBase {
|
|
|
448
484
|
return optimizedTransaction;
|
|
449
485
|
});
|
|
450
486
|
}
|
|
487
|
+
getBlockExplorerUrlsForCurrentNetwork() {
|
|
488
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
489
|
+
const network = this.getSelectedNetwork();
|
|
490
|
+
if (!network) {
|
|
491
|
+
return [];
|
|
492
|
+
}
|
|
493
|
+
return network.blockExplorerUrls;
|
|
494
|
+
});
|
|
495
|
+
}
|
|
451
496
|
getEnabledNetworks() {
|
|
452
497
|
return this.solNetworks;
|
|
453
498
|
}
|