@dubsdotapp/expo 0.2.27 → 0.2.29

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.d.mts CHANGED
@@ -428,6 +428,7 @@ interface TokenStorage {
428
428
  }
429
429
  declare const STORAGE_KEYS: {
430
430
  readonly MWA_AUTH_TOKEN: "dubs_mwa_auth_token";
431
+ readonly MWA_WALLET_ADDRESS: "dubs_mwa_wallet_address";
431
432
  readonly JWT_TOKEN: "dubs_jwt_token";
432
433
  readonly PHANTOM_SESSION: "dubs_phantom_session";
433
434
  readonly PHANTOM_CONNECT_IN_FLIGHT: "dubs_phantom_connect_in_flight";
@@ -562,16 +563,6 @@ interface MwaAdapterConfig {
562
563
  /**
563
564
  * Mobile Wallet Adapter implementation.
564
565
  * Wraps @solana-mobile/mobile-wallet-adapter-protocol-web3js.
565
- *
566
- * Usage:
567
- * ```ts
568
- * import { transact } from '@solana-mobile/mobile-wallet-adapter-protocol-web3js';
569
- *
570
- * const adapter = new MwaWalletAdapter({
571
- * transact,
572
- * appIdentity: { name: 'My App' },
573
- * });
574
- * ```
575
566
  */
576
567
  declare class MwaWalletAdapter implements WalletAdapter {
577
568
  private _publicKey;
@@ -586,8 +577,16 @@ declare class MwaWalletAdapter implements WalletAdapter {
586
577
  get connected(): boolean;
587
578
  get authToken(): string | null;
588
579
  setAuthToken(token: string | null): void;
580
+ /**
581
+ * Restore a previous session silently (no wallet interaction).
582
+ * Sets the public key and auth token so the adapter appears connected.
583
+ * The next signing operation will reauthorize with Phantom.
584
+ */
585
+ restoreSession(token: string, walletAddressBase58: string): void;
589
586
  /**
590
587
  * Connect to a mobile wallet. Call this before any signing.
588
+ * Tries reauthorize first (if we have a saved token), then falls back to
589
+ * a fresh authorize in a SEPARATE transact session.
591
590
  */
592
591
  connect(): Promise<void>;
593
592
  /**
@@ -597,6 +596,7 @@ declare class MwaWalletAdapter implements WalletAdapter {
597
596
  signTransaction(transaction: Transaction): Promise<Transaction>;
598
597
  signMessage(message: Uint8Array): Promise<Uint8Array>;
599
598
  signAndSendTransaction(transaction: Transaction): Promise<string>;
599
+ private applyAuthResult;
600
600
  }
601
601
 
602
602
  /** Serializable session state — save this to restore without a deeplink round-trip. */
package/dist/index.d.ts CHANGED
@@ -428,6 +428,7 @@ interface TokenStorage {
428
428
  }
429
429
  declare const STORAGE_KEYS: {
430
430
  readonly MWA_AUTH_TOKEN: "dubs_mwa_auth_token";
431
+ readonly MWA_WALLET_ADDRESS: "dubs_mwa_wallet_address";
431
432
  readonly JWT_TOKEN: "dubs_jwt_token";
432
433
  readonly PHANTOM_SESSION: "dubs_phantom_session";
433
434
  readonly PHANTOM_CONNECT_IN_FLIGHT: "dubs_phantom_connect_in_flight";
@@ -562,16 +563,6 @@ interface MwaAdapterConfig {
562
563
  /**
563
564
  * Mobile Wallet Adapter implementation.
564
565
  * Wraps @solana-mobile/mobile-wallet-adapter-protocol-web3js.
565
- *
566
- * Usage:
567
- * ```ts
568
- * import { transact } from '@solana-mobile/mobile-wallet-adapter-protocol-web3js';
569
- *
570
- * const adapter = new MwaWalletAdapter({
571
- * transact,
572
- * appIdentity: { name: 'My App' },
573
- * });
574
- * ```
575
566
  */
576
567
  declare class MwaWalletAdapter implements WalletAdapter {
577
568
  private _publicKey;
@@ -586,8 +577,16 @@ declare class MwaWalletAdapter implements WalletAdapter {
586
577
  get connected(): boolean;
587
578
  get authToken(): string | null;
588
579
  setAuthToken(token: string | null): void;
580
+ /**
581
+ * Restore a previous session silently (no wallet interaction).
582
+ * Sets the public key and auth token so the adapter appears connected.
583
+ * The next signing operation will reauthorize with Phantom.
584
+ */
585
+ restoreSession(token: string, walletAddressBase58: string): void;
589
586
  /**
590
587
  * Connect to a mobile wallet. Call this before any signing.
588
+ * Tries reauthorize first (if we have a saved token), then falls back to
589
+ * a fresh authorize in a SEPARATE transact session.
591
590
  */
592
591
  connect(): Promise<void>;
593
592
  /**
@@ -597,6 +596,7 @@ declare class MwaWalletAdapter implements WalletAdapter {
597
596
  signTransaction(transaction: Transaction): Promise<Transaction>;
598
597
  signMessage(message: Uint8Array): Promise<Uint8Array>;
599
598
  signAndSendTransaction(transaction: Transaction): Promise<string>;
599
+ private applyAuthResult;
600
600
  }
601
601
 
602
602
  /** Serializable session state — save this to restore without a deeplink round-trip. */
package/dist/index.js CHANGED
@@ -521,6 +521,7 @@ var DubsClient = class {
521
521
  // src/storage.ts
522
522
  var STORAGE_KEYS = {
523
523
  MWA_AUTH_TOKEN: "dubs_mwa_auth_token",
524
+ MWA_WALLET_ADDRESS: "dubs_mwa_wallet_address",
524
525
  JWT_TOKEN: "dubs_jwt_token",
525
526
  PHANTOM_SESSION: "dubs_phantom_session",
526
527
  PHANTOM_CONNECT_IN_FLIGHT: "dubs_phantom_connect_in_flight"
@@ -594,34 +595,41 @@ var MwaWalletAdapter = class {
594
595
  setAuthToken(token) {
595
596
  this._authToken = token;
596
597
  }
598
+ /**
599
+ * Restore a previous session silently (no wallet interaction).
600
+ * Sets the public key and auth token so the adapter appears connected.
601
+ * The next signing operation will reauthorize with Phantom.
602
+ */
603
+ restoreSession(token, walletAddressBase58) {
604
+ this._authToken = token;
605
+ this._publicKey = new import_web3.PublicKey(walletAddressBase58);
606
+ this._connected = true;
607
+ }
597
608
  /**
598
609
  * Connect to a mobile wallet. Call this before any signing.
610
+ * Tries reauthorize first (if we have a saved token), then falls back to
611
+ * a fresh authorize in a SEPARATE transact session.
599
612
  */
600
613
  async connect() {
601
- await this.transact(async (wallet) => {
602
- let authResult;
603
- if (this._authToken) {
604
- try {
605
- authResult = await wallet.reauthorize({ auth_token: this._authToken });
606
- } catch {
607
- console.log("[Dubs:MWA] reauthorize failed, falling back to authorize");
608
- this._authToken = null;
609
- authResult = await wallet.authorize({
610
- identity: this.config.appIdentity,
611
- cluster: this.config.cluster || "mainnet-beta"
612
- });
613
- }
614
- } else {
615
- authResult = await wallet.authorize({
616
- identity: this.config.appIdentity,
617
- cluster: this.config.cluster || "mainnet-beta"
614
+ if (this._authToken) {
615
+ try {
616
+ await this.transact(async (wallet) => {
617
+ const authResult = await wallet.reauthorize({ auth_token: this._authToken });
618
+ this.applyAuthResult(authResult);
618
619
  });
620
+ return;
621
+ } catch {
622
+ console.log("[Dubs:MWA] reauthorize failed, clearing token and doing fresh authorize");
623
+ this._authToken = null;
624
+ this.config.onAuthTokenChange?.(null);
619
625
  }
620
- this._mwaAddress = authResult.accounts[0].address;
621
- this._publicKey = toPublicKey(this._mwaAddress);
622
- this._authToken = authResult.auth_token;
623
- this._connected = true;
624
- this.config.onAuthTokenChange?.(this._authToken);
626
+ }
627
+ await this.transact(async (wallet) => {
628
+ const authResult = await wallet.authorize({
629
+ identity: this.config.appIdentity,
630
+ cluster: this.config.cluster || "mainnet-beta"
631
+ });
632
+ this.applyAuthResult(authResult);
625
633
  });
626
634
  }
627
635
  /**
@@ -638,8 +646,7 @@ var MwaWalletAdapter = class {
638
646
  if (!this._connected) throw new Error("Wallet not connected");
639
647
  const signed = await this.transact(async (wallet) => {
640
648
  const reauth = await wallet.reauthorize({ auth_token: this._authToken });
641
- this._authToken = reauth.auth_token;
642
- this.config.onAuthTokenChange?.(this._authToken);
649
+ this.applyAuthResult(reauth);
643
650
  const result = await wallet.signTransactions({
644
651
  transactions: [transaction]
645
652
  });
@@ -651,9 +658,7 @@ var MwaWalletAdapter = class {
651
658
  if (!this._connected || !this._publicKey) throw new Error("Wallet not connected");
652
659
  const sig = await this.transact(async (wallet) => {
653
660
  const reauth = await wallet.reauthorize({ auth_token: this._authToken });
654
- this._authToken = reauth.auth_token;
655
- this._mwaAddress = reauth.accounts[0].address;
656
- this.config.onAuthTokenChange?.(this._authToken);
661
+ this.applyAuthResult(reauth);
657
662
  const result = await wallet.signMessages({
658
663
  addresses: [reauth.accounts[0].address],
659
664
  payloads: [message]
@@ -666,8 +671,7 @@ var MwaWalletAdapter = class {
666
671
  if (!this._connected) throw new Error("Wallet not connected");
667
672
  const signature = await this.transact(async (wallet) => {
668
673
  const reauth = await wallet.reauthorize({ auth_token: this._authToken });
669
- this._authToken = reauth.auth_token;
670
- this.config.onAuthTokenChange?.(this._authToken);
674
+ this.applyAuthResult(reauth);
671
675
  const result = await wallet.signAndSendTransactions({
672
676
  transactions: [transaction]
673
677
  });
@@ -678,6 +682,13 @@ var MwaWalletAdapter = class {
678
682
  }
679
683
  return String(signature);
680
684
  }
685
+ applyAuthResult(authResult) {
686
+ this._mwaAddress = authResult.accounts[0].address;
687
+ this._publicKey = toPublicKey(this._mwaAddress);
688
+ this._authToken = authResult.auth_token;
689
+ this._connected = true;
690
+ this.config.onAuthTokenChange?.(this._authToken);
691
+ }
681
692
  };
682
693
 
683
694
  // src/wallet/phantom-deeplink/phantom-deeplink-adapter.ts
@@ -1379,7 +1390,7 @@ function ManagedWalletProvider({
1379
1390
  }
1380
1391
  return transactRef.current(...args);
1381
1392
  },
1382
- appIdentity: { name: appName },
1393
+ appIdentity: { name: appName, uri: appUrl },
1383
1394
  cluster,
1384
1395
  onAuthTokenChange: (token) => {
1385
1396
  if (token) {
@@ -1457,19 +1468,20 @@ function ManagedWalletProvider({
1457
1468
  }
1458
1469
  try {
1459
1470
  const savedToken = await storage.getItem(STORAGE_KEYS.MWA_AUTH_TOKEN);
1460
- if (savedToken && !cancelled) {
1461
- console.log(TAG3, "Found saved MWA auth token, reconnecting...");
1462
- adapter.setAuthToken(savedToken);
1463
- await adapter.connect();
1464
- if (!cancelled) {
1465
- console.log(TAG3, "MWA reconnected from saved token");
1466
- setConnected(true);
1467
- }
1471
+ const savedAddress = await storage.getItem(STORAGE_KEYS.MWA_WALLET_ADDRESS);
1472
+ if (savedToken && savedAddress && !cancelled) {
1473
+ console.log(TAG3, "Found saved MWA session, restoring silently for wallet:", savedAddress);
1474
+ adapter.restoreSession(savedToken, savedAddress);
1475
+ setConnected(true);
1468
1476
  } else {
1469
- console.log(TAG3, "No saved MWA auth token");
1477
+ console.log(TAG3, "No saved MWA session (token or address missing)");
1470
1478
  }
1471
1479
  } catch (err) {
1472
- console.log(TAG3, "MWA silent reconnect failed:", err instanceof Error ? err.message : err);
1480
+ console.log(TAG3, "MWA session restore failed:", err instanceof Error ? err.message : err);
1481
+ await storage.deleteItem(STORAGE_KEYS.MWA_AUTH_TOKEN).catch(() => {
1482
+ });
1483
+ await storage.deleteItem(STORAGE_KEYS.MWA_WALLET_ADDRESS).catch(() => {
1484
+ });
1473
1485
  } finally {
1474
1486
  if (!cancelled) {
1475
1487
  console.log(TAG3, "MWA init complete, marking ready");
@@ -1488,7 +1500,12 @@ function ManagedWalletProvider({
1488
1500
  setError(null);
1489
1501
  try {
1490
1502
  await adapter.connect();
1491
- console.log(TAG3, "handleConnect() \u2014 success, wallet:", adapter.publicKey?.toBase58());
1503
+ const walletAddress = adapter.publicKey?.toBase58();
1504
+ console.log(TAG3, "handleConnect() \u2014 success, wallet:", walletAddress);
1505
+ if (!usePhantom && walletAddress) {
1506
+ storage.setItem(STORAGE_KEYS.MWA_WALLET_ADDRESS, walletAddress).catch(() => {
1507
+ });
1508
+ }
1492
1509
  setConnected(true);
1493
1510
  } catch (err) {
1494
1511
  const message = err instanceof Error ? err.message : "Connection failed";
@@ -1497,7 +1514,7 @@ function ManagedWalletProvider({
1497
1514
  } finally {
1498
1515
  setConnecting(false);
1499
1516
  }
1500
- }, [adapter]);
1517
+ }, [adapter, storage, usePhantom]);
1501
1518
  const disconnect = (0, import_react.useCallback)(async () => {
1502
1519
  console.log(TAG3, "disconnect() \u2014 clearing all state");
1503
1520
  adapter.disconnect?.();
@@ -1509,6 +1526,8 @@ function ManagedWalletProvider({
1509
1526
  }
1510
1527
  await storage.deleteItem(STORAGE_KEYS.MWA_AUTH_TOKEN).catch(() => {
1511
1528
  });
1529
+ await storage.deleteItem(STORAGE_KEYS.MWA_WALLET_ADDRESS).catch(() => {
1530
+ });
1512
1531
  await storage.deleteItem(STORAGE_KEYS.PHANTOM_SESSION).catch(() => {
1513
1532
  });
1514
1533
  await storage.deleteItem(STORAGE_KEYS.JWT_TOKEN).catch(() => {