Documentation
¶
Overview ¶
Package state is an identity's durable record in its home: the funding trees its carriers and vaults spend, the vaults it owns (each vault's chain of mined tokens and every version it published), the objects persisted before they are published, the sweeps it built, every content key commitment it ever published or listed, and, for a reader, the latest token of each vault it has verified.
It is written before anything leaves the machine. A carrier is persisted with the funding output it spends marked used and its commitment recorded, and a transition with the record it signs, before either is sent, so a run that stops part way sends the same bytes again and never makes a second carrier on one funding output. The file is written atomically (a temporary file, fsync, rename, fsync of the directory) at mode 0600, and the home is locked while a command writes.
The file holds no key: a content key is sampled, wrapped and forgotten, and an epoch key is opened from the group's wraps each time it is needed. The identity key the wallet keeps in the same directory opens every version this identity wrote through its self wrap, so the home is kept at mode 0700 and backed up as a secret.
Index ¶
- Constants
- Variables
- func DropChain(home, crypt, org, vault string)
- func LoadChain(home, crypt, org, vault string) [][]byte
- func Lock(path string) (func(), error)
- func SaveChain(home, crypt, org, vault string, beefs [][]byte) error
- func WriteAtomic(path string, data []byte, perm os.FileMode) (err error)
- type Payment
- type Pending
- type PendingTree
- type SecretVersion
- type Seen
- type SeenGroup
- type State
- func (s *State) AddCrypt(crypt string)
- func (s *State) Commit(c string)
- func (s *State) Committed(c string) bool
- func (s *State) Done(txid, crypt string)
- func (s *State) DropPendingTree(txid string) bool
- func (s *State) Forget(crypt, org, vault string)
- func (s *State) ForgetGroup(hall, org, chain string)
- func (s *State) InFlight() *Sweep
- func (s *State) KeepPayments(waiting []string) bool
- func (s *State) KeepPendingTree(p PendingTree)
- func (s *State) MintedAhead(txid string) *funding.Tree
- func (s *State) OnSave(f func())
- func (s *State) PaymentOf(txid string) *Payment
- func (s *State) PendingTreeOf(txid string) *PendingTree
- func (s *State) Queued(txid, crypt string) bool
- func (s *State) Save() error
- func (s *State) See(v Seen)
- func (s *State) SeeGroup(v SeenGroup)
- func (s *State) SeenGroupOf(hall, org, chain string) *SeenGroup
- func (s *State) SeenOf(crypt, org, vault string) *Seen
- func (s *State) Set(kind string) *TreeSet
- func (s *State) TreeOf(txid string) (*funding.Tree, string, bool)
- func (s *State) UnsettledTrees() []PendingTree
- func (s *State) VaultByID(id string) *Vault
- type Sweep
- type Token
- type Transition
- type TreeSet
- type Vault
Constants ¶
const ( KindSecret = "secret" KindToken = "vault-token" KindSweep = "sweep" )
The kinds of object a home publishes.
const ( TreeSecret = "secret" TreeChain = "chain" )
The kinds of funding tree, each under its own key and basket (spec section 12.4).
const File = "state.json"
File is the state file's name in the home.
const Version = 1
Version is the state file's format version.
Variables ¶
var ErrLocked = errors.New("state: locked by another bsecret process")
ErrLocked is a lock another process holds.
var TreeKinds = []string{TreeSecret, TreeChain}
TreeKinds are the tree kinds in a fixed order.
Functions ¶
func DropChain ¶
func DropChain(home, crypt, org, vault string)
DropChain forgets the tokens kept of a vault.
func LoadChain ¶
LoadChain reads the tokens a reader kept of a vault, in seq order from 0; nil when it kept none.
func Lock ¶
Lock takes an exclusive lock on path (created at 0600), without waiting. The lock is the kernel's and ends with the process, so a crash never leaves it held. Release it with the returned function.
Types ¶
type Payment ¶
type Payment struct {
Txid string `json:"txid"`
// Beef is the payment as Atomic BEEF, hex, with its ancestry back to
// each proof.
Beef string `json:"beef"`
}
Payment is a payment this identity made that has not mined yet.
type Pending ¶
type Pending struct {
Kind string `json:"kind"`
Crypt string `json:"crypt"`
Txid string `json:"txid"`
// Beef is the object's BEEF, hex.
Beef string `json:"beef"`
// The lookup that confirms a host holds it, when the host's answer to
// the submission admitted nothing: for a secret the owner, vault,
// secret and version (version class); for a token the owner, vault and
// seq (vault-seq class); for a sweep one outpoint it spends.
Org string `json:"org,omitempty"`
Vault string `json:"vault,omitempty"`
Seq uint64 `json:"seq,omitempty"`
Secret string `json:"secret,omitempty"`
Version uint64 `json:"version,omitempty"`
Outpoint string `json:"outpoint,omitempty"`
// NotBefore is the Unix time before which it is not published: a mined
// object waits for the propagation delay (spec section 8.3).
NotBefore int64 `json:"notBefore,omitempty"`
}
Pending is one object persisted before it is published.
type PendingTree ¶
type PendingTree struct {
// Kind is the tree's kind.
Kind string `json:"kind"`
// Tree is the record the tree is adopted as, without a proof.
Tree funding.Tree `json:"tree"`
// Coin is the fee coin the tree spends, as the pool held it.
Coin bwallet.Output `json:"coin"`
// ReturnedOnce is set when a command found the tree absent from the
// node and the coin unspent, and put the coin back: the record is kept
// for one more command, in case the tree reaches the node after all.
ReturnedOnce bool `json:"returned_once,omitempty"`
}
PendingTree is a funding tree signed for a pool coin and not yet adopted, keyed by the tree's txid.
type SecretVersion ¶
type SecretVersion struct {
// Name is the secret's name; ID its identifier, hex.
Name string `json:"name"`
ID string `json:"id"`
Version uint64 `json:"version"`
// ContentID and Commitment are the version's, hash byte order, hex.
ContentID string `json:"contentId"`
Commitment string `json:"commitment"`
Epoch uint64 `json:"epoch"`
Label string `json:"label"`
// Txid is the carrier's txid, display order.
Txid string `json:"txid"`
// Tree and Vout are the secret-tree output the carrier spends: a sweep
// of it retracts the version.
Tree string `json:"tree"`
Vout uint32 `json:"vout"`
// Raw is the carrier's transaction, hex: its one output holds the
// record, with the ciphertext when it is carried. Emptied once the
// version is swept. The funding tree it spends is kept with the trees,
// and the BEEF it is published in stays in the outbox only until every
// host named took it.
Raw string `json:"raw,omitempty"`
// Hash is the ciphertext's SHA-256, hex; Stored is set when the
// ciphertext is not carried and was written to the content directory.
Hash string `json:"hash"`
Stored bool `json:"stored,omitempty"`
// Listed is set once a mined token of the vault lists the version, with
// that token's seq.
Listed bool `json:"listed,omitempty"`
Seq uint64 `json:"seq,omitempty"`
// Ended is set once a later token replaced or retired the version.
Ended bool `json:"ended,omitempty"`
// Swept is the sweep that spent its funding output.
Swept string `json:"swept,omitempty"`
// Created is the record's claim; RotateEvery and NotAfter the
// payload's, kept so that what is due is computed without a read.
Created uint64 `json:"created"`
RotateEvery uint64 `json:"rotateEvery,omitempty"`
NotAfter uint64 `json:"notAfter,omitempty"`
}
SecretVersion is one version of one secret, as its owner keeps it.
type Seen ¶
type Seen struct {
Crypt string `json:"crypt"`
Org string `json:"org"`
Vault string `json:"vault"`
Seq uint64 `json:"seq"`
Txid string `json:"txid"`
}
Seen is the latest token of one vault this identity verified.
type SeenGroup ¶
type SeenGroup struct {
Hall string `json:"hall"`
Org string `json:"org"`
Chain string `json:"chain"`
Seq uint64 `json:"seq"`
Txid string `json:"txid"`
}
SeenGroup is the latest token of one group's chain this identity verified: borg's hall, the organization, and the chain borg's reader names (a group id).
type State ¶
type State struct {
Version int `json:"version"`
// Identity is the identity key, compressed hex.
Identity string `json:"identity"`
// Crypts are the crypts this home created (crypt new).
Crypts []string `json:"crypts,omitempty"`
// Trees are the funding trees by kind.
Trees map[string]*TreeSet `json:"trees,omitempty"`
// PendingTrees are the funding trees signed for a pool coin that the
// home has not adopted yet, each with its kind and the coin it spends:
// the record made before a tree reaches the settlement leg, so a run
// that stops before the tree is adopted leaves what the next command
// needs to ask the node what became of it. Adopting a tree drops its
// record in the same save.
PendingTrees []PendingTree `json:"pendingTrees,omitempty"`
// Vaults are the vaults this identity owns.
Vaults []Vault `json:"vaults,omitempty"`
// Outbox holds every object persisted and not yet confirmed published,
// oldest first. A command that finds one publishes the same bytes
// before it builds anything new.
Outbox []Pending `json:"outbox,omitempty"`
// Sweeps are the sweeps this home built.
Sweeps []Sweep `json:"sweeps,omitempty"`
// Commitments are every content key commitment this home published or
// listed, in any vault (hash byte order, hex). A version whose
// commitment is here is never published (spec section 6.2).
Commitments []string `json:"commitments,omitempty"`
// Seen is the latest token of each vault this identity verified as a
// reader: a host that answers an older one is answering an old state.
Seen []Seen `json:"seen,omitempty"`
// SeenGroups is the latest token of each group's chain this identity
// verified through borg's reader: hosts of the hall that answer the
// group only below it are answering an old state, in which a member
// since removed is still a member.
SeenGroups []SeenGroup `json:"seenGroups,omitempty"`
// Payments are the payments this identity made for priced questions
// that have not mined yet, each as the BEEF the host was handed: the
// next payment may spend the change of one, and then carries it.
Payments []Payment `json:"payments,omitempty"`
// Book is what payee settle did for this identity as a host's payee:
// the payments it settled ("settled") and those the network refused
// for good ("unsettleable").
payee.Book
// Taking is the coin pool as it stood when a command that spends from
// it last saved this state: the record made before a coin is taken. A
// coin leaves the pool's own file the moment it is taken, before the
// transaction that spends it is recorded here, so a run that stops in
// between leaves a coin in neither. The next command finds it in this
// list and in no transaction the home records, and puts it back when
// the node shows it unspent. It is empty whenever no command is
// running.
Taking []bwallet.Output `json:"taking,omitempty"`
// contains filtered or unexported fields
}
State is one identity's state.
func (*State) Committed ¶
Committed reports whether a commitment (hash byte order, hex) was published or listed by this home before.
func (*State) DropPendingTree ¶
DropPendingTree drops the record of the tree txid, and reports whether there was one.
func (*State) Forget ¶
Forget drops what was seen of a vault: the token remembered is no longer mined, so a reorganization displaced it (spec section 14).
func (*State) ForgetGroup ¶
ForgetGroup drops what was seen of a group's chain: the token remembered is no longer mined, so a reorganization displaced it.
func (*State) KeepPayments ¶
KeepPayments drops every payment whose txid is not in waiting: it mined, and its change needs no ancestry any more. It reports whether any went.
func (*State) KeepPendingTree ¶
func (s *State) KeepPendingTree(p PendingTree)
KeepPendingTree records p, replacing a record of the same tree.
func (*State) MintedAhead ¶
MintedAhead finds txid among the trees minted ahead and not adopted, of every kind.
func (*State) OnSave ¶
func (s *State) OnSave(f func())
OnSave sets what runs before every Save: a publisher records the pool with it. Nil clears it.
func (*State) PendingTreeOf ¶
func (s *State) PendingTreeOf(txid string) *PendingTree
PendingTreeOf finds the record of the tree txid.
func (*State) Queued ¶
Queued reports whether txid is in the outbox for crypt. A sweep is published in every crypt it retracts a version of, so an object is one transaction in one crypt.
func (*State) SeeGroup ¶
SeeGroup records a verified latest token of a group's chain, never moving the group backwards.
func (*State) SeenGroupOf ¶
SeenGroupOf is the latest token of a group's chain this identity verified, or nil.
func (*State) UnsettledTrees ¶
func (s *State) UnsettledTrees() []PendingTree
UnsettledTrees are the records of trees the home records nowhere else: those a command has yet to ask the node about. A tree minted ahead and recorded in its kind's Ahead keeps its record until it is adopted, and is settled.
type Sweep ¶
type Sweep struct {
Tree string `json:"tree"`
Vouts []uint32 `json:"vouts"`
Crypt string `json:"crypt"`
// Crypts are every crypt the sweep is published in: Crypt, and every
// other crypt that holds a version funded by an output it spends. A
// funding tree is the identity's, not a crypt's.
Crypts []string `json:"crypts,omitempty"`
Txid string `json:"txid"`
// Adopted is set for a spend this home did not build, or built and
// gave up on: the node named it as the spender of an output, and the
// home took it as the sweep it is.
Adopted bool `json:"adopted,omitempty"`
// RawHex is the signed sweep; BumpHex and Height are set once it mined.
RawHex string `json:"rawHex"`
BumpHex string `json:"bumpHex,omitempty"`
Height uint32 `json:"height,omitempty"`
Submitted bool `json:"submitted,omitempty"`
// Done is set once it is mined and handed to the outbox.
Done bool `json:"done,omitempty"`
// Fee is the pool coin that pays its fee, as the pool held it.
Fee *bwallet.Output `json:"fee,omitempty"`
// Failed is why the network refused it, once it did.
Failed string `json:"failed,omitempty"`
}
Sweep is one mined transaction spending funding-tree outputs: output 0 a funding-shaped tombstone, so a host admits it, and every carrier that spent one of Vouts retracted once it mines.
type Token ¶
type Token struct {
Seq uint64 `json:"seq"`
Txid string `json:"txid"`
RawHex string `json:"rawHex"`
// BumpHex is its proof and Height its block's height.
BumpHex string `json:"bumpHex"`
Height uint32 `json:"height"`
// Record is the token's vault record, hex; Vout its token output.
Record string `json:"record"`
Vout uint32 `json:"vout"`
// Parent is the transaction its predecessor input spends: the token at
// seq - 1, or at seq 0 the chain tree.
Parent string `json:"parent"`
// Published is set once every host named took it.
Published bool `json:"published,omitempty"`
}
Token is one mined vault token.
type Transition ¶
type Transition struct {
// Vault is the vault's identifier.
Vault string `json:"vault"`
Seq uint64 `json:"seq"`
Txid string `json:"txid"`
// RawHex is the signed transaction, Record its vault record.
RawHex string `json:"rawHex"`
Record string `json:"record"`
Vout uint32 `json:"vout"`
// Parent is the transaction its predecessor input spends, and
// ParentVout the output.
Parent string `json:"parent"`
ParentVout uint32 `json:"parentVout"`
// Fee is the pool coin that pays its fee, as the pool held it.
Fee *bwallet.Output `json:"fee,omitempty"`
// Submitted is set once the settlement leg took it.
Submitted bool `json:"submitted,omitempty"`
// What describes it in notes.
What string `json:"what,omitempty"`
}
Transition is a vault token built and persisted before it is sent.
type TreeSet ¶
type TreeSet struct {
Tree *funding.Tree `json:"tree,omitempty"`
Trees []funding.Tree `json:"trees,omitempty"`
Ahead []funding.Tree `json:"ahead,omitempty"`
}
TreeSet is one kind's funding trees: the one carriers spend now, every tree minted, and the trees minted ahead and never adopted when a run ended (on the chain, in no other list, kept so a sweep finds them).
type Vault ¶
type Vault struct {
// ID is the vault identifier, 64 lowercase hex digits.
ID string `json:"id"`
Crypt string `json:"crypt"`
Name string `json:"name"`
// Hall and Group name the borg group whose epochs key the vault.
Hall string `json:"hall"`
Group string `json:"group"`
Anchor uint64 `json:"anchor"`
Labels []string `json:"labels"`
// Tokens are its chain, mined, in seq order.
Tokens []Token `json:"tokens,omitempty"`
// Pending is a transition built and persisted, not yet known mined.
Pending *Transition `json:"pending,omitempty"`
// Versions are every version of every secret this home published in
// the vault, oldest first.
Versions []SecretVersion `json:"versions,omitempty"`
}
Vault is one vault this identity owns.
func (*Vault) ByTxid ¶
func (v *Vault) ByTxid(txid string) *SecretVersion
ByTxid finds a version by its carrier's txid.
func (*Vault) VersionOf ¶
func (v *Vault) VersionOf(id, cid string) *SecretVersion
VersionOf finds a version of a secret (by identifier, hex) the home published: the one with the given content id when cid is not empty, else the highest listed and not ended.