@ghostlytools/sdk 1.11.4 → 1.12.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 +1 -2
- package/dist/bitcoinAddress-C2MAmcDT.js +1225 -0
- package/dist/bitcoinAddress-C2MAmcDT.js.map +1 -0
- package/dist/bolt11-CRiQrma3.js +266 -0
- package/dist/bolt11-CRiQrma3.js.map +1 -0
- package/dist/core.js +41538 -336
- package/dist/core.js.map +1 -1
- package/dist/{fakes-CXeeyI4Z.js → fakes-Cgl1w4Nv.js} +6 -9
- package/dist/{fakes-CXeeyI4Z.js.map → fakes-Cgl1w4Nv.js.map} +1 -1
- package/dist/fakes.js +1 -2
- package/dist/index.js +8 -9
- package/dist/index.js.map +1 -1
- package/dist/{keet-identity-key-DLXTTFZH.js → keet-identity-key-LuoCuz1t.js} +648 -324
- package/dist/keet-identity-key-LuoCuz1t.js.map +1 -0
- package/dist/pairedTransports-CkYMAoYN.js +1149 -0
- package/dist/pairedTransports-CkYMAoYN.js.map +1 -0
- package/dist/rolldown-runtime-DpEnGzO4.js +45 -0
- package/dist/testing.js +7 -8
- package/dist/testing.js.map +1 -1
- package/dist/types/browser/src/shared/mints.d.ts +3 -1
- package/dist/types/core/src/chatFiles.d.ts +3 -1
- package/dist/types/core/src/communityRendezvous.d.ts +4 -0
- package/dist/types/core/src/dhtDelivery.d.ts +9 -0
- package/dist/types/core/src/engineErrors.d.ts +7 -0
- package/dist/types/core/src/ghostlink.d.ts +12 -0
- package/dist/types/core/src/groupCalls.d.ts +56 -0
- package/dist/types/core/src/groupCommunity.d.ts +16 -0
- package/dist/types/core/src/groupCrypto.d.ts +6 -0
- package/dist/types/core/src/groupMeta.d.ts +22 -0
- package/dist/types/core/src/groupSession.d.ts +14 -1
- package/dist/types/core/src/handoff.d.ts +0 -2
- package/dist/types/core/src/index.d.ts +1 -0
- package/dist/types/core/src/pairedTransports.d.ts +5 -0
- package/dist/types/core/src/relayBreaker.d.ts +5 -1
- package/dist/types/core/src/services.d.ts +6 -0
- package/dist/types/core/src/text.d.ts +2 -0
- package/dist/types/core/src/transport.d.ts +1 -1
- package/dist/{types-DYLIIkU8.js → types-DbgC491n.js} +2 -3
- package/dist/{types-DYLIIkU8.js.map → types-DbgC491n.js.map} +1 -1
- package/dist/{verify-B9s82dbd.js → verify-CSo7-43-.js} +3 -4
- package/dist/{verify-B9s82dbd.js.map → verify-CSo7-43-.js.map} +1 -1
- package/package.json +3 -3
- package/dist/keet-identity-key-DLXTTFZH.js.map +0 -1
- package/dist/src-CqAqFhh9.js +0 -43635
- package/dist/src-CqAqFhh9.js.map +0 -1
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A member's request for a pass to its group's call (WISP 602 · Group Calls § The token request): what it sends to
|
|
3
|
+
* `POST <sfu>/sfu/group-token`, signed by its group key over the node's origin, so the node can tell a member of the
|
|
4
|
+
* roster asked, for this node, within the last minute.
|
|
5
|
+
*
|
|
6
|
+
* {"v":1,"g":"<group>","k":"<member key>","room":"g_<group>","ts":1794700800,"n":"<nonce>","name":"Ana","sig":"…"}
|
|
7
|
+
*
|
|
8
|
+
* Pure: the node's own route, the e2e double and the tests share these checks. Whether `k` is in the roster is the
|
|
9
|
+
* node's to say, since only it follows the group's chain; every refusal here is one 403 there.
|
|
10
|
+
*/
|
|
11
|
+
export declare const GROUP_CALL_VERSION = 1;
|
|
12
|
+
/** How far a request's `ts` may be from the node's clock, either way, in seconds. */
|
|
13
|
+
export declare const GROUP_CALL_SKEW_S = 60;
|
|
14
|
+
/** How long a nonce the node took is kept, in seconds: past it, `ts` alone refuses the request. */
|
|
15
|
+
export declare const GROUP_CALL_NONCE_S = 120;
|
|
16
|
+
/** Longest display name a pass carries, in code points. */
|
|
17
|
+
export declare const MAX_GROUP_CALL_NAME = 64;
|
|
18
|
+
export interface GroupCallRequest {
|
|
19
|
+
v: typeof GROUP_CALL_VERSION;
|
|
20
|
+
g: string;
|
|
21
|
+
k: string;
|
|
22
|
+
room: string;
|
|
23
|
+
ts: number;
|
|
24
|
+
n: string;
|
|
25
|
+
name?: string;
|
|
26
|
+
sig: string;
|
|
27
|
+
}
|
|
28
|
+
/** Why a request was refused: for logs and tests only, the node answers each the same way. */
|
|
29
|
+
export type GroupCallRefusal = "malformed" | "stale" | "replayed" | "signature";
|
|
30
|
+
/** Nonces the node took, each with the time it was taken (unix seconds). */
|
|
31
|
+
export type GroupCallNonces = Map<string, number>;
|
|
32
|
+
/** A group's call room: `g_` and the group id, a namespace no guest pass may enter. */
|
|
33
|
+
export declare const groupCallRoom: (g: string) => string;
|
|
34
|
+
/** Exactly the bytes a member signs: the array form, as a leave statement is. */
|
|
35
|
+
export declare const groupCallRequestBytes: (sfu: string, g: string, room: string, k: string, ts: number, n: string) => Uint8Array<ArrayBufferLike>;
|
|
36
|
+
/** A request for `sfu` (the group's `call.sfu`, as read), signed by the member's group key `seed`. */
|
|
37
|
+
export declare function signGroupCallRequest(input: {
|
|
38
|
+
sfu: string;
|
|
39
|
+
g: string;
|
|
40
|
+
name?: string;
|
|
41
|
+
ts?: number;
|
|
42
|
+
n?: string;
|
|
43
|
+
}, seed: Uint8Array): GroupCallRequest;
|
|
44
|
+
/**
|
|
45
|
+
* The node's checks but the roster, in order: the shape, the time within `GROUP_CALL_SKEW_S` of `now` (ms), a nonce
|
|
46
|
+
* not in `seen`, and the signature over the node's own origin `sfu`. A request that passes has its nonce added to
|
|
47
|
+
* `seen`; entries older than `GROUP_CALL_NONCE_S` are dropped on the way. The name comes back clean and cut to
|
|
48
|
+
* `MAX_GROUP_CALL_NAME` code points, or left out.
|
|
49
|
+
*/
|
|
50
|
+
export declare function verifyGroupCallRequest(raw: unknown, sfu: string, now: number, seen: GroupCallNonces): {
|
|
51
|
+
ok: true;
|
|
52
|
+
request: GroupCallRequest;
|
|
53
|
+
} | {
|
|
54
|
+
ok: false;
|
|
55
|
+
reason: GroupCallRefusal;
|
|
56
|
+
};
|
|
@@ -634,6 +634,11 @@ export declare class CommunitySession {
|
|
|
634
634
|
get others(): string[];
|
|
635
635
|
get isMember(): boolean;
|
|
636
636
|
get canSend(): boolean;
|
|
637
|
+
/** The call key of the newest epoch (WISP 602), or null until its secret arrives or once I am out. */
|
|
638
|
+
callKey(): {
|
|
639
|
+
epoch: number;
|
|
640
|
+
key: Uint8Array;
|
|
641
|
+
} | null;
|
|
637
642
|
/** The entry key of the group's link, or "" when it is off. */
|
|
638
643
|
get entryKey(): string;
|
|
639
644
|
/**
|
|
@@ -644,6 +649,11 @@ export declare class CommunitySession {
|
|
|
644
649
|
role(key: string): GroupRole | undefined;
|
|
645
650
|
/** The group's picture, if it has one. */
|
|
646
651
|
get picture(): string | undefined;
|
|
652
|
+
/** The node that forwards the group's calls, while the statement I keep names one that holds (WISP 602). */
|
|
653
|
+
get call(): {
|
|
654
|
+
sfu: string;
|
|
655
|
+
e2ee?: 1;
|
|
656
|
+
} | undefined;
|
|
647
657
|
/**
|
|
648
658
|
* Members of any epoch in the window: whom a frame may come from. A side commit's roster counts only while its branch
|
|
649
659
|
* could still win (`mayWin`): one let in only on a branch that lost is not in the roster anyone sees, and the main
|
|
@@ -1085,6 +1095,12 @@ export declare class CommunitySession {
|
|
|
1085
1095
|
setPicture(picture: string | null, now?: number): Promise<void>;
|
|
1086
1096
|
/** Renames the group: only the admin, signed under the current commit, beside the picture. */
|
|
1087
1097
|
rename(name: string, now?: number): Promise<void>;
|
|
1098
|
+
/**
|
|
1099
|
+
* Names (or, with null, removes) the node that forwards the group's calls (WISP 602): only the admin, beside the name
|
|
1100
|
+
* and picture. `e2ee` turns sealed call media on or off (§ End-to-end encryption); left out, the group keeps what it
|
|
1101
|
+
* had, so naming the node again does not turn it off.
|
|
1102
|
+
*/
|
|
1103
|
+
setCall(sfu: string | null, e2ee?: boolean, now?: number): Promise<void>;
|
|
1088
1104
|
/**
|
|
1089
1105
|
* Signs a body under my current commit, keeps it and sends it to everyone (hubs relay it). Inside `serialize`. Like a
|
|
1090
1106
|
* commit, only with admin work on and a good turn read (WISP 06 § Forced takeover): refused otherwise, or, `quiet`,
|
|
@@ -20,6 +20,12 @@ export declare function epochKeys(secret: Uint8Array, groupId: string, epoch: nu
|
|
|
20
20
|
message: Uint8Array;
|
|
21
21
|
confirm: Uint8Array;
|
|
22
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* The key that seals a `group-community/1` group's call media end to end (WISP 602): the epoch's secret and salt, under
|
|
25
|
+
* its own label, so it is never a message key. Every member of the epoch derives the same one; a member taken out gets
|
|
26
|
+
* no later secret, so not the next key either.
|
|
27
|
+
*/
|
|
28
|
+
export declare function groupCallKey(secret: Uint8Array, groupId: string, epoch: number): Uint8Array;
|
|
23
29
|
export declare function newEpochSecret(): Uint8Array;
|
|
24
30
|
export interface SealedSecret {
|
|
25
31
|
e: string;
|
|
@@ -35,7 +35,29 @@ export interface GroupMetaBody {
|
|
|
35
35
|
pic?: string;
|
|
36
36
|
/** Private groups: members the admin pins as hubs, and excludes (WISP 902 · Group Mesh § Hubs). Apps from before ignore it. */
|
|
37
37
|
hubs?: MeshHubPolicy;
|
|
38
|
+
/**
|
|
39
|
+
* Community groups: the node that forwards the group's calls (WISP 602 § The group names its node), and `e2ee: 1` when
|
|
40
|
+
* the admin turned on sealed call media (WISP 602 § End-to-end encryption). Apps from before ignore it.
|
|
41
|
+
*/
|
|
42
|
+
call?: {
|
|
43
|
+
sfu: string;
|
|
44
|
+
e2ee?: 1;
|
|
45
|
+
};
|
|
38
46
|
}
|
|
47
|
+
/** Longest call node origin a group may name, in characters (WISP 602). */
|
|
48
|
+
export declare const MAX_GROUP_CALL_SFU = 200;
|
|
49
|
+
/**
|
|
50
|
+
* Whether a `call`'s `e2ee` turns sealed call media on (WISP 602 § End-to-end encryption): `1`, as every writer writes
|
|
51
|
+
* it, or `true`, read as on so a body that says it as a JSON flag never leaves a call unsealed. Anything else is off.
|
|
52
|
+
* Read either way, it is kept and written again as `1`.
|
|
53
|
+
*/
|
|
54
|
+
export declare const groupCallE2ee: (raw: unknown) => boolean;
|
|
55
|
+
/**
|
|
56
|
+
* A group's call node as WISP 602 takes it: an `https` origin in its one spelling (`new URL(sfu).origin`: lower-case
|
|
57
|
+
* host, no default port, path, query, fragment, userinfo or trailing `/`), at most `MAX_GROUP_CALL_SFU` characters.
|
|
58
|
+
* Undefined otherwise: it is signed into every token request, so a second spelling is no call node.
|
|
59
|
+
*/
|
|
60
|
+
export declare function groupCallSfu(raw: unknown): string | undefined;
|
|
39
61
|
export interface GroupMetaStatement {
|
|
40
62
|
g: string;
|
|
41
63
|
/** The commit the admin signs under: its epoch (index in the chain) and hash. */
|
|
@@ -644,6 +644,12 @@ export declare class GroupSession {
|
|
|
644
644
|
filledSince(sender: string, asked: Record<string, number[]>): boolean;
|
|
645
645
|
private serialize;
|
|
646
646
|
private persist;
|
|
647
|
+
/**
|
|
648
|
+
* The state as a save takes it: the session goes on changing its own. The chain carries the whole roster at every
|
|
649
|
+
* commit and is never compacted (1.4 ms a deep copy at 271 commits in a group of 31, 0.1 ms for the rest), and a
|
|
650
|
+
* commit on it is signed and never changes: the copy shares the commits, in an array of its own.
|
|
651
|
+
*/
|
|
652
|
+
private copy;
|
|
647
653
|
/**
|
|
648
654
|
* A save within `GROUP_LIMITS.saveWithinMs`, for what a received message, commit or secret changes (what was seen,
|
|
649
655
|
* what is kept to hand on, the chain): the state holds the whole hand-on log and chain, and a member back in a busy
|
|
@@ -763,6 +769,13 @@ export declare class GroupSession {
|
|
|
763
769
|
private seal;
|
|
764
770
|
/** Into my bounded log, for members who missed it. */
|
|
765
771
|
private logOwn;
|
|
772
|
+
/**
|
|
773
|
+
* My message `id` was deleted for everyone: its frame, and each copy said again, keep their place in my log (`nextSeq`,
|
|
774
|
+
* `couldRead`, the removal's copies) and lose what they said. The log is in the saved state beside the epochs' secrets,
|
|
775
|
+
* so the text stayed readable from the profile until 32 later sends pushed it out (`message delete --purge` promises
|
|
776
|
+
* it leaves the folder). Saved soon, as a community's `forget`; `flush` writes it now.
|
|
777
|
+
*/
|
|
778
|
+
forget(id: string): void;
|
|
766
779
|
/**
|
|
767
780
|
* 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:
|
|
768
781
|
* my app just opened) is remembered (`alone`): I may be behind on the chain without knowing, and members let in
|
|
@@ -997,7 +1010,7 @@ export declare class GroupSession {
|
|
|
997
1010
|
/** My own messages a member's sync says it lacks, from my bounded log, for the epochs it was a member of. */
|
|
998
1011
|
private handOwn;
|
|
999
1012
|
private ownLacked;
|
|
1000
|
-
/** A frame of a message deleted for everyone (`hooks.removed`): handed to nobody, its removal is what they get. */
|
|
1013
|
+
/** A frame of a message deleted for everyone (`hooks.removed`, or one of mine `forget` emptied): handed to nobody, its removal is what they get. */
|
|
1001
1014
|
private isRemoved;
|
|
1002
1015
|
/** Sets (or, with null, removes) the group's picture: only the admin, signed under the current commit. */
|
|
1003
1016
|
setPicture(picture: string | null, now?: number): Promise<void>;
|
|
@@ -251,5 +251,3 @@ export declare function handoffAttemptFailed(attempts: HandoffAttempts | undefin
|
|
|
251
251
|
export declare const handoffAttemptSucceeded: () => HandoffAttempts;
|
|
252
252
|
/** Seconds until a locked-out device may try again (for `handoff-busy`). */
|
|
253
253
|
export declare const handoffRetryAfter: (attempts: HandoffAttempts | undefined, now: number) => number;
|
|
254
|
-
/** Two digests compared. */
|
|
255
|
-
export declare const sameDigest: (a: Uint8Array, b: Uint8Array) => boolean;
|
|
@@ -98,6 +98,7 @@ export * from "./groupCommunity.js";
|
|
|
98
98
|
export * from "./communityRendezvous.js";
|
|
99
99
|
export * from "./groupHubs.js";
|
|
100
100
|
export * from "./groupSignals.js";
|
|
101
|
+
export * from "./groupCalls.js";
|
|
101
102
|
export * from "./groupMeta.js";
|
|
102
103
|
export * from "./groupTyping.js";
|
|
103
104
|
export * from "./groupFiles.js";
|
|
@@ -59,6 +59,11 @@ 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
|
+
* A relay URL `relayUrl` refuses for its length alone (past 120 characters, a loopback path past 100): a relay setting
|
|
64
|
+
* asks for a shorter one, where "not a relay address" sent the person looking for a typo in it.
|
|
65
|
+
*/
|
|
66
|
+
export declare const relayUrlTooLong: (value: string) => boolean;
|
|
62
67
|
/**
|
|
63
68
|
* Whether an Iroh endpoint may dial a contact through the relay its descriptor names (none: a direct address alone).
|
|
64
69
|
* 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
|
|
@@ -102,6 +102,10 @@ export declare class RelayBreaker {
|
|
|
102
102
|
askedAgainIn(relay: string, relays: string[]): number;
|
|
103
103
|
/** A new network: every relay starts fresh. */
|
|
104
104
|
reset(): void;
|
|
105
|
-
/**
|
|
105
|
+
/**
|
|
106
|
+
* Each relay's health, in the order given. While every one is left alone for failing, `until` is the next probe
|
|
107
|
+
* (`allDownProbe`, every 15 s), whose answer ends the wait of them all: said as the end of each one's wait, a daemon's
|
|
108
|
+
* `status` and the connection panel named a time up to 5 minutes after the relays were seen answering again.
|
|
109
|
+
*/
|
|
106
110
|
health(relays: string[]): RelayHealth[];
|
|
107
111
|
}
|
|
@@ -13,6 +13,12 @@ export declare const HTTP_SERVICE_PROTO = "ghostly-http/1";
|
|
|
13
13
|
export declare const MAX_SERVICES = 16;
|
|
14
14
|
/** What a peer that predates `_svc` offers implicitly. */
|
|
15
15
|
export declare const LEGACY_SERVICES: ServiceAd[];
|
|
16
|
+
/**
|
|
17
|
+
* How many of its web apps one contact may be granted: a chat not paired yet tells chat, voice and video first, and a
|
|
18
|
+
* contact keeps only the first `MAX_SERVICES` of a list (`servicesFromWire`). A grant past it would read as shared here
|
|
19
|
+
* and never reach the contact.
|
|
20
|
+
*/
|
|
21
|
+
export declare const MAX_SHARED_APPS: number;
|
|
16
22
|
export declare function isValidServiceId(id: string): boolean;
|
|
17
23
|
/**
|
|
18
24
|
* The label that makes the origin a contact's app opens in this side's own (WISP 04): derived from the key this
|
|
@@ -32,5 +32,7 @@ export declare function trimEndOf(text: string, chars: string): string;
|
|
|
32
32
|
* of "Join us: <https://…#ghostly1…>!", "« ghostly1… »" or "code: ghostly1…". The last word, without the quotes,
|
|
33
33
|
* brackets and marks before and after it. Readers try it only once the paste itself did not read, so a bare token
|
|
34
34
|
* reads as it always did and a token with a character lost is still refused as one.
|
|
35
|
+
* A `/` a link ends with (typed, or added by a chat app's linkifier: `…/#/join/group2/…/`) is not the token's either,
|
|
36
|
+
* as `inviteRouteCode` drops it from an invite's route; a bare address keeps its own (`https://ghostly.tools/`).
|
|
35
37
|
*/
|
|
36
38
|
export declare function unwrapPasted(text: string): string;
|
|
@@ -100,8 +100,8 @@ export declare function withRequestOptions(transport: PkarrTransport, extra: Pka
|
|
|
100
100
|
* whoever publishes tries again then, and says nothing is wrong meanwhile.
|
|
101
101
|
*/
|
|
102
102
|
export declare class DiscoveryBudgetError extends Error {
|
|
103
|
+
readonly code: "discovery-budget";
|
|
103
104
|
readonly retryInMs: number;
|
|
104
|
-
readonly code = "discovery-budget";
|
|
105
105
|
constructor(retryInMs: number, message?: string);
|
|
106
106
|
}
|
|
107
107
|
/** Whether `error` is a request the budget held back (`DiscoveryBudgetError`), also from another copy of this module. */
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// ../browser/src/engine/paymentAdapters/providers/types.ts
|
|
2
2
|
var PROVIDER_PLATFORMS = [
|
|
3
3
|
"web",
|
|
4
4
|
"extension",
|
|
@@ -94,7 +94,6 @@ function redact(error, secrets = {}) {
|
|
|
94
94
|
for (const value of Object.values(secrets)) if (value && value.length >= 4) message = message.split(value).join("•••");
|
|
95
95
|
return message.slice(0, 300);
|
|
96
96
|
}
|
|
97
|
-
//#endregion
|
|
98
97
|
export { describeProvider as a, offeredIn as c, PROVIDER_PLATFORMS as i, providerDescriptorProblems as l, PROVIDER_ID as n, isNothingSpentError as o, PROVIDER_NETWORKS as r, networkMode as s, NothingSpentError as t, redact as u };
|
|
99
98
|
|
|
100
|
-
//# sourceMappingURL=types-
|
|
99
|
+
//# sourceMappingURL=types-DbgC491n.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-DYLIIkU8.js","names":[],"sources":["../../browser/src/engine/paymentAdapters/providers/types.ts"],"sourcesContent":["import type { BitcoinNetwork } from \"@ghostly/core\";\nimport type { WalletMode } from \"../../../shared/mints\";\n\n/**\n * What every wallet provider (a source of Lightning or of on-chain Bitcoin) shares: where it runs, how\n * it is configured, and the one distinction that keeps money safe. See PROVIDERS.md.\n */\n\n/** Where Ghostly runs: the web app, the browser extension (engine in an offscreen document), the Tauri app. */\nexport type ProviderPlatform = \"web\" | \"extension\" | \"desktop\";\nexport const PROVIDER_PLATFORMS: readonly ProviderPlatform[] = [\"web\", \"extension\", \"desktop\"];\nexport type ProviderKind = \"lightning\" | \"onchain\";\n/** The chain a provider's sats live on. Only `bitcoin` is real money; the others belong to the Testnet mode. */\nexport type ProviderNetwork = BitcoinNetwork;\nexport const PROVIDER_NETWORKS: readonly ProviderNetwork[] = [\"bitcoin\", \"signet\", \"testnet\", \"regtest\", \"mutinynet\"];\nexport const networkMode = (network: ProviderNetwork): WalletMode => (network === \"bitcoin\" ? \"mainnet\" : \"testnet\");\n\n/**\n * One field of a provider's configuration form. The wallet card renders these; a provider that needs\n * more registers its own form component instead (apps/ui/src/components/wallet/providers/forms.ts).\n * `secret` fields (an NWC URI, a macaroon, a rune, an API key, a password) are sealed before they are\n * stored, never shown again, never put in the engine state, and never logged.\n */\nexport interface ProviderField {\n name: string;\n label: string;\n kind: \"text\" | \"url\" | \"secret\" | \"select\" | \"textarea\";\n placeholder?: string;\n help?: string;\n optional?: boolean;\n /** `select` only. */\n options?: { value: string; label: string }[];\n /** Pre-filled per mode, e.g. a public test server for Testnet. */\n defaults?: Partial<Record<WalletMode, string>>;\n /**\n * Values offered under a `url` or `text` field (a list to pick from, anything may still be typed), each\n * only while the other fields hold `when`: e.g. a public Esplora server per network.\n */\n suggestions?: { value: string; label: string; when?: Record<string, string> }[];\n /**\n * A server address that can be changed on a saved source without its secrets being typed again, and\n * without changing whose money it is: an Esplora server of a BDK wallet (the wallet is the phrase). The\n * source's \"Change server\" edits these fields only. Never mark a field that picks another account (a\n * node's URL: another node is other money).\n */\n changeable?: boolean;\n}\n\n/** What the person typed, split by the field kinds: `config` is shown back, `secrets` never is. */\nexport interface ProviderSettings {\n config: Record<string, string>;\n secrets: Record<string, string>;\n}\n\n/** What the engine hands a provider's factory. */\nexport interface ProviderHost {\n platform: ProviderPlatform;\n /** The wallet mode the source is for: its provider must be on a network of this mode. */\n mode: WalletMode;\n /**\n * Reserved for the built-in Cashu mint source: the engine's own wallet. It is not part of the SDK, and\n * no other provider should read it.\n */\n cashu?: unknown;\n /**\n * Reserved for the built-in Cashu mint source: the Cashu balance of the mode in the engine's last wallet view, once\n * there is one. The view is made again whenever the wallet changes.\n */\n cashuBalance?: () => number | undefined;\n /** Reserved for the built-in Fedimint source: the engine's Fedimint wallet (its joined federations). Not part of the SDK. */\n fedimint?: unknown;\n /** Ends when the source is replaced, the mode switches or the engine stops: abort long waits on it. */\n signal: AbortSignal;\n /**\n * Desktop only: calls a command of the Tauri app (apps/desktop), for what a WebView cannot do (a pinned\n * certificate, no CORS, a raw socket). Absent on the web and in the extension.\n */\n invoke?: <T>(command: string, args: Record<string, unknown>) => Promise<T>;\n}\n\n/**\n * A provider module's export. Registering a provider is adding its module and one line in\n * `registry.ts`; everything else (storage, sealing, per-mode sources, the card, journals) is shared.\n */\nexport interface ProviderDescriptor<P> {\n id: string;\n label: string;\n kind: ProviderKind;\n /** One line under the name in the source picker: what it is and who holds the money. */\n description: string;\n /** Networks it can run on. A mode lists only providers with a network of that mode. */\n networks: readonly ProviderNetwork[];\n platforms: readonly ProviderPlatform[];\n fields: readonly ProviderField[];\n /** Custodial (someone else holds the sats) or still experimental: said in the picker. */\n custodial?: boolean;\n experimental?: boolean;\n /** Checks the form before anything is contacted; throws a message fit for the person. */\n validate?(settings: ProviderSettings, mode: WalletMode): void;\n /**\n * The wallet these (validated) settings reach, whatever their spelling: two sources with the same answer are one\n * wallet, and the same balance. Absent: the same settings, byte for byte.\n */\n wallet?(settings: ProviderSettings): string;\n /** Connects. The engine then asks `info()` and refuses a network of the other mode. */\n create(settings: ProviderSettings, host: ProviderHost): Promise<P>;\n}\n\n/** A provider can be offered here: it runs on this platform and on a network of this mode. */\nexport const offeredIn = (descriptor: { platforms: readonly ProviderPlatform[]; networks: readonly ProviderNetwork[] }, platform: ProviderPlatform, mode: WalletMode) =>\n descriptor.platforms.includes(platform) && descriptor.networks.some((network) => networkMode(network) === mode);\n\nconst FIELD_KINDS = [\"text\", \"url\", \"secret\", \"select\", \"textarea\"];\n/** What is stored with the profile and sent on the wire in journals: stable, short, lowercase. */\nexport const PROVIDER_ID = /^[a-z][a-z0-9-]{0,31}$/;\n\n/**\n * Problems with a provider descriptor, empty when it is well-formed. The registry refuses a descriptor\n * with any; the contract suite checks the same list, so an author sees them before the app does.\n */\nexport function providerDescriptorProblems(d: ProviderDescriptor<unknown>): string[] {\n const problems: string[] = [];\n if (!PROVIDER_ID.test(d.id ?? \"\")) problems.push(\"id must match ^[a-z][a-z0-9-]{0,31}$\");\n if (!d.label?.trim()) problems.push(\"label is empty\");\n if (d.kind !== \"lightning\" && d.kind !== \"onchain\") problems.push(\"kind must be lightning or onchain\");\n if (!d.description?.trim()) problems.push(\"description is empty: say what it is and who holds the money\");\n if (!Array.isArray(d.networks) || !d.networks.length) problems.push(\"no networks\");\n else for (const n of d.networks) if (!PROVIDER_NETWORKS.includes(n)) problems.push(`unknown network ${String(n)}`);\n if (!Array.isArray(d.platforms) || !d.platforms.length) problems.push(\"no platforms\");\n else for (const p of d.platforms) if (!PROVIDER_PLATFORMS.includes(p)) problems.push(`unknown platform ${String(p)}`);\n if (!Array.isArray(d.fields)) problems.push(\"fields must be a list (empty when there is nothing to configure)\");\n else {\n const names = d.fields.map((f) => f.name);\n if (new Set(names).size !== names.length) problems.push(\"field names are not unique\");\n for (const f of d.fields) {\n if (!/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(f.name ?? \"\")) problems.push(`field ${String(f.name)} has an invalid name`);\n if (!f.label?.trim()) problems.push(`field ${f.name} has no label`);\n if (!FIELD_KINDS.includes(f.kind)) problems.push(`field ${f.name} has an unknown kind`);\n if (f.kind === \"select\" && !f.options?.length) problems.push(`field ${f.name} is a select without options`);\n if (f.suggestions !== undefined && (!Array.isArray(f.suggestions) || f.suggestions.some((o: { value?: unknown; label?: unknown } | undefined) => typeof o?.value !== \"string\" || typeof o?.label !== \"string\"))) problems.push(`field ${f.name} has malformed suggestions`);\n if (f.changeable && (f.kind === \"secret\" || f.kind === \"select\")) problems.push(`field ${f.name} cannot be changeable: only a server address can`);\n }\n }\n if (typeof d.create !== \"function\") problems.push(\"create is not a function\");\n if (d.validate !== undefined && typeof d.validate !== \"function\") problems.push(\"validate is not a function\");\n if (d.wallet !== undefined && typeof d.wallet !== \"function\") problems.push(\"wallet is not a function\");\n return problems;\n}\n\n/** The serializable part of a descriptor, for the UI (a function cannot cross the extension's port). */\nexport type ProviderDescriptorView = Omit<ProviderDescriptor<unknown>, \"create\" | \"validate\" | \"wallet\">;\n/** Only these fields reach the UI, whatever else a provider module keeps on its descriptor. */\nexport const describeProvider = ({ id, label, kind, description, networks, platforms, fields, custodial, experimental }: ProviderDescriptor<unknown>): ProviderDescriptorView =>\n ({ id, label, kind, description, networks, platforms, fields, custodial, experimental });\n\n/**\n * The provider proved that nothing left the wallet (refused before sending, no route found before any\n * HTLC, a transaction that was never broadcast). Safe to try again, with this or another source.\n *\n * Any other error from a spend means the outcome is UNKNOWN: the payment may be in flight or done. It is\n * recorded as such and only reconciled (asked about), never retried. When in doubt, do not throw this.\n */\nexport class NothingSpentError extends Error {\n constructor(message: string) { super(message); this.name = \"NothingSpentError\"; }\n}\n\n/**\n * The source could not be reached: no answer, a time-out, a refused connection, a server error. The\n * engine keeps trying by itself (with backoff) and shows the source as connecting meanwhile.\n */\nexport class SourceUnreachableError extends Error {\n constructor(message: string, cause?: unknown) { super(message); this.name = \"SourceUnreachableError\"; if (cause !== undefined) Object.assign(this, { cause }); }\n}\n\n/**\n * A setting of the source is wrong (a server on another network, a phrase that makes no wallet): trying\n * again changes nothing until the setting does. The engine shows it as unavailable at once.\n */\nexport class SourceConfigError extends Error {\n constructor(message: string, cause?: unknown) { super(message); this.name = \"SourceConfigError\"; if (cause !== undefined) Object.assign(this, { cause }); }\n}\n\n/** What went wrong connecting a source, by name (a plugin bundles its own copies of these classes). */\nexport type SourceProblem = \"unreachable\" | \"config\" | \"other\";\nexport const sourceProblem = (error: unknown): SourceProblem =>\n error instanceof Error && error.name === \"SourceUnreachableError\" ? \"unreachable\" : error instanceof Error && error.name === \"SourceConfigError\" ? \"config\" : \"other\";\n\n/**\n * Whether an error says nothing was spent. By name, not by class: a provider built outside the app (an\n * SDK plugin bundled with its own copy of `NothingSpentError`) must be understood the same way.\n */\nexport const isNothingSpentError = (error: unknown): error is NothingSpentError =>\n error instanceof NothingSpentError || (error instanceof Error && error.name === \"NothingSpentError\");\n\n/**\n * An error message fit to show and store: every secret the source was given is blanked out, in case a\n * library echoed a URI or a key back.\n */\nexport function redact(error: unknown, secrets: Record<string, string> = {}): string {\n let message = error instanceof Error ? error.message : String(error);\n for (const value of Object.values(secrets)) if (value && value.length >= 4) message = message.split(value).join(\"•••\");\n return message.slice(0, 300);\n}\n"],"mappings":";AAUA,IAAa,qBAAkD;CAAC;CAAO;CAAa;AAAS;AAI7F,IAAa,oBAAgD;CAAC;CAAW;CAAU;CAAW;CAAW;AAAW;AACpH,IAAa,eAAe,YAA0C,YAAY,YAAY,YAAY;;AA8F1G,IAAa,aAAa,YAA8F,UAA4B,SAClJ,WAAW,UAAU,SAAS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AM,UAAU,OAAO,KAAK;CACnE,KAAK,MAAM,SAAS,OAAO,OAAO,OAAO,GAAG,IAAI,SAAS,MAAM,UAAU,GAAG,UAAU,QAAQ,MAAM,KAAK,CAAC,CAAC,KAAK,KAAK;CACrH,OAAO,QAAQ,MAAM,GAAG,GAAG;AAC7B"}
|
|
1
|
+
{"version":3,"file":"types-DbgC491n.js","names":[],"sources":["../../browser/src/engine/paymentAdapters/providers/types.ts"],"sourcesContent":["import type { BitcoinNetwork } from \"@ghostly/core\";\nimport type { WalletMode } from \"../../../shared/mints\";\n\n/**\n * What every wallet provider (a source of Lightning or of on-chain Bitcoin) shares: where it runs, how\n * it is configured, and the one distinction that keeps money safe. See PROVIDERS.md.\n */\n\n/** Where Ghostly runs: the web app, the browser extension (engine in an offscreen document), the Tauri app. */\nexport type ProviderPlatform = \"web\" | \"extension\" | \"desktop\";\nexport const PROVIDER_PLATFORMS: readonly ProviderPlatform[] = [\"web\", \"extension\", \"desktop\"];\nexport type ProviderKind = \"lightning\" | \"onchain\";\n/** The chain a provider's sats live on. Only `bitcoin` is real money; the others belong to the Testnet mode. */\nexport type ProviderNetwork = BitcoinNetwork;\nexport const PROVIDER_NETWORKS: readonly ProviderNetwork[] = [\"bitcoin\", \"signet\", \"testnet\", \"regtest\", \"mutinynet\"];\nexport const networkMode = (network: ProviderNetwork): WalletMode => (network === \"bitcoin\" ? \"mainnet\" : \"testnet\");\n\n/**\n * One field of a provider's configuration form. The wallet card renders these; a provider that needs\n * more registers its own form component instead (apps/ui/src/components/wallet/providers/forms.ts).\n * `secret` fields (an NWC URI, a macaroon, a rune, an API key, a password) are sealed before they are\n * stored, never shown again, never put in the engine state, and never logged.\n */\nexport interface ProviderField {\n name: string;\n label: string;\n kind: \"text\" | \"url\" | \"secret\" | \"select\" | \"textarea\";\n placeholder?: string;\n help?: string;\n optional?: boolean;\n /** `select` only. */\n options?: { value: string; label: string }[];\n /** Pre-filled per mode, e.g. a public test server for Testnet. */\n defaults?: Partial<Record<WalletMode, string>>;\n /**\n * Values offered under a `url` or `text` field (a list to pick from, anything may still be typed), each\n * only while the other fields hold `when`: e.g. a public Esplora server per network.\n */\n suggestions?: { value: string; label: string; when?: Record<string, string> }[];\n /**\n * A server address that can be changed on a saved source without its secrets being typed again, and\n * without changing whose money it is: an Esplora server of a BDK wallet (the wallet is the phrase). The\n * source's \"Change server\" edits these fields only. Never mark a field that picks another account (a\n * node's URL: another node is other money).\n */\n changeable?: boolean;\n}\n\n/** What the person typed, split by the field kinds: `config` is shown back, `secrets` never is. */\nexport interface ProviderSettings {\n config: Record<string, string>;\n secrets: Record<string, string>;\n}\n\n/** What the engine hands a provider's factory. */\nexport interface ProviderHost {\n platform: ProviderPlatform;\n /** The wallet mode the source is for: its provider must be on a network of this mode. */\n mode: WalletMode;\n /**\n * Reserved for the built-in Cashu mint source: the engine's own wallet. It is not part of the SDK, and\n * no other provider should read it.\n */\n cashu?: unknown;\n /**\n * Reserved for the built-in Cashu mint source: the Cashu balance of the mode in the engine's last wallet view, once\n * there is one. The view is made again whenever the wallet changes.\n */\n cashuBalance?: () => number | undefined;\n /** Reserved for the built-in Fedimint source: the engine's Fedimint wallet (its joined federations). Not part of the SDK. */\n fedimint?: unknown;\n /** Ends when the source is replaced, the mode switches or the engine stops: abort long waits on it. */\n signal: AbortSignal;\n /**\n * Desktop only: calls a command of the Tauri app (apps/desktop), for what a WebView cannot do (a pinned\n * certificate, no CORS, a raw socket). Absent on the web and in the extension.\n */\n invoke?: <T>(command: string, args: Record<string, unknown>) => Promise<T>;\n}\n\n/**\n * A provider module's export. Registering a provider is adding its module and one line in\n * `registry.ts`; everything else (storage, sealing, per-mode sources, the card, journals) is shared.\n */\nexport interface ProviderDescriptor<P> {\n id: string;\n label: string;\n kind: ProviderKind;\n /** One line under the name in the source picker: what it is and who holds the money. */\n description: string;\n /** Networks it can run on. A mode lists only providers with a network of that mode. */\n networks: readonly ProviderNetwork[];\n platforms: readonly ProviderPlatform[];\n fields: readonly ProviderField[];\n /** Custodial (someone else holds the sats) or still experimental: said in the picker. */\n custodial?: boolean;\n experimental?: boolean;\n /** Checks the form before anything is contacted; throws a message fit for the person. */\n validate?(settings: ProviderSettings, mode: WalletMode): void;\n /**\n * The wallet these (validated) settings reach, whatever their spelling: two sources with the same answer are one\n * wallet, and the same balance. Absent: the same settings, byte for byte.\n */\n wallet?(settings: ProviderSettings): string;\n /** Connects. The engine then asks `info()` and refuses a network of the other mode. */\n create(settings: ProviderSettings, host: ProviderHost): Promise<P>;\n}\n\n/** A provider can be offered here: it runs on this platform and on a network of this mode. */\nexport const offeredIn = (descriptor: { platforms: readonly ProviderPlatform[]; networks: readonly ProviderNetwork[] }, platform: ProviderPlatform, mode: WalletMode) =>\n descriptor.platforms.includes(platform) && descriptor.networks.some((network) => networkMode(network) === mode);\n\nconst FIELD_KINDS = [\"text\", \"url\", \"secret\", \"select\", \"textarea\"];\n/** What is stored with the profile and sent on the wire in journals: stable, short, lowercase. */\nexport const PROVIDER_ID = /^[a-z][a-z0-9-]{0,31}$/;\n\n/**\n * Problems with a provider descriptor, empty when it is well-formed. The registry refuses a descriptor\n * with any; the contract suite checks the same list, so an author sees them before the app does.\n */\nexport function providerDescriptorProblems(d: ProviderDescriptor<unknown>): string[] {\n const problems: string[] = [];\n if (!PROVIDER_ID.test(d.id ?? \"\")) problems.push(\"id must match ^[a-z][a-z0-9-]{0,31}$\");\n if (!d.label?.trim()) problems.push(\"label is empty\");\n if (d.kind !== \"lightning\" && d.kind !== \"onchain\") problems.push(\"kind must be lightning or onchain\");\n if (!d.description?.trim()) problems.push(\"description is empty: say what it is and who holds the money\");\n if (!Array.isArray(d.networks) || !d.networks.length) problems.push(\"no networks\");\n else for (const n of d.networks) if (!PROVIDER_NETWORKS.includes(n)) problems.push(`unknown network ${String(n)}`);\n if (!Array.isArray(d.platforms) || !d.platforms.length) problems.push(\"no platforms\");\n else for (const p of d.platforms) if (!PROVIDER_PLATFORMS.includes(p)) problems.push(`unknown platform ${String(p)}`);\n if (!Array.isArray(d.fields)) problems.push(\"fields must be a list (empty when there is nothing to configure)\");\n else {\n const names = d.fields.map((f) => f.name);\n if (new Set(names).size !== names.length) problems.push(\"field names are not unique\");\n for (const f of d.fields) {\n if (!/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(f.name ?? \"\")) problems.push(`field ${String(f.name)} has an invalid name`);\n if (!f.label?.trim()) problems.push(`field ${f.name} has no label`);\n if (!FIELD_KINDS.includes(f.kind)) problems.push(`field ${f.name} has an unknown kind`);\n if (f.kind === \"select\" && !f.options?.length) problems.push(`field ${f.name} is a select without options`);\n if (f.suggestions !== undefined && (!Array.isArray(f.suggestions) || f.suggestions.some((o: { value?: unknown; label?: unknown } | undefined) => typeof o?.value !== \"string\" || typeof o?.label !== \"string\"))) problems.push(`field ${f.name} has malformed suggestions`);\n if (f.changeable && (f.kind === \"secret\" || f.kind === \"select\")) problems.push(`field ${f.name} cannot be changeable: only a server address can`);\n }\n }\n if (typeof d.create !== \"function\") problems.push(\"create is not a function\");\n if (d.validate !== undefined && typeof d.validate !== \"function\") problems.push(\"validate is not a function\");\n if (d.wallet !== undefined && typeof d.wallet !== \"function\") problems.push(\"wallet is not a function\");\n return problems;\n}\n\n/** The serializable part of a descriptor, for the UI (a function cannot cross the extension's port). */\nexport type ProviderDescriptorView = Omit<ProviderDescriptor<unknown>, \"create\" | \"validate\" | \"wallet\">;\n/** Only these fields reach the UI, whatever else a provider module keeps on its descriptor. */\nexport const describeProvider = ({ id, label, kind, description, networks, platforms, fields, custodial, experimental }: ProviderDescriptor<unknown>): ProviderDescriptorView =>\n ({ id, label, kind, description, networks, platforms, fields, custodial, experimental });\n\n/**\n * The provider proved that nothing left the wallet (refused before sending, no route found before any\n * HTLC, a transaction that was never broadcast). Safe to try again, with this or another source.\n *\n * Any other error from a spend means the outcome is UNKNOWN: the payment may be in flight or done. It is\n * recorded as such and only reconciled (asked about), never retried. When in doubt, do not throw this.\n */\nexport class NothingSpentError extends Error {\n constructor(message: string) { super(message); this.name = \"NothingSpentError\"; }\n}\n\n/**\n * The source could not be reached: no answer, a time-out, a refused connection, a server error. The\n * engine keeps trying by itself (with backoff) and shows the source as connecting meanwhile.\n */\nexport class SourceUnreachableError extends Error {\n constructor(message: string, cause?: unknown) { super(message); this.name = \"SourceUnreachableError\"; if (cause !== undefined) Object.assign(this, { cause }); }\n}\n\n/**\n * A setting of the source is wrong (a server on another network, a phrase that makes no wallet): trying\n * again changes nothing until the setting does. The engine shows it as unavailable at once.\n */\nexport class SourceConfigError extends Error {\n constructor(message: string, cause?: unknown) { super(message); this.name = \"SourceConfigError\"; if (cause !== undefined) Object.assign(this, { cause }); }\n}\n\n/** What went wrong connecting a source, by name (a plugin bundles its own copies of these classes). */\nexport type SourceProblem = \"unreachable\" | \"config\" | \"other\";\nexport const sourceProblem = (error: unknown): SourceProblem =>\n error instanceof Error && error.name === \"SourceUnreachableError\" ? \"unreachable\" : error instanceof Error && error.name === \"SourceConfigError\" ? \"config\" : \"other\";\n\n/**\n * Whether an error says nothing was spent. By name, not by class: a provider built outside the app (an\n * SDK plugin bundled with its own copy of `NothingSpentError`) must be understood the same way.\n */\nexport const isNothingSpentError = (error: unknown): error is NothingSpentError =>\n error instanceof NothingSpentError || (error instanceof Error && error.name === \"NothingSpentError\");\n\n/**\n * An error message fit to show and store: every secret the source was given is blanked out, in case a\n * library echoed a URI or a key back.\n */\nexport function redact(error: unknown, secrets: Record<string, string> = {}): string {\n let message = error instanceof Error ? error.message : String(error);\n for (const value of Object.values(secrets)) if (value && value.length >= 4) message = message.split(value).join(\"•••\");\n return message.slice(0, 300);\n}\n"],"mappings":";AAUA,IAAa,qBAAkD;CAAC;CAAO;CAAa;AAAS;AAI7F,IAAa,oBAAgD;CAAC;CAAW;CAAU;CAAW;CAAW;AAAW;AACpH,IAAa,eAAe,YAA0C,YAAY,YAAY,YAAY;;AA8F1G,IAAa,aAAa,YAA8F,UAA4B,SAClJ,WAAW,UAAU,SAAS,QAAQ,KAAK,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,KAAK;CACnE,KAAK,MAAM,SAAS,OAAO,OAAO,OAAO,GAAG,IAAI,SAAS,MAAM,UAAU,GAAG,UAAU,QAAQ,MAAM,KAAK,CAAC,CAAC,KAAK,KAAK;CACrH,OAAO,QAAQ,MAAM,GAAG,GAAG;AAC7B"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { S as boundVerifiedIdentity, y as IdentityCheckUnavailable } from "./bitcoinAddress-C2MAmcDT.js";
|
|
2
|
+
// ../browser/src/proofs/verify.ts
|
|
3
3
|
var DAY = 86400;
|
|
4
4
|
/**
|
|
5
5
|
* The checks every proof goes through, whatever its provider: known provider, validity within the
|
|
@@ -101,7 +101,6 @@ function boundedIdentityFetch(options = { online: () => true }) {
|
|
|
101
101
|
};
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
|
-
//#endregion
|
|
105
104
|
export { verifyIdentity as i, boundedIdentityFetch as n, descriptorProblems as r, availableSigners as t };
|
|
106
105
|
|
|
107
|
-
//# sourceMappingURL=verify-
|
|
106
|
+
//# sourceMappingURL=verify-CSo7-43-.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify-
|
|
1
|
+
{"version":3,"file":"verify-CSo7-43-.js","names":[],"sources":["../../browser/src/proofs/verify.ts"],"sourcesContent":["import { boundVerifiedIdentity, IdentityCheckUnavailable, IDENTITY_MAX_EVIDENCE, IDENTITY_MAX_VALIDITY, type IdentityStatement, type VerifiedIdentity } from \"@ghostly/core\";\nimport type { IdentityFetch, IdentityProofProvider, IdentitySigner, VerifyContext } from \"./contract\";\n\nconst DAY = 86_400;\n\n/**\n * The checks every proof goes through, whatever its provider: known provider, validity within the\n * provider's limit, bounded evidence, strict parsing, the provider's own check, and the category rule\n * (a self-custodied proof proves exactly the subject it names; an attested one says who attests it).\n * The engine verifies a contact's proof, and the person's own proof before saving it, only through this.\n */\nexport async function verifyIdentity(providers: readonly IdentityProofProvider[], statement: IdentityStatement, evidence: unknown, ctx: VerifyContext): Promise<VerifiedIdentity> {\n const { binding } = statement;\n const provider = providers.find(p => p.id === binding.provider);\n if (!provider) throw new Error(\"This app cannot verify this kind of identity\");\n if (binding.expiresAt - binding.issuedAt > Math.min(provider.validity.maxDays * DAY, IDENTITY_MAX_VALIDITY)) throw new Error(\"The proof lasts longer than this kind of identity allows\");\n if (JSON.stringify(evidence ?? null).length > IDENTITY_MAX_EVIDENCE) throw new Error(\"Evidence too large\");\n const parsed = provider.parseEvidence(evidence);\n const verified = boundVerifiedIdentity(await provider.verify(statement, parsed, ctx));\n if (provider.category === \"self-custodied\" && verified.subject !== binding.subject) throw new Error(\"The evidence is for another identity\");\n if (provider.category === \"provider-attested\" && !verified.attester) throw new Error(\"The evidence does not say who attests it\");\n return verified;\n}\n\n/** Problems with a provider's descriptor, empty when it is well-formed. The registry and the contract suite use it. */\nexport function descriptorProblems(p: IdentityProofProvider): string[] {\n const problems: string[] = [];\n if (!/^[a-z][a-z0-9-]{0,31}$/.test(p.id)) problems.push(\"id must match ^[a-z][a-z0-9-]{0,31}$\");\n if (!p.label?.trim()) problems.push(\"label is empty\");\n if (!p.description?.trim()) problems.push(\"description is empty\");\n if (!p.privacy?.trim()) problems.push(\"privacy is empty: say what verify contacts\");\n if (p.category !== \"self-custodied\" && p.category !== \"provider-attested\") problems.push(\"category is unknown\");\n if (!p.platforms.length) problems.push(\"no platforms\");\n const { defaultDays, maxDays } = p.validity;\n if (!(Number.isInteger(defaultDays) && Number.isInteger(maxDays) && defaultDays >= 1 && defaultDays <= maxDays && maxDays * DAY <= IDENTITY_MAX_VALIDITY)) problems.push(\"validity must be whole days, 1 ≤ default ≤ max ≤ 400\");\n if (p.recheck && !(Number.isInteger(p.recheck.afterSeconds) && p.recheck.afterSeconds >= 60)) problems.push(\"recheck.afterSeconds must be at least 60\");\n if (p.recheck?.perHour !== undefined && !(Number.isInteger(p.recheck.perHour) && p.recheck.perHour >= 1)) problems.push(\"recheck.perHour must be a whole number, at least 1\");\n if (!p.signers.length) problems.push(\"no signers\");\n const ids = p.signers.map(s => s.id);\n if (new Set(ids).size !== ids.length) problems.push(\"signer ids are not unique\");\n for (const s of p.signers as readonly IdentitySigner<unknown>[]) {\n if (![\"in-app\", \"external-tool\", \"redirect\", \"publish\"].includes(s.kind)) problems.push(`signer ${s.id} has an unknown kind`);\n if (s.kind === \"in-app\" && typeof s.run !== \"function\") problems.push(`signer ${s.id} has no run()`);\n if (s.kind === \"external-tool\" && (typeof s.instructions !== \"function\" || typeof s.parse !== \"function\")) problems.push(`signer ${s.id} needs instructions() and parse()`);\n if (s.kind === \"redirect\" && typeof s.start !== \"function\") problems.push(`signer ${s.id} has no start()`);\n if (s.kind === \"publish\" && (typeof s.instructions !== \"function\" || typeof s.evidence !== \"function\")) problems.push(`signer ${s.id} needs instructions() and evidence()`);\n }\n return problems;\n}\n\n/** Signers of a provider that run on this platform and are available in this window. */\nexport function availableSigners<E>(p: IdentityProofProvider<E>, platform: IdentityProofProvider[\"platforms\"][number]): IdentitySigner<E>[] {\n return p.signers.filter(s => (s.platforms ?? p.platforms).includes(platform) && (s.available?.() ?? true));\n}\n\n/**\n * The engine's `ctx.fetch`: HTTPS GET only, no credentials or referrer, a time-out, a size cap,\n * redirects refused unless asked for.\n * `online` false refuses everything (the person turned the network off).\n */\nexport function boundedIdentityFetch(options: { online: () => boolean; timeoutMs?: number; fetcher?: typeof fetch } = { online: () => true }): IdentityFetch {\n return async (url, { headers, maxBytes = 64 * 1024, signal, redirect = \"error\" } = {}) => {\n if (!options.online()) throw new IdentityCheckUnavailable(\"Offline: this identity cannot be checked now\");\n const target = new URL(url);\n if (target.protocol !== \"https:\" || target.username || target.password) throw new Error(\"Identity checks use HTTPS only\");\n const timeout = AbortSignal.timeout(options.timeoutMs ?? 10_000);\n const response = await (options.fetcher ?? fetch)(target.href, {\n headers, signal: signal ? AbortSignal.any([signal, timeout]) : timeout,\n credentials: \"omit\", referrerPolicy: \"no-referrer\", cache: \"no-store\", redirect,\n });\n if (Number(response.headers.get(\"content-length\")) > maxBytes) throw new Error(\"Identity check response too large\");\n const reader = response.body?.getReader();\n const parts: Uint8Array[] = [];\n let length = 0;\n if (reader) {\n try {\n for (;;) {\n const { done, value } = await reader.read();\n if (done) break;\n length += value.length;\n if (length > maxBytes) throw new Error(\"Identity check response too large\");\n parts.push(value);\n }\n } finally { await reader.cancel().catch(() => {}); }\n }\n const bytes = new Uint8Array(length);\n let offset = 0;\n for (const part of parts) { bytes.set(part, offset); offset += part.length; }\n return { status: response.status, contentType: response.headers.get(\"content-type\") ?? \"\", text: new TextDecoder().decode(bytes), bytes };\n };\n}\n"],"mappings":";;AAGA,IAAM,MAAM;;;;;;;AAQZ,eAAsB,eAAe,WAA6C,WAA8B,UAAmB,KAA+C;CAChL,MAAM,EAAE,YAAY;CACpB,MAAM,WAAW,UAAU,MAAK,MAAK,EAAE,OAAO,QAAQ,QAAQ;CAC9D,IAAI,CAAC,UAAU,MAAM,IAAI,MAAM,8CAA8C;CAC7E,IAAI,QAAQ,YAAY,QAAQ,WAAW,KAAK,IAAI,SAAS,SAAS,UAAU,KAAA,MAA0B,GAAG,MAAM,IAAI,MAAM,0DAA0D;CACvL,IAAI,KAAK,UAAU,YAAY,IAAI,CAAC,CAAC,SAAA,OAAgC,MAAM,IAAI,MAAM,oBAAoB;CACzG,MAAM,SAAS,SAAS,cAAc,QAAQ;CAC9C,MAAM,WAAW,sBAAsB,MAAM,SAAS,OAAO,WAAW,QAAQ,GAAG,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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F,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.12.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",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"@ghostly/browser": "*",
|
|
67
67
|
"@ghostly/core": "*",
|
|
68
68
|
"typescript": "^5.9.3",
|
|
69
|
-
"vite": "^8.3.
|
|
70
|
-
"vitest": "^5.0
|
|
69
|
+
"vite": "^8.3.6",
|
|
70
|
+
"vitest": "^5.1.0"
|
|
71
71
|
}
|
|
72
72
|
}
|