@nostr-fetch/kernel
Version:
Kernel of nostr-fetch
146 lines • 4.7 kB
TypeScript
/**
* The data structure of Nostr event.
*/
export type NostrEvent = {
id: string;
pubkey: string;
created_at: number;
kind: number;
tags: string[][];
content: string;
sig: string;
};
/**
* Standardized Nostr event kinds.
* cf. https://github.com/nostr-protocol/nips#event-kinds
*
* @deprecated use literal kind numbers instead.
*/
export declare const eventKind: {
readonly metadata: 0;
readonly text: 1;
readonly recommendRelay: 2;
readonly contacts: 3;
readonly encryptedDirectMessage: 4;
readonly eventDeletion: 5;
readonly repost: 6;
readonly reaction: 7;
readonly badgeAward: 8;
readonly genericRepost: 16;
readonly channelCreation: 40;
readonly channelMetadata: 41;
readonly channelMessage: 42;
readonly channelHideMessage: 43;
readonly channelMuteUser: 44;
readonly fileMetadata: 1063;
readonly liveChatMessage: 1311;
readonly report: 1984;
readonly label: 1985;
readonly communityPostApproval: 4550;
readonly zapRequest: 9734;
readonly zap: 9735;
readonly muteList: 10000;
readonly pinList: 10001;
readonly relayList: 10002;
readonly walletInfo: 13194;
readonly clientAuth: 22242;
readonly walletRequest: 23194;
readonly walletResponse: 23195;
readonly nostrConnect: 24133;
readonly httpAuth: 27235;
readonly categorizedPeopleList: 30000;
readonly categorizedBookmarkList: 30001;
readonly profileBadges: 30008;
readonly badgeDefinition: 30009;
readonly marketplaceStall: 30017;
readonly marketplaceProduct: 30018;
readonly article: 30023;
readonly draftArticle: 30024;
readonly appSpecificData: 30078;
readonly liveEvent: 30311;
readonly classifiedListing: 30402;
readonly draftClassifiedListing: 30403;
readonly dateBasedCalendarEvent: 31922;
readonly timeBasedCalendarEvent: 31923;
readonly calendar: 31924;
readonly calendarEventRsvp: 31925;
readonly handlerRecommendation: 31989;
readonly handlerInformation: 31990;
readonly communityDefinition: 34550;
};
/**
* Keys of filter props for tag queries.
*/
type TagQueryKey = `#${string}`;
/**
* Checks if the given string is a valid key of tag query in filter.
*
* A valid tag query key is a string that starts with `#` and followed by a single Latin alphabet (`[A-Za-z]`).
*/
export declare const isValidTagQueryKey: (s: string) => boolean;
/**
* Filter for Nostr event subscription.
*/
export type Filter = {
ids?: string[];
kinds?: number[];
authors?: string[];
since?: number;
until?: number;
limit?: number;
search?: string;
} & {
[tag in TagQueryKey]: string[];
};
type C2RReq = [type: "REQ", subId: string, ...filters: Filter[]];
type C2RClose = [type: "CLOSE", subId: string];
export type C2RMessage = C2RReq | C2RClose;
export type C2RMessageType = C2RMessage[0];
type R2CEvent = [type: "EVENT", subId: string, event: NostrEvent];
type R2CEose = [type: "EOSE", subId: string];
type R2CClosed = [type: "CLOSED", subId: string, message: string];
type R2CNotice = [type: "NOTICE", notice: string];
export type R2CMessage = R2CEvent | R2CEose | R2CClosed | R2CNotice;
export type R2CMessageType = R2CMessage[0];
export type R2CSubMessage = R2CEvent | R2CEose;
export type R2CSubMessageType = R2CSubMessage[0];
export declare const parseR2CMessage: (rawMsg: string) => R2CMessage | undefined;
export declare const validateEvent: (rawEv: Record<string, unknown>) => rawEv is NostrEvent;
/**
* Type of functions that verify the signature of the Nostr event.
*/
export type EventVerifier = (event: NostrEvent) => boolean | Promise<boolean>;
/**
* no-op `EventVerifier` which regards all events have a valid signature.
*
* @example
* // emulating `skipVerification: true`
* import { NostrFetcher, noopVerifier } from "nostr-fetch";
*
* const fetcher = NostrFetcher.init();
* const events = fetcher.allEventsIterator({ ... }, { ... }, { eventVerifier: noopVerifier });
*/
export declare const noopVerifier: EventVerifier;
export declare class FilterMatcher {
#private;
constructor(filters: Filter[]);
match(ev: NostrEvent): boolean;
}
/**
* Queries supported NIP numbers of the given relay.
*/
export declare const querySupportedNips: (relayUrl: string) => Promise<Set<number>>;
export declare const generateSubId: () => string;
/**
* Checks if the NOTICE message seems to have to do with REQs by fetcher.
*
* Considers following relay implementations:
*
* - strfry
* - nostream
* - nostr-rs-relay
* - relayer
*/
export declare const isNoticeForReqError: (notice: string) => boolean;
export {};
//# sourceMappingURL=nostr.d.ts.map