Documentation
¶
Overview ¶
Package secrec is the byte-level contract of bsecret: the vault record that rides a mined chain token, the secret record that rides an unmined carrier, the payload a secret's ciphertext holds, the BRC-369 keyed content around it, the wrap of a content key under a group epoch's key and to the owner's own wallet, the crypt, label and name grammars, the vault fold, and the lookup question classes. docs/spec.md is the normative text; this package generates the golden vectors under testdata/vectors.
Every record is canonical CBOR through bcommon's cbor package, so one value has one encoding a reader accepts. Every decoder bounds its input before the CBOR decoder runs, and the CBOR decoder bounds every declared length against the bytes present before it allocates.
The content key, its commitment and BRC-2's symmetric form are bcommon's keyed package, and the record reader its record package (docs/spec.md section 16.1); keyed.go holds what only bsecret uses.
Index ¶
- Constants
- Variables
- func AnyoneKey() []byte
- func CarrierStatus(row *OutpointRow, commitment [32]byte, l *Listings, rec *Secret) string
- func CheckCiphertext(s *Secret, ciphertext []byte) error
- func CheckCrypt(s string) error
- func CheckCryptName(s string) error
- func CheckGroupEpoch(epochs []EpochEvent, epoch uint64, id [32]byte) error
- func CheckHall(s string) error
- func CheckIdentity(k []byte) error
- func CheckInSet(latest *Vault, latestTxid [32]byte, rec *Secret, path *InclusionContext) error
- func CheckLabel(s string) error
- func CheckLabels(a []string) error
- func CheckListed(token *Vault, rec *Secret) error
- func CheckOrgKey(k []byte) error
- func CheckScalar(k [32]byte) error
- func CheckSecretName(s string) error
- func CheckSegment(segment uint64) error
- func CheckSuccessor(token *Vault, prev, next *Secret) error
- func CheckVaultTransition(pred *Vault, predTxid [32]byte, next *Vault) error
- func Checks(ciphertext []byte, hash [32]byte, length uint64, k, commitment [32]byte, ...) ([]byte, error)
- func CipherLength(n, segment uint64) uint64
- func Commitment(k [32]byte) [32]byte
- func CommitmentPoint(k [32]byte) []byte
- func EpochWrapKey(epochSymmetric, contentID [32]byte) [32]byte
- func FundingScript(key *ec.PublicKey) []byte
- func FundingScriptOf(d pushdrop.Derivation, owner []byte) ([]byte, error)
- func IsAnyone(k []byte) bool
- func IsFundingShape(s []byte) bool
- func IsMined(ctx context.Context, tx *transaction.Transaction, ...) bool
- func Leaf(id [32]byte, version uint64, contentID [32]byte) [32]byte
- func Locator(hash [32]byte) string
- func MinimalPath(mp *transaction.MerklePath, txid *chainhash.Hash) (*transaction.MerklePath, error)
- func NewCrypt(name string, r io.Reader) (string, error)
- func OpenSegments(k [32]byte, salt [SaltLen]byte, segment uint64, ciphertext []byte) ([]byte, error)
- func PlainLength(length, segment uint64) (uint64, error)
- func PredecessorSpend(tx, prev *transaction.Transaction) (uint32, bool)
- func PushDropScript(key *ec.PublicKey, fields [][]byte, sig []byte) []byte
- func Reason(err error) string
- func Rekeys(pred, next *Vault) bool
- func Rooted(txs []*transaction.Transaction) map[[32]byte]bool
- func SampleKey(r io.Reader) ([32]byte, error)
- func Seal(k [32]byte, salt [SaltLen]byte, segment uint64, plaintext []byte) ([]byte, error)
- func SecretID(vault [32]byte, name string) ([32]byte, error)
- func SegmentIV(salt [SaltLen]byte, i uint64) [12]byte
- func SelfInvoice(contentID [32]byte) string
- func SelfKeyID(contentID [32]byte) string
- func SetRoot(set []Current) [32]byte
- func SplitCrypt(s string) (name, suffix string, err error)
- func SymmetricKey(k [32]byte) [32]byte
- func TokenBEEF(token, parent *transaction.Transaction) ([]byte, error)
- func Topic(crypt string) string
- func UnwrapFromEpoch(epochSymmetric, contentID [32]byte, wrap []byte, commitment [32]byte) ([32]byte, error)
- func UnwrapFromSelf(ctx context.Context, w wallet.Interface, contentID [32]byte, wrap []byte, ...) ([32]byte, error)
- func VaultID(txid [32]byte, vout uint32) [32]byte
- func WrapToEpoch(epochSymmetric, contentID, k [32]byte, r io.Reader) ([]byte, error)
- func WrapToEpochWithIV(epochSymmetric, contentID, k [32]byte, iv [32]byte) ([]byte, error)
- func WrapToSelf(ctx context.Context, w wallet.Interface, contentID, k [32]byte) ([]byte, error)
- func WrapToSelfWithIV(owner *ec.PrivateKey, contentID, k [32]byte, iv [32]byte) ([]byte, error)
- type Admission
- type Carrier
- type Class
- type Commitments
- type Current
- type Entry
- type EpochEvent
- type Event
- type Finding
- type Host
- type InclusionContext
- type Kind
- type Listings
- type Mined
- type OutpointRow
- type Payload
- func DecodePayload(b []byte) (*Payload, error)
- func OpenSecret(s *Secret, ciphertext []byte, k [32]byte) (*Payload, error)
- func ReadAsMember(s *Secret, ciphertext []byte, epochSymmetric [32]byte) (*Payload, error)
- func ReadAsOwner(ctx context.Context, w wallet.Interface, s *Secret, ciphertext []byte) (*Payload, error)
- type Question
- type Report
- type Secret
- type TxKind
- type Vault
- type VaultFold
- type VaultToken
- func CheckFirstToken(tx *transaction.Transaction) (*VaultToken, transaction.Outpoint, error)
- func CheckNextToken(prev *transaction.Transaction, prevToken *VaultToken, ...) (*VaultToken, error)
- func ReadToken(tx *transaction.Transaction) (*VaultToken, error)
- func StoredToken(b []byte) (*transaction.Transaction, *VaultToken, error)
- type Window
Constants ¶
const ( StatusConsistent = "consistent" StatusPending = "pending" StatusSetMismatch = "set-mismatch" StatusStaleMismatch = "stale-mismatch" StatusCommitmentReuse = "commitment-reuse" )
Token statuses the index, a reader and an auditor report (docs/spec.md section 11.2). They are never admission verdicts: each needs the chain, which a topic manager does not read while it admits.
const ( StatusRetracted = "retracted" StatusSuperseded = "superseded" StatusMismatched = "mismatched" StatusListed = "listed" StatusUnlisted = "unlisted" )
Carrier statuses (docs/spec.md section 11.2), the first that applies.
const ( AuditEmpty = "empty" // no token AuditFirst = "first" // the trail does not start at seq 0 AuditTransition = "transition" // a token breaks section 4.2 against the one before it AuditHeight = "height" // a token is mined below the one it spends AuditStatus = "status" // a token's fold is not consistent AuditEpoch = "epoch" // a token names an epoch the group has not begun, another epoch id, or an epoch before the block that began it AuditGroup = "group" // the group's epochs are not distinct, consecutive and in height order )
Problems an audit reports (docs/spec.md section 9.2). Any of them makes the audit fail.
const ( // ProtocolName is the BRC-43 protocol name of every public derivation, // at security level 1. ProtocolName = "bsecret" // SelfProtocolName is the BRC-43 protocol name of the self wrap, at // security level 2 with counterparty self. SelfProtocolName = "bsecret self" // KeyVault locks a vault chain token and signs its fields. KeyVault = "vault" // KeySecret locks a secret carrier's record output, signs its field, and // locks the outputs of the trees that fund secrets. KeySecret = "secret" // KeyChain locks the outputs of the trees that pay for a vault's first // token; no carrier is ever funded under it. KeyChain = "chain" // KeyFund is the embedded wallet's funding key. KeyFund = "fund" // TopicPrefix and LookupService are the overlay names (BRC-87). TopicPrefix = "tm_bsecret_" LookupService = "ls_bsecret" // DomainSymmetric and DomainCommitment are BRC-369 section 2's domain // strings, adopted verbatim. DomainSymmetric = keyed.DomainSymmetric DomainCommitment = keyed.DomainCommitment // DomainVaultID, DomainSecretID and DomainEpochWrap are bsecret's own // domain strings: each is hashed into an identifier or a key. DomainVaultID = "bsecret vault id v1" DomainSecretID = "bsecret secret id v1" DomainEpochWrap = "bsecret epoch wrap v1" )
Registry values (docs/frozen.md); frozen once the first record is published to a public host.
const ( DomainVaultIDV2 = "bsecret vault id v2" DomainSecretIDV2 = "bsecret secret id v2" DomainEpochWrapV2 = "bsecret epoch wrap v2" )
const ( // MaxSafe is 2^53 - 1. MaxSafe = 1<<53 - 1 // MaxTime is 9999-12-31T23:59:59Z, the last second RFC 3339 can write. MaxTime = 253402300799 // MaxEpoch is the largest epoch: BRC-369 section 5.2 writes the epoch as // four bytes. MaxEpoch = 1<<32 - 1 // SuffixLen is the length of a crypt's random suffix. SuffixLen = 10 // MaxCrypt is the longest crypt identifier: BRC-87 caps a name at 50 // characters and the topic prefix takes 11. MaxCrypt = 50 - len(TopicPrefix) // MaxCryptName is the longest readable part of a crypt identifier. MaxCryptName = MaxCrypt - 1 - SuffixLen // MinCrypt is the shortest crypt identifier. MinCrypt = 1 + 1 + SuffixLen // MinHall and MaxHall bound the identifier of the hall the vault's // group lives in, as the group's own contract bounds it. MinHall = 12 MaxHall = 42 // GroupIDLen is the length of a group identifier. GroupIDLen = 16 // MaxName bounds a vault's display name, in bytes. MaxName = 64 // MaxSecretName bounds a secret's name, in bytes. MaxSecretName = 128 // MaxLabels bounds a vault's label set; MaxLabel one label, in bytes. MaxLabels = 16 MaxLabel = 32 // MaxDelta bounds each change list of one transition: secrets created, // updated or retired. MaxDelta = 64 // MaxSecrets bounds the secrets a vault holds at once. MaxSecrets = 4096 // MaxVaultRecord bounds an encoded vault record: 64 created and 64 // updated entries and 64 retired identifiers take about 17 KiB. MaxVaultRecord = 20480 // MaxInline bounds a ciphertext carried inside its secret record. MaxInline = 16384 // MaxSecretRecord bounds an encoded secret record: the inline bound and // room for every other key. MaxSecretRecord = MaxInline + 1024 // MaxLength bounds the ciphertext a secret record describes when it is // not carried inline: 2^27 bytes, the most a payload of MaxPayload bytes // produces at the smallest segment. MaxLength = 1 << 27 // MinSegment and MaxSegment bound the plaintext bytes of one AES-256-GCM // segment (BRC-369 section 2.3). MinSegment = 16 MaxSegment = 1 << 20 // TagLen is the length of one segment's authentication tag. TagLen = 16 // SaltLen is the length of the per-content salt (BRC-369 section 2.3). SaltLen = 4 // WrapLen is the exact length of a wrapped content key: a 32-byte // scalar under BRC-2's symmetric form (32 + 32 + 16). WrapLen = 80 // MaxKeys bounds the entries of a record map, unknown keys included. MaxKeys = 64 // MaxType bounds a payload's media type, in bytes. MaxType = 128 // MaxPayload bounds an encoded payload: a record whose length is one // that a larger plaintext produces is refused, so every admitted record // describes a ciphertext a conforming reader can open. MaxPayload = 1 << 26 )
Bounds. A reader accepts every record within them; a later version may raise a bound but never lower it (docs/frozen.md).
const ( // AnchorVersion: a reader takes only versions a mined token lists. AnchorVersion = 0 // AnchorInterval: a reader may also take a version no token lists yet, // marked unanchored. AnchorInterval = 1 )
Anchor modes of a vault (docs/spec.md section 4.4), fixed at its first token.
const ( SKMagic = 0 SKCrypt = 1 SKOrg = 2 SKVault = 3 SKID = 4 SKVersion = 5 SKPrevious = 6 SKLabel = 7 SKGroup = 8 SKEpoch = 9 SKEpochID = 10 SKCommitment = 11 SKHash = 12 SKLength = 13 SKSalt = 14 SKSegment = 15 SKCreated = 16 SKSelf = 17 SKWrap = 18 SKInline = 19 )
Secret record keys.
const ( PKMagic = 0 PKName = 1 PKValue = 2 PKType = 3 PKNotAfter = 4 PKRotateEvery = 5 PKPad = 6 )
Payload keys.
const ( VKMagic = 0 VKCrypt = 1 VKOrg = 2 VKVault = 3 VKSeq = 4 VKPrev = 5 VKName = 6 VKHall = 7 VKGroup = 8 VKEpoch = 9 VKEpochID = 10 VKLabels = 11 VKAnchor = 12 VKCreate = 13 VKUpdate = 14 VKRetire = 15 VKCount = 16 VKStale = 17 VKRoot = 18 VKCreated = 19 )
Vault record keys.
const DefaultMaxBEEF = chaintoken.DefaultMaxBEEF
DefaultMaxBEEF is the BEEF bound Admit applies when a host names none: the floor docs/spec.md section 11.1 sets for a host's own bound.
const DefaultMaxSweepInputs = 1024
DefaultMaxSweepInputs is the sweep input bound Admit applies when a host names none: the floor docs/spec.md section 11.1 sets.
const MaxContext = 2048
MaxContext bounds an encoded inclusion context.
const MaxOthers = 8
MaxOthers is how many commitments beside the winner an outpoint row keeps as evidence that the owner equivocated; the rest are counted.
const MaxPathSteps = 32
MaxPathSteps bounds an inclusion path: a set of at most MaxSecrets secrets has a path of at most 12 steps.
Variables ¶
var ( ErrShape = errors.New("secrec: transaction has the wrong shape") ErrBEEF = chaintoken.ErrBEEF ErrMineable = errors.New("secrec: carrier is mineable") ErrUnlock = errors.New("secrec: unlocking script is not one canonical signature push") ErrLock = errors.New("secrec: output script is not the canonical one for the owner") ErrFieldSig = errors.New("secrec: field signature is not strict or does not verify") ErrFunding = errors.New("secrec: carrier does not spend a funding output of the owner, or does not carry its value") ErrUnmined = errors.New("secrec: proof does not verify against the host's headers") ErrTokenInput = errors.New("secrec: token does not spend its predecessor, or its chain tree at seq 0") ErrVaultID = errors.New("secrec: vault is not the identifier of the outpoint the first token spends") ErrNotBsecret = errors.New("secrec: transaction is not for this topic") ErrHostConfig = errors.New("secrec: host configuration or previous coins out of range") )
The transaction refusals of docs/spec.md section 11.1, beside the record refusals. A transaction is refused for the first rule it breaks. A record that names another crypt than the topic's is refused with ErrCrypt, the label of a crypt that breaks the grammar.
var ( TagPrefix = []byte("se") // TagVault is the first field of a vault chain token. TagVault = []byte{'s', 'e', 0x01} // TagFunding is the one field of a funding-tree output. TagFunding = []byte{'s', 'e', 0x02} // MagicVault is key 0 of a vault record: "se", 'v', version 1. MagicVault = []byte{'s', 'e', 'v', 0x01} // MagicSecret is key 0 of a secret record: "se", 's', version 1. MagicSecret = []byte{'s', 'e', 's', 0x01} // MagicPayload is key 0 of a payload, the plaintext a secret's // ciphertext holds: "se", 'p', version 1. MagicPayload = []byte{'s', 'e', 'p', 0x01} )
Tags and magics. The tag prefix "se" belongs to bsecret.
var ( MagicVaultV2 = []byte{'s', 'e', 'v', 0x02} MagicSecretV2 = []byte{'s', 'e', 's', 0x02} MagicPayloadV2 = []byte{'s', 'e', 'p', 0x02} )
Reserved for a second record version (docs/roadmap.md): the magics and domain strings a version-2 vault, secret and payload would carry. Nothing writes them. Every version-1 decoder refuses the magics as `magic` (refusal-v1.json), and no identifier or key is derived under the domains, so a record of the next version can never be read as one of this version and the next version's identifiers can never collide with this version's.
var ( Protocol = wallet.Protocol{SecurityLevel: wallet.SecurityLevelEveryApp, Protocol: ProtocolName} VaultDerivation = pushdrop.Derivation{Protocol: Protocol, KeyID: KeyVault} SecretDerivation = pushdrop.Derivation{Protocol: Protocol, KeyID: KeySecret} ChainDerivation = pushdrop.Derivation{Protocol: Protocol, KeyID: KeyChain} FundDerivation = pushdrop.Derivation{Protocol: Protocol, KeyID: KeyFund} // SelfProtocol is the self wrap's derivation protocol. SelfProtocol = wallet.Protocol{SecurityLevel: wallet.SecurityLevelEveryAppAndCounterparty, Protocol: SelfProtocolName} )
Derivations under [1, "bsecret"], each with counterparty anyone, so a reader derives the key from the identity key alone.
var ( ErrTooLarge = record.ErrTooLarge ErrCBOR = record.ErrCBOR ErrKeyType = record.ErrKeyType ErrMagic = record.ErrMagic ErrMissing = record.ErrMissing ErrType = record.ErrType ErrRange = record.ErrRange ErrIdentity = errors.New("secrec: identity key is not a canonical compressed key") ErrCrypt = errors.New("secrec: crypt identifier breaks the grammar") ErrHall = errors.New("secrec: hall identifier breaks the grammar") ErrName = errors.New("secrec: name breaks its rule") ErrLabel = errors.New("secrec: label breaks the grammar or the label set its rule") ErrList = record.ErrList ErrEntry = errors.New("secrec: change entry is not [id, version, content id, commitment]") ErrChain = errors.New("secrec: seq, prev, version and previous disagree") ErrCount = errors.New("secrec: count disagrees with the predecessor and the change lists") ErrDebt = errors.New("secrec: stale count disagrees with the predecessor and the change lists, or a secret is created while one is stale") ErrContent = errors.New("secrec: inline ciphertext does not match its length and hash") ErrTransition = errors.New("secrec: transition breaks the chain rules") ErrEpoch = errors.New("secrec: epoch goes back, or epoch and epoch id disagree with the predecessor") ErrQuery = errors.New("secrec: question is not one of the defined classes") // A reader's check labels (docs/spec.md section 7.2), never a host's. ErrListing = errors.New("secrec: the token does not list this record as it is") ErrSuccessor = errors.New("secrec: the record is not the next version of the one before it") ErrHash = errors.New("secrec: ciphertext is not the one the record names") ErrUnwrap = keyed.ErrUnwrap ErrScalar = keyed.ErrScalar ErrCommitment = keyed.ErrCommitment ErrTag = errors.New("secrec: a segment's authentication tag does not verify under the committed key") ErrPayload = errors.New("secrec: plaintext is not a payload for this secret") )
The refusals. A host counts them by Reason.
var Classes = []Class{ {"vault", []string{"crypt", "org", "vault"}, true, 8}, {"vault-seq", []string{"crypt", "org", "seq", "vault"}, true, 8}, {"vaults", []string{"crypt", "vaultsOf"}, true, 64}, {"vaults-after", []string{"after", "crypt", "vaultsOf"}, true, 64}, {"secret", []string{"crypt", "org", "secret", "vault"}, true, 8}, {"version", []string{"crypt", "org", "secret", "vault", "version"}, true, 8}, {"pending", []string{"crypt", "org", "pending", "vault"}, true, 8}, {"secrets", []string{"crypt", "org", "secretsOf"}, true, 16}, {"secrets-after", []string{"after", "crypt", "org", "secretsOf"}, true, 16}, {"label", []string{"crypt", "label", "org", "vault"}, true, 16}, {"label-after", []string{"after", "crypt", "label", "org", "vault"}, true, 16}, {"sweep", []string{"crypt", "spent"}, true, 8}, {"history", []string{"crypt", "history", "secret", "vault"}, false, 16}, {"history-after", []string{"after", "crypt", "history", "secret", "vault"}, false, 16}, {"audit", []string{"audit", "crypt", "vault"}, false, 64}, {"audit-after", []string{"after", "audit", "crypt", "vault"}, false, 64}, }
Classes is every class this version defines. A question carries exactly the members of one of them. No priced class is a superset of a free one: the priced classes carry history or audit, which no free class carries, and lack org.
var DefaultLabels = []string{"confidential", "internal", "public", "restricted"}
DefaultLabels is the label set a vault gets unless its owner chooses another at creation.
var ErrReuse = errors.New("secrec: this commitment was published or listed before")
ErrReuse is the owner's tooling's refusal of a content key commitment it has published or listed before (docs/spec.md section 6.2).
Functions ¶
func AnyoneKey ¶
func AnyoneKey() []byte
AnyoneKey is the public key of BRC-43's "anyone" counterparty, the generator point (private key 1).
func CarrierStatus ¶
func CarrierStatus(row *OutpointRow, commitment [32]byte, l *Listings, rec *Secret) string
CarrierStatus is a carrier's status, the first that applies of retracted, superseded, mismatched, listed and unlisted: row is its funding outpoint's row and l the listings of the branch an answer uses.
func CheckCiphertext ¶
CheckCiphertext is a reader's check 1 (docs/spec.md section 7.2): the ciphertext is exactly the record's length and hashes to the record's hash. It needs no key and comes before any wrap is opened.
func CheckCrypt ¶
CheckCrypt applies the crypt identifier grammar: <name>_<suffix>, where name meets CheckCryptName and suffix is exactly SuffixLen lowercase ASCII letters. TopicPrefix + crypt is then a BRC-87 topic manager name.
func CheckCryptName ¶
CheckCryptName applies the grammar of a crypt's readable part.
func CheckGroupEpoch ¶
func CheckGroupEpoch(epochs []EpochEvent, epoch uint64, id [32]byte) error
CheckGroupEpoch is a reader's check that an epoch and epoch id a vault token or a secret record names are those of an epoch the group's canonical chain began (docs/spec.md section 14). epochs is what the reader verified of the group's chain.
func CheckHall ¶
CheckHall applies the grammar of the identifier of the hall a vault's group lives in: the same shape as a crypt's, with the hall's own bounds.
func CheckIdentity ¶
CheckIdentity refuses anything but a canonical compressed secp256k1 key (bcommon guard.ParsePubKey): 33 bytes, prefix 0x02 or 0x03, an x-coordinate below the field prime, and a point on the curve. Accepting an alias would let two byte strings name one organization.
func CheckInSet ¶
func CheckInSet(latest *Vault, latestTxid [32]byte, rec *Secret, path *InclusionContext) error
CheckInSet is a reader's first check on a secret record a host answered for a vault's latest token, whose txid is latestTxid (docs/spec.md section 7.2): the inclusion path names that token and takes the leaf of the record's identifier, version and content id to its root; the record names the token's crypt, owner, vault and group and one of its labels; and it is keyed under the token's epoch, or, only while the token counts something stale, under an earlier one. A record keyed under an epoch before the token's in a vault that says nothing is stale was listed by a token that claimed a re-keying it did not make.
func CheckLabel ¶
CheckLabel applies the label grammar: 1 to MaxLabel bytes of lowercase ASCII letters, digits and single hyphens, starting with a letter and ending with a letter or a digit.
func CheckLabels ¶
CheckLabels applies the label set rule: 1 to MaxLabels labels, each meeting CheckLabel, in strictly ascending byte order.
func CheckListed ¶
CheckListed is the check of a record against the token that listed it, which an index, an auditor and a reader that folds the chain make (docs/spec.md sections 9.3 and 11.2): the token creates or updates the record's identifier at the record's version, with the record's content id and commitment; the record names the token's crypt, owner, vault and group and one of its labels; and it is keyed under the token's epoch and epoch id. A token that lists a content id whose record is keyed under another epoch than the token's has claimed a re-keying it did not make.
func CheckOrgKey ¶
CheckOrgKey is the key rule for a vault's owner: a canonical identity key that is not the anyone key, whose private key everyone knows.
func CheckScalar ¶
CheckScalar refuses a 32-byte big-endian value outside [1, n-1].
func CheckSecretName ¶
CheckSecretName applies the grammar of a secret's name: 1 to MaxSecretName bytes of lowercase ASCII letters, digits, '.', '_', '-' and '/', with no empty path segment. One name has one spelling, so one name has one identifier.
func CheckSuccessor ¶
CheckSuccessor is a reader's check on a version no token lists yet (docs/spec.md section 4.4). token is the vault's latest token and prev the version before next. The vault's anchor mode is interval; next is the version after prev of the same secret of the token's vault, names prev's content id as its previous, has another commitment than prev's and one of the vault's labels, and is keyed under the same group at an epoch that is neither before prev's nor before the token's. The same epoch has the same epoch id, and a later epoch another.
func CheckVaultTransition ¶
CheckVaultTransition applies the rules a host checks for a vault token against the one it spends (docs/spec.md section 4.2), in their order:
- ErrTransition: crypt, org, vault, hall, group, labels and anchor equal the predecessor's, seq is the predecessor's plus 1, and prev is the txid of the predecessor's transaction;
- ErrEpoch: the epoch never goes back; the same epoch keeps its epoch id, and a later epoch has another;
- ErrDebt: with a base of the predecessor's count when the transition acknowledges a later epoch and of the predecessor's stale otherwise, stale is the base less the secrets updated and retired while the base is not zero, and zero while it is; nothing is created unless stale is zero;
- ErrCount: count is the predecessor's plus the secrets created less those retired.
Rule 3 is the property the application exists for: once a vault's chain acknowledges a new epoch, it admits nothing but the re-keying or the retirement of what it held until nothing is left under an earlier epoch.
func Checks ¶
func Checks(ciphertext []byte, hash [32]byte, length uint64, k, commitment [32]byte, salt [SaltLen]byte, segment uint64) ([]byte, error)
Checks runs BRC-369 section 5.3's three checks in their order and stops at the first failure, so that each failure names its own culprit:
- ErrHash: the ciphertext is not the one committed to (a host or a store substituted bytes);
- ErrScalar or ErrCommitment: the candidate key is not the committed one (whoever wrapped it wrapped another);
- ErrTag: the committed key does not open the committed ciphertext (the publisher encrypted under a key it did not commit to).
func CipherLength ¶
CipherLength is the ciphertext length of n plaintext bytes in segments of segment bytes: each segment is followed by its 16-byte tag.
func Commitment ¶
Commitment is BRC-369 section 2.2's digest form.
func CommitmentPoint ¶
CommitmentPoint is BRC-369 section 2.2's point form, k * G compressed. bsecret never writes it; it is here to reproduce BRC-369's own vectors.
func EpochWrapKey ¶
EpochWrapKey is the key a content key is wrapped under for the members of one epoch: SHA-256 of the domain string, the epoch's BRC-369 symmetric key and the content id of the secret version. It is derived from the epoch's symmetric key, never used as it: one wrapping key wraps one content key, and no other application's use of the epoch key meets it.
func FundingScript ¶
FundingScript is a funding output locked to key: `<key> OP_CHECKSIG <73 65 02> OP_DROP`, unsigned (docs/spec.md section 12.4).
func FundingScriptOf ¶
func FundingScriptOf(d pushdrop.Derivation, owner []byte) ([]byte, error)
FundingScriptOf is the funding output script of an owner's tree under a derivation: SecretDerivation for a tree that funds carriers, ChainDerivation for one that pays for vaults' first tokens (docs/spec.md section 12.4). The key is derived from the identity key alone, as a reader derives it.
func IsFundingShape ¶
IsFundingShape reports a funding-shaped script under any key: the whole script is 0x21, 33 bytes, 0xac, 03 73 65 02, 75 (Classify's funding).
func IsMined ¶
func IsMined(ctx context.Context, tx *transaction.Transaction, headers chaintracker.ChainTracker) bool
IsMined reports whether tx carries a proof that verifies against the headers (bcommon chaintoken.Mined).
func Leaf ¶
Leaf is the leaf datum the vault's root commits one current secret by: SHA-256 of its identifier, its version as eight bytes big-endian, and its version's content id.
func Locator ¶
Locator is where a ciphertext that is not carried inline is found: the BRC-26 content address of its SHA-256 hash, written as a uhrp:// URL (Base58Check over the prefix ce00 and the hash). The record's hash alone determines it, so a record carries no locator.
func MinimalPath ¶
func MinimalPath(mp *transaction.MerklePath, txid *chainhash.Hash) (*transaction.MerklePath, error)
MinimalPath is mp cut to the proof of txid alone (docs/spec.md section 11.1: every path is minimal): at the lowest level txid, flagged as the txid, and its sibling; above that the one sibling each level needs, computed from the leaves below when mp holds only those. A node may answer a proof that carries more of its block than one transaction needs, and a host refuses a carrier or token whose BEEF carries such a proof. The result proves the same root.
func NewCrypt ¶
NewCrypt creates a crypt identifier for name: name, an underscore, and SuffixLen letters drawn uniformly at random from a to z by r (crypto/rand.Reader when r is nil). Whoever creates the crypt calls it once; the suffix never changes.
func OpenSegments ¶
func OpenSegments(k [32]byte, salt [SaltLen]byte, segment uint64, ciphertext []byte) ([]byte, error)
OpenSegments decrypts a ciphertext Seal wrote, verifying every segment's tag before any plaintext is returned (BRC-369 section 2.3 rule 5). A tag that fails is ErrTag.
func PlainLength ¶
PlainLength reverses CipherLength. It refuses a length no plaintext of at least one byte produces: an empty ciphertext, or a last segment that is only a tag or less.
func PredecessorSpend ¶
func PredecessorSpend(tx, prev *transaction.Transaction) (uint32, bool)
PredecessorSpend finds the input of a stored token that spends the token output of prev, the transaction holding the token before it: the check a reader and the index make when they walk a chain by spends (docs/spec.md sections 11.2 and 14). It reports false when no input, or more than one, spends a token output of prev.
func PushDropScript ¶
PushDropScript is the one canonical lock-before PushDrop for key, fields and an optional field signature (bcommon pushdrop.Script): the 33-byte key, OP_CHECKSIG, each field as one minimal push, the signature as one minimal push when there is one, and the fewest OP_2DROP then OP_DROP that clear them. Every script a host checks is compared byte for byte with it (docs/spec.md section 11.1).
func Reason ¶
Reason is the fixed label a host counts a refusal by, and a reader names a failed check by.
func Rooted ¶
func Rooted(txs []*transaction.Transaction) map[[32]byte]bool
Rooted reports which of the tokens a host holds, each as it stores it, are rooted (docs/spec.md section 11.2): a first token whose input's outpoint hashes to its vault identifier, and every token that descends from a rooted one by a spend of its token output under the transition rules. The result does not depend on the order of txs, and two rooted tokens may share a seq, each the tip of its own branch. A transaction that holds no well-formed token is not rooted.
func SampleKey ¶
SampleKey draws a content key: a scalar uniform in [1, n-1], never derived from anything (BRC-369 section 2.1 rule 1).
func Seal ¶
Seal encrypts plaintext under the content key k as BRC-369 section 2.3 writes it: fixed-size segments, each under AES-256-GCM with the symmetric key of section 2.1, the IV of SegmentIV and no associated data, each followed by its own tag. The salt MUST be fresh for every content key.
func SecretID ¶
SecretID is a secret's identifier, stable across its versions: SHA-256 of the domain string, the vault identifier and the name's bytes.
func SegmentIV ¶
SegmentIV is BRC-369 section 2.3 rule 2: the 4-byte salt followed by the segment index as eight bytes big-endian.
func SelfInvoice ¶
SelfInvoice is the BRC-43 invoice number the self wrap is derived under.
func SelfKeyID ¶
SelfKeyID is the self wrap's BRC-43 key id: the standard padded base64 of the content id, so a wrap cannot be moved to another version.
func SetRoot ¶
SetRoot is the RFC 6962 root (bcommon commit) a vault record commits its current set to: one leaf datum per secret, Leaf(id, version, content id), in ascending order of the identifiers' bytes. The empty set's root is SHA-256 of nothing.
func SplitCrypt ¶
SplitCrypt returns a crypt identifier's readable part and suffix. The readable part alone never identifies a crypt.
func SymmetricKey ¶
SymmetricKey is BRC-369 section 2.1 rule 3.
func TokenBEEF ¶
func TokenBEEF(token, parent *transaction.Transaction) ([]byte, error)
TokenBEEF assembles the BEEF a vault token is admitted in (docs/spec.md sections 11.1 and 11.6): a BEEF V1 of exactly the parent then the token, each with its own minimal path, or one merged path when both are in one block (bcommon chaintoken.TokenBEEF). A replayer builds it from the token as a host stores it and its parent: the token before it, or at seq 0 the chain tree.
func UnwrapFromEpoch ¶
func UnwrapFromEpoch(epochSymmetric, contentID [32]byte, wrap []byte, commitment [32]byte) ([32]byte, error)
UnwrapFromEpoch is a member's checks 2a and 2b. A reader runs check 1 first (CheckCiphertext, or ReadAsMember, which does all of it in order). It opens the wrap with the key derived from the epoch's symmetric key, refuses a value that is not a scalar, and checks it against the commitment before anything else uses it. A holder of another epoch's key derives another wrapping key, and the wrap does not open (ErrUnwrap).
func UnwrapFromSelf ¶
func UnwrapFromSelf(ctx context.Context, w wallet.Interface, contentID [32]byte, wrap []byte, commitment [32]byte) ([32]byte, error)
UnwrapFromSelf is the owner's side: its wallet decrypts the self wrap, and the same checks follow as for a member.
func VaultID ¶
VaultID is a vault's identifier: SHA-256 of the domain string and the outpoint the vault's first token spends from its chain tree, the txid in hash byte order and the output index as four bytes big-endian. An outpoint is spent by one mined transaction, so one identifier has one first token.
func WrapToEpoch ¶
WrapToEpoch wraps the content key k under EpochWrapKey in BRC-2's symmetric form: a 32-byte IV from r (crypto/rand.Reader when r is nil), the 32-byte ciphertext and the 16-byte tag, WrapLen bytes.
func WrapToEpochWithIV ¶
WrapToEpochWithIV is WrapToEpoch with a caller's IV, for golden vectors only. Unlike keyed.WrapToEpochWithIV it wraps a k that is not a scalar, so a vector can hold the wrap a reader refuses (undecryptable); the bytes are the same for every k both accept.
func WrapToSelf ¶
WrapToSelf wraps the content key k to the owner's own wallet: a BRC-100 encrypt under [2, "bsecret self"], the key id of SelfKeyID and counterparty self, WrapLen bytes. Only BRC-42 derivation touches the identity key; k itself is random.
func WrapToSelfWithIV ¶
WrapToSelfWithIV is WrapToSelf with a caller's 32-byte IV in place of a random one, for golden vectors only: the symmetric key is the one the wallet derives, and the result decrypts through any wallet's Decrypt.
Types ¶
type Admission ¶
type Admission struct {
Kind TxKind
// Txid is the transaction's txid, hash byte order.
Txid [32]byte
// Outputs are the output indices admitted.
Outputs []int
// Retain are the input indices that spend an output the topic holds.
Retain []int
// Carrier is set for TxSecret.
Carrier *Carrier
// Token, Predecessor and Parent are set for a vault token. Predecessor
// is the token at seq - 1 read from the parent the BEEF carries; nil at
// seq 0, where the parent is the chain tree. Spends is the outpoint the
// token's predecessor input (at seq 0, its funding input) spends.
Token *VaultToken
Predecessor *VaultToken
Parent [32]byte
Spends transaction.Outpoint
// Spent is, for TxSweep, every outpoint the sweep's inputs spend.
Spent []transaction.Outpoint
}
Admission is what a host admits from one transaction: the outputs to admit and the held inputs to retain (BRC-22's admittance instructions), and what the lookup service records.
func Admit ¶
Admit applies docs/spec.md section 11.1 to one submission: the BEEF as it arrived, and held, the indices of its subject's inputs that spend an output the topic holds (BRC-22's previous coins, as the engine hands them to the topic manager). held is checked against the subject's inputs and decides only what is retained, never a verdict: the predecessor of a token is read from the parent its BEEF carries, every spend a rule reads is read from the transactions in the BEEF, and no rule reads another topic or anything this topic holds. SPV of the BEEF is the engine's and is assumed to have run, including the scripts of an unproven carrier's input.
Every refusal is an error: a topic manager raises it rather than answer with empty instructions, so the engine records nothing for the txid.
type Carrier ¶
type Carrier struct {
Secret *Secret
// Owner is the record's org, the key the carrier is bound to.
Owner []byte
// Record is the record exactly as carried.
Record []byte
// ContentID is the version's content id.
ContentID [32]byte
// Commitment is C = txid(K), hash byte order.
Commitment [32]byte
// Funding is the outpoint the carrier spends; a mined sweep of it
// retracts the carrier.
Funding transaction.Outpoint
}
Carrier is an admitted secret carrier.
type Class ¶
type Class struct {
Name string
Members []string // sorted
Free bool
Limit int // most outputs one answer holds
}
Class is one lookup question class of ls_bsecret (docs/spec.md section 10.2).
type Commitments ¶
type Commitments struct {
// contains filtered or unexported fields
}
Commitments is the owner's tooling's record of every content key commitment it has published or listed, in any of its vaults. A content key and salt used twice give anyone the XOR of the two plaintexts and forgeable tags (docs/spec.md section 6.2), and hosts and the index see a repeat only within one vault, so the tooling refuses one before it publishes anything.
func NewCommitments ¶
func NewCommitments() *Commitments
NewCommitments starts an empty record. An instance that catches up from the hosts (docs/spec.md section 8.5) calls Use for every commitment of every record and token it reads before it writes.
func (*Commitments) Seen ¶
func (c *Commitments) Seen(commitment [32]byte) bool
Seen reports whether a commitment was recorded.
func (*Commitments) Use ¶
func (c *Commitments) Use(commitment [32]byte) error
Use records a commitment, and refuses one recorded before as ErrReuse.
type Current ¶
type Current struct {
ID [32]byte
Version uint64
ContentID [32]byte
Epoch uint64 // the epoch of the token that listed this version
Seq uint64 // the seq of that token
}
Current is one secret of a vault's current set.
type Entry ¶
type Entry struct {
ID [32]byte // the secret's identifier
Version uint64 // 1 to MaxSafe
ContentID [32]byte // the content id of the version's secret record
Commitment [32]byte // the version's content key commitment
}
Entry is one change a vault token lists: a version of a secret entering the vault's current set.
type EpochEvent ¶
EpochEvent is one epoch of the vault's group as an auditor holds it, from the canonical chain of the group the vault names: the height of the block that mined the group token that began it, and whether that token removed anyone.
type Event ¶
type Event struct {
Seq uint64
Kind string // "create", "update", "rekey" or "retire"
ID [32]byte
Version uint64 // the version entering the set; for a retire, the one leaving
ContentID [32]byte // zero for a retire
Epoch uint64 // the epoch the version is keyed under; for a retire, the token's
FromEpoch uint64 // for an update or a rekey: the epoch of the version it replaces
}
Event is one line of a vault's trail: what one token did to one secret.
type Host ¶
type Host struct {
Crypt string
Headers chaintracker.ChainTracker
MaxBEEF int
MaxSweepInputs int
}
Host is what admission needs beyond the submission: the topic's crypt, a chain tracker over the host's own block headers, the host's BEEF bound (DefaultMaxBEEF when zero) and its sweep input bound (DefaultMaxSweepInputs when zero). Nothing the topic holds is here: a verdict never reads another record (docs/spec.md section 11.1).
type InclusionContext ¶
type InclusionContext struct {
Seq uint64
Token [32]byte
Index uint64
Size uint64
Path commit.Path
}
InclusionContext is the BRC-24 context a secret answer carries (docs/spec.md section 10.2): the vault token whose set was used, by its seq and its txid (hash byte order; two tokens can share a seq after a reorganization), the secret's leaf index and the set's size, and the RFC 6962 inclusion path.
func DecodeContext ¶
func DecodeContext(b []byte) (*InclusionContext, error)
DecodeContext parses a context, bounding it first.
func ProveSecret ¶
ProveSecret builds the context for the secret id within the current set of the token at seq whose txid is token.
func (*InclusionContext) Encode ¶
func (c *InclusionContext) Encode() ([]byte, error)
Encode writes the context as canonical CBOR [seq, token, index, size, path], each step [bytes(32), bool], the bool true when the sibling is on the left.
func (*InclusionContext) VerifySecret ¶
func (c *InclusionContext) VerifySecret(id [32]byte, version uint64, contentID, root [32]byte) bool
VerifySecret checks a context against the root of the vault token at its seq: the path takes the leaf of (id, version, content id) to the root. The leaf and node prefixes of RFC 6962 keep a path from passing a subtree off as a leaf, so membership needs no more; index and size are hints.
type Kind ¶
type Kind string
Kind names what an output claims to be (docs/spec.md section 11.1, Classify).
type Listings ¶
type Listings struct {
// contains filtered or unexported fields
}
Listings is what the rooted tokens of one branch of one vault list: for each identifier and version, the token that listed it. The index builds one per branch and takes a carrier's listed, mismatched or unlisted status from it (docs/spec.md section 11.2).
func (*Listings) Apply ¶
Apply records what a rooted token lists. The caller supplies a branch's tokens in seq order.
func (*Listings) Status ¶
Status is a carrier's status once its outpoint row gives none: mismatched when a rooted token lists its identifier and version with another content id or commitment, lists its content id under another epoch than the record's, or the record's label is not one of the vault's; listed when a rooted token lists its identifier, version, content id and commitment under the record's epoch; unlisted otherwise.
type Mined ¶
Mined is one vault token as an auditor holds it: its record, the txid of its transaction (hash byte order) and the height of the block its proof names, which the auditor checked against its own headers.
type OutpointRow ¶
type OutpointRow struct {
Winner [32]byte
Others [][32]byte
More uint64
Any bool
Dropped bool
Swept bool
}
OutpointRow is the index's row for one funding outpoint (docs/spec.md section 11.2): its winner, the lowest commitment of every carrier ever admitted on it, kept as a running minimum so that it does not depend on what was dropped; up to MaxOthers other commitments and a count of the rest; whether a winner of the outpoint was ever dropped, which nothing clears; and whether an admitted sweep the host holds spends the outpoint.
func (*OutpointRow) Add ¶
func (r *OutpointRow) Add(c [32]byte)
Add records a carrier admitted on the outpoint. The winner is the lowest commitment, compared as 32 bytes in hash byte order; the others kept are the lowest of the rest, so which are kept does not depend on arrival.
func (*OutpointRow) Status ¶
func (r *OutpointRow) Status(c [32]byte) string
Status is a carrier's status on its row, the first that applies: retracted, then superseded; "" when neither does, and the listing decides (Listings.Status). It depends on the admitted set and the row, never on arrival order.
type Payload ¶
type Payload struct {
Name string // key 1, the name the secret's id hashes
Value []byte // key 2, the secret itself
Type string // key 3, optional: a media type
NotAfter uint64 // key 4, optional: when the value stops being usable, Unix seconds
RotateEvery uint64 // key 5, optional: seconds between the rotations its owner intends
Pad []byte // key 6, optional: padding, ignored
Extra cbor.Map // integer keys above 6, preserved and ignored
}
Payload is the plaintext a secret's ciphertext holds: the secret's name, its value, and what its owner says about the value. Nothing in it is visible to a host.
func DecodePayload ¶
DecodePayload parses a payload. A reader calls it only on plaintext whose every segment tag verified.
func OpenSecret ¶
OpenSecret is the checks on one version for a caller that already holds a candidate content key (docs/spec.md section 7.2): BRC-369 section 5.3's three checks in their order, then the payload, whose name must hash to the record's id. A reader that starts from a wrap uses ReadAsMember or ReadAsOwner, which check the ciphertext before they open the wrap. ciphertext is the record's inline ciphertext, or the bytes fetched for a record that carries none.
func ReadAsMember ¶
ReadAsMember is a member's read of one version, the checks of docs/spec.md section 7.2 from 1 on, in their order: the ciphertext's length and hash; the wrap, opened with the symmetric key of the epoch the record names and no other; the scalar and the commitment; every segment's tag; the payload and its name. The caller made check 0 and verified the epoch's key against the group's commitment.
func ReadAsOwner ¶
func ReadAsOwner(ctx context.Context, w wallet.Interface, s *Secret, ciphertext []byte) (*Payload, error)
ReadAsOwner is the owner's read of one version through its self wrap, in the same order as ReadAsMember.
func (*Payload) EncodePadded ¶
EncodePadded writes the payload padded to a multiple of block bytes: it leaves an encoding that is already a multiple alone, and otherwise sets Pad to the fewest zero bytes that reach one, re-encoding to find it (the padding key's own head and the map's head both grow with what they hold).
type Question ¶
Question is a validated question: its class and its members.
func ParseQuery ¶
ParseQuery validates a BRC-24 query object as parsed: a JSON object whose members are all strings (a member given twice takes its last value, as JSON parsers do), whose member set is exactly one class's, and whose values meet their rules. Anything else is refused, never answered empty.
type Report ¶
Report is an audit's result.
func Audit ¶
func Audit(tokens []Mined, epochs []EpochEvent) Report
Audit checks a vault's mined tokens, in seq order, against the epochs of its group, as section 9.2 steps 3 to 6 say: the trail starts at seq 0; every token meets the transition rules against the one before it, whose txid it names, and is mined at or above it; the fold is consistent at every token; and every token's epoch and epoch id are those of an epoch the group began at or below the token's height. It verifies no proof and no script: the caller has checked every token and every epoch against its own headers and passes the heights it found. It reports one window per epoch the group began after the vault's first token's. A report that is not OK says nothing reliable about windows.
type Secret ¶
type Secret struct {
Crypt string // key 1
Org []byte // key 2, the owner, and the carrier's owner
Vault [32]byte // key 3
ID [32]byte // key 4, SecretID(vault, name)
Version uint64 // key 5, 1 for the first version
Previous [32]byte // key 6, content id of version - 1; zero at version 1
Label string // key 7, one of the vault's labels
Group [GroupIDLen]byte // key 8, the group whose epoch key wraps the content key
Epoch uint64 // key 9
EpochID [32]byte // key 10
Commitment [32]byte // key 11, BRC-369 digest of the content key
Hash [32]byte // key 12, SHA-256 of the complete ciphertext
Length uint64 // key 13, bytes of the complete ciphertext
Salt [SaltLen]byte // key 14
Segment uint64 // key 15, plaintext bytes per segment
Created uint64 // key 16, Unix seconds, a claim
Self []byte // key 17, the content key wrapped to the owner's wallet
Wrap []byte // key 18, the content key wrapped under the epoch
Inline []byte // key 19, optional: the ciphertext
Extra cbor.Map // integer keys above 19, preserved and ignored
}
Secret is one secret record: the payload of one secret carrier's output. It is one version of one secret: the BRC-369 description of its ciphertext, the content key wrapped to the owner and to the members of one epoch of the vault's group, and, when it is small, the ciphertext itself.
func CarrierRecord ¶
CarrierRecord decodes the secret record a carrier's output script holds: its first push. The owner's tooling reads its own kept carriers with it; a reader holds a carrier to every rule first (Admit).
func CheckLinks ¶
CheckLinks is a reader's check on a run of unlisted versions (docs/spec.md section 4.4): listed is the version the token's set holds, and links are the records the reader holds above it, in any order. It returns the longest run that links to listed, successor by successor, lowest version first. It fails when two different records claim one version (the owner signed both), or when a commitment repeats anywhere in listed and the run. A record that does not link ends the run and is not in it.
func DecodeSecret ¶
DecodeSecret parses a secret record in the refusal order (docs/spec.md section 3.1).
func (*Secret) ContentID ¶
ContentID is the identifier of one version: SHA-256 of the record's canonical encoding with keys 17 (self), 18 (wrap) and 19 (inline) left out and every other key, unknown ones included, kept. It takes the place of BRC-369 section 4.2 rule 3's content id: it is fixed before any key is wrapped, both wraps are bound to it, and a vault token lists it.
type Vault ¶
type Vault struct {
Crypt string // key 1
Org []byte // key 2, the owner
Vault [32]byte // key 3, VaultID of the first token's funding outpoint
Seq uint64 // key 4
Prev [32]byte // key 5, txid of the token at seq-1; zero at seq 0
Name string // key 6, display name
Hall string // key 7, the hall the group lives in
Group [GroupIDLen]byte // key 8, the group whose epochs key this vault
Epoch uint64 // key 9, the epoch every version this token lists is keyed under
EpochID [32]byte // key 10
Labels []string // key 11, fixed at the first token
Anchor uint64 // key 12, fixed at the first token
Create []Entry // key 13, secrets entering the set, ascending by id
Update []Entry // key 14, new versions of secrets in the set, ascending by id
Retire [][32]byte // key 15, secrets leaving the set, ascending
Count uint64 // key 16, secrets in the set after this transition
Stale uint64 // key 17, secrets in the set still keyed under an earlier epoch
Root [32]byte // key 18, SetRoot after this transition
Created uint64 // key 19, Unix seconds, a claim
Extra cbor.Map // integer keys above 19, preserved and ignored
}
Vault is one vault record: the second field of a vault chain token. Each token is one transition of the vault's current set, and the chain of them is the vault's audit trail.
func DecodeVault ¶
DecodeVault parses a vault record in the refusal order (docs/spec.md section 3.1).
type VaultFold ¶
type VaultFold struct {
// contains filtered or unexported fields
}
VaultFold folds a vault's chain from seq 0: the current set after each token, the last version every identifier ever had, every commitment any token listed, and the trail. Once a token breaks the fold the chain is unusable from it on, and every later token reports the same status. A token that breaks the fold changes nothing: the set, the versions, the commitments and the trail stay those of the last token before it, which is the set a host goes on answering (docs/spec.md section 11.2).
func (*VaultFold) Apply ¶
Apply folds the next token (the caller supplies them in seq order along spends) and returns its status, the first that applies:
- set-mismatch (sticky): it creates an identifier the set holds, updates or retires one it does not, lists a version that is not above the last one the identifier had, or does not reproduce count and root;
- stale-mismatch (sticky): its stale is not the number of secrets in the set keyed under an epoch before its own;
- commitment-reuse: an entry's commitment is one an earlier token of the vault listed;
- consistent.
It is atomic: a token that breaks the fold is applied to a copy that is then discarded, so nothing of it reaches the set.
func (*VaultFold) Clone ¶
Clone is a fold that goes on from here on its own: a branch, or a transition tried before it is signed.
func (*VaultFold) Set ¶
Set is the current set after the last token that did not break the fold, ascending by id.
type VaultToken ¶
type VaultToken struct {
Vault *Vault
// Record is the record exactly as carried (the token's second field).
Record []byte
// Vout is the token output's index.
Vout uint32
}
VaultToken is a vault token's output: its record, decoded.
func CheckFirstToken ¶
func CheckFirstToken(tx *transaction.Transaction) (*VaultToken, transaction.Outpoint, error)
CheckFirstToken is a reader's and the index's check on the first token of a vault's chain as a host stores it, without its parent (docs/spec.md sections 11.4 and 14): the transaction holds one well-formed vault token at seq 0, and an input's outpoint hashes to the vault identifier. An outpoint is spent by one mined transaction, so the token is the vault's one first token. It returns the token and the outpoint.
func CheckNextToken ¶
func CheckNextToken(prev *transaction.Transaction, prevToken *VaultToken, next *transaction.Transaction) (*VaultToken, error)
CheckNextToken is the same check on a later token against the one before it, each as a host stores it: next holds one well-formed vault token, exactly one of its inputs spends a token output of prev and that output is prev's token, the two are of one crypt, owner and vault at successive seqs, and the transition rules of docs/spec.md section 4.2 hold. A token that passes from seq 0 on descends from the vault's first token.
func ReadToken ¶
func ReadToken(tx *transaction.Transaction) (*VaultToken, error)
ReadToken reads the one vault token a transaction holds, well formed, without its parent: how the index and a reader read a stored token (docs/spec.md section 11.4), which the engine keeps alone with its proof.
func StoredToken ¶
func StoredToken(b []byte) (*transaction.Transaction, *VaultToken, error)
StoredToken reads a vault token as a host stores it: the token's transaction alone, with its proof (docs/spec.md section 11.4). It returns the transaction and the token output's record, decoded, without the parent. An index and a reader read a stored token this way and never admit it again.
type Window ¶
type Window struct {
Epoch uint64
Removed bool
Began uint32 // height of the group token that began the epoch
Late uint64 // vault tokens mined above Began that still name an earlier epoch
Acknowledged uint32 // height of the first vault token at this epoch or later; 0 when none
Settled uint32 // height of the first such token after which the fold holds nothing under an earlier epoch; 0 when none
Stale uint64 // secrets still under an earlier epoch at the end of the trail
}
Window is what an audit reports for one epoch the group began after the vault's first token's: when the group began it, how long the vault went on writing under an earlier one, when the vault's chain acknowledged it, when the fold shows nothing left under an earlier epoch, and what was still under one at the end of the trail.