BitShares Forum

Other => Graveyard => Marketplace => Topic started by: xeroc on August 24, 2014, 06:25:15 pm

Title: [200BTSX] tool to convert bitcoin public key into BTSX/PTS address
Post by: xeroc on August 24, 2014, 06:25:15 pm
I offer 200 BTSX to the best solution for the following task.

Given: a bitcoin public key (in hexadecimal char vector)

Input:
 - from command line argument: public key for a bitcoin address in hexformat

Ouput:
 - the BTSX address that can be accessed if you own the private key to the input private key
 - the PTS address that can be accessed by the same private key

Hint .. go over to the BitShares Toolkit sources .. in the programs/utils folder there are tools that
can be expended to achieve this task. I tried figuring it out myself but just failed :(

Ah, yha, please post the documented source code (probably less than 50 lines of code)
Title: Re: [200BTSX] tool to convert bitcoin public key into BTSX/PTS address
Post by: cgafeng on August 24, 2014, 11:43:36 pm
   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.
Title: Re: [200BTSX] tool to convert bitcoin public key into BTSX/PTS address
Post by: crazybit on August 25, 2014, 06:35:49 am
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.
Title: Re: [200BTSX] tool to convert bitcoin public key into BTSX/PTS address
Post by: xeroc on August 25, 2014, 07:02:49 am
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$ ..
Title: Re: [200BTSX] tool to convert bitcoin public key into BTSX/PTS address
Post by: xeroc on August 27, 2014, 06:34:47 pm
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
Title: Re: [200BTSX] tool to convert bitcoin public key into BTSX/PTS address
Post by: xeroc on August 27, 2014, 07:14:16 pm
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?
Title: Re: [200BTSX] tool to convert bitcoin public key into BTSX/PTS address
Post by: bytemaster on August 27, 2014, 08:53:21 pm
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)
Title: Re: [200BTSX] tool to convert bitcoin public key into BTSX/PTS address
Post by: xeroc on August 27, 2014, 09:02:19 pm
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 ?
Title: Re: [200BTSX] tool to convert bitcoin public key into BTSX/PTS address
Post by: crazybit on August 28, 2014, 09:20:41 am
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))

Title: Re: [200BTSX] tool to convert bitcoin public key into BTSX/PTS address
Post by: xeroc on August 28, 2014, 09:32:01 am
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 :(
Title: Re: [200BTSX] tool to convert bitcoin public key into BTSX/PTS address
Post by: xeroc on August 28, 2014, 01:57:25 pm
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?
Title: Re: [200BTSX] tool to convert bitcoin public key into BTSX/PTS address
Post by: cgafeng on August 28, 2014, 02:28:44 pm
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.
Title: Re: [200BTSX] tool to convert bitcoin public key into BTSX/PTS address
Post by: pc on August 28, 2014, 08:12:45 pm
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.
Title: Re: [200BTSX] tool to convert bitcoin public key into BTSX/PTS address
Post by: xeroc on August 28, 2014, 08:17:26 pm
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!
Title: Re: [200BTSX] tool to convert bitcoin public key into BTSX/PTS address
Post by: xeroc on August 29, 2014, 06:15:34 pm
I think i got it .. gonna have to test it first .. publish code next week ... have a nace weekend
Title: Re: [200BTSX] tool to convert bitcoin public key into BTSX/PTS address
Post by: xeroc on September 01, 2014, 08:57:08 pm
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