@ghostlytools/sdk 0.0.0-stage → 1.2.3

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.
Files changed (145) hide show
  1. package/README.md +13 -2
  2. package/dist/app.js +67 -0
  3. package/dist/app.js.map +1 -0
  4. package/dist/core.js +207 -0
  5. package/dist/core.js.map +1 -0
  6. package/dist/fakes-CBIuqo5e.js +536 -0
  7. package/dist/fakes-CBIuqo5e.js.map +1 -0
  8. package/dist/fakes.js +2 -0
  9. package/dist/index.js +179 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/keet-identity-key-BylxCPl4.js +76483 -0
  12. package/dist/keet-identity-key-BylxCPl4.js.map +1 -0
  13. package/dist/src-DCeLPsi-.js +31056 -0
  14. package/dist/src-DCeLPsi-.js.map +1 -0
  15. package/dist/testing.js +330 -0
  16. package/dist/testing.js.map +1 -0
  17. package/dist/types/browser/src/engine/paymentAdapters/providers/contractSuite.d.ts +41 -0
  18. package/dist/types/browser/src/engine/paymentAdapters/providers/lightning.d.ts +103 -0
  19. package/dist/types/browser/src/engine/paymentAdapters/providers/onchain.d.ts +88 -0
  20. package/dist/types/browser/src/engine/paymentAdapters/providers/testing.d.ts +89 -0
  21. package/dist/types/browser/src/engine/paymentAdapters/providers/types.d.ts +151 -0
  22. package/dist/types/browser/src/plugins/bundled.d.ts +8 -0
  23. package/dist/types/browser/src/plugins/registry.d.ts +57 -0
  24. package/dist/types/browser/src/proofs/contract.d.ts +262 -0
  25. package/dist/types/browser/src/proofs/contractSuite.d.ts +27 -0
  26. package/dist/types/browser/src/proofs/testing.d.ts +36 -0
  27. package/dist/types/browser/src/proofs/verify.d.ts +23 -0
  28. package/dist/types/browser/src/shared/mints.d.ts +50 -0
  29. package/dist/types/core/src/appBundle.d.ts +173 -0
  30. package/dist/types/core/src/appStatements.d.ts +142 -0
  31. package/dist/types/core/src/appStore.d.ts +133 -0
  32. package/dist/types/core/src/appUpdates.d.ts +88 -0
  33. package/dist/types/core/src/atprotoIdentity.d.ts +49 -0
  34. package/dist/types/core/src/atprotoRepo.d.ts +101 -0
  35. package/dist/types/core/src/avatar.d.ts +19 -0
  36. package/dist/types/core/src/bip322.d.ts +57 -0
  37. package/dist/types/core/src/bitcoinAddress.d.ts +5 -0
  38. package/dist/types/core/src/bitcoinMessage.d.ts +15 -0
  39. package/dist/types/core/src/bitcoinScript.d.ts +69 -0
  40. package/dist/types/core/src/bolt11.d.ts +30 -0
  41. package/dist/types/core/src/bytes.d.ts +11 -0
  42. package/dist/types/core/src/callSignal.d.ts +232 -0
  43. package/dist/types/core/src/canonicalJson.d.ts +22 -0
  44. package/dist/types/core/src/capsRecord.d.ts +234 -0
  45. package/dist/types/core/src/catchUp.d.ts +45 -0
  46. package/dist/types/core/src/chatFiles.d.ts +271 -0
  47. package/dist/types/core/src/clockWatch.d.ts +72 -0
  48. package/dist/types/core/src/communityRendezvous.d.ts +113 -0
  49. package/dist/types/core/src/crypto.d.ts +10 -0
  50. package/dist/types/core/src/datalink.d.ts +187 -0
  51. package/dist/types/core/src/deviceInvite.d.ts +51 -0
  52. package/dist/types/core/src/deviceLink.d.ts +70 -0
  53. package/dist/types/core/src/dhtDelivery.d.ts +403 -0
  54. package/dist/types/core/src/dhtFiles.d.ts +46 -0
  55. package/dist/types/core/src/did.d.ts +134 -0
  56. package/dist/types/core/src/didDht.d.ts +155 -0
  57. package/dist/types/core/src/directPath.d.ts +63 -0
  58. package/dist/types/core/src/dns.d.ts +41 -0
  59. package/dist/types/core/src/domainProofs.d.ts +88 -0
  60. package/dist/types/core/src/engineErrors.d.ts +90 -0
  61. package/dist/types/core/src/enroll.d.ts +98 -0
  62. package/dist/types/core/src/files.d.ts +73 -0
  63. package/dist/types/core/src/forwards.d.ts +12 -0
  64. package/dist/types/core/src/frames.d.ts +211 -0
  65. package/dist/types/core/src/ghostlink.d.ts +1510 -0
  66. package/dist/types/core/src/groupCommits.d.ts +103 -0
  67. package/dist/types/core/src/groupCommunity.d.ts +714 -0
  68. package/dist/types/core/src/groupCrypto.d.ts +60 -0
  69. package/dist/types/core/src/groupEdits.d.ts +67 -0
  70. package/dist/types/core/src/groupEntry.d.ts +61 -0
  71. package/dist/types/core/src/groupFiles.d.ts +106 -0
  72. package/dist/types/core/src/groupHubs.d.ts +61 -0
  73. package/dist/types/core/src/groupMentions.d.ts +27 -0
  74. package/dist/types/core/src/groupMeta.d.ts +162 -0
  75. package/dist/types/core/src/groupSession.d.ts +710 -0
  76. package/dist/types/core/src/groupSignals.d.ts +167 -0
  77. package/dist/types/core/src/groupTyping.d.ts +56 -0
  78. package/dist/types/core/src/groupWake.d.ts +68 -0
  79. package/dist/types/core/src/handoff.d.ts +255 -0
  80. package/dist/types/core/src/http.d.ts +125 -0
  81. package/dist/types/core/src/identity.d.ts +17 -0
  82. package/dist/types/core/src/identityProofs.d.ts +243 -0
  83. package/dist/types/core/src/identityTimeline.d.ts +72 -0
  84. package/dist/types/core/src/image.d.ts +33 -0
  85. package/dist/types/core/src/index.d.ts +100 -0
  86. package/dist/types/core/src/invite.d.ts +128 -0
  87. package/dist/types/core/src/link.d.ts +353 -0
  88. package/dist/types/core/src/linkPreview.d.ts +60 -0
  89. package/dist/types/core/src/linkTrace.d.ts +12 -0
  90. package/dist/types/core/src/lnurl.d.ts +99 -0
  91. package/dist/types/core/src/messageTime.d.ts +28 -0
  92. package/dist/types/core/src/miniApp.d.ts +141 -0
  93. package/dist/types/core/src/pairedApps.d.ts +151 -0
  94. package/dist/types/core/src/pairedCalls.d.ts +59 -0
  95. package/dist/types/core/src/pairedCapabilities.d.ts +101 -0
  96. package/dist/types/core/src/pairedEdits.d.ts +83 -0
  97. package/dist/types/core/src/pairedFiles.d.ts +30 -0
  98. package/dist/types/core/src/pairedHttp.d.ts +15 -0
  99. package/dist/types/core/src/pairedSession.d.ts +163 -0
  100. package/dist/types/core/src/pairedSignal.d.ts +17 -0
  101. package/dist/types/core/src/pairedTransports.d.ts +76 -0
  102. package/dist/types/core/src/pairedTyping.d.ts +130 -0
  103. package/dist/types/core/src/pairedWake.d.ts +109 -0
  104. package/dist/types/core/src/pairingProgress.d.ts +107 -0
  105. package/dist/types/core/src/paymentIntent.d.ts +111 -0
  106. package/dist/types/core/src/paymentUri.d.ts +34 -0
  107. package/dist/types/core/src/payments.d.ts +97 -0
  108. package/dist/types/core/src/peerProofs.d.ts +98 -0
  109. package/dist/types/core/src/pins.d.ts +73 -0
  110. package/dist/types/core/src/pkarr.d.ts +48 -0
  111. package/dist/types/core/src/pkdns.d.ts +35 -0
  112. package/dist/types/core/src/pubkyProofs.d.ts +25 -0
  113. package/dist/types/core/src/pubkyRing.d.ts +21 -0
  114. package/dist/types/core/src/reactions.d.ts +108 -0
  115. package/dist/types/core/src/records.d.ts +89 -0
  116. package/dist/types/core/src/relay.d.ts +437 -0
  117. package/dist/types/core/src/relayBreaker.d.ts +99 -0
  118. package/dist/types/core/src/replies.d.ts +41 -0
  119. package/dist/types/core/src/services.d.ts +35 -0
  120. package/dist/types/core/src/setUpdate.d.ts +53 -0
  121. package/dist/types/core/src/signal.d.ts +53 -0
  122. package/dist/types/core/src/signer.d.ts +13 -0
  123. package/dist/types/core/src/sparkAddress.d.ts +37 -0
  124. package/dist/types/core/src/sshsig.d.ts +74 -0
  125. package/dist/types/core/src/statusCards.d.ts +253 -0
  126. package/dist/types/core/src/storeForward.d.ts +144 -0
  127. package/dist/types/core/src/text.d.ts +20 -0
  128. package/dist/types/core/src/transport.d.ts +151 -0
  129. package/dist/types/core/src/transportSwitch.d.ts +160 -0
  130. package/dist/types/core/src/turnRead.d.ts +145 -0
  131. package/dist/types/core/src/turnRecord.d.ts +165 -0
  132. package/dist/types/core/src/version.d.ts +9 -0
  133. package/dist/types/core/src/video.d.ts +44 -0
  134. package/dist/types/core/src/voice.d.ts +88 -0
  135. package/dist/types/core/src/webPush.d.ts +58 -0
  136. package/dist/types/sdk/src/app.d.ts +23 -0
  137. package/dist/types/sdk/src/core.d.ts +7 -0
  138. package/dist/types/sdk/src/fakes.d.ts +6 -0
  139. package/dist/types/sdk/src/index.d.ts +26 -0
  140. package/dist/types/sdk/src/testing.d.ts +7 -0
  141. package/dist/types-DvtCy3WB.js +99 -0
  142. package/dist/types-DvtCy3WB.js.map +1 -0
  143. package/dist/verify-DBGw6wYt.js +106 -0
  144. package/dist/verify-DBGw6wYt.js.map +1 -0
  145. package/package.json +70 -4
