Add proof-measure client (public securedBy / measured-immutability service)

proof-measure is a separate, public, unauthenticated Dragonchain service. Adds:
- client.UnauthenticatedClient: HMAC-free transport mirroring Client's
  marshal/decode/error handling.
- proofmeasure.ProofMeasureClient: GetSecurity / Report / Health, default base
  URL https://proof-measure.dragonchain.com; standalone + a DragonchainSDK.ProofMeasure handle.
- models for SecurityResult/RawMeasure/ReportRequest/TransactionReport/etc
  (decimals as strings, timestamps int64).
- httptest unit tests.
This commit is contained in:
2026-06-04 13:40:21 -04:00
parent bc2b622873
commit 7d8e23768f
6 changed files with 441 additions and 0 deletions

View File

@@ -206,3 +206,84 @@ type InterchainTrace struct {
ValidatorBlocks []VerificationBlock `json:"validatorBlocks"`
InterchainTransactions []InterchainTransaction `json:"interchainTransactions"`
}
// --- proof-measure service (measured immutability / "securedBy") ---
//
// Decimal-valued fields are transmitted as strings (full precision); timestamps
// are int64 unix seconds.
// RawMeasure is a network's native cumulative security measure: cumulative
// hashes for PoW, stake-seconds for PoS.
type RawMeasure struct {
Value string `json:"value"` // human-scaled mantissa (e.g. "484.44")
Unit string `json:"unit"` // e.g. "Zettahashes", "ETH·s"
Base string `json:"base"` // unscaled base amount (hashes or stake-seconds)
}
// SecurityResult is the security a single network accrued for a window/anchor,
// exposed as the raw native measure AND a USD valuation (energy cost for PoW,
// staked value for PoS), plus a normalized 0..1 score.
type SecurityResult struct {
Network string `json:"network"`
Consensus string `json:"consensus"` // "pow" | "pos"
Raw RawMeasure `json:"raw"`
ValueUSD string `json:"valueUsd"` // decimal string
ValueUSDFormatted string `json:"valueUsdFormatted"` // e.g. "$1,234.56"
Label string `json:"label"` // e.g. "$X energy consumed" / "$X staked"
NormalizedScore string `json:"normalizedScore"` // decimal string in [0,1]
SinceUnix int64 `json:"since"` // window/anchor start (unix seconds)
AsOfUnix int64 `json:"asOf"` // latest sample time (unix seconds)
}
// ReportAnchorInput is one anchor supplied in a report request. Provide either
// Network ("BTC"/"ETH") or the public-chain numeric ChainID; Network wins.
type ReportAnchorInput struct {
Network string `json:"network,omitempty"`
ChainID string `json:"chainId,omitempty"`
TxHash string `json:"txHash"`
Timestamp int64 `json:"timestamp"` // anchor time, unix seconds
}
// ReportRequest is the body of ProofMeasure.Report: a transaction's interchain
// anchors. The service computes the security each anchor's network accumulated
// since the anchor and returns a TransactionReport.
type ReportRequest struct {
TransactionID string `json:"transactionId"`
PrimeID string `json:"primeId"`
BlockID string `json:"blockId"`
Anchors []ReportAnchorInput `json:"anchors"`
}
// AnchorSecurity is one interchain anchor with the security its public network
// has accumulated since the anchor was placed.
type AnchorSecurity struct {
Network string `json:"network"`
AnchorTimestamp int64 `json:"anchorTimestamp"` // unix seconds
AnchorTxHash string `json:"anchorTxHash"`
Security SecurityResult `json:"security"`
}
// HashPower is the combined raw hash power across a report's PoW anchors.
type HashPower struct {
Value string `json:"value"`
Units string `json:"units"`
}
// TransactionReport is the per-transaction "securedBy" report: every public-chain
// anchor covering the transaction's block with both raw and USD security, plus
// combined totals. HashPower is nil when there are no PoW anchors.
type TransactionReport struct {
TransactionID string `json:"transactionId"`
PrimeID string `json:"primeId"`
BlockID string `json:"blockId"`
Anchors []AnchorSecurity `json:"anchors"`
TotalValueUSD string `json:"totalValueUsd"`
TotalValueUSDFormatted string `json:"totalValueUsdFormatted"`
HashPower *HashPower `json:"hashPower"`
TotalNormalizedScore string `json:"totalNormalizedScore"`
}
// HealthResponse is the proof-measure liveness payload.
type HealthResponse struct {
Status string `json:"status"`
}