zonerec

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 25 Imported by: 1 module, 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 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 carrier, signed by its writer | | Host record | "bdh" 0x01 | a carrier, 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

View Source
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
	MaxRecordBEEF  = 196608 // an attached or host record's carrier and its funding tree
	MaxFindings    = 16     // live findings one writer may have on a topic
	DefaultMaxBEEF = 262144
)

Bounds on what a host admits.

View Source
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 rides a carrier signed by its writer (section 12.7).

View Source
const (
	KindMember     = 1
	KindNameserver = 2 // a nameserver advertisement
	KindReceipt    = 3 // a render receipt
	KindObjection  = 4
	KindFinding    = 5
	KindReport     = 6
	KindOutcome    = 7
	KindChallenge  = 8 // texts for _acme-challenge.<name>
)

The assigned kinds of an attached record. A member's, a finding's and a challenge text's bodies have a form; every other kind's is opaque.

View Source
const (
	AheadMember    = 3600  // a member: one hour
	AheadFinding   = 3600  // a finding: one hour
	AheadChallenge = 600   // a challenge text: ten minutes
	AheadHost      = 86400 // a host record: one day
)

How far ahead of a host's clock a record's expiry may be (spec sections 9 and 10): a host refuses one further ahead (section 12.7).

View Source
const (
	MKHost = 1 // a member's host key, 33 bytes
	FKHost = 1 // a finding's host key, 33 bytes: the host the finding is against
	CKText = 1 // a challenge's texts

	MaxChallengeTexts = 4
	MaxChallengeText  = 255
)

The bodies of the attached kinds that have a form (docs/spec.md section 9). Each is a canonical CBOR map of exactly its keys: a different body is a different kind.

View Source
const (
	RuleGrant  = 1
	RuleAdvert = 2
)

The rules a member rule leaf names (section 4.1).

View Source
const (
	TypeA          = 1
	TypeNS         = 2
	TypeCNAME      = 5
	TypeSOA        = 6
	TypePTR        = 12
	TypeMX         = 15
	TypeTXT        = 16
	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.

View Source
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
	HKMethods   = 9 // 0 to 8 ACME validation methods (RFC 8657), distinct, ascending; none when there is no authority
	HKLast      = HKMethods

	MaxMethods = 8
	MaxMethod  = 32
)

The host record's keys (docs/spec.md section 10). It rides a carrier signed by the host's key (section 12.7), on the topic of the zone whose member names it.

View Source
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" // an attached record's carrier lock and field signature, and its funding tree
	KeyIDHost   = "host"   // a host record's carrier lock and field signature, and its funding tree
	KeyIDGuard  = "guard"  // a guard's field signature, under the chain's own protocol
)

The BRC-43 protocols, all at security level 1, and their key ids. Derivations are BRC-42 with the anyone counterparty.

View Source
const (
	TopicPrefix   = "tm_bdns_"
	LookupService = "ls_bdns"
	TopicLetterN  = 28
)

The topic prefix and the lookup service.

View Source
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
	OKGuard      = 17 // optional: the second key from this state on, as a record set's
	OKGuardSig   = 18 // optional: the previous state's guard's field signature
	OKLast       = OKGuardSig
)

The origin state's keys (docs/spec.md section 6).

View Source
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).

View Source
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.

View Source
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).

View Source
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
	RKGuard      = 13 // optional: the second key from this state on (section 5.1)
	RKGuardSig   = 14 // optional: the previous state's guard's field signature
	RKLast       = RKGuardSig
)

The record set state's keys (docs/spec.md section 5).

View Source
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
	MaxGuardSig    = 72 // a guard's strict DER signature

)

Bounds on what a record, a leaf and a leaves object carry.

View Source
const KeyIDLeaves = "leaves"

KeyIDLeaves locks a leaves piece's carrier and the trees that fund them (docs/spec.md sections 7 and 12).

