@ghostlytools/sdk 1.11.2 → 1.11.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.
Files changed (32) hide show
  1. package/dist/app.js +1 -1
  2. package/dist/app.js.map +1 -1
  3. package/dist/core.js +2 -2
  4. package/dist/{fakes-DCH5oJMm.js → fakes-CXeeyI4Z.js} +2 -2
  5. package/dist/{fakes-DCH5oJMm.js.map → fakes-CXeeyI4Z.js.map} +1 -1
  6. package/dist/fakes.js +1 -1
  7. package/dist/index.js +2 -2
  8. package/dist/{keet-identity-key-3EEmDkxz.js → keet-identity-key-DLXTTFZH.js} +1754 -86
  9. package/dist/keet-identity-key-DLXTTFZH.js.map +1 -0
  10. package/dist/{src-DA7T3Gvo.js → src-CqAqFhh9.js} +986 -237
  11. package/dist/src-CqAqFhh9.js.map +1 -0
  12. package/dist/testing.js +3 -3
  13. package/dist/types/core/src/appStore.d.ts +5 -0
  14. package/dist/types/core/src/communityRendezvous.d.ts +5 -2
  15. package/dist/types/core/src/datalink.d.ts +10 -0
  16. package/dist/types/core/src/frames.d.ts +18 -0
  17. package/dist/types/core/src/ghostlink.d.ts +59 -2
  18. package/dist/types/core/src/groupCommunity.d.ts +13 -3
  19. package/dist/types/core/src/groupSession.d.ts +2 -0
  20. package/dist/types/core/src/http.d.ts +26 -3
  21. package/dist/types/core/src/identity.d.ts +8 -0
  22. package/dist/types/core/src/linkPreview.d.ts +9 -2
  23. package/dist/types/core/src/miniApp.d.ts +1 -1
  24. package/dist/types/core/src/pairedAppRanges.d.ts +2 -0
  25. package/dist/types/core/src/pairedApps.d.ts +4 -2
  26. package/dist/types/core/src/relay.d.ts +10 -0
  27. package/dist/types/core/src/videoMetadata.d.ts +15 -1
  28. package/dist/{verify-DsXR5sRX.js → verify-B9s82dbd.js} +2 -2
  29. package/dist/{verify-DsXR5sRX.js.map → verify-B9s82dbd.js.map} +1 -1
  30. package/package.json +1 -1
  31. package/dist/keet-identity-key-3EEmDkxz.js.map +0 -1
  32. package/dist/src-DA7T3Gvo.js.map +0 -1
package/dist/testing.js CHANGED
@@ -1,7 +1,7 @@
1
- import { Dd as newIdentityBinding, LT as createIdentity, Ma as decodeBolt11, _d as IdentityExchange, bd as emptyIdentityLedger, od as IDENTITY_MAX_EVIDENCE, sa as isBitcoinAddress, wd as identityStatement } from "./src-DA7T3Gvo.js";
1
+ import { Md as newIdentityBinding, Pa as decodeBolt11, Sd as IdentityExchange, Td as emptyIdentityLedger, WT as createIdentity, dd as IDENTITY_MAX_EVIDENCE, kd as identityStatement, la as isBitcoinAddress } from "./src-CqAqFhh9.js";
2
2
  import { l as providerDescriptorProblems, o as isNothingSpentError } from "./types-DYLIIkU8.js";
3
- import { i as verifyIdentity, r as descriptorProblems } from "./verify-DsXR5sRX.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-DCH5oJMm.js";
3
+ import { i as verifyIdentity, r as descriptorProblems } from "./verify-B9s82dbd.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-CXeeyI4Z.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;
@@ -70,6 +70,11 @@ export interface AppFormatOptions {
70
70
  }
71
71
  /** Checks one entry of `apps`, which is also the whole of a `listing.json`. An unknown key is ignored unless `strict`. */
72
72
  export declare function checkAppListing(value: unknown, options?: AppFormatOptions): Check;
