@phantom/browser-sdk 0.3.5 → 0.3.7

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 CHANGED
@@ -11,11 +11,12 @@ npm install @phantom/browser-sdk
11
11
  ### Injected Provider (Browser Extension)
12
12
 
13
13
  ```typescript
14
- import { BrowserSDK, NetworkId } from "@phantom/browser-sdk";
14
+ import { BrowserSDK, NetworkId, AddressType } from "@phantom/browser-sdk";
15
15
 
16
16
  // Connect to Phantom browser extension
17
17
  const sdk = new BrowserSDK({
18
18
  providerType: "injected",
19
+ addressTypes: [AddressType.solana],
19
20
  });
20
21
 
21
22
  const { addresses } = await sdk.connect();
@@ -68,6 +69,7 @@ Uses the Phantom browser extension installed by the user. No additional configur
68
69
  ```typescript
69
70
  const sdk = new BrowserSDK({
70
71
  providerType: "injected",
72
+ addressTypes: [AddressType.solana],
71
73
  });
72
74
  ```
73
75
 
@@ -89,10 +91,6 @@ const sdk = new BrowserSDK({
89
91
  appName: "My DApp", // optional, for branding
90
92
  appLogo: "https://myapp.com/logo.png", // optional, for branding
91
93
  autoConnect: true, // optional, auto-connect to existing session (default: true for embedded)
92
- debug: {
93
- enabled: true, // optional, enable debug logging
94
- level: "info", // optional, debug level
95
- },
96
94
  });
97
95
  ```
98
96
 
@@ -169,6 +167,7 @@ The SDK can automatically reconnect to existing sessions when instantiated, prov
169
167
  ```typescript
170
168
  const sdk = new BrowserSDK({
171
169
  providerType: "embedded",
170
+ addressTypes: [AddressType.solana],
172
171
  // ... other config
173
172
  autoConnect: true, // Default: true for embedded, false for injected
174
173
  });
@@ -191,6 +190,7 @@ if (sdk.isConnected()) {
191
190
  ```typescript
192
191
  const sdk = new BrowserSDK({
193
192
  providerType: "embedded",
193
+ addressTypes: [AddressType.solana],
194
194
  // ... other config
195
195
  autoConnect: false, // Disable auto-connect
196
196
  });
