Author Topic: [200BTSX] tool to convert bitcoin public key into BTSX/PTS address  (Read 6100 times)

0 Members and 1 Guest are viewing this topic.

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
Here we go:
https://github.com/BitShares/bitshares_toolkit/pull/734

edit: just figured I need to distinguish between compressed and uncompressed format .. thought they where only for private keys ..
sth learned to day .. maybe I can figure that out too
« Last Edit: September 01, 2014, 10:27:40 pm by xeroc »

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
I think i got it .. gonna have to test it first .. publish code next week ... have a nace weekend

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
You cannot "generate a pubkey from a bitcoin address" because the address is essentially a cryptographic hash of the pubkey. Cryptographic hashes are one way - it's easy to compute the hash for a key but close to impossible to find the key(s) generating a given hash.
I know that .. fixed the typo above
I want to generate a BTSX PubKey from a BTC PubKey!

Offline pc

  • Hero Member
  • *****
  • Posts: 1530
    • View Profile
    • Bitcoin - Perspektive oder Risiko?
  • BitShares: cyrano
but there is no way to convert an address to a public key (address is hash of public key)
Is it even possible to to register a btsx account using a pubkey generated from a bitcoin address .. so that the holder of the privkey (bitcoin) can import an account name I registered for him?
You cannot "generate a pubkey from a bitcoin address" because the address is essentially a cryptographic hash of the pubkey. Cryptographic hashes are one way - it's easy to compute the hash for a key but close to impossible to find the key(s) generating a given hash.
Bitcoin - Perspektive oder Risiko? ISBN 978-3-8442-6568-2 http://bitcoin.quisquis.de

Offline cgafeng

BTSX addresses are not used anywhere in the API...  we use the public keys for the accounts, but there is no way to convert an address to a public key (address is hash of public key)
I tried to figure this out .. but failed ... could you points me to some direction so that I can try figure this out myself?
Is it even possible to to register a btsx account using a pubkey generated from a bitcoin address .. so that the holder of the privkey (bitcoin) can import an account name I registered for him?

I don't think this can work.
BTC:1EYwcZ9cYVj6C9LMLafdcjK9wicVMDV376

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
BTSX addresses are not used anywhere in the API...  we use the public keys for the accounts, but there is no way to convert an address to a public key (address is hash of public key)
I tried to figure this out .. but failed ... could you points me to some direction so that I can try figure this out myself?
Is it even possible to to register a btsx account using a pubkey generated from a bitcoin address pubkey .. so that the holder of the privkey (bitcoin) can import an account name I registered for him?
« Last Edit: August 28, 2014, 08:18:20 pm by xeroc »

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
BTSX addresses are not used anywhere in the API...  we use the public keys for the accounts, but there is no way to convert an address to a public key (address is hash of public key)

BM, how does the toolkit generates the balance id from the existing btc/pts address in genesis block?similar to the following logic? is  the balance id same with balance record owner ?

balance id =ripemd160(sha512(hash of public key))
The initial balances it stored in a BTSX ADDRESS .. the rest of the network works on BTSX PUBLIC KEYSs (ie, when you register a name, you register a pubkey .. not an address)

Thus, I cannot use the result of the above script to register a name on his behalf as I need to register a PUBKEY ... so I need to take the bitcoin pubkey of that address and convert that one to a bitsharesx pubkey ... just don't know yet how to do it :(

Offline crazybit

BTSX addresses are not used anywhere in the API...  we use the public keys for the accounts, but there is no way to convert an address to a public key (address is hash of public key)

BM, how does the toolkit generates the balance id from the existing btc/pts address in genesis block?similar to the following logic? is  the balance id same with balance record owner ?

balance id =ripemd160(sha512(hash of public key))


Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
BTSX addresses are not used anywhere in the API...  we use the public keys for the accounts, but there is no way to convert an address to a public key (address is hash of public key)
So I cannot register a name on the above results ...

can I convert a hex.formated bitcoin pubkey into a BTSX pubkey so that I can register a name on a bitcoin pubkey/address ?

Offline bytemaster

