importAccount method

Future importAccount({
  1. required KeyType keyType,
  2. required String key,
  3. required dynamic name,
  4. required dynamic password,
  5. CryptoType cryptoType = CryptoType.sr25519,
  6. String derivePath = '',
})

Import account from mnemonic/rawSeed/keystore. param cryptoType can be sr25519(default) or ed25519. return null if import failed.

Implementation

Future<dynamic> importAccount({
  required KeyType keyType,
  required String key,
  required name,
  required password,
  CryptoType cryptoType = CryptoType.sr25519,
  String derivePath = '',
}) async {
  // generate json from js-api
  final String type = keyType.toString().split('.')[1];
  final String crypto = cryptoType.toString().split('.')[1];
  String code =
      'keyring.recover("$type", "$crypto", \'$key$derivePath\', "$password")';
  code = code.replaceAll(RegExp(r'\t|\n|\r'), '');
  final dynamic acc = await serviceRoot.webView!.evalJavascript(code);
  if (acc == null || acc['error'] != null) {
    return acc;
  }

  // add metadata to json
  updateKeyPairMetaData(acc, name);

  return acc;
}