@reown/appkit-solana-react-native 2.0.0-alpha.2 → 2.0.0-alpha.4

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 (53) hide show
  1. package/lib/commonjs/adapter.js +4 -5
  2. package/lib/commonjs/adapter.js.map +1 -1
  3. package/lib/commonjs/connectors/DeeplinkConnector.js +271 -0
  4. package/lib/commonjs/connectors/DeeplinkConnector.js.map +1 -0
  5. package/lib/commonjs/connectors/PhantomConnector.js +15 -223
  6. package/lib/commonjs/connectors/PhantomConnector.js.map +1 -1
  7. package/lib/commonjs/connectors/SolflareConnector.js +36 -0
  8. package/lib/commonjs/connectors/SolflareConnector.js.map +1 -0
  9. package/lib/commonjs/index.js +7 -0
  10. package/lib/commonjs/index.js.map +1 -1
  11. package/lib/commonjs/providers/DeeplinkProvider.js +432 -0
  12. package/lib/commonjs/providers/DeeplinkProvider.js.map +1 -0
  13. package/lib/module/adapter.js +4 -5
  14. package/lib/module/adapter.js.map +1 -1
  15. package/lib/module/connectors/DeeplinkConnector.js +265 -0
  16. package/lib/module/connectors/DeeplinkConnector.js.map +1 -0
  17. package/lib/module/connectors/PhantomConnector.js +16 -223
  18. package/lib/module/connectors/PhantomConnector.js.map +1 -1
  19. package/lib/module/connectors/SolflareConnector.js +31 -0
  20. package/lib/module/connectors/SolflareConnector.js.map +1 -0
  21. package/lib/module/index.js +1 -0
  22. package/lib/module/index.js.map +1 -1
  23. package/lib/module/providers/DeeplinkProvider.js +426 -0
  24. package/lib/module/providers/DeeplinkProvider.js.map +1 -0
  25. package/lib/typescript/adapter.d.ts +1 -3
  26. package/lib/typescript/adapter.d.ts.map +1 -1
  27. package/lib/typescript/connectors/DeeplinkConnector.d.ts +30 -0
  28. package/lib/typescript/connectors/DeeplinkConnector.d.ts.map +1 -0
  29. package/lib/typescript/connectors/PhantomConnector.d.ts +8 -23
  30. package/lib/typescript/connectors/PhantomConnector.d.ts.map +1 -1
  31. package/lib/typescript/connectors/SolflareConnector.d.ts +12 -0
  32. package/lib/typescript/connectors/SolflareConnector.d.ts.map +1 -0
  33. package/lib/typescript/index.d.ts +2 -1
  34. package/lib/typescript/index.d.ts.map +1 -1
  35. package/lib/typescript/providers/DeeplinkProvider.d.ts +59 -0
  36. package/lib/typescript/providers/DeeplinkProvider.d.ts.map +1 -0
  37. package/lib/typescript/types.d.ts +27 -32
  38. package/lib/typescript/types.d.ts.map +1 -1
  39. package/package.json +2 -2
  40. package/src/adapter.ts +4 -5
  41. package/src/connectors/DeeplinkConnector.ts +353 -0
  42. package/src/connectors/PhantomConnector.ts +17 -313
  43. package/src/connectors/SolflareConnector.ts +33 -0
  44. package/src/index.ts +2 -1
  45. package/src/providers/DeeplinkProvider.ts +605 -0
  46. package/src/types.ts +29 -37
  47. package/lib/commonjs/providers/PhantomProvider.js +0 -391
  48. package/lib/commonjs/providers/PhantomProvider.js.map +0 -1
  49. package/lib/module/providers/PhantomProvider.js +0 -385
  50. package/lib/module/providers/PhantomProvider.js.map +0 -1
  51. package/lib/typescript/providers/PhantomProvider.d.ts +0 -37
  52. package/lib/typescript/providers/PhantomProvider.d.ts.map +0 -1
  53. package/src/providers/PhantomProvider.ts +0 -532
