@pollar/core 0.9.0-rc.2 → 0.9.0-rc.4

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.mjs CHANGED
@@ -1171,7 +1171,7 @@ function defaultStorage(options = {}) {
1171
1171
  }
1172
1172
 
1173
1173
  // src/version.ts
1174
- var POLLAR_CORE_VERSION = "0.9.0-rc.2" ;
1174
+ var POLLAR_CORE_VERSION = "0.9.0-rc.4" ;
1175
1175
 
1176
1176
  // src/visibility/noop.ts
1177
1177
  function createNoopVisibilityProvider() {
@@ -1496,7 +1496,7 @@ function isValidSession(value, logger = console) {
1496
1496
  return false;
1497
1497
  }
1498
1498
  const w = wallet;
1499
- if (w["type"] !== "internal" && w["type"] !== "smart" && w["type"] !== "external") {
1499
+ if (w["type"] !== "internal" && w["type"] !== "smart" && w["type"] !== "external" && w["type"] !== "custodial") {
1500
1500
  logger.debug("[PollarClient:session] Invalid session \u2014 wallet.type must be internal|smart|external");
1501
1501
  return false;
1502
1502
  }
@@ -1892,7 +1892,7 @@ async function loginOAuth(provider, deps) {
1892
1892
  }
1893
1893
 
1894
1894
  // src/client/auth/passkeyFlow.ts
1895
- async function loginSmartWallet(deps) {
1895
+ async function smartWalletFlow(deps, mode) {
1896
1896
  const { api, signal, setAuthState, passkey } = deps;
1897
1897
  if (!passkey) {
1898
1898
  setAuthState({
@@ -1915,7 +1915,7 @@ async function loginSmartWallet(deps) {
1915
1915
  return failPasskey(setAuthState, "Failed to start passkey");
1916
1916
  }
1917
1917
  setAuthState({ step: "creating_passkey" });
1918
- const ceremony = await passkey({ challenge });
1918
+ const ceremony = await passkey({ challenge, mode });
1919
1919
  const response = ceremony.response;
1920
1920
  if (ceremony.kind === "register") {
1921
1921
  setAuthState({ step: "deploying_smart_account" });
@@ -2508,9 +2508,10 @@ var PollarClient = class {
2508
2508
  loginWallet(type, this._flowDeps(controller.signal)).catch((err) => this._handleFlowError(err));
2509
2509
  }
2510
2510
  /**
2511
- * "Smart Wallet" login: runs the passkey (WebAuthn) ceremony and, for a new
2512
- * user, creates a sponsored smart-account C-address. Requires the `passkey`
2513
- * ceremony to be configured (e.g. via `@pollar/react`).
2511
+ * "Smart Wallet" login: runs the passkey (WebAuthn) `get()` ceremony for a
2512
+ * returning user and signs them in. Use {@link createSmartWallet} for a new
2513
+ * user. Requires the `passkey` ceremony to be configured (e.g. via
2514
+ * `@pollar/react`).
2514
2515
  */
2515
2516
  loginSmartWallet() {
2516
2517
  if (!isClientRuntime) {
@@ -2518,7 +2519,21 @@ var PollarClient = class {
2518
2519
  return;
2519
2520
  }
2520
2521
  const controller = this._newController();
2521
- loginSmartWallet(this._flowDeps(controller.signal)).catch((err) => this._handleFlowError(err));
2522
+ smartWalletFlow(this._flowDeps(controller.signal), "login").catch((err) => this._handleFlowError(err));
2523
+ }
2524
+ /**
2525
+ * "Smart Wallet" registration: runs the passkey (WebAuthn) `create()` ceremony
2526
+ * for a new user and deploys a sponsored smart-account C-address. Use
2527
+ * {@link loginSmartWallet} for a returning user. Requires the `passkey`
2528
+ * ceremony to be configured (e.g. via `@pollar/react`).
2529
+ */
2530
+ createSmartWallet() {
2531
+ if (!isClientRuntime) {
2532
+ warnServerSide("createSmartWallet");
2533
+ return;
2534
+ }
2535
+ const controller = this._newController();
2536
+ smartWalletFlow(this._flowDeps(controller.signal), "register").catch((err) => this._handleFlowError(err));
2522
2537
  }
2523
2538
  // ─── Cancel ───────────────────────────────────────────────────────────────
2524
2539
  cancelLogin() {
@@ -2758,6 +2773,54 @@ var PollarClient = class {
2758
2773
  this._setEnabledAssetsState({ step: "error", message: "Failed to load assets" });
2759
2774
  }
2760
2775
  }
2776
+ /**
2777
+ * Establishes (omit `limit`) or removes (`limit: '0'`) a trustline for an asset.
2778
+ *
2779
+ * Routing mirrors how the platform pays for the reserve:
2780
+ * - **Sponsored custodial** (`opts.sponsored` true, internal wallet) → the
2781
+ * server orchestrates a sponsored `changeTrust`: the app's wallets cover the
2782
+ * 0.5 XLM reserve and the fee, so the user pays nothing. Pass the asset's
2783
+ * `sponsored` flag (from {@link refreshAssets}) straight through.
2784
+ * - **Self-paid** (external/adapter wallet, sponsorship disabled, or a custom
2785
+ * asset not configured in the app) → a plain `change_trust` transaction the
2786
+ * user's own wallet signs and pays for, via {@link runTx}.
2787
+ *
2788
+ * Does not refresh on its own — callers should `refreshAssets()` afterwards.
2789
+ */
2790
+ async setTrustline(asset, opts) {
2791
+ const limit = opts?.limit;
2792
+ const walletType = this._session?.wallet?.type;
2793
+ if (!this._session?.wallet?.address) {
2794
+ return { status: "error", details: "No wallet connected" };
2795
+ }
2796
+ if (walletType === "smart") {
2797
+ return { status: "error", details: "Trustlines do not apply to smart wallets" };
2798
+ }
2799
+ if (opts?.sponsored && !this._walletAdapter && walletType === "internal") {
2800
+ try {
2801
+ const { data, error } = await this._api.POST("/wallet/assets/trustline", {
2802
+ body: { code: asset.code, issuer: asset.issuer, ...limit !== void 0 && { limit } }
2803
+ });
2804
+ if (!error && data?.success) {
2805
+ if (data.content) this._setEnabledAssetsState({ step: "loaded", data: data.content });
2806
+ return { status: "success" };
2807
+ }
2808
+ const details = error?.details ?? error?.code;
2809
+ return { status: "error", ...details && { details } };
2810
+ } catch (err) {
2811
+ const details = err instanceof Error ? err.message : void 0;
2812
+ return { status: "error", ...details && { details } };
2813
+ }
2814
+ }
2815
+ return this.runTx("change_trust", {
2816
+ asset: {
2817
+ type: asset.code.length <= 4 ? "credit_alphanum4" : "credit_alphanum12",
2818
+ code: asset.code,
2819
+ issuer: asset.issuer
2820
+ },
2821
+ ...limit !== void 0 && { limit }
2822
+ });
2823
+ }
2761
2824
  // ─── Transactions ─────────────────────────────────────────────────────────
2762
2825
  /**
2763
2826
  * Builds an unsigned XDR. Drives `_setTransactionState` for modal-style UIs