View Source
const LabelBinding = "_bweb"

LabelBinding is the first label of a binding to a bweb site, _bweb.<name>.

View Source
const MaxGrantKeys = 64

MaxGrantKeys bounds the keys one grant lists.

View Source
const TypeCAA = 257

TypeCAA is the CAA record type (RFC 8659), a protected type.

View Source
const TypeMemberRule = 65534

TypeMemberRule is the leaf type of a member rule (docs/spec.md section 4.1): the last of RFC 6895's private-use types, 65,280 to 65,534. A renderer never writes a leaf of this type as a record; it decides which members a name answers.

Variables

View Source
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 place, or a record of the same writer, kind and name as late")
	ErrFull        = errors.New("zonerec: the host holds its bound of pieces that no kept state names, or of the writer's live findings")
	ErrUnsupported = errors.New("zonerec: a retired tag, or an attached record of a kind this version does not admit")
	ErrExpiry      = errors.New("zonerec: a record's expiry is further ahead of the host's clock than its kind's bound")
	ErrUnnamed     = errors.New("zonerec: no live member names what the record is about")
	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.

View Source
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. TagAttached and TagHost are retired: version 2 carries those records on carriers, claimed by their magic, and an output that claims either tag is refused (unsupported).

View Source
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.

View Source
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")
	ErrFinding   = errors.New("zonerec: not a finding body")
	ErrChallenge = errors.New("zonerec: not a challenge body")
	ErrMethods   = errors.New("zonerec: validation methods are malformed, not distinct and ascending, or have no certificate authority")
	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, not ALPN identifiers of the allowed characters, 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, or not of URI characters without \";\"")
	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.

View Source
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")
	ErrMemberRule   = errors.New("zonerec: a member rule leaf is malformed, at a wildcard, or beside fixed addresses")
)

The refusals of the checks of spec section 8: C1 ErrMismatch, C2 ErrScope, then C3 to C7 in order.

View Source
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.

Chains lists them, for a host's metrics.

EmptyRoot is the root of no leaves: SHA-256 of the empty string.

View Source
var ErrGuard = errors.New("zonerec: a protected name changed without the guard's signature")

ErrGuard is the guard check's refusal (spec section 5.1): a state that changes a protected name without the previous state's guard's signature.

Kinds lists them, for a host's metrics.

View Source
var MagicPiece = []byte("bdl\x01")

MagicPiece is a leaves piece's magic.

RecordKinds are the kinds of record a carrier brings (spec section 12.7).

Functions

func Ahead added in v0.3.0

func Ahead(kind uint64) (uint64, bool)

Ahead is how far ahead of a host's clock an attached record of kind may expire, in seconds, and false for a kind version 2 does not admit.

func ChangesProtected added in v0.3.0

func ChangesProtected(beforeGuard []byte, beforeLeaves []*Leaf, guard []byte, leaves []*Leaf) bool

ChangesProtected reports whether a state with guard and leaves changes a protected name from the state before, with beforeGuard and beforeLeaves: its protected leaves are not those of the state before, byte for byte in key order, or its guard differs.

func CheckAnswer

func CheckAnswer(leaves []*Leaf) error

CheckAnswer applies C3 to C7 to what an origin answers: the leaves are one zone, so C4 and C5 hold whatever scope a leaf was written with.

func CheckGuard added in v0.3.0

func CheckGuard(before, s *State, beforeLeaves, leaves []*Leaf, spent transaction.Outpoint) error

