@ghostlytools/sdk 1.13.2 → 1.13.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.
@@ -1767,6 +1767,7 @@ var RelayTransport = class {
1767
1767
  }
1768
1768
  /** What `put` refuses a request to this relay with before its budget is asked; null when it gets that far. */
1769
1769
  refusal(relay, probe) {
1770
+ if (!this.relays.includes(relay)) return new RelayLeftAloneError(`${relay} is no longer a listed relay`);
1770
1771
  if (!probe && this.networkCoolingDown(relay, "PUT")) return new RelayNoAnswerError(`${relay} did not answer a moment ago; retry shortly`, false);
1771
1772
  const limited = this.rateLimitedFor(relay);
1772
1773
  if (limited > 0) return new DiscoveryBudgetError(limited, "Discovery relay is cooling down after a 429; retry shortly");
@@ -1779,7 +1780,7 @@ var RelayTransport = class {
1779
1780
  }
1780
1781
  /** One relay's packet for a key, read now: its time, kept for `nextTimestamp`. Null when it has none or does not answer. */
1781
1782
  async heldAt(relay, pubKeyZ32, who) {
1782
- if (!this.take(relay, who, pubKeyZ32)) return null;
1783
+ if (!this.relays.includes(relay) || !this.take(relay, who, pubKeyZ32)) return null;
1783
1784
  try {
1784
1785
  let payload;
1785
1786
  if (!(await this.request(`${relay}/${pubKeyZ32}`, { method: "GET" }, async (r, signal) => {
@@ -1890,8 +1891,9 @@ var RelayTransport = class {
1890
1891
  let first;
1891
1892
  const edgeSignal = isGroupSignal(asker(options, true));
1892
1893
  const failed = /* @__PURE__ */ new Set();
1893
- const nowhere = this.relays.map(() => false);
1894
- const puts = this.relays.map(async (relay, i) => {
1894
+ const relays = this.relays;
1895
+ const nowhere = relays.map(() => false);
1896
+ const puts = relays.map(async (relay, i) => {
1895
1897
  const slot = `${relay} ${pubKeyZ32}`;
1896
1898
  const previous = this.lastPut.get(slot);
1897
1899
  this.lastPut.set(slot, timestamp);
@@ -1935,7 +1937,8 @@ var RelayTransport = class {
1935
1937
  noWriteWaits();
1936
1938
  results.forEach((r, i) => {
1937
1939
  if (r.status !== "rejected") return;
1938
- if (isDiscoveryBudgetError(r.reason) || edgeSignal && failed.has(this.relays[i])) this.catchUpLater(this.relays[i], pubKeyZ32, payload, timestamp, edgeSignal ? asker(options, true) : CATCH_UP_ASKER);
1940
+ if (!this.relays.includes(relays[i])) return;
1941
+ if (isDiscoveryBudgetError(r.reason) || edgeSignal && failed.has(relays[i])) this.catchUpLater(relays[i], pubKeyZ32, payload, timestamp, edgeSignal ? asker(options, true) : CATCH_UP_ASKER);
1939
1942
  });
1940
1943
  return;
1941
1944
  }
@@ -1987,7 +1990,7 @@ var RelayTransport = class {
1987
1990
  */
1988
1991
  const next = (hedge) => {
1989
1992
  for (const relay of order) {
1990
- if (tried.has(relay)) continue;
1993
+ if (tried.has(relay) || !this.relays.includes(relay)) continue;
1991
1994
  if (relay !== probe && this.networkCoolingDown(relay, "GET")) {
1992
1995
  tried.add(relay);
1993
1996
  down = true;
@@ -3405,6 +3408,11 @@ var IdentityExchange = class IdentityExchange {
3405
3408
  requested = /* @__PURE__ */ new Set();
3406
3409
  /** The nonces of the presentations in their provider's check now. */
3407
3410
  checking = /* @__PURE__ */ new Set();
3411
+ /**
3412
+ * The nonces of the challenges sent on this connection. A presentation is signed for its session, so a challenge
3413
+ * from a closed link that is not in its check now can no longer be answered.
3414
+ */
3415
+ issued = /* @__PURE__ */ new Set();
3408
3416
  /** When the contact's presentations were checked with their provider (seconds), for `IDENTITY_MAX_CHECKS_PER_HOUR`. */
3409
3417
  checks = [];
3410
3418
  /** When this side sent its recent frames (ms), for `IDENTITY_SEND_LIMIT`. Kept across connections, as the contact's count is. */
@@ -3573,6 +3581,7 @@ var IdentityExchange = class IdentityExchange {
3573
3581
  stop() {
3574
3582
  this.requested.clear();
3575
3583
  this.peerProviders = void 0;
3584
+ this.issued.clear();
3576
3585
  this.outbox = [];
3577
3586
  this.attempts.clear();
3578
3587
  if (this.timer !== void 0) clearTimeout(this.timer);
@@ -3605,13 +3614,16 @@ var IdentityExchange = class IdentityExchange {
3605
3614
  const local = await this.options.localProof(id);
3606
3615
  if (!local) throw new Error("That identity is no longer in your profile");
3607
3616
  const { provider, subject } = local.statement.binding;
3617
+ const prior = this.shared(id);
3618
+ const held = prior && prior.status !== "withdrawn" && (prior.status !== "queued" || prior.held) ? { held: true } : {};
3608
3619
  const entry = {
3609
3620
  id,
3610
3621
  provider,
3611
3622
  subject,
3612
3623
  account: local.account ?? subject,
3613
3624
  status: "queued",
3614
- at: this.now()
3625
+ at: this.now(),
3626
+ ...held
3615
3627
  };
3616
3628
  await this.setShared(entry, {
3617
3629
  type: "shared",
@@ -3628,7 +3640,7 @@ var IdentityExchange = class IdentityExchange {
3628
3640
  let s = this.shared(id);
3629
3641
  if (!s || s.status === "withdrawn") return;
3630
3642
  this.requested.delete(id);
3631
- if (s.status === "queued") {
3643
+ if (s.status === "queued" && !s.held) {
3632
3644
  let answered;
3633
3645
  await this.options.storage.update((l) => {
3634
3646
  answered = l.shared.find((x) => x.id === id && x.status === "pending");
@@ -3851,6 +3863,11 @@ var IdentityExchange = class IdentityExchange {
3851
3863
  id
3852
3864
  };
3853
3865
  await this.options.storage.update((l) => {
3866
+ const stale = (c) => c.id === id && !this.issued.has(c.nonce) && !this.checking.has(c.nonce);
3867
+ if (l.challenges.some(stale)) l = {
3868
+ ...l,
3869
+ challenges: l.challenges.filter((c) => !stale(c))
3870
+ };
3854
3871
  if (l.challenges.filter((c) => liveAt(c, now)).length >= MAX_CHALLENGES) throw new Error("Too many identity challenges");
3855
3872
  return this.withoutExpired(this.log({
3856
3873
  ...l,
@@ -3862,6 +3879,9 @@ var IdentityExchange = class IdentityExchange {
3862
3879
  provider
3863
3880
  }), now);
3864
3881
  });
3882
+ const held = new Set(this.options.storage.read().challenges.map((c) => c.nonce));
3883
+ for (const n of this.issued) if (!held.has(n)) this.issued.delete(n);
3884
+ this.issued.add(challenge.nonce);
3865
3885
  this.send({
3866
3886
  t: "idp-challenge",
3867
3887
  id,
@@ -4130,4 +4150,4 @@ function isBitcoinAddress(address, network) {
4130
4150
  }
4131
4151
  export { DEFAULT_RELAYS as $, decodeTxtPacket as $t, identityRevocationValue as A, BREAKER_BASE_MS as At, applyIdentityEvent as B, withRequestOptions as Bt, IdentityCheckUnavailable as C, currentRelays as Ct, emptyIdentityLedger as D, setLinkTraceSink as Dt, boundVerifiedIdentity as E, relayUrlProblem as Et, receivedIdentityStatus as F, PublishFailedError as Ft, AWAITED_READS as G, createRelayPayload as Gt, ANSWER_READ_ALLOWANCE as H, PKARR_FUTURE_SKEW_MS as Ht, revokesIdentity as I, budgetRetryMs as It, BACKGROUND_WRITES_SHARE as J, openRelayPayload as Jt, BACKGROUND_REQUESTS_PER_MINUTE as K, measureRecords as Kt, signIdentityPresentation as L, heldBackError as Lt, identityStatementText as M, BREAKER_THRESHOLD as Mt, isIdentityBinding as N, RelayBreaker as Nt, identityPresentationBytes as O, traceLink as Ot, newIdentityBinding as P, DiscoveryBudgetError as Pt, CHAT_WATCH_SHARE as Q, decodeDnsAnswers as Qt, verifyIdentityPresentation as R, isDiscoveryBudgetError as Rt, IDENTITY_SUBJECT as S, WRITE_FIRST_MS as St, boundIdentityDisplay as T, readRelayBody as Tt, ANSWER_READ_FIRST_MS as U, PacketTooLargeError as Ut, lastSharedWithMe as V, MAX_DNS_PACKET_BYTES as Vt, ANSWER_READ_SPACING_MS as W, RELAY_PAYLOAD_MAX_BYTES as Wt, CHAT_RESERVE_MOST_SHARE as X, readOwnRelayPayload as Xt, CHAT_RESERVE as Y, parseRelayPayload as Yt, CHAT_RESERVE_PER_CHAT as Z, signRelayPayload as Zt, IDENTITY_REUSE_CHECK_S as _, stripHidden as _n, SLOW_DEMOTE_MS as _t, IDENTITY_CLOCK_SKEW as a, createIdentity as an, GROUP_OVER_PACE_MS as at, IDENTITY_SEND_WINDOW_MS as b, WATCH_SHARE as bt, IDENTITY_MAX_CHECKS_PER_HOUR as c, publicKeyFromZ32 as cn, HEDGE_MISSING_MS as ct, IDENTITY_MAX_RECEIVED as d, verify as dn, RELAY_REQUESTS_PER_MINUTE as dt, encodeTxtPacket as en, DEPARTED_READS as et, IDENTITY_MAX_VALIDITY as f, MAX_NICK_LENGTH as fn, REQUESTS_PER_MINUTE as ft, IDENTITY_RESEND_MS as g, sanitizeNick as gn, SIGNALING_WINDOW_MS as gt, IDENTITY_RESENDS as h, sanitizeDisplayText as hn, SIGNALING_ALLOWANCE_SHARE as ht, IDENTITY_CHECK_UNAVAILABLE as i, IDENTITY_MEMO_SIZE as in, GROUP_BURST_ONE_LINK as it, identityStatement as j, BREAKER_MAX_MS as jt, identityRefusal as k, BREAKER_ALL_DOWN_PROBE_MS as kt, IDENTITY_MAX_EVIDENCE as l, setPublicKeyFastPath as ln, HEDGE_MS as lt, IDENTITY_PROVIDER_ID as m, hasVisible as mn, RelaysFailedError as mt, isBitcoinAddress as n, IDENTITY_MEMO_IDLE_MS as nn, FRESH_READ_MS as nt, IDENTITY_FRAME_LIMIT as o, identityFromSeed as on, GROUP_RATION_WINDOW_MS as ot, IDENTITY_PROOF_CAPABILITY as p, dropLoneJoiners as pn, RelayTransport as pt, BACKGROUND_WHILE_SIGNALING as q, newerPacket as qt, IDENTITY_CHALLENGE_WINDOW as r, IDENTITY_MEMO_MAX as rn, GROUP_BURST_MS as rt, IDENTITY_FRAME_WINDOW_MS as s, identityFromSeedB64 as sn, GROUP_SIGNALING_ALLOWANCE_SHARE as st, BITCOIN_NETWORKS as t, readDnsName as tn, DOOR_FIRST_MS as tt, IDENTITY_MAX_FRAME as u, sign as un, PREVIOUS_DEFAULT_RELAYS as ut, IDENTITY_REVOCATION_LABEL as v, trimEndOf as vn, SLOW_MS as vt, IdentityExchange as w, normalizeRelayUrl as wt, IDENTITY_STATEMENT_PREFIX as x, WAY_BACK_SHARE as xt, IDENTITY_SEND_LIMIT as y, unwrapPasted as yn, TURN_SOURCE_TIMEOUT_MS as yt, IDENTITY_TIMELINE_MAX as z, publishedNowhere as zt };
4132
4152
 
4133
- //# sourceMappingURL=bitcoinAddress-BIW3tpJG.js.map
4153
+ //# sourceMappingURL=bitcoinAddress-CDYL3yPz.js.map