@node-dlc/messaging
Version:
DLC Messaging Protocol
77 lines (76 loc) • 2.8 kB
TypeScript
/// <reference types="node" />
import { MessageType } from '../MessageType';
import { IDlcMessage } from './DlcMessage';
import { IOracleEventJSON, OracleEvent } from './OracleEvent';
/**
* Oracle announcement that describe an event and the way that an oracle will
* attest to it. Updated to be rust-dlc compliant.
*
* In order to make it possible to hold oracles accountable in cases where
* they do not release a signature for an event outcome, there needs to be
* a proof that an oracle has committed to a given outcome. This proof is
* given in a so-called oracle announcement, which contains an oracle event
* together with the oracle public key and a signature over its serialization,
* which must be valid with respect to the specified public key.
*
* This also makes it possible for users to obtain oracle event information
* from an un-trusted peer while being guaranteed that it originates from a
* given oracle.
*/
export declare class OracleAnnouncement implements IDlcMessage {
static type: MessageType;
/**
* Creates an OracleAnnouncement from JSON data
* @param json JSON object representing oracle announcement
*/
static fromJSON(json: any): OracleAnnouncement;
/**
* Deserializes an oracle_announcement message
* @param buf
*/
static deserialize(buf: Buffer): OracleAnnouncement;
/**
* The type for oracle_announcement message. oracle_announcement = 55332
*/
type: MessageType;
length: bigint;
/** The signature enabling verifying the origin of the announcement. */
announcementSig: Buffer;
/** The public key of the oracle (32 bytes, x-only). */
oraclePublicKey: Buffer;
/** The description of the event and attesting. */
oracleEvent: OracleEvent;
/**
* Validates the oracle announcement according to rust-dlc specification.
* This includes validating the oracle event and verifying the announcement signature.
* @throws Will throw an error if validation fails
*/
validate(): void;
/**
* Returns the nonces from the oracle event.
* This is useful for finding matching oracle announcements.
*/
getNonces(): Buffer[];
/**
* Returns the event maturity epoch from the oracle event.
*/
getEventMaturityEpoch(): number;
/**
* Returns the event ID from the oracle event.
*/
getEventId(): string;
/**
* Converts oracle_announcement to JSON (canonical rust-dlc format)
*/
toJSON(): OracleAnnouncementJSON;
/**
* Serializes the oracle_announcement message into a Buffer
*/
serialize(): Buffer;
}
export interface OracleAnnouncementJSON {
type?: number;
announcementSignature: string;
oraclePublicKey: string;
oracleEvent: IOracleEventJSON;
}