@pollar/core 0.9.0-rc.1 → 0.9.0-rc.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.
@@ -1,5 +1,5 @@
1
1
  import { KeyManager, PublicEcJwk } from './index.mjs';
2
- export { AUTH_ERROR_CODES, AdapterFn, AlbedoAdapter, AuthErrorCode, AuthOpenContext, AuthState, AuthUrlOpener, BuildOutcome, BuildProofArgs, ConnectWalletResponse, DistributionClaimBody, DistributionClaimContent, DistributionRule, DistributionRulesState, EnabledAssetRecord, EnabledAssetsState, FreighterAdapter, KycFlow, KycLevel, KycProvider, KycStartBody, KycStartResponse, KycStatus, LocalStorageAdapterOptions, LogLevel, NetworkState, POLLAR_CORE_VERSION, PasskeyCeremony, PasskeySigner, PaymentInstructions, PollarAdapter, PollarAdapters, PollarApiClient, PollarApplicationConfigContent, PollarApplicationConfigResponse, PollarClient, PollarClientConfig, PollarFlowError, PollarLogger, PollarLoginOptions, PollarPersistedSession, PollarUserProfile, RampDirection, RampQuote, RampTxStatus, RampsOfframpBody, RampsOfframpResponse, RampsOnrampBody, RampsOnrampResponse, RampsQuoteQuery, RampsQuoteResponse, RampsTransactionResponse, RulePeriod, SessionInfo, SessionsState, SignAuthEntryOptions, SignAuthEntryResponse, SignOutcome, SignTransactionOptions, SignTransactionResponse, StellarBalance, StellarClient, StellarClientConfig, StellarNetwork, SubmitOutcome, TransactionState, TxBuildBody, TxBuildContent, TxBuildResponse, TxBuildSignSubmitBody, TxBuildSignSubmitContent, TxBuildSignSubmitResponse, TxErrorPhase, TxHistoryContent, TxHistoryParams, TxHistoryRecord, TxHistoryState, TxSignAndSendBody, TxSignBody, TxSignContent, TxSignResponse, TxSignSendResponse, TxSubmitSignedBody, WalletAdapter, WalletAdapterResolver, WalletAssetsContent, WalletBalanceContent, WalletBalanceRecord, WalletBalanceState, WalletId, WalletType, WebCryptoKeyManager, buildProof, canonicalEcJwk, claimDistributionRule, computeJwkThumbprint, createLocalStorageAdapter, createLogger, createMemoryAdapter, createOffRamp, createOnRamp, defaultKeyManager, defaultStorage, getKycProviders, getKycStatus, getRampTransaction, getRampsQuote, isValidSession, listDistributionRules, normalizeHtu, pollKycStatus, pollRampTransaction, pollarPaths, resolveKyc, startKyc } from './index.mjs';
2
+ export { AUTH_ERROR_CODES, AdapterFn, AlbedoAdapter, AuthErrorCode, AuthOpenContext, AuthState, AuthUrlOpener, BuildOutcome, BuildProofArgs, ConnectWalletResponse, DistributionClaimBody, DistributionClaimContent, DistributionRule, DistributionRulesState, EnabledAssetRecord, EnabledAssetsState, FreighterAdapter, KycFlow, KycLevel, KycProvider, KycStartBody, KycStartResponse, KycStatus, LocalStorageAdapterOptions, LogLevel, NetworkState, POLLAR_CORE_VERSION, PasskeyCeremony, PasskeyMode, PasskeySigner, PaymentInstructions, PollarAdapter, PollarAdapters, PollarApiClient, PollarApplicationConfigContent, PollarApplicationConfigResponse, PollarClient, PollarClientConfig, PollarFlowError, PollarLogger, PollarLoginOptions, PollarPersistedSession, PollarUserProfile, RampDirection, RampQuote, RampTxStatus, RampsOfframpBody, RampsOfframpResponse, RampsOnrampBody, RampsOnrampResponse, RampsQuoteQuery, RampsQuoteResponse, RampsTransactionResponse, RulePeriod, SessionInfo, SessionsState, SignAuthEntryOptions, SignAuthEntryResponse, SignOutcome, SignTransactionOptions, SignTransactionResponse, StellarBalance, StellarClient, StellarClientConfig, StellarNetwork, SubmitOutcome, TransactionState, TrustlineOutcome, TxBuildBody, TxBuildContent, TxBuildResponse, TxBuildSignSubmitBody, TxBuildSignSubmitContent, TxBuildSignSubmitResponse, TxErrorPhase, TxHistoryContent, TxHistoryParams, TxHistoryRecord, TxHistoryState, TxSignAndSendBody, TxSignBody, TxSignContent, TxSignResponse, TxSignSendResponse, TxSubmitSignedBody, WalletAdapter, WalletAdapterResolver, WalletAssetsContent, WalletBalanceContent, WalletBalanceRecord, WalletBalanceState, WalletId, WalletType, WebCryptoKeyManager, buildProof, canonicalEcJwk, claimDistributionRule, computeJwkThumbprint, createLocalStorageAdapter, createLogger, createMemoryAdapter, createOffRamp, createOnRamp, defaultKeyManager, defaultStorage, getKycProviders, getKycStatus, getRampTransaction, getRampsQuote, isValidSession, listDistributionRules, normalizeHtu, pollKycStatus, pollRampTransaction, pollarPaths, resolveKyc, startKyc } from './index.mjs';
3
3
  import { S as Storage } from './types-DqgJIJBl.mjs';
