BitShares Forum

Main => General Discussion => Topic started by: xeroc on December 07, 2014, 11:16:27 pm

Title: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: xeroc on December 07, 2014, 11:16:27 pm
I wrote a python script (copy-paste + modification) to get a random private key and the corresponding bts pubkey and bts address ..
https://github.com/xeroc/pytshares/blob/master/genbtskey.py

THAT CODE IS UNTESTED!!
USE WITH CAUTION!

Crosschecking results with https://bitsharestalk.org/index.php?topic=8907.msg115470#msg115470
are looking good ..
maybe there is a dev that can take a look and confirm/review the python code for correctness ..


For those not getting the reason for this script.
Suppose you want to have coldstorage ... how do you create a private key and the corresponding pubkey/address that you can fund WITHOUT installing the full client?!

I'd love to see someone code this in JS and have a offline Website like brainwallet.org for that too ...
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: arhag on December 08, 2014, 01:11:29 am
Cool. A JavaScript version with all necessary dependencies bundled would probably be ideal, since everyone has a browser that can run it.

Python is pretty ubiquitous on Linux, but even this code required me to install the ecdsa python module that my base python installation on Ubuntu 14.04 didn't have (sudo apt-get install python-ecdsa).

If I was trying to use this on an Ubuntu live CD, I would also have to put python-ecdsa_0.10-2_all.deb (http://packages.ubuntu.com/trusty/all/python-ecdsa/download) on my flash drive to set up the ecdsa python module before being able to run your script (since connecting to the internet to install it is obviously unacceptable).

Also it would be really great if the python script also optionally allowed the user to provide a passphrase to encrypt the private key and display that in the results as well. I would prefer the plaintext WIF private key to never actually exist anywhere other than the live environment. So, if I am writing down the private key on paper or storing in a password manager, I want it to be in encrypted form where the unique long passphrase is in my head and only ever typed on live Linux environments.

Of course this can also be done manually using openssl:

Then to decrypt it back into the plaintext WIF private key (also this should be done immediately after the previous steps to verify that you encrypted it properly):

Finally, although this code is good for generating the keys and funding the balances. It still does not address the offline transaction signing part (which toast has been working on). That will require some minimal BitShares code that can unpack and understand a transaction to present to the user what the transaction is doing (sending a certain amount of funds from these balances to these addresses) and provide a way for them to sign the transaction by providing the private keys necessary. Understanding the transaction and presenting that information to the user is important (rather than just blindly signing a transaction digest), because the online tool that generated the unsigned transaction in the first place may have been compromised to instead create a transaction that sends all of the user's funds to a hacker's address instead. 

Anyway, it would be ideal to have all of the above in both a self-contained executable with absolutely minimal dependencies that runs a CLI version of the tool, as well as a Javascript  version that provides a more familiar UI interface that people can run in the browser of a live Linux environment.
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: arhag on December 08, 2014, 02:04:42 am
Actually, you know what's better than encrypting the generated private key with a passphrase?

Deriving a 256-bit number from the passphrase and doing modular addition with that number and the generated private key to get a new private key. That way you can first generate a random private key (back that up for safe keeping), then use that and various passphrases to generate new private keys (and corresponding BTS addresses). Then use one of those addresses to store your funds.

The beauty of that approach is that it provides plausible deniability. You can have two different passphrases (the real one and a fake one) to generate two different BTS addresses (real and fake). You fund both addresses, but you put just enough to be plausible in the fake one and put the rest of your funds in the real one.

Now even if someone steals your paper backup of the original random private key and extorts you to get the passphrase that allows them to derive the private key that unlocks the funds, you can provide the fake passphrase and let them get away with the small amount of decoy money stored there while keeping the rest of your wealth safe. This of course assumes that the attacker doesn't know how much money you have stored in which balances, or else he could continue extorting you until you give up the passphrase that unlocks the balance that he knows belongs to you. I have to say that blockchain analysis makes it actually pretty easy for the attacker to be fairly confident a balance belongs to you (sucks for you if he is wrong I guess), so perhaps this wouldn't be all that useful in practice until CryptoNote-like privacy is implemented on the blockchain.

Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: merockstar on December 08, 2014, 03:37:30 am
I've been waiting eagerly for this. Can't wait until it's refined and field tested.
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: pc on December 08, 2014, 08:51:53 am
Are you aware of programs/utils/bts_create_key in the bitshares repo?
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: monsterer on December 08, 2014, 11:43:02 am
If it helps you any with your unit tests, here is a list of:

* private keys
* bitcoin addresses
* hex bitcoin public keys
* BTS public keys
* BTS addresses

They are all corresponding, so the private key for row I corresponds to the bitcoin address, hex public key, BTS pub key and BTS adress for row I.

Code: [Select]
List<string> m_bitcoinPrivKeys = new List<string>()
{
"5HqUkGuo62BfcJU5vNhTXKJRXuUi9QSE6jp8C3uBJ2BVHtB8WSd",
"5JWcdkhL3w4RkVPcZMdJsjos22yB5cSkPExerktvKnRNZR5gx1S",
"5HvVz6XMx84aC5KaaBbwYrRLvWE46cH6zVnv4827SBPLorg76oq",
"5Jete5oFNjjk3aUMkKuxgAXsp7ZyhgJbYNiNjHLvq5xzXkiqw7R",
"5KDT58ksNsVKjYShG4Ls5ZtredybSxzmKec8juj7CojZj6LPRF7"
};

List<string> m_bitcoinAddresses = new List<string>()
{
"141fYYgjgTfxWCzUhFwVrad54EWi8Yw29a",
"19854zGaBhcgHV2hZa6bzqMBW5kHCbw7YA",
"1G7qw8FiVfHEFrSt3tDi6YgfAdrDrEM44Z",
"12c7KAAZfpREaQZuvjC5EhpoN6si9vekqK",
"1Gu5191CVHmaoU3Zz3prept87jjnpFDrXL"
};

List<string> m_bitcoinPubKeys = new List<string>()
{
"04a05c6fd57267cc0f1b82e785f0261e1d25f6751978db972b39747393c489e614a6a45b3c07fe7e24c93846d8e2ce302fa7a9dadda308762bf63db28743d20bba",
"04906435f6f9ce6f3d4e4cf8d3d0ddce209a83277738ffdc7eae6308f4ed2963df0da8746cf13a6189a281965c580f42415d86e96c232a8925ea153254bb879f60",
"045836d5ecf8eb2572f8d3e45e9a401c3acbfffcabe76697ca3539b428aa8641b827fbcad3334e0bfc636463efb494e4a57525fce15721e2e15cfff15808859389",
"04a71eb3edee13ab02f16900f820f66d59028f68ca5a1f48d1676fad9fd78e246191d4619203ce7fa1161a3fc6d3466adcae232559db620b3f74e7fea420c9a60d",
"041e5080611e2f1d9d7a61146ae0dda74181ea557044cf6c418d9ffccd9ebefcf052895a13e0b184a10a95d82d5399a6ecdb36b4f852c6e8774a3aea658f626d64"
};

List<string> m_btsPubKeys = new List<string>()
{
"BTS677ZZd62Ca7SoUJoT1CytBhj4aJewzzi8tQZxYNqpSSK69FTuF",
"BTS5z5e3BawwMY6UmcBQxYpkKZ8QQm4wdtS4KMZiWAcWBUC3RJuLT",
"BTS7W5qsanXHgRAZPijbrLMDwX6VmHqUdL2s8PZiYKD5h1R7JaqRJ",
"BTS86qPFWptPfUNKVi6hemeEWshoLerN6JvzCvFjqnRSEJg7nackU",
"BTS57qhJwt9hZtBsGgV7J5ZPHFi5r5MEeommYnFpDb6grK3qev2qX"
};

List<string> m_btsAddresses = new List<string>()
{
"BTSFN9r6VYzBK8EKtMewfNbfiGCr56pHDBFi",
"BTSdXrrTXimLb6TEt3nHnePwFmBT6Cck112",
"BTSJQUAt4gz4civ8gSs5srTK4r82F7HvpChk",
"BTSFPXXHXXGbyTBwdKoJaAPXRnhFNtTRS4EL",
"BTS3qXyZnjJneeAddgNDYNYXbF7ARZrRv5dr"
};

I created these for my own unit tests in C# :)
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: merockstar on December 08, 2014, 02:20:15 pm
Are you aware of programs/utils/bts_create_key in the bitshares repo?

no I wasn't. I can just put that (alone) on a flashdrive and run it offline in a live-cd?
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: xeroc on December 08, 2014, 02:36:21 pm
Are you aware of programs/utils/bts_create_key in the bitshares repo?

no I wasn't. I can just put that (alone) on a flashdrive and run it offline in a live-cd?
The issue with that one is that ideally .. you need to compile it on a offline ci
omputer running a livelinux of some kind ..
while python is almost stand-alone

Javascript would ve alot nicer though
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: merockstar on December 08, 2014, 02:45:07 pm
Are you aware of programs/utils/bts_create_key in the bitshares repo?

no I wasn't. I can just put that (alone) on a flashdrive and run it offline in a live-cd?
The issue with that one is that ideally .. you need to compile it on a offline ci
omputer running a livelinux of some kind ..
while python is almost stand-alone

Javascript would ve alot nicer though

i'd also love a brainwallet feature. I know it's currently possible but it should be simplified.
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: xeroc on December 08, 2014, 04:01:39 pm
I am going to give it a try with JS ..
found this thing and will try to implement that stuff for BTS
http://procbits.com/2013/08/27/generating-a-bitcoin-address-with-javascript

edit: it seems I am too stupid to learn JS :)
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: xeroc on December 08, 2014, 04:02:27 pm
If it helps you any with your unit tests, here is a list of:

* private keys
* bitcoin addresses
* hex bitcoin public keys
* BTS public keys
* BTS addresses

They are all corresponding, so the private key for row I corresponds to the bitcoin address, hex public key, BTS pub key and BTS adress for row I.

Code: [Select]
List<string> m_bitcoinPrivKeys = new List<string>()
{
"5HqUkGuo62BfcJU5vNhTXKJRXuUi9QSE6jp8C3uBJ2BVHtB8WSd",
"5JWcdkhL3w4RkVPcZMdJsjos22yB5cSkPExerktvKnRNZR5gx1S",
"5HvVz6XMx84aC5KaaBbwYrRLvWE46cH6zVnv4827SBPLorg76oq",
"5Jete5oFNjjk3aUMkKuxgAXsp7ZyhgJbYNiNjHLvq5xzXkiqw7R",
"5KDT58ksNsVKjYShG4Ls5ZtredybSxzmKec8juj7CojZj6LPRF7"
};

List<string> m_bitcoinAddresses = new List<string>()
{
"141fYYgjgTfxWCzUhFwVrad54EWi8Yw29a",
"19854zGaBhcgHV2hZa6bzqMBW5kHCbw7YA",
"1G7qw8FiVfHEFrSt3tDi6YgfAdrDrEM44Z",
"12c7KAAZfpREaQZuvjC5EhpoN6si9vekqK",
"1Gu5191CVHmaoU3Zz3prept87jjnpFDrXL"
};

