@phantom/react-native-sdk 1.0.0-beta.2 → 1.0.0-beta.21
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 +74 -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,24 +264,56 @@ 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();
|
|
268
|
+
|
|
269
|
+
if (isAvailable) {
|
|
270
|
+
// Get accounts
|
|
271
|
+
const accounts = await ethereum.getAccounts();
|
|
263
272
|
|
|
264
|
-
//
|
|
265
|
-
const
|
|
273
|
+
// Sign a personal message
|
|
274
|
+
const signature = await ethereum.signPersonalMessage("Hello Ethereum!", accounts[0]);
|
|
266
275
|
|
|
267
|
-
// Sign a
|
|
268
|
-
const
|
|
276
|
+
// Sign a transaction (without sending)
|
|
277
|
+
const signedTx = await ethereum.signTransaction(transactionData);
|
|
269
278
|
|
|
270
|
-
// Sign a transaction
|
|
271
|
-
const
|
|
279
|
+
// Sign and send a transaction
|
|
280
|
+
const result = await ethereum.sendTransaction(transactionData);
|
|
272
281
|
|
|
273
|
-
//
|
|
274
|
-
|
|
282
|
+
// Switch to a different chain
|
|
283
|
+
await ethereum.switchChain(137); // Switch to Polygon
|
|
284
|
+
await ethereum.switchChain("0x89"); // Also accepts hex strings
|
|
275
285
|
|
|
276
|
-
// Get current chain ID
|
|
277
|
-
const chainId = await ethereum.getChainId();
|
|
286
|
+
// Get current chain ID
|
|
287
|
+
const chainId = await ethereum.getChainId();
|
|
288
|
+
}
|
|
278
289
|
```
|
|
279
290
|
|
|
291
|
+
**Available Methods:**
|
|
292
|
+
|
|
293
|
+
- `getAccounts()` - Get connected Ethereum accounts
|
|
294
|
+
- `signPersonalMessage(message, address)` - Sign personal message
|
|
295
|
+
- `signTypedData(typedData, address)` - Sign EIP-712 typed data
|
|
296
|
+
- `signTransaction(transaction)` - Sign transaction without sending
|
|
297
|
+
- `sendTransaction(transaction)` - Sign and send transaction
|
|
298
|
+
- `switchChain(chainId)` - Switch chains (accepts chain ID as number or hex string)
|
|
299
|
+
- `getChainId()` - Get current chain ID
|
|
300
|
+
- `isConnected()` - Check connection status
|
|
301
|
+
|
|
302
|
+
**Supported EVM Networks:**
|
|
303
|
+
|
|
304
|
+
| Network | Chain ID | Usage |
|
|
305
|
+
|---------|----------|-------|
|
|
306
|
+
| Ethereum Mainnet | `1` | `ethereum.switchChain(1)` |
|
|
307
|
+
| Ethereum Sepolia | `11155111` | `ethereum.switchChain(11155111)` |
|
|
308
|
+
| Polygon Mainnet | `137` | `ethereum.switchChain(137)` |
|
|
309
|
+
| Polygon Amoy | `80002` | `ethereum.switchChain(80002)` |
|
|
310
|
+
| Base Mainnet | `8453` | `ethereum.switchChain(8453)` |
|
|
311
|
+
| Base Sepolia | `84532` | `ethereum.switchChain(84532)` |
|
|
312
|
+
| Arbitrum One | `42161` | `ethereum.switchChain(42161)` |
|
|
313
|
+
| Arbitrum Sepolia | `421614` | `ethereum.switchChain(421614)` |
|
|
314
|
+
| Monad Mainnet | `143` | `ethereum.switchChain(143)` |
|
|
315
|
+
| Monad Testnet | `10143` | `ethereum.switchChain(10143)` |
|
|
316
|
+
|
|
280
317
|
#### useDisconnect
|
|
281
318
|
|
|
282
319
|
Manages wallet disconnection.
|
|
@@ -336,11 +373,9 @@ import { PhantomProvider, AddressType } from "@phantom/react-native-sdk";
|
|
|
336
373
|
|
|
337
374
|
<PhantomProvider
|
|
338
375
|
config={{
|
|
339
|
-
appId: "
|
|
376
|
+
appId: "your-app-id",
|
|
340
377
|
scheme: "myapp",
|
|
341
|
-
embeddedWalletType: "user-wallet",
|
|
342
378
|
addressTypes: [AddressType.solana],
|
|
343
|
-
apiBaseUrl: "https://api.phantom.app/v1/wallets",
|
|
344
379
|
}}
|
|
345
380
|
>
|
|
346
381
|
<App />
|
|
@@ -354,14 +389,10 @@ import { PhantomProvider, AddressType } from "@phantom/react-native-sdk";
|
|
|
354
389
|
|
|
355
390
|
<PhantomProvider
|
|
356
391
|
config={{
|
|
357
|
-
appId: "
|
|
392
|
+
appId: "your-app-id",
|
|
358
393
|
scheme: "mycompany-wallet",
|
|
359
|
-
embeddedWalletType: "user-wallet",
|
|
360
394
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
361
|
-
apiBaseUrl: "https://api.phantom.app/v1/wallets",
|
|
362
|
-
solanaProvider: "web3js",
|
|
363
395
|
authOptions: {
|
|
364
|
-
authUrl: "https://connect.phantom.app",
|
|
365
396
|
redirectUrl: "mycompany-wallet://auth/success",
|
|
366
397
|
},
|
|
367
398
|
}}
|
|
@@ -395,13 +426,9 @@ import { PhantomProvider, AddressType } from '@phantom/react-native-sdk';
|
|
|
395
426
|
const testConfig = {
|
|
396
427
|
appId: "test-app",
|
|
397
428
|
scheme: "testapp",
|
|
398
|
-
embeddedWalletType: "app-wallet" as const,
|
|
399
429
|
addressTypes: [AddressType.solana],
|
|
400
|
-
apiBaseUrl: "https://api.phantom.app/v1/wallets",
|
|
401
|
-
|
|
402
430
|
};
|
|
403
431
|
|
|
404
|
-
// Use app-wallet for testing (no OAuth required)
|
|
405
432
|
<PhantomProvider config={testConfig}>
|
|
406
433
|
<TestApp />
|
|
407
434
|
</PhantomProvider>
|
|
@@ -426,7 +453,7 @@ adb shell am start -W -a android.intent.action.VIEW -d "myapp://phantom-auth-cal
|
|
|
426
453
|
- Check `app.json` (Expo) or platform-specific configuration
|
|
427
454
|
|
|
428
455
|
2. **"Authentication failed"**
|
|
429
|
-
- Verify your
|
|
456
|
+
- Verify your app ID is correct
|
|
430
457
|
- Check network connectivity
|
|
431
458
|
- Ensure redirect URL matches your scheme
|
|
432
459
|
|
|
@@ -450,6 +477,7 @@ import { PhantomProvider, type PhantomSDKConfig, type PhantomDebugConfig } from
|
|
|
450
477
|
function App() {
|
|
451
478
|
// SDK configuration - static, won't change when debug settings change
|
|
452
479
|
const config: PhantomSDKConfig = {
|
|
480
|
+
appId: "your-app-id",
|
|
453
481
|
scheme: "mywalletapp",
|
|
454
482
|
// ... other config
|
|
455
483
|
};
|
|
@@ -475,11 +503,3 @@ interface PhantomDebugConfig {
|
|
|
475
503
|
}
|
|
476
504
|
```
|
|
477
505
|
|
|
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 };
|