ECPair.fromWIF constructor

ECPair.fromWIF(String wifPrivateKey, { Network network })

Creates a keypair from the private key provided in WIF format

Implementation

factory ECPair.fromWIF(String wifPrivateKey, {Network network}) {
  wif.WIF decoded = wif.decode(wifPrivateKey);
  final version = decoded.version;
  // TODO support multi networks
  Network nw;
  if (network != null) {
    nw = network;
    if (nw.private != version) throw ArgumentError("Invalid network version");
  } else {
    if (version == Network.bchPrivate) {
      nw = Network.bitcoinCash();
    } else if (version == Network.bchTestnetPrivate) {
      nw = Network.bitcoinCashTest();
    } else {
      throw ArgumentError("Unknown network version");
    }
  }
  return ECPair.fromPrivateKey(decoded.privateKey,
    compressed: decoded.compressed, network: nw);
}