Documentation
¶
Index ¶
- Constants
- Variables
- func EqualSubset(start, stop int, id1, id2 ID) bool
- func FirstDifferenceSubset(start, stop int, id1, id2 ID) (int, bool)
- func GetRelevantAliases(aliaser Aliaser, ids []ID) (map[ID][]string, error)
- func IsNativeChain(id ID) bool
- func IsSorted[T Sortable[T]](s []T) bool
- func IsSortedAndUnique[T Sortable[T]](s []T) bool
- func IsSortedAndUniqueBytes[T ~[]byte](s []T) bool
- func IsSortedAndUniqueOrdered[T cmp.Ordered](s []T) bool
- func IsSortedBytes[T ~[]byte](s []T) bool
- func NativeChainAlias(id ID) string
- func NativeChainString(id ID) string
- func ShortIDsToStrings(ids []ShortID) []string
- func Sort[T Sortable[T]](s []T)
- func TypedNodeIDFromMLDSA(scheme NodeIDScheme, chainID ID, pubKey []byte) (TypedNodeID, FullDigest, error)
- type Aliaser
- type AliaserReader
- type AliaserWriter
- type Certificate
- type FullDigest
- type ID
- func AllNativeChainIDs() []ID
- func Checksum256(data []byte) ID
- func FromString(idStr string) (ID, error)
- func FromStringOrPanic(idStr string) ID
- func FromStringWithForce(idStr string, forceIgnoreChecksum bool) (ID, error)
- func GenerateNodeIDFromBytes(bytes []byte) ID
- func GenerateTestID() ID
- func NativeChainFromString(s string) (ID, bool)
- func NativeChainIDFromLetter(letter byte) (ID, bool)
- func ToID(bytes []byte) (ID, error)
- func (id ID) Append(suffixes ...uint32) ID
- func (id ID) Bit(i uint) int
- func (id ID) Compare(other ID) int
- func (id ID) Hex() string
- func (id ID) IsZero() bool
- func (id ID) MarshalJSON() ([]byte, error)
- func (id ID) MarshalText() ([]byte, error)
- func (id ID) Prefix(prefixes ...uint64) ID
- func (id ID) String() string
- func (id ID) ToShortID() ShortID
- func (id *ID) UnmarshalJSON(b []byte) error
- func (id *ID) UnmarshalText(text []byte) error
- func (id ID) XOR(other ID) ID
- type NodeID
- func (id NodeID) Bytes() []byte
- func (id NodeID) Compare(other NodeID) int
- func (id NodeID) MarshalJSON() ([]byte, error)
- func (id NodeID) MarshalText() ([]byte, error)
- func (id NodeID) String() string
- func (id *NodeID) UnmarshalJSON(b []byte) error
- func (id *NodeID) UnmarshalText(text []byte) error
- type NodeIDScheme
- type RequestID
- type ShortID
- func (id ShortID) Bytes() []byte
- func (id ShortID) Compare(other ShortID) int
- func (id ShortID) Hex() string
- func (id ShortID) MarshalJSON() ([]byte, error)
- func (id ShortID) MarshalText() ([]byte, error)
- func (id ShortID) PrefixedString(prefix string) string
- func (id ShortID) String() string
- func (id *ShortID) UnmarshalJSON(b []byte) error
- func (id *ShortID) UnmarshalText(text []byte) error
- type Sortable
- type TypedNodeID
Constants ¶
const ( // Precomputed full strings for each chain PChainIDStr = nativeChainPrefix + "P" CChainIDStr = nativeChainPrefix + "C" XChainIDStr = nativeChainPrefix + "X" QChainIDStr = nativeChainPrefix + "Q" AChainIDStr = nativeChainPrefix + "A" BChainIDStr = nativeChainPrefix + "B" TChainIDStr = nativeChainPrefix + "T" ZChainIDStr = nativeChainPrefix + "Z" GChainIDStr = nativeChainPrefix + "G" // Coming soon IChainIDStr = nativeChainPrefix + "I" // Identity - Coming soon KChainIDStr = nativeChainPrefix + "K" // Coming soon DChainIDStr = nativeChainPrefix + "D" )
Native chain constants - precomputed for maximum speed
const ( NodeIDPrefix = "NodeID-" NodeIDLen = ShortIDLen )
const BitsPerByte = 8
BitsPerByte is the number of bits per byte
const FullDigestLen = 48
FullDigestLen is the byte length of the canonical NodeID full digest (SHAKE256-384). The 20-byte NodeID is the prefix of this digest; the full digest is what handshake transcripts and validator-set commitments bind.
const (
IDLen = 32
)
const NodeIDMLDSADomainPrefix = "LuxNodeID/v1"
NodeIDPrefix for the legacy ML-DSA NodeID derivation. Retained for backwards compatibility with chains that registered validators under the pre-v1 derivation; new strict-PQ chains use the canonical SHAKE256-384 derivation in node_id_scheme.go (NodeIDScheme.DeriveMLDSA), which domain-separates by chain id AND scheme byte and produces a 48-byte commitment whose 20-byte prefix is the NodeID.
const NumBits = 256
NumBits is the number of bits this patricia tree manages
const ShortIDLen = 20
const TypedNodeIDLen = 1 + NodeIDLen
TypedNodeIDLen is the byte length of a TypedNodeID on the wire: one scheme byte + 20-byte NodeID.
Variables ¶
var ( // ErrNodeIDSchemeInvalid — caller named NodeIDSchemeInvalid or // supplied a scheme outside the expected family (e.g. classical // scheme on an ML-DSA derivation call). ErrNodeIDSchemeInvalid = errors.New("ids: NodeIDScheme is invalid") // ErrNodeIDSchemeUnknown — wire byte does not name a scheme this // build understands. ErrNodeIDSchemeUnknown = errors.New("ids: NodeIDScheme is unknown") // ErrTypedNodeIDLen — wire input was not exactly TypedNodeIDLen bytes. ErrTypedNodeIDLen = errors.New("ids: TypedNodeID wire length mismatch") // ErrNodeIDSchemeMismatch — a TypedNodeID's scheme byte does not // match the scheme the consensus profile pins. This is the cross-axis // gate that catches a primitive-mismatch downgrade attempt at the // chain boundary. ErrNodeIDSchemeMismatch = errors.New("ids: NodeIDScheme does not match profile") )
Typed validation errors. Wrapped so consumers can match with errors.Is.
var ( // Empty is a useful all zero value Empty = ID{} )
var (
EmptyNodeID = NodeID{}
)
var (
ErrNoIDWithAlias = errors.New("there is no ID with alias")
)
var (
ShortEmpty = ShortID{}
)
ShortEmpty is a useful all zero value
Functions ¶
func EqualSubset ¶
EqualSubset takes in two indices and two ids and returns if the ids are equal from bit start to bit end (non-inclusive). Bit indices are defined as: [7 6 5 4 3 2 1 0] [15 14 13 12 11 10 9 8] ... [255 254 253 252 251 250 249 248] Where index 7 is the MSB of byte 0.
func FirstDifferenceSubset ¶
FirstDifferenceSubset takes in two indices and two ids and returns the index of the first difference between the ids inside bit start to bit end (non-inclusive). Bit indices are defined above
func GetRelevantAliases ¶
GetRelevantAliases returns the aliases with the redundant identity alias removed (each id is aliased to at least itself).
func IsNativeChain ¶ added in v1.2.0
IsNativeChain returns true if the ID is a well-known native chain ID. This is the fastest possible check - just verify all zeros except valid last byte.
func IsSortedAndUnique ¶ added in v1.2.10
IsSortedAndUnique returns true iff the elements in [s] are sorted and unique.
func IsSortedAndUniqueBytes ¶ added in v1.2.10
IsSortedAndUniqueBytes returns true iff the byte slices in [s] are sorted and unique.
func IsSortedAndUniqueOrdered ¶ added in v1.2.10
IsSortedAndUniqueOrdered returns true iff the elements in [s] are sorted and unique. Uses cmp.Ordered constraint for built-in comparable types.
func IsSortedBytes ¶ added in v1.2.10
IsSortedBytes returns true iff the byte slices in [s] are sorted.
func NativeChainAlias ¶ added in v1.2.0
NativeChainAlias returns the single-letter alias for a native chain (P, C, X, Q, A, B, T, Z, G, K, D). Returns empty string if not a native chain.
func NativeChainString ¶ added in v1.2.0
NativeChainString returns the human-friendly string for a native chain ID. Returns empty string if not a native chain. This is the fast-path for String().
func ShortIDsToStrings ¶
ShortIDsToStrings converts an array of shortIDs to an array of their string representations
func Sort ¶ added in v1.2.10
func Sort[T Sortable[T]](s []T)
Sort sorts a slice of Sortable elements using their Compare method.
func TypedNodeIDFromMLDSA ¶ added in v1.2.10
func TypedNodeIDFromMLDSA( scheme NodeIDScheme, chainID ID, pubKey []byte, ) (TypedNodeID, FullDigest, error)
TypedNodeIDFromMLDSA produces a strict-PQ TypedNodeID from an ML-DSA public key under the supplied chain id. scheme MUST be NodeIDSchemeMLDSA65 or NodeIDSchemeMLDSA87; any other byte is rejected.
The returned FullDigest is the 48-byte commitment; callers that bind validator identity into a transcript MUST use FullDigest, not the 20-byte NodeID alone.
Types ¶
type Aliaser ¶
type Aliaser interface {
AliaserReader
AliaserWriter
// PrimaryAliasOrDefault returns the first alias of [id], or ID string as a
// default if no alias exists
PrimaryAliasOrDefault(id ID) string
}
Aliaser allows one to give an ID aliases and lookup the aliases given to an ID.
func NewAliaser ¶
func NewAliaser() Aliaser
type AliaserReader ¶
type AliaserReader interface {
// Lookup returns the ID associated with alias
Lookup(alias string) (ID, error)
// PrimaryAlias returns the first alias of [id]
PrimaryAlias(id ID) (string, error)
// Aliases returns the aliases of an ID
Aliases(id ID) ([]string, error)
}
AliaserReader allows one to lookup the aliases given to an ID.
type AliaserWriter ¶
type AliaserWriter interface {
// Alias gives [id] the alias [alias]
Alias(id ID, alias string) error
// RemoveAliases of the provided ID
RemoveAliases(id ID)
}
AliaserWriter allows one to give an ID aliases. An ID can have arbitrarily many aliases; two IDs may not have the same alias.
type Certificate ¶
type Certificate struct {
// Raw contains the complete ASN.1 DER content of the certificate
Raw []byte
// PublicKey contains the public key from the certificate
PublicKey crypto.PublicKey
}
Certificate represents a TLS certificate
type FullDigest ¶ added in v1.2.10
type FullDigest [FullDigestLen]byte
FullDigest is the 48-byte commitment to a validator's identity. The 20-byte NodeID is FullDigest[:20]; the full digest is preserved for callers that need the post-quantum-strength commitment (handshake transcripts, genesis validator-set roots).
type ID ¶
ID wraps a 32 byte hash used as an identifier
var ( // PChainID is the well-known P-Chain (Platform) ID PChainID ID // CChainID is the well-known C-Chain (Contract/EVM) ID CChainID ID // XChainID is the well-known X-Chain (Exchange/DAG) ID XChainID ID // QChainID is the well-known Q-Chain (Quantum) ID QChainID ID // AChainID is the well-known A-Chain (AI) ID AChainID ID // BChainID is the well-known B-Chain (Bridge) ID BChainID ID // TChainID is the well-known T-Chain (Threshold) ID TChainID ID // ZChainID is the well-known Z-Chain (Zero-knowledge) ID ZChainID ID // GChainID is the well-known G-Chain (Graph/dgraph) ID - COMING SOON GChainID ID // IChainID is the well-known I-Chain (Identity) ID - COMING SOON IChainID ID // KChainID is the well-known K-Chain (KMS) ID - COMING SOON KChainID ID // DChainID is the well-known D-Chain (DEX) ID DChainID ID )
func AllNativeChainIDs ¶ added in v1.2.0
func AllNativeChainIDs() []ID
AllNativeChainIDs returns all well-known native chain IDs.
func Checksum256 ¶
Checksum256 computes SHA256 checksum and returns an ID
func FromString ¶
FromString is the inverse of ID.String()
func FromStringOrPanic ¶
FromStringOrPanic is the same as FromString, but will panic on error
func FromStringWithForce ¶
FromStringWithForce is like FromString but can force ignore checksum errors
func GenerateNodeIDFromBytes ¶
GenerateNodeIDFromBytes generates a node ID from bytes
func GenerateTestID ¶
func GenerateTestID() ID
GenerateTestID returns a new ID that should only be used for testing
func NativeChainFromString ¶ added in v1.2.0
NativeChainFromString parses a native chain string and returns the ID. Supports full strings (11111111111111111111111111111111P) and aliases (P, p). Returns Empty and false if not a native chain string.
func NativeChainIDFromLetter ¶ added in v1.2.0
NativeChainIDFromLetter returns the chain ID for a given letter. Returns Empty and false if the letter is not a valid chain identifier.
func (ID) Append ¶
Append this id with the provided suffixes and re-hash the result. This returns a new ID and does not modify the original ID.
This is used to generate LP-77 validationIDs.
func (ID) MarshalJSON ¶
func (ID) MarshalText ¶
func (ID) Prefix ¶
Prefix this id to create a more selective id. This can be used to store multiple values under the same key. For example: prefix1(id) -> confidence prefix2(id) -> vertex This will return a new id and not modify the original id.
func (*ID) UnmarshalJSON ¶
func (*ID) UnmarshalText ¶
type NodeID ¶
type NodeID ShortID
func BuildTestNodeID ¶
BuildTestNodeID is an utility to build NodeID from bytes in UTs It must not be used in production code. In production code we should use ToNodeID, which performs proper length checking.
func GenerateTestNodeID ¶
func GenerateTestNodeID() NodeID
GenerateTestNodeID returns a new ID that should only be used for testing
func NodeIDFromCert ¶
func NodeIDFromCert(cert *Certificate) NodeID
func NodeIDFromMLDSA ¶ added in v1.2.10
NodeIDFromMLDSA derives a 20-byte NodeID from an ML-DSA public key using the legacy (pre-chain-binding) derivation. Kept stable for existing call sites; new strict-PQ chains MUST use NodeIDScheme.DeriveMLDSA or TypedNodeIDFromMLDSA, which bind the chain id and scheme byte into the digest and return the full 48-byte SHAKE256-384 commitment alongside the truncated NodeID.
NodeID = RIPEMD160(SHA256("LuxNodeID/v1" || mldsa_pubkey_bytes))
func NodeIDFromString ¶
NodeIDFromString is the inverse of NodeID.String()
func (NodeID) MarshalJSON ¶
func (NodeID) MarshalText ¶
func (*NodeID) UnmarshalJSON ¶
func (*NodeID) UnmarshalText ¶
type NodeIDScheme ¶ added in v1.2.10
type NodeIDScheme uint8
NodeIDScheme is the wire byte that identifies which keying material produced a NodeID. Numbering aligns with the consensus SigSchemeID/WalletSchemeID enum blocks so the byte itself reads the same in every transcript:
0x00 — Invalid (never accepted)
0x42 — ML-DSA-65 (FIPS 204 Cat 3, canonical strict-PQ)
0x43 — ML-DSA-87 (FIPS 204 Cat 5, high-value validators)
0x90 — secp256k1 (classical; accepted ONLY under
LUX_CLASSICAL_COMPAT_UNSAFE)
New schemes claim the next free byte in the matching consensus block. Reuse is forbidden — a retired byte stays retired.
const ( // NodeIDSchemeInvalid is the zero value. Any decode that produces it // is an error; any encode that names it is a bug. NodeIDSchemeInvalid NodeIDScheme = 0x00 // NodeIDSchemeMLDSA65 is the canonical strict-PQ NodeID scheme. The // matching identity signature scheme is SigSchemeMLDSA65 in // luxfi/consensus/config. NodeIDSchemeMLDSA65 NodeIDScheme = 0x42 // NodeIDSchemeMLDSA87 is the high-value strict-PQ NodeID scheme used // for validators that secure governance roots / treasury operations. // The matching identity signature scheme is SigSchemeMLDSA87. NodeIDSchemeMLDSA87 NodeIDScheme = 0x43 // NodeIDSchemeSecp256k1 is the legacy classical scheme. Accepted only // when a chain explicitly opts into LUX_CLASSICAL_COMPAT_UNSAFE; any // strict-PQ profile rejects it. The 0x90 byte mirrors the consensus // "forbidden in PQ mode" block so an audit pipeline can flag a leak. NodeIDSchemeSecp256k1 NodeIDScheme = 0x90 )
func (NodeIDScheme) DeriveMLDSA ¶ added in v1.2.10
func (s NodeIDScheme) DeriveMLDSA(chainID ID, pubKey []byte) (NodeID, FullDigest, error)
DeriveMLDSA returns the 48-byte SHAKE256-384 digest and matching 20-byte NodeID for an ML-DSA public key under the supplied chain id.
digest = SHAKE256-384(left_encode(len)||"NODE_ID_V1" ||
chain_id || {scheme} || pubkey)
NodeID = digest[:20]
scheme MUST be NodeIDSchemeMLDSA65 or NodeIDSchemeMLDSA87 — any other byte is rejected so a caller cannot silently produce an off-spec NodeID by passing the wrong scheme tag. chainID is the 32-byte chain identifier (typically the ID of the chain the validator stakes on); a different chain produces a different NodeID for the same key, which prevents cross-chain replay of validator registrations.
func (NodeIDScheme) IsClassicalCompatUnsafe ¶ added in v1.2.10
func (s NodeIDScheme) IsClassicalCompatUnsafe() bool
IsClassicalCompatUnsafe reports whether this scheme is in the classical compatibility block (0x90+). These schemes are accepted only under an explicit operator opt-in; the strict-PQ profile refuses them.
func (NodeIDScheme) IsKnown ¶ added in v1.2.10
func (s NodeIDScheme) IsKnown() bool
IsKnown reports whether this byte names a scheme this build understands. An unknown byte is rejected by every gate — including the classical-compat path, which only accepts the named secp256k1 scheme, not arbitrary 0x90+ bytes.
func (NodeIDScheme) IsPostQuantum ¶ added in v1.2.10
func (s NodeIDScheme) IsPostQuantum() bool
IsPostQuantum reports whether this scheme is post-quantum (FIPS 204 ML-DSA family). Strict-PQ profiles refuse any NodeID whose scheme is not post-quantum.
func (NodeIDScheme) String ¶ added in v1.2.10
func (s NodeIDScheme) String() string
String returns the canonical wire name of this scheme.
type RequestID ¶
type RequestID struct {
// The node this request came from
NodeID NodeID
// The chain this request came from
SourceChainID ID
// The chain the expected response should come from
DestinationChainID ID
// The unique identifier for this request
RequestID uint32
// The message opcode
Op byte
}
RequestID is a unique identifier for an in-flight request pending a response.
type ShortID ¶
type ShortID [ShortIDLen]byte
ShortID wraps a 20 byte hash as an identifier
func GenerateTestShortID ¶
func GenerateTestShortID() ShortID
GenerateTestShortID returns a new ID that should only be used for testing
func ShortFromPrefixedString ¶
ShortFromPrefixedString returns a ShortID assuming the cb58 format is prefixed
func ShortFromString ¶
ShortFromString is the inverse of ShortID.String()
func (ShortID) Bytes ¶
Bytes returns the 20 byte hash as a slice. It is assumed this slice is not modified.
func (ShortID) MarshalJSON ¶
func (ShortID) MarshalText ¶
func (ShortID) PrefixedString ¶
PrefixedString returns the String representation with a prefix added
func (*ShortID) UnmarshalJSON ¶
func (*ShortID) UnmarshalText ¶
type Sortable ¶ added in v1.2.10
Sortable is the interface for types that can be compared for ordering.
type TypedNodeID ¶ added in v1.2.10
type TypedNodeID struct {
Scheme NodeIDScheme
NodeID NodeID
}
TypedNodeID is the wire-canonical NodeID: a NodeIDScheme byte followed by the 20-byte NodeID. Used at every boundary where the receiver MUST know which verifier to dispatch (peer handshake auth check, validator registration, block proposer attribution, mempool sender check) without relying on the chain profile alone — the profile catches a downgrade but not a primitive mismatch.
The 20-byte NodeID is preserved as a map-key / storage primitive; the scheme byte travels with it on the wire. In-memory consumers that already key by NodeID continue to work unchanged; only the wire boundary widens.
func NewTypedNodeID ¶ added in v1.2.10
func NewTypedNodeID(scheme NodeIDScheme, id NodeID) (TypedNodeID, error)
NewTypedNodeID constructs a TypedNodeID. The scheme MUST be a known scheme; NodeIDSchemeInvalid and unknown bytes are rejected so a caller cannot construct a TypedNodeID that the wire decoder would later refuse — the construction gate matches the decoding gate.
func ParseTypedNodeID ¶ added in v1.2.10
func ParseTypedNodeID(b []byte) (TypedNodeID, error)
ParseTypedNodeID is the inverse of TypedNodeID.Bytes. Refuses any input that is the wrong length, names NodeIDSchemeInvalid, or names an unknown scheme byte. The scheme byte is checked before the NodeID copy so a malformed input cannot consume the array space.
func TypedNodeIDFromCert ¶ added in v1.2.10
func TypedNodeIDFromCert(cert *Certificate) TypedNodeID
TypedNodeIDFromCert produces a classical-compat TypedNodeID from a staking certificate. Used by the classical-compat handshake path; a strict-PQ chain refuses this TypedNodeID at the cross-axis gate.
func (TypedNodeID) Bytes ¶ added in v1.2.10
func (t TypedNodeID) Bytes() []byte
Bytes returns the 21-byte wire form: one scheme byte followed by the 20-byte NodeID. Callers MUST NOT mutate the returned slice; a future version may share the underlying array.
func (TypedNodeID) Compare ¶ added in v1.2.10
func (t TypedNodeID) Compare(other TypedNodeID) int
Compare orders TypedNodeIDs lexicographically over (scheme, id). Used for deterministic sorting in validator-set commitments.
func (TypedNodeID) String ¶ added in v1.2.10
func (t TypedNodeID) String() string
String returns "scheme:NodeID-<cb58>" for logging. Not a wire form.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
test_native
command
|
|
|
Package codectest provides a test suite for testing functionality related to IDs.
|
Package codectest provides a test suite for testing functionality related to IDs. |