CheckGuard is the guard check of spec section 5.1, a pure function of two states of one chain, their leaves (each state's own, as check C1 read them) and the outpoint the later token spends. before is the guarded state before s: the latest earlier state this check did not mark, which is the state before unless that one was marked; nil at seq 0. A caller keeps it for each chain, so a thief who writes an unsigned change twice is marked twice. It returns nil, or ErrGuard when:

  • s carries a guard signature and the state before names no guard (none can be checked);
  • s carries a guard signature that is not strict low-S DER or does not verify, over GuardSigned, under derive(guard before, "guard");
  • s carries none, the state before names a guard, and s changes a protected name (ChangesProtected).

The guard that counts is the guarded state before's, never the last state a node rendered, so every node decides alike. A host admits a state that fails and marks it not renderable (label guard), as it does for checks C2 to C7.

func CheckKey

func CheckKey(b []byte) error

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

func CheckLeaves(leaves []*Leaf) error

CheckLeaves applies checks C3 to C7 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
C7 ErrMemberRule    a member rule leaf that is malformed, at a wildcard,
                    or at a name with an A, AAAA or CNAME leaf under the
                    same scope

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

func CheckOrder(leaves []*Leaf) error

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

func Commitment(originID, secret [32]byte) [32]byte

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

func EncodeLeaves(leaves []*Leaf, maxCount, maxSize int) ([]byte, error)

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

func EncodeName(n Name) ([]byte, error)

EncodeName writes a relative name as its canonical CBOR array of text labels, refusing what DecodeName refuses.

func FundingScript

func FundingScript(key *ec.PublicKey) []byte

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 GuardSign added in v0.3.0

func GuardSign(ctx context.Context, guard wallet.Interface, originator string, s *State, spent transaction.Outpoint) ([]byte, error)

GuardSign is a tool's: the guard's field signature on s, by the guard's wallet under its "guard" key of the chain's protocol, for the outpoint the token will spend. s.Record is not read; the caller sets the returned signature as the state's guard signature and encodes it again.

func GuardSigned added in v0.3.0

func GuardSigned(s *State, spent transaction.Outpoint) ([]byte, error)

GuardSigned is what a guard's field signature on s covers: Signed's bytes for the state's record written without its guard signature (key 14 of a record set, 18 of an origin), and the outpoint the token spends. The owner's signature then covers the record with it.

func LeafKey

func LeafKey(name Name, typ uint16, scope []byte) []byte

LeafKey is the key of the leaf of a name, type and scope.

func LockingKey

func LockingKey(d pushdrop.Derivation, identity []byte) (*ec.PublicKey, error)

LockingKey is the key an identity's output is locked to under d.

func MemberDerivation added in v0.3.0

func MemberDerivation(keyID string) pushdrop.Derivation

MemberDerivation is the derivation of keyID under the attached and host records' protocol, [1, "bdns member"], with counterparty anyone: KeyIDAttach for an attached record's carrier and funding tree, KeyIDHost for a host record's.

func OriginID

func OriginID(genesis []byte, txid [32]byte, vout uint32) [32]byte

OriginID is an origin's identifier, as RecordSetID under its own label.

func Pieces

func Pieces(size uint64) uint64

Pieces is how many pieces an object of size bytes is cut into.

func Protected added in v0.3.0

func Protected(l *Leaf) bool

Protected reports whether a leaf is at a protected name (docs/spec.md section 5.1): a binding (a name whose first label is _bweb, of any type), a CAA leaf, a member rule leaf, the NS leaf at the apex, or a TXT leaf at a wildcard name, which can answer for a _bweb name with no leaf of its own.

func Reason

func Reason(err error) string

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

func RecordSetID(genesis []byte, txid [32]byte, vout uint32) [32]byte

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

func Root(leaves []*Leaf) ([32]byte, error)

Root is the RFC 6962 root over leaves, which are in key order: each leaf's hash is commit.HashLeaf of its encoding.

func SameRecord added in v0.3.0

func SameRecord(a, b *Kept) bool

SameRecord reports whether two kept records are of one writer, kind and name: the place one record holds and a later one replaces.

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 SortLeaves

func SortLeaves(leaves []*Leaf)

SortLeaves puts leaves in key order.

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

func TokenScript(key *ec.PublicKey, tag, rec, sig []byte) []byte

TokenScript is a state token's output: <key> OP_CHECKSIG <tag> <record> <signature> OP_2DROP OP_DROP. The signature is over tag || record.

func Topic

func Topic(id [32]byte) string

Topic is the topic of a record set or an origin.

func TopicLetters

func TopicLetters(id [32]byte) string

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

func ValidDomain(d string) bool

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

func ValidLabel(l string) bool

ValidLabel reports a label: 1 to 63 bytes of lower-case letters, digits, hyphen and underscore, or the single byte "*".

Types

type Absence

type Absence struct {
	Before *Presence
	After  *Presence
}

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.

func (*Absence) Verify

func (a *Absence) Verify(root [32]byte, count uint64, key []byte) error

Verify holds the proof that no leaf has key in a state of count leaves under root. It trusts nothing of the prover: the neighbors are adjacent by index, or the first or the last leaf; each is under the root at its index; and key sorts strictly between their keys.

func (*Absence) VerifyName

func (a *Absence) VerifyName(root [32]byte, count uint64, name Name) error

VerifyName holds the proof that no leaf of any type or scope is at name.

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 C7 the state fails, else
	// "guard" when it fails the guard check, or "": such a state is admitted
	// and is not rendered (spec section 12.2, rules 16 and 17).
	Check string
	// For a leaves piece or a record: the piece and the funding outpoint.
	Piece   *Piece
	Funding transaction.Outpoint
	// For an attached or host record: the record. Replaces, above, is then
	// the kept record of the same writer, kind and name it replaces.
	Record *Kept
}