73
+ /**
74
+ * The first object key `text` writes twice in one object, as JSON.parse reads it (`"title"` is `title`), or null.
75
+ * `text` is JSON that JSON.parse already took: one pass, each string read to its closing quote.
76
+ */
77
+ export declare function repeatedJsonKey(text: string): string | null;
73
78
  /**
74
79
  * Reads a `listing.json`: JSON holding exactly one listing (written by hand in release 1.2, so not required canonical).
75
80
  * A store reads it, as a writer: strict by default, so a misspelt key is refused before the owner signs the index (the
@@ -117,8 +117,11 @@ export declare function freshHubs(hubs: Hub[], now?: number): Hub[];
117
117
  export declare function hubRank(subject: string, hubKey: string): string;
118
118
  export declare function rankHubs(subject: string, hubs: string[]): string[];
119
119
  /**
120
- * The hubs a member asks for edges: the least loaded fresh ones with room, ties broken by rank
121
- * for this member (so members spread out), at most `hubsPerMember`.
120
+ * The hubs a member asks for edges: fresh ones with room, at most `hubsPerMember`, by rendezvous hashing weighted by
121
+ * the room each has left, so the members picking at once spread over the hubs in proportion to it. The members a
122
+ * closing hub carried all pick in the same second: each took the least loaded hub, all of them the same one, which
123
+ * opened their 12 or 16 edges at once on its relays' budget and brought none up for minutes, then the next hub did the
124
+ * same, and 6 of them stepped up as hubs with nobody on them (36 members, bug hunt, 2026-11-11).
122
125
  */
123
126
  export declare function pickHubs(me: string, hubs: Hub[], now?: number, avoid?: ReadonlySet<string>): string[];
124
127
  /** Should this member be a hub? Too few fresh hubs, or all full, and room in the beacon. */
