mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-05-08 01:30:15 +02:00
nip19: decode to pointer.
This commit is contained in:
parent
4fb6fcd9a2
commit
ec55b1fac8
@ -1,6 +1,10 @@
|
|||||||
package nip19
|
package nip19
|
||||||
|
|
||||||
import "github.com/nbd-wtf/go-nostr"
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/nbd-wtf/go-nostr"
|
||||||
|
)
|
||||||
|
|
||||||
func EncodePointer(pointer nostr.Pointer) string {
|
func EncodePointer(pointer nostr.Pointer) string {
|
||||||
switch v := pointer.(type) {
|
switch v := pointer.(type) {
|
||||||
@ -16,3 +20,25 @@ func EncodePointer(pointer nostr.Pointer) string {
|
|||||||
}
|
}
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ToPointer(code string) (nostr.Pointer, error) {
|
||||||
|
prefix, data, err := Decode(code)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
switch prefix {
|
||||||
|
case "npub":
|
||||||
|
return nostr.ProfilePointer{PublicKey: data.(string)}, nil
|
||||||
|
case "nprofile":
|
||||||
|
return data.(nostr.ProfilePointer), nil
|
||||||
|
case "nevent":
|
||||||
|
return data.(nostr.EventPointer), nil
|
||||||
|
case "note":
|
||||||
|
return nostr.EventPointer{ID: data.(string)}, nil
|
||||||
|
case "naddr":
|
||||||
|
return data.(nostr.EntityPointer), nil
|
||||||
|
default:
|
||||||
|
return nil, fmt.Errorf("unexpected prefix '%s' to '%s'", prefix, code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package nip19
|
package nip19
|
||||||
|
|
||||||
import "github.com/nbd-wtf/go-nostr"
|
import (
|
||||||
|
"github.com/nbd-wtf/go-nostr"
|
||||||
|
)
|
||||||
|
|
||||||
func NeventFromRelayEvent(ie nostr.RelayEvent) string {
|
func NeventFromRelayEvent(ie nostr.RelayEvent) string {
|
||||||
v, _ := EncodeEvent(ie.ID, []string{ie.Relay.URL}, ie.PubKey)
|
v, _ := EncodeEvent(ie.ID, []string{ie.Relay.URL}, ie.PubKey)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user