applesauce-common 6.2.0 → 7.0.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 (224) 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 +11 -0
  23. package/dist/casts/index.js +11 -0
  24. package/dist/casts/napplet.d.ts +98 -0
  25. package/dist/casts/napplet.js +196 -0
  26. package/dist/casts/note.d.ts +8 -0
  27. package/dist/casts/note.js +21 -1
  28. package/dist/casts/nsite.d.ts +134 -0
  29. package/dist/casts/nsite.js +249 -0
  30. package/dist/casts/profile.d.ts +20 -0
  31. package/dist/casts/profile.js +30 -0
  32. package/dist/casts/reaction.d.ts +1 -1
  33. package/dist/casts/relay-discovery.d.ts +4 -0
  34. package/dist/casts/relay-discovery.js +9 -1
  35. package/dist/casts/report.d.ts +28 -15
  36. package/dist/casts/report.js +42 -19
  37. package/dist/casts/share.d.ts +1 -1
  38. package/dist/casts/torrent.d.ts +5 -0
  39. package/dist/casts/torrent.js +8 -1
  40. package/dist/casts/trusted-assertions.d.ts +2 -0
  41. package/dist/casts/trusted-assertions.js +19 -18
  42. package/dist/casts/user-status.d.ts +33 -0
  43. package/dist/casts/user-status.js +69 -0
  44. package/dist/casts/user.d.ts +7 -0
  45. package/dist/casts/user.js +20 -1
  46. package/dist/factories/app-handler.d.ts +31 -0
  47. package/dist/factories/app-handler.js +50 -0
  48. package/dist/factories/app-recommendation.d.ts +21 -0
  49. package/dist/factories/app-recommendation.js +28 -0
  50. package/dist/factories/chat-message.d.ts +37 -0
  51. package/dist/factories/chat-message.js +56 -0
  52. package/dist/factories/comment.d.ts +8 -7
  53. package/dist/factories/comment.js +2 -2
  54. package/dist/factories/external-identities.d.ts +17 -0
  55. package/dist/factories/external-identities.js +28 -0
  56. package/dist/factories/forum-thread.d.ts +34 -0
  57. package/dist/factories/forum-thread.js +50 -0
  58. package/dist/factories/git-applied-status.d.ts +39 -0
  59. package/dist/factories/git-applied-status.js +53 -0
  60. package/dist/factories/git-closed-status.d.ts +18 -0
  61. package/dist/factories/git-closed-status.js +24 -0
  62. package/dist/factories/git-draft-status.d.ts +18 -0
  63. package/dist/factories/git-draft-status.js +24 -0
  64. package/dist/factories/git-issue.d.ts +19 -0
  65. package/dist/factories/git-issue.js +25 -0
  66. package/dist/factories/git-open-status.d.ts +18 -0
  67. package/dist/factories/git-open-status.js +22 -0
  68. package/dist/factories/git-patch.d.ts +59 -0
  69. package/dist/factories/git-patch.js +102 -0
  70. package/dist/factories/git-pull-request-update.d.ts +23 -0
  71. package/dist/factories/git-pull-request-update.js +33 -0
  72. package/dist/factories/git-pull-request.d.ts +39 -0
  73. package/dist/factories/git-pull-request.js +64 -0
  74. package/dist/factories/index.d.ts +22 -0
  75. package/dist/factories/index.js +22 -0
  76. package/dist/factories/internal/git-pull-request.d.ts +19 -0
  77. package/dist/factories/internal/git-pull-request.js +26 -0
  78. package/dist/factories/internal/git-status.d.ts +11 -0
  79. package/dist/factories/internal/git-status.js +12 -0
  80. package/dist/factories/internal/git-thread.d.ts +19 -0
  81. package/dist/factories/internal/git-thread.js +29 -0
  82. package/dist/factories/internal/napplet-manifest.d.ts +52 -0
  83. package/dist/factories/internal/napplet-manifest.js +85 -0
  84. package/dist/factories/internal/nsite-manifest.d.ts +45 -0
  85. package/dist/factories/internal/nsite-manifest.js +68 -0
  86. package/dist/factories/legacy-message.d.ts +2 -0
  87. package/dist/factories/legacy-message.js +9 -2
  88. package/dist/factories/named-napplet.d.ts +20 -0
  89. package/dist/factories/named-napplet.js +30 -0
  90. package/dist/factories/named-nsite.d.ts +28 -0
  91. package/dist/factories/named-nsite.js +53 -0
  92. package/dist/factories/napplet-snapshot.d.ts +18 -0
  93. package/dist/factories/napplet-snapshot.js +38 -0
  94. package/dist/factories/nsite-snapshot.d.ts +18 -0
  95. package/dist/factories/nsite-snapshot.js +29 -0
  96. package/dist/factories/reaction.d.ts +3 -2
  97. package/dist/factories/report.d.ts +48 -0
  98. package/dist/factories/report.js +66 -0
  99. package/dist/factories/root-napplet.d.ts +18 -0
  100. package/dist/factories/root-napplet.js +24 -0
  101. package/dist/factories/root-nsite.d.ts +23 -0
  102. package/dist/factories/root-nsite.js +44 -0
  103. package/dist/factories/torrent.d.ts +24 -10
  104. package/dist/factories/torrent.js +48 -44
  105. package/dist/factories/trusted-provider-list.d.ts +23 -0
  106. package/dist/factories/trusted-provider-list.js +39 -0
  107. package/dist/factories/user-status.d.ts +26 -0
  108. package/dist/factories/user-status.js +52 -0
  109. package/dist/helpers/app-data.js +15 -7
  110. package/dist/helpers/app-handler.d.ts +43 -6
  111. package/dist/helpers/app-handler.js +53 -3
  112. package/dist/helpers/app-recommendation.d.ts +24 -0
  113. package/dist/helpers/app-recommendation.js +30 -0
  114. package/dist/helpers/bookmark.js +5 -2
  115. package/dist/helpers/comment.d.ts +11 -5
  116. package/dist/helpers/comment.js +7 -1
  117. package/dist/helpers/content.d.ts +3 -1
  118. package/dist/helpers/emoji-pack.js +11 -6
  119. package/dist/helpers/emoji.d.ts +2 -2
  120. package/dist/helpers/encrypted-content-cache.js +18 -1
  121. package/dist/helpers/external-id.js +13 -19
  122. package/dist/helpers/external-identities.d.ts +29 -0
  123. package/dist/helpers/external-identities.js +52 -0
  124. package/dist/helpers/file-metadata.js +5 -6
  125. package/dist/helpers/forum-thread.d.ts +10 -0
  126. package/dist/helpers/forum-thread.js +10 -0
  127. package/dist/helpers/gift-wrap.d.ts +40 -15
  128. package/dist/helpers/gift-wrap.js +110 -33
  129. package/dist/helpers/git-issue.d.ts +13 -0
  130. package/dist/helpers/git-issue.js +19 -0
  131. package/dist/helpers/git-patch.d.ts +41 -0
  132. package/dist/helpers/git-patch.js +73 -0
  133. package/dist/helpers/git-pull-request.d.ts +57 -0
  134. package/dist/helpers/git-pull-request.js +111 -0
  135. package/dist/helpers/git-repository.d.ts +4 -0
  136. package/dist/helpers/git-repository.js +16 -0
  137. package/dist/helpers/git-status.d.ts +44 -0
  138. package/dist/helpers/git-status.js +93 -0
  139. package/dist/helpers/git.d.ts +2 -0
  140. package/dist/helpers/git.js +4 -0
  141. package/dist/helpers/groups.d.ts +5 -2
  142. package/dist/helpers/groups.js +40 -18
  143. package/dist/helpers/hashtag.d.ts +4 -2
  144. package/dist/helpers/index.d.ts +10 -0
  145. package/dist/helpers/index.js +10 -0
  146. package/dist/helpers/lists.js +14 -2
  147. package/dist/helpers/lnurl.js +1 -1
  148. package/dist/helpers/mute.js +18 -7
  149. package/dist/helpers/napplet.d.ts +89 -0
  150. package/dist/helpers/napplet.js +144 -0
  151. package/dist/helpers/nsite.d.ts +90 -0
  152. package/dist/helpers/nsite.js +217 -0
  153. package/dist/helpers/relay-discovery.d.ts +4 -0
  154. package/dist/helpers/relay-discovery.js +8 -0
  155. package/dist/helpers/reports.d.ts +35 -0
  156. package/dist/helpers/reports.js +36 -5
  157. package/dist/helpers/threading.d.ts +4 -2
  158. package/dist/helpers/torrent.d.ts +9 -6
  159. package/dist/helpers/torrent.js +23 -15
  160. package/dist/helpers/trusted-assertions.d.ts +7 -0
  161. package/dist/helpers/trusted-assertions.js +41 -2
  162. package/dist/helpers/user-status.d.ts +13 -1
  163. package/dist/helpers/user-status.js +15 -0
  164. package/dist/models/app-handler.d.ts +21 -0
  165. package/dist/models/app-handler.js +47 -0
  166. package/dist/models/git.d.ts +34 -0
  167. package/dist/models/git.js +144 -0
  168. package/dist/models/index.d.ts +3 -0
  169. package/dist/models/index.js +3 -0
  170. package/dist/models/nsite.d.ts +22 -0
  171. package/dist/models/nsite.js +67 -0
  172. package/dist/models/thread.d.ts +4 -1
  173. package/dist/models/thread.js +34 -5
  174. package/dist/models/user-status.d.ts +8 -4
  175. package/dist/models/user-status.js +16 -22
  176. package/dist/observable/filter-timeline-by-mutes.d.ts +1 -1
  177. package/dist/observable/filter-timeline-by-mutes.js +5 -1
  178. package/dist/operations/app-handler.d.ts +24 -0
  179. package/dist/operations/app-handler.js +58 -0
  180. package/dist/operations/app-recommendation.d.ts +13 -0
  181. package/dist/operations/app-recommendation.js +40 -0
  182. package/dist/operations/calendar-event.js +3 -2
  183. package/dist/operations/chat-message.d.ts +9 -0
  184. package/dist/operations/chat-message.js +12 -0
  185. package/dist/operations/client.d.ts +1 -4
  186. package/dist/operations/client.js +1 -23
  187. package/dist/operations/comment.d.ts +9 -3
  188. package/dist/operations/comment.js +12 -9
  189. package/dist/operations/external-identities.d.ts +8 -0
  190. package/dist/operations/external-identities.js +23 -0
  191. package/dist/operations/forum-thread.d.ts +3 -0
  192. package/dist/operations/forum-thread.js +6 -0
  193. package/dist/operations/gift-wrap.js +38 -14
  194. package/dist/operations/git-issue.d.ts +18 -0
  195. package/dist/operations/git-issue.js +31 -0
  196. package/dist/operations/git-patch.d.ts +30 -0
  197. package/dist/operations/git-patch.js +75 -0
  198. package/dist/operations/git-pull-request.d.ts +29 -0
  199. package/dist/operations/git-pull-request.js +74 -0
  200. package/dist/operations/git-repository.js +4 -4
  201. package/dist/operations/git-status.d.ts +28 -0
  202. package/dist/operations/git-status.js +116 -0
  203. package/dist/operations/git-thread.d.ts +13 -0
  204. package/dist/operations/git-thread.js +39 -0
  205. package/dist/operations/index.d.ts +15 -0
  206. package/dist/operations/index.js +15 -0
  207. package/dist/operations/internal/git-commits.d.ts +2 -0
  208. package/dist/operations/internal/git-commits.js +16 -0
  209. package/dist/operations/napplet.d.ts +51 -0
  210. package/dist/operations/napplet.js +121 -0
  211. package/dist/operations/nsite.d.ts +51 -0
  212. package/dist/operations/nsite.js +112 -0
  213. package/dist/operations/reaction.d.ts +12 -2
  214. package/dist/operations/reaction.js +1 -1
  215. package/dist/operations/report.d.ts +33 -0
  216. package/dist/operations/report.js +60 -0
  217. package/dist/operations/stream.js +5 -4
  218. package/dist/operations/torrent.d.ts +1 -4
  219. package/dist/operations/torrent.js +24 -11
  220. package/dist/operations/trusted-providers.d.ts +14 -0
  221. package/dist/operations/trusted-providers.js +33 -0
  222. package/dist/operations/user-status.d.ts +11 -0
  223. package/dist/operations/user-status.js +29 -0
  224. package/package.json +9 -9
