applesauce-common 5.2.0 → 6.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 (263) hide show
  1. package/dist/casts/_circular-import.d.ts +7 -0
  2. package/dist/casts/_circular-import.js +9 -0
  3. package/dist/casts/article.d.ts +1 -1
  4. package/dist/casts/badge-award.d.ts +24 -0
  5. package/dist/casts/badge-award.js +39 -0
  6. package/dist/casts/badge.d.ts +19 -0
  7. package/dist/casts/badge.js +48 -0
  8. package/dist/casts/bookmarks.d.ts +5 -5
  9. package/dist/casts/cast.d.ts +1 -30
  10. package/dist/casts/cast.js +2 -67
  11. package/dist/casts/comment.d.ts +5 -5
  12. package/dist/casts/emoji-pack.d.ts +11 -0
  13. package/dist/casts/emoji-pack.js +25 -0
  14. package/dist/casts/favorite-emojis.d.ts +25 -0
  15. package/dist/casts/favorite-emojis.js +62 -0
  16. package/dist/casts/file-metadata.d.ts +22 -0
  17. package/dist/casts/file-metadata.js +55 -0
  18. package/dist/casts/groups.d.ts +1 -1
  19. package/dist/casts/index.d.ts +7 -0
  20. package/dist/casts/index.js +7 -0
  21. package/dist/casts/mutes.d.ts +1 -1
  22. package/dist/casts/note.d.ts +7 -7
  23. package/dist/casts/profile-badges.d.ts +28 -0
  24. package/dist/casts/profile-badges.js +59 -0
  25. package/dist/casts/reaction.d.ts +1 -1
  26. package/dist/casts/relay-lists.d.ts +1 -1
  27. package/dist/casts/relay-monitor.d.ts +1 -1
  28. package/dist/casts/report.d.ts +2 -2
  29. package/dist/casts/share.d.ts +2 -2
  30. package/dist/casts/stream.d.ts +9 -9
  31. package/dist/casts/torrent.d.ts +3 -3
  32. package/dist/casts/trusted-assertions.d.ts +144 -0
  33. package/dist/casts/trusted-assertions.js +281 -0
  34. package/dist/casts/user.d.ts +22 -40
  35. package/dist/casts/user.js +105 -161
  36. package/dist/casts/zap-goal.d.ts +2 -2
  37. package/dist/casts/zap.d.ts +4 -4
  38. package/dist/factories/app-data.d.ts +13 -0
  39. package/dist/factories/app-data.js +20 -0
  40. package/dist/factories/badge-award.d.ts +25 -0
  41. package/dist/factories/badge-award.js +41 -0
  42. package/dist/factories/badge.d.ts +32 -0
  43. package/dist/factories/badge.js +50 -0
  44. package/dist/factories/blocked-relays.d.ts +10 -0
  45. package/dist/factories/blocked-relays.js +16 -0
  46. package/dist/factories/blossom-server-list.d.ts +19 -0
  47. package/dist/factories/blossom-server-list.js +36 -0
  48. package/dist/factories/bookmark-list.d.ts +23 -0
  49. package/dist/factories/bookmark-list.js +45 -0
  50. package/dist/factories/bookmark-set.d.ts +25 -0
  51. package/dist/factories/bookmark-set.js +51 -0
  52. package/dist/factories/calendar-event.d.ts +88 -0
  53. package/dist/factories/calendar-event.js +175 -0
  54. package/dist/factories/calendar-rsvp.d.ts +22 -0
  55. package/dist/factories/calendar-rsvp.js +35 -0
  56. package/dist/factories/calendar.d.ts +20 -0
  57. package/dist/factories/calendar.js +36 -0
  58. package/dist/factories/code-snippet.d.ts +65 -0
  59. package/dist/factories/code-snippet.js +100 -0
  60. package/dist/factories/comment.d.ts +26 -0
  61. package/dist/factories/comment.js +49 -0
  62. package/dist/factories/contacts.d.ts +19 -0
  63. package/dist/factories/contacts.js +36 -0
  64. package/dist/factories/dm-relays.d.ts +10 -0
  65. package/dist/factories/dm-relays.js +16 -0
  66. package/dist/factories/favorite-relays.d.ts +16 -0
  67. package/dist/factories/favorite-relays.js +31 -0
  68. package/dist/factories/file-metadata.d.ts +54 -0
  69. package/dist/factories/file-metadata.js +92 -0
  70. package/dist/factories/follow-set.d.ts +12 -0
  71. package/dist/factories/follow-set.js +22 -0
  72. package/dist/factories/gift-wrap.d.ts +17 -0
  73. package/dist/factories/gift-wrap.js +21 -0
  74. package/dist/factories/group-management.d.ts +63 -0
  75. package/dist/factories/group-management.js +147 -0
  76. package/dist/factories/group.d.ts +35 -0
  77. package/dist/factories/group.js +69 -0
  78. package/dist/factories/highlight.d.ts +33 -0
  79. package/dist/factories/highlight.js +49 -0
  80. package/dist/factories/index.d.ts +41 -0
  81. package/dist/factories/index.js +41 -0
  82. package/dist/factories/legacy-message.d.ts +10 -0
  83. package/dist/factories/legacy-message.js +19 -0
  84. package/dist/factories/list.d.ts +56 -0
  85. package/dist/factories/list.js +120 -0
  86. package/dist/factories/live-stream.d.ts +48 -0
  87. package/dist/factories/live-stream.js +90 -0
  88. package/dist/factories/mute-list.d.ts +27 -0
  89. package/dist/factories/mute-list.js +57 -0
  90. package/dist/factories/note.d.ts +38 -0
  91. package/dist/factories/note.js +66 -0
  92. package/dist/factories/picture-post.d.ts +28 -0
  93. package/dist/factories/picture-post.js +46 -0
  94. package/dist/factories/pin-list.d.ts +14 -0
  95. package/dist/factories/pin-list.js +24 -0
  96. package/dist/factories/poll-response.d.ts +36 -0
  97. package/dist/factories/poll-response.js +46 -0
  98. package/dist/factories/poll.d.ts +35 -0
  99. package/dist/factories/poll.js +48 -0
  100. package/dist/factories/profile-badges.d.ts +31 -0
  101. package/dist/factories/profile-badges.js +52 -0
  102. package/dist/factories/reaction.d.ts +22 -0
  103. package/dist/factories/reaction.js +37 -0
  104. package/dist/factories/relay-set.d.ts +12 -0
  105. package/dist/factories/relay-set.js +22 -0
  106. package/dist/factories/search-relays.d.ts +10 -0
  107. package/dist/factories/search-relays.js +16 -0
  108. package/dist/factories/share.d.ts +26 -0
  109. package/dist/factories/share.js +44 -0
  110. package/dist/factories/stream-chat-message.d.ts +22 -0
  111. package/dist/factories/stream-chat-message.js +31 -0
  112. package/dist/factories/torrent.d.ts +57 -0
  113. package/dist/factories/torrent.js +93 -0
  114. package/dist/factories/wrapped-message.d.ts +22 -0
  115. package/dist/factories/wrapped-message.js +39 -0
  116. package/dist/factories/zap-goal.d.ts +35 -0
  117. package/dist/factories/zap-goal.js +49 -0
  118. package/dist/factories/zap-request.d.ts +28 -0
  119. package/dist/factories/zap-request.js +55 -0
  120. package/dist/factories/zap.d.ts +13 -0
  121. package/dist/factories/zap.js +21 -0
  122. package/dist/helpers/badge-award.d.ts +15 -0
  123. package/dist/helpers/badge-award.js +32 -0
  124. package/dist/helpers/badge.d.ts +27 -0
  125. package/dist/helpers/badge.js +59 -0
  126. package/dist/helpers/blossom.d.ts +29 -1
  127. package/dist/helpers/blossom.js +64 -7
  128. package/dist/helpers/emoji-pack.d.ts +43 -0
  129. package/dist/helpers/emoji-pack.js +108 -0
  130. package/dist/helpers/emoji.d.ts +0 -4
  131. package/dist/helpers/emoji.js +0 -16
  132. package/dist/helpers/file-metadata.d.ts +18 -13
  133. package/dist/helpers/file-metadata.js +10 -4
  134. package/dist/helpers/groups.d.ts +1 -0
  135. package/dist/helpers/groups.js +3 -2
  136. package/dist/helpers/hashtag.d.ts +1 -0
  137. package/dist/helpers/hashtag.js +3 -3
  138. package/dist/helpers/index.d.ts +7 -2
  139. package/dist/helpers/index.js +7 -2
  140. package/dist/helpers/lists.d.ts +8 -0
  141. package/dist/helpers/lists.js +27 -5
  142. package/dist/helpers/picture-post.d.ts +2 -2
  143. package/dist/helpers/profile-badges.d.ts +23 -0
  144. package/dist/helpers/profile-badges.js +51 -0
  145. package/dist/helpers/trusted-assertions.d.ts +81 -0
  146. package/dist/helpers/trusted-assertions.js +161 -0
  147. package/dist/helpers/zap.d.ts +8 -2
  148. package/dist/helpers/zap.js +31 -26
  149. package/dist/index.d.ts +2 -2
  150. package/dist/index.js +3 -3
  151. package/dist/models/index.d.ts +1 -1
  152. package/dist/models/index.js +1 -1
  153. package/dist/observable/chainable.d.ts +1 -36
  154. package/dist/observable/chainable.js +2 -72
  155. package/dist/operations/app-data.d.ts +8 -3
  156. package/dist/operations/app-data.js +9 -4
  157. package/dist/operations/badge-award.d.ts +17 -0
  158. package/dist/operations/badge-award.js +30 -0
  159. package/dist/operations/badge.d.ts +22 -0
  160. package/dist/operations/badge.js +54 -0
  161. package/dist/operations/blossom.d.ts +1 -1
  162. package/dist/operations/calendar-event.d.ts +1 -1
  163. package/dist/operations/calendar-rsvp.d.ts +1 -1
  164. package/dist/operations/calendar.d.ts +1 -1
  165. package/dist/operations/channel.d.ts +1 -1
  166. package/dist/operations/client.d.ts +1 -1
  167. package/dist/operations/client.js +2 -2
  168. package/dist/operations/code-snippet.d.ts +27 -0
  169. package/dist/operations/code-snippet.js +63 -0
  170. package/dist/operations/comment.d.ts +7 -3
  171. package/dist/operations/comment.js +8 -4
  172. package/dist/operations/file-metadata.d.ts +38 -4
  173. package/dist/operations/file-metadata.js +105 -19
  174. package/dist/operations/geohash.d.ts +1 -1
  175. package/dist/operations/gift-wrap.d.ts +19 -7
  176. package/dist/operations/gift-wrap.js +36 -26
  177. package/dist/operations/group.d.ts +1 -1
  178. package/dist/operations/hashtags.d.ts +1 -1
  179. package/dist/operations/highlight.d.ts +1 -1
  180. package/dist/operations/highlight.js +5 -5
  181. package/dist/operations/index.d.ts +7 -1
  182. package/dist/operations/index.js +7 -1
  183. package/dist/operations/legacy-message.d.ts +1 -1
  184. package/dist/operations/list.d.ts +1 -1
  185. package/dist/operations/live-stream.d.ts +7 -3
  186. package/dist/operations/live-stream.js +9 -5
  187. package/dist/operations/media-attachment.d.ts +3 -3
  188. package/dist/operations/note.d.ts +10 -4
  189. package/dist/operations/note.js +14 -8
  190. package/dist/operations/picture-post.d.ts +1 -1
  191. package/dist/operations/poll-response.d.ts +1 -1
  192. package/dist/operations/poll-response.js +1 -1
  193. package/dist/operations/poll.d.ts +1 -1
  194. package/dist/operations/profile-badges.d.ts +26 -0
  195. package/dist/operations/profile-badges.js +150 -0
  196. package/dist/operations/reaction.d.ts +8 -3
  197. package/dist/operations/reaction.js +10 -5
  198. package/dist/operations/share.d.ts +8 -3
  199. package/dist/operations/share.js +10 -5
  200. package/dist/operations/stream.d.ts +1 -1
  201. package/dist/operations/tag/bookmarks.d.ts +1 -1
  202. package/dist/operations/torrent.d.ts +1 -1
  203. package/dist/operations/wrapped-message.d.ts +1 -1
  204. package/dist/operations/zap-goal.d.ts +1 -1
  205. package/dist/operations/zap-request.d.ts +22 -0
  206. package/dist/operations/zap-request.js +40 -0
  207. package/dist/operations/zap-split.d.ts +8 -4
  208. package/dist/operations/zap-split.js +10 -6
  209. package/dist/operations/zap.d.ts +12 -0
  210. package/dist/operations/zap.js +34 -0
  211. package/package.json +12 -11
  212. package/dist/blueprints/__register__.d.ts +0 -7
  213. package/dist/blueprints/__register__.js +0 -8
  214. package/dist/blueprints/app-data.d.ts +0 -5
  215. package/dist/blueprints/app-data.js +0 -10
  216. package/dist/blueprints/calendar.d.ts +0 -5
  217. package/dist/blueprints/calendar.js +0 -7
  218. package/dist/blueprints/channels.d.ts +0 -6
  219. package/dist/blueprints/channels.js +0 -13
  220. package/dist/blueprints/comment.d.ts +0 -13
  221. package/dist/blueprints/comment.js +0 -15
  222. package/dist/blueprints/delete.d.ts +0 -9
  223. package/dist/blueprints/delete.js +0 -14
  224. package/dist/blueprints/file-metadata.d.ts +0 -8
  225. package/dist/blueprints/file-metadata.js +0 -11
  226. package/dist/blueprints/follow-set.d.ts +0 -11
  227. package/dist/blueprints/follow-set.js +0 -21
  228. package/dist/blueprints/gift-wrap.d.ts +0 -5
  229. package/dist/blueprints/gift-wrap.js +0 -6
  230. package/dist/blueprints/group-mangement.d.ts +0 -25
  231. package/dist/blueprints/group-mangement.js +0 -40
  232. package/dist/blueprints/group.d.ts +0 -9
  233. package/dist/blueprints/group.js +0 -17
  234. package/dist/blueprints/highlight.d.ts +0 -20
  235. package/dist/blueprints/highlight.js +0 -12
  236. package/dist/blueprints/index.d.ts +0 -25
  237. package/dist/blueprints/index.js +0 -26
  238. package/dist/blueprints/legacy-message.d.ts +0 -7
  239. package/dist/blueprints/legacy-message.js +0 -29
  240. package/dist/blueprints/live-stream.d.ts +0 -6
  241. package/dist/blueprints/live-stream.js +0 -9
  242. package/dist/blueprints/note.d.ts +0 -16
  243. package/dist/blueprints/note.js +0 -30
  244. package/dist/blueprints/picture-post.d.ts +0 -12
  245. package/dist/blueprints/picture-post.js +0 -17
  246. package/dist/blueprints/poll.d.ts +0 -41
  247. package/dist/blueprints/poll.js +0 -33
  248. package/dist/blueprints/profile.d.ts +0 -3
  249. package/dist/blueprints/profile.js +0 -7
  250. package/dist/blueprints/reaction.d.ts +0 -10
  251. package/dist/blueprints/reaction.js +0 -14
  252. package/dist/blueprints/share.d.ts +0 -12
  253. package/dist/blueprints/share.js +0 -25
  254. package/dist/blueprints/stream.d.ts +0 -6
  255. package/dist/blueprints/stream.js +0 -7
  256. package/dist/blueprints/torrent.d.ts +0 -30
  257. package/dist/blueprints/torrent.js +0 -29
  258. package/dist/blueprints/wrapped-message.d.ts +0 -20
  259. package/dist/blueprints/wrapped-message.js +0 -64
  260. package/dist/blueprints/zap-goal.d.ts +0 -16
  261. package/dist/blueprints/zap-goal.js +0 -12
  262. package/dist/register.d.ts +0 -2
  263. package/dist/register.js +0 -4