List<string> m_bitcoinPubKeys = new List<string>()
{
"04a05c6fd57267cc0f1b82e785f0261e1d25f6751978db972b39747393c489e614a6a45b3c07fe7e24c93846d8e2ce302fa7a9dadda308762bf63db28743d20bba",
"04906435f6f9ce6f3d4e4cf8d3d0ddce209a83277738ffdc7eae6308f4ed2963df0da8746cf13a6189a281965c580f42415d86e96c232a8925ea153254bb879f60",
"045836d5ecf8eb2572f8d3e45e9a401c3acbfffcabe76697ca3539b428aa8641b827fbcad3334e0bfc636463efb494e4a57525fce15721e2e15cfff15808859389",
"04a71eb3edee13ab02f16900f820f66d59028f68ca5a1f48d1676fad9fd78e246191d4619203ce7fa1161a3fc6d3466adcae232559db620b3f74e7fea420c9a60d",
"041e5080611e2f1d9d7a61146ae0dda74181ea557044cf6c418d9ffccd9ebefcf052895a13e0b184a10a95d82d5399a6ecdb36b4f852c6e8774a3aea658f626d64"
};

List<string> m_btsPubKeys = new List<string>()
{
"BTS677ZZd62Ca7SoUJoT1CytBhj4aJewzzi8tQZxYNqpSSK69FTuF",
"BTS5z5e3BawwMY6UmcBQxYpkKZ8QQm4wdtS4KMZiWAcWBUC3RJuLT",
"BTS7W5qsanXHgRAZPijbrLMDwX6VmHqUdL2s8PZiYKD5h1R7JaqRJ",
"BTS86qPFWptPfUNKVi6hemeEWshoLerN6JvzCvFjqnRSEJg7nackU",
"BTS57qhJwt9hZtBsGgV7J5ZPHFi5r5MEeommYnFpDb6grK3qev2qX"
};

