Documentation
¶
Overview ¶
Package source holds the CLI verifier's readers of a Stellar or Bitcoin source, the servers SPEC.md section 9 (What a verifier pins) names under "Sources": a Horizon server for Stellar, and an Esplora server or a Bitcoin Core node for Bitcoin; and of NIST's Randomness Beacon, which section 9 makes one source, read at its one compiled-in address. Each read is a call of SPEC.md section 10.4's informative table (Common sources), made through internal/httpclient's SingleRead: one attempt, no redirect followed, one deadline over the whole read and a bound on the body. The reads are built by their caller for each read, never at package init.
They are the reads SPEC.md sections 10.2, step 0, and 10.4 give every verifier in an online run, the reference verifier of section 13.1 among them, which reads chains and sources online when it is given a reader (section 8.3). They follow the Truestamp application's source readers, Truestamp.SourceCache.Identity, StellarSource and BitcoinSource (lib/truestamp/source_cache/identity.ex, stellar_source.ex and bitcoin_source.ex in truestamp-v2), adapted:
- the identity reads of SPEC.md section 10.2, step 0 (CONFIGURATION): Horizon's GET / for its network_passphrase, Esplora's GET /block-height/0 and Bitcoin Core's getblockhash 0 for the hash of the block at height 0; and Horizon's reads of CHAIN for a Stellar commitment entry, its root, a transaction and a ledger (stellar.go), and Esplora's and Bitcoin Core's reads of CHAIN for a Bitcoin commitment entry and genesis.bitcoin, the tip and the best-chain block at a height (bitcoin.go, SPEC.md section 10.4); and the reads of SOURCES for an entropy object, Horizon's ledger and root (stellar.go), Esplora's and Bitcoin Core's block by its hash (bitcoin.go) and the NIST beacon's pulse (nist.go); each an Answer in the form of a replay record (section 13.2);
- an identity read is found or unreachable, never not found (SPEC.md section 13.2 (The vectors)): every answer but a value in its form, a 404 and a Bitcoin Core error included, is an *Unreachable, whose reason is a fixed text that quotes nothing the server sent or the transport gave: no body, no part of a JSON-RPC answer and no transport error's text, which can carry the server's bytes (a malformed status line or header line) and names the URL. So nothing a server echoes back, such as the credentials a Core read sent, can reach a message, and nothing in this package prints: internal/registry's rule 2 scan refuses fmt's Print and Fprint functions and the print builtins here, and its import list holds neither log, log/slog nor os;
- every answer in JSON, an identity read's included, is read whole by the strict reader (internal/strictjson), so one that breaks J2 to J6 of SPEC.md section 10.1 in any member, a member no read uses included, is no usable answer (SPEC.md section 10.4, "Answers": an answer in JSON parses only when it meets J2 to J6 in every member);
- Bitcoin Core's RPC credentials are a Credentials, which prints masked whatever verb formats it and is sent only in the request's Authorization header, never in the URL; the application reaches its own node through its configuration instead.
Index ¶
- Constants
- func CheckURL(raw string) error
- func CoreIdentity(ctx context.Context, reads *httpclient.SingleRead, url string, ...) (string, error)
- func EsploraIdentity(ctx context.Context, reads *httpclient.SingleRead, base string) (string, error)
- func Identity(ctx context.Context, reads *httpclient.SingleRead, provider Provider, ...) (string, error)
- func StellarIdentity(ctx context.Context, reads *httpclient.SingleRead, base string) (string, error)
- type Answer
- func CoreBlock(ctx context.Context, reads *httpclient.SingleRead, url string, ...) Answer
- func CoreBlockAtHeight(ctx context.Context, reads *httpclient.SingleRead, url string, ...) Answer
- func CoreTip(ctx context.Context, reads *httpclient.SingleRead, url string, ...) Answer
- func EsploraBlock(ctx context.Context, reads *httpclient.SingleRead, base string, hash any) Answer
- func EsploraBlockAtHeight(ctx context.Context, reads *httpclient.SingleRead, base string, height any) Answer
- func EsploraTip(ctx context.Context, reads *httpclient.SingleRead, base string) Answer
- func NISTPulse(ctx context.Context, reads *httpclient.SingleRead, base string, ...) Answer
- func Read(ctx context.Context, reads *httpclient.SingleRead, provider Provider, ...) Answer
- func StellarLedger(ctx context.Context, reads *httpclient.SingleRead, base string, sequence any) Answer
- func StellarRoot(ctx context.Context, reads *httpclient.SingleRead, base string) Answer
- func StellarTransaction(ctx context.Context, reads *httpclient.SingleRead, base string, hash any) Answer
- type Credentials
- type Outcome
- type Provider
- type Unreachable
Constants ¶
const ( KindBitcoinTip = "bitcoin_tip" KindBitcoinBlockAtHeight = "bitcoin_block_at_height" KindBitcoinBlock = "bitcoin_block" )
The kinds of Bitcoin chain read this file makes (SPEC.md section 13.2's table).
const ( KindStellarRoot = "stellar_root" KindStellarTransaction = "stellar_transaction" KindStellarLedger = "stellar_ledger" )
The kinds of chain read this file makes (SPEC.md section 13.2's table).
const ( RootOctets = 65536 LedgerOctets = 65536 TransactionOctets = 1 << 20 )
The bounds of a Horizon answer's body: its root and a ledger are each a few kilobytes, and a transaction carries its envelope and result, whose XDR can run to some tens of kilobytes.
const BitcoinOctets = 65536
BitcoinOctets bounds the body of each Bitcoin answer: a height, a hash, or a block's header fields, which Esplora and Bitcoin Core each give in about a kilobyte.
const IdentityOctets = 65536
IdentityOctets bounds the body of an identity answer. Horizon's root is about two kilobytes, and the other two answers a hash.
const KindNISTPulse = "nist_pulse"
KindNISTPulse is the kind of the read of a NIST pulse (SPEC.md section 13.2's table).
const Masked = "[masked]"
Masked is what Credentials print as.
const NISTOctets = 65536
NISTOctets bounds the body of a pulse: the beacon writes one in about five kilobytes, its signature and its list values included.
Variables ¶
This section is empty.
Functions ¶
func CheckURL ¶
CheckURL refuses a source URL no read may be made to: one that does not parse, whose scheme is not http or https, that names no host, that carries user information, a query or a fragment. Its error never quotes the URL, which could hold credentials.
func CoreIdentity ¶
func CoreIdentity(ctx context.Context, reads *httpclient.SingleRead, url string, creds Credentials) (string, error)
CoreIdentity calls a Bitcoin Core node's getblockhash 0 at url and returns the hash of the block at height 0, a HEX64. The call is a JSON-RPC 1.0 POST, with creds in its Authorization header; the answer must be {result, error, id} with error null, id this call's and result the hash. A Core error, such as -8 for a height past the tip, comes with an HTTP status other than 200 OK, and is unreachable like any other.
func EsploraIdentity ¶
func EsploraIdentity(ctx context.Context, reads *httpclient.SingleRead, base string) (string, error)
EsploraIdentity reads an Esplora server's GET <base>/block-height/0 and returns the hash of the block at height 0, a HEX64.
func Identity ¶
func Identity(ctx context.Context, reads *httpclient.SingleRead, provider Provider, base string, creds Credentials) (string, error)
Identity reads the identity value of the source of provider at base through reads: Horizon's network_passphrase, or the hash of the block at height 0 of an Esplora server or a Bitcoin Core node. creds are sent only to a Bitcoin Core node. Any answer that is not a value in its form is an *Unreachable.
func StellarIdentity ¶
func StellarIdentity(ctx context.Context, reads *httpclient.SingleRead, base string) (string, error)
StellarIdentity reads a Horizon server's root, GET <base>/, and returns its network_passphrase, an ASCII128.
Types ¶
type Answer ¶
Answer is one chain read's answer, in the form of a replay record (SPEC.md section 13.2): Outcome; Value, for a found answer, the fields the read gives, each a value internal/jcs can write; and Reason, for an unreachable one, a fixed text that quotes nothing a server sent.
func CoreBlock ¶
func CoreBlock(ctx context.Context, reads *httpclient.SingleRead, url string, creds Credentials, hash any) Answer
CoreBlock reads the block whose hash is hash of a Bitcoin Core node at url, with creds: getblockheader <hash>, for its height, time and mediantime.
func CoreBlockAtHeight ¶
func CoreBlockAtHeight(ctx context.Context, reads *httpclient.SingleRead, url string, creds Credentials, height any) Answer
CoreBlockAtHeight reads the best-chain block at height of a Bitcoin Core node at url, with creds: getblockhash <height>, the block's hash, then getblockheader <hash>, for its mediantime and nTx.
func CoreTip ¶
func CoreTip(ctx context.Context, reads *httpclient.SingleRead, url string, creds Credentials) Answer
CoreTip calls a Bitcoin Core node's getblockcount at url, the height of its tip, with creds.
func EsploraBlock ¶
func EsploraBlock(ctx context.Context, reads *httpclient.SingleRead, base string, hash any) Answer
EsploraBlock reads the block whose hash is hash of an Esplora server, GET <base>/block/<hash>, for its height, timestamp and mediantime.
func EsploraBlockAtHeight ¶
func EsploraBlockAtHeight(ctx context.Context, reads *httpclient.SingleRead, base string, height any) Answer
EsploraBlockAtHeight reads the best-chain block at height of an Esplora server: GET <base>/block-height/<height>, the block's hash, then GET <base>/block/<hash>, for its mediantime and tx_count.
func EsploraTip ¶
func EsploraTip(ctx context.Context, reads *httpclient.SingleRead, base string) Answer
EsploraTip reads an Esplora server's GET <base>/blocks/tip/height, the height of its tip.
func NISTPulse ¶
func NISTPulse(ctx context.Context, reads *httpclient.SingleRead, base string, chainIndex, pulseIndex any) Answer
NISTPulse reads the pulse at chainIndex and pulseIndex of the beacon at base, GET <base>/chain/<chainIndex>/pulse/<pulseIndex>, for its outputValue and timeStamp.
func Read ¶
func Read(ctx context.Context, reads *httpclient.SingleRead, provider Provider, base string, creds Credentials, read map[string]any) Answer
Read makes the chain read named read, {kind, network for a Stellar or Bitcoin read, ...} as a replay record names it, of the source of provider at base, through reads, and gives its answer: Horizon's reads here, Esplora's and Bitcoin Core's in bitcoin.go, and the NIST beacon's in nist.go. creds are sent only to a Bitcoin Core node. A kind this provider does not serve is unreachable, with no request made.
func StellarLedger ¶
func StellarLedger(ctx context.Context, reads *httpclient.SingleRead, base string, sequence any) Answer
StellarLedger reads the ledger whose sequence is sequence, GET <base>/ledgers/<sequence>, for closed_at and hash.
func StellarRoot ¶
func StellarRoot(ctx context.Context, reads *httpclient.SingleRead, base string) Answer
StellarRoot reads a Horizon server's root, GET <base>/, for history_latest_ledger and history_elder_ledger, given as latest and elder.
func StellarTransaction ¶
func StellarTransaction(ctx context.Context, reads *httpclient.SingleRead, base string, hash any) Answer
StellarTransaction reads the transaction whose hash is hash, GET <base>/transactions/<hash>, for successful, memo_type, memo and ledger.
type Credentials ¶
type Credentials struct {
// contains filtered or unexported fields
}
Credentials are a Bitcoin Core node's RPC credentials, a user and a password. Every way of printing them prints Masked: fmt with any verb, encoding/json and any encoding.TextMarshaler. The members are unexported, so only this package reads them, to send them.
func NewCredentials ¶
func NewCredentials(user, password string) Credentials
NewCredentials returns the credentials of user and password.
func (Credentials) Empty ¶
func (c Credentials) Empty() bool
Empty reports whether neither a user nor a password is set.
func (Credentials) Format ¶
func (c Credentials) Format(f fmt.State, _ rune)
Format writes Masked for every verb, so neither %v, %+v, %#v, %s, %q nor %x shows the members.
func (Credentials) MarshalJSON ¶
func (c Credentials) MarshalJSON() ([]byte, error)
MarshalJSON returns Masked as a JSON string.
func (Credentials) MarshalText ¶
func (c Credentials) MarshalText() ([]byte, error)
MarshalText returns Masked.
type Outcome ¶
type Outcome string
Outcome is a chain read's outcome (SPEC.md section 10.4, "Answers").
const ( // OutcomeFound: the source returned the object asked for. OutcomeFound Outcome = "found" // OutcomeNotFound: the source answered that it holds no such object. OutcomeNotFound Outcome = "not_found" // OutcomeUnreachable: there is no usable answer. OutcomeUnreachable Outcome = "unreachable" )
The outcomes of a chain read.
type Provider ¶
type Provider string
Provider is the kind of server a source is.
const ( // Horizon is a Stellar Horizon server. Horizon Provider = "horizon" // Esplora is a Bitcoin Esplora server. Esplora Provider = "esplora" // BitcoinCore is a Bitcoin Core node, read over its JSON-RPC interface. BitcoinCore Provider = "bitcoin_core" )
The providers SPEC.md section 9 names.
const NISTBeacon Provider = "nist_beacon"
NISTBeacon is NIST's Randomness Beacon, read over its 2.0 API. It serves no chain (Provider.Chain).
type Unreachable ¶
type Unreachable struct {
Reason string
// contains filtered or unexported fields
}
Unreachable is an identity read that got no usable answer (SPEC.md section 10.4, "Answers"). Reason says why in a fixed text, which quotes nothing a server sent or the transport gave and names no URL. A read that failed before its answer arrived also wraps the transport's error as its cause, for errors.Is and errors.As; that error's text can carry bytes the server sent, such as a malformed status line, and names the URL, so it is never printed: Error returns Reason alone.
func (*Unreachable) Error ¶
func (e *Unreachable) Error() string
func (*Unreachable) Unwrap ¶
func (e *Unreachable) Unwrap() error
Unwrap returns the transport's error, or nil.