From 23c6a19d4e139cb178dc2c5d08a73b2208ebf6f5 Mon Sep 17 00:00:00 2001 From: Rogelio Blanco Date: Tue, 21 Jun 2022 21:02:55 -0600 Subject: [PATCH] Refactor #21 - Add external persistence storage - Clean code - Fix package names - Update project version - Move Wallet extensions out of the interface --- build.gradle.kts | 19 +++++++++--------- .../rootsid/wal/library/dlt/model/Claim.kt | 2 -- .../rootsid/wal/library/dlt/model/KeyPath.kt | 2 -- .../com/rootsid/wal/library/utils/QR.kt | 2 +- .../wal/library/wallet/model/Wallet.kt | 20 +++++++++---------- .../storage/document/DocumentStorage.kt | 3 +-- .../wallet/storage/document/WalletDocument.kt | 1 - .../com/rootsid/wal/library/DLTKtTest.kt | 2 -- 8 files changed, 21 insertions(+), 30 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 3b7fae3..3fe9802 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,7 +5,7 @@ plugins { } group = "com.rootsid.wal" -version = "1.0.2" +version = "2.0.0" java.sourceCompatibility = JavaVersion.VERSION_11 repositories { @@ -23,6 +23,12 @@ repositories { } dependencies { + // Align versions of all Kotlin components + implementation(platform("org.jetbrains.kotlin:kotlin-bom")) + + // Use the Kotlin JDK 8 standard library. + implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + implementation("org.jetbrains.kotlin:kotlin-stdlib:1.6.10") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0-native-mt") implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.3.2") @@ -47,13 +53,8 @@ dependencies { implementation("org.didcommx:didcomm:0.3.0") implementation("org.didcommx:peerdid:0.3.0") - implementation("org.junit.jupiter:junit-jupiter:5.8.2") - - // Align versions of all Kotlin components - implementation(platform("org.jetbrains.kotlin:kotlin-bom")) - - // Use the Kotlin JDK 8 standard library. - implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + // Test + testImplementation("org.junit.jupiter:junit-jupiter:5.8.2") } publishing { @@ -76,7 +77,7 @@ publishing { } } -tasks.withType() { +tasks.withType { kotlinOptions.jvmTarget = "11" } diff --git a/src/main/kotlin/com/rootsid/wal/library/dlt/model/Claim.kt b/src/main/kotlin/com/rootsid/wal/library/dlt/model/Claim.kt index cb2008d..09c7513 100644 --- a/src/main/kotlin/com/rootsid/wal/library/dlt/model/Claim.kt +++ b/src/main/kotlin/com/rootsid/wal/library/dlt/model/Claim.kt @@ -2,7 +2,6 @@ package com.rootsid.wal.library.dlt.model import io.iohk.atala.prism.api.CredentialClaim import io.iohk.atala.prism.identity.PrismDid -import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.Serializable import kotlinx.serialization.decodeFromString import kotlinx.serialization.json.Json @@ -25,7 +24,6 @@ data class Claim( * * Convert a Claim to PRISM CredentialClaim */ -@OptIn(ExperimentalSerializationApi::class) fun Claim.toCredentialClaim() = CredentialClaim( PrismDid.fromString(this.subjectDid), Json.decodeFromString(this.content) diff --git a/src/main/kotlin/com/rootsid/wal/library/dlt/model/KeyPath.kt b/src/main/kotlin/com/rootsid/wal/library/dlt/model/KeyPath.kt index 1119138..65175ff 100644 --- a/src/main/kotlin/com/rootsid/wal/library/dlt/model/KeyPath.kt +++ b/src/main/kotlin/com/rootsid/wal/library/dlt/model/KeyPath.kt @@ -9,8 +9,6 @@ import kotlinx.serialization.Serializable * @property didIdx * @property keyTypeValue * @property keyIdx - * @property privateKey - * @property publicKey * @property revoked * @constructor Create empty Key pair */ diff --git a/src/main/kotlin/com/rootsid/wal/library/utils/QR.kt b/src/main/kotlin/com/rootsid/wal/library/utils/QR.kt index 537f07e..77609db 100644 --- a/src/main/kotlin/com/rootsid/wal/library/utils/QR.kt +++ b/src/main/kotlin/com/rootsid/wal/library/utils/QR.kt @@ -1,4 +1,4 @@ -package com.rootsid.wal.library +package com.rootsid.wal.library.utils import boofcv.alg.fiducial.qrcode.QrCodeEncoder import boofcv.alg.fiducial.qrcode.QrCodeGeneratorImage diff --git a/src/main/kotlin/com/rootsid/wal/library/wallet/model/Wallet.kt b/src/main/kotlin/com/rootsid/wal/library/wallet/model/Wallet.kt index f0f47ec..69b3d45 100644 --- a/src/main/kotlin/com/rootsid/wal/library/wallet/model/Wallet.kt +++ b/src/main/kotlin/com/rootsid/wal/library/wallet/model/Wallet.kt @@ -6,8 +6,6 @@ import com.rootsid.wal.library.dlt.model.Did * Wallet * * @property _id - * @property mnemonic - * @property passphrase * @property dids * @property importedCredentials * @property issuedCredentials @@ -21,16 +19,16 @@ interface Wallet { var importedCredentials: MutableList // List of credentials issued by a DID from this wallet var issuedCredentials: MutableList +} - fun addDid(did: Did) { - dids.add(did) - } +fun Wallet.addDid(did: Did) { + dids.add(did) +} - fun addImportedCredential(credential: ImportedCredential) { - importedCredentials.add(credential) - } +fun Wallet.addImportedCredential(credential: ImportedCredential) { + importedCredentials.add(credential) +} - fun addIssuedCredential(credential: IssuedCredential) { - issuedCredentials.add(credential) - } +fun Wallet.addIssuedCredential(credential: IssuedCredential) { + issuedCredentials.add(credential) } diff --git a/src/main/kotlin/com/rootsid/wal/library/wallet/storage/document/DocumentStorage.kt b/src/main/kotlin/com/rootsid/wal/library/wallet/storage/document/DocumentStorage.kt index f514027..99603a0 100644 --- a/src/main/kotlin/com/rootsid/wal/library/wallet/storage/document/DocumentStorage.kt +++ b/src/main/kotlin/com/rootsid/wal/library/wallet/storage/document/DocumentStorage.kt @@ -1,9 +1,8 @@ -package com.rootsid.wal.library +package com.rootsid.wal.library.wallet.storage.document import com.mongodb.ConnectionString import com.mongodb.client.MongoDatabase import com.rootsid.wal.library.wallet.model.Wallet -import com.rootsid.wal.library.wallet.storage.document.WalletDocument import com.rootsid.wal.library.wallet.storage.Storage import io.iohk.atala.prism.crypto.util.BytesOps import org.litote.kmongo.* diff --git a/src/main/kotlin/com/rootsid/wal/library/wallet/storage/document/WalletDocument.kt b/src/main/kotlin/com/rootsid/wal/library/wallet/storage/document/WalletDocument.kt index 5782310..a2b7165 100644 --- a/src/main/kotlin/com/rootsid/wal/library/wallet/storage/document/WalletDocument.kt +++ b/src/main/kotlin/com/rootsid/wal/library/wallet/storage/document/WalletDocument.kt @@ -1,7 +1,6 @@ package com.rootsid.wal.library.wallet.storage.document import com.rootsid.wal.library.dlt.model.Did -import com.rootsid.wal.library.wallet.model.BlockchainTxLogEntry import com.rootsid.wal.library.wallet.model.ImportedCredential import com.rootsid.wal.library.wallet.model.IssuedCredential import com.rootsid.wal.library.wallet.model.Wallet diff --git a/src/test/kotlin/com/rootsid/wal/library/DLTKtTest.kt b/src/test/kotlin/com/rootsid/wal/library/DLTKtTest.kt index e244574..d2d2cd4 100644 --- a/src/test/kotlin/com/rootsid/wal/library/DLTKtTest.kt +++ b/src/test/kotlin/com/rootsid/wal/library/DLTKtTest.kt @@ -1,7 +1,5 @@ package com.rootsid.wal.library -import org.junit.jupiter.api.Assertions.* - internal class DLTKtTest { @org.junit.jupiter.api.Test