go mod tidy works now at least.

This commit is contained in:
fiatjaf
2025-04-15 18:39:14 -03:00
parent 2b5b646a62
commit cb0dd45a32
37 changed files with 540 additions and 917 deletions
+11 -52
View File
@@ -12,59 +12,9 @@ type RelayEvent struct {
Relay *Relay
}
var (
ZeroID = [32]byte{}
ZeroPK = [32]byte{}
)
type PubKey [32]byte
func (pk PubKey) String() string { return hex.EncodeToString(pk[:]) }
func (pk PubKey) Hex() string { return hex.EncodeToString(pk[:]) }
func PubKeyFromHex(pkh string) (PubKey, error) {
pk := PubKey{}
if len(pkh) != 64 {
return pk, fmt.Errorf("pubkey should be 64-char hex, got '%s'", pkh)
}
if _, err := hex.Decode(pk[:], unsafe.Slice(unsafe.StringData(pkh), 64)); err != nil {
return pk, fmt.Errorf("'%s' is not valid hex: %w", pkh, err)
}
if !IsValidPublicKey(pk) {
return pk, fmt.Errorf("'%s' is not a valid pubkey", pkh)
}
return pk, nil
}
func PubKeyFromHexCheap(pkh string) (PubKey, error) {
pk := PubKey{}
if len(pkh) != 64 {
return pk, fmt.Errorf("pubkey should be 64-char hex, got '%s'", pkh)
}
if _, err := hex.Decode(pk[:], unsafe.Slice(unsafe.StringData(pkh), 64)); err != nil {
return pk, fmt.Errorf("'%s' is not valid hex: %w", pkh, err)
}
return pk, nil
}
func MustPubKeyFromHex(pkh string) PubKey {
pk := PubKey{}
hex.Decode(pk[:], unsafe.Slice(unsafe.StringData(pkh), 64))
return pk
}
func ContainsPubKey(haystack []PubKey, needle PubKey) bool {
for _, cand := range haystack {
if cand == needle {
return true
}
}
return false
}
var ZeroID = [32]byte{}
// ID represents an event id
type ID [32]byte
func (id ID) String() string { return hex.EncodeToString(id[:]) }
@@ -88,3 +38,12 @@ func MustIDFromHex(idh string) ID {
hex.Decode(id[:], unsafe.Slice(unsafe.StringData(idh), 64))
return id
}
func ContainsID(haystack []ID, needle ID) bool {
for _, cand := range haystack {
if cand == needle {
return true
}
}
return false
}