@@ -1,21 +1,107 @@
1
- import { ensureSingletonTag } from "applesauce-core/helpers";
2
- import { createFileMetadataTags } from "../helpers/file-metadata.js";
3
- /** Sets all NIP-94 tags for {@link FileMetadata} */
1
+ import { eventPipe } from "applesauce-core/helpers";
2
+ import { addNameValueTag, removeNameValueTag, removeSingletonTag, setSingletonTag, } from "applesauce-core/operations/tag/common";
3
+ import { modifyPublicTags } from "applesauce-core/operations/tags";
4
+ function setNullableSingletonTag(name, value) {
5
+ return modifyPublicTags(value === null ? removeSingletonTag(name) : setSingletonTag([name, String(value)], true));
6
+ }
7
+ /** Sets or removes the file URL */
8
+ export function setFileURL(url) {
9
+ return setNullableSingletonTag("url", url);
10
+ }
11
+ /** Sets or removes the file MIME type */
12
+ export function setFileType(type) {
13
+ return setNullableSingletonTag("m", type);
14
+ }
15
+ /** Sets or removes the file SHA-256 hash */
16
+ export function setFileSHA256(hash) {
17
+ return setNullableSingletonTag("x", hash);
18
+ }
19
+ /** Sets or removes the original file SHA-256 hash */
20
+ export function setOriginalFileSHA256(hash) {
21
+ return setNullableSingletonTag("ox", hash);
22
+ }
23
+ /** Sets or removes the file size */
24
+ export function setFileSize(size) {
25
+ return setNullableSingletonTag("size", size);
26
+ }
27
+ /** Sets or removes the file dimensions */
28
+ export function setFileDimensions(dimensions) {
29
+ return setNullableSingletonTag("dim", dimensions);
30
+ }
31
+ /** Sets or removes the magnet URI */
32
+ export function setFileMagnet(magnet) {
33
+ return setNullableSingletonTag("magnet", magnet);
34
+ }
35
+ /** Sets or removes the torrent infohash */
36
+ export function setFileInfohash(infohash) {
37
+ return setNullableSingletonTag("i", infohash);
38
+ }
39
+ /** Sets or removes the thumbnail URL */
40
+ export function setFileThumbnail(url) {
41
+ return setNullableSingletonTag("thumb", url);
42
+ }
43
+ /** Sets or removes the preview image URL */
44
+ export function setFileImage(url) {
45
+ return setNullableSingletonTag("image", url);
46
+ }
47
+ /** Sets or removes the summary */
48
+ export function setFileSummary(summary) {
49
+ return setNullableSingletonTag("summary", summary);
50
+ }
51
+ /** Sets or removes the alt text */
52
+ export function setFileAlt(alt) {
53
+ return setNullableSingletonTag("alt", alt);
54
+ }
55
+ /** Sets or removes the blurhash */
56
+ export function setFileBlurhash(blurhash) {
57
+ return setNullableSingletonTag("blurhash", blurhash);
58
+ }
59
+ /** Adds a fallback URL */
60
+ export function addFallbackURL(url, replace = true) {
61
+ return modifyPublicTags(addNameValueTag(["fallback", url], replace));
62
+ }
63
+ /** Removes a matching fallback URL */
64
+ export function removeFallbackURL(url) {
65
+ return modifyPublicTags(removeNameValueTag(["fallback", url]));
66
+ }
67
+ /** Removes all fallback URLs */
68
+ export function clearFallbackURLs() {
69
+ return modifyPublicTags((tags) => tags.filter((tag) => tag[0] !== "fallback"));
70
+ }
71
+ /** Replaces all fallback URLs with the provided list */
72
+ export function setFallbackURLs(urls) {
73
+ return eventPipe(clearFallbackURLs(), ...urls.map((url) => addFallbackURL(url, false)));
74
+ }
75
+ /** Sets all NIP-94 tags for {@link FileMetadataFields} */
4
76
  export function setFileMetadata(metadata) {
5
- return (draft) => {
6
- let tags = Array.from(draft.tags);
7
- const fileTags = createFileMetadataTags(metadata);
8
- for (const tag of fileTags) {
9
- switch (tag[0]) {
10
- case "fallback":
11
- // support multiple fallback tags
12
- tags.push(tag);
13
- break;
14
- default:
15
- tags = ensureSingletonTag(tags, tag);
16
- break;
17
- }
18
- }
19
- return { ...draft, tags };
20
- };
77
+ const operations = [];
78
+ if ("url" in metadata)
79
+ operations.push(setFileURL(metadata.url ?? null));
80
+ if ("type" in metadata)
81
+ operations.push(setFileType(metadata.type ?? null));
82
+ if ("sha256" in metadata)
83
+ operations.push(setFileSHA256(metadata.sha256 ?? null));
84
+ if ("originalSha256" in metadata)
85
+ operations.push(setOriginalFileSHA256(metadata.originalSha256 ?? null));
86
+ if ("size" in metadata)
87
+ operations.push(setFileSize(metadata.size ?? null));
88
+ if ("dimensions" in metadata)
89
+ operations.push(setFileDimensions(metadata.dimensions ?? null));
90
+ if ("magnet" in metadata)
91
+ operations.push(setFileMagnet(metadata.magnet ?? null));
92
+ if ("infohash" in metadata)
93
+ operations.push(setFileInfohash(metadata.infohash ?? null));
94
+ if ("thumbnail" in metadata)
95
+ operations.push(setFileThumbnail(metadata.thumbnail ?? null));
96
+ if ("image" in metadata)
97
+ operations.push(setFileImage(metadata.image ?? null));
98
+ if ("summary" in metadata)
99
+ operations.push(setFileSummary(metadata.summary ?? null));
100
+ if ("alt" in metadata)
101
+ operations.push(setFileAlt(metadata.alt ?? null));
102
+ if ("blurhash" in metadata)
103
+ operations.push(setFileBlurhash(metadata.blurhash ?? null));
104
+ if ("fallback" in metadata)
105
+ operations.push(setFallbackURLs(metadata.fallback ?? []));
106
+ return eventPipe(...operations);
21
107
  }
