BitShares Forum

Main => General Discussion => Topic started by: xeroc on September 14, 2014, 04:53:00 pm

Title: Tool to convert btc pubkeys into btsx pubkeys
Post by: xeroc on September 14, 2014, 04:53:00 pm
I modified the "bu.py" script from pycoin to produce BTSX pubkeys given a public key from bitcoin:

pycoin: https://github.com/richardkiss/pycoin.git
particular bu.py sourcecode: https://github.com/richardkiss/pycoin/blob/master/pycoin/scripts/bitcoin_utils.py

The patch looks like this:
Code: [Select]
*** pycoin/pycoin/scripts/bitcoin_utils.py      2014-09-14 16:32:55.171411937 +0200
--- btsxaddrutil/btsxaddr.py    2014-09-14 18:46:21.691527277 +0200
*************** from pycoin.ecdsa import secp256k1
*** 10,11 ****
--- 10,13 ----
 
+ BTS_ADDRESS_PREFIX = "BTS"
+
  def parse_as_number(s):
*************** def main():
*** 103,104 ****
--- 105,109 ----
              hash160_unc = encoding.public_pair_to_hash160_sec(public_pair, compressed=False)
+             myeccpoint = encoding.public_pair_to_sec(public_pair, compressed=True)
+             myhash     = encoding.ripemd160( myeccpoint ).digest(  )
+             print("BTSX PubKey:     %s" % BTS_ADDRESS_PREFIX + encoding.b2a_base58(myeccpoint + myhash[ :4 ]))
          else:
(patch comes as is ... no warranty ... AT ALL!! check results your self)

nothing too complicated .. but it took me some hours to figure it out :)

Output looks like this
Code: [Select]
─(%) ./btsxaddr.py 04c089455cd1554f05e723a1de8331fc0b947119966db60f4409036fdaf6663e1f5f61a8c0656704e98775382c240d8eb1ee0df827342fd7054b1284d41c1bea2c                                                                          ─┘
public pair x:   87086603698720170063321393822553237916438159845584726570308491679063372873247
public pair y:   43142269461068752177588100742336804615736633778602002937675098874341555431980
  x as hex:      c089455cd1554f05e723a1de8331fc0b947119966db60f4409036fdaf6663e1f
  y as hex:      5f61a8c0656704e98775382c240d8eb1ee0df827342fd7054b1284d41c1bea2c
even
key pair as sec: 02c089455cd1554f05e723a1de8331fc0b947119966db60f4409036fdaf6663e1f
  uncompressed:  04c089455cd1554f05e723a1de8331fc0b947119966db60f4409036fdaf6663e1f\
                   5f61a8c0656704e98775382c240d8eb1ee0df827342fd7054b1284d41c1bea2c
BTSX PubKey:     BTS6MHS4JNrh6wVVe1uZAugJbuQpJpr9ENYyaQ74fjv8DZUadY4fq
hash160:         fa6dc9a5cdd1a2d9b5bd1845a1201711ae4eb7ae
  uncompressed:  ef1567d36cd10b8fe6d0849123c22f1356cc90bb
Bitcoin address: 1Pq9T97Ces8HHBYaSr5jphxsW5EAmEUNNu
  uncompressed:  1NoA98grVfXfVqysU4ijM9jhMBD8vmrUC8
Title: Re: Tool to convert btc pubkeys into btsx pubkeys
Post by: xeroc on November 26, 2014, 09:47:11 am
fixed "BTSX" -> "BTS"
Title: Re: Tool to convert btc pubkeys into btsx pubkeys
Post by: cass on November 26, 2014, 10:59:29 am
 +5%
Title: Re: Tool to convert btc pubkeys into btsx pubkeys
Post by: spartako on November 26, 2014, 01:30:16 pm
 +5%
Title: Re: Tool to convert btc pubkeys into btsx pubkeys
Post by: monsterer on December 03, 2014, 05:23:25 pm
I don't suppose you have the patched file to save me trying to figure out how to apply it? :)
Title: Re: Tool to convert btc pubkeys into btsx pubkeys
Post by: xeroc on December 03, 2014, 08:00:05 pm
You just have to add those lines in the patch above that start with a + sign .. at the acording place .. or anywhere pretty below in the main procedure ..

Plus you need to define the prefix somewhere ... if you cant manage drop me a line and i can post a patches file .. i am mobile atm
Title: Re: Tool to convert btc pubkeys into btsx pubkeys
Post by: monsterer on December 05, 2014, 11:57:48 am
Can I get a confirmation on this pseudo code for going from bitcoin pub key to BTS address?

