applesauce-core 0.0.0-next-20250120191411 → 0.0.0-next-20250123205825
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/package.json +1 -1
- package/dist/event-store/common.d.ts +0 -1
- package/dist/event-store/common.js +0 -2
- package/dist/event-store/database.d.ts +0 -64
- package/dist/event-store/database.js +0 -311
- package/dist/event-store/event-store.d.ts +0 -49
- package/dist/event-store/event-store.js +0 -389
- package/dist/event-store/index.d.ts +0 -2
- package/dist/event-store/index.js +0 -2
- package/dist/helpers/bolt11.d.ts +0 -9
- package/dist/helpers/bolt11.js +0 -15
- package/dist/helpers/cache.d.ts +0 -5
- package/dist/helpers/cache.js +0 -17
- package/dist/helpers/comment.d.ts +0 -47
- package/dist/helpers/comment.js +0 -116
- package/dist/helpers/content.d.ts +0 -3
- package/dist/helpers/content.js +0 -8
- package/dist/helpers/delete.d.ts +0 -3
- package/dist/helpers/delete.js +0 -7
- package/dist/helpers/emoji.d.ts +0 -11
- package/dist/helpers/emoji.js +0 -16
- package/dist/helpers/event.d.ts +0 -48
- package/dist/helpers/event.js +0 -105
- package/dist/helpers/external-id.d.ts +0 -29
- package/dist/helpers/external-id.js +0 -20
- package/dist/helpers/file-metadata.d.ts +0 -53
- package/dist/helpers/file-metadata.js +0 -90
- package/dist/helpers/file-metadata.test.d.ts +0 -1
- package/dist/helpers/file-metadata.test.js +0 -103
- package/dist/helpers/filter.d.ts +0 -10
- package/dist/helpers/filter.js +0 -46
- package/dist/helpers/hashtag.d.ts +0 -2
- package/dist/helpers/hashtag.js +0 -7
- package/dist/helpers/hidden-tags.d.ts +0 -48
- package/dist/helpers/hidden-tags.js +0 -108
- package/dist/helpers/hidden-tags.test.d.ts +0 -1
- package/dist/helpers/hidden-tags.test.js +0 -28
- package/dist/helpers/index.d.ts +0 -26
- package/dist/helpers/index.js +0 -26
- package/dist/helpers/json.d.ts +0 -2
- package/dist/helpers/json.js +0 -9
- package/dist/helpers/lnurl.d.ts +0 -4
- package/dist/helpers/lnurl.js +0 -40
- package/dist/helpers/lru.d.ts +0 -32
- package/dist/helpers/lru.js +0 -148
- package/dist/helpers/mailboxes.d.ts +0 -11
- package/dist/helpers/mailboxes.js +0 -36
- package/dist/helpers/mailboxes.test.d.ts +0 -1
- package/dist/helpers/mailboxes.test.js +0 -81
- package/dist/helpers/media-attachment.d.ts +0 -42
- package/dist/helpers/media-attachment.js +0 -72
- package/dist/helpers/media-attachment.test.d.ts +0 -1
- package/dist/helpers/media-attachment.test.js +0 -59
- package/dist/helpers/media-post.d.ts +0 -4
- package/dist/helpers/media-post.js +0 -6
- package/dist/helpers/picture-post.d.ts +0 -4
- package/dist/helpers/picture-post.js +0 -6
- package/dist/helpers/pipe.d.ts +0 -10
- package/dist/helpers/pipe.js +0 -3
- package/dist/helpers/pointers.d.ts +0 -55
- package/dist/helpers/pointers.js +0 -205
- package/dist/helpers/profile.d.ts +0 -20
- package/dist/helpers/profile.js +0 -31
- package/dist/helpers/relays.d.ts +0 -12
- package/dist/helpers/relays.js +0 -31
- package/dist/helpers/string.d.ts +0 -10
- package/dist/helpers/string.js +0 -15
- package/dist/helpers/tags.d.ts +0 -25
- package/dist/helpers/tags.js +0 -42
- package/dist/helpers/tags.test.d.ts +0 -1
- package/dist/helpers/tags.test.js +0 -16
- package/dist/helpers/threading.d.ts +0 -55
- package/dist/helpers/threading.js +0 -94
- package/dist/helpers/threading.test.d.ts +0 -1
- package/dist/helpers/threading.test.js +0 -41
- package/dist/helpers/time.d.ts +0 -2
- package/dist/helpers/time.js +0 -4
- package/dist/helpers/url.d.ts +0 -14
- package/dist/helpers/url.js +0 -30
- package/dist/helpers/zap.d.ts +0 -39
- package/dist/helpers/zap.js +0 -95
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -5
- package/dist/logger.d.ts +0 -2
- package/dist/logger.js +0 -2
- package/dist/observable/get-value.d.ts +0 -3
- package/dist/observable/get-value.js +0 -14
- package/dist/observable/index.d.ts +0 -2
- package/dist/observable/index.js +0 -2
- package/dist/observable/share-latest-value.d.ts +0 -8
- package/dist/observable/share-latest-value.js +0 -21
- package/dist/promise/deferred.d.ts +0 -6
- package/dist/promise/deferred.js +0 -15
- package/dist/promise/index.d.ts +0 -1
- package/dist/promise/index.js +0 -1
- package/dist/queries/comment.d.ts +0 -4
- package/dist/queries/comment.js +0 -14
- package/dist/queries/comments.d.ts +0 -4
- package/dist/queries/comments.js +0 -14
- package/dist/queries/index.d.ts +0 -7
- package/dist/queries/index.js +0 -7
- package/dist/queries/mailboxes.d.ts +0 -6
- package/dist/queries/mailboxes.js +0 -13
- package/dist/queries/profile.d.ts +0 -4
- package/dist/queries/profile.js +0 -12
- package/dist/queries/reactions.d.ts +0 -4
- package/dist/queries/reactions.js +0 -19
- package/dist/queries/simple.d.ts +0 -16
- package/dist/queries/simple.js +0 -38
- package/dist/queries/thread.d.ts +0 -25
- package/dist/queries/thread.js +0 -92
- package/dist/queries/zaps.d.ts +0 -5
- package/dist/queries/zaps.js +0 -21
- package/dist/query-store/index.d.ts +0 -57
- package/dist/query-store/index.js +0 -68
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { EventTemplate, NostrEvent } from "nostr-tools";
|
|
2
|
-
import { AddressPointer, EventPointer } from "nostr-tools/nip19";
|
|
3
|
-
export type ThreadReferences = {
|
|
4
|
-
root?: {
|
|
5
|
-
e: EventPointer;
|
|
6
|
-
a: undefined;
|
|
7
|
-
} | {
|
|
8
|
-
e: undefined;
|
|
9
|
-
a: AddressPointer;
|
|
10
|
-
} | {
|
|
11
|
-
e: EventPointer;
|
|
12
|
-
a: AddressPointer;
|
|
13
|
-
};
|
|
14
|
-
reply?: {
|
|
15
|
-
e: EventPointer;
|
|
16
|
-
a: undefined;
|
|
17
|
-
} | {
|
|
18
|
-
e: undefined;
|
|
19
|
-
a: AddressPointer;
|
|
20
|
-
} | {
|
|
21
|
-
e: EventPointer;
|
|
22
|
-
a: AddressPointer;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
export declare const Nip10ThreadRefsSymbol: unique symbol;
|
|
26
|
-
/**
|
|
27
|
-
* Gets an EventPointer form a NIP-10 threading "e" tag
|
|
28
|
-
* @throws
|
|
29
|
-
*/
|
|
30
|
-
export declare function getEventPointerFromThreadTag(tag: string[]): EventPointer;
|
|
31
|
-
/** Parses NIP-10 tags and handles legacy behavior */
|
|
32
|
-
export declare function interpretThreadTags(tags: string[][]): {
|
|
33
|
-
root?: {
|
|
34
|
-
e: string[];
|
|
35
|
-
a: undefined;
|
|
36
|
-
} | {
|
|
37
|
-
e: undefined;
|
|
38
|
-
a: string[];
|
|
39
|
-
} | {
|
|
40
|
-
e: string[];
|
|
41
|
-
a: string[];
|
|
42
|
-
};
|
|
43
|
-
reply?: {
|
|
44
|
-
e: string[];
|
|
45
|
-
a: undefined;
|
|
46
|
-
} | {
|
|
47
|
-
e: undefined;
|
|
48
|
-
a: string[];
|
|
49
|
-
} | {
|
|
50
|
-
e: string[];
|
|
51
|
-
a: string[];
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
/** Returns the parsed NIP-10 tags for an event */
|
|
55
|
-
export declare function getNip10References(event: NostrEvent | EventTemplate): ThreadReferences;
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { getAddressPointerFromATag } from "./pointers.js";
|
|
2
|
-
import { getOrComputeCachedValue } from "./cache.js";
|
|
3
|
-
import { safeRelayUrls } from "./relays.js";
|
|
4
|
-
export const Nip10ThreadRefsSymbol = Symbol.for("nip10-thread-refs");
|
|
5
|
-
/**
|
|
6
|
-
* Gets an EventPointer form a NIP-10 threading "e" tag
|
|
7
|
-
* @throws
|
|
8
|
-
*/
|
|
9
|
-
export function getEventPointerFromThreadTag(tag) {
|
|
10
|
-
if (!tag[1])
|
|
11
|
-
throw new Error("Missing event id in tag");
|
|
12
|
-
let pointer = { id: tag[1] };
|
|
13
|
-
if (tag[2])
|
|
14
|
-
pointer.relays = safeRelayUrls([tag[2]]);
|
|
15
|
-
// get author from NIP-18 quote tags, nip-22 comments tags, or nip-10 thread tags
|
|
16
|
-
if (tag[0] === "e" &&
|
|
17
|
-
(tag[3] === "root" || tag[3] === "reply" || tag[3] === "mention") &&
|
|
18
|
-
tag[4] &&
|
|
19
|
-
tag[4].length === 64) {
|
|
20
|
-
// NIP-10 "e" tag
|
|
21
|
-
pointer.author = tag[4];
|
|
22
|
-
}
|
|
23
|
-
return pointer;
|
|
24
|
-
}
|
|
25
|
-
/** Parses NIP-10 tags and handles legacy behavior */
|
|
26
|
-
export function interpretThreadTags(tags) {
|
|
27
|
-
const eTags = tags.filter((t) => t[0] === "e" && t[1]);
|
|
28
|
-
const aTags = tags.filter((t) => t[0] === "a" && t[1]);
|
|
29
|
-
// find the root and reply tags.
|
|
30
|
-
let rootETag = eTags.find((t) => t[3] === "root");
|
|
31
|
-
let replyETag = eTags.find((t) => t[3] === "reply");
|
|
32
|
-
let rootATag = aTags.find((t) => t[3] === "root");
|
|
33
|
-
let replyATag = aTags.find((t) => t[3] === "reply");
|
|
34
|
-
if (!rootETag || !replyETag) {
|
|
35
|
-
// a direct reply does not need a "reply" reference
|
|
36
|
-
// https://github.com/nostr-protocol/nips/blob/master/10.md
|
|
37
|
-
// this is not necessarily to spec. but if there is only one id (root or reply) then assign it to both
|
|
38
|
-
// this handles the cases where a client only set a "reply" tag and no root
|
|
39
|
-
rootETag = replyETag = rootETag || replyETag;
|
|
40
|
-
}
|
|
41
|
-
if (!rootATag || !replyATag) {
|
|
42
|
-
rootATag = replyATag = rootATag || replyATag;
|
|
43
|
-
}
|
|
44
|
-
if (!rootETag && !replyETag) {
|
|
45
|
-
// legacy behavior
|
|
46
|
-
// https://github.com/nostr-protocol/nips/blob/master/10.md#positional-e-tags-deprecated
|
|
47
|
-
const legacyETags = eTags.filter((t) => {
|
|
48
|
-
// ignore it if there is a marker
|
|
49
|
-
if (t[3])
|
|
50
|
-
return false;
|
|
51
|
-
return true;
|
|
52
|
-
});
|
|
53
|
-
if (legacyETags.length >= 1) {
|
|
54
|
-
// first tag is the root
|
|
55
|
-
rootETag = legacyETags[0];
|
|
56
|
-
// last tag is reply
|
|
57
|
-
replyETag = legacyETags[legacyETags.length - 1] ?? rootETag;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return {
|
|
61
|
-
root: rootETag || rootATag ? { e: rootETag, a: rootATag } : undefined,
|
|
62
|
-
reply: replyETag || replyATag ? { e: replyETag, a: replyATag } : undefined,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
/** Returns the parsed NIP-10 tags for an event */
|
|
66
|
-
export function getNip10References(event) {
|
|
67
|
-
return getOrComputeCachedValue(event, Nip10ThreadRefsSymbol, () => {
|
|
68
|
-
const tags = interpretThreadTags(event.tags);
|
|
69
|
-
let root;
|
|
70
|
-
if (tags.root) {
|
|
71
|
-
try {
|
|
72
|
-
root = {
|
|
73
|
-
e: tags.root.e && getEventPointerFromThreadTag(tags.root.e),
|
|
74
|
-
a: tags.root.a && getAddressPointerFromATag(tags.root.a),
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
catch (error) { }
|
|
78
|
-
}
|
|
79
|
-
let reply;
|
|
80
|
-
if (tags.reply) {
|
|
81
|
-
try {
|
|
82
|
-
reply = {
|
|
83
|
-
e: tags.reply.e && getEventPointerFromThreadTag(tags.reply.e),
|
|
84
|
-
a: tags.reply.a && getAddressPointerFromATag(tags.reply.a),
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
catch (error) { }
|
|
88
|
-
}
|
|
89
|
-
return {
|
|
90
|
-
root,
|
|
91
|
-
reply,
|
|
92
|
-
};
|
|
93
|
-
});
|
|
94
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { interpretThreadTags } from "./threading.js";
|
|
3
|
-
describe("threading helpers", () => {
|
|
4
|
-
describe("interpretThreadTags", () => {
|
|
5
|
-
it("should handle legacy tags", () => {
|
|
6
|
-
expect(interpretThreadTags([
|
|
7
|
-
["e", "root-id"],
|
|
8
|
-
["e", "reply-id"],
|
|
9
|
-
])).toEqual({ root: { a: undefined, e: ["e", "root-id"] }, reply: { a: undefined, e: ["e", "reply-id"] } });
|
|
10
|
-
});
|
|
11
|
-
it("should handle nip-10 tags", () => {
|
|
12
|
-
expect(interpretThreadTags([
|
|
13
|
-
["e", "root-id", "relay", "root"],
|
|
14
|
-
["e", "reply-id", "relay", "reply"],
|
|
15
|
-
])).toEqual({
|
|
16
|
-
root: { a: undefined, e: ["e", "root-id", "relay", "root"] },
|
|
17
|
-
reply: { a: undefined, e: ["e", "reply-id", "relay", "reply"] },
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
it("should ignore mention nip-10 tags", () => {
|
|
21
|
-
expect(interpretThreadTags([
|
|
22
|
-
["e", "root-id", "relay", "root"],
|
|
23
|
-
["e", "mention-id", "relay", "mention"],
|
|
24
|
-
["e", "reply-id", "relay", "reply"],
|
|
25
|
-
])).toEqual({
|
|
26
|
-
root: { a: undefined, e: ["e", "root-id", "relay", "root"] },
|
|
27
|
-
reply: { a: undefined, e: ["e", "reply-id", "relay", "reply"] },
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
it("should handle single nip-10 tags", () => {
|
|
31
|
-
expect(interpretThreadTags([["e", "root-id", "relay", "root"]])).toEqual({
|
|
32
|
-
root: { a: undefined, e: ["e", "root-id", "relay", "root"] },
|
|
33
|
-
reply: { a: undefined, e: ["e", "root-id", "relay", "root"] },
|
|
34
|
-
});
|
|
35
|
-
expect(interpretThreadTags([["e", "reply-id", "relay", "reply"]])).toEqual({
|
|
36
|
-
root: { a: undefined, e: ["e", "reply-id", "relay", "reply"] },
|
|
37
|
-
reply: { a: undefined, e: ["e", "reply-id", "relay", "reply"] },
|
|
38
|
-
});
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
});
|
package/dist/helpers/time.d.ts
DELETED
package/dist/helpers/time.js
DELETED
package/dist/helpers/url.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export declare const convertToUrl: (url: string | URL) => URL;
|
|
2
|
-
export declare const getURLFilename: (url: URL) => string | undefined;
|
|
3
|
-
export declare const IMAGE_EXT: string[];
|
|
4
|
-
export declare const VIDEO_EXT: string[];
|
|
5
|
-
export declare const STREAM_EXT: string[];
|
|
6
|
-
export declare const AUDIO_EXT: string[];
|
|
7
|
-
/** Checks if a url is a image URL */
|
|
8
|
-
export declare function isImageURL(url: string | URL): boolean;
|
|
9
|
-
/** Checks if a url is a video URL */
|
|
10
|
-
export declare function isVideoURL(url: string | URL): boolean;
|
|
11
|
-
/** Checks if a url is a stream URL */
|
|
12
|
-
export declare function isStreamURL(url: string | URL): boolean;
|
|
13
|
-
/** Checks if a url is a audio URL */
|
|
14
|
-
export declare function isAudioURL(url: string | URL): boolean;
|
package/dist/helpers/url.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
export const convertToUrl = (url) => (url instanceof URL ? url : new URL(url));
|
|
2
|
-
export const getURLFilename = (url) => url.pathname.split("/").pop()?.toLocaleLowerCase() || url.searchParams.get("filename")?.toLocaleLowerCase();
|
|
3
|
-
export const IMAGE_EXT = [".svg", ".gif", ".png", ".jpg", ".jpeg", ".webp", ".avif"];
|
|
4
|
-
export const VIDEO_EXT = [".mp4", ".mkv", ".webm", ".mov"];
|
|
5
|
-
export const STREAM_EXT = [".m3u8"];
|
|
6
|
-
export const AUDIO_EXT = [".mp3", ".wav", ".ogg", ".aac"];
|
|
7
|
-
/** Checks if a url is a image URL */
|
|
8
|
-
export function isImageURL(url) {
|
|
9
|
-
url = convertToUrl(url);
|
|
10
|
-
const filename = getURLFilename(url);
|
|
11
|
-
return !!filename && IMAGE_EXT.some((ext) => filename.endsWith(ext));
|
|
12
|
-
}
|
|
13
|
-
/** Checks if a url is a video URL */
|
|
14
|
-
export function isVideoURL(url) {
|
|
15
|
-
url = convertToUrl(url);
|
|
16
|
-
const filename = getURLFilename(url);
|
|
17
|
-
return !!filename && VIDEO_EXT.some((ext) => filename.endsWith(ext));
|
|
18
|
-
}
|
|
19
|
-
/** Checks if a url is a stream URL */
|
|
20
|
-
export function isStreamURL(url) {
|
|
21
|
-
url = convertToUrl(url);
|
|
22
|
-
const filename = getURLFilename(url);
|
|
23
|
-
return !!filename && STREAM_EXT.some((ext) => filename.endsWith(ext));
|
|
24
|
-
}
|
|
25
|
-
/** Checks if a url is a audio URL */
|
|
26
|
-
export function isAudioURL(url) {
|
|
27
|
-
url = convertToUrl(url);
|
|
28
|
-
const filename = getURLFilename(url);
|
|
29
|
-
return !!filename && AUDIO_EXT.some((ext) => filename.endsWith(ext));
|
|
30
|
-
}
|
package/dist/helpers/zap.d.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { NostrEvent } from "nostr-tools";
|
|
2
|
-
export declare const ZapRequestSymbol: unique symbol;
|
|
3
|
-
export declare const ZapFromSymbol: unique symbol;
|
|
4
|
-
export declare const ZapInvoiceSymbol: unique symbol;
|
|
5
|
-
export declare const ZapEventPointerSymbol: unique symbol;
|
|
6
|
-
export declare const ZapAddressPointerSymbol: unique symbol;
|
|
7
|
-
/** Returns the senders pubkey */
|
|
8
|
-
export declare function getZapSender(zap: NostrEvent): string;
|
|
9
|
-
/**
|
|
10
|
-
* Gets the receivers pubkey
|
|
11
|
-
* @throws
|
|
12
|
-
*/
|
|
13
|
-
export declare function getZapRecipient(zap: NostrEvent): string;
|
|
14
|
-
/** Returns the parsed bolt11 invoice */
|
|
15
|
-
export declare function getZapPayment(zap: NostrEvent): import("./bolt11.js").ParsedInvoice | undefined;
|
|
16
|
-
/** Gets the AddressPointer that was zapped */
|
|
17
|
-
export declare function getZapAddressPointer(zap: NostrEvent): import("nostr-tools/nip19").AddressPointer | null;
|
|
18
|
-
/** Gets the EventPointer that was zapped */
|
|
19
|
-
export declare function getZapEventPointer(zap: NostrEvent): import("nostr-tools/nip19").EventPointer | null;
|
|
20
|
-
/** Gets the preimage for the bolt11 invoice */
|
|
21
|
-
export declare function getZapPreimage(zap: NostrEvent): string | undefined;
|
|
22
|
-
/**
|
|
23
|
-
* Returns the zap request event inside the zap receipt
|
|
24
|
-
* @throws
|
|
25
|
-
*/
|
|
26
|
-
export declare function getZapRequest(zap: NostrEvent): import("nostr-tools").Event;
|
|
27
|
-
/**
|
|
28
|
-
* Checks if the zap is valid
|
|
29
|
-
* DOES NOT validate LNURL address
|
|
30
|
-
*/
|
|
31
|
-
export declare function isValidZap(zap?: NostrEvent): boolean;
|
|
32
|
-
export type ZapSplit = {
|
|
33
|
-
pubkey: string;
|
|
34
|
-
percent: number;
|
|
35
|
-
weight: number;
|
|
36
|
-
relay?: string;
|
|
37
|
-
};
|
|
38
|
-
/** Returns the zap splits for an event */
|
|
39
|
-
export declare function getZapSplits(event: NostrEvent): ZapSplit[] | undefined;
|
package/dist/helpers/zap.js
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { kinds, nip57 } from "nostr-tools";
|
|
2
|
-
import { getOrComputeCachedValue } from "./cache.js";
|
|
3
|
-
import { getTagValue } from "./event.js";
|
|
4
|
-
import { isATag, isETag } from "./tags.js";
|
|
5
|
-
import { getAddressPointerFromATag, getEventPointerFromETag } from "./pointers.js";
|
|
6
|
-
import { parseBolt11 } from "./bolt11.js";
|
|
7
|
-
export const ZapRequestSymbol = Symbol.for("zap-request");
|
|
8
|
-
export const ZapFromSymbol = Symbol.for("zap-from");
|
|
9
|
-
export const ZapInvoiceSymbol = Symbol.for("zap-bolt11");
|
|
10
|
-
export const ZapEventPointerSymbol = Symbol.for("zap-event-pointer");
|
|
11
|
-
export const ZapAddressPointerSymbol = Symbol.for("zap-address-pointer");
|
|
12
|
-
/** Returns the senders pubkey */
|
|
13
|
-
export function getZapSender(zap) {
|
|
14
|
-
return getTagValue(zap, "P") || getZapRequest(zap).pubkey;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Gets the receivers pubkey
|
|
18
|
-
* @throws
|
|
19
|
-
*/
|
|
20
|
-
export function getZapRecipient(zap) {
|
|
21
|
-
const recipient = getTagValue(zap, "p");
|
|
22
|
-
if (!recipient)
|
|
23
|
-
throw new Error("Missing recipient");
|
|
24
|
-
return recipient;
|
|
25
|
-
}
|
|
26
|
-
/** Returns the parsed bolt11 invoice */
|
|
27
|
-
export function getZapPayment(zap) {
|
|
28
|
-
return getOrComputeCachedValue(zap, ZapInvoiceSymbol, () => {
|
|
29
|
-
const bolt11 = getTagValue(zap, "bolt11");
|
|
30
|
-
return bolt11 ? parseBolt11(bolt11) : undefined;
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
/** Gets the AddressPointer that was zapped */
|
|
34
|
-
export function getZapAddressPointer(zap) {
|
|
35
|
-
return getOrComputeCachedValue(zap, ZapAddressPointerSymbol, () => {
|
|
36
|
-
const a = zap.tags.find(isATag);
|
|
37
|
-
return a ? getAddressPointerFromATag(a) : null;
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
/** Gets the EventPointer that was zapped */
|
|
41
|
-
export function getZapEventPointer(zap) {
|
|
42
|
-
return getOrComputeCachedValue(zap, ZapEventPointerSymbol, () => {
|
|
43
|
-
const e = zap.tags.find(isETag);
|
|
44
|
-
return e ? getEventPointerFromETag(e) : null;
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
/** Gets the preimage for the bolt11 invoice */
|
|
48
|
-
export function getZapPreimage(zap) {
|
|
49
|
-
return getTagValue(zap, "preimage");
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Returns the zap request event inside the zap receipt
|
|
53
|
-
* @throws
|
|
54
|
-
*/
|
|
55
|
-
export function getZapRequest(zap) {
|
|
56
|
-
return getOrComputeCachedValue(zap, ZapRequestSymbol, () => {
|
|
57
|
-
const description = getTagValue(zap, "description");
|
|
58
|
-
if (!description)
|
|
59
|
-
throw new Error("Missing description tag");
|
|
60
|
-
const error = nip57.validateZapRequest(description);
|
|
61
|
-
if (error)
|
|
62
|
-
throw new Error(error);
|
|
63
|
-
return JSON.parse(description);
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Checks if the zap is valid
|
|
68
|
-
* DOES NOT validate LNURL address
|
|
69
|
-
*/
|
|
70
|
-
export function isValidZap(zap) {
|
|
71
|
-
if (!zap)
|
|
72
|
-
return false;
|
|
73
|
-
if (zap.kind !== kinds.Zap)
|
|
74
|
-
return false;
|
|
75
|
-
try {
|
|
76
|
-
getZapRequest(zap);
|
|
77
|
-
getZapRecipient(zap);
|
|
78
|
-
return true;
|
|
79
|
-
}
|
|
80
|
-
catch (error) {
|
|
81
|
-
return false;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
/** Returns the zap splits for an event */
|
|
85
|
-
export function getZapSplits(event) {
|
|
86
|
-
const tags = event.tags.filter((t) => t[0] === "zap" && t[1] && t[3]);
|
|
87
|
-
if (tags.length > 0) {
|
|
88
|
-
const targets = tags
|
|
89
|
-
.map((t) => ({ pubkey: t[1], relay: t[2], weight: parseFloat(t[3]) }))
|
|
90
|
-
.filter((p) => Number.isFinite(p.weight));
|
|
91
|
-
const total = targets.reduce((v, p) => v + p.weight, 0);
|
|
92
|
-
return targets.map((p) => ({ ...p, percent: p.weight / total }));
|
|
93
|
-
}
|
|
94
|
-
return undefined;
|
|
95
|
-
}
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
package/dist/logger.d.ts
DELETED
package/dist/logger.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { BehaviorSubject } from "rxjs";
|
|
2
|
-
/** Subscribes and returns the observables current or next value */
|
|
3
|
-
export function getValue(observable) {
|
|
4
|
-
if (observable instanceof BehaviorSubject)
|
|
5
|
-
return observable.value;
|
|
6
|
-
if (Reflect.has(observable, "value"))
|
|
7
|
-
return Reflect.get(observable, "value");
|
|
8
|
-
return new Promise((res) => {
|
|
9
|
-
const sub = observable.subscribe((v) => {
|
|
10
|
-
res(v);
|
|
11
|
-
sub.unsubscribe();
|
|
12
|
-
});
|
|
13
|
-
});
|
|
14
|
-
}
|
package/dist/observable/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Observable, ShareConfig } from "rxjs";
|
|
2
|
-
/**
|
|
3
|
-
* Creates an operator that adds a 'value' property and multiplexes the source
|
|
4
|
-
* @param config Optional ShareConfig for customizing sharing behavior
|
|
5
|
-
*/
|
|
6
|
-
export declare function shareLatestValue<T>(config?: ShareConfig<T>): (source: Observable<T>) => Observable<T> & {
|
|
7
|
-
value: T | undefined;
|
|
8
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { share } from "rxjs";
|
|
2
|
-
import { tap } from "rxjs/operators";
|
|
3
|
-
/**
|
|
4
|
-
* Creates an operator that adds a 'value' property and multiplexes the source
|
|
5
|
-
* @param config Optional ShareConfig for customizing sharing behavior
|
|
6
|
-
*/
|
|
7
|
-
export function shareLatestValue(config = {}) {
|
|
8
|
-
return (source) => {
|
|
9
|
-
// Create storage for latest value
|
|
10
|
-
let latestValue = undefined;
|
|
11
|
-
// Create shared source with value tracking
|
|
12
|
-
const shared$ = source.pipe(tap((value) => {
|
|
13
|
-
latestValue = value;
|
|
14
|
-
}), share(config));
|
|
15
|
-
// Add value property
|
|
16
|
-
Object.defineProperty(shared$, "value", {
|
|
17
|
-
get: () => latestValue,
|
|
18
|
-
});
|
|
19
|
-
return shared$;
|
|
20
|
-
};
|
|
21
|
-
}
|
package/dist/promise/deferred.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/** Creates a controlled promise */
|
|
2
|
-
export function createDefer() {
|
|
3
|
-
let _resolve;
|
|
4
|
-
let _reject;
|
|
5
|
-
const promise = new Promise((resolve, reject) => {
|
|
6
|
-
// @ts-ignore
|
|
7
|
-
_resolve = resolve;
|
|
8
|
-
_reject = reject;
|
|
9
|
-
});
|
|
10
|
-
// @ts-ignore
|
|
11
|
-
promise.resolve = _resolve;
|
|
12
|
-
// @ts-ignore
|
|
13
|
-
promise.reject = _reject;
|
|
14
|
-
return promise;
|
|
15
|
-
}
|
package/dist/promise/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./deferred.js";
|
package/dist/promise/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./deferred.js";
|
package/dist/queries/comment.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { COMMENT_KIND, getEventUID } from "../helpers/index.js";
|
|
2
|
-
import { isParameterizedReplaceableKind } from "nostr-tools/kinds";
|
|
3
|
-
/** Returns all NIP-22 comment replies for the event */
|
|
4
|
-
export function CommentsQuery(parent) {
|
|
5
|
-
return {
|
|
6
|
-
key: `${getEventUID(parent)}-comments`,
|
|
7
|
-
run: (events) => {
|
|
8
|
-
const filter = { kinds: [COMMENT_KIND], "#e": [parent.id] };
|
|
9
|
-
if (isParameterizedReplaceableKind(parent.kind))
|
|
10
|
-
filter["#a"] = [getEventUID(parent)];
|
|
11
|
-
return events.timeline(filter);
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
}
|
package/dist/queries/comments.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { COMMENT_KIND, getEventUID } from "../helpers/index.js";
|
|
2
|
-
import { isParameterizedReplaceableKind } from "nostr-tools/kinds";
|
|
3
|
-
/** Returns all NIP-22 comment replies for the event */
|
|
4
|
-
export function CommentsQuery(parent) {
|
|
5
|
-
return {
|
|
6
|
-
key: `${getEventUID(parent)}-comments`,
|
|
7
|
-
run: (events) => {
|
|
8
|
-
const filter = { kinds: [COMMENT_KIND], "#e": [parent.id] };
|
|
9
|
-
if (isParameterizedReplaceableKind(parent.kind))
|
|
10
|
-
filter["#a"] = [getEventUID(parent)];
|
|
11
|
-
return events.timeline(filter);
|
|
12
|
-
},
|
|
13
|
-
};
|
|
14
|
-
}
|
package/dist/queries/index.d.ts
DELETED
package/dist/queries/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { kinds } from "nostr-tools";
|
|
2
|
-
import { map } from "rxjs/operators";
|
|
3
|
-
import { getInboxes, getOutboxes } from "../helpers/mailboxes.js";
|
|
4
|
-
/** A query that gets and parses the inbox and outbox relays for a pubkey */
|
|
5
|
-
export function MailboxesQuery(pubkey) {
|
|
6
|
-
return {
|
|
7
|
-
key: pubkey,
|
|
8
|
-
run: (events) => events.replaceable(kinds.RelayList, pubkey).pipe(map((event) => event && {
|
|
9
|
-
inboxes: getInboxes(event),
|
|
10
|
-
outboxes: getOutboxes(event),
|
|
11
|
-
})),
|
|
12
|
-
};
|
|
13
|
-
}
|
package/dist/queries/profile.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { kinds } from "nostr-tools";
|
|
2
|
-
import { filter, map } from "rxjs/operators";
|
|
3
|
-
import { getProfileContent, isValidProfile } from "../helpers/profile.js";
|
|
4
|
-
/** A query that gets and parses the kind 0 metadata for a pubkey */
|
|
5
|
-
export function ProfileQuery(pubkey) {
|
|
6
|
-
return {
|
|
7
|
-
key: pubkey,
|
|
8
|
-
run: (events) => {
|
|
9
|
-
return events.replaceable(kinds.Metadata, pubkey).pipe(filter(isValidProfile), map((event) => event && getProfileContent(event)));
|
|
10
|
-
},
|
|
11
|
-
};
|
|
12
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { kinds } from "nostr-tools";
|
|
2
|
-
import { getEventUID, isReplaceable } from "../helpers/event.js";
|
|
3
|
-
/** A query that returns all reactions to an event (supports replaceable events) */
|
|
4
|
-
export function ReactionsQuery(event) {
|
|
5
|
-
return {
|
|
6
|
-
key: getEventUID(event),
|
|
7
|
-
run: (events) => events.timeline(isReplaceable(event.kind)
|
|
8
|
-
? [
|
|
9
|
-
{ kinds: [kinds.Reaction], "#e": [event.id] },
|
|
10
|
-
{ kinds: [kinds.Reaction], "#a": [getEventUID(event)] },
|
|
11
|
-
]
|
|
12
|
-
: [
|
|
13
|
-
{
|
|
14
|
-
kinds: [kinds.Reaction],
|
|
15
|
-
"#e": [event.id],
|
|
16
|
-
},
|
|
17
|
-
]),
|
|
18
|
-
};
|
|
19
|
-
}
|
package/dist/queries/simple.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { Filter, NostrEvent } from "nostr-tools";
|
|
2
|
-
import { Query } from "../query-store/index.js";
|
|
3
|
-
/** Creates a Query that returns a single event or undefined */
|
|
4
|
-
export declare function SingleEventQuery(id: string): Query<NostrEvent | undefined>;
|
|
5
|
-
/** Creates a Query that returns a multiple events in a map */
|
|
6
|
-
export declare function MultipleEventsQuery(ids: string[]): Query<Record<string, NostrEvent>>;
|
|
7
|
-
/** Creates a Query returning the latest version of a replaceable event */
|
|
8
|
-
export declare function ReplaceableQuery(kind: number, pubkey: string, d?: string): Query<NostrEvent | undefined>;
|
|
9
|
-
/** Creates a Query that returns an array of sorted events matching the filters */
|
|
10
|
-
export declare function TimelineQuery(filters: Filter | Filter[], keepOldVersions?: boolean): Query<NostrEvent[]>;
|
|
11
|
-
/** Creates a Query that returns a directory of events by their UID */
|
|
12
|
-
export declare function ReplaceableSetQuery(pointers: {
|
|
13
|
-
kind: number;
|
|
14
|
-
pubkey: string;
|
|
15
|
-
identifier?: string;
|
|
16
|
-
}[]): Query<Record<string, NostrEvent>>;
|