@@ -1,4 +1,4 @@
1
- import { EventOperation } from "applesauce-core/event-factory";
1
+ import { EventOperation } from "applesauce-core/factories";
2
2
  /** Adds all "g" geohash tags for a given geohash or removes them if null */
3
3
  export declare function setGeohash(geohash: string | null): EventOperation;
4
4
  /** Removes all "g" geohash tags from an event */
@@ -1,13 +1,25 @@
1
- import { EventOperation } from "applesauce-core/event-factory";
1
+ import type { EventOperation } from "applesauce-core/factories";
2
2
  import { EventTemplate, NostrEvent, UnsignedEvent } from "applesauce-core/helpers/event";
3
3
  import { MetaTagOptions } from "applesauce-core/operations/event";
4
4
  import { Rumor } from "../helpers/gift-wrap.js";
5
- /** Converts an event to a rumor. The first operation in the gift wrap pipeline */
6
- export declare function toRumor(): EventOperation<EventTemplate | UnsignedEvent | NostrEvent, Rumor>;
7
- /** Seals a rumor in a NIP-59 seal. The second operation in the gift wrap pipeline */
8
- export declare function sealRumor(pubkey: string): EventOperation<Rumor, NostrEvent>;
5
+ /**
6
+ * Converts an event to a rumor. The first operation in the gift wrap pipeline
7
+ * @param signer - EventSigner for getting pubkey
8
+ */
9
+ export declare function toRumor(signer?: import("applesauce-core/factories").EventSigner): EventOperation<EventTemplate | UnsignedEvent | NostrEvent, Rumor>;
10
+ /**
11
+ * Seals a rumor in a NIP-59 seal. The second operation in the gift wrap pipeline
12
+ * @param pubkey - Pubkey to encrypt seal for
13
+ * @param signer - EventSigner for signing the seal
14
+ */
15
+ export declare function sealRumor(pubkey: string, signer?: import("applesauce-core/factories").EventSigner): EventOperation<Rumor, NostrEvent>;
9
16
  export type GiftWrapOptions = MetaTagOptions;
