@pollar/core 0.9.0-rc.1 → 0.9.0-rc.2
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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +31 -41
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -41
- package/dist/index.mjs.map +1 -1
- package/dist/index.rn.js +31 -41
- package/dist/index.rn.js.map +1 -1
- package/dist/index.rn.mjs +31 -41
- package/dist/index.rn.mjs.map +1 -1
- package/package.json +1 -1
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.
|
|
1112
|
+
var POLLAR_CORE_VERSION = "0.9.0-rc.2" ;
|
|
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(() =>
|
|
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.
|
|
1338
|
+
url.searchParams.set("callback", `${window.location.origin}/albedo-callback`);
|
|
1354
1339
|
url.searchParams.set("origin", window.location.origin);
|
|
1355
|
-
|
|
1356
|
-
const result = await
|
|
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.
|
|
1351
|
+
url.searchParams.set("callback", `${window.location.origin}/albedo-callback`);
|
|
1367
1352
|
url.searchParams.set("origin", window.location.origin);
|
|
1368
|
-
|
|
1369
|
-
const result = await
|
|
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"] !== "
|
|
1453
|
-
logger.debug("[PollarClient:session] Invalid session \u2014 wallet.type must be
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
|
@@ -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
|
|
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" };
|
|
@@ -3347,6 +3331,9 @@ var PollarClient = class {
|
|
|
3347
3331
|
void this._resume();
|
|
3348
3332
|
} else {
|
|
3349
3333
|
this._log.info("[PollarClient] No session in storage");
|
|
3334
|
+
if (this._authState.step !== "idle") {
|
|
3335
|
+
await this._clearSession();
|
|
3336
|
+
}
|
|
3350
3337
|
}
|
|
3351
3338
|
}
|
|
3352
3339
|
/**
|
|
@@ -3393,8 +3380,11 @@ var PollarClient = class {
|
|
|
3393
3380
|
user: session.user,
|
|
3394
3381
|
// The wire response still carries the legacy `publicKey` alias (kept for
|
|
3395
3382
|
// older SDKs); the persisted session standardizes on `address` only.
|
|
3383
|
+
// The wire also still emits the legacy type `'custodial'` (unchanged for
|
|
3384
|
+
// SDKs ≤0.8.x); we remap it to `'internal'` here so the SDK surface and
|
|
3385
|
+
// persisted session speak one vocabulary while the wire stays compatible.
|
|
3396
3386
|
wallet: {
|
|
3397
|
-
type: w.type,
|
|
3387
|
+
type: w.type === "custodial" ? "internal" : w.type,
|
|
3398
3388
|
address: w.address ?? w.publicKey ?? null,
|
|
3399
3389
|
...w.existsOnStellar !== void 0 ? { existsOnStellar: w.existsOnStellar } : {},
|
|
3400
3390
|
...w.createdAt !== void 0 ? { createdAt: w.createdAt } : {},
|