@@ -0,0 +1,265 @@
1
+ "use strict";
2
+
3
+ import { WalletConnector, solana, solanaDevnet, solanaTestnet } from '@reown/appkit-common-react-native';
4
+ import nacl from 'tweetnacl';
5
+ import bs58 from 'bs58';
6
+ import { DeeplinkProvider, SOLANA_SIGNING_METHODS } from '../providers/DeeplinkProvider';
7
+ const SOLANA_CLUSTER_TO_NETWORK = {
8
+ 'mainnet-beta': solana,
9
+ 'testnet': solanaTestnet,
10
+ 'devnet': solanaDevnet
11
+ };
12
+ export class DeeplinkConnector extends WalletConnector {
13
+ currentCaipNetworkId = null;
14
+ static SUPPORTED_NAMESPACE = 'solana';
15
+ constructor(config) {
16
+ super({
17
+ type: config.type
18
+ });
19
+ this.config = config;
20
+ }
21
+
22
+ // Abstract methods that wallet-specific connectors must implement
23
+
24
+ async init(ops) {
25
+ super.init(ops);
26
+ this.storage = ops.storage;
27
+ await this.initializeKeyPair();
28
+ const appScheme = ops.metadata.redirect?.universal ?? ops.metadata.redirect?.native;
29
+ if (!appScheme) {
30
+ throw new Error(`${this.type} connector: No redirect link found in metadata. Please add redirect.universal or redirect.native to the metadata.`);
31
+ }
32
+ const providerConfig = {
33
+ appScheme,
34
+ dappUrl: ops.metadata.url,
35
+ storage: ops.storage,
36
+ type: this.type,
37
+ cluster: this.config?.cluster ?? 'mainnet-beta',
38
+ dappEncryptionKeyPair: this.dappEncryptionKeyPair,
39
+ baseUrl: this.getBaseUrl(),
40
+ encryptionKeyFieldName: this.getEncryptionKeyFieldName()
41
+ };
42
+ this.provider = new DeeplinkProvider(providerConfig);
43
+ await this.restoreSession();
44
+ }
45
+ async initializeKeyPair() {
46
+ try {
47
+ const secretKeyB58 = await this.getStorage().getItem(this.getDappKeypairStorageKey());
48
+ if (secretKeyB58) {
49
+ const secretKey = bs58.decode(secretKeyB58);
50
+ this.dappEncryptionKeyPair = nacl.box.keyPair.fromSecretKey(secretKey);
51
+ } else {
52
+ const newKeyPair = nacl.box.keyPair();
53
+ this.dappEncryptionKeyPair = newKeyPair;
54
+ await this.getStorage().setItem(this.getDappKeypairStorageKey(), bs58.encode(newKeyPair.secretKey));
55
+ }
56
+ } catch (error) {
57
+ // disconnect and clear session
58
+ await this.disconnect();
59
+ throw error;
60
+ }
61
+ }
62
+ async connect(opts) {
63
+ if (this.isConnected() && this.namespaces) {
64
+ return this.namespaces;
65
+ }
66
+ const defaultNetworkId = opts?.defaultNetwork?.caipNetworkId?.split(':')?.[0] === 'solana' ? opts?.defaultNetwork?.caipNetworkId : opts?.namespaces?.['solana']?.chains?.[0];
67
+ const requestedCluster = this.config?.cluster ?? Object.keys(SOLANA_CLUSTER_TO_NETWORK).find(key => SOLANA_CLUSTER_TO_NETWORK[key]?.caipNetworkId === defaultNetworkId);
68
+ try {
69
+ const connectResult = await this.getProvider().connect({
70
+ cluster: requestedCluster
71
+ });
72
+ const solanaChainId = SOLANA_CLUSTER_TO_NETWORK[connectResult.cluster]?.caipNetworkId;
73
+ if (!solanaChainId) {
74
+ throw new Error(`${this.type} Connect: Internal - Unknown cluster mapping for ${connectResult.cluster}`);
75
+ }
76
+ this.currentCaipNetworkId = solanaChainId;
77
+ this.wallet = {
78
+ name: this.getWalletInfo()?.name
79
+ };
80
+ const userPublicKey = this.getProvider().getUserPublicKey();
81
+ if (!userPublicKey) {
82
+ throw new Error(`${this.type} Connect: Provider failed to return a user public key.`);
83
+ }
84
+ const caipAddress = `${this.currentCaipNetworkId}:${userPublicKey}`;
85
+ this.namespaces = {
86
+ [DeeplinkConnector.SUPPORTED_NAMESPACE]: {
87
+ accounts: [caipAddress],
88
+ methods: Object.values(SOLANA_SIGNING_METHODS),
89
+ events: [],
90
+ chains: [this.currentCaipNetworkId]
91
+ }
92
+ };
93
+ await this.saveSession(); // Save connector-specific session on successful connect
94
+
95
+ return this.namespaces;
96
+ } catch (error) {
97
+ this.clearSession();
98
+ throw error;
99
+ }
100
+ }
101
+ async disconnect() {
102
+ try {
103
+ if (this.isConnected()) {
104
+ await super.disconnect();
105
+ }
106
+ } catch (error) {
107
+ console.warn(`${this.type} Connector: Error during provider disconnect: ${error.message}. Proceeding with local clear.`);
108
+ }
109
+
110
+ // Cleanup provider resources
111
+ if (this.provider) {
112
+ this.provider.destroy();
113
+ }
114
+ await this.clearSession();
115
+ }
116
+ async clearSession() {
117
+ this.namespaces = undefined;
118
+ this.wallet = undefined;
119
+ this.currentCaipNetworkId = null;
120
+ await this.clearSessionStorage();
121
+ }
122
+ getProvider() {
123
+ if (!this.provider) {
124
+ throw new Error(`${this.type} Connector: Provider not initialized. Call init() first.`);
125
+ }
126
+ return this.provider;
127
+ }
128
+ getStorage() {
129
+ if (!this.storage) {
130
+ throw new Error(`${this.type} Connector: Storage not initialized. Call init() first.`);
131
+ }
132
+ return this.storage;
133
+ }
134
+ getNamespaces() {
135
+ if (!this.namespaces) {
136
+ throw new Error(`${this.type} Connector: Not connected. Call connect() first.`);
137
+ }
138
+ return this.namespaces;
139
+ }
140
+ getChainId(namespace) {
141
+ if (namespace === DeeplinkConnector.SUPPORTED_NAMESPACE) {
142
+ return this.currentCaipNetworkId ?? undefined;
143
+ }
144
+ return undefined;
145
+ }
146
+ getProperties() {
147
+ return this.properties;
148
+ }
149
+ isConnected() {
150
+ // Rely solely on the provider as the source of truth for connection status.
151
+ const provider = this.getProvider();
152
+ return provider.isConnected() && !!provider.getUserPublicKey();
153
+ }
154
+ async switchNetwork(network) {
155
+ const targetClusterName = Object.keys(SOLANA_CLUSTER_TO_NETWORK).find(key => SOLANA_CLUSTER_TO_NETWORK[key]?.caipNetworkId === network.caipNetworkId);
156
+ if (!targetClusterName) {
157
+ throw new Error(`${this.type} Connector: Cannot switch to unsupported network ID: ${network.id}`);
158
+ }
159
+ const currentClusterName = Object.keys(SOLANA_CLUSTER_TO_NETWORK).find(key => SOLANA_CLUSTER_TO_NETWORK[key]?.caipNetworkId === this.currentCaipNetworkId);
160
+ if (targetClusterName === currentClusterName && this.isConnected()) {
161
+ return Promise.resolve();
162
+ }
163
+
164
+ // Phantom/Solflare don't provide a way to switch network, so we need to disconnect and reconnect.
165
+ await this.disconnect(); // Clear current session
166
+
167
+ // Create a temporary options object to guide the new connection
168
+ const tempConnectOpts = {
169
+ defaultNetwork: SOLANA_CLUSTER_TO_NETWORK[targetClusterName]
170
+ };
171
+
172
+ // Attempt to connect to the new cluster
173
+ // The connect method will use the defaultNetwork from opts to determine the cluster.
174
+ await this.connect(tempConnectOpts);
175
+ this.getProvider().emit('chainChanged', network.id);
176
+
177
+ // Verify if the connection was successful and to the correct new network
178
+ if (!this.isConnected() || this.getChainId(DeeplinkConnector.SUPPORTED_NAMESPACE) !== tempConnectOpts.defaultNetwork?.caipNetworkId) {
179
+ throw new Error(`${this.type} Connector: Failed to switch network to ${targetClusterName}. Please try connecting manually.`);
180
+ }
181
+ }
182
+
183
+ // Orchestrates session restoration
184
+ async restoreSession() {
185
+ try {
186
+ const providerSession = await this.getProvider().restoreSession();
187
+ if (!providerSession) {
188
+ return false;
189
+ }
190
+
191
+ // If provider session is restored, try to restore connector data
192
+ const connectorData = await this.getStorage().getItem(this.getStorageKey());
193
+ if (!connectorData) {
194
+ // Self-heal: reconstruct connector state from provider session
195
+ const userPublicKey = this.getProvider().getUserPublicKey();
196
+ const cluster = this.getProvider().getCurrentCluster();
197
+ const caipNetworkId = SOLANA_CLUSTER_TO_NETWORK[cluster]?.caipNetworkId;
198
+ if (userPublicKey && caipNetworkId) {
199
+ this.currentCaipNetworkId = caipNetworkId;
200
+ this.wallet = {
201
+ name: this.getWalletInfo()?.name
202
+ };
203
+ const caipAddress = `${caipNetworkId}:${userPublicKey}`;
204
+ this.namespaces = {
205
+ [DeeplinkConnector.SUPPORTED_NAMESPACE]: {
206
+ accounts: [caipAddress],
207
+ methods: Object.values(SOLANA_SIGNING_METHODS),
208
+ events: [],
209
+ chains: [caipNetworkId]
210
+ }
211
+ };
212
+ await this.saveSession();
213
+ } else {
214
+ // Provider looks connected but we can't reconstruct state → clear everything
215
+ await this.disconnect();
216
+ return false;
217
+ }
218
+ } else {
219
+ this.namespaces = connectorData.namespaces;
220
+ this.wallet = connectorData.wallet;
221
+ this.currentCaipNetworkId = connectorData.currentCaipNetworkId;
222
+ }
223
+
224
+ // Final validation
225
+ if (this.isConnected()) {
226
+ return true;
227
+ }
228
+
229
+ // If validation fails, something is out of sync. Clear everything.
230
+ await this.disconnect();
231
+ return false;
232
+ } catch (error) {
233
+ // On any error, disconnect to ensure a clean state
234
+ await this.disconnect();
235
+ return false;
236
+ }
237
+ }
238
+
239
+ // Saves only connector-specific data
240
+ async saveSession() {
241
+ if (!this.namespaces || !this.wallet || !this.currentCaipNetworkId) {
242
+ return;
243
+ }
244
+ const connectorData = {
245
+ namespaces: this.namespaces,
246
+ wallet: this.wallet,
247
+ currentCaipNetworkId: this.currentCaipNetworkId
248
+ };
249
+ try {
250
+ await this.getStorage().setItem(this.getStorageKey(), connectorData);
251
+ } catch (error) {
252
+ // console.error(`${this.type} Connector: Failed to save session.`, error);
253
+ }
254
+ }
255
+
256
+ // Clears only connector-specific data from storage
257
+ async clearSessionStorage() {
258
+ try {
259
+ await this.getStorage().removeItem(this.getStorageKey());
260
+ } catch (error) {
261
+ // console.error(`${this.type} Connector: Failed to clear session from storage.`, error);
262
+ }
263
+ }
264
+ }
265
+ //# sourceMappingURL=DeeplinkConnector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["WalletConnector","solana","solanaDevnet","solanaTestnet","nacl","bs58","DeeplinkProvider","SOLANA_SIGNING_METHODS","SOLANA_CLUSTER_TO_NETWORK","DeeplinkConnector","currentCaipNetworkId","SUPPORTED_NAMESPACE","constructor","config","type","init","ops","storage","initializeKeyPair","appScheme","metadata","redirect","universal","native","Error","providerConfig","dappUrl","url","cluster","dappEncryptionKeyPair","baseUrl","getBaseUrl","encryptionKeyFieldName","getEncryptionKeyFieldName","provider","restoreSession","secretKeyB58","getStorage","getItem","getDappKeypairStorageKey","secretKey","decode","box","keyPair","fromSecretKey","newKeyPair","setItem","encode","error","disconnect","connect","opts","isConnected","namespaces","defaultNetworkId","defaultNetwork","caipNetworkId","split","chains","requestedCluster","Object","keys","find","key","connectResult","getProvider","solanaChainId","wallet","name","getWalletInfo","userPublicKey","getUserPublicKey","caipAddress","accounts","methods","values","events","saveSession","clearSession","console","warn","message","destroy","undefined","clearSessionStorage","getNamespaces","getChainId","namespace","getProperties","properties","switchNetwork","network","targetClusterName","id","currentClusterName","Promise","resolve","tempConnectOpts","emit","providerSession","connectorData","getStorageKey","getCurrentCluster","removeItem"],"sourceRoot":"../../../src","sources":["connectors/DeeplinkConnector.ts"],"mappings":";;AAAA,SACEA,eAAe,EASfC,MAAM,EACNC,YAAY,EACZC,aAAa,QAER,mCAAmC;AAC1C,OAAOC,IAAI,MAAM,WAAW;AAC5B,OAAOC,IA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AAE;MAClE;IACF;IAEA,MAAM0F,aAA2C,GAAG;MAClD/C,UAAU,EAAE,IAAI,CAACA,UAAU;MAC3Bc,MAAM,EAAE,IAAI,CAACA,MAAM;MACnBzD,oBAAoB,EAAE,IAAI,CAACA;IAC7B,CAAC;IAED,IAAI;MACF,MAAM,IAAI,CAAC2B,UAAU,CAAC,CAAC,CAACS,OAAO,CAAC,IAAI,CAACuD,aAAa,CAAC,CAAC,EAAED,aAAa,CAAC;IACtE,CAAC,CAAC,OAAOpD,KAAK,EAAE;MACd;IAAA;EAEJ;;EAEA;EACA,MAAcoC,mBAAmBA,CAAA,EAAkB;IACjD,IAAI;MACF,MAAM,IAAI,CAAC/C,UAAU,CAAC,CAAC,CAACkE,UAAU,CAAC,IAAI,CAACF,aAAa,CAAC,CAAC,CAAC;IAC1D,CAAC,CAAC,OAAOrD,KAAK,EAAE;MACd;IAAA;EAEJ;AACF","ignoreList":[]}
@@ -1,238 +1,31 @@
1
1
  "use strict";
