@ghostlytools/sdk 1.5.1 → 1.5.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.
Files changed (32) hide show
  1. package/dist/core.js +2 -2
  2. package/dist/{fakes-CD1PMHc7.js → fakes-CZXQp6lN.js} +2 -2
  3. package/dist/{fakes-CD1PMHc7.js.map → fakes-CZXQp6lN.js.map} +1 -1
  4. package/dist/fakes.js +1 -1
  5. package/dist/index.js +2 -2
  6. package/dist/{keet-identity-key-DbgcBlKV.js → keet-identity-key-rtBRcqeE.js} +2 -2
  7. package/dist/{keet-identity-key-DbgcBlKV.js.map → keet-identity-key-rtBRcqeE.js.map} +1 -1
  8. package/dist/{src-DmirvhXS.js → src-Cri2xrHC.js} +518 -123
  9. package/dist/src-Cri2xrHC.js.map +1 -0
  10. package/dist/testing.js +3 -3
  11. package/dist/types/core/src/capsRecord.d.ts +2 -0
  12. package/dist/types/core/src/catchUp.d.ts +2 -2
  13. package/dist/types/core/src/chatFiles.d.ts +44 -17
  14. package/dist/types/core/src/ghostlink.d.ts +27 -2
  15. package/dist/types/core/src/groupCommunity.d.ts +40 -7
  16. package/dist/types/core/src/groupEntry.d.ts +4 -1
  17. package/dist/types/core/src/groupFiles.d.ts +5 -1
  18. package/dist/types/core/src/groupSession.d.ts +7 -0
  19. package/dist/types/core/src/groupSignals.d.ts +1 -0
  20. package/dist/types/core/src/invite.d.ts +7 -0
  21. package/dist/types/core/src/link.d.ts +8 -1
  22. package/dist/types/core/src/pairedAppRanges.d.ts +5 -0
  23. package/dist/types/core/src/pairedSession.d.ts +2 -0
  24. package/dist/types/core/src/relay.d.ts +5 -1
  25. package/dist/types/core/src/storeForward.d.ts +3 -1
  26. package/dist/types/core/src/text.d.ts +7 -0
  27. package/dist/types/core/src/transport.d.ts +7 -0
  28. package/dist/types/core/src/transportSwitch.d.ts +7 -0
  29. package/dist/{verify-CwAcEmuz.js → verify-BEKZfwjk.js} +2 -2
  30. package/dist/{verify-CwAcEmuz.js.map → verify-BEKZfwjk.js.map} +1 -1
  31. package/package.json +1 -1
  32. package/dist/src-DmirvhXS.js.map +0 -1
package/dist/testing.js CHANGED
@@ -1,7 +1,7 @@
1
- import { CC as createIdentity, Iu as IDENTITY_MAX_EVIDENCE, Ju as emptyIdentityLedger, Ku as IdentityExchange, Oa as decodeBolt11, Zu as identityStatement, ed as newIdentityBinding, ra as isBitcoinAddress } from "./src-DmirvhXS.js";
1
+ import { $u as identityStatement, EC as createIdentity, Ju as IdentityExchange, Oa as decodeBolt11, Ru as IDENTITY_MAX_EVIDENCE, Xu as emptyIdentityLedger, nd as newIdentityBinding, ra as isBitcoinAddress } from "./src-Cri2xrHC.js";
2
2
  import { l as providerDescriptorProblems, o as isNothingSpentError } from "./types-DvtCy3WB.js";
3
- import { i as verifyIdentity, r as descriptorProblems } from "./verify-CwAcEmuz.js";
4
- import { _ as fakeAddress, a as fakeAccount, b as fakeOnchain, c as fakeKeySign, d as fakeRecord, f as fakeRecordText, g as TEST_PROVIDERS_FLAG, h as FakeOnchainProvider, i as TEST_IDENTITIES_FLAG, l as fakeKeySubject, m as FakeLightningProvider, n as FAKE_ISSUER, o as fakeAccountToken, p as testIdentitiesEnabled, r as FAKE_RECORD_HOST, s as fakeKey, t as FAKE_IDENTITY_PROVIDERS, u as fakeKeyring, v as fakeInvoice, x as testProvidersEnabled, y as fakeLightning } from "./fakes-CD1PMHc7.js";
3
+ import { i as verifyIdentity, r as descriptorProblems } from "./verify-BEKZfwjk.js";
4
+ import { _ as fakeAddress, a as fakeAccount, b as fakeOnchain, c as fakeKeySign, d as fakeRecord, f as fakeRecordText, g as TEST_PROVIDERS_FLAG, h as FakeOnchainProvider, i as TEST_IDENTITIES_FLAG, l as fakeKeySubject, m as FakeLightningProvider, n as FAKE_ISSUER, o as fakeAccountToken, p as testIdentitiesEnabled, r as FAKE_RECORD_HOST, s as fakeKey, t as FAKE_IDENTITY_PROVIDERS, u as fakeKeyring, v as fakeInvoice, x as testProvidersEnabled, y as fakeLightning } from "./fakes-CZXQp6lN.js";
5
5
  import { afterEach, describe, expect, it, vi } from "vitest";
6
6
  //#region ../browser/src/engine/paymentAdapters/providers/contractSuite.ts
7
7
  var WAIT = 1e4;