@@ -0,0 +1,165 @@
1
+ import { type Identity } from "./identity.js";
2
+ /** The record's format, byte 0 of the body. */
3
+ export declare const TURN_VERSION = 1;
4
+ /** The device set holds four devices at most; each has a slot of the record. */
5
+ export declare const TURN_SLOTS = 4;
6
+ export declare const TURN_NAME_BYTES = 16;
7
+ /** The body's length, and how much of it the author signs (everything before its signature). */
8
+ export declare const TURN_BODY_BYTES = 374;
9
+ export declare const TURN_SIGNED_BYTES = 310;
10
+ /** `nonce(24) || box`, the box 16 bytes longer than the body. */
11
+ export declare const TURN_SEALED_BYTES: number;
12
+ /** The highest turn of an ordinary record. One above it is the tombstone's. */
13
+ export declare const TURN_MAX: number;
14
+ export declare const TOMBSTONE_TURN: number;
15
+ /** `rev` stays under this; when it would reach it the active device writes the next turn, released to itself. */
16
+ export declare const TURN_REV_LIMIT: number;
17
+ /** Every tombstone has this one sequence number, the highest there is: no ordinary record outranks it. */
18
+ export declare const TOMBSTONE_SEQUENCE: number;
19
+ /** The highest sequence an ordinary record can have: the last turn, the last `rev`, the last slot. Anything above it that is no valid tombstone closes the address. */
20
+ export declare const TURN_LAST_SEQUENCE: number;
21
+ /** `active` in a tombstone, and nowhere else. */
22
+ export declare const TURN_NO_ACTIVE = 255;
23
+ /** The record's one TXT label: a label that says nothing. */
24
+ export declare const TURN_LABEL = "_s";
25
+ /** The TTL of the TXT record. Part of the signed bytes, so fixed. */
26
+ export declare const TURN_TTL = 300;
27
+ /** What a holder of `D` derives for the turn: the identity the packet is published under, and the key that seals it. */
28
+ export interface TurnKeys {
29
+ identity: Identity;
30
+ /** The turn address: the identity's public key, 32 bytes. It is what both signatures in the body name. */
31
+ address: Uint8Array;
32
+ sealKey: Uint8Array;
33
+ }
34
+ /** The first device-set secret of a profile, from its DID key's seed (WISP 06 § Terms): every backup already carries that. */
35
+ export declare function firstDeviceSetSecret(didSeed: Uint8Array): Uint8Array;
36
+ /** The turn's keys under the device-set secret `D` (32 bytes). */
37
+ export declare function turnKeys(d: Uint8Array): TurnKeys;
38
+ /** The BEP44 sequence number of an ordinary record: not the clock. Two devices never sign an equal one, each has its slot in the low bits. */
39
+ export declare function turnSequence(turn: number, rev: number, author: number): number;
40
+ export interface TurnSlot {
41
+ /** The device signing key (Ed25519 public key, 32 bytes). */
42
+ key: Uint8Array;
43
+ /** At most 16 bytes of UTF-8. */
44
+ name: string;
45
+ }
46
+ export interface TurnRelease {
47
+ /** The slot of the device that gave the turn up. */
48
+ from: number;
49
+ /** The slot of the device it was given to. */
50
+ to: number;
51
+ /** `H`, the digest of the state handed over (32 bytes). */
52
+ h: Uint8Array;
53
+ /** `from`'s signature (`turnReleaseMessage`). */
54
+ signature: Uint8Array;
55
+ }
56
+ /** What a record says, before its author signs it. */
57
+ export interface TurnFields {
58
+ turn: number;
59
+ rev: number;
60
+ /** The slot of the device that signs this record. */
61
+ author: number;
62
+ /** The slot of the active device; `TURN_NO_ACTIVE` in a tombstone. */
63
+ active: number;
64
+ /** By slot, four entries; null for a slot nobody holds. */
65
+ slots: (TurnSlot | null)[];
66
+ /** 8 bytes, made anew for every record: random, and in an ordinary record the verifier mark (`turnInstance`). */
67
+ instance: Uint8Array;
68
+ release?: TurnRelease;
69
+ }
70
+ /** The mark of a verifier (its `setup` and `record` as stored), or of a profile that has none (null). 3 bytes. */
71
+ export declare function turnVerifierMark(verifier: {
72
+ setup: string;
73
+ record: string;
74
+ } | null | undefined): Uint8Array;
75
+ /**
76
+ * A record's `instance` that states `mark` (`turnVerifierMark`), or, with no mark, one that states nothing: 8 random
77
+ * bytes that never carry the marker (a tombstone, a record written where the profile's verifier is not at hand).
78
+ */
79
+ export declare function turnInstance(mark?: Uint8Array | null, random?: (length: number) => Uint8Array): Uint8Array;
80
+ /** The verifier mark an `instance` states, or null when it states none (a record written by an app from before). */
81
+ export declare function turnStatedVerifier(instance: Uint8Array): Uint8Array | null;
82
+ /** A record as read: its fields, its sequence number, and the body's bytes. */
83
+ export interface TurnRecord extends TurnFields {
84
+ tombstone: boolean;
85
+ sequence: number;
86
+ signature: Uint8Array;
87
+ body: Uint8Array;
88
+ }
89
+ /** Signs with a device signing key. Asynchronous: where WebCrypto holds the key, the app has no seed to sign with. */
90
+ export type TurnSigner = (bytes: Uint8Array) => Uint8Array | Promise<Uint8Array>;
91
+ /** Why the reader refuses a record. Each one is a rule of WISP 06 § Record. */
92
+ export type TurnRefusal = "packet" | "label" | "seal" | "length" | "version" | "turn" | "rev" | "author" | "active" | "count" | "slots" | "name" | "release-layout" | "tombstone" | "author-not-active" | "signature" | "release" | "sequence";
93
+ export declare class TurnRecordError extends Error {
94
+ readonly refusal: TurnRefusal;
95
+ constructor(refusal: TurnRefusal, detail?: string);
96
+ }
97
+ /**
98
+ * A device's name as its slot holds it: UTF-8, cut at a character boundary to 16 bytes, and with no NUL (the padding).
99
+ * A character is what a person sees as one (a grapheme), so a cut never leaves half an emoji or a lone joiner.
100
+ * A name is display text a device chooses for itself and every device of the set shows: it is cleaned as a nickname is
101
+ * (`sanitizeDisplayText`: no control, invisible or direction-changing character, and empty when nothing of it shows)
102
+ * and trimmed, made and read alike.
103
+ */
104
+ export declare function turnName(name: string): string;
105
+ /** What a release signs: `"ghostly-turn-release" || turnAddress(32) || turn(4) || toKey(32) || H(32)`. */
106
+ export declare function turnReleaseMessage(address: Uint8Array, turn: number, toKey: Uint8Array, h: Uint8Array): Uint8Array;
107
+ /** What the author signs: `"ghostly-turn" || turnAddress(32) || body[0..310]`. */
108
+ export declare function turnSignedMessage(address: Uint8Array, unsigned: Uint8Array): Uint8Array;
109
+ /** The first 310 bytes of the body. Throws on fields that no record may hold; the reader's rules are `readTurnBody`'s. */
110
+ export declare function encodeTurnFields(fields: TurnFields): Uint8Array;
111
+ /** A release of `turn` to the device whose key is `toKey`, signed by the device that gives the turn up. */
112
+ export declare function signTurnRelease(address: Uint8Array, turn: number, from: number, to: number, toKey: Uint8Array, h: Uint8Array, signer: TurnSigner): Promise<TurnRelease>;
113
+ /** The whole body, 374 bytes: the fields and the author's signature over them. */
114
+ export declare function signTurnBody(address: Uint8Array, fields: TurnFields, signer: TurnSigner): Promise<Uint8Array>;
115
+ /**
116
+ * A body as a record, or a `TurnRecordError` naming the rule it breaks (WISP 06 § Record, "A reader accepts a record
117
+ * that..."). What depends on what the reader already holds (a sequence not lower than its own, the release's `from`
118
+ * against the device that was active before) is the caller's: `turnRead.ts`.
119
+ */
120
+ export declare function readTurnBody(body: Uint8Array, address: Uint8Array): TurnRecord;
121
+ /** The TXT value: base64url of `nonce(24) || XSalsa20-Poly1305(sealKey, nonce, body)`. */
122
+ export declare function sealTurnBody(body: Uint8Array, sealKey: Uint8Array, nonce?: Uint8Array): string;
123
+ /** The body inside a TXT value, or null when it does not open under the seal key. */
124
+ export declare function openTurnValue(value: string, sealKey: Uint8Array): Uint8Array | null;
125
+ /**
126
+ * The packet of a signed body, as a relay payload (`signature(64) || sequence(8) || DNS packet`): sealed once, signed
127
+ * under the turn key at the record's own sequence. These are the bytes a device stores and puts, unchanged, every time.
128
+ */
129
+ export declare function turnPacket(keys: TurnKeys, body: Uint8Array, nonce?: Uint8Array): Uint8Array;
130
+ /** Signs and seals a record: its packet, to be stored before it is put. */
131
+ export declare function signTurnPacket(keys: TurnKeys, fields: TurnFields, signer: TurnSigner, nonce?: Uint8Array): Promise<Uint8Array>;
132
+ /**
133
+ * A packet read at the turn address.
134
+ * - `valid`: a record every rule accepts.
135
+ * - `invalid`: a BEP44 packet under the turn key (a node stores it, so its sequence counts as seen) that is no valid record.
136
+ * - `foreign`: not a packet under the turn key at all. No honest source holds it, and nothing of it counts.
137
+ */
138
+ export type TurnPacketRead = {
139
+ kind: "valid";
140
+ sequence: bigint;
141
+ record: TurnRecord;
142
+ } | {
143
+ kind: "invalid";
144
+ sequence: bigint;
145
+ refusal: TurnRefusal;
146
+ } | {
147
+ kind: "foreign";
148
+ };
149
+ /** Verifies and opens one packet. Never throws. */
150
+ export declare function readTurnPacket(keys: TurnKeys, payload: Uint8Array): TurnPacketRead;
151
+ /** The sequence number of a relay payload, read without verifying it: bytes 64 to 72. Null when it is too short. */
152
+ export declare function turnPayloadSequence(payload: Uint8Array): bigint | null;
153
+ /**
154
+ * The `turn` and `rev` of the next record a device writes in its slot `author` at `turn`, above everything ever seen
155
+ * at the address: above its own last record there (`lastRev` plus one; null when it wrote none in this turn), and
156
+ * above the highest raw sequence `seen`, valid or not, so an invalid record with a high `rev` never makes its put
157
+ * fail as older. `raised` says the turn itself had to rise: `rev` ran out, or something was seen above this turn. A
158
+ * device that is not taking the turn then writes it with a release from itself to itself. Null when nothing can be
159
+ * written any more (something at or above the last ordinary turn was seen).
160
+ */
161
+ export declare function nextTurnPosition(turn: number, lastRev: number | null, author: number, seen: bigint | number): {
162
+ turn: number;
163
+ rev: number;
164
+ raised: boolean;
165
+ } | null;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Which of two released versions is newer. Every client asks this of whatever
3
+ * it found published, so a malformed answer must never read as an update: the
4
+ * numbers are the only thing trusted here, and anything else sorts as older.
5
+ */
6
+ /** Negative when `a` is older, positive when it is newer, 0 when they match or either is not a version. */
7
+ export declare function compareVersions(a: string, b: string): number;
8
+ /** Whether `latest` is worth updating to from `current`. Unparseable input is never an update. */
9
+ export declare function isNewerVersion(latest: string, current: string): boolean;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Videos. A video is an ordinary file (files/2, files/3 or a held item) whose announcement may also carry a
3
+ * `video` description: how long it is, its size in pixels and a small JPEG of its first frame, so the
4
+ * receiver shows a picture and a length before a byte of it has arrived. A peer that does not know `video`
5
+ * ignores it and shows a file; a bad description only means no poster.
6
+ */
7
+ export interface VideoMeta {
8
+ /** Milliseconds. */
9
+ duration: number;
10
+ /** Pixels, as it plays (rotation applied). */
11
+ width: number;
12
+ height: number;
13
+ /** A JPEG of an early frame, base64url, at most `VIDEO_LIMITS.maxPosterBytes`. */
14
+ poster?: string;
15
+ }
16
+ export declare const VIDEO_LIMITS: {
17
+ /** The poster's bytes: with the rest of an offer, a frame stays far below the 60 KiB a session carries. */
18
+ readonly maxPosterBytes: number;
19
+ /** The poster's longest side, in pixels, as the sender draws it. */
20
+ readonly posterEdge: 320;
21
+ /** Ten hours: longer is a mistake, not a video. */
22
+ readonly maxDurationMs: number;
23
+ /** Pixels on either side (8K and a bit). */
24
+ readonly maxEdge: 16384;
25
+ };
26
+ /**
27
+ * Video a player may be handed as it is. None of these runs anything in the page's origin, so received bytes
28
+ * of these types are served with their type (see `safeBlobType`): WebKit will not play what is typed as bytes.
29
+ */
30
+ export declare const PLAYABLE_VIDEO: RegExp;
31
+ /** Whether a file is a video, by its type: shown in a video bubble whether or not it came with a description. */
32
+ export declare function isVideoMime(mime: string): boolean;
33
+ /**
34
+ * Whether a file is shown as a video (a poster, a player): a type a player may be handed. Other video types
35
+ * (Matroska, AVI) are files, saved to be played elsewhere.
36
+ */
37
+ export declare function isPlayableVideoType(mime: string): boolean;
38
+ /**
39
+ * A peer's `video` description, or undefined when it is not one. It never refuses the file. A poster that is
40
+ * too large or not a JPEG is dropped on its own; the length and size are kept.
41
+ */
42
+ export declare function parseVideoMeta(value: unknown, mime?: string): VideoMeta | undefined;
43
+ /** `0:07`, `12:45`, `1:02:03`: as a player shows a video's length. */
44
+ export declare function formatVideoDuration(ms: number): string;
@@ -0,0 +1,88 @@
1
+ import { type VideoMeta } from "./video.js";
2
+ /**
3
+ * Voice messages. A voice message is an ordinary file (files/2, or a held item) whose
4
+ * announcement also carries a `voice` description: how long it is and the shape of its
5
+ * sound. The shape is measured once, while recording, so no player ever decodes audio
6
+ * to draw it. A peer that does not know `voice` ignores it and shows an audio file.
7
+ */
8
+ export interface VoiceMeta {
9
+ /** Milliseconds. */
10
+ duration: number;
11
+ /** Loudness per bar, 0-255, in playing order. */
12
+ peaks: number[];
13
+ }
14
+ export declare const VOICE_LIMITS: {
15
+ /** Fifteen minutes: at the bitrate recorded (32 kbit/s) about 3.6 MB, well inside a held item's 8 MiB. */
16
+ readonly maxDurationMs: number;
17
+ /** Bars drawn for a recording. */
18
+ readonly bars: 64;
19
+ /** Bars accepted from a peer. */
20
+ readonly maxBars: 128;
21
+ /** Asked of the recorder; opus speech is clear well below it. */
22
+ readonly audioBitsPerSecond: 32000;
23
+ };
24
+ /**
25
+ * Audio a player may be handed as it is. None of these runs anything in the page's origin,
26
+ * so received bytes of these types are served with their type (see `safeBlobType`).
27
+ */
28
+ export declare const PLAYABLE_AUDIO: RegExp;
29
+ /**
30
+ * Whether a file sent as a file (not a voice message) is shown with a player: a type a player may be handed.
31
+ * Other audio types (MIDI, AIFF, WMA) are files, saved to be played elsewhere.
32
+ */
33
+ export declare function isPlayableAudioType(mime: string): boolean;
34
+ /** The part of a type before its parameters, in lower case: `audio/webm;codecs=opus` → `audio/webm`. */
35
+ export declare function baseMime(mime: string): string;
36
+ /**
37
+ * A peer's `voice` description, or undefined when it is not one. It never refuses the file:
38
+ * a bad description only means the file is shown as a file.
39
+ */
40
+ export declare function parseVoiceMeta(value: unknown, mime?: string): VoiceMeta | undefined;
41
+ /**
42
+ * How the level is metered while recording (apps/ui/src/lib/voiceRecorder.ts): every `intervalMs`, the RMS of the last
43
+ * `window` samples an AnalyserNode holds (at a 48 kHz context, about 21 ms of sound).
44
+ */
45
+ export declare const VOICE_METER: {
46
+ readonly intervalMs: 50;
47
+ readonly window: 1024;
48
+ readonly windowRate: 48000;
49
+ };
50
+ /** One reading of the meter, 0-1: the RMS of the samples, lifted because speech sits low on a linear scale. */
51
+ export declare function voiceLevel(samples: ArrayLike<number>): number;
52
+ /**
53
+ * The readings the recorder would have taken of this sound (mono, -1 to 1), for a recording made elsewhere: one
54
+ * every `intervalMs` of it, each over the window that ends there, as long in time as the analyser's.
55
+ */
56
+ export declare function voiceLevelsOf(mono: Float32Array, sampleRate: number): number[];
57
+ /** The waveform sent with a recording made elsewhere, drawn as the recorder draws its own. */
58
+ export declare function voicePeaksOf(mono: Float32Array, sampleRate: number, bars?: number): number[];
59
+ /**
60
+ * Bars from the loudness measured while recording (RMS, 0-1, oldest first): the loudest
61
+ * sample of each stretch, scaled so the loudest bar is full height.
62
+ */
63
+ export declare function downsamplePeaks(levels: ArrayLike<number>, bars?: number): number[];
64
+ /**
65
+ * What to record in, by preference: opus in WebM plays on Chromium, Firefox, Safari 15+ and
66
+ * WebKitGTK; older WebKit (WKWebView on macOS before Safari 18.4) records only AAC in MP4,
67
+ * which Chrome, Edge and Safari play. `recorder` is asked of MediaRecorder, `file` is sent.
68
+ */
69
+ export declare const RECORDING_TYPES: readonly ["audio/webm;codecs=opus", "audio/ogg;codecs=opus", "audio/mp4;codecs=mp4a.40.2", "audio/mp4", "audio/webm"];
70
+ export declare function recordingMime(isTypeSupported: (mime: string) => boolean): {
71
+ recorder: string;
72
+ file: string;
73
+ } | null;
74
+ /** A name for the file, for whoever saves it or runs a Ghostly that shows it as a file. */
75
+ export declare function voiceFileName(mime: string, timestamp: number): string;
76
+ /**
77
+ * The name a downloaded voice message is saved under, made here from the message's time and its
78
+ * type (the sender's own name for it is not used): "Ghostly voice 2026-09-27 14.01.30.webm".
79
+ */
80
+ export declare function voiceDownloadName(mime: string, timestamp: number): string;
81
+ /** `0:07`, `12:45`: minutes and seconds, as a player shows them. */
82
+ export declare function formatVoiceDuration(ms: number): string;
83
+ /** The line a file message shows in the chat list and in notifications. */
84
+ export declare function fileMessageText(file: {
85
+ name: string;
86
+ voice?: VoiceMeta;
87
+ video?: VideoMeta;
88
+ }): string;
@@ -0,0 +1,58 @@
1
+ /** A VAPID key pair: the public key as an uncompressed P-256 point, the private one as its 32-byte scalar. */
2
+ export interface VapidKeys {
3
+ publicKey: string;
4
+ privateKey: string;
5
+ }
6
+ /** What a browser's `PushSubscription` gives: where to post, and the keys to encrypt to. */
7
+ export interface PushTarget {
8
+ endpoint: string;
9
+ /** The subscription's P-256 public key, uncompressed, base64url (`getKey("p256dh")`). */
10
+ p256dh: string;
11
+ /** Its 16-byte auth secret, base64url (`getKey("auth")`). */
12
+ auth: string;
13
+ }
14
+ /** An HTTP request, ready for `fetch` or a relay. */
15
+ export interface PushRequest {
16
+ url: string;
17
+ headers: Record<string, string>;
18
+ body: Uint8Array;
19
+ }
20
+ export declare class WebPushError extends Error {
21
+ }
22
+ export declare function generateVapidKeys(): VapidKeys;
23
+ /** Whether a VAPID key pair is well formed and its halves belong together. */
24
+ export declare function vapidKeysMatch(keys: VapidKeys): boolean;
25
+ /**
26
+ * The push services a browser subscribes with: Google (Chrome, Edge on Android, Brave, Opera), Apple (Safari), Mozilla
27
+ * (Firefox), Microsoft (Edge on Windows). The same list as the push relay's (infra/services/push-relay/relay.mjs).
28
+ */
29
+ export declare const PUSH_SERVICE_HOSTS: readonly RegExp[];
30
+ /**
31
+ * Only https, on one of the push services' host names and their default port, without credentials. The endpoint came
32
+ * from a contact: it must not turn this app into a way to post to the contact's choice of address, local or not.
33
+ */
34
+ export declare function checkPushEndpoint(endpoint: string): URL;
35
+ /** `Authorization: vapid t=<JWT>, k=<public key>` for a request to `endpoint` (RFC 8292). */
36
+ export declare function vapidAuthorization(endpoint: string, keys: VapidKeys, subject: string, now?: number): string;
37
+ /**
38
+ * `plaintext` encrypted for a subscription (RFC 8291 with RFC 8188 `aes128gcm`, one record). `sender` fixes
39
+ * the sender's ephemeral key and salt, for the RFC's test vector only.
40
+ */
41
+ export declare function encryptPushPayload(plaintext: Uint8Array, target: Pick<PushTarget, "p256dh" | "auth">, sender?: {
42
+ secret: Uint8Array;
43
+ salt: Uint8Array;
44
+ }): Uint8Array;
45
+ /**
46
+ * The receiving side of `encryptPushPayload`, which a browser does for its service worker. Here for tests and
47
+ * for a push service stand-in; the app itself never decrypts a push.
48
+ */
49
+ export declare function decryptPushPayload(body: Uint8Array, receiverSecret: Uint8Array, authSecret: Uint8Array): Uint8Array;
50
+ /**
51
+ * 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).
53
+ */
54
+ export declare function pushRequest(target: PushTarget, keys: VapidKeys, payload: Uint8Array, options: {
55
+ subject: string;
56
+ ttlSeconds?: number;
57
+ now?: number;
58
+ }): PushRequest;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @ghostlytools/sdk/app: what a mini-app (WISP 1200, Apps) is written against. The `window.ghostly` API the runner
3
+ * gives an app, the broker's messages and refusal codes, the limits the broker enforces, and the manifest
4
+ * (`ghostly-app.json`) that `ghostly app publish` signs into a bundle. Apps run in Ghostly from release 1.2.
5
+ *
6
+ * Nothing in it imports anything at run time, so an app's single-file bundle takes only what it uses: the types, plus
7
+ * `MINI_APP_LIMITS`, `MINI_APP_ERROR_CODES` and `miniAppErrorCode`. The client reads the same module, so the two cannot
8
+ * drift.
9
+ *
10
+ * import type { MiniAppApi } from "@ghostlytools/sdk/app";
11
+ * declare global { interface Window { ghostly: MiniAppApi } }
12
+ */
13
+ import type { AppManifestDraft } from "../../core/src/appBundle.js";
14
+ export type { MiniAppJson, MiniAppContext, MiniAppPeerEvent, MiniAppApi, MiniAppRequestType, MiniAppRequest, MiniAppAnswer, MiniAppEvent, MiniAppErrorCode, } from "../../core/src/miniApp.js";
15
+ export { MINI_APP_LIMITS, MINI_APP_ERROR_CODES, miniAppErrorCode } from "../../core/src/miniApp.js";
16
+ export type { AppManifest, AppManifestDraft, AppFileEntry, AppPermission, AppViewMode, AppClient, AppBundleRefusal } from "../../core/src/appBundle.js";
17
+ /**
18
+ * `ghostly-app.json`, the manifest as a publisher writes it: everything but `publisher` and `files`, which
19
+ * `ghostly app publish` writes from the key and the folder, and `sequence`, which it raises by itself when left out.
20
+ */
21
+ export type AppManifestSource = Omit<AppManifestDraft, "sequence"> & {
22
+ sequence?: number;
23
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @ghostlytools/sdk/core: the whole protocol library (`packages/core`), for a client that implements only
3
+ * the WISP contracts it needs: identities and records, invites, Pkarr rendezvous, the data link and
4
+ * its frames, paired sessions and their capabilities, payments, identity proofs. It follows the WISP
5
+ * drafts it implements: anything here may change with them, minor by minor, until they are Final.
6
+ */
7
+ export * from "../../core/src/index.js";
@@ -0,0 +1,6 @@
1
+ /**
2
+ * @ghostlytools/sdk/fakes: the fake adapters the app itself tests with, usable at run time (no vitest):
3
+ * in-memory regtest sats and test identities that hold nothing and reach nothing.
4
+ */
5
+ export { FakeLightningProvider, FakeOnchainProvider, fakeInvoice, fakeAddress, fakeLightning, fakeOnchain, TEST_PROVIDERS_FLAG, testProvidersEnabled, type FakeBehaviour, } from "../../browser/src/engine/paymentAdapters/providers/testing.js";
6
+ export { fakeKey, fakeAccount, fakeRecord, FAKE_IDENTITY_PROVIDERS, fakeKeyring, fakeKeySubject, fakeKeySign, fakeAccountToken, fakeRecordText, FAKE_ISSUER, FAKE_RECORD_HOST, TEST_IDENTITIES_FLAG, testIdentitiesEnabled, type FakeKeyEvidence, type FakeAccountEvidence, } from "../../browser/src/proofs/testing.js";
@@ -0,0 +1,26 @@
1
+ /**
2
+ * @ghostlytools/sdk: what someone building for Ghostly needs, and nothing of the app's internals.
3
+ *
4
+ * - Wallet sources: the `LightningProvider` and `OnchainProvider` contracts, their descriptors, the
5
+ * money-safety error (`NothingSpentError`) and the descriptor checks.
6
+ * - Identity proofs: the `IdentityProofProvider` contract, its signers, and the shared verification.
7
+ * - Plugins: `registerAdapters`, the one way an adapter written outside the app gets into it.
8
+ * - Transports and records: the contracts a transport or a minimal client implements (from the core).
9
+ *
10
+ * Fakes and contract test suites: `@ghostlytools/sdk/testing`. The whole protocol library: `@ghostlytools/sdk/core`.
11
+ * Read docs/SDK.md first: the rules about money and secrets are not optional.
12
+ */
13
+ export type { ProviderPlatform, ProviderKind, ProviderNetwork, ProviderField, ProviderSettings, ProviderHost, ProviderDescriptor, ProviderDescriptorView, } from "../../browser/src/engine/paymentAdapters/providers/types.js";
14
+ export { PROVIDER_PLATFORMS, PROVIDER_NETWORKS, PROVIDER_ID, networkMode, offeredIn, describeProvider, providerDescriptorProblems, NothingSpentError, isNothingSpentError, redact, } from "../../browser/src/engine/paymentAdapters/providers/types.js";
15
+ export type { WalletMode } from "../../browser/src/shared/mints.js";
16
+ export type { LightningInfo, LightningInvoice, InvoiceStatus, LightningPaymentRef, LightningPayResult, LightningPaymentStatus, LightningCapabilities, LightningProvider, LightningProviderDescriptor, } from "../../browser/src/engine/paymentAdapters/providers/lightning.js";
17
+ export type { OnchainInfo, OnchainBalance, OnchainSendRequest, OnchainPrepared, OnchainTxStatus, OnchainTx, OnchainProvider, OnchainProviderDescriptor, } from "../../browser/src/engine/paymentAdapters/providers/onchain.js";
18
+ export type { IdentityCategory, IdentityPlatform, IdentityFetchOptions, IdentityFetchResponse, IdentityFetch, VerifyContext, SubjectSpec, SignerField, SignerContext, SignerSession, InstructionStep, SignerInstructions, InAppSigner, ExternalToolSigner, RedirectSigner, PublishSigner, IdentitySigner, IdentityProofProvider, } from "../../browser/src/proofs/contract.js";
19
+ export { IDENTITY_PLATFORMS } from "../../browser/src/proofs/contract.js";
20
+ export { verifyIdentity, descriptorProblems as identityDescriptorProblems, availableSigners, boundedIdentityFetch } from "../../browser/src/proofs/verify.js";
21
+ export type { IdentityStatement, IdentityBinding, VerifiedIdentity, IdentityDisplay, LocalIdentityProof, } from "../../core/src/index.js";
22
+ export { identityStatement, newIdentityBinding, IDENTITY_MAX_EVIDENCE, IDENTITY_MAX_VALIDITY } from "../../core/src/index.js";
23
+ export type { GhostlyAdapterPlugin, AdapterKind } from "../../browser/src/plugins/registry.js";
24
+ export { SDK_API, PLUGIN_ID, registerAdapters, pluginProblems, onAdaptersChanged, registeredPlugins, registeredLightningProviders, registeredOnchainProviders, registeredIdentityProviders, resetAdapterRegistry, } from "../../browser/src/plugins/registry.js";
25
+ export type { BitcoinNetwork, PkarrTransport, GhostRecord, SignedPacket, Identity, NativeEndpoint, NativeTransport, NativeBinding, BoundChannel, TransportDescriptors, PairedTransport, FrameChannel, } from "../../core/src/index.js";
26
+ export { TRANSPORTS, decodeBolt11, isBitcoinAddress } from "../../core/src/index.js";
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @ghostlytools/sdk/testing: the contract suites every adapter runs against itself, plus the fakes of
3
+ * `@ghostlytools/sdk/fakes`. Needs vitest (a peer dependency): import it from test files only.
4
+ */
5
+ export * from "./fakes.js";
6
+ export { describeLightningProvider, describeOnchainProvider, type ContractOptions, type LightningHarness, type OnchainHarness } from "../../browser/src/engine/paymentAdapters/providers/contractSuite.js";
7
+ export { describeIdentityProof, type IdentityProofHarness } from "../../browser/src/proofs/contractSuite.js";
@@ -0,0 +1,99 @@
1
+ //#region ../browser/src/engine/paymentAdapters/providers/types.ts
2
+ var PROVIDER_PLATFORMS = [
3
+ "web",
4
+ "extension",
5
+ "desktop"
6
+ ];
7
+ var PROVIDER_NETWORKS = [
8
+ "bitcoin",
9
+ "signet",
10
+ "testnet",
11
+ "regtest",
12
+ "mutinynet"
13
+ ];
14
+ var networkMode = (network) => network === "bitcoin" ? "mainnet" : "testnet";
15
+ /** A provider can be offered here: it runs on this platform and on a network of this mode. */
16
+ var offeredIn = (descriptor, platform, mode) => descriptor.platforms.includes(platform) && descriptor.networks.some((network) => networkMode(network) === mode);
17
+ var FIELD_KINDS = [
18
+ "text",
19
+ "url",
20
+ "secret",
21
+ "select",
22
+ "textarea"
23
+ ];
24
+ /** What is stored with the profile and sent on the wire in journals: stable, short, lowercase. */
25
+ var PROVIDER_ID = /^[a-z][a-z0-9-]{0,31}$/;
26
+ /**
27
+ * Problems with a provider descriptor, empty when it is well-formed. The registry refuses a descriptor
28
+ * with any; the contract suite checks the same list, so an author sees them before the app does.
29
+ */
30
+ function providerDescriptorProblems(d) {
31
+ const problems = [];
32
+ if (!PROVIDER_ID.test(d.id ?? "")) problems.push("id must match ^[a-z][a-z0-9-]{0,31}$");
33
+ if (!d.label?.trim()) problems.push("label is empty");
34
+ if (d.kind !== "lightning" && d.kind !== "onchain") problems.push("kind must be lightning or onchain");
35
+ if (!d.description?.trim()) problems.push("description is empty: say what it is and who holds the money");
36
+ if (!Array.isArray(d.networks) || !d.networks.length) problems.push("no networks");
37
+ else for (const n of d.networks) if (!PROVIDER_NETWORKS.includes(n)) problems.push(`unknown network ${String(n)}`);
38
+ if (!Array.isArray(d.platforms) || !d.platforms.length) problems.push("no platforms");
39
+ else for (const p of d.platforms) if (!PROVIDER_PLATFORMS.includes(p)) problems.push(`unknown platform ${String(p)}`);
40
+ if (!Array.isArray(d.fields)) problems.push("fields must be a list (empty when there is nothing to configure)");
41
+ else {
42
+ const names = d.fields.map((f) => f.name);
43
+ if (new Set(names).size !== names.length) problems.push("field names are not unique");
44
+ for (const f of d.fields) {
45
+ if (!/^[a-zA-Z][a-zA-Z0-9_-]{0,63}$/.test(f.name ?? "")) problems.push(`field ${String(f.name)} has an invalid name`);
46
+ if (!f.label?.trim()) problems.push(`field ${f.name} has no label`);
47
+ if (!FIELD_KINDS.includes(f.kind)) problems.push(`field ${f.name} has an unknown kind`);
48
+ if (f.kind === "select" && !f.options?.length) problems.push(`field ${f.name} is a select without options`);
49
+ if (f.suggestions !== void 0 && (!Array.isArray(f.suggestions) || f.suggestions.some((o) => typeof o?.value !== "string" || typeof o?.label !== "string"))) problems.push(`field ${f.name} has malformed suggestions`);
50
+ if (f.changeable && (f.kind === "secret" || f.kind === "select")) problems.push(`field ${f.name} cannot be changeable: only a server address can`);
51
+ }
52
+ }
53
+ if (typeof d.create !== "function") problems.push("create is not a function");
54
+ if (d.validate !== void 0 && typeof d.validate !== "function") problems.push("validate is not a function");
55
+ return problems;
56
+ }
57
+ /** Only these fields reach the UI, whatever else a provider module keeps on its descriptor. */
58
+ var describeProvider = ({ id, label, kind, description, networks, platforms, fields, custodial, experimental }) => ({
59
+ id,
60
+ label,
61
+ kind,
62
+ description,
63
+ networks,
64
+ platforms,
65
+ fields,
66
+ custodial,
67
+ experimental
68
+ });
69
+ /**
70
+ * The provider proved that nothing left the wallet (refused before sending, no route found before any
71
+ * HTLC, a transaction that was never broadcast). Safe to try again, with this or another source.
72
+ *
73
+ * Any other error from a spend means the outcome is UNKNOWN: the payment may be in flight or done. It is
74
+ * recorded as such and only reconciled (asked about), never retried. When in doubt, do not throw this.
75
+ */
76
+ var NothingSpentError = class extends Error {
77
+ constructor(message) {
78
+ super(message);
79
+ this.name = "NothingSpentError";
80
+ }
81
+ };
82
+ /**
83
+ * Whether an error says nothing was spent. By name, not by class: a provider built outside the app (an
84
+ * SDK plugin bundled with its own copy of `NothingSpentError`) must be understood the same way.
85
+ */
86
+ var isNothingSpentError = (error) => error instanceof NothingSpentError || error instanceof Error && error.name === "NothingSpentError";
87
+ /**
88
+ * An error message fit to show and store: every secret the source was given is blanked out, in case a
89
+ * library echoed a URI or a key back.
90
+ */
91
+ function redact(error, secrets = {}) {
92
+ let message = error instanceof Error ? error.message : String(error);
93
+ for (const value of Object.values(secrets)) if (value && value.length >= 4) message = message.split(value).join("•••");
94
+ return message.slice(0, 300);
95
+ }
96
+ //#endregion
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 };
98
+
99
+ //# sourceMappingURL=types-DvtCy3WB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-DvtCy3WB.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 /** 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 /** 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 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\">;\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":"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"}