Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: restore process duplicates did peers #173

Merged
merged 3 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
@file:Suppress("ktlint:standard:import-ordering")

package org.hyperledger.identus.walletsdk.pluto

import java.util.*
import kotlinx.serialization.EncodeDefault
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.KSerializer
Expand Down Expand Up @@ -32,11 +35,12 @@ import org.hyperledger.identus.walletsdk.domain.models.keyManagement.IndexKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.JWK
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.PrivateKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.StorableKey
import org.hyperledger.identus.walletsdk.pluto.PlutoRestoreTask.BackUpMessage.JsonAsStringSerializer.descriptor
import org.hyperledger.identus.walletsdk.pluto.PlutoRestoreTask.BackUpMessage.JsonAsStringSerializer.deserialize
import org.hyperledger.identus.walletsdk.pluto.PlutoRestoreTask.BackUpMessage.JsonAsStringSerializer.serialize
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.JWTCredential
import java.util.*
import kotlin.jvm.Throws
import kotlin.time.DurationUnit
import kotlin.time.toDuration

Expand All @@ -57,12 +61,12 @@ open class PlutoRestoreTask(
*/
fun run() {
restoreCredentials()
restoreDids()
restoreDidPairs()
restoreKeys()
restoreLinkSecret()
restoreMessages()
restoreMediators()
restoreDids()
}

/**
Expand Down Expand Up @@ -169,14 +173,21 @@ open class PlutoRestoreTask(
}.forEach {
if (it.third is DID) {
if (it.third.toString().contains("peer")) {
val metaId = (it.third as DID).toString()
val origDid = (it.third as DID)
val did = if (origDid.toString().contains("#")) {
val splits = origDid.toString().split("#")
DID(splits[0])
} else {
DID(origDid.toString())
}
val keyId = origDid.toString()
pluto.storePrivateKeys(
it.first as StorableKey,
it.third as DID,
did,
(it.first.keySpecification[IndexKey().property])?.toInt(),
metaId
keyId
)
pluto.storePeerDID(it.third as DID)
// pluto.storePeerDID(did)
} else {
pluto.storePrismDIDAndPrivateKeys(
it.third as DID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ class BackupRestorationTests {

// Validates DIDs are backed up and restored properly, and passed to pluto for storage
val didCaptor = argumentCaptor<DID>()
verify(edgeAgent.pluto, times(9)).storePeerDID(didCaptor.capture())
assertEquals(9, didCaptor.allValues.size)
verify(edgeAgent.pluto, times(5)).storePeerDID(didCaptor.capture())
assertEquals(5, didCaptor.allValues.size)

assertTrue {
didCaptor.allValues.contains(DID("did:peer:2.Ez6LSok96TA4orHQXSMHZj3mqyUuVLMfLfGGqj27i1giErbXL.Vz6Mku5mY1GuJ9AN2vvDwjMv5QUC2zqKVRPCcbmJVYTFTCFmr"))
Expand All @@ -328,18 +328,6 @@ class BackupRestorationTests {
assertTrue {
didCaptor.allValues.contains(DID("did:prism:0a4b552169e3158781741fbbeffe81212784d32d90cf8f2622923f11f6ecd966:CoUBCoIBEjsKB21hc3RlcjAQAUouCglzZWNwMjU2azESIQLgzhsuOqhAyImy-c8o9ZmIJ4iY_Gc8tvNIT3l1w58f2BJDCg9hdXRoZW50aWNhdGlvbjAQBEouCglzZWNwMjU2azESIQLgzhsuOqhAyImy-c8o9ZmIJ4iY_Gc8tvNIT3l1w58f2A"))
}
assertTrue {
didCaptor.allValues.contains(DID("did:peer:2.Ez6LSok96TA4orHQXSMHZj3mqyUuVLMfLfGGqj27i1giErbXL.Vz6Mku5mY1GuJ9AN2vvDwjMv5QUC2zqKVRPCcbmJVYTFTCFmr#key-2"))
}
assertTrue {
didCaptor.allValues.contains(DID("did:peer:2.Ez6LSok96TA4orHQXSMHZj3mqyUuVLMfLfGGqj27i1giErbXL.Vz6Mku5mY1GuJ9AN2vvDwjMv5QUC2zqKVRPCcbmJVYTFTCFmr#key-1"))
}
assertTrue {
didCaptor.allValues.contains(DID("did:peer:2.Ez6LSqWfJdwLMDmpew7Yd8AQS2MxDwvSCNpjaZ7EQVst8rkfA.Vz6MknpCj4WomXhC2eur8nf4wnoFzHpCA6EAFU6afEmmrUVRA.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6ImRpZDpwZWVyOjIuRXo2TFNnaHdTRTQzN3duREUxcHQzWDZoVkRVUXpTanNIemlucFgzWEZ2TWpSQW03eS5WejZNa2hoMWU1Q0VZWXE2SkJVY1RaNkNwMnJhbkNXUnJ2N1lheDNMZTRONTlSNmRkLlNleUowSWpvaVpHMGlMQ0p6SWpwN0luVnlhU0k2SW1oMGRIQnpPaTh2YzJsMExYQnlhWE50TFcxbFpHbGhkRzl5TG1GMFlXeGhjSEpwYzIwdWFXOGlMQ0poSWpwYkltUnBaR052YlcwdmRqSWlYWDE5LlNleUowSWpvaVpHMGlMQ0p6SWpwN0luVnlhU0k2SW5kemN6b3ZMM05wZEMxd2NtbHpiUzF0WldScFlYUnZjaTVoZEdGc1lYQnlhWE50TG1sdkwzZHpJaXdpWVNJNld5SmthV1JqYjIxdEwzWXlJbDE5ZlEiLCJyIjpbXSwiYSI6W119fQ#key-2"))
}
assertTrue {
didCaptor.allValues.contains(DID("did:peer:2.Ez6LSqWfJdwLMDmpew7Yd8AQS2MxDwvSCNpjaZ7EQVst8rkfA.Vz6MknpCj4WomXhC2eur8nf4wnoFzHpCA6EAFU6afEmmrUVRA.SeyJ0IjoiZG0iLCJzIjp7InVyaSI6ImRpZDpwZWVyOjIuRXo2TFNnaHdTRTQzN3duREUxcHQzWDZoVkRVUXpTanNIemlucFgzWEZ2TWpSQW03eS5WejZNa2hoMWU1Q0VZWXE2SkJVY1RaNkNwMnJhbkNXUnJ2N1lheDNMZTRONTlSNmRkLlNleUowSWpvaVpHMGlMQ0p6SWpwN0luVnlhU0k2SW1oMGRIQnpPaTh2YzJsMExYQnlhWE50TFcxbFpHbGhkRzl5TG1GMFlXeGhjSEpwYzIwdWFXOGlMQ0poSWpwYkltUnBaR052YlcwdmRqSWlYWDE5LlNleUowSWpvaVpHMGlMQ0p6SWpwN0luVnlhU0k2SW5kemN6b3ZMM05wZEMxd2NtbHpiUzF0WldScFlYUnZjaTVoZEdGc1lYQnlhWE50TG1sdkwzZHpJaXdpWVNJNld5SmthV1JqYjIxdEwzWXlJbDE5ZlEiLCJyIjpbXSwiYSI6W119fQ#key-1"))
}

// Validates DID pairs are backed up and restored properly, and passed to pluto for storage
val didPairsHostCaptor = argumentCaptor<DID>()
Expand Down Expand Up @@ -371,7 +359,7 @@ class BackupRestorationTests {
)
// 9 because of already ran items and items in the key backup
val keysDidCaptor2 = argumentCaptor<DID>()
verify(edgeAgent.pluto, times(9)).storePeerDID(keysDidCaptor2.capture())
verify(edgeAgent.pluto, times(5)).storePeerDID(keysDidCaptor2.capture())

val keysCaptor = argumentCaptor<StorableKey>()
val keysDidCaptor3 = argumentCaptor<DID>()
Expand Down

Large diffs are not rendered by default.

Loading