@@ -214,7 +214,7 @@ interface BrowserSDKConfig {
214
214
  providerType: "injected" | "embedded";
215
215
  appName?: string; // Optional app name for branding
216
216
  appLogo?: string; // Optional app logo URL for branding
217
- addressTypes?: AddressType[]; // Networks to enable (e.g., [AddressType.solana])
217
+ addressTypes?: [AddressType, ...AddressType[]]; // Networks to enable (e.g., [AddressType.solana])
218
218
 
219
219
  // Required for embedded provider only
220
220
  apiBaseUrl?: string; // Phantom API base URL
@@ -226,13 +226,6 @@ interface BrowserSDKConfig {
226
226
  embeddedWalletType?: "app-wallet" | "user-wallet"; // Wallet type
227
227
  solanaProvider?: "web3js" | "kit"; // Solana library choice (default: 'web3js')
228
228
  autoConnect?: boolean; // Enable auto-connect to existing sessions (default: true)
229
-
230
- // Debug options
231
- debug?: {
232
- enabled?: boolean; // Enable debug logging
233
- level?: "info" | "warn" | "error"; // Debug level
234
- callback?: (level: string, message: string, data?: any) => void; // Custom debug callback
235
- };
236
229
  }
237
230
  ```
238
231
 
@@ -362,6 +355,110 @@ Attempt auto-connection using existing session. Should be called after setting u
362
355
  await sdk.autoConnect();
363
356
  ```
364
357
 
358
+ ## Debug Configuration
359
+
360
+ The BrowserSDK provides dynamic debug configuration that can be changed at runtime without reinstantiating the SDK. This provides better performance and cleaner architecture.
361
+
362
+ ### Debug Methods
363
+
364
+ ```typescript
365
+ // Enable debug logging
366
+ sdk.enableDebug();
367
+
368
+ // Disable debug logging
369
+ sdk.disableDebug();
370
+
371
+ // Set debug level
372
+ sdk.setDebugLevel(DebugLevel.INFO);
373
+
374
+ // Set debug callback function
375
+ sdk.setDebugCallback((message) => {
376
+ console.log(`[${message.category}] ${message.message}`, message.data);
377
+ });
378
+
379
+ // Configure all debug settings at once
380
+ sdk.configureDebug({
381
+ enabled: true,
382
+ level: DebugLevel.DEBUG,
383
+ callback: (message) => {
384
+ // Handle debug messages
385
+ console.log(`[${message.level}] ${message.category}: ${message.message}`);
386
+ }
387
+ });
388
+ ```
389
+
390
+ ### Debug Levels
391
+
392
+ ```typescript
393
+ import { DebugLevel } from "@phantom/browser-sdk";
394
+
395
+ // Available debug levels (in order of verbosity)
396
+ DebugLevel.ERROR // 0 - Only error messages
397
+ DebugLevel.WARN // 1 - Warning and error messages
398
+ DebugLevel.INFO // 2 - Info, warning, and error messages
399
+ DebugLevel.DEBUG // 3 - All debug messages (most verbose)
400
+ ```
401
+
402
+ ### Debug Message Structure
403
+
404
+ Debug callbacks receive a `DebugMessage` object:
405
+
406
+ ```typescript
407
+ interface DebugMessage {
408
+ timestamp: number; // Unix timestamp
409
+ level: DebugLevel; // Message level
410
+ category: string; // Component category (e.g., "BrowserSDK", "ProviderManager")
411
+ message: string; // Debug message text
412
+ data?: any; // Additional debug data (optional)
413
+ }
414
+ ```
415
+
416
+ ### Example: Debug Console Implementation
417
+
418
+ ```typescript
419
+ import { BrowserSDK, DebugLevel } from "@phantom/browser-sdk";
420
+
421
+ const sdk = new BrowserSDK({
422
+ providerType: "embedded",
423
+ // ... other config
424
+ });
425
+
426
+ // Store debug messages
427
+ const debugMessages: DebugMessage[] = [];
428
+
429
+ // Set up debug system
430
+ sdk.configureDebug({
431
+ enabled: true,
432
+ level: DebugLevel.INFO,
433
+ callback: (message) => {
434
+ debugMessages.push(message);
435
+
436
+ // Keep only last 100 messages
437
+ if (debugMessages.length > 100) {
438
+ debugMessages.shift();
439
+ }
440
+
441
+ // Update UI
442
+ updateDebugConsole();
443
+ }
444
+ });
445
+
446
+ // Dynamic debug level changing
447
+ function changeDebugLevel(newLevel: DebugLevel) {
448
+ sdk.setDebugLevel(newLevel);
449
+ console.log(`Debug level changed to: ${DebugLevel[newLevel]}`);
450
+ }
451
+
452
+ // Toggle debug on/off
453
+ function toggleDebug(enabled: boolean) {
454
+ if (enabled) {
455
+ sdk.enableDebug();
456
+ } else {
457
+ sdk.disableDebug();
458
+ }
459
+ }
460
+ ```
461
+
365
462
  ## Transaction Examples
366
463
 
367
464
  ### Solana Transactions
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { EmbeddedProviderConfig, AuthOptions, ConnectResult, SignMessageParams, SignMessageResult, SignAndSendTransactionParams, SignedTransaction, WalletAddress, EmbeddedProviderEvent, EventCallback } from '@phantom/embedded-provider-core';
2
2
  export { AuthOptions, ConnectResult, SignAndSendTransactionParams, SignMessageParams, SignMessageResult, SignedTransaction, WalletAddress } from '@phantom/embedded-provider-core';
3
- export { NetworkId } from '@phantom/constants';
3
+ import { AddressType } from '@phantom/client';
4
4
  export { AddressType } from '@phantom/client';
5
+ export { NetworkId } from '@phantom/constants';
5
6
 
6
7
  declare enum DebugLevel {
7
8
  ERROR = 0,
@@ -47,17 +48,18 @@ declare const DebugCategory: {
47
48
  readonly SESSION: "Session";
48
49
  };
49
50
 
51
+ interface DebugConfig {
52
+ enabled?: boolean;
53
+ level?: DebugLevel;
54
+ callback?: DebugCallback;
55
+ }
50
56
  interface BrowserSDKConfig extends Partial<EmbeddedProviderConfig> {
51
57
  providerType: "injected" | "embedded" | (string & Record<never, never>);
58
+ addressTypes: [AddressType, ...AddressType[]];
52
59
  apiBaseUrl?: string;
53
60
  organizationId?: string;
54
61
  embeddedWalletType?: "app-wallet" | "user-wallet" | (string & Record<never, never>);
55
62
  autoConnect?: boolean;
56
- debug?: {
57
- enabled?: boolean;
58
- level?: DebugLevel;
59
- callback?: DebugCallback;
60
- };
61
63
  }
62
64
 
63
65
  interface Provider {
@@ -145,6 +147,34 @@ declare class BrowserSDK {
145
147
  * Only works with embedded providers
146
148
  */
147
149
  autoConnect(): Promise<void>;
150
+ /**
151
+ * Debug configuration methods
152
+ * These allow dynamic debug configuration without SDK reinstantiation
153
+ */
154
+ /**
155
+ * Enable debug logging
156
+ */
157
+ enableDebug(): void;
158
+ /**
159
+ * Disable debug logging
160
+ */
161
+ disableDebug(): void;
162
+ /**
163
+ * Set debug level
164
+ */
165
+ setDebugLevel(level: DebugLevel): void;
166
+ /**
167
+ * Set debug callback function
168
+ */
169
+ setDebugCallback(callback: DebugCallback): void;
170
+ /**
171
+ * Configure debug settings all at once
172
+ */
173
+ configureDebug(config: {
174
+ enabled?: boolean;
175
+ level?: DebugLevel;
176
+ callback?: DebugCallback;
177
+ }): void;
148
178
  }
149
179
 
150
180
  /**
@@ -180,4 +210,4 @@ declare function getPlatformName(): string;
180
210
  */
181
211
  declare function getBrowserDisplayName(): string;
182
212
 
183
- export { BrowserInfo, BrowserSDK, BrowserSDKConfig, DEFAULT_AUTH_URL, DEFAULT_WALLET_API_URL, DebugCallback, DebugCategory, DebugLevel, DebugMessage, Provider, debug, detectBrowser, getBrowserDisplayName, getPlatformName, parseBrowserFromUserAgent };
213
+ export { BrowserInfo, BrowserSDK, BrowserSDKConfig, DEFAULT_AUTH_URL, DEFAULT_WALLET_API_URL, DebugCallback, DebugCategory, DebugConfig, DebugLevel, DebugMessage, Provider, debug, detectBrowser, getBrowserDisplayName, getPlatformName, parseBrowserFromUserAgent };
package/dist/index.js CHANGED
@@ -30,7 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
- AddressType: () => import_client2.AddressType,
33
+ AddressType: () => import_client3.AddressType,
34
34
  BrowserSDK: () => BrowserSDK,
35
35
  DEFAULT_AUTH_URL: () => DEFAULT_AUTH_URL,
36
36
  DEFAULT_WALLET_API_URL: () => DEFAULT_WALLET_API_URL,
@@ -138,7 +138,7 @@ var InjectedProvider = class {
138
138
  this.browserInjectedCleanupFunctions = [];
139
139
  this.eventsInitialized = false;
140
140
  debug.log(DebugCategory.INJECTED_PROVIDER, "Initializing InjectedProvider", { config });
141
- this.addressTypes = config.addressTypes || [import_client.AddressType.solana, import_client.AddressType.ethereum];
141
+ this.addressTypes = config.addressTypes;
142
142
  debug.log(DebugCategory.INJECTED_PROVIDER, "Address types configured", { addressTypes: this.addressTypes });
143
143
  const plugins = [(0, import_browser_injected_sdk.createExtensionPlugin)()];
144
144
  if (this.addressTypes.includes(import_client.AddressType.solana)) {
@@ -1058,7 +1058,7 @@ var ProviderManager = class {
1058
1058
  if (type === "injected") {
1059
1059
  provider = new InjectedProvider({
1060
1060
  solanaProvider: this.config.solanaProvider || "web3js",
1061
- addressTypes: this.config.addressTypes || []
1061
+ addressTypes: this.config.addressTypes
1062
1062
  });
1063
1063
  } else {
1064
1064
  if (!this.config.apiBaseUrl || !this.config.organizationId) {
@@ -1069,7 +1069,7 @@ var ProviderManager = class {
1069
1069
  organizationId: this.config.organizationId,
1070
1070
  authOptions: this.config.authOptions,
1071
1071
  embeddedWalletType: embeddedWalletType || "app-wallet",
1072
- addressTypes: this.config.addressTypes || [],
1072
+ addressTypes: this.config.addressTypes,
1073
1073
  solanaProvider: this.config.solanaProvider || "web3js",
1074
1074
  appLogo: this.config.appLogo,
1075
1075
  // Optional app logo URL
@@ -1124,20 +1124,10 @@ var ProviderManager = class {
1124
1124
  var import_browser_injected_sdk2 = require("@phantom/browser-injected-sdk");
1125
1125
  var BrowserSDK = class {
1126
1126
  constructor(config) {
1127
- if (config.debug?.enabled) {
1128
- debug.enable();
1129
- if (config.debug.level !== void 0) {
1130
- debug.setLevel(config.debug.level);
1131
- }
1132
- if (config.debug.callback) {
1133
- debug.setCallback(config.debug.callback);
1134
- }
1135
- }
1136
1127
  debug.info(DebugCategory.BROWSER_SDK, "Initializing BrowserSDK", {
1137
1128
  providerType: config.providerType,
1138
1129
  embeddedWalletType: config.embeddedWalletType,
1139
- addressTypes: config.addressTypes,
1140
- debugEnabled: config.debug?.enabled
1130
+ addressTypes: config.addressTypes
1141
1131
  });
1142
1132
  if (!["injected", "embedded"].includes(config.providerType)) {
1143
1133
  debug.error(DebugCategory.BROWSER_SDK, "Invalid providerType", { providerType: config.providerType });
@@ -1323,8 +1313,60 @@ var BrowserSDK = class {
1323
1313
  });
1324
1314
  }
1325
1315
  }
1316
+ /**
1317
+ * Debug configuration methods
1318
+ * These allow dynamic debug configuration without SDK reinstantiation
1319
+ */
1320
+ /**
1321
+ * Enable debug logging
1322
+ */
1323
+ enableDebug() {
1324
+ debug.enable();
1325
+ debug.info(DebugCategory.BROWSER_SDK, "Debug logging enabled");
1326
+ }
1327
+ /**
1328
+ * Disable debug logging
1329
+ */
1330
+ disableDebug() {
1331
+ debug.disable();
1332
+ }
1333
+ /**
1334
+ * Set debug level
1335
+ */
1336
+ setDebugLevel(level) {
1337
+ debug.setLevel(level);
1338
+ debug.info(DebugCategory.BROWSER_SDK, "Debug level updated", { level });
1339
+ }
1340
+ /**
1341
+ * Set debug callback function
1342
+ */
1343
+ setDebugCallback(callback) {
1344
+ debug.setCallback(callback);
1345
+ debug.info(DebugCategory.BROWSER_SDK, "Debug callback updated");
1346
+ }
1347
+ /**
1348
+ * Configure debug settings all at once
1349
+ */
1350
+ configureDebug(config) {
1351
+ if (config.enabled !== void 0) {
1352
+ if (config.enabled) {
1353
+ this.enableDebug();
1354
+ } else {
1355
+ this.disableDebug();
1356
+ }
1357
+ }
1358
+ if (config.level !== void 0) {
1359
+ this.setDebugLevel(config.level);
1360
+ }
1361
+ if (config.callback !== void 0) {
1362
+ this.setDebugCallback(config.callback);
1363
+ }
1364
+ }
1326
1365
  };
1327
1366
 
1367
+ // src/types.ts
1368
+ var import_client2 = require("@phantom/client");
1369
+
1328
1370
  // src/index.ts
1329
1371
  var import_constants3 = require("@phantom/constants");
1330
- var import_client2 = require("@phantom/client");
1372
+ var import_client3 = require("@phantom/client");
package/dist/index.mjs CHANGED
@@ -91,7 +91,7 @@ var InjectedProvider = class {
91
91
  this.browserInjectedCleanupFunctions = [];
92
92
  this.eventsInitialized = false;
93
93
  debug.log(DebugCategory.INJECTED_PROVIDER, "Initializing InjectedProvider", { config });
94
- this.addressTypes = config.addressTypes || [AddressType.solana, AddressType.ethereum];
94
+ this.addressTypes = config.addressTypes;
95
95
  debug.log(DebugCategory.INJECTED_PROVIDER, "Address types configured", { addressTypes: this.addressTypes });
96
96
  const plugins = [createExtensionPlugin()];
97
97
  if (this.addressTypes.includes(AddressType.solana)) {
@@ -1011,7 +1011,7 @@ var ProviderManager = class {
1011
1011
  if (type === "injected") {
1012
1012
  provider = new InjectedProvider({
1013
1013
  solanaProvider: this.config.solanaProvider || "web3js",
1014
- addressTypes: this.config.addressTypes || []
1014
+ addressTypes: this.config.addressTypes
1015
1015
  });
1016
1016
  } else {
1017
1017
  if (!this.config.apiBaseUrl || !this.config.organizationId) {
@@ -1022,7 +1022,7 @@ var ProviderManager = class {
1022
1022
  organizationId: this.config.organizationId,
1023
1023
  authOptions: this.config.authOptions,
1024
1024
  embeddedWalletType: embeddedWalletType || "app-wallet",
1025
- addressTypes: this.config.addressTypes || [],
1025
+ addressTypes: this.config.addressTypes,
1026
1026
  solanaProvider: this.config.solanaProvider || "web3js",
1027
1027
  appLogo: this.config.appLogo,
1028
1028
  // Optional app logo URL
@@ -1077,20 +1077,10 @@ var ProviderManager = class {
1077
1077
  import { isPhantomExtensionInstalled } from "@phantom/browser-injected-sdk";
1078
1078
  var BrowserSDK = class {
1079
1079
  constructor(config) {
1080
- if (config.debug?.enabled) {
1081
- debug.enable();
1082
- if (config.debug.level !== void 0) {
1083
- debug.setLevel(config.debug.level);
1084
- }
1085
- if (config.debug.callback) {
1086
- debug.setCallback(config.debug.callback);
1087
- }
1088
- }
1089
1080
  debug.info(DebugCategory.BROWSER_SDK, "Initializing BrowserSDK", {
1090
1081
  providerType: config.providerType,
1091
1082
  embeddedWalletType: config.embeddedWalletType,
1092
- addressTypes: config.addressTypes,
1093
- debugEnabled: config.debug?.enabled
1083
+ addressTypes: config.addressTypes
1094
1084
  });
1095
1085
  if (!["injected", "embedded"].includes(config.providerType)) {
1096
1086
  debug.error(DebugCategory.BROWSER_SDK, "Invalid providerType", { providerType: config.providerType });
@@ -1276,13 +1266,65 @@ var BrowserSDK = class {
1276
1266
  });
1277
1267
  }
1278
1268
  }
1269
+ /**
1270
+ * Debug configuration methods
1271
+ * These allow dynamic debug configuration without SDK reinstantiation
1272
+ */
1273
+ /**
1274
+ * Enable debug logging
1275
+ */
1276
+ enableDebug() {
1277
+ debug.enable();
1278
+ debug.info(DebugCategory.BROWSER_SDK, "Debug logging enabled");
1279
+ }
1280
+ /**
1281
+ * Disable debug logging
1282
+ */
1283
+ disableDebug() {
1284
+ debug.disable();
1285
+ }
1286
+ /**
1287
+ * Set debug level
1288
+ */
1289
+ setDebugLevel(level) {
1290
+ debug.setLevel(level);
1291
+ debug.info(DebugCategory.BROWSER_SDK, "Debug level updated", { level });
1292
+ }
1293
+ /**
1294
+ * Set debug callback function
1295
+ */
1296
+ setDebugCallback(callback) {
1297
+ debug.setCallback(callback);
1298
+ debug.info(DebugCategory.BROWSER_SDK, "Debug callback updated");
1299
+ }
1300
+ /**
1301
+ * Configure debug settings all at once
1302
+ */
1303
+ configureDebug(config) {
1304
+ if (config.enabled !== void 0) {
1305
+ if (config.enabled) {
1306
+ this.enableDebug();
1307
+ } else {
1308
+ this.disableDebug();
1309
+ }
1310
+ }
1311
+ if (config.level !== void 0) {
1312
+ this.setDebugLevel(config.level);
1313
+ }
1314
+ if (config.callback !== void 0) {
1315
+ this.setDebugCallback(config.callback);
1316
+ }
1317
+ }
1279
1318
  };
1280
1319
 
1320
+ // src/types.ts
1321
+ import { AddressType as AddressType2 } from "@phantom/client";
1322
+
1281
1323
  // src/index.ts
1282
1324
  import { NetworkId } from "@phantom/constants";
1283
- import { AddressType as AddressType2 } from "@phantom/client";
1325
+ import { AddressType as AddressType3 } from "@phantom/client";
1284
1326
  export {
1285
- AddressType2 as AddressType,
1327
+ AddressType3 as AddressType,
1286
1328
  BrowserSDK,
1287
1329
  DEFAULT_AUTH_URL,
1288
1330
  DEFAULT_WALLET_API_URL,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phantom/browser-sdk",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "description": "Browser SDK for Phantom Wallet with unified interface",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -30,9 +30,9 @@
30
30
  "dependencies": {
31
31
  "@phantom/base64url": "^0.1.0",
32
32
  "@phantom/browser-injected-sdk": "^0.0.9",
33
- "@phantom/client": "^0.1.8",
33
+ "@phantom/client": "^0.1.9",
34
34
  "@phantom/constants": "^0.0.3",
35
- "@phantom/embedded-provider-core": "^0.1.6",
35
+ "@phantom/embedded-provider-core": "^0.1.8",
36
36
  "@phantom/indexed-db-stamper": "^0.1.4",
37
37
  "@phantom/parsers": "^0.0.7",
38
38
  "axios": "^1.10.0",