archethic-foundation / archethic-wallet

Archethic Wallet
GNU Affero General Public License v3.0
57 stars 25 forks source link

Implementation of BIP44 Path to define the address from the private key derived from seed #73

Closed redDwarf03 closed 2 years ago

redDwarf03 commented 2 years ago

Problem to solve

No response

Solution

/// purpose = 44' (BIP44)
/// coin_type = 650' (UCO of ArchEthic Blockchain)
/// account = Depends on the intended use of the key.
/// Currently fixed values: 0xFFFF for o_{key}, 0x0000 for a simple w_{key})
/// change = 0 (0 for external, 1 for internal)
/// address_index = variable (0,1,2,...)
/// path = m/44'/650'/0'/0'/0'
const int kPurpose = 44;
const int kCoinType = 650;

String privateKey = seedToPrivateKey(seed, 0, 0, 0);
final String genesisAddress = deriveAddress(privateKey, 0);

String seedToPrivateKey(
      String seed, int account, int change, int addressIndex) {
    return uint8ListToHex(bip32.BIP32
        .fromSeed(bip39.mnemonicToSeed(bip39.entropyToMnemonic(seed)))
        .derivePath("m/" +
            kPurpose.toString() +
            "'/" +
            kCoinType.toString() +
            "'/" +
            account.toString() +
            "'/" +
            change.toString() +
            "/" +
            addressIndex.toString())
        .privateKey!);
  }
redDwarf03 commented 2 years ago

@samuel-uniris I need a code review please https://github.com/archethic-foundation/archethic-wallet/blob/dc11a939f5ce5d9fb6c70f36451558a89ba84e32/packages/core_ui/lib/util/app_util.dart#L38

redDwarf03 commented 2 years ago

deployed in dev branch

ghost commented 2 years ago

We need to check with the ledger app for the derivation key algorithm, do you want to leverage BIP32 to get a private key and then apply a custom derivation key or using directly BIP32. The issue with BIP32 is by default it's using secp256k1, so need to figure a way to specify a custom curve

redDwarf03 commented 2 years ago

i close this issue because we have to change path derivation management