@@ -121,6 +121,8 @@ export declare class CapsKeys {
121
121
  private readonly seed;
122
122
  private readonly inviteKey;
123
123
  constructor(params: LinkParams, participationSeedB64: string);
124
+ /** The key sealed for each pinned contact: one X25519 per contact and link, not one per seal and open (agents#1087). */
125
+ private readonly pinned;
124
126
  private pinnedKey;
125
127
  private signable;
126
128
  /**
@@ -47,8 +47,8 @@ export declare class CatchUpAnswers<F> {
47
47
  constructor(hooks: CatchUpHooks<F>);
48
48
  /**
49
49
  * The first two slices go now, the rest without holding the group's other frames back. A newer answer to the same
50
- * member goes after what is left of the last, without the frames still queued there (the same objects: a store's)
51
- * nor those still on their way (`onTheirWay`); it took their place before, and left out what the member's `have`
50
+ * member goes after what is left of the last, without the frames still queued there (the same objects: a store's, or
51
+ * the same `key`) nor those still on their way (`onTheirWay`); it took their place before, and left out what the member's `have`
52
52
  * said it held: a live frame of an author raises it above that author's frames still queued, which were lost for
53
53
  * good. A frame the edge did not take ends the answer (the member asks again when its edge opens).
54
54
  */
@@ -184,6 +184,41 @@ export interface ChatFilesHost {
184
184
  */
185
185
  resend?(record: FileTransferRecord, sent: number): boolean;
186
186
  now?(): number;
187
+ /**
188
+ * The uplink this chat's files share with others that leave the device by it (`FileUplink`): a group's edges, each
189
+ * a `ChatFiles` of its own, serving one file to several members at once. Absent: the uplink is this chat's alone.
190
+ */
191
+ uplink?: FileUplink;
192
+ }
193
+ /** What a `FileUplink` asks of the `ChatFiles` that share it. */
194
+ interface UplinkMember {
195
+ /** Its files are sending: bytes in flight, or held for the window. */
196
+ sending(): boolean;
197
+ /** The shortest round trip its files saw on its own session. */
198
+ baseRtt(): number;
199
+ }
200
+ /**
201
+ * The uplink several chats' files leave the device by. Each chat paces its files by its own path (`FilePace`), down to
202
+ * a floor of `FILE_LIMITS.minWindowBytes`; on one uplink, that floor is shared out among the chats sending at once.
203
+ * Each with a floor of its own, a member serving a file to three members on a 1 Mbit/s uplink kept 192 KiB in flight,
204
+ * and everything else it sent (texts, a ring, a call's voice) waited 1-2 s behind them, up to 5.8 s (agents#1569). A
205
+ * chat whose receiver barely confirms holds only its share, never the others' bytes. Each chat also reads the queue
206
+ * against the lowest round trip of the uplink's chats, not its own alone (`lowestBase`).
207
+ */
208
+ export declare class FileUplink {
209
+ private readonly members;
210
+ join(member: UplinkMember): void;
211
+ leave(member: UplinkMember): void;
212
+ /**
213
+ * The floor of one chat's window: its share of `minWindowBytes` among the chats sending, in whole chunks, a chunk at
214
+ * least (a window sends chunks while what is in flight is under it: 21 KiB would let two go).
215
+ */
216
+ floor(): number;
217
+ /**
218
+ * The shortest round trip any chat on the uplink saw: its path with the least queue. Each chat's own counts the
219
+ * others' queue on the shared uplink as its path (428-637 ms read on a 1-10 ms path), and so never sees one.
220
+ */
221
+ lowestBase(): number;
187
222
  }
188
223
  /**
189
224
  * files/4 (WISP 501 § files/4): a chunk as one binary message of the session, in place of the base64url text of a
@@ -214,15 +249,15 @@ export declare class ChatFiles {
214
249
  private readonly held;
215
250
  private attached;
216
251
  private peerRoomValue;
217
- /** Bytes the chat's files may have in flight on this session: sized by the path, from the confirms (`paced`). */
218
- private window;
219
- /** The shortest round trip of a chunk to its confirm on this session: the path without a queue. */
220
- private baseRtt;
221
- /** When a confirm last came close to `baseRtt`, or a probe measured it. */
222
- private baseAt;
223
- /** The path's own round trip is being measured: one chunk in flight from `since`, until one sent then is confirmed. */
224
- private probe?;
252
+ /** What the chat's files may have in flight, sized by the path. */
253
+ private readonly pace;
225
254
  constructor(host: ChatFilesHost);
255
+ /** The floor of this chat's window: all of `minWindowBytes`, or its share of an uplink it shares (`FileUplink`). */
256
+ private floor;
257
+ /** Its files are sending: bytes in flight, or held for the window (`FileUplink`). */
258
+ sending(): boolean;
259
+ /** The shortest round trip this chat's files saw on its session (`FileUplink.lowestBase`). */
260
+ baseRtt(): number;
226
261
  private now;
227
262
  /** Records kept from before a restart. Nothing is sent until `attach`. */
228
263
  restore(records: FileTransferRecord[]): void;
@@ -256,15 +291,6 @@ export declare class ChatFiles {
256
291
  /** Whether this file's own window lets it send more. */
257
292
  private fileMayPump;
258
293
  private shouldPump;
259
- /**
260
- * A confirm came for a chunk sent at `sentAt` with `flight` bytes in flight then: the window becomes what keeps the path
261
- * busy with no more than `FILE_LIMITS.queueMs` of queue on it (delay-based, as LEDBAT). Throughput is about
262
- * flight / rtt, so flight × (base + queueMs) / rtt: it grows while confirms come about as fast as they can, and shrinks
263
- * when they slow down because the files queue on a slow uplink, ahead of everything else the sender says there.
264
- * The base is measured again once no confirm has come close to it for `FILE_LIMITS.baseProbeMs`: with one chunk in
265
- * flight, so the queue drains first and a slow link's own queue never passes for a longer path.
266
- */
267
- private paced;
268
294
  /** Bytes this chat's files sent and have not seen confirmed. */
269
295
  private inFlight;
270
296
  /** Bytes were confirmed, or a file stopped sending: the files the chat's window held go on, before the one that freed it. */
@@ -339,3 +365,4 @@ export declare class ChatFiles {
339
365
  /** Forgets a transfer (its message was deleted): an unfinished one is cancelled on both sides first. */
340
366
  forget(direction: "in" | "out", id: string): void;
341
367
  }
368
+ export {};
@@ -125,6 +125,11 @@ export declare const ANSWERS_REFUSED_PAUSE_MS = 2000;
125
125
  */
126
126
  export declare const PAIRING_ATTEMPT_MS = 15000;
127
127
  export declare const PAIRING_RETRY_MS = 3000;
128
+ /**
129
+ * How long a first pairing that has not gone live keeps a first pairing's dials (`firstPairing`): both sides, at
130
+ * `PAIRING_RETRY_MS`. Past it, a chat that only ever ran on the DHT dials as a saved contact's does.
131
+ */
132
+ export declare const FIRST_PAIRING_PACE_MS: number;
128
133
  /** An inviter that sees the joiner without its offer waits this long for one before offering itself. */
129
134
  export declare const INVITER_DIAL_GRACE_MS = 2500;
130
135
  /**
@@ -645,6 +650,8 @@ export declare class GhostLink {
645
650
  /** `plan`: a switch both sides agreed; without one, a replacement the contact dialled (`attachReplacement`). */
646
651
  private candidate;
647
652
  private candidateEpoch;
653
+ /** The native dial a transport change has in flight, per transport (`prepareSwitch`). */
654
+ private readonly switchDials;
648
655
  /** Channels a switch replaced, closed after `SWITCH_RETIRE_MS` (or at once on disconnect). */
649
656
  private retiring;
650
657
  private rtcCandidateWaiter;
@@ -1318,6 +1325,16 @@ export declare class GhostLink {
1318
1325
  * answered again.
1319
1326
  */
1320
1327
  private dialSeenNow;
1328
+ /**
1329
+ * Still a first pairing, for its dials (`dialWait`, `awaitsContactDial`): not live yet (nor stopped for good), and
1330
+ * not on the DHT, or on it only because a native stream dial failed, within `FIRST_PAIRING_PACE_MS`. That dial was
1331
+ * the first contact between two apps that just read each other's records, and one that aborts in milliseconds (a
1332
+ * hole punch on a lossy network) dropped the pairing to a saved contact's pace, the lower key alone dialling 20 s,
1333
+ * 40 s, 80 s later: two first dials failing went live after 40 s, and not in 180 s at 15% loss (agents#1657). A
1334
+ * WebRTC offer that connected nothing keeps the saved contact's pace: the other side answers each one, and offers at
1335
+ * a pairing's pace kept it answering, never shown on the DHT.
1336
+ */
1337
+ private firstPairing;
1321
1338
  /** How long after the last automatic dial the next one may go. A first pairing tries again sooner: the contact just read the invite and is waiting. */
1322
1339
  private dialWait;
1323
1340
  /** The name this side shows, told to a paired peer directly. */
@@ -1510,6 +1527,8 @@ export declare class GhostLink {
1510
1527
  sendAppRange(task: AppRangeTask, bytes: Uint8Array, size: number): Promise<void>;
1511
1528
  /** `task`'s file cannot be read: `changed` or `gone` goes in place of its bytes (nothing once it is no longer live, but its place frees). */
1512
1529
  failAppRange(task: AppRangeTask, error: "changed" | "gone"): void;
1530
+ /** Whether `task` still waits for an answer on this session (`AppRanges.holds`): one that does not needs none. */
1531
+ holdsAppRange(task: AppRangeTask): boolean;
1513
1532
  /** An `ar-*` frame from the contact, on a session that agreed `app-ranges/1`. */
1514
1533
  private receiveAppRange;
1515
1534
  /** What the contact had open is gone (`apps/1` is no longer agreed, or this link stopped): each app hears it now. */
@@ -1657,6 +1676,8 @@ export declare class GhostLink {
1657
1676
  * answers pings is still handling what came before (a phone with a long history), not one that cannot say.
1658
1677
  */
1659
1678
  handled(): Promise<boolean | "late">;
1679
+ /** Frames the contact sent on this session that this app received and has not handled yet: 0 without a session. */
1680
+ framesWaiting(): number;
1660
1681
  /** Something came back on the session: the ping's wait is over. */
1661
1682
  private heardFromPeer;
1662
1683
  /**
@@ -1708,8 +1729,12 @@ export declare class GhostLink {
1708
1729
  depart(options?: {
1709
1730
  quitting?: boolean;
1710
1731
  }): void;
1711
- /** A link made just now for a peer that is about to show up (a group's entry session): look fast for a while. */
1712
- expectPeer(): void;
1732
+ /**
1733
+ * A link made just now for a peer that is about to show up (a group's entry session): look fast for a while.
1734
+ * `awaited`: nothing reaches the peer until this link reads it (the edge to a member just let in): its reads go on the
1735
+ * relays' floor meanwhile (`LinkSession.expectPeer`).
1736
+ */
1737
+ expectPeer(awaited?: boolean): void;
1713
1738
  /** The peer's packet is at hand without a relay (a member of the group carried it, `CarriedTransport`): read it now. */
1714
1739
  look(): void;
1715
1740
  /**
@@ -89,7 +89,7 @@ export declare function encodeCommunityLink(link: {
89
89
  g: string;
90
90
  host: string;
91
91
  }): string;
92
- /** A pasted link, a `/join/…` path or the bare code; null when it is not a community group's link. */
92
+ /** A pasted link, a `/join/…` path or the bare code (or one in words: `unwrapPasted`); null when it is not a community group's link. */
93
93
  export declare function decodeCommunityLink(input: string): {
94
94
  g: string;
95
95
  host: string;
@@ -431,6 +431,11 @@ export interface CommunitySessionHooks {
431
431
  * the answer asks again. Absent: an answer goes all at once, as before 2026-10-07.
432
432
  */
433
433
  handled?(to: string): Promise<CatchUpHandled>;
434
+ /**
435
+ * Whether message `id` was deleted for everyone (WISP 400 § Delete for everyone), by its author or here: a frame of it
436
+ * that comes (a catch-up, a hub passing it on) is not taken, kept or passed on. Absent: none is.
437
+ */
438
+ removed?(id: string): boolean;
434
439
  }
435
440
  export declare const communityMessageId: (sender: string, epoch: number, h: string, seq: number) => string;
436
441
  /**
@@ -455,8 +460,11 @@ export declare class CommunitySession {
455
460
  private known;
456
461
  /** Commit hash → roster after it, for the window of the main branch and the side commits. */
457
462
  private rosters;
458
- /** Commit hash → roster after it, for a few main-branch commits older than the window that `couldRead` was asked about. */
459
- private pastRosters;
463
+ /**
464
+ * Who was in the roster after each main-branch commit, from one replay of the branch: key → the places where it came in
465
+ * and went out, in turn (an open last span while it is in). `through` commits are counted, the last one `top`.
466
+ */
467
+ private spans;
460
468
  private mainIndex;
461
469
  private pendingCommits;
462
470
  private pendingSecrets;
@@ -500,7 +508,12 @@ export declare class CommunitySession {
500
508
  get name(): string;
501
509
  get myKey(): string;
502
510
  get top(): CommunityCommit;
511
+ /**
512
+ * The top commit's hash, kept for the commit it was taken from: a view reads it for each member (its roster, what
513
+ * each member's lines are missing), and hashing it every time cost tens of milliseconds per state in big communities.
514
+ */
503
515
  get topHash(): string;
516
+ private topHashOf;
504
517
  get epoch(): number;
505
518
  get roster(): Roster;
506
519
  get admin(): string | undefined;
@@ -521,8 +534,11 @@ export declare class CommunitySession {
521
534
  * for, and of the roster now. A holder serves a group file only to such a member (WISP 503 § Asking).
522
535
  */
523
536
  couldRead(key: string, messageId: string): boolean;
524
- /** The roster after an old commit of the main branch, replayed and kept apart from the window's (a few, the latest asked). */
525
- private pastRoster;
537
+ /**
538
+ * Whether `key` was in the roster after the main branch's commit `i`. The branch is replayed once, as `rebuild` does (its
539
+ * leaves were checked when they were taken), and only further as it grows: again from the start only once it changed.
540
+ */
541
+ private wasInAt;
526
542
  /** Someone the chain took out (removed or left) and who is not back in. */
527
543
  wasRemoved(key: string): boolean;
528
544
  /** When the chain took them out (the commit's time, by its signer's clock), if it did and they are not back in. */
@@ -679,8 +695,8 @@ export declare class CommunitySession {
679
695
  }>;
680
696
  /**
681
697
  * An application frame that says the group's state (`CommunitySessionHooks.lasting`) in place of the one of its
682
- * kind kept now, unless that one is newer (by the author's time, then the frame's identity, so every member keeps
683
- * the same one).
698
+ * kind kept now, unless that one is newer (by the author's time, then its epoch, so one said again under a newer
699
+ * commit takes the first's place, then the frame's identity, so every member keeps the same one).
684
700
  */
685
701
  private keepLasting;
686
702
  /**
@@ -719,6 +735,14 @@ export declare class CommunitySession {
719
735
  * first member I reach may be one let in since, who cannot read it but can carry it (`receiveSync`).
720
736
  */
721
737
  private say;
738
+ /**
739
+ * Message `id` was deleted for everyone (WISP 400 § Delete for everyone), by its author or here: its frame goes from
740
+ * the store, so no catch-up hands it to a member who was away (they get the removal, which stays). A frame said again
741
+ * (`reseal`) carries the first one's place inside: its author's are opened to tell.
742
+ */
743
+ forget(id: string): void;
744
+ /** The id of the message a stored frame is, by its first place when it was said again (and I can open it). */
745
+ private storedId;
722
746
  private keep;
723
747
  /**
724
748
  * My frames sealed under a commit I took for the newest while I was behind (no edge was up, and others were let in
@@ -730,6 +754,15 @@ export declare class CommunitySession {
730
754
  */
731
755
  reseal(): Promise<void>;
732
756
  private resealBehind;
757
+ /**
758
+ * My lasting frames (`keepLasting`), said again under the current commit once theirs is half the window behind: past
759
+ * the window no member finds that commit or holds its secret, and a member back from away after more commits than
760
+ * that was never handed the group's state. With the same content and time and `o` naming the first, as
761
+ * `resealBehind` says one, so it stays one message, and in the place of the one kept, everywhere.
762
+ */
763
+ private renewLasting;
764
+ /** Whether a lasting frame kept here is `f`'s author's, said at its time, and is the message `id` (the first's, said again). */
765
+ private keepsLasting;
733
766
  /** The message a frame of mine is: the first one's id for a frame said again (`resealBehind`), else its own. */
734
767
  messageIdOf(f: {
735
768
  s: string;
@@ -40,7 +40,10 @@ export interface Knock {
40
40
  export declare function encodeGroupEntryLink(link: GroupEntryLink): string;
41
41
  /** Where the link opens the web app: its join route. */
42
42
  export declare function groupEntryUrl(origin: string, link: GroupEntryLink): string;
43
- /** A pasted link, a `/join/…` path or the bare code; null when it is none of them. */
43
+ /**
44
+ * A pasted link, a `/join/…` path or the bare code; null when it is none of them. Copied with the words around it
45
+ * ("Join our group: <https://…/join/group1/…>."), it is read as the token in it (`unwrapPasted`).
46
+ */
44
47
  export declare function decodeGroupEntryLink(input: string): GroupEntryLink | null;
45
48
  /** The Pkarr identity every holder of the link can publish knocks under. */
46
49
  export declare function knockIdentity(link: GroupEntryLink): Identity;
@@ -87,7 +87,11 @@ export declare const GROUP_VERSION_FILES = 6;
87
87
  export declare const GROUP_WANT_FRAME = "group-want";
88
88
  export declare const GROUP_WANT_NO_FRAME = "group-want-no";
89
89
  export declare const GROUP_HAVE_FRAME = "group-have";
90
- export type GroupWantRefusal = "gone" | "busy" | "refused";
90
+ /**
91
+ * Why a holder does not serve a file (`group-want-no`). `day`: it served its day's bytes already
92
+ * (`serveBytesPerDay`), so asking it again soon is no use; an app from before reads it as `busy`.
93
+ */
94
+ export type GroupWantRefusal = "gone" | "busy" | "refused" | "day";
91
95
  export declare const isGroupMessageId: (value: unknown) => value is string;
92
96
  /** A `group-want` of group `groupId`: the message whose file is asked for, or null. */
93
97
  export declare function readGroupWant(value: unknown, groupId: string): {
@@ -370,6 +370,11 @@ export interface GroupSessionHooks {
370
370
  * here, and the leave is passed on as a member passes it. Absent: yes.
371
371
  */
372
372
  adminTurn?(): Promise<boolean>;
373
+ /**
374
+ * Whether message `id` was deleted for everyone (WISP 400 § Delete for everyone), by its author or here: its frame is
375
+ * no longer handed to anyone (a catch-up, a member handing it on, a frame said again). Absent: none is.
376
+ */
377
+ removed?(id: string): boolean;
373
378
  }
374
379
  export declare const groupMessageId: (sender: string, epoch: number, seq: number) => string;
375
380
  /**
@@ -796,6 +801,8 @@ export declare class GroupSession {
796
801
  /** My own messages a member's sync says it lacks, from my bounded log, for the epochs it was a member of. */
797
802
  private handOwn;
798
803
  private ownLacked;
804
+ /** A frame of a message deleted for everyone (`hooks.removed`): handed to nobody, its removal is what they get. */
805
+ private isRemoved;
799
806
  /** Sets (or, with null, removes) the group's picture: only the admin, signed under the current commit. */
800
807
  setPicture(picture: string | null, now?: number): Promise<void>;
801
808
  /** Renames the group: only the admin, signed under the current commit, beside the picture and the hubs. */
@@ -129,6 +129,7 @@ export declare class CarriedTransport implements PkarrTransport {
129
129
  readonly subscribe?: PkarrTransport["subscribe"];
130
130
  readonly networkChanged?: PkarrTransport["networkChanged"];
131
131
  readonly configure?: PkarrTransport["configure"];
132
+ readonly publishHeld?: PkarrTransport["publishHeld"];
132
133
  constructor(inner: PkarrTransport, myKey: string, peerKey: string, hooks: CarriedHooks);
133
134
  describe(): {
134
135
  protocol: string;
@@ -76,6 +76,13 @@ export declare function inviteQrSegments(code: string, origin?: string): string[
76
76
  * the older slash forms. A refused code is never retried as another format.
77
77
  */
78
78
  export declare function readInviteCode(input: string): InviteReading;
79
+ /** `reading` of `input`, or the reading of the token in it (`unwrapPasted`) when that reads or says more. */
80
+ export declare function pastedAgain<T extends {
81
+ ok: true;
82
+ } | {
83
+ ok: false;
84
+ reason: string;
85
+ }>(input: string, reading: T, read: (input: string) => T): T;
79
86
  /** The parameters of an invite, or null when it is refused (`readInviteCode` says why). */
80
87
  export declare function decodeInviteCode(input: string): LinkParams | null;
81
88
  /** Creates both ends of a link: keep `mine`, hand `invite` to the peer. */
@@ -255,6 +255,13 @@ export declare class LinkSession {
255
255
  private fastStepsAfter;
256
256
  /** When the last `expectPeer` window ends (or ended): the pace slows down from there step by step. */
257
257
  private expectUntil;
258
+ /**
259
+ * Until when this link's reads go as a resume's (`PkarrRequestOptions.resume`: a group edge's on the relays' floor):
260
+ * the peer is due now and nothing reaches it until its packet is read (`expectPeer(true)`: the edge to a member a hub
261
+ * just let in). As plain fast reads, a hub's admissions in a row spent the budget and the newcomer's edge waited for it:
262
+ * 22-39 s before it could send, receive or leave (agents#1740). Ends once a read finds the peer's packet.
263
+ */
264
+ private awaitedUntil;
258
265
  private watchUntil;
259
266
  /** The time of the peer's packet read last when it went away (`watchPeer`): a newer one that advertises says it is back. */
260
267
  private watchFrom;
@@ -319,7 +326,7 @@ export declare class LinkSession {
319
326
  * The peer, or its offer, is due any moment: poll fast for `EXPECT_PEER_MS` (never cutting a longer fast window short),
320
327
  * then slow down step by step (`nextInterval`) rather than at once.
321
328
  */
322
- expectPeer(): void;
329
+ expectPeer(awaited?: boolean): void;
323
330
  /**
324
331
  * The contact just left a live session, and is likely coming back (an app restarting): fast for `EXPECT_PEER_MS`,
325
332
  * then the active pace until `WATCH_PEER_MS` passed, whatever the chat's pace would be.
@@ -173,6 +173,11 @@ export declare class AppRanges {
173
173
  fail(task: AppRangeTask, error: "changed" | "gone"): void;
174
174
  /** The session stopped working on `task` without an answer (it is no longer live, or the channel went): its place frees, nothing is sent. */
175
175
  release(task: AppRangeTask): void;
176
+ /**
177
+ * Whether `task` is still this session's: serving, or cancelled and draining until it is settled. False once it was
178
+ * settled, or its app closed or the session ended, which free its place: an answer to it sends and frees nothing.
179
+ */
180
+ holds(task: AppRangeTask): boolean;
176
181
  /** Reads `length` bytes at `offset` of what the contact's `app` serves as `serve`: the bytes (fewer at the end) and the file's size. */
177
182
  read(app: string, serve: string, offset: number, length: number): Promise<{
178
183
  bytes: Uint8Array;
@@ -147,6 +147,8 @@ export declare class PairedSession {
147
147
  /** The peer said in its offer that it answers pings, so its silence from the open means it stopped. */
148
148
  get peerAnswersPings(): boolean;
149
149
  get peerAllowsFallback(): boolean;
150
+ /** Frames received from the peer and not handled yet (the one being handled included). */
151
+ get waiting(): number;
150
152
  start(): void;
151
153
  private send;
152
154
  private receive;
@@ -1,7 +1,7 @@
1
1
  import type { Identity } from "./identity.js";
2
2
  import { type GhostRecord, type SignedPacket } from "./pkarr.js";
3
3
  import { type DiscoveryStatus, type RelayBreakerOptions } from "./relayBreaker.js";
4
- import { type DiscoveryChange, type PkarrRequestOptions, type PkarrTransport, type ServerTime } from "./transport.js";
4
+ import { DiscoveryBudgetError, type DiscoveryChange, type PkarrRequestOptions, type PkarrTransport, type ServerTime } from "./transport.js";
5
5
  import type { TurnConditions, TurnSourceAnswer, TurnSourcePut } from "./turnRead.js";
6
6
  /**
7
7
  * Public Pkarr relays. They are generic Pkarr infrastructure (an HTTP bridge to
@@ -374,6 +374,8 @@ export declare class RelayTransport implements PkarrTransport {
374
374
  * that did take it, readers still preferred the later-dated empty packet of another relay.
375
375
  */
376
376
  publishDated(identity: Identity, records: GhostRecord[], put: (pubKeyZ32: string, payload: Uint8Array, timestamp: bigint, conflict: (relay: string) => void) => Promise<void>, options?: PkarrRequestOptions, again?: boolean, elsewhere?: boolean): Promise<void>;
377
+ /** `PkarrTransport.publishHeld`: `publishDated`'s check before signing, for a payload signed elsewhere in this process. */
378
+ publishHeld(pubKeyZ32: string, options?: PkarrRequestOptions): DiscoveryBudgetError | null;
377
379
  /**
378
380
  * How long until some relay takes a publish of this asker, and why each holds it back; null when one would now. Walks the relays as `put` does,
379
381
  * without asking any: a relay the budget holds back gets its refused `take` (the asker's write then waits first in
@@ -456,6 +458,8 @@ export declare class RelayTransport implements PkarrTransport {
456
458
  */
457
459
  private hedgeRoom;
458
460
  readAnsweredAt(pubKeyZ32: string): number | undefined;
461
+ /** The last read of this key was answered 404 (`HEDGE_MISSING_MS`): a relay takes seconds to say so. */
462
+ lastReadMissing(pubKeyZ32: string): boolean;
459
463
  readHeldBackFor(pubKeyZ32: string): number | undefined;
460
464
  private heldBackUntil;
461
465
  /** The relays answered a read of this key now; answers older than `FRESH_READ_MS` are dropped as the list grows. */
@@ -136,7 +136,9 @@ export declare class HoldKeys {
136
136
  }
137
137
  /**
138
138
  * A URL a bundle or manifest may be fetched from. The contact chose it and this device fetches it on its own, so it
139
- * is HTTPS, without a user or password, at a name or a public IPv4 address: never this machine or its network.
139
+ * is HTTPS, without a user or password, at a public name or a public IPv4 address: never this machine or its network.
140
+ * A name with no dot or under a local suffix is a local one. A public name may still resolve to a local address:
141
+ * where the host can resolve, its `fetch` refuses that too (the CLI's, packages/cli/src/runtime/holdFetch.ts).
140
142
  * `loopback` adds plain HTTP to this machine, for a test against a local server; no shipped app passes it.
141
143
  */
142
144
  export declare function isHoldUrl(value: unknown, loopback?: boolean): value is string;
@@ -18,3 +18,10 @@ export declare function sanitizeNick(nick: unknown): string | undefined;
18
18
  * from every character of a run that does not reach the end.
19
19
  */
20
20
  export declare function trimEndOf(text: string, chars: string): string;
21
+ /**
22
+ * The token in what someone copied with the words around it: an invite, a group's link or a device code from the end
23
+ * of "Join us: <https://…#ghostly1…>!", "« ghostly1… »" or "code: ghostly1…". The last word, without the quotes,
24
+ * brackets and marks before and after it. Readers try it only once the paste itself did not read, so a bare token
25
+ * reads as it always did and a token with a character lost is still refused as one.
26
+ */
27
+ export declare function unwrapPasted(text: string): string;
@@ -152,6 +152,13 @@ export interface PkarrTransport {
152
152
  * copy (`readAnsweredAt` did not move): when to read again. Undefined once a read went out, or where it cannot say.
153
153
  */
154
154
  readHeldBackFor?(pubKeyZ32: string): number | undefined;
155
+ /**
156
+ * A publish of this key with these options that nothing would take now, said before anything is signed: the wait
157
+ * (`DiscoveryBudgetError`) a put would be refused with, or null when it would go (or where the transport cannot say,
158
+ * or it also puts packets where no budget holds them, the CLI's DHT). As `publish` checks itself before signing; a
159
+ * caller that signs its own payloads (`CarriedTransport`) asks first. A wait said is a refusal noted, as a put's.
160
+ */
161
+ publishHeld?(pubKeyZ32: string, options?: PkarrRequestOptions): DiscoveryBudgetError | null;
155
162
  /**
156
163
  * Called with each time a server gave (`ServerTime`), where the transport can read one: what `ClockWatch` holds this
157
164
  * device's clock against. Returns the unsubscribe.
@@ -18,6 +18,11 @@ export interface SwitchPlan {
18
18
  */
19
19
  upgrade?: boolean;
20
20
  }
21
+ /**
22
+ * The contact's policies read per window. A choice, a retry or a session's start each say one, so a handful a minute;
23
+ * every one read may plan a move this side dials. Past that only the newest waits, read once the window has room.
24
+ */
25
+ export declare const POLICY_RECEIVE_LIMIT = 10, POLICY_RECEIVE_WINDOW_MS = 60000;
21
26
  export declare const allowedTransports: (policy: TransportPolicy) => ("iroh/1" | "hyperdht/1" | "webrtc/1")[];
22
27
  /** Runs only inside a participation-authenticated channel. Both roles may propose;
23
28
  * the lower rendezvous key coordinates a revision-checked plan, never both dials.
@@ -46,6 +51,8 @@ export declare class TransportSwitch {
46
51
  private remoteReplaces;
47
52
  /** This side chose while no session was open: the next one begins with it as a choice. */
48
53
  private apart;
54
+ private readonly policiesRead;
55
+ private policyHeld;
49
56
  constructor(options: {
50
57
  key: string;
51
58
  peerKey: string;
@@ -1,4 +1,4 @@
1
- import { qu as boundVerifiedIdentity } from "./src-DmirvhXS.js";
1
+ import { Yu as boundVerifiedIdentity } from "./src-Cri2xrHC.js";
2
2
  //#region ../browser/src/proofs/verify.ts
3
3
  var DAY = 86400;
4
4
  /**
@@ -103,4 +103,4 @@ function boundedIdentityFetch(options = { online: () => true }) {
103
103
  //#endregion
104
104
  export { verifyIdentity as i, boundedIdentityFetch as n, descriptorProblems as r, availableSigners as t };
105
105
 
106
- //# sourceMappingURL=verify-CwAcEmuz.js.map
106
+ //# sourceMappingURL=verify-BEKZfwjk.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"verify-CwAcEmuz.js","names":[],"sources":["../../browser/src/proofs/verify.ts"],"sourcesContent":["import { boundVerifiedIdentity, IDENTITY_MAX_EVIDENCE, IDENTITY_MAX_VALIDITY, type IdentityStatement, type VerifiedIdentity } from \"@ghostly/core\";\nimport type { IdentityFetch, IdentityProofProvider, IdentitySigner, VerifyContext } from \"./contract\";\n\nconst DAY = 86_400;\n\n/**\n * The checks every proof goes through, whatever its provider: known provider, validity within the\n * provider's limit, bounded evidence, strict parsing, the provider's own check, and the category rule\n * (a self-custodied proof proves exactly the subject it names; an attested one says who attests it).\n * The engine verifies a contact's proof, and the person's own proof before saving it, only through this.\n */\nexport async function verifyIdentity(providers: readonly IdentityProofProvider[], statement: IdentityStatement, evidence: unknown, ctx: VerifyContext): Promise<VerifiedIdentity> {\n const { binding } = statement;\n const provider = providers.find(p => p.id === binding.provider);\n if (!provider) throw new Error(\"This app cannot verify this kind of identity\");\n if (binding.expiresAt - binding.issuedAt > Math.min(provider.validity.maxDays * DAY, IDENTITY_MAX_VALIDITY)) throw new Error(\"The proof lasts longer than this kind of identity allows\");\n if (JSON.stringify(evidence ?? null).length > IDENTITY_MAX_EVIDENCE) throw new Error(\"Evidence too large\");\n const parsed = provider.parseEvidence(evidence);\n const verified = boundVerifiedIdentity(await provider.verify(statement, parsed, ctx));\n if (provider.category === \"self-custodied\" && verified.subject !== binding.subject) throw new Error(\"The evidence is for another identity\");\n if (provider.category === \"provider-attested\" && !verified.attester) throw new Error(\"The evidence does not say who attests it\");\n return verified;\n}\n\n/** Problems with a provider's descriptor, empty when it is well-formed. The registry and the contract suite use it. */\nexport function descriptorProblems(p: IdentityProofProvider): string[] {\n const problems: string[] = [];\n if (!/^[a-z][a-z0-9-]{0,31}$/.test(p.id)) problems.push(\"id must match ^[a-z][a-z0-9-]{0,31}$\");\n if (!p.label?.trim()) problems.push(\"label is empty\");\n if (!p.description?.trim()) problems.push(\"description is empty\");\n if (!p.privacy?.trim()) problems.push(\"privacy is empty: say what verify contacts\");\n if (p.category !== \"self-custodied\" && p.category !== \"provider-attested\") problems.push(\"category is unknown\");\n if (!p.platforms.length) problems.push(\"no platforms\");\n const { defaultDays, maxDays } = p.validity;\n if (!(Number.isInteger(defaultDays) && Number.isInteger(maxDays) && defaultDays >= 1 && defaultDays <= maxDays && maxDays * DAY <= IDENTITY_MAX_VALIDITY)) problems.push(\"validity must be whole days, 1 ≤ default ≤ max ≤ 400\");\n if (p.recheck && !(Number.isInteger(p.recheck.afterSeconds) && p.recheck.afterSeconds >= 60)) problems.push(\"recheck.afterSeconds must be at least 60\");\n if (!p.signers.length) problems.push(\"no signers\");\n const ids = p.signers.map(s => s.id);\n if (new Set(ids).size !== ids.length) problems.push(\"signer ids are not unique\");\n for (const s of p.signers as readonly IdentitySigner<unknown>[]) {\n if (![\"in-app\", \"external-tool\", \"redirect\", \"publish\"].includes(s.kind)) problems.push(`signer ${s.id} has an unknown kind`);\n if (s.kind === \"in-app\" && typeof s.run !== \"function\") problems.push(`signer ${s.id} has no run()`);\n if (s.kind === \"external-tool\" && (typeof s.instructions !== \"function\" || typeof s.parse !== \"function\")) problems.push(`signer ${s.id} needs instructions() and parse()`);\n if (s.kind === \"redirect\" && typeof s.start !== \"function\") problems.push(`signer ${s.id} has no start()`);\n if (s.kind === \"publish\" && (typeof s.instructions !== \"function\" || typeof s.evidence !== \"function\")) problems.push(`signer ${s.id} needs instructions() and evidence()`);\n }\n return problems;\n}\n\n/** Signers of a provider that run on this platform and are available in this window. */\nexport function availableSigners<E>(p: IdentityProofProvider<E>, platform: IdentityProofProvider[\"platforms\"][number]): IdentitySigner<E>[] {\n return p.signers.filter(s => (s.platforms ?? p.platforms).includes(platform) && (s.available?.() ?? true));\n}\n\n/**\n * The engine's `ctx.fetch`: HTTPS GET only, no credentials or referrer, a time-out, a size cap,\n * redirects refused unless asked for.\n * `online` false refuses everything (the person turned the network off).\n */\nexport function boundedIdentityFetch(options: { online: () => boolean; timeoutMs?: number; fetcher?: typeof fetch } = { online: () => true }): IdentityFetch {\n return async (url, { headers, maxBytes = 64 * 1024, signal, redirect = \"error\" } = {}) => {\n if (!options.online()) throw new Error(\"Offline: this identity cannot be checked now\");\n const target = new URL(url);\n if (target.protocol !== \"https:\" || target.username || target.password) throw new Error(\"Identity checks use HTTPS only\");\n const timeout = AbortSignal.timeout(options.timeoutMs ?? 10_000);\n const response = await (options.fetcher ?? fetch)(target.href, {\n headers, signal: signal ? AbortSignal.any([signal, timeout]) : timeout,\n credentials: \"omit\", referrerPolicy: \"no-referrer\", cache: \"no-store\", redirect,\n });\n if (Number(response.headers.get(\"content-length\")) > maxBytes) throw new Error(\"Identity check response too large\");\n const reader = response.body?.getReader();\n const parts: Uint8Array[] = [];\n let length = 0;\n if (reader) {\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n length += value.length;\n if (length > maxBytes) throw new Error(\"Identity check response too large\");\n parts.push(value);\n }\n } finally { await reader.cancel().catch(() => {}); }\n }\n const bytes = new Uint8Array(length);\n let offset = 0;\n for (const part of parts) { bytes.set(part, offset); offset += part.length; }\n return { status: response.status, contentType: response.headers.get(\"content-type\") ?? \"\", text: new TextDecoder().decode(bytes), bytes };\n };\n}\n"],"mappings":";;AAGA,IAAM,MAAM;;;;;;;AAQZ,eAAsB,eAAe,WAA6C,WAA8B,UAAmB,KAA+C;CAChL,MAAM,EAAE,YAAY;CACpB,MAAM,WAAW,UAAU,MAAK,MAAK,EAAE,OAAO,QAAQ,QAAQ;CAC9D,IAAI,CAAC,UAAU,MAAM,IAAI,MAAM,8CAA8C;CAC7E,IAAI,QAAQ,YAAY,QAAQ,WAAW,KAAK,IAAI,SAAS,SAAS,UAAU,KAAA,MAA0B,GAAG,MAAM,IAAI,MAAM,0DAA0D;CACvL,IAAI,KAAK,UAAU,YAAY,IAAI,CAAC,CAAC,SAAA,OAAgC,MAAM,IAAI,MAAM,oBAAoB;CACzG,MAAM,SAAS,SAAS,cAAc,QAAQ;CAC9C,MAAM,WAAW,sBAAsB,MAAM,SAAS,OAAO,WAAW,QAAQ,GAAG,CAAC;CACpF,IAAI,SAAS,aAAa,oBAAoB,SAAS,YAAY,QAAQ,SAAS,MAAM,IAAI,MAAM,sCAAsC;CAC1I,IAAI,SAAS,aAAa,uBAAuB,CAAC,SAAS,UAAU,MAAM,IAAI,MAAM,0CAA0C;CAC/H,OAAO;AACT;;AAGA,SAAgB,mBAAmB,GAAoC;CACrE,MAAM,WAAqB,CAAC;CAC5B,IAAI,CAAC,yBAAyB,KAAK,EAAE,EAAE,GAAG,SAAS,KAAK,sCAAsC;CAC9F,IAAI,CAAC,EAAE,OAAO,KAAK,GAAG,SAAS,KAAK,gBAAgB;CACpD,IAAI,CAAC,EAAE,aAAa,KAAK,GAAG,SAAS,KAAK,sBAAsB;CAChE,IAAI,CAAC,EAAE,SAAS,KAAK,GAAG,SAAS,KAAK,4CAA4C;CAClF,IAAI,EAAE,aAAa,oBAAoB,EAAE,aAAa,qBAAqB,SAAS,KAAK,qBAAq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AAE,QAAQ,SAAS;GAAQ,aAAa,SAAS,QAAQ,IAAI,cAAc,KAAK;GAAI,MAAM,IAAI,YAAY,CAAC,CAAC,OAAO,KAAK;GAAG;EAAM;CAC1I;AACF"}
1
+ {"version":3,"file":"verify-BEKZfwjk.js","names":[],"sources":["../../browser/src/proofs/verify.ts"],"sourcesContent":["import { boundVerifiedIdentity, IDENTITY_MAX_EVIDENCE, IDENTITY_MAX_VALIDITY, type IdentityStatement, type VerifiedIdentity } from \"@ghostly/core\";\nimport type { IdentityFetch, IdentityProofProvider, IdentitySigner, VerifyContext } from \"./contract\";\n\nconst DAY = 86_400;\n\n/**\n * The checks every proof goes through, whatever its provider: known provider, validity within the\n * provider's limit, bounded evidence, strict parsing, the provider's own check, and the category rule\n * (a self-custodied proof proves exactly the subject it names; an attested one says who attests it).\n * The engine verifies a contact's proof, and the person's own proof before saving it, only through this.\n */\nexport async function verifyIdentity(providers: readonly IdentityProofProvider[], statement: IdentityStatement, evidence: unknown, ctx: VerifyContext): Promise<VerifiedIdentity> {\n const { binding } = statement;\n const provider = providers.find(p => p.id === binding.provider);\n if (!provider) throw new Error(\"This app cannot verify this kind of identity\");\n if (binding.expiresAt - binding.issuedAt > Math.min(provider.validity.maxDays * DAY, IDENTITY_MAX_VALIDITY)) throw new Error(\"The proof lasts longer than this kind of identity allows\");\n if (JSON.stringify(evidence ?? null).length > IDENTITY_MAX_EVIDENCE) throw new Error(\"Evidence too large\");\n const parsed = provider.parseEvidence(evidence);\n const verified = boundVerifiedIdentity(await provider.verify(statement, parsed, ctx));\n if (provider.category === \"self-custodied\" && verified.subject !== binding.subject) throw new Error(\"The evidence is for another identity\");\n if (provider.category === \"provider-attested\" && !verified.attester) throw new Error(\"The evidence does not say who attests it\");\n return verified;\n}\n\n/** Problems with a provider's descriptor, empty when it is well-formed. The registry and the contract suite use it. */\nexport function descriptorProblems(p: IdentityProofProvider): string[] {\n const problems: string[] = [];\n if (!/^[a-z][a-z0-9-]{0,31}$/.test(p.id)) problems.push(\"id must match ^[a-z][a-z0-9-]{0,31}$\");\n if (!p.label?.trim()) problems.push(\"label is empty\");\n if (!p.description?.trim()) problems.push(\"description is empty\");\n if (!p.privacy?.trim()) problems.push(\"privacy is empty: say what verify contacts\");\n if (p.category !== \"self-custodied\" && p.category !== \"provider-attested\") problems.push(\"category is unknown\");\n if (!p.platforms.length) problems.push(\"no platforms\");\n const { defaultDays, maxDays } = p.validity;\n if (!(Number.isInteger(defaultDays) && Number.isInteger(maxDays) && defaultDays >= 1 && defaultDays <= maxDays && maxDays * DAY <= IDENTITY_MAX_VALIDITY)) problems.push(\"validity must be whole days, 1 ≤ default ≤ max ≤ 400\");\n if (p.recheck && !(Number.isInteger(p.recheck.afterSeconds) && p.recheck.afterSeconds >= 60)) problems.push(\"recheck.afterSeconds must be at least 60\");\n if (!p.signers.length) problems.push(\"no signers\");\n const ids = p.signers.map(s => s.id);\n if (new Set(ids).size !== ids.length) problems.push(\"signer ids are not unique\");\n for (const s of p.signers as readonly IdentitySigner<unknown>[]) {\n if (![\"in-app\", \"external-tool\", \"redirect\", \"publish\"].includes(s.kind)) problems.push(`signer ${s.id} has an unknown kind`);\n if (s.kind === \"in-app\" && typeof s.run !== \"function\") problems.push(`signer ${s.id} has no run()`);\n if (s.kind === \"external-tool\" && (typeof s.instructions !== \"function\" || typeof s.parse !== \"function\")) problems.push(`signer ${s.id} needs instructions() and parse()`);\n if (s.kind === \"redirect\" && typeof s.start !== \"function\") problems.push(`signer ${s.id} has no start()`);\n if (s.kind === \"publish\" && (typeof s.instructions !== \"function\" || typeof s.evidence !== \"function\")) problems.push(`signer ${s.id} needs instructions() and evidence()`);\n }\n return problems;\n}\n\n/** Signers of a provider that run on this platform and are available in this window. */\nexport function availableSigners<E>(p: IdentityProofProvider<E>, platform: IdentityProofProvider[\"platforms\"][number]): IdentitySigner<E>[] {\n return p.signers.filter(s => (s.platforms ?? p.platforms).includes(platform) && (s.available?.() ?? true));\n}\n\n/**\n * The engine's `ctx.fetch`: HTTPS GET only, no credentials or referrer, a time-out, a size cap,\n * redirects refused unless asked for.\n * `online` false refuses everything (the person turned the network off).\n */\nexport function boundedIdentityFetch(options: { online: () => boolean; timeoutMs?: number; fetcher?: typeof fetch } = { online: () => true }): IdentityFetch {\n return async (url, { headers, maxBytes = 64 * 1024, signal, redirect = \"error\" } = {}) => {\n if (!options.online()) throw new Error(\"Offline: this identity cannot be checked now\");\n const target = new URL(url);\n if (target.protocol !== \"https:\" || target.username || target.password) throw new Error(\"Identity checks use HTTPS only\");\n const timeout = AbortSignal.timeout(options.timeoutMs ?? 10_000);\n const response = await (options.fetcher ?? fetch)(target.href, {\n headers, signal: signal ? AbortSignal.any([signal, timeout]) : timeout,\n credentials: \"omit\", referrerPolicy: \"no-referrer\", cache: \"no-store\", redirect,\n });\n if (Number(response.headers.get(\"content-length\")) > maxBytes) throw new Error(\"Identity check response too large\");\n const reader = response.body?.getReader();\n const parts: Uint8Array[] = [];\n let length = 0;\n if (reader) {\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n length += value.length;\n if (length > maxBytes) throw new Error(\"Identity check response too large\");\n parts.push(value);\n }\n } finally { await reader.cancel().catch(() => {}); }\n }\n const bytes = new Uint8Array(length);\n let offset = 0;\n for (const part of parts) { bytes.set(part, offset); offset += part.length; }\n return { status: response.status, contentType: response.headers.get(\"content-type\") ?? \"\", text: new TextDecoder().decode(bytes), bytes };\n };\n}\n"],"mappings":";;AAGA,IAAM,MAAM;;;;;;;AAQZ,eAAsB,eAAe,WAA6C,WAA8B,UAAmB,KAA+C;CAChL,MAAM,EAAE,YAAY;CACpB,MAAM,WAAW,UAAU,MAAK,MAAK,EAAE,OAAO,QAAQ,QAAQ;CAC9D,IAAI,CAAC,UAAU,MAAM,IAAI,MAAM,8CAA8C;CAC7E,IAAI,QAAQ,YAAY,QAAQ,WAAW,KAAK,IAAI,SAAS,SAAS,UAAU,KAAA,MAA0B,GAAG,MAAM,IAAI,MAAM,0DAA0D;CACv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,QAAQ,WAAW,MAAA,CAAO,OAAO,MAAM;GAC7D;GAAS,QAAQ,SAAS,YAAY,IAAI,CAAC,QAAQ,OAAO,CAAC,IAAI;GAC/D,aAAa;GAAQ,gBAAgB;GAAe,OAAO;GAAY;EACzE,CAAC;EACD,IAAI,OAAO,SAAS,QAAQ,IAAI,gBAAgB,CAAC,IAAI,UAAU,MAAM,IAAI,MAAM,mCAAmC;EAClH,MAAM,SAAS,SAAS,MAAM,UAAU;EACxC,MAAM,QAAsB,CAAC;EAC7B,IAAI,SAAS;EACb,IAAI,QACF,IAAI;GACF,SAAS;IACP,MAAM,EAAE,MAAM,UAAU,MAAM,OAAO,KAAK;IAC1C,IAAI,MAAM;IACV,UAAU,MAAM;IAChB,IAAI,SAAS,UAAU,MAAM,IAAI,MAAM,mCAAmC;IAC1E,MAAM,KAAK,KAAK;GAClB;EACF,UAAU;GAAE,MAAM,OAAO,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC;EAAG;EAErD,MAAM,QAAQ,IAAI,WAAW,MAAM;EACnC,IAAI,SAAS;EACb,KAAK,MAAM,QAAQ,OAAO;GAAE,MAAM,IAAI,MAAM,MAAM;GAAG,UAAU,KAAK;EAAQ;EAC5E,OAAO;GAAE,QAAQ,SAAS;GAAQ,aAAa,SAAS,QAAQ,IAAI,cAAc,KAAK;GAAI,MAAM,IAAI,YAAY,CAAC,CAAC,OAAO,KAAK;GAAG;EAAM;CAC1I;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ghostlytools/sdk",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
4
4
  "type": "module",
5
5
  "description": "Build a wallet source, an identity proof, a mini-app or a client for Ghostly without reading its internals: the adapter contracts, their fakes and contract test suites, the plugin registry, and the mini-app API types (Apps run in Ghostly 1.2 and later).",
6
6
  "license": "MIT",