gossip icon indicating copy to clipboard operation
gossip copied to clipboard

import of private key from Flamingo NOSTR browser extension fails with "private key not recognized" message

Open sysfu opened this issue 1 year ago • 1 comments
trafficstars

Trying to import my Flamingo private nsec key but it's failing with "private key not recognized" message.

Console output

Environment is PureOS 11 Crimson (debian based)

$ gossip
Gossip 0.11.3
2024-10-02T20:59:52.931755Z  INFO gossip-lib/src/filter.rs:30: No spam filter: No such file or directory (os error 2)
2024-10-02T20:59:52.936321Z  INFO /usr/local/cargo/git/checkouts/egui-904381843a0f3282/63dde4c/crates/eframe/src/lib.rs:255: Both the glow and wgpu renderers are available. Using glow.    
2024-10-02T20:59:52.989049Z  INFO /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/winit-0.29.15/src/platform_impl/linux/x11/window.rs:189: Guessed window scale factor: 1    

sysfu avatar Oct 02 '24 21:10 sysfu

Are you at the wizard page? Or are you already setup and now you want to import an nsec?

At the wizard page it seems to work for me.

mikedilger avatar Oct 03 '24 06:10 mikedilger

Are you at the wizard page? Or are you already setup and now you want to import an nsec?

At the wizard page it seems to work for me.

The latter, already setup and want to import an nsec.

sysfu avatar Oct 06 '24 17:10 sysfu

I simply cannot replicate. I can import nsecs from the keys page after I delete my identity and it gives me the field. So I don't know how to fix this for you.

mikedilger avatar Oct 07 '24 03:10 mikedilger

I simply cannot replicate. I can import nsecs from the keys page after I delete my identity and it gives me the field. So I don't know how to fix this for you.

Is there a way to launch gossip from the terminal with a debug or verbose option? It's hard to troubleshoot this because it's failing tersely with the 'private key not recognized' message.

I have tried importing with and without a password, and it fails either way.

sysfu avatar Oct 07 '24 14:10 sysfu

Here is the relevant block of code

 /// Import a private key
    pub fn import_priv(mut privkey: String, mut password: String) -> Result<(), Error> {
        if privkey.starts_with("ncryptsec") {
            let epk = EncryptedPrivateKey(privkey);
            match GLOBALS.identity.set_encrypted_private_key(epk, &password) {
                Ok(_) => {
                    GLOBALS.identity.unlock(&password)?;
                    password.zeroize();
                }
                Err(err) => {
                    password.zeroize();
                    GLOBALS
                        .status_queue
                        .write()
                        .write(format!("Error importing ncryptsec: {}", err));
                }
            }
        } else {
            let maybe_pk1 = PrivateKey::try_from_bech32_string(privkey.trim());
            let maybe_pk2 = PrivateKey::try_from_hex_string(privkey.trim());
            privkey.zeroize();
            if maybe_pk1.is_err() && maybe_pk2.is_err() {
                password.zeroize();
                GLOBALS
                    .status_queue
                    .write()
                    .write("Private key not recognized.".to_owned());
            } else {
                let privkey = maybe_pk1.unwrap_or_else(|_| maybe_pk2.unwrap());
                GLOBALS.identity.set_private_key(privkey, &password)?;
                password.zeroize();
            }
        }

        Ok(())
    }

That error is printed if your input could not be recognized either as a bech32 private key or a hex private key.

Try with either of these (do not keep them!) and see if it still fails:

nsec1w3yl04x4ukwngwc2lmrv75680t85dgpr0zde83f544qqclkxrjnqjwqt2g

7449f7d4d5e59d343b0afec6cf53477acf46a023789b93c534ad400c7ec61ca6

mikedilger avatar Oct 07 '24 20:10 mikedilger

Here is the relevant block of code

 /// Import a private key
    pub fn import_priv(mut privkey: String, mut password: String) -> Result<(), Error> {
        if privkey.starts_with("ncryptsec") {
            let epk = EncryptedPrivateKey(privkey);
            match GLOBALS.identity.set_encrypted_private_key(epk, &password) {
                Ok(_) => {
                    GLOBALS.identity.unlock(&password)?;
                    password.zeroize();
                }
                Err(err) => {
                    password.zeroize();
                    GLOBALS
                        .status_queue
                        .write()
                        .write(format!("Error importing ncryptsec: {}", err));
                }
            }
        } else {
            let maybe_pk1 = PrivateKey::try_from_bech32_string(privkey.trim());
            let maybe_pk2 = PrivateKey::try_from_hex_string(privkey.trim());
            privkey.zeroize();
            if maybe_pk1.is_err() && maybe_pk2.is_err() {
                password.zeroize();
                GLOBALS
                    .status_queue
                    .write()
                    .write("Private key not recognized.".to_owned());
            } else {
                let privkey = maybe_pk1.unwrap_or_else(|_| maybe_pk2.unwrap());
                GLOBALS.identity.set_private_key(privkey, &password)?;
                password.zeroize();
            }
        }

        Ok(())
    }

That error is printed if your input could not be recognized either as a bech32 private key or a hex private key.

Try with either of these (do not keep them!) and see if it still fails:

nsec1w3yl04x4ukwngwc2lmrv75680t85dgpr0zde83f544qqclkxrjnqjwqt2g

7449f7d4d5e59d343b0afec6cf53477acf46a023789b93c534ad400c7ec61ca6

Both fail with 'private key not recognized' error

sysfu avatar Oct 08 '24 15:10 sysfu

Have you tried upgrading to 0.12.0?

mikedilger avatar Oct 08 '24 22:10 mikedilger

0.12.0

0.12.0 release resolved the issue, thank you.

sysfu avatar Oct 09 '24 17:10 sysfu