Skip to content

Commit

Permalink
Merge pull request #1189 from atsign-foundation/verify_atsign_onboarded
Browse files Browse the repository at this point in the history
fix: Add "isOnboarded" method to verify if atSign is onboarded
  • Loading branch information
sitaram-kalluri authored Dec 28, 2023
2 parents dd895c5 + 7985c91 commit 58f1e4e
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/at_client_mobile/lib/at_client_mobile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ export 'src/at_client_service.dart';
export 'src/keychain_manager.dart';
export 'package:at_client/at_client.dart';
export 'src/onboarding_status.dart';
export 'src/auth/at_auth_service.dart';
export 'src/auth/at_auth_service_impl.dart';
7 changes: 7 additions & 0 deletions packages/at_client_mobile/lib/src/auth/at_auth_service.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
abstract class AtAuthService {
/// Checks whether the atSign has been onboarded.
/// Queries the keychain for the encryption public key.
/// If the key is found, the atSign is considered onboarded, and true is returned.
/// Otherwise, false is returned.
Future<bool> isOnboarded(String atSign);
}
32 changes: 32 additions & 0 deletions packages/at_client_mobile/lib/src/auth/at_auth_service_impl.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import 'dart:async';

import 'package:at_client_mobile/at_client_mobile.dart';
import 'package:at_client_mobile/src/atsign_key.dart';

class AtAuthServiceImpl implements AtAuthService {
AtServiceFactory? atServiceFactory;

// ignore: unused_field
final String _atSign;

// ignore: unused_field
final AtClientPreference _atClientPreference;

final KeyChainManager _keyChainManager = KeyChainManager.getInstance();
AtClientManager atClientManager = AtClientManager.getInstance();

AtAuthServiceImpl(this._atSign, this._atClientPreference);

@override
Future<bool> isOnboarded(String atSign) async {
AtsignKey? atsignKey = await _keyChainManager.readAtsign(name: atSign);
if (atsignKey == null) {
return false;
}
if (atsignKey.encryptionPublicKey == null ||
atsignKey.encryptionPublicKey!.isEmpty) {
return false;
}
return true;
}
}

0 comments on commit 58f1e4e

Please sign in to comment.