Admission is what a host admits from one transaction.

func Admit

func Admit(ctx context.Context, beef []byte, held []int, h Admitter) (*Admission, error)

Admit applies the rules to one submission: the BEEF as it arrived, and held, the indices of its inputs that spend an output the topic holds. held decides only what is retained (every one of them), never a verdict. SPV of the BEEF is the engine's and is assumed to have run.

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

func DecodeAttached(raw []byte) (*Attached, error)

DecodeAttached reads an attached record's payload, key by key. A member's, a finding's and a challenge text's bodies are held to their forms; every other kind's body is opaque and only bounded.

func (*Attached) Encode

func (a *Attached) Encode() ([]byte, error)

Encode writes the payload canonically, refusing what DecodeAttached refuses.

type Chain

type Chain string

Chain is which of the two chains a topic carries.

const (
	ChainRecordSet Chain = "record-set"
	ChainOrigin    Chain = "origin"
)

The chains.

func ChainOf

func ChainOf(id [32]byte, genesis []byte, txid [32]byte, vout uint32) (Chain, bool)

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.

func (Chain) Protocol

func (c Chain) Protocol() wallet.Protocol

Protocol is the chain's BRC-43 protocol.

func (Chain) Tag

func (c Chain) Tag() []byte

Tag is the chain's token tag.

type Challenge added in v0.3.0

type Challenge struct {
	Texts []string
}

Challenge is the body of an attached record of kind challenge: {1: texts}, the values its writer, an admitted member of the record's name, asks for at _acme-challenge.<name>. One to four texts, each 1 to 255 bytes of the base64url alphabet, distinct and ascending.

func DecodeChallenge added in v0.3.0

func DecodeChallenge(raw []byte) (*Challenge, error)

DecodeChallenge reads a challenge body.

func (*Challenge) Encode added in v0.3.0

func (c *Challenge) Encode() ([]byte, error)

Encode writes the body canonically, refusing what DecodeChallenge refuses.

type CheckFailure added in v0.1.1

type CheckFailure struct {
	// Number is the check, "C2" to "C7".
	Number string
	Err    error
}

CheckFailure is a refusal by one of checks C2 to C7 (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 C7, 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"
	// ClaimRetired is an output that claims the retired attached or host
	// record tag, 62 64 04 or 62 64 05: a form no writer makes.
	ClaimRetired Claim = "retired"
)

