Giter Club home page Giter Club logo

bitcoin-tool's Introduction

Introduction

bitcoin-tool is a simple tool written in C to convert Bitcoin keys to addresses, and various other conversions of keys.

Disclaimer: THIS CODE IS EXPERIMENTAL, IT IS PROBABLY BUGGY. PLEASE DO NOT TRUST YOUR BITCOINS WITH IT. IT IS EASY TO MAKE AN IRREVERSIBLE MISTAKE AND SEND YOUR BITCOINS TO A ADDRESS WITH NO WAY OF GETTING THEM BACK.

Build Instructions

Run make test to compile and run all tests.

Requirements

  • A C compiler
  • OpenSSL headers and libraries (with elliptic curve support)
  • GNU make : Packages: FreeBSD gmake
  • GNU bash (for running tests)
  • xxd (for running tests) : Packages: Linux vim, FreeBSD vim or vim-lite

Platform-specific Instructions

Gentoo Linux

Gentoo by default enables the bindist flag on the openssl package, which disables elliptic curve support, presumably because of software patent concerns. Since the openssh package also has bindist USE-flag set, the USE-flag must be disabled in both, then re-emerged to get an OpenSSL library with elliptic curve support.

FreeBSD

Use gmake to process the Makefile.

Tested on:

  • FreeBSD 10.4 amd64, clang 3.4.1
  • FreeBSD 11.1 amd64, clang 4.0.0

Windows

Tested on Windows 10 64-bit edition using Cygwin (64-bit) with x86_64_w64_mingw32-gcc compiler.

Requires Cygwin packages: bash, make, mingw64-x86_64-gcc-core, openssl-devel

Use make CC=other_cc to specify a different compiler if needed.

Description

I created this because I couldn't find an offline tool or library able to create addresses from Bitcoin private keys, and as a learning exercise in Bitcoin address formats and ECDSA.

Some day I'd like to replace the dependancy on OpenSSL with my own implementation of ECDSA (for portability).

The option names are a little verbose but I wanted to make it clear exactly what each one is referring to, especially when it is possible to make a costly mistake.

I've tried to add as much sanity checking as possible, to remove the scope for errors and misinterpretation of data. This sometimes boreders on the pedantic and annoying. For example, if the file for --input-file contains more data than is expected, then it'll refuse to process it at all.

Command-line options

  --input-type : Input data type, must be one of :
      mini-private-key : 30 character Casascius mini private key
      private-key      : 32 byte ECDSA private key
      private-key-wif  : 33/34 byte ECDSA WIF private key
      public-key       : 33/65 byte ECDSA public key
      public-key-sha   : 32 byte SHA256(public key) hash
      public-key-rmd   : 20 byte RIPEMD160(SHA256(public key)) hash
      address          : 21 byte Bitcoin address (prefix + hash)
  --input-format : Input data format, must be one of :
      raw         : Raw binary
      hex         : Hexadecimal encoded
      base58      : Base58 encoded
      base58check : Base58Check encoded (most common)
  --output-type  : Output data type, must be one of :
      all              : All output types, as type:value pairs, most of which
                         are never commonly used, probably for good reason.
      mini-private-key : 30 character Casascius mini private key
      private-key      : 32 byte ECDSA private key
      private-key-wif  : 33/34 byte ECDSA WIF private key
      public-key       : 33/65 byte ECDSA public key
      public-key-sha   : 32 byte SHA256(public key) hash
      public-key-rmd   : 20 byte RIPEMD160(SHA256(public key)) hash
      address          : 21 byte Bitcoin address (prefix + hash)
  --output-format : Output data format, must be one of :
      raw         : Raw binary
      hex         : Hexadecimal encoded
      base58      : Base58 encoded
      base58check : Base58Check encoded (most common)

  --input               : Specify input data on command line
  --input-file          : Specify file name to read for input ('-' for stdin)
  --batch               : Read multiple lines of input from --input-file
  --ignore-input-errors : Continue processing batch input if errors are found.

  --public-key-compression : Can be one of :
      auto         : determine compression from base58 private key (default)
      compressed   : force compressed public key
      uncompressed : force uncompressed public key
    (must be specified for raw/hex keys, should be auto for base58)
  --network        : Network type of keys, one of :
      bitcoin
      bitcoin-testnet
      litecoin
      litecoin-testnet
      feathercoin
      feathercoin-testnet
      dogecoin
      dogecoin-testnet
      quarkcoin
      quarkcoin-testnet
      darkcoin
      darkcoin-testnet
      jumbucks
      jumbucks-testnet
  --fix-base58check : Attempt to fix a Base58Check string by changing
                      characters until the checksum matches.
  --fix-base58check-change-chars : Maximum number of characters to change
                                   (default=3)

The mini-private-key input-type requires --input to be a 30 character ASCII string in valid mini private key format and --input-format to be raw.

If raw keys are input and an address output is required, then the key type prefix must be specified via --network

Examples

Manual address / key generation

Let's manually generate a Bitcoin address and private key for the purpose of an offline wallet (cold storage).

Create private key:

$ openssl rand 32 > key.bin

Inspect private key:

$ hexdump -e '32/1 "%02X" "\n"' key.bin

62A87AD3272B41E67108FEA10C57BA6ED609F2F7A2264A83B690CD45707090D1

Convert private key to WIF (Wallet Import Format). Since it is a raw key, the network type must be explicitally set (to bitcoin in this case) because it cannot be determined from the raw key :

$ ./bitcoin-tool \
    --network bitcoin \
    --input-type private-key \
    --input-format raw \
    --input-file key.bin \
    --output-type private-key-wif \
    --output-format base58check \
    --public-key-compression uncompressed

5JZjfs5wJv1gNkJXCmYpyj6VxciqPkwmK4yHW8zMmPN1PW7Hk7F

Specifying --public-key-compression is mandatory because the WIF output is different depending on which public key compression type you choose, and there is no way to guess from a raw private key.

Same again but compressed public key :

$ ./bitcoin-tool \
    --network bitcoin \
    --input-type private-key \
    --input-format raw \
    --input-file key.bin \
    --output-type private-key-wif \
    --output-format base58check \
    --public-key-compression compressed

KzXVLY4ni4yznz8LJwdUmNoGpUfebSxiakXRqcGAeuhihzaVe3Rz

Note that the WIF private key is longer with public key compression on, because an extra byte flag is stored to indicate that the public key should be compressed (the private key is exactly the same).

Show address for uncompressed WIF private key:

$ ./bitcoin-tool \
    --input-type private-key-wif \
    --input-format base58check \
    --input 5JZjfs5wJv1gNkJXCmYpyj6VxciqPkwmK4yHW8zMmPN1PW7Hk7F \
    --output-type address \
    --output-format base58check

1KYv3U6gWcxS5UfbNzP25eDEjd5PHHB5Gh

Show address for compressed WIF private key:

$ ./bitcoin-tool \
    --input-type private-key-wif \
    --input-format base58check \
    --input KzXVLY4ni4yznz8LJwdUmNoGpUfebSxiakXRqcGAeuhihzaVe3Rz \
    --output-type address \
    --output-format base58check

1Lm2DPqbhsutDkKoK9ZPPUkDKnGxQfpJLW

This demonstrates why it is necessary to be careful when converting raw private keys to addresses; the same private key will (almost definitely) result in two seperate addresses, one for each intermediate form of the public key.

Convert the WIF private key to a QR code so we can print it and import it easily later:

$ qrencode -d 300 -s 3 -l H 5JZjfs5wJv1gNkJXCmYpyj6VxciqPkwmK4yHW8zMmPN1PW7Hk7F -o privkey.png

Now you can receive Bitcoins using the address above, but you will need to import the private key into your wallet at a later time in order to spend them (bitcoind importprivkey, for the official client), or at least be able to sign transactions with that key (not necessarily online).

Generate address from random private key

./bitcoin-tool \
    --network bitcoin \
    --input-type private-key \
    --input-format raw \
    --input-file <(openssl rand 32) \
    --output-type address \
    --output-format base58check \
    --public-key-compression compressed

This outputs an address you can send Bitcoins to, if you want to loose them forever (because the private key is never output!).

Poor-mans brainwallet

Hash a text phrase with SHA256, which is then used as the private key to generate an address from.

Never use this example for an actual wallet, it will be stolen almost immediately! (I did a test with another dictionary word and it took all of 4 seconds for someone to steal it!)

This shows the --output-type all option, which spews out lots of unnecessary garbage which I can't imagine would ever be useful, but it does so because it can. So There.

./bitcoin-tool \
    --input-type private-key \
    --input-format raw \
    --input-file <(echo -n sausage|openssl dgst -sha256 -binary) \
    --public-key-compression uncompressed \
    --network bitcoin \
    --output-type all

address.hex:000511096ab078473911e0222fcbc3375314e2bab1
address.base58:156T6Af12SKCQGbjEWNeTkADhJNk
address.base58check:1TnnhMEgic5g4ttrCQyDopwqTs4hheuNZ
public-key-ripemd160.hex:0511096ab078473911e0222fcbc3375314e2bab1
public-key-ripemd160.base58:56T6Af12SKCQGbjEWNeTkADhJNk
public-key-ripemd160.base58check:TnnhMEgic5g4ttrCQyDopwqTs4k6XbAK
public-key-sha256.hex:b17978b7528353483429a758fb9ec833882a5ddbb27c1fc2bb4a66436f7e342f
public-key-sha256.base58:CwnbNMmu9yCkXE32543pfPAgVSynE2wjGYv9Mip4yrb8
public-key-sha256.base58check:2MAMBCve8eVyrbxxBzqn5HLNqqyc8CysKPdfaKPzA81mHxPvyu
public-key.hex:04a32ed011213146495f58d3ed83a6cc3fc0fd107d5fa2887bbc2fcea81e8bc84f650e81f4ddc84424daab546945f0d7d9dfd4dce39ce3776ee6b8ba78e6eddc7a
public-key.base58:QjfX2h4LdAA21NTa2K5dVcxcuQVTtvT3dL5JFLvxAMuCGKY3t8yCKNzJid8MHWbYmoHSRXAS9hggkhQUDiwaaGAV
public-key.base58check:3gKQTqtZhdBHDDe1echja7ac39tup3SnNSzwZSrnHb417QbL7T8JcTfW7GgEQsvhYrPqLsiraabne6xDrSGZ6bBB4S5YGM
private-key-wif.hex:8030caae2fcb7c34ecadfddc45e0a27e9103bd7cfc87730d7818cc096b1266a683
private-key-wif.base58:f5g1GA5uH4gsfEU6ANnGCzoe1VZvnZ1mYh3frnVSPR1nJ
private-key-wif.base58check:5JBmuBc64pVrKLyDc8ktyXJmAeEwKQogn6jsk6taeq8zRMtGZrE
private-key.hex:30caae2fcb7c34ecadfddc45e0a27e9103bd7cfc87730d7818cc096b1266a683
private-key.base58:4HTpd7gVSeVJDurhJKYGEYyFWMZRCNjSnXaEcan9K6Gz
private-key.base58check:NVKW9zzMvs4LawZwJztUZdx3R27Gwc4Hg6WvqqQxHMFkbn3Wz

