@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/dist/index.js CHANGED
@@ -20,9 +20,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
- AddressType: () => import_client3.AddressType,
23
+ AddressType: () => import_client2.AddressType,
24
24
  BrowserSDK: () => BrowserSDK,
25
- NetworkId: () => import_client3.NetworkId
25
+ DEFAULT_AUTH_URL: () => DEFAULT_AUTH_URL,
26
+ DEFAULT_WALLET_API_URL: () => DEFAULT_WALLET_API_URL,
27
+ DebugCategory: () => DebugCategory,
28
+ DebugLevel: () => DebugLevel,
29
+ NetworkId: () => import_client2.NetworkId,
30
+ debug: () => debug
26
31
  });
27
32
  module.exports = __toCommonJS(src_exports);
28
33
 
@@ -31,26 +36,118 @@ var import_client = require("@phantom/client");
31
36
  var import_browser_injected_sdk = require("@phantom/browser-injected-sdk");
32
37
  var import_solana = require("@phantom/browser-injected-sdk/solana");
33
38
  var import_ethereum = require("@phantom/browser-injected-sdk/ethereum");
39
+
40
+ // src/debug.ts
41
+ var DebugLevel = /* @__PURE__ */ ((DebugLevel2) => {
42
+ DebugLevel2[DebugLevel2["ERROR"] = 0] = "ERROR";
43
+ DebugLevel2[DebugLevel2["WARN"] = 1] = "WARN";
44
+ DebugLevel2[DebugLevel2["INFO"] = 2] = "INFO";
45
+ DebugLevel2[DebugLevel2["DEBUG"] = 3] = "DEBUG";
46
+ return DebugLevel2;
47
+ })(DebugLevel || {});
48
+ var Debug = class {
49
+ constructor() {
50
+ this.level = 0 /* ERROR */;
51
+ this.enabled = false;
52
+ }
53
+ static getInstance() {
54
+ if (!Debug.instance) {
55
+ Debug.instance = new Debug();
56
+ }
57
+ return Debug.instance;
58
+ }
59
+ setCallback(callback) {
60
+ this.callback = callback;
61
+ }
62
+ setLevel(level) {
63
+ this.level = level;
64
+ }
65
+ enable() {
66
+ this.enabled = true;
67
+ }
68
+ disable() {
69
+ this.enabled = false;
70
+ }
71
+ writeLog(level, category, message, data) {
72
+ if (!this.enabled || level > this.level) {
73
+ return;
74
+ }
75
+ const debugMessage = {
76
+ timestamp: Date.now(),
77
+ level,
78
+ category,
79
+ message,
80
+ data
81
+ };
82
+ if (this.callback) {
83
+ this.callback(debugMessage);
84
+ }
85
+ }
86
+ error(category, message, data) {
87
+ this.writeLog(0 /* ERROR */, category, message, data);
88
+ }
89
+ warn(category, message, data) {
90
+ this.writeLog(1 /* WARN */, category, message, data);
91
+ }
92
+ info(category, message, data) {
93
+ this.writeLog(2 /* INFO */, category, message, data);
94
+ }
95
+ debug(category, message, data) {
96
+ this.writeLog(3 /* DEBUG */, category, message, data);
97
+ }
98
+ log(category, message, data) {
99
+ this.writeLog(3 /* DEBUG */, category, message, data);
100
+ }
101
+ };
102
+ var debug = Debug.getInstance();
103
+ var DebugCategory = {
104
+ BROWSER_SDK: "BrowserSDK",
105
+ PROVIDER_MANAGER: "ProviderManager",
106
+ EMBEDDED_PROVIDER: "EmbeddedProvider",
107
+ INJECTED_PROVIDER: "InjectedProvider",
108
+ PHANTOM_CONNECT_AUTH: "PhantomConnectAuth",
109
+ JWT_AUTH: "JWTAuth",
110
+ STORAGE: "Storage",
111
+ SESSION: "Session"
112
+ };
113
+
114
+ // src/providers/injected/index.ts
34
115
  var InjectedProvider = class {
35
116
  constructor(config) {
36
117
  this.connected = false;
37
118
  this.addresses = [];
119
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Initializing InjectedProvider", { config });
38
120
  this.addressTypes = config.addressTypes || [import_client.AddressType.solana, import_client.AddressType.ethereum];
121
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Address types configured", { addressTypes: this.addressTypes });
39
122
  const plugins = [(0, import_browser_injected_sdk.createExtensionPlugin)()];
40
123
  if (this.addressTypes.includes(import_client.AddressType.solana)) {
41
124
  plugins.push((0, import_solana.createSolanaPlugin)());
125
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Solana plugin added");
42
126
  }
43
127
  if (this.addressTypes.includes(import_client.AddressType.ethereum)) {
44
128
  plugins.push((0, import_ethereum.createEthereumPlugin)());
129
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Ethereum plugin added");
45
130
  }
131
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Creating Phantom instance with plugins", {
132
+ pluginCount: plugins.length
133
+ });
46
134
  this.phantom = (0, import_browser_injected_sdk.createPhantom)({ plugins });
