applesauce-core 0.0.0-next-20250923113611 → 0.0.0-next-20250930093922
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.
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { NostrEvent } from "nostr-tools";
|
|
2
2
|
import { ProfilePointer } from "nostr-tools/nip19";
|
|
3
|
+
import { HiddenContentSigner } from "./hidden-content.js";
|
|
3
4
|
export declare const ContactsRelaysSymbol: unique symbol;
|
|
4
5
|
export declare const PublicContactsSymbol: unique symbol;
|
|
5
6
|
export declare const HiddenContactsSymbol: unique symbol;
|
|
7
|
+
/** Type for contact events with unlocked hidden tags */
|
|
8
|
+
export type UnlockedContacts = {
|
|
9
|
+
[HiddenContactsSymbol]: ProfilePointer[];
|
|
10
|
+
};
|
|
6
11
|
export declare function getRelaysFromContactsEvent(event: NostrEvent): Map<string, "inbox" | "outbox" | "all"> | null;
|
|
7
12
|
/** Merges any number of contact lists into a single list */
|
|
8
13
|
export declare function mergeContacts(...pointers: (ProfilePointer | undefined | (ProfilePointer | undefined)[])[]): ProfilePointer[];
|
|
@@ -10,5 +15,9 @@ export declare function mergeContacts(...pointers: (ProfilePointer | undefined |
|
|
|
10
15
|
export declare function getContacts(event: NostrEvent): ProfilePointer[];
|
|
11
16
|
/** Returns only the public contacts from a contacts list event */
|
|
12
17
|
export declare function getPublicContacts(event: NostrEvent): ProfilePointer[];
|
|
18
|
+
/** Checks if the hidden contacts are unlocked */
|
|
19
|
+
export declare function isHiddenContactsUnlocked<T extends NostrEvent>(event: T): event is T & UnlockedContacts;
|
|
13
20
|
/** Returns only the hidden contacts from a contacts list event */
|
|
14
21
|
export declare function getHiddenContacts(event: NostrEvent): ProfilePointer[] | undefined;
|
|
22
|
+
/** Unlocks the hidden contacts */
|
|
23
|
+
export declare function unlockHiddenContacts(event: NostrEvent, signer: HiddenContentSigner): Promise<ProfilePointer[]>;
|
package/dist/helpers/contacts.js
CHANGED
|
@@ -2,7 +2,8 @@ import { getOrComputeCachedValue } from "./cache.js";
|
|
|
2
2
|
import { isSafeRelayURL } from "./relays.js";
|
|
3
3
|
import { isPTag, processTags } from "./tags.js";
|
|
4
4
|
import { getProfilePointerFromPTag } from "./pointers.js";
|
|
5
|
-
import { getHiddenTags, isHiddenTagsUnlocked } from "./hidden-tags.js";
|
|
5
|
+
import { getHiddenTags, isHiddenTagsUnlocked, unlockHiddenTags } from "./hidden-tags.js";
|
|
6
|
+
import { notifyEventUpdate } from "./index.js";
|
|
6
7
|
export const ContactsRelaysSymbol = Symbol.for("contacts-relays");
|
|
7
8
|
export const PublicContactsSymbol = Symbol.for("public-contacts");
|
|
8
9
|
export const HiddenContactsSymbol = Symbol.for("hidden-contacts");
|
|
@@ -51,9 +52,35 @@ export function getContacts(event) {
|
|
|
51
52
|
export function getPublicContacts(event) {
|
|
52
53
|
return getOrComputeCachedValue(event, PublicContactsSymbol, () => processTags(event.tags, (t) => (isPTag(t) ? t : undefined), getProfilePointerFromPTag));
|
|
53
54
|
}
|
|
55
|
+
/** Checks if the hidden contacts are unlocked */
|
|
56
|
+
export function isHiddenContactsUnlocked(event) {
|
|
57
|
+
return isHiddenTagsUnlocked(event) && Reflect.has(event, HiddenContactsSymbol);
|
|
58
|
+
}
|
|
54
59
|
/** Returns only the hidden contacts from a contacts list event */
|
|
55
60
|
export function getHiddenContacts(event) {
|
|
56
|
-
if (
|
|
61
|
+
if (isHiddenContactsUnlocked(event))
|
|
62
|
+
return event[HiddenContactsSymbol];
|
|
63
|
+
// Get hidden tags
|
|
64
|
+
const tags = getHiddenTags(event);
|
|
65
|
+
if (!tags)
|
|
57
66
|
return undefined;
|
|
58
|
-
|
|
67
|
+
// Parse tags
|
|
68
|
+
const contacts = processTags(tags, (t) => (isPTag(t) ? t : undefined), getProfilePointerFromPTag);
|
|
69
|
+
// Set cache and notify event store
|
|
70
|
+
Reflect.set(event, HiddenContactsSymbol, contacts);
|
|
71
|
+
return contacts;
|
|
72
|
+
}
|
|
73
|
+
/** Unlocks the hidden contacts */
|
|
74
|
+
export async function unlockHiddenContacts(event, signer) {
|
|
75
|
+
if (isHiddenContactsUnlocked(event))
|
|
76
|
+
return event[HiddenContactsSymbol];
|
|
77
|
+
// Unlock hidden tags
|
|
78
|
+
await unlockHiddenTags(event, signer);
|
|
79
|
+
// Get hidden contacts
|
|
80
|
+
const contacts = getHiddenContacts(event);
|
|
81
|
+
if (!contacts)
|
|
82
|
+
throw new Error("Failed to unlock hidden contacts");
|
|
83
|
+
// Set cache and notify event store
|
|
84
|
+
notifyEventUpdate(event);
|
|
85
|
+
return contacts;
|
|
59
86
|
}
|