applesauce-common 6.2.0 → 7.1.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.
Files changed (251) hide show
  1. package/README.md +1 -0
  2. package/dist/casts/_circular-import.d.ts +3 -0
  3. package/dist/casts/_circular-import.js +3 -0
  4. package/dist/casts/app-handler.d.ts +56 -0
  5. package/dist/casts/app-handler.js +105 -0
  6. package/dist/casts/app-recommendation.d.ts +26 -0
  7. package/dist/casts/app-recommendation.js +41 -0
  8. package/dist/casts/external-identities.d.ts +9 -0
  9. package/dist/casts/external-identities.js +14 -0
  10. package/dist/casts/forum-thread.d.ts +17 -0
  11. package/dist/casts/forum-thread.js +31 -0
  12. package/dist/casts/git-issue.d.ts +18 -0
  13. package/dist/casts/git-issue.js +26 -0
  14. package/dist/casts/git-patch.d.ts +49 -0
  15. package/dist/casts/git-patch.js +88 -0
  16. package/dist/casts/git-pull-request.d.ts +67 -0
  17. package/dist/casts/git-pull-request.js +122 -0
  18. package/dist/casts/git-repository.d.ts +9 -0
  19. package/dist/casts/git-repository.js +16 -0
  20. package/dist/casts/git-thread.d.ts +33 -0
  21. package/dist/casts/git-thread.js +65 -0
  22. package/dist/casts/index.d.ts +12 -0
  23. package/dist/casts/index.js +12 -0
  24. package/dist/casts/napplet-handlers.d.ts +39 -0
  25. package/dist/casts/napplet-handlers.js +91 -0
  26. package/dist/casts/napplet.d.ts +98 -0
  27. package/dist/casts/napplet.js +196 -0
  28. package/dist/casts/note.d.ts +8 -0
  29. package/dist/casts/note.js +21 -1
  30. package/dist/casts/nsite.d.ts +134 -0
  31. package/dist/casts/nsite.js +249 -0
  32. package/dist/casts/profile.d.ts +20 -0
  33. package/dist/casts/profile.js +30 -0
  34. package/dist/casts/reaction.d.ts +1 -1
  35. package/dist/casts/relay-discovery.d.ts +4 -0
  36. package/dist/casts/relay-discovery.js +9 -1
  37. package/dist/casts/report.d.ts +28 -15
  38. package/dist/casts/report.js +42 -19
  39. package/dist/casts/share.d.ts +1 -1
  40. package/dist/casts/torrent.d.ts +5 -0
  41. package/dist/casts/torrent.js +8 -1
  42. package/dist/casts/trusted-assertions.d.ts +2 -0
  43. package/dist/casts/trusted-assertions.js +19 -18
  44. package/dist/casts/user-status.d.ts +33 -0
  45. package/dist/casts/user-status.js +69 -0
  46. package/dist/casts/user.d.ts +7 -0
  47. package/dist/casts/user.js +20 -1
  48. package/dist/factories/app-handler.d.ts +31 -0
  49. package/dist/factories/app-handler.js +50 -0
  50. package/dist/factories/app-recommendation.d.ts +21 -0
  51. package/dist/factories/app-recommendation.js +28 -0
  52. package/dist/factories/chat-message.d.ts +37 -0
  53. package/dist/factories/chat-message.js +56 -0
  54. package/dist/factories/comment.d.ts +8 -7
  55. package/dist/factories/comment.js +2 -2
  56. package/dist/factories/external-identities.d.ts +17 -0
  57. package/dist/factories/external-identities.js +28 -0
  58. package/dist/factories/file-message.d.ts +24 -0
  59. package/dist/factories/file-message.js +37 -0
  60. package/dist/factories/forum-thread.d.ts +34 -0
  61. package/dist/factories/forum-thread.js +50 -0
  62. package/dist/factories/git-applied-status.d.ts +39 -0
  63. package/dist/factories/git-applied-status.js +53 -0
  64. package/dist/factories/git-closed-status.d.ts +18 -0
  65. package/dist/factories/git-closed-status.js +24 -0
  66. package/dist/factories/git-draft-status.d.ts +18 -0
  67. package/dist/factories/git-draft-status.js +24 -0
  68. package/dist/factories/git-issue.d.ts +19 -0
  69. package/dist/factories/git-issue.js +25 -0
  70. package/dist/factories/git-open-status.d.ts +18 -0
  71. package/dist/factories/git-open-status.js +22 -0
  72. package/dist/factories/git-patch.d.ts +59 -0
  73. package/dist/factories/git-patch.js +102 -0
  74. package/dist/factories/git-pull-request-update.d.ts +23 -0
  75. package/dist/factories/git-pull-request-update.js +33 -0
  76. package/dist/factories/git-pull-request.d.ts +39 -0
  77. package/dist/factories/git-pull-request.js +64 -0
  78. package/dist/factories/index.d.ts +24 -0
  79. package/dist/factories/index.js +24 -0
  80. package/dist/factories/internal/git-pull-request.d.ts +19 -0
  81. package/dist/factories/internal/git-pull-request.js +26 -0
  82. package/dist/factories/internal/git-status.d.ts +11 -0
  83. package/dist/factories/internal/git-status.js +12 -0
  84. package/dist/factories/internal/git-thread.d.ts +19 -0
  85. package/dist/factories/internal/git-thread.js +29 -0
  86. package/dist/factories/internal/napplet-manifest.d.ts +52 -0
  87. package/dist/factories/internal/napplet-manifest.js +85 -0
  88. package/dist/factories/internal/nsite-manifest.d.ts +45 -0
  89. package/dist/factories/internal/nsite-manifest.js +68 -0
  90. package/dist/factories/legacy-message.d.ts +2 -0
  91. package/dist/factories/legacy-message.js +9 -2
  92. package/dist/factories/named-napplet.d.ts +20 -0
  93. package/dist/factories/named-napplet.js +30 -0
  94. package/dist/factories/named-nsite.d.ts +28 -0
  95. package/dist/factories/named-nsite.js +53 -0
  96. package/dist/factories/napplet-handlers.d.ts +34 -0
  97. package/dist/factories/napplet-handlers.js +77 -0
  98. package/dist/factories/napplet-snapshot.d.ts +18 -0
  99. package/dist/factories/napplet-snapshot.js +38 -0
  100. package/dist/factories/nsite-snapshot.d.ts +18 -0
  101. package/dist/factories/nsite-snapshot.js +29 -0
  102. package/dist/factories/reaction.d.ts +3 -2
  103. package/dist/factories/report.d.ts +48 -0
  104. package/dist/factories/report.js +66 -0
  105. package/dist/factories/root-napplet.d.ts +18 -0
  106. package/dist/factories/root-napplet.js +24 -0
  107. package/dist/factories/root-nsite.d.ts +23 -0
  108. package/dist/factories/root-nsite.js +44 -0
  109. package/dist/factories/torrent.d.ts +24 -10
  110. package/dist/factories/torrent.js +48 -44
  111. package/dist/factories/trusted-provider-list.d.ts +23 -0
  112. package/dist/factories/trusted-provider-list.js +39 -0
  113. package/dist/factories/user-status.d.ts +26 -0
  114. package/dist/factories/user-status.js +52 -0
  115. package/dist/factories/wrapped-message.js +10 -4
  116. package/dist/helpers/app-data.js +15 -7
  117. package/dist/helpers/app-handler.d.ts +43 -6
  118. package/dist/helpers/app-handler.js +53 -3
  119. package/dist/helpers/app-recommendation.d.ts +24 -0
  120. package/dist/helpers/app-recommendation.js +30 -0
  121. package/dist/helpers/bookmark.js +5 -2
  122. package/dist/helpers/comment.d.ts +11 -5
  123. package/dist/helpers/comment.js +7 -1
  124. package/dist/helpers/content.d.ts +3 -1
  125. package/dist/helpers/emoji-pack.js +11 -6
  126. package/dist/helpers/emoji.d.ts +2 -2
  127. package/dist/helpers/encrypted-content-cache.d.ts +2 -11
  128. package/dist/helpers/encrypted-content-cache.js +6 -14
  129. package/dist/helpers/encrypted-file.d.ts +41 -0
  130. package/dist/helpers/encrypted-file.js +64 -0
  131. package/dist/helpers/external-id.js +13 -19
  132. package/dist/helpers/external-identities.d.ts +29 -0
  133. package/dist/helpers/external-identities.js +52 -0
  134. package/dist/helpers/file-message.d.ts +18 -0
  135. package/dist/helpers/file-message.js +44 -0
  136. package/dist/helpers/file-metadata.d.ts +9 -4
  137. package/dist/helpers/file-metadata.js +21 -6
  138. package/dist/helpers/forum-thread.d.ts +10 -0
  139. package/dist/helpers/forum-thread.js +10 -0
  140. package/dist/helpers/gift-wrap.d.ts +40 -15
  141. package/dist/helpers/gift-wrap.js +110 -33
  142. package/dist/helpers/git-issue.d.ts +13 -0
  143. package/dist/helpers/git-issue.js +19 -0
  144. package/dist/helpers/git-patch.d.ts +41 -0
  145. package/dist/helpers/git-patch.js +73 -0
  146. package/dist/helpers/git-pull-request.d.ts +57 -0
  147. package/dist/helpers/git-pull-request.js +111 -0
  148. package/dist/helpers/git-repository.d.ts +4 -0
  149. package/dist/helpers/git-repository.js +16 -0
  150. package/dist/helpers/git-status.d.ts +44 -0
  151. package/dist/helpers/git-status.js +93 -0
  152. package/dist/helpers/git.d.ts +2 -0
  153. package/dist/helpers/git.js +4 -0
  154. package/dist/helpers/groups.d.ts +5 -2
  155. package/dist/helpers/groups.js +40 -18
  156. package/dist/helpers/hashtag.d.ts +4 -2
  157. package/dist/helpers/index.d.ts +13 -0
  158. package/dist/helpers/index.js +13 -0
  159. package/dist/helpers/lists.js +14 -2
  160. package/dist/helpers/lnurl.js +1 -1
  161. package/dist/helpers/messages.js +3 -2
  162. package/dist/helpers/mute.js +20 -9
  163. package/dist/helpers/napplet-handlers.d.ts +79 -0
  164. package/dist/helpers/napplet-handlers.js +187 -0
  165. package/dist/helpers/napplet.d.ts +107 -0
  166. package/dist/helpers/napplet.js +177 -0
  167. package/dist/helpers/nsite.d.ts +90 -0
  168. package/dist/helpers/nsite.js +217 -0
  169. package/dist/helpers/relay-discovery.d.ts +4 -0
  170. package/dist/helpers/relay-discovery.js +8 -0
  171. package/dist/helpers/reports.d.ts +35 -0
  172. package/dist/helpers/reports.js +36 -5
  173. package/dist/helpers/threading.d.ts +4 -2
  174. package/dist/helpers/torrent.d.ts +9 -6
  175. package/dist/helpers/torrent.js +23 -15
  176. package/dist/helpers/trusted-assertions.d.ts +7 -0
  177. package/dist/helpers/trusted-assertions.js +41 -2
  178. package/dist/helpers/user-status.d.ts +13 -1
  179. package/dist/helpers/user-status.js +15 -0
  180. package/dist/helpers/wrapped-messages.d.ts +2 -0
  181. package/dist/helpers/wrapped-messages.js +6 -1
  182. package/dist/models/app-handler.d.ts +21 -0
  183. package/dist/models/app-handler.js +47 -0
  184. package/dist/models/git.d.ts +34 -0
  185. package/dist/models/git.js +144 -0
  186. package/dist/models/index.d.ts +4 -0
  187. package/dist/models/index.js +4 -0
  188. package/dist/models/legacy-messages.js +6 -1
  189. package/dist/models/napplet-handlers.d.ts +16 -0
  190. package/dist/models/napplet-handlers.js +45 -0
  191. package/dist/models/nsite.d.ts +22 -0
  192. package/dist/models/nsite.js +67 -0
  193. package/dist/models/thread.d.ts +4 -1
  194. package/dist/models/thread.js +34 -5
  195. package/dist/models/user-status.d.ts +8 -4
  196. package/dist/models/user-status.js +16 -22
  197. package/dist/models/wrapped-messages.js +9 -7
  198. package/dist/observable/filter-timeline-by-mutes.d.ts +1 -1
  199. package/dist/observable/filter-timeline-by-mutes.js +6 -2
  200. package/dist/operations/app-handler.d.ts +24 -0
  201. package/dist/operations/app-handler.js +58 -0
  202. package/dist/operations/app-recommendation.d.ts +13 -0
  203. package/dist/operations/app-recommendation.js +40 -0
  204. package/dist/operations/calendar-event.js +3 -2
  205. package/dist/operations/chat-message.d.ts +9 -0
  206. package/dist/operations/chat-message.js +12 -0
  207. package/dist/operations/client.d.ts +1 -4
  208. package/dist/operations/client.js +1 -23
  209. package/dist/operations/comment.d.ts +9 -3
  210. package/dist/operations/comment.js +12 -9
  211. package/dist/operations/external-identities.d.ts +8 -0
  212. package/dist/operations/external-identities.js +23 -0
  213. package/dist/operations/file-message.d.ts +7 -0
  214. package/dist/operations/file-message.js +34 -0
  215. package/dist/operations/forum-thread.d.ts +3 -0
  216. package/dist/operations/forum-thread.js +6 -0
  217. package/dist/operations/gift-wrap.js +38 -14
  218. package/dist/operations/git-issue.d.ts +18 -0
  219. package/dist/operations/git-issue.js +31 -0
  220. package/dist/operations/git-patch.d.ts +30 -0
  221. package/dist/operations/git-patch.js +75 -0
  222. package/dist/operations/git-pull-request.d.ts +29 -0
  223. package/dist/operations/git-pull-request.js +74 -0
  224. package/dist/operations/git-repository.js +4 -4
  225. package/dist/operations/git-status.d.ts +28 -0
  226. package/dist/operations/git-status.js +116 -0
  227. package/dist/operations/git-thread.d.ts +13 -0
  228. package/dist/operations/git-thread.js +39 -0
  229. package/dist/operations/index.d.ts +17 -0
  230. package/dist/operations/index.js +17 -0
  231. package/dist/operations/internal/git-commits.d.ts +2 -0
  232. package/dist/operations/internal/git-commits.js +16 -0
  233. package/dist/operations/napplet-handlers.d.ts +47 -0
  234. package/dist/operations/napplet-handlers.js +161 -0
  235. package/dist/operations/napplet.d.ts +51 -0
  236. package/dist/operations/napplet.js +121 -0
  237. package/dist/operations/nsite.d.ts +51 -0
  238. package/dist/operations/nsite.js +112 -0
  239. package/dist/operations/reaction.d.ts +12 -2
  240. package/dist/operations/reaction.js +1 -1
  241. package/dist/operations/report.d.ts +33 -0
  242. package/dist/operations/report.js +60 -0
  243. package/dist/operations/stream.js +5 -4
  244. package/dist/operations/torrent.d.ts +1 -4
  245. package/dist/operations/torrent.js +24 -11
  246. package/dist/operations/trusted-providers.d.ts +14 -0
  247. package/dist/operations/trusted-providers.js +33 -0
  248. package/dist/operations/user-status.d.ts +11 -0
  249. package/dist/operations/user-status.js +29 -0
  250. package/dist/operations/wrapped-message.js +2 -2
  251. package/package.json +13 -17
