celo-org / celo-monorepo

Official repository for core projects comprising the Celo platform
https://celo.org
Apache License 2.0
697 stars 369 forks source link

Feature request: Add BIP-32/39/44 mnemonic support to contract kit #3419

Closed prestwich closed 2 years ago

prestwich commented 4 years ago

Expected Behavior

Kit should accept a mnemonic and automatically derive the bip44 Celo (0xce10) key. Code below is sample truffle-config.js code

const alfajores = {
  provider: () => {
    const kit = Kit.newKit('https://alfajores-forno.celo-testnet.org');
    kit.addMnemonic(mnemonic);
    return kit.web3.currentProvider;
  }
}

Current Behavior

Instead we need to independently derive that key and add it to the kit

const alfajores = {
  provider: () => {
    const provider = new HDWalletProvider(mnemonic, 'http://127.0.0.1:9999'); // sinkhole any requests
    // slip44
    const celoBIP44 = "m/44'/52752'/0'/0/0";  // 52752 === 0xce10
    const hdkey = provider.hdwallet.derivePath(celoBIP44);
    // Get the privkey and hand it to the kit
    const privkey = hdkey._hdkey.privateKey.toString('hex');
    const kit = Kit.newKit('https://alfajores-forno.celo-testnet.org');
    kit.addAccount(privkey);
    return kit.web3.currentProvider;
  }z
}
github-actions[bot] commented 2 years ago

This issue is stale and will be closed in 30 days without activity