The claims.

func Classify

func Classify(s []byte) Claim

Classify says what a locking script claims, reading only its first push after <33-byte key> OP_CHECKSIG: a token's tag; the start of a leaves piece, an attached record or a host record, each a carrier's one field; a retired tag; or, for the whole 40-byte script <key> OP_CHECKSIG <tag> OP_DROP, the funding tag.

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

func DecodeData(raw []byte) (Data, error)

DecodeData reads one record's data from its canonical CBOR array.

func (Data) Check

func (d Data) Check() error

Check holds data to section 3.

func (Data) Encode

func (d Data) Encode() ([]byte, error)

Encode writes the data as its canonical CBOR array, refusing what DecodeData refuses.

func (Data) HasName

func (d Data) HasName() bool

HasName reports whether the data holds a name part.

func (Data) Join

func (d Data) Join() Data

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

func (d Data) Wire(origin []string) []byte

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

type Extension struct {
	Kind     uint64
	Critical bool
	Body     []byte
}

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 Finding added in v0.3.0

type Finding struct {
	Host []byte
}

Finding is the body of an attached record of kind finding: {1: host key}, the host behind the record's name that the writer says fails. It makes a renderer challenge that host at once and removes nothing by itself.

func DecodeFinding added in v0.3.0

func DecodeFinding(raw []byte) (*Finding, error)

DecodeFinding reads a finding body.

func (*Finding) Encode added in v0.3.0

func (f *Finding) Encode() ([]byte, error)

Encode writes the body canonically, refusing what DecodeFinding refuses.

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
	Methods   []string
	Extra     cbor.Map
}

Host is a host's claim of where it answers.

func DecodeHost

func DecodeHost(raw []byte) (*Host, error)

DecodeHost reads a host record's payload, key by key. Addresses and protocols ascend by their own bytes.

func (*Host) Encode

func (h *Host) Encode() ([]byte, error)

Encode writes the payload canonically, refusing what DecodeHost refuses.

type Kept added in v0.3.0

type Kept struct {
	Outpoint transaction.Outpoint
	// Attached is an attached record's, nil for a host record.
	Attached *Attached
	// Host is a host record's, nil for an attached record.
	Host *Host
	// Names is the host key a member or a finding names, else nil.
	Names []byte
}

Kept is an attached or host record a topic keeps (spec section 12.7): the carrier's output and the record it carries.

func ReadKept added in v0.3.0

ReadKept reads a record off a carrier's output: its one field decoded as an attached or a host record by the claim it makes. It checks the record's own rules and nothing of the carrier.

func (*Kept) Expiry added in v0.3.0

func (k *Kept) Expiry() uint64

Expiry is the time after which the record is not believed.

func (*Kept) Kind added in v0.3.0

func (k *Kept) Kind() Kind

Kind is the record's kind; "" for an attached kind version 2 does not admit.

func (*Kept) Live added in v0.3.0

func (k *Kept) Live(now int64) bool

Live reports whether the record is believed at the Unix time now: now is at or before its expiry.

func (*Kept) Name added in v0.3.0

func (k *Kept) Name() Name

Name is what an attached record is about; nil for a host record.

func (*Kept) Writer added in v0.3.0

func (k *Kept) Writer() []byte

Writer is who signs the record: an attached record's writer, a host record's host.

type Kind

type Kind string

Kind is what an admitted transaction is to the topic.

const (
	KindRecordSet Kind = "record-set"
	KindOrigin    Kind = "origin"
	KindLeaves    Kind = "leaves"
	// The records of spec section 12.7, each on a carrier.
	KindMemberRecord    Kind = "member"
	KindFindingRecord   Kind = "finding"
	KindChallengeRecord Kind = "challenge"
	KindHostRecord      Kind = "host"
)

The kinds.

func RecordKind added in v0.3.0

func RecordKind(kind uint64) (Kind, bool)

