Author

Topic: Unharden Address Path (Read 215 times)

jr. member
Activity: 51
Merit: 56
October 05, 2018, 06: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!
legendary
Activity: 3472
Merit: 10611
October 04, 2018, 10:55:39 PM
#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.
jr. member
Activity: 51
Merit: 56
October 04, 2018, 10:24:18 PM
#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.
legendary
Activity: 3472
Merit: 10611
October 04, 2018, 10:16:28 PM
#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.
legendary
Activity: 3122
Merit: 2178
Playgram - The Telegram Casino
October 04, 2018, 06:35:39 PM
#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.
jr. member
Activity: 51
Merit: 56
October 04, 2018, 05:25:22 PM
#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 ?



Jump to: