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); + } +} +