135
+ debug.info(DebugCategory.INJECTED_PROVIDER, "InjectedProvider initialized");
47
136
  }
48
- async connect() {
137
+ async connect(authOptions) {
138
+ debug.info(DebugCategory.INJECTED_PROVIDER, "Starting injected provider connect", {
139
+ addressTypes: this.addressTypes,
140
+ authOptionsIgnored: !!authOptions
141
+ // Note: authOptions are ignored for injected provider
142
+ });
49
143
  if (!this.phantom.extension.isInstalled()) {
144
+ debug.error(DebugCategory.INJECTED_PROVIDER, "Phantom wallet extension not found");
50
145
  throw new Error("Phantom wallet not found");
51
146
  }
147
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Phantom extension detected");
52
148
  const connectedAddresses = [];
53
149
  if (this.addressTypes.includes(import_client.AddressType.solana)) {
150
+ debug.log(DebugCategory.INJECTED_PROVIDER, "Attempting Solana connection");
54
151
  try {
55
152
  const publicKey = await this.phantom.solana.connect();
56
153
  if (publicKey) {
@@ -58,9 +155,10 @@ var InjectedProvider = class {
58
155
  addressType: import_client.AddressType.solana,
59
156
  address: publicKey
60
157
  });
158
+ debug.info(DebugCategory.INJECTED_PROVIDER, "Solana connected successfully", { address: publicKey });
61
159
  }
62
160
  } catch (err) {
63
- console.error("Failed to connect Solana:", err);
161
+ debug.warn(DebugCategory.INJECTED_PROVIDER, "Failed to connect Solana", { error: err });
64
162
  }
65
163
  }
66
164
  if (this.addressTypes.includes(import_client.AddressType.ethereum)) {
@@ -75,7 +173,7 @@ var InjectedProvider = class {
75
173
  );
76
174
  }
77
175
  } catch (err) {
78
- console.error("Failed to connect Ethereum:", err);
176
+ debug.warn(DebugCategory.INJECTED_PROVIDER, "Failed to connect Ethereum", { error: err });
79
177
  }
80
178
  }
