mirror of
https://github.com/luxfi/utxo.git
synced 2026-10-30 15:13:57 +00:00
Adds github.com/luxfi/utxo/wire package + per-fx wire.go adapters so
that luxfi/node's vms/{platformvm,xvm}/txs/codec.go can be deleted.
wire/ package mirrors luxfi/node/vms/wire — every fxs primitive carries
a (TypeKind, ShapeKind) discriminator pair on its wire envelope, then
a ZAP message describing its fields. Decomposes the legacy
codec.Manager slot map (which braided "fx family" and "primitive shape"
into a single dense uint32 slot id) into two orthogonal 1-byte tags.
PQ-specific schemas (pq_output_owners, pq_transfer_output,
pq_mint_output) handle the mldsafx/slhdsafx case where addresses are
full PQ pubkeys (1312-2592 bytes) rather than 20-byte hashed ShortIDs.
The wire layer is stride-agnostic — the per-fx wire.go resolves
SecurityLevel → pubkey stride before parsing.
Per-fx wire.go adapters provide (value T).Bytes() []byte (Go type →
wire envelope) and Wrap*(b []byte) (*T, error) (wire envelope → Go
type). The Initialize(vm)/codec.Manager.RegisterType chain stays in
place pending downstream coordination; this commit gets the wire/
package + adapters in so consumer agents (platformvm/warp,
platformvm/state, xvm) can pin a SHA and start their migrations.
UTXO.WireBytes() builds the outer envelope by calling the polymorphic
Out's Bytes() (any fxs primitive implementing wireSerializable).
WrapUTXOBytes(b) parses the outer envelope; the inner output is
dispatched by the caller via OutputDiscriminator() → fx-package
WrapTransferOutput / WrapMintOutput / WrapAttestationOutput.
Tests: 35 round-trip tests across 9 packages. go vet clean. go test
-race clean. gofmt clean.
Activation: 2025-12-25T16:20:00-08:00 (unix 1766708400). No
backwards compat — pre-activation legacy codec blobs are a
protocol-violation reject after activation.
123 lines
3.6 KiB
Go
123 lines
3.6 KiB
Go
// Copyright (C) 2026, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package wire
|
|
|
|
import (
|
|
"github.com/luxfi/ids"
|
|
"github.com/luxfi/zap"
|
|
)
|
|
|
|
// MintOutput is the cross-fx ZAP schema for the MintOutput primitive
|
|
// (`OutputOwners`). Same shape as OutputOwners — MintOutput identifies a
|
|
// mint-authority owner group, not a value-bearing output.
|
|
//
|
|
// Fixed-section layout (size 20 bytes; identical to OutputOwners):
|
|
//
|
|
// Locktime uint64 @ 0
|
|
// Threshold uint32 @ 8
|
|
// AddressList list @ 12 (4-byte relOffset + 4-byte length, 8 bytes)
|
|
//
|
|
// Wire prefix: TypeKind names the fx; ShapeKind is ShapeKindMintOutput
|
|
// (0x03). Same payload bytes as a TransferOutput owner section — only
|
|
// the ShapeKind discriminator distinguishes "mint authority" from
|
|
// "spending output".
|
|
const (
|
|
OffsetMintOutput_Locktime = OffsetOutputOwners_Locktime // 0
|
|
OffsetMintOutput_Threshold = OffsetOutputOwners_Threshold // 8
|
|
OffsetMintOutput_AddressList = OffsetOutputOwners_AddressList // 12
|
|
SizeMintOutput = SizeOutputOwners // 20
|
|
)
|
|
|
|
// MintOutput is the zero-copy typed accessor.
|
|
type MintOutput struct {
|
|
tk TypeKind
|
|
msg *zap.Message
|
|
obj zap.Object
|
|
}
|
|
|
|
// TypeKind returns the fx family that owns this mint authority.
|
|
func (m MintOutput) TypeKind() TypeKind { return m.tk }
|
|
|
|
// Locktime returns the unix timestamp before which mint cannot fire.
|
|
func (m MintOutput) Locktime() uint64 {
|
|
return m.obj.Uint64(OffsetMintOutput_Locktime)
|
|
}
|
|
|
|
// Threshold returns the signatures-required count for mint authority.
|
|
func (m MintOutput) Threshold() uint32 {
|
|
return m.obj.Uint32(OffsetMintOutput_Threshold)
|
|
}
|
|
|
|
// AddressList returns the mint authority address list.
|
|
func (m MintOutput) AddressList() AddressList {
|
|
return AddressList{list: m.obj.ListStride(OffsetMintOutput_AddressList, AddressStride)}
|
|
}
|
|
|
|
// SyntacticVerify enforces the same gates as OutputOwners.
|
|
func (m MintOutput) SyntacticVerify() error {
|
|
addrs := m.AddressList()
|
|
n := addrs.Len()
|
|
if n == 0 {
|
|
return ErrOwnerAddrsEmpty
|
|
}
|
|
th := m.Threshold()
|
|
if th == 0 {
|
|
return ErrOwnerThresholdZero
|
|
}
|
|
if uint64(th) > uint64(n) {
|
|
return ErrOwnerThresholdExceedsAddrs
|
|
}
|
|
for i := 0; i < n; i++ {
|
|
if addrs.At(i) == (ids.ShortID{}) {
|
|
return ErrOwnerAddrZero
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// IsZero reports whether the accessor wraps a parsed message.
|
|
func (m MintOutput) IsZero() bool { return m.msg == nil }
|
|
|
|
// WrapMintOutput parses a MintOutput wire envelope.
|
|
func WrapMintOutput(b []byte) (MintOutput, error) {
|
|
tk, sk, zapBytes, err := readEnvelopePrefix(b)
|
|
if err != nil {
|
|
return MintOutput{}, err
|
|
}
|
|
if sk != ShapeKindMintOutput {
|
|
return MintOutput{}, ErrWrongShapeKind
|
|
}
|
|
if tk == TypeKindReserved {
|
|
return MintOutput{}, ErrWrongTypeKind
|
|
}
|
|
msg, err := zap.Parse(zapBytes)
|
|
if err != nil {
|
|
return MintOutput{}, err
|
|
}
|
|
return MintOutput{tk: tk, msg: msg, obj: msg.Root()}, nil
|
|
}
|
|
|
|
// MintOutputInput is the constructor input.
|
|
type MintOutputInput struct {
|
|
TypeKind TypeKind
|
|
Locktime uint64
|
|
Threshold uint32
|
|
Addresses []ids.ShortID
|
|
}
|
|
|
|
// NewMintOutput builds a MintOutput wire envelope.
|
|
func NewMintOutput(in MintOutputInput) []byte {
|
|
capEstimate := zap.HeaderSize + SizeMintOutput + len(in.Addresses)*AddressStride + 64
|
|
b := zap.NewBuilder(capEstimate)
|
|
|
|
addrListOff, addrListCount := writeAddressList(b, in.Addresses)
|
|
|
|
ob := b.StartObject(SizeMintOutput)
|
|
ob.SetUint64(OffsetMintOutput_Locktime, in.Locktime)
|
|
ob.SetUint32(OffsetMintOutput_Threshold, in.Threshold)
|
|
ob.SetList(OffsetMintOutput_AddressList, addrListOff, addrListCount)
|
|
ob.FinishAsRoot()
|
|
return writeEnvelopePrefix(in.TypeKind, ShapeKindMintOutput, b.Finish())
|
|
}
|