RecordKind is the kind of record an attached record of kind is, and false for a kind version 2 does not admit.

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

func Answer(recordSet, own []*Leaf, originID [32]byte) ([]*Leaf, error)

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 C7 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

func DecodeLeaf(raw []byte) (*Leaf, error)

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

func DecodeLeaves(raw []byte, maxCount, maxSize int) ([]*Leaf, error)

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 LeavesOf added in v0.3.0

func LeavesOf(ctx context.Context, v View, s *State) ([]*Leaf, error)

LeavesOf reads a kept state's leaves back through the view: its object, held to the state by check C1. A failure of C2 to C7 is not an error here.

func (*Leaf) Encode

func (l *Leaf) Encode() ([]byte, error)

Encode writes the leaf canonically. It refuses what DecodeLeaf refuses, so a leaf this package writes is one it reads.

func (*Leaf) Key

func (l *Leaf) Key() []byte

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.

func (*Leaf) SortData

func (l *Leaf) SortData() error

SortData puts a leaf's records in the order a leaf carries them and drops repeats. It returns the first refusal of a record's data.

type Member

type Member struct {
	Host []byte
}

Member is the body of an attached record of kind member: {1: host key}. The rule a member is held to is the zone's member rule leaf, not the member's.

func DecodeMember

func DecodeMember(raw []byte) (*Member, error)

DecodeMember reads a member body.

func (*Member) Encode

func (m *Member) Encode() ([]byte, error)

Encode writes the body canonically, refusing what DecodeMember refuses.

type MemberRule added in v0.3.0

type MemberRule struct {
	Rule uint64
	Keys [][]byte
}

MemberRule is the rule a name's members are held to: grant, with the keys whose members it admits, or advert, with none.

func DecodeMemberRule added in v0.3.0

func DecodeMemberRule(l *Leaf) (*MemberRule, error)

DecodeMemberRule reads a member rule leaf, refusing (ErrMemberRule) one that is not of the type, is at a wildcard name, has a TTL other than 0, is not one record of one byte part, names no rule, or whose keys are not 1 to 64 canonical keys, distinct and ascending, for a grant, or are any for an advert.

func (*MemberRule) Grants added in v0.3.0

func (r *MemberRule) Grants(key []byte) bool

Grants reports whether the rule admits a member written by key.

func (*MemberRule) Leaf added in v0.3.0

func (r *MemberRule) Leaf(name Name, scope []byte) (*Leaf, error)

Leaf is the member rule as a leaf at name with scope: TTL 0, one record whose data is one byte part, the rule's byte then, for a grant, the keys.

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

func DecodeName(raw []byte) (Name, error)

DecodeName reads a relative name from its canonical CBOR array.

func (Name) Check

func (n Name) Check() error

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

func (n Name) CheckAbsolute() error

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) Equal

func (n Name) Equal(o Name) bool

Equal reports the same labels in the same order.

func (Name) KeyPrefix

func (n Name) KeyPrefix() []byte

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.

func (Name) String

func (n Name) String() string

String is the name in dotted form, "@" for no labels.

func (Name) WireLen

func (n Name) WireLen() int

WireLen is the name's length on the wire without a root byte: each label and its length 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
	// Guard and GuardSig are keys 17 and 18, nil when absent.
	Guard    []byte
	GuardSig []byte
	// 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

func DecodeOrigin(raw []byte) (*Origin, error)

DecodeOrigin reads an origin state, key by key, then the rules that join keys, as DecodeRecordSet.

func (*Origin) AnswersWith

func (o *Origin) AnswersWith(s *RecordSet) bool

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) Check

func (o *Origin) Check(object []byte) ([]*Leaf, error)

Check applies checks C1 to C7 to an origin state and its own leaves object.

func (*Origin) Commit

func (o *Origin) Commit(leaves []*Leaf) ([]byte, error)

Commit is RecordSet.Commit for an origin state and its own leaves, none of which has a scope.

