vread

package
v0.6.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 30 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package vread asks overlay hosts the ls_bsecret questions and checks every answer itself (docs/spec.md sections 10.2, 13 and 14): a vault token's record, lock and field signature, its proof against the reader's own headers and its descent by spends from the vault's first token; a secret carrier by the host's own admission rules and by SPV through its funding parent; a sweep by its proof. A host is trusted for nothing: an answer is verified here or reported as refused, naming the host. An empty answer means only that the host holds nothing that answers.

A reader that asks several hosts compares their answers and reports a difference as such, never merging it silently: a host can withhold a token or a record, and only a comparison (or a root) shows it.

The vault's group is borg's. Its chain, its epochs and a member's epoch keys are read by borg's own reader package (group.go), never by a copy of its rules.

Index

Constants

View Source
const (
	LabelRetracted = "retracted"
	LabelRollback  = "rollback"
)

The labels beside secrec's own.

Variables

View Source
var ErrHost = errors.New("vread: the host refused the question")

ErrHost is a host that answered with an error: its words travel with it.

View Source
var ErrNoChain = errors.New("vread: no host answers this vault")

ErrNoChain is a vault no host answered.

View Source
var ErrNoHeaders = errors.New("vread: no header source; refusing to verify against a default")

ErrNoHeaders refuses to verify against no header source.

View Source
var ErrNoHosts = errors.New("no overlay host configured (config key hosts, or -hosts)")

ErrNoHosts is a reader with no host to ask.

View Source
var ErrNoTerms = errors.New("vread: the host serves no terms document, so it charges for nothing")

ErrNoTerms is a host that serves no terms document: it charges for nothing.

View Source
var ErrNoWrap = errors.New("vread: no host of the hall answers the wrap")

ErrNoWrap is the key of an epoch that a member of that epoch could not open because no host of the hall answered its wrap: an absence, which names nobody and proves nothing.

View Source
var ErrUnavailable = errors.New("vread: no content source holds the ciphertext")

ErrUnavailable is a ciphertext no configured source holds: nothing names a store that serves none (spec section 18).

Functions

func GroupFresh

func GroupFresh(ctx context.Context, spends Spends, raw func(ctx context.Context, txid string) ([]byte, error), g *Group, now time.Time) error

GroupFresh is a writer's evidence that the group's latest token is the latest (spec section 7.1 rule 2): borg's reader.Latest.

func HallRefused added in v0.1.1

func HallRefused(r reader.Refusal) string

HallRefused words a wrap a hall host answered that did not verify, or an answer over borg's bound (Overfull).

func Hash

func Hash(txid string) ([32]byte, error)

Hash is a display txid as a hash (hash byte order).

func Hex32

func Hex32(s string) ([32]byte, error)

Hex32 reads 64 lowercase hex digits: a vault or secret identifier.

func JoinSeqs

func JoinSeqs(s []uint64) string

JoinSeqs words a list of seqs.

func OpenEpoch

func OpenEpoch(ctx context.Context, rd *reader.Client, w wallet.Interface, me []byte, g *Group, epoch uint64) (key [32]byte, refused []reader.Refusal, err error)

OpenEpoch opens the key of one epoch of the group for the key me, whose wallet is w, by borg's member checks (borg's reader.Open: the token that began the epoch from the canonical chain, a wrap that verifies and holds an entry for me, the wallet's decryption, the commitment), and returns the epoch's BRC-369 symmetric key, the input of the epoch wrap key (docs/spec.md section 6.3). A key that was not a member of the epoch holds no wrap of it and opens nothing.

Every hall host is asked, and every wrap each answers for me is checked after one has opened the key: refused are the wraps a hall host answered that did not verify, each naming its host, also when another host's wrap opened the key. What a host refused here is not used; a caller names each host and treats the read as incomplete.

func Overfull added in v0.1.2

func Overfull(r reader.Refusal) bool

Overfull reports a refusal that names no carrier: a hall host's answer over borg's bound for one question (reader.ErrOverfull, reason overfull) or a paged walk cut at the reader's bound (reader.ErrTruncated, reason truncated). What was read below the bound is used as any answer is; what the host answered past it is not read, so the read is incomplete.

func OverfullWords added in v0.1.2

func OverfullWords(r reader.Refusal) string

OverfullWords words an Overfull refusal.

func ReleaserWallet added in v0.6.0