@@ -133,6 +133,8 @@ export declare class DataLink {
133
133
  private fullGather;
134
134
  /** The offer or answer out has no public candidate (as it went: the connection's description gains any that come later). */
135
135
  private sentLacksPublic;
136
+ /** Connections the gathering under way replaced for finding no candidate at all (`gathered`); 0 when none is under way. */
137
+ private gatherStalls;
136
138
  private lastSignalTs;
137
139
  /** The peer's description as this connection was given it: Chrome shows it as `remoteDescription` only once applied. */
138
140
  private remoteSdp;
@@ -208,6 +210,14 @@ export declare class DataLink {
208
210
  * candidate, a public port per STUN server, or (for the side that offered) candidates that read as reachable.
209
211
  */
210
212
  private directEvidence;
213
+ /**
214
+ * The gathering under way found no candidate on every connection but the one it waits on now (`GATHER_ATTEMPTS` - 1
215
+ * stalls): ended from outside now (another transport went live, the contact's offer took its place), it says what
216
+ * one that ran out says, `no-public`. Saying nothing held the note back on a network that blocks direct connections:
217
+ * a browser there gathers none, its chats went live over Iroh before the third stall, and only a later attempt, if
218
+ * any came, said it (direct-blocked e2e, 2026-11-13).
219
+ */
220
+ private get gatherStalled();
211
221
  /**
212
222
  * The attempt on this connection failed (it timed out, ICE failed or closed, its channel closed). An answer the
213
223
  * offerer may not have read yet is made again for the same offer while it still stands (`REANSWERS`); anything
@@ -36,6 +36,24 @@ export declare const LIMITS: {
36
36
  */
37
37
  readonly maxClientWaiting: 64;
38
38
  readonly maxClientWaitingBodyBytes: number;
39
+ /**
40
+ * Response-body bytes a client holds for one response before whatever reads it took them. Past it, a response its
41
+ * reader takes nothing of for `unreadStallMs` is reset: its reader stalled. Four times what a host keeps buffered on
42
+ * the link (`sendHighWaterMark`), so a reader that keeps up never reaches it.
43
+ */
44
+ readonly maxUnreadResponseBytes: number;
45
+ /**
46
+ * How long a reader past `maxUnreadResponseBytes` may take nothing before its response is reset. One that keeps
47
+ * reading, only slower than the link (a video playing as it arrives, a contact's app read through the web's services
48
+ * worker), is not cut: it holds up to the response's own bound.
49
+ */
50
+ readonly unreadStallMs: 2000;
51
+ /**
52
+ * Response-body bytes a client holds for all its responses before their readers took them. Past it, a response over
53
+ * `maxUnreadResponseBytes` is reset at once, its reader's pace aside: one slow reader keeps its whole response (as
54
+ * much as `maxResponseBodyBytes`), but many cannot add up (a contact's app reading each answer a chunk at a time).
55
+ */
56
+ readonly maxClientUnreadResponseBytes: number;
39
57
  readonly maxChatMessageBytes: number;
40
58
  readonly maxFileBytes: number;
41
59
  /** Files a peer may be sending us at once. */
@@ -76,6 +76,12 @@ export declare const BLOCKED_DIAL_WAIT_MS = 10000;
76
76
  * Desktop's knock 15 s in, and the Desktop dialled again only 30 s in).
77
77
  */
78
78
  export declare const UNPROVEN_AUTH_MS = 15000;
79
+ /**
80
+ * Connections dialled in that authenticate at once beside the one waiting to take over (`contend`). Whoever read the
81
+ * endpoint and dials it over and over pushes out only the oldest of them: the contact's, a few round trips long, is
82
+ * pushed out only by this many dials within those round trips.
83
+ */
84
+ export declare const DIALED_IN_CONTENDERS = 8;
79
85
  /**
80
86
  * A native connection this side dialled that has not authenticated this long after it opened, while the contact's
81
87
  * record names a newer way to dial it: the dial went to an old address (the web app's Iroh homed on another relay after
@@ -95,6 +101,14 @@ export declare const RACE_DIRECT_MS = 8000;
95
101
  * over a relay stays there (no probing while live, WISP 100), where the answer would have made it direct.
96
102
  */
97
103
  export declare const RACE_RELAYED_MS = 40000;
104
+ /**
105
+ * A relayed transport dialled ahead of the others (Automatic's Iroh through its relay, WISP 100 revision 2026-11-08) has
106
+ * this long before the next ranked one is dialled too, the first still going: whichever goes live first carries the
107
+ * chat. Through a relay that answers it connects well within it (0.1-0.9 s measured); one that reaches nobody (the
108
+ * relay down, the contact no longer on it) gives up only at Iroh's connect timeout, 20 s, and held the WebRTC offer back
109
+ * that long at every return: 26-30 s to live between two CLIs with the Iroh relay down, 4 s with WebRTC chosen.
110
+ */
111
+ export declare const RELAYED_FIRST_MS = 3000;
98
112
  /**
99
113
  * A WebRTC offer this side made that was answered, and has not connected this long after the answer was applied: where
100
114
  * a path exists ICE finds it in a second or two, so there is none (a VPN's NAT, a firewall that drops UDP, and no TURN
@@ -715,6 +729,11 @@ export declare class GhostLink {
715
729
  private readonly switcher;
716
730
  /** `plan`: a switch both sides agreed; without one, a replacement the contact dialled (`attachReplacement`). */
717
731
  private candidate;
732
+ /**
733
+ * Connections that authenticate beside a `candidate` dialled in and unproven (`contend`), oldest first: whichever
734
+ * authenticates first takes over, so one that never does neither holds the place nor takes it from the contact's.
735
+ */
736
+ private contenders;
718
737
  private candidateEpoch;
719
738
  /** The native dial a transport change has in flight, per transport (`prepareSwitch`). */
720
739
  private readonly switchDials;
@@ -857,7 +876,8 @@ export declare class GhostLink {
857
876
  /**
858
877
  * The WebRTC offer this side's dial made last, with fallback allowed: what a transport that comes up meanwhile joins.
859
878
  * `resume`: the dial that made it is this side back after an absence, over WebRTC (`resuming`); `woke`: the absence
860
- * was the app's in the background, not a restart (`resumeAfterAbsence`).
879
+ * was the app's in the background, not a restart (`resumeAfterAbsence`). `knockMissed`: the dial that made it followed a
880
+ * resume's knock that found nothing (`resumeKnockMissed`).
861
881
  */
862
882
  private offered?;
863
883
  /**
@@ -868,6 +888,10 @@ export declare class GhostLink {
868
888
  /** The attempt (its epoch) whose direct transports were knocked on as its offer went out (`knockEarly`), and whether that is under way. */
869
889
  private knockedEarly;
870
890
  private knockingEarly;
891
+ /** The attempt (its epoch) of a resume over WebRTC whose offer Iroh joined, its endpoint up only after the dial (`joinRace`). */
892
+ private irohJoinedResume;
893
+ /** The same for HyperDHT (direct, and already in the race's `afterRtc`). */
894
+ private hyperdhtJoinedResume;
871
895
  /** When this side's offer's answer was applied (`RACE_ANSWERED_MS`); 0 while the data link is not connecting on it. */
872
896
  private answeredAt;
873
897
  /** This side's offer is out unanswered, or answered and not connected yet: what is ranked after WebRTC may race it. */
@@ -955,6 +979,8 @@ export declare class GhostLink {
955
979
  private resumeWaitUntil;
956
980
  /** The contact's other native transports were knocked on while this resume waited (`knockWhileResuming`). */
957
981
  private resumeKnocked;
982
+ /** The resume's knock found nothing (`knock`): the next dial is still the resume's, made whatever the key. */
983
+ private resumeKnockMissed;
958
984
  /** What the last live session ran on, kept after it ended: a wake resumes on it (`resumeAfterAbsence`). */
959
985
  private lastLiveOn;
960
986
  /** `resuming` is a wake's, not a restart's. */
@@ -1061,6 +1087,12 @@ export declare class GhostLink {
1061
1087
  get dhtDelivery(): DhtDeliveryView | undefined;
1062
1088
  /** The chat is on screen: on the DHT its mailbox is read at the signaling pace (WISP 403, poll pace). */
1063
1089
  setChatActive(active: boolean): void;
1090
+ /**
1091
+ * What `emitDeliveryState` said last, cleared by any other pairing state: every mailbox read and publication of a
1092
+ * DHT-only chat asks for it again, and one that changed nothing builds no engine state (bug hunt 1109-chat-perf).
1093
+ */
1094
+ private saidDeliveryState;
1095
+ private sayPairingState;
1064
1096
  private emitDeliveryState;
1065
1097
  setDeliveryMode(mode: DeliveryMode): Promise<void>;
1066
1098
  start(): void;
@@ -1217,6 +1249,11 @@ export declare class GhostLink {
1217
1249
  * holds the old session and would notice only when its liveness gives up (a minute); a dial reaches it now and takes
1218
1250
  * over (`attachReplacement`). Once only, and a knock that does not connect counts as no failure: the contact may
1219
1251
  * simply be away. Two dials crossing are settled by key order (see `registerEndpoint`).
1252
+ *
1253
+ * A resume's knock that does not connect leaves its dial whatever the key to the next one (`resumeKnockMissed`), whose
1254
+ * offer knocks on the contact's other transports (`knockMissed`): a contact holding the old session over HyperDHT
1255
+ * announces no listener (endpoint.mjs), so the knock finds nothing, and the higher key waited for the contact to
1256
+ * notice (14.5-15.2 s between two CLI daemons, against 0.8-1.6 s with the lower key; under 5 s now).
1220
1257
  */
1221
1258
  private knock;
1222
1259
  /**
@@ -1315,7 +1352,11 @@ export declare class GhostLink {
1315
1352
  private upgradesFromRelay;
1316
1353
  /** The contact's newest packet is older than `EXPECT_PEER_MS`: it is not signalling, and reads at a slow pace. */
1317
1354
  private contactQuiet;
1318
- /** The direct transports of an attempt that resumes to a quiet contact, knocked on while its offer stands (`scheduleRace`). */
1355
+ /**
1356
+ * The direct transports of an attempt that resumes to a quiet contact, knocked on while its offer stands (`scheduleRace`).
1357
+ * So are those of the dial after a resume's knock that found nothing (`knockMissed`), relayed ones too, whatever the
1358
+ * contact's newest packet: it holds the old session and reads offers at a live chat's pace.
1359
+ */
1319
1360
  private maybeKnockEarly;
1320
1361
  /**
1321
1362
  * Back after a restart on a native transport whose endpoint has not started yet (Iroh waits up to 10 s for its relay,
@@ -1331,6 +1372,11 @@ export declare class GhostLink {
1331
1372
  * ranked what to try, and joins the race (and what the offer ending goes on to) if both sides allow it.
1332
1373
  */
1333
1374
  private joinRace;
1375
+ /**
1376
+ * On Automatic with no choice standing, Iroh ranks ahead of WebRTC for this contact and can be dialled now (WISP 100,
1377
+ * revision 2026-11-08): where a resume over WebRTC goes on Iroh instead (`dial`).
1378
+ */
1379
+ private irohRanksFirst;
1334
1380
  /** WebRTC could not start an attempt here: it goes last in the dial order for `RTC_UNSTARTED_MS`, while another transport remains. */
1335
1381
  private rtcUnstarted;
1336
1382
  /**
@@ -1780,9 +1826,20 @@ export declare class GhostLink {
1780
1826
  get contactAway(): boolean;
1781
1827
  requirePaymentSupport(): Promise<void>;
1782
1828
  private requireLegacyCapabilities;
1829
+ /** `closeRtc`: a WebRTC attempt under way beside a native session is this change's, and ends with it. */
1783
1830
  private cancelCandidate;
1784
1831
  private prepareSwitch;
1785
1832
  private attachCandidate;
1833
+ /** The candidate waiting for `plan` (none: a replacement) was dialled in and has not authenticated yet. */
1834
+ private contendable;
1835
+ /**
1836
+ * A connection that authenticates beside the candidate held (`contenders`), or takes the place if none is. With
1837
+ * `DIALED_IN_CONTENDERS` waiting already, the oldest dialled in and unproven of them gives its place up.
1838
+ */
1839
+ private contend;
1840
+ /** One of the `contenders` authenticated first: it takes the candidate's place, and the candidate held closes. */
1841
+ private promoteContender;
1842
+ private dropContenders;
1786
1843
  /**
1787
1844
  * Both sides dialled at once (two apps back after a restart, each knocking): the lower key's dial carries the chat, on
1788
1845
  * both sides; the higher key's side takes it over as a replacement (`attachReplacement`). Here, on the lower key's
@@ -514,6 +514,11 @@ export declare function communityHasFrame(state: Pick<CommunityState, "seen" | "
514
514
  h: string;
515
515
  n: number;
516
516
  }): boolean;
517
+ /**
518
+ * A `group-secret` or `group-entry` frame a hub routes for another member, rebuilt from its known fields when each has
519
+ * its real shape: what a hub remembers and hands on is no bigger than a real one. Null for anything else.
520
+ */
521
+ export declare function routedCommunityFrame(raw: Record<string, unknown>): CommunitySecretFrame | CommunityEntryFrame | null;
517
522
  /**
518
523
  * One member's view of a community group: the branch it follows and the ones it knows, the
519
524
  * secrets it holds, what it has seen, and the recent frames it keeps for others.
@@ -611,11 +616,16 @@ export declare class CommunitySession {
611
616
  get myKey(): string;
612
617
  get top(): CommunityCommit;
613
618
  /**
614
- * The top commit's hash, kept for the commit it was taken from: a view reads it for each member (its roster, what
615
- * each member's lines are missing), and hashing it every time cost tens of milliseconds per state in big communities.
619
+ * The top commit's hash: a view reads it for each member (its roster, what each member's lines are missing), and
620
+ * hashing it every time cost tens of milliseconds per state in big communities.
616
621
  */
617
622
  get topHash(): string;
618
- private topHashOf;
623
+ /**
624
+ * A commit's hash, kept for the commit it was taken from (a commit never changes once made): every sync frame, sync
625
+ * answer and commit hashed the whole window again, about a tenth of the load test's CPU at 64 and 128 members.
626
+ */
627
+ private hashOf;
628
+ private readonly hashes;
619
629
  get epoch(): number;
620
630
  get roster(): Roster;
621
631
  get admin(): string | undefined;
@@ -679,6 +679,8 @@ export declare class GroupSession {
679
679
  private commit;
680
680
  /** Someone removed or gone is not handed on any more, whatever they sent while in the roster (WISP 902 § Catch-up). */
681
681
  private pruneRelay;
682
+ /** An edit of an epoch I was not a member of (let in after it): kept and handed on unread (WISP 902 § Edits, "Carried unread"). */
683
+ private carriedUnread;
682
684
  /** Whether a kept edit is a removal (WISP 400 § Delete for everyone): its box, under its epoch's key, says `rm`. */
683
685
  private isRemovalEdit;
684
686
  /**
@@ -21,7 +21,8 @@ export declare function formatLocalTarget(target: LocalTarget): string;
21
21
  */
22
22
  export declare function resolveTargetUrl(target: LocalTarget, path: string): string | null;
23
23
  export declare function sanitizeRequestHeaders(headers: HeaderList): HeaderList;
24
- export declare function sanitizeResponseHeaders(headers: HeaderList, target: LocalTarget): HeaderList;
24
+ /** `from`: the local URL of the request answered, the one a relative `Location` is read against. */
25
+ export declare function sanitizeResponseHeaders(headers: HeaderList, target: LocalTarget, from?: string): HeaderList;
25
26
  /**
26
27
  * The contact's headers a viewer does not pass on: each makes the browser send something to a place it names, outside
27
28
  * `connect-src` (violation and network-error reports, and the endpoints they go to; `Link` preloads, prefetches and
@@ -75,12 +76,20 @@ export declare function withViewerPolicy(headers: HeaderList, relayOnly?: boolea
75
76
  /**
76
77
  * Turns `http://localhost:3400/base/x` into `/x` so the client never learns or
77
78
  * follows the local address. Null when the location is not on the target origin
78
- * and under its base path.
79
+ * and under its base path. A relative one (`edit`, `?page=2`, `../x`) is read
80
+ * against `from`, the local URL of the request it answers, as a browser reads it;
81
+ * without one, against the base path.
79
82
  */
80
- export declare function relativizeLocation(location: string, target: LocalTarget): string | null;
83
+ export declare function relativizeLocation(location: string, target: LocalTarget, from?: string): string | null;
81
84
  export interface HostedHttpService {
82
85
  id: string;
83
86
  target: LocalTarget;
87
+ /**
88
+ * Aborts once this peer may no longer reach the service (stopped, removed,
89
+ * or the contact taken off its list): the requests still open are reset, not
90
+ * answered.
91
+ */
92
+ revoked?: AbortSignal;
84
93
  }
85
94
  export interface LocalRequest {
86
95
  url: string;
@@ -115,6 +124,8 @@ export declare class HttpHost {
115
124
  private readonly live;
116
125
  /** Body bytes of the streams in `live`: a peer cannot make the host hold more than `maxHostBodyBytesPerPeer`. */
117
126
  private heldBodyBytes;
127
+ /** One listener per `revoked` signal of the open streams, not one per stream: a page opens dozens at once. */
128
+ private readonly revokedListeners;
118
129
  constructor(channel: FrameChannel, getService: (id: string) => HostedHttpService | undefined, localFetch: LocalFetch);
119
130
  get activeRequests(): number;
120
131
  handleRequest(frame: HttpRequestFrame): void;
@@ -126,6 +137,8 @@ export declare class HttpHost {
126
137
  /** Ids are reused after a reset, so a stream is current only if it is the one in the map. */
127
138
  private isCurrent;
128
139
  private end;
140
+ /** An answer still on its way would reach someone the app is no longer shared with: those streams are reset. */
141
+ private watchRevoked;
129
142
  /** The stream no longer counts toward the limits: its body is dropped, or its local fetch has settled. */
130
143
  private release;
131
144
  private fail;
@@ -160,10 +173,20 @@ export declare class HttpClient {
160
173
  private waitingBytes;
161
174
  private inFlight;
162
175
  private closed;
176
+ /** Response-body bytes all this client's responses hold before their readers took them. */
177
+ private readonly unread;
163
178
  constructor(channel: FrameChannel);
164
179
  request(serviceId: string, request: ClientRequest): Promise<ClientResponse>;
165
180
  handleResponse(frame: HttpResponseFrame): void;
166
181
  handleChunk(chunk: ChunkFrame): void;
182
+ /**
183
+ * Nothing tells the peer to slow down, and its last chunk frees the slot: a reader that stalls (a contact's page that
184
+ * never reads what it fetched) would have the whole body held here, one per request it leaves unread. Past the bound
185
+ * the reader gets `unreadStallMs`, as a link that hands over many chunks at once leaves it no turn: one that took
186
+ * something in it is looked at again, one that took nothing has the response reset and what it held let go.
187
+ */
188
+ private checkUnread;
189
+ private dropUnread;
167
190
  handleReset(frame: ResetFrame): void;
168
191
  close(): void;
169
192
  private armIdleTimer;
@@ -18,6 +18,14 @@ export declare const IDENTITY_MEMO_SIZE = 1024;
18
18
  export declare const IDENTITY_MEMO_IDLE_MS: number;
19
19
  /** The most keys kept, used or not: ~410 bytes each in V8 (its id, its key and when it was used), ~6.7 MB in all. */
20
20
  export declare const IDENTITY_MEMO_MAX = 16384;
21
+ /**
22
+ * A faster derivation of a seed's Ed25519 public key a host may give (the CLI gives node:crypto's, ~4x noble's): each
23
+ * process starts with an empty memo, so a one-shot command derives every chat's keys again. A throw, or an answer that
24
+ * is not 32 bytes, leaves the key to noble.
25
+ */
26
+ export type PublicKeyFastPath = (seed: Uint8Array) => Uint8Array;
27
+ /** Gives (or, with `null`, takes back) the faster derivation of every public key `identityFromSeed` derives. */
28
+ export declare function setPublicKeyFastPath(derive: PublicKeyFastPath | null): void;
21
29
  export declare function identityFromSeed(seed: Uint8Array): Identity;
22
30
  export declare function identityFromSeedB64(seedB64: string): Identity;
23
31
  export declare function createIdentity(): Identity;
@@ -29,14 +29,21 @@ export declare const LINK_PREVIEW_LIMITS: {
29
29
  };
30
30
  /** What a link leaves out at its end: a sentence's punctuation ("…", "»", "”" too), never a path's "/". */
31
31
  export declare const LINK_TRAILING: RegExp;
32
+ /** How many UTF-16 units of `url` before `end` are an emoji's or an invisible character's last code point (0: none). */
33
+ export declare function linkTail(url: string, end: number): number;
32
34
  /** A link up to the first `LINK_STOP`: "https://x.example/a。" opens /a, not /a%E3%80%82. */
33
35
  export declare function linkStop(url: string): string;
34
36
  /**
35
37
  * A link ends where the sentence around it takes over: trailing punctuation ("see https://x.example/a.", in any of
36
- * the app's languages) and a closing bracket or quote the link did not open ("(https://x.example/a)") are left as
37
- * text. The same rule as the message bubble's links.
38
+ * the app's languages), an emoji or invisible character (`linkTail`) and a closing bracket or quote the link did not
39
+ * open ("(https://x.example/a)") are left as text. The same rule as the message bubble's links.
38
40
  */
39
41
  export declare function linkEnd(whole: string): string;
42
+ /**
43
+ * A payment link (`bitcoin:`, `monero:`…) ends as a web link does, but keeps an emoji at its end: its label or message
44
+ * is text written as it is ("…&label=Pizza 🍕"), cut at 140 characters wherever that falls.
45
+ */
46
+ export declare function uriEnd(whole: string): string;
40
47
  /** Characters of a link worth reading: a longer one is no address anyone shares, and is left as text. */
41
48
  export declare const LINK_MAX_CHARS: number;
42
49
  /** The http(s) links of a text, in order, each ending as the bubble ends it. */
@@ -204,7 +204,7 @@ export declare const MINI_APP_LIMITS: {
204
204
  /** Requests per second, per app. */
205
205
  readonly requestsPerSecond: 50;
206
206
  /**
207
- * Bytes of `file`, `files.read`, `files.list` and `remote.read` answers per second, per app, counted together: a whole bundle's
207
+ * Bytes of `file`, `files.read`, `files.list`, `remote.read` and `storage.keys` answers per second, per app, counted together: a whole bundle's
208
208
  * worth. A request that starts under it is answered whole; past it the request is refused with `too-fast` until the
209
209
  * second has gone.
210
210
  */
@@ -149,6 +149,8 @@ export declare class AppRanges {
149
149
  private readonly newServeId;
150
150
  private readonly now;
151
151
  private readonly serves;
152
+ /** The same serves by app, then file: an app may serve 100,000 files, and walking `serves` for each was O(n²). */
153
+ private readonly servesByApp;
152
154
  private readonly serving;
153
155
  /**
154
156
  * Tasks cancelled, unserved, or stopped by the contact's close or a session's end, that this side is still reading or
@@ -138,13 +138,15 @@ export declare class AppSessions {
138
138
  canSend(app: string, data: unknown): AppSendError | null;
139
139
  /**
140
140
  * The session ended, or `apps/1` is no longer agreed: what the peer had open is gone, and each such app hears a
141
- * `close` with `offline`. This side's open apps stay, and say `open` again on the next session.
141
+ * `close` with `offline`. This side's open apps stay, and say `open` again on the next session. The rate windows
142
+ * stay too: they are the contact's per app, or turning `apps/1` off and on would give each app a new 50.
142
143
  */
143
144
  sessionEnded(): AppFrameEvent[];
144
145
  /**
145
146
  * The session ended or was replaced, and another may follow at once: what the peer had open is held, not closed (no
146
147
  * event now). Nothing is sent to a held app; an `open` on the next session takes it back, a `close` closes it, and
147
- * `heldExpired` closes the rest once `graceMs` has passed since the suspension that held each.
148
+ * `heldExpired` closes the rest once `graceMs` has passed since the suspension that held each. The rate windows stay,
149
+ * as in `sessionEnded`.
148
150
  */
149
151
  sessionSuspended(graceMs?: number): void;
150
152
  /** Whether any of the peer's apps is held, waiting for its next session. */
@@ -473,6 +473,16 @@ export declare class RelayTransport implements PkarrTransport {
473
473
  * before, and when no relay is held back at all.
474
474
  */
475
475
  private publishWait;
476
+ /**
477
+ * A publish that every relay would refuse now without being asked (its network cooling down, left alone after failing,
478
+ * its rate limit or this asker's budget), and not as a wait alone (`publishWait` says those): the failure `putEverywhere`
479
+ * would end in, in the same words, said before the packet is signed and dated. Null when some relay would be asked. With
480
+ * every relay out of reach on a page that is online, each chat signed a packet every few seconds that went nowhere: ~58
481
+ * a second at 300 chats (bug hunt, 2026-11-12).
482
+ */
483
+ private refusedEverywhere;
484
+ /** What `put` refuses a request to this relay with before its budget is asked; null when it gets that far. */
485
+ private refusal;
476
486
  /** One relay's packet for a key, read now: its time, kept for `nextTimestamp`. Null when it has none or does not answer. */
477
487
  private heldAt;
478
488
  /** A packet under this key was read (on a relay, or by the CLI on the DHT): its time, for `nextTimestamp`. */
@@ -3,10 +3,18 @@ export declare const VIDEO_METADATA_LIMITS: {
3
3
  readonly maxBoxBytes: number;
4
4
  /** The most top-level boxes walked (a fragmented MP4 has two per fragment). */
5
5
  readonly maxBoxes: 100000;
6
+ /** The most chunks of an AVI walked (one per frame and per piece of sound). */
7
+ readonly maxChunks: 4000000;
6
8
  /** Bytes read first to tell a video from another file. */
7
9
  readonly headBytes: 64;
8
10
  /** Bytes read at once for a box's header or a small box, so the next headers and `moof`s are read with it. */
9
11
  readonly readAhead: number;
12
+ /** The most a walk going on from its window reads at once (an Ogg's pages, a live WebM's blocks: the whole file). */
13
+ readonly readAheadMax: number;
14
+ /** The most bytes between two parts replaced that are read and sent with them as one part of the stripped video. */
15
+ readonly joinGap: number;
16
+ /** The most bytes of such a part. */
17
+ readonly joinedBytes: number;
10
18
  };
11
19
  /** Why a video is refused: its metadata could not be removed, so it does not go at all. */
12
20
  export declare const NO_VIDEO_METADATA = "This video cannot be sent: Ghostly could not remove the details saved in it, like where it was recorded";
@@ -18,7 +26,12 @@ export interface VideoSource {
18
26
  /**
19
27
  * `source` read a window at a time: a read that fits in `readAhead` bytes reads that many from where it starts, and
20
28
  * the reads after it within them (the next boxes' headers, a fragment's `moof`) are served from it, as copies (they
21
- * are changed in place). A Blob's read costs about the same whatever its size, so a fragment costs one, not three.
29
+ * are changed in place). A Blob's read costs most for being one (in Chromium ~0.3 ms, and ~0.9 ms per MiB), so a
30
+ * fragment costs one, not three.
31
+ *
32
+ * A walk that goes on from its window (an Ogg's pages, a live WebM's blocks: headers less than a window apart, through
33
+ * the whole file) reads twice as much each time, up to `readAheadMax`, so it makes a few large reads, not one per
34
+ * 64 KiB. One that jumps farther (over a fragment's samples) or back reads `readAhead` again.
22
35
  */
23
36
  export declare function readingAhead(source: VideoSource): VideoSource;
24
37
  /** A part of a video replaced as it is sent, `start` to `end` of the file: by `bytes`, or by zeros. */
@@ -27,6 +40,7 @@ export interface VideoPatch {
27
40
  end: number;
28
41
  bytes?: Uint8Array;
29
42
  }
43
+ export declare const isAsf: (head: Uint8Array) => boolean;
30
44
  /**
31
45
  * `source` as it is sent: an MP4 or QuickTime video without its metadata, made of `source`'s own bytes but for the
32
46
  * boxes and samples zeroed; undefined when it goes as it is (not one of these videos, a file without a video track).
@@ -1,4 +1,4 @@
1
- import { gd as IdentityCheckUnavailable, yd as boundVerifiedIdentity } from "./src-DA7T3Gvo.js";
1
+ import { wd as boundVerifiedIdentity, xd as IdentityCheckUnavailable } from "./src-CqAqFhh9.js";
2
2
  //#region ../browser/src/proofs/verify.ts
3
3
  var DAY = 86400;
4
4
  /**
@@ -104,4 +104,4 @@ function boundedIdentityFetch(options = { online: () => true }) {
104
104
  //#endregion
105
105
  export { verifyIdentity as i, boundedIdentityFetch as n, descriptorProblems as r, availableSigners as t };
106
106
 
107
- //# sourceMappingURL=verify-DsXR5sRX.js.map
107
+ //# sourceMappingURL=verify-B9s82dbd.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"verify-DsXR5sRX.js","names":[],"sources":["../../browser/src/proofs/verify.ts"],"sourcesContent":["import { boundVerifiedIdentity, IdentityCheckUnavailable, 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.recheck?.perHour !== undefined && !(Number.isInteger(p.recheck.perHour) && p.recheck.perHour >= 1)) problems.push(\"recheck.perHour must be a whole number, at least 1\");\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 IdentityCheckUnavailable(\"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,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,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"}
1
+ {"version":3,"file":"verify-B9s82dbd.js","names":[],"sources":["../../browser/src/proofs/verify.ts"],"sourcesContent":["import { boundVerifiedIdentity, IdentityCheckUnavailable, 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.recheck?.perHour !== undefined && !(Number.isInteger(p.recheck.perHour) && p.recheck.perHour >= 1)) problems.push(\"recheck.perHour must be a whole number, at least 1\");\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 IdentityCheckUnavailable(\"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,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ErD,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.11.2",
3
+ "version": "1.11.4",
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",