importAccount method
Future
importAccount({
- required KeyType keyType,
- required String key,
- required dynamic name,
- required dynamic password,
- CryptoType cryptoType = CryptoType.sr25519,
- 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;
}