createAccount method Null safety
- String password
Creates a new Account with the given password
. This process generates a two random 32 byte keys and stores them in the keychain during production and in the temporary
storage during development. Returns CreateAccountResponse
if the account is created successfully.
Example
final res = await MotorFlutter.to.createAccount('terrible-password-123');
if (res == null) {
throw Exception('Account creation failed');
}
print('Account created successfully: ${res.address}');
Next Steps:
- Login with the newly created account using login
- Issue payments to the account using sendTokens
- Buy a .snr/ subdomain to simplify your account address using buyAlias
- ADR-1
Implementation
Future<CreateAccountResponse?> createAccount(String password) async {
final dscKey = e.Key.fromSecureRandom(32);
final pskKey = e.Key.fromSecureRandom(32);
final resp = await MotorFlutterPlatform.instance.createAccountWithKeys(CreateAccountWithKeysRequest(
password: password,
aesDscKey: dscKey.bytes,
aesPskKey: pskKey.bytes,
));
if (resp != null) {
address.value = resp.address;
didDocument.value = resp.whoIs.didDocument;
authorized.value = true;
await writeKeysForAddr(dscKey.bytes, pskKey.bytes, resp.address);
return resp.toDefaultResponse();
}
return null;
}