Documentation
¶
Overview ¶
Package zonerec is bdns's record codec: the four records a zone's topic carries, the leaves a state commits to, their root and their proofs (docs/spec.md). Each record is a canonical CBOR map with unsigned-integer keys, key 0 its four-byte magic, read with bcommon's record rules: a record is refused for the first rule it breaks, in key order, and keys above the last one a version defines are preserved verbatim.
| Record | Magic | Carried as | | Record set state | "bdr" 0x01 | a chain token under the set's owner | | Origin state | "bdo" 0x01 | a chain token under the origin's owner | | Attached record | "bda" 0x01 | a PushDrop, signed by its writer | | Host record | "bdh" 0x01 | a PushDrop, signed by the host |
A leaf is not a record: it is a canonical CBOR array, one per name and type, and a state commits to its leaves by an RFC 6962 root.
Index ¶
- Constants
- Variables
- func CheckAnswer(leaves []*Leaf) error
- func CheckKey(b []byte) error
- func CheckLeaves(leaves []*Leaf) error
- func CheckOrder(leaves []*Leaf) error
- func Commitment(originID, secret [32]byte) [32]byte
- func EncodeLeaves(leaves []*Leaf, maxCount, maxSize int) ([]byte, error)
- func EncodeName(n Name) ([]byte, error)
- func FundingScript(key *ec.PublicKey) []byte
- func LeafKey(name Name, typ uint16, scope []byte) []byte
- func LockingKey(d pushdrop.Derivation, identity []byte) (*ec.PublicKey, error)
- func OriginID(genesis []byte, txid [32]byte, vout uint32) [32]byte
- func Pieces(size uint64) uint64
- func Reason(err error) string
- func Reasons() []string
- func RecordSetID(genesis []byte, txid [32]byte, vout uint32) [32]byte
- func Root(leaves []*Leaf) ([32]byte, error)
- func Signed(tag, rec []byte, spent transaction.Outpoint) []byte
- func SignedBy(tx *transaction.Transaction, vout int, c Chain, identity []byte, ...) bool
- func SortLeaves(leaves []*Leaf)
- func TokenLock(ctx context.Context, signer wallet.Interface, originator string, s *State, ...) (*script.Script, error)
- func TokenScript(key *ec.PublicKey, tag, rec, sig []byte) []byte
- func Topic(id [32]byte) string
- func TopicLetters(id [32]byte) string
- func ValidDomain(d string) bool
- func ValidLabel(l string) bool
- type Absence
- type Admission
- type Admitter
- type Attached
- type Chain
- type CheckFailure
- type Claim
- type Data
- type Extension
- type Held
- type Host
- type Kind
- type Leaf
- type Member
- type Name
- type Origin
- func (o *Origin) AnswersWith(s *RecordSet) bool
- func (o *Origin) Check(object []byte) ([]*Leaf, error)
- func (o *Origin) Commit(leaves []*Leaf) ([]byte, error)
- func (o *Origin) Commitment() [32]byte
- func (o *Origin) Encode() ([]byte, error)
- func (o *Origin) Precedes(next *Origin) bool
- func (o *Origin) UnknownCritical(known func(kind uint64) bool) (uint64, bool)
- type Part
- type Piece
- type Presence
- type Proof
- type RecordSet
- func (s *RecordSet) Check(object []byte) ([]*Leaf, error)
- func (s *RecordSet) Commit(leaves []*Leaf) ([]byte, error)
- func (s *RecordSet) Encode() ([]byte, error)
- func (s *RecordSet) Lists(c [32]byte) bool
- func (s *RecordSet) Precedes(next *RecordSet) bool
- func (s *RecordSet) UnknownCritical(known func(kind uint64) bool) (uint64, bool)
- type State
- func (s *State) Anchor() transaction.Outpoint
- func (s *State) Check(object []byte) ([]*Leaf, error)
- func (s *State) Count() uint64
- func (s *State) Data() [32]byte
- func (s *State) Follows(prev *State) error
- func (s *State) Genesis() []byte
- func (s *State) ID() [32]byte
- func (s *State) Lapse() uint64
- func (s *State) Owner() []byte
- func (s *State) Root() [32]byte
- func (s *State) Seq() uint64
- func (s *State) Signer(prev *State) []byte
- func (s *State) Size() uint64
- func (s *State) UnknownCritical(known func(kind uint64) bool) (uint64, bool)
- type Tree
- func (t *Tree) Count() uint64
- func (t *Tree) Find(key []byte) (int, bool)
- func (t *Tree) Prove(index int) (*Presence, error)
- func (t *Tree) ProveAbsent(key []byte) (*Absence, error)
- func (t *Tree) ProveAbsentName(name Name) (*Absence, error)
- func (t *Tree) ProveKey(name Name, typ uint16, scope []byte) (*Proof, error)
- func (t *Tree) ProveName(name Name) (*Proof, error)
- func (t *Tree) Root() [32]byte
- type View
Constants ¶
const ( MaxTokenBEEF = 196608 // a token with its parent, or with what its inputs spend MaxPieceBEEF = 196608 // a leaves piece's carrier and its funding tree MaxLoosePieces = 256 // pieces a chain holds that no kept state names DefaultMaxBEEF = 262144 )
Bounds on what a host admits.
const ( AKMagic = 0 AKZone = 1 // the identifier of the record set or origin it attaches to AKKind = 2 // what it is, 1 to 65,535 AKWriter = 3 // who signs it, 33 bytes AKName = 4 // the name it is about; no labels for the zone AKExpiry = 5 // Unix seconds after which it is not believed AKBody = 6 // at most 8,192 bytes; its form is the kind's AKLast = AKBody )
The attached record's keys (docs/spec.md section 9). It is the payload of a PushDrop signed by its writer. Version 1 admits no kind.
const ( KindMember = 1 KindNameserver = 2 // a nameserver advertisement KindReceipt = 3 // a render receipt KindObjection = 4 KindFinding = 5 KindReport = 6 KindOutcome = 7 )
The assigned kinds of an attached record. Only a member's body has a form in this version.
const ( MKHost = 1 // the host's key, 33 bytes MKRule = 2 // RuleGrant or RuleAdvert RuleGrant = 1 RuleAdvert = 2 )
The member body's keys and rules.
const ( TypeA = 1 TypeNS = 2 TypeCNAME = 5 TypeSOA = 6 TypePTR = 12 TypeMX = 15 TypeAAAA = 28 TypeSRV = 33 TypeDNAME = 39 TypeOPT = 41 TypeDS = 43 TypeRRSIG = 46 TypeNSEC = 47 TypeDNSKEY = 48 TypeNSEC3 = 50 TypeNSEC3PARAM = 51 TypeCDS = 59 TypeCDNSKEY = 60 TypeSVCB = 64 TypeHTTPS = 65 TypeTKEY = 249 TypeTSIG = 250 )
The record types the checks name.
const ( HKMagic = 0 HKHost = 1 // the host's key, 33 bytes HKAddresses = 2 // 1 to 32 addresses of 4 or 16 bytes, distinct, ascending; none IPv4-mapped HKPort = 3 // 1 to 65,535 HKProtocols = 4 // 0 to 8 ALPN identifiers of 1 to 32 bytes, distinct, ascending HKCA = 5 // the certificate authority's CAA domain, or "" HKAccount = 6 // the account URI at that authority, at most 512 bytes; "" when there is no authority HKLocation = 7 // an IATA metro code, three upper-case letters, or "" HKExpiry = 8 // Unix seconds after which it is not believed HKLast = HKExpiry )
The host record's keys (docs/spec.md section 10). It is the payload of a PushDrop signed by the host's key. Version 1 admits none.
const ( SecurityLevel = 1 ProtocolRecordSet = "bdns records" ProtocolOrigin = "bdns origin" ProtocolMember = "bdns member" // attached and host records KeyIDState = "state" // token lock and field signature KeyIDChain = "chain" // the outputs of the tree that pays for a chain's first token KeyIDAttach = "attach" // attached record lock and field signature KeyIDHost = "host" // host record lock and field signature )
The BRC-43 protocols, all at security level 1, and their key ids. Derivations are BRC-42 with the anyone counterparty.
const ( TopicPrefix = "tm_bdns_" LookupService = "ls_bdns" TopicLetterN = 28 )
The topic prefix and the lookup service.
const ( OKMagic = 0 OKID = 1 // the origin's identifier: 32 bytes, the same in every state OKSeq = 2 // 0 for the first state, then one more each state OKGenesis = 3 // the owner at seq 0, 33 bytes; the same in every state OKOwner = 4 // who signs this state; the genesis key at seq 0 OKAnchor = 5 // the outpoint the first state spent: txid || uint32be(vout) OKBase = 6 // the identifier of the record set this origin answers with OKSecret = 7 // opens the record set's commitment to this origin OKSerial = 8 // the SOA serial, greater than the previous state's OKRoot = 9 // the RFC 6962 root over this origin's own leaves OKCount = 10 // the number of its own leaves OKData = 11 // SHA-256 of its leaves object OKSize = 12 // bytes of its leaves object OKRecovery = 13 // empty, or SHA-256 of a key that may replace a lost owner key OKSigning = 14 // reserved for the zone's signing keys; empty OKExtensions = 15 // extensions, as a record set's OKLapse = 16 // Unix seconds after which an unmined state is not believed OKLast = OKLapse )
The origin state's keys (docs/spec.md section 6).
const ( MaxPiece = 128 << 10 // bytes of a leaves object one piece carries MaxPieceRecord = MaxPiece + 512 // a piece, encoded )
Bounds of a leaves piece (docs/spec.md section 12).
const ( PKMagic = 0 PKZone = 1 // the chain's identifier PKGenesis = 2 // the chain's genesis key PKAnchor = 3 // the chain's anchor: txid || uint32be(vout) PKWriter = 4 // who signs the piece PKData = 5 // SHA-256 of the whole leaves object PKSize = 6 // bytes of the whole leaves object PKIndex = 7 // which piece, from 0 PKBytes = 8 // the object's bytes from index * MaxPiece PKLast = PKBytes )
The leaves piece's keys.
const ( MaxProofLeaves = 64 // leaves at one name a proof carries MaxProof = 2 << 20 // a proof, encoded )
Bounds of a proof's byte form (docs/spec.md section 13).
const ( RKMagic = 0 RKID = 1 // the record set's identifier: 32 bytes, the same in every state RKSeq = 2 // 0 for the first state, then one more each state RKGenesis = 3 // the owner at seq 0, 33 bytes; the same in every state RKOwner = 4 // who signs this state; the genesis key at seq 0 RKAnchor = 5 // the outpoint the first state spent: txid || uint32be(vout) RKRoot = 6 // the RFC 6962 root over the leaves RKCount = 7 // the number of leaves RKData = 8 // SHA-256 of the leaves object RKSize = 9 // bytes of the leaves object RKAccepts = 10 // commitments to origins: distinct, ascending RKExtensions = 11 // extensions: distinct and ascending by kind RKLapse = 12 // Unix seconds after which an unmined state is not believed RKLast = RKLapse )
The record set state's keys (docs/spec.md section 5).
const ( MaxRecord = 16 << 10 // any record, encoded MaxLeaf = 16 << 10 // a leaf, encoded MaxLabel = 63 // a label's bytes MaxNameWire = 200 // a relative name's labels with their length bytes MaxDNSName = 255 // an absolute name on the wire, its root byte included MaxParts = 16 // parts of one record's data MaxPartBytes = 4096 // a byte-string part MaxValues = 64 // records of one leaf MaxType = 65535 MaxTTL = 1<<31 - 1 MaxSetCount = 1 << 20 // leaves of a record set MaxSetSize = 16 << 20 // a record set's leaves object, bytes MaxOriginCount = 4096 // an origin's own leaves MaxOriginSize = 1 << 20 // an origin's leaves object, bytes MaxAccepts = 64 MaxExtensions = 8 MaxExtension = 1024 // an extension's body MaxSerial = 1<<32 - 1 MaxBody = 8192 // an attached record's body MaxAddresses = 32 MaxProtocols = 8 MaxProtocol = 32 MaxAccount = 512 MaxCADomain = 253 MaxSafe = 1<<53 - 1 )
Bounds on what a record, a leaf and a leaves object carry.
const KeyIDLeaves = "leaves"
KeyIDLeaves locks a leaves piece's carrier and the trees that fund them (docs/spec.md sections 7 and 12).
Variables ¶
var ( ErrShape = errors.New("zonerec: transaction has the wrong shape") ErrBEEF = chaintoken.ErrBEEF ErrZone = errors.New("zonerec: record is not for this topic's chain") ErrLock = errors.New("zonerec: output script is not the canonical one for its key") ErrTokenInput = errors.New("zonerec: token does not spend its predecessor, or its chain tree at seq 0") ErrAnchor = errors.New("zonerec: anchor is not the outpoint the first token spends") ErrContinuity = errors.New("zonerec: state does not follow its predecessor") ErrSerial = errors.New("zonerec: serial is not greater than the previous state's") ErrRecovery = errors.New("zonerec: recovery differs from the previous state's") ErrFieldSig = errors.New("zonerec: field signature is not strict or does not verify under its signer") ErrUnmined = errors.New("zonerec: proof does not verify against the host's headers") ErrScript = errors.New("zonerec: an unmined token's input does not unlock the output it spends") ErrLapsed = errors.New("zonerec: an unmined state's lapse time has passed") ErrOrphan = errors.New("zonerec: the host does not hold the state this one follows") ErrFork = errors.New("zonerec: the host holds another successor of the same state") ErrNoLeaves = errors.New("zonerec: the host does not hold the state's whole leaves object") ErrPiece = errors.New("zonerec: a leaves piece is not a piece of its object") ErrMineable = errors.New("zonerec: carrier is mineable") ErrUnlock = errors.New("zonerec: unlocking script is not one canonical signature push") ErrFunding = errors.New("zonerec: carrier does not spend a funding output of its key, or does not carry its value") ErrWriter = errors.New("zonerec: a leaves piece's writer may not sign the chain's next state") ErrHeld = errors.New("zonerec: the host already holds a piece of this object at this index") ErrFull = errors.New("zonerec: the host holds its bound of pieces that no kept state names") ErrUnsupported = errors.New("zonerec: attached and host records are not admitted yet") ErrNotBdns = errors.New("zonerec: transaction is not for this topic") ErrHostConfig = errors.New("zonerec: host configuration or previous coins out of range") )
The transaction refusals (docs/spec.md section 12), beside the record refusals. A transaction is refused for the first rule it breaks.
var ( TagRecordSet = []byte{0x62, 0x64, 0x01} TagFunding = []byte{0x62, 0x64, 0x02} TagOrigin = []byte{0x62, 0x64, 0x03} TagAttached = []byte{0x62, 0x64, 0x04} TagHost = []byte{0x62, 0x64, 0x05} )
The tags a script carries before its record.
var ( MagicRecordSet = []byte("bdr\x01") MagicOrigin = []byte("bdo\x01") MagicAttached = []byte("bda\x01") MagicHost = []byte("bdh\x01") )
The records' magics: four bytes, the last the version.
var ( ErrLabel = errors.New("zonerec: not a label") ErrName = errors.New("zonerec: a name is over its bound, or has a wildcard label that is not first") ErrPart = errors.New("zonerec: a data part is malformed, or two byte parts are adjacent") ErrData = errors.New("zonerec: record data is missing, over the bound, or not distinct and ascending") ErrLeaf = errors.New("zonerec: a leaf is not its five items") ErrScope = errors.New("zonerec: a scope is not empty or 32 bytes that are not all zero, or an origin's own leaf has one") ErrOrder = errors.New("zonerec: leaves are not in key order") ErrDuplicate = errors.New("zonerec: two leaves share a key") ErrKey = errors.New("zonerec: not a canonical compressed public key, or the anyone key") ErrGenesis = errors.New("zonerec: the owner at seq 0 is not the genesis key") ErrID = errors.New("zonerec: the identifier is not the one its genesis key and outpoint give") ErrExtension = errors.New("zonerec: an extension is malformed, or kinds are not distinct and ascending") ErrMember = errors.New("zonerec: not a member body") ErrAddress = errors.New("zonerec: addresses are missing, not 4 or 16 bytes, IPv4-mapped, or not distinct and ascending") ErrProtocol = errors.New("zonerec: protocols are over the bound, or not distinct and ascending") ErrCA = errors.New("zonerec: not a certificate authority's domain") ErrAccount = errors.New("zonerec: an account with no certificate authority") ErrLocation = errors.New("zonerec: not an IATA metro code") ErrProof = errors.New("zonerec: the proof does not hold") ErrPresent = errors.New("zonerec: the key is present") )
Refusals beyond bcommon's record ones. Reason gives each a fixed label.
var ( ErrMismatch = errors.New("zonerec: the leaves object does not match the state") ErrRendererType = errors.New("zonerec: a leaf of a type the renderer writes, or of a type that is not data") ErrCNAME = errors.New("zonerec: a CNAME at the apex, beside another type, or of more than one record") ErrCut = errors.New("zonerec: a leaf at or below a delegation") ErrNoName = errors.New("zonerec: data of a type that names a host holds no name part") )
The refusals of the checks of spec section 8: C1 ErrMismatch, C2 ErrScope, then C3 to C6 in order.
var AnyoneKey = []byte{
0x02, 0x79, 0xbe, 0x66, 0x7e, 0xf9, 0xdc, 0xbb, 0xac, 0x55, 0xa0, 0x62, 0x95, 0xce, 0x87, 0x0b, 0x07,
0x02, 0x9b, 0xfc, 0xdb, 0x2d, 0xce, 0x28, 0xd9, 0x59, 0xf2, 0x81, 0x5b, 0x16, 0xf8, 0x17, 0x98,
}
AnyoneKey is BRC-43's anyone counterparty: the generator point, whose private key is 1. No record names it.
var Chains = []Chain{ChainRecordSet, ChainOrigin}
Chains lists them, for a host's metrics.
var EmptyRoot = commit.RootOfLeafHashes(nil)
EmptyRoot is the root of no leaves: SHA-256 of the empty string.
var Kinds = []Kind{KindRecordSet, KindOrigin, KindLeaves}
Kinds lists them, for a host's metrics.
var MagicPiece = []byte("bdl\x01")
MagicPiece is a leaves piece's magic.
Functions ¶
func CheckAnswer ¶
CheckAnswer applies C3 to C6 to what an origin answers: the leaves are one zone, so C4 and C5 hold whatever scope a leaf was written with.
func CheckKey ¶
CheckKey holds b to the key rule of spec section 1: a canonical compressed point (bcommon guard.ParsePubKey) that is not the anyone key.
func CheckLeaves ¶
CheckLeaves applies checks C3 to C6 of spec section 8 to one state's leaves, in that order, each over all the leaves in the order given, and returns the first refusal:
C3 ErrRendererType a leaf of a type the renderer writes or that is not data
C4 ErrCNAME a CNAME at the apex, of more than one record, or at a
name with another type under the same scope
C5 ErrCut a leaf at or below a name with an NS leaf, off the apex
C6 ErrNoName a record of a type that names a host with no name part
C5 reads a delegation as cutting every leaf an origin could answer beside it: of the same scope, or with either scope empty. It lets through the NS leaves at the cut, DS at the cut, and A and AAAA leaves whose name an NS record of the cut gives as a single name part relative to the origin.
func CheckOrder ¶
CheckOrder holds leaves to key order with no key twice: ErrDuplicate for two leaves of one key, ErrOrder for a leaf before its place.
func Commitment ¶
Commitment is what a record set lists for an origin it answers for: SHA-256 of the label, the origin's identifier and its secret.
func EncodeLeaves ¶
EncodeLeaves writes the leaves object: the canonical CBOR array of the leaves in key order. It refuses a leaf DecodeLeaf refuses, leaves out of order, a key twice, more than maxCount leaves and more than maxSize bytes.
func EncodeName ¶
EncodeName writes a relative name as its canonical CBOR array of text labels, refusing what DecodeName refuses.
func FundingScript ¶
FundingScript is a funding output locked to key: <key> OP_CHECKSIG <62 64 02> OP_DROP. A chain tree's outputs and a leaves tree's are each this, under their own key.
func LockingKey ¶
LockingKey is the key an identity's output is locked to under d.
func Reason ¶
Reason is the fixed label of a refusal: bcommon's record labels, then this package's, else "other".
func Reasons ¶
func Reasons() []string
Reasons are every label Reason gives but "other": bcommon's record labels, then this package's. A host presets a counter for each.
func RecordSetID ¶
RecordSetID is a record set's identifier: SHA-256 of the label, the genesis key, and the anchor: the outpoint its first state spent, the txid in hash byte order.
func Root ¶
Root is the RFC 6962 root over leaves, which are in key order: each leaf's hash is commit.HashLeaf of its encoding.
func Signed ¶
func Signed(tag, rec []byte, spent transaction.Outpoint) []byte
Signed is what a token's field signature covers: the tag, the record and the outpoint the token spends (its predecessor's, or the anchor at seq 0), the txid in hash byte order then the index as four big-endian bytes. The outpoint binds the signature to the token's place in the chain: the output copied into a transaction that spends anything else does not verify.
func SignedBy ¶
func SignedBy(tx *transaction.Transaction, vout int, c Chain, identity []byte, spent transaction.Outpoint) bool
SignedBy reports whether the token at output vout of tx carries a strict field signature of identity's "state" key over its tag, its record and the outpoint spent.
func TokenLock ¶
func TokenLock(ctx context.Context, signer wallet.Interface, originator string, s *State, spent transaction.Outpoint) (*script.Script, error)
TokenLock builds a state token's locking script: locked to derive(owner, "state") and signed, over Signed's bytes for the outpoint the token will spend, by signer's wallet under its own "state" key. signer is the owner's wallet, or at a change of owner the previous owner's.
func TokenScript ¶
TokenScript is a state token's output: <key> OP_CHECKSIG <tag> <record> <signature> OP_2DROP OP_DROP. The signature is over tag || record.
func TopicLetters ¶
TopicLetters is the identifier's first 16 bytes read as a big-endian number and written in base 26 with the digits a to z, padded on the left with a to 28 letters.
func ValidDomain ¶
ValidDomain reports a lower-case DNS name in dotted form: at least two letter-digit-hyphen labels, 253 bytes at most, no trailing dot, and a last label that is not all digits.
func ValidLabel ¶
ValidLabel reports a label: 1 to 63 bytes of lower-case letters, digits, hyphen and underscore, or the single byte "*".
Types ¶
type Absence ¶
Absence proves that a state holds no leaf in a range of keys: the leaf before the range and the leaf after it, adjacent in the state. Before is nil when the range sorts before every leaf, After when it sorts after every leaf, and both when the state has no leaves.
type Admission ¶
type Admission struct {
Kind Kind
Txid [32]byte
Outputs []int
Retain []int
// For a token: the state, whether the token is proven, the outpoint it
// spends (its predecessor, or its anchor at seq 0), the unmined rival it
// replaces, an unknown critical extension's kind, and a failed check.
State *State
Mined bool
Spends transaction.Outpoint
Replaces *transaction.Outpoint
Critical *uint64
// Check is the label of the check of C2 to C6 the state fails, or "":
// such a state is admitted and is not rendered (spec section 12.2).
Check string
// For a leaves piece: the piece and its funding outpoint.
Piece *Piece
Funding transaction.Outpoint
}
Admission is what a host admits from one transaction.
type Admitter ¶
type Admitter struct {
Zone [32]byte
Headers chaintracker.ChainTracker
MaxBEEF int
Now func() time.Time
View View
}
Admitter is what admission needs beyond the submission: the topic's chain, a chain tracker over the host's headers, its BEEF bound (zero is the floor, DefaultMaxBEEF), its clock and its view of the topic.
type Attached ¶
type Attached struct {
Zone [32]byte
Kind uint64
Writer []byte
Name Name
Expiry uint64
Body []byte
Extra cbor.Map
}
Attached is a record attached to a record set or an origin.
func DecodeAttached ¶
DecodeAttached reads an attached record's payload, key by key. A member's body is held to the member form; every other kind's body is opaque to this version and only bounded.
type Chain ¶
type Chain string
Chain is which of the two chains a topic carries.
func ChainOf ¶
ChainOf is the chain whose identifier id is, for a genesis key and an anchor: a record set's and an origin's are hashed under different labels.
func (Chain) Derivation ¶
func (c Chain) Derivation(keyID string) pushdrop.Derivation
Derivation is the chain's derivation of keyID, with counterparty anyone, so anyone derives a key from the identity key alone.
type CheckFailure ¶ added in v0.1.1
CheckFailure is a refusal by one of checks C2 to C6 (spec section 8): the leaves object is the state's (C1 holds), and what it holds may not be rendered. A host admits such a state and keeps it for the chain's continuity (spec section 12.2).
func Failed ¶ added in v0.1.1
func Failed(err error) (*CheckFailure, bool)
Failed reports whether err is a refusal by one of checks C2 to C6, and which.
func (*CheckFailure) Error ¶ added in v0.1.1
func (e *CheckFailure) Error() string
func (*CheckFailure) Label ¶ added in v0.1.1
func (e *CheckFailure) Label() string
Label is the check's label (Reason).
func (*CheckFailure) Unwrap ¶ added in v0.1.1
func (e *CheckFailure) Unwrap() error
type Claim ¶
type Claim string
Claim is what an output claims to be.
const ( ClaimNone Claim = "" ClaimRecordSet Claim = "record-set" ClaimOrigin Claim = "origin" ClaimAttached Claim = "attached" ClaimHost Claim = "host" ClaimPiece Claim = "leaves" ClaimFunding Claim = "funding" )
The claims.
type Data ¶
type Data []Part
Data is one resource record's data: 1 to 16 parts, no two byte parts adjacent. The codec does not know record types.
func DecodeData ¶
DecodeData reads one record's data from its canonical CBOR array.
func (Data) Encode ¶
Encode writes the data as its canonical CBOR array, refusing what DecodeData refuses.
func (Data) Join ¶
Join returns the data with adjacent byte parts joined, as an encoder writes it. A joined part over 4,096 bytes is still refused by Check.
func (Data) Wire ¶
Wire is the data in DNS wire form under origin, the origin's labels leftmost first: the parts in order, each name written uncompressed with its root byte, and the origin's labels appended to a relative one. It is nil when the data does not hold to section 3, when origin has a label that is not 1 to 63 bytes, or when a name would pass 255 bytes on the wire.
type Extension ¶
Extension is one extension of a state: a kind, whether a reader that does not know the kind must stop, and a body of at most 1,024 bytes.
type Held ¶
type Held struct {
Outpoint transaction.Outpoint
State *State
Mined bool
}
Held is a state the host keeps: its token's outpoint, the state, and whether the host knows the token mined.
type Host ¶
type Host struct {
Host []byte
Addresses [][]byte
Port uint16
Protocols []string
CA string
Account string
Location string
Expiry uint64
Extra cbor.Map
}
Host is a host's claim of where it answers.
func DecodeHost ¶
DecodeHost reads a host record's payload, key by key. Addresses and protocols ascend by their own bytes.
type Leaf ¶
type Leaf struct {
Name Name
Type uint16 // 1 to 65,535
TTL uint32 // 0 to 2,147,483,647
// Data is 1 to 64 records' data, distinct, ascending by encoded bytes.
Data []Data
// Scope is empty, or the 32-byte identifier of the one origin this leaf
// stands under.
Scope []byte
}
Leaf is one record set in the DNS sense: every record of one name and type (spec section 4). It is the canonical CBOR array [name, type, ttl, data, scope].
func Answer ¶
Answer is what an origin answers (spec section 6): the record set's leaves with an empty scope, then its leaves with the origin's identifier as scope, then the origin's own leaves; of leaves of one name and type the later wins. The result is ordered by name and type as leaf keys are, and its leaves keep the scope they were written with.
Both inputs are in key order with no key twice. An own leaf with a scope is refused (ErrScope), and so is a result that does not hold to checks C3 to C6 read as one zone (CheckAnswer). The origin's domain is not known here: a name that would pass 255 bytes under it is the renderer's to leave out and report.
func DecodeLeaf ¶
DecodeLeaf reads a leaf, refusing it for the first rule it breaks: the bound, canonical CBOR, an array of five items, then item by item.
func DecodeLeaves ¶
DecodeLeaves reads a leaves object of at most maxSize bytes and maxCount leaves: the bound, canonical CBOR, an array, then leaf by leaf, each within MaxLeaf and after the one before it in key order.
func (*Leaf) Encode ¶
Encode writes the leaf canonically. It refuses what DecodeLeaf refuses, so a leaf this package writes is one it reads.
func (*Leaf) Key ¶
Key is the leaf's key: for each label from the last to the first, the label then one zero byte; then one more zero byte; then the type as two big-endian bytes; then the scope, or 32 zero bytes when it is empty. Leaves are ordered by their keys as byte strings, which orders their names as RFC 4034 section 6.1 does.
type Member ¶
Member is the body of an attached record of kind member: the canonical CBOR map {1: host key, 2: rule}, and no other key. A different body is a different kind.
func DecodeMember ¶
DecodeMember reads a member body.
type Name ¶
type Name []string
Name is a name of spec section 2: labels, leftmost first, each a CBOR text string. A relative name stands under an origin a record does not know; no labels is the origin itself. An absolute name is the same form read as a full domain name; no labels is the root.
func DecodeName ¶
DecodeName reads a relative name from its canonical CBOR array.
func (Name) Check ¶
Check holds a relative name to section 2: every label a label, "*" only first, and at most 200 bytes with the labels' length bytes.
func (Name) CheckAbsolute ¶
CheckAbsolute holds an absolute name to section 2: as Check, and at most 255 bytes with the labels' length bytes and the root byte.
func (Name) KeyPrefix ¶
KeyPrefix is what every leaf key of exactly this name starts with: the labels last to first, each followed by one zero byte, then one more zero byte.
type Origin ¶
type Origin struct {
ID [32]byte
Seq uint64
Genesis []byte
Owner []byte
// AnchorTxid and AnchorVout are the outpoint the chain's seq 0 token
// spent (key 5), as a record set's.
AnchorTxid [32]byte
AnchorVout uint32
Base [32]byte
Secret [32]byte
Serial uint32
Root [32]byte
Count uint64
Data [32]byte
Size uint64
Recovery []byte
Signing [][]byte
Extensions []Extension
Lapse uint64
// Extra holds keys above OKLast, verbatim.
Extra cbor.Map
}
Origin is one state of an origin: a zone apex that answers with a record set's leaves and its own. It does not carry its domain.
func DecodeOrigin ¶
DecodeOrigin reads an origin state, key by key, then the rules that join keys, as DecodeRecordSet.
func (*Origin) AnswersWith ¶
AnswersWith reports whether the origin answers with the record set's state s: s is a state of the origin's base, and it lists the origin's commitment. That s is the record set's latest state is the caller's.
func (*Origin) Commit ¶
Commit is RecordSet.Commit for an origin state and its own leaves, none of which has a scope.
func (*Origin) Commitment ¶
Commitment is the value a record set lists to answer for this origin.
type Part ¶
type Part struct {
// Bytes is a byte part: 1 to 4,096 bytes. Unused by a name part.
Bytes []byte
// IsName marks a name part. Absolute is its form: false for a name
// relative to the origin, true for an absolute name.
IsName bool
Absolute bool
Name Name
}
Part is one part of a record's data (spec section 3): wire-format bytes copied as they are, or a name the renderer writes out.
type Piece ¶
type Piece struct {
Zone [32]byte
Genesis []byte
AnchorTxid [32]byte
AnchorVout uint32
Writer []byte
Data [32]byte
Size uint64
Index uint64
Bytes []byte
// Chain is the chain Zone names, set by DecodePiece.
Chain Chain
// Extra holds keys above PKLast, verbatim.
Extra cbor.Map
}
Piece is one piece of a leaves object: the object cut every MaxPiece bytes, so one object has one cutting.
func DecodePiece ¶
DecodePiece reads a leaves piece: the record rules with its own bound, key by key, then the rules that join keys, in this order: the zone is the identifier the genesis key and the anchor give, as a record set or as an origin (id); then the object is within its chain's bound, the index is one of its pieces and the bytes are that piece's length (piece).
type Presence ¶
Presence proves one leaf of a state: the leaf, its index, and its RFC 6962 audit path, leaf to root. The state's count and root are the verifier's own, from the state.
type Proof ¶
type Proof struct {
// Whole is every leaf at Name, whatever its type and scope; else the
// one leaf of Name, Type and Scope.
Whole bool
Name Name
Type uint16
Scope []byte
// Present are the leaves there, in key order.
Present []*Presence
// Before and After are the leaves next to the key or the name's leaves:
// nil at either end of the state, and both nil for one leaf proven
// present, which needs no neighbor.
Before, After *Presence
}
Proof is the byte form of a proof against one state (spec section 13): for one key (a name, a type and a scope) or for a whole name, the leaves there, each with its path, and the neighbors that show there is no other. It answers both ways: Present holds what is there, and when it is empty the neighbors prove absence (section 4).
func DecodeProof ¶
DecodeProof reads a proof's byte form: the bound, canonical CBOR, the seven items, each of its type and within its rule. It decides nothing about whether the proof holds: Verify does, against a state.
func (*Proof) Encode ¶
Encode writes the proof as its canonical CBOR array [form, name, type, scope, present, before, after], refusing what DecodeProof refuses.
func (*Proof) Verify ¶
Verify holds the proof against a state of count leaves under root. It trusts nothing of the prover. With no leaf present it is section 4's proof of absence. One key present is the leaf under the root, with that key and no neighbor. A whole name present is its leaves, adjacent by index, each under the root with the name's prefix, and on either side a neighbor outside the name, or the end of the state.
type RecordSet ¶
type RecordSet struct {
ID [32]byte
Seq uint64
Genesis []byte
Owner []byte
// AnchorTxid and AnchorVout are the outpoint the chain's seq 0 token
// spent (key 5): the txid in hash byte order. With Genesis it is hashed
// into ID.
AnchorTxid [32]byte
AnchorVout uint32
Root [32]byte
Count uint64
Data [32]byte
Size uint64
Accepts [][32]byte
Extensions []Extension
Lapse uint64
// Extra holds keys above RKLast, verbatim.
Extra cbor.Map
}
RecordSet is one state of a record set: the leaves it commits to and the origins it answers for.
func DecodeRecordSet ¶
DecodeRecordSet reads a record set state, refusing it for the first rule it breaks: the record rules (too-large, cbor, key-type, magic), then key by key in key order (missing, type, the key's own rule), then the rules that join keys, in this order: at seq 0 the owner is the genesis key (genesis), and the identifier is the one the genesis key and the anchor give (id).
func (*RecordSet) Check ¶
Check applies checks C1 and C3 to C6 of spec section 8 to the state and its leaves object, and returns the leaves or the first refusal. A refusal by C2 to C6 is a CheckFailure, returned with the leaves.
func (*RecordSet) Commit ¶
Commit sets the state's root, count, data and size from leaves and returns the leaves object it then commits to.
func (*RecordSet) Encode ¶
Encode writes the record canonically. It refuses what DecodeRecordSet refuses, so a record this package writes is one it reads.
func (*RecordSet) Precedes ¶
Precedes reports whether next may follow s in one record set's chain: the same identifier, genesis key and outpoint, one more seq. The token transactions' own link, and who signs a change of owner, are the module's to check.
func (*RecordSet) UnknownCritical ¶
UnknownCritical reports the first critical extension of a kind the reader does not know. When it reports one, the reader stops rendering the chain at this state and says so. Version 1 defines no kind.
type State ¶
type State struct {
Chain Chain
Set *RecordSet // a record set's state
Origin *Origin // an origin's
// Record is the record's bytes, as the token carries them.
Record []byte
}
State is one state of either chain, read through what the two share.
func DecodeState ¶
DecodeState reads rec as a state of chain c.
func ReadState ¶
func ReadState(tx *transaction.Transaction) (*State, int, error)
ReadState reads the one state token a stored transaction holds, without its parent: how an index reads a token it admitted. The field signature is not checked here, since it covers the outpoint spent and at a change of owner is the previous owner's; SignedBy checks it once both are known.
func (*State) Anchor ¶
func (s *State) Anchor() transaction.Outpoint
Anchor is the outpoint the chain's first token spent.
func (*State) Check ¶
Check applies checks C1 to C6 to the state and its leaves object. A refusal by C2 to C6 is a CheckFailure, returned with the leaves.
func (*State) Follows ¶
Follows holds s to the continuity rules after prev (spec section 12), in their order: the same chain, identifier, genesis key and anchor and one more seq (ErrContinuity); for an origin a greater serial (ErrSerial) and the same recovery (ErrRecovery).
type Tree ¶
type Tree struct {
// contains filtered or unexported fields
}
Tree is a state's leaves in key order with their keys and hashes: what a holder of the leaves object proves from.
func NewTree ¶
NewTree hashes leaves, which are in key order with no key twice. It refuses a leaf DecodeLeaf refuses.
func (*Tree) ProveAbsent ¶
ProveAbsent proves that no leaf has key, or returns ErrPresent.
func (*Tree) ProveAbsentName ¶
ProveAbsentName proves that no leaf of any type or scope is at name, or returns ErrPresent.
func (*Tree) ProveKey ¶
ProveKey proves the leaf of a name, a type and a scope, or that there is none.
type View ¶
type View interface {
// At is the state kept at seq, or nil.
At(seq uint64) *Held
// Tip is the kept state of the highest seq, or nil.
Tip() *Held
// HasPiece reports whether a piece of the object of data and size is
// held at index.
HasPiece(data [32]byte, size, index uint64) bool
// Loose is how many pieces are held that no kept state names.
Loose() int
// Object is the leaves object of data and size joined from the pieces
// held, or nil while a piece is missing. The bytes are not checked.
Object(ctx context.Context, data [32]byte, size uint64) ([]byte, error)
}
View is what admission reads of what the topic holds, and nothing more: the states kept and the leaves pieces held.