func (*Origin) Commitment

func (o *Origin) Commitment() [32]byte

Commitment is the value a record set lists to answer for this origin.

func (*Origin) Encode

func (o *Origin) Encode() ([]byte, error)

Encode writes the record canonically, refusing what DecodeOrigin refuses.

func (*Origin) Precedes

func (o *Origin) Precedes(next *Origin) bool

Precedes reports whether next may follow o in one origin's chain: the same identifier, genesis key, outpoint and recovery, one more seq, and a greater serial.

func (*Origin) UnknownCritical

func (o *Origin) UnknownCritical(known func(kind uint64) bool) (uint64, bool)

UnknownCritical is RecordSet.UnknownCritical for an origin state.

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.

func Abs

func Abs(labels ...string) Part

Abs is an absolute name part.

func Raw

func Raw(b []byte) Part

Raw is a byte part.

func Rel

func Rel(labels ...string) Part

Rel is a name part relative to the origin.

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 Cut

func Cut(s *State, writer, object []byte) []*Piece

Cut cuts a leaves object into its pieces for a chain and a writer.

func DecodePiece

func DecodePiece(raw []byte) (*Piece, error)

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).

func (*Piece) Encode

func (p *Piece) Encode() ([]byte, error)

Encode writes the piece canonically, refusing what DecodePiece refuses.

type Presence

type Presence struct {
	Leaf  *Leaf
	Index uint64
	Path  [][32]byte
}

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.

func (*Presence) Verify

func (p *Presence) Verify(root [32]byte, count uint64) error

Verify recomputes the root from the leaf and its path and holds it to root, in a state of count leaves.

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

func DecodeProof(raw []byte) (*Proof, error)

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

func (p *Proof) Encode() ([]byte, error)

Encode writes the proof as its canonical CBOR array [form, name, type, scope, present, before, after], refusing what DecodeProof refuses.

func (*Proof) Verify

func (p *Proof) Verify(root [32]byte, count uint64) error

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
	// Guard and GuardSig are keys 13 and 14, nil when absent: a version 1
	// state has neither.
	Guard    []byte
	GuardSig []byte
	// 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

func DecodeRecordSet(raw []byte) (*RecordSet, error)

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

func (s *RecordSet) Check(object []byte) ([]*Leaf, error)

Check applies checks C1 and C3 to C7 of spec section 8 to the state and its leaves object, and returns the leaves or the first refusal. A refusal by C2 to C7 is a CheckFailure, returned with the leaves.

func (*RecordSet) Commit

func (s *RecordSet) Commit(leaves []*Leaf) ([]byte, error)

Commit sets the state's root, count, data and size from leaves and returns the leaves object it then commits to.

func (*RecordSet) Encode

func (s *RecordSet) Encode() ([]byte, error)

Encode writes the record canonically. It refuses what DecodeRecordSet refuses, so a record this package writes is one it reads.

func (*RecordSet) Lists

func (s *RecordSet) Lists(c [32]byte) bool

Lists reports whether the state lists commitment c.

func (*RecordSet) Precedes

func (s *RecordSet) Precedes(next *RecordSet) bool

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

func (s *RecordSet) UnknownCritical(known func(kind uint64) bool) (uint64, bool)

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

func DecodeState(c Chain, rec []byte) (*State, error)

DecodeState reads rec as a state of chain c.

func NewState

func NewState(set *RecordSet, origin *Origin) (*State, error)

NewState wraps a record set state or an origin state, encoded.

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

func (s *State) Check(object []byte) ([]*Leaf, error)

Check applies checks C1 to C7 to the state and its leaves object. A refusal by C2 to C7 is a CheckFailure, returned with the leaves.

func (*State) Count

func (s *State) Count() uint64

Count is the number of leaves.

func (*State) Data

func (s *State) Data() [32]byte

Data and Size commit to the leaves object's bytes.

func (*State) Follows

