@phantom/react-native-sdk 0.1.1 → 0.1.3
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 +33 -8
- package/dist/index.mjs +33 -8
- 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 });
|
|
@@ -279,9 +293,11 @@ var import_crypto = require("@phantom/crypto");
|
|
|
279
293
|
var import_base64url = require("@phantom/base64url");
|
|
280
294
|
var import_sdk_types = require("@phantom/sdk-types");
|
|
281
295
|
var ReactNativeStamper = class {
|
|
296
|
+
// Optional for PKI, required for OIDC
|
|
282
297
|
constructor(config = {}) {
|
|
283
298
|
this.keyInfo = null;
|
|
284
299
|
this.algorithm = import_sdk_types.Algorithm.ed25519;
|
|
300
|
+
this.type = "PKI";
|
|
285
301
|
this.keyPrefix = config.keyPrefix || "phantom-rn-stamper";
|
|
286
302
|
this.organizationId = config.organizationId || "default";
|
|
287
303
|
}
|
|
@@ -318,12 +334,10 @@ var ReactNativeStamper = class {
|
|
|
318
334
|
}
|
|
319
335
|
/**
|
|
320
336
|
* Create X-Phantom-Stamp header value using stored secret key
|
|
321
|
-
* @param
|
|
337
|
+
* @param params - Parameters object with data to sign and optional override params
|
|
322
338
|
* @returns Complete X-Phantom-Stamp header value
|
|
323
339
|
*/
|
|
324
|
-
async stamp({
|
|
325
|
-
data
|
|
326
|
-
}) {
|
|
340
|
+
async stamp(params) {
|
|
327
341
|
if (!this.keyInfo) {
|
|
328
342
|
throw new Error("Stamper not initialized. Call init() first.");
|
|
329
343
|
}
|
|
@@ -332,7 +346,7 @@ var ReactNativeStamper = class {
|
|
|
332
346
|
throw new Error("Secret key not found in secure storage");
|
|
333
347
|
}
|
|
334
348
|
const apiKeyStamper = new import_api_key_stamper.ApiKeyStamper({ apiSecretKey: storedSecretKey });
|
|
335
|
-
return await apiKeyStamper.stamp(
|
|
349
|
+
return await apiKeyStamper.stamp(params);
|
|
336
350
|
}
|
|
337
351
|
/**
|
|
338
352
|
* Clear all stored keys from SecureStore
|
|
@@ -416,7 +430,10 @@ function PhantomProvider({ children, config }) {
|
|
|
416
430
|
},
|
|
417
431
|
embeddedWalletType: config.embeddedWalletType,
|
|
418
432
|
addressTypes: config.addressTypes,
|
|
419
|
-
solanaProvider: config.solanaProvider || "web3js"
|
|
433
|
+
solanaProvider: config.solanaProvider || "web3js",
|
|
434
|
+
appName: config.appName,
|
|
435
|
+
appLogo: config.appLogo
|
|
436
|
+
// Optional app logo URL
|
|
420
437
|
};
|
|
421
438
|
const storage = new ExpoSecureStorage();
|
|
422
439
|
const authProvider = new ExpoAuthProvider();
|
|
@@ -453,6 +470,14 @@ function PhantomProvider({ children, config }) {
|
|
|
453
470
|
} catch (err) {
|
|
454
471
|
console.error("[PhantomProvider] Error updating connection state", err);
|
|
455
472
|
setError(err);
|
|
473
|
+
try {
|
|
474
|
+
sdk.disconnect();
|
|
475
|
+
setIsConnected(false);
|
|
476
|
+
setAddresses([]);
|
|
477
|
+
setWalletId(null);
|
|
478
|
+
} catch (disconnectErr) {
|
|
479
|
+
console.error("[PhantomProvider] Error disconnecting after error", disconnectErr);
|
|
480
|
+
}
|
|
456
481
|
}
|
|
457
482
|
}, [sdk]);
|
|
458
483
|
(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 });
|
|
@@ -235,9 +249,11 @@ import { generateKeyPair } from "@phantom/crypto";
|
|
|
235
249
|
import { base64urlEncode } from "@phantom/base64url";
|
|
236
250
|
import { Algorithm } from "@phantom/sdk-types";
|
|
237
251
|
var ReactNativeStamper = class {
|
|
252
|
+
// Optional for PKI, required for OIDC
|
|
238
253
|
constructor(config = {}) {
|
|
239
254
|
this.keyInfo = null;
|
|
240
255
|
this.algorithm = Algorithm.ed25519;
|
|
256
|
+
this.type = "PKI";
|
|
241
257
|
this.keyPrefix = config.keyPrefix || "phantom-rn-stamper";
|
|
242
258
|
this.organizationId = config.organizationId || "default";
|
|
243
259
|
}
|
|
@@ -274,12 +290,10 @@ var ReactNativeStamper = class {
|
|
|
274
290
|
}
|
|
275
291
|
/**
|
|
276
292
|
* Create X-Phantom-Stamp header value using stored secret key
|
|
277
|
-
* @param
|
|
293
|
+
* @param params - Parameters object with data to sign and optional override params
|
|
278
294
|
* @returns Complete X-Phantom-Stamp header value
|
|
279
295
|
*/
|
|
280
|
-
async stamp({
|
|
281
|
-
data
|
|
282
|
-
}) {
|
|
296
|
+
async stamp(params) {
|
|
283
297
|
if (!this.keyInfo) {
|
|
284
298
|
throw new Error("Stamper not initialized. Call init() first.");
|
|
285
299
|
}
|
|
@@ -288,7 +302,7 @@ var ReactNativeStamper = class {
|
|
|
288
302
|
throw new Error("Secret key not found in secure storage");
|
|
289
303
|
}
|
|
290
304
|
const apiKeyStamper = new ApiKeyStamper({ apiSecretKey: storedSecretKey });
|
|
291
|
-
return await apiKeyStamper.stamp(
|
|
305
|
+
return await apiKeyStamper.stamp(params);
|
|
292
306
|
}
|
|
293
307
|
/**
|
|
294
308
|
* Clear all stored keys from SecureStore
|
|
@@ -372,7 +386,10 @@ function PhantomProvider({ children, config }) {
|
|
|
372
386
|
},
|
|
373
387
|
embeddedWalletType: config.embeddedWalletType,
|
|
374
388
|
addressTypes: config.addressTypes,
|
|
375
|
-
solanaProvider: config.solanaProvider || "web3js"
|
|
389
|
+
solanaProvider: config.solanaProvider || "web3js",
|
|
390
|
+
appName: config.appName,
|
|
391
|
+
appLogo: config.appLogo
|
|
392
|
+
// Optional app logo URL
|
|
376
393
|
};
|
|
377
394
|
const storage = new ExpoSecureStorage();
|
|
378
395
|
const authProvider = new ExpoAuthProvider();
|
|
@@ -409,6 +426,14 @@ function PhantomProvider({ children, config }) {
|
|
|
409
426
|
} catch (err) {
|
|
410
427
|
console.error("[PhantomProvider] Error updating connection state", err);
|
|
411
428
|
setError(err);
|
|
429
|
+
try {
|
|
430
|
+
sdk.disconnect();
|
|
431
|
+
setIsConnected(false);
|
|
432
|
+
setAddresses([]);
|
|
433
|
+
setWalletId(null);
|
|
434
|
+
} catch (disconnectErr) {
|
|
435
|
+
console.error("[PhantomProvider] Error disconnecting after error", disconnectErr);
|
|
436
|
+
}
|
|
412
437
|
}
|
|
413
438
|
}, [sdk]);
|
|
414
439
|
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.3",
|
|
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.4",
|
|
49
49
|
"@phantom/base64url": "^0.1.0",
|
|
50
|
-
"@phantom/client": "^0.1.
|
|
50
|
+
"@phantom/client": "^0.1.7",
|
|
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.4",
|
|
54
|
+
"@phantom/sdk-types": "^0.1.3",
|
|
55
55
|
"@types/bs58": "^5.0.0",
|
|
56
56
|
"bs58": "^6.0.0",
|
|
57
57
|
"buffer": "^6.0.3"
|