81
179
  if (connectedAddresses.length === 0) {
@@ -84,7 +182,8 @@ var InjectedProvider = class {
84
182
  this.addresses = connectedAddresses;
85
183
  this.connected = true;
86
184
  return {
87
- addresses: this.addresses
185
+ addresses: this.addresses,
186
+ status: "completed"
88
187
  // walletId is not applicable for injected providers
89
188
  };
90
189
  }
@@ -170,11 +269,10 @@ var InjectedProvider = class {
170
269
  };
171
270
 
172
271
  // src/providers/embedded/index.ts
173
- var import_client2 = require("@phantom/client");
174
- var import_api_key_stamper = require("@phantom/api-key-stamper");
272
+ var import_embedded_provider_core = require("@phantom/embedded-provider-core");
175
273
 
176
- // src/providers/embedded/storage.ts
177
- var IndexedDBStorage = class {
274
+ // src/providers/embedded/adapters/storage.ts
275
+ var BrowserStorage = class {
178
276
  constructor() {
179
277
  this.dbName = "phantom-browser-sdk";
180
278
  this.storeName = "sessions";
@@ -194,149 +292,222 @@ var IndexedDBStorage = class {
194
292
  });
195
293
  }
196
294
  async getSession() {
295
+ debug.log(DebugCategory.STORAGE, "Getting session from IndexedDB");
197
296
  const db = await this.getDB();
198
297
  return new Promise((resolve, reject) => {
199
298
  const transaction = db.transaction([this.storeName], "readonly");
200
299
  const store = transaction.objectStore(this.storeName);
201
300
  const request = store.get("currentSession");
202
- request.onsuccess = () => resolve(request.result || null);
203
- request.onerror = () => reject(request.error);
301
+ request.onsuccess = () => {
302
+ const session = request.result || null;
303
+ debug.log(DebugCategory.STORAGE, "Retrieved session from IndexedDB", {
304
+ hasSession: !!session,
305
+ sessionId: session?.sessionId
306
+ });
307
+ resolve(session);
308
+ };
309
+ request.onerror = () => {
310
+ debug.error(DebugCategory.STORAGE, "Failed to get session from IndexedDB", { error: request.error });
311
+ reject(request.error);
312
+ };
204
313
  });
205
314
  }
206
315
  async saveSession(session) {
316
+ debug.log(DebugCategory.STORAGE, "Saving session to IndexedDB", {
317
+ sessionId: session.sessionId,
318
+ walletId: session.walletId,
319
+ status: session.status
320
+ });
207
321
  const db = await this.getDB();
208
322
  return new Promise((resolve, reject) => {
209
323
  const transaction = db.transaction([this.storeName], "readwrite");
210
324
  const store = transaction.objectStore(this.storeName);
211
325
  const request = store.put(session, "currentSession");
212
- request.onsuccess = () => resolve();
213
- request.onerror = () => reject(request.error);
326
+ request.onsuccess = () => {
327
+ debug.log(DebugCategory.STORAGE, "Successfully saved session to IndexedDB");
328
+ resolve();
329
+ };
330
+ request.onerror = () => {
331
+ debug.error(DebugCategory.STORAGE, "Failed to save session to IndexedDB", { error: request.error });
332
+ reject(request.error);
333
+ };
214
334
  });
215
335
  }
216
336
  async clearSession() {
337
+ debug.log(DebugCategory.STORAGE, "Clearing session from IndexedDB");
217
338
  const db = await this.getDB();
218
339
  return new Promise((resolve, reject) => {
219
340
  const transaction = db.transaction([this.storeName], "readwrite");
220
341
  const store = transaction.objectStore(this.storeName);
221
342
  const request = store.delete("currentSession");
222
- request.onsuccess = () => resolve();
223
- request.onerror = () => reject(request.error);
343
+ request.onsuccess = () => {
344
+ debug.log(DebugCategory.STORAGE, "Successfully cleared session from IndexedDB");
345
+ resolve();
346
+ };
347
+ request.onerror = () => {
348
+ debug.error(DebugCategory.STORAGE, "Failed to clear session from IndexedDB", { error: request.error });
349
+ reject(request.error);
350
+ };
224
351
  });
225
352
  }
226
353
  };
227
354
 
228
- // src/providers/embedded/auth.ts
229
- var IframeAuth = class {
230
- async authenticate(_options) {
231
- await new Promise((resolve) => setTimeout(resolve, 100));
232
- return {
233
- walletId: `wallet-${Date.now()}`
234
- };
355
+ // src/providers/embedded/adapters/url-params.ts
356
+ var BrowserURLParamsAccessor = class {
357
+ getParam(key) {
358
+ const urlParams = new URLSearchParams(window.location.search);
359
+ return urlParams.get(key);
235
360
  }
236
361
  };
362
+ var browserUrlParamsAccessor = new BrowserURLParamsAccessor();
237
363
 
238
- // src/providers/embedded/index.ts
239
- var import_parsers = require("@phantom/parsers");
240
- var EmbeddedProvider = class {
241
- constructor(config) {
242
- this.client = null;
243
- this.walletId = null;
244
- this.addresses = [];
245
- this.config = config;
246
- this.storage = new IndexedDBStorage();
247
- config.solanaProvider;
248
- }
249
- async connect() {
250
- let session = await this.storage.getSession();
251
- if (!session) {
252
- const keypair = (0, import_client2.generateKeyPair)();
253
- const stamper2 = new import_api_key_stamper.ApiKeyStamper({
254
- apiSecretKey: keypair.secretKey
364
+ // src/constants.ts
365
+ var DEFAULT_AUTH_URL = "https://connect.phantom.app";
366
+ var DEFAULT_WALLET_API_URL = "https://api.phantom.app/v1/wallets";
367
+
368
+ // src/providers/embedded/adapters/auth.ts
369
+ var BrowserAuthProvider = class {
370
+ constructor(urlParamsAccessor) {
371
+ this.urlParamsAccessor = urlParamsAccessor;
372
+ }
373
+ authenticate(options) {
374
+ return new Promise((resolve) => {
375
+ if ("jwtToken" in options) {
376
+ throw new Error("JWT authentication should be handled by the core JWTAuth class");
377
+ }
378
+ const phantomOptions = options;
379
+ debug.info(DebugCategory.PHANTOM_CONNECT_AUTH, "Starting Phantom Connect authentication", {
380
+ organizationId: phantomOptions.organizationId,
381
+ parentOrganizationId: phantomOptions.parentOrganizationId,
382
+ provider: phantomOptions.provider,
383
+ authUrl: phantomOptions.authUrl,
384
+ hasCustomData: !!phantomOptions.customAuthData
255
385
  });
256
- const tempClient = new import_client2.PhantomClient(
257
- {
258
- apiBaseUrl: this.config.apiBaseUrl
259
- },
260
- stamper2
261
- );
262
- const uid = Date.now();
263
- const organizationName = `${this.config.organizationId}-${uid}`;
264
- const { organizationId } = await tempClient.createOrganization(organizationName, keypair);
265
- let walletId;
266
- if (this.config.embeddedWalletType === "user-wallet") {
267
- const auth = new IframeAuth();
268
- const authResult = await auth.authenticate({
269
- iframeUrl: this.config.authUrl || "https://auth-flow.phantom.app",
270
- organizationId,
271
- parentOrganizationId: this.config.organizationId,
272
- embeddedWalletType: this.config.embeddedWalletType
386
+ const baseUrl = phantomOptions.authUrl || DEFAULT_AUTH_URL;
387
+ debug.log(DebugCategory.PHANTOM_CONNECT_AUTH, "Using auth URL", { baseUrl });
388
+ const params = new URLSearchParams({
389
+ organization_id: phantomOptions.organizationId,
390
+ parent_organization_id: phantomOptions.parentOrganizationId,
391
+ redirect_uri: phantomOptions.redirectUrl || (typeof window !== "undefined" ? window.location.href : ""),
392
+ session_id: phantomOptions.sessionId,
393
+ clear_previous_session: true.toString()
394
+ });
395
+ if (phantomOptions.provider) {
396
+ debug.log(DebugCategory.PHANTOM_CONNECT_AUTH, "Provider specified, will skip selection", {
397
+ provider: phantomOptions.provider
273
398
  });
274
- walletId = authResult.walletId;
399
+ params.append("provider", phantomOptions.provider);
275
400
  } else {
276
- const wallet = await tempClient.createWallet(`Wallet ${Date.now()}`);
277
- walletId = wallet.walletId;
401
+ debug.log(DebugCategory.PHANTOM_CONNECT_AUTH, "No provider specified, defaulting to Google");
402
+ params.append("provider", "google");
403
+ }
404
+ if (phantomOptions.customAuthData) {
405
+ debug.log(DebugCategory.PHANTOM_CONNECT_AUTH, "Adding custom auth data");
406
+ params.append("authData", JSON.stringify(phantomOptions.customAuthData));
278
407
  }
279
- session = {
408
+ const authContext = {
409
+ organizationId: phantomOptions.organizationId,
410
+ parentOrganizationId: phantomOptions.parentOrganizationId,
411
+ provider: phantomOptions.provider,
412
+ sessionId: phantomOptions.sessionId
413
+ };
414
+ sessionStorage.setItem("phantom-auth-context", JSON.stringify(authContext));
415
+ debug.log(DebugCategory.PHANTOM_CONNECT_AUTH, "Stored auth context in session storage", { authContext });
416
+ const authUrl = `${baseUrl}?${params.toString()}`;
417
+ debug.info(DebugCategory.PHANTOM_CONNECT_AUTH, "Redirecting to Phantom Connect", { authUrl });
418
+ window.location.href = authUrl;
419
+ resolve();
420
+ });
421
+ }
422
+ resumeAuthFromRedirect() {
423
+ try {
424
+ const walletId = this.urlParamsAccessor.getParam("wallet_id");
425
+ const sessionId = this.urlParamsAccessor.getParam("session_id");
426
+ const error = this.urlParamsAccessor.getParam("error");
427
+ const errorDescription = this.urlParamsAccessor.getParam("error_description");
428
+ if (error) {
429
+ const errorMsg = errorDescription || error;
430
+ switch (error) {
431
+ case "access_denied":
432
+ throw new Error(`Authentication cancelled: ${errorMsg}`);
433
+ case "invalid_request":
434
+ throw new Error(`Invalid authentication request: ${errorMsg}`);
435
+ case "server_error":
436
+ throw new Error(`Authentication server error: ${errorMsg}`);
437
+ case "temporarily_unavailable":
438
+ throw new Error(`Authentication service temporarily unavailable: ${errorMsg}`);
439
+ default:
440
+ throw new Error(`Authentication failed: ${errorMsg}`);
441
+ }
442
+ }
443
+ if (!walletId || !sessionId) {
444
+ debug.log(DebugCategory.PHANTOM_CONNECT_AUTH, "Missing auth parameters in URL", {
445
+ hasWalletId: !!walletId,
446
+ hasSessionId: !!sessionId
447
+ });
448
+ return null;
449
+ }
450
+ const contextStr = sessionStorage.getItem("phantom-auth-context");
451
+ let context = {};
452
+ if (contextStr) {
453
+ try {
454
+ context = JSON.parse(contextStr);
455
+ } catch (parseError) {
456
+ debug.warn(DebugCategory.PHANTOM_CONNECT_AUTH, "Failed to parse stored auth context", { error: parseError });
457
+ }
458
+ }
459
+ if (context.sessionId && sessionId !== context.sessionId) {
460
+ debug.error(DebugCategory.PHANTOM_CONNECT_AUTH, "Session ID mismatch", {
461
+ urlSessionId: sessionId,
462
+ storedSessionId: context.sessionId
463
+ });
464
+ throw new Error("Session ID mismatch - possible session corruption or replay attack");
465
+ }
466
+ sessionStorage.removeItem("phantom-auth-context");
467
+ debug.info(DebugCategory.PHANTOM_CONNECT_AUTH, "Successfully resumed auth from redirect", {
280
468
  walletId,
281
- organizationId: this.config.organizationId,
282
- keypair
469
+ sessionId
470
+ });
471
+ return {
472
+ walletId,
473
+ userInfo: context
283
474
  };
284
- await this.storage.saveSession(session);
475
+ } catch (error) {
476
+ sessionStorage.removeItem("phantom-auth-context");
477
+ throw error;
285
478
  }
286
- const stamper = new import_api_key_stamper.ApiKeyStamper({
287
- apiSecretKey: session.keypair.secretKey
288
- });
289
- this.client = new import_client2.PhantomClient(
290
- {
291
- apiBaseUrl: this.config.apiBaseUrl,
292
- organizationId: session.organizationId
293
- },
294
- stamper
295
- );
296
- this.walletId = session.walletId;
297
- const addresses = await this.client.getWalletAddresses(session.walletId);
298
- this.addresses = addresses.filter((addr) => this.config.addressTypes.some((type) => type === addr.addressType)).map((addr) => ({
299
- addressType: addr.addressType,
300
- address: addr.address
301
- }));
302
- return {
303
- walletId: this.walletId,
304
- addresses: this.addresses
305
- };
306
479
  }
307
- async disconnect() {
308
- await this.storage.clearSession();
309
- this.client = null;
310
- this.walletId = null;
311
- this.addresses = [];
480
+ };
481
+
482
+ // src/providers/embedded/adapters/logger.ts
483
+ var BrowserLogger = class {
484
+ info(category, message, data) {
485
+ debug.info(category, message, data);
312
486
  }
313
- async signMessage(params) {
314
- if (!this.client || !this.walletId) {
315
- throw new Error("Not connected");
316
- }
317
- const parsedMessage = (0, import_parsers.parseMessage)(params.message);
318
- return await this.client.signMessage({
319
- walletId: this.walletId,
320
- message: parsedMessage.base64url,
321
- networkId: params.networkId
322
- });
487
+ warn(category, message, data) {
488
+ debug.warn(category, message, data);
323
489
  }
324
- async signAndSendTransaction(params) {
325
- if (!this.client || !this.walletId) {
326
- throw new Error("Not connected");
327
- }
328
- const parsedTransaction = await (0, import_parsers.parseTransaction)(params.transaction, params.networkId);
329
- return await this.client.signAndSendTransaction({
330
- walletId: this.walletId,
331
- transaction: parsedTransaction.base64url,
332
- networkId: params.networkId
333
- });
490
+ error(category, message, data) {
491
+ debug.error(category, message, data);
334
492
  }
335
- getAddresses() {
336
- return this.addresses;
493
+ log(category, message, data) {
494
+ debug.log(category, message, data);
337
495
  }
338
- isConnected() {
339
- return this.client !== null && this.walletId !== null;
496
+ };
497
+
498
+ // src/providers/embedded/index.ts
499
+ var EmbeddedProvider = class extends import_embedded_provider_core.EmbeddedProvider {
500
+ constructor(config) {
501
+ debug.log(DebugCategory.EMBEDDED_PROVIDER, "Initializing Browser EmbeddedProvider", { config });
502
+ const urlParamsAccessor = new BrowserURLParamsAccessor();
503
+ const platform = {
504
+ storage: new BrowserStorage(),
505
+ authProvider: new BrowserAuthProvider(urlParamsAccessor),
506
+ urlParamsAccessor
507
+ };
508
+ const logger = new BrowserLogger();
509
+ super(config, platform, logger);
510
+ debug.info(DebugCategory.EMBEDDED_PROVIDER, "Browser EmbeddedProvider initialized");
340
511
  }
341
512
  };
342
513
 
@@ -347,8 +518,13 @@ var ProviderManager = class {
347
518
  this.currentProvider = null;
348
519
  this.currentProviderKey = null;
349
520
  this.walletId = null;
521
+ debug.log(DebugCategory.PROVIDER_MANAGER, "Initializing ProviderManager", { config });
350
522
  this.config = config;
523
+ debug.log(DebugCategory.PROVIDER_MANAGER, "Setting default provider");
351
524
  this.setDefaultProvider();
525
+ debug.info(DebugCategory.PROVIDER_MANAGER, "ProviderManager initialized", {
526
+ currentProviderKey: this.currentProviderKey
527
+ });
352
528
  }
353
529
  /**
354
530
  * Switch to a different provider type
@@ -389,13 +565,27 @@ var ProviderManager = class {
389
565
  /**
390
566
  * Connect using the current provider
391
567
  */
392
- async connect() {
568
+ async connect(authOptions) {
569
+ debug.info(DebugCategory.PROVIDER_MANAGER, "Starting connection", {
570
+ currentProviderKey: this.currentProviderKey,
571
+ authOptions: authOptions ? { provider: authOptions.provider, hasJwtToken: !!authOptions.jwtToken } : void 0
572
+ });
393
573
  if (!this.currentProvider) {
574
+ debug.error(DebugCategory.PROVIDER_MANAGER, "No provider selected");
394
575
  throw new Error("No provider selected");
395
576
  }
396
- const result = await this.currentProvider.connect();
577
+ debug.log(DebugCategory.PROVIDER_MANAGER, "Delegating to provider connect method");
578
+ const result = await this.currentProvider.connect(authOptions);
397
579
  this.walletId = result.walletId || null;
580
+ debug.log(DebugCategory.PROVIDER_MANAGER, "Connection successful, saving preferences", {
581
+ walletId: this.walletId,
582
+ addressCount: result.addresses?.length || 0
583
+ });
398
584
  this.saveProviderPreference();
585
+ debug.info(DebugCategory.PROVIDER_MANAGER, "Connect completed", {
586
+ walletId: this.walletId,
587
+ addresses: result.addresses
588
+ });
399
589
  return result;
400
590
  }
401
591
  /**
@@ -475,7 +665,7 @@ var ProviderManager = class {
475
665
  provider = new EmbeddedProvider({
476
666
  apiBaseUrl: this.config.apiBaseUrl,
477
667
  organizationId: this.config.organizationId,
478
- authUrl: this.config.authUrl,
668
+ authOptions: this.config.authOptions,
479
669
  embeddedWalletType: embeddedWalletType || "app-wallet",
480
670
  addressTypes: this.config.addressTypes || [],
481
671
  solanaProvider: this.config.solanaProvider || "web3js"
@@ -529,37 +719,78 @@ var ProviderManager = class {
529
719
  var import_browser_injected_sdk2 = require("@phantom/browser-injected-sdk");
530
720
  var BrowserSDK = class {
531
721
  constructor(config) {
722
+ if (config.debug?.enabled) {
723
+ debug.enable();
724
+ if (config.debug.level !== void 0) {
725
+ debug.setLevel(config.debug.level);
726
+ }
727
+ if (config.debug.callback) {
728
+ debug.setCallback(config.debug.callback);
729
+ }
730
+ }
731
+ debug.info(DebugCategory.BROWSER_SDK, "Initializing BrowserSDK", {
732
+ providerType: config.providerType,
733
+ embeddedWalletType: config.embeddedWalletType,
734
+ addressTypes: config.addressTypes,
735
+ debugEnabled: config.debug?.enabled
736
+ });
532
737
  if (!["injected", "embedded"].includes(config.providerType)) {
738
+ debug.error(DebugCategory.BROWSER_SDK, "Invalid providerType", { providerType: config.providerType });
533
739
  throw new Error(`Invalid providerType: ${config.providerType}. Must be "injected" or "embedded".`);
534
740
  }
535
741
  const embeddedWalletType = config.embeddedWalletType || "app-wallet";
536
742
  if (config.providerType === "embedded" && !["app-wallet", "user-wallet"].includes(embeddedWalletType)) {
743
+ debug.error(DebugCategory.BROWSER_SDK, "Invalid embeddedWalletType", {
744
+ embeddedWalletType: config.embeddedWalletType
745
+ });
537
746
  throw new Error(
538
747
  `Invalid embeddedWalletType: ${config.embeddedWalletType}. Must be "app-wallet" or "user-wallet".`
539
748
  );
540
749
  }
541
750
  config.embeddedWalletType = embeddedWalletType;
542
751
  this.config = config;
752
+ debug.log(DebugCategory.BROWSER_SDK, "Creating ProviderManager", { config });
543
753
  this.providerManager = new ProviderManager(config);
754
+ debug.info(DebugCategory.BROWSER_SDK, "BrowserSDK initialized successfully");
544
755
  }
545
756
  /**
546
757
  * Connect to the wallet with optional provider switching
547
758
  */
548
759
  async connect(options) {
760
+ debug.info(DebugCategory.BROWSER_SDK, "Starting connect process", { options });
549
761
  if (options?.providerType) {
762
+ debug.log(DebugCategory.BROWSER_SDK, "Provider switch requested", {
763
+ providerType: options.providerType,
764
+ embeddedWalletType: options.embeddedWalletType
765
+ });
550
766
  if (!["injected", "embedded"].includes(options.providerType)) {
767
+ debug.error(DebugCategory.BROWSER_SDK, "Invalid providerType in connect options", {
768
+ providerType: options.providerType
769
+ });
551
770
  throw new Error(`Invalid providerType: ${options.providerType}. Must be "injected" or "embedded".`);
552
771
  }
553
772
  if (options.embeddedWalletType && !["app-wallet", "user-wallet"].includes(options.embeddedWalletType)) {
773
+ debug.error(DebugCategory.BROWSER_SDK, "Invalid embeddedWalletType in connect options", {
774
+ embeddedWalletType: options.embeddedWalletType
775
+ });
554
776
  throw new Error(
555
777
  `Invalid embeddedWalletType: ${options.embeddedWalletType}. Must be "app-wallet" or "user-wallet".`
556
778
  );
557
779
  }
780
+ debug.log(DebugCategory.BROWSER_SDK, "Switching provider", {
781
+ providerType: options.providerType,
782
+ embeddedWalletType: options.embeddedWalletType
783
+ });
558
784
  await this.providerManager.switchProvider(options.providerType, {
559
785
  embeddedWalletType: options.embeddedWalletType
560
786
  });
561
787
  }
562
- return this.providerManager.connect();
788
+ debug.log(DebugCategory.BROWSER_SDK, "Delegating to ProviderManager.connect", {
789
+ authOptions: options?.authOptions
790
+ });
791
+ const result = await this.providerManager.connect(options?.authOptions);
792
+ debug.info(DebugCategory.BROWSER_SDK, "Connect completed successfully", result);
793
+ return result;
563
794
  }
564
795
  /**
565
796
  * Switch to a different provider type
@@ -667,4 +898,4 @@ var BrowserSDK = class {
667
898
  };
668
899
 
669
900
  // src/index.ts
670
- var import_client3 = require("@phantom/client");
901
+ var import_client2 = require("@phantom/client");