func (s *State) Follows(prev *State) error

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).

func (*State) Genesis

func (s *State) Genesis() []byte

Genesis is the owner at seq 0.

func (*State) Guard added in v0.3.0

func (s *State) Guard() []byte

Guard is the state's guard key, nil when it names none.

func (*State) GuardSig added in v0.3.0

func (s *State) GuardSig() []byte

GuardSig is the guard signature the state carries, nil when none.

func (*State) ID

func (s *State) ID() [32]byte

ID is the chain's identifier.

func (*State) Lapse

func (s *State) Lapse() uint64

Lapse is when an unmined token of this state stops being believed.

func (*State) Owner

func (s *State) Owner() []byte

Owner is who owns the chain from this state.

func (*State) Root

func (s *State) Root() [32]byte

Root and Count commit to the state's leaves.

func (*State) Seq

func (s *State) Seq() uint64

Seq is the state's place in the chain.

func (*State) Signer

func (s *State) Signer(prev *State) []byte

Signer is the key that signs a token of this state: its owner, or at a change of owner the previous state's. prev is nil at seq 0.

func (*State) Size

func (s *State) Size() uint64

Size is the leaves object's length.

func (*State) UnknownCritical

func (s *State) UnknownCritical(known func(kind uint64) bool) (uint64, bool)

UnknownCritical reports the first critical extension of a kind known does not report.

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

func NewTree(leaves []*Leaf) (*Tree, error)

NewTree hashes leaves, which are in key order with no key twice. It refuses a leaf DecodeLeaf refuses.

func (*Tree) Count

func (t *Tree) Count() uint64

Count is the number of leaves.

func (*Tree) Find

func (t *Tree) Find(key []byte) (int, bool)

Find is the index of the leaf with key, and whether there is one.

func (*Tree) Prove

func (t *Tree) Prove(index int) (*Presence, error)

Prove proves the leaf at index.

func (*Tree) ProveAbsent

func (t *Tree) ProveAbsent(key []byte) (*Absence, error)

ProveAbsent proves that no leaf has key, or returns ErrPresent.

func (*Tree) ProveAbsentName

func (t *Tree) ProveAbsentName(name Name) (*Absence, error)

ProveAbsentName proves that no leaf of any type or scope is at name, or returns ErrPresent.

func (*Tree) ProveKey

func (t *Tree) ProveKey(name Name, typ uint16, scope []byte) (*Proof, error)

ProveKey proves the leaf of a name, a type and a scope, or that there is none.

func (*Tree) ProveName

func (t *Tree) ProveName(name Name) (*Proof, error)

ProveName proves every leaf at a name, or that there is none. A name of more than MaxProofLeaves leaves is refused (too-large): its leaves are asked for one key at a time.

func (*Tree) Root

func (t *Tree) Root() [32]byte

Root is the RFC 6962 root over the leaves.

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)
	// GuardedBefore is the guarded state before a state at seq (spec section
	// 5.1): the latest kept state below seq that neither checks C2 to C7 nor
	// the guard check marked and that has no unknown critical extension, or
	// nil. A view may answer any kept state below seq when none of them names
	// a guard: the guard check then decides alike whichever it reads.
	GuardedBefore(ctx context.Context, seq uint64) (*Held, error)
	// Record is the record the topic keeps of kind, writer and name (for a
	// host record, of the host key writer; name is not read), or nil. It may
	// be one past its expiry that the view has not dropped yet.
	Record(kind Kind, writer []byte, name Name) *Kept
	// MembersOf are the members the topic keeps that name host, expired ones
	// perhaps among them.
	MembersOf(host []byte) []*Kept
	// Findings are the findings the topic keeps of writer, expired ones
	// perhaps among them.
	Findings(writer []byte) []*Kept
}

View is what admission reads of what the topic holds, and nothing more: the states kept and the leaves pieces held.

Jump to

Keyboard shortcuts

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