refactor aliases to not be experted
This commit is contained in:
@@ -15,21 +15,21 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
NoteHRP = B("note")
|
||||
NsecHRP = B("nsec")
|
||||
NpubHRP = B("npub")
|
||||
NprofileHRP = B("nprofile")
|
||||
NeventHRP = B("nevent")
|
||||
NentityHRP = B("naddr")
|
||||
NoteHRP = by("note")
|
||||
NsecHRP = by("nsec")
|
||||
NpubHRP = by("npub")
|
||||
NprofileHRP = by("nprofile")
|
||||
NeventHRP = by("nevent")
|
||||
NentityHRP = by("naddr")
|
||||
)
|
||||
|
||||
func DecodeToString(bech32String B) (prefix, value B, err E) {
|
||||
func DecodeToString(bech32String by) (prefix, value by, err er) {
|
||||
var s any
|
||||
if prefix, s, err = Decode(bech32String); chk.D(err) {
|
||||
return
|
||||
}
|
||||
var ok bool
|
||||
if value, ok = s.(B); ok {
|
||||
var ok bo
|
||||
if value, ok = s.(by); ok {
|
||||
return
|
||||
}
|
||||
err = log.E.Err("value was not decoded to a string, found type %s",
|
||||
@@ -37,8 +37,8 @@ func DecodeToString(bech32String B) (prefix, value B, err E) {
|
||||
return
|
||||
}
|
||||
|
||||
func Decode(bech32string B) (prefix B, value any, err E) {
|
||||
var bits5 []byte
|
||||
func Decode(bech32string by) (prefix by, value any, err er) {
|
||||
var bits5 by
|
||||
if prefix, bits5, err = bech32.DecodeNoLimit(bech32string); chk.D(err) {
|
||||
return
|
||||
}
|
||||
@@ -53,7 +53,7 @@ func Decode(bech32string B) (prefix B, value any, err E) {
|
||||
if len(data) < 32 {
|
||||
return prefix, nil, errorf.E("data is less than 32 bytes (%d)", len(data))
|
||||
}
|
||||
b := make(B, schnorr.PubKeyBytesLen*2)
|
||||
b := make(by, schnorr.PubKeyBytesLen*2)
|
||||
hex.EncBytes(b, data[:32])
|
||||
return prefix, b, nil
|
||||
case equals(prefix, NprofileHRP):
|
||||
@@ -73,7 +73,7 @@ func Decode(bech32string B) (prefix B, value any, err E) {
|
||||
if len(v) < 32 {
|
||||
return prefix, nil, errorf.E("pubkey is less than 32 bytes (%d)", len(v))
|
||||
}
|
||||
result.PublicKey = make(B, schnorr.PubKeyBytesLen*2)
|
||||
result.PublicKey = make(by, schnorr.PubKeyBytesLen*2)
|
||||
hex.EncBytes(result.PublicKey, v)
|
||||
case TLVRelay:
|
||||
result.Relays = append(result.Relays, v)
|
||||
@@ -106,7 +106,7 @@ func Decode(bech32string B) (prefix B, value any, err E) {
|
||||
if len(v) < 32 {
|
||||
return prefix, nil, errorf.E("author is less than 32 bytes (%d)", len(v))
|
||||
}
|
||||
result.Author = make(B, schnorr.PubKeyBytesLen*2)
|
||||
result.Author = make(by, schnorr.PubKeyBytesLen*2)
|
||||
hex.EncBytes(result.Author, v)
|
||||
case TLVKind:
|
||||
result.Kind = kind.New(binary.BigEndian.Uint32(v))
|
||||
@@ -139,7 +139,7 @@ func Decode(bech32string B) (prefix B, value any, err E) {
|
||||
if len(v) < 32 {
|
||||
return prefix, nil, errorf.E("author is less than 32 bytes (%d)", len(v))
|
||||
}
|
||||
result.PublicKey = make(B, schnorr.PubKeyBytesLen*2)
|
||||
result.PublicKey = make(by, schnorr.PubKeyBytesLen*2)
|
||||
hex.EncBytes(result.PublicKey, v)
|
||||
case TLVKind:
|
||||
result.Kind = kind.New(binary.BigEndian.Uint32(v))
|
||||
@@ -153,7 +153,7 @@ func Decode(bech32string B) (prefix B, value any, err E) {
|
||||
return prefix, data, errorf.E("unknown tag %s", prefix)
|
||||
}
|
||||
|
||||
func EncodeNote(eventIDHex B) (s B, err E) {
|
||||
func EncodeNote(eventIDHex by) (s by, err er) {
|
||||
var b []byte
|
||||
if _, err = hex.DecBytes(b, eventIDHex); chk.D(err) {
|
||||
err = log.E.Err("failed to decode event id hex: %w", err)
|
||||
@@ -166,9 +166,9 @@ func EncodeNote(eventIDHex B) (s B, err E) {
|
||||
return bech32.Encode(NoteHRP, bits5)
|
||||
}
|
||||
|
||||
func EncodeProfile(publicKeyHex B, relays []B) (s B, err E) {
|
||||
func EncodeProfile(publicKeyHex by, relays []by) (s by, err er) {
|
||||
buf := &bytes.Buffer{}
|
||||
pb := make(B, schnorr.PubKeyBytesLen)
|
||||
pb := make(by, schnorr.PubKeyBytesLen)
|
||||
if _, err = hex.DecBytes(pb, publicKeyHex); chk.D(err) {
|
||||
err = log.E.Err("invalid pubkey '%s': %w", publicKeyHex, err)
|
||||
return
|
||||
@@ -185,9 +185,9 @@ func EncodeProfile(publicKeyHex B, relays []B) (s B, err E) {
|
||||
return bech32.Encode(NprofileHRP, bits5)
|
||||
}
|
||||
|
||||
func EncodeEvent(eventIDHex *eventid.T, relays []B, author B) (s B, err E) {
|
||||
func EncodeEvent(eventIDHex *eventid.T, relays []by, author by) (s by, err er) {
|
||||
buf := &bytes.Buffer{}
|
||||
id := make(B, sha256.Size)
|
||||
id := make(by, sha256.Size)
|
||||
if _, err = hex.DecBytes(id, eventIDHex.ByteString(nil)); chk.D(err) ||
|
||||
len(id) != 32 {
|
||||
|
||||
@@ -198,7 +198,7 @@ func EncodeEvent(eventIDHex *eventid.T, relays []B, author B) (s B, err E) {
|
||||
for _, url := range relays {
|
||||
writeTLVEntry(buf, TLVRelay, []byte(url))
|
||||
}
|
||||
pubkey := make(B, schnorr.PubKeyBytesLen)
|
||||
pubkey := make(by, schnorr.PubKeyBytesLen)
|
||||
if _, err = hex.DecBytes(pubkey, author); len(pubkey) == 32 {
|
||||
writeTLVEntry(buf, TLVAuthor, pubkey)
|
||||
}
|
||||
@@ -211,13 +211,13 @@ func EncodeEvent(eventIDHex *eventid.T, relays []B, author B) (s B, err E) {
|
||||
return bech32.Encode(NeventHRP, bits5)
|
||||
}
|
||||
|
||||
func EncodeEntity(pk B, k *kind.T, id B, relays []B) (s B, err E) {
|
||||
func EncodeEntity(pk by, k *kind.T, id by, relays []by) (s by, err er) {
|
||||
buf := &bytes.Buffer{}
|
||||
writeTLVEntry(buf, TLVDefault, []byte(id))
|
||||
for _, url := range relays {
|
||||
writeTLVEntry(buf, TLVRelay, []byte(url))
|
||||
}
|
||||
pb := make(B, schnorr.PubKeyBytesLen)
|
||||
pb := make(by, schnorr.PubKeyBytesLen)
|
||||
if _, err = hex.DecBytes(pb, pk); chk.D(err) {
|
||||
return nil, errorf.E("invalid pubkey '%s': %w", pb, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user