4
4
  export { O as OnStorageDegrade, a as StorageDegradeReason } from './types-DqgJIJBl.mjs';
5
5
  import './types-Dyky8g0p.mjs';
@@ -1,5 +1,5 @@
1
1
  import { KeyManager, PublicEcJwk } from './index.js';
2
- export { AUTH_ERROR_CODES, AdapterFn, AlbedoAdapter, AuthErrorCode, AuthOpenContext, AuthState, AuthUrlOpener, BuildOutcome, BuildProofArgs, ConnectWalletResponse, DistributionClaimBody, DistributionClaimContent, DistributionRule, DistributionRulesState, EnabledAssetRecord, EnabledAssetsState, FreighterAdapter, KycFlow, KycLevel, KycProvider, KycStartBody, KycStartResponse, KycStatus, LocalStorageAdapterOptions, LogLevel, NetworkState, POLLAR_CORE_VERSION, PasskeyCeremony, PasskeySigner, PaymentInstructions, PollarAdapter, PollarAdapters, PollarApiClient, PollarApplicationConfigContent, PollarApplicationConfigResponse, PollarClient, PollarClientConfig, PollarFlowError, PollarLogger, PollarLoginOptions, PollarPersistedSession, PollarUserProfile, RampDirection, RampQuote, RampTxStatus, RampsOfframpBody, RampsOfframpResponse, RampsOnrampBody, RampsOnrampResponse, RampsQuoteQuery, RampsQuoteResponse, RampsTransactionResponse, RulePeriod, SessionInfo, SessionsState, SignAuthEntryOptions, SignAuthEntryResponse, SignOutcome, SignTransactionOptions, SignTransactionResponse, StellarBalance, StellarClient, StellarClientConfig, StellarNetwork, SubmitOutcome, TransactionState, TxBuildBody, TxBuildContent, TxBuildResponse, TxBuildSignSubmitBody, TxBuildSignSubmitContent, TxBuildSignSubmitResponse, TxErrorPhase, TxHistoryContent, TxHistoryParams, TxHistoryRecord, TxHistoryState, TxSignAndSendBody, TxSignBody, TxSignContent, TxSignResponse, TxSignSendResponse, TxSubmitSignedBody, WalletAdapter, WalletAdapterResolver, WalletAssetsContent, WalletBalanceContent, WalletBalanceRecord, WalletBalanceState, WalletId, WalletType, WebCryptoKeyManager, buildProof, canonicalEcJwk, claimDistributionRule, computeJwkThumbprint, createLocalStorageAdapter, createLogger, createMemoryAdapter, createOffRamp, createOnRamp, defaultKeyManager, defaultStorage, getKycProviders, getKycStatus, getRampTransaction, getRampsQuote, isValidSession, listDistributionRules, normalizeHtu, pollKycStatus, pollRampTransaction, pollarPaths, resolveKyc, startKyc } from './index.js';
2
+ export { AUTH_ERROR_CODES, AdapterFn, AlbedoAdapter, AuthErrorCode, AuthOpenContext, AuthState, AuthUrlOpener, BuildOutcome, BuildProofArgs, ConnectWalletResponse, DistributionClaimBody, DistributionClaimContent, DistributionRule, DistributionRulesState, EnabledAssetRecord, EnabledAssetsState, FreighterAdapter, KycFlow, KycLevel, KycProvider, KycStartBody, KycStartResponse, KycStatus, LocalStorageAdapterOptions, LogLevel, NetworkState, POLLAR_CORE_VERSION, PasskeyCeremony, PasskeyMode, PasskeySigner, PaymentInstructions, PollarAdapter, PollarAdapters, PollarApiClient, PollarApplicationConfigContent, PollarApplicationConfigResponse, PollarClient, PollarClientConfig, PollarFlowError, PollarLogger, PollarLoginOptions, PollarPersistedSession, PollarUserProfile, RampDirection, RampQuote, RampTxStatus, RampsOfframpBody, RampsOfframpResponse, RampsOnrampBody, RampsOnrampResponse, RampsQuoteQuery, RampsQuoteResponse, RampsTransactionResponse, RulePeriod, SessionInfo, SessionsState, SignAuthEntryOptions, SignAuthEntryResponse, SignOutcome, SignTransactionOptions, SignTransactionResponse, StellarBalance, StellarClient, StellarClientConfig, StellarNetwork, SubmitOutcome, TransactionState, TrustlineOutcome, TxBuildBody, TxBuildContent, TxBuildResponse, TxBuildSignSubmitBody, TxBuildSignSubmitContent, TxBuildSignSubmitResponse, TxErrorPhase, TxHistoryContent, TxHistoryParams, TxHistoryRecord, TxHistoryState, TxSignAndSendBody, TxSignBody, TxSignContent, TxSignResponse, TxSignSendResponse, TxSubmitSignedBody, WalletAdapter, WalletAdapterResolver, WalletAssetsContent, WalletBalanceContent, WalletBalanceRecord, WalletBalanceState, WalletId, WalletType, WebCryptoKeyManager, buildProof, canonicalEcJwk, claimDistributionRule, computeJwkThumbprint, createLocalStorageAdapter, createLogger, createMemoryAdapter, createOffRamp, createOnRamp, defaultKeyManager, defaultStorage, getKycProviders, getKycStatus, getRampTransaction, getRampsQuote, isValidSession, listDistributionRules, normalizeHtu, pollKycStatus, pollRampTransaction, pollarPaths, resolveKyc, startKyc } from './index.js';
3
3
  import { S as Storage } from './types-DqgJIJBl.js';
