0

I have the BIP-32 derivation path of m/44'/52752'/0'/0/index, where index >= 0.

How do I convert it to an int []?

I've tried doing int[] path = {44 | HARDENED_BIT, 52752 | HARDENED_BIT, 0 | HARDENED_BIT, 0}; but this is returning the incorrect public wallet address.

I have tested another derivation path, converting it to an int[] and it worked (returning the correct public wallet address). This one however, I think I'm missing a part in the int[] because I'm not quite sure what to do with the index at the end of the path.

What am I doing incorrectly?

DIRTY DAVE
  • 2,523
  • 2
  • 20
  • 83

1 Answers1

0

Kotlin code

HARDENED_BIT is 0x80000000

IS_NUMERIC = "[0-9]+(.[0-9]+)?".toRegex()

The "or" function compares corresponding bits of two values. If either of the bits is 1, it gives 1. If not, it gives 0. For example,

private fun generateBip44KeyPair(master: Bip32ECKeyPair?, path: String): Bip32ECKeyPair {
        // m/44'/60'/0'/0/0
        val resultIntArray = arrayListOf<Int>()
        path.split("/").forEach {
            if (it.contains('\'')) {
                resultIntArray.add(it.substring(0, it.length - 1).toInt() or Bip32ECKeyPair.HARDENED_BIT)
            } else if (IS_NUMERIC.matches(it)) {
                resultIntArray.add(it.toInt())
            }
        }
        return Bip32ECKeyPair.deriveKeyPair(master, resultIntArray.toIntArray())
    }
Boris
  • 1
  • 1