@reown/appkit-solana-react-native 2.0.0-alpha.3 → 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 (47) hide show
  1. package/lib/commonjs/adapter.js +3 -3
  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 -230
  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/{PhantomProvider.js → DeeplinkProvider.js} +155 -154
  12. package/lib/commonjs/providers/DeeplinkProvider.js.map +1 -0
  13. package/lib/module/adapter.js +3 -3
  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 -230
  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/{PhantomProvider.js → DeeplinkProvider.js} +153 -152
  24. package/lib/module/providers/DeeplinkProvider.js.map +1 -0
  25. package/lib/typescript/connectors/DeeplinkConnector.d.ts +30 -0
  26. package/lib/typescript/connectors/DeeplinkConnector.d.ts.map +1 -0
  27. package/lib/typescript/connectors/PhantomConnector.d.ts +8 -23
  28. package/lib/typescript/connectors/PhantomConnector.d.ts.map +1 -1
  29. package/lib/typescript/connectors/SolflareConnector.d.ts +12 -0
  30. package/lib/typescript/connectors/SolflareConnector.d.ts.map +1 -0
  31. package/lib/typescript/index.d.ts +2 -1
  32. package/lib/typescript/index.d.ts.map +1 -1
  33. package/lib/typescript/providers/{PhantomProvider.d.ts → DeeplinkProvider.d.ts} +16 -8
  34. package/lib/typescript/providers/DeeplinkProvider.d.ts.map +1 -0
  35. package/lib/typescript/types.d.ts +27 -32
  36. package/lib/typescript/types.d.ts.map +1 -1
  37. package/package.json +2 -2
  38. package/src/adapter.ts +3 -3
  39. package/src/connectors/DeeplinkConnector.ts +353 -0
  40. package/src/connectors/PhantomConnector.ts +17 -313
  41. package/src/connectors/SolflareConnector.ts +33 -0
  42. package/src/index.ts +2 -1
  43. package/src/providers/{PhantomProvider.ts → DeeplinkProvider.ts} +256 -233
  44. package/src/types.ts +29 -37
  45. package/lib/commonjs/providers/PhantomProvider.js.map +0 -1
  46. package/lib/module/providers/PhantomProvider.js.map +0 -1
  47. package/lib/typescript/providers/PhantomProvider.d.ts.map +0 -1
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import type { Provider, RequestArguments, CaipNetworkId } from '@reown/appkit-common-react-native';
3
- import type { PhantomProviderConfig, PhantomConnectResult, PhantomSession, PhantomCluster } from '../types';
3
+ import type { DeeplinkProviderConfig, DeeplinkConnectResult, DeeplinkSession, Cluster } from '../types';
4
4
  import EventEmitter from 'events';
