Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions nostr/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@

## Unreleased

### Breaking changes

- Require `CryptoRng` trait for secret key generation (https://github.com/nostrdevkit/nostr/pull/1437)

### Fixed

- The `Display` implementations of `NostrConnectMessage` redact the sensitive data (https://github.com/nostrdevkit/nostr/pull/1432)
Expand Down
4 changes: 3 additions & 1 deletion nostr/examples/embedded/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use core::panic::PanicInfo;
use alloc_cortex_m::CortexMHeap;
use cortex_m_rt::entry;
use cortex_m_semihosting::{debug, hprintln};
use rand::TryRng;
use rand::{TryRng, TryCryptoRng};
use secp256k1::Secp256k1;
use nostr::key::{Keys, SecretKey};
use nostr::nips::nip19::{FromBech32, ToBech32};
Expand Down Expand Up @@ -47,6 +47,8 @@ impl TryRng for FakeRng {
}
}

impl TryCryptoRng for FakeRng {}


#[entry]
fn main() -> ! {
Expand Down
2 changes: 1 addition & 1 deletion nostr/src/key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl Keys {
pub fn generate_with_rng<C, R>(secp: &Secp256k1<C>, rng: &mut R) -> Self
where
C: Signing,
R: Rng,
R: Rng + CryptoRng,
{
let secret_key: SecretKey = SecretKey::generate_with_rng(rng);
Self::new_with_ctx(secp, secret_key)
Expand Down
8 changes: 4 additions & 4 deletions nostr/src/key/secret_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ use alloc::string::String;
use core::ops::{Deref, DerefMut};
use core::str::FromStr;

#[cfg(feature = "rand")]
use rand::Rng;
#[cfg(all(feature = "std", feature = "os-rng"))]
use rand::rand_core::UnwrapErr;
#[cfg(all(feature = "std", feature = "os-rng"))]
use rand::rngs::SysRng;
#[cfg(feature = "rand")]
use rand::{CryptoRng, Rng};
use serde::{Deserialize, Deserializer};

use crate::error::{Error, ErrorKind};
Expand Down Expand Up @@ -99,12 +99,12 @@ impl SecretKey {
#[cfg(feature = "rand")]
pub fn generate_with_rng<R>(rng: &mut R) -> Self
where
R: Rng,
R: Rng + CryptoRng,
{
let mut data: [u8; Self::LEN] = util::random_32_bytes(rng);

loop {
match secp256k1::SecretKey::from_slice(&data) {
match secp256k1::SecretKey::from_byte_array(&data) {
Ok(secret_key) => return Self { inner: secret_key },
Err(_) => data = util::random_32_bytes(rng),
}
Expand Down
Loading