Add proof-measure client + bump to 1.4.0
proof-measure is a separate, public, unauthenticated Dragonchain service. Adds: - UnauthHttpClient: HMAC-free transport mirroring DragonchainClient (timeout, agent, redirect refusal). - ProofMeasureClient: getSecurity / report / health; default base URL https://proof-measure.dragonchain.com. Standalone (new ProofMeasureClient()) and via DragonchainSDK.proofMeasure. - Proof-measure types (decimals as strings, timestamps as numbers). - jest tests.
This commit is contained in:
69
src/proofMeasure.ts
Normal file
69
src/proofMeasure.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
/**
|
||||
* 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<ProofMeasureSecurityResult> {
|
||||
const query = since && since > 0 ? `?since=${since}` : '';
|
||||
return this.client.get<ProofMeasureSecurityResult>(`/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<ProofMeasureTransactionReport> {
|
||||
return this.client.post<ProofMeasureTransactionReport>(
|
||||
'/api/v1/report',
|
||||
ContentType.JSON,
|
||||
request
|
||||
);
|
||||
}
|
||||
|
||||
/** Reports service liveness and DB reachability. */
|
||||
async health(): Promise<ProofMeasureHealthResponse> {
|
||||
return this.client.get<ProofMeasureHealthResponse>('/api/v1/health');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user