applesauce-core
Advanced tools
Comparing version 0.0.0-next-20241115160057 to 0.0.0-next-20241119142128
@@ -8,2 +8,3 @@ export type ParsedInvoice = { | ||
}; | ||
/** Parses a lightning invoice */ | ||
export declare function parseBolt11(paymentRequest: string): ParsedInvoice; |
import { decode } from "light-bolt11-decoder"; | ||
/** Parses a lightning invoice */ | ||
export function parseBolt11(paymentRequest) { | ||
@@ -3,0 +4,0 @@ const decoded = decode(paymentRequest); |
import { EventTemplate, NostrEvent } from "nostr-tools"; | ||
export declare function getEmojiTag(event: NostrEvent | EventTemplate, code: string): ["emoji", string, string]; | ||
/** Returns the name of a NIP-30 emoji pack */ | ||
export declare function getPackName(pack: NostrEvent): string | undefined; | ||
/** Returns an array of emojis from a NIP-30 emoji pack */ | ||
export declare function getEmojis(pack: NostrEvent): { | ||
name: string; | ||
url: string; | ||
}[]; |
@@ -0,1 +1,2 @@ | ||
import { getTagValue } from "./event.js"; | ||
export function getEmojiTag(event, code) { | ||
@@ -5,1 +6,11 @@ code = code.replace(/^:|:$/g, "").toLocaleLowerCase(); | ||
} | ||
/** Returns the name of a NIP-30 emoji pack */ | ||
export function getPackName(pack) { | ||
return getTagValue(pack, "title") || getTagValue(pack, "d"); | ||
} | ||
/** Returns an array of emojis from a NIP-30 emoji pack */ | ||
export function getEmojis(pack) { | ||
return pack.tags | ||
.filter((t) => t[0] === "emoji" && t[1] && t[2]) | ||
.map((t) => ({ name: t[1], url: t[2] })); | ||
} |
@@ -0,1 +1,2 @@ | ||
/** Returns the parsed JSON or undefined if invalid */ | ||
export declare function safeParse<T extends unknown = any>(str: string): T | undefined; |
@@ -0,1 +1,2 @@ | ||
/** Returns the parsed JSON or undefined if invalid */ | ||
export function safeParse(str) { | ||
@@ -2,0 +3,0 @@ try { |
import { NostrEvent } from "nostr-tools"; | ||
export declare const MailboxesInboxesSymbol: unique symbol; | ||
export declare const MailboxesOutboxesSymbol: unique symbol; | ||
declare module "nostr-tools" { | ||
interface Event { | ||
[MailboxesInboxesSymbol]?: string[]; | ||
[MailboxesOutboxesSymbol]?: string[]; | ||
} | ||
} | ||
/** | ||
@@ -11,0 +5,0 @@ * Parses a 10002 event and stores the inboxes in the event using the {@link MailboxesInboxesSymbol} symbol |
import { safeRelayUrl } from "./relays.js"; | ||
import { getOrComputeCachedValue } from "./cache.js"; | ||
export const MailboxesInboxesSymbol = Symbol.for("mailboxes-inboxes"); | ||
@@ -8,3 +9,3 @@ export const MailboxesOutboxesSymbol = Symbol.for("mailboxes-outboxes"); | ||
export function getInboxes(event) { | ||
if (!event[MailboxesInboxesSymbol]) { | ||
return getOrComputeCachedValue(event, MailboxesInboxesSymbol, () => { | ||
const inboxes = []; | ||
@@ -18,5 +19,4 @@ for (const tag of event.tags) { | ||
} | ||
event[MailboxesInboxesSymbol] = inboxes; | ||
} | ||
return event[MailboxesInboxesSymbol]; | ||
return inboxes; | ||
}); | ||
} | ||
@@ -27,3 +27,3 @@ /** | ||
export function getOutboxes(event) { | ||
if (!event[MailboxesOutboxesSymbol]) { | ||
return getOrComputeCachedValue(event, MailboxesOutboxesSymbol, () => { | ||
const outboxes = []; | ||
@@ -37,5 +37,4 @@ for (const tag of event.tags) { | ||
} | ||
event[MailboxesOutboxesSymbol] = outboxes; | ||
} | ||
return event[MailboxesOutboxesSymbol]; | ||
return outboxes; | ||
}); | ||
} |
@@ -19,1 +19,3 @@ import { NostrEvent } from "nostr-tools"; | ||
export declare function getProfileContent(event: NostrEvent): ProfileContent; | ||
/** Checks if the content of the kind 0 event is valid JSON */ | ||
export declare function isValidProfile(profile?: NostrEvent): boolean; |
@@ -0,1 +1,2 @@ | ||
import { kinds } from "nostr-tools"; | ||
import { getOrComputeCachedValue } from "./cache.js"; | ||
@@ -17,1 +18,15 @@ export const ProfileContentSymbol = Symbol.for("profile-content"); | ||
} | ||
/** Checks if the content of the kind 0 event is valid JSON */ | ||
export function isValidProfile(profile) { | ||
if (!profile) | ||
return false; | ||
if (profile.kind !== kinds.Metadata) | ||
return false; | ||
try { | ||
getProfileContent(profile); | ||
return true; | ||
} | ||
catch (error) { | ||
return false; | ||
} | ||
} |
@@ -0,4 +1,10 @@ | ||
/** Tests if a string is hex */ | ||
export declare function isHex(str?: string): boolean; | ||
/** Tests if a string is a 64 length hex string */ | ||
export declare function isHexKey(key?: string): boolean; | ||
/** | ||
* Remove invisible characters from a string | ||
* @see read more https://www.regular-expressions.info/unicode.html#category | ||
*/ | ||
export declare function stripInvisibleChar(str: string): string; | ||
export declare function stripInvisibleChar(str?: string | undefined): string | undefined; |
@@ -0,1 +1,2 @@ | ||
/** Tests if a string is hex */ | ||
export function isHex(str) { | ||
@@ -6,2 +7,3 @@ if (str?.match(/^[0-9a-f]+$/i)) | ||
} | ||
/** Tests if a string is a 64 length hex string */ | ||
export function isHexKey(key) { | ||
@@ -8,0 +10,0 @@ if (key?.toLowerCase()?.match(/^[0-9a-f]{64}$/)) |
@@ -14,1 +14,2 @@ import { NostrEvent } from "nostr-tools"; | ||
export declare function getZapRequest(zap: NostrEvent): import("nostr-tools").Event; | ||
export declare function isValidZap(zap?: NostrEvent): boolean; |
@@ -1,2 +0,2 @@ | ||
import { nip57 } from "nostr-tools"; | ||
import { kinds, nip57 } from "nostr-tools"; | ||
import { getOrComputeCachedValue } from "./cache.js"; | ||
@@ -53,1 +53,15 @@ import { getTagValue } from "./event.js"; | ||
} | ||
export function isValidZap(zap) { | ||
if (!zap) | ||
return false; | ||
if (zap.kind !== kinds.Zap) | ||
return false; | ||
try { | ||
getZapRequest(zap); | ||
getZapRecipient(zap); | ||
return true; | ||
} | ||
catch (error) { | ||
return false; | ||
} | ||
} |
import { kinds } from "nostr-tools"; | ||
import { map } from "rxjs/operators"; | ||
import { getProfileContent } from "../helpers/profile.js"; | ||
import { filter, map } from "rxjs/operators"; | ||
import { getProfileContent, isValidProfile } from "../helpers/profile.js"; | ||
export function ProfileQuery(pubkey) { | ||
@@ -8,5 +8,5 @@ return { | ||
run: (events) => { | ||
return events.replaceable(kinds.Metadata, pubkey).pipe(map((event) => event && getProfileContent(event))); | ||
return events.replaceable(kinds.Metadata, pubkey).pipe(filter(isValidProfile), map((event) => event && getProfileContent(event))); | ||
}, | ||
}; | ||
} |
@@ -0,3 +1,5 @@ | ||
import { map } from "rxjs"; | ||
import { kinds } from "nostr-tools"; | ||
import { getCoordinateFromAddressPointer, isAddressPointer } from "../helpers/pointers.js"; | ||
import { isValidZap } from "../helpers/zap.js"; | ||
export function EventZapsQuery(id) { | ||
@@ -8,7 +10,9 @@ return { | ||
if (isAddressPointer(id)) { | ||
return events.timeline([{ kinds: [kinds.Zap], "#a": [getCoordinateFromAddressPointer(id)] }]); | ||
return events | ||
.timeline([{ kinds: [kinds.Zap], "#a": [getCoordinateFromAddressPointer(id)] }]) | ||
.pipe(map((events) => events.filter(isValidZap))); | ||
} | ||
else { | ||
id = typeof id === "string" ? id : id.id; | ||
return events.timeline([{ kinds: [kinds.Zap], "#e": [id] }]); | ||
return events.timeline([{ kinds: [kinds.Zap], "#e": [id] }]).pipe(map((events) => events.filter(isValidZap))); | ||
} | ||
@@ -15,0 +19,0 @@ }, |
{ | ||
"name": "applesauce-core", | ||
"version": "0.0.0-next-20241115160057", | ||
"version": "0.0.0-next-20241119142128", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "type": "module", |
120379
3062