login method Null safety
Logging In
Logs in to an existing account with the given password
. During production, this method retrieves the keys from the keychain using address
. Both of these params are required in order
to return a successful LoginResponse.
Parameters
address
- The address of the account to login to.password
- The password used to encrypt the wallet shards with AES.pskKey
- The pre-shared key used to encrypt the wallet shards with AES. (optional)dscKey
- The data signing key used to encrypt the wallet shards with AES. (optional)
final res = await MotorFlutter.to.login(password: 'terrible-password-123', did: 'did:snr:abc123');
if (res == null) {
throw Exception('Login failed');
}
print('Account logged in successfully: ${res.address}');
Next Steps
- Define a new blockchain verifiable data model using publishSchema
- Buy a .snr/ subdomain to simplify your account address using buyAlias
- Connect to the p2p network and enable secure device-to-devce communication with connect
- ADR-1
Implementation
Future<WhoIs> login({required String password, required String address, List<int>? pskKey, List<int>? dscKey}) async {
final auth = await readKeysForAddr(address);
if (auth == null && (pskKey == null || dscKey == null)) {
throw Exception('No keys found for did: $address');
}
final resp = await MotorFlutterPlatform.instance.loginWithKeys(LoginWithKeysRequest(
did: address,
password: password,
aesDscKey: auth?.item1 ?? dscKey,
aesPskKey: auth?.item2 ?? pskKey,
));
if (resp == null) {
throw UnmarshalException<LoginResponse>();
}
this.address.value = resp.whoIs.owner;
didDocument.value = resp.whoIs.didDocument;
authorized.value = true;
return resp.whoIs;
}