wire

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 9 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 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

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

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

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

View Source
var ErrFrame = errors.New("beefcat: bad frame")

ErrFrame is a frame a reader does not take.

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

View Source
var Preamble = []byte("BEEFCAT\x01")

Preamble opens every stream: seven letters and the framing version.

Functions

func Classify

func Classify(payload []byte) (bool, error)

Classify takes a PushDrop field that opens with the magic as a beefcat payload.

func IsAtomic

func IsAtomic(frame []byte) bool

IsAtomic reports whether a frame opens as Atomic BEEF (BRC-95): the prefix 0x01010101 and the subject's transaction id.

func ReadFrame

func ReadFrame(r io.Reader) ([]byte, error)

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

func ReadPreamble(r io.Reader) error

ReadPreamble reads and checks a stream's opening.

func WriteFrame

func WriteFrame(w io.Writer, beef []byte) error

WriteFrame writes one carrier's BEEF as a frame: a four-byte length and the bytes.

func WritePreamble

func WritePreamble(w io.Writer) error

WritePreamble opens a stream.

Types

type Header struct {
	Last     bool
	Stream   [16]byte
	Seq      uint64
	Identity [33]byte
}

Header is a decoded payload header.

func Parse

func Parse(payload []byte) (Header, []byte, error)

Parse reads a payload's header and returns it with the data that follows. It applies the payload's own rules, in a fixed order, so a payload that breaks two is refused for the first.

func (Header) Append

func (h Header) Append(dst []byte) []byte

Append appends the header to dst.

Jump to

Keyboard shortcuts

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