Long time ago I created an account: Ae2tdPwUPEYydDNeSeZEym7cfEdoA31tREpZEkq7JbE6SU9B4wvonrqNWys using mnemonics.
let mnemonics = XXXXXXX;
let password = YYYYYYY;
let seed = bip39::Seed::from_mnemonic_string(&mnemonics, &password);
let xprv = XPrv::generate_from_bip39(&seed);
let wallet = bip44::Wallet::from_root_key(xprv, Default::default());
let account = wallet.create_account("", account_index).public();
let addr_type = if internal == 1 {
bip44::AddrType::Internal
} else {
bip44::AddrType::External
};
let mut c_address = ffi::CString::new("");
account.address_generator(addr_type, from_index)
.expect("we expect the derivation to happen successfully")
.take(num_indices)
.enumerate()
.map(|(_idx, xpub)| {
let address = address::ExtendedAddr::new_simple(*xpub.unwrap(), ProtocolMagic::default().into());
c_address = Ok(ffi_address_to_base58(&address));
}).count();
This xprv work find on byron mainnet, now I want to transfer fund from Ae2tdPwUPEYydDNeSeZEym7cfEdoA31tREpZEkq7JbE6SU9B4wvonrqNWys to an Ed25519 account address on incentivized testnet but I don't know to create an ed25519_sk & ed25519_pk key pairs from that mnemonics and password to sign the transfer transaction from Ae2tdPwUPEYydDNeSeZEym7cfEdoA31tREpZEkq7JbE6SU9B4wvonrqNWys.
You can refer to this code to see how to get a ed25519bip32 from a mnemonic https://repl.it/repls/IndolentWarmheartedDehardwarization
Once you have that, you can use either the same site or JCLI to derive the key down to the ed25519bip32 key for the index you want. You can then use JCLI again to create a legacy-witness to sign the transaction.
Alternatively if you want to do this more programmatically you can check out the EMURGO fork of js-chain-libs which has support for this
bip32 key creation & derivation: https://github.com/Emurgo/js-chain-libs/pull/7
legacy utxo signing: https://github.com/Emurgo/js-chain-libs/pull/9
Thank @SebastienGllmt for your help, the problem is I created bip44 wallet from bip39 seed (64 bytes seed) and your way are recover a bip44 wallet from an entropy with 96 (XPRV_SIZE) bytes seed length:
Bip44RootPrivateKey:
pub fn recover(entropy: &Entropy, password: &str) -> Result<Bip44RootPrivateKey, JsValue> {
let key = PrivateKey::new(entropy, password);
let rpk = Bip44RootPrivateKey {
key: key,
derivation_scheme: DerivationScheme::v2(),
};
Ok(rpk)
}
PrivateKey:
pub fn new(entropy: &Entropy, password: &str) -> PrivateKey {
let mut bytes = [0; hdwallet::XPRV_SIZE];
wallet::keygen::generate_seed(&entropy.0, password.as_bytes(), &mut bytes);
PrivateKey(hdwallet::XPrv::normalize_bytes(bytes))
}
So mean that there're no way I can't recover my address on incentivized testnet. More info for my first commented:
mnemonics: abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about
password: password
seed 319a85221b9c4ce9a2896ed8cb2c0ea205c44c512d9214c9d80e663b8aa97f09e5e4810e2d85ef57d770279d2aea6d3f0e448de3a8e0c1ea9db691d0cb6bc681
xprv 70985cc267f3e7374377475306aff888e494fcd591b38c044d90347b4553f646b42a7dc2f1be2122129a36904ada578850464d6cbf78e4ba522c88ac12496c26e5e4810e2d85ef57d770279d2aea6d3f0e448de3a8e0c1ea9db691d0cb6bc681
address type External index 0 generated: Ae2tdPwUPEZ3to1tD3ovyREAN5AajAPWuehHRSd5kNkTqgv2zkk4W4v14cS
You can use any bip39 library to convert a mnemonic to entropy. We use https://github.com/bitcoinjs/bip39 in Yoroi. Be careful to only use these libraries to do mnemonic -> entropy. You CANNOT use mnemonic -> seed because the algorithm to generate a seed in Cardano is different than Bitcoin (which is what their library implements)
Thank you @SebastienGllmt, I can generate Ed25519Bip32 key, sign the legacy-utxo transaction and it execute successfully.
Most helpful comment
Alternatively if you want to do this more programmatically you can check out the EMURGO fork of js-chain-libs which has support for this
bip32 key creation & derivation: https://github.com/Emurgo/js-chain-libs/pull/7
legacy utxo signing: https://github.com/Emurgo/js-chain-libs/pull/9