NearCoin.fromPrivateKey constructor

NearCoin.fromPrivateKey(
  1. dynamic privateKey, [
  2. WalletSetting? setting
])

Implementation

factory NearCoin.fromPrivateKey(dynamic privateKey,
    [WalletSetting? setting]) {
  final wallet = NearCoin(setting: setting);
  if (privateKey.runtimeType.toString() == 'String') {
    if (privateKey.startsWith('ed25519:')) {
      final data = privateKey.substring(8);
      final secretKey = base58.decode(data);
      wallet.initFromPrivateKey(dynamicToUint8List(secretKey.sublist(0, 32)));
    } else {
      wallet.initFromPrivateKey(dynamicToUint8List(privateKey));
    }
  } else {
    throw Exception('Unsupported private key');
  }
  return wallet;
}