Author Topic: Public key and address formats  (Read 1854 times)

0 Members and 1 Guest are viewing this topic.

Offline pc

  • Hero Member
  • *****
  • Posts: 1530
    • View Profile
    • Bitcoin - Perspektive oder Risiko?
  • BitShares: cyrano
Bitcoin - Perspektive oder Risiko? ISBN 978-3-8442-6568-2 http://bitcoin.quisquis.de

coinfan

  • Guest
Thanks for such a timely and comprehensive answer!  :)

This is the format of the address you would receive from calling "suggest_brain_key" on the bitshares cli_wallet?


Offline pc

  • Hero Member
  • *****
  • Posts: 1530
    • View Profile
    • Bitcoin - Perspektive oder Risiko?
  • BitShares: cyrano
In Graphene, public key cryptography uses the same elliptic curve as Bitcoin, i. e. secp256k1. It even uses the same implementation.

A public key is just a point on the curve. This can be represented as two 256-bit numbers, or due to curve symmetry as a single 256-bit number plus a flag. In order to distinguish the formats, the key is prefixed with '04' byte in the first case (called "uncompressed format"), and, depending on the flag value, with a '02' or '03' byte in the second case (called "compressed format").

To construct a Graphene address from a public key, these steps need to be applied:

1. You need the 33 bytes making up the compressed representation of the public key CPK.
2. Compute the hash H1 = SHA512(CPK).
3. Compute the hash H2 = RIPEMD160(H1).
4. Compute the hash H3 = RIPEMD160(H2).
5. Take the last 4 bytes from the hash value H3 as checksum CS.
6. Append CS to H2.
7. Transform the result into base58 format.
8. Prepend the network address prefix, i.e. "BTS" for BitShares.

In BitShares, like in Bitcoin, addresses are used to indicate required authorization for performing operations on certain objects. The similarity ends at this abstract level, though.

Update: in step 2 it's SHA-512 not SHA-256!
« Last Edit: June 19, 2017, 02:48:00 pm by pc »
Bitcoin - Perspektive oder Risiko? ISBN 978-3-8442-6568-2 http://bitcoin.quisquis.de

coinfan

  • Guest
I want to convert an uncompressed public key i have on my HW wallet into a BTS compatible format, but I'm kind of confused as how exactly to do that. I've looked at some of the source code and I'm confused as to:

1. What is the exact format of BTS (Graphene?) public keys? Is it different from the keys used in bitcoin?
2. I see mentions of BTS addresses, how different are they from bitcoin addresses? Where are they used?

I want to convert this input:
Code: [Select]
045a3dce7aba50d343d8aa6ad5e9eb66eebead1df13f9d95e709ef22cae3445c9862066bf1a2e8381d0aa2fc33b9e3ebac64bb4d2ce4f1cb75a9d29e411f6851c8into something like this:
Code: [Select]
GPH6KXx5gnuZxumkBfHQhZQFPMaca2yAVtjMMhRTLMo4aaiyiKchp
Thx in advance  :)