@ghostlytools/sdk 1.10.0 → 1.10.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 +2 -2
- package/dist/{fakes-BTB2ugB3.js → fakes-83bCOBaf.js} +2 -2
- package/dist/{fakes-BTB2ugB3.js.map → fakes-83bCOBaf.js.map} +1 -1
- package/dist/fakes.js +1 -1
- package/dist/index.js +2 -2
- package/dist/{keet-identity-key-a4pR0QSm.js → keet-identity-key-DyvuvnRO.js} +2 -2
- package/dist/{keet-identity-key-a4pR0QSm.js.map → keet-identity-key-DyvuvnRO.js.map} +1 -1
- package/dist/{src-BZy4lDju.js → src-CEgQHzFr.js} +3207 -2864
- package/dist/src-CEgQHzFr.js.map +1 -0
- package/dist/testing.js +3 -3
- package/dist/types/core/src/callSignal.d.ts +10 -0
- package/dist/types/core/src/engineErrors.d.ts +1 -0
- package/dist/types/core/src/ghostlink.d.ts +2 -0
- package/dist/types/core/src/groupCommunity.d.ts +33 -2
- package/dist/types/core/src/groupSession.d.ts +46 -3
- package/dist/types/core/src/link.d.ts +16 -2
- package/dist/types/core/src/pairedTransports.d.ts +8 -0
- package/dist/types/core/src/pairedWake.d.ts +2 -1
- package/dist/types/core/src/webPush.d.ts +15 -6
- package/dist/{verify-Bcd7K4q-.js → verify-BWOWTWmV.js} +2 -2
- package/dist/{verify-Bcd7K4q-.js.map → verify-BWOWTWmV.js.map} +1 -1
- package/package.json +1 -1
- package/dist/src-BZy4lDju.js.map +0 -1
package/dist/testing.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Au as IdentityExchange, Cw as createIdentity, Fu as identityStatement, Mu as emptyIdentityLedger, Ru as newIdentityBinding, bu as IDENTITY_MAX_EVIDENCE, ia as isBitcoinAddress, ka as decodeBolt11 } from "./src-CEgQHzFr.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-BWOWTWmV.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-83bCOBaf.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;
|
|
@@ -170,6 +170,16 @@ export declare function extractParamsFromSdp(sdp: string, { maxCandidates, loopb
|
|
|
170
170
|
}): Partial<CallSignal>;
|
|
171
171
|
/** Offers, answers and hang-ups older (or further in the future) than this are ignored. */
|
|
172
172
|
export declare const CALL_SIGNAL_MAX_AGE_MS = 120000;
|
|
173
|
+
/**
|
|
174
|
+
* A call that comes this soon after the contact's last missed one does not ring, when that one barely rang
|
|
175
|
+
* (`BURST_RING_MS`): a bot looping call and hang-up does that (1,375 calls a minute), no person does. It is kept as a
|
|
176
|
+
* missed call, and the wait starts over with it, so a burst rings once and a call placed after a pause rings again.
|
|
177
|
+
* A person's call that rang a while, then was cancelled or rang out, holds nothing back: calling again at once (voice to
|
|
178
|
+
* video, a slip of the finger) rings. The apps (`useWebRTC`) and the headless CLI's call manager both keep it.
|
|
179
|
+
*/
|
|
180
|
+
export declare const QUICK_REDIAL_MS = 2000;
|
|
181
|
+
/** A missed call that rang shorter than this was not a person's (`QUICK_REDIAL_MS`). */
|
|
182
|
+
export declare const BURST_RING_MS = 1000;
|
|
173
183
|
/**
|
|
174
184
|
* A signal dated further ahead of this clock than this is not taken, however it was heard. A receiver acts on a signal
|
|
175
185
|
* only when its `ts` is later than the last one it acted on: taken, a signal dated a day ahead would be that last one,
|
|
@@ -71,6 +71,7 @@ export declare const ENGINE_ERRORS: {
|
|
|
71
71
|
readonly fedimintAlreadyJoined: "You already joined this federation";
|
|
72
72
|
readonly fedimintConnecting: "Wait for the federation to connect";
|
|
73
73
|
readonly fedimintNotEnough: "Not enough in this federation";
|
|
74
|
+
readonly fedimintRedeemUnheard: "Could not hear from the federation about these notes: if they don't show in your balance soon, paste them again";
|
|
74
75
|
readonly fedimintRealOnTestnet: "This federation holds real bitcoin: it belongs in a Mainnet Fedimint wallet";
|
|
75
76
|
readonly fedimintTestOnMainnet: "This federation is on {chain}, a test network: it belongs in a Testnet Fedimint wallet";
|
|
76
77
|
readonly walletAway: "{wallet} can't be used here. Use it on {device}.";
|
|
@@ -589,6 +589,8 @@ export interface GhostLinkOptions {
|
|
|
589
589
|
avatar?: string;
|
|
590
590
|
lastSeenTimestamp?: number;
|
|
591
591
|
pollIntervals?: PollIntervals;
|
|
592
|
+
/** A contact that left a live session is read no slower than the idle pace this long (a CLI daemon's, `DAEMON_WATCH_PEER_IDLE_MS`). */
|
|
593
|
+
watchPeerIdleMs?: number;
|
|
592
594
|
/**
|
|
593
595
|
* The transport this chat was live on when the app last ran (it quit, or crashed, with the session up). The contact is
|
|
594
596
|
* probably still there, holding a session that is dead now: that transport is dialled first, and a native one is
|
|
@@ -329,10 +329,15 @@ export interface CommunityState {
|
|
|
329
329
|
/** My next sequence number under the commit `seqH` (full hash). */
|
|
330
330
|
seq: number;
|
|
331
331
|
seqH: string;
|
|
332
|
-
/**
|
|
332
|
+
/**
|
|
333
|
+
* Sender → `e:h16` → highest seen and the window below it. `gap`: the lowest number missing below it, how many syncs
|
|
334
|
+
* asked for it and when the last did (`haveOf`); `floor`: what is missing at or below it is given up.
|
|
335
|
+
*/
|
|
333
336
|
seen: Record<string, Record<string, {
|
|
334
337
|
high: number;
|
|
335
338
|
window: number[];
|
|
339
|
+
gap?: [number, number, number];
|
|
340
|
+
floor?: number;
|
|
336
341
|
}>>;
|
|
337
342
|
nicks: Record<string, string>;
|
|
338
343
|
/** Recent frames from everyone (mine included), oldest first. */
|
|
@@ -353,6 +358,12 @@ export interface CommunityState {
|
|
|
353
358
|
* Absent in older states.
|
|
354
359
|
*/
|
|
355
360
|
alone?: string[];
|
|
361
|
+
/**
|
|
362
|
+
* My texts saved here (counter, frame in `store`) whose message row may not be stored or whose frame may not have gone
|
|
363
|
+
* yet, as `e:h16:n`, oldest first: an app killed in between stores and says them when it opens again (`resume`), so the
|
|
364
|
+
* number is never given to another text. Absent in older states.
|
|
365
|
+
*/
|
|
366
|
+
unsaid?: string[];
|
|
356
367
|
/** Leave requests waiting for a member to commit them. */
|
|
357
368
|
pendingLeaves: {
|
|
358
369
|
s: string;
|
|
@@ -864,9 +875,21 @@ export declare class CommunitySession {
|
|
|
864
875
|
/**
|
|
865
876
|
* Saves, then says my frame on every edge. One no edge took (none is up: I just joined, or my app just opened) is
|
|
866
877
|
* remembered until a member it was written for is handed it: I may be behind on the chain without knowing, and the
|
|
867
|
-
* first member I reach may be one let in since, who cannot read it but can carry it (`receiveSync`).
|
|
878
|
+
* first member I reach may be one let in since, who cannot read it but can carry it (`receiveSync`). `saved`: the
|
|
879
|
+
* caller marked it unheard and saved it (`sendText`).
|
|
868
880
|
*/
|
|
869
881
|
private say;
|
|
882
|
+
/** My frame in `unheard`, before it is said: the frames of mine the store no longer holds leave it. */
|
|
883
|
+
private markUnheard;
|
|
884
|
+
/**
|
|
885
|
+
* Stores and says what an app killed mid-send left `unsaid`: its counter and frame were saved, its row or its sending
|
|
886
|
+
* may not have happened. A row stored already is not stored twice (the app's store takes one row per id), a frame
|
|
887
|
+
* that went already is taken by the members as one they hold. The engine calls this on each tick; a send does first.
|
|
888
|
+
*/
|
|
889
|
+
resume(): Promise<void>;
|
|
890
|
+
private sayUnsaid;
|
|
891
|
+
/** The row of one of my own texts, as `sendText` stored it, opened from its frame; none for anything else, or one deleted for everyone. */
|
|
892
|
+
private ownRow;
|
|
870
893
|
/**
|
|
871
894
|
* Message `id` was deleted for everyone (WISP 400 § Delete for everyone), by its author or here: its frame goes from
|
|
872
895
|
* the store, so no catch-up hands it to a member who was away (they get the removal, which stays). A frame said again
|
|
@@ -934,6 +957,14 @@ export declare class CommunitySession {
|
|
|
934
957
|
*/
|
|
935
958
|
private ownFrame;
|
|
936
959
|
private isDuplicate;
|
|
960
|
+
/**
|
|
961
|
+
* What a sync says I have of a sender under a commit: below the lowest number missing, not the highest seen. A live
|
|
962
|
+
* frame raises the highest above that sender's frames still coming in a catch-up answer, and when the rest of the
|
|
963
|
+
* answer never came (my app closed or my edge dropped, or the hub's app closed), every later sync said I had them:
|
|
964
|
+
* they were lost for good (2026-10-18). A gap asked for by `GAP_ASKS` syncs at least `GAP_ASK_MS` apart that none
|
|
965
|
+
* filled (the stores rolled past it, a leaver's frames) is given up: each answer hands what is stored above it again.
|
|
966
|
+
*/
|
|
967
|
+
private haveOf;
|
|
937
968
|
private markSeen;
|
|
938
969
|
private park;
|
|
939
970
|
/** Something is missing here: the current epoch's secret, or the epoch of frames waiting. */
|
|
@@ -317,6 +317,12 @@ export interface GroupState {
|
|
|
317
317
|
* (`resealBehind`): I may have been behind on the chain without knowing. Absent in older states.
|
|
318
318
|
*/
|
|
319
319
|
alone?: string[];
|
|
320
|
+
/**
|
|
321
|
+
* My texts saved here (counter, frame in `sent`) whose message row may not be stored or whose frame may not have gone
|
|
322
|
+
* yet, as `e:n`, oldest first: an app killed in between stores and says them when it opens again (`resume`), so the
|
|
323
|
+
* number is never given to another text. Absent in older states.
|
|
324
|
+
*/
|
|
325
|
+
unsaid?: string[];
|
|
320
326
|
/** Epoch → the admin's mark (`GroupCommitFrame.left`) on the commit of that epoch that took out a member who left. Absent in older states. */
|
|
321
327
|
leftMarks?: Record<string, string>;
|
|
322
328
|
}
|
|
@@ -635,6 +641,8 @@ export declare class GroupSession {
|
|
|
635
641
|
private kept;
|
|
636
642
|
private trimRelay;
|
|
637
643
|
private pruneSecrets;
|
|
644
|
+
/** Someone out of the roster is named by no record of theirs, mine as the admin's: let in again, theirs start over. */
|
|
645
|
+
private pruneNames;
|
|
638
646
|
/**
|
|
639
647
|
* Leaves: my secrets go now; the admin removes me from the roster when it hears. `pick`: whom an admin with other
|
|
640
648
|
* members hands the role to first, in the same turn. The role can reach me while my leave is under way (a hand-over
|
|
@@ -671,6 +679,24 @@ export declare class GroupSession {
|
|
|
671
679
|
} | {
|
|
672
680
|
error: string;
|
|
673
681
|
}>;
|
|
682
|
+
/**
|
|
683
|
+
* Stores and says what an app killed mid-send left `unsaid`: its counter and frame were saved, its row or its sending
|
|
684
|
+
* may not have happened. A row stored already is not stored twice (the app's store takes one row per id), a frame
|
|
685
|
+
* that went already is taken by the members as one they hold. The engine calls this on each tick; a send does first.
|
|
686
|
+
*/
|
|
687
|
+
resume(): Promise<void>;
|
|
688
|
+
private sayUnsaid;
|
|
689
|
+
/** The row of one of my own frames, as `sendText` stored it, opened from the frame. */
|
|
690
|
+
private ownRow;
|
|
691
|
+
/**
|
|
692
|
+
* The highest number of mine, per epoch, among the rows the app stored (`GroupIncomingMessage.seq` of my own): my
|
|
693
|
+
* counter goes above them, so a row left by an older app killed mid-send never shares its id with a new text.
|
|
694
|
+
*/
|
|
695
|
+
ownRows(rows: Iterable<{
|
|
696
|
+
epoch: number;
|
|
697
|
+
seq: number;
|
|
698
|
+
}>): void;
|
|
699
|
+
private readonly rowHigh;
|
|
674
700
|
/** My next sequence number in `epoch`: the running counter in the current one, past every frame of mine I keep in an older one. */
|
|
675
701
|
private nextSeq;
|
|
676
702
|
/** A text sealed and signed as my frame `n` of `epoch`, with its boxes; `o`: where it was first said (`resealBehind`). */
|
|
@@ -678,7 +704,7 @@ export declare class GroupSession {
|
|
|
678
704
|
/** Into my bounded log, for members who missed it. */
|
|
679
705
|
private logOwn;
|
|
680
706
|
/**
|
|
681
|
-
* Saves, then sends my frame to every other member of its epoch still in the group. One no edge took (none was up:
|
|
707
|
+
* Saves, then sends my frame to every other member of its epoch still in the group (`saved`: the caller saved it). One no edge took (none was up:
|
|
682
708
|
* my app just opened) is remembered (`alone`): I may be behind on the chain without knowing, and members let in
|
|
683
709
|
* meanwhile could never open it (`resealBehind`).
|
|
684
710
|
*/
|
|
@@ -767,12 +793,24 @@ export declare class GroupSession {
|
|
|
767
793
|
/**
|
|
768
794
|
* A frame from an authenticated member over the pairwise edge. Anything malformed or unauthorized is dropped.
|
|
769
795
|
* Resolves to what it took that a hub passes on to its other edges (WISP 902 · Group Mesh § Hubs): each message,
|
|
770
|
-
* edit, commit (without the secret sealed for me), metadata statement and signed
|
|
771
|
-
* flood among hubs stops at every member that already has it
|
|
796
|
+
* edit, commit (without the secret sealed for me: `handOnTo` seals it for each member), metadata statement and signed
|
|
797
|
+
* leave, the first time only, so a flood among hubs stops at every member that already has it; a commit once more when
|
|
798
|
+
* its secret comes after it (`handOnAgain`). Only what its author still in the roster signed.
|
|
772
799
|
*/
|
|
773
800
|
handle(from: string, raw: unknown): Promise<GroupEdgeFrame[]>;
|
|
774
801
|
/** Taken for the first time: a hub passes it on (see `handle`). */
|
|
775
802
|
private took;
|
|
803
|
+
/**
|
|
804
|
+
* The secret of my top epoch came after its commit, which I handed on without it: the commit goes on once more, now
|
|
805
|
+
* with it (`handOnTo`), to the members who took it from me and asked me in vain. Once per epoch, as a secret is taken once.
|
|
806
|
+
*/
|
|
807
|
+
private handOnAgain;
|
|
808
|
+
/**
|
|
809
|
+
* A frame I took, as a hub passes it on to `to` (WISP 902 · Group Mesh § Hubs): a commit with its epoch's secret sealed
|
|
810
|
+
* for `to` when `to` is in that roster and I hold the secret, as a sync answer has it, so a member need not ask for it;
|
|
811
|
+
* anything else as it is.
|
|
812
|
+
*/
|
|
813
|
+
handOnTo(to: string, frame: GroupEdgeFrame): GroupEdgeFrame;
|
|
776
814
|
/**
|
|
777
815
|
* My leave, signed, for hubs to carry to the admin (see `GroupByeFrame`). Made while I am still a member: `leave`
|
|
778
816
|
* forgets everything but my key.
|
|
@@ -849,6 +887,11 @@ export declare class GroupSession {
|
|
|
849
887
|
private openReply;
|
|
850
888
|
private isDuplicate;
|
|
851
889
|
private markSeen;
|
|
890
|
+
/**
|
|
891
|
+
* The same for every sender, as the chain moves: `markSeen` prunes only the sender that writes, and a member who left
|
|
892
|
+
* never writes again. Each sync carries what is left here (`have`, `miss`), on every edge.
|
|
893
|
+
*/
|
|
894
|
+
private pruneSeen;
|
|
852
895
|
private park;
|
|
853
896
|
/** Whoever sent something I cannot read yet is ahead of me, or holds a secret I lack: ask, but not in a loop. */
|
|
854
897
|
private ask;
|
|
@@ -62,6 +62,17 @@ export declare const EXPECT_PEER_MS = 30000;
|
|
|
62
62
|
* or the session dropped): an app that restarts is back within this, and its dial or offer is seen in seconds.
|
|
63
63
|
*/
|
|
64
64
|
export declare const WATCH_PEER_MS: number;
|
|
65
|
+
/**
|
|
66
|
+
* A CLI daemon (a bot) reads a contact that went away from a live session at the idle pace, not its background one, from
|
|
67
|
+
* the end of `WATCH_PEER_MS` until this long after it left (`LinkSession.watchPeer`). A phone that put the app to sleep is
|
|
68
|
+
* often back after more than 2 minutes, and where WebRTC is all there is between them its offer waits for the daemon's
|
|
69
|
+
* read: every 30 s past 2 minutes, a web app at phone size was live again 18.3 s after 5 minutes asleep (the lab,
|
|
70
|
+
* 2026-11-01). Cost, a contact away the whole 5 minutes: from 2 to 5 minutes, a read every 10 s and not every 30 s, 12
|
|
71
|
+
* more. A key's reads take turns between the two default relays (`readOrder` in relay.ts), 6 more on each: at 12 such
|
|
72
|
+
* absences an hour, 72 more an hour on a relay, 4% of the 1,800 this client allows itself there (`REQUESTS_PER_MINUTE`).
|
|
73
|
+
* At the active pace for the whole 5 minutes instead, 39 more an absence: 13%.
|
|
74
|
+
*/
|
|
75
|
+
export declare const DAEMON_WATCH_PEER_IDLE_MS: number;
|
|
65
76
|
/**
|
|
66
77
|
* The longest a link reads fast for a data link whose connection went `disconnected` (`setDataLinkStalled`): a little
|
|
67
78
|
* past the 12 s such a connection is given (`DISCONNECT_GRACE_MS`), by when it is back or the session is gone.
|
|
@@ -287,6 +298,8 @@ export declare class LinkSession {
|
|
|
287
298
|
private watchUntil;
|
|
288
299
|
/** The time of the peer's packet read last when it went away (`watchPeer`): a newer one that advertises says it is back. */
|
|
289
300
|
private watchFrom;
|
|
301
|
+
/** Until when a contact that went away is read at the idle pace once `watchUntil` passed (`watchPeer`'s `idleMs`). */
|
|
302
|
+
private lingerUntil;
|
|
290
303
|
/** Until when the reads of a contact that went away are its first ones (`DEPARTED_READ_MS`). */
|
|
291
304
|
private departedUntil;
|
|
292
305
|
private publishRetryTimer;
|
|
@@ -351,9 +364,10 @@ export declare class LinkSession {
|
|
|
351
364
|
expectPeer(awaited?: boolean): void;
|
|
352
365
|
/**
|
|
353
366
|
* The contact just left a live session, and is likely coming back (an app restarting): fast for `EXPECT_PEER_MS`,
|
|
354
|
-
* then the active pace until `WATCH_PEER_MS` passed, whatever the chat's pace would be.
|
|
367
|
+
* then the active pace until `WATCH_PEER_MS` passed, whatever the chat's pace would be. `idleMs` (a daemon's,
|
|
368
|
+
* `DAEMON_WATCH_PEER_IDLE_MS`): then no slower than the idle pace until that long after now.
|
|
355
369
|
*/
|
|
356
|
-
watchPeer(): void;
|
|
370
|
+
watchPeer(idleMs?: number): void;
|
|
357
371
|
/**
|
|
358
372
|
* Nothing a read finds can be acted on for a while (a dial waiting out its backoff, whose end has a look of its own):
|
|
359
373
|
* the windows that look fast for the contact (`expectPeer`, `watchPeer`) end, and the link reads at its pace from the
|
|
@@ -59,6 +59,14 @@ export declare const RELAY_URL: RegExp;
|
|
|
59
59
|
export declare const RELAY_WITH_SECRETS: RegExp;
|
|
60
60
|
/** A relay URL a descriptor may name: `RELAY_URL`, with nothing but the server's address in it. */
|
|
61
61
|
export declare const relayUrl: (value: unknown) => value is string;
|
|
62
|
+
/**
|
|
63
|
+
* Whether an Iroh endpoint may dial a contact through the relay its descriptor names (none: a direct address alone).
|
|
64
|
+
* The contact chose that relay and this device opens it on its own, again on each redial, so it is held to what a held
|
|
65
|
+
* item's address is (`isHoldUrl`): https at a public name or a public address, never this machine or its network.
|
|
66
|
+
* One of the endpoint's own relays (`own`: the person's settings, a private network's or a test's) is dialled as well,
|
|
67
|
+
* in either spelling: this device opens it anyway.
|
|
68
|
+
*/
|
|
69
|
+
export declare function dialableIrohRelay(relay: unknown, own: readonly string[]): boolean;
|
|
62
70
|
/**
|
|
63
71
|
* A contact's native descriptors as it tells them on a session (`paired-policy`, `paired-adapters`) or as this app
|
|
64
72
|
* kept them: only what the adapters dial, each field in the shape its adapter makes. The keys are 64 hex characters,
|
|
@@ -12,7 +12,8 @@ import { type PushRequest, type PushTarget, type VapidKeys } from "./webPush.js"
|
|
|
12
12
|
* of a few bytes to the endpoint: `{"wake":1,"k":"<token>"}`. It says nothing about the message: the contact's
|
|
13
13
|
* app shows "New message", opens on a tap, connects and fetches the message itself. The token is the contact's
|
|
14
14
|
* own name for this chat, different for every contact, so its app knows which chat (and whether it is muted)
|
|
15
|
-
* without the push service learning anything:
|
|
15
|
+
* without the push service learning anything: every wake-up is padded to one size (`PUSH_PAD_BYTES`), so it sees that
|
|
16
|
+
* a push happened, and when; only the time to live and a call's repeats set a call or a device handoff apart.
|
|
16
17
|
*
|
|
17
18
|
* It needs `wake/1` in `paired-capabilities` on both sides. The VAPID key pair belongs to that one subscription,
|
|
18
19
|
* so sharing its private half lets a contact post to that subscription and nothing else. Rotating it (a new
|
|
@@ -19,6 +19,12 @@ export interface PushRequest {
|
|
|
19
19
|
}
|
|
20
20
|
export declare class WebPushError extends Error {
|
|
21
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Every wake-up's record is padded to this many bytes (its plaintext, the delimiter and zeros, RFC 8188), so the push
|
|
24
|
+
* service and a relay see one body length for a message, a call and a device handoff. 128 holds the longest of them
|
|
25
|
+
* with the longest token a contact may give (64 characters).
|
|
26
|
+
*/
|
|
27
|
+
export declare const PUSH_PAD_BYTES = 128;
|
|
22
28
|
export declare function generateVapidKeys(): VapidKeys;
|
|
23
29
|
/** Whether a VAPID key pair is well formed and its halves belong together. */
|
|
24
30
|
export declare function vapidKeysMatch(keys: VapidKeys): boolean;
|
|
@@ -35,12 +41,14 @@ export declare function checkPushEndpoint(endpoint: string): URL;
|
|
|
35
41
|
/** `Authorization: vapid t=<JWT>, k=<public key>` for a request to `endpoint` (RFC 8292). */
|
|
36
42
|
export declare function vapidAuthorization(endpoint: string, keys: VapidKeys, subject: string, now?: number): string;
|
|
37
43
|
/**
|
|
38
|
-
* `plaintext` encrypted for a subscription (RFC 8291 with RFC 8188 `aes128gcm`, one record). `
|
|
39
|
-
* the
|
|
44
|
+
* `plaintext` encrypted for a subscription (RFC 8291 with RFC 8188 `aes128gcm`, one record). `padTo`: the record's
|
|
45
|
+
* plaintext is padded with zeros after the delimiter to this many bytes (a longer one goes as it is). `secret` and
|
|
46
|
+
* `salt` fix the sender's ephemeral key and salt, for the RFC's test vector only.
|
|
40
47
|
*/
|
|
41
|
-
export declare function encryptPushPayload(plaintext: Uint8Array, target: Pick<PushTarget, "p256dh" | "auth">,
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
export declare function encryptPushPayload(plaintext: Uint8Array, target: Pick<PushTarget, "p256dh" | "auth">, options?: {
|
|
49
|
+
padTo?: number;
|
|
50
|
+
secret?: Uint8Array;
|
|
51
|
+
salt?: Uint8Array;
|
|
44
52
|
}): Uint8Array;
|
|
45
53
|
/**
|
|
46
54
|
* The receiving side of `encryptPushPayload`, which a browser does for its service worker. Here for tests and
|
|
@@ -49,7 +57,8 @@ export declare function encryptPushPayload(plaintext: Uint8Array, target: Pick<P
|
|
|
49
57
|
export declare function decryptPushPayload(body: Uint8Array, receiverSecret: Uint8Array, authSecret: Uint8Array): Uint8Array;
|
|
50
58
|
/**
|
|
51
59
|
* The whole request that wakes a subscription: POST, encrypted body, VAPID authorization, a short time to live
|
|
52
|
-
* (a wake-up an hour late is no use) and high urgency (a phone on battery saver still gets it).
|
|
60
|
+
* (a wake-up an hour late is no use) and high urgency (a phone on battery saver still gets it). The body is padded to
|
|
61
|
+
* `PUSH_PAD_BYTES`, so its length does not tell one kind of wake-up from another.
|
|
53
62
|
*/
|
|
54
63
|
export declare function pushRequest(target: PushTarget, keys: VapidKeys, payload: Uint8Array, options: {
|
|
55
64
|
subject: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ju as boundVerifiedIdentity, ku as IdentityCheckUnavailable } from "./src-CEgQHzFr.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-BWOWTWmV.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify-
|
|
1
|
+
{"version":3,"file":"verify-BWOWTWmV.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.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,CAAC;CACpF,IAAI,SAAS,aAAa,oBA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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.10.
|
|
3
|
+
"version": "1.10.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",
|