func ReleaserWallet(org wallet.Interface, orgKey []byte) (wallet.Interface, []byte, error)

ReleaserWallet is the organization's own wallet acting for its signer key: the wallet that holds the organization's identity key, wherever that is (a hardware module, a remote signer), opening the wrap borg made to the signer key from the releaser's side. A wrap is a BRC-2 ciphertext between the organization and the member under BRC-42 child keys, so the organization, which released it, derives the same key the member does: decrypting with the member as counterparty opens it. The returned wallet answers borg's member checks (reader.Open) as the signer key would, with no private key leaving the organization's wallet. orgKey is the organization's identity key; it returns the wallet and the signer's public key.

func Remembered

func Remembered(ctx context.Context, beefs [][]byte, crypt string, org []byte, vault [32]byte, headers chaintracker.ChainTracker, source ChainSource) ([]*Tok, Memory)

Remembered rebuilds the chain a reader verified before from the tokens it kept, each as a host answered it (Tok.Beef), in seq order from 0. Every token is read again as a well-formed token of the vault, and the last one's proof must verify against the reader's headers. When the stored proof no longer does, the chain source is asked for the transaction's current proof (spec section 14): one that verifies replaces the stored one; only the source's word that the transaction is not mined is a reorganization. A header source or chain source that fails proves nothing, and nothing is forgotten on its account: forgetting would let a host that rolled the vault back be believed by a reader whose header source blinked. The tokens before the last are held to it by spends when the chain is walked, and a transaction a mined one spends is mined.

func Seq

func Seq(n uint64) string

Seq is a seq or a version as a question writes it.

func Short

func Short(s string) string

Short is a txid's or an identifier's first 12 digits, for notes.

func SignerWallet

func SignerWallet(orgKey *ec.PrivateKey) (wallet.Interface, []byte, error)

SignerWallet is the wallet of the organization's signer key: the key derived from the organization's identity key that borg keeps a member of each group once `borg org signer` has run, so that every instance of the organization's tooling opens the epoch keys another instance sampled (borg's spec section 7.4; docs/spec.md section 8.5). It returns the wallet and the signer's public key.

func SubjectID

func SubjectID(beef []byte) string

SubjectID is the txid of a BEEF's subject.

func Txid

func Txid(h [32]byte) string

Txid is a hash in display order.

func VaultHex

func VaultHex(v [32]byte) string

VaultHex is a vault identifier as a question writes it.

func VerifySweep

func VerifySweep(ctx context.Context, beef []byte, crypt string, headers chaintracker.ChainTracker) ([]transaction.Outpoint, string, error)

VerifySweep checks an answered sweep: admitted by the host's rules (a mined transaction whose output 0 is funding-shaped) against the reader's own headers, and returns the outpoints it spends.

func WrapsMissing

func WrapsMissing(ctx context.Context, rd *reader.Client, g *Group, epoch uint64) (missing [][]byte, refused []reader.Refusal, err error)

WrapsMissing are the members of the group's latest token that no host answers a wrap of epoch for: a version keyed under a new epoch is published only after borg's wraps of the epoch's key are (spec section 8.3), or the members who remain could not open it. refused are the wraps a hall host answered that did not verify, and its answers over borg's bound (Overfull): a wrap past a cut is not read, so its members are counted missing.

Types

type Car

type Car struct {
	Txid string
	Beef []byte
	Tx   *transaction.Transaction
	// Carrier is the carrier by the host's own rules: its record, owner,
	// content id, commitment and funding outpoint.
	Carrier *secrec.Carrier
	// Context is the BRC-24 context the host answered with it.
	Context []byte
	// Host is the first host that answered it.
	Host string
}

Car is one answered secret carrier that verified.

func VerifyCarrier

func VerifyCarrier(ctx context.Context, beef []byte, crypt string, headers chaintracker.ChainTracker) (*Car, error)

VerifyCarrier checks one answered secret carrier: the host's admission rules for crypt (every carrier rule and the record's own, the inline ciphertext's length and hash among them), and SPV through its funding parent against headers.

type ChainSource

type ChainSource interface {
	Spender(ctx context.Context, txid string, vout uint32) (string, error)
	TxRaw(ctx context.Context, txid string) ([]byte, error)
	MerkleProof(ctx context.Context, txid string) (*transaction.MerklePath, error)
}

ChainSource is a node's view of what spends an output, with the spender's bytes and proof: nodeapi.Asset is one. An answer of "" with no error is "unspent".

