applesauce-common 0.0.0-next-20251203172109

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 (225) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +59 -0
  3. package/dist/blueprints/app-data.d.ts +5 -0
  4. package/dist/blueprints/app-data.js +10 -0
  5. package/dist/blueprints/calendar.d.ts +5 -0
  6. package/dist/blueprints/calendar.js +7 -0
  7. package/dist/blueprints/channels.d.ts +6 -0
  8. package/dist/blueprints/channels.js +13 -0
  9. package/dist/blueprints/comment.d.ts +12 -0
  10. package/dist/blueprints/comment.js +15 -0
  11. package/dist/blueprints/delete.d.ts +9 -0
  12. package/dist/blueprints/delete.js +14 -0
  13. package/dist/blueprints/file-metadata.d.ts +8 -0
  14. package/dist/blueprints/file-metadata.js +11 -0
  15. package/dist/blueprints/follow-set.d.ts +11 -0
  16. package/dist/blueprints/follow-set.js +21 -0
  17. package/dist/blueprints/gift-wrap.d.ts +5 -0
  18. package/dist/blueprints/gift-wrap.js +6 -0
  19. package/dist/blueprints/group.d.ts +9 -0
  20. package/dist/blueprints/group.js +17 -0
  21. package/dist/blueprints/highlight.d.ts +20 -0
  22. package/dist/blueprints/highlight.js +12 -0
  23. package/dist/blueprints/index.d.ts +23 -0
  24. package/dist/blueprints/index.js +24 -0
  25. package/dist/blueprints/legacy-message.d.ts +7 -0
  26. package/dist/blueprints/legacy-message.js +29 -0
  27. package/dist/blueprints/live-stream.d.ts +6 -0
  28. package/dist/blueprints/live-stream.js +9 -0
  29. package/dist/blueprints/note.d.ts +16 -0
  30. package/dist/blueprints/note.js +30 -0
  31. package/dist/blueprints/picture-post.d.ts +12 -0
  32. package/dist/blueprints/picture-post.js +17 -0
  33. package/dist/blueprints/poll.d.ts +41 -0
  34. package/dist/blueprints/poll.js +33 -0
  35. package/dist/blueprints/profile.d.ts +3 -0
  36. package/dist/blueprints/profile.js +7 -0
  37. package/dist/blueprints/reaction.d.ts +10 -0
  38. package/dist/blueprints/reaction.js +14 -0
  39. package/dist/blueprints/share.d.ts +12 -0
  40. package/dist/blueprints/share.js +25 -0
  41. package/dist/blueprints/stream.d.ts +6 -0
  42. package/dist/blueprints/stream.js +7 -0
  43. package/dist/blueprints/torrent.d.ts +23 -0
  44. package/dist/blueprints/torrent.js +25 -0
  45. package/dist/blueprints/wrapped-message.d.ts +20 -0
  46. package/dist/blueprints/wrapped-message.js +64 -0
  47. package/dist/helpers/app-data.d.ts +39 -0
  48. package/dist/helpers/app-data.js +68 -0
  49. package/dist/helpers/app-handler.d.ts +22 -0
  50. package/dist/helpers/app-handler.js +67 -0
  51. package/dist/helpers/article.d.ts +14 -0
  52. package/dist/helpers/article.js +24 -0
  53. package/dist/helpers/blossom.d.ts +11 -0
  54. package/dist/helpers/blossom.js +40 -0
  55. package/dist/helpers/bolt11.d.ts +10 -0
  56. package/dist/helpers/bolt11.js +17 -0
  57. package/dist/helpers/bookmark.d.ts +30 -0
  58. package/dist/helpers/bookmark.js +96 -0
  59. package/dist/helpers/calendar-event.d.ts +39 -0
  60. package/dist/helpers/calendar-event.js +121 -0
  61. package/dist/helpers/calendar-rsvp.d.ts +15 -0
  62. package/dist/helpers/calendar-rsvp.js +38 -0
  63. package/dist/helpers/calendar.d.ts +6 -0
  64. package/dist/helpers/calendar.js +11 -0
  65. package/dist/helpers/channels.d.ts +13 -0
  66. package/dist/helpers/channels.js +27 -0
  67. package/dist/helpers/comment.d.ts +47 -0
  68. package/dist/helpers/comment.js +185 -0
  69. package/dist/helpers/content.d.ts +3 -0
  70. package/dist/helpers/content.js +8 -0
  71. package/dist/helpers/emoji.d.ts +21 -0
  72. package/dist/helpers/emoji.js +34 -0
  73. package/dist/helpers/encrypted-content-cache.d.ts +22 -0
  74. package/dist/helpers/encrypted-content-cache.js +138 -0
  75. package/dist/helpers/file-metadata.d.ts +55 -0
  76. package/dist/helpers/file-metadata.js +130 -0
  77. package/dist/helpers/gift-wrap.d.ts +66 -0
  78. package/dist/helpers/gift-wrap.js +204 -0
  79. package/dist/helpers/groups-helper.d.ts +6 -0
  80. package/dist/helpers/groups-helper.js +9 -0
  81. package/dist/helpers/groups.d.ts +26 -0
  82. package/dist/helpers/groups.js +49 -0
  83. package/dist/helpers/hashtag.d.ts +2 -0
  84. package/dist/helpers/hashtag.js +7 -0
  85. package/dist/helpers/highlight.d.ts +45 -0
  86. package/dist/helpers/highlight.js +76 -0
  87. package/dist/helpers/index.d.ts +37 -0
  88. package/dist/helpers/index.js +37 -0
  89. package/dist/helpers/legacy-messages.d.ts +31 -0
  90. package/dist/helpers/legacy-messages.js +49 -0
  91. package/dist/helpers/lists.d.ts +58 -0
  92. package/dist/helpers/lists.js +110 -0
  93. package/dist/helpers/lnurl.d.ts +8 -0
  94. package/dist/helpers/lnurl.js +44 -0
  95. package/dist/helpers/mailboxes.d.ts +7 -0
  96. package/dist/helpers/mailboxes.js +49 -0
  97. package/dist/helpers/messages.d.ts +31 -0
  98. package/dist/helpers/messages.js +57 -0
  99. package/dist/helpers/mute.d.ts +33 -0
  100. package/dist/helpers/mute.js +111 -0
  101. package/dist/helpers/picture-post.d.ts +5 -0
  102. package/dist/helpers/picture-post.js +6 -0
  103. package/dist/helpers/poll.d.ts +46 -0
  104. package/dist/helpers/poll.js +78 -0
  105. package/dist/helpers/reaction.d.ts +8 -0
  106. package/dist/helpers/reaction.js +56 -0
  107. package/dist/helpers/relay-discovery.d.ts +87 -0
  108. package/dist/helpers/relay-discovery.js +126 -0
  109. package/dist/helpers/reports.d.ts +28 -0
  110. package/dist/helpers/reports.js +38 -0
  111. package/dist/helpers/share.d.ts +19 -0
  112. package/dist/helpers/share.js +58 -0
  113. package/dist/helpers/stream-chat.d.ts +4 -0
  114. package/dist/helpers/stream-chat.js +9 -0
  115. package/dist/helpers/stream.d.ts +31 -0
  116. package/dist/helpers/stream.js +81 -0
  117. package/dist/helpers/threading.d.ts +55 -0
  118. package/dist/helpers/threading.js +94 -0
  119. package/dist/helpers/torrent.d.ts +55 -0
  120. package/dist/helpers/torrent.js +270 -0
  121. package/dist/helpers/user-status.d.ts +18 -0
  122. package/dist/helpers/user-status.js +22 -0
  123. package/dist/helpers/wrapped-messages.d.ts +14 -0
  124. package/dist/helpers/wrapped-messages.js +23 -0
  125. package/dist/helpers/zap.d.ts +46 -0
  126. package/dist/helpers/zap.js +125 -0
  127. package/dist/index.d.ts +5 -0
  128. package/dist/index.js +6 -0
  129. package/dist/models/blossom.d.ts +11 -0
  130. package/dist/models/blossom.js +18 -0
  131. package/dist/models/bookmarks.d.ts +8 -0
  132. package/dist/models/bookmarks.js +24 -0
  133. package/dist/models/calendar.d.ts +6 -0
  134. package/dist/models/calendar.js +15 -0
  135. package/dist/models/channels.d.ts +11 -0
  136. package/dist/models/channels.js +61 -0
  137. package/dist/models/comments.d.ts +11 -0
  138. package/dist/models/comments.js +17 -0
  139. package/dist/models/gift-wrap.d.ts +7 -0
  140. package/dist/models/gift-wrap.js +20 -0
  141. package/dist/models/index.d.ts +15 -0
  142. package/dist/models/index.js +16 -0
  143. package/dist/models/legacy-messages.d.ts +14 -0
  144. package/dist/models/legacy-messages.js +64 -0
  145. package/dist/models/mutes.d.ts +16 -0
  146. package/dist/models/mutes.js +34 -0
  147. package/dist/models/pins.d.ts +4 -0
  148. package/dist/models/pins.js +10 -0
  149. package/dist/models/reactions.d.ts +11 -0
  150. package/dist/models/reactions.js +21 -0
  151. package/dist/models/thread.d.ts +33 -0
  152. package/dist/models/thread.js +93 -0
  153. package/dist/models/user-status.d.ts +11 -0
  154. package/dist/models/user-status.js +32 -0
  155. package/dist/models/wrapped-messages.d.ts +31 -0
  156. package/dist/models/wrapped-messages.js +76 -0
  157. package/dist/models/zaps.d.ts +9 -0
  158. package/dist/models/zaps.js +26 -0
  159. package/dist/operations/app-data.d.ts +6 -0
  160. package/dist/operations/app-data.js +21 -0
  161. package/dist/operations/blossom.d.ts +5 -0
  162. package/dist/operations/blossom.js +13 -0
  163. package/dist/operations/calendar-event.d.ts +34 -0
  164. package/dist/operations/calendar-event.js +72 -0
  165. package/dist/operations/calendar-rsvp.d.ts +10 -0
  166. package/dist/operations/calendar-rsvp.js +35 -0
  167. package/dist/operations/calendar.d.ts +9 -0
  168. package/dist/operations/calendar.js +15 -0
  169. package/dist/operations/channel.d.ts +4 -0
  170. package/dist/operations/channel.js +10 -0
  171. package/dist/operations/client.d.ts +4 -0
  172. package/dist/operations/client.js +23 -0
  173. package/dist/operations/comment.d.ts +4 -0
  174. package/dist/operations/comment.js +11 -0
  175. package/dist/operations/file-metadata.d.ts +4 -0
  176. package/dist/operations/file-metadata.js +21 -0
  177. package/dist/operations/geohash.d.ts +5 -0
  178. package/dist/operations/geohash.js +17 -0
  179. package/dist/operations/gift-wrap.d.ts +13 -0
  180. package/dist/operations/gift-wrap.js +93 -0
  181. package/dist/operations/group.d.ts +11 -0
  182. package/dist/operations/group.js +34 -0
  183. package/dist/operations/hashtags.d.ts +7 -0
  184. package/dist/operations/hashtags.js +17 -0
  185. package/dist/operations/highlight.d.ts +18 -0
  186. package/dist/operations/highlight.js +47 -0
  187. package/dist/operations/index.d.ts +28 -0
  188. package/dist/operations/index.js +28 -0
  189. package/dist/operations/legacy-message.d.ts +6 -0
  190. package/dist/operations/legacy-message.js +13 -0
  191. package/dist/operations/list.d.ts +7 -0
  192. package/dist/operations/list.js +14 -0
  193. package/dist/operations/live-stream.d.ts +4 -0
  194. package/dist/operations/live-stream.js +11 -0
  195. package/dist/operations/media-attachment.d.ts +4 -0
  196. package/dist/operations/media-attachment.js +12 -0
  197. package/dist/operations/note.d.ts +9 -0
  198. package/dist/operations/note.js +42 -0
  199. package/dist/operations/picture-post.d.ts +4 -0
  200. package/dist/operations/picture-post.js +14 -0
  201. package/dist/operations/poll-response.d.ts +9 -0
  202. package/dist/operations/poll-response.js +20 -0
  203. package/dist/operations/poll.d.ts +19 -0
  204. package/dist/operations/poll.js +42 -0
  205. package/dist/operations/reaction.d.ts +7 -0
  206. package/dist/operations/reaction.js +39 -0
  207. package/dist/operations/share.d.ts +8 -0
  208. package/dist/operations/share.js +34 -0
  209. package/dist/operations/stream-chat.d.ts +7 -0
  210. package/dist/operations/stream-chat.js +27 -0
  211. package/dist/operations/stream.d.ts +41 -0
  212. package/dist/operations/stream.js +83 -0
  213. package/dist/operations/tag/bookmarks.d.ts +6 -0
  214. package/dist/operations/tag/bookmarks.js +20 -0
  215. package/dist/operations/tag/index.d.ts +1 -0
  216. package/dist/operations/tag/index.js +1 -0
  217. package/dist/operations/torrent.d.ts +33 -0
  218. package/dist/operations/torrent.js +66 -0
  219. package/dist/operations/wrapped-message.d.ts +12 -0
  220. package/dist/operations/wrapped-message.js +28 -0
  221. package/dist/operations/zap-split.d.ts +10 -0
  222. package/dist/operations/zap-split.js +20 -0
  223. package/dist/register.d.ts +11 -0
  224. package/dist/register.js +13 -0
  225. package/package.json +91 -0
