readExternalWallet static method
Reads an external wallet from a byte array and returns a list of AddressObject.
Parameters:
fileBytes: The byte array representing the external wallet file.isIngoreVerification: ignore the verification of addresses with a signature in order to quickly import large addresses or addresses locked in a file
Returns: A list of AddressObject parsed from the byte array, or null if the fileBytes is null or empty.
Implementation
static List<AddressObject>? readExternalWallet(Uint8List? fileBytes,
{bool isIngoreVerification = false}) {
final List<AddressObject> addresses = [];
if (fileBytes == null || fileBytes.isEmpty) {
return null;
}
try {
int cursor = 0;
while (cursor + 625 <= fileBytes.length) {
Uint8List current = fileBytes.sublist(cursor, cursor + 625);
cursor += 626;
var hash = String.fromCharCodes(current.sublist(1, current[0] + 1));
var custom =
String.fromCharCodes(current.sublist(42, 42 + current[41]));
AddressObject addressObject = AddressObject(
hash: hash,
custom: custom.isEmpty ? null : custom,
publicKey:
String.fromCharCodes(current.sublist(83, 83 + current[82])),
privateKey:
String.fromCharCodes(current.sublist(339, 339 + current[338])));
var keyPair = KeyPair(
publicKey: addressObject.publicKey,
privateKey: addressObject.privateKey);
if (keyPair.isValid()) {
if (isIngoreVerification) {
addresses.add(addressObject);
} else {
bool verification = NosoSigner().verifyKeysPair(keyPair);
if (verification) {
addresses.add(addressObject);
}
}
}
}
return addresses.isEmpty ? null : addresses;
} catch (e) {
print("Error readExternalWallet: $e");
return null;
}
}