@phantom/browser-sdk 0.2.1 → 0.2.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 +60 -1
- package/dist/index.d.ts +66 -23
- package/dist/index.js +349 -118
- package/dist/index.mjs +347 -116
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -83,6 +83,10 @@ const sdk = new BrowserSDK({
|
|
|
83
83
|
apiBaseUrl: "https://api.phantom.com",
|
|
84
84
|
organizationId: "your-org-id",
|
|
85
85
|
embeddedWalletType: "app-wallet", // or 'user-wallet'
|
|
86
|
+
authOptions: {
|
|
87
|
+
authUrl: "https://auth.phantom.app", // optional, defaults to "https://connect.phantom.app"
|
|
88
|
+
redirectUrl: "https://yourapp.com/callback", // optional, defaults to current page
|
|
89
|
+
},
|
|
86
90
|
});
|
|
87
91
|
```
|
|
88
92
|
|
|
@@ -170,7 +174,10 @@ interface BrowserSDKConfig {
|
|
|
170
174
|
addressTypes?: AddressType[]; // Networks to enable
|
|
171
175
|
apiBaseUrl?: string; // Phantom API base URL
|
|
172
176
|
organizationId?: string; // Your organization ID
|
|
173
|
-
|
|
177
|
+
authOptions?: {
|
|
178
|
+
authUrl?: string; // Custom auth URL (default: "https://connect.phantom.app")
|
|
179
|
+
redirectUrl?: string; // Custom redirect URL after authentication
|
|
180
|
+
};
|
|
174
181
|
embeddedWalletType?: "app-wallet" | "user-wallet"; // Wallet type
|
|
175
182
|
solanaProvider?: "web3js" | "kit"; // Solana library choice (default: 'web3js')
|
|
176
183
|
}
|
|
@@ -188,6 +195,58 @@ const result = await sdk.connect();
|
|
|
188
195
|
// addresses only includes types from addressTypes config
|
|
189
196
|
```
|
|
190
197
|
|
|
198
|
+
For embedded user-wallets, you can specify authentication options:
|
|
199
|
+
|
|
200
|
+
```typescript
|
|
201
|
+
// Phantom Connect with provider selection (default)
|
|
202
|
+
const result = await sdk.connect();
|
|
203
|
+
|
|
204
|
+
// Phantom Connect with Google authentication (skips provider selection)
|
|
205
|
+
const result = await sdk.connect({
|
|
206
|
+
authOptions: {
|
|
207
|
+
provider: "google",
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// Phantom Connect with Apple authentication (skips provider selection)
|
|
212
|
+
const result = await sdk.connect({
|
|
213
|
+
authOptions: {
|
|
214
|
+
provider: "apple",
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
// JWT authentication (direct API call)
|
|
219
|
+
const result = await sdk.connect({
|
|
220
|
+
authOptions: {
|
|
221
|
+
provider: "jwt",
|
|
222
|
+
jwtToken: "your-jwt-token",
|
|
223
|
+
customAuthData: { userId: "user123" },
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
**Authentication Options:**
|
|
229
|
+
|
|
230
|
+
- `provider` - Authentication method: `"google"`, `"apple"`, or `"jwt"`
|
|
231
|
+
- If not specified: Shows provider selection screen on Phantom Connect
|
|
232
|
+
- If `"google"` or `"apple"`: Skips provider selection and uses specified provider
|
|
233
|
+
- If `"jwt"`: Uses JWT authentication flow via API call
|
|
234
|
+
- `jwtToken` - Required when `provider` is `"jwt"`. Your JWT token for authentication
|
|
235
|
+
- `customAuthData` - Additional data to pass to authentication service
|
|
236
|
+
|
|
237
|
+
**Authentication Flow Types:**
|
|
238
|
+
|
|
239
|
+
1. **Phantom Connect (Redirect-based)**: Used when `provider` is undefined, `"google"`, or `"apple"`
|
|
240
|
+
|
|
241
|
+
- Redirects to `https://connect.phantom.app` (or custom `authOptions.authUrl` from config)
|
|
242
|
+
- Handles OAuth flow with selected provider
|
|
243
|
+
- Returns to your app with authentication result using `authOptions.redirectUrl` or current page
|
|
244
|
+
|
|
245
|
+
2. **JWT Authentication (API-based)**: Used when `provider` is `"jwt"`
|
|
246
|
+
- Makes direct API call to `/api/auth/jwt` endpoint
|
|
247
|
+
- Validates JWT token server-side
|
|
248
|
+
- Returns wallet immediately without redirect
|
|
249
|
+
|
|
191
250
|
#### signAndSendTransaction(transaction)
|
|
192
251
|
|
|
193
252
|
Sign and send a native transaction object.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,51 @@
|
|
|
1
|
-
import { AddressType
|
|
1
|
+
import { AddressType } from '@phantom/client';
|
|
2
2
|
export { AddressType, NetworkId } from '@phantom/client';
|
|
3
|
+
import { AuthOptions, ConnectResult, SignMessageParams, SignAndSendTransactionParams, SignedTransaction, WalletAddress } from '@phantom/embedded-provider-core';
|
|
4
|
+
export { AuthOptions, ConnectResult, SignAndSendTransactionParams, SignMessageParams, SignedTransaction, WalletAddress } from '@phantom/embedded-provider-core';
|
|
5
|
+
|
|
6
|
+
declare enum DebugLevel {
|
|
7
|
+
ERROR = 0,
|
|
8
|
+
WARN = 1,
|
|
9
|
+
INFO = 2,
|
|
10
|
+
DEBUG = 3
|
|
11
|
+
}
|
|
12
|
+
interface DebugMessage {
|
|
13
|
+
timestamp: number;
|
|
14
|
+
level: DebugLevel;
|
|
15
|
+
category: string;
|
|
16
|
+
message: string;
|
|
17
|
+
data?: any;
|
|
18
|
+
}
|
|
19
|
+
type DebugCallback = (message: DebugMessage) => void;
|
|
20
|
+
declare class Debug {
|
|
21
|
+
private static instance;
|
|
22
|
+
private callback?;
|
|
23
|
+
private level;
|
|
24
|
+
private enabled;
|
|
25
|
+
private constructor();
|
|
26
|
+
static getInstance(): Debug;
|
|
27
|
+
setCallback(callback: DebugCallback): void;
|
|
28
|
+
setLevel(level: DebugLevel): void;
|
|
29
|
+
enable(): void;
|
|
30
|
+
disable(): void;
|
|
31
|
+
private writeLog;
|
|
32
|
+
error(category: string, message: string, data?: any): void;
|
|
33
|
+
warn(category: string, message: string, data?: any): void;
|
|
34
|
+
info(category: string, message: string, data?: any): void;
|
|
35
|
+
debug(category: string, message: string, data?: any): void;
|
|
36
|
+
log(category: string, message: string, data?: any): void;
|
|
37
|
+
}
|
|
38
|
+
declare const debug: Debug;
|
|
39
|
+
declare const DebugCategory: {
|
|
40
|
+
readonly BROWSER_SDK: "BrowserSDK";
|
|
41
|
+
readonly PROVIDER_MANAGER: "ProviderManager";
|
|
42
|
+
readonly EMBEDDED_PROVIDER: "EmbeddedProvider";
|
|
43
|
+
readonly INJECTED_PROVIDER: "InjectedProvider";
|
|
44
|
+
readonly PHANTOM_CONNECT_AUTH: "PhantomConnectAuth";
|
|
45
|
+
readonly JWT_AUTH: "JWTAuth";
|
|
46
|
+
readonly STORAGE: "Storage";
|
|
47
|
+
readonly SESSION: "Session";
|
|
48
|
+
};
|
|
3
49
|
|
|
4
50
|
interface BrowserSDKConfig {
|
|
5
51
|
providerType: "injected" | "embedded" | (string & Record<never, never>);
|
|
@@ -7,29 +53,18 @@ interface BrowserSDKConfig {
|
|
|
7
53
|
addressTypes?: AddressType[];
|
|
8
54
|
apiBaseUrl?: string;
|
|
9
55
|
organizationId?: string;
|
|
10
|
-
|
|
56
|
+
authOptions?: {
|
|
57
|
+
authUrl?: string;
|
|
58
|
+
redirectUrl?: string;
|
|
59
|
+
};
|
|
11
60
|
embeddedWalletType?: "app-wallet" | "user-wallet" | (string & Record<never, never>);
|
|
12
61
|
solanaProvider?: "web3js" | "kit";
|
|
13
62
|
serverUrl?: string;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
interface ConnectResult {
|
|
20
|
-
walletId?: string;
|
|
21
|
-
addresses: WalletAddress[];
|
|
22
|
-
}
|
|
23
|
-
interface SignMessageParams {
|
|
24
|
-
message: string;
|
|
25
|
-
networkId: NetworkId;
|
|
26
|
-
}
|
|
27
|
-
interface SignAndSendTransactionParams {
|
|
28
|
-
transaction: any;
|
|
29
|
-
networkId: NetworkId;
|
|
30
|
-
}
|
|
31
|
-
interface SignedTransaction {
|
|
32
|
-
rawTransaction: string;
|
|
63
|
+
debug?: {
|
|
64
|
+
enabled?: boolean;
|
|
65
|
+
level?: DebugLevel;
|
|
66
|
+
callback?: DebugCallback;
|
|
67
|
+
};
|
|
33
68
|
}
|
|
34
69
|
interface CreateUserOrganizationParams {
|
|
35
70
|
userId: string;
|
|
@@ -38,8 +73,9 @@ interface CreateUserOrganizationParams {
|
|
|
38
73
|
interface CreateUserOrganizationResult {
|
|
39
74
|
organizationId: string;
|
|
40
75
|
}
|
|
76
|
+
|
|
41
77
|
interface Provider {
|
|
42
|
-
connect(): Promise<ConnectResult>;
|
|
78
|
+
connect(authOptions?: AuthOptions): Promise<ConnectResult>;
|
|
43
79
|
disconnect(): Promise<void>;
|
|
44
80
|
signMessage(params: SignMessageParams): Promise<string>;
|
|
45
81
|
signAndSendTransaction(params: SignAndSendTransactionParams): Promise<SignedTransaction>;
|
|
@@ -65,6 +101,7 @@ declare class BrowserSDK {
|
|
|
65
101
|
connect(options?: {
|
|
66
102
|
providerType?: "injected" | "embedded" | (string & Record<never, never>);
|
|
67
103
|
embeddedWalletType?: "app-wallet" | "user-wallet" | (string & Record<never, never>);
|
|
104
|
+
authOptions?: AuthOptions;
|
|
68
105
|
}): Promise<ConnectResult>;
|
|
69
106
|
/**
|
|
70
107
|
* Switch to a different provider type
|
|
@@ -115,4 +152,10 @@ declare class BrowserSDK {
|
|
|
115
152
|
createUserOrganization(params: CreateUserOrganizationParams): Promise<CreateUserOrganizationResult>;
|
|
116
153
|
}
|
|
117
154
|
|
|
118
|
-
|
|
155
|
+
/**
|
|
156
|
+
* Constants used throughout the browser SDK
|
|
157
|
+
*/
|
|
158
|
+
declare const DEFAULT_AUTH_URL = "https://connect.phantom.app";
|
|
159
|
+
declare const DEFAULT_WALLET_API_URL = "https://api.phantom.app/v1/wallets";
|
|
160
|
+
|
|
161
|
+
export { BrowserSDK, BrowserSDKConfig, CreateUserOrganizationParams, CreateUserOrganizationResult, DEFAULT_AUTH_URL, DEFAULT_WALLET_API_URL, DebugCallback, DebugCategory, DebugLevel, DebugMessage, Provider, debug };
|