@@ -0,0 +1,26 @@
1
+ import { NostrEvent } from "applesauce-core/helpers/event";
2
+ export declare const GROUPS_LIST_KIND = 10009;
3
+ export declare const GROUP_MESSAGE_KIND = 9;
4
+ /** NIP-29 group pointer */
5
+ export type GroupPointer = {
6
+ /** the id of the group */
7
+ id: string;
8
+ /** The url to the relay with wss:// or ws:// protocol */
9
+ relay: string;
10
+ /** The name of the group */
11
+ name?: string;
12
+ };
13
+ /** decodes a group identifier into a group pointer object */
14
+ export declare function decodeGroupPointer(str: string): GroupPointer | null;
15
+ /** Converts a group pointer into a group identifier */
16
+ export declare function encodeGroupPointer(pointer: GroupPointer): string;
17
+ export declare const GroupsPublicSymbol: unique symbol;
18
+ export declare const GroupsHiddenSymbol: unique symbol;
19
+ /** gets a {@link GroupPointer} from a "h" tag if it has a relay hint */
20
+ export declare function getGroupPointerFromHTag(tag: string[]): GroupPointer | undefined;
21
+ /** gets a {@link GroupPointer} from a "group" tag */
22
+ export declare function getGroupPointerFromGroupTag(tag: string[]): GroupPointer;
23
+ /** Returns all the public groups from a k:10009 list */
24
+ export declare function getPublicGroups(bookmark: NostrEvent): GroupPointer[];
25
+ /** Returns all the hidden groups from a k:10009 list */
26
+ export declare function getHiddenGroups(bookmark: NostrEvent): GroupPointer[] | undefined;
@@ -0,0 +1,49 @@
1
+ import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
2
+ import { getHiddenTags } from "applesauce-core/helpers/hidden-tags";
3
+ import { processTags } from "applesauce-core/helpers/tags";
4
+ import { normalizeURL } from "applesauce-core/helpers/url";
5
+ export const GROUPS_LIST_KIND = 10009;
6
+ export const GROUP_MESSAGE_KIND = 9;
7
+ /** decodes a group identifier into a group pointer object */
8
+ export function decodeGroupPointer(str) {
9
+ let [relay, id] = str.split("'");
10
+ if (!relay)
11
+ return null;
12
+ // Prepend wss:// if missing
13
+ if (!relay.match(/^wss?:/))
14
+ relay = `wss://${relay}`;
15
+ // Normalize the relay url
16
+ relay = normalizeURL(relay);
17
+ return { relay, id: id || "_" };
18
+ }
19
+ /** Converts a group pointer into a group identifier */
20
+ export function encodeGroupPointer(pointer) {
21
+ const hostname = URL.canParse(pointer.relay) ? new URL(pointer.relay).hostname : pointer.relay;
22
+ return `${hostname}'${pointer.id}`;
23
+ }
24
+ export const GroupsPublicSymbol = Symbol.for("groups-public");
25
+ export const GroupsHiddenSymbol = Symbol.for("groups-hidden");
26
+ /** gets a {@link GroupPointer} from a "h" tag if it has a relay hint */
27
+ export function getGroupPointerFromHTag(tag) {
28
+ const [_, id, relay] = tag;
29
+ if (!id || !relay)
30
+ return undefined;
31
+ return { id, relay };
32
+ }
33
+ /** gets a {@link GroupPointer} from a "group" tag */
34
+ export function getGroupPointerFromGroupTag(tag) {
35
+ const [_, id, relay, name] = tag;
36
+ return { id, relay, name };
37
+ }
38
+ /** Returns all the public groups from a k:10009 list */
39
+ export function getPublicGroups(bookmark) {
40
+ return getOrComputeCachedValue(bookmark, GroupsPublicSymbol, () => processTags(bookmark.tags.filter((t) => t[0] === "group"), getGroupPointerFromGroupTag));
41
+ }
42
+ /** Returns all the hidden groups from a k:10009 list */
43
+ export function getHiddenGroups(bookmark) {
44
+ return getOrComputeCachedValue(bookmark, GroupsHiddenSymbol, () => {
45
+ const tags = getHiddenTags(bookmark);
46
+ return (tags &&
47
+ processTags(bookmark.tags.filter((t) => t[0] === "group"), getGroupPointerFromGroupTag));
48
+ });
49
+ }
@@ -0,0 +1,2 @@
1
+ import { EventTemplate, NostrEvent } from "applesauce-core/helpers/event";
2
+ export declare function getHashtagTag(event: NostrEvent | EventTemplate, hashtag: string): ["t", string];
@@ -0,0 +1,7 @@
1
+ import { stripInvisibleChar } from "applesauce-core/helpers/string";
2
+ export function getHashtagTag(event, hashtag) {
3
+ hashtag = stripInvisibleChar(hashtag.replace(/^#/, "").toLocaleLowerCase());
4
+ return event.tags
5
+ .filter((t) => t[0] === "t" && t[1])
6
+ .find((t) => stripInvisibleChar(t[1].toLowerCase()) === hashtag);
7
+ }
@@ -0,0 +1,45 @@
1
+ import { NostrEvent } from "applesauce-core/helpers/event";
2
+ import { AddressPointer, EventPointer, ProfilePointer } from "applesauce-core/helpers/pointers";
3
+ export declare const HighlightSourceEventPointerSymbol: unique symbol;
4
+ export declare const HighlightSourceAddressPointerSymbol: unique symbol;
5
+ export declare const HighlightAttributionSymbol: unique symbol;
6
+ /**
7
+ * Get the highlighted content from a highlight event
8
+ * Returns the content field which contains the highlighted text
9
+ */
10
+ export declare function getHighlightText(event: NostrEvent): string;
11
+ /**
12
+ * Get the source event pointer that was highlighted (from 'e' tag)
13
+ * Returns undefined if no event reference is found
14
+ */
15
+ export declare function getHighlightSourceEventPointer(event: NostrEvent): EventPointer | undefined;
16
+ /**
17
+ * Get the source address pointer that was highlighted (from 'a' tag)
18
+ * Returns undefined if no address reference is found
19
+ */
20
+ export declare function getHighlightSourceAddressPointer(event: NostrEvent): AddressPointer | undefined;
21
+ /** Get the source URL that was highlighted (from 'r' tag) */
22
+ export declare function getHighlightSourceUrl(event: NostrEvent): string | undefined;
23
+ /** Role of an attributed profiles in a highlight */
24
+ export type HighlightAttributionRole = "author" | "editor" | "mention" | string;
25
+ /** Attribution information for a highlight */
26
+ export type HighlightAttribution = ProfilePointer & {
27
+ /** Role of the attributed profile */
28
+ role?: HighlightAttributionRole;
29
+ };
30
+ /**
31
+ * Get attribution information from p tags
32
+ * Parses p tags to extract authors, editors, and other attributed individuals
33
+ */
34
+ export declare function getHighlightAttributions(event: NostrEvent): HighlightAttribution[];
35
+ /**
36
+ * Get the context text for a highlight (from 'context' tag)
37
+ * This provides surrounding content to give context to the highlight
38
+ */
39
+ export declare function getHighlightContext(event: NostrEvent): string | undefined;
40
+ /** Get the comment for a highlight (from 'comment' tag) */
41
+ export declare function getHighlightComment(event: NostrEvent): string | undefined;
42
+ /**
43
+ * Check if the highlight has any source reference (event, address, or URL)
44
+ */
45
+ export declare function hasHighlightSource(event: NostrEvent): boolean;
@@ -0,0 +1,76 @@
1
+ import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
2
+ import { getTagValue } from "applesauce-core/helpers/event";
3
+ import { getAddressPointerFromATag, getEventPointerFromETag, getProfilePointerFromPTag, } from "applesauce-core/helpers/pointers";
4
+ import { isATag, isETag, isPTag } from "applesauce-core/helpers/tags";
5
+ // Symbol constants for caching
6
+ export const HighlightSourceEventPointerSymbol = Symbol.for("highlight-source-event-pointer");
7
+ export const HighlightSourceAddressPointerSymbol = Symbol.for("highlight-source-address-pointer");
8
+ export const HighlightAttributionSymbol = Symbol.for("highlight-attribution");
9
+ /**
10
+ * Get the highlighted content from a highlight event
11
+ * Returns the content field which contains the highlighted text
12
+ */
13
+ export function getHighlightText(event) {
14
+ return event.content;
15
+ }
16
+ /**
17
+ * Get the source event pointer that was highlighted (from 'e' tag)
18
+ * Returns undefined if no event reference is found
19
+ */
20
+ export function getHighlightSourceEventPointer(event) {
21
+ return getOrComputeCachedValue(event, HighlightSourceEventPointerSymbol, () => {
22
+ const eTag = event.tags.find(isETag);
23
+ return eTag ? getEventPointerFromETag(eTag) : undefined;
24
+ });
25
+ }
26
+ /**
27
+ * Get the source address pointer that was highlighted (from 'a' tag)
28
+ * Returns undefined if no address reference is found
29
+ */
30
+ export function getHighlightSourceAddressPointer(event) {
31
+ return getOrComputeCachedValue(event, HighlightSourceAddressPointerSymbol, () => {
32
+ const aTag = event.tags.find(isATag);
33
+ return aTag ? getAddressPointerFromATag(aTag) : undefined;
34
+ });
35
+ }
36
+ /** Get the source URL that was highlighted (from 'r' tag) */
37
+ export function getHighlightSourceUrl(event) {
38
+ return getTagValue(event, "r");
39
+ }
40
+ /**
41
+ * Get attribution information from p tags
42
+ * Parses p tags to extract authors, editors, and other attributed individuals
43
+ */
44
+ export function getHighlightAttributions(event) {
45
+ return getOrComputeCachedValue(event, HighlightAttributionSymbol, () => {
46
+ const attributions = [];
47
+ const pTags = event.tags.filter(isPTag);
48
+ for (const pTag of pTags) {
49
+ const pointer = getProfilePointerFromPTag(pTag);
50
+ const role = pTag[3] || "other"; // Role is the 4th element (index 3)
51
+ const entry = { ...pointer, role };
52
+ // Categorize by role
53
+ attributions.push(entry);
54
+ }
55
+ return attributions;
56
+ });
57
+ }
58
+ /**
59
+ * Get the context text for a highlight (from 'context' tag)
60
+ * This provides surrounding content to give context to the highlight
61
+ */
62
+ export function getHighlightContext(event) {
63
+ return getTagValue(event, "context");
64
+ }
65
+ /** Get the comment for a highlight (from 'comment' tag) */
66
+ export function getHighlightComment(event) {
67
+ return getTagValue(event, "comment");
68
+ }
69
+ /**
70
+ * Check if the highlight has any source reference (event, address, or URL)
71
+ */
72
+ export function hasHighlightSource(event) {
73
+ return !!(getHighlightSourceEventPointer(event) ||
74
+ getHighlightSourceAddressPointer(event) ||
75
+ getHighlightSourceUrl(event));
76
+ }
@@ -0,0 +1,37 @@
1
+ export * from "./app-handler.js";
2
+ export * from "./article.js";
3
+ export * from "./blossom.js";
4
+ export * from "./bolt11.js";
5
+ export * from "./bookmark.js";
6
+ export * from "./calendar-event.js";
7
+ export * from "./calendar-rsvp.js";
8
+ export * from "./calendar.js";
9
+ export * from "./channels.js";
10
+ export * from "./comment.js";
11
+ export * from "./content.js";
12
+ export * from "./emoji.js";
13
+ export * from "./encrypted-content-cache.js";
14
+ export * from "./file-metadata.js";
15
+ export * from "./gift-wrap.js";
16
+ export * from "./groups.js";
17
+ export * from "./hashtag.js";
18
+ export * from "./highlight.js";
19
+ export * from "./legacy-messages.js";
20
+ export * from "./lists.js";
21
+ export * from "./lnurl.js";
22
+ export * from "./mailboxes.js";
23
+ export * from "./messages.js";
24
+ export * from "./mute.js";
25
+ export * from "./picture-post.js";
26
+ export * from "./poll.js";
27
+ export * from "./reaction.js";
28
+ export * from "./relay-discovery.js";
29
+ export * from "./reports.js";
30
+ export * from "./share.js";
31
+ export * from "./stream-chat.js";
32
+ export * from "./stream.js";
33
+ export * from "./threading.js";
34
+ export * from "./torrent.js";
35
+ export * from "./user-status.js";
36
+ export * from "./wrapped-messages.js";
37
+ export * from "./zap.js";
@@ -0,0 +1,37 @@
1
+ export * from "./app-handler.js";
2
+ export * from "./article.js";
3
+ export * from "./blossom.js";
4
+ export * from "./bolt11.js";
5
+ export * from "./bookmark.js";
6
+ export * from "./calendar-event.js";
7
+ export * from "./calendar-rsvp.js";
8
+ export * from "./calendar.js";
9
+ export * from "./channels.js";
10
+ export * from "./comment.js";
11
+ export * from "./content.js";
12
+ export * from "./emoji.js";
13
+ export * from "./encrypted-content-cache.js";
14
+ export * from "./file-metadata.js";
15
+ export * from "./gift-wrap.js";
16
+ export * from "./groups.js";
17
+ export * from "./hashtag.js";
18
+ export * from "./highlight.js";
19
+ export * from "./legacy-messages.js";
20
+ export * from "./lists.js";
21
+ export * from "./lnurl.js";
22
+ export * from "./mailboxes.js";
23
+ export * from "./messages.js";
24
+ export * from "./mute.js";
25
+ export * from "./picture-post.js";
26
+ export * from "./poll.js";
27
+ export * from "./reaction.js";
28
+ export * from "./relay-discovery.js";
29
+ export * from "./reports.js";
30
+ export * from "./share.js";
31
+ export * from "./stream-chat.js";
32
+ export * from "./stream.js";
33
+ export * from "./threading.js";
34
+ export * from "./torrent.js";
35
+ export * from "./user-status.js";
36
+ export * from "./wrapped-messages.js";
37
+ export * from "./zap.js";
@@ -0,0 +1,31 @@
1
+ import { EncryptedContentSigner, UnlockedEncryptedContent } from "applesauce-core/helpers/encrypted-content";
2
+ import { kinds, KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
3
+ /** Type for valid legacy direct messages */
4
+ export type LegacyMessage = KnownEvent<kinds.EncryptedDirectMessage>;
5
+ /** Type for a legacy direct message with unlocked encrypted content */
6
+ export type UnlockedLegacyMessage = LegacyMessage & UnlockedEncryptedContent;
7
+ /** Checks if a legacy direct message content is encrypted */
8
+ export declare function isLegacyMessageUnlocked<T extends NostrEvent>(event: T): event is T & UnlockedEncryptedContent;
9
+ /** Returns the correspondent of a legacy direct message */
10
+ export declare function getLegacyMessageCorrespondent<T extends LegacyMessage>(message: T, self: string): string;
11
+ export declare function getLegacyMessageCorrespondent<T extends NostrEvent>(message: T, self: string): string | undefined;
12
+ /** Returns the receiver of a legacy direct me */
13
+ export declare const getLegacyMessageReceiver: typeof getLegacyMessageCorrespondent;
14
+ /** @deprecated use {@link getLegacyMessageCorrespondent} instead */
15
+ export declare const getLegacyMessageCorraspondant: typeof getLegacyMessageCorrespondent;
16
+ /** Returns the sender of a legacy direct message */
17
+ export declare function getLegacyMessageSender(message: NostrEvent): string;
18
+ /** Returns the parent message id of a legacy message */
19
+ export declare function getLegacyMessageParent(message: NostrEvent): string | undefined;
20
+ /** Checks if a legacy message is valid */
21
+ export declare function isValidLegacyMessage(event: any): event is LegacyMessage;
22
+ /**
23
+ * Returns the decrypted content of a direct message
24
+ * @param message - The message to decrypt
25
+ * @param self - The public key of the user
26
+ * @param signer - The signer to use to decrypt the message
27
+ * @returns The decrypted content of the message
28
+ */
29
+ export declare function unlockLegacyMessage(message: NostrEvent, self: string, signer: EncryptedContentSigner): Promise<string>;
30
+ /** Clears the cached plaintext of a direct message */
31
+ export declare function lockLegacyMessage(message: NostrEvent): Promise<void>;
@@ -0,0 +1,49 @@
1
+ import { getEncryptedContent, isEncryptedContentUnlocked, lockEncryptedContent, unlockEncryptedContent, } from "applesauce-core/helpers/encrypted-content";
2
+ import { getTagValue, kinds } from "applesauce-core/helpers/event";
3
+ /** Checks if a legacy direct message content is encrypted */
4
+ export function isLegacyMessageUnlocked(event) {
5
+ return isEncryptedContentUnlocked(event);
6
+ }
7
+ export function getLegacyMessageCorrespondent(message, self) {
8
+ return message.pubkey === self ? getTagValue(message, "p") : message.pubkey;
9
+ }
10
+ /** Returns the receiver of a legacy direct me */
11
+ export const getLegacyMessageReceiver = getLegacyMessageCorrespondent;
12
+ /** @deprecated use {@link getLegacyMessageCorrespondent} instead */
13
+ export const getLegacyMessageCorraspondant = getLegacyMessageCorrespondent;
14
+ /** Returns the sender of a legacy direct message */
15
+ export function getLegacyMessageSender(message) {
16
+ return message.pubkey;
17
+ }
18
+ /** Returns the parent message id of a legacy message */
19
+ export function getLegacyMessageParent(message) {
20
+ return getTagValue(message, "e");
21
+ }
22
+ /** Checks if a legacy message is valid */
23
+ export function isValidLegacyMessage(event) {
24
+ return (event.kind === kinds.EncryptedDirectMessage &&
25
+ getLegacyMessageCorrespondent(event, event.pubkey) !== undefined &&
26
+ event.content.length > 0);
27
+ }
28
+ /**
29
+ * Returns the decrypted content of a direct message
30
+ * @param message - The message to decrypt
31
+ * @param self - The public key of the user
32
+ * @param signer - The signer to use to decrypt the message
33
+ * @returns The decrypted content of the message
34
+ */
35
+ export async function unlockLegacyMessage(message, self, signer) {
36
+ const cached = getEncryptedContent(message);
37
+ if (cached)
38
+ return cached;
39
+ // Get the correspondent
40
+ const correspondent = getLegacyMessageCorrespondent(message, self);
41
+ if (!correspondent)
42
+ throw new Error("No correspondent found");
43
+ // Unlock the encrypted content
44
+ return await unlockEncryptedContent(message, correspondent, signer);
45
+ }
46
+ /** Clears the cached plaintext of a direct message */
47
+ export async function lockLegacyMessage(message) {
48
+ lockEncryptedContent(message);
49
+ }
@@ -0,0 +1,58 @@
1
+ import { NostrEvent } from "applesauce-core/helpers/event";
2
+ import { AddressPointer, EventPointer, ProfilePointer } from "applesauce-core/helpers/pointers";
3
+ export declare const FAVORITE_RELAYS_KIND = 10012;
4
+ export type ReadListTags = "public" | "hidden" | "all";
5
+ /** Returns all the tags of a list or set */
6
+ export declare function getListTags(list: NostrEvent, type?: ReadListTags): string[][];
7
+ /**
8
+ * Checks if an event pointer is anywhere in a list or set
9
+ * NOTE: Ignores the `relay` field in EventPointer
10
+ * @param list - The list or set to check
11
+ * @param pointer - The event pointer to check
12
+ * @param type - Which types of tags to check
13
+ */
14
+ export declare function isEventPointerInList(list: NostrEvent, pointer: string | EventPointer, type?: ReadListTags): boolean;
15
+ /**
16
+ * Checks if an address pointer is anywhere in a list or set
17
+ * NOTE: Ignores the `relay` field in AddressPointer
18
+ * @param list - The list or set to check
19
+ * @param pointer - The address pointer to check
20
+ * @param type - Which types of tags to check
21
+ */
22
+ export declare function isAddressPointerInList(list: NostrEvent, pointer: string | AddressPointer, type?: ReadListTags): boolean;
23
+ /**
24
+ * Checks if an profile pointer is anywhere in a list or set
25
+ * NOTE: Ignores the `relay` field in ProfilePointer
26
+ * @param list - The list or set to check
27
+ * @param pointer - The profile pointer to check
28
+ * @param type - Which types of tags to check
29
+ */
30
+ export declare function isProfilePointerInList(list: NostrEvent, pointer: string | ProfilePointer, type?: ReadListTags): boolean;
31
+ /** Returns if an event is in a list */
32
+ export declare function isEventInList(list: NostrEvent, event: NostrEvent): boolean;
33
+ /**
34
+ * Returns all the EventPointer in a list or set
35
+ * @param list - The list or set to get the event pointers from
36
+ * @param type - Which types of tags to read
37
+ */
38
+ export declare function getEventPointersFromList(list: NostrEvent, type?: ReadListTags): EventPointer[];
39
+ /**
40
+ * Returns all the AddressPointer in a list or set
41
+ * @param list - The list or set to get the address pointers from
42
+ * @param type - Which types of tags to read
43
+ */
44
+ export declare function getAddressPointersFromList(list: NostrEvent, type?: ReadListTags): AddressPointer[];
45
+ /**
46
+ * Returns all the ProfilePointer in a list or set
47
+ * @param list - The list or set to get the profile pointers from
48
+ * @param type - Which types of tags to read
49
+ */
50
+ export declare function getProfilePointersFromList(list: NostrEvent, type?: ReadListTags): ProfilePointer[];
51
+ /**
52
+ * Returns a deduplicated array of all 'relay' tags in a list or set
53
+ * @param list - The list or set to get the relays from
54
+ * @param type - Which types of tags to read
55
+ */
56
+ export declare function getRelaysFromList(list: NostrEvent, type?: ReadListTags): string[];
57
+ /** Returns if an event is a valid list or set */
58
+ export declare function isValidList(event: NostrEvent): boolean;
@@ -0,0 +1,110 @@
1
+ import { getReplaceableIdentifier, isAddressableKind, isReplaceable, isReplaceableKind, } from "applesauce-core/helpers/event";
2
+ import { getHiddenTags } from "applesauce-core/helpers/hidden-tags";
3
+ import { getAddressPointerForEvent, getAddressPointerFromATag, getCoordinateFromAddressPointer, getEventPointerFromETag, getProfilePointerFromPTag, } from "applesauce-core/helpers/pointers";
4
+ import { mergeRelaySets } from "applesauce-core/helpers/relays";
5
+ import { isATag, isETag, isPTag, processTags } from "applesauce-core/helpers/tags";
6
+ export const FAVORITE_RELAYS_KIND = 10012;
7
+ /** Returns all the tags of a list or set */
8
+ export function getListTags(list, type) {
9
+ switch (type) {
10
+ case "public":
11
+ return list.tags;
12
+ case "hidden":
13
+ return getHiddenTags(list) ?? [];
14
+ default:
15
+ case "all":
16
+ return [...(getHiddenTags(list) ?? []), ...list.tags];
17
+ }
18
+ }
19
+ /**
20
+ * Checks if an event pointer is anywhere in a list or set
21
+ * NOTE: Ignores the `relay` field in EventPointer
22
+ * @param list - The list or set to check
23
+ * @param pointer - The event pointer to check
24
+ * @param type - Which types of tags to check
25
+ */
26
+ export function isEventPointerInList(list, pointer, type) {
27
+ const id = typeof pointer === "string" ? pointer : pointer.id;
28
+ const tags = getListTags(list, type);
29
+ return tags.some((t) => t[0] === "e" && t[1] === id);
30
+ }
31
+ /**
32
+ * Checks if an address pointer is anywhere in a list or set
33
+ * NOTE: Ignores the `relay` field in AddressPointer
34
+ * @param list - The list or set to check
35
+ * @param pointer - The address pointer to check
36
+ * @param type - Which types of tags to check
37
+ */
38
+ export function isAddressPointerInList(list, pointer, type) {
39
+ const cord = typeof pointer === "string" ? pointer : getCoordinateFromAddressPointer(pointer);
40
+ const tags = getListTags(list, type);
41
+ return tags.some((t) => t[0] === "a" && t[1] === cord);
42
+ }
43
+ /**
44
+ * Checks if an profile pointer is anywhere in a list or set
45
+ * NOTE: Ignores the `relay` field in ProfilePointer
46
+ * @param list - The list or set to check
47
+ * @param pointer - The profile pointer to check
48
+ * @param type - Which types of tags to check
49
+ */
50
+ export function isProfilePointerInList(list, pointer, type) {
51
+ const pubkey = typeof pointer === "string" ? pointer : pointer.pubkey;
52
+ const tags = getListTags(list, type);
53
+ return tags.some((t) => t[0] === "p" && t[1] === pubkey);
54
+ }
55
+ /** Returns if an event is in a list */
56
+ export function isEventInList(list, event) {
57
+ return isReplaceable(event.kind)
58
+ ? isAddressPointerInList(list, getAddressPointerForEvent(event))
59
+ : isEventPointerInList(list, event);
60
+ }
61
+ /**
62
+ * Returns all the EventPointer in a list or set
63
+ * @param list - The list or set to get the event pointers from
64
+ * @param type - Which types of tags to read
65
+ */
66
+ export function getEventPointersFromList(list, type) {
67
+ return processTags(getListTags(list, type), (tag) => (isETag(tag) ? tag : undefined), getEventPointerFromETag);
68
+ }
69
+ /**
70
+ * Returns all the AddressPointer in a list or set
71
+ * @param list - The list or set to get the address pointers from
72
+ * @param type - Which types of tags to read
73
+ */
74
+ export function getAddressPointersFromList(list, type) {
75
+ return processTags(getListTags(list, type), (t) => (isATag(t) ? t : undefined), getAddressPointerFromATag);
76
+ }
77
+ /**
78
+ * Returns all the ProfilePointer in a list or set
79
+ * @param list - The list or set to get the profile pointers from
80
+ * @param type - Which types of tags to read
81
+ */
82
+ export function getProfilePointersFromList(list, type) {
83
+ return processTags(getListTags(list, type), (t) => (isPTag(t) ? t : undefined), getProfilePointerFromPTag);
84
+ }
85
+ /**
86
+ * Returns a deduplicated array of all 'relay' tags in a list or set
87
+ * @param list - The list or set to get the relays from
88
+ * @param type - Which types of tags to read
89
+ */
90
+ export function getRelaysFromList(list, type) {
91
+ return mergeRelaySets(processTags(getListTags(list, type), (t) => (t[0] === "relay" ? t[1] : undefined)));
92
+ }
93
+ /** Returns if an event is a valid list or set */
94
+ export function isValidList(event) {
95
+ try {
96
+ if (isAddressableKind(event.kind)) {
97
+ // event is a set
98
+ // ensure the set has an identifier
99
+ if (!getReplaceableIdentifier(event))
100
+ return false;
101
+ return true;
102
+ }
103
+ else if (isReplaceableKind(event.kind) && event.kind >= 10000 && event.kind < 20000) {
104
+ // event is a list
105
+ return true;
106
+ }
107
+ }
108
+ catch (error) { }
109
+ return false;
110
+ }
@@ -0,0 +1,8 @@
1
+ /** Parses a lightning address (lud16) into a LNURLp */
2
+ export declare function parseLightningAddress(address: string): URL | undefined;
3
+ /** Parses a LNURLp into a URL */
4
+ export declare function decodeLNURL(lnurl: string): URL | undefined;
5
+ /** Parses a lightning address or LNURLp into a URL */
6
+ export declare function parseLNURLOrAddress(addressOrLNURL: string): URL | undefined;
7
+ /** Requests a bolt11 invoice from a LNURLp callback URL */
8
+ export declare function getInvoice(callback: URL): Promise<string>;
@@ -0,0 +1,44 @@
1
+ import { bech32 } from "@scure/base";
2
+ import { parseBolt11 } from "./bolt11.js";
3
+ const decoder = new TextDecoder();
4
+ /** Parses a lightning address (lud16) into a LNURLp */
5
+ export function parseLightningAddress(address) {
6
+ let [name, domain] = address.split("@");
7
+ if (!name || !domain)
8
+ return;
9
+ return new URL(`https://${domain}/.well-known/lnurlp/${name}`);
10
+ }
11
+ /** Parses a LNURLp into a URL */
12
+ export function decodeLNURL(lnurl) {
13
+ try {
14
+ const { words, prefix } = bech32.decode(lnurl);
15
+ if (prefix !== "lnurl")
16
+ return;
17
+ const str = decoder.decode(bech32.fromWords(words));
18
+ return new URL(str);
19
+ }
20
+ catch (error) { }
21
+ return undefined;
22
+ }
23
+ /** Parses a lightning address or LNURLp into a URL */
24
+ export function parseLNURLOrAddress(addressOrLNURL) {
25
+ if (addressOrLNURL.includes("@"))
26
+ return parseLightningAddress(addressOrLNURL);
27
+ else
28
+ return decodeLNURL(addressOrLNURL);
29
+ }
30
+ /** Requests a bolt11 invoice from a LNURLp callback URL */
31
+ export async function getInvoice(callback) {
32
+ const { pr: payRequest } = await fetch(callback).then((res) => res.json());
33
+ const amount = callback.searchParams.get("amount");
34
+ if (!amount)
35
+ throw new Error("Missing amount");
36
+ if (payRequest) {
37
+ const parsed = parseBolt11(payRequest);
38
+ if (parsed.amount !== parseInt(amount))
39
+ throw new Error("Incorrect amount");
40
+ return payRequest;
41
+ }
42
+ else
43
+ throw new Error("Failed to get invoice");
44
+ }
@@ -0,0 +1,7 @@
1
+ import { NostrEvent } from "applesauce-core/helpers/event";
2
+ export declare const MailboxesInboxesSymbol: unique symbol;
3
+ export declare const MailboxesOutboxesSymbol: unique symbol;
4
+ /** Parses a 10002 event and stores the inboxes in the event using the {@link MailboxesInboxesSymbol} symbol */
5
+ export declare function getInboxes(event: NostrEvent): string[];
6
+ /** Parses a 10002 event and stores the outboxes in the event using the {@link MailboxesOutboxesSymbol} symbol */
7
+ export declare function getOutboxes(event: NostrEvent): string[];
@@ -0,0 +1,49 @@
1
+ import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
2
+ import { isSafeRelayURL } from "applesauce-core/helpers/relays";
3
+ import { isRTag } from "applesauce-core/helpers/tags";
4
+ import { normalizeURL } from "applesauce-core/helpers/url";
5
+ export const MailboxesInboxesSymbol = Symbol.for("mailboxes-inboxes");
6
+ export const MailboxesOutboxesSymbol = Symbol.for("mailboxes-outboxes");
7
+ /** Parses a 10002 event and stores the inboxes in the event using the {@link MailboxesInboxesSymbol} symbol */
8
+ export function getInboxes(event) {
9
+ return getOrComputeCachedValue(event, MailboxesInboxesSymbol, () => {
10
+ const inboxes = [];
11
+ for (const tag of event.tags) {
12
+ if (!isRTag(tag))
13
+ continue;
14
+ try {
15
+ const [, url, mode] = tag;
16
+ if (url && isSafeRelayURL(url) && !inboxes.includes(url) && (mode === "read" || mode === undefined)) {
17
+ inboxes.push(normalizeURL(url));
18
+ }
19
+ }
20
+ catch {
21
+ // Ignore invalid url tags
22
+ }
23
+ }
24
+ return inboxes;
25
+ });
26
+ }
27
+ /** Parses a 10002 event and stores the outboxes in the event using the {@link MailboxesOutboxesSymbol} symbol */
28
+ export function getOutboxes(event) {
29
+ return getOrComputeCachedValue(event, MailboxesOutboxesSymbol, () => {
30
+ const outboxes = [];
31
+ for (const tag of event.tags) {
32
+ if (!isRTag(tag))
33
+ continue;
34
+ try {
35
+ const [name, url, mode] = tag;
36
+ if (name === "r" &&
37
+ isSafeRelayURL(url) &&
38
+ !outboxes.includes(url) &&
39
+ (mode === "write" || mode === undefined)) {
40
+ outboxes.push(normalizeURL(url));
41
+ }
42
+ }
43
+ catch {
44
+ // Ignore invalid url tags
45
+ }
46
+ }
47
+ return outboxes;
48
+ });
49
+ }