UNPKG

@node-dlc/messaging

Version:
91 lines (90 loc) 3.5 kB
/// <reference types="node" /> import { MessageType } from '../MessageType'; import { IDlcMessage } from './DlcMessage'; import { DigitDecompositionEventDescriptor, EnumEventDescriptor, EventDescriptor, IDigitDecompositionEventDescriptorJSON, IEnumEventDescriptorJSON } from './EventDescriptor'; /** * Oracle event containing information about an event and the way that the * oracle will attest to it. Updated to be rust-dlc compliant. * * For users to be able to create DLCs based on a given event, they also * need to obtain information about the oracle and the time at which it * plans on releasing a signature over the event outcome. OracleEvent * messages contain such information, which includes: * - the nonce(s) that will be used to sign the event outcome(s) * - the earliest time (UTC) at which it plans on releasing a signature * over the event outcome, in epoch seconds * - the event descriptor * - the event ID which can be a name or categorization associated with * the event by the oracle */ export declare class OracleEvent implements IDlcMessage { static type: MessageType; /** * Creates an OracleEvent from JSON data * @param json JSON object representing oracle event */ static fromJSON(json: any): OracleEvent; /** * Deserializes an oracle_event message * @param buf */ static deserialize(buf: Buffer): OracleEvent; /** * The type for oracle_event message. oracle_event = 55330 */ type: MessageType; length: bigint; /** The nonces that the oracle will use to attest to the event outcome. */ oracleNonces: Buffer[]; /** The expected maturity of the contract (Unix timestamp). */ eventMaturityEpoch: number; /** The description of the event. */ eventDescriptor: EventDescriptor; /** The ID of the event. */ eventId: string; /** * Validates correctness of all fields in the message according to rust-dlc specification. * This includes validating that the number of nonces matches the expected count for the event type. * https://github.com/discreetlogcontracts/dlcspecs/blob/master/Oracle.md * @throws Will throw an error if validation fails */ validate(): void; /** * Returns the expected number of nonces based on the event descriptor type. * This matches the rust-dlc validation logic. */ private getExpectedNonceCount; /** * Returns whether this event is for enumerated outcomes. */ isEnumEvent(): boolean; /** * Returns whether this event is for numerical outcomes. */ isDigitDecompositionEvent(): boolean; /** * Returns the event descriptor as EnumEventDescriptor if it's an enum event. * @throws Error if not an enum event */ getEnumEventDescriptor(): EnumEventDescriptor; /** * Returns the event descriptor as DigitDecompositionEventDescriptor if it's a numerical event. * @throws Error if not a numerical event */ getDigitDecompositionEventDescriptor(): DigitDecompositionEventDescriptor; /** * Converts oracle_event to JSON */ toJSON(): IOracleEventJSON; /** * Serializes the oracle_event message into a Buffer */ serialize(): Buffer; } export interface IOracleEventJSON { type?: number; oracleNonces: string[]; eventMaturityEpoch: number; eventDescriptor: IEnumEventDescriptorJSON | IDigitDecompositionEventDescriptorJSON; eventId: string; }