2
2
 
3
- import { WalletConnector, solana, solanaDevnet, solanaTestnet, ConstantsUtil } from '@reown/appkit-common-react-native';
4
- import nacl from 'tweetnacl';
5
- import bs58 from 'bs58';
6
- import { PhantomProvider, SOLANA_SIGNING_METHODS } from '../providers/PhantomProvider';
7
- const SOLANA_CLUSTER_TO_CHAIN_ID_PART = {
8
- 'mainnet-beta': solana.id,
9
- 'testnet': solanaTestnet.id,
10
- 'devnet': solanaDevnet.id
11
- };
3
+ import { ConstantsUtil } from '@reown/appkit-common-react-native';
4
+ import { DeeplinkConnector } from './DeeplinkConnector';
5
+ const PHANTOM_BASE_URL = 'https://phantom.app/ul/v1';
12
6
  const PHANTOM_CONNECTOR_STORAGE_KEY = '@appkit/phantom-connector-data';
13
- const DAPP_KEYPAIR_STORAGE_KEY = '@appkit/phantom-dapp-secret-key';
14
- export class PhantomConnector extends WalletConnector {
15
- currentCaipNetworkId = null;
16
- static SUPPORTED_NAMESPACE = 'solana';
7
+ const PHANTOM_DAPP_KEYPAIR_STORAGE_KEY = '@appkit/phantom-dapp-secret-key';
8
+ export class PhantomConnector extends DeeplinkConnector {
17
9
  constructor(config) {
18
10
  super({
19
- type: 'phantom'
11
+ type: 'phantom',
12
+ cluster: config?.cluster
20
13
  });
21
- this.config = config ?? {
22
- cluster: 'mainnet-beta'
23
- };
24
- }
25
- async init(ops) {
26
- super.init(ops);
27
- this.storage = ops.storage;
28
- await this.initializeKeyPair();
29
- const appScheme = ops.metadata.redirect?.universal ?? ops.metadata.redirect?.native;
30
- if (!appScheme) {
31
- throw new Error('Phantom Connector: No redirect link found in metadata. Please add redirect.universal or redirect.native to the metadata.');
32
- }
33
- const providerConfig = {
34
- appScheme,
35
- dappUrl: ops.metadata.url,
36
- storage: ops.storage,
37
- dappEncryptionKeyPair: this.dappEncryptionKeyPair
38
- };
39
- this.provider = new PhantomProvider(providerConfig);
40
- await this.restoreSession();
41
- }
42
- async initializeKeyPair() {
43
- try {
44
- const secretKeyB58 = await this.getStorage().getItem(DAPP_KEYPAIR_STORAGE_KEY);
45
- if (secretKeyB58) {
46
- const secretKey = bs58.decode(secretKeyB58);
47
- this.dappEncryptionKeyPair = nacl.box.keyPair.fromSecretKey(secretKey);
48
- } else {
49
- const newKeyPair = nacl.box.keyPair();
50
- this.dappEncryptionKeyPair = newKeyPair;
51
- await this.getStorage().setItem(DAPP_KEYPAIR_STORAGE_KEY, bs58.encode(newKeyPair.secretKey));
52
- }
53
- } catch (error) {
54
- // disconnect and clear session
55
- await this.disconnect();
56
- throw error;
57
- }
58
- }
59
- async connect(opts) {
60
- if (this.isConnected()) {
61
- return this.namespaces;
62
- }
63
- const defaultChain = opts?.defaultChain?.split(':')?.[0] === 'solana' ? opts?.defaultChain?.split(':')[1] : opts?.namespaces?.['solana']?.chains?.[0]?.split(':')[1];
64
- const requestedCluster = this.config.cluster ?? Object.keys(SOLANA_CLUSTER_TO_CHAIN_ID_PART).find(key => SOLANA_CLUSTER_TO_CHAIN_ID_PART[key] === defaultChain);
65
- try {
66
- const connectResult = await this.getProvider().connect({
67
- cluster: requestedCluster
68
- });
69
- const solanaChainIdPart = SOLANA_CLUSTER_TO_CHAIN_ID_PART[connectResult.cluster];
70
- if (!solanaChainIdPart) {
71
- throw new Error(`Phantom Connect: Internal - Unknown cluster mapping for ${connectResult.cluster}`);
72
- }
73
- this.currentCaipNetworkId = `solana:${solanaChainIdPart}`;
74
- this.wallet = ConstantsUtil.PHANTOM_CUSTOM_WALLET;
75
- const userPublicKey = this.getProvider().getUserPublicKey();
76
- if (!userPublicKey) {
77
- throw new Error('Phantom Connect: Provider failed to return a user public key.');
78
- }
79
- const caipAddress = `${this.currentCaipNetworkId}:${userPublicKey}`;
80
- this.namespaces = {
81
- [PhantomConnector.SUPPORTED_NAMESPACE]: {
82
- accounts: [caipAddress],
83
- methods: Object.values(SOLANA_SIGNING_METHODS),
84
- events: [],
85
- chains: [this.currentCaipNetworkId]
86
- }
87
- };
88
- await this.saveSession(); // Save connector-specific session on successful connect
89
-
90
- return this.namespaces;
91
- } catch (error) {
92
- this.clearSession();
93
- throw error;
94
- }
95
- }
96
- async disconnect() {
97
- try {
98
- if (this.isConnected()) {
99
- await super.disconnect();
100
- }
101
- } catch (error) {
102
- // console.warn(`PhantomConnector: Error during provider disconnect: ${error.message}. Proceeding with local clear.`);
103
- }
104
- await this.clearSession();
105
- }
106
- async clearSession() {
107
- this.namespaces = undefined;
108
- this.wallet = undefined;
109
- this.currentCaipNetworkId = null;
110
- await this.clearSessionStorage();
111
- }
112
- getProvider() {
113
- if (!this.provider) {
114
- throw new Error('Phantom Connector: Provider not initialized. Call init() first.');
115
- }
116
- return this.provider;
117
- }
118
- getStorage() {
119
- if (!this.storage) {
120
- throw new Error('Phantom Connector: Storage not initialized. Call init() first.');
121
- }
122
- return this.storage;
123
- }
124
- getNamespaces() {
125
- if (!this.namespaces) {
126
- throw new Error('Phantom Connector: Not connected. Call connect() first.');
127
- }
128
- return this.namespaces;
129
- }
130
- getChainId(namespace) {
131
- if (namespace === PhantomConnector.SUPPORTED_NAMESPACE) {
132
- return this.currentCaipNetworkId ?? undefined;
133
- }
134
- return undefined;
135
- }
136
- getProperties() {
137
- return this.properties;
138
14
  }
139
15
  getWalletInfo() {
140
- if (!this.isConnected()) {
141
- return undefined;
142
- }
143
- return this.wallet;
16
+ return ConstantsUtil.PHANTOM_CUSTOM_WALLET;
144
17
  }
145
- isConnected() {
146
- // Rely solely on the provider as the source of truth for connection status.
147
- return this.getProvider().isConnected() && !!this.getProvider().getUserPublicKey();
18
+ getBaseUrl() {
19
+ return PHANTOM_BASE_URL;
148
20
  }
149
- async switchNetwork(network) {
150
- const targetClusterName = Object.keys(SOLANA_CLUSTER_TO_CHAIN_ID_PART).find(key => SOLANA_CLUSTER_TO_CHAIN_ID_PART[key] === network.id);
151
- if (!targetClusterName) {
152
- throw new Error(`Cannot switch to unsupported network ID: ${network.id}`);
153
- }
154
- const currentClusterName = Object.keys(SOLANA_CLUSTER_TO_CHAIN_ID_PART).find(key => `solana:${SOLANA_CLUSTER_TO_CHAIN_ID_PART[key]}` === this.currentCaipNetworkId);
155
- if (targetClusterName === currentClusterName && this.isConnected()) {
156
- return Promise.resolve();
157
- }
158
-
159
- // Phantom doesn't provide a way to switch network, so we need to disconnect and reconnect.
160
- await this.disconnect(); // Clear current session
161
-
162
- // Create a temporary options object to guide the new connection
163
- const tempConnectOpts = {
164
- defaultChain: `solana:${SOLANA_CLUSTER_TO_CHAIN_ID_PART[targetClusterName]}`
165
- };
166
-
167
- // Attempt to connect to the new cluster
168
- // The connect method will use the defaultChain from opts to determine the cluster.
169
- await this.connect(tempConnectOpts);
170
- this.getProvider().emit('chainChanged', network.id);
171
-
172
- // Verify if the connection was successful and to the correct new network
173
- if (!this.isConnected() || this.getChainId(PhantomConnector.SUPPORTED_NAMESPACE) !== tempConnectOpts.defaultChain) {
174
- throw new Error(`Failed to switch network to ${targetClusterName}. Please try connecting manually.`);
175
- }
21
+ getStorageKey() {
22
+ return PHANTOM_CONNECTOR_STORAGE_KEY;
176
23
  }
177
-
178
- // Orchestrates session restoration
179
- async restoreSession() {
180
- try {
181
- const providerSession = await this.getProvider().restoreSession();
182
- if (!providerSession) {
183
- return false;
184
- }
185
-
186
- // If provider session is restored, try to restore connector data
187
- const connectorData = await this.getStorage().getItem(PHANTOM_CONNECTOR_STORAGE_KEY);
188
- if (!connectorData) {
189
- return false; // Provider session exists but connector data is missing
190
- }
191
- this.namespaces = connectorData.namespaces;
192
- this.wallet = connectorData.wallet;
193
- this.currentCaipNetworkId = connectorData.currentCaipNetworkId;
194
-
195
- // await this.initializeKeyPair();
196
-
197
- // Final validation
198
- if (this.isConnected()) {
199
- return true;
200
- }
201
-
202
- // If validation fails, something is out of sync. Clear everything.
203
- await this.disconnect();
204
- return false;
205
- } catch (error) {
206
- // On any error, disconnect to ensure a clean state
207
- await this.disconnect();
208
- return false;
209
- }
24
+ getDappKeypairStorageKey() {
25
+ return PHANTOM_DAPP_KEYPAIR_STORAGE_KEY;
210
26
  }
211
-
212
- // Saves only connector-specific data
213
- async saveSession() {
214
- if (!this.namespaces || !this.wallet || !this.currentCaipNetworkId) {
215
- return;
216
- }
217
- const connectorData = {
218
- namespaces: this.namespaces,
219
- wallet: this.wallet,
220
- currentCaipNetworkId: this.currentCaipNetworkId
221
- };
222
- try {
223
- await this.getStorage().setItem(PHANTOM_CONNECTOR_STORAGE_KEY, connectorData);
224
- } catch (error) {
225
- // console.error('PhantomConnector: Failed to save session.', error);
226
- }
227
- }
228
-
229
- // Clears only connector-specific data from storage
230
- async clearSessionStorage() {
231
- try {
232
- await this.getStorage().removeItem(PHANTOM_CONNECTOR_STORAGE_KEY);
233
- } catch (error) {
234
- // console.error('PhantomConnector: Failed to clear session from storage.', error);
235
- }
27
+ getEncryptionKeyFieldName() {
28
+ return 'phantom_encryption_public_key';
236
29
  }
237
30
  }
238
31
  //# sourceMappingURL=PhantomConnector.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["WalletConnector","solana","solanaDevnet","solanaTestnet","ConstantsUtil","nacl","bs58","PhantomProvider","SOLANA_SIGNING_METHODS","SOLANA_CLUSTER_TO_CHAIN_ID_PART","id","PHANTOM_CONNECTOR_STORAGE_KEY","DAPP_KEYPAIR_STORAGE_KEY","PhantomConnector","currentCaipNetworkId","SUPPORTED_NAMESPACE","constructor","config","type","cluster","init","ops","storage","initializeKeyPair","appScheme","metadata","redirect","universal","native","Error","providerConfig","dappUrl","url","dappEncryptionKeyPair","provider","restoreSession","secretKeyB58","getStorage","getItem","secretKey","decode","box","keyPair","fromSecretKey","newKeyPair","setItem","encode","error","disconnect","connect","opts","isConnected","namespaces","defaultChain","split","chains","requestedCluster","Object","keys","find","key","connectResult","getProvider","solanaChainIdPart","wallet","PHANTOM_CUSTOM_WALLET","userPublicKey","getUserPublicKey","caipAddress","accounts","methods","values","events","saveSession","clearSession","undefined","clearSessionStorage","getNamespaces","getChainId","namespace","getProperties","properties","getWalletInfo","switchNetwork","network","targetClusterName","currentClusterName","Promise","resolve","tempConnectOpts","emit","providerSession","connectorData","removeItem"],"sourceRoot":"../../../src","sources":["connectors/PhantomConnector.ts"],"mappings":";;AAAA,SACEA,eAAe,EAUfC,MAAM,EACNC,YAAY,EACZC,aAAa,EAEbC,aAAa,QACR,mCAAmC;AAC1C,OAAOC,IAAI,MAAM,WAAW;AAC5B,OAAOC,IAAI,MAAM,MAAM;AAEvB,SAASC,eAAe,EAAEC,sBAAsB,QAAQ,8BAA8B;AAQtF,MAAMC,+BAA+D,GAAG;EACtE,cAAc,EAAER,MAAM,CAACS,EAAY;EACnC,SAAS,EAAEP,aAAa,CAACO,EAAY;EACrC,QAAQ,EAAER,YAAY,CAACQ;AACzB,CAAC;AAED,MAAMC,6BAA6B,GAAG,gCAAgC;AACtE,MAAMC,wBAAwB,GAAG,iCAAiC;AAElE,OAAO,MAAMC,gBAAgB,SAASb,eAAe,CAAC;EAG5Cc,oBAAoB,GAAyB,IAAI;EAGzD,OAAwBC,mBAAmB,GAAmB,QAAQ;EAE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A6B,CAAC;IACnE,CAAC,CAAC,OAAOoC,KAAK,EAAE;MACd;IAAA;EAEJ;AACF","ignoreList":[]}
1
+ {"version":3,"names":["ConstantsUtil","DeeplinkConnector","PHANTOM_BASE_URL","PHANTOM_CONNECTOR_STORAGE_KEY","PHANTOM_DAPP_KEYPAIR_STORAGE_KEY","PhantomConnector","constructor","config","type","cluster","getWalletInfo","PHANTOM_CUSTOM_WALLET","getBaseUrl","getStorageKey","getDappKeypairStorageKey","getEncryptionKeyFieldName"],"sourceRoot":"../../../src","sources":["connectors/PhantomConnector.ts"],"mappings":";;AAAA,SAASA,aAAa,QAAyB,mCAAmC;AAClF,SAASC,iBAAiB,QAAQ,qBAAqB;AAGvD,MAAMC,gBAAgB,GAAG,2BAA2B;AACpD,MAAMC,6BAA6B,GAAG,gCAAgC;AACtE,MAAMC,gCAAgC,GAAG,iCAAiC;AAE1E,OAAO,MAAMC,gBAAgB,SAASJ,iBAAiB,CAAC;EACtDK,WAAWA,CAACC,MAA+B,EAAE;IAC3C,KAAK,CAAC;MAAEC,IAAI,EAAE,SAAS;MAAEC,OAAO,EAAEF,MAAM,EAAEE;IAAQ,CAAC,CAAC;EACtD;EAESC,aAAaA,CAAA,EAAe;IACnC,OAAOV,aAAa,CAACW,qBAAqB;EAC5C;EAEUC,UAAUA,CAAA,EAAW;IAC7B,OAAOV,gBAAgB;EACzB;EAEUW,aAAaA,CAAA,EAAW;IAChC,OAAOV,6BAA6B;EACtC;EAEUW,wBAAwBA,CAAA,EAAW;IAC3C,OAAOV,gCAAgC;EACzC;EAEUW,yBAAyBA,CAAA,EAAW;IAC5C,OAAO,+BAA+B;EACxC;AACF","ignoreList":[]}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ import { ConstantsUtil } from '@reown/appkit-common-react-native';
4
+ import { DeeplinkConnector } from './DeeplinkConnector';
5
+ const SOLFLARE_BASE_URL = 'https://solflare.com/ul/v1';
6
+ const SOLFLARE_CONNECTOR_STORAGE_KEY = '@appkit/solflare-connector-data';
7
+ const SOLFLARE_DAPP_KEYPAIR_STORAGE_KEY = '@appkit/solflare-dapp-secret-key';
8
+ export class SolflareConnector extends DeeplinkConnector {
9
+ constructor(config) {
10
+ super({
11
+ type: 'solflare',
12
+ cluster: config?.cluster
13
+ });
14
+ }
15
+ getWalletInfo() {
16
+ return ConstantsUtil.SOLFLARE_CUSTOM_WALLET;
17
+ }
18
+ getBaseUrl() {
19
+ return SOLFLARE_BASE_URL;
20
+ }
21
+ getStorageKey() {
22
+ return SOLFLARE_CONNECTOR_STORAGE_KEY;
23
+ }
24
+ getDappKeypairStorageKey() {
25
+ return SOLFLARE_DAPP_KEYPAIR_STORAGE_KEY;
26
+ }
27
+ getEncryptionKeyFieldName() {
28
+ return 'solflare_encryption_public_key';
29
+ }
30
+ }
31
+ //# sourceMappingURL=SolflareConnector.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ConstantsUtil","DeeplinkConnector","SOLFLARE_BASE_URL","SOLFLARE_CONNECTOR_STORAGE_KEY","SOLFLARE_DAPP_KEYPAIR_STORAGE_KEY","SolflareConnector","constructor","config","type","cluster","getWalletInfo","SOLFLARE_CUSTOM_WALLET","getBaseUrl","getStorageKey","getDappKeypairStorageKey","getEncryptionKeyFieldName"],"sourceRoot":"../../../src","sources":["connectors/SolflareConnector.ts"],"mappings":";;AAAA,SAASA,aAAa,QAAyB,mCAAmC;AAClF,SAASC,iBAAiB,QAAQ,qBAAqB;AAGvD,MAAMC,iBAAiB,GAAG,4BAA4B;AACtD,MAAMC,8BAA8B,GAAG,iCAAiC;AACxE,MAAMC,iCAAiC,GAAG,kCAAkC;AAE5E,OAAO,MAAMC,iBAAiB,SAASJ,iBAAiB,CAAC;EACvDK,WAAWA,CAACC,MAAgC,EAAE;IAC5C,KAAK,CAAC;MAAEC,IAAI,EAAE,UAAU;MAAEC,OAAO,EAAEF,MAAM,EAAEE;IAAQ,CAAC,CAAC;EACvD;EAESC,aAAaA,CAAA,EAAe;IACnC,OAAOV,aAAa,CAACW,sBAAsB;EAC7C;EAEUC,UAAUA,CAAA,EAAW;IAC7B,OAAOV,iBAAiB;EAC1B;EAEUW,aAAaA,CAAA,EAAW;IAChC,OAAOV,8BAA8B;EACvC;EAEUW,wBAAwBA,CAAA,EAAW;IAC3C,OAAOV,iCAAiC;EAC1C;EAEUW,yBAAyBA,CAAA,EAAW;IAC5C,OAAO,gCAAgC;EACzC;AACF","ignoreList":[]}
@@ -7,4 +7,5 @@ export { SolanaAdapter } from './adapter';
7
7
 
8
8
  // Connectors
9
9
  export { PhantomConnector } from './connectors/PhantomConnector';
10
+ export { SolflareConnector } from './connectors/SolflareConnector';
10
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["SolanaAdapter","PhantomConnector"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA;AACA,SAASA,aAAa,QAAQ,WAAW;;AAEzC;;AAGA;AACA,SAASC,gBAAgB,QAAQ,+BAA+B","ignoreList":[]}
1
+ {"version":3,"names":["SolanaAdapter","PhantomConnector","SolflareConnector"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA;AACA,SAASA,aAAa,QAAQ,WAAW;;AAEzC;;AAGA;AACA,SAASC,gBAAgB,QAAQ,+BAA+B;AAChE,SAASC,iBAAiB,QAAQ,gCAAgC","ignoreList":[]}