Files
zeekay 45df2649d9 feat: ZAP-native wire schemas — activation 2025-12-25T16:20:00-08: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.
2026-06-03 09:34:23 -07:00

72 lines
1.7 KiB
Go

// Copyright (C) 2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package bls12381fx
import (
"bytes"
"testing"
)
func TestWire_AttestationOutput_RoundTrip(t *testing.T) {
pk1 := make([]byte, PubKeyLen)
pk2 := make([]byte, PubKeyLen)
for i := range pk1 {
pk1[i] = byte(i)
}
for i := range pk2 {
pk2[i] = byte(0xFF - i)
}
in := &AttestationOutput{
AttestedHash: [AttestedHashLen]byte{1, 2, 3, 4, 5},
Threshold: 2,
PubKeys: [][]byte{pk1, pk2},
}
got, err := WrapAttestationOutput(in.Bytes())
if err != nil {
t.Fatalf("WrapAttestationOutput: %v", err)
}
if got.AttestedHash != in.AttestedHash {
t.Errorf("AttestedHash mismatch")
}
if got.Threshold != in.Threshold {
t.Errorf("Threshold: got %d, want %d", got.Threshold, in.Threshold)
}
if len(got.PubKeys) != 2 {
t.Fatalf("PubKeys.Len: got %d, want 2", len(got.PubKeys))
}
if !bytes.Equal(got.PubKeys[0], pk1) {
t.Errorf("PubKeys[0] mismatch")
}
if !bytes.Equal(got.PubKeys[1], pk2) {
t.Errorf("PubKeys[1] mismatch")
}
}
func TestWire_AttestationInput_RoundTrip(t *testing.T) {
bitmap := []byte{0x05, 0x80}
in := &AttestationInput{Signers: bitmap}
got, err := WrapAttestationInput(in.Bytes())
if err != nil {
t.Fatalf("WrapAttestationInput: %v", err)
}
if !bytes.Equal(got.Signers, bitmap) {
t.Errorf("Signers: got %x, want %x", got.Signers, bitmap)
}
}
func TestWire_Credential_RoundTrip(t *testing.T) {
var aggSig [SigLen]byte
for i := range aggSig {
aggSig[i] = byte(i)
}
in := &Credential{AggSig: aggSig}
got, err := WrapCredential(in.Bytes())
if err != nil {
t.Fatalf("WrapCredential: %v", err)
}
if !bytes.Equal(got.AggSig[:], aggSig[:]) {
t.Errorf("AggSig mismatch")
}
}