@ghostlytools/sdk 1.11.2 → 1.11.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.
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 { Ed as identityStatement, Na as decodeBolt11, Sd as emptyIdentityLedger, VT as createIdentity, ca as isBitcoinAddress, cd as IDENTITY_MAX_EVIDENCE, kd as newIdentityBinding, yd as IdentityExchange } from "./src-B9HeOlsG.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-DZpnNeF7.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-CK9Ra4X4.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
@@ -95,6 +95,14 @@ export declare const RACE_DIRECT_MS = 8000;
95
95
  * over a relay stays there (no probing while live, WISP 100), where the answer would have made it direct.
96
96
  */
97
97
  export declare const RACE_RELAYED_MS = 40000;
98
+ /**
99
+ * A relayed transport dialled ahead of the others (Automatic's Iroh through its relay, WISP 100 revision 2026-11-08) has
100
+ * this long before the next ranked one is dialled too, the first still going: whichever goes live first carries the
101
+ * chat. Through a relay that answers it connects well within it (0.1-0.9 s measured); one that reaches nobody (the
102
+ * relay down, the contact no longer on it) gives up only at Iroh's connect timeout, 20 s, and held the WebRTC offer back
103
+ * that long at every return: 26-30 s to live between two CLIs with the Iroh relay down, 4 s with WebRTC chosen.
104
+ */
105
+ export declare const RELAYED_FIRST_MS = 3000;
98
106
  /**
99
107
  * A WebRTC offer this side made that was answered, and has not connected this long after the answer was applied: where
100
108
  * 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
@@ -857,7 +865,8 @@ export declare class GhostLink {
857
865
  /**
858
866
  * The WebRTC offer this side's dial made last, with fallback allowed: what a transport that comes up meanwhile joins.
859
867
  * `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`).
868
+ * was the app's in the background, not a restart (`resumeAfterAbsence`). `knockMissed`: the dial that made it followed a
869
+ * resume's knock that found nothing (`resumeKnockMissed`).
861
870
  */
862
871
  private offered?;
863
872
  /**
@@ -955,6 +964,8 @@ export declare class GhostLink {
955
964
  private resumeWaitUntil;
956
965
  /** The contact's other native transports were knocked on while this resume waited (`knockWhileResuming`). */
957
966
  private resumeKnocked;
967
+ /** The resume's knock found nothing (`knock`): the next dial is still the resume's, made whatever the key. */
968
+ private resumeKnockMissed;
958
969
  /** What the last live session ran on, kept after it ended: a wake resumes on it (`resumeAfterAbsence`). */
959
970
  private lastLiveOn;
960
971
  /** `resuming` is a wake's, not a restart's. */
@@ -1217,6 +1228,11 @@ export declare class GhostLink {
1217
1228
  * holds the old session and would notice only when its liveness gives up (a minute); a dial reaches it now and takes
1218
1229
  * over (`attachReplacement`). Once only, and a knock that does not connect counts as no failure: the contact may
1219
1230
  * simply be away. Two dials crossing are settled by key order (see `registerEndpoint`).
1231
+ *
1232
+ * A resume's knock that does not connect leaves its dial whatever the key to the next one (`resumeKnockMissed`), whose
1233
+ * offer knocks on the contact's other transports (`knockMissed`): a contact holding the old session over HyperDHT
1234
+ * announces no listener (endpoint.mjs), so the knock finds nothing, and the higher key waited for the contact to
1235
+ * 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
1236
  */
1221
1237
  private knock;
1222
1238
  /**
@@ -1315,7 +1331,11 @@ export declare class GhostLink {
1315
1331
  private upgradesFromRelay;
1316
1332
  /** The contact's newest packet is older than `EXPECT_PEER_MS`: it is not signalling, and reads at a slow pace. */
1317
1333
  private contactQuiet;
1318
- /** The direct transports of an attempt that resumes to a quiet contact, knocked on while its offer stands (`scheduleRace`). */
1334
+ /**
1335
+ * The direct transports of an attempt that resumes to a quiet contact, knocked on while its offer stands (`scheduleRace`).
1336
+ * So are those of the dial after a resume's knock that found nothing (`knockMissed`), relayed ones too, whatever the
1337
+ * contact's newest packet: it holds the old session and reads offers at a live chat's pace.
1338
+ */
1319
1339
  private maybeKnockEarly;
1320
1340
  /**
1321
1341
  * Back after a restart on a native transport whose endpoint has not started yet (Iroh waits up to 10 s for its relay,
@@ -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
  /**
@@ -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
  */
@@ -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`. */
@@ -7,6 +7,8 @@ export declare const VIDEO_METADATA_LIMITS: {
7
7
  readonly headBytes: 64;
8
8
  /** 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
9
  readonly readAhead: number;
10
+ /** The most a walk going on from its window reads at once (an Ogg's pages, a live WebM's blocks: the whole file). */
11
+ readonly readAheadMax: number;
10
12
  };
11
13
  /** Why a video is refused: its metadata could not be removed, so it does not go at all. */
12
14
  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 +20,12 @@ export interface VideoSource {
18
20
  /**
19
21
  * `source` read a window at a time: a read that fits in `readAhead` bytes reads that many from where it starts, and
20
22
  * 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.
23
+ * 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
24
+ * fragment costs one, not three.
25
+ *
26
+ * A walk that goes on from its window (an Ogg's pages, a live WebM's blocks: headers less than a window apart, through
27
+ * the whole file) reads twice as much each time, up to `readAheadMax`, so it makes a few large reads, not one per
28
+ * 64 KiB. One that jumps farther (over a fragment's samples) or back reads `readAhead` again.
22
29
  */
23
30
  export declare function readingAhead(source: VideoSource): VideoSource;
24
31
  /** A part of a video replaced as it is sent, `start` to `end` of the file: by `bytes`, or by zeros. */
@@ -1,4 +1,4 @@
1
- import { gd as IdentityCheckUnavailable, yd as boundVerifiedIdentity } from "./src-DA7T3Gvo.js";
1
+ import { vd as IdentityCheckUnavailable, xd as boundVerifiedIdentity } from "./src-B9HeOlsG.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-DZpnNeF7.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,G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AAS,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"}
1
+ {"version":3,"file":"verify-DZpnNeF7.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,mBA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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.11.2",
3
+ "version": "1.11.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",