metaplex-foundation / SolanaKT

This is a open source library on kotlin for Solana protocol.
MIT License
71 stars 36 forks source link

Impossible to generate set of keypairs from mnemonic #116

Closed samdowd closed 1 year ago

samdowd commented 2 years ago

Bip44WithChange is used by Solana to generate a set of keypairs for a given seed. This exists in SolanaKT but is not fully implemented.

private fun getPrivateKeyFromBip44SeedWithChange(seed: ByteArray): ByteArray {
        val masterAddress = hdKeyGenerator.getAddressFromSeed(seed, solanaCoin)
        val purposeAddress =
            hdKeyGenerator.getAddress(masterAddress, PURPOSE, solanaCoin.alwaysHardened) // 44H
        val coinTypeAddress =
            hdKeyGenerator.getAddress(purposeAddress, TYPE, solanaCoin.alwaysHardened) // 501H
        val accountAddress =
            hdKeyGenerator.getAddress(coinTypeAddress, ACCOUNT, solanaCoin.alwaysHardened) //0H
        val changeAddress = hdKeyGenerator.getAddress(
            accountAddress,
            CHANGE.toLong(),
            solanaCoin.alwaysHardened
        ) //0H
        return changeAddress.privateKey.privateKey
    }

CHANGE is a constant set to 0. Therefore you can only get the privateKey without change effectively. You should be able to pass in a change number to this function in vendor.bip32.wallet.