@reown/appkit-solana-react-native 0.0.0-canary-20251008180350
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/lib/commonjs/adapter.js +271 -0
- package/lib/commonjs/adapter.js.map +1 -0
- package/lib/commonjs/connectors/DeeplinkConnector.js +271 -0
- package/lib/commonjs/connectors/DeeplinkConnector.js.map +1 -0
- package/lib/commonjs/connectors/PhantomConnector.js +39 -0
- package/lib/commonjs/connectors/PhantomConnector.js.map +1 -0
- package/lib/commonjs/connectors/SolflareConnector.js +39 -0
- package/lib/commonjs/connectors/SolflareConnector.js.map +1 -0
- package/lib/commonjs/helpers.js +102 -0
- package/lib/commonjs/helpers.js.map +1 -0
- package/lib/commonjs/index.js +27 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/providers/DeeplinkProvider.js +432 -0
- package/lib/commonjs/providers/DeeplinkProvider.js.map +1 -0
- package/lib/commonjs/types.js +6 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/utils/createSPLTokenTransaction.js +96 -0
- package/lib/commonjs/utils/createSPLTokenTransaction.js.map +1 -0
- package/lib/commonjs/utils/createSendTransaction.js +30 -0
- package/lib/commonjs/utils/createSendTransaction.js.map +1 -0
- package/lib/module/adapter.js +265 -0
- package/lib/module/adapter.js.map +1 -0
- package/lib/module/connectors/DeeplinkConnector.js +265 -0
- package/lib/module/connectors/DeeplinkConnector.js.map +1 -0
- package/lib/module/connectors/PhantomConnector.js +34 -0
- package/lib/module/connectors/PhantomConnector.js.map +1 -0
- package/lib/module/connectors/SolflareConnector.js +34 -0
- package/lib/module/connectors/SolflareConnector.js.map +1 -0
- package/lib/module/helpers.js +95 -0
- package/lib/module/helpers.js.map +1 -0
- package/lib/module/index.js +11 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/providers/DeeplinkProvider.js +426 -0
- package/lib/module/providers/DeeplinkProvider.js.map +1 -0
- package/lib/module/types.js +4 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/utils/createSPLTokenTransaction.js +92 -0
- package/lib/module/utils/createSPLTokenTransaction.js.map +1 -0
- package/lib/module/utils/createSendTransaction.js +26 -0
- package/lib/module/utils/createSendTransaction.js.map +1 -0
- package/lib/typescript/adapter.d.ts +23 -0
- package/lib/typescript/adapter.d.ts.map +1 -0
- package/lib/typescript/connectors/DeeplinkConnector.d.ts +30 -0
- package/lib/typescript/connectors/DeeplinkConnector.d.ts.map +1 -0
- package/lib/typescript/connectors/PhantomConnector.d.ts +12 -0
- package/lib/typescript/connectors/PhantomConnector.d.ts.map +1 -0
- package/lib/typescript/connectors/SolflareConnector.d.ts +12 -0
- package/lib/typescript/connectors/SolflareConnector.d.ts.map +1 -0
- package/lib/typescript/helpers.d.ts +31 -0
- package/lib/typescript/helpers.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +5 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/providers/DeeplinkProvider.d.ts +59 -0
- package/lib/typescript/providers/DeeplinkProvider.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +99 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/lib/typescript/utils/createSPLTokenTransaction.d.ts +4 -0
- package/lib/typescript/utils/createSPLTokenTransaction.d.ts.map +1 -0
- package/lib/typescript/utils/createSendTransaction.d.ts +10 -0
- package/lib/typescript/utils/createSendTransaction.d.ts.map +1 -0
- package/package.json +54 -0
- package/readme.md +9 -0
- package/src/adapter.ts +315 -0
- package/src/connectors/DeeplinkConnector.ts +353 -0
- package/src/connectors/PhantomConnector.ts +36 -0
- package/src/connectors/SolflareConnector.ts +36 -0
- package/src/helpers.ts +102 -0
- package/src/index.ts +9 -0
- package/src/providers/DeeplinkProvider.ts +605 -0
- package/src/types.ts +132 -0
- package/src/utils/createSPLTokenTransaction.ts +152 -0
- package/src/utils/createSendTransaction.ts +41 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ConstantsUtil, type WalletInfo } from '@reown/appkit-common-react-native';
|
|
2
|
+
import { DeeplinkConnector } from './DeeplinkConnector';
|
|
3
|
+
import type { SolflareConnectorConfig } from '../types';
|
|
4
|
+
|
|
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
|
+
|
|
9
|
+
export class SolflareConnector extends DeeplinkConnector {
|
|
10
|
+
constructor(config?: SolflareConnectorConfig) {
|
|
11
|
+
super({ type: 'solflare', cluster: config?.cluster });
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
override getWalletInfo(): WalletInfo {
|
|
15
|
+
return {
|
|
16
|
+
name: ConstantsUtil.SOLFLARE_CUSTOM_WALLET.name,
|
|
17
|
+
type: 'external'
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
protected getBaseUrl(): string {
|
|
22
|
+
return SOLFLARE_BASE_URL;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
protected getStorageKey(): string {
|
|
26
|
+
return SOLFLARE_CONNECTOR_STORAGE_KEY;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
protected getDappKeypairStorageKey(): string {
|
|
30
|
+
return SOLFLARE_DAPP_KEYPAIR_STORAGE_KEY;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
protected getEncryptionKeyFieldName(): string {
|
|
34
|
+
return 'solflare_encryption_public_key';
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/helpers.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { TokenInfo } from './types';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Validates if the given string is a Solana address.
|
|
5
|
+
* @param address The string to validate.
|
|
6
|
+
* @returns True if the address is valid, false otherwise.
|
|
7
|
+
*/
|
|
8
|
+
export function isSolanaAddress(address: string): boolean {
|
|
9
|
+
const solanaAddressRegex = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
|
|
10
|
+
|
|
11
|
+
return solanaAddressRegex.test(address);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Helper to fetch SOL balance using JSON-RPC
|
|
16
|
+
* @param rpcUrl Solana RPC endpoint
|
|
17
|
+
* @param address Solana public address (base58)
|
|
18
|
+
*/
|
|
19
|
+
export async function getSolanaNativeBalance(rpcUrl: string, address: string): Promise<number> {
|
|
20
|
+
if (!isSolanaAddress(address)) {
|
|
21
|
+
throw new Error('Invalid Solana address format');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const response = await fetch(rpcUrl, {
|
|
25
|
+
method: 'POST',
|
|
26
|
+
headers: { 'Content-Type': 'application/json' },
|
|
27
|
+
body: JSON.stringify({
|
|
28
|
+
jsonrpc: '2.0',
|
|
29
|
+
id: 1,
|
|
30
|
+
method: 'getBalance',
|
|
31
|
+
params: [address]
|
|
32
|
+
})
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const json = (await response.json()) as {
|
|
36
|
+
result: { value: number };
|
|
37
|
+
error?: { message: string };
|
|
38
|
+
};
|
|
39
|
+
if (json.error) throw new Error(json.error.message);
|
|
40
|
+
|
|
41
|
+
return json.result.value / 1000000000; // Convert lamports to SOL
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let tokenCache: Record<string, TokenInfo> = {};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Fetch metadata for a Solana SPL token using the Jupiter token list.
|
|
48
|
+
* @param mint - The token's mint address
|
|
49
|
+
* @returns TokenInfo if found, or undefined
|
|
50
|
+
*/
|
|
51
|
+
export async function getSolanaTokenMetadata(mint: string): Promise<TokenInfo | undefined> {
|
|
52
|
+
// Return from cache if available
|
|
53
|
+
if (tokenCache[mint]) return tokenCache[mint];
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
const res = await fetch('https://token.jup.ag/all');
|
|
57
|
+
const list: TokenInfo[] = await res.json();
|
|
58
|
+
|
|
59
|
+
for (const token of list) {
|
|
60
|
+
tokenCache[token.address] = token;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return tokenCache[mint];
|
|
64
|
+
} catch (error) {
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Get the balance of a token for a given address
|
|
71
|
+
* @param rpcUrl - The RPC URL to use
|
|
72
|
+
* @param address - The address to get the balance for
|
|
73
|
+
* @param tokenAddress - The address of the token to get the balance for
|
|
74
|
+
* @returns The balance of the token for the given address
|
|
75
|
+
*/
|
|
76
|
+
export async function getSolanaTokenBalance(
|
|
77
|
+
rpcUrl: string,
|
|
78
|
+
address: string,
|
|
79
|
+
tokenAddress: string
|
|
80
|
+
): Promise<{ amount: string; symbol: string }> {
|
|
81
|
+
if (!isSolanaAddress(address)) {
|
|
82
|
+
throw new Error('Invalid Solana address format');
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const token = await getSolanaTokenMetadata(tokenAddress);
|
|
86
|
+
|
|
87
|
+
const response = await fetch(rpcUrl, {
|
|
88
|
+
method: 'POST',
|
|
89
|
+
headers: { 'Content-Type': 'application/json' },
|
|
90
|
+
body: JSON.stringify({
|
|
91
|
+
jsonrpc: '2.0',
|
|
92
|
+
id: 1,
|
|
93
|
+
method: 'getTokenAccountsByOwner',
|
|
94
|
+
params: [address, { mint: tokenAddress }, { encoding: 'jsonParsed' }]
|
|
95
|
+
})
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const result = await response.json();
|
|
99
|
+
const balance = result.result.value[0]?.account?.data?.parsed?.info?.tokenAmount?.uiAmount;
|
|
100
|
+
|
|
101
|
+
return { amount: balance?.toString() ?? '0', symbol: token?.symbol ?? 'SOL' };
|
|
102
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Adapter
|
|
2
|
+
export { SolanaAdapter } from './adapter';
|
|
3
|
+
|
|
4
|
+
// Types
|
|
5
|
+
export type { PhantomConnectorConfig, SolflareConnectorConfig } from './types';
|
|
6
|
+
|
|
7
|
+
// Connectors
|
|
8
|
+
export { PhantomConnector } from './connectors/PhantomConnector';
|
|
9
|
+
export { SolflareConnector } from './connectors/SolflareConnector';
|