mirror of
https://github.com/luxfi/sdk.git
synced 2026-10-30 15:19:23 +00:00
Lux Partners Limited is not the entity behind this work. Every place the old name stood — copyright lines, site footers, brand config, legal and compliance text — now names the company that actually holds it. lux.fund is the exception and is not renamed to match: that site belongs to Lux Assets Management LLC, a different company, and it says so. Two kinds of line were left for a person rather than rewritten. A dated news item recording that Lux Partners Limited was established in the Isle of Man is a historical fact, and renaming it would falsify the record. And a sentence asserting that the company is domiciled in the Isle of Man is a claim about a jurisdiction, not a name — an Inc or an LLC is not an Isle of Man company, so swapping the name there would assert something untrue. Co-authored-by: Hanzo Dev <[email protected]>
81 lines
1.9 KiB
Go
81 lines
1.9 KiB
Go
// Copyright (C) 2020-2025, Lux Industries Inc All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
// Package types provides internal type definitions.
|
|
package types
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/hex"
|
|
)
|
|
|
|
// ID represents a 32-byte identifier
|
|
type ID [32]byte
|
|
|
|
// NodeID represents a node identifier
|
|
type NodeID [20]byte
|
|
|
|
// ShortID represents a 20-byte identifier
|
|
type ShortID [20]byte
|
|
|
|
// Empty returns an empty ID
|
|
var Empty = ID{}
|
|
|
|
// String returns the string representation of an ID
|
|
func (id ID) String() string {
|
|
return hex.EncodeToString(id[:])
|
|
}
|
|
|
|
// String returns the string representation of a NodeID
|
|
func (id NodeID) String() string {
|
|
return "NodeID-" + hex.EncodeToString(id[:])
|
|
}
|
|
|
|
// String returns the string representation of a ShortID
|
|
func (id ShortID) String() string {
|
|
return hex.EncodeToString(id[:])
|
|
}
|
|
|
|
// GenerateTestID generates a random ID for testing
|
|
func GenerateTestID() ID {
|
|
var id ID
|
|
if _, err := rand.Read(id[:]); err != nil {
|
|
// For test ID generation, we panic on error as this should never fail
|
|
panic("failed to generate test ID: " + err.Error())
|
|
}
|
|
return id
|
|
}
|
|
|
|
// GenerateTestNodeID generates a random NodeID for testing
|
|
func GenerateTestNodeID() NodeID {
|
|
var id NodeID
|
|
if _, err := rand.Read(id[:]); err != nil {
|
|
// For test ID generation, we panic on error as this should never fail
|
|
panic("failed to generate test NodeID: " + err.Error())
|
|
}
|
|
return id
|
|
}
|
|
|
|
// ShortFromString creates a ShortID from a string
|
|
func ShortFromString(s string) (ShortID, error) {
|
|
var id ShortID
|
|
// Simple implementation for testing
|
|
copy(id[:], []byte(s))
|
|
return id, nil
|
|
}
|
|
|
|
// NodeIDFromString creates a NodeID from a string
|
|
func NodeIDFromString(s string) (NodeID, error) {
|
|
var id NodeID
|
|
// Simple implementation for testing
|
|
if len(s) > 7 && s[:7] == "NodeID-" {
|
|
s = s[7:]
|
|
}
|
|
decoded, err := hex.DecodeString(s)
|
|
if err != nil {
|
|
return id, err
|
|
}
|
|
copy(id[:], decoded)
|
|
return id, nil
|
|
}
|