@@ -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,4 +1,5 @@
1
1
  import { logger } from "applesauce-core";
2
+ import { setCachedValue } from "applesauce-core/helpers/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";
@@ -7,7 +8,23 @@ import { getGiftWrapSeal, getSealGiftWrap, getSealRumor, isGiftWrapUnlocked } fr
7
8
  export const EncryptedContentFromCacheSymbol = Symbol.for("encrypted-content-from-cache");
8
9
  /** Marks the encrypted content as being from a cache */
9
10
  export function markEncryptedContentFromCache(event) {
10
- Reflect.set(event, EncryptedContentFromCacheSymbol, true);
11
+ // A restore-provenance flag that is instance-local — unlike FromCacheSymbol, it is NOT a member
12
+ // of EventStore.copySymbolsToDuplicateEvent's merge list (see cache.ts taxonomy), so a
13
+ // duplicate-delivery merge never copies it onto another object. persistEncryptedContent's
14
+ // `persist` and `persistSeals` subscriptions both filter on isEncryptedContentFromCache(event)
15
+ // === false to avoid re-persisting content that was just restored from the cache: if a
16
+ // logically-identical event ever reached that filter as a distinct object lacking this flag, the
17
+ // filter would fail open and re-persist already-cached content. Whether that is reachable is
18
+ // unverified here: EventMemory.add keeps the originally-tracked object for a same-id duplicate
19
+ // and discards the newcomer entirely, so the ordinary EventStore.add duplicate-delivery path does
20
+ // not appear to replace the tracked instance — but replaceable-history and cross-store paths were
21
+ // not traced as part of this comment-only fix.
22
+ //
23
+ // Written non-enumerable via setCachedValue (05.1-09) so a plain spread drops it instead of
24
+ // carrying a stale provenance flag forward. isEncryptedContentFromCache's Reflect.has reader is
25
+ // enumerability-blind and still sees this write (WR-11's separate === true tightening stays
26
+ // deferred — D-10 — and is out of scope here).
27
+ setCachedValue(event, EncryptedContentFromCacheSymbol, true);
11
28
  }