type ChainView

type ChainView struct {
	Crypt string
	Org   []byte
	Vault [32]byte
	// Tokens are the canonical chain, seq 0 to the latest.
	Tokens []*Tok
	// Statuses are the fold's status of each token (spec section 11.2).
	Statuses []string
	// HostLatest is the highest seq each host answered to the vault class;
	// HostErr the hosts that could not be asked.
	HostLatest map[string]uint64
	HostErr    map[string]error
	// Lacks are, per host that answered, the canonical seqs it did not
	// answer: a host behind, or withholding.
	Lacks map[string][]uint64
	// Refused are answered tokens that did not verify.
	Refused []Refusal
	// Forks are tokens that verified at a seq of the canonical chain but do
	// not continue it.
	Forks []*Tok
	// Claimed are the verified tokens the hosts answered as the vault's
	// latest.
	Claimed []*Tok
	// contains filtered or unexported fields
}

ChainView is one vault's chain as a reader established it from every host it asked (spec section 14): the canonical chain, which descends by spends from the vault's first token, each token verified against the reader's headers, held to the transition rules and folded, and how each host's answers compare with it.

func FromTokens

func FromTokens(crypt string, org []byte, vault [32]byte, toks []*Tok) (*ChainView, error)

FromTokens establishes a chain from tokens a reader was handed (the audit class's answer, or a trail from any source), each already verified. It is walked from seq 0 by spends; a token at a seq the walk never reaches is a fork, whatever seq it names.

func (*ChainView) Agree

func (v *ChainView) Agree() bool

Agree reports whether every host that answered holds the whole canonical chain.

func (*ChainView) Beyond

func (v *ChainView) Beyond() []*Tok

Beyond are the verified tokens of the vault at a seq above the chain read, each once: a host answered them (as the latest, or at a seq the walk could not link), and no chain of spends reaches them from the first token. A token between was withheld, or the owner signed a stray one; either way what was read may be an older state than the vault's latest, and a reader with no memory of its own has nothing else to tell it so.

func (*ChainView) Broken

func (v *ChainView) Broken() string

Broken reports the status that ended the chain's use, or "".

func (*ChainView) Commitments

func (v *ChainView) Commitments() [][32]byte

Commitments are every commitment a usable token of the chain listed.

func (*ChainView) Current

func (v *ChainView) Current(id [32]byte) (secrec.Current, bool)

Current is the version of id the set holds, when it holds one.

func (*ChainView) Fold

func (v *ChainView) Fold() *secrec.VaultFold

Fold is the fold of the usable chain: a writer tries its next transition on a clone of it before it signs.

func (*ChainView) Head

func (v *ChainView) Head() *Tok

Head is the last usable token: the one whose set a reader takes.

func (*ChainView) History

func (v *ChainView) History(car *Car) (uint64, error)

History is the check a reader makes on a carrier it reads as history, a version the set no longer holds (spec section 7.2): the first usable token that lists the record's identifier at its version is the one that listed it, and it lists this record as it is; and the version was not listed under a commitment an earlier token of the vault listed. A later token that names the same version proves nothing about a record the first did not list. It returns the seq of the token that listed it.

func (*ChainView) Latest

func (v *ChainView) Latest() *Tok

Latest is the canonical chain's last token, or nil.

func (*ChainView) Linked

func (v *ChainView) Linked(listed *Car, links []*Car) ([]*Car, bool, error)

Linked takes, for an interval vault, the highest version that links to the listed one successor by successor (spec section 4.4). links are the carriers held above the listed version. It returns the run, lowest version first, and whether a later version exists that does not link.

func (*ChainView) Listed

func (v *ChainView) Listed(car *Car) (pathOK bool, err error)

Listed is a reader's check 0 on a carrier a host answered for the set (spec section 7.2), made against the chain the reader folded: the set of the last usable token holds the record's identifier at its version and content id; the token that listed it lists its commitment, names the record's crypt, owner, vault and group and one of the vault's labels, and is of the record's epoch and epoch id; and no earlier token listed the commitment. An inclusion path the host answered is checked too when it names the token the reader holds, and a path that does not verify is reported and otherwise ignored: the fold is the stronger check.

func (*ChainView) Reused

func (v *ChainView) Reused(contentID [32]byte) bool

Reused reports whether the version with this content id was listed under a commitment an earlier token of the vault listed (commitment-reuse): a reader refuses it, since its key is one an earlier version's readers hold.

func (*ChainView) Set

func (v *ChainView) Set() []secrec.Current

Set is the current set after the last usable token, ascending by id.

func (*ChainView) Trail

func (v *ChainView) Trail() []secrec.Event

Trail is every event of the usable chain, in order.

func (*ChainView) Usable

func (v *ChainView) Usable() int

Usable is how many tokens from seq 0 fold without a mismatch: a reader fails closed from the first mismatched token on.

type Client

type Client struct {
	// Hosts are the overlay hosts' base URLs, asked in order.
	Hosts []string
	// Headers is the reader's own header source. It is required: an answer
	// is only as good as the headers it is checked against.
	Headers chaintracker.ChainTracker
	// Timeout bounds each request; HTTP, when set, is the client used.
	Timeout time.Duration
	HTTP    *http.Client
	// MaxPages bounds the pages one question reads per host.
	MaxPages int
	// Source, when set, is a chain source that indexes spends: a sweep is
	// also looked for there (Swept), by its proof.
	Source ChainSource
	// Auth, when set, asks every question over BRC-104 as the reader's own
	// identity, as a private crypt's hosts require (spec section 10.4): it
	// posts body to url and returns the answer's status and body.
	Auth func(ctx context.Context, url string, body []byte) (status int, answer []byte, err error)
}

Client asks hosts and checks their answers.

func (*Client) Ask

func (c *Client) Ask(ctx context.Context, host string, q Query) ([]lookup.Output, error)

Ask asks one host one question and returns the outputs it answered. The question is held to the class rules first, so a question no host could answer is never sent.

func (*Client) Carrier

func (c *Client) Carrier(ctx context.Context, beef []byte, crypt string) (*Car, error)

Carrier is VerifyCarrier, with a stale proof of the carrier's funding tree replaced by the chain source's current one.

func (*Client) Chain

func (c *Client) Chain(ctx context.Context, crypt string, org []byte, vault [32]byte, known ...*Tok) (*ChainView, error)

Chain establishes a vault's chain. Every host is asked the vault class; then every seq from 0 to the highest any host answered is asked of every host, so the reader walks the chain from seq 0 itself: the first token by the outpoint its vault identifier hashes, every later one by its spend of the token before it and the transition rules, each folded as it goes.

known is the chain this reader verified before, from seq 0 (Remembered): the walk then starts from the token it remembers (spec section 14), and the hosts are asked only the seqs above it. A host that answers a latest token below the remembered one is answering an older state; the caller refuses that (rollback).

func (*Client) Held

func (c *Client) Held(ctx context.Context, host string, q Query, txid string) (bool, error)

Held asks whether host answers a question with an output whose subject is txid: a publisher's confirmation that a host holds the object (spec section 13).

func (*Client) Open

func (c *Client) Open(ctx context.Context, v *ChainView, g *Group, car *Car, anchored bool, keys Keys, content Content) (*Reading, error)

Open performs a reader's checks on one carrier in the signed order (spec section 7.2) and stops at the first failure, which names its own culprit: the listing (or, for an unanchored version, the links the caller verified), every epoch against the group's chain, and the retraction; the ciphertext's length and hash, before any wrap is opened; the wrap, under the key of the epoch the record names and no other, or the owner's self wrap; the commitment; every segment's tag; the payload and its name.

func (*Client) Pages

func (c *Client) Pages(ctx context.Context, host string, q Query, cursor func(lookup.Output) string, less func(a, b string) bool) HostOutputs

Pages asks one host a paged class, page after page, until a page is empty: a page never splits one secret's or one seq's outputs, so a page short of the limit is not thereby the last. cursor gives the -after member for an output, or "" when it has none; the highest cursor of a page (by less) asks for the next. A host that answers nothing past the cursor it was given ends the walk.

func (*Client) Pending

func (c *Client) Pending(ctx context.Context, v *ChainView, id [32]byte) ([]*Car, []Refusal, map[string]error)

Pending asks every host the pending class for id: the carriers held for versions above the one the set holds.

func (*Client) Ping

func (c *Client) Ping(ctx context.Context, host string) error

Ping asks a host a question no class answers, which a live ls_bsecret refuses with an error: the host is up and runs the service.

func (*Client) Run

func (c *Client) Run(ctx context.Context, v *ChainView, listed *Car) (run []*Car, later bool, refused []Refusal, errs map[string]error, err error)

Run reads, for an interval vault, the versions of a secret no token lists yet: the pending class at every host, then, version by version from the listed one, each version the pending answers did not hold, asked for only while the one before it was answered. So the work is bounded by the records the hosts hold in a row and by limits.RunVersions, never by a version a carrier claims. It returns the run that links to listed (lowest version first), whether a later version exists that is not in it, the carriers refused and the hosts that could not be asked.

func (*Client) Secret

func (c *Client) Secret(ctx context.Context, v *ChainView, id [32]byte) ([]*Car, []Refusal, map[string]error)

Secret asks every host the secret class for id and returns the carriers that verified, each once, with the hosts that could not be asked.

func (*Client) Secrets

func (c *Client) Secrets(ctx context.Context, v *ChainView) []SetAnswer

Secrets asks every host the secrets class (all pages) and compares what each answered with the set the reader folded: a host whose answer does not reproduce the root withheld or added a record (spec section 14).

func (*Client) Sweep

func (c *Client) Sweep(ctx context.Context, beef []byte, crypt string) ([]transaction.Outpoint, string, error)

Sweep is VerifySweep, with a stale stored proof replaced by the chain source's current one.

func (*Client) Swept

func (c *Client) Swept(ctx context.Context, crypt string, op transaction.Outpoint) (string, error)

Swept reports the mined transaction that spends op, when one is found by the sweep class at a host or by the chain source, and its proof verifies against the reader's headers: a reader must not use a record whose funding outpoint a mined sweep spends (spec section 14). Only a mined spend retracts: a spender with no proof that verifies does not count.

func (*Client) Token

func (c *Client) Token(ctx context.Context, beef []byte, crypt string, org []byte, vault *[32]byte) (*Tok, error)

Token is VerifyToken, with a stale stored proof replaced by the chain source's current one.

func (*Client) Vaults

func (c *Client) Vaults(ctx context.Context, crypt string, org []byte) (map[[32]byte]*Tok, map[string]error)

Vaults asks every host the vaults class for org (all pages) and returns, by identifier, the latest verified token each host answered for each of org's vaults. A host's answer here is a claim about which vaults exist and which token is latest, never evidence of descent: a reader that uses a vault walks its chain (Chain).

func (*Client) Version

func (c *Client) Version(ctx context.Context, v *ChainView, id [32]byte, n uint64) ([]*Car, []Refusal, map[string]error)

Version asks every host the version class for version n of id.

type Content

type Content interface {
	Get(ctx context.Context, hash [32]byte, length uint64) ([]byte, error)
}

Content fetches a ciphertext that is not carried in its record, by its hash, bounded by the reader's budget and the record's length.

type Failure

type Failure struct {
	// Label is listing, successor, retracted, hash, undecryptable,
	// commitment, tag, payload or rollback.
	Label string
	Err   error
}

Failure is a reader's check that failed (docs/spec.md section 7.2): its label, which names the culprit, and what was found.

func (*Failure) Error

func (f *Failure) Error() string

func (*Failure) Unwrap

func (f *Failure) Unwrap() error

type Forgetter

type Forgetter interface {
	Forget(hall, org, chain string)
}

Forgetter is a reader's Floor that can forget one chain: what ReadGroup asks of the floor when the token it remembers was displaced by a reorganization.

type Group

type Group struct {
	*reader.GroupView
	// Epochs are the epochs the canonical chain began, ascending: each with
	// its id (the hash of the group record that began it), the height of
	// the block that mined that token, and whether the token removed
	// anyone.
	Epochs []secrec.EpochEvent
}

Group is the vault's group as borg's reader established it: its canonical chain, verified against the reader's own headers, and the epochs that chain began. Everything here is borg's own code reading borg's own records (docs/spec.md section 16.1).

func ReadGroup

func ReadGroup(ctx context.Context, rd *reader.Client, hall string, org []byte, group [secrec.GroupIDLen]byte) (*Group, error)

ReadGroup establishes the chain of group of org in hall through borg's reader. org is the vault's owner: borg's reader verifies every token as that organization's, so a group it returns is the vault's organization's (spec section 7.2).

When the reader has a Floor (borg's reader.Client.Floor), the group is held to the latest token this caller verified of it before (spec section 14, no going back): hosts that answer the group's chain only below it are answering an older state, one in which a member since removed is still a member and the epoch that removal began does not exist. That is refused (rollback). Only the chain source's word that the remembered token is no longer mined, a reorganization, makes the floor forget it; a source that fails proves nothing, and nothing is forgotten on its account.

func (*Group) Current

func (g *Group) Current() secrec.EpochEvent

Current is the group's latest epoch.

func (*Group) EpochAt

func (g *Group) EpochAt(e uint64) (secrec.EpochEvent, bool)

EpochAt is the epoch numbered e, when the group began it.

func (*Group) Stand

func (g *Group) Stand(v *secrec.Vault) Standing

Stand is the standing of a vault token against the group.

type HostOutputs

type HostOutputs struct {
	Host      string
	Outputs   []lookup.Output
	Err       error
	Truncated bool
}

HostOutputs is what one host answered to one question, all pages.

type Keys

type Keys struct {
	// Owner, when set, is the owner's wallet: the self wrap is opened
	// through it and no epoch key is needed (spec section 6.4).
	Owner wallet.Interface
	// Epoch returns the BRC-369 symmetric key of one epoch of the vault's
	// group, for a member that held it; an error when this reader holds no
	// key of that epoch.
	Epoch func(ctx context.Context, epoch uint64) ([32]byte, error)
}

Keys are what a reader opens a content key with.

type Memory

type Memory int

Memory is what became of the chain a reader kept.

const (
	// MemoryNone: the reader kept nothing.
	MemoryNone Memory = iota
	// MemoryHeld: the chain kept is returned; its last token is mined in
	// the reader's headers.
	MemoryHeld
	// MemoryUnknown: whether the last token is still mined could not be
	// settled (the header source failed, or its stored proof does not
	// verify and no chain source could give a current one). Nothing is
	// forgotten on that: the reader walks the chain again, and what it
	// verified before stays its floor.
	MemoryUnknown
	// MemoryDisplaced: the last token's stored proof does not verify and
	// the chain source says the transaction is not mined: a reorganization
	// displaced it. The reader forgets it and reads the chain again (spec
	// section 14).
	MemoryDisplaced
	// MemoryCorrupt: what was kept does not read back as the vault's
	// chain. The copy is dropped; the floor is not.
	MemoryCorrupt
)

What Remembered found.

type NoWrapError

type NoWrapError struct {
	Epoch   uint64
	Label   string
	Err     error
	Refused []reader.Refusal
}

NoWrapError is ErrNoWrap for one epoch: Label and Err are borg's reader's last word, and Refused what the hall's hosts answered for the epoch's wraps that did not verify, each naming its host.

func (*NoWrapError) Error

func (e *NoWrapError) Error() string

func (*NoWrapError) Unwrap

func (e *NoWrapError) Unwrap() error

type Query

type Query map[string]string

Query is one ls_bsecret question: its members, every one a string.

type Reading

type Reading struct {
	Car     *Car
	Payload *secrec.Payload
	// Anchored is set when a mined token of the vault lists the version;
	// an unanchored version was taken by its links in an interval vault.
	Anchored bool
	// Exposed is set when the version is keyed under an epoch before the
	// group's latest: someone the group has since removed, or a key it has
	// rotated away from, opens it.
	Exposed bool
	// PathOK is set when the host's inclusion path verified against the
	// token the reader holds.
	PathOK bool
}

Reading is one version read.

type Refusal

type Refusal struct {
	Host   string
	Txid   string
	Reason string
	Err    error
}

Refusal is an answered output that did not verify.

func (*Refusal) Error

func (r *Refusal) Error() string

type SetAnswer

type SetAnswer struct {
	Host string
	// Cars are the carriers that verified.
	Cars []*Car
	// Matches is set when the host answered a carrier for every version
	// the set holds and no other: the set's root is reproduced from its
	// answer.
	Matches   bool
	Refused   []Refusal
	Err       error
	Truncated bool
}

SetAnswer is the set as one host answered it.

type Spends

type Spends = reader.Spends

Spends is a source that indexes spends (borg's reader.Spends).

type Standing

type Standing struct {
	// Ahead: the vault names an epoch the group has not begun, or another
	// epoch id than the group's for that epoch. A reader takes nothing
	// from it.
	Ahead bool
	// Behind: the vault's epoch is before the group's latest.
	Behind bool
	// Stale is the latest token's stale count: above zero, the vault is in
	// debt.
	Stale uint64
	// Epoch is the vault's epoch and Group the group's latest.
	Epoch, Group uint64
}

Standing is a vault's state against its group (spec section 7.3).

func (Standing) Settled

func (s Standing) Settled() bool

Settled reports a vault that owes nothing: its epoch is the group's latest and nothing in it is stale.

func (Standing) String

func (s Standing) String() string

type Store

type Store struct {
	// Sources are directories and http(s) base URLs, tried in order.
	Sources []string
	// Max is the most bytes a reader fetches for one ciphertext.
	Max  int
	HTTP *http.Client
	// contains filtered or unexported fields
}

Store is where ciphertexts that are not carried in their records are kept (docs/spec.md section 5.4): directories and http(s) base URLs, each holding a ciphertext in a file named by the lowercase hex of its SHA-256. The owner publishes a directory under BRC-26, where its locator is the uhrp:// form of the same hash; this is the reader's and the writer's end of it and speaks no advertisement protocol.

func (*Store) Dir

func (s *Store) Dir() string

Dir is the first directory among the sources: where a writer stores.

func (*Store) Get

func (s *Store) Get(ctx context.Context, hash [32]byte, length uint64) ([]byte, error)

Get fetches the ciphertext of hash, of length bytes, from the first source that serves exactly it: every source's bytes are held to the length and the hash the record names before they are taken, so a source that serves other bytes, or cuts them, is passed over and the next is tried. A length over the reader's budget is refused before anything is fetched, and no source is read past length: a record is a fetch instruction, and a reader bounds it. When no source serves the ciphertext and one served other bytes, those are returned, so that the reader's own check names the failure (hash) rather than an absence, and Served names the source they came from.

func (*Store) Put

func (s *Store) Put(ct []byte) (string, error)

Put writes a ciphertext into the first directory source, named by its hash, and returns the file's path. A file that exists holds the same bytes, so it is left.

func (*Store) Served

func (s *Store) Served(hash [32]byte) string

Served names the source whose bytes the last Get of hash returned when no source served the ciphertext itself, or "": the store a reader's hash check names.

type Terms

type Terms struct {
	Service string `json:"service"`
	Terms   int    `json:"terms"`
	Classes []struct {
		Class    string `json:"class"`
		Satoshis uint64 `json:"satoshis"`
	} `json:"classes"`
}

Terms is a host's terms document (spec section 10.3).

func FetchTerms

func FetchTerms(ctx context.Context, hc *http.Client, base string) (*Terms, error)

FetchTerms reads <base>/ls_bsecret/terms. Members and classes a client does not know are ignored; a free class with a price is reported, and a client never pays for one.

type Tok

type Tok struct {
	Txid string
	Tx   *transaction.Transaction
	// Token is the token output, its record decoded.
	Token *secrec.VaultToken
	// Height and Pos place it: its block and its offset in the block.
	Height uint32
	Pos    uint64
	// Beef is the token as answered (the engine's stored form).
	Beef []byte
}

Tok is one answered vault token that verified.

func Trail

func Trail(q Query, ask func(Query) ([]lookup.Output, error), verify func(beef []byte) (*Tok, error)) ([]*Tok, error)

Trail reads a vault's whole chain through the audit class, page after page: q is the first question, ask asks one (at a price, when the host prices the class) and verify checks one answered token. A page never splits a seq and a seq holds at most 8 tokens, so a page of fewer than 57 tokens is the last, and no further page is asked or paid for. A token that does not verify ends the walk with a *Refusal.

func VerifyToken

func VerifyToken(ctx context.Context, beef []byte, crypt string, org []byte, vault *[32]byte, headers chaintracker.ChainTracker) (*Tok, error)

VerifyToken checks one answered token as a reader does (spec section 14): the transaction holds exactly one well-formed vault token (its record, its lock derived from the record's owner, its field signature), of crypt and owner org and, when vault is not nil, of that vault, and its proof verifies against headers. Descent from the vault's first token is the chain's (Chain).

func (*Tok) Before

func (t *Tok) Before(u *Tok) bool

Before reports whether t was mined before u: lower height, then lower position in its block, then lower txid.

func (*Tok) Hash

func (t *Tok) Hash() [32]byte

Hash is the token's txid in hash byte order.

func (*Tok) Seq

func (t *Tok) Seq() uint64

Seq is the token's seq.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL