@phantom/react-native-sdk 1.0.0-beta.2 → 1.0.0-beta.20
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/README.md +44 -54
- package/dist/index.d.ts +20 -41
- package/dist/index.js +138 -218
- package/dist/index.mjs +132 -212
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -89,12 +89,9 @@ export default function App() {
|
|
|
89
89
|
return (
|
|
90
90
|
<PhantomProvider
|
|
91
91
|
config={{
|
|
92
|
-
appId: "your-app-id",
|
|
92
|
+
appId: "your-app-id", // Get your app ID from phantom.com/portal
|
|
93
93
|
scheme: "mywalletapp", // Must match app.json scheme
|
|
94
|
-
embeddedWalletType: "user-wallet",
|
|
95
94
|
addressTypes: [AddressType.solana],
|
|
96
|
-
apiBaseUrl: "https://api.phantom.app/v1/wallets",
|
|
97
|
-
solanaProvider: "web3js",
|
|
98
95
|
authOptions: {
|
|
99
96
|
redirectUrl: "mywalletapp://phantom-auth-callback",
|
|
100
97
|
},
|
|
@@ -117,8 +114,8 @@ import { useConnect, useAccounts, useSolana, useEthereum, useDisconnect } from "
|
|
|
117
114
|
export function WalletScreen() {
|
|
118
115
|
const { connect, isConnecting, error: connectError } = useConnect();
|
|
119
116
|
const { addresses, isConnected } = useAccounts();
|
|
120
|
-
const solana = useSolana();
|
|
121
|
-
const ethereum = useEthereum();
|
|
117
|
+
const { solana } = useSolana();
|
|
118
|
+
const { ethereum } = useEthereum();
|
|
122
119
|
const { disconnect } = useDisconnect();
|
|
123
120
|
|
|
124
121
|
const handleConnect = async () => {
|
|
@@ -132,8 +129,10 @@ export function WalletScreen() {
|
|
|
132
129
|
|
|
133
130
|
const handleSignSolanaMessage = async () => {
|
|
134
131
|
try {
|
|
135
|
-
|
|
136
|
-
|
|
132
|
+
if (solana.isAvailable) {
|
|
133
|
+
const signature = await solana.solana.signMessage("Hello from Solana!");
|
|
134
|
+
Alert.alert("Solana Signed!", `Signature: ${signature.signature.slice(0, 10)}...`);
|
|
135
|
+
}
|
|
137
136
|
} catch (error) {
|
|
138
137
|
Alert.alert("Error", `Failed to sign: ${error.message}`);
|
|
139
138
|
}
|
|
@@ -141,9 +140,11 @@ export function WalletScreen() {
|
|
|
141
140
|
|
|
142
141
|
const handleSignEthereumMessage = async () => {
|
|
143
142
|
try {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
143
|
+
if (ethereum.isAvailable) {
|
|
144
|
+
const accounts = await ethereum.ethereum.getAccounts();
|
|
145
|
+
const signature = await ethereum.ethereum.signPersonalMessage("Hello from Ethereum!", accounts[0]);
|
|
146
|
+
Alert.alert("Ethereum Signed!", `Signature: ${signature.slice(0, 10)}...`);
|
|
147
|
+
}
|
|
147
148
|
} catch (error) {
|
|
148
149
|
Alert.alert("Error", `Failed to sign: ${error.message}`);
|
|
149
150
|
}
|
|
@@ -198,15 +199,17 @@ The main provider component that initializes the SDK and provides context to all
|
|
|
198
199
|
```typescript
|
|
199
200
|
interface PhantomSDKConfig {
|
|
200
201
|
scheme: string; // Custom URL scheme for your app
|
|
201
|
-
|
|
202
|
+
appId: string; // Your app ID from phantom.com/portal (required)
|
|
202
203
|
addressTypes: [AddressType, ...AddressType[]]; // e.g., [AddressType.solana]
|
|
203
|
-
|
|
204
|
-
|
|
204
|
+
|
|
205
|
+
// Optional configuration
|
|
206
|
+
embeddedWalletType?: "user-wallet"; // optional, defaults to "user-wallet", currently the only supported type
|
|
207
|
+
apiBaseUrl?: string; // e.g., "https://api.phantom.app/v1/wallets" (optional, has default)
|
|
205
208
|
authOptions?: {
|
|
206
209
|
authUrl?: string; // Custom auth URL (optional)
|
|
207
210
|
redirectUrl?: string; // Custom redirect URL (optional)
|
|
208
211
|
};
|
|
209
|
-
autoConnect?: boolean; // Auto-connect to existing session on SDK instantiation (
|
|
212
|
+
autoConnect?: boolean; // Auto-connect to existing session on SDK instantiation (optional, defaults to true)
|
|
210
213
|
}
|
|
211
214
|
```
|
|
212
215
|
|
|
@@ -242,16 +245,18 @@ const {
|
|
|
242
245
|
Provides access to Solana-specific operations.
|
|
243
246
|
|
|
244
247
|
```typescript
|
|
245
|
-
const solana = useSolana();
|
|
248
|
+
const { solana, isAvailable } = useSolana();
|
|
246
249
|
|
|
247
|
-
|
|
248
|
-
|
|
250
|
+
if (isAvailable) {
|
|
251
|
+
// Sign a message
|
|
252
|
+
const signature = await solana.signMessage("Hello Solana!");
|
|
249
253
|
|
|
250
|
-
// Sign a transaction (without sending)
|
|
251
|
-
const signedTx = await solana.signTransaction(transaction);
|
|
254
|
+
// Sign a transaction (without sending)
|
|
255
|
+
const signedTx = await solana.signTransaction(transaction);
|
|
252
256
|
|
|
253
|
-
// Sign and send a transaction
|
|
254
|
-
const result = await solana.signAndSendTransaction(transaction);
|
|
257
|
+
// Sign and send a transaction
|
|
258
|
+
const result = await solana.signAndSendTransaction(transaction);
|
|
259
|
+
}
|
|
255
260
|
```
|
|
256
261
|
|
|
257
262
|
#### useEthereum
|
|
@@ -259,22 +264,24 @@ const result = await solana.signAndSendTransaction(transaction);
|
|
|
259
264
|
Provides access to Ethereum-specific operations.
|
|
260
265
|
|
|
261
266
|
```typescript
|
|
262
|
-
const ethereum = useEthereum();
|
|
267
|
+
const { ethereum, isAvailable } = useEthereum();
|
|
263
268
|
|
|
264
|
-
|
|
265
|
-
|
|
269
|
+
if (isAvailable) {
|
|
270
|
+
// Get accounts
|
|
271
|
+
const accounts = await ethereum.getAccounts();
|
|
266
272
|
|
|
267
|
-
// Sign a personal message
|
|
268
|
-
const signature = await ethereum.signPersonalMessage("Hello Ethereum!", accounts[0]);
|
|
273
|
+
// Sign a personal message
|
|
274
|
+
const signature = await ethereum.signPersonalMessage("Hello Ethereum!", accounts[0]);
|
|
269
275
|
|
|
270
|
-
// Sign a transaction (without sending)
|
|
271
|
-
const signedTx = await ethereum.signTransaction(transactionData);
|
|
276
|
+
// Sign a transaction (without sending)
|
|
277
|
+
const signedTx = await ethereum.signTransaction(transactionData);
|
|
272
278
|
|
|
273
|
-
// Sign and send a transaction
|
|
274
|
-
const result = await ethereum.sendTransaction(transactionData);
|
|
279
|
+
// Sign and send a transaction
|
|
280
|
+
const result = await ethereum.sendTransaction(transactionData);
|
|
275
281
|
|
|
276
|
-
// Get current chain ID
|
|
277
|
-
const chainId = await ethereum.getChainId();
|
|
282
|
+
// Get current chain ID
|
|
283
|
+
const chainId = await ethereum.getChainId();
|
|
284
|
+
}
|
|
278
285
|
```
|
|
279
286
|
|
|
280
287
|
#### useDisconnect
|
|
@@ -336,11 +343,9 @@ import { PhantomProvider, AddressType } from "@phantom/react-native-sdk";
|
|
|
336
343
|
|
|
337
344
|
<PhantomProvider
|
|
338
345
|
config={{
|
|
339
|
-
appId: "
|
|
346
|
+
appId: "your-app-id",
|
|
340
347
|
scheme: "myapp",
|
|
341
|
-
embeddedWalletType: "user-wallet",
|
|
342
348
|
addressTypes: [AddressType.solana],
|
|
343
|
-
apiBaseUrl: "https://api.phantom.app/v1/wallets",
|
|
344
349
|
}}
|
|
345
350
|
>
|
|
346
351
|
<App />
|
|
@@ -354,14 +359,10 @@ import { PhantomProvider, AddressType } from "@phantom/react-native-sdk";
|
|
|
354
359
|
|
|
355
360
|
<PhantomProvider
|
|
356
361
|
config={{
|
|
357
|
-
appId: "
|
|
362
|
+
appId: "your-app-id",
|
|
358
363
|
scheme: "mycompany-wallet",
|
|
359
|
-
embeddedWalletType: "user-wallet",
|
|
360
364
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
361
|
-
apiBaseUrl: "https://api.phantom.app/v1/wallets",
|
|
362
|
-
solanaProvider: "web3js",
|
|
363
365
|
authOptions: {
|
|
364
|
-
authUrl: "https://connect.phantom.app",
|
|
365
366
|
redirectUrl: "mycompany-wallet://auth/success",
|
|
366
367
|
},
|
|
367
368
|
}}
|
|
@@ -395,13 +396,9 @@ import { PhantomProvider, AddressType } from '@phantom/react-native-sdk';
|
|
|
395
396
|
const testConfig = {
|
|
396
397
|
appId: "test-app",
|
|
397
398
|
scheme: "testapp",
|
|
398
|
-
embeddedWalletType: "app-wallet" as const,
|
|
399
399
|
addressTypes: [AddressType.solana],
|
|
400
|
-
apiBaseUrl: "https://api.phantom.app/v1/wallets",
|
|
401
|
-
|
|
402
400
|
};
|
|
403
401
|
|
|
404
|
-
// Use app-wallet for testing (no OAuth required)
|
|
405
402
|
<PhantomProvider config={testConfig}>
|
|
406
403
|
<TestApp />
|
|
407
404
|
</PhantomProvider>
|
|
@@ -426,7 +423,7 @@ adb shell am start -W -a android.intent.action.VIEW -d "myapp://phantom-auth-cal
|
|
|
426
423
|
- Check `app.json` (Expo) or platform-specific configuration
|
|
427
424
|
|
|
428
425
|
2. **"Authentication failed"**
|
|
429
|
-
- Verify your
|
|
426
|
+
- Verify your app ID is correct
|
|
430
427
|
- Check network connectivity
|
|
431
428
|
- Ensure redirect URL matches your scheme
|
|
432
429
|
|
|
@@ -450,6 +447,7 @@ import { PhantomProvider, type PhantomSDKConfig, type PhantomDebugConfig } from
|
|
|
450
447
|
function App() {
|
|
451
448
|
// SDK configuration - static, won't change when debug settings change
|
|
452
449
|
const config: PhantomSDKConfig = {
|
|
450
|
+
appId: "your-app-id",
|
|
453
451
|
scheme: "mywalletapp",
|
|
454
452
|
// ... other config
|
|
455
453
|
};
|
|
@@ -475,11 +473,3 @@ interface PhantomDebugConfig {
|
|
|
475
473
|
}
|
|
476
474
|
```
|
|
477
475
|
|
|
478
|
-
## Support
|
|
479
|
-
|
|
480
|
-
- **Documentation**: [phantom.app/docs](https://phantom.app/docs)
|
|
481
|
-
- **GitHub Issues**: [github.com/phantom/wallet-sdk/issues](https://github.com/phantom/wallet-sdk/issues)
|
|
482
|
-
|
|
483
|
-
## License
|
|
484
|
-
|
|
485
|
-
MIT License - see [LICENSE](LICENSE) file for details.
|
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
|
2
2
|
import { ReactNode } from 'react';
|
|
3
3
|
import * as _phantom_embedded_provider_core from '@phantom/embedded-provider-core';
|
|
4
4
|
import { EmbeddedProviderConfig, EmbeddedProvider, WalletAddress, ConnectResult } from '@phantom/embedded-provider-core';
|
|
5
|
-
export { ConnectResult, SignAndSendTransactionParams, SignMessageParams, SignMessageResult, SignedTransaction, WalletAddress } from '@phantom/embedded-provider-core';
|
|
6
|
-
import { ISolanaChain, IEthereumChain
|
|
5
|
+
export { ConnectErrorEventData, ConnectEventData, ConnectResult, ConnectStartEventData, DisconnectEventData, EmbeddedProviderEvent, EmbeddedProviderEventMap, EventCallback, SignAndSendTransactionParams, SignMessageParams, SignMessageResult, SignedTransaction, WalletAddress } from '@phantom/embedded-provider-core';
|
|
6
|
+
import { ISolanaChain, IEthereumChain } from '@phantom/chain-interfaces';
|
|
7
7
|
export { AddressType } from '@phantom/client';
|
|
8
8
|
export { NetworkId } from '@phantom/constants';
|
|
9
9
|
|
|
@@ -11,15 +11,23 @@ interface PhantomDebugConfig {
|
|
|
11
11
|
/** Enable debug logging */
|
|
12
12
|
enabled?: boolean;
|
|
13
13
|
}
|
|
14
|
-
interface PhantomSDKConfig extends EmbeddedProviderConfig {
|
|
14
|
+
interface PhantomSDKConfig extends Omit<EmbeddedProviderConfig, "apiBaseUrl" | "embeddedWalletType" | "authOptions"> {
|
|
15
15
|
/** Custom URL scheme for your app (e.g., "myapp") */
|
|
16
16
|
scheme: string;
|
|
17
17
|
/** Enable auto-connect to existing sessions (default: true) */
|
|
18
18
|
autoConnect?: boolean;
|
|
19
|
+
/** Base URL for Phantom API (default: "https://api.phantom.app/v1/wallets") */
|
|
20
|
+
apiBaseUrl?: string;
|
|
21
|
+
/** Authentication options */
|
|
22
|
+
embeddedWalletType?: "app-wallet" | "user-wallet";
|
|
23
|
+
authOptions?: {
|
|
24
|
+
authUrl?: string;
|
|
25
|
+
redirectUrl?: string;
|
|
26
|
+
};
|
|
19
27
|
}
|
|
20
28
|
interface ConnectOptions {
|
|
21
|
-
/** OAuth provider to use */
|
|
22
|
-
provider
|
|
29
|
+
/** OAuth provider to use (required) */
|
|
30
|
+
provider: "google" | "apple" | "jwt" | "phantom";
|
|
23
31
|
/** JWT token for JWT authentication */
|
|
24
32
|
jwtToken?: string;
|
|
25
33
|
/** Custom authentication data */
|
|
@@ -27,13 +35,14 @@ interface ConnectOptions {
|
|
|
27
35
|
}
|
|
28
36
|
|
|
29
37
|
interface PhantomContextValue {
|
|
30
|
-
sdk: EmbeddedProvider
|
|
38
|
+
sdk: EmbeddedProvider;
|
|
31
39
|
isConnected: boolean;
|
|
32
40
|
isConnecting: boolean;
|
|
33
41
|
connectError: Error | null;
|
|
34
42
|
addresses: WalletAddress[];
|
|
35
43
|
walletId: string | null;
|
|
36
44
|
setWalletId: (walletId: string | null) => void;
|
|
45
|
+
user: ConnectResult | null;
|
|
37
46
|
}
|
|
38
47
|
interface PhantomProviderProps {
|
|
39
48
|
children: ReactNode;
|
|
@@ -44,7 +53,7 @@ declare function PhantomProvider({ children, config, debugConfig }: PhantomProvi
|
|
|
44
53
|
declare function usePhantom(): PhantomContextValue;
|
|
45
54
|
|
|
46
55
|
declare function useConnect(): {
|
|
47
|
-
connect: (
|
|
56
|
+
connect: (options: ConnectOptions) => Promise<ConnectResult>;
|
|
48
57
|
isConnecting: boolean;
|
|
49
58
|
error: Error | null;
|
|
50
59
|
};
|
|
@@ -64,51 +73,21 @@ declare function useAccounts(): {
|
|
|
64
73
|
/**
|
|
65
74
|
* Hook for Solana chain operations in React Native
|
|
66
75
|
*
|
|
67
|
-
* @returns Solana chain interface
|
|
76
|
+
* @returns Solana chain interface with connection enforcement
|
|
68
77
|
*/
|
|
69
78
|
declare function useSolana(): {
|
|
70
|
-
solana: ISolanaChain
|
|
71
|
-
signMessage: (message: string | Uint8Array) => Promise<{
|
|
72
|
-
signature: Uint8Array;
|
|
73
|
-
publicKey: string;
|
|
74
|
-
}>;
|
|
75
|
-
signTransaction: <T>(transaction: T) => Promise<T>;
|
|
76
|
-
signAndSendTransaction: <T>(transaction: T) => Promise<{
|
|
77
|
-
signature: string;
|
|
78
|
-
}>;
|
|
79
|
-
connect: (options?: {
|
|
80
|
-
onlyIfTrusted?: boolean;
|
|
81
|
-
}) => Promise<{
|
|
82
|
-
publicKey: string;
|
|
83
|
-
}>;
|
|
84
|
-
disconnect: () => Promise<void>;
|
|
85
|
-
switchNetwork: (network: "mainnet" | "devnet") => Promise<void | undefined>;
|
|
86
|
-
getPublicKey: () => Promise<string | null>;
|
|
79
|
+
solana: ISolanaChain;
|
|
87
80
|
isAvailable: boolean;
|
|
88
|
-
isConnected: boolean;
|
|
89
81
|
};
|
|
90
82
|
|
|
91
83
|
/**
|
|
92
84
|
* Hook for Ethereum chain operations in React Native
|
|
93
85
|
*
|
|
94
|
-
* @returns Ethereum chain interface
|
|
86
|
+
* @returns Ethereum chain interface with connection enforcement
|
|
95
87
|
*/
|
|
96
88
|
declare function useEthereum(): {
|
|
97
|
-
ethereum: IEthereumChain
|
|
98
|
-
request: <T = any>(args: {
|
|
99
|
-
method: string;
|
|
100
|
-
params?: unknown[];
|
|
101
|
-
}) => Promise<T>;
|
|
102
|
-
signPersonalMessage: (message: string, address: string) => Promise<string>;
|
|
103
|
-
signMessage: (message: string) => Promise<string>;
|
|
104
|
-
signTransaction: (transaction: EthTransactionRequest) => Promise<string>;
|
|
105
|
-
signTypedData: (typedData: any) => Promise<string>;
|
|
106
|
-
sendTransaction: (transaction: EthTransactionRequest) => Promise<string>;
|
|
107
|
-
switchChain: (chainId: number) => Promise<void>;
|
|
108
|
-
getChainId: () => Promise<number>;
|
|
109
|
-
getAccounts: () => Promise<string[]>;
|
|
89
|
+
ethereum: IEthereumChain;
|
|
110
90
|
isAvailable: boolean;
|
|
111
|
-
isConnected: boolean;
|
|
112
91
|
};
|
|
113
92
|
|
|
114
93
|
export { ConnectOptions, PhantomDebugConfig, PhantomProvider, PhantomSDKConfig, useAccounts, useConnect, useDisconnect, useEthereum, usePhantom, useSolana };
|