-
-
Save oviniciusfeitosa/03480223dc4519f21582c4648b2194f8 to your computer and use it in GitHub Desktop.
Flutter + Ethereum BIP39, BIP32
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:bip39/bip39.dart' as bip39; | |
import "package:hex/hex.dart"; | |
import 'package:web3dart/credentials.dart'; | |
import 'package:bip32/bip32.dart' as bip32; | |
abstract class OKAddressETH { | |
String generateMnemonic(); | |
String getPrivateKey(String mnemonic); | |
Future<EthereumAddress> getPublicAddress(String privateKey); | |
} | |
class OKAddress implements OKAddressETH { | |
@override | |
String generateMnemonic() { | |
return bip39.generateMnemonic(); | |
} | |
@override | |
String getPrivateKey(String mnemonic) { | |
final privateKey = HEX.encode(master.key); | |
final root = bip32.BIP32.fromSeed(HEX.decode(seed)); | |
final child1 = root.derivePath("m/44'/60'/0'/0/0"); | |
final privateKey = HEX.encode(child1.privateKey); | |
return privateKey; | |
} | |
@override | |
Future<EthereumAddress> getPublicAddress(String privateKey) async { | |
final private = EthPrivateKey.fromHex(privateKey); | |
final address = await private.extractAddress(); | |
return address; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment