Giter Site home page Giter Site logo

key-convertr's Introduction

Key-Convertr

People are copy-pasting nostr private keys into webpages to convert between the original hex-encoding and bech32-encoding (specified in NIP-19).

This is kind of bonkers, so here's a command-line utility that you can run to convert public/private keys between hex-encoding and the NIP-19 bech32 encoding. It can also convert note id's, and even convert a list of public keys from NIP5 configured domains from hex to bech32 in single shot.

Features:

Note: "keys" + "nip5" arguments accept multiple inputs for bulk operations

  • convert from bech32 (npub/nsec/note) to hex
  • convert from hex to bech32 (npub/nsec/note)
  • supports NIP-05 domain identifiers:

Installation

Building with Cargo

If you have cargo installed, then from the key-convertr directory, just do cargo install --path .. It will put a program called key-convertr in your $HOME/.cargo/bin directory.

Then, to convert from a hex-encoded pubkey to a bech32-encoded pubkey, you can do

$> key-convertr --kind npub 3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d
npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6

Running with Docker

If you have docker installed, you can simply do docker run --rm ghcr.io/rot13maxi/key-convertr:main to download and run the latest main revision of the tool. Then just follow the instructions below. For example,

$> docker run --rm ghcr.io/rot13maxi/key-convertr:main --kind npub 3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d
npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6

Building with Docker

If you have docker installed, you can do docker build -f docker/Dockerfile -t key-convertr . to build a container (no local cargo install required!). Then just do docker run --rm key-convertr [args] to run it. For example:

$> docker run --rm key-convertr --kind npub 3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d
npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6

Usage

Just provide the hex-encoded key or note-id and a --kind argument. The kinds supported are:

  • npub
  • nsec
  • note

To convert from an bech32(npub/nsec/note) to hex-encoding, you can do

$> key-convertr --to-hex npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6
3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d

To convert from an hex-encoding to bech32 (npub/nsec/note), you can do

$> key-convertr --kind npub 3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d
npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6

To convert list of public keys for a given NIP-05 domain identifier, you can

$> key-convertr --nip5 satoshivibes.com
Aurelius,npub169yu4d6xl8a6d4xvfyhstjdxr0cc7qtfq5pch5kwv4k2wkapa3pq8v2thg
frontrunbitcoin,npub199samvtne4sahhdkr6dcq3mauuqs7k7r3eulufp2y2lf04zewglqtu9mfd
lukeonchain,npub138guayty78ch9k42n3uyz5ch3jcaa3u390647hwq0c83m2lypekq6wk36k
  • you can also enable NIP5 related stats via "--nip-stats" or "-s";
    • this prints out summary stats in this format: domain=SomeName.com|count=21
    • this output could then be parsed (if needed) by other dev tools/libraries
$> key-convertr --nip5 strike.me --nip-stats
ZAurelius,npub169yu4d6xl8a6d4xvfyhstjdxr0cc7qtfq5pch5kwv4k2wkapa3pq8v2thg
frontrunbitcoin,npub199samvtne4sahhdkr6dcq3mauuqs7k7r3eulufp2y2lf04zewglqtu9mfd
lukeonchain,npub138guayty78ch9k42n3uyz5ch3jcaa3u390647hwq0c83m2lypekq6wk36k
domain=satoshivibes.com|count=3

You can also pass multiple keys/notes to the tool by putting a comma or space between them:

  • example with multiple "keys"
$> key-convertr --kind npub 3bf0c63fcb93463407af97a5e5ee64fa883d107ef9e558472c4eb9aaaefa459d,863883611bdbe6291c081fb8775908a7ab0cb04b608405ec1e85e9f938020a98
npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6
npub1scugxcgmm0nzj8qgr7u8wkgg574sevztvzzqtmq7sh5ljwqzp2vqf45w5j
  • example with multiple NIP5 domains (output omitted due to size)
$> key-convertr --nip5 nostrplebs.com,strike.me,satoshivibes.com

TODO

Optimizations:

  • multi threaded "--nip5" logic (multiple domains converted in parallel; some lists will be very large i.e nostrplebs.com)

key-convertr's People

Contributors

praveenperera avatar rot13maxi avatar snazzybytes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

key-convertr's Issues

Can't find no `key-converter` folder after installing Cargo on Debian

Just as the title says.
The instructions from your Github are probably incomplete or something else must be missing.
I tried to install Cargo, and it was installed successfully but I couldn't find that folder anywhere!

How can I move on?

Another question is if this script can convert a PK starting with 0x6... into nsec format.

Thanks

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: InvalidKeyDecode

Upon running key-convertr --kind npub npub1ftf4r5vs2atpp62jsskyfqvzzagusxcvxw2wqsddeg42d3zlfczsm46e26, I get the following error:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: InvalidKeyDecode("npub1ftf4r5vs2atpp62jsskyfqvzzagusxcvxw2wqsddeg42d3zlfczsm46e26")', src/main.rs:99:51
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

This happens both when I locally install the app with cargo, as when I try to run the app with Docker.

nprofile

Will you ever include support for nprofile in which relays are embedded with the pubkey?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.