Documentation
¶
Overview ¶
Package wire is everything beefcat freezes at its first release: the key derivation, the funding tag, the signed payload header every carrier holds, and the framing of a stream of carriers (docs/frozen.md).
A stream is a preamble followed by frames. Each frame is one carrier in Atomic BEEF (BRC-95): an unmineable transaction whose output holds a signed payload and whose one input spends a mined funding output (bcommon's carrier package). The payload is a fixed header followed by the sender's bytes. The header numbers every carrier within its stream and marks the last, and the sender signs it with the data, so order and the end of the stream are signed and a reader can refuse a stream that was reordered, spliced or cut short. No carrier depends on another's bytes, so a sender signs them, and a reader checks them, on as many cores as it has.
Index ¶
Constants ¶
const ( ProtocolName = "beefcat carrier" KeyCarrier = "1" KeyFund = "fund" )
The derivation and the funding tag. Both are hashed into or matched against every key and funding output, so they never change.
const ( Magic = "BCAT" Version = 1 FlagLast = 0x01 HeaderLen = 63 // MaxData is the most data one carrier holds. MaxData = 4 << 20 // MaxFrame bounds one frame: the data, its header and transaction, and // the largest funding tree with its proof. MaxFrame = MaxData + 64<<10 )
The payload header, 63 bytes, every integer big-endian:
offset size field 0 4 magic "BCAT" 4 1 version, 1 5 1 flags; bit 0 set on the last carrier of a stream 6 16 stream id, random per stream 22 8 sequence, from 0 30 33 the sender's identity key, compressed 63 ... data, 0 to MaxData bytes
Variables ¶
var ( // Protocol is the BRC-43 protocol every beefcat key derives under. Protocol = wallet.Protocol{SecurityLevel: wallet.SecurityLevelEveryApp, Protocol: ProtocolName} // Derivation locks carriers and funding outputs. Derivation = pushdrop.Derivation{Protocol: Protocol, KeyID: KeyCarrier} // FundingTag is the one field of a funding output. FundingTag = []byte("beefcat fund") // Profile is the embedded wallet's profile. Profile = bwallet.Profile{ FundProtocol: Protocol, FundKeyID: KeyFund, FundBasket: "beefcat fund", Version: "beefcat-1", LegacyPoolFile: "beefcat-pool.json", } )
var ( ErrPayload = errors.New("beefcat: payload is not a beefcat record") ErrVersion = errors.New("beefcat: payload version is not 1") )
The payload refusals. Their texts are what readers print.
var ErrFrame = errors.New("beefcat: bad frame")
ErrFrame is a frame a reader does not take.
var Params = carrier.Params{ Derivation: Derivation, FundingTag: FundingTag, ValidatePayload: func(p []byte) error { _, _, err := Parse(p) return err }, }
Params are the carrier parameters of every beefcat carrier.
var Preamble = []byte("BEEFCAT\x01")
Preamble opens every stream: seven letters and the framing version.
Functions ¶
func IsAtomic ¶
IsAtomic reports whether a frame opens as Atomic BEEF (BRC-95): the prefix 0x01010101 and the subject's transaction id.
func ReadFrame ¶
ReadFrame reads one frame. It answers io.EOF only at a clean frame boundary; a stream that ends inside a frame is io.ErrUnexpectedEOF, and a length out of bounds is ErrFrame, before anything is allocated for it.
func ReadPreamble ¶
ReadPreamble reads and checks a stream's opening.
func WriteFrame ¶
WriteFrame writes one carrier's BEEF as a frame: a four-byte length and the bytes.