Batch processing

You can read multiple lines of input from a text file and process individually with the --batch option. This requires the --input-file option to be set. This will be faster than spawning a new instance of bitcoin-tool for each line of a line - from a shell script, for example.

Generate 1000 random private keys in hex format keys=1000 ; openssl rand $[32*keys] | xxd -p -c32 > hexkeys

Convert all the private keys to addresses

./bitcoin-tool \
--batch \
--input-file hexkeys \
--input-format hex \
--input-type private-key \
--network bitcoin \
--public-key-compression compressed \
--output-type address \
--output-format base58check

bitcoin-tool's People

Contributors

clehner avatar hrobeers avatar jyap808 avatar matja 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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

bitcoin-tool's Issues

--batch: command not found

Dear dearest author, I need your help and I cant resolve it alone, I was try cygwin and followed all instruction, used command
bitcoin-tool --batch --input-file 1mix.txt --input-format hex --input-type private-key --network bitcoin --public-key-compression auto --output-type address --output-format base58check --output-file r.txt
also
./bitcoin-tool --batch --input-file 1mix.txt --input-format hex --input-type private-key --network bitcoin --public-key-compression auto --output-type address --output-format base58check --output-file r.txt
-bash: ./bitcoin-tool: No such file or directory, but directory exits. I removed ./bitcoin-tool or bitcoin-tool and used command
--batch --input-file 1mix.txt --input-format hex --input-type private-key --network bitcoin --public-key-compression auto --output-type address --output-format base58check --output-file r.txt
I see --batch: command not found
I removed --batch and I see --input-file: command not found
and no results. What I do wrong?? I removed cygwin and installed ubuntu on win10 and same result. Command keys=99999 ; openssl rand $[32*keys] | xxd -p -c32 > hexkeys working good without any one mistake. which command I have to add on terminal to convert these hex keys to addresses??
Cygwin path to folder cd /cygdrive/c/bitcoin-tool/
Ubuntu path C:\Users\Diana\AppData\Local\Packages\CanonicalGroupLimited.Ubuntu20.04onWindows_79rhkp1fndgsc\LocalState\rootfs\home\didi\bitcoin-tool if I am right? it is a right path? how I can add new file to folder to convert ,maybe wrong path?
I am girl but not stupid but here I feel I miss some small word in command, please help , I stay 1 week like this.

Problem compiling bitcoin-tool

Hello, has anyone had these compiling bugs fixed?

git clone https://github.com/matja/bitcoin-tool
Cloning into 'bitcoin-tool'...
remote: Counting objects: 259, done.
remote: Total 259 (delta 0), reused 0 (delta 0), pack-reused 259
Receiving objects: 100% (259/259), 103.26 KiB | 2.95 MiB/s, done.
Resolving deltas: 100% (169/169), done.
root@ip-172-31-8-228:~ # cd bitcoin-tool/
root@ip-172-31-8-228:~/bitcoin-tool # make test
make: "/root/bitcoin-tool/Makefile" line 2: Missing dependency operator
make: "/root/bitcoin-tool/Makefile" line 6: Need an operator
make: "/root/bitcoin-tool/Makefile" line 8: Need an operator
make: "/root/bitcoin-tool/Makefile" line 16: Need an operator
make: "/root/bitcoin-tool/Makefile" line 21: Need an operator
make: "/root/bitcoin-tool/Makefile" line 23: Missing dependency operator
make: "/root/bitcoin-tool/Makefile" line 24: warning: duplicate script for target "ifeq" ignored
make: "/root/bitcoin-tool/Makefile" line 5: warning: using previous script for "ifeq" defined here
make: "/root/bitcoin-tool/Makefile" line 25: Need an operator
make: Fatal errors encountered -- cannot continue
make: stopped in /root/bitcoin-tool

Cannot load compressed WIF

Let's say you generate a few private key WIFs in compressed format on bitaddress.org:
screen shot 2013-11-26 at 2 16 19 pm

Then try to load one of those into bitcoin-tool:

$ ./bitcoin-tool \
>     --input-type private-key \
>     --input-format base58check \
>     --input L5eRUKKJ3KV2QXVJuy9roFUkR4QUaUvRzMuRTnggnTdAobW5wC3q \
>     --output-type all
BitcoinTool_run: failed to load private key from base58 string [success]

However, if we run it against an uncompressed WIF it works perfectly (this WIF is from https://en.bitcoin.it/wiki/Wallet_import_format but any uncompressed WIF will do):

$ ./bitcoin-tool \
>     --input-type private-key \
>     --input-format base58check \
>     --input 5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ \
>     --output-type all
address-hex:00a65d1a239d4ec666643d350c7bb8fc44d2881128
address-base58:1GAehh7TsJAHuUAeKZcXf5CnwuGuGgyX2S
public-key-hex:04d0de0aaeaefad02b8bdc8a01a1b8b11c696bd3d66a2c5f10780d95b7df42645cd85228a6fb29940e858e7e55842ae2bd115d1ed7cc0e82d934e929c97648cb0a
public-key-base58:3nJ4XSefGZrjiWxsUSQmAJFYhuxJ8kSCvkCaKngUYBbiqpmWywaxmdgTcWbPio55q7CHDTNBK9mhuK9fbHg6nAKXqasq1B
private-key-hex:0c28fca386c7a227600b2fe50b7cae11ec86d3bf1fbe471be89827e19d72aa1d
private-key-base58:5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ

This looks like a great library, thanks for sharing it matja! If you can support compressed WIFs, I have a database of ~1 MM bitcoin WIFs that were generated using pycoin; I can run your tool on those WIFs and share the results.

how can use batch mode with --input-format base58check

./bitcoin-tool
--input-type private-key-wif
--input-format base58check
--input 5JKj55SsT2THBbLxgbXHtvmrrwp617z2pmfzJYY296MbmPFGpHv
--output-type all
--output-format base58check

how can i convert above to batch mode ?
i am looking to get only
private-key.hex:42d88ef1b198dc09ca8d968fa24495ceadff1193637071b2aa0aaeb0e124ed18

i tried like this

./bitcoin-tool
--input-type private-key-wif
--input-format base58check
--input-file UncompressedWIF.txt
--output-type private-key
--output-format hex

but i am getting

Invalid character (ASCII 10)
Failed to decode Base58Check input (invalid format).
You can use the --fix-base58check option to change the input string until the checksum is valid, but this may return a false positive match.

I can't run it using Cygwin on Windows 7

OS: Windows 7 x64
I'm using the recommended compiler Cygwin with the required packages.
if I used the following:
./bitcoin-tool \ --network bitcoin \ --input-type private-key \ --input-format raw \ --input-file key.bin \ --output-type private-key-wif \ --output-format base58check \ --public-key-compression compressed
it results
-bash: ./bitcoin-tool: Is a directory
it gives the same result even if I cd to the bitcoin-tool folder ..
also when I try:
apt-cyg http://github.com/matja/bitcoin-tool.git install
it results:

Installing http://github.com/matja/bitcoin-tool.git
Unable to locate package http://github.com/matja/bitcoin-tool.git

I tried make -f Makefile too .. but it results undefined reference to __errno

I have like 2000 text files filled with random WIF (~300M) keys which I thought this tool may help me to convert them to addresses ..
can someone please explain to me how to use it correctly? I'm totally new to Cygwin and I truly have no idea what to do .. I have been trying for like a week .. I searched for any solution or anyone who may have faced the same issues but not so many people using this tool ..
Also, I tried to install Gentoo on my other laptop .. and it is really hard work and still can't install Gentoo ๐Ÿ˜†
It would be really appreciated if you can explain to me how to use this tool.
Thanks in advance :)
P.S: I know it is mentioned in the README file that it was tested on Windows10 .. I tried it on Windows10 .. same results .. and by the way .. is it only me or the cygwin reads //comments as code lines I had to remove the comments manually!
@matja

openssl dgst -sha256 -binary

Useful tool but wouldn't it be better do it inline instead of input redirection? Perhaps something like RIPEMD160(SHA256(s, 65, 0), SHA256_DIGEST_LENGTH, rmd + 1) to encode the coin using openssl headers.

Input file cannot be read

./bitcoin-tool --output-format base58check --public-key-compression uncompressed --network bitcoin --input-type private-key --input-format hex --output-type private-key-wif --input-file passcrck.txt
Invalid character (ASCII=58) at offset 40
Failed to decode hex input (invalid format).

I have tried everything I even converted the file to unicode characters but I am still getting the same error.

option to skip invalid inputs when in batch mode

I'm trying to recover a private key and know most of it and am using a program to generate the possible full private keys. So I'm calling bitcoin-tool like so:

./generate-keys | bitcoin-tool --batch --network bitcoin --input-type private-key-wif --input-format base58check --input-file - --output-type address --output-format base58check --public-key-compression compressed

But bitcoin-tool exits when it encounters any keys which fail to decode properly with base58check, so I'm forced to call bitcoin-tool in a shell script for each individual key, which is a lot slower. Is it possible to add an option to just skip invalid input when under batch mode?

Core dump when trying example from docs

When trying this (straight from your examples page), I the program crashes:

/bitcoin-tool --input-type private-key-wif --input-format base58check --input KzXVLY4ni4yznz8LJwdUmNoGpUfebSxiakXRqcGAeuhihzaVe3Rz --output-type address --output-format base58check

This is on Fedora 20, compiled from master source.

Compile using MinGW/Windows

To compile this tool under MinGW/Windows there is necessary to change some:

base58.c
#include <alloca.h> -> #include <malloc.h>

Makefile
add a -lgdi32 after -lcrypto

-lgdi32 required by OpenSSL under MinGW/Windows.

Segfault in batch mode

I've been testing out batch mode extensively. Bitcoin-tool doesn't pipe out the result immediately which is probably the cause of the problem.

If you feed it a file that's ~20 mil keys, it will run for a while and segfault. Less than 15 mil keys is okay, though it will probably segfault on some system.

I've implemented some of your functions in my program, and it's working very well.
It doesn't segfault if you fprintf to stdout and free memory after every loop for each line.

You're right that generating the public key is the biggest bottleneck.
When generating compressed and uncompressed RIPEMD160, I'm getting ~1000 keys/sec.

This is with no IO bottleneck. The program is not piping to stdout.
I got this number by setting a loop counter and incrementing at the end of every loop.

Running multiple jobs with GNU Parallel helps, but is there no other way to speed up public key calculation?

Can we use some other secp256k1 library that is faster
(such as this one https://github.com/bitcoin/secp256k1)
or will the performance gain by negligible?

Thanks for all the work you've done. It really helped me.

Is public-key-rmd supported?

Hi there,

I get "unsupported input type", whenever I try to do something like this:

./bitcoin-tool --input-type public-key-rmd --input-format hex --input 62E907B15CBF27D5425399EBF6F0FB50EBB88F18 --output-type address --output-format base58check

Though, according to the command line help, this should work?

Thanks heaps!

prvkey to pubkey

when converting 20mil hex privatekey to pubkeys, take 3 hours, when pubkeys to address, take only 16 minutes
why prvkey to pubkey take toooo mych time, any solution, or you have plan to update these tools to use cuda, where aspected works would be in min/sec
hope see your updates regarding this issue

Just can't uncompress public key

Trying to uncompress public key:

$ ./bitcoin-tool --input-type public-key --input-format hex --input 02710f15e674fbbb328272ea7de191715275c7a814a6d18a59dd41f3ef4535d9ea --output-type public-key --output-format hex --public-key-compression uncompressed
02710f15e674fbbb328272ea7de191715275c7a814a6d18a59dd41f3ef4535d9ea
$ ./bitcoin-tool --input-type public-key --input-format hex --input 02710f15e674fbbb328272ea7de191715275c7a814a6d18a59dd41f3ef4535d9ea --output-type all --network bitcoin --public-key-compression uncompressed
address.hex:00dac839ce05cf9504cb4ef3652845c33f3effc3eb
address.base58:143nUvkwEKCxPFhqRwDpGaS5Uenka
address.base58check:1LwpAkb3yXd9x96o6wyNBCN75fcvkqTLhn
public-key-ripemd160.hex:dac839ce05cf9504cb4ef3652845c33f3effc3eb
public-key-ripemd160.base58:43nUvkwEKCxPFhqRwDpGaS5Uenka
public-key-ripemd160.base58check:LwpAkb3yXd9x96o6wyNBCN75fcvniKbzG
public-key-sha256.hex:42177ebe8ecee72d311b102e8de2b4baa80853e1384d9376e3fd14f7527a8386
public-key-sha256.base58:5SzgrrWTZE8AekBe4xPyWkrAbT44V8461z53Bk8ZgYE1
public-key-sha256.base58check:W7E6SwQmcH85QGJQLC66nR8i71ssKC8R4JxG7pW3FSUTDif3a
public-key.hex:02710f15e674fbbb328272ea7de191715275c7a814a6d18a59dd41f3ef4535d9ea
public-key.base58:j4y9s95MeM9s37bsY3eZxNcgiPBpsjUqeKFjFcCGfevu
public-key.base58check:5kHHuFqsrCGvJ57RNpMp9Bu56ak8nTi4TctPxPJZpzu57ounjZ

Please I need some help

Hi, thanks for creating tool, I'm really thankful.
I'm currently using it to generate a large amount of keys and it's taking a very long time because I'm loading a text file from a shell script and piping the hex output to bitcoin-tool 's input parameter.
It's taking it over 3 days to generate 100 million keys.
Would it be possible to modify this to load a large text file into memory and process it line by line?

Please help, I would have no problem offering some donation for your time.
I couldn't find the contact info in your profile.
Best regards.

bitcoin publickey finder

do you have any tools to find a bitcoin public key from a btc address?
I have a btc address and I am looking for publickey started with 02 or 03 or 04
do you have anything to help?

Can --batch mode return both address and private key pair?

Hi

I am currently testing bitcoin-tool for a project.

I have 2 questions :

  • I would like to know if the current version of bitcoin-tool permits to return both address and private key pairs ? I have tried to use it but from my trial, it seems that the batch mode can only return one output-type. Which is a bit annoying since only having an address without the associated private key is not very useful in terms of bitcoin usage.

  • How hard would it be to modify the code in order to permit to --batch mode to return both address and private key pairs?

Thanks
Xavier

Is this library still being actively developed/supported?

Hello people and the library author. Could you please advise if this library is still actively supported, or would you recommend using a different command line tool when starting a new project that would call the tool through command line to automate some bitcoin-related tasks?

bech32

Hi,
Thank you for adding bech32 addresses, but there is a problem with decoding long bech32 addresses. Is it possible to modify the decoding of long bech32 addresses?
Example: bc1q3026x9qhu5ucsx6fcly682zu54ma0w3js4nvasp53lx0rkyh8k8scn8yp5
Thank.

OpenSSL v1.1 compatibility

OpenSSL types cannot be stack allocated anymore.
They are made opaque to the outside through forward declarations.

Just a heads up that I'll fix this. PR coming later this week.

Compilation time

How many time need to compile bitcoin-tool? PC freeze nearly day

SegWit

What is the nature of the work required to add SegWit addresses to bitcoin-tool?
Is it a big job?

how to use tool as hex-to-base58 conversor?

I need to convert usual hexadecimal hashes (ex. SHA1 by sha1sum * > sha1sum.txt terminal command) to base58 strings... No bitcoin context... What is the simplest way to do this convesion?


PS: perhaps something as ./bitcoin-tool ... --input-format raw ... --output-format base58check but is not obvius how to obtain a simple and direct conversion.

address to public-key-rmd

i have address
bc1qsssfz2x83e8mlhwl52n7y5p8c3rj5r4yk0744y
i want convert to hash160 (20byte)
could you guide what command you saying to work
i tried all way its return always error
thankx for update me

BitcoinResult Bitcoin_FixBase58Check() fn signature, implementation, call mismatch ?

base58.h file contains the function signature as follows:

BitcoinResult Bitcoin_FixBase58Check(
char *fixed_output, size_t fixed_output_buffer_size,
size_t *fixed_output_size, uint8_t *output, size_t output_buffer_size,
size_t *decoded_output_size, const char *input, size_t input_size,
unsigned change_chars, unsigned insert_chars, unsigned remove_chars);

The implementation is in file base58.c and the naming or order of last two parameters are different.

BitcoinResult Bitcoin_FixBase58Check(
char *fixed_output, size_t fixed_output_buffer_size, size_t *fixed_output_size,
uint8_t *output, size_t output_buffer_size, size_t *decoded_output_size,
const char *input, size_t input_size,
unsigned change_chars,
unsigned remove_chars,
unsigned insert_chars)
{
}

Function is called from main.c and there the naming of last two parameters follows the signature.

				result = Bitcoin_FixBase58Check(
					output_base58, output_base58_buffer_size, &output_base58_size,
					self->input_raw, sizeof(self->input_raw), &self->input_raw_size,
					self->input, self->input_size,
					self->options.fix_base58_change_chars,
					self->options.fix_base58_insert_chars,
					self->options.fix_base58_remove_chars)

My understanding is that when running the code the fix_base58_insert_chars and fix_base58_remove_chars might not be used properly. Compiler complains about the implementation that remove_chars is not used. So when calling the function, ...insert_chars are not used and ... remove_chars are used as insert_chars ?

Noticed the issue when trying to get rid of compiler warnings in my forked revision. I haven't dig deep into the code. I just build a simple wrapper for tool so that it can be used as library from my code. I have pushed my changes into fork that can be found at:

https://github.com/pulmark/bitcoin-tool

Using the tool as library works when called via wrapper. I redirected the results back to my app by using a simple callback also. The implementation details are in .lib directory in my fork.

I will push my app into github later this year or in the beginning of next year.

Great tool, EC_POINT_mul question

I am trying to learn EC/crpytography and this tool is very useful but I am little confused, given

BN_bin2bn(private_key.data, BITCOIN_PRIVATE_KEY_SIZE, &private_key_bn);
EC_POINT_mul(group, ec_public, &private_key_bn, NULL, NULL, ctx);

how can I display the private key? in Base58Check format?

public-key-sha address generation

bitcoin-tool --input-file <(echo $MY_STRING | openssl sha256 -binary) \
--input-type public-key-sha \
--input-format raw \
--network bitcoin \
--output-format base58check \
--output-type address \
--public-key-compression compressed

Returns the same address for every $MY_STRING.
I will try to fix when I find some time.

bech32 (SegWit) long address

Hi,
address like:
bc1qa5wkgaew2dkv56kfvj49j0av5nml45x9ek9hz6 is working. But longer (valid) address like:
bc1qvpgyac88vqtslewxu7yu9dqwp8rd83zch55zpm3xgn3mgg72w3kqv0s8qa throws error:
"Invalid size input for address: expected 21 bytes but got 33 bytes instead."

./bitcoin-tool \
    --network bitcoin \
    --input-type address \
    --input-format bech32 \
    --input "bc1qgdjqv0av3q56jvd82tkdjpy7gdp9ut8tlqmgrpmv24sq90ecnvqqjwvw97" \
    --ignore-input-errors \
    --output-type public-key-rmd \
    --output-format hex

Invalid size input for address: expected 21 bytes but got 33 bytes instead.

---
./bitcoin-tool \
    --network bitcoin \
    --input-type address \
    --input-format bech32 \
    --input "bc1qhmc0vk4xzr37ayv7tlyhns7x4dk04tyvflk8ey" \
    --ignore-input-errors \
    --output-type public-key-rmd \
    --output-format hex

bef0f65aa610e3ee919e5fc979c3c6ab6cfaac8c

Also please note that --input-format bech32 is NOT at title page neither help --help.
Is there really req. for "bech32" param? Isn't "address" enought?
To add 1xxx, 3xxx also bc1xxx and bc1xxx....xxx address types.

Note: SegWit #26

private-key-bip38

Hi,

I'm thinking about adding a private-key-bip38 option to your tool.
Are you open to such a contribution?

Kind regards,
hrobeers

wrong base58check to hex encoding

Hi. Bug:
This command line:
bitcoin-tool --input-type address --input-format base58check --output-type address --output-format hex --input 15cLKZtKbqeSVxXWjhi5i4DjeftC8ky3bo

Give me following hex digit:
00328f307df6191bacf2bfdccfed12246fc19debd2

Going to Online Address Validator and Base58 Encoder/Decoder
http://lenschulwitz.com/base58
paste hex and see this:
1hrXJp891VFJ8KLGRyszDoqLeJJV

Correct work, for example:
bx base58-decode 15cLKZtKbqeSVxXWjhi5i4DjeftC8ky3bo
00328f307df6191bacf2bfdccfed12246fc19debd24913a03a

http://lenschulwitz.com/base58 give:
15cLKZtKbqeSVxXWjhi5i4DjeftC8ky3bo

misleading help for input in compressed wif format

bitcoin-tool --input-type private-key --input-format base58check --input cat k1 --output-type all

This resulted in the output:

invalid size input for private key: expected 32 bytes but got 34 bytes (did you mean "--input-format private-key-wif"?)

But the real hint would be:

bitcoin-tool --input-type private-key-wif --input-format base58check --input cat k1 --output-type all

Thus the input-type parameter was wrong, not the input-format parameter.

Your tool did make my day, anyway. Thanks a lot!

LICENSE missing

This project is missing a license.
I assumed this project to be very liberally licensed, but it's not explicitly stated, which legally means no rights are provided to the use and distribution of this code.

Please choose a license so I can continue contributing to this codebase.
Any FSF-approved license is fine for me.

--output-type all results in 5 errors

After adding Bech32 support in #36 the example from the README.md yields multiple errors.

./bitcoin-tool \
    --input-type private-key \
    --input-format raw \
    --input-file <(echo -n sausage|openssl dgst -sha256 -binary) \
    --public-key-compression uncompressed \
    --network bitcoin \
    --output-type all

output:

address.hex:000511096ab078473911e0222fcbc3375314e2bab1
address.base58:156T6Af12SKCQGbjEWNeTkADhJNk
address.base58check:1TnnhMEgic5g4ttrCQyDopwqTs4hheuNZ
address.bech32:bc1qq5gsj64s0prnjy0qyghuhseh2v2w9w43dqsgr5
address-checksum.hex:000511096ab078473911e0222fcbc3375314e2bab101490d3a
address-checksum.base58:1TnnhMEgic5g4ttrCQyDopwqTs4hheuNZ
Failed to encode raw output data (unknown result code)
address-checksum.bech32:public-key-ripemd160.hex:0511096ab078473911e0222fcbc3375314e2bab1
public-key-ripemd160.base58:56T6Af12SKCQGbjEWNeTkADhJNk
public-key-ripemd160.base58check:TnnhMEgic5g4ttrCQyDopwqTs4k6XbAK
Failed to encode raw output data (unknown result code)
public-key-ripemd160.bech32:public-key-sha256.hex:b17978b7528353483429a758fb9ec833882a5ddbb27c1fc2bb4a66436f7e342f
public-key-sha256.base58:CwnbNMmu9yCkXE32543pfPAgVSynE2wjGYv9Mip4yrb8
public-key-sha256.base58check:2MAMBCve8eVyrbxxBzqn5HLNqqyc8CysKPdfaKPzA81mHxPvyu
Failed to encode raw output data (unknown result code)
public-key-sha256.bech32:public-key.hex:04a32ed011213146495f58d3ed83a6cc3fc0fd107d5fa2887bbc2fcea81e8bc84f650e81f4ddc84424daab546945f0d7d9dfd4dce39ce3776ee6b8ba78e6eddc7a
public-key.base58:QjfX2h4LdAA21NTa2K5dVcxcuQVTtvT3dL5JFLvxAMuCGKY3t8yCKNzJid8MHWbYmoHSRXAS9hggkhQUDiwaaGAV
public-key.base58check:3gKQTqtZhdBHDDe1echja7ac39tup3SnNSzwZSrnHb417QbL7T8JcTfW7GgEQsvhYrPqLsiraabne6xDrSGZ6bBB4S5YGM
Failed to encode raw output data (unknown result code)
public-key.bech32:private-key-wif.hex:8030caae2fcb7c34ecadfddc45e0a27e9103bd7cfc87730d7818cc096b1266a683
private-key-wif.base58:f5g1GA5uH4gsfEU6ANnGCzoe1VZvnZ1mYh3frnVSPR1nJ
private-key-wif.base58check:5JBmuBc64pVrKLyDc8ktyXJmAeEwKQogn6jsk6taeq8zRMtGZrE
private-key-wif.bech32:bc1qxr92ut7t0s6wet0am3z7pgn7jypm6l8usaes67qcesykkynx56psr2ua62
private-key.hex:30caae2fcb7c34ecadfddc45e0a27e9103bd7cfc87730d7818cc096b1266a683
private-key.base58:4HTpd7gVSeVJDurhJKYGEYyFWMZRCNjSnXaEcan9K6Gz
private-key.base58check:NVKW9zzMvs4LawZwJztUZdx3R27Gwc4Hg6WvqqQxHMFkbn3Wz
Failed to encode raw output data (unknown result code)
private-key.bech32:

Also, there is some redirection order problem as Failed to encode raw output data (unknown result code) messages are thrown before the actual problematic line. Those lines are getting mixed with the next lines (no newline characters?). It should look more or less like this:

address.hex:000511096ab078473911e0222fcbc3375314e2bab1
address.base58:156T6Af12SKCQGbjEWNeTkADhJNk
address.base58check:1TnnhMEgic5g4ttrCQyDopwqTs4hheuNZ
address.bech32:bc1qq5gsj64s0prnjy0qyghuhseh2v2w9w43dqsgr5
address-checksum.hex:000511096ab078473911e0222fcbc3375314e2bab101490d3a
address-checksum.base58:1TnnhMEgic5g4ttrCQyDopwqTs4hheuNZ
address-checksum.bech32:Failed to encode raw output data (unknown result code)
public-key-ripemd160.hex:0511096ab078473911e0222fcbc3375314e2bab1
public-key-ripemd160.base58:56T6Af12SKCQGbjEWNeTkADhJNk
public-key-ripemd160.base58check:TnnhMEgic5g4ttrCQyDopwqTs4k6XbAK
public-key-ripemd160.bech32:Failed to encode raw output data (unknown result code)
public-key-sha256.hex:b17978b7528353483429a758fb9ec833882a5ddbb27c1fc2bb4a66436f7e342f
public-key-sha256.base58:CwnbNMmu9yCkXE32543pfPAgVSynE2wjGYv9Mip4yrb8
public-key-sha256.base58check:2MAMBCve8eVyrbxxBzqn5HLNqqyc8CysKPdfaKPzA81mHxPvyu
public-key-sha256.bech32:Failed to encode raw output data (unknown result code)
public-key.hex:04a32ed011213146495f58d3ed83a6cc3fc0fd107d5fa2887bbc2fcea81e8bc84f650e81f4ddc84424daab546945f0d7d9dfd4dce39ce3776ee6b8ba78e6eddc7a
public-key.base58:QjfX2h4LdAA21NTa2K5dVcxcuQVTtvT3dL5JFLvxAMuCGKY3t8yCKNzJid8MHWbYmoHSRXAS9hggkhQUDiwaaGAV
public-key.base58check:3gKQTqtZhdBHDDe1echja7ac39tup3SnNSzwZSrnHb417QbL7T8JcTfW7GgEQsvhYrPqLsiraabne6xDrSGZ6bBB4S5YGM
public-key.bech32:Failed to encode raw output data (unknown result code)
private-key-wif.hex:8030caae2fcb7c34ecadfddc45e0a27e9103bd7cfc87730d7818cc096b1266a683
private-key-wif.base58:f5g1GA5uH4gsfEU6ANnGCzoe1VZvnZ1mYh3frnVSPR1nJ
private-key-wif.base58check:5JBmuBc64pVrKLyDc8ktyXJmAeEwKQogn6jsk6taeq8zRMtGZrE
private-key-wif.bech32:bc1qxr92ut7t0s6wet0am3z7pgn7jypm6l8usaes67qcesykkynx56psr2ua62
private-key.hex:30caae2fcb7c34ecadfddc45e0a27e9103bd7cfc87730d7818cc096b1266a683
private-key.base58:4HTpd7gVSeVJDurhJKYGEYyFWMZRCNjSnXaEcan9K6Gz
private-key.base58check:NVKW9zzMvs4LawZwJztUZdx3R27Gwc4Hg6WvqqQxHMFkbn3Wz
private-key.bech32:Failed to encode raw output data (unknown result code)

If it is hard to spot above, the following lines throw errors before them:

address-checksum.bech32:
public-key-ripemd160.bech32:
public-key-sha256.bech32:
public-key.bech32:
private-key.bech32:

Private key too short

Hi,

I am using the tool to derive dogecoin private keys from 64bit hex values for import into multidoge. However the generated keys are 50 (sometimes 51) characters and multidoge exported keys have 53 characters. Any ideas?

Here is the command I'm running:

bitcoin-tool --batch --network dogecoin --input-type private-key --input-format hex --input-file ../recovered-keys.txt --output-type private-key --output-format base58check --public-key-compression uncompressed

Thanks.

Bech32 possible for uncompressed key

#36 added bech32 support as input and output address format. It is now possible to generate Bech32 formatted Bitcoin address even for uncompressed public key. Example:

./bitcoin-tool \
    --input-type private-key \
    --input-format raw \
    --input-file <(echo -n sausage|openssl dgst -sha256 -binary) \
    --public-key-compression uncompressed \
    --network bitcoin \
    --output-type address \
    --output-format bech32

This will return:
bc1qq5gsj64s0prnjy0qyghuhseh2v2w9w43dqsgr5
However, this is not a valid Bitcoin address! Native SegWit addresses are generated only based on compressed public key (see https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki#Restrictions_on_public_key_type).

I recommend adding a warning message when trying to generate Bech32 address based on uncompressed pubkey, similar that is implemented when manually defining compression for --input-type private-key-wif --input-format base58check
using --input-format base58check with --public-key-compression other than auto to override the WIF compression type is very unusual, please be sure what you are doing!

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.