4
4
  export { O as OnStorageDegrade, a as StorageDegradeReason } from './types-DqgJIJBl.js';
5
5
  import './types-Dyky8g0p.js';
package/dist/index.rn.js CHANGED
@@ -1109,7 +1109,7 @@ function defaultStorage(options = {}) {
1109
1109
  }
1110
1110
 
1111
1111
  // src/version.ts
1112
- var POLLAR_CORE_VERSION = "0.9.0-rc.1" ;
1112
+ var POLLAR_CORE_VERSION = "0.9.0-rc.3" ;
1113
1113
 
1114
1114
  // src/visibility/noop.ts
1115
1115
  function createNoopVisibilityProvider() {
@@ -1281,7 +1281,10 @@ function openAlbedoPopup(url) {
1281
1281
  }
1282
1282
  function waitForAlbedoPopup() {
1283
1283
  return new Promise((resolve, reject) => {
1284
- const timeout = setTimeout(() => reject(new Error("Albedo response timeout")), 2 * 60 * 1e3);
1284
+ const timeout = setTimeout(() => {
1285
+ window.removeEventListener("message", handler);
1286
+ reject(new Error("Albedo response timeout"));
1287
+ }, 2 * 60 * 1e3);
1285
1288
  function handler(event) {
1286
1289
  if (event.origin !== window.location.origin || event.data?.type !== "ALBEDO_RESULT") return;
1287
1290
  clearTimeout(timeout);
@@ -1291,24 +1294,6 @@ function waitForAlbedoPopup() {
1291
1294
  window.addEventListener("message", handler);
1292
1295
  });
1293
1296
  }
1294
- function waitForAlbedoResult() {
1295
- return new Promise((resolve, reject) => {
1296
- const timeout = setTimeout(() => reject(new Error("Albedo response timeout")), 2 * 60 * 1e3);
1297
- const parseResult = () => {
1298
- const params = new URLSearchParams(window.location.search);
1299
- if (!params.has("pubkey") && !params.has("signed_envelope_xdr") && !params.has("signed_xdr")) return;
1300
- clearTimeout(timeout);
1301
- const result = {};
1302
- params.forEach((value, key) => {
1303
- result[key] = value;
1304
- });
1305
- window.history.replaceState({}, document.title, window.location.pathname);
1306
- resolve(result);
1307
- };
1308
- parseResult();
1309
- window.addEventListener("popstate", parseResult);
1310
- });
1311
- }
1312
1297
  var AlbedoAdapter = class {
1313
1298
  /**
1314
1299
  * Network used for `connect` and `signAuthEntry` (which carry no per-call
@@ -1350,10 +1335,10 @@ var AlbedoAdapter = class {
1350
1335
  url.searchParams.set("xdr", xdr);
1351
1336
  url.searchParams.set("app_name", "Pollar");
1352
1337
  url.searchParams.set("network", albedoNetwork(options, this.network));
1353
- url.searchParams.set("callback", window.location.href);
1338
+ url.searchParams.set("callback", `${window.location.origin}/albedo-callback`);
1354
1339
  url.searchParams.set("origin", window.location.origin);
1355
- window.location.href = url.toString();
1356
- const result = await waitForAlbedoResult();
1340
+ openAlbedoPopup(url.toString());
1341
+ const result = await waitForAlbedoPopup();
1357
1342
  if (!result.signed_envelope_xdr) throw new Error("Albedo signing rejected");
1358
1343
  return { signedTxXdr: result.signed_envelope_xdr };
1359
1344
  }
@@ -1363,10 +1348,10 @@ var AlbedoAdapter = class {
1363
1348
  url.searchParams.set("xdr", entryXdr);
1364
1349
  url.searchParams.set("app_name", "Pollar");
1365
1350
  url.searchParams.set("network", this.network);
1366
- url.searchParams.set("callback", window.location.href);
1351
+ url.searchParams.set("callback", `${window.location.origin}/albedo-callback`);
1367
1352
  url.searchParams.set("origin", window.location.origin);
1368
- window.location.href = url.toString();
1369
- const result = await waitForAlbedoResult();
1353
+ openAlbedoPopup(url.toString());
1354
+ const result = await waitForAlbedoPopup();
1370
1355
  if (!result.signed_xdr) throw new Error("Albedo auth entry signing rejected");
1371
1356
  return { signedAuthEntry: result.signed_xdr };
1372
1357
  }
@@ -1449,8 +1434,8 @@ function isValidSession(value, logger = console) {
1449
1434
  return false;
1450
1435
  }
1451
1436
  const w = wallet;
1452
- if (w["type"] !== "custodial" && w["type"] !== "smart" && w["type"] !== "external") {
1453
- logger.debug("[PollarClient:session] Invalid session \u2014 wallet.type must be custodial|smart|external");
1437
+ if (w["type"] !== "internal" && w["type"] !== "smart" && w["type"] !== "external") {
1438
+ logger.debug("[PollarClient:session] Invalid session \u2014 wallet.type must be internal|smart|external");
1454
1439
  return false;
1455
1440
  }
1456
1441
  if (w["address"] !== null && !isBoundedString(w["address"], MAX_WALLET_PUBLIC_KEY)) {
@@ -1481,6 +1466,9 @@ async function readStorage(storage, apiKeyHash, logger = console) {
1481
1466
  if (w && w["address"] == null && typeof w["publicKey"] === "string") {
1482
1467
  w["address"] = w["publicKey"];
1483
1468
  }
1469
+ if (w && w["type"] === "custodial") {
1470
+ w["type"] = "internal";
1471
+ }
1484
1472
  }
1485
1473
  if (!isValidSession(session, logger)) {
1486
1474
  await storage.remove(sessionStorageKey(apiKeyHash));
@@ -1581,16 +1569,12 @@ async function streamUntilFound(api, clientSessionId, check, retryDelayMs = 200,
1581
1569
  }
1582
1570
  const reader = data.getReader();
1583
1571
  const decoder = new TextDecoder();
1584
- let streamDone = false;
1585
1572
  let sawAnyChunk = false;
1586
1573
  try {
1587
1574
  while (true) {
1588
1575
  throwIfAborted(signal);
1589
1576
  const { done, value } = await reader.read();
1590
- if (done) {
1591
- streamDone = true;
1592
- break;
1593
- }
1577
+ if (done) break;
1594
1578
  sawAnyChunk = true;
1595
1579
  const chunk = decoder.decode(value);
1596
1580
  for (const message of chunk.split("\n\n").filter(Boolean)) {
@@ -1618,8 +1602,7 @@ async function streamUntilFound(api, clientSessionId, check, retryDelayMs = 200,
1618
1602
  }
1619
1603
  if (sawAnyChunk) backoff = retryDelayMs;
1620
1604
  else backoff = Math.min(backoff * 2, MAX_BACKOFF_MS);
1621
- const delay = streamDone ? backoff : 0;
1622
- if (delay) await sleep(delay);
1605
+ await sleep(backoff);
1623
1606
  }
1624
1607
  }
1625
1608
  async function pollUntilFound(baseUrl, clientSessionId, check, intervalMs = 500, signal, logger = console) {
@@ -1699,17 +1682,18 @@ async function authenticate(clientSessionId, deps, expectedWallet) {
1699
1682
  signal
1700
1683
  });
1701
1684
  if (data?.code === "SDK_LOGIN_SUCCESS" && isValidSession(data?.content, logger)) {
1702
- if (expectedWallet && data.content.data.providers.wallet?.address !== expectedWallet) {
1685
+ const sessionWallet = data.content.data?.providers?.wallet?.address;
1686
+ if (expectedWallet && sessionWallet !== expectedWallet) {
1703
1687
  setAuthState({
1704
1688
  step: "error",
1705
1689
  previousStep: "authenticating",
1706
1690
  message: "Wallet mismatch: session wallet does not match connected wallet",
1707
1691
  errorCode: AUTH_ERROR_CODES.WALLET_AUTH_FAILED
1708
1692
  });
1709
- clearSession();
1693
+ await clearSession();
1710
1694
  return;
1711
1695
  }
1712
- storeSession(data.content);
1696
+ await storeSession(data.content);
1713
1697
  } else {
1714
1698
  setAuthState({
1715
1699
  step: "error",
@@ -1717,7 +1701,7 @@ async function authenticate(clientSessionId, deps, expectedWallet) {
1717
1701
  message: "Failed to load session",
1718
1702
  errorCode: AUTH_ERROR_CODES.AUTH_FAILED
1719
1703
  });
1720
- clearSession();
1704
+ await clearSession();
1721
1705
  }
1722
1706
  }
1723
1707
 
@@ -1846,7 +1830,7 @@ async function loginOAuth(provider, deps) {
1846
1830
  }
1847
1831
 
1848
1832
  // src/client/auth/passkeyFlow.ts
1849
- async function loginSmartWallet(deps) {
1833
+ async function smartWalletFlow(deps, mode) {
1850
1834
  const { api, signal, setAuthState, passkey } = deps;
1851
1835
  if (!passkey) {
1852
1836
  setAuthState({
@@ -1869,7 +1853,7 @@ async function loginSmartWallet(deps) {
1869
1853
  return failPasskey(setAuthState, "Failed to start passkey");
1870
1854
  }
1871
1855
  setAuthState({ step: "creating_passkey" });
1872
- const ceremony = await passkey({ challenge });
1856
+ const ceremony = await passkey({ challenge, mode });
1873
1857
  const response = ceremony.response;
1874
1858
  if (ceremony.kind === "register") {
1875
1859
  setAuthState({ step: "deploying_smart_account" });
@@ -2033,7 +2017,7 @@ var PollarClient = class {
2033
2017
  this._visibilityProvider = config.visibilityProvider ?? defaultVisibilityProvider();
2034
2018
  this._maxIdleMs = config.maxIdleMs;
2035
2019
  this._openAuthUrl = config.openAuthUrl ?? defaultWebOAuthOpener;
2036
- this._oauthRedirectUri = config.oauthRedirectUri ?? (isBrowser ? window.location.origin : "");
2020
+ this._oauthRedirectUri = config.oauthRedirectUri ?? (isBrowser ? window.location?.origin ?? "" : "");
2037
2021
  this._api = createApiClient(this.basePath);
2038
2022
  this._wireMiddlewares();
2039
2023
  this._networkState = { step: "connected", network: config.stellarNetwork ?? "testnet" };
@@ -2462,9 +2446,10 @@ var PollarClient = class {
2462
2446
  loginWallet(type, this._flowDeps(controller.signal)).catch((err) => this._handleFlowError(err));
2463
2447
  }
2464
2448
  /**
2465
- * "Smart Wallet" login: runs the passkey (WebAuthn) ceremony and, for a new
2466
- * user, creates a sponsored smart-account C-address. Requires the `passkey`
2467
- * ceremony to be configured (e.g. via `@pollar/react`).
2449
+ * "Smart Wallet" login: runs the passkey (WebAuthn) `get()` ceremony for a
2450
+ * returning user and signs them in. Use {@link createSmartWallet} for a new
2451
+ * user. Requires the `passkey` ceremony to be configured (e.g. via
2452
+ * `@pollar/react`).
2468
2453
  */
2469
2454
  loginSmartWallet() {
2470
2455
  if (!isClientRuntime) {
@@ -2472,7 +2457,21 @@ var PollarClient = class {
2472
2457
  return;
2473
2458
  }
2474
2459
  const controller = this._newController();
2475
- loginSmartWallet(this._flowDeps(controller.signal)).catch((err) => this._handleFlowError(err));
2460
+ smartWalletFlow(this._flowDeps(controller.signal), "login").catch((err) => this._handleFlowError(err));
2461
+ }
2462
+ /**
2463
+ * "Smart Wallet" registration: runs the passkey (WebAuthn) `create()` ceremony
2464
+ * for a new user and deploys a sponsored smart-account C-address. Use
2465
+ * {@link loginSmartWallet} for a returning user. Requires the `passkey`
2466
+ * ceremony to be configured (e.g. via `@pollar/react`).
2467
+ */
2468
+ createSmartWallet() {
2469
+ if (!isClientRuntime) {
2470
+ warnServerSide("createSmartWallet");
2471
+ return;
2472
+ }
2473
+ const controller = this._newController();
2474
+ smartWalletFlow(this._flowDeps(controller.signal), "register").catch((err) => this._handleFlowError(err));
2476
2475
  }
2477
2476
  // ─── Cancel ───────────────────────────────────────────────────────────────
2478
2477
  cancelLogin() {
@@ -2712,6 +2711,54 @@ var PollarClient = class {
2712
2711
  this._setEnabledAssetsState({ step: "error", message: "Failed to load assets" });
2713
2712
  }
2714
2713
  }
2714
+ /**
2715
+ * Establishes (omit `limit`) or removes (`limit: '0'`) a trustline for an asset.
2716
+ *
2717
+ * Routing mirrors how the platform pays for the reserve:
2718
+ * - **Sponsored custodial** (`opts.sponsored` true, internal wallet) → the
2719
+ * server orchestrates a sponsored `changeTrust`: the app's wallets cover the
2720
+ * 0.5 XLM reserve and the fee, so the user pays nothing. Pass the asset's
2721
+ * `sponsored` flag (from {@link refreshAssets}) straight through.
2722
+ * - **Self-paid** (external/adapter wallet, sponsorship disabled, or a custom
2723
+ * asset not configured in the app) → a plain `change_trust` transaction the
2724
+ * user's own wallet signs and pays for, via {@link runTx}.
2725
+ *
2726
+ * Does not refresh on its own — callers should `refreshAssets()` afterwards.
2727
+ */
2728
+ async setTrustline(asset, opts) {
2729
+ const limit = opts?.limit;
2730
+ const walletType = this._session?.wallet?.type;
2731
+ if (!this._session?.wallet?.address) {
2732
+ return { status: "error", details: "No wallet connected" };
2733
+ }
2734
+ if (walletType === "smart") {
2735
+ return { status: "error", details: "Trustlines do not apply to smart wallets" };
2736
+ }
2737
+ if (opts?.sponsored && !this._walletAdapter && walletType === "internal") {
2738
+ try {
2739
+ const { data, error } = await this._api.POST("/wallet/assets/trustline", {
2740
+ body: { code: asset.code, issuer: asset.issuer, ...limit !== void 0 && { limit } }
2741
+ });
2742
+ if (!error && data?.success) {
2743
+ if (data.content) this._setEnabledAssetsState({ step: "loaded", data: data.content });
2744
+ return { status: "success" };
2745
+ }
2746
+ const details = error?.details ?? error?.code;
2747
+ return { status: "error", ...details && { details } };
2748
+ } catch (err) {
2749
+ const details = err instanceof Error ? err.message : void 0;
2750
+ return { status: "error", ...details && { details } };
2751
+ }
2752
+ }
2753
+ return this.runTx("change_trust", {
2754
+ asset: {
2755
+ type: asset.code.length <= 4 ? "credit_alphanum4" : "credit_alphanum12",
2756
+ code: asset.code,
2757
+ issuer: asset.issuer
2758
+ },
2759
+ ...limit !== void 0 && { limit }
2760
+ });
2761
+ }
2715
2762
  // ─── Transactions ─────────────────────────────────────────────────────────
2716
2763
  /**
2717
2764
  * Builds an unsigned XDR. Drives `_setTransactionState` for modal-style UIs
@@ -3347,6 +3394,9 @@ var PollarClient = class {
3347
3394
  void this._resume();
3348
3395
  } else {
3349
3396
  this._log.info("[PollarClient] No session in storage");
3397
+ if (this._authState.step !== "idle") {
3398
+ await this._clearSession();
3399
+ }
3350
3400
  }
3351
3401
  }
3352
3402
  /**
@@ -3393,8 +3443,11 @@ var PollarClient = class {
3393
3443
  user: session.user,
3394
3444
  // The wire response still carries the legacy `publicKey` alias (kept for
3395
3445
  // older SDKs); the persisted session standardizes on `address` only.
3446
+ // The wire also still emits the legacy type `'custodial'` (unchanged for
3447
+ // SDKs ≤0.8.x); we remap it to `'internal'` here so the SDK surface and
3448
+ // persisted session speak one vocabulary while the wire stays compatible.
3396
3449
  wallet: {
3397
- type: w.type,
3450
+ type: w.type === "custodial" ? "internal" : w.type,
3398
3451
  address: w.address ?? w.publicKey ?? null,
3399
3452
  ...w.existsOnStellar !== void 0 ? { existsOnStellar: w.existsOnStellar } : {},
3400
3453
  ...w.createdAt !== void 0 ? { createdAt: w.createdAt } : {},