token

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package token is the mined state token: PushDrop [tag, C] under the identity's profile derivation, one per transition, each spending the last.

The token is deliberately terse. It carries a three-byte tag and a 32-byte commitment and nothing else; the record it commits to rides the plane inside a carrier transaction and never reaches the chain. What the chain gives the design is ordering and double-spend protection, and 35 bytes is enough to buy that.

Everything here is frozen at the first mint: the protocol triple is hashed into every derived key (BRC-43), so changing it orphans every token ever minted. The constants are exported so the other packages cannot drift.

The derivation and the tagged PushDrop are the library's (package pushdrop of github.com/lightwebinc/bcommon); this package is finger's use of them, supplying the triple and the tags, and keeps the API finger's callers were built on.

Index

Constants

View Source
const (
	// KeyIDProfile locks the state token.
	KeyIDProfile = "profile"
	// KeyIDRecord locks the carrier's output and the funding outputs it spends.
	KeyIDRecord = "record"
)

Key identifiers under Protocol.

View Source
const Satoshis uint64 = 1

Satoshis is the value a token output carries. One is enough: the output exists to be spent by the next transition, never to hold value.

Variables

View Source
var ErrNotToken = errors.New("token: not a state token")

ErrNotToken reports a script that is not a state token.

View Source
var FundingTag = []byte{'b', 'f', 0x02}

FundingTag marks a funding-tree output: "bf" and 0x02. A funding output is PushDrop FundingTag with no signature under the record derivation, so a host can admit it by the tag and later see it spent.

View Source
var Protocol = wallet.Protocol{SecurityLevel: wallet.SecurityLevelEveryApp, Protocol: "bfinger"}

Protocol is the BRC-43 protocol every finger key derives under. Security level 1 with the name "bfinger" gives the invoice numbers "1-bfinger-profile" and "1-bfinger-record".

View Source
var Tag = []byte{'b', 'f', 0x01}

Tag is the token's leading field: "bf" and version 1.

Functions

func Anyone

func Anyone() wallet.Counterparty

Anyone is the counterparty both PushDrops are locked with; see the library's Anyone for why it, and never a zero-value Counterparty, is passed.

func ExpectedLockingKey

func ExpectedLockingKey(identity *ec.PublicKey, keyID string) (*ec.PublicKey, error)

ExpectedLockingKey is the reader's side of the derivation: from the anyone root, the identity's key under Protocol and keyID. It equals what the identity's own wallet produces with counterparty Anyone and forSelf=true.

func Lock

func Lock(ctx context.Context, w wallet.Interface, originator string, c [32]byte) (*script.Script, error)

Lock builds the token locking script for commitment c through the wallet: PushDrop [Tag, c] under Protocol/KeyIDProfile, counterparty Anyone, forSelf=true, signature included, lock before. The library copies the fields on every call, so no buffer here can carry one token's signature into the next.

Types

type Template

type Template = bcpushdrop.Template

Template spends a token or record output through the wallet; it is the library's adapter, named here so finger's callers keep their type.

func RecordUnlocker

func RecordUnlocker(ctx context.Context, w wallet.Interface, originator string) Template

RecordUnlocker is the same adapter under the record derivation, for a carrier spending its funding output.

func Unlocker

func Unlocker(ctx context.Context, w wallet.Interface, originator string) Template

Unlocker returns the template that spends a token output through the wallet, for the next transition's input.

type Token

type Token struct {
	// C is the commitment: the carrier's txid in hash byte order.
	C [32]byte
	// LockingKey is the key the output is locked to.
	LockingKey *ec.PublicKey
	// Signature is Lock's DER signature over sha256(Tag || C).
	Signature []byte
}

Token is a decoded state token.

func Decode

func Decode(s *script.Script) (*Token, error)

Decode parses a token locking script. Only the lock-before layout decodes, which is the layout Lock writes; a lock-after script from some other producer is refused rather than guessed at.

func (*Token) Signed

func (t *Token) Signed() []byte

Signed returns the bytes Lock signed: the fields concatenated.

func (*Token) VerifySignature

func (t *Token) VerifySignature() bool

VerifySignature checks the embedded signature under the locking key. The wallet signs sha256 of the concatenated fields, so that is what is verified.

Jump to

Keyboard shortcuts

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