nip19.
This commit is contained in:
@@ -1,17 +1,28 @@
|
||||
package nip19
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"strings"
|
||||
"bytes"
|
||||
)
|
||||
|
||||
// TranslatePublicKey turns a hex or bech32 public key into always hex
|
||||
func TranslatePublicKey(bech32orHexKey string) string {
|
||||
if strings.HasPrefix(bech32orHexKey, "npub1") {
|
||||
data, _, _ := Decode(bech32orHexKey)
|
||||
return hex.EncodeToString(data)
|
||||
const (
|
||||
TLVDefault uint8 = 0
|
||||
TLVRelay uint8 = 1
|
||||
)
|
||||
|
||||
func readTLVEntry(data []byte) (typ uint8, value []byte) {
|
||||
if len(data) < 2 {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
// just return what we got
|
||||
return bech32orHexKey
|
||||
typ = data[0]
|
||||
length := int(data[1])
|
||||
value = data[2 : 2+length]
|
||||
return
|
||||
}
|
||||
|
||||
func writeTLVEntry(buf *bytes.Buffer, typ uint8, value []byte) {
|
||||
length := len(value)
|
||||
buf.WriteByte(typ)
|
||||
buf.WriteByte(uint8(length))
|
||||
buf.Write(value)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user