@ghostlytools/sdk 1.12.1 → 1.13.0
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/core.js +416 -30
- package/dist/core.js.map +1 -1
- 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 +18 -0
- package/dist/types/core/src/groupCalls.d.ts +56 -0
- package/dist/types/core/src/relay.d.ts +14 -1
- package/dist/types/core/src/viewerGuard.d.ts +10 -3
- package/package.json +1 -1
|
@@ -318,6 +318,11 @@ export declare class ChatFiles {
|
|
|
318
318
|
private readonly moving;
|
|
319
319
|
/** Files that stopped sending for the chat's window alone: they go on once another's bytes are confirmed. */
|
|
320
320
|
private readonly held;
|
|
321
|
+
/**
|
|
322
|
+
* The entries not ended (`track`): what is still to come or under way is read from these, not from every file the
|
|
323
|
+
* chat ever had, which it keeps for good. An offer read all of them, in every chat, at 100,000 files about 10 ms each.
|
|
324
|
+
*/
|
|
325
|
+
private readonly unended;
|
|
321
326
|
/**
|
|
322
327
|
* Files this side cancelled while no session carried the cancel (`pf-abort`), said on the next one. The session also
|
|
323
328
|
* goes for a moment when a move swaps it (its capabilities are agreed again): unsaid, the receiver showed the file
|
|
@@ -349,6 +354,12 @@ export declare class ChatFiles {
|
|
|
349
354
|
/** What the contact said it can take, on this session. */
|
|
350
355
|
get peerRoom(): number | null;
|
|
351
356
|
records(): FileTransferRecord[];
|
|
357
|
+
/** Bytes still to come of the files taken here, not ended (one still asked about is not taken yet). */
|
|
358
|
+
stillToCome(): number;
|
|
359
|
+
/** A transfer under way: offered, moving, or being checked. */
|
|
360
|
+
underWay(): boolean;
|
|
361
|
+
/** Bytes of the files received here that were taken without asking and are kept (or on their way). */
|
|
362
|
+
takenUnasked(): number;
|
|
352
363
|
get(direction: "in" | "out", id: string): FileTransferRecord | undefined;
|
|
353
364
|
/** Bytes moved so far: confirmed by the receiver (sending), stored (receiving). */
|
|
354
365
|
transferred(direction: "in" | "out", id: string): number;
|
|
@@ -356,6 +367,11 @@ export declare class ChatFiles {
|
|
|
356
367
|
sent(id: string): number;
|
|
357
368
|
private moved;
|
|
358
369
|
private changed;
|
|
370
|
+
/**
|
|
371
|
+
* Keeps `unended` to the entries of this chat not ended. Each change of a record's state is reported (`changed`),
|
|
372
|
+
* so that is where a file that ended leaves it, and one taken or sent again comes back.
|
|
373
|
+
*/
|
|
374
|
+
private track;
|
|
359
375
|
private send;
|
|
360
376
|
private sendData;
|
|
361
377
|
/** A session that agreed files/3 is open: say what fits here, then offer again what is not finished. */
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
* this script first, a declarative shadow root the page's script would make is refused, and with `VIEWER_GUARD_CSP`
|
|
29
29
|
* a `javascript:` URL is refused (its own Trusted Types default policy; one passes every other string on as it is,
|
|
30
30
|
* or, once the page made its own `default` policy, to that one's rules: the page's `createPolicy("default")` gets the
|
|
31
|
-
* guard's policy back with them, and the copy of itself it puts in a `srcdoc` frame skips them)
|
|
31
|
+
* guard's policy back with them, and the copy of itself it puts in a `srcdoc` frame skips them);
|
|
32
|
+
* - starts a worker made from a `blob:` URL of the page's own from a script that makes a pass-through Trusted Types
|
|
33
|
+
* `default` policy in it first, as the WebRTC guard does (`VIEWER_GUARD_SCRIPT`, whichever of the two runs first).
|
|
32
34
|
* A frame's window keeps what was run in it on its first, empty page when the page it loads is of the same origin (the
|
|
33
35
|
* bridge's guard reaches the app's frame then): there this script only watches the new document. Each document it
|
|
34
36
|
* watches is marked (`ghostlyClipboardGuard`, fixed in place): the bridge reads that to know the guard ran in the page
|
|
@@ -38,6 +40,6 @@
|
|
|
38
40
|
* inside a shadow tree written in the HTML the page itself sends, is out of its sight.
|
|
39
41
|
* No backslash, `${` or backtick in it.
|
|
40
42
|
*/
|
|
41
|
-
export declare const CLIPBOARD_GUARD_SCRIPT = "(function noClipboardWrites(w) {\n \"use strict\";\n try {\n const apply = w.Reflect.apply;\n const describe = w.Object.getOwnPropertyDescriptor;\n const define = w.Object.defineProperty;\n const proto = w.Document.prototype;\n const home = w.document;\n const exec = describe(proto, \"execCommand\");\n const fresh = !!exec && exec.configurable === true && typeof exec.value === \"function\";\n const watched = !!describe(home, \"ghostlyClipboardGuard\");\n if (!fresh && watched) return;\n if (!watched) define(home, \"ghostlyClipboardGuard\", { value: true });\n const own = \"<script>(\" + noClipboardWrites + \")(window)<\" + \"/script>\";\n const close = \"<\" + \"/script>\";\n const webRtc = \"<script>(function noWebRtc(\";\n const text = w.String;\n const lower = text.prototype.toLowerCase;\n const slice = text.prototype.slice;\n const index = text.prototype.indexOf;\n const listen = w.EventTarget.prototype.addEventListener;\n const shut = (inner) => {\n try { if (inner && inner !== w) noClipboardWrites(inner); } catch (e) {}\n };\n const count = describe(w, \"length\").get;\n const view = describe(proto, \"defaultView\").get;\n const sweep = () => {\n try { for (let i = apply(count, w, []); i-- > 0;) shut(w[i]); } catch (e) {}\n };\n const elements = w.Element.prototype;\n const getAttribute = elements.getAttribute;\n const setAttribute = elements.setAttribute;\n const removeAttribute = elements.removeAttribute;\n const attachShadow = elements.attachShadow;\n const size = describe(w.NodeList.prototype, \"length\").get;\n let passing = false;\n const first = (frame) => {\n const doc = apply(getAttribute, frame, [\"srcdoc\"]);\n if (doc === null) return;\n let at = 0;\n if (apply(slice, doc, [0, webRtc.length]) === webRtc) {\n const end = apply(index, doc, [close]);\n if (end >= 0) at = end + close.length;\n }\n if (apply(slice, doc, [at, at + own.length]) === own) return;\n passing = true;\n try { apply(setAttribute, frame, [\"srcdoc\", own + doc]); } catch (e) { apply(removeAttribute, frame, [\"srcdoc\"]); }\n passing = false;\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 apply(listen, root, [\"load\", sweep, true]);\n scan();\n return root;\n };\n if (fresh) {\n const run = exec.value;\n const phase = describe(w.Event.prototype, \"eventPhase\").get;\n const trust = (event) => {\n try {\n const found = describe(event, \"isTrusted\");\n if (found && found.get && apply(found.get, event, []) === true) return found.get;\n } catch (e) {}\n return null;\n };\n const dispatching = (event, trusted) => {\n try { return apply(trusted, event, []) === true && apply(phase, event, []) !== 0; } catch (e) { return false; }\n };\n const stamp = describe(w.Event.prototype, \"timeStamp\");\n const clock = w.performance;\n const tick = clock && clock.now;\n const time = () => { try { return apply(tick, clock, []); } catch (e) { return NaN; } };\n const recent = (at) => time() - at <= 1000;\n const shutters = [];\n try {\n const channel = new w.MessageChannel();\n const post = w.MessagePort.prototype.postMessage;\n const out = channel.port2;\n channel.port1.onmessage = () => settle();\n shutters[0] = () => apply(post, out, [0]);\n } catch (e) {}\n try {\n const tasks = w.scheduler;\n const postTask = tasks && tasks.postTask;\n const urgent = { __proto__: null, priority: \"user-blocking\" };\n if (typeof postTask === \"function\") shutters[shutters.length] = () => { apply(postTask, tasks, [settle, urgent]); };\n } catch (e) {}\n try {\n const frame = w.requestAnimationFrame;\n if (typeof frame === \"function\") shutters[shutters.length] = () => { apply(frame, w, [settle]); };\n } catch (e) {}\n let tap = null;\n let trusted = null;\n let tapped = NaN;\n let open = 0;\n let follows = null;\n const settle = () => { open = 0; follows = null; };\n const seen = (event) => {\n const found = trust(event);\n if (found === null) return;\n let at = time();\n try {\n const given = apply(stamp.get, event, []);\n if (given >= 0 && given < at) at = given;\n } catch (e) {}\n tap = event;\n trusted = found;\n tapped = at;\n if (shutters.length === 0) return;\n open = 1;\n for (let i = 0; i < shutters.length; i++) { try { shutters[i](); } catch (e) {} }\n };\n const taps = [\"pointerdown\", \"pointerup\", \"mousedown\", \"mouseup\", \"click\", \"auxclick\", \"dblclick\", \"contextmenu\", \"touchstart\", \"touchend\", \"keydown\", \"keypress\", \"keyup\"];\n for (let i = 0; i < taps.length; i++) apply(listen, w, [taps[i], seen, true]);\n const followed = (event) => {\n if (open === 0) return;\n const found = trust(event);\n if (found !== null) follows = { event: event, trusted: found, at: tapped, next: follows };\n };\n apply(listen, w, [\"submit\", followed, true]);\n apply(listen, w, [\"change\", followed, true]);\n const tapping = () => {\n if (tap !== null && dispatching(tap, trusted) && recent(tapped)) return true;\n for (let f = follows; f !== null; f = f.next) if (dispatching(f.event, f.trusted) && recent(f.at)) return true;\n return false;\n };\n const guarded = function execCommand(command) {\n const name = apply(lower, text(command), []);\n if (name === \"paste\" || ((name === \"copy\" || name === \"cut\") && !tapping())) return false;\n const args = [name];\n for (let i = 1; i < arguments.length; i++) args[i] = arguments[i];\n return apply(run, this, args);\n };\n define(proto, \"execCommand\", { value: guarded, writable: false, enumerable: exec.enumerable, configurable: false });\n const types = w.trustedTypes;\n if (types && !types.defaultPolicy) {\n try {\n let rules = null;\n const rule = (kind) => (input, type, sink) => {\n if (kind === \"createScript\" && sink === \"Location href\") return null;\n if (passing || rules === null) return input;\n return rules[kind] ? apply(rules[kind], undefined, [input, type, sink]) : null;\n };\n const members = [\"createHTML\", \"createScript\", \"createScriptURL\"];\n const create = types.createPolicy;\n const policy = apply(create, types, [\"default\", { createHTML: rule(members[0]), createScript: rule(members[1]), createScriptURL: rule(members[2]) }]);\n const Mistyped = w.TypeError;\n w.Object.getPrototypeOf(types).createPolicy = function createPolicy(name, options) {\n if (this !== types || rules !== null || text(name) !== \"default\") return apply(create, this, arguments);\n const given = { createHTML: null, createScript: null, createScriptURL: null };\n for (let i = 0; i < members.length; i++) {\n const found = options ? options[members[i]] : undefined;\n if (found === undefined || found === null) continue;\n if (typeof found !== \"function\") throw new Mistyped(\"The policy's \" + members[i] + \" is not a function\");\n given[members[i]] = found;\n }\n rules = given;\n return policy;\n };\n } catch (e) {}\n }\n const reopen = proto.open;\n proto.open = function () {\n const got = apply(reopen, this, arguments);\n try { if (apply(view, this, []) === w) apply(listen, this, [\"load\", sweep, true]); } catch (e) {}\n return got;\n };\n const shadowed = (html) => apply(index, apply(lower, html, []), [\"shadowrootmode\"]) >= 0;\n const Refused = w.TypeError;\n const refuse = () => { throw new Refused(\"A declarative shadow root is not allowed here\"); };\n const parsers = [[elements, \"setHTMLUnsafe\"], [w.ShadowRoot && w.ShadowRoot.prototype, \"setHTMLUnsafe\"], [w.Document, \"parseHTMLUnsafe\"]];\n for (let i = 0; i < parsers.length; i++) {\n const owner = parsers[i][0];\n const name = parsers[i][1];\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 const writes = [\"write\", \"writeln\"];\n for (let i = 0; i < writes.length; i++) {\n const real = proto[writes[i]];\n if (typeof real !== \"function\") continue;\n proto[writes[i]] = function () {\n let checked = \"\";\n for (let j = 0; j < arguments.length; j++) checked += text(arguments[j]);\n if (shadowed(tail + checked)) refuse();\n tail = apply(slice, tail + checked, [-16]);\n return apply(real, this, [checked]);\n };\n }\n const kinds = [\"HTMLIFrameElement\", \"HTMLFrameElement\", \"HTMLObjectElement\", \"HTMLEmbedElement\"];\n const reads = [\"contentWindow\", \"contentDocument\", \"getSVGDocument\"];\n for (let k = 0; k < kinds.length; k++) {\n const owner = w[kinds[k]] && w[kinds[k]].prototype;\n for (let r = 0; r < reads.length; r++) {\n const name = reads[r];\n const found = owner && describe(owner, 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(owner, name, found); } catch (e) {}\n }\n }\n const inShadow = w.DocumentFragment.prototype.querySelectorAll;\n if (attachShadow) {\n elements.attachShadow = function () {\n const root = apply(attachShadow, this, arguments);\n try { watch(root, inShadow); } catch (e) {}\n return root;\n };\n }\n }\n if (!watched) watch(home, proto.querySelectorAll);\n } catch (e) {}\n})(window)";
|
|
43
|
+
export declare const CLIPBOARD_GUARD_SCRIPT = "(function noClipboardWrites(w) {\n \"use strict\";\n try {\n const apply = w.Reflect.apply;\n const describe = w.Object.getOwnPropertyDescriptor;\n const define = w.Object.defineProperty;\n const proto = w.Document.prototype;\n const home = w.document;\n const exec = describe(proto, \"execCommand\");\n const fresh = !!exec && exec.configurable === true && typeof exec.value === \"function\";\n const watched = !!describe(home, \"ghostlyClipboardGuard\");\n if (!fresh && watched) return;\n if (!watched) define(home, \"ghostlyClipboardGuard\", { value: true });\n const own = \"<script>(\" + noClipboardWrites + \")(window)<\" + \"/script>\";\n const close = \"<\" + \"/script>\";\n const webRtc = \"<script>(function noWebRtc(\";\n const text = w.String;\n const lower = text.prototype.toLowerCase;\n const slice = text.prototype.slice;\n const index = text.prototype.indexOf;\n const listen = w.EventTarget.prototype.addEventListener;\n const shut = (inner) => {\n try { if (inner && inner !== w) noClipboardWrites(inner); } catch (e) {}\n };\n const count = describe(w, \"length\").get;\n const view = describe(proto, \"defaultView\").get;\n const sweep = () => {\n try { for (let i = apply(count, w, []); i-- > 0;) shut(w[i]); } catch (e) {}\n };\n const elements = w.Element.prototype;\n const getAttribute = elements.getAttribute;\n const setAttribute = elements.setAttribute;\n const removeAttribute = elements.removeAttribute;\n const attachShadow = elements.attachShadow;\n const size = describe(w.NodeList.prototype, \"length\").get;\n let passing = false;\n const first = (frame) => {\n const doc = apply(getAttribute, frame, [\"srcdoc\"]);\n if (doc === null) return;\n let at = 0;\n if (apply(slice, doc, [0, webRtc.length]) === webRtc) {\n const end = apply(index, doc, [close]);\n if (end >= 0) at = end + close.length;\n }\n if (apply(slice, doc, [at, at + own.length]) === own) return;\n passing = true;\n try { apply(setAttribute, frame, [\"srcdoc\", own + doc]); } catch (e) { apply(removeAttribute, frame, [\"srcdoc\"]); }\n passing = false;\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 apply(listen, root, [\"load\", sweep, true]);\n scan();\n return root;\n };\n if (fresh) {\n const run = exec.value;\n const phase = describe(w.Event.prototype, \"eventPhase\").get;\n const trust = (event) => {\n try {\n const found = describe(event, \"isTrusted\");\n if (found && found.get && apply(found.get, event, []) === true) return found.get;\n } catch (e) {}\n return null;\n };\n const dispatching = (event, trusted) => {\n try { return apply(trusted, event, []) === true && apply(phase, event, []) !== 0; } catch (e) { return false; }\n };\n const stamp = describe(w.Event.prototype, \"timeStamp\");\n const clock = w.performance;\n const tick = clock && clock.now;\n const time = () => { try { return apply(tick, clock, []); } catch (e) { return NaN; } };\n const recent = (at) => time() - at <= 1000;\n const shutters = [];\n try {\n const channel = new w.MessageChannel();\n const post = w.MessagePort.prototype.postMessage;\n const out = channel.port2;\n channel.port1.onmessage = () => settle();\n shutters[0] = () => apply(post, out, [0]);\n } catch (e) {}\n try {\n const tasks = w.scheduler;\n const postTask = tasks && tasks.postTask;\n const urgent = { __proto__: null, priority: \"user-blocking\" };\n if (typeof postTask === \"function\") shutters[shutters.length] = () => { apply(postTask, tasks, [settle, urgent]); };\n } catch (e) {}\n try {\n const frame = w.requestAnimationFrame;\n if (typeof frame === \"function\") shutters[shutters.length] = () => { apply(frame, w, [settle]); };\n } catch (e) {}\n let tap = null;\n let trusted = null;\n let tapped = NaN;\n let open = 0;\n let follows = null;\n const settle = () => { open = 0; follows = null; };\n const seen = (event) => {\n const found = trust(event);\n if (found === null) return;\n let at = time();\n try {\n const given = apply(stamp.get, event, []);\n if (given >= 0 && given < at) at = given;\n } catch (e) {}\n tap = event;\n trusted = found;\n tapped = at;\n if (shutters.length === 0) return;\n open = 1;\n for (let i = 0; i < shutters.length; i++) { try { shutters[i](); } catch (e) {} }\n };\n const taps = [\"pointerdown\", \"pointerup\", \"mousedown\", \"mouseup\", \"click\", \"auxclick\", \"dblclick\", \"contextmenu\", \"touchstart\", \"touchend\", \"keydown\", \"keypress\", \"keyup\"];\n for (let i = 0; i < taps.length; i++) apply(listen, w, [taps[i], seen, true]);\n const followed = (event) => {\n if (open === 0) return;\n const found = trust(event);\n if (found !== null) follows = { event: event, trusted: found, at: tapped, next: follows };\n };\n apply(listen, w, [\"submit\", followed, true]);\n apply(listen, w, [\"change\", followed, true]);\n const tapping = () => {\n if (tap !== null && dispatching(tap, trusted) && recent(tapped)) return true;\n for (let f = follows; f !== null; f = f.next) if (dispatching(f.event, f.trusted) && recent(f.at)) return true;\n return false;\n };\n const guarded = function execCommand(command) {\n const name = apply(lower, text(command), []);\n if (name === \"paste\" || ((name === \"copy\" || name === \"cut\") && !tapping())) return false;\n const args = [name];\n for (let i = 1; i < arguments.length; i++) args[i] = arguments[i];\n return apply(run, this, args);\n };\n define(proto, \"execCommand\", { value: guarded, writable: false, enumerable: exec.enumerable, configurable: false });\n const types = w.trustedTypes;\n if (types && !types.defaultPolicy) {\n try {\n let rules = null;\n const rule = (kind) => (input, type, sink) => {\n if (kind === \"createScript\" && sink === \"Location href\") return null;\n if (passing || rules === null) return input;\n return rules[kind] ? apply(rules[kind], undefined, [input, type, sink]) : null;\n };\n const members = [\"createHTML\", \"createScript\", \"createScriptURL\"];\n const create = types.createPolicy;\n const policy = apply(create, types, [\"default\", { createHTML: rule(members[0]), createScript: rule(members[1]), createScriptURL: rule(members[2]) }]);\n const Mistyped = w.TypeError;\n w.Object.getPrototypeOf(types).createPolicy = function createPolicy(name, options) {\n if (this !== types || rules !== null || text(name) !== \"default\") return apply(create, this, arguments);\n const given = { createHTML: null, createScript: null, createScriptURL: null };\n for (let i = 0; i < members.length; i++) {\n const found = options ? options[members[i]] : undefined;\n if (found === undefined || found === null) continue;\n if (typeof found !== \"function\") throw new Mistyped(\"The policy's \" + members[i] + \" is not a function\");\n given[members[i]] = found;\n }\n rules = given;\n return policy;\n };\n } catch (e) {}\n }\n if (types && w.URL && w.Blob && !describe(w, \"ghostlyWorkerGuard\")) {\n try {\n define(w, \"ghostlyWorkerGuard\", { value: true });\n const construct = w.Reflect.construct;\n const json = w.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 const makers = [\"Worker\", \"SharedWorker\"];\n for (let i = 0; i < makers.length; i++) {\n const Real = w[makers[i]];\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 j = 0; j < arguments.length; j++) args[j] = arguments[j];\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: makers[i] });\n started.prototype = Real.prototype;\n define(Real.prototype, \"constructor\", { value: started, writable: true, enumerable: false, configurable: true });\n w[makers[i]] = started;\n }\n } catch (e) {}\n }\n const reopen = proto.open;\n proto.open = function () {\n const got = apply(reopen, this, arguments);\n try { if (apply(view, this, []) === w) apply(listen, this, [\"load\", sweep, true]); } catch (e) {}\n return got;\n };\n const shadowed = (html) => apply(index, apply(lower, html, []), [\"shadowrootmode\"]) >= 0;\n const Refused = w.TypeError;\n const refuse = () => { throw new Refused(\"A declarative shadow root is not allowed here\"); };\n const parsers = [[elements, \"setHTMLUnsafe\"], [w.ShadowRoot && w.ShadowRoot.prototype, \"setHTMLUnsafe\"], [w.Document, \"parseHTMLUnsafe\"]];\n for (let i = 0; i < parsers.length; i++) {\n const owner = parsers[i][0];\n const name = parsers[i][1];\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 const writes = [\"write\", \"writeln\"];\n for (let i = 0; i < writes.length; i++) {\n const real = proto[writes[i]];\n if (typeof real !== \"function\") continue;\n proto[writes[i]] = function () {\n let checked = \"\";\n for (let j = 0; j < arguments.length; j++) checked += text(arguments[j]);\n if (shadowed(tail + checked)) refuse();\n tail = apply(slice, tail + checked, [-16]);\n return apply(real, this, [checked]);\n };\n }\n const kinds = [\"HTMLIFrameElement\", \"HTMLFrameElement\", \"HTMLObjectElement\", \"HTMLEmbedElement\"];\n const reads = [\"contentWindow\", \"contentDocument\", \"getSVGDocument\"];\n for (let k = 0; k < kinds.length; k++) {\n const owner = w[kinds[k]] && w[kinds[k]].prototype;\n for (let r = 0; r < reads.length; r++) {\n const name = reads[r];\n const found = owner && describe(owner, 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(owner, name, found); } catch (e) {}\n }\n }\n const inShadow = w.DocumentFragment.prototype.querySelectorAll;\n if (attachShadow) {\n elements.attachShadow = function () {\n const root = apply(attachShadow, this, arguments);\n try { watch(root, inShadow); } catch (e) {}\n return root;\n };\n }\n }\n if (!watched) watch(home, proto.querySelectorAll);\n } catch (e) {}\n})(window)";
|
|
42
44
|
/** `CLIPBOARD_GUARD_SCRIPT`'s hash, as a CSP source: the bridge's policy and a contact's own are given it. */
|
|
43
|
-
export declare const CLIPBOARD_GUARD_HASH = "'sha256-
|
|
45
|
+
export declare const CLIPBOARD_GUARD_HASH = "'sha256-D8U3zSg1xP77RbZuV/DekRuM6nx80gIN5mh2TQAtZ40='";
|
|
@@ -208,6 +208,8 @@ export declare class DhtDelivery {
|
|
|
208
208
|
* one any more), not at the next keep-alive four minutes on. Any envelope that goes out replaces it.
|
|
209
209
|
*/
|
|
210
210
|
private withdrawal?;
|
|
211
|
+
/** When the last withdrawal's envelope went (its `lastPublish`), for `withdrawalWaits`. */
|
|
212
|
+
private withdrewAt;
|
|
211
213
|
/** The sequence of the last envelope of the contact that was past its expiry (traced once). */
|
|
212
214
|
private expiredSeen;
|
|
213
215
|
private controlDue;
|
|
@@ -249,6 +251,8 @@ export declare class DhtDelivery {
|
|
|
249
251
|
private namedRev?;
|
|
250
252
|
/** A reaction of this side waits to ride on an envelope, or the contact's reactions wait to be said taken. */
|
|
251
253
|
private reactionsDue;
|
|
254
|
+
/** The text on the floor whose envelope left the reactions no room (its id): they wait for the ones its backoff publishes. */
|
|
255
|
+
private crowdedBy?;
|
|
252
256
|
constructor(options: {
|
|
253
257
|
params: LinkParams;
|
|
254
258
|
mode: DeliveryMode;
|
|
@@ -462,8 +466,17 @@ export declare class DhtDelivery {
|
|
|
462
466
|
* one's place on the relays, so a contact who looks later finds no text. Resolves once the state without it is saved;
|
|
463
467
|
* the new envelope goes after. One that does not go (no relay reachable) is tried again within seconds (`withdrawal`):
|
|
464
468
|
* a reader takes the withdrawn envelope until its expiry and the clock skew allowed past it (`DHT_EXPIRY_SKEW_MS`).
|
|
469
|
+
* It goes at once, spacing or not: the deleted text is out of reach from then on. The text that takes the floor next
|
|
470
|
+
* waits out the spacing instead (`withdrawalWaits`).
|
|
465
471
|
*/
|
|
466
472
|
withdraw(wireId: string): Promise<void>;
|
|
473
|
+
/**
|
|
474
|
+
* The last envelope was a withdrawal's, inside the publication spacing: the text that takes the floor now goes once
|
|
475
|
+
* the spacing allows (`schedule`), not in an envelope of its own at once. Deleted then, it never went, so it costs
|
|
476
|
+
* no withdrawal: deleting 10 texts queued for an away contact one after the other, each one's withdrawal and the next
|
|
477
|
+
* text's envelope put 10 envelopes on every relay in under 2 s, each replaced a moment later (bug hunt, 2026-11-15).
|
|
478
|
+
*/
|
|
479
|
+
private withdrawalWaits;
|
|
467
480
|
/** The id of what awaits its receipt on the floor now, if anything does. */
|
|
468
481
|
get pendingId(): string | undefined;
|
|
469
482
|
/**
|
|
@@ -488,6 +501,11 @@ export declare class DhtDelivery {
|
|
|
488
501
|
private publish;
|
|
489
502
|
/** The contact is pinned and this side's envelope in the invite's mailbox is still unsealed (`unsealedOut`). */
|
|
490
503
|
private get resealDue();
|
|
504
|
+
/**
|
|
505
|
+
* Reactions due (`reactionsDue`) that force an envelope of their own: not while the text that left them no room
|
|
506
|
+
* (`crowdedBy`) is still retried, or each publication spends one of its attempts 4 s apart instead of at its backoff.
|
|
507
|
+
*/
|
|
508
|
+
private get reactionsPress();
|
|
491
509
|
/**
|
|
492
510
|
* The relays' request budget held the envelope back: nothing went out, so it was no attempt (a text keeps its eight),
|
|
493
511
|
* and what it carried (a text, a receipt, a new mode) goes the moment the budget frees a request: the text and the
|
|
@@ -54,3 +54,59 @@ export declare function verifyGroupCallRequest(raw: unknown, sfu: string, now: n
|
|
|
54
54
|
ok: false;
|
|
55
55
|
reason: GroupCallRefusal;
|
|
56
56
|
};
|
|
57
|
+
/**
|
|
58
|
+
* An admin's request to act on a member in its group's call (WISP 602 · Group Calls § Moderation): what it sends to
|
|
59
|
+
* `POST <sfu>/sfu/group-moderate`, signed by its group key over the node's origin as a token request is, under its own
|
|
60
|
+
* tag, so neither request can stand for the other.
|
|
61
|
+
*
|
|
62
|
+
* {"v":1,"g":"<group>","k":"<admin key>","room":"g_<group>","act":"mute","target":"<member key>","src":["microphone"],
|
|
63
|
+
* "ts":1794700800,"n":"<nonce>","sig":"…"}
|
|
64
|
+
*
|
|
65
|
+
* `mute` takes `src` away from `target`, `allow` gives it back, `remove` takes `target` out of the call and keeps it
|
|
66
|
+
* out, `unban` lets it back in, and `state` changes nothing (the reply says who is muted and banned). Whether `k` is
|
|
67
|
+
* the group's admin is the node's to say, from its roster.
|
|
68
|
+
*/
|
|
69
|
+
/** What an admin can take from a member, in the sorted order a request lists them in. */
|
|
70
|
+
export declare const GROUP_CALL_SOURCES: readonly ["camera", "microphone", "screen_share"];
|
|
71
|
+
export type GroupCallSource = (typeof GROUP_CALL_SOURCES)[number];
|
|
72
|
+
export declare const GROUP_CALL_MODERATION_ACTS: readonly ["mute", "allow", "remove", "unban", "state"];
|
|
73
|
+
export type GroupCallModerationAct = (typeof GROUP_CALL_MODERATION_ACTS)[number];
|
|
74
|
+
export interface GroupCallModeration {
|
|
75
|
+
v: typeof GROUP_CALL_VERSION;
|
|
76
|
+
g: string;
|
|
77
|
+
k: string;
|
|
78
|
+
room: string;
|
|
79
|
+
act: GroupCallModerationAct;
|
|
80
|
+
/** The member acted on; `""` for `state`. */
|
|
81
|
+
target: string;
|
|
82
|
+
/** Non-empty, unique and sorted for `mute` and `allow`; empty for the other acts. */
|
|
83
|
+
src: GroupCallSource[];
|
|
84
|
+
ts: number;
|
|
85
|
+
n: string;
|
|
86
|
+
sig: string;
|
|
87
|
+
}
|
|
88
|
+
/** Exactly the bytes an admin signs: the array form, as the token request's. */
|
|
89
|
+
export declare const groupCallModerationBytes: (sfu: string, g: string, room: string, k: string, act: GroupCallModerationAct, target: string, src: readonly GroupCallSource[], ts: number, n: string) => Uint8Array<ArrayBufferLike>;
|
|
90
|
+
/** A moderation request for `sfu`, signed by the admin's group key `seed`; `src` is listed unique and sorted. */
|
|
91
|
+
export declare function signGroupCallModeration(input: {
|
|
92
|
+
sfu: string;
|
|
93
|
+
g: string;
|
|
94
|
+
act: GroupCallModerationAct;
|
|
95
|
+
target?: string;
|
|
96
|
+
src?: readonly GroupCallSource[];
|
|
97
|
+
ts?: number;
|
|
98
|
+
n?: string;
|
|
99
|
+
}, seed: Uint8Array): GroupCallModeration;
|
|
100
|
+
/**
|
|
101
|
+
* The node's checks of a moderation request but the roster, in order: the shape (a known act, a `target` that is a
|
|
102
|
+
* member key other than `k`, or `""` for `state`, and `src` as the act takes it), the time within `GROUP_CALL_SKEW_S`
|
|
103
|
+
* of `now` (ms), a nonce not in `seen`, and the signature over the node's own origin `sfu`. A request that passes has
|
|
104
|
+
* its nonce added to `seen`; entries older than `GROUP_CALL_NONCE_S` are dropped on the way.
|
|
105
|
+
*/
|
|
106
|
+
export declare function verifyGroupCallModeration(raw: unknown, sfu: string, now: number, seen: GroupCallNonces): {
|
|
107
|
+
ok: true;
|
|
108
|
+
request: GroupCallModeration;
|
|
109
|
+
} | {
|
|
110
|
+
ok: false;
|
|
111
|
+
reason: GroupCallRefusal;
|
|
112
|
+
};
|
|
@@ -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`). */
|
|
@@ -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
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ghostlytools/sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0",
|
|
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",
|