List<string> m_btsAddresses = new List<string>()
{
"BTSFN9r6VYzBK8EKtMewfNbfiGCr56pHDBFi",
"BTSdXrrTXimLb6TEt3nHnePwFmBT6Cck112",
"BTSJQUAt4gz4civ8gSs5srTK4r82F7HvpChk",
"BTSFPXXHXXGbyTBwdKoJaAPXRnhFNtTRS4EL",
"BTS3qXyZnjJneeAddgNDYNYXbF7ARZrRv5dr"
};

I created these for my own unit tests in C# :)

Would you like to take the code pack it and write some test modules for it?
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: xeroc on December 08, 2014, 04:03:29 pm
Actually, you know what's better than encrypting the generated private key with a passphrase?

Deriving a 256-bit number from the passphrase and doing modular addition with that number and the generated private key to get a new private key. That way you can first generate a random private key (back that up for safe keeping), then use that and various passphrases to generate new private keys (and corresponding BTS addresses). Then use one of those addresses to store your funds.

The beauty of that approach is that it provides plausible deniability. You can have two different passphrases (the real one and a fake one) to generate two different BTS addresses (real and fake). You fund both addresses, but you put just enough to be plausible in the fake one and put the rest of your funds in the real one.

Now even if someone steals your paper backup of the original random private key and extorts you to get the passphrase that allows them to derive the private key that unlocks the funds, you can provide the fake passphrase and let them get away with the small amount of decoy money stored there while keeping the rest of your wealth safe. This of course assumes that the attacker doesn't know how much money you have stored in which balances, or else he could continue extorting you until you give up the passphrase that unlocks the balance that he knows belongs to you. I have to say that blockchain analysis makes it actually pretty easy for the attacker to be fairly confident a balance belongs to you (sucks for you if he is wrong I guess), so perhaps this wouldn't be all that useful in practice until CryptoNote-like privacy is implemented on the blockchain.

thanks for the input ..

somewhere I do have a working BIP32 python implementation and could easily add this to the python script ..
For your idea I certainly need to learn more about ECC to be sure it's correct what I implement :)
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: monsterer on December 08, 2014, 04:21:07 pm
Would you like to take the code pack it and write some test modules for it?

What's the code pack? If it's python, I'm afraid my knowledge is pretty rudimentary. :)
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: xeroc on December 08, 2014, 04:51:34 pm
Would you like to take the code pack it and write some test modules for it?

What's the code pack? If it's python, I'm afraid my knowledge is pretty rudimentary. :)
mine is too :) lol

I will try to learn it myself :)
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: xeroc on December 08, 2014, 05:45:47 pm
Ok .. I successfully read into unittesting of python and added your unit tests for private key addresses pubkeys and wif format.
unit test can be executed via
  $ python2 -m unittest genbtskey
