@phantom/browser-sdk 0.3.1 → 0.3.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 +22 -66
- package/dist/index.d.ts +2 -16
- package/dist/index.js +5 -28
- package/dist/index.mjs +5 -28
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -87,6 +87,12 @@ const sdk = new BrowserSDK({
|
|
|
87
87
|
authUrl: "https://auth.phantom.app", // optional, defaults to "https://connect.phantom.app"
|
|
88
88
|
redirectUrl: "https://yourapp.com/callback", // optional, defaults to current page
|
|
89
89
|
},
|
|
90
|
+
appName: "My DApp", // optional, for branding
|
|
91
|
+
appLogo: "https://myapp.com/logo.png", // optional, for branding
|
|
92
|
+
debug: {
|
|
93
|
+
enabled: true, // optional, enable debug logging
|
|
94
|
+
level: "info", // optional, debug level
|
|
95
|
+
},
|
|
90
96
|
});
|
|
91
97
|
```
|
|
92
98
|
|
|
@@ -169,9 +175,11 @@ new BrowserSDK(config: BrowserSDKConfig)
|
|
|
169
175
|
```typescript
|
|
170
176
|
interface BrowserSDKConfig {
|
|
171
177
|
providerType: "injected" | "embedded";
|
|
178
|
+
appName?: string; // Optional app name for branding
|
|
179
|
+
appLogo?: string; // Optional app logo URL for branding
|
|
180
|
+
addressTypes?: AddressType[]; // Networks to enable (e.g., [AddressType.solana])
|
|
172
181
|
|
|
173
182
|
// Required for embedded provider only
|
|
174
|
-
addressTypes?: AddressType[]; // Networks to enable
|
|
175
183
|
apiBaseUrl?: string; // Phantom API base URL
|
|
176
184
|
organizationId?: string; // Your organization ID
|
|
177
185
|
authOptions?: {
|
|
@@ -180,6 +188,13 @@ interface BrowserSDKConfig {
|
|
|
180
188
|
};
|
|
181
189
|
embeddedWalletType?: "app-wallet" | "user-wallet"; // Wallet type
|
|
182
190
|
solanaProvider?: "web3js" | "kit"; // Solana library choice (default: 'web3js')
|
|
191
|
+
|
|
192
|
+
// Debug options
|
|
193
|
+
debug?: {
|
|
194
|
+
enabled?: boolean; // Enable debug logging
|
|
195
|
+
level?: "info" | "warn" | "error"; // Debug level
|
|
196
|
+
callback?: (level: string, message: string, data?: any) => void; // Custom debug callback
|
|
197
|
+
};
|
|
183
198
|
}
|
|
184
199
|
```
|
|
185
200
|
|
|
@@ -662,12 +677,12 @@ try {
|
|
|
662
677
|
|
|
663
678
|
2. **Install dependencies based on enabled networks**:
|
|
664
679
|
|
|
665
|
-
| AddressType | Required Dependencies |
|
|
666
|
-
| --------------------------- | ---------------------------------- |
|
|
667
|
-
| `AddressType.solana` | `@solana/web3.js` OR `@solana/kit` |
|
|
668
|
-
| `AddressType.ethereum` | `viem` |
|
|
669
|
-
| `AddressType.bitcoinSegwit` | `bitcoinjs-lib` |
|
|
670
|
-
| `AddressType.sui` | `@mysten/sui.js` |
|
|
680
|
+
| AddressType | Required Dependencies |
|
|
681
|
+
| --------------------------- | ---------------------------------- |
|
|
682
|
+
| `AddressType.solana` | `@solana/web3.js` OR `@solana/kit` |
|
|
683
|
+
| `AddressType.ethereum` | `viem` |
|
|
684
|
+
| `AddressType.bitcoinSegwit` | `bitcoinjs-lib` |
|
|
685
|
+
| `AddressType.sui` | `@mysten/sui.js` |
|
|
671
686
|
|
|
672
687
|
**Example package.json for Solana + Ethereum (using @solana/web3.js)**:
|
|
673
688
|
|
|
@@ -742,62 +757,3 @@ try {
|
|
|
742
757
|
}
|
|
743
758
|
}
|
|
744
759
|
```
|
|
745
|
-
|
|
746
|
-
3. **Monitor bundle size**:
|
|
747
|
-
```bash
|
|
748
|
-
# Analyze your bundle
|
|
749
|
-
npx webpack-bundle-analyzer dist/main.js
|
|
750
|
-
```
|
|
751
|
-
|
|
752
|
-
## Server Setup for Embedded Wallets
|
|
753
|
-
|
|
754
|
-
For embedded wallets, you need to set up a backend endpoint. Add the `serverUrl` parameter to your SDK configuration:
|
|
755
|
-
|
|
756
|
-
```typescript
|
|
757
|
-
const sdk = new BrowserSDK({
|
|
758
|
-
providerType: "embedded",
|
|
759
|
-
addressTypes: [AddressType.solana],
|
|
760
|
-
apiBaseUrl: "https://api.phantom.app/v1/wallets",
|
|
761
|
-
organizationId: "your-org-id",
|
|
762
|
-
serverUrl: "http://localhost:3000/api",
|
|
763
|
-
});
|
|
764
|
-
```
|
|
765
|
-
|
|
766
|
-
### Required Backend Endpoint
|
|
767
|
-
|
|
768
|
-
Your backend needs an endpoint that uses the server-sdk:
|
|
769
|
-
|
|
770
|
-
```javascript
|
|
771
|
-
// server.js
|
|
772
|
-
const express = require("express");
|
|
773
|
-
const { ServerSDK } = require("@phantom/server-sdk");
|
|
774
|
-
|
|
775
|
-
const app = express();
|
|
776
|
-
app.use(express.json());
|
|
777
|
-
|
|
778
|
-
const serverSDK = new ServerSDK({
|
|
779
|
-
organizationId: process.env.ORGANIZATION_ID,
|
|
780
|
-
apiPrivateKey: process.env.PRIVATE_KEY,
|
|
781
|
-
apiBaseUrl: process.env.API_URL,
|
|
782
|
-
});
|
|
783
|
-
|
|
784
|
-
app.post("/api/organizations", async (req, res) => {
|
|
785
|
-
try {
|
|
786
|
-
const { userId } = req.body;
|
|
787
|
-
|
|
788
|
-
if (!userId) {
|
|
789
|
-
return res.status(400).json({ error: "userId is required" });
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
const organization = await serverSDK.getOrCreateChildOrganizationByTag({
|
|
793
|
-
tag: userId,
|
|
794
|
-
});
|
|
795
|
-
|
|
796
|
-
res.json({ organizationId: organization.id });
|
|
797
|
-
} catch (error) {
|
|
798
|
-
res.status(500).json({ error: "Failed to process request" });
|
|
799
|
-
}
|
|
800
|
-
});
|
|
801
|
-
|
|
802
|
-
app.listen(3000);
|
|
803
|
-
```
|
package/dist/index.d.ts
CHANGED
|
@@ -51,6 +51,7 @@ declare const DebugCategory: {
|
|
|
51
51
|
interface BrowserSDKConfig {
|
|
52
52
|
providerType: "injected" | "embedded" | (string & Record<never, never>);
|
|
53
53
|
appName?: string;
|
|
54
|
+
appLogo?: string;
|
|
54
55
|
addressTypes?: AddressType[];
|
|
55
56
|
apiBaseUrl?: string;
|
|
56
57
|
organizationId?: string;
|
|
@@ -60,20 +61,12 @@ interface BrowserSDKConfig {
|
|
|
60
61
|
};
|
|
61
62
|
embeddedWalletType?: "app-wallet" | "user-wallet" | (string & Record<never, never>);
|
|
62
63
|
solanaProvider?: "web3js" | "kit";
|
|
63
|
-
serverUrl?: string;
|
|
64
64
|
debug?: {
|
|
65
65
|
enabled?: boolean;
|
|
66
66
|
level?: DebugLevel;
|
|
67
67
|
callback?: DebugCallback;
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
-
interface CreateUserOrganizationParams {
|
|
71
|
-
userId: string;
|
|
72
|
-
[key: string]: any;
|
|
73
|
-
}
|
|
74
|
-
interface CreateUserOrganizationResult {
|
|
75
|
-
organizationId: string;
|
|
76
|
-
}
|
|
77
70
|
|
|
78
71
|
interface Provider {
|
|
79
72
|
connect(authOptions?: AuthOptions): Promise<ConnectResult>;
|
|
@@ -94,7 +87,6 @@ interface SwitchProviderOptions {
|
|
|
94
87
|
|
|
95
88
|
declare class BrowserSDK {
|
|
96
89
|
private providerManager;
|
|
97
|
-
private config;
|
|
98
90
|
constructor(config: BrowserSDKConfig);
|
|
99
91
|
/**
|
|
100
92
|
* Connect to the wallet with optional provider switching
|
|
@@ -145,12 +137,6 @@ declare class BrowserSDK {
|
|
|
145
137
|
* Get the current wallet ID (for embedded wallets)
|
|
146
138
|
*/
|
|
147
139
|
getWalletId(): string | null;
|
|
148
|
-
/**
|
|
149
|
-
* Create a user organization via your backend API
|
|
150
|
-
* @param params - Parameters including userId and any additional options
|
|
151
|
-
* @returns Organization creation result with organizationId
|
|
152
|
-
*/
|
|
153
|
-
createUserOrganization(params: CreateUserOrganizationParams): Promise<CreateUserOrganizationResult>;
|
|
154
140
|
}
|
|
155
141
|
|
|
156
142
|
/**
|
|
@@ -186,4 +172,4 @@ declare function getPlatformName(): string;
|
|
|
186
172
|
*/
|
|
187
173
|
declare function getBrowserDisplayName(): string;
|
|
188
174
|
|
|
189
|
-
export { BrowserInfo, BrowserSDK, BrowserSDKConfig,
|
|
175
|
+
export { BrowserInfo, BrowserSDK, BrowserSDKConfig, DEFAULT_AUTH_URL, DEFAULT_WALLET_API_URL, DebugCallback, DebugCategory, DebugLevel, DebugMessage, Provider, debug, detectBrowser, getBrowserDisplayName, getPlatformName, parseBrowserFromUserAgent };
|
package/dist/index.js
CHANGED
|
@@ -418,7 +418,11 @@ var BrowserAuthProvider = class {
|
|
|
418
418
|
parent_organization_id: phantomOptions.parentOrganizationId,
|
|
419
419
|
redirect_uri: phantomOptions.redirectUrl || (typeof window !== "undefined" ? window.location.href : ""),
|
|
420
420
|
session_id: phantomOptions.sessionId,
|
|
421
|
-
clear_previous_session: true.toString()
|
|
421
|
+
clear_previous_session: true.toString(),
|
|
422
|
+
app_name: phantomOptions.appName || "",
|
|
423
|
+
// Optional app name
|
|
424
|
+
app_logo: phantomOptions.appLogo || ""
|
|
425
|
+
// Optional app logo URL
|
|
422
426
|
});
|
|
423
427
|
if (phantomOptions.provider) {
|
|
424
428
|
debug.log(DebugCategory.PHANTOM_CONNECT_AUTH, "Provider specified, will skip selection", {
|
|
@@ -893,7 +897,6 @@ var BrowserSDK = class {
|
|
|
893
897
|
);
|
|
894
898
|
}
|
|
895
899
|
config.embeddedWalletType = embeddedWalletType;
|
|
896
|
-
this.config = config;
|
|
897
900
|
debug.log(DebugCategory.BROWSER_SDK, "Creating ProviderManager", { config });
|
|
898
901
|
this.providerManager = new ProviderManager(config);
|
|
899
902
|
debug.info(DebugCategory.BROWSER_SDK, "BrowserSDK initialized successfully");
|
|
@@ -1032,32 +1035,6 @@ var BrowserSDK = class {
|
|
|
1032
1035
|
getWalletId() {
|
|
1033
1036
|
return this.providerManager.getWalletId();
|
|
1034
1037
|
}
|
|
1035
|
-
/**
|
|
1036
|
-
* Create a user organization via your backend API
|
|
1037
|
-
* @param params - Parameters including userId and any additional options
|
|
1038
|
-
* @returns Organization creation result with organizationId
|
|
1039
|
-
*/
|
|
1040
|
-
async createUserOrganization(params) {
|
|
1041
|
-
if (!this.config.serverUrl) {
|
|
1042
|
-
throw new Error("serverUrl is required in config to create user organizations");
|
|
1043
|
-
}
|
|
1044
|
-
try {
|
|
1045
|
-
const response = await fetch(`${this.config.serverUrl}/organizations`, {
|
|
1046
|
-
method: "POST",
|
|
1047
|
-
headers: {
|
|
1048
|
-
"Content-Type": "application/json"
|
|
1049
|
-
},
|
|
1050
|
-
body: JSON.stringify(params)
|
|
1051
|
-
});
|
|
1052
|
-
if (!response.ok) {
|
|
1053
|
-
throw new Error(`Failed to create organization: ${response.status} ${response.statusText}`);
|
|
1054
|
-
}
|
|
1055
|
-
const result = await response.json();
|
|
1056
|
-
return result;
|
|
1057
|
-
} catch (error) {
|
|
1058
|
-
throw new Error(`Error creating user organization: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
1038
|
};
|
|
1062
1039
|
|
|
1063
1040
|
// src/index.ts
|
package/dist/index.mjs
CHANGED
|
@@ -371,7 +371,11 @@ var BrowserAuthProvider = class {
|
|
|
371
371
|
parent_organization_id: phantomOptions.parentOrganizationId,
|
|
372
372
|
redirect_uri: phantomOptions.redirectUrl || (typeof window !== "undefined" ? window.location.href : ""),
|
|
373
373
|
session_id: phantomOptions.sessionId,
|
|
374
|
-
clear_previous_session: true.toString()
|
|
374
|
+
clear_previous_session: true.toString(),
|
|
375
|
+
app_name: phantomOptions.appName || "",
|
|
376
|
+
// Optional app name
|
|
377
|
+
app_logo: phantomOptions.appLogo || ""
|
|
378
|
+
// Optional app logo URL
|
|
375
379
|
});
|
|
376
380
|
if (phantomOptions.provider) {
|
|
377
381
|
debug.log(DebugCategory.PHANTOM_CONNECT_AUTH, "Provider specified, will skip selection", {
|
|
@@ -846,7 +850,6 @@ var BrowserSDK = class {
|
|
|
846
850
|
);
|
|
847
851
|
}
|
|
848
852
|
config.embeddedWalletType = embeddedWalletType;
|
|
849
|
-
this.config = config;
|
|
850
853
|
debug.log(DebugCategory.BROWSER_SDK, "Creating ProviderManager", { config });
|
|
851
854
|
this.providerManager = new ProviderManager(config);
|
|
852
855
|
debug.info(DebugCategory.BROWSER_SDK, "BrowserSDK initialized successfully");
|
|
@@ -985,32 +988,6 @@ var BrowserSDK = class {
|
|
|
985
988
|
getWalletId() {
|
|
986
989
|
return this.providerManager.getWalletId();
|
|
987
990
|
}
|
|
988
|
-
/**
|
|
989
|
-
* Create a user organization via your backend API
|
|
990
|
-
* @param params - Parameters including userId and any additional options
|
|
991
|
-
* @returns Organization creation result with organizationId
|
|
992
|
-
*/
|
|
993
|
-
async createUserOrganization(params) {
|
|
994
|
-
if (!this.config.serverUrl) {
|
|
995
|
-
throw new Error("serverUrl is required in config to create user organizations");
|
|
996
|
-
}
|
|
997
|
-
try {
|
|
998
|
-
const response = await fetch(`${this.config.serverUrl}/organizations`, {
|
|
999
|
-
method: "POST",
|
|
1000
|
-
headers: {
|
|
1001
|
-
"Content-Type": "application/json"
|
|
1002
|
-
},
|
|
1003
|
-
body: JSON.stringify(params)
|
|
1004
|
-
});
|
|
1005
|
-
if (!response.ok) {
|
|
1006
|
-
throw new Error(`Failed to create organization: ${response.status} ${response.statusText}`);
|
|
1007
|
-
}
|
|
1008
|
-
const result = await response.json();
|
|
1009
|
-
return result;
|
|
1010
|
-
} catch (error) {
|
|
1011
|
-
throw new Error(`Error creating user organization: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
1012
|
-
}
|
|
1013
|
-
}
|
|
1014
991
|
};
|
|
1015
992
|
|
|
1016
993
|
// src/index.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phantom/browser-sdk",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "Browser SDK for Phantom Wallet with unified interface",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@phantom/base64url": "^0.1.0",
|
|
32
32
|
"@phantom/browser-injected-sdk": "^0.0.9",
|
|
33
|
-
"@phantom/client": "^0.1.
|
|
33
|
+
"@phantom/client": "^0.1.6",
|
|
34
34
|
"@phantom/constants": "^0.0.2",
|
|
35
|
-
"@phantom/embedded-provider-core": "^0.1.
|
|
36
|
-
"@phantom/indexed-db-stamper": "^0.1.
|
|
37
|
-
"@phantom/parsers": "^0.0.
|
|
35
|
+
"@phantom/embedded-provider-core": "^0.1.3",
|
|
36
|
+
"@phantom/indexed-db-stamper": "^0.1.2",
|
|
37
|
+
"@phantom/parsers": "^0.0.6",
|
|
38
38
|
"axios": "^1.10.0",
|
|
39
39
|
"bs58": "^6.0.0",
|
|
40
40
|
"buffer": "^6.0.3",
|