Bitcoin Forum
October 23, 2018, 08:20:26 AM *
News: Make sure you are not using versions of Bitcoin Core other than 0.17.0 [Torrent], 0.16.3, 0.15.2, or 0.14.3. More info.
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: Unharden Address Path  (Read 68 times)
Kruddler
Jr. Member
*
Offline Offline

Activity: 45
Merit: 10


View Profile
October 04, 2018, 10:25:22 PM
Merited by DarkStar_ (2)
 #1

When a BIP0044 address path is created, the CoinNumber is hardened like this (C#):

HardeningConstant = 0x80000000;

(CoinType | HardeningConstant) >> 0

Is it possible to take the hardened number and get the original unhardened coin number?

For example, if the coin is Bitcoin, the path is 0x80000000, but the coin number I want is 0. If the coin is Bitcoin cash, the path is 0x80000091, but I want 145 (0x91‬). Is there a bitwise operation I can do to get 145 0x91 from 0x80000091?

Is just subtracting safe? I.e. 0x80000091 - 0x80000000 ?



1540282826
Hero Member
*
Offline Offline

Posts: 1540282826

View Profile Personal Message (Offline)

Ignore
1540282826
Reply with quote  #2

1540282826
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1540282826
Hero Member
*
Offline Offline

Posts: 1540282826

View Profile Personal Message (Offline)

Ignore
1540282826
Reply with quote  #2

1540282826
Report to moderator
1540282826
Hero Member
*
Offline Offline

Posts: 1540282826

View Profile Personal Message (Offline)

Ignore
1540282826
Reply with quote  #2

1540282826
Report to moderator
1540282826
Hero Member
*
Offline Offline

Posts: 1540282826

View Profile Personal Message (Offline)

Ignore
1540282826
Reply with quote  #2

1540282826
Report to moderator
HeRetiK
Hero Member
*****
Offline Offline

Activity: 896
Merit: 764


the forkings will continue until morale improves


View Profile
October 04, 2018, 11:35:39 PM
Merited by DarkStar_ (2)
 #2

When a BIP0044 address path is created, the CoinNumber is hardened like this (C#):

HardeningConstant = 0x80000000;

(CoinType | HardeningConstant) >> 0

Is it possible to take the hardened number and get the original unhardened coin number?

For example, if the coin is Bitcoin, the path is 0x80000000, but the coin number I want is 0. If the coin is Bitcoin cash, the path is 0x80000091, but I want 145 (0x91‬). Is there a bitwise operation I can do to get 145 0x91 from 0x80000091?

Is just subtracting safe? I.e. 0x80000091 - 0x80000000 ?

In this case just subtracting is safe. Alternatively you could -- in this case -- also use bitwise XOR, ie. 0x80000091 ^ 0x80000000.

I'm not sure with what else there is to consider when working with hardened derivation, but if all you want is to derive the CoinType that should be it.

pooya87
Legendary
*
Offline Offline

Activity: 1428
Merit: 1206


Buy bitcoin they said... who listened?


View Profile
October 05, 2018, 03:16:28 AM
 #3

what is it that you are exactly trying to do?

because these "numbers" are simply "indexes" that you use in your derivation steps. you don't convert one to another! you decide what number you need and then pass that in your derivation function (read BIP32). for example you want bitcoin so you pass 0' and if you want bitcoin_testnet you pass 1' and you should not worry about the hardened number you pass them with an indicator like ' or the letter H and the function has to recognize it as hardened and add that index (2^31 or 0x80000000) to it, there is still no subtraction here.

in this case if you want bitcoin_cash then your index in level 2 is 145' and you already know that. you don't get it from something else.
and in order to get the extended keys you do need the parent extended key. because the operations don't work in reverse.

Kruddler
Jr. Member
*
Offline Offline

Activity: 45
Merit: 10


View Profile
October 05, 2018, 03:24:18 AM
 #4

Some code uses the unhardened number, and some code uses the hardened number. In this case, someone else's code gives me the hardened number. I need the unhardened number - I.e. the index as per Slip0044 of the coin.

I can convert from unhardened to hardened, but my question was how to convert the other way around.
pooya87
Legendary
*
Offline Offline

Activity: 1428
Merit: 1206


Buy bitcoin they said... who listened?


View Profile
October 05, 2018, 03:55:39 AM
 #5

I can convert from unhardened to hardened, but my question was how to convert the other way around.

yeah, you subtract but it still doesn't make sense in practice. it would be like saying second day of the week is Monday, i want to know what is the first day of the week so i subtract 1 from Monday. it obviously works but you should already know it is Sunday.

if you are coding for example in c# you hard code an enum that contains the names and their values like this:
enum Bip44Indices : uint
{
    BTC = 0x80000000,
    TestNet = 0x80000001,
    LTC = 0x80000002,
    ....
    BCH = 0x80000091,
    ....
}
then you use that wherever in your code you want.

Kruddler
Jr. Member
*
Offline Offline

Activity: 45
Merit: 10


View Profile
October 05, 2018, 11:10:13 PM
 #6

When a BIP0044 address path is created, the CoinNumber is hardened like this (C#):

HardeningConstant = 0x80000000;

(CoinType | HardeningConstant) >> 0

Is it possible to take the hardened number and get the original unhardened coin number?

For example, if the coin is Bitcoin, the path is 0x80000000, but the coin number I want is 0. If the coin is Bitcoin cash, the path is 0x80000091, but I want 145 (0x91‬). Is there a bitwise operation I can do to get 145 0x91 from 0x80000091?

Is just subtracting safe? I.e. 0x80000091 - 0x80000000 ?

In this case just subtracting is safe. Alternatively you could -- in this case -- also use bitwise XOR, ie. 0x80000091 ^ 0x80000000.

I'm not sure with what else there is to consider when working with hardened derivation, but if all you want is to derive the CoinType that should be it.

Bitwise XOR is the answer! Thanks HeRetik!
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!