@ghostlytools/sdk 1.12.1 → 1.13.1
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/bitcoinAddress-BbPG0DF7.js +3927 -0
- package/dist/bitcoinAddress-BbPG0DF7.js.map +1 -0
- package/dist/core.js +496 -2386
- package/dist/core.js.map +1 -1
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/{pairedTransports-CkYMAoYN.js → pairedTransports-C0I24YFz.js} +9 -291
- package/dist/pairedTransports-C0I24YFz.js.map +1 -0
- package/dist/testing.js +2 -2
- package/dist/types/browser/src/proofs/contract.d.ts +5 -0
- package/dist/types/browser/src/proofs/pkarrRelays.d.ts +4 -0
- package/dist/types/browser/src/proofs/verify.d.ts +3 -0
- package/dist/types/core/src/chatFiles.d.ts +16 -0
- package/dist/types/core/src/clipboardGuard.d.ts +5 -3
- package/dist/types/core/src/dhtDelivery.d.ts +20 -0
- package/dist/types/core/src/domainProofs.d.ts +2 -1
- package/dist/types/core/src/ghostlink.d.ts +30 -0
- package/dist/types/core/src/groupCalls.d.ts +56 -0
- package/dist/types/core/src/groupCommunity.d.ts +15 -1
- package/dist/types/core/src/groupSession.d.ts +15 -1
- package/dist/types/core/src/index.d.ts +1 -1
- package/dist/types/core/src/relay.d.ts +14 -1
- package/dist/types/core/src/statusCards.d.ts +6 -0
- package/dist/types/core/src/viewerGuard.d.ts +10 -3
- package/dist/{verify-CSo7-43-.js → verify-BoVhjvc_.js} +24 -5
- package/dist/verify-BoVhjvc_.js.map +1 -0
- package/package.json +1 -1
- package/dist/bitcoinAddress-C2MAmcDT.js +0 -1225
- package/dist/bitcoinAddress-C2MAmcDT.js.map +0 -1
- package/dist/pairedTransports-CkYMAoYN.js.map +0 -1
- package/dist/verify-CSo7-43-.js.map +0 -1
|
@@ -389,6 +389,8 @@ export declare class RelayTransport implements PkarrTransport {
|
|
|
389
389
|
private readonly lastPut;
|
|
390
390
|
/** Per relay and key, the newest packet that relay held back for its budget while another relay took it (`catchUpLater`). */
|
|
391
391
|
private readonly catchUp;
|
|
392
|
+
/** Per relay, how many packets wait in `catchUp` for it: background reads leave them their share (`heldFor`). */
|
|
393
|
+
private readonly catchUpWaiting;
|
|
392
394
|
private catchUpTimer;
|
|
393
395
|
/**
|
|
394
396
|
* Per key whose reads the budget held back since its last read went out: when a request frees for it
|
|
@@ -583,11 +585,14 @@ export declare class RelayTransport implements PkarrTransport {
|
|
|
583
585
|
/**
|
|
584
586
|
* A relay whose budget (this client's, or its own rate limit) held a packet back that another relay took: it gets
|
|
585
587
|
* that packet when it frees a request, as a background write (`who`: a group edge's offer or answer as its own, also
|
|
586
|
-
* after that relay failed it). Only the newest per key and relay
|
|
588
|
+
* after that relay failed it). Only the newest per key and relay, until that relay takes this packet or a newer one (one
|
|
589
|
+
* the budget holds there takes its place). Without this,
|
|
587
590
|
* that relay kept the key's older packet for good, and an app that restarted and read it first found a contact's offer
|
|
588
591
|
* long answered, answered it again, and waited on it (bug hunt r7a).
|
|
589
592
|
*/
|
|
590
593
|
private catchUpLater;
|
|
594
|
+
private keepCatchUp;
|
|
595
|
+
private dropCatchUp;
|
|
591
596
|
private scheduleCatchUp;
|
|
592
597
|
private runCatchUp;
|
|
593
598
|
/** `sent`: told, once the budget took the request, whether the relay takes the packet (a 2xx). */
|
|
@@ -643,6 +648,14 @@ export declare class RelayTransport implements PkarrTransport {
|
|
|
643
648
|
* waiting for the chats held every chat's read back (CLI lab, 2026-10-13).
|
|
644
649
|
*/
|
|
645
650
|
private turnAhead;
|
|
651
|
+
/**
|
|
652
|
+
* How long until a background read of `key` the budget held back is likely to have its turn: the background reads of
|
|
653
|
+
* keys ahead of it in turn (read longer ago, still asking; `turnAhead`), one after the other at the relays' background
|
|
654
|
+
* share. Told only when the budget frees the next request, every held key asked again then, and lost it to the key
|
|
655
|
+
* whose turn it was: a daemon whose 50 contacts were away asked about 600 times a minute for some 50 reads, and one
|
|
656
|
+
* with 200 three times as often after four hours as after 15 minutes (bug hunts, 2026-11-06 and 2026-11-14).
|
|
657
|
+
*/
|
|
658
|
+
private backgroundTurnIn;
|
|
646
659
|
/** A 1:1 chat's read of `key` the budget has held back for `READ_STARVED_MS` without a break. */
|
|
647
660
|
private starved;
|
|
648
661
|
/** This key's departed reads past the limit in the last minute (`DEPARTED_READS`). */
|
|
@@ -269,6 +269,12 @@ export declare function cardTimeUtc(ms: number): string;
|
|
|
269
269
|
* name when the sender knows it ("🗑 Task removed: Fix relay rotation"). An app without the `removed` kind shows it.
|
|
270
270
|
*/
|
|
271
271
|
export declare function removedCardText(of: RemovableKind, title?: string): string;
|
|
272
|
+
/**
|
|
273
|
+
* A message's text without the line that is its app card's link (`statusCardText` puts it on a line of its own for an
|
|
274
|
+
* older app): what a line quoting the message says where the card is not drawn, never the bundle's raw link. Any other
|
|
275
|
+
* message's text as it is.
|
|
276
|
+
*/
|
|
277
|
+
export declare function withoutAppLink(text: string, card: StatusCard | undefined): string;
|
|
272
278
|
/**
|
|
273
279
|
* The text a card's message carries: what an app without cards shows, the DHT floor carries, the chat list previews
|
|
274
280
|
* and search finds. Plain lines, the first naming the card, no bars or layout that would read badly elsewhere.
|
|
@@ -14,7 +14,14 @@ import type { HeaderList } from "./frames.js";
|
|
|
14
14
|
* refuses `javascript:` URLs (its own Trusted Types default policy: one passes every other string on as it is);
|
|
15
15
|
* - refuses a declarative shadow root the page's script would make (`setHTMLUnsafe`, `Document.parseHTMLUnsafe`,
|
|
16
16
|
* `document.write`, a write split in two too): its `srcdoc` frames would be out of the guard's sight;
|
|
17
|
-
* - listens for frames' loads again after `document.open()`, which takes every listener of the document away
|
|
17
|
+
* - listens for frames' loads again after `document.open()`, which takes every listener of the document away;
|
|
18
|
+
* - starts a worker made from a `blob:` URL of the page's own (`URL.createObjectURL` in that window) from a script of its
|
|
19
|
+
* own that makes a pass-through Trusted Types `default` policy there first and then runs the page's (`importScripts`;
|
|
20
|
+
* for a module worker, a static `import` of the policy's module, then of the page's): such a worker takes the page's
|
|
21
|
+
* policy, Trusted Types included, and no guard runs in it to make one. A `SharedWorker` made twice from one blob gets
|
|
22
|
+
* the same script, so it is the same worker; the page's revoke of the blob's URL drops the guard's own a minute later.
|
|
23
|
+
* A `data:` worker, and a blob made in another window, in a worker or already revoked, run as they were. Once per
|
|
24
|
+
* window, whichever guard runs first (`ghostlyWorkerGuard`, `CLIPBOARD_GUARD_SCRIPT` does the same).
|
|
18
25
|
* It uses nothing the page can change after it ran (the page's own code runs later, in the same realm).
|
|
19
26
|
*
|
|
20
27
|
* What a script put in the page cannot do, so where the viewer does not run it per document this is not a guarantee:
|
|
@@ -23,9 +30,9 @@ import type { HeaderList } from "./frames.js";
|
|
|
23
30
|
* guard is there.
|
|
24
31
|
* No backslash, `${` or backtick in it: Desktop's copy (`SERVICE_GUARD`, apps/desktop/src/viewer.rs) is the same text.
|
|
25
32
|
*/
|
|
26
|
-
export declare const VIEWER_GUARD_SCRIPT = "(function noWebRtc(w) {\n \"use strict\";\n try {\n const apply = Reflect.apply;\n const own = \"<script>(\" + noWebRtc + \")(window)<\" + \"/script>\";\n for (const name of Object.getOwnPropertyNames(w)) {\n if (/^(webkit)?RTC/.test(name)) { try { delete w[name]; } catch (e) {} }\n }\n if (w.trustedTypes && !w.trustedTypes.defaultPolicy) {\n try {\n w.trustedTypes.createPolicy(\"default\", {\n createHTML: (input) => input,\n createScript: (input, type, sink) => (sink === \"Location href\" ? null : input),\n createScriptURL: (input) => input,\n });\n } catch (e) {}\n }\n const open = w.open;\n const opener = function (url, target) {\n apply(open, this, [url === undefined ? \"\" : url, target === undefined ? \"_blank\" : target, \"noopener\"]);\n return null;\n };\n w.open = opener;\n const describe = Object.getOwnPropertyDescriptor;\n const define = Object.defineProperty;\n const shut = (inner) => {\n try { if (inner && inner !== w && (\"RTCPeerConnection\" in inner || \"webkitRTCPeerConnection\" in inner)) noWebRtc(inner); } catch (e) {}\n };\n const count = describe(w, \"length\").get;\n const view = describe(w.Document.prototype, \"defaultView\").get;\n const slice = String.prototype.slice;\n const sweep = () => {\n try { for (let i = apply(count, w, []); i-- > 0;) shut(w[i]); } catch (e) {}\n };\n const listen = w.EventTarget.prototype.addEventListener;\n const home = w.document;\n const reopen = w.Document.prototype.open;\n w.Document.prototype.open = function () {\n if (arguments.length > 2) return apply(opener, w, [arguments[0], arguments[1]]);\n const got = apply(reopen, this, arguments);\n if (this === home) { try { apply(listen, home, [\"load\", sweep, true]); } catch (e) {} }\n return got;\n };\n const text = String;\n const lower = String.prototype.toLowerCase;\n const index = String.prototype.indexOf;\n const Refused = w.TypeError;\n const shadowed = (html) => apply(index, apply(lower, html, []), [\"shadowrootmode\"]) >= 0;\n const refuse = () => { throw new Refused(\"A declarative shadow root is not allowed here\"); };\n for (const [owner, name] of [[w.Element.prototype, \"setHTMLUnsafe\"], [w.ShadowRoot && w.ShadowRoot.prototype, \"setHTMLUnsafe\"], [w.Document, \"parseHTMLUnsafe\"]]) {\n const real = owner && owner[name];\n if (typeof real !== \"function\") continue;\n owner[name] = function (html) {\n const checked = text(html);\n if (shadowed(checked)) refuse();\n return apply(real, this, arguments.length > 1 ? [checked, arguments[1]] : [checked]);\n };\n }\n let tail = \"\";\n for (const name of [\"write\", \"writeln\"]) {\n const real = w.Document.prototype[name];\n if (typeof real !== \"function\") continue;\n w.Document.prototype[name] = function () {\n let checked = \"\";\n for (let i = 0; i < arguments.length; i++) checked += text(arguments[i]);\n if (shadowed(tail + checked)) refuse();\n tail = apply(slice, tail + checked, [-16]);\n return apply(real, this, [checked]);\n };\n }\n for (const kind of [\"HTMLIFrameElement\", \"HTMLFrameElement\", \"HTMLObjectElement\", \"HTMLEmbedElement\"]) {\n const proto = w[kind] && w[kind].prototype;\n for (const name of [\"contentWindow\", \"contentDocument\", \"getSVGDocument\"]) {\n const found = proto && describe(proto, name);\n const key = found && found.get ? \"get\" : \"value\";\n if (!found || typeof found[key] !== \"function\") continue;\n const read = found[key];\n found[key] = function () {\n const got = apply(read, this, arguments);\n try { shut(name === \"contentWindow\" ? got : apply(view, got, [])); } catch (e) {}\n return got;\n };\n try { define(proto, name, found); } catch (e) {}\n }\n }\n const { getAttribute, setAttribute, removeAttribute, attachShadow } = w.Element.prototype;\n const size = describe(w.NodeList.prototype, \"length\").get;\n const first = (frame) => {\n const doc = apply(getAttribute, frame, [\"srcdoc\"]);\n if (doc === null || apply(slice, doc, [0, own.length]) === own) return;\n try { apply(setAttribute, frame, [\"srcdoc\", own + doc]); } catch (e) { apply(removeAttribute, frame, [\"srcdoc\"]); }\n };\n const Observer = w.MutationObserver;\n const observe = Observer.prototype.observe;\n const watch = (root, all) => {\n const scan = () => {\n try {\n const frames = apply(all, root, [\"iframe[srcdoc]\"]);\n for (let i = apply(size, frames, []); i-- > 0;) first(frames[i]);\n } catch (e) {}\n sweep();\n };\n apply(observe, new Observer(scan), [root, { subtree: true, childList: true, attributes: true, attributeFilter: [\"srcdoc\"] }]);\n scan();\n return root;\n };\n const inShadow = w.DocumentFragment.prototype.querySelectorAll;\n if (attachShadow) {\n w.Element.prototype.attachShadow = function () {\n const root = apply(attachShadow, this, arguments);\n try { watch(root, inShadow); } catch (e) {}\n return root;\n };\n }\n apply(listen, home, [\"load\", sweep, true]);\n watch(home, w.Document.prototype.querySelectorAll);\n } catch (e) {}\n})(window)";
|
|
33
|
+
export declare const VIEWER_GUARD_SCRIPT = "(function noWebRtc(w) {\n \"use strict\";\n try {\n const apply = Reflect.apply;\n const own = \"<script>(\" + noWebRtc + \")(window)<\" + \"/script>\";\n for (const name of Object.getOwnPropertyNames(w)) {\n if (/^(webkit)?RTC/.test(name)) { try { delete w[name]; } catch (e) {} }\n }\n if (w.trustedTypes && !w.trustedTypes.defaultPolicy) {\n try {\n w.trustedTypes.createPolicy(\"default\", {\n createHTML: (input) => input,\n createScript: (input, type, sink) => (sink === \"Location href\" ? null : input),\n createScriptURL: (input) => input,\n });\n } catch (e) {}\n }\n const open = w.open;\n const opener = function (url, target) {\n apply(open, this, [url === undefined ? \"\" : url, target === undefined ? \"_blank\" : target, \"noopener\"]);\n return null;\n };\n w.open = opener;\n const describe = Object.getOwnPropertyDescriptor;\n const define = Object.defineProperty;\n const shut = (inner) => {\n try { if (inner && inner !== w && (\"RTCPeerConnection\" in inner || \"webkitRTCPeerConnection\" in inner)) noWebRtc(inner); } catch (e) {}\n };\n const count = describe(w, \"length\").get;\n const view = describe(w.Document.prototype, \"defaultView\").get;\n const slice = String.prototype.slice;\n const sweep = () => {\n try { for (let i = apply(count, w, []); i-- > 0;) shut(w[i]); } catch (e) {}\n };\n const listen = w.EventTarget.prototype.addEventListener;\n const home = w.document;\n const reopen = w.Document.prototype.open;\n w.Document.prototype.open = function () {\n if (arguments.length > 2) return apply(opener, w, [arguments[0], arguments[1]]);\n const got = apply(reopen, this, arguments);\n if (this === home) { try { apply(listen, home, [\"load\", sweep, true]); } catch (e) {} }\n return got;\n };\n const text = String;\n const lower = String.prototype.toLowerCase;\n const index = String.prototype.indexOf;\n const Refused = w.TypeError;\n const shadowed = (html) => apply(index, apply(lower, html, []), [\"shadowrootmode\"]) >= 0;\n const refuse = () => { throw new Refused(\"A declarative shadow root is not allowed here\"); };\n for (const [owner, name] of [[w.Element.prototype, \"setHTMLUnsafe\"], [w.ShadowRoot && w.ShadowRoot.prototype, \"setHTMLUnsafe\"], [w.Document, \"parseHTMLUnsafe\"]]) {\n const real = owner && owner[name];\n if (typeof real !== \"function\") continue;\n owner[name] = function (html) {\n const checked = text(html);\n if (shadowed(checked)) refuse();\n return apply(real, this, arguments.length > 1 ? [checked, arguments[1]] : [checked]);\n };\n }\n let tail = \"\";\n for (const name of [\"write\", \"writeln\"]) {\n const real = w.Document.prototype[name];\n if (typeof real !== \"function\") continue;\n w.Document.prototype[name] = function () {\n let checked = \"\";\n for (let i = 0; i < arguments.length; i++) checked += text(arguments[i]);\n if (shadowed(tail + checked)) refuse();\n tail = apply(slice, tail + checked, [-16]);\n return apply(real, this, [checked]);\n };\n }\n for (const kind of [\"HTMLIFrameElement\", \"HTMLFrameElement\", \"HTMLObjectElement\", \"HTMLEmbedElement\"]) {\n const proto = w[kind] && w[kind].prototype;\n for (const name of [\"contentWindow\", \"contentDocument\", \"getSVGDocument\"]) {\n const found = proto && describe(proto, name);\n const key = found && found.get ? \"get\" : \"value\";\n if (!found || typeof found[key] !== \"function\") continue;\n const read = found[key];\n found[key] = function () {\n const got = apply(read, this, arguments);\n try { shut(name === \"contentWindow\" ? got : apply(view, got, [])); } catch (e) {}\n return got;\n };\n try { define(proto, name, found); } catch (e) {}\n }\n }\n const { getAttribute, setAttribute, removeAttribute, attachShadow } = w.Element.prototype;\n const size = describe(w.NodeList.prototype, \"length\").get;\n const first = (frame) => {\n const doc = apply(getAttribute, frame, [\"srcdoc\"]);\n if (doc === null || apply(slice, doc, [0, own.length]) === own) return;\n try { apply(setAttribute, frame, [\"srcdoc\", own + doc]); } catch (e) { apply(removeAttribute, frame, [\"srcdoc\"]); }\n };\n const Observer = w.MutationObserver;\n const observe = Observer.prototype.observe;\n const watch = (root, all) => {\n const scan = () => {\n try {\n const frames = apply(all, root, [\"iframe[srcdoc]\"]);\n for (let i = apply(size, frames, []); i-- > 0;) first(frames[i]);\n } catch (e) {}\n sweep();\n };\n apply(observe, new Observer(scan), [root, { subtree: true, childList: true, attributes: true, attributeFilter: [\"srcdoc\"] }]);\n scan();\n return root;\n };\n const inShadow = w.DocumentFragment.prototype.querySelectorAll;\n if (attachShadow) {\n w.Element.prototype.attachShadow = function () {\n const root = apply(attachShadow, this, arguments);\n try { watch(root, inShadow); } catch (e) {}\n return root;\n };\n }\n if (w.trustedTypes && w.URL && w.Blob && !describe(w, \"ghostlyWorkerGuard\")) {\n try {\n define(w, \"ghostlyWorkerGuard\", { value: true });\n const construct = Reflect.construct;\n const json = JSON.stringify;\n const later = w.setTimeout;\n const Blob = w.Blob;\n const sized = describe(Blob.prototype, \"size\").get;\n const make = w.URL.createObjectURL;\n const revoke = w.URL.revokeObjectURL;\n const policy = \"if (self.trustedTypes && !self.trustedTypes.defaultPolicy) { try { self.trustedTypes.createPolicy('default', { createHTML: (s) => s, createScript: (s) => s, createScriptURL: (s) => s }); } catch (e) {} }\";\n const script = (code) => apply(make, null, [new Blob([code], { type: \"text/javascript\" })]);\n const known = { __proto__: null };\n let first = null;\n w.URL.createObjectURL = function createObjectURL(object) {\n const made = apply(make, this, arguments);\n try { apply(sized, object, []); known[made] = { blob: object, inner: null, classic: null, module: null }; } catch (e) {}\n return made;\n };\n w.URL.revokeObjectURL = function revokeObjectURL(url) {\n try {\n const key = text(url);\n const entry = known[key];\n if (entry) {\n delete known[key];\n const ours = [entry.inner, entry.classic, entry.module];\n apply(later, w, [() => { for (let i = 0; i < 3; i++) { if (ours[i] !== null) apply(revoke, null, [ours[i]]); } }, 60000]);\n }\n } catch (e) {}\n return apply(revoke, this, arguments);\n };\n const start = (url, options) => {\n const entry = known[text(url)];\n if (!entry) return url;\n const kind = options && typeof options === \"object\" && options.type === \"module\" ? \"module\" : \"classic\";\n if (entry[kind] === null) {\n if (entry.inner === null) entry.inner = apply(make, null, [entry.blob]);\n if (kind === \"module\" && first === null) first = script(policy);\n entry[kind] = script(kind === \"module\" ? \"import \" + json(first) + \"; import \" + json(entry.inner) + \";\" : policy + \" importScripts(\" + json(entry.inner) + \");\");\n }\n return entry[kind];\n };\n for (const name of [\"Worker\", \"SharedWorker\"]) {\n const Real = w[name];\n if (typeof Real !== \"function\") continue;\n const started = function (url) {\n if (new.target === undefined) return apply(Real, this, arguments);\n const args = [];\n for (let i = 0; i < arguments.length; i++) args[i] = arguments[i];\n if (args.length > 0) { try { args[0] = start(url, args[1]); } catch (e) {} }\n return construct(Real, args, new.target);\n };\n define(started, \"name\", { value: name });\n started.prototype = Real.prototype;\n define(Real.prototype, \"constructor\", { value: started, writable: true, enumerable: false, configurable: true });\n w[name] = started;\n }\n } catch (e) {}\n }\n apply(listen, home, [\"load\", sweep, true]);\n watch(home, w.Document.prototype.querySelectorAll);\n } catch (e) {}\n})(window)";
|
|
27
34
|
/** `VIEWER_GUARD_SCRIPT`'s hash, as a CSP source: a contact's own policy that would refuse it is given it (`allowingViewerGuard`). */
|
|
28
|
-
export declare const VIEWER_GUARD_HASH = "'sha256-
|
|
35
|
+
export declare const VIEWER_GUARD_HASH = "'sha256-DweV0mr/eyHFWESxtsRrzk0i6VjF4GSCokjozAiXkbQ='";
|
|
29
36
|
/**
|
|
30
37
|
* With the guard, where it is put in the page and not run by the viewer in every frame: frames only from the app's own
|
|
31
38
|
* origin (a `data:` or `blob:` frame would run before the guard could), and Trusted Types, which hands each
|
|
@@ -1,4 +1,20 @@
|
|
|
1
|
-
import { S as boundVerifiedIdentity, y as IdentityCheckUnavailable } from "./bitcoinAddress-
|
|
1
|
+
import { S as boundVerifiedIdentity, Y as DEFAULT_RELAYS, y as IdentityCheckUnavailable, yt as normalizeRelayUrl } from "./bitcoinAddress-BbPG0DF7.js";
|
|
2
|
+
// ../browser/src/proofs/pkarrRelays.ts
|
|
3
|
+
/**
|
|
4
|
+
* The profile's Pkarr relays (Network settings), which a did:dht proof is read from, as every other Pkarr read: a
|
|
5
|
+
* person who replaced the list is never read from the defaults. The UI and the engine each set where to read it. Here,
|
|
6
|
+
* not in the provider, so setting it does not load the providers.
|
|
7
|
+
*/
|
|
8
|
+
var source = () => void 0;
|
|
9
|
+
function pkarrRelays() {
|
|
10
|
+
const relays = source();
|
|
11
|
+
return relays?.length ? [...relays] : [...DEFAULT_RELAYS];
|
|
12
|
+
}
|
|
13
|
+
/** Whether `url` is under one of the profile's Pkarr relays (`<relay>/…`). */
|
|
14
|
+
function isOwnPkarrRelayUrl(url) {
|
|
15
|
+
if (url.username || url.password) return false;
|
|
16
|
+
return pkarrRelays().map(normalizeRelayUrl).some((relay) => relay !== null && url.href.startsWith(`${relay}/`));
|
|
17
|
+
}
|
|
2
18
|
// ../browser/src/proofs/verify.ts
|
|
3
19
|
var DAY = 86400;
|
|
4
20
|
/**
|
|
@@ -57,14 +73,17 @@ function availableSigners(p, platform) {
|
|
|
57
73
|
* The engine's `ctx.fetch`: HTTPS GET only, no credentials or referrer, a time-out, a size cap,
|
|
58
74
|
* redirects refused unless asked for.
|
|
59
75
|
* `online` false refuses everything (the person turned the network off).
|
|
76
|
+
* A did:dht read of the profile's own Pkarr relays (`ownPkarrRelay`) may be http://, through `relayFetcher`: those are
|
|
77
|
+
* the relays the person chose, as the chats read them, not an address a contact named.
|
|
60
78
|
*/
|
|
61
79
|
function boundedIdentityFetch(options = { online: () => true }) {
|
|
62
|
-
return async (url, { headers, maxBytes = 65536, signal, redirect = "error" } = {}) => {
|
|
80
|
+
return async (url, { headers, maxBytes = 65536, signal, redirect = "error", ownPkarrRelay } = {}) => {
|
|
63
81
|
if (!options.online()) throw new IdentityCheckUnavailable("Offline: this identity cannot be checked now");
|
|
64
82
|
const target = new URL(url);
|
|
65
|
-
|
|
83
|
+
const ownRelay = ownPkarrRelay === true && isOwnPkarrRelayUrl(target);
|
|
84
|
+
if (!ownRelay && (target.protocol !== "https:" || target.username || target.password)) throw new Error("Identity checks use HTTPS only");
|
|
66
85
|
const timeout = AbortSignal.timeout(options.timeoutMs ?? 1e4);
|
|
67
|
-
const response = await (options.fetcher ?? fetch)(target.href, {
|
|
86
|
+
const response = await ((ownRelay ? options.relayFetcher : void 0) ?? options.fetcher ?? fetch)(target.href, {
|
|
68
87
|
headers,
|
|
69
88
|
signal: signal ? AbortSignal.any([signal, timeout]) : timeout,
|
|
70
89
|
credentials: "omit",
|
|
@@ -103,4 +122,4 @@ function boundedIdentityFetch(options = { online: () => true }) {
|
|
|
103
122
|
}
|
|
104
123
|
export { verifyIdentity as i, boundedIdentityFetch as n, descriptorProblems as r, availableSigners as t };
|
|
105
124
|
|
|
106
|
-
//# sourceMappingURL=verify-
|
|
125
|
+
//# sourceMappingURL=verify-BoVhjvc_.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-BoVhjvc_.js","names":[],"sources":["../../browser/src/proofs/pkarrRelays.ts","../../browser/src/proofs/verify.ts"],"sourcesContent":["import { DEFAULT_RELAYS, normalizeRelayUrl } from \"@ghostly/core\";\n\n/**\n * The profile's Pkarr relays (Network settings), which a did:dht proof is read from, as every other Pkarr read: a\n * person who replaced the list is never read from the defaults. The UI and the engine each set where to read it. Here,\n * not in the provider, so setting it does not load the providers.\n */\nlet source: () => readonly string[] | undefined = () => undefined;\nexport function setPkarrRelaySource(read: () => readonly string[] | undefined): void { source = read; }\nexport function pkarrRelays(): string[] {\n const relays = source();\n return relays?.length ? [...relays] : [...DEFAULT_RELAYS];\n}\n\n/** Whether `url` is under one of the profile's Pkarr relays (`<relay>/…`). */\nexport function isOwnPkarrRelayUrl(url: URL): boolean {\n if (url.username || url.password) return false;\n return pkarrRelays().map(normalizeRelayUrl).some(relay => relay !== null && url.href.startsWith(`${relay}/`));\n}\n","import { boundVerifiedIdentity, IdentityCheckUnavailable, IDENTITY_MAX_EVIDENCE, IDENTITY_MAX_VALIDITY, type IdentityStatement, type VerifiedIdentity } from \"@ghostly/core\";\nimport type { IdentityFetch, IdentityProofProvider, IdentitySigner, VerifyContext } from \"./contract\";\nimport { isOwnPkarrRelayUrl } from \"./pkarrRelays\";\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 * A did:dht read of the profile's own Pkarr relays (`ownPkarrRelay`) may be http://, through `relayFetcher`: those are\n * the relays the person chose, as the chats read them, not an address a contact named.\n */\nexport function boundedIdentityFetch(options: { online: () => boolean; timeoutMs?: number; fetcher?: typeof fetch; relayFetcher?: typeof fetch } = { online: () => true }): IdentityFetch {\n return async (url, { headers, maxBytes = 64 * 1024, signal, redirect = \"error\", ownPkarrRelay } = {}) => {\n if (!options.online()) throw new IdentityCheckUnavailable(\"Offline: this identity cannot be checked now\");\n const target = new URL(url);\n const ownRelay = ownPkarrRelay === true && isOwnPkarrRelayUrl(target);\n if (!ownRelay && (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 fetcher = (ownRelay ? options.relayFetcher : undefined) ?? options.fetcher ?? fetch;\n const response = await fetcher(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":";;;;;;;AAOA,IAAI,eAAoD,KAAA;AAExD,SAAgB,cAAwB;CACtC,MAAM,SAAS,OAAO;CACtB,OAAO,QAAQ,SAAS,CAAC,GAAG,MAAM,IAAI,CAAC,GAAG,cAAc;AAC1D;;AAGA,SAAgB,mBAAmB,KAAmB;CACpD,IAAI,IAAI,YAAY,IAAI,UAAU,OAAO;CACzC,OAAO,YAAY,CAAC,CAAC,IAAI,iBAAiB,CAAC,CAAC,MAAK,UAAS,UAAU,QAAQ,IAAI,KAAK,WAAW,GAAG,MAAM,EAAE,CAAC;AAC9G;;ACdA,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,QAA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M;EAE/D,MAAM,WAAW,QADA,WAAW,QAAQ,eAAe,KAAA,MAAc,QAAQ,WAAW,MAAA,CACrD,OAAO,MAAM;GAC1C;GAAS,QAAQ,SAAS,YAAY,IAAI,CAAC,QAAQ,OAAO,CAAC,IAAI;GAC/D,aAAa;GAAQ,gBAAgB;GAAe,OAAO;GAAY;EACzE,CAAC;EACD,IAAI,OAAO,SAAS,QAAQ,IAAI,gBAAgB,CAAC,IAAI,UAAU,MAAM,IAAI,MAAM,mCAAmC;EAClH,MAAM,SAAS,SAAS,MAAM,UAAU;EACxC,MAAM,QAAsB,CAAC;EAC7B,IAAI,SAAS;EACb,IAAI,QACF,IAAI;GACF,SAAS;IACP,MAAM,EAAE,MAAM,UAAU,MAAM,OAAO,KAAK;IAC1C,IAAI,MAAM;IACV,UAAU,MAAM;IAChB,IAAI,SAAS,UAAU,MAAM,IAAI,MAAM,mCAAmC;IAC1E,MAAM,KAAK,KAAK;GAClB;EACF,UAAU;GAAE,MAAM,OAAO,OAAO,CAAC,CAAC,YAAY,CAAC,CAAC;EAAG;EAErD,MAAM,QAAQ,IAAI,WAAW,MAAM;EACnC,IAAI,SAAS;EACb,KAAK,MAAM,QAAQ,OAAO;GAAE,MAAM,IAAI,MAAM,MAAM;GAAG,UAAU,KAAK;EAAQ;EAC5E,OAAO;GAAE,QAAQ,SAAS;GAAQ,aAAa,SAAS,QAAQ,IAAI,cAAc,KAAK;GAAI,MAAM,IAAI,YAAY,CAAC,CAAC,OAAO,KAAK;GAAG;EAAM;CAC1I;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ghostlytools/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.1",
|
|
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",
|