Open zhaobinglong opened 4 years ago
deadline: 2019-12-20 size:1
github找到一个库,它使用了助记词才生成钱包:
stackoverflow上的链接: https://stackoverflow.com/questions/55363842/ethereum-hd-wallet-implementation-in-flutter-is-there-any-library-in-flutter
github仓库: https://github.com/allanclempe/ether-wallet-flutter
APP截图:
使用bip39生成助记词和种子
String mnemonic = bip39.generateMnemonic();
String randomMnemonic = bip39.generateMnemonic();
String seed = bip39.mnemonicToSeedHex(randomMnemonic);
如何把种子转换为钱包的私钥呢?这是一个问题
9854f39ea66919065169c2fc154cecad7b82f9fcf0bd6723cea0921fedbe357d f759af1461151e4c6ba0ba38c0d8749df3bb97ef30723e391c2bebe833fabcf3
https://github.com/anicdh/bitcoin_flutter/blob/master/test/integration/bip32_test.dart#L30
test('can create a BIP44, bitcoin, account 0, external address', () {
final root = bip32.BIP32.fromSeed(HEX.decode('dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd'));
final child1 = root.derivePath("m/44'/0'/0'/0/0");
// option 2, manually
final child1b = root.deriveHardened(44)
.deriveHardened(0)
.deriveHardened(0)
.derive(0)
.derive(0);
expect(getAddress(child1), '12Tyvr1U8A3ped6zwMEU5M8cx3G38sP5Au');
expect(getAddress(child1b), '12Tyvr1U8A3ped6zwMEU5M8cx3G38sP5Au');
});
生成钱包私钥和公钥
const mnemonic = 'praise you muffin lion enable neck grocery crumble super myself license ghost';
final seed = bip39.mnemonicToSeed(mnemonic);
final root = bip32.BIP32.fromSeed(seed);
final child1 = root.derivePath("m/44'/60'/0'/0/0");
print( bytesToHex(child1.publicKey));
print( bytesToHex(child1.privateKey));
生成助记词:
计算钱包地址