applesauce-common 6.2.0 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/casts/_circular-import.d.ts +3 -0
- package/dist/casts/_circular-import.js +3 -0
- package/dist/casts/app-handler.d.ts +56 -0
- package/dist/casts/app-handler.js +105 -0
- package/dist/casts/app-recommendation.d.ts +26 -0
- package/dist/casts/app-recommendation.js +41 -0
- package/dist/casts/external-identities.d.ts +9 -0
- package/dist/casts/external-identities.js +14 -0
- package/dist/casts/forum-thread.d.ts +17 -0
- package/dist/casts/forum-thread.js +31 -0
- package/dist/casts/git-issue.d.ts +18 -0
- package/dist/casts/git-issue.js +26 -0
- package/dist/casts/git-patch.d.ts +49 -0
- package/dist/casts/git-patch.js +88 -0
- package/dist/casts/git-pull-request.d.ts +67 -0
- package/dist/casts/git-pull-request.js +122 -0
- package/dist/casts/git-repository.d.ts +9 -0
- package/dist/casts/git-repository.js +16 -0
- package/dist/casts/git-thread.d.ts +33 -0
- package/dist/casts/git-thread.js +65 -0
- package/dist/casts/index.d.ts +12 -0
- package/dist/casts/index.js +12 -0
- package/dist/casts/napplet-handlers.d.ts +39 -0
- package/dist/casts/napplet-handlers.js +91 -0
- package/dist/casts/napplet.d.ts +98 -0
- package/dist/casts/napplet.js +196 -0
- package/dist/casts/note.d.ts +8 -0
- package/dist/casts/note.js +21 -1
- package/dist/casts/nsite.d.ts +134 -0
- package/dist/casts/nsite.js +249 -0
- package/dist/casts/profile.d.ts +20 -0
- package/dist/casts/profile.js +30 -0
- package/dist/casts/reaction.d.ts +1 -1
- package/dist/casts/relay-discovery.d.ts +4 -0
- package/dist/casts/relay-discovery.js +9 -1
- package/dist/casts/report.d.ts +28 -15
- package/dist/casts/report.js +42 -19
- package/dist/casts/share.d.ts +1 -1
- package/dist/casts/torrent.d.ts +5 -0
- package/dist/casts/torrent.js +8 -1
- package/dist/casts/trusted-assertions.d.ts +2 -0
- package/dist/casts/trusted-assertions.js +19 -18
- package/dist/casts/user-status.d.ts +33 -0
- package/dist/casts/user-status.js +69 -0
- package/dist/casts/user.d.ts +7 -0
- package/dist/casts/user.js +20 -1
- package/dist/factories/app-handler.d.ts +31 -0
- package/dist/factories/app-handler.js +50 -0
- package/dist/factories/app-recommendation.d.ts +21 -0
- package/dist/factories/app-recommendation.js +28 -0
- package/dist/factories/chat-message.d.ts +37 -0
- package/dist/factories/chat-message.js +56 -0
- package/dist/factories/comment.d.ts +8 -7
- package/dist/factories/comment.js +2 -2
- package/dist/factories/external-identities.d.ts +17 -0
- package/dist/factories/external-identities.js +28 -0
- package/dist/factories/file-message.d.ts +24 -0
- package/dist/factories/file-message.js +37 -0
- package/dist/factories/forum-thread.d.ts +34 -0
- package/dist/factories/forum-thread.js +50 -0
- package/dist/factories/git-applied-status.d.ts +39 -0
- package/dist/factories/git-applied-status.js +53 -0
- package/dist/factories/git-closed-status.d.ts +18 -0
- package/dist/factories/git-closed-status.js +24 -0
- package/dist/factories/git-draft-status.d.ts +18 -0
- package/dist/factories/git-draft-status.js +24 -0
- package/dist/factories/git-issue.d.ts +19 -0
- package/dist/factories/git-issue.js +25 -0
- package/dist/factories/git-open-status.d.ts +18 -0
- package/dist/factories/git-open-status.js +22 -0
- package/dist/factories/git-patch.d.ts +59 -0
- package/dist/factories/git-patch.js +102 -0
- package/dist/factories/git-pull-request-update.d.ts +23 -0
- package/dist/factories/git-pull-request-update.js +33 -0
- package/dist/factories/git-pull-request.d.ts +39 -0
- package/dist/factories/git-pull-request.js +64 -0
- package/dist/factories/index.d.ts +24 -0
- package/dist/factories/index.js +24 -0
- package/dist/factories/internal/git-pull-request.d.ts +19 -0
- package/dist/factories/internal/git-pull-request.js +26 -0
- package/dist/factories/internal/git-status.d.ts +11 -0
- package/dist/factories/internal/git-status.js +12 -0
- package/dist/factories/internal/git-thread.d.ts +19 -0
- package/dist/factories/internal/git-thread.js +29 -0
- package/dist/factories/internal/napplet-manifest.d.ts +52 -0
- package/dist/factories/internal/napplet-manifest.js +85 -0
- package/dist/factories/internal/nsite-manifest.d.ts +45 -0
- package/dist/factories/internal/nsite-manifest.js +68 -0
- package/dist/factories/legacy-message.d.ts +2 -0
- package/dist/factories/legacy-message.js +9 -2
- package/dist/factories/named-napplet.d.ts +20 -0
- package/dist/factories/named-napplet.js +30 -0
- package/dist/factories/named-nsite.d.ts +28 -0
- package/dist/factories/named-nsite.js +53 -0
- package/dist/factories/napplet-handlers.d.ts +34 -0
- package/dist/factories/napplet-handlers.js +77 -0
- package/dist/factories/napplet-snapshot.d.ts +18 -0
- package/dist/factories/napplet-snapshot.js +38 -0
- package/dist/factories/nsite-snapshot.d.ts +18 -0
- package/dist/factories/nsite-snapshot.js +29 -0
- package/dist/factories/reaction.d.ts +3 -2
- package/dist/factories/report.d.ts +48 -0
- package/dist/factories/report.js +66 -0
- package/dist/factories/root-napplet.d.ts +18 -0
- package/dist/factories/root-napplet.js +24 -0
- package/dist/factories/root-nsite.d.ts +23 -0
- package/dist/factories/root-nsite.js +44 -0
- package/dist/factories/torrent.d.ts +24 -10
- package/dist/factories/torrent.js +48 -44
- package/dist/factories/trusted-provider-list.d.ts +23 -0
- package/dist/factories/trusted-provider-list.js +39 -0
- package/dist/factories/user-status.d.ts +26 -0
- package/dist/factories/user-status.js +52 -0
- package/dist/factories/wrapped-message.js +10 -4
- package/dist/helpers/app-data.js +15 -7
- package/dist/helpers/app-handler.d.ts +43 -6
- package/dist/helpers/app-handler.js +53 -3
- package/dist/helpers/app-recommendation.d.ts +24 -0
- package/dist/helpers/app-recommendation.js +30 -0
- package/dist/helpers/bookmark.js +5 -2
- package/dist/helpers/comment.d.ts +11 -5
- package/dist/helpers/comment.js +7 -1
- package/dist/helpers/content.d.ts +3 -1
- package/dist/helpers/emoji-pack.js +11 -6
- package/dist/helpers/emoji.d.ts +2 -2
- package/dist/helpers/encrypted-content-cache.d.ts +2 -11
- package/dist/helpers/encrypted-content-cache.js +6 -14
- package/dist/helpers/encrypted-file.d.ts +41 -0
- package/dist/helpers/encrypted-file.js +64 -0
- package/dist/helpers/external-id.js +13 -19
- package/dist/helpers/external-identities.d.ts +29 -0
- package/dist/helpers/external-identities.js +52 -0
- package/dist/helpers/file-message.d.ts +18 -0
- package/dist/helpers/file-message.js +44 -0
- package/dist/helpers/file-metadata.d.ts +9 -4
- package/dist/helpers/file-metadata.js +21 -6
- package/dist/helpers/forum-thread.d.ts +10 -0
- package/dist/helpers/forum-thread.js +10 -0
- package/dist/helpers/gift-wrap.d.ts +40 -15
- package/dist/helpers/gift-wrap.js +110 -33
- package/dist/helpers/git-issue.d.ts +13 -0
- package/dist/helpers/git-issue.js +19 -0
- package/dist/helpers/git-patch.d.ts +41 -0
- package/dist/helpers/git-patch.js +73 -0
- package/dist/helpers/git-pull-request.d.ts +57 -0
- package/dist/helpers/git-pull-request.js +111 -0
- package/dist/helpers/git-repository.d.ts +4 -0
- package/dist/helpers/git-repository.js +16 -0
- package/dist/helpers/git-status.d.ts +44 -0
- package/dist/helpers/git-status.js +93 -0
- package/dist/helpers/git.d.ts +2 -0
- package/dist/helpers/git.js +4 -0
- package/dist/helpers/groups.d.ts +5 -2
- package/dist/helpers/groups.js +40 -18
- package/dist/helpers/hashtag.d.ts +4 -2
- package/dist/helpers/index.d.ts +13 -0
- package/dist/helpers/index.js +13 -0
- package/dist/helpers/lists.js +14 -2
- package/dist/helpers/lnurl.js +1 -1
- package/dist/helpers/messages.js +3 -2
- package/dist/helpers/mute.js +20 -9
- package/dist/helpers/napplet-handlers.d.ts +79 -0
- package/dist/helpers/napplet-handlers.js +187 -0
- package/dist/helpers/napplet.d.ts +107 -0
- package/dist/helpers/napplet.js +177 -0
- package/dist/helpers/nsite.d.ts +90 -0
- package/dist/helpers/nsite.js +217 -0
- package/dist/helpers/relay-discovery.d.ts +4 -0
- package/dist/helpers/relay-discovery.js +8 -0
- package/dist/helpers/reports.d.ts +35 -0
- package/dist/helpers/reports.js +36 -5
- package/dist/helpers/threading.d.ts +4 -2
- package/dist/helpers/torrent.d.ts +9 -6
- package/dist/helpers/torrent.js +23 -15
- package/dist/helpers/trusted-assertions.d.ts +7 -0
- package/dist/helpers/trusted-assertions.js +41 -2
- package/dist/helpers/user-status.d.ts +13 -1
- package/dist/helpers/user-status.js +15 -0
- package/dist/helpers/wrapped-messages.d.ts +2 -0
- package/dist/helpers/wrapped-messages.js +6 -1
- package/dist/models/app-handler.d.ts +21 -0
- package/dist/models/app-handler.js +47 -0
- package/dist/models/git.d.ts +34 -0
- package/dist/models/git.js +144 -0
- package/dist/models/index.d.ts +4 -0
- package/dist/models/index.js +4 -0
- package/dist/models/legacy-messages.js +6 -1
- package/dist/models/napplet-handlers.d.ts +16 -0
- package/dist/models/napplet-handlers.js +45 -0
- package/dist/models/nsite.d.ts +22 -0
- package/dist/models/nsite.js +67 -0
- package/dist/models/thread.d.ts +4 -1
- package/dist/models/thread.js +34 -5
- package/dist/models/user-status.d.ts +8 -4
- package/dist/models/user-status.js +16 -22
- package/dist/models/wrapped-messages.js +9 -7
- package/dist/observable/filter-timeline-by-mutes.d.ts +1 -1
- package/dist/observable/filter-timeline-by-mutes.js +6 -2
- package/dist/operations/app-handler.d.ts +24 -0
- package/dist/operations/app-handler.js +58 -0
- package/dist/operations/app-recommendation.d.ts +13 -0
- package/dist/operations/app-recommendation.js +40 -0
- package/dist/operations/calendar-event.js +3 -2
- package/dist/operations/chat-message.d.ts +9 -0
- package/dist/operations/chat-message.js +12 -0
- package/dist/operations/client.d.ts +1 -4
- package/dist/operations/client.js +1 -23
- package/dist/operations/comment.d.ts +9 -3
- package/dist/operations/comment.js +12 -9
- package/dist/operations/external-identities.d.ts +8 -0
- package/dist/operations/external-identities.js +23 -0
- package/dist/operations/file-message.d.ts +7 -0
- package/dist/operations/file-message.js +34 -0
- package/dist/operations/forum-thread.d.ts +3 -0
- package/dist/operations/forum-thread.js +6 -0
- package/dist/operations/gift-wrap.js +38 -14
- package/dist/operations/git-issue.d.ts +18 -0
- package/dist/operations/git-issue.js +31 -0
- package/dist/operations/git-patch.d.ts +30 -0
- package/dist/operations/git-patch.js +75 -0
- package/dist/operations/git-pull-request.d.ts +29 -0
- package/dist/operations/git-pull-request.js +74 -0
- package/dist/operations/git-repository.js +4 -4
- package/dist/operations/git-status.d.ts +28 -0
- package/dist/operations/git-status.js +116 -0
- package/dist/operations/git-thread.d.ts +13 -0
- package/dist/operations/git-thread.js +39 -0
- package/dist/operations/index.d.ts +17 -0
- package/dist/operations/index.js +17 -0
- package/dist/operations/internal/git-commits.d.ts +2 -0
- package/dist/operations/internal/git-commits.js +16 -0
- package/dist/operations/napplet-handlers.d.ts +47 -0
- package/dist/operations/napplet-handlers.js +161 -0
- package/dist/operations/napplet.d.ts +51 -0
- package/dist/operations/napplet.js +121 -0
- package/dist/operations/nsite.d.ts +51 -0
- package/dist/operations/nsite.js +112 -0
- package/dist/operations/reaction.d.ts +12 -2
- package/dist/operations/reaction.js +1 -1
- package/dist/operations/report.d.ts +33 -0
- package/dist/operations/report.js +60 -0
- package/dist/operations/stream.js +5 -4
- package/dist/operations/torrent.d.ts +1 -4
- package/dist/operations/torrent.js +24 -11
- package/dist/operations/trusted-providers.d.ts +14 -0
- package/dist/operations/trusted-providers.js +33 -0
- package/dist/operations/user-status.d.ts +11 -0
- package/dist/operations/user-status.js +29 -0
- package/dist/operations/wrapped-message.js +2 -2
- package/package.json +13 -17
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { sha256 } from "@noble/hashes/sha2.js";
|
|
2
|
+
import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
|
|
3
|
+
import { bytesToHex, getTagValue } from "applesauce-core/helpers/event";
|
|
4
|
+
import { decodePointer, getAddressPointerFromATag, npubEncode, } from "applesauce-core/helpers/pointers";
|
|
5
|
+
import { processTags } from "applesauce-core/helpers/tags";
|
|
6
|
+
import { isSha256 } from "./blossom.js";
|
|
7
|
+
/** The event kind for NIP-5A manifest snapshots */
|
|
8
|
+
export const NSITE_SNAPSHOT_KIND = 5128;
|
|
9
|
+
/** The event kind for NIP-5A root sites */
|
|
10
|
+
export const NSITE_ROOT_KIND = 15128;
|
|
11
|
+
/** The event kind for NIP-5A named sites */
|
|
12
|
+
export const NSITE_KIND = 35128;
|
|
13
|
+
/** All NIP-5A manifest kinds */
|
|
14
|
+
export const NSITE_KINDS = [NSITE_SNAPSHOT_KIND, NSITE_ROOT_KIND, NSITE_KIND];
|
|
15
|
+
const FilesSymbol = Symbol.for("nsite-files");
|
|
16
|
+
const ServersSymbol = Symbol.for("nsite-servers");
|
|
17
|
+
const AppsSymbol = Symbol.for("nsite-apps");
|
|
18
|
+
const HashSymbol = Symbol.for("nsite-aggregate-hash");
|
|
19
|
+
/** Checks if an identifier fits the canonical named-site DNS label */
|
|
20
|
+
export function isValidNsiteIdentifier(identifier) {
|
|
21
|
+
return /^[a-z0-9-]{1,13}$/.test(identifier) && !identifier.endsWith("-");
|
|
22
|
+
}
|
|
23
|
+
/** Checks if a path is absolute and ends in a filename with an extension */
|
|
24
|
+
export function isValidNsitePath(path) {
|
|
25
|
+
return (/^\/(?:[^\r\n?#\\/]+\/)*[^\r\n?#\\/]+\.[^\r\n?#\\/.]+$/u.test(path) &&
|
|
26
|
+
!path.split("/").some((part) => part === "." || part === ".."));
|
|
27
|
+
}
|
|
28
|
+
/** Checks if an address pointer references a root or named site */
|
|
29
|
+
export function isNsiteAddressPointer(pointer) {
|
|
30
|
+
return (isSha256(pointer.pubkey) &&
|
|
31
|
+
((pointer.kind === NSITE_ROOT_KIND && pointer.identifier === "") ||
|
|
32
|
+
(pointer.kind === NSITE_KIND && isValidNsiteIdentifier(pointer.identifier))));
|
|
33
|
+
}
|
|
34
|
+
/** Checks if an event is a root site */
|
|
35
|
+
export function isRootNsite(event) {
|
|
36
|
+
return event?.kind === NSITE_ROOT_KIND;
|
|
37
|
+
}
|
|
38
|
+
/** Checks if an event is a named site */
|
|
39
|
+
export function isNamedNsite(event) {
|
|
40
|
+
return event?.kind === NSITE_KIND;
|
|
41
|
+
}
|
|
42
|
+
/** Checks if an event is a manifest snapshot */
|
|
43
|
+
export function isNsiteSnapshot(event) {
|
|
44
|
+
return event?.kind === NSITE_SNAPSHOT_KIND;
|
|
45
|
+
}
|
|
46
|
+
function lineagePointer(event, name) {
|
|
47
|
+
const tag = event.tags.find((t) => t[0] === name);
|
|
48
|
+
const pointer = tag && /^(15128|35128):[0-9a-f]{64}:/.test(tag[1] ?? "") && getAddressPointerFromATag(tag);
|
|
49
|
+
return pointer && isNsiteAddressPointer(pointer) ? pointer : undefined;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Checks if an event is a valid NIP-5A manifest
|
|
53
|
+
* @see https://github.com/nostr-protocol/nips/blob/master/5A.md
|
|
54
|
+
*/
|
|
55
|
+
export function isValidNsite(event) {
|
|
56
|
+
if (!event || !NSITE_KINDS.includes(event.kind))
|
|
57
|
+
return false;
|
|
58
|
+
const paths = event.tags.filter((t) => t[0] === "path");
|
|
59
|
+
if (!paths.length || paths.some((t) => t.length !== 3 || !isValidNsitePath(t[1]) || !isSha256(t[2])))
|
|
60
|
+
return false;
|
|
61
|
+
const d = event.tags.filter((t) => t[0] === "d");
|
|
62
|
+
if (isNamedNsite(event) ? d.length !== 1 || !isValidNsiteIdentifier(d[0][1] ?? "") : d.length !== 0)
|
|
63
|
+
return false;
|
|
64
|
+
const x = event.tags.filter((t) => t[0] === "x");
|
|
65
|
+
if (x.length > 1 || x.some((t) => t.length !== 3 || !isSha256(t[1]) || t[2] !== "aggregate"))
|
|
66
|
+
return false;
|
|
67
|
+
const a = event.tags.filter((t) => t[0] === "a");
|
|
68
|
+
const A = event.tags.filter((t) => t[0] === "A");
|
|
69
|
+
if (a.length > 1 ||
|
|
70
|
+
A.length > 1 ||
|
|
71
|
+
(a.length && !getNsiteParentPointer(event)) ||
|
|
72
|
+
(A.length && !getNsiteRootPointer(event)))
|
|
73
|
+
return false;
|
|
74
|
+
if (isNsiteSnapshot(event))
|
|
75
|
+
return x.length === 1 && a.length === 1;
|
|
76
|
+
return a.length === A.length;
|
|
77
|
+
}
|
|
78
|
+
/** Checks if an event is a valid root site */
|
|
79
|
+
export function isValidRootNsite(event) {
|
|
80
|
+
return isRootNsite(event) && isValidNsite(event);
|
|
81
|
+
}
|
|
82
|
+
/** Checks if an event is a valid named site */
|
|
83
|
+
export function isValidNamedNsite(event) {
|
|
84
|
+
return isNamedNsite(event) && isValidNsite(event);
|
|
85
|
+
}
|
|
86
|
+
/** Checks if an event is a valid manifest snapshot */
|
|
87
|
+
export function isValidNsiteSnapshot(event) {
|
|
88
|
+
return isNsiteSnapshot(event) && isValidNsite(event);
|
|
89
|
+
}
|
|
90
|
+
/** Returns the named site's identifier */
|
|
91
|
+
export function getNsiteIdentifier(event) {
|
|
92
|
+
return isNamedNsite(event) ? getTagValue(event, "d") : undefined;
|
|
93
|
+
}
|
|
94
|
+
/** Returns the site's display title */
|
|
95
|
+
export function getNsiteTitle(event) {
|
|
96
|
+
return getTagValue(event, "title");
|
|
97
|
+
}
|
|
98
|
+
/** Returns the site's description tag */
|
|
99
|
+
export function getNsiteDescription(event) {
|
|
100
|
+
return getTagValue(event, "description");
|
|
101
|
+
}
|
|
102
|
+
/** Returns the site's source repository or archive URL */
|
|
103
|
+
export function getNsiteSource(event) {
|
|
104
|
+
return getTagValue(event, "source");
|
|
105
|
+
}
|
|
106
|
+
/** Returns the valid file mappings from the manifest */
|
|
107
|
+
export function getNsiteFiles(event) {
|
|
108
|
+
return getOrComputeCachedValue(event, FilesSymbol, () => processTags(event.tags, (t) => t[0] === "path" && t.length === 3 && isValidNsitePath(t[1]) && isSha256(t[2])
|
|
109
|
+
? { path: t[1], sha256: t[2] }
|
|
110
|
+
: undefined));
|
|
111
|
+
}
|
|
112
|
+
/** Returns the Blossom server hints */
|
|
113
|
+
export function getNsiteServers(event) {
|
|
114
|
+
return getOrComputeCachedValue(event, ServersSymbol, () => processTags(event.tags, (t) => (t[0] === "server" && t[1] ? t[1] : undefined)));
|
|
115
|
+
}
|
|
116
|
+
/** Returns the upstream addressable app descriptor pointers */
|
|
117
|
+
export function getNsiteAppPointers(event) {
|
|
118
|
+
return getOrComputeCachedValue(event, AppsSymbol, () => processTags(event.tags, (t) => {
|
|
119
|
+
if (t[0] !== "app" || !t[1])
|
|
120
|
+
return undefined;
|
|
121
|
+
const pointer = getAddressPointerFromATag(t);
|
|
122
|
+
return pointer && pointer.kind >= 30000 && pointer.kind < 40000 ? pointer : undefined;
|
|
123
|
+
}));
|
|
124
|
+
}
|
|
125
|
+
/** Returns the immediate parent site address */
|
|
126
|
+
export function getNsiteParentPointer(event) {
|
|
127
|
+
return lineagePointer(event, "a");
|
|
128
|
+
}
|
|
129
|
+
/** Returns the origin site address of a copy lineage */
|
|
130
|
+
export function getNsiteRootPointer(event) {
|
|
131
|
+
return lineagePointer(event, "A");
|
|
132
|
+
}
|
|
133
|
+
/** Returns the advertised aggregate hash */
|
|
134
|
+
export function getNsiteAggregateHash(event) {
|
|
135
|
+
const tag = event.tags.find((t) => t[0] === "x" && t[2] === "aggregate");
|
|
136
|
+
return tag?.[1] && isSha256(tag[1]) ? tag[1] : undefined;
|
|
137
|
+
}
|
|
138
|
+
/** Returns the deterministic SHA-256 of all path tags, including duplicates */
|
|
139
|
+
export function computeNsiteAggregateHash(manifest) {
|
|
140
|
+
const lines = manifest.tags
|
|
141
|
+
.filter((t) => t[0] === "path")
|
|
142
|
+
.map(([, path, hash]) => `${hash} ${path}\n`)
|
|
143
|
+
.sort()
|
|
144
|
+
.join("");
|
|
145
|
+
return bytesToHex(sha256(new TextEncoder().encode(lines)));
|
|
146
|
+
}
|
|
147
|
+
/** Returns the cached computed aggregate hash of a manifest */
|
|
148
|
+
export function getComputedNsiteAggregateHash(event) {
|
|
149
|
+
return getOrComputeCachedValue(event, HashSymbol, () => computeNsiteAggregateHash(event));
|
|
150
|
+
}
|
|
151
|
+
/** Checks if the advertised aggregate hash matches the manifest's path tags */
|
|
152
|
+
export function verifyNsiteAggregateHash(event) {
|
|
153
|
+
return getNsiteAggregateHash(event) === getComputedNsiteAggregateHash(event);
|
|
154
|
+
}
|
|
155
|
+
/** Resolves a request path with index.html and 404.html fallbacks */
|
|
156
|
+
export function resolveNsitePath(event, path) {
|
|
157
|
+
if (!path.startsWith("/"))
|
|
158
|
+
return undefined;
|
|
159
|
+
const file = path.split("/").at(-1);
|
|
160
|
+
const resolved = file.includes(".") ? path : `${path.replace(/\/$/, "")}/index.html`;
|
|
161
|
+
const files = getNsiteFiles(event);
|
|
162
|
+
return files.find((f) => f.path === resolved) ?? files.find((f) => f.path === "/404.html");
|
|
163
|
+
}
|
|
164
|
+
function decodeBase36(value) {
|
|
165
|
+
let n = 0n;
|
|
166
|
+
for (const char of value)
|
|
167
|
+
n = n * 36n + BigInt(parseInt(char, 36));
|
|
168
|
+
const hex = n.toString(16);
|
|
169
|
+
return hex.length <= 64 ? hex.padStart(64, "0") : undefined;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Returns the canonical DNS label for an nsite manifest
|
|
173
|
+
* @throws if the manifest is invalid
|
|
174
|
+
*/
|
|
175
|
+
export function getNsiteHostLabel(event) {
|
|
176
|
+
if (!isValidNsite(event))
|
|
177
|
+
throw new Error("Invalid nsite manifest");
|
|
178
|
+
if (isRootNsite(event))
|
|
179
|
+
return npubEncode(event.pubkey);
|
|
180
|
+
const hex = isNsiteSnapshot(event) ? event.id : event.pubkey;
|
|
181
|
+
// Fixed width preserves leading-zero keys and the specification's 50-character routing boundary.
|
|
182
|
+
const value = BigInt(`0x${hex}`).toString(36).padStart(50, "0");
|
|
183
|
+
return isNsiteSnapshot(event) ? `v${value}` : `${value}${getNsiteIdentifier(event)}`;
|
|
184
|
+
}
|
|
185
|
+
/** Parses a canonical nsite DNS label into a site or snapshot pointer */
|
|
186
|
+
export function parseNsiteHostLabel(label) {
|
|
187
|
+
if (label.startsWith("npub1")) {
|
|
188
|
+
try {
|
|
189
|
+
const decoded = decodePointer(label);
|
|
190
|
+
return decoded.type === "npub" ? { kind: NSITE_ROOT_KIND, pubkey: decoded.data, identifier: "" } : undefined;
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
return undefined;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (/^v[0-9a-z]{50}$/.test(label)) {
|
|
197
|
+
const id = decodeBase36(label.slice(1));
|
|
198
|
+
return id ? { id } : undefined;
|
|
199
|
+
}
|
|
200
|
+
if (/^[0-9a-z]{50}[a-z0-9-]{1,13}$/.test(label) && !label.endsWith("-")) {
|
|
201
|
+
const pubkey = decodeBase36(label.slice(0, 50));
|
|
202
|
+
return pubkey ? { kind: NSITE_KIND, pubkey, identifier: label.slice(50) } : undefined;
|
|
203
|
+
}
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Returns a site's URL on an nsite host
|
|
208
|
+
* @throws if the manifest or host URL is invalid
|
|
209
|
+
*/
|
|
210
|
+
export function getNsiteURL(event, host) {
|
|
211
|
+
const url = new URL(typeof host === "string" && !host.includes("://") ? `https://${host}` : host);
|
|
212
|
+
url.hostname = `${getNsiteHostLabel(event)}.${url.hostname}`;
|
|
213
|
+
url.pathname = "/";
|
|
214
|
+
url.search = "";
|
|
215
|
+
url.hash = "";
|
|
216
|
+
return url;
|
|
217
|
+
}
|
|
@@ -20,6 +20,8 @@ export declare function getRelayDiscoveryRTT(event: NostrEvent, type: "open" | "
|
|
|
20
20
|
* Should be one of: clearnet, tor, i2p, loki
|
|
21
21
|
*/
|
|
22
22
|
export declare function getRelayDiscoveryNetworkType(event: NostrEvent): string | undefined;
|
|
23
|
+
/** Gets all relay types from a relay discovery event (from `T` tags), e.g. `PublicOutbox` */
|
|
24
|
+
export declare function getRelayDiscoveryTypes(event: NostrEvent): string[];
|
|
23
25
|
/**
|
|
24
26
|
* Gets all relay attributes from a relay discovery event (from `W` tags)
|
|
25
27
|
* Attributes describe the relay type/characteristics
|
|
@@ -51,6 +53,8 @@ export declare function getRelayDiscoveryAcceptedKinds(event: NostrEvent): strin
|
|
|
51
53
|
* This is a NIP-52 geohash
|
|
52
54
|
*/
|
|
53
55
|
export declare function getRelayDiscoveryGeohash(event: NostrEvent): string | undefined;
|
|
56
|
+
/** Gets all geohashes from a relay discovery event (from `g` tags) */
|
|
57
|
+
export declare function getRelayDiscoveryGeohashes(event: NostrEvent): string[];
|
|
54
58
|
/**
|
|
55
59
|
* Validates that an event is a proper relay discovery event
|
|
56
60
|
* Checks that the event is kind 30166 and has the required `d` tag
|
|
@@ -26,6 +26,10 @@ export function getRelayDiscoveryRTT(event, type) {
|
|
|
26
26
|
export function getRelayDiscoveryNetworkType(event) {
|
|
27
27
|
return getTagValue(event, "n");
|
|
28
28
|
}
|
|
29
|
+
/** Gets all relay types from a relay discovery event (from `T` tags), e.g. `PublicOutbox` */
|
|
30
|
+
export function getRelayDiscoveryTypes(event) {
|
|
31
|
+
return event.tags.filter((t) => t[0] === "T" && t[1]).map((t) => t[1]);
|
|
32
|
+
}
|
|
29
33
|
/**
|
|
30
34
|
* Gets all relay attributes from a relay discovery event (from `W` tags)
|
|
31
35
|
* Attributes describe the relay type/characteristics
|
|
@@ -69,6 +73,10 @@ export function getRelayDiscoveryAcceptedKinds(event) {
|
|
|
69
73
|
export function getRelayDiscoveryGeohash(event) {
|
|
70
74
|
return getTagValue(event, "g");
|
|
71
75
|
}
|
|
76
|
+
/** Gets all geohashes from a relay discovery event (from `g` tags) */
|
|
77
|
+
export function getRelayDiscoveryGeohashes(event) {
|
|
78
|
+
return event.tags.filter((t) => t[0] === "g" && t[1]).map((t) => t[1]);
|
|
79
|
+
}
|
|
72
80
|
/**
|
|
73
81
|
* Validates that an event is a proper relay discovery event
|
|
74
82
|
* Checks that the event is kind 30166 and has the required `d` tag
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
+
/** The NIP-56 report event kind */
|
|
3
|
+
export declare const REPORT_KIND = 1984;
|
|
4
|
+
/** The cache key for the legacy report projection */
|
|
2
5
|
export declare const ParsedReportSymbol: unique symbol;
|
|
6
|
+
/** The standard NIP-56 report categories */
|
|
3
7
|
export declare enum ReportReason {
|
|
4
8
|
nudity = "nudity",
|
|
5
9
|
malware = "malware",
|
|
@@ -9,23 +13,54 @@ export declare enum ReportReason {
|
|
|
9
13
|
impersonation = "impersonation",
|
|
10
14
|
other = "other"
|
|
11
15
|
}
|
|
16
|
+
/** A user report with its source event */
|
|
12
17
|
export type ReportedUser = {
|
|
18
|
+
/** The report category */
|
|
13
19
|
type: "user";
|
|
20
|
+
/** The source report */
|
|
14
21
|
event: NostrEvent;
|
|
22
|
+
/** The reported public key */
|
|
15
23
|
pubkey: string;
|
|
24
|
+
/** The report reason */
|
|
16
25
|
reason?: ReportReason;
|
|
26
|
+
/** The reporter's explanation */
|
|
17
27
|
comment?: string;
|
|
18
28
|
};
|
|
29
|
+
/** An event report with its source event */
|
|
19
30
|
export type ReportedEvent = {
|
|
31
|
+
/** The report category */
|
|
20
32
|
type: "event";
|
|
33
|
+
/** The source report */
|
|
21
34
|
event: NostrEvent;
|
|
35
|
+
/** The reporter's explanation */
|
|
22
36
|
comment?: string;
|
|
37
|
+
/** The reported event ID */
|
|
23
38
|
id: string;
|
|
39
|
+
/** The reported public key */
|
|
24
40
|
pubkey: string;
|
|
41
|
+
/** The report reason */
|
|
25
42
|
reason?: ReportReason;
|
|
43
|
+
/** The reported blob hashes */
|
|
26
44
|
blobs?: string[];
|
|
27
45
|
};
|
|
28
46
|
/** Reads a report event as either a user or event report */
|
|
29
47
|
export declare function getReported(report: NostrEvent): ReportedEvent | ReportedUser | null;
|
|
30
48
|
/** Gets the server tags from a report event (for blob reports) */
|
|
31
49
|
export declare function getReportServers(report: NostrEvent): string[];
|
|
50
|
+
/** A target explicitly assigned a report reason */
|
|
51
|
+
export type ReportTarget = {
|
|
52
|
+
/** The target category */
|
|
53
|
+
type: "user" | "event" | "blob";
|
|
54
|
+
/** The public key, event ID, or blob hash */
|
|
55
|
+
value: string;
|
|
56
|
+
/** The report category for this target */
|
|
57
|
+
reason: ReportReason;
|
|
58
|
+
};
|
|
59
|
+
/** Checks whether a value is a lowercase 32-byte hex identifier */
|
|
60
|
+
export declare function isReportIdentifier(value: string | undefined): value is string;
|
|
61
|
+
/** Returns all explicitly reported targets and their individual reasons */
|
|
62
|
+
export declare function getReportTargets(event: NostrEvent): ReportTarget[];
|
|
63
|
+
/** Checks whether an event has NIP-56 targets and required context tags */
|
|
64
|
+
export declare function isValidReport(event: NostrEvent): event is NostrEvent & {
|
|
65
|
+
kind: typeof REPORT_KIND;
|
|
66
|
+
};
|
package/dist/helpers/reports.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
|
|
2
2
|
import { isETag, isNameValueTag, isPTag } from "applesauce-core/helpers/tags";
|
|
3
|
+
/** The NIP-56 report event kind */
|
|
4
|
+
export const REPORT_KIND = 1984;
|
|
5
|
+
/** The cache key for the legacy report projection */
|
|
3
6
|
export const ParsedReportSymbol = Symbol("parsed-report");
|
|
7
|
+
/** The standard NIP-56 report categories */
|
|
4
8
|
export var ReportReason;
|
|
5
9
|
(function (ReportReason) {
|
|
6
10
|
ReportReason["nudity"] = "nudity";
|
|
@@ -13,30 +17,57 @@ export var ReportReason;
|
|
|
13
17
|
})(ReportReason || (ReportReason = {}));
|
|
14
18
|
/** Reads a report event as either a user or event report */
|
|
15
19
|
export function getReported(report) {
|
|
20
|
+
if (report.kind !== REPORT_KIND)
|
|
21
|
+
return null;
|
|
16
22
|
return getOrComputeCachedValue(report, ParsedReportSymbol, () => {
|
|
17
|
-
const pTag = report.tags.find(isPTag);
|
|
23
|
+
const pTag = report.tags.find((t) => isPTag(t) && isReportIdentifier(t[1]));
|
|
18
24
|
if (!pTag)
|
|
19
25
|
return null;
|
|
20
26
|
const comment = report.content ? report.content.trim() : undefined;
|
|
21
|
-
const eTag = report.tags.find(isETag);
|
|
27
|
+
const eTag = report.tags.find((t) => isETag(t) && isReportIdentifier(t[1]));
|
|
22
28
|
// Event report
|
|
23
29
|
if (eTag) {
|
|
24
|
-
const blobs = report.tags.filter((t) => t[0] === "x" && t[1]).map((t) => t[1]);
|
|
30
|
+
const blobs = report.tags.filter((t) => t[0] === "x" && isReportIdentifier(t[1])).map((t) => t[1]);
|
|
25
31
|
return {
|
|
26
32
|
type: "event",
|
|
27
33
|
event: report,
|
|
28
34
|
comment,
|
|
29
35
|
id: eTag[1],
|
|
30
36
|
pubkey: pTag[1],
|
|
31
|
-
reason: eTag[2],
|
|
37
|
+
reason: parseReason(eTag[2]) ?? getReportTargets(report).find((t) => t.type === "blob")?.reason,
|
|
32
38
|
blobs,
|
|
33
39
|
};
|
|
34
40
|
}
|
|
35
41
|
// User report
|
|
36
|
-
return { type: "user", event: report, comment, pubkey: pTag[1], reason: pTag[2] };
|
|
42
|
+
return { type: "user", event: report, comment, pubkey: pTag[1], reason: parseReason(pTag[2]) };
|
|
37
43
|
});
|
|
38
44
|
}
|
|
39
45
|
/** Gets the server tags from a report event (for blob reports) */
|
|
40
46
|
export function getReportServers(report) {
|
|
41
47
|
return report.tags.filter((t) => isNameValueTag(t, "server") && t[1]).map((t) => t[1]);
|
|
42
48
|
}
|
|
49
|
+
/** Checks whether a value is a lowercase 32-byte hex identifier */
|
|
50
|
+
export function isReportIdentifier(value) {
|
|
51
|
+
return typeof value === "string" && /^[0-9a-f]{64}$/.test(value);
|
|
52
|
+
}
|
|
53
|
+
function parseReason(value) {
|
|
54
|
+
return Object.values(ReportReason).includes(value) ? value : undefined;
|
|
55
|
+
}
|
|
56
|
+
/** Returns all explicitly reported targets and their individual reasons */
|
|
57
|
+
export function getReportTargets(event) {
|
|
58
|
+
if (event.kind !== REPORT_KIND)
|
|
59
|
+
return [];
|
|
60
|
+
return event.tags.flatMap((tag) => {
|
|
61
|
+
const type = tag[0] === "p" ? "user" : tag[0] === "e" ? "event" : tag[0] === "x" ? "blob" : undefined;
|
|
62
|
+
const reason = parseReason(tag[2]);
|
|
63
|
+
return type && isReportIdentifier(tag[1]) && reason ? [{ type, value: tag[1], reason }] : [];
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/** Checks whether an event has NIP-56 targets and required context tags */
|
|
67
|
+
export function isValidReport(event) {
|
|
68
|
+
if (event.kind !== REPORT_KIND || !event.tags.some((t) => isPTag(t) && isReportIdentifier(t[1])))
|
|
69
|
+
return false;
|
|
70
|
+
const targets = getReportTargets(event);
|
|
71
|
+
return (targets.length > 0 &&
|
|
72
|
+
(!targets.some((t) => t.type === "blob") || event.tags.some((t) => isETag(t) && isReportIdentifier(t[1]))));
|
|
73
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
2
2
|
import { AddressPointer, EventPointer } from "applesauce-core/helpers/pointers";
|
|
3
3
|
export type ThreadReferences = {
|
|
4
4
|
root?: {
|
|
@@ -52,4 +52,6 @@ export declare function interpretThreadTags(tags: string[][]): {
|
|
|
52
52
|
};
|
|
53
53
|
};
|
|
54
54
|
/** Returns the parsed NIP-10 tags for an event */
|
|
55
|
-
export declare function getNip10References
|
|
55
|
+
export declare function getNip10References<E extends {
|
|
56
|
+
tags: string[][];
|
|
57
|
+
} = NostrEvent>(event: E): ThreadReferences;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
+
/** The NIP-35 torrent event kind */
|
|
2
3
|
export declare const TORRENT_KIND = 2003;
|
|
3
4
|
/** Type for validated torrent events */
|
|
4
5
|
export type TorrentEvent = KnownEvent<typeof TORRENT_KIND>;
|
|
@@ -26,6 +27,7 @@ export type TorrentExternalIdentifier = {
|
|
|
26
27
|
export declare function getTorrentInfoHash(torrent: TorrentEvent): string;
|
|
27
28
|
export declare function getTorrentInfoHash(torrent: NostrEvent): string | undefined;
|
|
28
29
|
/** Returns the torrent title from the `title` tag */
|
|
30
|
+
export declare function getTorrentTitle(torrent: TorrentEvent): string | undefined;
|
|
29
31
|
export declare function getTorrentTitle(torrent: NostrEvent): string | undefined;
|
|
30
32
|
/** Returns all file entries from `file` tags */
|
|
31
33
|
export declare function getTorrentFiles(torrent: NostrEvent): TorrentFile[];
|
|
@@ -37,19 +39,20 @@ export declare function getTorrentCategory(torrent: NostrEvent): number | undefi
|
|
|
37
39
|
export declare function getTorrentSearchTags(torrent: NostrEvent): string[];
|
|
38
40
|
/** Returns the category path from the `tcat` identifier in `i` tags (e.g., "video,movie,4k") */
|
|
39
41
|
export declare function getTorrentCategoryPath(torrent: NostrEvent): string | undefined;
|
|
42
|
+
/** Returns the `tcat` category path split into its parts (e.g., ["video", "movie", "4k"]) */
|
|
43
|
+
export declare function getTorrentCategoryPathParts(torrent: NostrEvent): string[];
|
|
40
44
|
/** Returns all external identifiers from `i` tags (excluding tcat and newznab, which are handled separately) */
|
|
41
45
|
export declare function getTorrentExternalIdentifiers(torrent: NostrEvent): TorrentExternalIdentifier[];
|
|
42
|
-
/**
|
|
43
|
-
* Creates a TorrentExternalIdentifier object from prefix, id, and optional mediaType
|
|
44
|
-
* Automatically constructs the full identifier string
|
|
45
|
-
*/
|
|
46
|
+
/** Creates a TorrentExternalIdentifier and builds its full identifier string */
|
|
46
47
|
export declare function createTorrentExternalIdentifier(prefix: TorrentExternalIdentifierPrefix, id: string, mediaType?: string): TorrentExternalIdentifier;
|
|
47
48
|
/**
|
|
48
49
|
* Builds a magnet link from an info hash, optional trackers, and optional name
|
|
49
|
-
*
|
|
50
|
+
* @see https://www.bittorrent.org/beps/bep_0053.html
|
|
50
51
|
*/
|
|
51
52
|
export declare function buildTorrentMagnetLink(infoHash: string, trackers?: string[], name?: string): string;
|
|
52
53
|
/** Returns the magnet link for a torrent, building it from the event if needed */
|
|
53
54
|
export declare function getTorrentMagnetLink(torrent: NostrEvent): string | undefined;
|
|
54
|
-
/**
|
|
55
|
+
/** Checks if a string is a hex encoded V1 BitTorrent info hash */
|
|
56
|
+
export declare function isTorrentInfoHash(hash: string): boolean;
|
|
57
|
+
/** Checks if an event is a valid torrent event (kind 2003 with a V1 info hash in the `x` tag) */
|
|
55
58
|
export declare function isValidTorrent(torrent: NostrEvent): torrent is TorrentEvent;
|
package/dist/helpers/torrent.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
|
|
2
2
|
import { getTagValue } from "applesauce-core/helpers/event";
|
|
3
|
+
/** The NIP-35 torrent event kind */
|
|
3
4
|
export const TORRENT_KIND = 2003;
|
|
4
5
|
const TorrentInfoHashSymbol = Symbol.for("torrent-info-hash");
|
|
5
6
|
const TorrentTitleSymbol = Symbol.for("torrent-title");
|
|
@@ -17,7 +18,6 @@ export function getTorrentInfoHash(torrent) {
|
|
|
17
18
|
return getTagValue(torrent, "x");
|
|
18
19
|
});
|
|
19
20
|
}
|
|
20
|
-
/** Returns the torrent title from the `title` tag */
|
|
21
21
|
export function getTorrentTitle(torrent) {
|
|
22
22
|
if (torrent.kind !== TORRENT_KIND)
|
|
23
23
|
return undefined;
|
|
@@ -104,13 +104,17 @@ export function getTorrentCategoryPath(torrent) {
|
|
|
104
104
|
return undefined;
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
|
-
/**
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
107
|
+
/** Returns the `tcat` category path split into its parts (e.g., ["video", "movie", "4k"]) */
|
|
108
|
+
export function getTorrentCategoryPathParts(torrent) {
|
|
109
|
+
const path = getTorrentCategoryPath(torrent);
|
|
110
|
+
if (!path)
|
|
111
|
+
return [];
|
|
112
|
+
return path
|
|
113
|
+
.split(",")
|
|
114
|
+
.map((part) => part.trim())
|
|
115
|
+
.filter(Boolean);
|
|
116
|
+
}
|
|
117
|
+
// Parses tmdb, ttvdb, imdb, mal and anilist identifiers; tcat and newznab are handled by their own getters
|
|
114
118
|
function parseTorrentExternalIdentifier(value) {
|
|
115
119
|
// Skip tcat - it's handled separately as a category path
|
|
116
120
|
if (value.startsWith("tcat:"))
|
|
@@ -213,10 +217,7 @@ export function getTorrentExternalIdentifiers(torrent) {
|
|
|
213
217
|
return identifiers;
|
|
214
218
|
});
|
|
215
219
|
}
|
|
216
|
-
/**
|
|
217
|
-
* Creates a TorrentExternalIdentifier object from prefix, id, and optional mediaType
|
|
218
|
-
* Automatically constructs the full identifier string
|
|
219
|
-
*/
|
|
220
|
+
/** Creates a TorrentExternalIdentifier and builds its full identifier string */
|
|
220
221
|
export function createTorrentExternalIdentifier(prefix, id, mediaType) {
|
|
221
222
|
let identifier;
|
|
222
223
|
// Build identifier string based on prefix and whether mediaType is provided
|
|
@@ -237,7 +238,7 @@ export function createTorrentExternalIdentifier(prefix, id, mediaType) {
|
|
|
237
238
|
}
|
|
238
239
|
/**
|
|
239
240
|
* Builds a magnet link from an info hash, optional trackers, and optional name
|
|
240
|
-
*
|
|
241
|
+
* @see https://www.bittorrent.org/beps/bep_0053.html
|
|
241
242
|
*/
|
|
242
243
|
export function buildTorrentMagnetLink(infoHash, trackers, name) {
|
|
243
244
|
const parts = [`magnet:?xt=urn:btih:${infoHash}`];
|
|
@@ -264,7 +265,14 @@ export function getTorrentMagnetLink(torrent) {
|
|
|
264
265
|
return buildTorrentMagnetLink(infoHash, trackers.length > 0 ? trackers : undefined, title);
|
|
265
266
|
});
|
|
266
267
|
}
|
|
267
|
-
/**
|
|
268
|
+
/** Checks if a string is a hex encoded V1 BitTorrent info hash */
|
|
269
|
+
export function isTorrentInfoHash(hash) {
|
|
270
|
+
return /^[0-9a-f]{40}$/i.test(hash);
|
|
271
|
+
}
|
|
272
|
+
/** Checks if an event is a valid torrent event (kind 2003 with a V1 info hash in the `x` tag) */
|
|
268
273
|
export function isValidTorrent(torrent) {
|
|
269
|
-
|
|
274
|
+
if (torrent.kind !== TORRENT_KIND)
|
|
275
|
+
return false;
|
|
276
|
+
const infoHash = getTorrentInfoHash(torrent);
|
|
277
|
+
return infoHash !== undefined && isTorrentInfoHash(infoHash);
|
|
270
278
|
}
|
|
@@ -2,6 +2,11 @@ import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
|
|
|
2
2
|
import { HiddenContentSigner } from "applesauce-core/helpers/hidden-content";
|
|
3
3
|
export declare const TRUSTED_PROVIDER_LIST_KIND = 10040;
|
|
4
4
|
export declare const USER_ASSERTION_KIND = 30382;
|
|
5
|
+
export declare const EVENT_ASSERTION_KIND = 30383;
|
|
6
|
+
export declare const ADDRESS_ASSERTION_KIND = 30384;
|
|
7
|
+
export declare const IDENTIFIER_ASSERTION_KIND = 30385;
|
|
8
|
+
/** The result tags defined by NIP-85 for each assertion kind */
|
|
9
|
+
export declare const TRUSTED_ASSERTION_TAGS: Record<number, string[]>;
|
|
5
10
|
export type TrustedProviderListEvent = KnownEvent<typeof TRUSTED_PROVIDER_LIST_KIND>;
|
|
6
11
|
export type UserAssertionEvent = KnownEvent<typeof USER_ASSERTION_KIND>;
|
|
7
12
|
/** A parsed trusted provider declaration from a kind 10040 event */
|
|
@@ -28,6 +33,8 @@ export declare function isValidTrustedProviderList(event: NostrEvent): event is
|
|
|
28
33
|
* Tag format: ["<kind>:<tag>", "<servicePubkey>", "<relayHint?>"]
|
|
29
34
|
*/
|
|
30
35
|
export declare function parseProviderTag(tag: string[]): TrustedProvider | undefined;
|
|
36
|
+
/** Creates a kind 10040 provider tag from a {@link TrustedProvider} */
|
|
37
|
+
export declare function createProviderTag(provider: TrustedProvider): string[];
|
|
31
38
|
/** Returns all public trusted providers from a kind 10040 event */
|
|
32
39
|
export declare function getPublicProviders(event: NostrEvent): TrustedProvider[];
|
|
33
40
|
/** Returns hidden trusted providers if the event is unlocked */
|
|
@@ -1,9 +1,38 @@
|
|
|
1
1
|
import { getOrComputeCachedValue, notifyEventUpdate } from "applesauce-core/helpers";
|
|
2
|
+
import { setCachedValue } from "applesauce-core/helpers/cache";
|
|
2
3
|
import { getTagValue } from "applesauce-core/helpers/event";
|
|
3
4
|
import { getHiddenTags, isHiddenTagsUnlocked, setHiddenTagsEncryptionMethod, unlockHiddenTags, } from "applesauce-core/helpers/hidden-tags";
|
|
4
5
|
// NIP-85 Trusted Assertions Kinds
|
|
5
6
|
export const TRUSTED_PROVIDER_LIST_KIND = 10040;
|
|
6
7
|
export const USER_ASSERTION_KIND = 30382;
|
|
8
|
+
export const EVENT_ASSERTION_KIND = 30383;
|
|
9
|
+
export const ADDRESS_ASSERTION_KIND = 30384;
|
|
10
|
+
export const IDENTIFIER_ASSERTION_KIND = 30385;
|
|
11
|
+
/** The result tags defined by NIP-85 for each assertion kind */
|
|
12
|
+
export const TRUSTED_ASSERTION_TAGS = {
|
|
13
|
+
[USER_ASSERTION_KIND]: [
|
|
14
|
+
"rank",
|
|
15
|
+
"followers",
|
|
16
|
+
"first_created_at",
|
|
17
|
+
"post_cnt",
|
|
18
|
+
"reply_cnt",
|
|
19
|
+
"reactions_cnt",
|
|
20
|
+
"zap_amt_recd",
|
|
21
|
+
"zap_amt_sent",
|
|
22
|
+
"zap_cnt_recd",
|
|
23
|
+
"zap_cnt_sent",
|
|
24
|
+
"zap_avg_amt_day_recd",
|
|
25
|
+
"zap_avg_amt_day_sent",
|
|
26
|
+
"reports_cnt_recd",
|
|
27
|
+
"reports_cnt_sent",
|
|
28
|
+
"t",
|
|
29
|
+
"active_hours_start",
|
|
30
|
+
"active_hours_end",
|
|
31
|
+
],
|
|
32
|
+
[EVENT_ASSERTION_KIND]: ["rank", "comment_cnt", "quote_cnt", "repost_cnt", "reaction_cnt", "zap_cnt", "zap_amount"],
|
|
33
|
+
[ADDRESS_ASSERTION_KIND]: ["rank", "comment_cnt", "quote_cnt", "repost_cnt", "reaction_cnt", "zap_cnt", "zap_amount"],
|
|
34
|
+
[IDENTIFIER_ASSERTION_KIND]: ["rank", "comment_cnt", "reaction_cnt"],
|
|
35
|
+
};
|
|
7
36
|
// Register NIP-85 kind 10040 as using NIP-44 hidden tags
|
|
8
37
|
setHiddenTagsEncryptionMethod(TRUSTED_PROVIDER_LIST_KIND, "nip44");
|
|
9
38
|
// Caching symbols
|
|
@@ -33,6 +62,13 @@ export function parseProviderTag(tag) {
|
|
|
33
62
|
return undefined;
|
|
34
63
|
return { kind, tag: assertionTag, servicePubkey, relay: relay || undefined };
|
|
35
64
|
}
|
|
65
|
+
/** Creates a kind 10040 provider tag from a {@link TrustedProvider} */
|
|
66
|
+
export function createProviderTag(provider) {
|
|
67
|
+
const tag = [`${provider.kind}:${provider.tag}`, provider.servicePubkey];
|
|
68
|
+
if (provider.relay)
|
|
69
|
+
tag.push(provider.relay);
|
|
70
|
+
return tag;
|
|
71
|
+
}
|
|
36
72
|
/** Returns all public trusted providers from a kind 10040 event */
|
|
37
73
|
export function getPublicProviders(event) {
|
|
38
74
|
return getOrComputeCachedValue(event, TrustedProvidersPublicSymbol, () => event.tags.map(parseProviderTag).filter((p) => p !== undefined));
|
|
@@ -44,12 +80,15 @@ export function getHiddenProviders(event) {
|
|
|
44
80
|
if (!tags)
|
|
45
81
|
return undefined;
|
|
46
82
|
const providers = tags.map(parseProviderTag).filter((p) => p !== undefined);
|
|
47
|
-
|
|
83
|
+
// Derived from the event's own hidden tags — identity memo (see applesauce-core's cache.ts
|
|
84
|
+
// taxonomy). Written non-enumerable via setCachedValue (05.1-09) so a plain spread drops it
|
|
85
|
+
// instead of carrying a stale derivation onto a copy whose hidden tags differ.
|
|
86
|
+
setCachedValue(event, TrustedProvidersHiddenSymbol, providers);
|
|
48
87
|
return providers;
|
|
49
88
|
}
|
|
50
89
|
/** Checks if the hidden providers are unlocked */
|
|
51
90
|
export function isHiddenProvidersUnlocked(event) {
|
|
52
|
-
return TrustedProvidersHiddenSymbol in event ||
|
|
91
|
+
return (isHiddenTagsUnlocked(event) && (TrustedProvidersHiddenSymbol in event || getHiddenProviders(event) !== undefined));
|
|
53
92
|
}
|
|
54
93
|
/** Unlocks the hidden providers in a trusted provider list event */
|
|
55
94
|
export async function unlockHiddenProviders(event, signer) {
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import { NostrEvent } from "applesauce-core/helpers/event";
|
|
1
|
+
import { kinds, KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
|
|
2
2
|
import { AddressPointer, EventPointer, ProfilePointer } from "applesauce-core/helpers/pointers";
|
|
3
|
+
/** The event kind for NIP-38 user statuses */
|
|
4
|
+
export declare const USER_STATUS_KIND = 30315;
|
|
5
|
+
/** A NIP-38 user status event */
|
|
6
|
+
export type UserStatusEvent = KnownEvent<typeof kinds.UserStatuses>;
|
|
7
|
+
/** The type of a user status, `general` and `music` are defined by NIP-38 */
|
|
8
|
+
export type UserStatusType = "general" | "music" | (string & {});
|
|
3
9
|
export declare const UserStatusPointerSymbol: unique symbol;
|
|
4
10
|
export type UserStatusPointer = {
|
|
5
11
|
type: "nevent";
|
|
@@ -14,5 +20,11 @@ export type UserStatusPointer = {
|
|
|
14
20
|
type: "url";
|
|
15
21
|
data: string;
|
|
16
22
|
};
|
|
23
|
+
/** Checks if an event is a valid NIP-38 user status */
|
|
24
|
+
export declare function isValidUserStatus(event?: NostrEvent): event is UserStatusEvent;
|
|
25
|
+
/** Gets the status type (the "d" tag) of a user status event */
|
|
26
|
+
export declare function getUserStatusType(status: NostrEvent): UserStatusType;
|
|
27
|
+
/** Checks if a user status has been cleared (empty content) */
|
|
28
|
+
export declare function isUserStatusCleared(status: NostrEvent): boolean;
|
|
17
29
|
/** Gets the {@link UserStatusPointer} for a status event */
|
|
18
30
|
export declare function getUserStatusPointer(status: NostrEvent): UserStatusPointer | null;
|