BTSX addresses are not used anywhere in the API...  we use the public keys for the accounts, but there is no way to convert an address to a public key (address is hash of public key)
For the latest updates checkout my blog: http://bytemaster.bitshares.org
Anything said on these forums does not constitute an intent to create a legal obligation or contract between myself and anyone else.   These are merely my opinions and I reserve the right to change them at any time.

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
Code: [Select]
#include <bts/blockchain/address.hpp>
#include <bts/blockchain/pts_address.hpp>
#include <bts/utilities/key_conversion.hpp>
#include <fc/crypto/elliptic.hpp>
#include <iostream>

using namespace bts::blockchain;

bts::blockchain::address btc_address_convert_to_bts_address(const std::string& base58str)
{
 return address(pts_address(base58str));
}


int main( int argc, char** argv )
{
 if( argc == 1 )
 {
  std::cout << "useage: convert_btc_address <btcaddress>" <<"\n";
 }
 else
 {
  std::string myarg = argv[1];
  std::cout << "Input:       " << myarg << "\n";
  std::cout << "BTS address: " << std::string(btc_address_convert_to_bts_address(myarg)) << "\n";
 }
}

But it is not working as intended :(

I generated a random new key and added it to an existing account ... result
Code: [Select]
>> wallet_account_list_public_keys xeroc
[{
    "hex": "029ce4fb7d77478a8760d08b79b4664d78453958d2efeb1b8d91d033a175c35b7c",
    "native_pubkey": "BTSX65b1ez7zLiJZ5PwGQ3qdQ6bWr5goeyZnfwqYBtzjAVVZr9dxcP",
    "native_address": "BTSXEkMHfXiWnRb7hHSZ67Gw9iJ8ZbL8FEJKw",
    "pts_normal_address": "PdVJKUTwGdtV1RDrZ8TbXsC2dU874MSqyS",
    "pts_compressed_address": "PmLJC5PbKgL6WS51c823LciPsMbtKdSMSm",
    "btc_normal_address": "16ZXBPmoWXwRD9R1BdokNqwyPDhHBgfhH1",
    "btc_compressed_address": "1EQX3zhTZaP2iAGAEdNCBbULd7B4Vjt5Eq"
  },{

I took the BTC address 16ZXBPmoWXwRD9R1BdokNqwyPDhHBgfhH1 and put it into the executable:

Code: [Select]
./convert_btc_address 16ZXBPmoWXwRD9R1BdokNqwyPDhHBgfhH1                                                                                                                                                     
Input:       16ZXBPmoWXwRD9R1BdokNqwyPDhHBgfhH1
BTS address: BTSXPfmi29tucM9HRpPAEKD1dqJuFQRY5gqcY

BTS addresses don't match ... No what?

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
Code: [Select]
2014-08-27T18:33:54 332007    xeroc               cgafeng             200.00000 BTSX          bounty                                      0.50000 BTSX        56a975d8
 2014-08-27T18:34:04 332008    xeroc               crazybit            200.00000 BTSX          bounty                                      0.50000 BTSX        8891114b
Thanks for pointing me there .. I try to figure out the rest my self

Offline xeroc

  • Board Moderator
  • Hero Member
  • *****
  • Posts: 12922
  • ChainSquad GmbH
    • View Profile
    • ChainSquad GmbH
  • BitShares: xeroc
  • GitHub: xeroc
nice solutions so far ...
As I am not a coder (and I figured those parts out my self already)
I'd really like to see a full-length compileable file ...
(from within the toolkit)

(best for me would be a git pull request to the official repo that includes that file in the utilities of the toolbox .. )

edit:// and I figured 200 BTSX is to few for that task ..
I will send both of you the 200 BTSX and as soon as I get to it I will raise the bounty price to sth. that is more like 40-50$ ..

Offline crazybit

bts::blockchain::address btc _address convert_to_bts_address (std::string& ptsbase58str)
{
return address(pts_address(ptsbase58str ));
}


i write this with my phone, not test yet.
« Last Edit: August 25, 2014, 06:39:39 am by crazybit »

Offline cgafeng

   string client_impl::btctobts(const string& btcaddress)const
   {
      balance_record initial_balance(pts_address(btcaddress),
         asset(share_type(0), 0),
         0 /* Not voting for anyone */
         );
      return string(initial_balance.condition.get_address());
   }

this work on client.cpp.
« Last Edit: August 24, 2014, 11:45:50 pm by cgafeng »
BTC:1EYwcZ9cYVj6C9LMLafdcjK9wicVMDV376