@phantom/react-native-sdk 0.1.1 → 0.1.2
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 +11 -5
- package/dist/index.d.ts +4 -10
- package/dist/index.js +29 -6
- package/dist/index.mjs +29 -6
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -94,9 +94,12 @@ export default function App() {
|
|
|
94
94
|
embeddedWalletType: "user-wallet",
|
|
95
95
|
addressTypes: [AddressType.solana],
|
|
96
96
|
apiBaseUrl: "https://api.phantom.app/v1/wallets",
|
|
97
|
+
solanaProvider: "web3js",
|
|
97
98
|
authOptions: {
|
|
98
99
|
redirectUrl: "mywalletapp://phantom-auth-callback",
|
|
99
100
|
},
|
|
101
|
+
appName: "My Wallet App", // Optional branding
|
|
102
|
+
debug: false, // Optional debug logging
|
|
100
103
|
}}
|
|
101
104
|
>
|
|
102
105
|
<YourAppContent />
|
|
@@ -115,7 +118,7 @@ import { useConnect, useAccounts, useSignMessage, useDisconnect } from "@phantom
|
|
|
115
118
|
|
|
116
119
|
export function WalletScreen() {
|
|
117
120
|
const { connect, isConnecting, error: connectError } = useConnect();
|
|
118
|
-
const { addresses, isConnected
|
|
121
|
+
const { addresses, isConnected } = useAccounts();
|
|
119
122
|
const { signMessage, isSigning } = useSignMessage();
|
|
120
123
|
const { disconnect } = useDisconnect();
|
|
121
124
|
|
|
@@ -156,7 +159,6 @@ export function WalletScreen() {
|
|
|
156
159
|
return (
|
|
157
160
|
<View style={{ padding: 20 }}>
|
|
158
161
|
<Text style={{ fontSize: 18, marginBottom: 10 }}>Wallet Connected</Text>
|
|
159
|
-
<Text>Wallet ID: {walletId}</Text>
|
|
160
162
|
<Text>Address: {addresses[0]?.address}</Text>
|
|
161
163
|
|
|
162
164
|
<Button
|
|
@@ -187,16 +189,20 @@ The main provider component that initializes the SDK and provides context to all
|
|
|
187
189
|
#### Configuration Options
|
|
188
190
|
|
|
189
191
|
```typescript
|
|
190
|
-
interface
|
|
192
|
+
interface PhantomSDKConfig {
|
|
191
193
|
organizationId: string; // Your Phantom organization ID
|
|
192
194
|
scheme: string; // Custom URL scheme for your app
|
|
193
195
|
embeddedWalletType: "user-wallet" | "app-wallet";
|
|
194
|
-
addressTypes: AddressType[];
|
|
195
|
-
apiBaseUrl: "https://api.phantom.app/v1/wallets"
|
|
196
|
+
addressTypes: AddressType[]; // e.g., [AddressType.solana]
|
|
197
|
+
apiBaseUrl: string; // e.g., "https://api.phantom.app/v1/wallets"
|
|
198
|
+
solanaProvider: "web3js" | "kit"; // Solana provider to use
|
|
196
199
|
authOptions?: {
|
|
197
200
|
authUrl?: string; // Custom auth URL (optional)
|
|
198
201
|
redirectUrl?: string; // Custom redirect URL (optional)
|
|
199
202
|
};
|
|
203
|
+
appName?: string; // Optional app name for branding
|
|
204
|
+
appLogo?: string; // Optional app logo URL for branding
|
|
205
|
+
debug?: boolean; // Enable debug logging (optional)
|
|
200
206
|
}
|
|
201
207
|
```
|
|
202
208
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,23 +1,17 @@
|
|
|
1
1
|
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
|
-
import { EmbeddedProviderConfig,
|
|
4
|
+
import { EmbeddedProviderConfig, EmbeddedProvider, WalletAddress, ConnectResult, SignMessageParams, SignMessageResult, SignAndSendTransactionParams, SignedTransaction } from '@phantom/embedded-provider-core';
|
|
5
5
|
export { ConnectResult, SignAndSendTransactionParams, SignMessageParams, SignMessageResult, SignedTransaction, WalletAddress } from '@phantom/embedded-provider-core';
|
|
6
6
|
export { AddressType } from '@phantom/client';
|
|
7
7
|
export { NetworkId } from '@phantom/constants';
|
|
8
8
|
|
|
9
|
-
interface
|
|
9
|
+
interface PhantomSDKConfig extends EmbeddedProviderConfig {
|
|
10
10
|
/** Custom URL scheme for your app (e.g., "myapp") */
|
|
11
11
|
scheme: string;
|
|
12
|
-
/** Authentication options */
|
|
13
|
-
authOptions?: ReactNativeAuthOptions;
|
|
14
12
|
/** Enable debug logging */
|
|
15
13
|
debug?: boolean;
|
|
16
14
|
}
|
|
17
|
-
interface ReactNativeAuthOptions extends AuthOptions {
|
|
18
|
-
/** Custom redirect URL - defaults to {scheme}://phantom-auth-callback */
|
|
19
|
-
redirectUrl?: string;
|
|
20
|
-
}
|
|
21
15
|
interface ConnectOptions {
|
|
22
16
|
/** OAuth provider to use */
|
|
23
17
|
provider?: "google" | "apple" | "jwt";
|
|
@@ -38,7 +32,7 @@ interface PhantomContextValue {
|
|
|
38
32
|
}
|
|
39
33
|
interface PhantomProviderProps {
|
|
40
34
|
children: ReactNode;
|
|
41
|
-
config:
|
|
35
|
+
config: PhantomSDKConfig;
|
|
42
36
|
}
|
|
43
37
|
declare function PhantomProvider({ children, config }: PhantomProviderProps): react_jsx_runtime.JSX.Element;
|
|
44
38
|
/**
|
|
@@ -78,4 +72,4 @@ declare function useSignAndSendTransaction(): {
|
|
|
78
72
|
error: Error | null;
|
|
79
73
|
};
|
|
80
74
|
|
|
81
|
-
export { ConnectOptions, PhantomProvider,
|
|
75
|
+
export { ConnectOptions, PhantomProvider, PhantomSDKConfig, useAccounts, useConnect, useDisconnect, usePhantom, useSignAndSendTransaction, useSignMessage };
|
package/dist/index.js
CHANGED
|
@@ -103,7 +103,17 @@ var ExpoAuthProvider = class {
|
|
|
103
103
|
return;
|
|
104
104
|
}
|
|
105
105
|
const phantomOptions = options;
|
|
106
|
-
const {
|
|
106
|
+
const {
|
|
107
|
+
authUrl,
|
|
108
|
+
redirectUrl,
|
|
109
|
+
organizationId,
|
|
110
|
+
parentOrganizationId,
|
|
111
|
+
sessionId,
|
|
112
|
+
provider,
|
|
113
|
+
customAuthData,
|
|
114
|
+
appName,
|
|
115
|
+
appLogo
|
|
116
|
+
} = phantomOptions;
|
|
107
117
|
if (!redirectUrl) {
|
|
108
118
|
throw new Error("redirectUrl is required for web browser authentication");
|
|
109
119
|
}
|
|
@@ -117,7 +127,11 @@ var ExpoAuthProvider = class {
|
|
|
117
127
|
parent_organization_id: parentOrganizationId,
|
|
118
128
|
redirect_uri: redirectUrl,
|
|
119
129
|
session_id: sessionId,
|
|
120
|
-
clear_previous_session: "true"
|
|
130
|
+
clear_previous_session: "true",
|
|
131
|
+
app_name: appName || "",
|
|
132
|
+
// Optional app name
|
|
133
|
+
app_logo: appLogo || ""
|
|
134
|
+
// Optional app logo URL
|
|
121
135
|
});
|
|
122
136
|
if (provider) {
|
|
123
137
|
console.log("[ExpoAuthProvider] Provider specified, will skip selection", { provider });
|
|
@@ -321,9 +335,7 @@ var ReactNativeStamper = class {
|
|
|
321
335
|
* @param data - Data to sign (Buffer)
|
|
322
336
|
* @returns Complete X-Phantom-Stamp header value
|
|
323
337
|
*/
|
|
324
|
-
async stamp({
|
|
325
|
-
data
|
|
326
|
-
}) {
|
|
338
|
+
async stamp({ data }) {
|
|
327
339
|
if (!this.keyInfo) {
|
|
328
340
|
throw new Error("Stamper not initialized. Call init() first.");
|
|
329
341
|
}
|
|
@@ -416,7 +428,10 @@ function PhantomProvider({ children, config }) {
|
|
|
416
428
|
},
|
|
417
429
|
embeddedWalletType: config.embeddedWalletType,
|
|
418
430
|
addressTypes: config.addressTypes,
|
|
419
|
-
solanaProvider: config.solanaProvider || "web3js"
|
|
431
|
+
solanaProvider: config.solanaProvider || "web3js",
|
|
432
|
+
appName: config.appName,
|
|
433
|
+
appLogo: config.appLogo
|
|
434
|
+
// Optional app logo URL
|
|
420
435
|
};
|
|
421
436
|
const storage = new ExpoSecureStorage();
|
|
422
437
|
const authProvider = new ExpoAuthProvider();
|
|
@@ -453,6 +468,14 @@ function PhantomProvider({ children, config }) {
|
|
|
453
468
|
} catch (err) {
|
|
454
469
|
console.error("[PhantomProvider] Error updating connection state", err);
|
|
455
470
|
setError(err);
|
|
471
|
+
try {
|
|
472
|
+
sdk.disconnect();
|
|
473
|
+
setIsConnected(false);
|
|
474
|
+
setAddresses([]);
|
|
475
|
+
setWalletId(null);
|
|
476
|
+
} catch (disconnectErr) {
|
|
477
|
+
console.error("[PhantomProvider] Error disconnecting after error", disconnectErr);
|
|
478
|
+
}
|
|
456
479
|
}
|
|
457
480
|
}, [sdk]);
|
|
458
481
|
(0, import_react.useEffect)(() => {
|
package/dist/index.mjs
CHANGED
|
@@ -59,7 +59,17 @@ var ExpoAuthProvider = class {
|
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
61
|
const phantomOptions = options;
|
|
62
|
-
const {
|
|
62
|
+
const {
|
|
63
|
+
authUrl,
|
|
64
|
+
redirectUrl,
|
|
65
|
+
organizationId,
|
|
66
|
+
parentOrganizationId,
|
|
67
|
+
sessionId,
|
|
68
|
+
provider,
|
|
69
|
+
customAuthData,
|
|
70
|
+
appName,
|
|
71
|
+
appLogo
|
|
72
|
+
} = phantomOptions;
|
|
63
73
|
if (!redirectUrl) {
|
|
64
74
|
throw new Error("redirectUrl is required for web browser authentication");
|
|
65
75
|
}
|
|
@@ -73,7 +83,11 @@ var ExpoAuthProvider = class {
|
|
|
73
83
|
parent_organization_id: parentOrganizationId,
|
|
74
84
|
redirect_uri: redirectUrl,
|
|
75
85
|
session_id: sessionId,
|
|
76
|
-
clear_previous_session: "true"
|
|
86
|
+
clear_previous_session: "true",
|
|
87
|
+
app_name: appName || "",
|
|
88
|
+
// Optional app name
|
|
89
|
+
app_logo: appLogo || ""
|
|
90
|
+
// Optional app logo URL
|
|
77
91
|
});
|
|
78
92
|
if (provider) {
|
|
79
93
|
console.log("[ExpoAuthProvider] Provider specified, will skip selection", { provider });
|
|
@@ -277,9 +291,7 @@ var ReactNativeStamper = class {
|
|
|
277
291
|
* @param data - Data to sign (Buffer)
|
|
278
292
|
* @returns Complete X-Phantom-Stamp header value
|
|
279
293
|
*/
|
|
280
|
-
async stamp({
|
|
281
|
-
data
|
|
282
|
-
}) {
|
|
294
|
+
async stamp({ data }) {
|
|
283
295
|
if (!this.keyInfo) {
|
|
284
296
|
throw new Error("Stamper not initialized. Call init() first.");
|
|
285
297
|
}
|
|
@@ -372,7 +384,10 @@ function PhantomProvider({ children, config }) {
|
|
|
372
384
|
},
|
|
373
385
|
embeddedWalletType: config.embeddedWalletType,
|
|
374
386
|
addressTypes: config.addressTypes,
|
|
375
|
-
solanaProvider: config.solanaProvider || "web3js"
|
|
387
|
+
solanaProvider: config.solanaProvider || "web3js",
|
|
388
|
+
appName: config.appName,
|
|
389
|
+
appLogo: config.appLogo
|
|
390
|
+
// Optional app logo URL
|
|
376
391
|
};
|
|
377
392
|
const storage = new ExpoSecureStorage();
|
|
378
393
|
const authProvider = new ExpoAuthProvider();
|
|
@@ -409,6 +424,14 @@ function PhantomProvider({ children, config }) {
|
|
|
409
424
|
} catch (err) {
|
|
410
425
|
console.error("[PhantomProvider] Error updating connection state", err);
|
|
411
426
|
setError(err);
|
|
427
|
+
try {
|
|
428
|
+
sdk.disconnect();
|
|
429
|
+
setIsConnected(false);
|
|
430
|
+
setAddresses([]);
|
|
431
|
+
setWalletId(null);
|
|
432
|
+
} catch (disconnectErr) {
|
|
433
|
+
console.error("[PhantomProvider] Error disconnecting after error", disconnectErr);
|
|
434
|
+
}
|
|
412
435
|
}
|
|
413
436
|
}, [sdk]);
|
|
414
437
|
useEffect(() => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phantom/react-native-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Phantom Wallet SDK for React Native and Expo applications",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -45,13 +45,13 @@
|
|
|
45
45
|
"directory": "packages/react-native-sdk"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@phantom/api-key-stamper": "^0.1.
|
|
48
|
+
"@phantom/api-key-stamper": "^0.1.3",
|
|
49
49
|
"@phantom/base64url": "^0.1.0",
|
|
50
|
-
"@phantom/client": "^0.1.
|
|
50
|
+
"@phantom/client": "^0.1.6",
|
|
51
51
|
"@phantom/constants": "^0.0.2",
|
|
52
|
-
"@phantom/crypto": "^0.1.
|
|
53
|
-
"@phantom/embedded-provider-core": "^0.1.
|
|
54
|
-
"@phantom/sdk-types": "^0.1.
|
|
52
|
+
"@phantom/crypto": "^0.1.2",
|
|
53
|
+
"@phantom/embedded-provider-core": "^0.1.3",
|
|
54
|
+
"@phantom/sdk-types": "^0.1.2",
|
|
55
55
|
"@types/bs58": "^5.0.0",
|
|
56
56
|
"bs58": "^6.0.0",
|
|
57
57
|
"buffer": "^6.0.3"
|