Code: [Select]
.....
----------------------------------------------------------------------
Ran 5 tests in 1.893s

OK

I also added the option to have a single argument .. a WIF key .. and convert that to the corresponding address/pubkey ..
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: pc on December 08, 2014, 05:52:48 pm
Are you aware of programs/utils/bts_create_key in the bitshares repo?

no I wasn't. I can just put that (alone) on a flashdrive and run it offline in a live-cd?
The issue with that one is that ideally .. you need to compile it on a offline ci
omputer running a livelinux of some kind ..
while python is almost stand-alone

Javascript would ve alot nicer though

Depends on your level of paranoia, I suppose. Don't forget to compile python on your livelinux before using your version. And the compiler used for compiling python of course. And the kernel. And...  ;)

Yes, it should be possible to put that alone on a flashdrive and run it offline.
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: arhag on December 09, 2014, 12:44:10 am
Depends on your level of paranoia, I suppose. Don't forget to compile python on your livelinux before using your version. And the compiler used for compiling python of course. And the kernel. And...  ;)

http://scienceblogs.com/goodmath/2007/04/15/strange-loops-dennis-ritchie-a/  ;)
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: xeroc on December 09, 2014, 09:14:12 pm
related thread: 
https://bitsharestalk.org/index.php?topic=8907.msg160155#msg160155

quote:

here we go .. I just updated the "pytshares" repo on github .. now there are two different scripts:

Code: [Select]
└─(1:%) ./genbtskey.py                                                                                                                                                                                                          ─┘
Secret Exponent         : b3a5255b0567f73da73a27663c0ea5998c67cb6bf860f6dad23af7c1f03290b5
Private Key             : 5KBQNg7LVWcfyZKYzYMVnwsV3d1JS351rD6EhddZvSSzpX2C34X
BTC Address             : 1Bfy6Pv7t1z4hXW89zGHbydnspevDdg9fN
--------------------------------------------------------------------------------
BTC Pubkey (compressed) : 02885d9abff5ca754bdea9c70c9fd95f3d1ea9200b563b2e43081a4d75bc63a1e5
BTC Address             : 1Bfy6Pv7t1z4hXW89zGHbydnspevDdg9fN
--------------------------------------------------------------------------------
BTS PubKey              : BTS5vYdYntohDkUyCCUmzp1QZE2isBwyS6ZARdA6P4gxWgzvFr9qz
BTS Address             : BTSPfYihuV1t7f7HczrY4oJXoX9tULALksLD
--------------------------------------------------------------------------------
┌─(xeroc@hermike:pts/2)────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────(~/pytshares)─┐
└─(%) ./convertbtcpubkey.py 02885d9abff5ca754bdea9c70c9fd95f3d1ea9200b563b2e43081a4d75bc63a1e5                                                                                                                                  ─┘
BTC PubKey      : 02885d9abff5ca754bdea9c70c9fd95f3d1ea9200b563b2e43081a4d75bc63a1e5
BTC Address     : 1BSxmaYgptZ2ZZeknMN8wNjmHViyW8SpC4
BTS PubKey      : BTS5vYdYntohDkUyCCUmzp1QZE2isBwyS6ZARdA6P4gxWgzvFr9qz
BTS Address     : BTSPfYihuV1t7f7HczrY4oJXoX9tULALksLD

Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: xeroc on December 09, 2014, 11:35:48 pm
Cool. A JavaScript version with all necessary dependencies bundled would probably be ideal, since everyone has a browser that can run it.
...
Anyway, it would be ideal to have all of the above in both a self-contained executable with absolutely minimal dependencies that runs a CLI version of the tool, as well as a Javascript  version that provides a more familiar UI interface that people can run in the browser of a live Linux environment.

