@ghostlytools/sdk 1.4.4 → 1.5.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/app.js +15 -7
- package/dist/app.js.map +1 -1
- package/dist/core.js +2 -2
- package/dist/{fakes-Cg-kTSO_.js → fakes-CdgaBLS1.js} +2 -2
- package/dist/{fakes-Cg-kTSO_.js.map → fakes-CdgaBLS1.js.map} +1 -1
- package/dist/fakes.js +1 -1
- package/dist/index.js +2 -2
- package/dist/{keet-identity-key-BHXtiqy8.js → keet-identity-key-D_bUxyiq.js} +2 -2
- package/dist/{keet-identity-key-BHXtiqy8.js.map → keet-identity-key-D_bUxyiq.js.map} +1 -1
- package/dist/{src-BdAF18HA.js → src-D9oJLTXM.js} +863 -83
- package/dist/src-D9oJLTXM.js.map +1 -0
- package/dist/testing.js +3 -3
- package/dist/types/core/src/callSignal.d.ts +33 -4
- package/dist/types/core/src/catchUp.d.ts +18 -5
- package/dist/types/core/src/dhtDelivery.d.ts +4 -4
- package/dist/types/core/src/ghostlink.d.ts +54 -1
- package/dist/types/core/src/groupCommunity.d.ts +27 -3
- package/dist/types/core/src/groupEdits.d.ts +6 -0
- package/dist/types/core/src/groupSession.d.ts +6 -3
- package/dist/types/core/src/index.d.ts +1 -0
- package/dist/types/core/src/miniApp.d.ts +39 -9
- package/dist/types/core/src/pairedAppRanges.d.ts +188 -0
- package/dist/types/core/src/pairedCapabilities.d.ts +6 -1
- package/dist/types/core/src/pairedEdits.d.ts +14 -1
- package/dist/types/core/src/relay.d.ts +12 -1
- package/dist/types/core/src/relayBreaker.d.ts +7 -2
- package/dist/types/core/src/signal.d.ts +4 -1
- package/dist/types/core/src/statusCards.d.ts +21 -1
- package/dist/{verify-BUV-kmKL.js → verify-DMeDznOh.js} +2 -2
- package/dist/{verify-BUV-kmKL.js.map → verify-DMeDznOh.js.map} +1 -1
- package/package.json +1 -1
- package/dist/src-BdAF18HA.js.map +0 -1
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import { isChatAppId } from "./pairedApps.js";
|
|
2
|
+
/**
|
|
3
|
+
* The read lane of mini-apps in a 1:1 chat (WISP 1200 § A read lane to the contact: `app-ranges/1`): the contact's app
|
|
4
|
+
* reads, in ranges, a file this side's app serves, over the chat's session but not through `apps/1`.
|
|
5
|
+
*
|
|
6
|
+
* {"t":"ar-get","a":"<chat app id>","s":"<serve id>","r":7,"o":0,"n":1048576}
|
|
7
|
+
* {"t":"ar-data","a":"<chat app id>","r":7,"o":0,"d":"<base64url>"}
|
|
8
|
+
* {"t":"ar-end","a":"<chat app id>","r":7,"z":734003200}
|
|
9
|
+
* {"t":"ar-err","a":"<chat app id>","r":7,"e":"not-served"}
|
|
10
|
+
* {"t":"ar-cancel","a":"<chat app id>","r":7}
|
|
11
|
+
*
|
|
12
|
+
* The asker sends `ar-get` (request `r`, a number of its own, for `n` bytes at offset `o` of serve `s`) and may send
|
|
13
|
+
* `ar-cancel`; the server answers with the bytes in chunks of at most `APP_RANGE_LIMITS.chunkBytes`, then `ar-end`
|
|
14
|
+
* once every byte asked was sent (fewer at the end of the file), with `z` the served file's size, or `ar-err` instead of
|
|
15
|
+
* any. A read of one byte at 0 is how the asker learns the size. Where `files/4` is on,
|
|
16
|
+
* a chunk is a binary message of kind `APP_RANGE_DATA_KIND` (`encodeAppRangeData`) in place of `ar-data`. It needs
|
|
17
|
+
* `app-ranges/1` in `paired-capabilities` on both sides. A reader ignores keys it does not know, so a later version
|
|
18
|
+
* can add some.
|
|
19
|
+
*/
|
|
20
|
+
export declare const APP_RANGE_FRAMES: Set<string>;
|
|
21
|
+
export declare const APP_RANGE_LIMITS: {
|
|
22
|
+
/** One `ar-get`, at most: as one `remote.read` of the app. */
|
|
23
|
+
readonly requestBytes: number;
|
|
24
|
+
/** One chunk, `ar-data` or binary: as a chat file's. */
|
|
25
|
+
readonly chunkBytes: number;
|
|
26
|
+
/** The largest request number: it is 4 bytes in a binary chunk. */
|
|
27
|
+
readonly maxRequest: 4294967295;
|
|
28
|
+
/** Requests a server takes in flight per app; one more is answered `busy`. An asker keeps the rest waiting. */
|
|
29
|
+
readonly inFlight: 4;
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* What an `ar-err` says. `not-served`: no serve of that id on this session (never given, or ended); `changed` and
|
|
33
|
+
* `gone`: the file under it, as `files.read` says them; `busy`: past the requests the server takes in flight. A
|
|
34
|
+
* later version may add one: an asker reads a code it does not know as a failure.
|
|
35
|
+
*/
|
|
36
|
+
export declare const APP_RANGE_ERRORS: readonly ["not-served", "changed", "gone", "busy"];
|
|
37
|
+
export type AppRangeError = typeof APP_RANGE_ERRORS[number];
|
|
38
|
+
export type AppRangeFrame = {
|
|
39
|
+
t: "ar-get";
|
|
40
|
+
a: string;
|
|
41
|
+
s: string;
|
|
42
|
+
r: number;
|
|
43
|
+
o: number;
|
|
44
|
+
n: number;
|
|
45
|
+
} | {
|
|
46
|
+
t: "ar-data";
|
|
47
|
+
a: string;
|
|
48
|
+
r: number;
|
|
49
|
+
o: number;
|
|
50
|
+
d: string;
|
|
51
|
+
} | {
|
|
52
|
+
t: "ar-end";
|
|
53
|
+
a: string;
|
|
54
|
+
r: number;
|
|
55
|
+
z: number;
|
|
56
|
+
} | {
|
|
57
|
+
t: "ar-err";
|
|
58
|
+
a: string;
|
|
59
|
+
r: number;
|
|
60
|
+
e: string;
|
|
61
|
+
} | {
|
|
62
|
+
t: "ar-cancel";
|
|
63
|
+
a: string;
|
|
64
|
+
r: number;
|
|
65
|
+
};
|
|
66
|
+
/** Why a reader refuses an `ar-*` frame (the vectors' `refusal`). */
|
|
67
|
+
export type AppRangeRefusal = "not-ranges" | "bad-a" | "bad-s" | "bad-r" | "bad-o" | "bad-n" | "bad-d" | "bad-e" | "bad-z";
|
|
68
|
+
/** A serve id as it is on the wire: 22 base64url characters (16 random bytes, no padding), as a chat app id. */
|
|
69
|
+
export declare const isServeId: typeof isChatAppId;
|
|
70
|
+
/** The bytes of `d`, or null when it is not 1 to `chunkBytes` bytes of canonical base64url without padding. */
|
|
71
|
+
export declare function appRangeChunk(d: unknown): Uint8Array | null;
|
|
72
|
+
export declare function appRangeGetFrame(app: string, serve: string, request: number, offset: number, length: number): AppRangeFrame;
|
|
73
|
+
export declare function appRangeDataFrame(app: string, request: number, offset: number, data: Uint8Array): AppRangeFrame;
|
|
74
|
+
export declare function appRangeEndFrame(app: string, request: number, size: number): AppRangeFrame;
|
|
75
|
+
export declare function appRangeErrorFrame(app: string, request: number, error: AppRangeError): AppRangeFrame;
|
|
76
|
+
export declare function appRangeCancelFrame(app: string, request: number): AppRangeFrame;
|
|
77
|
+
/**
|
|
78
|
+
* An `ar-*` frame as the peer sent it, or why a reader must refuse it: an unknown `t`, no valid `a`, an `ar-get`
|
|
79
|
+
* without a valid `s`, a request number that is not 0 to 2^32 - 1, an offset that is not a safe whole number at or
|
|
80
|
+
* above 0, an `n` that is not 1 to `requestBytes` (or runs past 2^53 - 1), a `d` that is not 1 to `chunkBytes` bytes of
|
|
81
|
+
* canonical base64url, an `e` that is not a code (lower case letters and `-`, at most 32), an `ar-end` whose `z` is not
|
|
82
|
+
* a size (a safe whole number at or above 0). Other keys are ignored.
|
|
83
|
+
*/
|
|
84
|
+
export declare function readAppRangeFrame(frame: Record<string, unknown>): {
|
|
85
|
+
ok: true;
|
|
86
|
+
frame: AppRangeFrame;
|
|
87
|
+
} | {
|
|
88
|
+
ok: false;
|
|
89
|
+
refusal: AppRangeRefusal;
|
|
90
|
+
};
|
|
91
|
+
/** An `ar-*` frame as the peer sent it, or null when a reader must refuse it (`readAppRangeFrame` says why). */
|
|
92
|
+
export declare function parseAppRangeFrame(frame: Record<string, unknown>): AppRangeFrame | null;
|
|
93
|
+
/**
|
|
94
|
+
* `app-ranges/1` beside `files/4` (WISP 100 § Text and binary messages): a chunk as one binary message of the session,
|
|
95
|
+
* in place of the base64url text of an `ar-data` frame:
|
|
96
|
+
*
|
|
97
|
+
* kind 0x05 (1) | chat app id (16) | request (4, big endian) | offset (8, big endian) | data (1 to `chunkBytes`)
|
|
98
|
+
*/
|
|
99
|
+
export declare const APP_RANGE_DATA_KIND = 5;
|
|
100
|
+
/** The binary message for the bytes of request `request` of app `app` at `offset`. Throws on what no receiver would take. */
|
|
101
|
+
export declare function encodeAppRangeData(app: string, request: number, offset: number, data: Uint8Array): Uint8Array;
|
|
102
|
+
/** What a binary message from the contact says, or null when it is not well-formed app range data. `data` is a view of `message`. */
|
|
103
|
+
export declare function decodeAppRangeData(message: Uint8Array): {
|
|
104
|
+
a: string;
|
|
105
|
+
r: number;
|
|
106
|
+
o: number;
|
|
107
|
+
data: Uint8Array;
|
|
108
|
+
} | null;
|
|
109
|
+
/** Why a read of the contact's file failed, as the app hears it (a broker code). */
|
|
110
|
+
export type AppRangeReadError = "not-served" | "changed" | "gone" | "offline" | "peer-closed" | "failed";
|
|
111
|
+
/** A request of the contact's to answer: read `length` bytes of `file` at `offset`, send them, then `finish`. */
|
|
112
|
+
export interface AppRangeTask {
|
|
113
|
+
readonly app: string;
|
|
114
|
+
readonly request: number;
|
|
115
|
+
/** The serve id it came under: the page that served it answers it. */
|
|
116
|
+
readonly serve: string;
|
|
117
|
+
/** What this side's app served, as it named it (a linked file's id). */
|
|
118
|
+
readonly file: string;
|
|
119
|
+
readonly offset: number;
|
|
120
|
+
readonly length: number;
|
|
121
|
+
/**
|
|
122
|
+
* False once the asker cancelled, the app closed or the session ended: send nothing more for it. A task the asker
|
|
123
|
+
* cancelled still holds its place among the app's `inFlight` until it is settled (`finish`, `fail` or `release`).
|
|
124
|
+
*/
|
|
125
|
+
readonly live: boolean;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The read lane of one chat, both ways (WISP 1200 § A read lane to the contact). As the side that serves it keeps the
|
|
129
|
+
* serve ids it gave out on this session and answers the contact's `ar-get` for those only, at most
|
|
130
|
+
* `APP_RANGE_LIMITS.inFlight` per app (`busy` past it); the bytes themselves are read and sent by the session, which
|
|
131
|
+
* calls `finish` or `fail` for each task. As the side that asks it sends at most `inFlight` requests per app, keeps
|
|
132
|
+
* the rest waiting, and puts each answer back together, in order, from the offset asked. Serves and requests last one
|
|
133
|
+
* session: `reset` ends them all, `closeApp` those of one app.
|
|
134
|
+
*/
|
|
135
|
+
export declare class AppRanges {
|
|
136
|
+
private readonly send;
|
|
137
|
+
private readonly newServeId;
|
|
138
|
+
private readonly serves;
|
|
139
|
+
private readonly serving;
|
|
140
|
+
/** Tasks cancelled or unserved that the session is still reading or sending: each counts in its app's `inFlight` until settled. */
|
|
141
|
+
private readonly draining;
|
|
142
|
+
private readonly asking;
|
|
143
|
+
private readonly waiting;
|
|
144
|
+
private nextRequest;
|
|
145
|
+
constructor(send: (frame: AppRangeFrame) => void, newServeId?: () => string);
|
|
146
|
+
/** Lets the contact's `app` read `file` on this session: the serve id to tell it. */
|
|
147
|
+
serve(app: string, file: string): string;
|
|
148
|
+
/** Ends one serve: requests under it still being sent stop. False when it was not served. */
|
|
149
|
+
unserve(serveId: string): boolean;
|
|
150
|
+
/** The serve ids `app` has given out on this session (what the panel's "Sharing with" line shows). */
|
|
151
|
+
servesOf(app: string): string[];
|
|
152
|
+
/** An `ar-get` from the contact: the task to read and send, or null when it was refused (the refusal is sent) or dropped. */
|
|
153
|
+
receiveGet(frame: Extract<AppRangeFrame, {
|
|
154
|
+
t: "ar-get";
|
|
155
|
+
}>): AppRangeTask | null;
|
|
156
|
+
/** An `ar-cancel` from the contact: that request sends nothing more, and its number frees; its place frees once it is settled. */
|
|
157
|
+
receiveCancel(frame: Extract<AppRangeFrame, {
|
|
158
|
+
t: "ar-cancel";
|
|
159
|
+
}>): void;
|
|
160
|
+
/** Every byte of `task` was sent: `ar-end` goes with the file's size, unless the task was dropped meanwhile. */
|
|
161
|
+
finish(task: AppRangeTask, size: number): void;
|
|
162
|
+
/** The file under `task` could not be read: `ar-err` goes in place of the rest, unless the task was dropped meanwhile. */
|
|
163
|
+
fail(task: AppRangeTask, error: "changed" | "gone"): void;
|
|
164
|
+
/** The session stopped working on `task` without an answer (it is no longer live, or the channel went): its place frees, nothing is sent. */
|
|
165
|
+
release(task: AppRangeTask): void;
|
|
166
|
+
/** Reads `length` bytes at `offset` of what the contact's `app` serves as `serve`: the bytes (fewer at the end) and the file's size. */
|
|
167
|
+
read(app: string, serve: string, offset: number, length: number): Promise<{
|
|
168
|
+
bytes: Uint8Array;
|
|
169
|
+
size: number;
|
|
170
|
+
}>;
|
|
171
|
+
/** Bytes of a request of ours, from `ar-data` or a binary chunk. Out of order or past what was asked fails the request. */
|
|
172
|
+
receiveData(app: string, request: number, offset: number, data: Uint8Array): void;
|
|
173
|
+
/** The contact's `ar-end` or `ar-err` for a request of ours. */
|
|
174
|
+
receiveAnswer(frame: Extract<AppRangeFrame, {
|
|
175
|
+
t: "ar-end" | "ar-err";
|
|
176
|
+
}>): void;
|
|
177
|
+
/** `app` closed on either side: its serves end, what it was sending stops and what it asked fails with `error`. */
|
|
178
|
+
closeApp(app: string, error?: AppRangeReadError): void;
|
|
179
|
+
/** The session ended: no serve id lasts into the next, and every request fails with `offline`. */
|
|
180
|
+
reset(): void;
|
|
181
|
+
/** Stops `task` and frees its request number; `draining` keeps it counted until it is settled. */
|
|
182
|
+
private drop;
|
|
183
|
+
/** Frees `task`'s place; false when it was no longer live (nothing to send for it). */
|
|
184
|
+
private take;
|
|
185
|
+
/** Ends `ask` (failing it with `error` when given) and sends the next one waiting for its app. */
|
|
186
|
+
private settle;
|
|
187
|
+
private pump;
|
|
188
|
+
}
|
|
@@ -59,11 +59,16 @@ export declare const UPGRADE_CAPABILITY = "upgrade/1";
|
|
|
59
59
|
* `pairedApps.ts`). Offered only while the apps feature is on.
|
|
60
60
|
*/
|
|
61
61
|
export declare const APPS_CAPABILITY = "apps/1";
|
|
62
|
+
/**
|
|
63
|
+
* The read lane of mini-apps (WISP 1200 § A read lane to the contact, `pairedAppRanges.ts`): the contact's app reads a
|
|
64
|
+
* file this side's app serves, in ranges, outside `apps/1`. Offered beside `apps/1` only.
|
|
65
|
+
*/
|
|
66
|
+
export declare const APP_RANGES_CAPABILITY = "app-ranges/1";
|
|
62
67
|
/**
|
|
63
68
|
* What only a device link offers (WISP 06, `deviceLink.ts`): the frames between a person's own devices. They are in
|
|
64
69
|
* the type so a device link can announce them, and not in `KNOWN_SESSION_CAPABILITIES`: no chat knows them.
|
|
65
70
|
*/
|
|
66
|
-
export type SessionCapability = DeviceCapability | typeof CALLS_CAPABILITY | typeof SERVICES_CAPABILITY | typeof FILES_CAPABILITY | typeof FILES_BINARY_CAPABILITY | typeof TYPING_CAPABILITY | typeof REACTIONS_CAPABILITY | typeof EDIT_CAPABILITY | typeof WAKE_SESSION_CAPABILITY | typeof PIN_CAPABILITY | typeof STATUS_CARD_CAPABILITY | typeof BUTTONS_CAPABILITY | typeof UPGRADE_CAPABILITY | typeof APPS_CAPABILITY;
|
|
71
|
+
export type SessionCapability = DeviceCapability | typeof CALLS_CAPABILITY | typeof SERVICES_CAPABILITY | typeof FILES_CAPABILITY | typeof FILES_BINARY_CAPABILITY | typeof TYPING_CAPABILITY | typeof REACTIONS_CAPABILITY | typeof EDIT_CAPABILITY | typeof WAKE_SESSION_CAPABILITY | typeof PIN_CAPABILITY | typeof STATUS_CARD_CAPABILITY | typeof BUTTONS_CAPABILITY | typeof UPGRADE_CAPABILITY | typeof APPS_CAPABILITY | typeof APP_RANGES_CAPABILITY;
|
|
67
72
|
/** Every capability this app knows on a session: what `receive` reports changes of. */
|
|
68
73
|
export declare const KNOWN_SESSION_CAPABILITIES: readonly SessionCapability[];
|
|
69
74
|
export declare const SESSION_CAPABILITIES_FRAME = "paired-capabilities";
|
|
@@ -14,11 +14,20 @@ import { type StatusCard } from "./statusCards.js";
|
|
|
14
14
|
* message. A status card (`sc`, WISP 405 · Status Cards) may come with it too; a card message takes up to
|
|
15
15
|
* `STATUS_CARD_LIMITS.edits` edits, a number past `MAX_EDITS_PER_MESSAGE` holding only with a card. Older apps drop
|
|
16
16
|
* both frames: they have an id, but a `t` they do not know.
|
|
17
|
+
*
|
|
18
|
+
* A removal (WISP 400 § Delete for everyone) is the message's last edit, flagged `rm`, with a fallback text and
|
|
19
|
+
* nothing else beside it; an app from before removals shows that text as the edit:
|
|
20
|
+
*
|
|
21
|
+
* {"t":"paired-edit","id":"<the message's wire id>","e":4,"ts":1790000000000,"m":"🗑 Message removed","rm":true}
|
|
17
22
|
*/
|
|
18
23
|
export declare const EDIT_FRAME = "paired-edit";
|
|
19
24
|
export declare const EDITED_FRAME = "paired-edited";
|
|
20
25
|
/** Edits one message takes; the sender refuses the next one and the receiver ignores a higher number. */
|
|
21
26
|
export declare const MAX_EDITS_PER_MESSAGE = 100;
|
|
27
|
+
/** A removal is numbered one past the message's last edit, so it may pass a card message's bound by one. */
|
|
28
|
+
export declare const MAX_REMOVAL_NUMBER: number;
|
|
29
|
+
/** The text a removal carries: only what an app from before removals shows in the message's place. */
|
|
30
|
+
export declare const REMOVED_TEXT = "\uD83D\uDDD1 Message removed";
|
|
22
31
|
/** A sender says at most this many edits per `EDIT_RATE_WINDOW_MS` in one chat; the newest text of each message waits. */
|
|
23
32
|
export declare const EDIT_SEND_LIMIT = 10;
|
|
24
33
|
/** A receiver takes at most this many edit frames per window; the rest are dropped unconfirmed, so they come again. */
|
|
@@ -40,6 +49,8 @@ export interface WireEdit {
|
|
|
40
49
|
pv?: LinkPreview;
|
|
41
50
|
/** The status card of this version (WISP 405 · Status Cards): a message with a card takes an edit with one. */
|
|
42
51
|
sc?: StatusCard;
|
|
52
|
+
/** The author deleted the message for everyone (WISP 400 § Delete for everyone): `m` is only a fallback. */
|
|
53
|
+
rm?: true;
|
|
43
54
|
}
|
|
44
55
|
/**
|
|
45
56
|
* A `paired-edit` frame; the preview is left out when the frame would be too large with it. A card (`sc`) always
|
|
@@ -50,12 +61,14 @@ export declare function editFrame(edit: WireEdit): string;
|
|
|
50
61
|
export declare function editedFrame(id: string, e: number): string;
|
|
51
62
|
/** An edit number a message can have. */
|
|
52
63
|
export declare function validEditNumber(e: unknown): e is number;
|
|
64
|
+
/** A removal's number: any up to one past a card message's bound, card or not. */
|
|
65
|
+
export declare function validRemovalNumber(e: unknown): e is number;
|
|
53
66
|
/** A message's new text: not empty, no space around it, within a chat message's bytes. The same on a session and on the DHT. */
|
|
54
67
|
export declare function validEditMessage(m: unknown): m is string;
|
|
55
68
|
/**
|
|
56
69
|
* The edit a `paired-edit` frame says, or null when it is malformed (then it says nothing and is not confirmed). A
|
|
57
70
|
* preview or a card that does not hold is dropped, never the edit; an edit numbered past `MAX_EDITS_PER_MESSAGE`
|
|
58
|
-
* holds only with a card.
|
|
71
|
+
* holds only with a card. A removal carries its fallback text alone, and a `rm` other than `true` is no edit.
|
|
59
72
|
*/
|
|
60
73
|
export declare function parseEditFrame(frame: Record<string, unknown>, now?: number): WireEdit | null;
|
|
61
74
|
/** The confirmation a `paired-edited` frame says, or null when it is malformed. */
|
|
@@ -236,6 +236,14 @@ export interface RelayTransportOptions {
|
|
|
236
236
|
log?: (line: string) => void;
|
|
237
237
|
}
|
|
238
238
|
export declare function normalizeRelayUrl(input: string): string | null;
|
|
239
|
+
/**
|
|
240
|
+
* A read the relays failed (or left alone for failing before), when its caller has another path to ask
|
|
241
|
+
* (`RelayTransport.resolve` with `keptOnFailure` false): `kept` is the newest packet the relays gave for the key before.
|
|
242
|
+
*/
|
|
243
|
+
export declare class RelaysFailedError extends Error {
|
|
244
|
+
readonly kept: SignedPacket;
|
|
245
|
+
constructor(kept: SignedPacket);
|
|
246
|
+
}
|
|
239
247
|
export declare class RelayTransport implements PkarrTransport {
|
|
240
248
|
private relays;
|
|
241
249
|
private readonly timeoutMs;
|
|
@@ -422,8 +430,11 @@ export declare class RelayTransport implements PkarrTransport {
|
|
|
422
430
|
*
|
|
423
431
|
* A hedge spends a second request, so it goes only where the budget has requests to spare (`hedgeRoom`), never for a
|
|
424
432
|
* background read (nobody waits on it), and later for a key whose last read found nothing (`HEDGE_MISSING_MS`).
|
|
433
|
+
*
|
|
434
|
+
* `keptOnFailure` false: a read the relays failed throws `RelaysFailedError` with the packet they gave last, in place
|
|
435
|
+
* of handing that back as their answer (a CLI asks the DHT then, `RelaysAndDht`).
|
|
425
436
|
*/
|
|
426
|
-
resolve(pubKeyZ32: string, options?: PkarrRequestOptions): Promise<SignedPacket | null>;
|
|
437
|
+
resolve(pubKeyZ32: string, options?: PkarrRequestOptions, keptOnFailure?: boolean): Promise<SignedPacket | null>;
|
|
427
438
|
/**
|
|
428
439
|
* The order a key's read asks the relays in: in turn per key (see `resolve`), relays found slow lately last. A relay
|
|
429
440
|
* with a small share of its own (`RELAY_REQUESTS_PER_MINUTE` under `REQUESTS_PER_MINUTE`: pkarr.miguelmedeiros.dev's 5)
|
|
@@ -85,8 +85,13 @@ export declare class RelayBreaker {
|
|
|
85
85
|
* its answer says nothing either way: a probe among them is no longer out, and the next request may probe again.
|
|
86
86
|
*/
|
|
87
87
|
cancel(relay: string): void;
|
|
88
|
-
/**
|
|
89
|
-
|
|
88
|
+
/**
|
|
89
|
+
* The relay answered: whatever was wrong is over. When it was left alone and so was every other relay of `relays`
|
|
90
|
+
* (by default those that failed), for failing, the outage is over for them too: they are asked again now, not at the
|
|
91
|
+
* end of a wait of up to `BREAKER_MAX_MS` (two clients whose probes another relay answered each would share none
|
|
92
|
+
* for minutes). Their trips stay: one really down trips again at once, for longer.
|
|
93
|
+
*/
|
|
94
|
+
success(relay: string, relays?: string[]): void;
|
|
90
95
|
/**
|
|
91
96
|
* The relay failed a request; a probe that fails trips it again at once. While it is left alone and no probe is out,
|
|
92
97
|
* a failure is a request sent before it tripped (a start burst): already counted in, it trips nothing again.
|
|
@@ -47,7 +47,10 @@ export interface SignalSight {
|
|
|
47
47
|
* from this clock by the age allowed, either way.
|
|
48
48
|
*/
|
|
49
49
|
export declare function offerIsFresh(ts: number, sight?: SignalSight, now?: number): boolean;
|
|
50
|
-
|
|
50
|
+
/** `relayOnly` ("Hide my IP from contacts", the connection keeps to relays): relay candidates only, whatever else is in the SDP. */
|
|
51
|
+
export declare function extractRtcParams(sdp: string, { relayOnly }?: {
|
|
52
|
+
relayOnly?: boolean;
|
|
53
|
+
}): Pick<RtcSignal, "u" | "p" | "f" | "s" | "c">;
|
|
51
54
|
/** Validates an untrusted signal; anything that could inject SDP lines is rejected. */
|
|
52
55
|
export declare function parseRtcSignal(json: string): RtcSignal | null;
|
|
53
56
|
export declare function buildDataSdp(signal: RtcSignal): string;
|
|
@@ -189,10 +189,25 @@ export interface UsageCard {
|
|
|
189
189
|
updatedAt?: number;
|
|
190
190
|
windows?: UsageWindow[];
|
|
191
191
|
}
|
|
192
|
-
|
|
192
|
+
/** The kinds a sender may take back (WISP 405 § Removing a card). */
|
|
193
|
+
export declare const REMOVABLE_KINDS: readonly ["task", "routine"];
|
|
194
|
+
export type RemovableKind = typeof REMOVABLE_KINDS[number];
|
|
195
|
+
/**
|
|
196
|
+
* A task or routine its sender took back (WISP 405 § Removing a card): the edit of the card's message that retracts it.
|
|
197
|
+
* Not a task nor a routine, so no Tasks view counts it; an app without this kind drops it and shows the text.
|
|
198
|
+
*/
|
|
199
|
+
export interface RemovedCard {
|
|
200
|
+
kind: "removed";
|
|
201
|
+
/** The id of the card taken back. */
|
|
202
|
+
id: string;
|
|
203
|
+
of: RemovableKind;
|
|
204
|
+
}
|
|
205
|
+
export type StatusCard = TaskCard | RoutineCard | ButtonsCard | AppCard | UsageCard | RemovedCard;
|
|
193
206
|
export type StatusCardKind = StatusCard["kind"];
|
|
194
207
|
/** A button's id: 1 to 32 of `A-Z a-z 0-9 _ . : -`, not starting with `-`. */
|
|
195
208
|
export declare const BUTTON_ID: RegExp;
|
|
209
|
+
/** A routine's cron line, trimmed: 1 to 64 of `0-9 A-Z a-z * , / ? # -` and spaces (shown, never run). */
|
|
210
|
+
export declare const CRON_LINE: RegExp;
|
|
196
211
|
/**
|
|
197
212
|
* Whether a typed answer is a button's label or id (WISP 406 · Message Buttons): ignoring case and spaces at the ends.
|
|
198
213
|
* Not the device's locale's case: the presser's and the author's apps must agree ("I" is not "ı" anywhere).
|
|
@@ -244,6 +259,11 @@ export declare function checkStatusCard(raw: unknown, now?: number): {
|
|
|
244
259
|
export declare function taskProgress(card: Pick<TaskCard, "progress" | "done" | "total">): number | undefined;
|
|
245
260
|
/** A time as the fallback text says it: in UTC, to the minute ("2026-09-30 01:00 UTC"). */
|
|
246
261
|
export declare function cardTimeUtc(ms: number): string;
|
|
262
|
+
/**
|
|
263
|
+
* The text a removed card's message carries (WISP 405 § Removing a card): "🗑 Task removed", with the card's title or
|
|
264
|
+
* name when the sender knows it ("🗑 Task removed: Fix relay rotation"). An app without the `removed` kind shows it.
|
|
265
|
+
*/
|
|
266
|
+
export declare function removedCardText(of: RemovableKind, title?: string): string;
|
|
247
267
|
/**
|
|
248
268
|
* The text a card's message carries: what an app without cards shows, the DHT floor carries, the chat list previews
|
|
249
269
|
* and search finds. Plain lines, the first naming the card, no bars or layout that would read badly elsewhere.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { qu as boundVerifiedIdentity } from "./src-D9oJLTXM.js";
|
|
2
2
|
//#region ../browser/src/proofs/verify.ts
|
|
3
3
|
var DAY = 86400;
|
|
4
4
|
/**
|
|
@@ -103,4 +103,4 @@ function boundedIdentityFetch(options = { online: () => true }) {
|
|
|
103
103
|
//#endregion
|
|
104
104
|
export { verifyIdentity as i, boundedIdentityFetch as n, descriptorProblems as r, availableSigners as t };
|
|
105
105
|
|
|
106
|
-
//# sourceMappingURL=verify-
|
|
106
|
+
//# sourceMappingURL=verify-DMeDznOh.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify-
|
|
1
|
+
{"version":3,"file":"verify-DMeDznOh.js","names":[],"sources":["../../browser/src/proofs/verify.ts"],"sourcesContent":["import { boundVerifiedIdentity, IDENTITY_MAX_EVIDENCE, IDENTITY_MAX_VALIDITY, type IdentityStatement, type VerifiedIdentity } from \"@ghostly/core\";\nimport type { IdentityFetch, IdentityProofProvider, IdentitySigner, VerifyContext } from \"./contract\";\n\nconst DAY = 86_400;\n\n/**\n * The checks every proof goes through, whatever its provider: known provider, validity within the\n * provider's limit, bounded evidence, strict parsing, the provider's own check, and the category rule\n * (a self-custodied proof proves exactly the subject it names; an attested one says who attests it).\n * The engine verifies a contact's proof, and the person's own proof before saving it, only through this.\n */\nexport async function verifyIdentity(providers: readonly IdentityProofProvider[], statement: IdentityStatement, evidence: unknown, ctx: VerifyContext): Promise<VerifiedIdentity> {\n const { binding } = statement;\n const provider = providers.find(p => p.id === binding.provider);\n if (!provider) throw new Error(\"This app cannot verify this kind of identity\");\n if (binding.expiresAt - binding.issuedAt > Math.min(provider.validity.maxDays * DAY, IDENTITY_MAX_VALIDITY)) throw new Error(\"The proof lasts longer than this kind of identity allows\");\n if (JSON.stringify(evidence ?? null).length > IDENTITY_MAX_EVIDENCE) throw new Error(\"Evidence too large\");\n const parsed = provider.parseEvidence(evidence);\n const verified = boundVerifiedIdentity(await provider.verify(statement, parsed, ctx));\n if (provider.category === \"self-custodied\" && verified.subject !== binding.subject) throw new Error(\"The evidence is for another identity\");\n if (provider.category === \"provider-attested\" && !verified.attester) throw new Error(\"The evidence does not say who attests it\");\n return verified;\n}\n\n/** Problems with a provider's descriptor, empty when it is well-formed. The registry and the contract suite use it. */\nexport function descriptorProblems(p: IdentityProofProvider): string[] {\n const problems: string[] = [];\n if (!/^[a-z][a-z0-9-]{0,31}$/.test(p.id)) problems.push(\"id must match ^[a-z][a-z0-9-]{0,31}$\");\n if (!p.label?.trim()) problems.push(\"label is empty\");\n if (!p.description?.trim()) problems.push(\"description is empty\");\n if (!p.privacy?.trim()) problems.push(\"privacy is empty: say what verify contacts\");\n if (p.category !== \"self-custodied\" && p.category !== \"provider-attested\") problems.push(\"category is unknown\");\n if (!p.platforms.length) problems.push(\"no platforms\");\n const { defaultDays, maxDays } = p.validity;\n if (!(Number.isInteger(defaultDays) && Number.isInteger(maxDays) && defaultDays >= 1 && defaultDays <= maxDays && maxDays * DAY <= IDENTITY_MAX_VALIDITY)) problems.push(\"validity must be whole days, 1 ≤ default ≤ max ≤ 400\");\n if (p.recheck && !(Number.isInteger(p.recheck.afterSeconds) && p.recheck.afterSeconds >= 60)) problems.push(\"recheck.afterSeconds must be at least 60\");\n if (!p.signers.length) problems.push(\"no signers\");\n const ids = p.signers.map(s => s.id);\n if (new Set(ids).size !== ids.length) problems.push(\"signer ids are not unique\");\n for (const s of p.signers as readonly IdentitySigner<unknown>[]) {\n if (![\"in-app\", \"external-tool\", \"redirect\", \"publish\"].includes(s.kind)) problems.push(`signer ${s.id} has an unknown kind`);\n if (s.kind === \"in-app\" && typeof s.run !== \"function\") problems.push(`signer ${s.id} has no run()`);\n if (s.kind === \"external-tool\" && (typeof s.instructions !== \"function\" || typeof s.parse !== \"function\")) problems.push(`signer ${s.id} needs instructions() and parse()`);\n if (s.kind === \"redirect\" && typeof s.start !== \"function\") problems.push(`signer ${s.id} has no start()`);\n if (s.kind === \"publish\" && (typeof s.instructions !== \"function\" || typeof s.evidence !== \"function\")) problems.push(`signer ${s.id} needs instructions() and evidence()`);\n }\n return problems;\n}\n\n/** Signers of a provider that run on this platform and are available in this window. */\nexport function availableSigners<E>(p: IdentityProofProvider<E>, platform: IdentityProofProvider[\"platforms\"][number]): IdentitySigner<E>[] {\n return p.signers.filter(s => (s.platforms ?? p.platforms).includes(platform) && (s.available?.() ?? true));\n}\n\n/**\n * The engine's `ctx.fetch`: HTTPS GET only, no credentials or referrer, a time-out, a size cap,\n * redirects refused unless asked for.\n * `online` false refuses everything (the person turned the network off).\n */\nexport function boundedIdentityFetch(options: { online: () => boolean; timeoutMs?: number; fetcher?: typeof fetch } = { online: () => true }): IdentityFetch {\n return async (url, { headers, maxBytes = 64 * 1024, signal, redirect = \"error\" } = {}) => {\n if (!options.online()) throw new Error(\"Offline: this identity cannot be checked now\");\n const target = new URL(url);\n if (target.protocol !== \"https:\" || target.username || target.password) throw new Error(\"Identity checks use HTTPS only\");\n const timeout = AbortSignal.timeout(options.timeoutMs ?? 10_000);\n const response = await (options.fetcher ?? fetch)(target.href, {\n headers, signal: signal ? AbortSignal.any([signal, timeout]) : timeout,\n credentials: \"omit\", referrerPolicy: \"no-referrer\", cache: \"no-store\", redirect,\n });\n if (Number(response.headers.get(\"content-length\")) > maxBytes) throw new Error(\"Identity check response too large\");\n const reader = response.body?.getReader();\n const parts: Uint8Array[] = [];\n let length = 0;\n if (reader) {\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n length += value.length;\n if (length > maxBytes) throw new Error(\"Identity check response too large\");\n parts.push(value);\n }\n } finally { await reader.cancel().catch(() => {}); }\n }\n const bytes = new Uint8Array(length);\n let offset = 0;\n for (const part of parts) { bytes.set(part, offset); offset += part.length; }\n return { status: response.status, contentType: response.headers.get(\"content-type\") ?? \"\", text: new TextDecoder().decode(bytes), bytes };\n };\n}\n"],"mappings":";;AAGA,IAAM,MAAM;;;;;;;AAQZ,eAAsB,eAAe,WAA6C,WAA8B,UAAmB,KAA+C;CAChL,MAAM,EAAE,YAAY;CACpB,MAAM,WAAW,UAAU,MAAK,MAAK,EAAE,OAAO,QAAQ,QAAQ;CAC9D,IAAI,CAAC,UAAU,MAAM,IAAI,MAAM,8CAA8C;CAC7E,IAAI,QAAQ,YAAY,QAAQ,WAAW,KAAK,IAAI,SAAS,SAAS,UAAU,KAAA,MAA0B,GAAG,MAAM,IAAI,MAAM,0DAA0D;CACvL,IAAI,KAAK,UAAU,YAAY,IAAI,CAAC,CAAC,SAAA,OAAgC,MAAM,IAAI,MAAM,oBAAoB;CACzG,MAAM,SAAS,SAAS,cAAc,QAAQ;CAC9C,MAAM,WAAW,sBAAsB,MAAM,SAAS,OAAO,WAAW,QAAQ,GAAG,CAAC;CACpF,IAAI,SAAS,aAAa,oBAAoB,SAAS,YAAY,QAAQ,SAAS,MAAM,IAAI,MAAM,sCAAsC;CAC1I,IAAI,SAAS,aAAa,uBAAuB,CAAC,S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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.5.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",
|