From 9fd1f8d19cc8926c0dcccea1a7568ef1fd0dbb3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nu=C5=A1a=20Puk=C5=A1i=C4=8D?= Date: Fri, 10 Oct 2025 13:20:10 +0200 Subject: [PATCH] Util --- src/Util/NostrKeyUtil.php | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/Util/NostrKeyUtil.php diff --git a/src/Util/NostrKeyUtil.php b/src/Util/NostrKeyUtil.php new file mode 100644 index 0000000..09ccfc6 --- /dev/null +++ b/src/Util/NostrKeyUtil.php @@ -0,0 +1,53 @@ +convertToHex($npub); + } + + /** + * Convert hex pubkey to npub (bech32). + * Throws \InvalidArgumentException if invalid. + */ + public static function hexToNpub(string $pubkey): string + { + if (!self::isHexPubkey($pubkey)) { + throw new \InvalidArgumentException('Not a valid hex pubkey'); + } + $key = new Key(); + return $key->convertPublicKeyToBech32($pubkey); + } +} +