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 ¶
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.
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 ¶
var ErrNotToken = errors.New("token: not a state token")
ErrNotToken reports a script that is not a state token.
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.
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".
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 ¶
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 ¶
RecordUnlocker is the same adapter under the record derivation, for a carrier spending its funding output.
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 ¶
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) VerifySignature ¶
VerifySignature checks the embedded signature under the locking key. The wallet signs sha256 of the concatenated fields, so that is what is verified.