@ghostlytools/sdk 1.2.3 → 1.2.4
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 +5 -0
- package/dist/app.js.map +1 -1
- package/dist/core.js +1 -1
- package/dist/{fakes-CBIuqo5e.js → fakes-JOzOFxn3.js} +2 -2
- package/dist/{fakes-CBIuqo5e.js.map → fakes-JOzOFxn3.js.map} +1 -1
- package/dist/fakes.js +1 -1
- package/dist/index.js +2 -2
- package/dist/{keet-identity-key-BylxCPl4.js → keet-identity-key-BLli1rE4.js} +2 -2
- package/dist/{keet-identity-key-BylxCPl4.js.map → keet-identity-key-BLli1rE4.js.map} +1 -1
- package/dist/{src-DCeLPsi-.js → src-BqHTnRWH.js} +278 -38
- package/dist/src-BqHTnRWH.js.map +1 -0
- package/dist/testing.js +3 -3
- package/dist/types/core/src/dhtDelivery.d.ts +4 -0
- package/dist/types/core/src/engineErrors.d.ts +1 -0
- package/dist/types/core/src/ghostlink.d.ts +27 -5
- package/dist/types/core/src/groupCommunity.d.ts +6 -0
- package/dist/types/core/src/groupSession.d.ts +19 -1
- package/dist/types/core/src/miniApp.d.ts +5 -0
- package/dist/types/core/src/relay.d.ts +22 -0
- package/dist/types/core/src/transport.d.ts +7 -0
- package/dist/{verify-DBGw6wYt.js → verify-RjMx7eW6.js} +2 -2
- package/dist/{verify-DBGw6wYt.js.map → verify-RjMx7eW6.js.map} +1 -1
- package/package.json +1 -1
- package/dist/src-DCeLPsi-.js.map +0 -1
package/dist/testing.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { $l as emptyIdentityLedger, Fi as isBitcoinAddress, Hl as IDENTITY_MAX_EVIDENCE, Zl as IdentityExchange, au as newIdentityBinding, nu as identityStatement, oa as decodeBolt11, zb as createIdentity } from "./src-
|
|
1
|
+
import { $l as emptyIdentityLedger, Fi as isBitcoinAddress, Hl as IDENTITY_MAX_EVIDENCE, Zl as IdentityExchange, au as newIdentityBinding, nu as identityStatement, oa as decodeBolt11, zb as createIdentity } from "./src-BqHTnRWH.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-RjMx7eW6.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-JOzOFxn3.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;
|
|
@@ -141,6 +141,10 @@ export declare const emptyDhtDeliveryState: () => DhtDeliveryState;
|
|
|
141
141
|
export declare class DhtDelivery {
|
|
142
142
|
private readonly options;
|
|
143
143
|
private state;
|
|
144
|
+
/** The state as last saved: a save that would write the same row again is skipped. */
|
|
145
|
+
private saved?;
|
|
146
|
+
/** The sequence of the last envelope signed here; the state's is the highest set aside (`SEQUENCE_BLOCK`). */
|
|
147
|
+
private sequence;
|
|
144
148
|
private mode;
|
|
145
149
|
private running;
|
|
146
150
|
private ticking;
|
|
@@ -24,6 +24,7 @@ export declare const ENGINE_ERRORS: {
|
|
|
24
24
|
readonly notEnoughSats: "Not enough sats in your wallet";
|
|
25
25
|
readonly noSharedMint: "You share no mint with this contact";
|
|
26
26
|
readonly ecashAlreadySpent: "This ecash was already spent somewhere else";
|
|
27
|
+
readonly ecashBeingReceived: "This ecash is already being received";
|
|
27
28
|
readonly ecashOtherUnit: "This ecash is in {unit}: only sat ecash can be redeemed here";
|
|
28
29
|
readonly reviewedEcashSpent: "The ecash for this payment was already spent somewhere else. Nothing was sent, and your balance now shows what the mint still holds.";
|
|
29
30
|
readonly reviewedSatsGone: "The sats this payment was reviewed with went to another payment. Nothing was sent: review it again.";
|
|
@@ -31,8 +31,15 @@ import { type PairingProgress, type PairingRole } from "./pairingProgress.js";
|
|
|
31
31
|
export declare const DHT_PIN_GRACE_MS = 10000;
|
|
32
32
|
/** Back after a restart (`resume`), dials wait this long at most for the native endpoint that carried the chat to start. */
|
|
33
33
|
export declare const RESUME_WAIT_MS = 10000;
|
|
34
|
-
/**
|
|
35
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Two dials crossing: how long the lower key's side waits for its own to connect before it takes the contact's. Two
|
|
36
|
+
* dials that both go through connect within a round trip of each other: each side's preface goes out as the other's
|
|
37
|
+
* dial reaches it. One not connected by then has stalled (a HyperDHT stream that opened and carries nothing, dialled
|
|
38
|
+
* again only 2 s later) or goes to an endpoint the contact no longer runs: waiting for it held a working connection
|
|
39
|
+
* back 0.9-1.9 s (DHT-direct lab, 5 of 20 first pairings). Taken, this side's dial is closed when it lands, and on the
|
|
40
|
+
* contact's side it never authenticates (`attachReplacement`).
|
|
41
|
+
*/
|
|
42
|
+
export declare const CROSSED_WAIT_MS = 500;
|
|
36
43
|
/**
|
|
37
44
|
* A session this side dialled this recently is one a crossing dial of the contact's may meet (both connected): the
|
|
38
45
|
* lower key keeps its own. Older, the session is one the contact has since lost (its app restarted), and its dial
|
|
@@ -700,10 +707,15 @@ export declare class GhostLink {
|
|
|
700
707
|
* was the app's in the background, not a restart (`resumeAfterAbsence`).
|
|
701
708
|
*/
|
|
702
709
|
private offered?;
|
|
710
|
+
/**
|
|
711
|
+
* The WebRTC offer this side's dial made last, fallback allowed or not: one made before the contact's record was read
|
|
712
|
+
* races once it is (`raceStandingOffer`).
|
|
713
|
+
*/
|
|
714
|
+
private offerMade?;
|
|
703
715
|
/** The attempt (its epoch) whose direct transports were knocked on as its offer went out (`knockEarly`), and whether that is under way. */
|
|
704
716
|
private knockedEarly;
|
|
705
717
|
private knockingEarly;
|
|
706
|
-
/** When
|
|
718
|
+
/** When this side's offer's answer was applied (`RACE_ANSWERED_MS`); 0 while the data link is not connecting on it. */
|
|
707
719
|
private answeredAt;
|
|
708
720
|
/** This side's offer is out unanswered, or answered and not connected yet: what is ranked after WebRTC may race it. */
|
|
709
721
|
private get offerOut();
|
|
@@ -1056,6 +1068,14 @@ export declare class GhostLink {
|
|
|
1056
1068
|
* it) or `RACE_RELAYED_MS` (a relayed one), those are dialled too, the offer standing meanwhile.
|
|
1057
1069
|
*/
|
|
1058
1070
|
private scheduleRace;
|
|
1071
|
+
/**
|
|
1072
|
+
* This side's offer went out before the contact's record was read (a joiner's early one, `dialEarly`): nothing was
|
|
1073
|
+
* known of what the contact runs, so it was made with no fallback and nothing raced it. Once the record says, and both
|
|
1074
|
+
* sides allow it, the offer races what both run as one made then would: answered and not connected `RACE_ANSWERED_MS`
|
|
1075
|
+
* later, the relayed ones too. Behind a VPN that drops UDP, a first pairing went live over the relayed Iroh only once
|
|
1076
|
+
* the attempt timed out and the next one raced, 32 to 66 s in (zero's VPN lab, 2026-10-13).
|
|
1077
|
+
*/
|
|
1078
|
+
private raceStandingOffer;
|
|
1059
1079
|
/**
|
|
1060
1080
|
* Back after an absence, this side answers an offer the contact made while it was away (it dials whatever its key):
|
|
1061
1081
|
* the contact looks for that answer at the pace of an offer out a while (every 8 s on the relays), and its attempt may
|
|
@@ -1399,8 +1419,8 @@ export declare class GhostLink {
|
|
|
1399
1419
|
* Both sides dialled at once (two apps back after a restart, each knocking): the lower key's dial carries the chat, on
|
|
1400
1420
|
* both sides; the higher key's side takes it over as a replacement (`attachReplacement`). Here, on the lower key's
|
|
1401
1421
|
* side, the contact's connection waits: dropped once this side's own dial connects, taken if that dial fails, or has
|
|
1402
|
-
* not connected within `CROSSED_WAIT_MS` (
|
|
1403
|
-
*
|
|
1422
|
+
* not connected within `CROSSED_WAIT_MS` (it stalled, or goes to an endpoint the contact no longer runs, for as long
|
|
1423
|
+
* as it takes to give up).
|
|
1404
1424
|
*/
|
|
1405
1425
|
private crossed;
|
|
1406
1426
|
private parkCrossed;
|
|
@@ -1423,6 +1443,8 @@ export declare class GhostLink {
|
|
|
1423
1443
|
private readonly dialedIn;
|
|
1424
1444
|
/** Connections whose session started with no key pinned nor named by the invite. */
|
|
1425
1445
|
private readonly openedUnpinned;
|
|
1446
|
+
/** The WebRTC offer under way was made or answered with no key pinned nor named by the invite (its channel opens later). */
|
|
1447
|
+
private rtcStartedUnpinned;
|
|
1426
1448
|
/**
|
|
1427
1449
|
* `migration`: the channel is a candidate that takes over from the session open now once it authenticated. With a
|
|
1428
1450
|
* `plan`, a live switch both sides agreed; without one, a replacement (`attachReplacement`): the contact dialled
|
|
@@ -467,6 +467,12 @@ export declare class CommunitySession {
|
|
|
467
467
|
/** When the chain took them out (the commit's time, by its signer's clock), if it did and they are not back in. */
|
|
468
468
|
outAt(key: string): number | undefined;
|
|
469
469
|
private outIndex;
|
|
470
|
+
/**
|
|
471
|
+
* Someone the chain removed (not one who left) and who is not back in: nothing it signs is heard any more, even for
|
|
472
|
+
* an epoch it was in. What one who left wrote while in the group is still taken and handed on, for the epochs it was
|
|
473
|
+
* in (WISP 903 § Leaving and removal): its goodbye reaches the members who were away.
|
|
474
|
+
*/
|
|
475
|
+
private wasExpelled;
|
|
470
476
|
/**
|
|
471
477
|
* What someone the chain took out is told when it comes back (WISP 903 § Leaving and removal): the commits from where
|
|
472
478
|
* it says it is (`sync`: its tip, or its locator) up to the one that took it out, and nothing after. Later commits
|
|
@@ -140,11 +140,17 @@ export interface GroupEditFrame {
|
|
|
140
140
|
c: string;
|
|
141
141
|
sig: string;
|
|
142
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* `left`: on a `remove` commit made on the member's own leave (its `group-leave`, its signed `group-bye`, or its leave
|
|
145
|
+
* on the admin's chat), the committer's signature over `leftSigned` (WISP 902 § Leaving): only the admin knows the
|
|
146
|
+
* removal was asked for, and a hub cannot add the mark to one it was not. Apps from before leave it out and drop it.
|
|
147
|
+
*/
|
|
143
148
|
export interface GroupCommitFrame {
|
|
144
149
|
t: "group-commit";
|
|
145
150
|
g: string;
|
|
146
151
|
commit: GroupCommit;
|
|
147
152
|
secret?: SealedSecret;
|
|
153
|
+
left?: string;
|
|
148
154
|
}
|
|
149
155
|
/**
|
|
150
156
|
* `mt`: which metadata statement I hold (`groupMetaTag`); apps without metadata leave it out. `miss`: sequence numbers
|
|
@@ -265,6 +271,8 @@ export interface GroupState {
|
|
|
265
271
|
* (`resealBehind`): I may have been behind on the chain without knowing. Absent in older states.
|
|
266
272
|
*/
|
|
267
273
|
alone?: string[];
|
|
274
|
+
/** Epoch → the admin's mark (`GroupCommitFrame.left`) on the commit of that epoch that took out a member who left. Absent in older states. */
|
|
275
|
+
leftMarks?: Record<string, string>;
|
|
268
276
|
}
|
|
269
277
|
/**
|
|
270
278
|
* `completes`: this message was delivered before from a copy another member handed on without its author's whole
|
|
@@ -487,7 +495,15 @@ export declare class GroupSession {
|
|
|
487
495
|
* contact link) after telling the existing members over their edges.
|
|
488
496
|
*/
|
|
489
497
|
admit(memberKey: string, now?: number): Promise<(GroupChainFrame | GroupWelcomeFrame)[]>;
|
|
490
|
-
|
|
498
|
+
/**
|
|
499
|
+
* A welcome for a member already in the roster that never got the first one (its chat closed while it was let in):
|
|
500
|
+
* nothing is committed. It carries the secrets of the epochs it was in, from its admission on, sealed to its key.
|
|
501
|
+
*/
|
|
502
|
+
rewelcome(memberKey: string): Promise<(GroupChainFrame | GroupWelcomeFrame)[]>;
|
|
503
|
+
/** `left`: the member asked to leave (on the admin's chat), and the commit says so (`GroupCommitFrame.left`). */
|
|
504
|
+
remove(memberKey: string, now?: number, { left }?: {
|
|
505
|
+
left?: boolean | undefined;
|
|
506
|
+
}): Promise<void>;
|
|
491
507
|
transferAdmin(memberKey: string, now?: number): Promise<void>;
|
|
492
508
|
/** A fresh secret without a membership change: whoever holds the old one and is not a member learns nothing new. */
|
|
493
509
|
rotate(now?: number): Promise<void>;
|
|
@@ -662,6 +678,8 @@ export declare class GroupSession {
|
|
|
662
678
|
private ask;
|
|
663
679
|
private replayWaiting;
|
|
664
680
|
private receiveCommit;
|
|
681
|
+
/** Keeps the admin's mark on a commit that took out a member who left (`GroupCommitFrame.left`) when it holds; true when new. */
|
|
682
|
+
private takeLeftMark;
|
|
665
683
|
private apply;
|
|
666
684
|
/** A sealed secret for an epoch of my chain: kept only when it confirms against that epoch's commit. */
|
|
667
685
|
private takeSecret;
|
|
@@ -128,6 +128,11 @@ export declare const MINI_APP_LIMITS: {
|
|
|
128
128
|
readonly requestBytes: number;
|
|
129
129
|
/** Requests per second, per app. */
|
|
130
130
|
readonly requestsPerSecond: 50;
|
|
131
|
+
/**
|
|
132
|
+
* Bytes of `file` answers per second, per app: a whole bundle's worth. A read that starts under it is answered whole;
|
|
133
|
+
* past it `file` is refused with `too-fast` until the second has gone.
|
|
134
|
+
*/
|
|
135
|
+
readonly fileBytesPerSecond: number;
|
|
131
136
|
/** A storage key, UTF-8. */
|
|
132
137
|
readonly storageKeyBytes: 256;
|
|
133
138
|
/** One stored JSON value, serialized. */
|
|
@@ -225,6 +225,8 @@ export declare class RelayTransport implements PkarrTransport {
|
|
|
225
225
|
* it is under the watch share (`WATCH_SHARE`) and while the groups' reads are rationed (`GROUP_RATION_WINDOW_MS`).
|
|
226
226
|
*/
|
|
227
227
|
private readonly readTurns;
|
|
228
|
+
/** Per key read in turn (`isTurnRead`), when a read of it last went out and when it last asked (`READ_TURN_MS`). */
|
|
229
|
+
private readonly keyTurns;
|
|
228
230
|
/** Groups' reads (not background ones) on each relay in the last `GROUP_RATION_WINDOW_MS`. */
|
|
229
231
|
private readonly spentGroupReads;
|
|
230
232
|
/** When a group's read last found each relay's minute full: its reads there are rationed for `GROUP_RATION_MS`. */
|
|
@@ -244,6 +246,11 @@ export declare class RelayTransport implements PkarrTransport {
|
|
|
244
246
|
/** Per relay and key, the newest packet that relay held back for its budget while another relay took it (`catchUpLater`). */
|
|
245
247
|
private readonly catchUp;
|
|
246
248
|
private catchUpTimer;
|
|
249
|
+
/**
|
|
250
|
+
* Per key whose reads the budget held back since its last read went out: when a request frees for it
|
|
251
|
+
* (`readHeldBackFor`), how many times in a row, and since when (`READ_STARVED_MS`).
|
|
252
|
+
*/
|
|
253
|
+
private readonly heldBack;
|
|
247
254
|
/** When the relays last answered a read of each key, for `FRESH_READ_MS`. */
|
|
248
255
|
private readonly readAt;
|
|
249
256
|
private readonly freshReadMs;
|
|
@@ -343,6 +350,8 @@ export declare class RelayTransport implements PkarrTransport {
|
|
|
343
350
|
*/
|
|
344
351
|
private hedgeRoom;
|
|
345
352
|
readAnsweredAt(pubKeyZ32: string): number | undefined;
|
|
353
|
+
readHeldBackFor(pubKeyZ32: string): number | undefined;
|
|
354
|
+
private heldBackUntil;
|
|
346
355
|
/** The relays answered a read of this key now; answers older than `FRESH_READ_MS` are dropped as the list grows. */
|
|
347
356
|
private answeredRead;
|
|
348
357
|
/** The relay that answered a key's read, for its next one; the keys read longest ago go past `READ_TURNS_KEPT`. */
|
|
@@ -381,6 +390,19 @@ export declare class RelayTransport implements PkarrTransport {
|
|
|
381
390
|
* would keep a turn it cannot take.
|
|
382
391
|
*/
|
|
383
392
|
private readsAhead;
|
|
393
|
+
/** A read of `key` that takes turns asks: it waits for its turn from now on, unless it is taken (`turnAhead`). */
|
|
394
|
+
private turnAsked;
|
|
395
|
+
/**
|
|
396
|
+
* Whether a key read in turn longer ago than `key`, still asking, would take this relay's next request: one read in the
|
|
397
|
+
* background for a background read, and a chat's that is starved (`READ_STARVED_MS`) for any. One asks again after
|
|
398
|
+
* the budget held it back (a link's poll does, a one-off look does not), and keeps asking within `READ_TURN_MS` of its
|
|
399
|
+
* last ask, or of when it was told the budget frees a request for it (`readHeldBackFor`).
|
|
400
|
+
* One the budget holds back on its own account (a group's read, for the chats' reserve) keeps no turn: a group key
|
|
401
|
+
* waiting for the chats held every chat's read back (CLI lab, 2026-10-13).
|
|
402
|
+
*/
|
|
403
|
+
private turnAhead;
|
|
404
|
+
/** A 1:1 chat's read of `key` the budget has held back for `READ_STARVED_MS` without a break. */
|
|
405
|
+
private starved;
|
|
384
406
|
/** This contact's departed reads past the limit in the last minute (`DEPARTED_READS`). */
|
|
385
407
|
private departedReads;
|
|
386
408
|
/** One more, the contacts with none in the last minute dropped. */
|
|
@@ -31,6 +31,8 @@ export type DiscoveryChange = "tripped" | "recovered";
|
|
|
31
31
|
* fast for a while, on the hub left and on its members alike: on CLI daemons the hub left got 2 of 24 beacon writes
|
|
32
32
|
* through in 90 s (its entry went stale, and members it should have carried became hubs), and the members' requests
|
|
33
33
|
* in its lobby went out 40 s after they asked (2026-10-03).
|
|
34
|
+
* A hub's reads say `door` only while someone is coming in (`Communities.doorBusy`): otherwise they give way like any
|
|
35
|
+
* background read, and an app that was a hub of several communities left its edges' signaling the share (2026-10-13).
|
|
34
36
|
*
|
|
35
37
|
* `signal`: a link's WebRTC signaling, what its contact waits for: the write of a new offer or answer, or a read for
|
|
36
38
|
* the answer while this side's offer is out, or the reads of a DHT-only contact's mailbox once it shows it is leaving,
|
|
@@ -119,6 +121,11 @@ export interface PkarrTransport {
|
|
|
119
121
|
* where the transport cannot say; such a caller then takes no read for one.
|
|
120
122
|
*/
|
|
121
123
|
readAnsweredAt?(pubKeyZ32: string): number | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* How long the budget still holds back a read of this key, when its last read was held back and answered from a kept
|
|
126
|
+
* copy (`readAnsweredAt` did not move): when to read again. Undefined once a read went out, or where it cannot say.
|
|
127
|
+
*/
|
|
128
|
+
readHeldBackFor?(pubKeyZ32: string): number | undefined;
|
|
122
129
|
/**
|
|
123
130
|
* Called with each time a server gave (`ServerTime`), where the transport can read one: what `ClockWatch` holds this
|
|
124
131
|
* device's clock against. Returns the unsubscribe.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Ql as boundVerifiedIdentity } from "./src-
|
|
1
|
+
import { Ql as boundVerifiedIdentity } from "./src-BqHTnRWH.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-RjMx7eW6.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify-
|
|
1
|
+
{"version":3,"file":"verify-RjMx7eW6.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,SAAS,UAAU,MAAM,IAAI,MAAM,0CAA0C;CAC/H,OAAO;AACT;;AAGA,SAAgB,mBAAmB,GAAoC;CACrE,MAAM,WAAqB,CAAC;CAC5B,IAAI,CAAC,yBAAyB,KAAK,EAAE,EAAE,GAAG,SAAS,KAAK,sCAAsC;CAC9F,IAAI,CAAC,EAAE,OAAO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ClB;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.2.
|
|
3
|
+
"version": "1.2.4",
|
|
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",
|