diff --git a/crates/nostr/src/event/unsigned.rs b/crates/nostr/src/event/unsigned.rs index 4149c3779..898610d6c 100644 --- a/crates/nostr/src/event/unsigned.rs +++ b/crates/nostr/src/event/unsigned.rs @@ -111,7 +111,7 @@ impl UnsignedEvent { kind: self.kind, tags: self.tags, content: self.content, - sig: keys.sign_schnorr(secp, &message, rng)?, + sig: keys.sign_schnorr_with_ctx(secp, &message, rng)?, #[cfg(feature = "nip03")] ots: None, }) diff --git a/crates/nostr/src/key/mod.rs b/crates/nostr/src/key/mod.rs index 19e067c31..4cbbc127f 100644 --- a/crates/nostr/src/key/mod.rs +++ b/crates/nostr/src/key/mod.rs @@ -97,8 +97,7 @@ impl Keys { /// Generate new random [`Keys`] pub fn generate() -> Self { - let mut rng = OsRng; - Self::generate_with_ctx(&SECP256K1, &mut rng) + Self::generate_with_ctx(&SECP256K1, &mut OsRng) } /// Generate random [`Keys`] with custom [`Rng`] @@ -117,6 +116,19 @@ impl Keys { { Self::generate_without_keypair_with_ctx(&SECP256K1, rng) } + + /// Get [`PublicKey`] + pub fn normalized_public_key(&self) -> Result + where + C: Signing, + { + self.normalized_public_key_with_ctx(&SECP256K1) + } + + /// Sign schnorr [`Message`] + pub fn sign_schnorr(&self, message: &Message) -> Result { + self.sign_schnorr_with_ctx(&SECP256K1, message, &mut OsRng) + } } impl Keys { @@ -185,7 +197,7 @@ impl Keys { } /// Get [`PublicKey`] - pub fn normalized_public_key(&self, secp: &Secp256k1) -> Result + pub fn normalized_public_key_with_ctx(&self, secp: &Secp256k1) -> Result where C: Signing, { @@ -208,7 +220,7 @@ impl Keys { } /// Sign schnorr [`Message`] - pub fn sign_schnorr( + pub fn sign_schnorr_with_ctx( &self, secp: &Secp256k1, message: &Message, diff --git a/crates/nostr/src/nips/nip26.rs b/crates/nostr/src/nips/nip26.rs index 381dac263..8263d49c1 100644 --- a/crates/nostr/src/nips/nip26.rs +++ b/crates/nostr/src/nips/nip26.rs @@ -151,7 +151,7 @@ where let unhashed_token = DelegationToken::new(delegatee_pk, conditions); let hashed_token = Sha256Hash::hash(unhashed_token.as_bytes()); let message = Message::from_slice(hashed_token.as_byte_array())?; - Ok(delegator_keys.sign_schnorr(secp, &message, rng)?) + Ok(delegator_keys.sign_schnorr_with_ctx(secp, &message, rng)?) } /// Verify delegation signature diff --git a/crates/nostr/src/nips/nip46.rs b/crates/nostr/src/nips/nip46.rs index bb55d94b7..1c8d96e68 100644 --- a/crates/nostr/src/nips/nip46.rs +++ b/crates/nostr/src/nips/nip46.rs @@ -259,7 +259,7 @@ impl Request { Self::SignSchnorr(value) => { let hash = Sha256Hash::hash(value.as_bytes()); let message = Secp256k1Message::from(hash); - let sig: Signature = keys.sign_schnorr(secp, &message, rng)?; + let sig: Signature = keys.sign_schnorr_with_ctx(secp, &message, rng)?; Some(Response::SignSchnorr(sig)) } };