10
17
  /** Gift wraps a seal to a pubkey. The third operation in the gift wrap pipeline */
11
18
  export declare function wrapSeal(pubkey: string, opts?: GiftWrapOptions): EventOperation<NostrEvent, NostrEvent>;
12
- /** An operation that gift wraps an event to a pubkey */
13
- export declare function giftWrap(pubkey: string, opts?: GiftWrapOptions): EventOperation<EventTemplate | UnsignedEvent | NostrEvent, NostrEvent>;
19
+ /**
20
+ * An operation that gift wraps an event to a pubkey
21
+ * @param pubkey - Pubkey to gift wrap for
22
+ * @param signer - EventSigner for creating rumor and seal
23
+ * @param opts - Optional gift wrap options
24
+ */
25
+ export declare function giftWrap(pubkey: string, signer?: import("applesauce-core/factories").EventSigner, opts?: GiftWrapOptions): EventOperation<EventTemplate | UnsignedEvent | NostrEvent, NostrEvent>;
@@ -1,6 +1,6 @@
1
1
  // Read https://github.com/nostr-protocol/nips/blob/master/59.md#overview for details on rumors and seals
2
2
  // Gift wrap (signed random key) -> seal (signed sender key) -> rumor (unsigned)
3
- import { buildEvent } from "applesauce-core/event-factory";
3
+ import { blankEventTemplate } from "applesauce-core/factories";
4
4
  import { EncryptedContentSymbol } from "applesauce-core/helpers/encrypted-content";