If you are brave .. you can give this a try:
https://github.com/xeroc/jshares/archive/master.zip
Download the zip file .. unpack it and run the html file in the browser ..
it will randomly choose a private key and print the public key, private key, and bts address for it in text format and as QR code ..
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: arhag on December 10, 2014, 04:57:49 am
Cool. A JavaScript version with all necessary dependencies bundled would probably be ideal, since everyone has a browser that can run it.
...
Anyway, it would be ideal to have all of the above in both a self-contained executable with absolutely minimal dependencies that runs a CLI version of the tool, as well as a Javascript  version that provides a more familiar UI interface that people can run in the browser of a live Linux environment.

If you are brave .. you can give this a try:
https://github.com/xeroc/jshares/archive/master.zip
Download the zip file .. unpack it and run the html file in the browser ..
it will randomly choose a private key and print the public key, private key, and bts address for it in text format and as QR code ..

Nice. Seems to work on Chrome.

Is there a reason you have a huge crypto library mixed in together with the BitShares specific code in a single file? It would make sense to to me to split those up to the BitShares specific code which is easier to study in its own file and a separate minified crypto library. Then people could also replace the various libraries script files with ones from their original sources and if they trust the original sources, they would only have to audit the BitShares specific part.
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: xeroc on December 10, 2014, 07:01:36 am
I am a coffee script noobie and just dont yet know how to use it that way ;)

the huge js file has be deplpyed by the bitsharesJS library from the bishares github account .. i am just using it ..
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: arhag on December 10, 2014, 07:19:30 am
the huge js file has be deplpyed by the bitsharesJS library from the bishares github account .. i am just using it ..

