nip19 codes as nip21 URLs, and display them right after parsed too.

This commit is contained in:
fiatjaf 2023-03-25 09:46:25 -03:00
parent 268022800d
commit 7633eb3615
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1

View File

@ -27,7 +27,7 @@ object Components {
"npub", "npub",
NIP19.encode(XOnlyPublicKey(bytes32)) NIP19.encode(XOnlyPublicKey(bytes32))
), ),
entry( nip19_21(
"nprofile", "nprofile",
NIP19.encode(ProfilePointer(XOnlyPublicKey(bytes32))) NIP19.encode(ProfilePointer(XOnlyPublicKey(bytes32)))
) )
@ -43,7 +43,7 @@ object Components {
"npub", "npub",
NIP19.encode(XOnlyPublicKey(bytes32)) NIP19.encode(XOnlyPublicKey(bytes32))
), ),
entry( nip19_21(
"nprofile", "nprofile",
NIP19.encode(ProfilePointer(XOnlyPublicKey(bytes32))) NIP19.encode(ProfilePointer(XOnlyPublicKey(bytes32)))
) )
@ -51,7 +51,7 @@ object Components {
"if this is an event id:", "if this is an event id:",
div( div(
cls := "pl-2 mb-2", cls := "pl-2 mb-2",
entry( nip19_21(
"nevent", "nevent",
NIP19.encode(EventPointer(bytes32.toHex)) NIP19.encode(EventPointer(bytes32.toHex))
) )
@ -69,7 +69,8 @@ object Components {
else None, else None,
evp.author.map { pk => evp.author.map { pk =>
entry("author hint (pubkey hex)", pk.value.toHex) entry("author hint (pubkey hex)", pk.value.toHex)
} },
nip19_21("nevent", NIP19.encode(evp))
) )
def renderProfilePointer( def renderProfilePointer(
@ -82,7 +83,9 @@ object Components {
entry("public key (hex)", pp.pubkey.value.toHex), entry("public key (hex)", pp.pubkey.value.toHex),
if pp.relays.size > 0 then if pp.relays.size > 0 then
Some(entry("relay hints", pp.relays.reduce((a, b) => s"$a, $b"))) Some(entry("relay hints", pp.relays.reduce((a, b) => s"$a, $b")))
else None else None,
entry("npub", NIP19.encode(pp.pubkey)),
nip19_21("nprofile", NIP19.encode(pp))
) )
def renderAddressPointer( def renderAddressPointer(
@ -95,7 +98,8 @@ object Components {
entry("kind", addr.kind.toString), entry("kind", addr.kind.toString),
if addr.relays.size > 0 then if addr.relays.size > 0 then
Some(entry("relay hints", addr.relays.reduce((a, b) => s"$a, $b"))) Some(entry("relay hints", addr.relays.reduce((a, b) => s"$a, $b")))
else None else None,
nip19_21("naddr", NIP19.encode(addr))
) )
def renderEvent( def renderEvent(
@ -188,7 +192,8 @@ object Components {
event.isValid match { event.isValid match {
case true => "yes"; case false => "no" case true => "yes"; case false => "no"
} }
) ),
event.id.map(id => nip19_21("nevent", NIP19.encode(EventPointer(id))))
) )
private def entry( private def entry(
@ -199,4 +204,19 @@ object Components {
span(cls := "font-bold", key + " "), span(cls := "font-bold", key + " "),
span(Styles.mono, value) span(Styles.mono, value)
) )
private def nip19_21(
key: String,
code: String
): Resource[IO, HtmlDivElement[IO]] =
div(
span(cls := "font-bold", key + " "),
span(
Styles.mono,
a(
href := "nostr:" + code,
code
)
)
)
} }