5
5
  import { nip44 } from "applesauce-core/helpers/encryption";
6
6
  import { finalizeEvent, getEventHash, kinds, } from "applesauce-core/helpers/event";
@@ -18,16 +18,19 @@ PRESERVE_EVENT_SYMBOLS.add(RumorSymbol);
18
18
  function randomNow() {
19
19
  return unixNow() - Math.floor(Math.random() * 60 * 60);
20
20
  }
21
- /** Converts an event to a rumor. The first operation in the gift wrap pipeline */
22
- export function toRumor() {
23
- return async (draft, ctx) => {
21
+ /**
22
+ * Converts an event to a rumor. The first operation in the gift wrap pipeline
23
+ * @param signer - EventSigner for getting pubkey
24
+ */
25
+ export function toRumor(signer) {
26
+ return async (draft) => {
24
27
  // @ts-expect-error
25
28
  const rumor = { ...draft };
26
29
  // Ensure rumor has pubkey
27
30
  if (!Reflect.has(rumor, "pubkey")) {
28
- if (!ctx.signer)
31
+ if (!signer)
29
32
  throw new Error("A signer is required to create a rumor");
30
- rumor.pubkey = await ctx.signer.getPublicKey();
33
+ rumor.pubkey = await signer.getPublicKey();
31
34
  }
32
35
  // Ensure rumor has id
33
36
  if (!Reflect.has(rumor, "id"))
@@ -37,18 +40,22 @@ export function toRumor() {
37
40
  return rumor;
38
41
  };
39
42
  }
40
- /** Seals a rumor in a NIP-59 seal. The second operation in the gift wrap pipeline */
41
- export function sealRumor(pubkey) {
42
- return async (rumor, ctx) => {
43
- if (!ctx.signer)
43
+ /**
44
+ * Seals a rumor in a NIP-59 seal. The second operation in the gift wrap pipeline
45
+ * @param pubkey - Pubkey to encrypt seal for
46
+ * @param signer - EventSigner for signing the seal
47
+ */
48
+ export function sealRumor(pubkey, signer) {
49
+ return async (rumor) => {
50
+ if (!signer)
44
51
  throw new Error("A signer is required to create a seal");
45
52
  const plaintext = JSON.stringify(rumor);
46
- const unsigned = await buildEvent({ kind: kinds.Seal, created_at: randomNow() }, ctx,
53
+ const unsigned = await eventPipe(
47
54
  // Set the encrypted content
48
- setEncryptedContent(pubkey, plaintext),
49
- // Stamp the seal with the signers's pubkey
50
- stamp());
51
- const seal = await ctx.signer.signEvent(unsigned);
55
+ setEncryptedContent(pubkey, plaintext, signer),
56
+ // Stamp the seal with the signer's pubkey
57
+ stamp(signer))({ ...blankEventTemplate(kinds.Seal), created_at: randomNow() });
58
+ const seal = await signer.signEvent(unsigned);
52
59
  // Set the downstream reference on the seal
53
60
  Reflect.set(seal, RumorSymbol, rumor);
54
61
  // Add the upstream reference to the rumor
@@ -65,16 +72,14 @@ export function wrapSeal(pubkey, opts) {
65
72
  return async (seal) => {
66
73
  const key = generateSecretKey();
67
74
  const plaintext = JSON.stringify(seal);
68
- const draft = await buildEvent({
69
- kind: kinds.GiftWrap,
75
+ const draft = await eventPipe(
76
+ // Set meta tags on the gift wrap
77
+ setMetaTags(opts))({
78
+ ...blankEventTemplate(kinds.GiftWrap),
70
79
  created_at: randomNow(),
71
80
  content: nip44.encrypt(plaintext, nip44.getConversationKey(key, pubkey)),
72
81
  tags: [["p", pubkey]],
73
- },
74
- // Pass an empty context here so here there is no chance to use the users pubkey
75
- {},
76
- // Set meta tags on the gift wrap
77
- setMetaTags(opts));
82
+ });
78
83
  const gift = finalizeEvent(draft, key);
79
84
  // Set the upstream references on the seal
80
85
  Reflect.set(seal, GiftWrapSymbol, gift);
@@ -85,9 +90,14 @@ export function wrapSeal(pubkey, opts) {
85
90
  return gift;
86
91
  };
87
92
  }
88
- /** An operation that gift wraps an event to a pubkey */
89
- export function giftWrap(pubkey, opts) {
90
- return eventPipe(toRumor(),
93
+ /**
94
+ * An operation that gift wraps an event to a pubkey
95
+ * @param pubkey - Pubkey to gift wrap for
96
+ * @param signer - EventSigner for creating rumor and seal
97
+ * @param opts - Optional gift wrap options
98
+ */
99
+ export function giftWrap(pubkey, signer, opts) {
100
+ return eventPipe(toRumor(signer),
91
101
  // @ts-expect-error
92
- sealRumor(pubkey), wrapSeal(pubkey, opts));
102
+ sealRumor(pubkey, signer), wrapSeal(pubkey, opts));
93
103
  }
@@ -1,4 +1,4 @@
1
- import { EventOperation } from "applesauce-core/event-factory";
1
+ import { EventOperation } from "applesauce-core/factories";
2
2
  import { EventPointer, ProfilePointer } from "applesauce-core/helpers";
3
3
  import { NostrEvent } from "applesauce-core/helpers/event";
4
4
  import { GroupMetadata, GroupPointer } from "../helpers/groups.js";
@@ -1,4 +1,4 @@
1
- import { EventOperation } from "applesauce-core/event-factory";
1
+ import { EventOperation } from "applesauce-core/factories";
2
2
  /** Adds a hashtag to the live event */
3
3
  export declare function addHashtag(hashtag: string): EventOperation;
4
4
  /** Removes a hashtag from the live event */
@@ -1,4 +1,4 @@
1
- import { EventOperation } from "applesauce-core/event-factory";
1
+ import { EventOperation } from "applesauce-core/factories";
2
2
  import { NostrEvent } from "applesauce-core/helpers/event";
3
3
  import { AddressPointer, EventPointer } from "applesauce-core/helpers/pointers";
4
4
  import { HighlightAttribution } from "../helpers/highlight.js";
@@ -14,25 +14,25 @@ export function setSource(source) {
14
14
  const address = getAddressPointerForEvent(source);
15
15
  if (address) {
16
16
  // Include both the event pointer and address pointer
17
- return modifyPublicTags(addEventPointerTag(source, true), addAddressPointerTag(address, true));
17
+ return modifyPublicTags(addEventPointerTag(source, undefined, true), addAddressPointerTag(address, undefined, true));
18
18
  }
19
19
  else {
20
20
  // Just include the event pointer
21
- return modifyPublicTags(addEventPointerTag(source, true));
21
+ return modifyPublicTags(addEventPointerTag(source, undefined, true));
22
22
  }
23
23
  }
24
24
  else {
25
25
  // Include the event pointer for normal events
26
- return modifyPublicTags(addEventPointerTag(source, true));
26
+ return modifyPublicTags(addEventPointerTag(source, undefined, true));
27
27
  }
28
28
  }
29
29
  else if (isAddressPointer(source)) {
30
30
  // Include "a" tag for address pointers
31
- return modifyPublicTags(addAddressPointerTag(source, true));
31
+ return modifyPublicTags(addAddressPointerTag(source, undefined, true));
32
32
  }
33
33
  else if (isEventPointer(source)) {
34
34
  // Include "e" tag for event pointers
35
- return modifyPublicTags(addEventPointerTag(source, true));
35
+ return modifyPublicTags(addEventPointerTag(source, undefined, true));
36
36
  }
37
37
  else if (typeof source === "string") {
38
38
  // Include "r" tags for URLs
@@ -1,4 +1,7 @@
1
1
  export * as AppData from "./app-data.js";
2
+ export * as Badge from "./badge.js";
3
+ export * as BadgeAward from "./badge-award.js";
4
+ export * as CodeSnippet from "./code-snippet.js";
2
5
  export * as Calendar from "./calendar.js";
3
6
  export * as CalendarEvent from "./calendar-event.js";
4
7
  export * as CalendarRsvp from "./calendar-rsvp.js";
@@ -20,10 +23,13 @@ export * as PicturePost from "./picture-post.js";
20
23
  export * as Poll from "./poll.js";
21
24
  export * as PollResponse from "./poll-response.js";
22
25
  export * as Reaction from "./reaction.js";
26
+ export * as ProfileBadges from "./profile-badges.js";
23
27
  export * as Stream from "./stream.js";
24
28
  export * as StreamChat from "./stream-chat.js";
25
29
  export * as Torrent from "./torrent.js";
26
30
  export * as WrappedMessage from "./wrapped-message.js";
27
- export * as Zap from "./zap-split.js";
31
+ export * as Zap from "./zap.js";
28
32
  export * as ZapGoal from "./zap-goal.js";
33
+ export * as ZapRequest from "./zap-request.js";
34
+ export * as ZapSplit from "./zap-split.js";
29
35
  export * as TagOperations from "./tag/index.js";
@@ -1,4 +1,7 @@
1
1
  export * as AppData from "./app-data.js";
2
+ export * as Badge from "./badge.js";
3
+ export * as BadgeAward from "./badge-award.js";
4
+ export * as CodeSnippet from "./code-snippet.js";
2
5
  export * as Calendar from "./calendar.js";
3
6
  export * as CalendarEvent from "./calendar-event.js";
4
7
  export * as CalendarRsvp from "./calendar-rsvp.js";
@@ -20,10 +23,13 @@ export * as PicturePost from "./picture-post.js";
20
23
  export * as Poll from "./poll.js";
21
24
  export * as PollResponse from "./poll-response.js";
22
25
  export * as Reaction from "./reaction.js";
26
+ export * as ProfileBadges from "./profile-badges.js";
23
27
  export * as Stream from "./stream.js";
24
28
  export * as StreamChat from "./stream-chat.js";
25
29
  export * as Torrent from "./torrent.js";
26
30
  export * as WrappedMessage from "./wrapped-message.js";
27
- export * as Zap from "./zap-split.js";
31
+ export * as Zap from "./zap.js";
28
32
  export * as ZapGoal from "./zap-goal.js";
33
+ export * as ZapRequest from "./zap-request.js";
34
+ export * as ZapSplit from "./zap-split.js";
29
35
  export * as TagOperations from "./tag/index.js";
@@ -1,4 +1,4 @@
1
- import { EventOperation } from "applesauce-core/event-factory";
1
+ import { EventOperation } from "applesauce-core/factories";
2
2
  import { NostrEvent } from "applesauce-core/helpers/event";
3
3
  /** Includes the nip-04 direct message "p" tag */
4
4
  export declare function setMessageAddress(pubkey: string): EventOperation;
@@ -1,4 +1,4 @@
1
- import { EventOperation } from "applesauce-core/event-factory";
1
+ import { EventOperation } from "applesauce-core/factories";
2
2
  /** Sets or removes the "title" tag on a NIP-51 list */
3
3
  export declare function setTitle(title: string | null): EventOperation;
4
4
  /** Sets or removes the "image" tag on a NIP-51 list */
@@ -1,4 +1,8 @@
1
- import { EventOperation } from "applesauce-core/event-factory";
1
+ import { EventOperation } from "applesauce-core/factories";
2
2
  import { NostrEvent } from "applesauce-core/helpers/event";
3
- /** Includes the "a" tag for live streams */
4
- export declare function includeLiveStreamTag(stream: NostrEvent): EventOperation;
3
+ /**
4
+ * Includes the "a" tag for live streams
5
+ * @param stream - Live stream event
6
+ * @param getRelayHint - Optional function to get relay hint
7
+ */
8
+ export declare function includeLiveStreamTag(stream: NostrEvent, getRelayHint?: (eventId: string) => Promise<string | undefined>): EventOperation;
@@ -1,14 +1,18 @@
1
1
  import { ensureMarkedAddressPointerTag } from "applesauce-core/helpers/factory";
2
2
  import { getAddressPointerForEvent } from "applesauce-core/helpers/pointers";
3
- /** Includes the "a" tag for live streams */
4
- export function includeLiveStreamTag(stream) {
5
- return async (draft, ctx) => {
3
+ /**
4
+ * Includes the "a" tag for live streams
5
+ * @param stream - Live stream event
6
+ * @param getRelayHint - Optional function to get relay hint
7
+ */
8
+ export function includeLiveStreamTag(stream, getRelayHint) {
9
+ return async (draft) => {
6
10
  const pointer = getAddressPointerForEvent(stream);
7
11
  if (!pointer)
8
12
  throw new Error("Stream is not addressable");
9
13
  // add relay hint if there isn't one
10
- if (pointer.relays?.[0] === undefined && ctx.getEventRelayHint) {
11
- const hint = await ctx.getEventRelayHint(stream.id);
14
+ if (pointer.relays?.[0] === undefined && getRelayHint) {
15
+ const hint = await getRelayHint(stream.id);
12
16
  if (hint)
13
17
  pointer.relays = [hint];
14
18
  }
@@ -1,4 +1,4 @@
1
- import { EventOperation } from "applesauce-core/event-factory";
2
- import { FileMetadata } from "../helpers/file-metadata.js";
1
+ import { EventOperation } from "applesauce-core/factories";
2
+ import { FileMetadataFields } from "../helpers/file-metadata.js";
3
3
  /** Adds "imeta" tags on to any event */
4
- export declare function addMediaAttachments(attachments: FileMetadata[]): EventOperation;
4
+ export declare function addMediaAttachments(attachments: FileMetadataFields[]): EventOperation;
@@ -1,9 +1,15 @@
1
- import { EventOperation } from "applesauce-core/event-factory";
1
+ import { EventOperation } from "applesauce-core/factories";
2
2
  import { NostrEvent } from "applesauce-core/helpers/event";
3
3
  /**
4
4
  * Includes NIP-10 reply tags
5
+ * @param parent - Parent event to reply to
6
+ * @param getRelayHint - Optional function to get relay hint for event ID
5
7
  * @throws {Error} if the parent is not a short text note
6
8
  */
7
- export declare function setThreadParent(parent: NostrEvent): EventOperation;
8
- /** Copies "p" tags from parent event and adds new pubkeys */
9
- export declare function includePubkeyNotificationTags(parent: NostrEvent): EventOperation;
9
+ export declare function setThreadParent(parent: NostrEvent, getRelayHint?: (eventId: string) => Promise<string | undefined>): EventOperation;
10
+ /**
11
+ * Copies "p" tags from parent event and adds new pubkeys
12
+ * @param parent - Parent event to copy p tags from
13
+ * @param getRelayHint - Optional function to get relay hint for pubkey
14
+ */
15
+ export declare function includePubkeyNotificationTags(parent: NostrEvent, getRelayHint?: (pubkey: string) => Promise<string | undefined>): EventOperation;
@@ -4,16 +4,18 @@ import { isPTag } from "applesauce-core/helpers/tags";
4
4
  import { getNip10References } from "../helpers/threading.js";
5
5
  /**
6
6
  * Includes NIP-10 reply tags
7
+ * @param parent - Parent event to reply to
8
+ * @param getRelayHint - Optional function to get relay hint for event ID
7
9
  * @throws {Error} if the parent is not a short text note
8
10
  */
9
- export function setThreadParent(parent) {
11
+ export function setThreadParent(parent, getRelayHint) {
10
12
  if (parent.kind !== kinds.ShortTextNote)
11
13
  throw new Error("Parent must be a short text note");
12
- return async (draft, ctx) => {
14
+ return async (draft) => {
13
15
  let tags = Array.from(draft.tags);
14
16
  const pointer = { id: parent.id, author: parent.pubkey, kind: parent.kind };
15
- if (ctx.getEventRelayHint) {
16
- const hint = await ctx.getEventRelayHint(parent.id);
17
+ if (getRelayHint) {
18
+ const hint = await getRelayHint(parent.id);
17
19
  if (hint)
18
20
  pointer.relays = [hint];
19
21
  }
@@ -25,9 +27,13 @@ export function setThreadParent(parent) {
25
27
  return { ...draft, tags };
26
28
  };
27
29
  }
28
- /** Copies "p" tags from parent event and adds new pubkeys */
29
- export function includePubkeyNotificationTags(parent) {
30
- return async (draft, ctx) => {
30
+ /**
31
+ * Copies "p" tags from parent event and adds new pubkeys
32
+ * @param parent - Parent event to copy p tags from
33
+ * @param getRelayHint - Optional function to get relay hint for pubkey
34
+ */
35
+ export function includePubkeyNotificationTags(parent, getRelayHint) {
36
+ return async (draft) => {
31
37
  let tags = Array.from(draft.tags);
32
38
  // copy "p" tags from parent event that are not mentions
33
39
  for (const tag of parent.tags) {
@@ -35,7 +41,7 @@ export function includePubkeyNotificationTags(parent) {
35
41
  tags.push(tag);
36
42
  }
37
43
  // add new "p" tag
38
- const hint = await ctx.getPubkeyRelayHint?.(parent.pubkey);
44
+ const hint = getRelayHint ? await getRelayHint(parent.pubkey) : undefined;
39
45
  tags = ensureProfilePointerTag(tags, { pubkey: parent.pubkey, relays: hint ? [hint] : undefined });
40
46
  return { ...draft, tags };
41
47
  };
@@ -1,4 +1,4 @@
1
- import { EventOperation } from "applesauce-core/event-factory";
1
+ import { EventOperation } from "applesauce-core/factories";
2
2
  import { MediaAttachment } from "../helpers/file-metadata.js";
3
3
  /** Includes the "x" and "m" tags for kind 20 picture posts */
4
4
  export declare function setImageMetadata(pictures: MediaAttachment[]): EventOperation;
@@ -1,4 +1,4 @@
1
- import { EventOperation } from "applesauce-core/event-factory";
1
+ import { EventOperation } from "applesauce-core/factories";
2
2
  import { NostrEvent } from "applesauce-core/helpers/event";
3
3
  import { EventPointer } from "applesauce-core/helpers/pointers";
4
4
  /** Sets the poll event that this response is for using an 'e' tag */
@@ -2,7 +2,7 @@ import { addEventPointerTag } from "applesauce-core/operations/tag/common";
2
2
  import { modifyPublicTags } from "applesauce-core/operations/tags";
3
3
  /** Sets the poll event that this response is for using an 'e' tag */
4
4
  export function setPollEvent(poll) {
5
- return modifyPublicTags(addEventPointerTag(poll, true));
5
+ return modifyPublicTags(addEventPointerTag(poll, undefined, true));
6
6
  }
7
7
  /** Sets multiple response options at once, replacing any existing response tags */
8
8
  export function setChoices(optionIds) {
@@ -1,4 +1,4 @@
1
- import { EventOperation } from "applesauce-core/event-factory";
1
+ import { EventOperation } from "applesauce-core/factories";
2
2
  import { PollType } from "../helpers/poll.js";
3
3
  /** Sets the content (poll question/label) for a poll event */
4
4
  export declare function setQuestion(question: string): EventOperation;
@@ -0,0 +1,26 @@
1
+ import { EventOperation } from "applesauce-core/factories";
2
+ import { type NostrEvent } from "applesauce-core/helpers/event";
3
+ import { AddressPointer, EventPointer } from "applesauce-core/helpers/pointers";
4
+ import type { ProfileBadgeSlot } from "../helpers/profile-badges.js";
5
+ export type ProfileBadgeSlotInput = {
6
+ badge: AddressPointer | NostrEvent | string;
7
+ award: EventPointer | NostrEvent | string;
8
+ };
9
+ /** Replaces every badge slot with the provided list */
10
+ export declare function setSlots(slots: Array<ProfileBadgeSlotInput | ProfileBadgeSlot>): EventOperation;
11
+ /** Adds a slot, replacing any existing slot for the same badge */
12
+ export declare function addSlot(slot: ProfileBadgeSlotInput | ProfileBadgeSlot): EventOperation;
13
+ /** Removes every slot */
14
+ export declare function clearSlots(): EventOperation;
15
+ /** Removes the slot associated with a specific badge definition */
16
+ export declare function removeSlotByBadge(badge: AddressPointer | NostrEvent | string): EventOperation;
17
+ /** Removes the slot referencing a specific award receipt */
18
+ export declare function removeSlotByAward(award: EventPointer | NostrEvent | string): EventOperation;
19
+ /** Inserts a slot at a specific position among existing slots */
20
+ export declare function insertSlot(index: number, slot: ProfileBadgeSlotInput | ProfileBadgeSlot): EventOperation;
21
+ /** Inserts a slot at the beginning */
22
+ export declare function prependSlot(slot: ProfileBadgeSlotInput | ProfileBadgeSlot): EventOperation;
23
+ /** Inserts a slot at the end */
24
+ export declare function appendSlot(slot: ProfileBadgeSlotInput | ProfileBadgeSlot): EventOperation;
25
+ /** Replaces the slot at a specific position with a new one */
26
+ export declare function setSlot(index: number, slot: ProfileBadgeSlotInput | ProfileBadgeSlot): EventOperation;