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,187 @@
|
|
|
1
|
+
import { getOrComputeCachedValue, setCachedValue } from "applesauce-core/helpers/cache";
|
|
2
|
+
import { getReplaceableIdentifier, notifyEventUpdate } from "applesauce-core/helpers/event";
|
|
3
|
+
import { getHiddenTags, isHiddenTagsUnlocked, setHiddenTagsEncryptionMethod, unlockHiddenTags, } from "applesauce-core/helpers/hidden-tags";
|
|
4
|
+
import { getAddressPointerFromATag, getEventPointerFromETag, getReplaceableAddressFromPointer, parseReplaceableAddress, } from "applesauce-core/helpers/pointers";
|
|
5
|
+
import { isHexKey } from "applesauce-core/helpers/string";
|
|
6
|
+
import { NAPPLET_KIND, NAPPLET_ROOT_KIND, NAPPLET_SNAPSHOT_KIND, parseNappletConvention } from "./napplet.js";
|
|
7
|
+
/**
|
|
8
|
+
* The event kind for napplet handler preferences (addressable events)
|
|
9
|
+
* @see https://github.com/napplet/naps/blob/master/naps/NAP-INTENT.md
|
|
10
|
+
*/
|
|
11
|
+
export const NAPPLET_HANDLERS_KIND = 31129;
|
|
12
|
+
// Private entries are NIP-44 encrypted to the author, as in NIP-51
|
|
13
|
+
setHiddenTagsEncryptionMethod(NAPPLET_HANDLERS_KIND, "nip44");
|
|
14
|
+
export const NappletHandlersPublicSymbol = Symbol.for("napplet-handlers-public");
|
|
15
|
+
export const NappletHandlersHiddenSymbol = Symbol.for("napplet-handlers-hidden");
|
|
16
|
+
/** Checks if an event is a valid napplet handler preferences event (kind 31129) */
|
|
17
|
+
export function isValidNappletHandlers(event) {
|
|
18
|
+
return !!event && event.kind === NAPPLET_HANDLERS_KIND && getReplaceableIdentifier(event) !== "";
|
|
19
|
+
}
|
|
20
|
+
/** Returns the archetype from the `d` tag */
|
|
21
|
+
export function getNappletHandlersArchetype(event) {
|
|
22
|
+
return getReplaceableIdentifier(event);
|
|
23
|
+
}
|
|
24
|
+
/** Returns a relay filter for handler preferences of an archetype, optionally from a set of authors */
|
|
25
|
+
export function getNappletHandlersFilter(archetype, authors) {
|
|
26
|
+
return { kinds: [NAPPLET_HANDLERS_KIND], "#d": [archetype], ...(authors ? { authors } : {}) };
|
|
27
|
+
}
|
|
28
|
+
/** Checks if an address points to a named (with an identifier) or root (without one) napplet manifest */
|
|
29
|
+
export function isNappletHandlerAddress(pointer) {
|
|
30
|
+
if (pointer.kind === NAPPLET_KIND)
|
|
31
|
+
return pointer.identifier !== "";
|
|
32
|
+
if (pointer.kind === NAPPLET_ROOT_KIND)
|
|
33
|
+
return pointer.identifier === "";
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
/** Returns the coordinate or snapshot id that identifies a handler reference, ignoring relay hints */
|
|
37
|
+
export function getNappletHandlerRefKey(ref) {
|
|
38
|
+
return ref.type === "address" ? getReplaceableAddressFromPointer(ref.pointer) : ref.pointer.id;
|
|
39
|
+
}
|
|
40
|
+
/** Checks if two handler references name the same napplet or the same pinned snapshot */
|
|
41
|
+
export function isSameNappletHandlerRef(a, b) {
|
|
42
|
+
return getNappletHandlerRefKey(a) === getNappletHandlerRefKey(b);
|
|
43
|
+
}
|
|
44
|
+
/** Parses an `i` tag `<ref>`: a napplet coordinate or a snapshot id */
|
|
45
|
+
export function parseNappletHandlerRef(value) {
|
|
46
|
+
if (isHexKey(value))
|
|
47
|
+
return { type: "snapshot", pointer: { id: value.toLowerCase(), kind: NAPPLET_SNAPSHOT_KIND } };
|
|
48
|
+
const pointer = parseReplaceableAddress(value);
|
|
49
|
+
if (!pointer || !isNappletHandlerAddress(pointer))
|
|
50
|
+
return undefined;
|
|
51
|
+
return { type: "address", pointer };
|
|
52
|
+
}
|
|
53
|
+
/** Parses an archetype-wide `a` or `e` handler tag */
|
|
54
|
+
function parseHandlerTag(tag) {
|
|
55
|
+
if (tag[0] === "a") {
|
|
56
|
+
const pointer = getAddressPointerFromATag(tag);
|
|
57
|
+
if (!pointer || !isNappletHandlerAddress(pointer))
|
|
58
|
+
return undefined;
|
|
59
|
+
return { type: "address", pointer };
|
|
60
|
+
}
|
|
61
|
+
if (tag[0] === "e") {
|
|
62
|
+
const pointer = getEventPointerFromETag(tag);
|
|
63
|
+
if (!pointer)
|
|
64
|
+
return undefined;
|
|
65
|
+
// The author is in the fourth position, after the optional relay hint
|
|
66
|
+
const snapshot = { ...pointer, kind: NAPPLET_SNAPSHOT_KIND };
|
|
67
|
+
if (isHexKey(tag[3]))
|
|
68
|
+
snapshot.author = tag[3];
|
|
69
|
+
return { type: "snapshot", pointer: snapshot };
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
/** Parses the archetype-wide `a` and `e` handlers from a set of tags, keeping the first of any repeats */
|
|
74
|
+
function parseHandlerTags(tags) {
|
|
75
|
+
const handlers = [];
|
|
76
|
+
const seen = new Set();
|
|
77
|
+
for (const tag of tags) {
|
|
78
|
+
const ref = parseHandlerTag(tag);
|
|
79
|
+
if (!ref)
|
|
80
|
+
continue;
|
|
81
|
+
const key = getNappletHandlerRefKey(ref);
|
|
82
|
+
if (seen.has(key))
|
|
83
|
+
continue;
|
|
84
|
+
seen.add(key);
|
|
85
|
+
handlers.push(ref);
|
|
86
|
+
}
|
|
87
|
+
return handlers;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Parses the handler entries from a set of tags, skipping malformed entries and unknown tags
|
|
91
|
+
* @param tags The public or private tags of the event
|
|
92
|
+
* @param archetype The archetype from the event's `d` tag
|
|
93
|
+
* @param hintTags Extra tags whose `a` and `e` entries provide relay hints and authors for `i` references
|
|
94
|
+
*/
|
|
95
|
+
export function parseNappletHandlerTags(tags, archetype, hintTags = []) {
|
|
96
|
+
const handlers = parseHandlerTags(tags);
|
|
97
|
+
// An `i` tag has no relay hint, so borrow one from an `a` or `e` tag with the same reference
|
|
98
|
+
const hints = new Map();
|
|
99
|
+
for (const ref of [...handlers, ...parseHandlerTags(hintTags)]) {
|
|
100
|
+
const key = getNappletHandlerRefKey(ref);
|
|
101
|
+
if (!hints.has(key))
|
|
102
|
+
hints.set(key, ref);
|
|
103
|
+
}
|
|
104
|
+
const intents = new Map();
|
|
105
|
+
for (const tag of tags) {
|
|
106
|
+
if (tag[0] !== "i" || !tag[1] || !tag[2])
|
|
107
|
+
continue;
|
|
108
|
+
// Ignore identities with a query or fragment, or for another archetype
|
|
109
|
+
const convention = parseNappletConvention(tag[1]);
|
|
110
|
+
if (convention?.archetype !== archetype)
|
|
111
|
+
continue;
|
|
112
|
+
const parsed = parseNappletHandlerRef(tag[2]);
|
|
113
|
+
if (!parsed)
|
|
114
|
+
continue;
|
|
115
|
+
const ref = hints.get(getNappletHandlerRefKey(parsed)) ?? parsed;
|
|
116
|
+
const refs = intents.get(tag[1]) ?? [];
|
|
117
|
+
if (refs.some((existing) => isSameNappletHandlerRef(existing, ref)))
|
|
118
|
+
continue;
|
|
119
|
+
refs.push(ref);
|
|
120
|
+
intents.set(tag[1], refs);
|
|
121
|
+
}
|
|
122
|
+
return { handlers, intents };
|
|
123
|
+
}
|
|
124
|
+
/** Returns the public handler entries, which other users read as recommendations */
|
|
125
|
+
export function getPublicNappletHandlers(event) {
|
|
126
|
+
return getOrComputeCachedValue(event, NappletHandlersPublicSymbol, () => parseNappletHandlerTags(event.tags, getNappletHandlersArchetype(event)));
|
|
127
|
+
}
|
|
128
|
+
export function getHiddenNappletHandlers(event) {
|
|
129
|
+
if (NappletHandlersHiddenSymbol in event)
|
|
130
|
+
return event[NappletHandlersHiddenSymbol];
|
|
131
|
+
const tags = getHiddenTags(event);
|
|
132
|
+
if (!tags)
|
|
133
|
+
return undefined;
|
|
134
|
+
// Private `i` entries may reference a publicly listed napplet, so public tags also provide hints
|
|
135
|
+
const entries = parseNappletHandlerTags(tags, getNappletHandlersArchetype(event), event.tags);
|
|
136
|
+
// Derived from the event's own hidden tags, so it is memoized on the event non-enumerably
|
|
137
|
+
setCachedValue(event, NappletHandlersHiddenSymbol, entries);
|
|
138
|
+
return entries;
|
|
139
|
+
}
|
|
140
|
+
/** Checks if the private handler entries are unlocked */
|
|
141
|
+
export function isHiddenNappletHandlersUnlocked(event) {
|
|
142
|
+
return (isHiddenTagsUnlocked(event) &&
|
|
143
|
+
(NappletHandlersHiddenSymbol in event || getHiddenNappletHandlers(event) !== undefined));
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Decrypts the private handler entries
|
|
147
|
+
* @throws if the content cannot be decrypted into a list of tags
|
|
148
|
+
*/
|
|
149
|
+
export async function unlockHiddenNappletHandlers(event, signer) {
|
|
150
|
+
if (NappletHandlersHiddenSymbol in event)
|
|
151
|
+
return event[NappletHandlersHiddenSymbol];
|
|
152
|
+
await unlockHiddenTags(event, signer);
|
|
153
|
+
const entries = getHiddenNappletHandlers(event);
|
|
154
|
+
if (!entries)
|
|
155
|
+
throw new Error("Failed to unlock hidden napplet handlers");
|
|
156
|
+
notifyEventUpdate(event);
|
|
157
|
+
return entries;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Returns the handlers to try for a convention identity, in resolution order
|
|
161
|
+
* @note Private entries are only included once unlocked, and a shell must still check each candidate is usable
|
|
162
|
+
*/
|
|
163
|
+
export function getNappletHandlerCandidates(event, identity) {
|
|
164
|
+
const publicEntries = getPublicNappletHandlers(event);
|
|
165
|
+
const hiddenEntries = getHiddenNappletHandlers(event);
|
|
166
|
+
// Private intent entries, then public intent entries, then private and public archetype-wide entries
|
|
167
|
+
const groups = [
|
|
168
|
+
[hiddenEntries?.intents.get(identity), true, true],
|
|
169
|
+
[publicEntries.intents.get(identity), false, true],
|
|
170
|
+
[hiddenEntries?.handlers, true, false],
|
|
171
|
+
[publicEntries.handlers, false, false],
|
|
172
|
+
];
|
|
173
|
+
const candidates = [];
|
|
174
|
+
const seen = new Set();
|
|
175
|
+
for (const [refs, hidden, intent] of groups) {
|
|
176
|
+
if (!refs)
|
|
177
|
+
continue;
|
|
178
|
+
for (const ref of refs) {
|
|
179
|
+
const key = getNappletHandlerRefKey(ref);
|
|
180
|
+
if (seen.has(key))
|
|
181
|
+
continue;
|
|
182
|
+
seen.add(key);
|
|
183
|
+
candidates.push({ ref, hidden, intent });
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return candidates;
|
|
187
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
+
import { AddressPointer } from "applesauce-core/helpers/pointers";
|
|
3
|
+
/**
|
|
4
|
+
* The event kind for NIP-5D napplet snapshots (regular events)
|
|
5
|
+
* @see https://github.com/nostr-protocol/nips/pull/2303
|
|
6
|
+
*/
|
|
7
|
+
export declare const NAPPLET_SNAPSHOT_KIND = 5129;
|
|
8
|
+
/**
|
|
9
|
+
* The event kind for NIP-5D root napplets (replaceable events)
|
|
10
|
+
* @see https://github.com/nostr-protocol/nips/pull/2303
|
|
11
|
+
*/
|
|
12
|
+
export declare const NAPPLET_ROOT_KIND = 15129;
|
|
13
|
+
/**
|
|
14
|
+
* The event kind for NIP-5D named napplets (addressable events)
|
|
15
|
+
* @see https://github.com/nostr-protocol/nips/pull/2303
|
|
16
|
+
*/
|
|
17
|
+
export declare const NAPPLET_KIND = 35129;
|
|
18
|
+
/** The event kinds of a NIP-5D napplet manifest */
|
|
19
|
+
export type NappletKind = typeof NAPPLET_SNAPSHOT_KIND | typeof NAPPLET_ROOT_KIND | typeof NAPPLET_KIND;
|
|
20
|
+
/** All NIP-5D napplet manifest kinds */
|
|
21
|
+
export declare const NAPPLET_KINDS: NappletKind[];
|
|
22
|
+
/** The MIME types allowed for a napplet icon */
|
|
23
|
+
export declare const NAPPLET_ICON_TYPES: readonly ["image/png", "image/jpeg", "image/webp"];
|
|
24
|
+
/** A MIME type allowed for a napplet icon */
|
|
25
|
+
export type NappletIconType = (typeof NAPPLET_ICON_TYPES)[number];
|
|
26
|
+
/** A validated NIP-5D napplet manifest event */
|
|
27
|
+
export type NappletEvent = KnownEvent<NappletKind>;
|
|
28
|
+
/** A NIP-5D napplet snapshot event (kind 5129) */
|
|
29
|
+
export type NappletSnapshotEvent = KnownEvent<typeof NAPPLET_SNAPSHOT_KIND>;
|
|
30
|
+
/** A NIP-5D root napplet event (kind 15129) */
|
|
31
|
+
export type RootNappletEvent = KnownEvent<typeof NAPPLET_ROOT_KIND>;
|
|
32
|
+
/** A NIP-5D named napplet event (kind 35129) */
|
|
33
|
+
export type NamedNappletEvent = KnownEvent<typeof NAPPLET_KIND>;
|
|
34
|
+
/** An intent accepted by a napplet and its advertised parameter names */
|
|
35
|
+
export type NappletIntent = {
|
|
36
|
+
intent: string;
|
|
37
|
+
params: string[];
|
|
38
|
+
};
|
|
39
|
+
/** A content-addressed napplet icon */
|
|
40
|
+
export type NappletIcon = {
|
|
41
|
+
sha256: string;
|
|
42
|
+
type: NappletIconType;
|
|
43
|
+
};
|
|
44
|
+
/** Checks if a MIME type is allowed for a napplet icon */
|
|
45
|
+
export declare function isNappletIconType(type: string): type is NappletIconType;
|
|
46
|
+
/**
|
|
47
|
+
* Checks if an event is a valid NIP-5D napplet manifest
|
|
48
|
+
* @see https://github.com/nostr-protocol/nips/pull/2303
|
|
49
|
+
*/
|
|
50
|
+
export declare function isValidNapplet(event?: NostrEvent): event is NappletEvent;
|
|
51
|
+
/** Checks if an event is a napplet snapshot (kind 5129) */
|
|
52
|
+
export declare function isNappletSnapshot(event?: NostrEvent): event is NappletSnapshotEvent;
|
|
53
|
+
/** Checks if an event is a root napplet (kind 15129) */
|
|
54
|
+
export declare function isRootNapplet(event?: NostrEvent): event is RootNappletEvent;
|
|
55
|
+
/** Checks if an event is a named napplet (kind 35129) */
|
|
56
|
+
export declare function isNamedNapplet(event?: NostrEvent): event is NamedNappletEvent;
|
|
57
|
+
/** Checks if an event is a valid napplet snapshot manifest */
|
|
58
|
+
export declare function isValidNappletSnapshot(event?: NostrEvent): event is NappletSnapshotEvent;
|
|
59
|
+
/** Checks if an event is a valid root napplet manifest */
|
|
60
|
+
export declare function isValidRootNapplet(event?: NostrEvent): event is RootNappletEvent;
|
|
61
|
+
/** Checks if an event is a valid named napplet manifest */
|
|
62
|
+
export declare function isValidNamedNapplet(event?: NostrEvent): event is NamedNappletEvent;
|
|
63
|
+
/** Returns the identifier from the `d` tag of a named napplet */
|
|
64
|
+
export declare function getNappletIdentifier(event: NostrEvent): string | undefined;
|
|
65
|
+
/** Returns the sha256 of the napplet `index.html` artifact from the `x` tag */
|
|
66
|
+
export declare function getNappletArtifactHash(event: NappletEvent): string;
|
|
67
|
+
export declare function getNappletArtifactHash(event: NostrEvent): string | undefined;
|
|
68
|
+
/** Returns the plain-text description of the napplet */
|
|
69
|
+
export declare function getNappletDescription(event: NostrEvent): string;
|
|
70
|
+
/** Returns the short display label from the `title` tag */
|
|
71
|
+
export declare function getNappletTitle(event: NostrEvent): string | undefined;
|
|
72
|
+
/** Returns the source URL from the `source` tag */
|
|
73
|
+
export declare function getNappletSource(event: NostrEvent): string | undefined;
|
|
74
|
+
/** Returns the Blossom server hints from the `server` tags */
|
|
75
|
+
export declare function getNappletServers(event: NostrEvent): string[];
|
|
76
|
+
/** Returns the archetypes from the `z` tags */
|
|
77
|
+
export declare function getNappletArchetypes(event: NostrEvent): string[];
|
|
78
|
+
/** Returns the accepted intents and their parameter names from the `i` tags */
|
|
79
|
+
export declare function getNappletIntents(event: NostrEvent): NappletIntent[];
|
|
80
|
+
/** Returns the NAP domains required for full functionality from the `R` tags */
|
|
81
|
+
export declare function getNappletRequiredDomains(event: NostrEvent): string[];
|
|
82
|
+
/** Returns the optional NAP domains from the `O` tags */
|
|
83
|
+
export declare function getNappletOptionalDomains(event: NostrEvent): string[];
|
|
84
|
+
/** Returns the icon from the `icon` tag, or undefined if the hash or MIME type is invalid */
|
|
85
|
+
export declare function getNappletIcon(event: NostrEvent): NappletIcon | undefined;
|
|
86
|
+
/** Returns the address of the napplet a snapshot derives from (`a` tag) */
|
|
87
|
+
export declare function getNappletParentPointer(event: NostrEvent): AddressPointer | undefined;
|
|
88
|
+
/** Returns the address of the root napplet a snapshot's lineage originates from (`A` tag) */
|
|
89
|
+
export declare function getNappletRootPointer(event: NostrEvent): AddressPointer | undefined;
|
|
90
|
+
/** A NAP-INTENT convention identity split into its archetype and intent */
|
|
91
|
+
export type NappletConvention = {
|
|
92
|
+
archetype: string;
|
|
93
|
+
intent: string;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Parses a `napplet:<archetype>/<intent>` convention identity
|
|
97
|
+
* @returns undefined if the identity is malformed or has a query or fragment
|
|
98
|
+
* @see https://github.com/napplet/naps/blob/master/naps/NAP-INTENT.md
|
|
99
|
+
*/
|
|
100
|
+
export declare function parseNappletConvention(identity: string): NappletConvention | undefined;
|
|
101
|
+
/**
|
|
102
|
+
* Creates a `napplet:<archetype>/<intent>` convention identity
|
|
103
|
+
* @throws if the resulting identity is malformed or has a query or fragment
|
|
104
|
+
*/
|
|
105
|
+
export declare function createNappletConvention(archetype: string, intent: string): string;
|
|
106
|
+
/** Checks if a manifest advertises a convention identity for its archetype */
|
|
107
|
+
export declare function nappletSupportsConvention(manifest: NostrEvent, identity: string): boolean;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { getOrComputeCachedValue } from "applesauce-core/helpers/cache";
|
|
2
|
+
import { getTagValue } from "applesauce-core/helpers/event";
|
|
3
|
+
import { getAddressPointerFromATag } from "applesauce-core/helpers/pointers";
|
|
4
|
+
import { processTags } from "applesauce-core/helpers/tags";
|
|
5
|
+
import { isSha256 } from "./blossom.js";
|
|
6
|
+
/**
|
|
7
|
+
* The event kind for NIP-5D napplet snapshots (regular events)
|
|
8
|
+
* @see https://github.com/nostr-protocol/nips/pull/2303
|
|
9
|
+
*/
|
|
10
|
+
export const NAPPLET_SNAPSHOT_KIND = 5129;
|
|
11
|
+
/**
|
|
12
|
+
* The event kind for NIP-5D root napplets (replaceable events)
|
|
13
|
+
* @see https://github.com/nostr-protocol/nips/pull/2303
|
|
14
|
+
*/
|
|
15
|
+
export const NAPPLET_ROOT_KIND = 15129;
|
|
16
|
+
/**
|
|
17
|
+
* The event kind for NIP-5D named napplets (addressable events)
|
|
18
|
+
* @see https://github.com/nostr-protocol/nips/pull/2303
|
|
19
|
+
*/
|
|
20
|
+
export const NAPPLET_KIND = 35129;
|
|
21
|
+
/** All NIP-5D napplet manifest kinds */
|
|
22
|
+
export const NAPPLET_KINDS = [NAPPLET_SNAPSHOT_KIND, NAPPLET_ROOT_KIND, NAPPLET_KIND];
|
|
23
|
+
/** The MIME types allowed for a napplet icon */
|
|
24
|
+
export const NAPPLET_ICON_TYPES = ["image/png", "image/jpeg", "image/webp"];
|
|
25
|
+
const NappletArchetypesSymbol = Symbol.for("napplet-archetypes");
|
|
26
|
+
const NappletIntentsSymbol = Symbol.for("napplet-intents");
|
|
27
|
+
const NappletRequiredDomainsSymbol = Symbol.for("napplet-required-domains");
|
|
28
|
+
const NappletOptionalDomainsSymbol = Symbol.for("napplet-optional-domains");
|
|
29
|
+
const NappletServersSymbol = Symbol.for("napplet-servers");
|
|
30
|
+
/** Checks if a MIME type is allowed for a napplet icon */
|
|
31
|
+
export function isNappletIconType(type) {
|
|
32
|
+
return NAPPLET_ICON_TYPES.includes(type);
|
|
33
|
+
}
|
|
34
|
+
/** Returns the values of all tags with a name */
|
|
35
|
+
function getTagValues(event, name) {
|
|
36
|
+
return processTags(event.tags, (t) => (t[0] === name && t[1] ? t[1] : undefined));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Checks if an event is a valid NIP-5D napplet manifest
|
|
40
|
+
* @see https://github.com/nostr-protocol/nips/pull/2303
|
|
41
|
+
*/
|
|
42
|
+
export function isValidNapplet(event) {
|
|
43
|
+
if (!event || !NAPPLET_KINDS.includes(event.kind))
|
|
44
|
+
return false;
|
|
45
|
+
if (event.content.trim().length === 0)
|
|
46
|
+
return false;
|
|
47
|
+
// The manifest must carry exactly one valid "x" tag
|
|
48
|
+
const x = event.tags.filter((t) => t[0] === "x");
|
|
49
|
+
if (x.length !== 1 || !x[0][1] || !isSha256(x[0][1]))
|
|
50
|
+
return false;
|
|
51
|
+
// Named napplets must have exactly one "d" tag, other kinds must have none
|
|
52
|
+
const d = event.tags.filter((t) => t[0] === "d");
|
|
53
|
+
if (event.kind === NAPPLET_KIND)
|
|
54
|
+
return d.length === 1 && !!d[0][1];
|
|
55
|
+
return d.length === 0;
|
|
56
|
+
}
|
|
57
|
+
/** Checks if an event is a napplet snapshot (kind 5129) */
|
|
58
|
+
export function isNappletSnapshot(event) {
|
|
59
|
+
return event?.kind === NAPPLET_SNAPSHOT_KIND;
|
|
60
|
+
}
|
|
61
|
+
/** Checks if an event is a root napplet (kind 15129) */
|
|
62
|
+
export function isRootNapplet(event) {
|
|
63
|
+
return event?.kind === NAPPLET_ROOT_KIND;
|
|
64
|
+
}
|
|
65
|
+
/** Checks if an event is a named napplet (kind 35129) */
|
|
66
|
+
export function isNamedNapplet(event) {
|
|
67
|
+
return event?.kind === NAPPLET_KIND;
|
|
68
|
+
}
|
|
69
|
+
/** Checks if an event is a valid napplet snapshot manifest */
|
|
70
|
+
export function isValidNappletSnapshot(event) {
|
|
71
|
+
return isNappletSnapshot(event) && isValidNapplet(event);
|
|
72
|
+
}
|
|
73
|
+
/** Checks if an event is a valid root napplet manifest */
|
|
74
|
+
export function isValidRootNapplet(event) {
|
|
75
|
+
return isRootNapplet(event) && isValidNapplet(event);
|
|
76
|
+
}
|
|
77
|
+
/** Checks if an event is a valid named napplet manifest */
|
|
78
|
+
export function isValidNamedNapplet(event) {
|
|
79
|
+
return isNamedNapplet(event) && isValidNapplet(event);
|
|
80
|
+
}
|
|
81
|
+
/** Returns the identifier from the `d` tag of a named napplet */
|
|
82
|
+
export function getNappletIdentifier(event) {
|
|
83
|
+
if (!isNamedNapplet(event))
|
|
84
|
+
return undefined;
|
|
85
|
+
return getTagValue(event, "d") || undefined;
|
|
86
|
+
}
|
|
87
|
+
export function getNappletArtifactHash(event) {
|
|
88
|
+
return getTagValue(event, "x");
|
|
89
|
+
}
|
|
90
|
+
/** Returns the plain-text description of the napplet */
|
|
91
|
+
export function getNappletDescription(event) {
|
|
92
|
+
return event.content;
|
|
93
|
+
}
|
|
94
|
+
/** Returns the short display label from the `title` tag */
|
|
95
|
+
export function getNappletTitle(event) {
|
|
96
|
+
return getTagValue(event, "title") || undefined;
|
|
97
|
+
}
|
|
98
|
+
/** Returns the source URL from the `source` tag */
|
|
99
|
+
export function getNappletSource(event) {
|
|
100
|
+
return getTagValue(event, "source") || undefined;
|
|
101
|
+
}
|
|
102
|
+
/** Returns the Blossom server hints from the `server` tags */
|
|
103
|
+
export function getNappletServers(event) {
|
|
104
|
+
return getOrComputeCachedValue(event, NappletServersSymbol, () => getTagValues(event, "server"));
|
|
105
|
+
}
|
|
106
|
+
/** Returns the archetypes from the `z` tags */
|
|
107
|
+
export function getNappletArchetypes(event) {
|
|
108
|
+
return getOrComputeCachedValue(event, NappletArchetypesSymbol, () => getTagValues(event, "z"));
|
|
109
|
+
}
|
|
110
|
+
/** Returns the accepted intents and their parameter names from the `i` tags */
|
|
111
|
+
export function getNappletIntents(event) {
|
|
112
|
+
return getOrComputeCachedValue(event, NappletIntentsSymbol, () => processTags(event.tags, (t) => t[0] === "i" && t[1] ? { intent: t[1], params: t.slice(2).filter((p) => p.length > 0) } : undefined));
|
|
113
|
+
}
|
|
114
|
+
/** Returns the NAP domains required for full functionality from the `R` tags */
|
|
115
|
+
export function getNappletRequiredDomains(event) {
|
|
116
|
+
return getOrComputeCachedValue(event, NappletRequiredDomainsSymbol, () => getTagValues(event, "R"));
|
|
117
|
+
}
|
|
118
|
+
/** Returns the optional NAP domains from the `O` tags */
|
|
119
|
+
export function getNappletOptionalDomains(event) {
|
|
120
|
+
return getOrComputeCachedValue(event, NappletOptionalDomainsSymbol, () => getTagValues(event, "O"));
|
|
121
|
+
}
|
|
122
|
+
/** Returns the icon from the `icon` tag, or undefined if the hash or MIME type is invalid */
|
|
123
|
+
export function getNappletIcon(event) {
|
|
124
|
+
const tag = event.tags.find((t) => t[0] === "icon");
|
|
125
|
+
if (!tag || !tag[1] || !tag[2])
|
|
126
|
+
return undefined;
|
|
127
|
+
if (!isSha256(tag[1]) || !isNappletIconType(tag[2]))
|
|
128
|
+
return undefined;
|
|
129
|
+
return { sha256: tag[1], type: tag[2] };
|
|
130
|
+
}
|
|
131
|
+
/** Returns the address of the napplet a snapshot derives from (`a` tag) */
|
|
132
|
+
export function getNappletParentPointer(event) {
|
|
133
|
+
if (!isNappletSnapshot(event))
|
|
134
|
+
return undefined;
|
|
135
|
+
const tag = event.tags.find((t) => t[0] === "a" && t[1]);
|
|
136
|
+
return (tag && getAddressPointerFromATag(tag)) || undefined;
|
|
137
|
+
}
|
|
138
|
+
/** Returns the address of the root napplet a snapshot's lineage originates from (`A` tag) */
|
|
139
|
+
export function getNappletRootPointer(event) {
|
|
140
|
+
if (!isNappletSnapshot(event))
|
|
141
|
+
return undefined;
|
|
142
|
+
const tag = event.tags.find((t) => t[0] === "A" && t[1]);
|
|
143
|
+
return (tag && getAddressPointerFromATag(tag)) || undefined;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Parses a `napplet:<archetype>/<intent>` convention identity
|
|
147
|
+
* @returns undefined if the identity is malformed or has a query or fragment
|
|
148
|
+
* @see https://github.com/napplet/naps/blob/master/naps/NAP-INTENT.md
|
|
149
|
+
*/
|
|
150
|
+
export function parseNappletConvention(identity) {
|
|
151
|
+
if (identity.includes("?") || identity.includes("#"))
|
|
152
|
+
return undefined;
|
|
153
|
+
const match = identity.match(/^napplet:([^/]+)\/(.+)$/);
|
|
154
|
+
if (!match)
|
|
155
|
+
return undefined;
|
|
156
|
+
return { archetype: match[1], intent: match[2] };
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Creates a `napplet:<archetype>/<intent>` convention identity
|
|
160
|
+
* @throws if the resulting identity is malformed or has a query or fragment
|
|
161
|
+
*/
|
|
162
|
+
export function createNappletConvention(archetype, intent) {
|
|
163
|
+
const identity = `napplet:${archetype}/${intent}`;
|
|
164
|
+
const parsed = parseNappletConvention(identity);
|
|
165
|
+
if (parsed?.archetype !== archetype)
|
|
166
|
+
throw new Error(`Invalid napplet convention identity: ${identity}`);
|
|
167
|
+
return identity;
|
|
168
|
+
}
|
|
169
|
+
/** Checks if a manifest advertises a convention identity for its archetype */
|
|
170
|
+
export function nappletSupportsConvention(manifest, identity) {
|
|
171
|
+
const convention = parseNappletConvention(identity);
|
|
172
|
+
if (!convention)
|
|
173
|
+
return false;
|
|
174
|
+
if (!getNappletArchetypes(manifest).includes(convention.archetype))
|
|
175
|
+
return false;
|
|
176
|
+
return getNappletIntents(manifest).some((entry) => entry.intent === identity);
|
|
177
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { KnownEvent, NostrEvent } from "applesauce-core/helpers/event";
|
|
2
|
+
import { AddressPointer, EventPointer } from "applesauce-core/helpers/pointers";
|
|
3
|
+
/** The event kind for NIP-5A manifest snapshots */
|
|
4
|
+
export declare const NSITE_SNAPSHOT_KIND = 5128;
|
|
5
|
+
/** The event kind for NIP-5A root sites */
|
|
6
|
+
export declare const NSITE_ROOT_KIND = 15128;
|
|
7
|
+
/** The event kind for NIP-5A named sites */
|
|
8
|
+
export declare const NSITE_KIND = 35128;
|
|
9
|
+
/** The event kinds of an nsite manifest */
|
|
10
|
+
export type NsiteKind = typeof NSITE_SNAPSHOT_KIND | typeof NSITE_ROOT_KIND | typeof NSITE_KIND;
|
|
11
|
+
/** All NIP-5A manifest kinds */
|
|
12
|
+
export declare const NSITE_KINDS: NsiteKind[];
|
|
13
|
+
/** A validated nsite manifest */
|
|
14
|
+
export type NsiteEvent = KnownEvent<NsiteKind>;
|
|
15
|
+
/** A root site manifest */
|
|
16
|
+
export type RootNsiteEvent = KnownEvent<typeof NSITE_ROOT_KIND>;
|
|
17
|
+
/** A named site manifest */
|
|
18
|
+
export type NamedNsiteEvent = KnownEvent<typeof NSITE_KIND>;
|
|
19
|
+
/** A manifest snapshot */
|
|
20
|
+
export type NsiteSnapshotEvent = KnownEvent<typeof NSITE_SNAPSHOT_KIND>;
|
|
21
|
+
/** A file in an nsite manifest */
|
|
22
|
+
export interface NsiteFile {
|
|
23
|
+
/** The absolute path to the file */
|
|
24
|
+
path: string;
|
|
25
|
+
/** The lowercase hexadecimal SHA-256 of the file */
|
|
26
|
+
sha256: string;
|
|
27
|
+
}
|
|
28
|
+
/** Checks if an identifier fits the canonical named-site DNS label */
|
|
29
|
+
export declare function isValidNsiteIdentifier(identifier: string): boolean;
|
|
30
|
+
/** Checks if a path is absolute and ends in a filename with an extension */
|
|
31
|
+
export declare function isValidNsitePath(path: string): boolean;
|
|
32
|
+
/** Checks if an address pointer references a root or named site */
|
|
33
|
+
export declare function isNsiteAddressPointer(pointer: AddressPointer): boolean;
|
|
34
|
+
/** Checks if an event is a root site */
|
|
35
|
+
export declare function isRootNsite(event?: NostrEvent): event is RootNsiteEvent;
|
|
36
|
+
/** Checks if an event is a named site */
|
|
37
|
+
export declare function isNamedNsite(event?: NostrEvent): event is NamedNsiteEvent;
|
|
38
|
+
/** Checks if an event is a manifest snapshot */
|
|
39
|
+
export declare function isNsiteSnapshot(event?: NostrEvent): event is NsiteSnapshotEvent;
|
|
40
|
+
/**
|
|
41
|
+
* Checks if an event is a valid NIP-5A manifest
|
|
42
|
+
* @see https://github.com/nostr-protocol/nips/blob/master/5A.md
|
|
43
|
+
*/
|
|
44
|
+
export declare function isValidNsite(event?: NostrEvent): event is NsiteEvent;
|
|
45
|
+
/** Checks if an event is a valid root site */
|
|
46
|
+
export declare function isValidRootNsite(event?: NostrEvent): event is RootNsiteEvent;
|
|
47
|
+
/** Checks if an event is a valid named site */
|
|
48
|
+
export declare function isValidNamedNsite(event?: NostrEvent): event is NamedNsiteEvent;
|
|
49
|
+
/** Checks if an event is a valid manifest snapshot */
|
|
50
|
+
export declare function isValidNsiteSnapshot(event?: NostrEvent): event is NsiteSnapshotEvent;
|
|
51
|
+
/** Returns the named site's identifier */
|
|
52
|
+
export declare function getNsiteIdentifier(event: NostrEvent): string | undefined;
|
|
53
|
+
/** Returns the site's display title */
|
|
54
|
+
export declare function getNsiteTitle(event: NostrEvent): string | undefined;
|
|
55
|
+
/** Returns the site's description tag */
|
|
56
|
+
export declare function getNsiteDescription(event: NostrEvent): string | undefined;
|
|
57
|
+
/** Returns the site's source repository or archive URL */
|
|
58
|
+
export declare function getNsiteSource(event: NostrEvent): string | undefined;
|
|
59
|
+
/** Returns the valid file mappings from the manifest */
|
|
60
|
+
export declare function getNsiteFiles(event: NostrEvent): NsiteFile[];
|
|
61
|
+
/** Returns the Blossom server hints */
|
|
62
|
+
export declare function getNsiteServers(event: NostrEvent): string[];
|
|
63
|
+
/** Returns the upstream addressable app descriptor pointers */
|
|
64
|
+
export declare function getNsiteAppPointers(event: NostrEvent): AddressPointer[];
|
|
65
|
+
/** Returns the immediate parent site address */
|
|
66
|
+
export declare function getNsiteParentPointer(event: NostrEvent): AddressPointer | undefined;
|
|
67
|
+
/** Returns the origin site address of a copy lineage */
|
|
68
|
+
export declare function getNsiteRootPointer(event: NostrEvent): AddressPointer | undefined;
|
|
69
|
+
/** Returns the advertised aggregate hash */
|
|
70
|
+
export declare function getNsiteAggregateHash(event: NostrEvent): string | undefined;
|
|
71
|
+
/** Returns the deterministic SHA-256 of all path tags, including duplicates */
|
|
72
|
+
export declare function computeNsiteAggregateHash(manifest: Pick<NostrEvent, "tags">): string;
|
|
73
|
+
/** Returns the cached computed aggregate hash of a manifest */
|
|
74
|
+
export declare function getComputedNsiteAggregateHash(event: NostrEvent): string;
|
|
75
|
+
/** Checks if the advertised aggregate hash matches the manifest's path tags */
|
|
76
|
+
export declare function verifyNsiteAggregateHash(event: NostrEvent): boolean;
|
|
77
|
+
/** Resolves a request path with index.html and 404.html fallbacks */
|
|
78
|
+
export declare function resolveNsitePath(event: NostrEvent, path: string): NsiteFile | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* Returns the canonical DNS label for an nsite manifest
|
|
81
|
+
* @throws if the manifest is invalid
|
|
82
|
+
*/
|
|
83
|
+
export declare function getNsiteHostLabel(event: NostrEvent): string;
|
|
84
|
+
/** Parses a canonical nsite DNS label into a site or snapshot pointer */
|
|
85
|
+
export declare function parseNsiteHostLabel(label: string): AddressPointer | EventPointer | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* Returns a site's URL on an nsite host
|
|
88
|
+
* @throws if the manifest or host URL is invalid
|
|
89
|
+
*/
|
|
90
|
+
export declare function getNsiteURL(event: NostrEvent, host: string | URL): URL;
|