@@ -82,7 +82,7 @@ class EThree
8282
8383 private val virgilCrypto = VirgilCrypto ()
8484 private val cardManager: CardManager
85- private val localKeyStorage : KeyManagerLocal
85+ private val keyManagerLocal : KeyManagerLocal
8686 private val keyManagerCloud: KeyManagerCloud
8787
8888 init {
@@ -92,7 +92,7 @@ class EThree
9292 VirgilCardVerifier (cardCrypto, false , false ),
9393 VirgilCardClient (VIRGIL_BASE_URL + VIRGIL_CARDS_SERVICE_PATH ))
9494 }
95- localKeyStorage = KeyManagerLocal (tokenProvider.getToken(NO_CONTEXT ).identity, context)
95+ keyManagerLocal = KeyManagerLocal (tokenProvider.getToken(NO_CONTEXT ).identity, context)
9696 keyManagerCloud = KeyManagerCloud (currentIdentity(), tokenProvider)
9797 }
9898
@@ -109,7 +109,7 @@ class EThree
109109 throw RegistrationException (" Card with identity " +
110110 " ${currentIdentity()} already exists" )
111111
112- if (localKeyStorage .exists())
112+ if (keyManagerLocal .exists())
113113 throw PrivateKeyExistsException (" You already have a Private Key on this " +
114114 " device for identity: ${currentIdentity()} . " +
115115 " Please, use \' cleanup()\' function first." )
@@ -119,7 +119,7 @@ class EThree
119119 this .publicKey,
120120 currentIdentity())
121121
122- localKeyStorage .store(this .privateKey.rawKey)
122+ keyManagerLocal .store(this .privateKey.rawKey)
123123 }
124124 }
125125
@@ -139,9 +139,15 @@ class EThree
139139 fun cleanup () {
140140 checkPrivateKeyOrThrow()
141141
142- localKeyStorage .delete()
142+ keyManagerLocal .delete()
143143 }
144144
145+ /* *
146+ * Checks whether the private key is present in the local storage of current device.
147+ * Returns *true* if the key is present in the local key storage otherwise *false*.
148+ */
149+ fun hasLocalPrivateKey () = keyManagerLocal.exists()
150+
145151 /* *
146152 * Encrypts the user's private key using the user's [password] and backs up the encrypted
147153 * private key to Virgil's cloud. This enables users to log in from other devices and have
@@ -164,7 +170,7 @@ class EThree
164170 if (password.isBlank())
165171 throw IllegalArgumentException (" \' password\' should not be empty" )
166172
167- with (localKeyStorage .load()) {
173+ with (keyManagerLocal .load()) {
168174 keyManagerCloud.store(password,
169175 this .value,
170176 this .meta)
@@ -222,7 +228,7 @@ class EThree
222228 */
223229 fun restorePrivateKey (password : String ): Deferred <Unit > = GlobalScope .asyncWithCatch(
224230 {
225- if (localKeyStorage .exists())
231+ if (keyManagerLocal .exists())
226232 throw RestoreKeyException (" You already have a Private Key on this device" +
227233 " for identity: ${currentIdentity()} . Please, use" +
228234 " \' cleanup()\' function first." )
@@ -233,7 +239,7 @@ class EThree
233239
234240 val keyEntry = keyManagerCloud.retrieve(password)
235241
236- localKeyStorage .store(keyEntry.data)
242+ keyManagerLocal .store(keyEntry.data)
237243 } else {
238244 throw RestoreKeyException (" There is no key backup with " +
239245 " identity: ${currentIdentity()} " )
@@ -256,7 +262,7 @@ class EThree
256262 * @throws CryptoException
257263 */
258264 fun rotatePrivateKey (): Deferred <Unit > = GlobalScope .async {
259- if (localKeyStorage .exists())
265+ if (keyManagerLocal .exists())
260266 throw PrivateKeyExistsException (" You already have a Private Key on this device" +
261267 " for identity: ${currentIdentity()} . Please, use" +
262268 " \' cleanup()\' function first." )
@@ -278,7 +284,7 @@ class EThree
278284 this .first.identifier)
279285 cardManager.publishCard(rawCard)
280286
281- localKeyStorage .store(this .second.privateKey.rawKey)
287+ keyManagerLocal .store(this .second.privateKey.rawKey)
282288 }
283289 }
284290
@@ -486,7 +492,7 @@ class EThree
486492 * from [tokenProvider].
487493 */
488494 private fun loadCurrentPrivateKey (): PrivateKey =
489- localKeyStorage .load().let {
495+ keyManagerLocal .load().let {
490496 virgilCrypto.importPrivateKey(it.value)
491497 }
492498
@@ -507,7 +513,7 @@ class EThree
507513 * [PrivateKeyNotFoundException] exception.
508514 */
509515 private fun checkPrivateKeyOrThrow () {
510- if (! localKeyStorage .exists())
516+ if (! keyManagerLocal .exists())
511517 throw PrivateKeyNotFoundException (" You have to get private key first. Use " +
512518 " \' register\' or \' restorePrivateKey\' functions." )
513519 }
0 commit comments