/** * Copyright 2025 The Lotusia Stewardship * Github: https://github.com/LotusiaStewardship * License: MIT */ import { Buffer } from 'buffer/'; import OpCode from './opcode.js'; export type ScriptChunkLokadUTF8 = 'RANK' | 'RNKC'; export type ScriptChunkPlatformUTF8 = 'lotusia' | 'twitter'; export type ScriptChunkSentimentUTF8 = 'positive' | 'negative' | 'neutral'; export type ScriptChunkLokadMap = Map; export type ScriptChunkPlatformMap = Map; export type ScriptChunkSentimentMap = Map; export type ScriptChunkField = 'sentiment' | 'platform' | 'profileId' | 'postId' | 'comment' | 'postHash' | 'instanceId'; export type ScriptChunk = { /** Byte offset of the chunk in the output script */ offset: number | null; /** Byte length of the chunk in the output script */ len: number | null; /** Map of supported RANK script chunks */ map?: ScriptChunkLokadMap | ScriptChunkPlatformMap | ScriptChunkSentimentMap; }; /** Required RNKC script chunks */ export type ScriptChunksRNKC = { [name in Exclude]: ScriptChunk; }; /** Required RANK script chunks */ export type ScriptChunksRANK = { [name in Exclude]: ScriptChunk; }; /** Optional RANK script chunks */ export type ScriptChunksOptionalRANK = { [name in Extract]: ScriptChunk; }; /** OP_RETURN \ \ \ [\ \ [\]] */ export type TransactionOutputRANK = { /** positive or negative sentiment (can support more) */ sentiment: ScriptChunkSentimentUTF8; /** e.g. Twitter/X.com, etc. */ platform: ScriptChunkPlatformUTF8; /** who the ranking is for */ profileId: string; /** optional post ID if ranking specific content */ postId?: string; }; /** OP_RETURN \ \ \ \ */ export type TransactionOutputRNKC = { /** outIdx 1 and 2 concatenated as comment data in UTF-8 encoding */ data: Uint8Array; /** Minimum fee rate for accepting RNKC transaction, in satoshis per byte */ feeRate: number; /** e.g. Twitter/X.com, etc. */ inReplyToPlatform: ScriptChunkPlatformUTF8; /** who the comment is replying to */ inReplyToProfileId?: string; /** ID of the post being replied to */ inReplyToPostId?: string; }; /** Transaction data for the backend indexer */ export type Transaction = { txid: string; outIdx: number; sats: bigint; firstSeen: bigint; scriptPayload: string; instanceId?: string; height?: number; timestamp?: bigint; }; /** RANK transaction data for the backend indexer */ export type TransactionRANK = TransactionOutputRANK & Transaction; /** RNKC transaction data for the backend indexer */ export type TransactionRNKC = TransactionOutputRNKC & Transaction; /** Target entity being ranked by a RANK transaction, commented on by an RNKC transaction, etc. (e.g. Profile, Post, etc.) */ export type TargetEntity = { id: string; platform: string; ranking: bigint; ranks: Omit[]; comments: Omit[]; satsPositive: bigint; satsNegative: bigint; votesPositive: number; votesNegative: number; }; /** * `IndexedTransactionRANK` objects are converted to a `ProfileMap` for database ops * * `string` is `profileId` */ export type ProfileMap = Map; export type PostMap = Map; /** */ export type Profile = TargetEntity & { posts?: PostMap; }; /** */ export type Post = TargetEntity & { profileId: string; /** If this post is a RNKC transaction, this is set for establishing relation to `RankComment` */ data?: Uint8Array; }; /** Platform parameters */ export type PlatformParameters = { profileId: { len: number; regex: RegExp; }; postId: { len: number; regex: RegExp; type: 'BigInt' | 'Number' | 'String'; }; }; /** LOKAD chunk map */ export declare const LOKAD_PREFIX_RANK = 1380011595; export declare const LOKAD_PREFIX_RNKC = 1380862787; export declare const SCRIPT_CHUNK_LOKAD: ScriptChunkLokadMap; export declare const RANK_SENTIMENT_NEUTRAL = OpCode.OP_16; export declare const RANK_SENTIMENT_POSITIVE = OpCode.OP_1; export declare const RANK_SENTIMENT_NEGATIVE = OpCode.OP_0; /** Sentiment chunk map */ export declare const SCRIPT_CHUNK_SENTIMENT: ScriptChunkSentimentMap; /** Sentiment OP code map */ export declare const RANK_SENTIMENT_OP_CODES: Map; /** Platform chunk map */ export declare const SCRIPT_CHUNK_PLATFORM: ScriptChunkPlatformMap; /** Required RANK Comment script chunks */ export declare const ScriptChunksRNKCMap: Map; /** Length of the required RANK script chunks in bytes */ export declare const RANK_SCRIPT_REQUIRED_LENGTH = 10; /** Required RANK script chunks */ export declare const ScriptChunksRANKMap: Map; export declare const ScriptChunksOptionalRANKMap: Map; /** Platform configuration */ export declare const PlatformConfiguration: Map; /** * RANK script utilities */ /** * Convert the profile ID to a buffer * @param platform - The platform to convert the profile ID for * @param profileId - The profile ID to convert * @returns The profile ID buffer */ export declare function toProfileIdBuf(platform: ScriptChunkPlatformUTF8, profileId: string): Buffer | null; /** * Convert the `OP_RETURN` profile name back to UTF-8 with null bytes removed * @param profileIdBuf - The profile ID buffer to convert, padded with null bytes * @returns The UTF-8 profile ID */ export declare function toProfileIdUTF8(profileIdBuf: Buffer): string; /** * Convert the post ID to a buffer * @param platform - The platform to convert the post ID for * @param postId - The post ID to convert * @returns The post ID buffer */ export declare function toPostIdBuf(platform: ScriptChunkPlatformUTF8, postId: string): Buffer | undefined; /** * Convert the UTF-8 platform name to the defined 1-byte platform hex code * @param platform * @returns */ export declare function toPlatformBuf(platform: ScriptChunkPlatformUTF8): Buffer | undefined; /** * Convert the defined 1-byte platform hex code to the UTF-8 platform name * @param platformBuf */ export declare function toPlatformUTF8(platformBuf: Buffer): ScriptChunkPlatformUTF8 | undefined; /** * Convert the UTF-8 sentiment name to the defined 1-byte OP code * @param sentiment * @returns */ export declare function toSentimentOpCode(sentiment: ScriptChunkSentimentUTF8): string | undefined; /** * Convert the defined 1-byte sentiment OP code to the UTF-8 sentiment name * @param sentimentBuf */ export declare function toSentimentUTF8(sentimentBuf: Buffer): ScriptChunkSentimentUTF8 | undefined; /** * Convert the comment buffer to a UTF-8 string * @param commentBuf - The comment buffer to convert * @returns The UTF-8 string */ export declare function toCommentUTF8(commentBuf: Buffer | Uint8Array): string | undefined; /** * Create a hex-encoded RANK script from the given parameters * @param sentiment - The sentiment to use * @param platform - The platform to use * @param profileId - The profile ID to use * @param postId - The post ID to use * @returns The hex-encoded RANK script, as `Buffer` */ export declare function toScriptRANK(sentiment: ScriptChunkSentimentUTF8, platform: ScriptChunkPlatformUTF8, profileId: string, postId?: string): Buffer; /** * Create a hex-encoded RANK Comment script from the given parameters * * RNKC requires 2 output scripts at minimum, so we return output scripts in an * array of `Buffer` objects according to outIdx. * @param platform - The platform to use * @param profileId - The profile ID to use * @param postId - The post ID to use * @param comment - The comment to use * @returns The hex-encoded RANK Comment script */ export declare function toScriptRNKC({ platform, profileId, postId, comment, }: { platform: ScriptChunkPlatformUTF8; profileId: string; postId?: string; comment: string; }): Buffer[]; /** * Processor for defined LOKAD protocols (RANK, RNKC, etc.) * @param script - The script to process, as a `Buffer` */ export declare class ScriptProcessor { private chunks; /** The script to process, as a `Buffer` */ private script; /** Supplemental scripts, e.g. outIdx 1 and/or 2 for RNKC */ private supplementalScripts; constructor(script: Buffer); /** * Add a supplemental OP_RETURN script to the processor * @param script - The script to add, as a `Buffer` * @returns true if the script was added, false otherwise */ addScript(script: string | Buffer): boolean; /** * Get the LOKAD type from the script * @returns The LOKAD type or undefined if invalid */ get lokadType(): ScriptChunkLokadUTF8 | undefined; /** * Process the LOKAD chunk * @returns The LOKAD value or undefined if invalid */ private processLokad; /** * Process the sentiment chunk (RANK) * @returns The sentiment value or undefined if invalid */ private processSentiment; /** * Process the platform chunk * @returns The platform value or undefined if invalid */ private processPlatform; /** * Process the profileId chunk * @returns The profileId value or undefined if invalid */ private processProfileId; /** * Process the postId chunk * @returns The postId value or undefined if invalid */ private processPostId; /** * Process the RNKC comment chunks (outIdx 1 and 2) * @param scripts - outIdx 1 and 2 scripts, if outIdx 0 is RNKC * @returns The comment value or null if invalid */ private processComment; /** * Validate the required RANK chunks and store the processed output * @returns true if all required chunks are valid, false otherwise */ processScriptRANK(): TransactionOutputRANK | null; /** * Validate the required RNKC chunks and store the processed output * @returns true if all required chunks are valid, false otherwise */ processScriptRNKC(burnedSats: number | bigint, options?: { minDataLength: number; minFeeRate: number; }): TransactionOutputRNKC | null; } //# sourceMappingURL=index.d.ts.map