Oh I see (https://github.com/BitShares/BitShares-JS). Great.
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: monsterer on December 10, 2014, 07:09:58 pm
If you are brave .. you can give this a try:
https://github.com/xeroc/jshares/archive/master.zip
Download the zip file .. unpack it and run the html file in the browser ..
it will randomly choose a private key and print the public key, private key, and bts address for it in text format and as QR code ..

Have you been careful with the RNG? There is a shitstorm at the moment in bitcoin due to private key discovery caused by bad random number generation leading to re-used R values.
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: xeroc on December 10, 2014, 07:38:05 pm
I am following the advice from
http://procbits.com/2013/08/27/generating-a-bitcoin-address-with-javascript
and use
window.crypto for picking random numbers ... take a look at the html file .. the code is quite straight forward and simple
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: Strip on December 13, 2014, 11:43:55 am
related thread: 
https://bitsharestalk.org/index.php?topic=8907.msg160155#msg160155

quote:

here we go .. I just updated the "pytshares" repo on github .. now there are two different scripts:

Code: [Select]
└─(1:%) ./genbtskey.py                                                                                                                                                                                                          ─┘
Secret Exponent         : b3a5255b0567f73da73a27663c0ea5998c67cb6bf860f6dad23af7c1f03290b5
Private Key             : 5KBQNg7LVWcfyZKYzYMVnwsV3d1JS351rD6EhddZvSSzpX2C34X
BTC Address             : 1Bfy6Pv7t1z4hXW89zGHbydnspevDdg9fN
--------------------------------------------------------------------------------
BTC Pubkey (compressed) : 02885d9abff5ca754bdea9c70c9fd95f3d1ea9200b563b2e43081a4d75bc63a1e5
BTC Address             : 1Bfy6Pv7t1z4hXW89zGHbydnspevDdg9fN
--------------------------------------------------------------------------------
BTS PubKey              : BTS5vYdYntohDkUyCCUmzp1QZE2isBwyS6ZARdA6P4gxWgzvFr9qz
BTS Address             : BTSPfYihuV1t7f7HczrY4oJXoX9tULALksLD
--------------------------------------------------------------------------------
┌─(xeroc@hermike:pts/2)────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────(~/pytshares)─┐
└─(%) ./convertbtcpubkey.py 02885d9abff5ca754bdea9c70c9fd95f3d1ea9200b563b2e43081a4d75bc63a1e5                                                                                                                                  ─┘
BTC PubKey      : 02885d9abff5ca754bdea9c70c9fd95f3d1ea9200b563b2e43081a4d75bc63a1e5
BTC Address     : 1BSxmaYgptZ2ZZeknMN8wNjmHViyW8SpC4
BTS PubKey      : BTS5vYdYntohDkUyCCUmzp1QZE2isBwyS6ZARdA6P4gxWgzvFr9qz
BTS Address     : BTSPfYihuV1t7f7HczrY4oJXoX9tULALksLD


I've tried both btsxaddr.py (with your patch) and convertvertbtcpubkey.py. Give them BTC public key (compressed) as a parameter and they give same BTS public key BUT different BTC address. btsxaddr.py gives right BTC address.

I like what you're doing here!
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: xeroc on December 13, 2014, 11:02:48 pm
Different btc addresses? cant check atm .. but btc addresses for compressed keys look different from noncompressed .. not sure what pycoin ia doing there ..can you give me a pubkey which produces diff. keys?
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: Strip on December 15, 2014, 05:35:27 pm
Different btc addresses? cant check atm .. but btc addresses for compressed keys look different from noncompressed .. not sure what pycoin ia doing there ..can you give me a pubkey which produces diff. keys?

Here is random BTC Public Key (compressed) from bitaddress.org:
039B518E3A38F38F813986371D52B24678AFB4610EE548E7E161D2B70E33795E34

pycoin gives: 1LvNaciVSM3EBLTUMtg4yftVxsTLRK6vPP (which correspond with  Bitcoin Address on bitadddress.org)
convertbtcpubkey.py: 12dwhLoEEqyvz8MpuaD6o1GiXW37JiKBbA (which correspond with Bitcoin Address Compressed on bitadddress.org)
BTS Pub keys are same: BTS81dwALnisZ5kaDjvt48BUy3f67DM5LcMkqPSWtEmMMrxzGZn9x

Here is private key for checking: 5JEPT35PuKrPWpQXvXaXUeVT1wfQB1tHHDk3Bj23dLcMc9LPebX

I think with some minor changes your code will return Bitcoin Address instead of compressed one.
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: xeroc on December 15, 2014, 09:36:40 pm
both address are valid with the same pubkey (IMHO):
Code: [Select]
└─(%) ./bitcoin_utils.py 5JEPT35PuKrPWpQXvXaXUeVT1wfQB1tHHDk3Bj23dLcMc9LPebX                                 ─┘
secret exponent: 24752670551704840911898197285133742638496361000728503947115201457657773762440
  hex:           36b983da902fd8095730e9e5bd959c0284accc389b1ddff191b50d8bf3af2788
WIF:             Ky465vAQ5xCzNcEsVFxyX2UZqAGVHCuLrbExeLTcbPZ3x4NMJQfK
  uncompressed:  5JEPT35PuKrPWpQXvXaXUeVT1wfQB1tHHDk3Bj23dLcMc9LPebX
public pair x:   70252587760309173621949825579917202930592538592986610219712637566763860057652
public pair y:   94085665968317647470297178062363365722307526286772903085374573868739763613109
  x as hex:      9b518e3a38f38f813986371d52b24678afb4610ee548e7e161d2b70e33795e34
  y as hex:      d002998d031660ebad1dcee2596da1ca4274bc9e3ca20f1281e97d0b8b87adb5
y parity:        odd
key pair as sec: 039b518e3a38f38f813986371d52b24678afb4610ee548e7e161d2b70e33795e34
  uncompressed:  049b518e3a38f38f813986371d52b24678afb4610ee548e7e161d2b70e33795e34\
                   d002998d031660ebad1dcee2596da1ca4274bc9e3ca20f1281e97d0b8b87adb5
BTS PubKey:     BTS81dwALnisZ5kaDjvt48BUy3f67DM5LcMkqPSWtEmMMrxzGZn9x
BTS Address:    BTSCG3GYSPRrAenNiAsKNt5kUMSQRT7WdgXr
hash160:         11f4c208bc7b3de7b15dccaa9ad7f365454e2d76
  uncompressed:  da827318a633afc92841e037b2e3a85d78d7a6be
Bitcoin address: 12dwhLoEEqyvz8MpuaD6o1GiXW37JiKBbA
  uncompressed:  1LvNaciVSM3EBLTUMtg4yftVxsTLRK6vPP
take a look at the last two lines

My scripts currently only work with COMPRESSED keys .. not sure if it's worth the work to change that
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: Strip on December 16, 2014, 04:49:02 pm
both address are valid with the same pubkey (IMHO):

take a look at the last two lines

My scripts currently only work with COMPRESSED keys .. not sure if it's worth the work to change that

Agree. No need to change anything. I just wanted to be clear for myself in how  scripts work.
Thanks for awesome work and help.
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: deprdoo on January 17, 2015, 07:01:23 pm
xeroc,
Today I was testing some cold storage techniques when I came up with what seems like a bug to me.

The private key to produce this problem is:
5HpaxYRdcinkA2HZt47hXrm2D4JWZcc6i2oWYypHtBdThm62BZr

Quote
$ ./convertbtcpubkey.py 0338900D92A42D9D89CB1FE73072E71D97DC7F44C8165E642C35E8AB47A588A896
BTC PubKey      : 0338900D92A42D9D89CB1FE73072E71D97DC7F44C8165E642C35E8AB47A588A896
BTC Address     : 1HoMKWTmxXZDjXHDcqmBoqG9f5XpPpZssW
BTS PubKey      : BTS7G9MAa8kToxvU9zcC84eSAAgtSFvPfYDML2ie2gxUFVY6HMgoQ
BTS Address     : BTS2LPYPSzyM3zPn9Wd2zAHfQBJ9hjDb9eF

yet if I check the BTS Pubkey with bts_key_info I get:
Quote
$ ./bts_key_info BTS7G9MAa8kToxvU9zcC84eSAAgtSFvPfYDML2ie2gxUFVY6HMgoQ
{
  "public_key": "BTS7G9MAa8kToxvU9zcC84eSAAgtSFvPfYDML2ie2gxUFVY6HMgoQ",
  "native_address": "BTS12LPYPSzyM3zPn9Wd2zAHfQBJ9hjDb9eF",
  "pts_address": "Ppj8Tb9uidWHXo64zLR2xrWCuKxeCYmPPH"
}

Should I put this on github or is this the place for it?
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: xeroc on January 17, 2015, 07:15:10 pm
Interessting ... there an extra 1 after BTS ... not sure what the reason here is ... gonne check with my testunits when back home ..

Maybe @toast knows about what may have caused this ... i have a feeling this is a bug in BTS_KEY_info ... or maybe a change in the adress format that i am unaware of
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: deprdoo on January 17, 2015, 07:26:16 pm
The result from convertbtcpubkey.py, the BTS2LPYPSzyM3zPn9Wd2zAHfQBJ9hjDb9eF address (without the 1), isn't a valid address.
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: xeroc on January 17, 2015, 07:50:20 pm
Odd .. gonna check on monday when back from holiday .. sorry for the inconvenience ..
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: theoretical on January 19, 2015, 08:23:21 am
Looks like our code expects addresses to be the full length.  It looks like our address generation code inserts padding, but yours does not.

I'm going to check into whether the cryptocurrency community has anything resembling a standard about whether addresses without padding are OK or not, and update our code to enforce the standard.  For practical purposes the code right now requires padding, but it's only sort-of enforcing it when the checksum fails with high probability.

See https://github.com/BitShares/bitshares/issues/1274
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: xeroc on January 19, 2015, 08:46:16 am
thx .. I marked the OP accordingly
Title: Re: [Request Review] Python Code for PrivKey/Address Creation [ColdStorage]
Post by: xeroc on January 20, 2015, 08:25:32 am
fixed the python code:
https://github.com/xeroc/pytshares/blob/master/genbtskey.py#L21
added another check for the particular case of the forum
https://github.com/xeroc/pytshares/blob/master/genbtskey.py#L122