@@ -0,0 +1,52 @@
1
+ import { blankEventTemplate, EventFactory, toEventTemplate } from "applesauce-core/factories";
2
+ import { kinds } from "applesauce-core/helpers/event";
3
+ import { includeEmojis, setContent } from "applesauce-core/operations/content";
4
+ import { removeSingletonTag } from "applesauce-core/operations/tag/common";
5
+ import { clearStatusLink, setStatusLink, setStatusType } from "../operations/user-status.js";
6
+ const removeEmojiTags = (tags) => tags.filter((t) => t[0] !== "emoji");
7
+ /** A factory class for building NIP-38 user status events (kind 30315) */
8
+ export class UserStatusFactory extends EventFactory {
9
+ /** Creates a new user status factory for a status type */
10
+ static create(type = "general", content = "") {
11
+ return new UserStatusFactory((res) => res(blankEventTemplate(kinds.UserStatuses))).type(type).status(content);
12
+ }
13
+ /** Creates a "music" status that expires when the track stops playing */
14
+ static music(content, expiration, link) {
15
+ let factory = UserStatusFactory.create("music", content);
16
+ if (expiration)
17
+ factory = factory.expiration(expiration);
18
+ if (link)
19
+ factory = factory.link(link);
20
+ return factory;
21
+ }
22
+ /** Creates a factory configured to modify an existing user status */
23
+ static modify(event) {
24
+ if (event.kind !== kinds.UserStatuses)
25
+ throw new Error("Expected a user status event");
26
+ return new UserStatusFactory((res) => res(toEventTemplate(event)));
27
+ }
28
+ /** Sets the status type ("d" tag) */
29
+ type(type) {
30
+ return this.chain(setStatusType(type));
31
+ }
32
+ /** Sets the status text and includes any NIP-30 custom emojis used in it */
33
+ status(content, emojis) {
34
+ return this.modifyPublicTags(removeEmojiTags).chain(setContent(content)).chain(includeEmojis(emojis));
35
+ }
36
+ /** Sets the URL, profile, event, or address the status links to */
37
+ link(link) {
38
+ return this.chain(setStatusLink(link));
39
+ }
40
+ /** Removes the status link */
41
+ clearLink() {
42
+ return this.chain(clearStatusLink());
43
+ }
44
+ /** Removes the expiration timestamp */
45
+ clearExpiration() {
46
+ return this.modifyPublicTags(removeSingletonTag("expiration"));
47
+ }
48
+ /** Clears the status by removing the content, link, emojis, and expiration */
49
+ clear() {
50
+ return this.status("").clearLink().clearExpiration();
51
+ }
52
+ }
@@ -1,7 +1,7 @@
1
1
  import { blankEventTemplate, EventFactory } from "applesauce-core/factories";
