@ghostlytools/sdk 1.7.1 → 1.7.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 { OC as createIdentity, Oa as decodeBolt11, Yu as IdentityExchange, Zu as emptyIdentityLedger, ed as identityStatement, ra as isBitcoinAddress, rd as newIdentityBinding, zu as IDENTITY_MAX_EVIDENCE } from "./src-BQIrd6HM.js";
1
+ import { Oa as decodeBolt11, Yu as IdentityExchange, Zu as emptyIdentityLedger, ed as identityStatement, kC as createIdentity, ra as isBitcoinAddress, rd as newIdentityBinding, zu as IDENTITY_MAX_EVIDENCE } from "./src-Dw-9Vq6U.js";
2
2
  import { l as providerDescriptorProblems, o as isNothingSpentError } from "./types-DvtCy3WB.js";
3
- import { i as verifyIdentity, r as descriptorProblems } from "./verify-m9lUHJ3Y.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-BHdvWF8e.js";
3
+ import { i as verifyIdentity, r as descriptorProblems } from "./verify-chCUPRKH.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-NFHnJNv8.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;
@@ -202,6 +202,12 @@ export interface ChatFilesHost {
202
202
  * sending, stored when receiving); `progress` says only that moved, so keeping it can wait.
203
203
  */
204
204
  changed(record: FileTransferRecord, transferred: number, progress: boolean): void;
205
+ /**
206
+ * Resolves once what `changed` was given so far is kept, so a restart finds it. A receiver says a file is done
207
+ * (`pf-done`) only then: said before, a restart found it unfinished while its sender had it done, and asking for it
208
+ * again got no answer. Absent: `changed` keeps it at once.
209
+ */
210
+ kept?(): Promise<void>;
205
211
  /** Bytes a file may still take here, or null when the platform does not say. */
206
212
  room?(): Promise<number | null>;
207
213
  /**
@@ -371,6 +377,11 @@ export declare class ChatFiles {
371
377
  /** `pf-accept` from what is taken here: the sender goes on from there (it ignores it for a transfer that ended). */
372
378
  private askAgain;
373
379
  private onSum;
380
+ /**
381
+ * `pf-done` once the host kept the file's done record (`kept`). Not kept (the app gone first), the sender still
382
+ * waits, offers it again on the next session, and the receiver answers from what it kept.
383
+ */
384
+ private sayDone;
374
385
  /** A frame from the contact (one of `FILE_FRAMES`). Returns quickly: writing goes on in the background. */
375
386
  handle(frame: Record<string, unknown>): Promise<void>;
376
387
  private end;