12
29
  /** Checks if the encrypted content is from a cache */
13
30
  export function isEncryptedContentFromCache(event) {
@@ -1,23 +1,8 @@
1
+ import { serializeURL } from "applesauce-core/helpers/url";
1
2
  /** Casts a string to a valid external pointer */
2
3
  export function isValidExternalPointer(identifier) {
3
4
  return parseExternalPointer(identifier) !== null;
4
5
  }
5
- /**
6
- * Normalizes a URL according to NIP-73:
7
- * - Removes fragment
8
- * - Returns the normalized URL string
9
- */
10
- function normalizeUrl(url) {
11
- try {
12
- const urlObj = new URL(url);
13
- urlObj.hash = ""; // Remove fragment
14
- return urlObj.toString();
15
- }
16
- catch {
17
- // If URL parsing fails, return original (will be caught by validation)
18
- return url;
19
- }
20
- }
21
6
  export function parseExternalPointer(identifier) {
22
7
  // Check explicit prefixes first (these take precedence over URL parsing)
23
8
  if (identifier.startsWith("#"))
@@ -49,9 +34,18 @@ export function parseExternalPointer(identifier) {
49
34
  // Check for URL (must be a valid URL, normalized, no fragment)
50
35
  // URLs don't have a prefix, so we check if it's a valid URL after checking all prefixes
51
36
  try {
52
- new URL(identifier); // Validate URL
53
- // Valid URL - normalize it (remove fragment) and return
54
- const normalized = normalizeUrl(identifier);
37
+ let normalized;
38
+ if (/^(?:https?|wss?):\/\//i.test(identifier)) {
39
+ const serialized = serializeURL(identifier);
40
+ const hash = serialized.indexOf("#");
41
+ normalized = hash === -1 ? serialized : serialized.slice(0, hash);
42
+ }
43
+ else {
44
+ // Removing a fragment can also trim opaque paths, so retain the native setter here.
45
+ const url = new URL(identifier);
46
+ url.hash = "";
47
+ normalized = url.href;
48
+ }
55
49
  return { kind: "web", identifier: normalized };
56
50
  }
57
51
  catch {
@@ -0,0 +1,29 @@
1
+ import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
2
+ export declare const EXTERNAL_IDENTITIES_KIND = 10011;
3
+ export declare const ExternalIdentitiesSymbol: unique symbol;
4
+ export type ExternalIdentitiesEvent = KnownEvent<typeof EXTERNAL_IDENTITIES_KIND>;
5
+ /** An external identity claimed by a NIP-39 "i" tag */
6
+ export type ExternalIdentity = {
7
+ /** The platform name (github, twitter, mastodon, telegram, bluesky, discord, etc) */
8
+ platform: string;
9
+ /** The identity on the platform */
10
+ identity: string;
11
+ /** A platform specific pointer to the proof of ownership */
12
+ proof: string;
13
+ };
14
+ /** Checks if an event is a NIP-39 external identities list */
15
+ export declare function isValidExternalIdentities(event?: NostrEvent): event is ExternalIdentitiesEvent;
16
+ /** Parses a NIP-39 ["i", "platform:identity", "proof"] tag */
17
+ export declare function getExternalIdentityFromTag(tag: string[]): ExternalIdentity | undefined;
18
+ /** Creates a NIP-39 "i" tag for an external identity */
19
+ export declare function createExternalIdentityTag(identity: ExternalIdentity): string[];
20
+ /**
21
+ * Returns the external identities from a NIP-39 identities list
22
+ * @see https://github.com/nostr-protocol/nips/blob/master/39.md
23
+ */
24
+ export declare function getExternalIdentities(event?: NostrEvent): ExternalIdentity[];
25
+ /**
26
+ * Returns the URL of the proof for an external identity, or undefined for unknown platforms
27
+ * @see https://github.com/nostr-protocol/nips/blob/master/39.md
28
+ */
29
+ export declare function getExternalIdentityProofUrl({ platform, identity, proof }: ExternalIdentity): string | undefined;
@@ -0,0 +1,52 @@
1
+ import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
2
+ import { processTags } from "applesauce-core/helpers/tags";
3
+ export const EXTERNAL_IDENTITIES_KIND = 10011;
4
+ export const ExternalIdentitiesSymbol = Symbol.for("external-identities");
5
+ /** Checks if an event is a NIP-39 external identities list */
6
+ export function isValidExternalIdentities(event) {
7
+ return !!event && event.kind === EXTERNAL_IDENTITIES_KIND;
8
+ }
9
+ /** Parses a NIP-39 ["i", "platform:identity", "proof"] tag */
10
+ export function getExternalIdentityFromTag(tag) {
11
+ if (tag[0] !== "i" || !tag[1] || !tag[2])
12
+ return undefined;
13
+ const index = tag[1].indexOf(":");
14
+ if (index <= 0 || index === tag[1].length - 1)
15
+ return undefined;
16
+ return { platform: tag[1].slice(0, index), identity: tag[1].slice(index + 1), proof: tag[2] };
17
+ }
18
+ /** Creates a NIP-39 "i" tag for an external identity */
19
+ export function createExternalIdentityTag(identity) {
20
+ return ["i", `${identity.platform}:${identity.identity}`, identity.proof];
21
+ }
22
+ /**
23
+ * Returns the external identities from a NIP-39 identities list
24
+ * @see https://github.com/nostr-protocol/nips/blob/master/39.md
25
+ */
26
+ export function getExternalIdentities(event) {
27
+ if (!isValidExternalIdentities(event))
28
+ return [];
29
+ return getOrComputeCachedValue(event, ExternalIdentitiesSymbol, () => processTags(event.tags, getExternalIdentityFromTag));
30
+ }
31
+ /**
32
+ * Returns the URL of the proof for an external identity, or undefined for unknown platforms
33
+ * @see https://github.com/nostr-protocol/nips/blob/master/39.md
34
+ */
35
+ export function getExternalIdentityProofUrl({ platform, identity, proof }) {
36
+ switch (platform) {
37
+ case "github":
38
+ return `https://gist.github.com/${identity}/${proof}`;
39
+ case "twitter":
40
+ return `https://twitter.com/${identity}/status/${proof}`;
41
+ case "mastodon":
42
+ return `https://${identity}/${proof}`;
43
+ case "telegram":
44
+ return `https://t.me/${proof}`;
45
+ case "bluesky":
46
+ return `https://bsky.app/profile/${identity}/post/${proof}`;
47
+ case "discord":
48
+ return `https://discord.com/channels/${proof}`;
49
+ default:
50
+ return undefined;
51
+ }
52
+ }
@@ -1,3 +1,4 @@
1
+ import { getURLPathname } from "applesauce-core/helpers/url";
1
2
  import { getTagValue } from "applesauce-core/helpers/event";
2
3
  import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
3
4
  /** Type guard for a valid kind 1063 file metadata event */
@@ -85,12 +86,10 @@ export function getFileMetadata(file) {
85
86
  }
86
87
  /** Returns the last 64 length hex string in a URL */
87
88
  export function getSha256FromURL(url) {
88
- if (typeof url === "string")
89
- url = new URL(url);
90
- const hashes = Array.from(url.pathname.matchAll(/[0-9a-f]{64}/gi));
91
- if (hashes.length > 0)
92
- return hashes[hashes.length - 1][0];
93
- return;
89
+ let hash;
90
+ for (const match of getURLPathname(url).matchAll(/[0-9a-f]{64}/gi))
91
+ hash = match[0];
92
+ return hash;
94
93
  }
95
94
  /** Creates tags for {@link FileMetadataFields} */
96
95
  export function createFileMetadataTags(attachment) {
@@ -0,0 +1,10 @@
1
+ import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
2
+ /** NIP-7D forum thread kind (11) */
3
+ export declare const FORUM_THREAD_KIND = 11;
4
+ /** Type for a validated NIP-7D forum thread event */
5
+ export type ForumThreadEvent = KnownEvent<typeof FORUM_THREAD_KIND>;
6
+ /** Returns a forum thread's title, if it has one (NIP-7D `title` tag) */
7
+ export declare function getForumThreadTitle(thread: ForumThreadEvent): string;
8
+ export declare function getForumThreadTitle(thread: NostrEvent): string | undefined;
9
+ /** Validates that an event is a NIP-7D forum thread (kind 11) */
10
+ export declare function isValidForumThread(thread: NostrEvent): thread is ForumThreadEvent;
@@ -0,0 +1,10 @@
1
+ import { getTagValue, kinds } from "applesauce-core/helpers/event";
2
+ /** NIP-7D forum thread kind (11) */
3
+ export const FORUM_THREAD_KIND = kinds.ForumThread;
4
+ export function getForumThreadTitle(thread) {
5
+ return getTagValue(thread, "title");
6
+ }
7
+ /** Validates that an event is a NIP-7D forum thread (kind 11) */
8
+ export function isValidForumThread(thread) {
9
+ return thread.kind === FORUM_THREAD_KIND;
10
+ }
@@ -1,20 +1,14 @@
1
1
  import { EventMemory } from "applesauce-core/event-store";
2
2
  import { EncryptedContentSigner } from "applesauce-core/helpers/encrypted-content";
3
- import { kinds, KnownEvent, NostrEvent, UnsignedEvent } from "applesauce-core/helpers/event";
3
+ import { kinds, KnownEvent, NostrEvent, Rumor } from "applesauce-core/helpers/event";
4
+ import { GiftWrapSymbol, RumorSymbol, SealSymbol } from "applesauce-core/helpers/gift-wrap";
4
5
  /**
5
6
  * An internal event set to keep track of seals and rumors
6
7
  * This is intentionally isolated from the main applications event store so to prevent seals and rumors from being leaked
7
8
  */
8
- export declare const internalGiftWrapEvents: EventMemory;
9
- export type Rumor = UnsignedEvent & {
10
- id: string;
11
- };
12
- /** Used to store a reference to the seal event on gift wraps (downstream) or the seal event on rumors (upstream[]) */
13
- export declare const SealSymbol: unique symbol;
14
- /** Used to store a reference to the rumor on seals (downstream) */
15
- export declare const RumorSymbol: unique symbol;
16
- /** Used to store a reference to the parent gift wrap event on seals (upstream) */
17
- export declare const GiftWrapSymbol: unique symbol;
9
+ export declare const internalGiftWrapEvents: EventMemory<NostrEvent>;
10
+ export type { Rumor };
11
+ export { GiftWrapSymbol, RumorSymbol, SealSymbol };
18
12
  /** A gift wrap event that knows its seal event */
19
13
  export type UnlockedGiftWrapEvent = KnownEvent<kinds.GiftWrap> & {
20
14
  /** Downstream seal event */
@@ -29,6 +23,20 @@ export type UnlockedSeal = KnownEvent<kinds.Seal> & {
29
23
  };
30
24
  /** Checks if an event is a rumor (normal event with "id" and no "sig") */
31
25
  export declare function isRumor(event: any): event is Rumor;
26
+ /**
27
+ * Checks that an event is a seal and that its id and signature are valid.
28
+ *
29
+ * The seal's signature is the ONLY authorship proof in a NIP-59 envelope — the gift wrap is
30
+ * signed by a throwaway key that says nothing about who wrote the message, and the rumor is
31
+ * unsigned by definition. Everything downstream that attributes a rumor to an author (notably
32
+ * getSealRumor's `rumor.pubkey !== seal.pubkey` binding) rests on this check having passed.
33
+ *
34
+ * Cheap to repeat: verifyWrappedEvent -> nostr-tools' verifyEvent memoises both outcomes on the
35
+ * event via `verifiedSymbol`, so calls after the first are a symbol read. That is what makes it
36
+ * affordable to re-assert this at every boundary a seal can enter through rather than trusting
37
+ * the caller to have checked.
38
+ */
39
+ export declare function isValidSeal(event: NostrEvent): event is KnownEvent<kinds.Seal>;
32
40
  /** Returns all the parent gift wraps for a seal event */
33
41
  export declare function getSealGiftWrap(seal: UnlockedSeal): UnlockedGiftWrapEvent;
34
42
  export declare function getSealGiftWrap(seal: NostrEvent): UnlockedGiftWrapEvent | undefined;
@@ -36,13 +44,22 @@ export declare function getSealGiftWrap(seal: NostrEvent): UnlockedGiftWrapEvent
36
44
  export declare function getRumorSeals(rumor: Rumor): UnlockedSeal[];
37
45
  /** Returns all the parent gift wraps for a rumor event */
38
46
  export declare function getRumorGiftWraps(rumor: Rumor): UnlockedGiftWrapEvent[];
39
- /** Checks if a seal event is locked and casts it to the {@link UnlockedSeal} type */
47
+ /**
48
+ * Checks if a seal event is locked and casts it to the {@link UnlockedSeal} type
49
+ *
50
+ * The presence test is only sound because getSealRumor never writes an `undefined` RumorSymbol
51
+ * — see the invariant documented there. If it did, this would narrow a seal that never yielded
52
+ * a rumor to UnlockedSeal.
53
+ */
40
54
  export declare function isSealUnlocked(seal: NostrEvent): seal is UnlockedSeal;
41
55
  /** Returns if a gift-wrap event or gift-wrap seal is locked */
42
56
  export declare function isGiftWrapUnlocked(gift: NostrEvent): gift is UnlockedGiftWrapEvent;
43
57
  /**
44
58
  * Gets the rumor from a seal event
45
- * @throws {Error} If the author of the rumor event does not match the author of the seal
59
+ *
60
+ * Returns undefined for any seal that does not yield a usable rumor — an invalid seal signature,
61
+ * unparseable content, an invalid rumor id, or a rumor whose author does not match its seal.
62
+ * These are things a stranger can put in your inbox, so none of them throw.
46
63
  */
47
64
  export declare function getSealRumor(seal: UnlockedSeal): Rumor;
48
65
  export declare function getSealRumor(seal: NostrEvent): Rumor | undefined;
@@ -54,12 +71,20 @@ export declare function getGiftWrapRumor(gift: UnlockedGiftWrapEvent): Rumor;
54
71
  export declare function getGiftWrapRumor(gift: NostrEvent): Rumor | undefined;
55
72
  /**
56
73
  * Unlocks a seal event and returns the rumor event
57
- * @throws {Error} If the author of the rumor event does not match the author of the seal
74
+ *
75
+ * Unlike the getters, this throws rather than returning undefined: it is an imperative operation
76
+ * on one caller-chosen event with a non-optional return type, not a read applied across a
77
+ * timeline, so there is no observable for a throw to tear down.
78
+ * @throws {Error} If the seal does not yield a usable rumor — including an invalid seal
79
+ * signature, unparseable content, or a rumor whose author does not match its seal
58
80
  */
59
81
  export declare function unlockSeal(seal: NostrEvent, signer: EncryptedContentSigner): Promise<Rumor>;
60
82
  /**
61
83
  * Unlocks and returns the unsigned seal event in a gift-wrap
62
- * @throws {Error} If the author of the rumor event does not match the author of the seal
84
+ *
85
+ * Throws for the same reason unlockSeal does — see the note there.
86
+ * @throws {Error} If the gift wrap does not yield a usable rumor — including an invalid seal
87
+ * signature, unparseable content, or a rumor whose author does not match its seal
63
88
  */
64
89
  export declare function unlockGiftWrap(gift: NostrEvent, signer: EncryptedContentSigner): Promise<Rumor>;
65
90
  /** Locks a gift-wrap event and seals its seal event */
@@ -1,23 +1,27 @@
1
+ import { logger } from "applesauce-core";
1
2
  import { EventMemory } from "applesauce-core/event-store";
2
3
  import { safeParse } from "applesauce-core/helpers";
4
+ import { setCachedValue } from "applesauce-core/helpers/cache";
3
5
  import { getEncryptedContent, isEncryptedContentUnlocked, lockEncryptedContent, unlockEncryptedContent, } from "applesauce-core/helpers/encrypted-content";
4
- import { kinds, notifyEventUpdate, verifyWrappedEvent, } from "applesauce-core/helpers/event";
6
+ import { kinds, notifyEventUpdate, verifyRumor, verifyWrappedEvent, } from "applesauce-core/helpers/event";
7
+ // GiftWrapSymbol/SealSymbol/RumorSymbol are owned by applesauce-core (members of
8
+ // PRESERVE_EVENT_SYMBOLS) and re-exported here so existing common consumers keep resolving
9
+ // them; Symbol.for() registry identity is unchanged regardless of which module imports it.
10
+ import { GiftWrapSymbol, RumorSymbol, SealSymbol } from "applesauce-core/helpers/gift-wrap";
5
11
  /**
6
12
  * An internal event set to keep track of seals and rumors
7
13
  * This is intentionally isolated from the main applications event store so to prevent seals and rumors from being leaked
8
14
  */
9
15
  export const internalGiftWrapEvents = new EventMemory();
10
- /** Used to store a reference to the seal event on gift wraps (downstream) or the seal event on rumors (upstream[]) */
11
- export const SealSymbol = Symbol.for("seal");
12
- /** Used to store a reference to the rumor on seals (downstream) */
13
- export const RumorSymbol = Symbol.for("rumor");
14
- /** Used to store a reference to the parent gift wrap event on seals (upstream) */
15
- export const GiftWrapSymbol = Symbol.for("gift-wrap");
16
+ const log = logger.extend("GiftWrap");
17
+ export { GiftWrapSymbol, RumorSymbol, SealSymbol };
16
18
  /** Adds a parent reference to a seal or rumor */
17
19
  function addParentSealReference(rumor, seal) {
18
20
  const parents = Reflect.get(rumor, SealSymbol);
21
+ // Mutated in place across calls (the Set gains members over time), the same shape as
22
+ // applesauce-core's SeenRelaysSymbol — accumulated state (see cache.ts taxonomy), not a memo.
19
23
  if (!parents)
20
- Reflect.set(rumor, SealSymbol, new Set([seal]));
24
+ setCachedValue(rumor, SealSymbol, new Set([seal]));
21
25
  else
22
26
  parents.add(seal);
23
27
  }
@@ -40,6 +44,22 @@ export function isRumor(event) {
40
44
  typeof event.created_at === "number" &&
41
45
  event.created_at > 0);
42
46
  }
47
+ /**
48
+ * Checks that an event is a seal and that its id and signature are valid.
49
+ *
50
+ * The seal's signature is the ONLY authorship proof in a NIP-59 envelope — the gift wrap is
51
+ * signed by a throwaway key that says nothing about who wrote the message, and the rumor is
52
+ * unsigned by definition. Everything downstream that attributes a rumor to an author (notably
53
+ * getSealRumor's `rumor.pubkey !== seal.pubkey` binding) rests on this check having passed.
54
+ *
55
+ * Cheap to repeat: verifyWrappedEvent -> nostr-tools' verifyEvent memoises both outcomes on the
56
+ * event via `verifiedSymbol`, so calls after the first are a symbol read. That is what makes it
57
+ * affordable to re-assert this at every boundary a seal can enter through rather than trusting
58
+ * the caller to have checked.
59
+ */
60
+ export function isValidSeal(event) {
61
+ return event.kind === kinds.Seal && verifyWrappedEvent(event);
62
+ }
43
63
  export function getSealGiftWrap(seal) {
44
64
  return Reflect.get(seal, GiftWrapSymbol);
45
65
  }
@@ -48,7 +68,9 @@ export function getRumorSeals(rumor) {
48
68
  let set = Reflect.get(rumor, SealSymbol);
49
69
  if (!set) {
50
70
  set = new Set();
51
- Reflect.set(rumor, SealSymbol, set);
71
+ // Lazily initializes the same mutable Set addParentSealReference (line ~53) grows over
72
+ // time — accumulated state (see cache.ts taxonomy), not a memo.
73
+ setCachedValue(rumor, SealSymbol, set);
52
74
  }
53
75
  return Array.from(set);
54
76
  }
@@ -63,7 +85,13 @@ export function getRumorGiftWraps(rumor) {
63
85
  }
64
86
  return Array.from(giftWraps);
65
87
  }
66
- /** Checks if a seal event is locked and casts it to the {@link UnlockedSeal} type */
88
+ /**
89
+ * Checks if a seal event is locked and casts it to the {@link UnlockedSeal} type
90
+ *
91
+ * The presence test is only sound because getSealRumor never writes an `undefined` RumorSymbol
92
+ * — see the invariant documented there. If it did, this would narrow a seal that never yielded
93
+ * a rumor to UnlockedSeal.
94
+ */
67
95
  export function isSealUnlocked(seal) {
68
96
  return RumorSymbol in seal || (isEncryptedContentUnlocked(seal) === true && getSealRumor(seal) !== undefined);
69
97
  }
@@ -81,8 +109,13 @@ export function isGiftWrapUnlocked(gift) {
81
109
  return true;
82
110
  }
83
111
  export function getSealRumor(seal) {
84
- // Non seal events cant have rumors
85
- if (seal.kind !== kinds.Seal)
112
+ // Non seal events, and seals whose id/signature do not check out, cant have rumors. Seals
113
+ // reached via getGiftWrapSeal were already verified there, and the verdict is memoised, so
114
+ // this costs a symbol read on that path. It earns its place on the other one: getSealRumor
115
+ // and unlockSeal are exported and take any NostrEvent, so a consumer can hand in a seal that
116
+ // never passed through getGiftWrapSeal. Without this, the `rumor.pubkey !== seal.pubkey`
117
+ // check below would be comparing against an unverified `seal.pubkey` and would prove nothing.
118
+ if (!isValidSeal(seal))
86
119
  return undefined;
87
120
  // If unlocked return the rumor
88
121
  if (RumorSymbol in seal)
@@ -94,26 +127,50 @@ export function getSealRumor(seal) {
94
127
  return undefined;
95
128
  // Parse the content as a rumor event
96
129
  let rumor = safeParse(content);
97
- // Failed to parse rumor, save undefined and return undefined
98
- if (!rumor) {
99
- Reflect.set(seal, RumorSymbol, undefined);
130
+ // Failed to parse rumor — return WITHOUT caching anything.
131
+ //
132
+ // INVARIANT: RumorSymbol is only ever written with a real Rumor, never with `undefined`.
133
+ // Both readers below depend on it, because both test for presence rather than value:
134
+ // - isSealUnlocked's `RumorSymbol in seal` would report a seal that never yielded a rumor
135
+ // as unlocked, and narrow it to UnlockedSeal.
136
+ // - unlockSeal then returns `seal[RumorSymbol]` — `undefined` typed as `Rumor` — walking
137
+ // past its own `if (!rumor) throw` guard and handing the caller a value its signature
138
+ // says cannot exist.
139
+ // A negative memo would also be permanent: the seal could never be re-read even once its
140
+ // content became parseable.
141
+ if (!rumor)
142
+ return undefined;
143
+ // Reject mismatched ids before they can select or populate a cached rumor.
144
+ if (!verifyRumor(rumor)) {
145
+ log("Dropping rumor %s: id does not match its contents", rumor.id);
100
146
  return undefined;
101
147
  }
102
- // Check if the rumor event already exists in the internal event set
148
+ // Check if the rumor event already exists in the internal event set. Resolve the instance
149
+ // first but do NOT record it yet — the author check below has to run against whatever we are
150
+ // actually about to return, and a rejected rumor must not be left behind in the set.
103
151
  const existing = internalGiftWrapEvents.getEvent(rumor.id);
152
+ // Reuse the existing rumor instance
104
153
  if (existing)
105
- // Reuse the existing rumor instance
106
154
  rumor = existing;
107
- else
108
- // Add to the internal event set
155
+ // A rumor whose author does not match its seal proves nothing about authorship, so it is
156
+ // dropped. Returning undefined rather than throwing: this is sender-controlled input that any
157
+ // stranger can put in your inbox, and every caller reaches it from inside an RxJS pipe —
158
+ // WrappedMessagesModel maps getGiftWrapRumor over the WHOLE gift-wrap timeline. A throw there
159
+ // errors the observable, which is terminal, so one malformed wrap would permanently kill the
160
+ // user's entire message list rather than skipping one message. Those call sites already
161
+ // `.filter((e) => !!e)`, so undefined is the contract they were written for.
162
+ if (rumor.pubkey !== seal.pubkey) {
163
+ log("Dropping rumor %s: author does not match its seal %s", rumor.id, seal.id);
164
+ return undefined;
165
+ }
166
+ // Add to the internal event set, now that the rumor has been accepted
167
+ if (!existing)
109
168
  internalGiftWrapEvents.add(rumor);
110
- // Throw an error if the seal and rumor authors do not match
111
- if (rumor.pubkey !== seal.pubkey)
112
- throw new Error("Seal author does not match rumor author");
113
169
  // Save a reference to the parent seal event
114
170
  addParentSealReference(rumor, seal);
115
- // Cache the rumor event
116
- Reflect.set(seal, RumorSymbol, rumor);
171
+ // Cache the rumor event. Propagated by reference across duplicate seal events rather than
172
+ // by spread — accumulated state (see cache.ts taxonomy).
173
+ setCachedValue(seal, RumorSymbol, rumor);
117
174
  return rumor;
118
175
  }
119
176
  export function getGiftWrapSeal(gift) {
@@ -126,7 +183,19 @@ export function getGiftWrapSeal(gift) {
126
183
  if (!content)
127
184
  return undefined;
128
185
  // Parse seal as nostr event
129
- let seal = JSON.parse(content);
186
+ const parsed = safeParse(content);
187
+ if (!parsed)
188
+ return undefined;
189
+ // Verify BEFORE the seal is used for anything else, including as a lookup key. verifyEvent
190
+ // rejects unless the event hashes to its own `id`, so passing this is what makes `parsed.id`
191
+ // trustworthy. Checking after the lookup below would let a sender write any id they like into
192
+ // the seal JSON and be handed back a seal they never signed — no signature checked, and the
193
+ // wrap then caches a reference to it. This is the sole insertion point for seals into
194
+ // internalGiftWrapEvents (EventMemory.add does no verification of its own), so gating here is
195
+ // what makes that set a set of authenticated seals.
196
+ if (!isValidSeal(parsed))
197
+ return undefined;
198
+ let seal = parsed;
130
199
  // Check if the seal event already exists in the internal event set
131
200
  const existing = internalGiftWrapEvents.getEvent(seal.id);
132
201
  if (existing) {
@@ -134,15 +203,15 @@ export function getGiftWrapSeal(gift) {
134
203
  seal = existing;
135
204
  }
136
205
  else {
137
- // Verify the seal event
138
- verifyWrappedEvent(seal);
139
206
  // Add to the internal event set
140
207
  internalGiftWrapEvents.add(seal);
141
- // Set the reference to the parent gift wrap event (upstream)
142
- Reflect.set(seal, GiftWrapSymbol, gift);
208
+ // Set the reference to the parent gift wrap event (upstream). Propagated by reference
209
+ // across duplicate events, not by spread — accumulated state (see cache.ts taxonomy).
210
+ setCachedValue(seal, GiftWrapSymbol, gift);
143
211
  }
144
- // Save a reference to the seal on the gift wrap (downstream)
145
- Reflect.set(gift, SealSymbol, seal);
212
+ // Save a reference to the seal on the gift wrap (downstream). Propagated by reference
213
+ // across duplicate events, not by spread — accumulated state (see cache.ts taxonomy).
214
+ setCachedValue(gift, SealSymbol, seal);
146
215
  return seal;
147
216
  }
148
217
  export function getGiftWrapRumor(gift) {
@@ -153,7 +222,12 @@ export function getGiftWrapRumor(gift) {
153
222
  }
154
223
  /**
155
224
  * Unlocks a seal event and returns the rumor event
156
- * @throws {Error} If the author of the rumor event does not match the author of the seal
225
+ *
226
+ * Unlike the getters, this throws rather than returning undefined: it is an imperative operation
227
+ * on one caller-chosen event with a non-optional return type, not a read applied across a
228
+ * timeline, so there is no observable for a throw to tear down.
229
+ * @throws {Error} If the seal does not yield a usable rumor — including an invalid seal
230
+ * signature, unparseable content, or a rumor whose author does not match its seal
157
231
  */
158
232
  export async function unlockSeal(seal, signer) {
159
233
  // If already unlocked, return the rumor
@@ -170,7 +244,10 @@ export async function unlockSeal(seal, signer) {
170
244
  }
171
245
  /**
172
246
  * Unlocks and returns the unsigned seal event in a gift-wrap
173
- * @throws {Error} If the author of the rumor event does not match the author of the seal
247
+ *
248
+ * Throws for the same reason unlockSeal does — see the note there.
249
+ * @throws {Error} If the gift wrap does not yield a usable rumor — including an invalid seal
250
+ * signature, unparseable content, or a rumor whose author does not match its seal
174
251
  */
175
252
  export async function unlockGiftWrap(gift, signer) {
176
253
  // If already unlocked, return the rumor
@@ -0,0 +1,13 @@
1
+ import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
2
+ /** The NIP-34 issue event kind */
3
+ export declare const GIT_ISSUE_KIND = 1621;
4
+ /** A validated NIP-34 issue event */
5
+ export type GitIssueEvent = KnownEvent<typeof GIT_ISSUE_KIND>;
6
+ /** The cache key for issue labels */
7
+ export declare const GitIssueLabelsSymbol: unique symbol;
8
+ /** Checks if an event is a valid NIP-34 issue that references a repository */
9
+ export declare function isValidGitIssue(event?: NostrEvent): event is GitIssueEvent;
10
+ /** Returns the issue subject from the `subject` tag */
11
+ export declare function getGitIssueSubject(event: NostrEvent): string | undefined;
12
+ /** Returns the issue labels from the `t` tags */
13
+ export declare function getGitIssueLabels(event: NostrEvent): string[];
@@ -0,0 +1,19 @@
1
+ import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
2
+ import { getTagValue } from "applesauce-core/helpers/event";
3
+ import { getGitRepositoryReference } from "./git-repository.js";
4
+ /** The NIP-34 issue event kind */
5
+ export const GIT_ISSUE_KIND = 1621;
6
+ /** The cache key for issue labels */
7
+ export const GitIssueLabelsSymbol = Symbol.for("git-issue-labels");
8
+ /** Checks if an event is a valid NIP-34 issue that references a repository */
9
+ export function isValidGitIssue(event) {
10
+ return !!event && event.kind === GIT_ISSUE_KIND && !!getGitRepositoryReference(event);
11
+ }
12
+ /** Returns the issue subject from the `subject` tag */
13
+ export function getGitIssueSubject(event) {
14
+ return getTagValue(event, "subject") || undefined;
15
+ }
16
+ /** Returns the issue labels from the `t` tags */
17
+ export function getGitIssueLabels(event) {
18
+ return getOrComputeCachedValue(event, GitIssueLabelsSymbol, () => event.tags.filter((t) => t[0] === "t" && t[1]).map((t) => t[1]));
19
+ }