5
5
  export declare const SOLANA_SIGNING_METHODS: {
6
6
  readonly SOLANA_SIGN_TRANSACTION: "solana_signTransaction";
@@ -8,17 +8,19 @@ export declare const SOLANA_SIGNING_METHODS: {
8
8
  readonly SOLANA_SIGN_AND_SEND_TRANSACTION: "solana_signAndSendTransaction";
9
9
  readonly SOLANA_SIGN_ALL_TRANSACTIONS: "solana_signAllTransactions";
10
10
  };
11
- export declare class PhantomProvider extends EventEmitter implements Provider {
11
+ export declare class DeeplinkProvider extends EventEmitter implements Provider {
12
12
  private readonly config;
13
13
  private dappEncryptionKeyPair;
14
14
  private currentCluster;
15
+ private sharedKey;
15
16
  private storage;
16
17
  private sessionToken;
17
18
  private userPublicKey;
18
- private phantomEncryptionPublicKeyBs58;
19
+ private walletEncryptionPublicKeyBs58;
19
20
  private activeSubscription;
20
21
  private isOperationPending;
21
- constructor(config: PhantomProviderConfig);
22
+ constructor(config: DeeplinkProviderConfig);
23
+ private getSessionStorageKey;
22
24
  /**
23
25
  * Cleanup method to be called when the provider is destroyed
24
26
  */
@@ -33,19 +35,25 @@ export declare class PhantomProvider extends EventEmitter implements Provider {
33
35
  private setActiveSubscription;
34
36
  getUserPublicKey(): string | null;
35
37
  isConnected(): boolean;
38
+ getCurrentCluster(): Cluster;
36
39
  private buildUrl;
40
+ /**
41
+ * Open a deeplink URL and wait for a redirect back to the app. Handles subscription
42
+ * lifecycle and common error extraction from `errorCode`/`errorMessage` query params.
43
+ */
44
+ private openDeeplinkAndWait;
37
45
  private getRpcMethodName;
38
46
  private encryptPayload;
39
47
  private decryptPayload;
40
48
  restoreSession(): Promise<boolean>;
41
49
  private saveSession;
42
50
  private clearSessionStorage;
43
- connect<T = PhantomConnectResult>(params?: {
44
- cluster?: PhantomCluster;
51
+ connect<T = DeeplinkConnectResult>(params?: {
52
+ cluster?: Cluster;
45
53
  }): Promise<T>;
46
54
  disconnect(): Promise<void>;
47
55
  clearSession(): Promise<void>;
48
- setSession(session: PhantomSession): void;
56
+ setSession(session: DeeplinkSession): void;
49
57
  request<T>(args: RequestArguments, _chainId?: CaipNetworkId): Promise<T>;
50
58
  }
51
- //# sourceMappingURL=PhantomProvider.d.ts.map
59
+ //# sourceMappingURL=DeeplinkProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeeplinkProvider.d.ts","sourceRoot":"","sources":["../../../src/providers/DeeplinkProvider.ts"],"names":[],"mappings":";AAIA,OAAO,KAAK,EACV,QAAQ,EACR,gBAAgB,EAChB,aAAa,EAEd,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,EACV,sBAAsB,EACtB,qBAAqB,EACrB,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AO,EAAE,eAAe,GAAG,IAAI;IAOpC,OAAO,CAAC,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,QAAQ,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,CAAC,CAAC;CAyKtF"}
@@ -7,19 +7,13 @@ export interface TokenInfo {
7
7
  decimals: number;
8
8
  logoURI?: string;
9
9
  }
10
- export type PhantomCluster = 'mainnet-beta' | 'testnet' | 'devnet';
11
- export interface PhantomProviderConfig {
12
- appScheme: string;
13
- dappUrl: string;
14
- storage: Storage;
15
- dappEncryptionKeyPair: nacl.BoxKeyPair;
16
- }
17
- export type PhantomConnectResult = PhantomSession;
18
- export interface PhantomSession {
10
+ export type Cluster = 'mainnet-beta' | 'testnet' | 'devnet';
11
+ export type DeeplinkConnectResult = DeeplinkSession;
12
+ export interface DeeplinkSession {
19
13
  sessionToken: string;
20
14
  userPublicKey: string;
21
- phantomEncryptionPublicKeyBs58: string;
22
- cluster: PhantomCluster;
15
+ walletEncryptionPublicKeyBs58: string;
16
+ cluster: Cluster;
23
17
  }
24
18
  export interface SignTransactionRequestParams {
25
19
  transaction: string;
@@ -31,8 +25,8 @@ export interface SignMessageRequestParams {
31
25
  export interface SignAllTransactionsRequestParams {
32
26
  transactions: string[];
33
27
  }
34
- export interface PhantomDeeplinkResponse {
35
- phantom_encryption_public_key?: string;
28
+ export interface DeeplinkResponse {
29
+ wallet_encryption_public_key?: string;
36
30
  nonce: string;
37
31
  data: string;
38
32
  }
@@ -40,57 +34,58 @@ export interface DecryptedConnectData {
40
34
  public_key: string;
41
35
  session: string;
42
36
  }
43
- export interface PhantomProviderConfig {
37
+ export interface DeeplinkProviderConfig {
44
38
  appScheme: string;
45
39
  dappUrl: string;
46
40
  storage: Storage;
41
+ cluster?: Cluster;
47
42
  dappEncryptionKeyPair: nacl.BoxKeyPair;
43
+ type: 'phantom' | 'solflare';
44
+ baseUrl: string;
45
+ encryptionKeyFieldName: string;
48
46
  }
49
- export interface PhantomSession {
50
- sessionToken: string;
51
- userPublicKey: string;
52
- phantomEncryptionPublicKeyBs58: string;
53
- cluster: PhantomCluster;
54
- }
55
- export type PhantomRpcMethod = 'connect' | 'disconnect' | 'signTransaction' | 'signAndSendTransaction' | 'signAllTransactions' | 'signMessage';
56
- export interface PhantomSignTransactionParams {
47
+ export type DeeplinkRpcMethod = 'connect' | 'disconnect' | 'signTransaction' | 'signAndSendTransaction' | 'signAllTransactions' | 'signMessage';
48
+ export interface DeeplinkSignTransactionParams {
57
49
  dapp_encryption_public_key: string;
58
50
  redirect_link: string;
59
51
  payload: string;
60
52
  nonce: string;
61
- cluster?: PhantomCluster;
53
+ cluster?: Cluster;
62
54
  }
63
- export interface PhantomSignAllTransactionsParams {
55
+ export interface DeeplinkSignAllTransactionsParams {
64
56
  dapp_encryption_public_key: string;
65
57
  redirect_link: string;
66
58
  payload: string;
67
59
  nonce: string;
68
- cluster?: PhantomCluster;
60
+ cluster?: Cluster;
69
61
  }
70
- export interface PhantomSignMessageParams {
62
+ export interface DeeplinkSignMessageParams {
71
63
  dapp_encryption_public_key: string;
72
64
  redirect_link: string;
73
65
  payload: string;
74
66
  nonce: string;
75
67
  }
76
- export interface PhantomConnectParams {
68
+ export interface DeeplinkConnectParams {
77
69
  app_url: string;
78
70
  dapp_encryption_public_key: string;
79
71
  redirect_link: string;
80
- cluster?: PhantomCluster;
72
+ cluster?: Cluster;
81
73
  }
82
- export interface PhantomDisconnectParams {
74
+ export interface DeeplinkDisconnectParams {
83
75
  dapp_encryption_public_key: string;
84
76
  redirect_link: string;
85
77
  payload: string;
86
78
  nonce: string;
87
79
  }
88
- export interface PhantomConnectorConfig {
89
- cluster?: PhantomCluster;
80
+ export interface DeeplinkConnectorConfig {
81
+ type: 'phantom' | 'solflare';
82
+ cluster?: Cluster;
90
83
  }
91
- export interface PhantomConnectorSessionData {
84
+ export interface DeeplinkConnectorSessionData {
92
85
  namespaces: Namespaces;
93
86
  wallet: WalletInfo;
94
87
  currentCaipNetworkId: CaipNetworkId;
95
88
  }
89
+ export type PhantomConnectorConfig = Pick<DeeplinkConnectorConfig, 'cluster'>;
90
+ export type SolflareConnectorConfig = Pick<DeeplinkConnectorConfig, 'cluster'>;
96
91
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,UAAU,EACV,OAAO,EACP,UAAU,EACX,MAAM,mCAAmC,CAAC;AAC3C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAIlC,MAAM,WAAW,SAAS;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAID,MAAM,MAAM,cAAc,GAAG,cAAc,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEnE,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,qBAAqB,EAAE,IAAI,CAAC,UAAU,CAAC;CACxC;AAED,MAAM,MAAM,oBAAoB,GAAG,cAAc,CAAC;AAElD,MAAM,WAAW,cAAc;IAC7B,YAAY,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,MAAM,CAAC;IACtB,8BAA8B,EAAE,MAAM,CAAC;IACvC,OAAO,EAAE,cAAc,CAAC;CACzB;AAED,MAAM,WAAW,4BAA4B;IAC3C,WAAW,EAAE,MAAM,CAAC;CACrB;AACD,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,UAAU,GAAG,MAAM,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;CAC1B;AACD,MAAM,WAAW,gCAAgC;IAC/C,YAAY,EAAE,MAAM,EAAE,CAAC;CACxB;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AAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,qBAAqB;IACpC,OAAO,EAAE,MAAM,CAAC;IAChB,0BAA0B,EAAE,MAAM,CAAC;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,wBAAwB;IACvC,0BAA0B,EAAE,MAAM,CAAC;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,SAAS,GAAG,UAAU,CAAC;IAC7B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,4BAA4B;IAC3C,UAAU,EAAE,UAAU,CAAC;IACvB,MAAM,EAAE,UAAU,CAAC;IACnB,oBAAoB,EAAE,aAAa,CAAC;CACrC;AAED,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,uBAAuB,EAAE,SAAS,CAAC,CAAC;AAC9E,MAAM,MAAM,uBAAuB,GAAG,IAAI,CAAC,uBAAuB,EAAE,SAAS,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reown/appkit-solana-react-native",
3
- "version": "2.0.0-alpha.3",
3
+ "version": "2.0.0-alpha.4",
4
4
  "main": "lib/commonjs/index.js",
5
5
  "types": "lib/typescript/index.d.ts",
6
6
  "module": "lib/module/index.js",
@@ -39,7 +39,7 @@
39
39
  "access": "public"
40
40
  },
41
41
  "dependencies": {
42
- "@reown/appkit-common-react-native": "2.0.0-alpha.3",
42
+ "@reown/appkit-common-react-native": "2.0.0-alpha.4",
43
43
  "@solana/web3.js": "1.98.2",
44
44
  "bs58": "6.0.0",
45
45
  "tweetnacl": "1.0.3"
package/src/adapter.ts CHANGED
@@ -87,7 +87,7 @@ export class SolanaAdapter extends SolanaBaseAdapter {
87
87
  throw new Error('SolanaAdapter:signTransaction - network is undefined');
88
88
  }
89
89
 
90
- const provider = this.connector.getProvider();
90
+ const provider = this.connector.getProvider('solana');
91
91
  if (!provider) {
92
92
  throw new Error('SolanaAdapter:signTransaction - provider is undefined');
93
93
  }
@@ -150,7 +150,7 @@ export class SolanaAdapter extends SolanaBaseAdapter {
150
150
  throw new Error('SolanaAdapter:sendTransaction - no active connector');
151
151
  }
152
152
 
153
- const provider = this.connector.getProvider();
153
+ const provider = this.connector.getProvider('solana');
154
154
  if (!provider) {
155
155
  throw new Error('SolanaAdapter:sendTransaction - provider is undefined');
156
156
  }
@@ -216,7 +216,7 @@ export class SolanaAdapter extends SolanaBaseAdapter {
216
216
  async switchNetwork(network: AppKitNetwork): Promise<void> {
217
217
  if (!this.connector) throw new Error('No active connector');
218
218
 
219
- const provider = this.connector.getProvider();
219
+ const provider = this.connector.getProvider('solana');
220
220
  if (!provider) throw new Error('No active provider');
221
221
 
222
222
  try {
@@ -0,0 +1,353 @@
1
+ import {
2
+ WalletConnector,
3
+ type AppKitNetwork,
4
+ type CaipNetworkId,
5
+ type ChainNamespace,
6
+ type ConnectOptions,
7
+ type Namespaces,
8
+ type CaipAddress,
9
+ type ConnectorInitOptions,
10
+ type Storage,
11
+ solana,
12
+ solanaDevnet,
13
+ solanaTestnet,
14
+ type ConnectionProperties
15
+ } from '@reown/appkit-common-react-native';
16
+ import nacl from 'tweetnacl';
17
+ import bs58 from 'bs58';
18
+
19
+ import { DeeplinkProvider, SOLANA_SIGNING_METHODS } from '../providers/DeeplinkProvider';
20
+ import type {
21
+ Cluster,
22
+ DeeplinkConnectorConfig,
23
+ DeeplinkConnectorSessionData,
24
+ DeeplinkProviderConfig
25
+ } from '../types';
26
+
27
+ const SOLANA_CLUSTER_TO_NETWORK: Record<Cluster, AppKitNetwork> = {
28
+ 'mainnet-beta': solana,
29
+ 'testnet': solanaTestnet,
30
+ 'devnet': solanaDevnet
31
+ };
32
+
33
+ export abstract class DeeplinkConnector extends WalletConnector {
34
+ private readonly config: DeeplinkConnectorConfig;
35
+ private currentCaipNetworkId: CaipNetworkId | null = null;
36
+ private dappEncryptionKeyPair?: nacl.BoxKeyPair;
37
+
38
+ private static readonly SUPPORTED_NAMESPACE: ChainNamespace = 'solana';
39
+
40
+ constructor(config: DeeplinkConnectorConfig) {
41
+ super({ type: config.type });
42
+ this.config = config;
43
+ }
44
+
45
+ // Abstract methods that wallet-specific connectors must implement
46
+ protected abstract getBaseUrl(): string;
47
+ protected abstract getStorageKey(): string;
48
+ protected abstract getDappKeypairStorageKey(): string;
49
+ protected abstract getEncryptionKeyFieldName(): string;
50
+
51
+ override async init(ops: ConnectorInitOptions) {
52
+ super.init(ops);
53
+ this.storage = ops.storage;
54
+ await this.initializeKeyPair();
55
+
56
+ const appScheme = ops.metadata.redirect?.universal ?? ops.metadata.redirect?.native;
57
+ if (!appScheme) {
58
+ throw new Error(
59
+ `${this.type} connector: No redirect link found in metadata. Please add redirect.universal or redirect.native to the metadata.`
60
+ );
61
+ }
62
+
63
+ const providerConfig: DeeplinkProviderConfig = {
64
+ appScheme,
65
+ dappUrl: ops.metadata.url,
66
+ storage: ops.storage,
67
+ type: this.type as 'phantom' | 'solflare',
68
+ cluster: this.config?.cluster ?? 'mainnet-beta',
69
+ dappEncryptionKeyPair: this.dappEncryptionKeyPair!,
70
+ baseUrl: this.getBaseUrl(),
71
+ encryptionKeyFieldName: this.getEncryptionKeyFieldName()
72
+ };
73
+
74
+ this.provider = new DeeplinkProvider(providerConfig);
75
+ await this.restoreSession();
76
+ }
77
+
78
+ private async initializeKeyPair(): Promise<void> {
79
+ try {
80
+ const secretKeyB58 = await this.getStorage().getItem(this.getDappKeypairStorageKey());
81
+ if (secretKeyB58) {
82
+ const secretKey = bs58.decode(secretKeyB58);
83
+ this.dappEncryptionKeyPair = nacl.box.keyPair.fromSecretKey(secretKey);
84
+ } else {
85
+ const newKeyPair = nacl.box.keyPair();
86
+ this.dappEncryptionKeyPair = newKeyPair;
87
+ await this.getStorage().setItem(
88
+ this.getDappKeypairStorageKey(),
89
+ bs58.encode(newKeyPair.secretKey)
90
+ );
91
+ }
92
+ } catch (error) {
93
+ // disconnect and clear session
94
+ await this.disconnect();
95
+ throw error;
96
+ }
97
+ }
98
+
99
+ override async connect(opts?: ConnectOptions): Promise<Namespaces | undefined> {
100
+ if (this.isConnected() && this.namespaces) {
101
+ return this.namespaces;
102
+ }
103
+
104
+ const defaultNetworkId: CaipNetworkId | undefined =
105
+ opts?.defaultNetwork?.caipNetworkId?.split(':')?.[0] === 'solana'
106
+ ? opts?.defaultNetwork?.caipNetworkId
107
+ : opts?.namespaces?.['solana']?.chains?.[0];
108
+
109
+ const requestedCluster =
110
+ this.config?.cluster ??
111
+ (Object.keys(SOLANA_CLUSTER_TO_NETWORK).find(
112
+ key => SOLANA_CLUSTER_TO_NETWORK[key as Cluster]?.caipNetworkId === defaultNetworkId
113
+ ) as Cluster | undefined);
114
+
115
+ try {
116
+ const connectResult = await this.getProvider().connect({ cluster: requestedCluster });
117
+
118
+ const solanaChainId = SOLANA_CLUSTER_TO_NETWORK[connectResult.cluster]?.caipNetworkId;
119
+ if (!solanaChainId) {
120
+ throw new Error(
121
+ `${this.type} Connect: Internal - Unknown cluster mapping for ${connectResult.cluster}`
122
+ );
123
+ }
124
+ this.currentCaipNetworkId = solanaChainId;
125
+
126
+ this.wallet = {
127
+ name: this.getWalletInfo()?.name
128
+ };
129
+
130
+ const userPublicKey = this.getProvider().getUserPublicKey();
131
+ if (!userPublicKey) {
132
+ throw new Error(`${this.type} Connect: Provider failed to return a user public key.`);
133
+ }
134
+
135
+ const caipAddress = `${this.currentCaipNetworkId}:${userPublicKey}` as CaipAddress;
136
+ this.namespaces = {
137
+ [DeeplinkConnector.SUPPORTED_NAMESPACE]: {
138
+ accounts: [caipAddress],
139
+ methods: Object.values(SOLANA_SIGNING_METHODS),
140
+ events: [],
141
+ chains: [this.currentCaipNetworkId]
142
+ }
143
+ };
144
+
145
+ await this.saveSession(); // Save connector-specific session on successful connect
146
+
147
+ return this.namespaces;
148
+ } catch (error: any) {
149
+ this.clearSession();
150
+ throw error;
151
+ }
152
+ }
153
+
154
+ override async disconnect(): Promise<void> {
155
+ try {
156
+ if (this.isConnected()) {
157
+ await super.disconnect();
158
+ }
159
+ } catch (error: any) {
160
+ console.warn(
161
+ `${this.type} Connector: Error during provider disconnect: ${error.message}. Proceeding with local clear.`
162
+ );
163
+ }
164
+
165
+ // Cleanup provider resources
166
+ if (this.provider) {
167
+ (this.provider as DeeplinkProvider).destroy();
168
+ }
169
+
170
+ await this.clearSession();
171
+ }
172
+
173
+ private async clearSession(): Promise<void> {
174
+ this.namespaces = undefined;
175
+ this.wallet = undefined;
176
+ this.currentCaipNetworkId = null;
177
+ await this.clearSessionStorage();
178
+ }
179
+
180
+ override getProvider(): DeeplinkProvider {
181
+ if (!this.provider) {
182
+ throw new Error(`${this.type} Connector: Provider not initialized. Call init() first.`);
183
+ }
184
+
185
+ return this.provider as DeeplinkProvider;
186
+ }
187
+
188
+ private getStorage(): Storage {
189
+ if (!this.storage) {
190
+ throw new Error(`${this.type} Connector: Storage not initialized. Call init() first.`);
191
+ }
192
+
193
+ return this.storage;
194
+ }
195
+
196
+ override getNamespaces(): Namespaces {
197
+ if (!this.namespaces) {
198
+ throw new Error(`${this.type} Connector: Not connected. Call connect() first.`);
199
+ }
200
+
201
+ return this.namespaces;
202
+ }
203
+
204
+ override getChainId(namespace: ChainNamespace): CaipNetworkId | undefined {
205
+ if (namespace === DeeplinkConnector.SUPPORTED_NAMESPACE) {
206
+ return this.currentCaipNetworkId ?? undefined;
207
+ }
208
+
209
+ return undefined;
210
+ }
211
+
212
+ override getProperties(): ConnectionProperties | undefined {
213
+ return this.properties;
214
+ }
215
+
216
+ isConnected(): boolean {
217
+ // Rely solely on the provider as the source of truth for connection status.
218
+ const provider = this.getProvider();
219
+
220
+ return provider.isConnected() && !!provider.getUserPublicKey();
221
+ }
222
+
223
+ override async switchNetwork(network: AppKitNetwork): Promise<void> {
224
+ const targetClusterName = Object.keys(SOLANA_CLUSTER_TO_NETWORK).find(
225
+ key => SOLANA_CLUSTER_TO_NETWORK[key as Cluster]?.caipNetworkId === network.caipNetworkId
226
+ ) as Cluster | undefined;
227
+
228
+ if (!targetClusterName) {
229
+ throw new Error(
230
+ `${this.type} Connector: Cannot switch to unsupported network ID: ${network.id}`
231
+ );
232
+ }
233
+
234
+ const currentClusterName = Object.keys(SOLANA_CLUSTER_TO_NETWORK).find(
235
+ key => SOLANA_CLUSTER_TO_NETWORK[key as Cluster]?.caipNetworkId === this.currentCaipNetworkId
236
+ ) as Cluster | undefined;
237
+
238
+ if (targetClusterName === currentClusterName && this.isConnected()) {
239
+ return Promise.resolve();
240
+ }
241
+
242
+ // Phantom/Solflare don't provide a way to switch network, so we need to disconnect and reconnect.
243
+ await this.disconnect(); // Clear current session
244
+
245
+ // Create a temporary options object to guide the new connection
246
+ const tempConnectOpts: ConnectOptions = {
247
+ defaultNetwork: SOLANA_CLUSTER_TO_NETWORK[targetClusterName]
248
+ };
249
+
250
+ // Attempt to connect to the new cluster
251
+ // The connect method will use the defaultNetwork from opts to determine the cluster.
252
+ await this.connect(tempConnectOpts);
253
+ this.getProvider().emit('chainChanged', network.id);
254
+
255
+ // Verify if the connection was successful and to the correct new network
256
+ if (
257
+ !this.isConnected() ||
258
+ this.getChainId(DeeplinkConnector.SUPPORTED_NAMESPACE) !==
259
+ tempConnectOpts.defaultNetwork?.caipNetworkId
260
+ ) {
261
+ throw new Error(
262
+ `${this.type} Connector: Failed to switch network to ${targetClusterName}. Please try connecting manually.`
263
+ );
264
+ }
265
+ }
266
+
267
+ // Orchestrates session restoration
268
+ override async restoreSession(): Promise<boolean> {
269
+ try {
270
+ const providerSession = await this.getProvider().restoreSession();
271
+ if (!providerSession) {
272
+ return false;
273
+ }
274
+
275
+ // If provider session is restored, try to restore connector data
276
+ const connectorData = await this.getStorage().getItem<DeeplinkConnectorSessionData>(
277
+ this.getStorageKey()
278
+ );
279
+ if (!connectorData) {
280
+ // Self-heal: reconstruct connector state from provider session
281
+ const userPublicKey = this.getProvider().getUserPublicKey();
282
+ const cluster = this.getProvider().getCurrentCluster();
283
+ const caipNetworkId = SOLANA_CLUSTER_TO_NETWORK[cluster]?.caipNetworkId;
284
+ if (userPublicKey && caipNetworkId) {
285
+ this.currentCaipNetworkId = caipNetworkId;
286
+ this.wallet = { name: this.getWalletInfo()?.name };
287
+ const caipAddress = `${caipNetworkId}:${userPublicKey}` as CaipAddress;
288
+ this.namespaces = {
289
+ [DeeplinkConnector.SUPPORTED_NAMESPACE]: {
290
+ accounts: [caipAddress],
291
+ methods: Object.values(SOLANA_SIGNING_METHODS),
292
+ events: [],
293
+ chains: [caipNetworkId]
294
+ }
295
+ };
296
+ await this.saveSession();
297
+ } else {
298
+ // Provider looks connected but we can't reconstruct state → clear everything
299
+ await this.disconnect();
300
+
301
+ return false;
302
+ }
303
+ } else {
304
+ this.namespaces = connectorData.namespaces;
305
+ this.wallet = connectorData.wallet;
306
+ this.currentCaipNetworkId = connectorData.currentCaipNetworkId;
307
+ }
308
+
309
+ // Final validation
310
+ if (this.isConnected()) {
311
+ return true;
312
+ }
313
+
314
+ // If validation fails, something is out of sync. Clear everything.
315
+ await this.disconnect();
316
+
317
+ return false;
318
+ } catch (error) {
319
+ // On any error, disconnect to ensure a clean state
320
+ await this.disconnect();
321
+
322
+ return false;
323
+ }
324
+ }
325
+
326
+ // Saves only connector-specific data
327
+ private async saveSession(): Promise<void> {
328
+ if (!this.namespaces || !this.wallet || !this.currentCaipNetworkId) {
329
+ return;
330
+ }
331
+
332
+ const connectorData: DeeplinkConnectorSessionData = {
333
+ namespaces: this.namespaces,
334
+ wallet: this.wallet,
335
+ currentCaipNetworkId: this.currentCaipNetworkId
336
+ };
337
+
338
+ try {
339
+ await this.getStorage().setItem(this.getStorageKey(), connectorData);
340
+ } catch (error) {
341
+ // console.error(`${this.type} Connector: Failed to save session.`, error);
342
+ }
343
+ }
344
+
345
+ // Clears only connector-specific data from storage
346
+ private async clearSessionStorage(): Promise<void> {
347
+ try {
348
+ await this.getStorage().removeItem(this.getStorageKey());
349
+ } catch (error) {
350
+ // console.error(`${this.type} Connector: Failed to clear session from storage.`, error);
351
+ }
352
+ }
353
+ }