@@ -22,6 +22,7 @@ export declare const ENGINE_ERRORS: {
22
22
  readonly invalidMintUrl: "That is not a valid mint URL";
23
23
  readonly mintNotHttps: "Mints must use https";
24
24
  readonly notEnoughSats: "Not enough sats in your wallet";
25
+ readonly notEnoughForFee: "Not enough sats in your wallet: {amount} sats leave room for the fee";
25
26
  readonly noSharedMint: "You share no mint with this contact";
26
27
  readonly ecashAlreadySpent: "This ecash was already spent somewhere else";
27
28
  readonly ecashBeingReceived: "This ecash is already being received";
@@ -207,6 +207,12 @@ export interface FrameChannel {
207
207
  * Absent: text only, as the Iroh channels are, and nothing binary is offered or sent on it.
208
208
  */
209
209
  readonly binary?: boolean;
210
+ /**
211
+ * A frame the transport sends on this connection by itself as the app exits, should the page not be there to say it
212
+ * (the Desktop's native channels: a logout ends the WebView's processes with the app); null takes it back. Absent:
213
+ * whatever the page does not say on its way out is not said.
214
+ */
215
+ parting?(frame: string | null): void;
210
216
  close(): void;
211
217
  onMessage: ((data: string | Uint8Array) => void) | null;
212
218
  onClose: (() => void) | null;
@@ -715,6 +715,8 @@ export declare class GhostLink {
715
715
  /** What each side announced after the handshake (`paired-capabilities`): calls, services. */
716
716
  private readonly sessionCapabilities;
717
717
  private readonly pairedCalls;
718
+ /** The channel holding this side's call hang-up, to be sent by the transport should the page go first (`leaveHangUp`). */
719
+ private partingOn;
718
720
  /** Typing on this session (`typing/1`): when to say `start` again, and the contact's word with its timeout. */
719
721
  private readonly typingSender;
720
722
  private readonly typingReceiver;
@@ -798,6 +800,8 @@ export declare class GhostLink {
798
800
  private offerReplaced?;
799
801
  private lastAutoConnectAt;
800
802
  private autoConnectFailures;
803
+ /** The wait (dial and count of failures) whose `dial-backoff` line is written: the looks during it write none. */
804
+ private backoffTraced;
801
805
  /** The look due when a failed dial's backoff ends (`lookAtRetry`). */
802
806
  private retryLook;
803
807
  /** This side's offer is out to the data link and has not reached the relays yet. */
@@ -1289,6 +1293,13 @@ export declare class GhostLink {
1289
1293
  settleDht(id: string): Promise<void>;
1290
1294
  /** Publishes a `_call` signal; a connected peer also gets it right away over the data link. */
1291
1295
  setCallSignal(signal: string | null): Promise<void>;
1296
+ /**
1297
+ * Hands the transport the hang-up of the call this side is on (`PairedCalls.parting`), for it to send as the app
1298
+ * exits should the page be gone by then: a logout or a shutdown ends the Desktop's WebView with the app, and its
1299
+ * goodbye (`depart`) never ran, the contact's call stalling until its media gave up 16 s later. Taken back once no
1300
+ * call of ours is on, and from a session no longer the chat's.
1301
+ */
1302
+ private leaveHangUp;
1292
1303
  /** Issues an HTTP request to a service the peer advertises. */
1293
1304
  request(serviceId: string, request: ClientRequest): Promise<ClientResponse>;
1294
1305
  /** Payments only travel over the data link: tokens and invoices do not fit in Pkarr, and should not sit there. */
@@ -343,6 +343,7 @@ export interface CommunityState {
343
343
  /** A few statements I held before `meta`, oldest first, for a member back from away (`keepPastGroupMeta`). Absent in older states. */
344
344
  metaPast?: GroupMeta[];
345
345
  }
346
+ /** `frame`: the frame the message came in, as it is kept to hand on to a member who missed it. An app may keep it with the message it stores. */
346
347
  export interface CommunityIncomingMessage {
347
348
  id: string;
348
349
  sender: string;
@@ -355,6 +356,7 @@ export interface CommunityIncomingMessage {
355
356
  forwarded?: number;
356
357
  card?: StatusCard;
357
358
  file?: GroupFileMeta;
359
+ frame?: CommunityMessageFrame;
358
360
  }
359
361
  /**
360
362
  * What an application sends through the group rather than as text: `frame` for everyone in the epoch (the group
@@ -383,7 +385,10 @@ export interface CommunitySessionHooks {
383
385
  direct(to: string, frame: CommunityFrame): boolean | void;
384
386
  /** To one member, wherever they are: over their edge if I have it, else to the hubs with `to`. */
385
387
  addressed(to: string, frame: CommunitySecretFrame | CommunityEntryFrame): void;
386
- message(message: CommunityIncomingMessage): Promise<void> | void;
388
+ /** `true`: the app stored the message's `frame` with it, durably, so the saved state need not carry that frame. */
389
+ message(message: CommunityIncomingMessage): Promise<boolean | void> | boolean | void;
390
+ /** A frame the app holds with its message (`id`) is no longer kept to hand on: newer ones took its place, or I am out. */
391
+ forgetFrame?(id: string): void;
387
392
  /**
388
393
  * Whether an application frame (mine or a member's) says the group's state rather than news, and of which kind: the
389
394
  * newest frame of each kind is kept past the store and handed with every catch-up to a member who lacks it, however
@@ -485,7 +490,13 @@ export declare class CommunitySession {
485
490
  private saveTimer;
486
491
  /** One metadata frame naming a commit or a secret I do not have yet: tried again when the chain or my secrets move. */
487
492
  private pendingMeta;
488
- constructor(state: CommunityState, hooks: CommunitySessionHooks);
493
+ /** The store's frames the app holds with their messages (`storeKey` → message id): in memory here, not in what is saved. */
494
+ private readonly onRows;
495
+ /** `rows`: the frames the app holds with the messages it stored (`CommunityIncomingMessage.frame`). They join the store. */
496
+ constructor(state: CommunityState, hooks: CommunitySessionHooks, rows?: readonly {
497
+ id: string;
498
+ frame: CommunityMessageFrame;
499
+ }[]);
489
500
  static create(name: string, now?: number): CommunityState;
490
501
  /**
491
502
  * Joining from a welcome over the link's entry session: the whole chain verifies from its
@@ -632,6 +643,8 @@ export declare class CommunitySession {
632
643
  private takeSecret;
633
644
  private serialize;
634
645
  private persist;
646
+ /** The state as it is saved: a copy, without the frames the app holds with their messages (`onRows`). */
647
+ private toSave;
635
648
  /**
636
649
  * A save within a second, for what may happen many times a second (every message received, in a
637
650
  * group of hundreds): the state holds the chain and the store, and is not worth writing each time.
@@ -744,6 +757,9 @@ export declare class CommunitySession {
744
757
  /** The id of the message a stored frame is, by its first place when it was said again (and I can open it). */
745
758
  private storedId;
746
759
  private keep;
760
+ private trimStore;
761
+ /** The frames the app's rows hold, into the store: oldest first by when they were written, with what the record kept from before. */
762
+ private takeRows;
747
763
  /**
748
764
  * My frames sealed under a commit I took for the newest while I was behind (no edge was up, and others were let in
749
765
  * meanwhile): the members let in before I said them could never open them. Once the chain I follow (and its secret)
@@ -129,7 +129,6 @@ 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"];
133
132
  constructor(inner: PkarrTransport, myKey: string, peerKey: string, hooks: CarriedHooks);
134
133
  describe(): {
135
134
  protocol: string;
@@ -16,4 +16,8 @@ export declare function identityFromSeedB64(seedB64: string): Identity;
16
16
  export declare function createIdentity(): Identity;
17
17
  export declare function publicKeyFromZ32(z32: string): Uint8Array;
18
18
  export declare function sign(message: Uint8Array, seed: Uint8Array): Uint8Array;
19
+ /**
20
+ * Ed25519 verification as RFC 8032 writes it (`zip215: false`): canonical encodings only, and no key of small order,
21
+ * which no secret key goes with and which "verifies" a constant signature of any message.
22
+ */
19
23
  export declare function verify(signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): boolean;
@@ -41,6 +41,15 @@ export declare const OFFER_FAST_MS = 10000;
41
41
  export declare const OFFER_STEP_MAX = 4;
42
42
  /** An offer to a saved contact is looked at for an answer as long as its attempt lasts (`CONNECT_TIMEOUT_MS`), not 45 s. */
43
43
  export declare const OFFER_LOOK_MS = 90000;
44
+ /**
45
+ * The first fast reads after a new offer or answer of this side's went out are signaling (`PkarrRequestOptions.signal`),
46
+ * as the reads for the answer to an offer to a saved contact are all along. An answer's: the offer it answered may be
47
+ * given up by then (its attempt ended before it read the answer, or the answer was refused), and the offerer's next one,
48
+ * made at once, is what both sides wait on. 3 at the relays' fast pace cover 6 s. As plain reads, an extension back
49
+ * from Offline with its relay minute spent never read its contact's new offer and answered the old one again: the
50
+ * matrix's chat stayed "On DHT · retrying live" for 45 s (E2E full, 2026-10-30).
51
+ */
52
+ export declare const SIGNAL_OUT_READS = 3;
44
53
  /**
45
54
  * How long a link looks fast when its peer, or the peer's offer, is due any moment. The peer that
46
55
  * dials does so as soon as it sees the other one here, and its offer lands in its packet a moment
@@ -253,6 +262,8 @@ export declare class LinkSession {
253
262
  private fastPollUntil;
254
263
  /** An offer to a saved contact is out: from then on its fast window looks less often (`OFFER_FAST_MS`); 0 for none. */
255
264
  private fastStepsAfter;
265
+ /** Fast reads still signaling since this side's last new offer or answer went out (`SIGNAL_OUT_READS`). */
266
+ private signalReadsLeft;
256
267
  /** When the last `expectPeer` window ends (or ended): the pace slows down from there step by step. */
257
268
  private expectUntil;
258
269
  /**
@@ -59,6 +59,14 @@ export declare class PairedCalls {
59
59
  hangUp(options?: {
60
60
  declineRinging?: boolean;
61
61
  }): PairedCallFrame | null;
62
+ /**
63
+ * The hang-up of a call this side placed or answered, for the transport to send should the app go without a word
64
+ * (`FrameChannel.parting`: a logout ends the Desktop's page with the app), or null when no call of ours is on. Nothing
65
+ * is said or changed here. Its time is just after this side's latest signal, so it stays the same until that changes;
66
+ * a hang-up the page itself says on its way out too (`hangUp`) is no older, and finds the call over already.
67
+ */
68
+ parting(): PairedCallFrame | null;
69
+ private said;
62
70
  /** On a new session that carries calls: the latest signal again, if it is still fresh enough to act on. */
63
71
  pending(): PairedCallFrame | null;
64
72
  }
@@ -295,6 +295,8 @@ export declare class RelayTransport implements PkarrTransport {
295
295
  private readonly readTurns;
296
296
  /** Per key read in turn (`isTurnRead`), when a read of it last went out and when it last asked (`READ_TURN_MS`). */
297
297
  private readonly keyTurns;
298
+ /** When `readTurns` and `keyTurns` last dropped their stale turns (`TURNS_PRUNE_MS`). */
299
+ private readonly turnsPrunedAt;
298
300
  /** Groups' reads (not background ones) on each relay in the last `GROUP_RATION_WINDOW_MS`. */
299
301
  private readonly spentGroupReads;
300
302
  /** When a group's read last found each relay's minute full: its reads there are rationed for `GROUP_RATION_MS`. */
@@ -514,6 +516,8 @@ export declare class RelayTransport implements PkarrTransport {
514
516
  private readsAhead;
515
517
  /** A read of `key` that takes turns asks: it waits for its turn from now on, unless it is taken (`turnAhead`). */
516
518
  private turnAsked;
519
+ /** Drops the turns asked and read over a minute ago, at most once in `TURNS_PRUNE_MS` (or when the clock went back). */
520
+ private pruneTurns;
517
521
  /**
518
522
  * Whether a key read in turn longer ago than `key`, still asking, would take this relay's next request: one read in the
519
523
  * background for a background read, and a chat's that is starved (`READ_STARVED_MS`) for any. One asks again after
@@ -1,4 +1,4 @@
1
- import { Xu as boundVerifiedIdentity } from "./src-BQIrd6HM.js";
1
+ import { Xu as boundVerifiedIdentity } from "./src-Dw-9Vq6U.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-m9lUHJ3Y.js.map
106
+ //# sourceMappingURL=verify-chCUPRKH.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"verify-m9lUHJ3Y.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,oBAAo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,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-chCUPRKH.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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M,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.7.1",
3
+ "version": "1.7.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",