Files
zeekay 7cf87b230b node-unified is the node
The module already called itself github.com/luxfi/node while containing no node
in Go: cmd/luxd was twenty-one lines that printed the size of a few types, and
the Go column of the matrix measured a VM plugin. A repo that fetches the thing
it claims to be has not replaced it, so the Go sources move in — 1515 files,
the daemon and everything under it — and the build reaches outside this module
for nothing.

Rust and C++ sit beside it unchanged and are still measured against it by the
differential. That is the point of one repo: the reference implementation and
the two ports are the same checkout, so parity is a thing you can run rather
than a thing you assert.

Verified: builds, and the closure carries no lux-private — checked at build time
rather than believed. The daemon starts twelve chains on a local network
(P X C Q Z A B G K M F, plus D through its plugin) and reports healthy.
2026-09-07 16:15:25 -07:00

57 lines
1.5 KiB
Go

// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package cb58
import (
"bytes"
"errors"
"fmt"
"math"
"github.com/mr-tron/base58/base58"
"github.com/luxfi/crypto/hash"
)
const checksumLen = 4
var (
ErrBase58Decoding = errors.New("base58 decoding error")
ErrMissingChecksum = errors.New("input string is smaller than the checksum size")
ErrBadChecksum = errors.New("invalid input checksum")
errEncodingOverFlow = errors.New("encoding overflow")
)
// Encode [bytes] to a string using cb58 format.
// [bytes] may be nil, in which case it will be treated the same as an empty
// slice.
func Encode(bytes []byte) (string, error) {
bytesLen := len(bytes)
if bytesLen > math.MaxInt32-checksumLen {
return "", errEncodingOverFlow
}
checked := make([]byte, bytesLen+checksumLen)
copy(checked, bytes)
copy(checked[len(bytes):], hash.Checksum(bytes, checksumLen))
return base58.Encode(checked), nil
}
// Decode [str] to bytes from cb58.
func Decode(str string) ([]byte, error) {
decodedBytes, err := base58.Decode(str)
if err != nil {
return nil, fmt.Errorf("%w: %w", ErrBase58Decoding, err)
}
if len(decodedBytes) < checksumLen {
return nil, ErrMissingChecksum
}
// Verify the checksum
rawBytes := decodedBytes[:len(decodedBytes)-checksumLen]
checksum := decodedBytes[len(decodedBytes)-checksumLen:]
if !bytes.Equal(checksum, hash.Checksum(rawBytes, checksumLen)) {
return nil, ErrBadChecksum
}
return rawBytes, nil
}