Skip to content

Commit

Permalink
chore: clean up code, add some inline docs and improve code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianIOHK committed Jun 7, 2024
1 parent 8ce7b43 commit 11f2835
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*@file:Suppress("ktlint:standard:import-ordering")
@file:Suppress("ktlint:standard:import-ordering")

package org.hyperledger.identus.walletsdk.edgeagent

Expand Down Expand Up @@ -185,4 +185,4 @@ class AnoncredsTests {
}
}
}
}*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ interface Pluto {
*/
fun storePrivateKeys(storableKey: StorableKey, did: DID, keyPathIndex: Int, metaId: String? = null)

/**
* Stores a private key with its recovery ID.
*
* @param storableKey The private key to store. Must implement the [StorableKey] interface.
* @param recoveryId String that identifies the type of key used on recovery process.
*/
fun storePrivate(sorableKey: StorableKey, recoveryId: String)

/**
Expand Down Expand Up @@ -380,19 +386,5 @@ interface Pluto {
*/
fun observeRevokedCredentials(): Flow<List<CredentialRecovery>>

/**
* Create a Backup object from the stored data.
*/
suspend fun backup(): Flow<BackupV0_0_1>

/**
* Load the given data into the store.
*
* @param backup The backup object to be restored.
*/
suspend fun restore(backup: BackupV0_0_1, castor: Castor, pollux: Pollux): Flow<Unit>

fun getAllKeysForBackUp(): Flow<List<BackupV0_0_1.Key>>

// Top-level class to encapsulate the backup structure
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ import org.hyperledger.identus.walletsdk.logger.LogComponent
import org.hyperledger.identus.walletsdk.logger.Metadata
import org.hyperledger.identus.walletsdk.logger.PrismLogger
import org.hyperledger.identus.walletsdk.logger.PrismLoggerImpl
import org.hyperledger.identus.walletsdk.pluto.PlutoBackupTask
import org.hyperledger.identus.walletsdk.pluto.PlutoRestoreTask
import org.hyperledger.identus.walletsdk.pluto.backup.models.BackupV0_0_1
import org.hyperledger.identus.walletsdk.pollux.models.AnonCredential
import org.hyperledger.identus.walletsdk.pollux.models.CredentialRequestMeta
Expand Down Expand Up @@ -1204,7 +1206,8 @@ class EdgeAgent {
val header = JWEHeader.Builder(JWEAlgorithm.ECDH_ES_A256KW, EncryptionMethod.A256CBC_HS512)
.build()

val backup = pluto.backup().first()
val backupTask = PlutoBackupTask(pluto)
val backup = backupTask.run().first()

// 4. Create a JWE object
val payloadString = Json.encodeToString(backup)
Expand Down Expand Up @@ -1258,6 +1261,9 @@ class EdgeAgent {

// 7. Restore the pluto instance
pluto.restore(backupObject, castor, pollux)

val restoreTask = PlutoRestoreTask(pluto, castor, pollux, backupObject)
restoreTask.run()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,11 @@ class PlutoImpl(private val connection: DbConnection) : Pluto {
}
}

/**
* Retrieves all DIDs.
*
* @return A flow of lists of DIDs.
*/
override fun getAllDIDs(): Flow<List<DID>> {
return getInstance().dIDQueries.fetchAllDIDs()
.asFlow()
Expand Down Expand Up @@ -707,6 +712,12 @@ class PlutoImpl(private val connection: DbConnection) : Pluto {
}
}

/**
* Retrieves all the messages of the provided type.
*
* @param type The message type as a string
* @return a Flow of List of Message objects representing all the messages of the type
*/
override fun getAllMessagesByType(type: String): Flow<List<Message>> {
return getInstance().messageQueries.fetchAllMessagesByType(type)
.asFlow()
Expand Down Expand Up @@ -1222,22 +1233,4 @@ class PlutoImpl(private val connection: DbConnection) : Pluto {
val keys = keysWithDID + keysWithNoDID
return flowOf(keys)
}

/**
* Create a Backup object from the stored data.
*/
override suspend fun backup(): Flow<BackupV0_0_1> {
val backupTask = PlutoBackupTask(this)
return backupTask.run()
}

/**
* Load the given data into the store.
*
* @param backup The backup object to be restored.
*/
override suspend fun restore(backup: BackupV0_0_1, castor: Castor, pollux: Pollux): Flow<Unit> {
val restoreTask = PlutoRestoreTask(this, castor, pollux, backup)
return flowOf(restoreTask.run())
}
}

0 comments on commit 11f2835

Please sign in to comment.