@ghostlytools/sdk 1.11.0 → 1.11.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/core.js +187 -2
- package/dist/core.js.map +1 -1
- package/dist/{fakes-Cu6mpUKs.js → fakes-LaWqqMv4.js} +2 -2
- package/dist/{fakes-Cu6mpUKs.js.map → fakes-LaWqqMv4.js.map} +1 -1
- package/dist/fakes.js +1 -1
- package/dist/index.js +2 -2
- package/dist/{keet-identity-key-DHlSH_39.js → keet-identity-key-CASfmXry.js} +2 -2
- package/dist/{keet-identity-key-DHlSH_39.js.map → keet-identity-key-CASfmXry.js.map} +1 -1
- package/dist/{src-i6IUh-ng.js → src-BN4AAuHI.js} +812 -176
- package/dist/src-BN4AAuHI.js.map +1 -0
- package/dist/testing.js +3 -3
- package/dist/types/core/src/audioMetadata.d.ts +46 -0
- package/dist/types/core/src/clipboardGuard.d.ts +26 -0
- package/dist/types/core/src/groupCommunity.d.ts +7 -1
- package/dist/types/core/src/groupSession.d.ts +7 -1
- package/dist/types/core/src/index.d.ts +2 -0
- package/dist/types/core/src/videoMetadata.d.ts +8 -2
- package/dist/types/core/src/viewerGuard.d.ts +14 -7
- package/dist/{verify-BoaDPIrS.js → verify-oCL662ms.js} +2 -2
- package/dist/{verify-BoaDPIrS.js.map → verify-oCL662ms.js.map} +1 -1
- package/package.json +1 -1
- package/dist/src-i6IUh-ng.js.map +0 -1
package/dist/testing.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Cd as newIdentityBinding, bd as identityStatement, gd as emptyIdentityLedger, ia as isBitcoinAddress, kT as createIdentity, ka as decodeBolt11, nd as IDENTITY_MAX_EVIDENCE, pd as IdentityExchange } from "./src-BN4AAuHI.js";
|
|
2
2
|
import { l as providerDescriptorProblems, o as isNothingSpentError } from "./types-DvtCy3WB.js";
|
|
3
|
-
import { i as verifyIdentity, r as descriptorProblems } from "./verify-
|
|
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-
|
|
3
|
+
import { i as verifyIdentity, r as descriptorProblems } from "./verify-oCL662ms.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-LaWqqMv4.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;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What an audio file leaves with. A recording made in another app, or a song a tagger went through, says more than its
|
|
3
|
+
* sound: a title or a file name that is where it was recorded (a phone's recorder names it after the place), a comment,
|
|
4
|
+
* a location tag, a picture, the date. The sender removes them before the file is stored and its digest computed, as
|
|
5
|
+
* pictures' and videos' are (pictureMetadata.ts, videoMetadata.ts), without decoding or re-encoding a sample, and the
|
|
6
|
+
* file keeps its size, so no offset in it moves and it plays as it did:
|
|
7
|
+
*
|
|
8
|
+
* - MP4 audio (M4A, a voice note recorded in MP4): videoMetadata.ts's box walk, its `udta` and `meta` emptied.
|
|
9
|
+
* - MP3 and AAC: an ID3v2 tag at the start becomes an empty one (its frames zeros: padding), one at the end (with its
|
|
10
|
+
* footer), an APEv2 tag's items, a Lyrics3v2 tag and an ID3v1 tag's fields become zeros.
|
|
11
|
+
* - FLAC: every metadata block but its stream info and seek table (a Vorbis comment, a picture, a cue sheet, an
|
|
12
|
+
* application's) becomes padding, zeroed.
|
|
13
|
+
* - Ogg Opus, Vorbis and Speex: the comment header keeps its vendor (the encoder's name) and has no comment, the bytes
|
|
14
|
+
* after it zeros; each page it changed has its checksum made again.
|
|
15
|
+
* - WAV: every chunk but its format, data and the ones of the sound itself (`fact`, `cue `, `smpl`, `inst`) becomes
|
|
16
|
+
* `JUNK`, zeroed (an INFO list, an `id3 ` chunk, a broadcast `bext` with its date and originator, XMP).
|
|
17
|
+
* - WebM and Matroska, audio or video: `Tags`, `Attachments`, `Chapters`, the title, the date, the file names and each
|
|
18
|
+
* track's name become `Void` elements (and the SeekHead's entries for them); the muxer's and the writing app's names
|
|
19
|
+
* are zeroed. Clusters, cues and track settings are kept as they are.
|
|
20
|
+
*
|
|
21
|
+
* Fail-closed: a file that is one of these by its bytes and whose tags cannot be removed (truncated, malformed) is
|
|
22
|
+
* refused with `NO_AUDIO_METADATA`, never sent as it was. Any other file goes as it is (other audio formats too).
|
|
23
|
+
*/
|
|
24
|
+
import { type VideoPatch, type VideoSource } from "./videoMetadata.js";
|
|
25
|
+
export declare const AUDIO_METADATA_LIMITS: {
|
|
26
|
+
/** The largest header, element or tag read whole (an Ogg comment header with a picture in it): past this the file is refused. */
|
|
27
|
+
readonly maxReadBytes: number;
|
|
28
|
+
/** The most pages, chunks, blocks or elements walked. */
|
|
29
|
+
readonly maxParts: 1000000;
|
|
30
|
+
/** Bytes read first to tell an audio file from another file. */
|
|
31
|
+
readonly headBytes: 64;
|
|
32
|
+
};
|
|
33
|
+
/** Why an audio file is refused: its tags could not be removed, so it does not go at all. */
|
|
34
|
+
export declare const NO_AUDIO_METADATA = "This audio cannot be sent: Ghostly could not remove the details saved in it, like where it was recorded";
|
|
35
|
+
/**
|
|
36
|
+
* What `withoutAudioMetadata` changes in an audio file read from `source` (one not held in a Blob: a file kept in
|
|
37
|
+
* storage): the parts replaced, in order and apart, the rest of its bytes going as they are; undefined when it goes as
|
|
38
|
+
* it is. Throws `NO_AUDIO_METADATA` for one whose tags cannot be removed; an error reading `source` as it is.
|
|
39
|
+
*/
|
|
40
|
+
export declare function audioMetadataPatches(file: VideoSource, mime: string): Promise<VideoPatch[] | undefined>;
|
|
41
|
+
/**
|
|
42
|
+
* `source` as it is sent: an audio file without its tags, made of `source`'s own bytes but for the parts emptied;
|
|
43
|
+
* undefined when it goes as it is (not one of these, or one with nothing to remove). Throws `NO_AUDIO_METADATA` for
|
|
44
|
+
* one whose tags cannot be removed; an error reading `source` as it is.
|
|
45
|
+
*/
|
|
46
|
+
export declare function withoutAudioMetadata(source: Blob, mime: string): Promise<Blob | undefined>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A contact's shared app on the web writes the clipboard only in the person's own tap in it. Its frames allow no
|
|
3
|
+
* `clipboard-write`, but Chromium lets `document.execCommand("copy")` write the system clipboard for as long as a tap's
|
|
4
|
+
* activation lasts (seconds, from a timer too), and no sandbox token or permissions policy turns that off. So this
|
|
5
|
+
* script runs first in each of the app's pages (`guardViewerAnswer`) and in the bridge (apps/web/src/svc/bridge.ts):
|
|
6
|
+
* - `execCommand("copy")` and `execCommand("cut")` work only while a trusted tap, click or key of the person's is being
|
|
7
|
+
* dispatched in that window: a copy button copies on its own tap, and nothing else does (not on load, not from a
|
|
8
|
+
* timer or a promise after a tap). `execCommand("paste")` is refused. Every other command passes as it is. The
|
|
9
|
+
* wrapped `execCommand` is left fixed in place (not writable, not configurable), once per window;
|
|
10
|
+
* - runs in a frame's window before the page holds it, as the WebRTC guard does (`VIEWER_GUARD_SCRIPT`): what a frame
|
|
11
|
+
* element hands out is guarded first, the frames of the document and of its shadow trees are gone over as one loads
|
|
12
|
+
* (an empty frame's first load fires as it is put in the page) and as the page changes, each `srcdoc` frame gets
|
|
13
|
+
* this script first, a declarative shadow root the page's script would make is refused, and with `VIEWER_GUARD_CSP`
|
|
14
|
+
* a `javascript:` URL is refused (its own Trusted Types default policy; one passes every other string on as it is).
|
|
15
|
+
* 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
|
|
16
|
+
* bridge's guard reaches the app's frame then): there this script only watches the new document. Each document it
|
|
17
|
+
* watches is marked (`ghostlyClipboardGuard`, fixed in place): the bridge reads that to know the guard ran in the page
|
|
18
|
+
* it shows. It uses nothing the page can change after it ran (the page's own code runs later, in the same realm).
|
|
19
|
+
*
|
|
20
|
+
* A fence, not a wall, as the WebRTC guard's own: a frame's window read by its index (`window[0]`) before it loads,
|
|
21
|
+
* inside a shadow tree written in the HTML the page itself sends, is out of its sight.
|
|
22
|
+
* No backslash, `${` or backtick in it.
|
|
23
|
+
*/
|
|
24
|
+
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 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 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 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 let tap = null;\n let trusted = null;\n const seen = (event) => {\n try {\n const found = describe(event, \"isTrusted\");\n if (found && found.get && apply(found.get, event, []) === true) { tap = event; trusted = found.get; }\n } catch (e) {}\n };\n const taps = [\"pointerdown\", \"pointerup\", \"mousedown\", \"mouseup\", \"click\", \"auxclick\", \"touchstart\", \"touchend\", \"keydown\", \"keyup\"];\n for (let i = 0; i < taps.length; i++) apply(listen, w, [taps[i], seen, true]);\n const tapping = () => {\n try { return tap !== null && apply(trusted, tap, []) === true && apply(phase, tap, []) !== 0; } catch (e) { 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 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 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)";
|
|
25
|
+
/** `CLIPBOARD_GUARD_SCRIPT`'s hash, as a CSP source: the bridge's policy and a contact's own are given it. */
|
|
26
|
+
export declare const CLIPBOARD_GUARD_HASH = "'sha256-FGs001DxOSnlZv8nm6JyMeex+LlNQJzrCFbnJhAh8n4='";
|
|
@@ -563,7 +563,7 @@ export declare class CommunitySession {
|
|
|
563
563
|
/** My frames said again in this run (`e:h16:n`) → the id of the message they first were. In memory only. */
|
|
564
564
|
private resealedFrom;
|
|
565
565
|
private saveTimer;
|
|
566
|
-
/**
|
|
566
|
+
/** Metadata frames naming a commit or a secret I do not have yet, one signed by the admin and one by anyone else (`waitMeta`): tried again when the chain or my secrets move. */
|
|
567
567
|
private pendingMeta;
|
|
568
568
|
/** The store's frames the app holds with their messages (`storeKey` → message id): in memory here, not in what is saved. */
|
|
569
569
|
private readonly onRows;
|
|
@@ -1095,6 +1095,12 @@ export declare class CommunitySession {
|
|
|
1095
1095
|
* whether it was new, so a hub relays it. One naming what I do not have yet waits for the chain.
|
|
1096
1096
|
*/
|
|
1097
1097
|
private receiveMeta;
|
|
1098
|
+
/**
|
|
1099
|
+
* A statement that waits for the chain: only one its signer signed, so an altered copy cannot push out the one
|
|
1100
|
+
* waiting. The admin I know has a place of their own, which another member's statement cannot take, and in each
|
|
1101
|
+
* place only a later statement takes the one waiting.
|
|
1102
|
+
*/
|
|
1103
|
+
private waitMeta;
|
|
1098
1104
|
/**
|
|
1099
1105
|
* Who made the change a statement brings me (`at`: its commit's place on my main branch): its signer, when they were
|
|
1100
1106
|
* the admin all along since the statement I held (or, with none, since I got in). A new admin signs again what the
|
|
@@ -496,7 +496,7 @@ export declare class GroupSession {
|
|
|
496
496
|
private messagePace;
|
|
497
497
|
private editPace;
|
|
498
498
|
private queue;
|
|
499
|
-
/**
|
|
499
|
+
/** Metadata frames that name a commit or an epoch I do not have yet, one signed by the admin and one by anyone else (`waitMeta`): tried again when the chain moves. */
|
|
500
500
|
private pendingMeta;
|
|
501
501
|
/** While `handle` runs: the frames it took that a hub passes on (`handle`'s result). */
|
|
502
502
|
private passOn;
|
|
@@ -1010,6 +1010,12 @@ export declare class GroupSession {
|
|
|
1010
1010
|
* it names into metadata Ghostly shows. One naming what I do not have yet waits for the chain.
|
|
1011
1011
|
*/
|
|
1012
1012
|
private receiveMeta;
|
|
1013
|
+
/**
|
|
1014
|
+
* A statement that waits for the chain: only one its signer signed, so an altered copy cannot push out the one
|
|
1015
|
+
* waiting. The admin I know has a place of their own, which another member's statement cannot take, and in each
|
|
1016
|
+
* place only a later statement takes the one waiting.
|
|
1017
|
+
*/
|
|
1018
|
+
private waitMeta;
|
|
1013
1019
|
/**
|
|
1014
1020
|
* Who made the change a statement brings me: its signer, when they were the admin all along since the statement I
|
|
1015
1021
|
* held (or, with none, since I got in). A new admin signs again what the last one set (`metaFollowsChain`): to a
|
|
@@ -27,6 +27,7 @@ export * from "./signal.js";
|
|
|
27
27
|
export * from "./frames.js";
|
|
28
28
|
export * from "./http.js";
|
|
29
29
|
export * from "./viewerGuard.js";
|
|
30
|
+
export * from "./clipboardGuard.js";
|
|
30
31
|
export * from "./link.js";
|
|
31
32
|
export * from "./datalink.js";
|
|
32
33
|
export * from "./ghostlink.js";
|
|
@@ -37,6 +38,7 @@ export * from "./video.js";
|
|
|
37
38
|
export * from "./image.js";
|
|
38
39
|
export * from "./pictureMetadata.js";
|
|
39
40
|
export * from "./videoMetadata.js";
|
|
41
|
+
export * from "./audioMetadata.js";
|
|
40
42
|
export * from "./linkPreview.js";
|
|
41
43
|
export * from "./messageTime.js";
|
|
42
44
|
export * from "./payments.js";
|
|
@@ -15,6 +15,12 @@ export interface VideoSource {
|
|
|
15
15
|
size: number;
|
|
16
16
|
read(offset: number, length: number): Promise<Uint8Array>;
|
|
17
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* `source` read a window at a time: a read that fits in `readAhead` bytes reads that many from where it starts, and
|
|
20
|
+
* the reads after it within them (the next boxes' headers, a fragment's `moof`) are served from it, as copies (they
|
|
21
|
+
* are changed in place). A Blob's read costs about the same whatever its size, so a fragment costs one, not three.
|
|
22
|
+
*/
|
|
23
|
+
export declare function readingAhead(source: VideoSource): VideoSource;
|
|
18
24
|
/** A part of a video replaced as it is sent, `start` to `end` of the file: by `bytes`, or by zeros. */
|
|
19
25
|
export interface VideoPatch {
|
|
20
26
|
start: number;
|
|
@@ -30,6 +36,6 @@ export declare function withoutVideoMetadata(source: Blob, mime: string): Promis
|
|
|
30
36
|
/**
|
|
31
37
|
* What `withoutVideoMetadata` changes in a video read from `source` (one not held in a Blob: a file kept in storage):
|
|
32
38
|
* the parts replaced, in order and apart, the rest of its bytes going as they are; undefined when it goes as it is.
|
|
33
|
-
* Throws `NO_VIDEO_METADATA` as it does.
|
|
39
|
+
* Throws `NO_VIDEO_METADATA` as it does. With `audio`, a movie without a video track (an M4A) is stripped too.
|
|
34
40
|
*/
|
|
35
|
-
export declare function videoMetadataPatches(file: VideoSource, mime: string): Promise<VideoPatch[] | undefined>;
|
|
41
|
+
export declare function videoMetadataPatches(file: VideoSource, mime: string, audio?: boolean): Promise<VideoPatch[] | undefined>;
|
|
@@ -32,12 +32,19 @@ export declare const VIEWER_GUARD_HASH = "'sha256-P3jYgJwfoJ/cAS31rQz7Tk99bBwsSe
|
|
|
32
32
|
* `javascript:` URL to the guard's policy before it runs.
|
|
33
33
|
*/
|
|
34
34
|
export declare const VIEWER_GUARD_CSP = "frame-src 'self'; object-src 'self'; require-trusted-types-for 'script'";
|
|
35
|
+
/** A script `guardViewerAnswer` puts first in each page, and its hash, as a CSP source. */
|
|
36
|
+
export interface PageGuard {
|
|
37
|
+
script: string;
|
|
38
|
+
hash: string;
|
|
39
|
+
}
|
|
40
|
+
/** The WebRTC guard, the one `guardViewerAnswer` puts in when it is given none. */
|
|
41
|
+
export declare const WEBRTC_GUARD: PageGuard;
|
|
35
42
|
/**
|
|
36
|
-
* A contact's `Content-Security-Policy` value (one policy or several, joined by commas), each given the
|
|
43
|
+
* A contact's `Content-Security-Policy` value (one policy or several, joined by commas), each given the guards' hashes
|
|
37
44
|
* where it would refuse an inline script: in the directive that governs `<script>` elements (`script-src-elem`, else
|
|
38
45
|
* `script-src`, else `default-src`), unless it lets every inline script run already. Nothing else of it changes.
|
|
39
46
|
*/
|
|
40
|
-
export declare function allowingViewerGuard(value: string): string;
|
|
47
|
+
export declare function allowingViewerGuard(value: string, hashes?: readonly string[]): string;
|
|
41
48
|
/**
|
|
42
49
|
* Where the guard goes in an HTML page that starts with `head`: after a byte order mark, blank space, comments and the
|
|
43
50
|
* doctype (before them the page would turn to quirks mode), so before anything that can run or set a policy. Null when
|
|
@@ -45,14 +52,14 @@ export declare function allowingViewerGuard(value: string): string;
|
|
|
45
52
|
*/
|
|
46
53
|
export declare function viewerGuardOffset(head: Uint8Array, done: boolean): number | null;
|
|
47
54
|
/**
|
|
48
|
-
* A contact's answer as a viewer serves it
|
|
49
|
-
*
|
|
50
|
-
* (`allowingViewerGuard`) and `VIEWER_GUARD_CSP` goes along. A page (`destination`, null when the browser did not say)
|
|
51
|
-
* that is HTML gets the
|
|
55
|
+
* A contact's answer as a viewer serves it where it cannot run `guards` in every frame itself (the web runner; the
|
|
56
|
+
* WebRTC guard while Hide my IP from contacts is on, unless it is given others): the contact's policies take the guards'
|
|
57
|
+
* hashes (`allowingViewerGuard`) and `VIEWER_GUARD_CSP` goes along. A page (`destination`, null when the browser did not say)
|
|
58
|
+
* that is HTML gets the guards first in it, in their order; one they cannot be put in (another type, more than one type, a
|
|
52
59
|
* compressed, UTF-16 or ISO-2022-JP body, a type with a quote or a backslash in it, an escape byte before the guard's
|
|
53
60
|
* place) runs no script at all. Anything that is not a page passes as it was. The caller adds Ghostly's own policy as before.
|
|
54
61
|
*/
|
|
55
|
-
export declare function guardViewerAnswer(headers: HeaderList, body: AsyncIterable<Uint8Array>, destination: string | null): Promise<{
|
|
62
|
+
export declare function guardViewerAnswer(headers: HeaderList, body: AsyncIterable<Uint8Array>, destination: string | null, guards?: readonly PageGuard[]): Promise<{
|
|
56
63
|
headers: HeaderList;
|
|
57
64
|
body: AsyncIterable<Uint8Array>;
|
|
58
65
|
}>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { fd as IdentityCheckUnavailable, hd as boundVerifiedIdentity } from "./src-BN4AAuHI.js";
|
|
2
2
|
//#region ../browser/src/proofs/verify.ts
|
|
3
3
|
var DAY = 86400;
|
|
4
4
|
/**
|
|
@@ -104,4 +104,4 @@ function boundedIdentityFetch(options = { online: () => true }) {
|
|
|
104
104
|
//#endregion
|
|
105
105
|
export { verifyIdentity as i, boundedIdentityFetch as n, descriptorProblems as r, availableSigners as t };
|
|
106
106
|
|
|
107
|
-
//# sourceMappingURL=verify-
|
|
107
|
+
//# sourceMappingURL=verify-oCL662ms.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify-
|
|
1
|
+
{"version":3,"file":"verify-oCL662ms.js","names":[],"sources":["../../browser/src/proofs/verify.ts"],"sourcesContent":["import { boundVerifiedIdentity, IdentityCheckUnavailable, IDENTITY_MAX_EVIDENCE, IDENTITY_MAX_VALIDITY, type IdentityStatement, type VerifiedIdentity } from \"@ghostly/core\";\nimport type { IdentityFetch, IdentityProofProvider, IdentitySigner, VerifyContext } from \"./contract\";\n\nconst DAY = 86_400;\n\n/**\n * The checks every proof goes through, whatever its provider: known provider, validity within the\n * provider's limit, bounded evidence, strict parsing, the provider's own check, and the category rule\n * (a self-custodied proof proves exactly the subject it names; an attested one says who attests it).\n * The engine verifies a contact's proof, and the person's own proof before saving it, only through this.\n */\nexport async function verifyIdentity(providers: readonly IdentityProofProvider[], statement: IdentityStatement, evidence: unknown, ctx: VerifyContext): Promise<VerifiedIdentity> {\n const { binding } = statement;\n const provider = providers.find(p => p.id === binding.provider);\n if (!provider) throw new Error(\"This app cannot verify this kind of identity\");\n if (binding.expiresAt - binding.issuedAt > Math.min(provider.validity.maxDays * DAY, IDENTITY_MAX_VALIDITY)) throw new Error(\"The proof lasts longer than this kind of identity allows\");\n if (JSON.stringify(evidence ?? null).length > IDENTITY_MAX_EVIDENCE) throw new Error(\"Evidence too large\");\n const parsed = provider.parseEvidence(evidence);\n const verified = boundVerifiedIdentity(await provider.verify(statement, parsed, ctx));\n if (provider.category === \"self-custodied\" && verified.subject !== binding.subject) throw new Error(\"The evidence is for another identity\");\n if (provider.category === \"provider-attested\" && !verified.attester) throw new Error(\"The evidence does not say who attests it\");\n return verified;\n}\n\n/** Problems with a provider's descriptor, empty when it is well-formed. The registry and the contract suite use it. */\nexport function descriptorProblems(p: IdentityProofProvider): string[] {\n const problems: string[] = [];\n if (!/^[a-z][a-z0-9-]{0,31}$/.test(p.id)) problems.push(\"id must match ^[a-z][a-z0-9-]{0,31}$\");\n if (!p.label?.trim()) problems.push(\"label is empty\");\n if (!p.description?.trim()) problems.push(\"description is empty\");\n if (!p.privacy?.trim()) problems.push(\"privacy is empty: say what verify contacts\");\n if (p.category !== \"self-custodied\" && p.category !== \"provider-attested\") problems.push(\"category is unknown\");\n if (!p.platforms.length) problems.push(\"no platforms\");\n const { defaultDays, maxDays } = p.validity;\n if (!(Number.isInteger(defaultDays) && Number.isInteger(maxDays) && defaultDays >= 1 && defaultDays <= maxDays && maxDays * DAY <= IDENTITY_MAX_VALIDITY)) problems.push(\"validity must be whole days, 1 ≤ default ≤ max ≤ 400\");\n if (p.recheck && !(Number.isInteger(p.recheck.afterSeconds) && p.recheck.afterSeconds >= 60)) problems.push(\"recheck.afterSeconds must be at least 60\");\n if (p.recheck?.perHour !== undefined && !(Number.isInteger(p.recheck.perHour) && p.recheck.perHour >= 1)) problems.push(\"recheck.perHour must be a whole number, at least 1\");\n if (!p.signers.length) problems.push(\"no signers\");\n const ids = p.signers.map(s => s.id);\n if (new Set(ids).size !== ids.length) problems.push(\"signer ids are not unique\");\n for (const s of p.signers as readonly IdentitySigner<unknown>[]) {\n if (![\"in-app\", \"external-tool\", \"redirect\", \"publish\"].includes(s.kind)) problems.push(`signer ${s.id} has an unknown kind`);\n if (s.kind === \"in-app\" && typeof s.run !== \"function\") problems.push(`signer ${s.id} has no run()`);\n if (s.kind === \"external-tool\" && (typeof s.instructions !== \"function\" || typeof s.parse !== \"function\")) problems.push(`signer ${s.id} needs instructions() and parse()`);\n if (s.kind === \"redirect\" && typeof s.start !== \"function\") problems.push(`signer ${s.id} has no start()`);\n if (s.kind === \"publish\" && (typeof s.instructions !== \"function\" || typeof s.evidence !== \"function\")) problems.push(`signer ${s.id} needs instructions() and evidence()`);\n }\n return problems;\n}\n\n/** Signers of a provider that run on this platform and are available in this window. */\nexport function availableSigners<E>(p: IdentityProofProvider<E>, platform: IdentityProofProvider[\"platforms\"][number]): IdentitySigner<E>[] {\n return p.signers.filter(s => (s.platforms ?? p.platforms).includes(platform) && (s.available?.() ?? true));\n}\n\n/**\n * The engine's `ctx.fetch`: HTTPS GET only, no credentials or referrer, a time-out, a size cap,\n * redirects refused unless asked for.\n * `online` false refuses everything (the person turned the network off).\n */\nexport function boundedIdentityFetch(options: { online: () => boolean; timeoutMs?: number; fetcher?: typeof fetch } = { online: () => true }): IdentityFetch {\n return async (url, { headers, maxBytes = 64 * 1024, signal, redirect = \"error\" } = {}) => {\n if (!options.online()) throw new IdentityCheckUnavailable(\"Offline: this identity cannot be checked now\");\n const target = new URL(url);\n if (target.protocol !== \"https:\" || target.username || target.password) throw new Error(\"Identity checks use HTTPS only\");\n const timeout = AbortSignal.timeout(options.timeoutMs ?? 10_000);\n const response = await (options.fetcher ?? fetch)(target.href, {\n headers, signal: signal ? AbortSignal.any([signal, timeout]) : timeout,\n credentials: \"omit\", referrerPolicy: \"no-referrer\", cache: \"no-store\", redirect,\n });\n if (Number(response.headers.get(\"content-length\")) > maxBytes) throw new Error(\"Identity check response too large\");\n const reader = response.body?.getReader();\n const parts: Uint8Array[] = [];\n let length = 0;\n if (reader) {\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n length += value.length;\n if (length > maxBytes) throw new Error(\"Identity check response too large\");\n parts.push(value);\n }\n } finally { await reader.cancel().catch(() => {}); }\n }\n const bytes = new Uint8Array(length);\n let offset = 0;\n for (const part of parts) { bytes.set(part, offset); offset += part.length; }\n return { status: response.status, contentType: response.headers.get(\"content-type\") ?? \"\", text: new TextDecoder().decode(bytes), bytes };\n };\n}\n"],"mappings":";;AAGA,IAAM,MAAM;;;;;;;AAQZ,eAAsB,eAAe,WAA6C,WAA8B,UAAmB,KAA+C;CAChL,MAAM,EAAE,YAAY;CACpB,MAAM,WAAW,UAAU,MAAK,MAAK,EAAE,OAAO,QAAQ,QAAQ;CAC9D,IAAI,CAAC,UAAU,MAAM,IAAI,MAAM,8CAA8C;CAC7E,IAAI,QAAQ,YAAY,QAAQ,WAAW,KAAK,IAAI,SAAS,SAAS,UAAU,KAAA,MAA0B,GAAG,MAAM,IAAI,MAAM,0DAA0D;CACvL,IAAI,KAAK,UAAU,YAAY,IAAI,CAAC,CAAC,SAAA,OAAgC,MAAM,IAAI,MAAM,oBAAoB;CACzG,MAAM,SAAS,SAAS,cAAc,QAAQ;CAC9C,MAAM,WAAW,sBAAsB,MAAM,SAAS,OAAO,WAAW,QAAQ,GAAG,CA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AQ,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.11.
|
|
3
|
+
"version": "1.11.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",
|