onboard method
Returns true
on successfully completing onboarding.
Throws OnboardingStatus.ATSIGN_NOT_FOUND exception if atsign not found.
Throws OnboardingStatus.PRIVATE_KEY_NOT_FOUND exception if privatekey not found.
Implementation
Future<bool> onboard(
{required AtClientPreference atClientPreference, String? atsign}) async {
_atClientAuthenticator = AtClientAuthenticator();
if (atsign == null || atsign == '') {
atsign = await _keyChainManager.getAtSign();
} else {
atsign = _formatAtSign(atsign);
}
if (atsign == null || atsign == '') {
_logger.severe('Atsign not found');
throw OnboardingStatus.ATSIGN_NOT_FOUND;
}
var privateKey = atClientPreference.privateKey;
if (privateKey == null || privateKey == '') {
privateKey = await _keyChainManager.getPkamPrivateKey(atsign);
}
if (privateKey == null || privateKey == '') {
_logger.severe('PrivateKey not found');
throw OnboardingStatus.PRIVATE_KEY_NOT_FOUND;
}
atClientPreference.privateKey = privateKey;
await _init(atsign, atClientPreference);
var keyRestorePolicyStatus = await getKeyRestorePolicy(atsign);
if (keyRestorePolicyStatus == OnboardingStatus.ACTIVATE ||
keyRestorePolicyStatus == OnboardingStatus.RESTORE) {
_status = keyRestorePolicyStatus;
throw (keyRestorePolicyStatus);
}
//no need of having pkam auth as unauth error can be thrown by keypolicy.
var result = await pkamAuth(privateKey);
if (result) await _sync(atClientPreference, atsign);
return result;
}