Nip04 Decrypt Panic
blakejakopovic opened this issue · 2 comments
blakejakopovic commented
I updated to 0.20.0
(and 0.20.2
) after the last fix and the decrypt
issue seemed to be resolved, however I think perhaps there is still an issue with decrypt
. I downgraded to 0.16.2
and again it seems to be fine.
Basically, I get a panic which I think is from this unwrap, but I'm unsure why it's failing. https://github.com/0xtlt/nostr_rust/blame/9f3ec7cbc6252987484f69a546c6eaa1d8071d40/src/nips/nip4.rs#L85
How to reproduce
// nostr_rust = "0.20.2" // FAILS
// nostr_rust = "0.16.2" // WORKS
// secp256k1 = { version = "0.25", features = ["bitcoin_hashes", "global-context", "rand-std"] }
use nostr_rust::keys;
use nostr_rust::nips::nip4;
use secp256k1::XOnlyPublicKey;
use std::str::FromStr;
fn main() {
// Example Event
// {"id": "eff830c8dfac58c83676da961d5a38f2576f036034742e84a698b389c8e35b85","pubkey": "bbe938a1176f7d57fd98bff11b7b3fba938d6021093c00e8118da9638bdbf2d4","created_at": 1674735555,"kind": 4,"tags": [["p","bbe938a1176f7d57fd98bff11b7b3fba938d6021093c00e8118da9638bdbf2d4"]],"content": "OxYmyW8FnDUsUjcq8VO9rg==?iv=gPYD/OKASjjoWwdQ8kJRTA==","sig": "3964d3c38426abef1525fbc7f21fb4da869c2b09bff7bf6763fda8391a9ce7c03f9dc1831eb2c98476b661f2da05c8199428dd29463b7fc5db8dd4e5c23d6acc"}
let event_pubkey = "bbe938a1176f7d57fd98bff11b7b3fba938d6021093c00e8118da9638bdbf2d4";
let event_content = "OxYmyW8FnDUsUjcq8VO9rg==?iv=gPYD/OKASjjoWwdQ8kJRTA==";
let nostr_private_key = "240682ce7a297990f2e651b635f1a5a45af89acf0a4c1c16d1bb1aaa376be0bc"; // TESTING SEC KEY
let system_sec_key = keys::secret_key_from_str(&nostr_private_key).unwrap();
let sender_pub_key = XOnlyPublicKey::from_str(&event_pubkey).unwrap();
// Note: You cannot catch the panic caused inside nip04::decrypt
let message = nip4::decrypt(&system_sec_key, &sender_pub_key, event_content);
println!("message: {message:?}");
}
Rust Backtrace
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `32`,
right: `16`', /Users/blakejakopovic/.cargo/registry/src/github.com-1ecc6299db9ec823/generic-array-0.14.6/src/lib.rs:565:9
stack backtrace:
0: rust_begin_unwind
at /rustc/0b90256ada21c6a81b4c18f2c7a23151ab5fc232/library/std/src/panicking.rs:575:5
1: core::panicking::panic_fmt
at /rustc/0b90256ada21c6a81b4c18f2c7a23151ab5fc232/library/core/src/panicking.rs:64:14
2: core::panicking::assert_failed_inner
at /rustc/0b90256ada21c6a81b4c18f2c7a23151ab5fc232/library/core/src/panicking.rs:258:17
3: core::panicking::assert_failed
at /rustc/0b90256ada21c6a81b4c18f2c7a23151ab5fc232/library/core/src/panicking.rs:212:5
4: <&generic_array::GenericArray<T,N> as core::convert::From<&[T]>>::from
at /Users/blakejakopovic/.cargo/registry/src/github.com-1ecc6299db9ec823/generic-array-0.14.6/src/lib.rs:565:9
5: <T as core::convert::Into<U>>::into
at /rustc/0b90256ada21c6a81b4c18f2c7a23151ab5fc232/library/core/src/convert/mod.rs:726:9
6: nostr_rust::nips::nip4::decrypt
at /Users/blakejakopovic/.cargo/registry/src/github.com-1ecc6299db9ec823/nostr_rust-0.20.2/src/nips/nip4.rs:80:59
7: nostr_rust_nip04_decrypt_broken::main
at ./nostrgraph_sandbox/src/bin/nostr_rust_nip04_decrypt_broken.rs:24:19
8: core::ops::function::FnOnce::call_once
at /rustc/0b90256ada21c6a81b4c18f2c7a23151ab5fc232/library/core/src/ops/function.rs:250:5
0xtlt commented
Thanks, will take a look
0xtlt commented
Fixed in the last update :)
Thanks for your reporting