@graperank/protocols-nostr
Version:
The Nostr Protocols plugin for GrapeRank allows the Interpreter to fetch and normalize ratings data from any kind[s] of Nostr event.
40 lines (39 loc) • 2.11 kB
TypeScript
import { Event as NostrEvent } from 'nostr-tools/core';
import { InterpretationProtocol, ProtocolParams, ProtocolRequest, RatingsMap, userId } from "@graperank/util/types";
export type NostrProtocolConfig<ParamsType extends ProtocolParams> = {
kinds: number[];
params: ParamsType;
interpret?: (instance: InterpretationProtocol<ParamsType>, dos: number) => Promise<RatingsMap>;
validate?: (events: Set<NostrEvent>, authors: userId[], previous?: Set<NostrEvent>) => boolean | userId[];
};
export declare class NostrProtocol<ParamsType extends ProtocolParams> implements InterpretationProtocol<ParamsType> {
readonly kinds: number[];
request: ProtocolRequest;
private _params;
get params(): ParamsType & ProtocolParams;
fetched: Set<NostrEvent>[];
interpreted: RatingsMap;
interpret: (dos?: number) => Promise<RatingsMap>;
validate?: (events: Set<NostrEvent>, authors: userId[], previous?: Set<NostrEvent>) => boolean | userId[];
constructor(config: NostrProtocolConfig<ParamsType>);
fetchData(authors?: Set<userId>): Promise<number>;
private fetchEventsPromise;
}
export declare function applyRatingsByTag(instance: NostrProtocol<any>, dos: number, tag?: string, rateeindex?: number, scoreindex?: number): Promise<RatingsMap>;
export declare function validatePubkey(pubkey: string): boolean;
export declare function validateEachEventHasAuthor(events: Set<NostrEvent>, authors: userId[], previous?: Set<NostrEvent>): boolean | userId[];
export declare function validateOneEventIsNew(events: Set<NostrEvent>, authors: userId[], previous?: Set<NostrEvent>): boolean | userId[];
export declare function getEventsAuthors(events: Set<NostrEvent>, exclude?: userId[]): userId[];
export type pubkey = string;
export type signature = string;
/**
* All data collected from Nostr relating to a collection of pubkeys
*/
export type NostrUserCache = Record<pubkey, {
readonly follows: pubkey[];
readonly followedBy: pubkey[];
readonly mutes: pubkey[];
readonly mutedBy: pubkey[];
readonly reports: pubkey[];
readonly reportedBy: pubkey[];
}>;