Add proof-measure client + bump to 1.4.0
Some checks failed
Build and Test / build (16.x) (push) Failing after 45s
Build and Test / build (18.x) (push) Failing after 40s
Publish to NPM Registry / publish (release) Successful in 54s
Build and Test / build (20.x) (push) Failing after 38s

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:
2026-06-04 13:45:09 -04:00
parent a35dc508b0
commit 5a943f45a6
7 changed files with 394 additions and 1 deletions

69
src/proofMeasure.ts Normal file
View File

@@ -0,0 +1,69 @@
/**
* Client for the Dragonchain proof-measure service — the measured-immutability
* / "securedBy" metric for L1L5 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');
}
}