/** * Client for the Dragonchain proof-measure service — the measured-immutability * / "securedBy" metric for L1–L5 verification chains. * * proof-measure is a separate, public, UNauthenticated service (no API keys), * so this client needs only a base URL. It exposes a network's accumulated * security as both a raw measure (cumulative hashes / stake-seconds) and a USD * valuation, plus a per-transaction "securedBy" report over interchain anchors. */ import { UnauthHttpClient, UnauthClientConfig } from './unauthHttpClient'; import { ContentType, ProofMeasureSecurityResult, ProofMeasureReportRequest, ProofMeasureTransactionReport, ProofMeasureHealthResponse, } from './types'; /** Public production proof-measure endpoint. */ export const PROOF_MEASURE_DEFAULT_BASE_URL = 'https://proof-measure.dragonchain.com'; export class ProofMeasureClient { private client: UnauthHttpClient; /** * @param clientOrConfig - an existing UnauthHttpClient, a config object, or * nothing. With no argument (or no baseURL) the public production endpoint is * used, so `new ProofMeasureClient()` works with zero configuration. */ constructor(clientOrConfig?: UnauthHttpClient | UnauthClientConfig) { if (clientOrConfig instanceof UnauthHttpClient) { this.client = clientOrConfig; } else { this.client = new UnauthHttpClient({ baseURL: clientOrConfig?.baseURL || PROOF_MEASURE_DEFAULT_BASE_URL, timeout: clientOrConfig?.timeout, agent: clientOrConfig?.agent, }); } } /** * Returns the security a public network (network = 'BTC' or 'ETH') has * accumulated since the given unix timestamp, as a raw measure + USD * valuation. Omit `since` (or pass <= 0) to use the service default window. */ async getSecurity(network: string, since?: number): Promise { const query = since && since > 0 ? `?since=${since}` : ''; return this.client.get(`/api/v1/security/${network}${query}`); } /** * Computes the per-transaction "securedBy" report for the supplied interchain * anchors: each anchor's raw + USD security since it was placed, plus totals. */ async report(request: ProofMeasureReportRequest): Promise { return this.client.post( '/api/v1/report', ContentType.JSON, request ); } /** Reports service liveness and DB reachability. */ async health(): Promise { return this.client.get('/api/v1/health'); } }