2
2
  import { kinds } from "applesauce-core/helpers";
3
3
  import { includeNameValueTag } from "applesauce-core/operations/tags";
4
- import { setShortTextContent } from "applesauce-core/operations/content";
4
+ import { includeEmojis, setContent, setContentWarning } from "applesauce-core/operations/content";
5
5
  import { setParent, setSubject } from "../operations/wrapped-message.js";
6
6
  export class WrappedMessageFactory extends EventFactory {
7
7
  /**
@@ -11,7 +11,7 @@ export class WrappedMessageFactory extends EventFactory {
11
11
  */
12
12
  static create(recipients, message) {
13
13
  const recipientList = typeof recipients === "string" ? [recipients] : recipients;
14
- let factory = new WrappedMessageFactory((res) => res(blankEventTemplate(kinds.PrivateDirectMessage))).chain(setShortTextContent(message));
14
+ let factory = new WrappedMessageFactory((res) => res(blankEventTemplate(kinds.PrivateDirectMessage))).chain(setContent(message));
15
15
  for (const recipient of recipientList) {
16
16
  factory = factory.chain(includeNameValueTag(["p", recipient]));
17
17
  }
@@ -20,13 +20,19 @@ export class WrappedMessageFactory extends EventFactory {
20
20
  /** Creates a reply to a wrapped message */
21
21
  static reply(parent, recipient, message) {
22
22
  return new WrappedMessageFactory((res) => res(blankEventTemplate(kinds.PrivateDirectMessage)))
23
- .chain(setShortTextContent(message))
23
+ .chain(setContent(message))
24
24
  .chain(includeNameValueTag(["p", recipient]))
25
25
  .replyTo(parent);
26
26
  }
27
27
  /** Sets the text content of the message */
28
28
  text(content, options) {
29
- return this.chain(setShortTextContent(content, options));
29
+ // In NIP-17 every p tag is a recipient, including tags inferred from mentions.
30
+ let factory = this.chain(setContent(content));
31
+ if (options?.emojis)
32
+ factory = factory.chain(includeEmojis(options.emojis));
33
+ if (options?.contentWarning !== undefined)
34
+ factory = factory.chain(setContentWarning(options.contentWarning));
35
+ return factory;
30
36
  }
31
37
  /** Sets the parent message "e" tag for NIP-17 reply threading */
32
38
  replyTo(parent) {
@@ -1,3 +1,4 @@
1
+ import { setCachedValue } from "applesauce-core/helpers/cache";
1
2
  import { isNIP04Encrypted } from "applesauce-core/helpers/encryption";
2
3
  import { getHiddenContent, isHiddenContentUnlocked, lockHiddenContent, setHiddenContentEncryptionMethod, unlockHiddenContent, } from "applesauce-core/helpers/hidden-content";
3
4
  import { safeParse } from "applesauce-core/helpers/json";
@@ -28,21 +29,24 @@ export function isAppDataUnlocked(event) {
28
29
  }
29
30
  /** Returns the parsed application data for an event if it's unlocked */
30
31
  export function getAppDataContent(event) {
31
- const cached = Reflect.get(event, AppDataContentSymbol);
32
- if (cached)
33
- return cached;
32
+ if (Reflect.has(event, AppDataContentSymbol))
33
+ return Reflect.get(event, AppDataContentSymbol);
34
34
  // If content is empty, return undefined
35
35
  if (event.content.length === 0)
36
36
  return undefined;
37
37
  let data = getAppDataEncryption(event) ? undefined : safeParse(event.content);
38
- if (!data) {
38
+ if (data === undefined) {
39
39
  const decrypted = getHiddenContent(event);
40
- if (decrypted)
40
+ if (decrypted !== undefined)
41
41
  data = safeParse(decrypted);
42
42
  }
43
- if (!data)
43
+ if (data === undefined)
44
44
  return undefined;
45
- Reflect.set(event, AppDataContentSymbol, data);
45
+ // Derived from the event's own (possibly encrypted) content — identity memo (see
46
+ // applesauce-core's cache.ts taxonomy). Written non-enumerable via setCachedValue (05.1-09) so
47
+ // a plain spread drops it instead of carrying a stale derivation onto a copy whose content
48
+ // differs. lockAppData's Reflect.deleteProperty still clears it (CR-03).
49
+ setCachedValue(event, AppDataContentSymbol, data);
46
50
  return data;
47
51
  }
48
52
  /**
@@ -64,5 +68,9 @@ export async function unlockAppData(event, signer, override) {
64
68
  }
65
69
  /** Removes the unencrypted application data cache on an event */
66
70
  export function lockAppData(event) {
71
+ // Two-delete lock (mirrors lockHiddenTags): drop the parsed-plaintext memo first, then lock the
72
+ // underlying hidden content. Without this, AppDataContentSymbol's cached-read early return in
73
+ // getAppDataContent survives the lock and keeps handing back decrypted plaintext (CR-03).
74
+ Reflect.deleteProperty(event, AppDataContentSymbol);
67
75
  lockHiddenContent(event);
68
76
  }
@@ -1,7 +1,44 @@
1
- import { NostrEvent } from "applesauce-core/helpers/event";
1
+ import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
2
+ import { Filter } from "applesauce-core/helpers/filter";
2
3
  import { AddressPointer, DecodeResult, EventPointer, ProfilePointer } from "applesauce-core/helpers/pointers";
4
+ /** The event kind for NIP-89 handler information */
5
+ export declare const APP_HANDLER_KIND = 31990;
6
+ /** A validated NIP-89 handler information event */
7
+ export type AppHandlerEvent = KnownEvent<typeof APP_HANDLER_KIND>;
3
8
  export type HandlerLinkPlatform = "web" | "ios" | "android";
4
9
  export type HandlerLinkType = DecodeResult["type"];
10
+ /** A URL template for opening NIP-19 entities in a handler */
11
+ export interface HandlerLink {
12
+ /** The URL with a `<bech32>` placeholder */
13
+ url: string;
14
+ /** The NIP-19 entity type the URL handles, or undefined for any type */
15
+ type?: HandlerLinkType;
16
+ }
17
+ /** A parsed NIP-89 `client` tag */
18
+ export interface ClientTag {
19
+ /** The client's display name */
20
+ name: string;
21
+ /** The client's handler information address */
22
+ pointer?: AddressPointer;
23
+ }
24
+ /** Checks if an event is a valid NIP-89 handler information event (kind 31990) */
25
+ export declare function isValidAppHandler(event?: NostrEvent): event is AppHandlerEvent;
26
+ /** Returns the handler's `d` tag identifier */
27
+ export declare function getHandlerIdentifier(handler: NostrEvent): string;
28
+ /** Returns the named nsite (kind 35128) the handler currently serves from its `latest` tag */
29
+ export declare function getHandlerLatestPointer(handler: NostrEvent): AddressPointer | undefined;
30
+ /** Returns the named nsite (kind 35128) the handler is rolling out from its `next` tag */
31
+ export declare function getHandlerNextPointer(handler: NostrEvent): AddressPointer | undefined;
32
+ /** An event or draft with tags, for helpers that only read handler link tags */
33
+ export type HandlerTags = Pick<NostrEvent, "tags">;
34
+ /** Returns a relay filter for handlers that support an event kind */
35
+ export declare function getAppHandlersFilter(kind: number): Filter;
36
+ /** Returns all URL templates the handler advertises for a platform */
37
+ export declare function getHandlerLinks(handler: HandlerTags, platform?: HandlerLinkPlatform): HandlerLink[];
38
+ /** Returns the platforms the handler has at least one URL template for */
39
+ export declare function getHandlerPlatforms(handler: HandlerTags): HandlerLinkPlatform[];
40
+ /** Returns the NIP-89 `client` tag of an event */
41
+ export declare function getClientTag(event: NostrEvent): ClientTag | undefined;
5
42
  /** Returns an array of supported kinds for a given handler */
6
43
  export declare function getHandlerSupportedKinds(handler: NostrEvent): number[];
7
44
  /** Returns the name of the handler */
@@ -11,12 +48,12 @@ export declare function getHandlerPicture(handler: NostrEvent, fallback?: string
11
48
  /** Returns the description of the handler */
12
49
  export declare function getHandlerDescription(handler: NostrEvent): string | undefined;
13
50
  /** Returns the web link template for a handler and type */
14
- export declare function getHandlerLinkTemplate(handler: NostrEvent, platform?: HandlerLinkPlatform, type?: HandlerLinkType): string | undefined;
51
+ export declare function getHandlerLinkTemplate(handler: HandlerTags, platform?: HandlerLinkPlatform, type?: HandlerLinkType): string | undefined;
15
52
  /** Returns a link for a Profile Pointer */
16
- export declare function createHandlerProfileLink(handler: NostrEvent, pointer: ProfilePointer, platform?: HandlerLinkPlatform): string | undefined;
53
+ export declare function createHandlerProfileLink(handler: HandlerTags, pointer: ProfilePointer, platform?: HandlerLinkPlatform): string | undefined;
17
54
  /** Returns a link for an Event Pointer */
18
- export declare function createHandlerEventLink(handler: NostrEvent, pointer: EventPointer, platform?: HandlerLinkPlatform): string | undefined;
55
+ export declare function createHandlerEventLink(handler: HandlerTags, pointer: EventPointer, platform?: HandlerLinkPlatform): string | undefined;
19
56
  /** Returns a link for an Address Pointer */
20
- export declare function createHandlerAddressLink(handler: NostrEvent, pointer: AddressPointer, platform?: HandlerLinkPlatform): string | undefined;
57
+ export declare function createHandlerAddressLink(handler: HandlerTags, pointer: AddressPointer, platform?: HandlerLinkPlatform): string | undefined;
21
58
  /** Creates a handler link for a pointer and optionally fallsback to a web link */
22
- export declare function createHandlerLink(handler: NostrEvent, pointer: AddressPointer | EventPointer | ProfilePointer, platform?: HandlerLinkPlatform, webFallback?: boolean): string | undefined;
59
+ export declare function createHandlerLink(handler: HandlerTags, pointer: AddressPointer | EventPointer | ProfilePointer, platform?: HandlerLinkPlatform, webFallback?: boolean): string | undefined;
@@ -1,9 +1,59 @@
1
- import { isAddressPointer, isEventPointer, naddrEncode, neventEncode, noteEncode, nprofileEncode, npubEncode, } from "applesauce-core/helpers/pointers";
1
+ import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
2
+ import { getReplaceableIdentifier, kinds } from "applesauce-core/helpers/event";
3
+ import { getAddressPointerFromATag, isAddressPointer, isEventPointer, naddrEncode, neventEncode, noteEncode, nprofileEncode, npubEncode, } from "applesauce-core/helpers/pointers";
2
4
  import { getDisplayName, getProfileContent, getProfilePicture, isValidProfile } from "applesauce-core/helpers/profile";
3
5
  import { processTags } from "applesauce-core/helpers/tags";
6
+ import { NSITE_KIND } from "./nsite.js";
7
+ /** The event kind for NIP-89 handler information */
8
+ export const APP_HANDLER_KIND = kinds.Handlerinformation;
9
+ const LatestSymbol = Symbol.for("app-handler-latest");
10
+ const NextSymbol = Symbol.for("app-handler-next");
11
+ const KindsSymbol = Symbol.for("app-handler-kinds");
12
+ /** Checks if an event is a valid NIP-89 handler information event (kind 31990) */
13
+ export function isValidAppHandler(event) {
14
+ return !!event && event.kind === APP_HANDLER_KIND && !!getReplaceableIdentifier(event);
15
+ }
16
+ /** Returns the handler's `d` tag identifier */
17
+ export function getHandlerIdentifier(handler) {
18
+ return getReplaceableIdentifier(handler);
19
+ }
20
+ function nsiteTagPointer(handler, name) {
21
+ const tag = handler.tags.find((t) => t[0] === name);
22
+ const pointer = tag && getAddressPointerFromATag(tag);
23
+ return pointer && pointer.kind === NSITE_KIND ? pointer : undefined;
24
+ }
25
+ /** Returns the named nsite (kind 35128) the handler currently serves from its `latest` tag */
26
+ export function getHandlerLatestPointer(handler) {
27
+ return getOrComputeCachedValue(handler, LatestSymbol, () => nsiteTagPointer(handler, "latest"));
28
+ }
29
+ /** Returns the named nsite (kind 35128) the handler is rolling out from its `next` tag */
30
+ export function getHandlerNextPointer(handler) {
31
+ return getOrComputeCachedValue(handler, NextSymbol, () => nsiteTagPointer(handler, "next"));
32
+ }
33
+ const PLATFORMS = ["web", "ios", "android"];
34
+ /** Returns a relay filter for handlers that support an event kind */
35
+ export function getAppHandlersFilter(kind) {
36
+ return { kinds: [APP_HANDLER_KIND], "#k": [String(kind)] };
37
+ }
38
+ /** Returns all URL templates the handler advertises for a platform */
39
+ export function getHandlerLinks(handler, platform = "web") {
40
+ return processTags(handler.tags, (t) => t[0] === platform && t[1] ? { url: t[1], type: (t[2] || undefined) } : undefined);
41
+ }
42
+ /** Returns the platforms the handler has at least one URL template for */
43
+ export function getHandlerPlatforms(handler) {
44
+ return PLATFORMS.filter((platform) => handler.tags.some((t) => t[0] === platform && t[1]));
45
+ }
46
+ /** Returns the NIP-89 `client` tag of an event */
47
+ export function getClientTag(event) {
48
+ const tag = event.tags.find((t) => t[0] === "client" && t[1]);
49
+ if (!tag)
50
+ return undefined;
51
+ const pointer = tag[2] ? getAddressPointerFromATag(tag.slice(1)) : null;
52
+ return pointer?.kind === APP_HANDLER_KIND ? { name: tag[1], pointer } : { name: tag[1] };
53
+ }
4
54
  /** Returns an array of supported kinds for a given handler */
5
55
  export function getHandlerSupportedKinds(handler) {
6
- return processTags(handler.tags, (t) => (t[0] === "k" && t[1] ? parseInt(t[1]) : undefined));
56
+ return getOrComputeCachedValue(handler, KindsSymbol, () => processTags(handler.tags, (t) => (t[0] === "k" && /^\d+$/.test(t[1] ?? "") ? parseInt(t[1]) : undefined)));
7
57
  }
8
58
  /** Returns the name of the handler */
9
59
  export function getHandlerName(handler) {
@@ -47,7 +97,7 @@ export function createHandlerEventLink(handler, pointer, platform = "web") {
47
97
  }
48
98
  /** Returns a link for an Address Pointer */
49
99
  export function createHandlerAddressLink(handler, pointer, platform = "web") {
50
- // First attempt to use a nevent link, then fallback to note
100
+ // First attempt to use a naddr link, then fallback to the generic link
51
101
  return (getHandlerLinkTemplate(handler, platform, "naddr")?.replace("<bech32>", naddrEncode(pointer)) ||
52
102
  getHandlerLinkTemplate(handler, platform)?.replace("<bech32>", naddrEncode(pointer)));
53
103
  }
@@ -0,0 +1,24 @@
1
+ import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
2
+ import { Filter } from "applesauce-core/helpers/filter";
3
+ import { AddressPointer } from "applesauce-core/helpers/pointers";
4
+ import { HandlerLinkPlatform } from "./app-handler.js";
5
+ /** The event kind for NIP-89 handler recommendations */
6
+ export declare const APP_RECOMMENDATION_KIND = 31989;
7
+ /** A validated NIP-89 handler recommendation event */
8
+ export type AppRecommendationEvent = KnownEvent<typeof APP_RECOMMENDATION_KIND>;
9
+ /** A handler recommended for an event kind */
10
+ export interface RecommendedHandler {
11
+ /** The handler information address */
12
+ pointer: AddressPointer;
13
+ /** The platform the recommendation applies to */
14
+ platform?: HandlerLinkPlatform;
15
+ }
16
+ /** Returns a relay filter for recommendations for an event kind, optionally from a set of authors */
17
+ export declare function getAppRecommendationsFilter(kind: number, authors?: string[]): Filter;
18
+ /** Checks if an event is a valid NIP-89 handler recommendation (kind 31989) for a numeric event kind */
19
+ export declare function isValidAppRecommendation(event?: NostrEvent): event is AppRecommendationEvent;
20
+ /** Returns the event kind the recommendation applies to */
21
+ export declare function getRecommendationKind(recommendation: AppRecommendationEvent): number;
22
+ export declare function getRecommendationKind(recommendation: NostrEvent): number | undefined;
23
+ /** Returns the recommended handlers from the `a` tags */
24
+ export declare function getRecommendedHandlers(recommendation: NostrEvent): RecommendedHandler[];
@@ -0,0 +1,30 @@
1
+ import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
2
+ import { getReplaceableIdentifier, kinds } from "applesauce-core/helpers/event";
3
+ import { getAddressPointerFromATag } from "applesauce-core/helpers/pointers";
4
+ import { processTags } from "applesauce-core/helpers/tags";
5
+ import { APP_HANDLER_KIND } from "./app-handler.js";
6
+ /** The event kind for NIP-89 handler recommendations */
7
+ export const APP_RECOMMENDATION_KIND = kinds.Handlerrecommendation;
8
+ const HandlersSymbol = Symbol.for("app-recommendation-handlers");
9
+ /** Returns a relay filter for recommendations for an event kind, optionally from a set of authors */
10
+ export function getAppRecommendationsFilter(kind, authors) {
11
+ return { kinds: [APP_RECOMMENDATION_KIND], "#d": [String(kind)], ...(authors ? { authors } : {}) };
12
+ }
13
+ /** Checks if an event is a valid NIP-89 handler recommendation (kind 31989) for a numeric event kind */
14
+ export function isValidAppRecommendation(event) {
15
+ return !!event && event.kind === APP_RECOMMENDATION_KIND && /^\d+$/.test(getReplaceableIdentifier(event));
16
+ }
17
+ export function getRecommendationKind(recommendation) {
18
+ return isValidAppRecommendation(recommendation) ? parseInt(getReplaceableIdentifier(recommendation)) : undefined;
19
+ }
20
+ /** Returns the recommended handlers from the `a` tags */
21
+ export function getRecommendedHandlers(recommendation) {
22
+ return getOrComputeCachedValue(recommendation, HandlersSymbol, () => processTags(recommendation.tags, (t) => {
23
+ if (t[0] !== "a")
24
+ return undefined;
25
+ const pointer = getAddressPointerFromATag(t);
26
+ if (pointer?.kind !== APP_HANDLER_KIND)
27
+ return undefined;
28
+ return t[3] ? { pointer, platform: t[3] } : { pointer };
29
+ }));
30
+ }
@@ -1,4 +1,5 @@
1
1
  import { getOrComputeCachedValue, isATag, isETag, notifyEventUpdate, processTags } from "applesauce-core/helpers";
2
+ import { setCachedValue } from "applesauce-core/helpers/cache";
2
3
  import { kinds } from "applesauce-core/helpers/event";
3
4
  import { getHiddenTags, isHiddenTagsUnlocked, unlockHiddenTags } from "applesauce-core/helpers/hidden-tags";
4
5
  import { getAddressPointerFromATag, getEventPointerFromETag, getReplaceableAddressFromPointer, isAddressPointer, isEventPointer, mergeAddressPointers, mergeEventPointers, } from "applesauce-core/helpers/pointers";
@@ -67,8 +68,10 @@ export function getHiddenBookmarks(bookmark) {
67
68
  return undefined;
68
69
  // parse bookmarks
69
70
  const bookmarks = parseBookmarkTags(tags);
70
- // set cached value
71
- Reflect.set(bookmark, BookmarkHiddenSymbol, bookmarks);
71
+ // Derived from the event's own hidden tags — identity memo (see applesauce-core's cache.ts
72
+ // taxonomy). Written non-enumerable via setCachedValue (05.1-09) so a plain spread drops it
73
+ // instead of carrying a stale derivation onto a copy whose hidden tags differ.
74
+ setCachedValue(bookmark, BookmarkHiddenSymbol, bookmarks);
72
75
  return bookmarks;
73
76
  }
74
77
  /** Unlocks the hidden bookmarks on a bookmarks event */
@@ -1,4 +1,4 @@
1
- import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
1
+ import { KnownEvent, NostrEvent, StoreEvent } from "applesauce-core/helpers/event";
2
2
  import { ExternalIdentifiers, ExternalPointer } from "./external-id.js";
3
3
  export declare const COMMENT_KIND = 1111;
4
4
  /** Type for validated comment events */
@@ -32,9 +32,9 @@ export declare function getCommentAddressPointer(tags: string[][], root?: boolea
32
32
  export declare function getCommentExternalPointer(tags: string[][], root?: boolean): CommentExternalPointer<keyof ExternalIdentifiers> | null;
33
33
  /** Returns the root pointer for a comment */
34
34
  export declare function getCommentRootPointer(comment: CommentEvent): CommentPointer;
35
- export declare function getCommentRootPointer(comment: NostrEvent): CommentPointer | null;
35
+ export declare function getCommentRootPointer(comment: StoreEvent): CommentPointer | null;
36
36
  /** Returns the reply pointer for a comment */
37
- export declare function getCommentReplyPointer(comment: NostrEvent): CommentPointer | null;
37
+ export declare function getCommentReplyPointer(comment: StoreEvent): CommentPointer | null;
38
38
  /** Checks if a pointer is a {@link CommentEventPointer} */
39
39
  export declare function isCommentEventPointer(pointer: any): pointer is CommentEventPointer;
40
40
  /** Checks if a pointer is a {@link CommentAddressPointer} */
@@ -45,5 +45,11 @@ export declare function isCommentExternalPointer(pointer: any): pointer is Comme
45
45
  export declare function isValidComment(comment: NostrEvent): comment is CommentEvent;
46
46
  /** Create a set fo tags for a single CommentPointer */
47
47
  export declare function createCommentTagsFromCommentPointer(pointer: CommentPointer, root?: boolean): string[][];
48
- /** Returns an array of NIP-22 tags for a kind 1111 comment event */
49
- export declare function createCommentTagsForEvent(parent: NostrEvent, relayHint?: string): string[][];
48
+ /**
49
+ * Returns an array of NIP-22 tags for a kind 1111 comment event
50
+ * @param parent - The full parent event or {@link Rumor} being replied to. Only
51
+ * `id`/`kind`/`pubkey`/`tags` are read, so an unsigned rumor works the same as a
52
+ * signed event — the parent's own root tags are what make nested replies stay
53
+ * rooted on the original event.
54
+ */
55
+ export declare function createCommentTagsForEvent(parent: StoreEvent, relayHint?: string): string[][];
@@ -158,7 +158,13 @@ export function createCommentTagsFromCommentPointer(pointer, root = false) {
158
158
  }
159
159
  throw new Error("Unknown comment pointer kind");
160
160
  }
161
- /** Returns an array of NIP-22 tags for a kind 1111 comment event */
161
+ /**
162
+ * Returns an array of NIP-22 tags for a kind 1111 comment event
163
+ * @param parent - The full parent event or {@link Rumor} being replied to. Only
164
+ * `id`/`kind`/`pubkey`/`tags` are read, so an unsigned rumor works the same as a
165
+ * signed event — the parent's own root tags are what make nested replies stay
166
+ * rooted on the original event.
167
+ */
162
168
  export function createCommentTagsForEvent(parent, relayHint) {
163
169
  const tags = [];
164
170
  let parentPointer;
@@ -1,3 +1,5 @@
1
1
  import { NostrEvent } from "applesauce-core/helpers/event";
2
2
  /** Returns the NIP-36 content-warning for an event. returns boolean if there is no "reason" */
3
- export declare function getContentWarning(event: NostrEvent): string | boolean;
3
+ export declare function getContentWarning<E extends {
4
+ tags: string[][];
5
+ } = NostrEvent>(event: E): string | boolean;
@@ -1,4 +1,5 @@
1
1
  import { getOrComputeCachedValue, notifyEventUpdate } from "applesauce-core/helpers";
2
+ import { setCachedValue } from "applesauce-core/helpers/cache";
2
3
  import { getReplaceableIdentifier, getTagValue, kinds } from "applesauce-core/helpers/event";
3
4
  import { getHiddenTags, isHiddenTagsUnlocked, setHiddenTagsEncryptionMethod, unlockHiddenTags, } from "applesauce-core/helpers/hidden-tags";
4
5
  import { getAddressPointerFromATag } from "applesauce-core/helpers/pointers";
@@ -69,7 +70,10 @@ export function getHiddenFavoriteEmojis(list) {
69
70
  if (!tags)
70
71
  return undefined;
71
72
  const emojis = parseEmojiTags(tags);
72
- Reflect.set(list, FavoriteEmojiPacksHiddenSymbol, emojis);
73
+ // Derived from the list's own hidden tags — identity memo (see applesauce-core's cache.ts
74
+ // taxonomy). Written non-enumerable via setCachedValue (05.1-09) so a plain spread drops it
75
+ // instead of carrying a stale derivation onto a copy whose hidden tags differ.
76
+ setCachedValue(list, FavoriteEmojiPacksHiddenSymbol, emojis);
73
77
  return emojis;
74
78
  }
75
79
  export function getHiddenFavoriteEmojiPackPointers(list) {
@@ -79,16 +83,17 @@ export function getHiddenFavoriteEmojiPackPointers(list) {
79
83
  if (!tags)
80
84
  return undefined;
81
85
  const pointers = parseEmojiPackPointers(tags);
82
- Reflect.set(list, FavoriteEmojiPacksHiddenPointersSymbol, pointers);
86
+ // Derived from the list's own hidden tags — identity memo (see applesauce-core's cache.ts
87
+ // taxonomy). Written non-enumerable via setCachedValue (05.1-09) so a plain spread drops it
88
+ // instead of carrying a stale derivation onto a copy whose hidden tags differ.
89
+ setCachedValue(list, FavoriteEmojiPacksHiddenPointersSymbol, pointers);
83
90
  return pointers;
84
91
  }
85
92
  /** Checks if the hidden favorite emoji packs are unlocked */
86
93
  export function isHiddenFavoriteEmojiPacksUnlocked(list) {
87
94
  return (isHiddenTagsUnlocked(list) &&
88
- (FavoriteEmojiPacksHiddenSymbol in list ||
89
- FavoriteEmojiPacksHiddenPointersSymbol in list ||
90
- getHiddenFavoriteEmojis(list) !== undefined ||
91
- getHiddenFavoriteEmojiPackPointers(list) !== undefined));
95
+ getHiddenFavoriteEmojis(list) !== undefined &&
96
+ getHiddenFavoriteEmojiPackPointers(list) !== undefined);
92
97
  }
93
98
  /** Unlocks the hidden favorite emojis and pack pointers on a kind 10030 list */
94
99
  export async function unlockHiddenFavoriteEmojiPacks(list, signer) {
@@ -1,4 +1,4 @@
1
- import { NostrEvent } from "applesauce-core/helpers/event";
1
+ import { NostrEvent, StoreEvent } from "applesauce-core/helpers/event";
2
2
  import { AddressPointer } from "applesauce-core/helpers/pointers";
3
3
  export type Emoji = {
4
4
  /** The emoji shortcode (without the ::) */
@@ -17,4 +17,4 @@ export declare function getEmojiFromTags(event: {
17
17
  tags: string[][];
18
18
  } | string[][], code: string): Emoji | undefined;
19
19
  /** Returns the custom emoji for a reaction event */
20
- export declare function getReactionEmoji(event: NostrEvent): Emoji | undefined;
20
+ export declare function getReactionEmoji<E extends StoreEvent = NostrEvent>(event: E): Emoji | undefined;
@@ -1,17 +1,8 @@
1
1
  import { IEventStoreStreams } from "applesauce-core/event-store";
2
+ import { EncryptedContentCache } from "applesauce-core/helpers/encrypted-content-cache";
2
3
  import { NostrEvent } from "applesauce-core/helpers/event";
3
4
  import { Observable } from "rxjs";
4
- /** A symbol that is used to mark encrypted content as being from a cache */
5
- export declare const EncryptedContentFromCacheSymbol: unique symbol;
6
- /** An interface that is used to cache encrypted content on events */
7
- export interface EncryptedContentCache {
8
- getItem: (key: string) => Promise<string | null>;
9
- setItem: (key: string, value: string) => Promise<any>;
10
- }
11
- /** Marks the encrypted content as being from a cache */
12
- export declare function markEncryptedContentFromCache<T extends object>(event: T): void;
13
- /** Checks if the encrypted content is from a cache */
14
- export declare function isEncryptedContentFromCache<T extends object>(event: T): boolean;
5
+ export * from "applesauce-core/helpers/encrypted-content-cache";
15
6
  /**
16
7
  * Starts a process that persists and restores all encrypted content
17
8
  * @param eventStore - The event store to listen to
@@ -1,18 +1,10 @@
1
1
  import { logger } from "applesauce-core";
2
+ import { isEncryptedContentFromCache, markEncryptedContentFromCache, } from "applesauce-core/helpers/encrypted-content-cache";
2
3
  import { canHaveEncryptedContent, getEncryptedContent, isEncryptedContentUnlocked, setEncryptedContentCache, } from "applesauce-core/helpers/encrypted-content";
3
4
  import { kinds, notifyEventUpdate } from "applesauce-core/helpers/event";
4
5
  import { catchError, combineLatest, combineLatestWith, distinct, EMPTY, filter, isObservable, map, merge, mergeMap, of, switchMap, } from "rxjs";
5
6
  import { getGiftWrapSeal, getSealGiftWrap, getSealRumor, isGiftWrapUnlocked } from "./gift-wrap.js";
6
- /** A symbol that is used to mark encrypted content as being from a cache */
7
- export const EncryptedContentFromCacheSymbol = Symbol.for("encrypted-content-from-cache");
8
- /** Marks the encrypted content as being from a cache */
9
- export function markEncryptedContentFromCache(event) {
10
- Reflect.set(event, EncryptedContentFromCacheSymbol, true);
11
- }
12
- /** Checks if the encrypted content is from a cache */
13
- export function isEncryptedContentFromCache(event) {
14
- return Reflect.has(event, EncryptedContentFromCacheSymbol);
15
- }
7
+ export * from "applesauce-core/helpers/encrypted-content-cache";
16
8
  const log = logger.extend("EncryptedContentCache");
17
9
  /**
18
10
  * Starts a process that persists and restores all encrypted content
@@ -25,7 +17,7 @@ export function persistEncryptedContent(eventStore, storage, fallback) {
25
17
  const storage$ = isObservable(storage) ? storage : of(storage);
26
18
  // Get the encrypted content from storage or call the fallback
27
19
  const getItem = async (storage, event) => {
28
- return (await storage.getItem(event.id)) || (fallback ? await fallback(event) : null);
20
+ return (await storage.getItem(event.id)) ?? (fallback ? await fallback(event) : null);
29
21
  };
30
22
  // Restore encrypted content when it is inserted
31
23
  const restore = eventStore.insert$
@@ -71,7 +63,7 @@ export function persistEncryptedContent(eventStore, storage, fallback) {
71
63
  return EMPTY;
72
64
  }))))
73
65
  .subscribe(async ([seal, content]) => {
74
- if (!seal || !content)
66
+ if (!seal || typeof content !== "string")
75
67
  return;
76
68
  markEncryptedContentFromCache(seal);
77
69
  setEncryptedContentCache(seal, content);
@@ -97,7 +89,7 @@ export function persistEncryptedContent(eventStore, storage, fallback) {
97
89
  .subscribe(async ([event, storage]) => {
98
90
  try {
99
91
  const content = getEncryptedContent(event);
100
- if (content) {
92
+ if (content !== undefined) {
101
93
  await storage.setItem(event.id, content);
102
94
  log(`Persisted encrypted content for ${event.id}`);
103
95
  }
@@ -117,7 +109,7 @@ export function persistEncryptedContent(eventStore, storage, fallback) {
117
109
  return;
118
110
  try {
119
111
  const content = getEncryptedContent(seal);
120
- if (content) {
112
+ if (content !== undefined) {
121
113
  await storage.setItem(seal.id, content);
122
114
  log(`Persisted encrypted content for ${seal.id}`);
123
115
  }
@@ -0,0 +1,41 @@
1
+ /** The file encryption algorithm used by NIP-17 file messages */
2
+ export declare const ENCRYPTED_FILE_ALGORITHM = "aes-gcm";
3
+ /** Raw file data accepted by {@link encryptFile} and {@link decryptFile} */
4
+ export type FileData = Blob | ArrayBuffer | Uint8Array;
5
+ /** The result of encrypting a file */
6
+ export type EncryptedFile = {
7
+ /** The encrypted bytes to upload */
8
+ ciphertext: Uint8Array;
9
+ /** The encryption algorithm, always {@link ENCRYPTED_FILE_ALGORITHM} */
10
+ algorithm: typeof ENCRYPTED_FILE_ALGORITHM;
11
+ /** The hex encoded AES key */
12
+ key: string;
13
+ /** The hex encoded AES-GCM nonce */
14
+ nonce: string;
15
+ /** The sha256 of the encrypted bytes */
16
+ sha256: string;
17
+ /** The sha256 of the original bytes */
18
+ originalSha256: string;
19
+ /** The size of the encrypted bytes */
20
+ size: number;
21
+ };
22
+ /** The fields needed to decrypt a file */
23
+ export type FileDecryptionFields = {
24
+ /** The encryption algorithm, defaults to {@link ENCRYPTED_FILE_ALGORITHM} */
25
+ encryptionAlgorithm?: string;
26
+ /** The hex encoded AES key */
27
+ decryptionKey?: string;
28
+ /** The hex encoded AES-GCM nonce */
29
+ decryptionNonce?: string;
30
+ /** The expected sha256 of the encrypted bytes */
31
+ sha256?: string;
32
+ /** The expected sha256 of the decrypted bytes */
33
+ originalSha256?: string;
34
+ };
35
+ /** Encrypts a file with a random AES-GCM key and nonce for upload to a public file server */
36
+ export declare function encryptFile(data: FileData): Promise<EncryptedFile>;
37
+ /**
38
+ * Decrypts a file encrypted with {@link encryptFile} or another NIP-17 client
39
+ * @throws if the algorithm is unsupported, the key or nonce is missing, a hash does not match, or decryption fails
40
+ */
41
+ export declare function decryptFile(data: FileData, fields: FileDecryptionFields): Promise<Uint8Array>;