Code: [Select]
addr = ripemd160(sha512(bitcoinPubKeyBinary))
check = ripemd160(addr)
finalBinary = addr + first_four_bytes(check)
finalBase58 = 'BTS' + base58(finalBinary)
Title: Re: Tool to convert btc pubkeys into btsx pubkeys
Post by: xeroc on December 05, 2014, 12:48:15 pm
Never worked wih addresses... but you can take a random key .. import into the wallet and  heck with wallet_account_list_public_keys .. it shows the pubkey and adresses
Title: Re: Tool to convert btc pubkeys into btsx pubkeys
Post by: monsterer on December 05, 2014, 01:35:28 pm
Never worked wih addresses... but you can take a random key .. import into the wallet and  heck with wallet_account_list_public_keys .. it shows the pubkey and adresses

Using wallet_import_private_key?

edit: does this overwrite the private key of the account?.... I guess it can't actually. So there are multiple private keys for each account?
Title: Re: Tool to convert btc pubkeys into btsx pubkeys
Post by: xeroc on December 05, 2014, 02:29:08 pm
Multiple keys per account .. yes
Title: Re: Tool to convert btc pubkeys into btsx pubkeys
Post by: Thom on December 05, 2014, 10:05:04 pm
What is the implication of this?

It sounds similar to sharedropping but rather than coins / shares it is addresses.

Does this imply you could send BTS to a bitcoin account, or a bitcoin account could send BTC to to a BTS wallet?
Title: Re: Tool to convert btc pubkeys into btsx pubkeys
Post by: monsterer on December 05, 2014, 10:44:25 pm
What is the implication of this?

It sounds similar to sharedropping but rather than coins / shares it is addresses.

Does this imply you could send BTS to a bitcoin account, or a bitcoin account could send BTC to to a BTS wallet?

It does, but think in terms of bitBTC instead of BTS :)
Title: Re: Tool to convert btc pubkeys into btsx pubkeys
Post by: NewMine on December 06, 2014, 04:07:27 am
Can I create a BTS address through oclvanitygen, then import it and register the key to a Titan name? If so what would the -X flag variable be?
Title: Re: Tool to convert btc pubkeys into btsx pubkeys
Post by: xeroc on December 06, 2014, 12:56:51 pm
What is the implication of this?

It sounds similar to sharedropping but rather than coins / shares it is addresses.

Does this imply you could send BTS to a bitcoin account, or a bitcoin account could send BTC to to a BTS wallet?

It does, but think in terms of bitBTC instead of BTS :)
you cannot do crosschain transactions .. but you can reuse the.private key ..

If you want to send 2bitUSD to someone only having a btc pubkey (address) you can convert the pubkey to a bts pubkey or address and send BTS there .. the other guy can redeem the bts by importing the btc privkey into bts
Title: Re: Tool to convert btc pubkeys into btsx pubkeys
Post by: xeroc on December 06, 2014, 12:57:25 pm
Can I create a BTS address through oclvanitygen, then import it and register the key to a Titan name? If so what would the -X flag variable be?
Not without major code modifications ..
Title: Re: Tool to convert btc pubkeys into btsx pubkeys
Post by: Strip on December 09, 2014, 06:50:22 pm
 +5%
Thank you! It's awesome! Now we could do brain wallets!
Title: Re: Tool to convert btc pubkeys into btsx pubkeys
Post by: xeroc on December 09, 2014, 08:10:56 pm
+5%
Thank you! It's awesome! Now we could do brain wallets!
Brainwallets can be uses in the original client too... check this out:

   help wallet_create
Title: Re: Tool to convert btc pubkeys into btsx pubkeys
Post by: Strip on December 09, 2014, 08:28:15 pm
xeroc,

I'm struggling too understand how to use this code for several hour by now. Can you explain a little bit, please.

I have the BTC address and I want to convert in BTS format. What argument to btsxaddr.py should I give?
It won't take BTC address. But it take hash160 but results not identical if I give the private key for the same address.

Brainwallets can be uses in the original client too... check this out:

   help wallet_create
Holy moly! It is so easy!
Title: Re: Tool to convert btc pubkeys into btsx pubkeys
Post by: xeroc on December 09, 2014, 08:35:48 pm
xeroc,

I'm struggling too understand how to use this code for several hour by now. Can you explain a little bit, please.

I have the BTC address and I want to convert in BTS format. What argument to btsxaddr.py should I give?
It won't take BTC address. But it take hash160 but results not identical if I give the private key for the same address.
Oh .. I should write some more lines about that ...
the genbts.py script int "pytshares" is just createing a private key and the bts addresses ..

if you only have the public key and want that one converted to bts address you need to use my modified "pycoin" repo and install that one .. than you can use the bitcoin_utils.py (or "bu") tool that is installed .. that one takes the pubkey and converts it to the pubkey and address ..
I will try to write a separated file to do that .. give me 30 minutes or so .
Title: Re: Tool to convert btc pubkeys into btsx pubkeys
Post by: xeroc on December 09, 2014, 09:12:33 pm
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: Tool to convert btc pubkeys into btsx pubkeys
Post by: Strip on December 09, 2014, 09:38:17 pm
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


Thank you a lot! Testing.

Seems working in both scripts(modified bitcoin_utils.py and new convertbtcpubkey.py . Just needed to import compressed public key.