mirror of
https://relay.ngit.dev/npub15qydau2hjma6ngxkl2cyar74wzyjshvl65za5k5rl69264ar2exs5cyejr/ngit-grasp.git
synced 2026-10-05 15:08:24 +00:00
fix: use hex format for pubkey in NIP-11 document
The NIP-11 specification requires the pubkey field to be a 64-character hex string, but we were incorrectly using npub (bech32) format. Changes: - Add Config::relay_owner_pubkey_hex() method to get hex format - Update NIP-11 document to use hex format instead of npub - Update test to verify 64-char hex string instead of npub format Fixes nak relay command error: 'must be a hex string of 64 characters'
This commit is contained in:
+7
-1
@@ -574,7 +574,13 @@ impl Config {
|
||||
Keys::parse(nsec).context("Invalid relay_owner_nsec")
|
||||
}
|
||||
|
||||
/// Get the relay owner's public key (npub format) for NIP-11
|
||||
/// Get the relay owner's public key (hex format) for NIP-11
|
||||
pub fn relay_owner_pubkey_hex(&self) -> Result<String> {
|
||||
let keys = self.relay_owner_keys()?;
|
||||
Ok(keys.public_key().to_hex())
|
||||
}
|
||||
|
||||
/// Get the relay owner's public key (npub format)
|
||||
pub fn relay_owner_npub(&self) -> Result<String> {
|
||||
let keys = self.relay_owner_keys()?;
|
||||
Ok(keys.public_key().to_bech32()?)
|
||||
|
||||
+4
-3
@@ -100,7 +100,7 @@ impl RelayInformationDocument {
|
||||
Self {
|
||||
name: config.relay_name(),
|
||||
description: config.relay_description.clone(),
|
||||
pubkey: config.relay_owner_npub().ok(),
|
||||
pubkey: config.relay_owner_pubkey_hex().ok(),
|
||||
contact: None, // Could be added to config if needed
|
||||
supported_nips: vec![
|
||||
1, // NIP-01: Basic protocol flow
|
||||
@@ -145,10 +145,11 @@ mod tests {
|
||||
assert_eq!(doc.name, "Test Relay");
|
||||
assert_eq!(doc.description, "A test relay");
|
||||
|
||||
// Verify pubkey is present and is a valid npub
|
||||
// Verify pubkey is present and is a valid hex string (64 chars)
|
||||
assert!(doc.pubkey.is_some());
|
||||
let pubkey = doc.pubkey.unwrap();
|
||||
assert!(pubkey.starts_with("npub1"));
|
||||
assert_eq!(pubkey.len(), 64);
|
||||
assert!(pubkey.chars().all(|c| c.is_ascii_hexdigit()));
|
||||
|
||||
assert!(doc.supported_nips.contains(&1));
|
||||
assert!(doc.supported_nips.contains(&11));
|
||||
|
||||
Reference in New Issue
Block a user