-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ATL-1925] feat(agent): define key-management interface (2) (#66)
* feat(agent): add keystore subproject * feat(agent): add intefaces & models for custodian layer * docs(agent): add readme about key-mangement * feat(agent): fix as reviewed * feat(agent): implement InMemoryDIDKeyStorage * feat(agent): add tests for InMemoryDIDKeyStorage * feat(agent): add createCustodialDID endpoint * feat(agent): refine createCustodialDID endpoint * feat(agent): refine createCustodialDID endpoint
- Loading branch information
Showing
8 changed files
with
336 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...stodian/src/main/scala/io/iohk/atala/agent/custodian/keystore/InMemoryDIDKeyStorage.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.iohk.atala.agent.custodian.keystore | ||
|
||
import io.iohk.atala.agent.custodian.model.ECKeyPair | ||
import io.iohk.atala.castor.core.model.did.DID | ||
import zio.{Ref, Task, ULayer, ZLayer} | ||
|
||
private[custodian] class InMemoryDIDKeyStorage(store: Ref[Map[DID, Map[String, ECKeyPair]]]) extends DIDKeyStorage { | ||
override def listKeys(did: DID): Task[Map[String, ECKeyPair]] = store.get.map(_.getOrElse(did, Map.empty)) | ||
|
||
override def getKey(did: DID, keyId: String): Task[Option[ECKeyPair]] = listKeys(did).map(_.get(keyId)) | ||
|
||
override def upsertKey(did: DID, keyId: String, keyPair: ECKeyPair): Task[Unit] = store | ||
.update { currentStore => | ||
val currentStoredKeys = currentStore.getOrElse(did, Map.empty) | ||
val updatedStoredKeys = currentStoredKeys.updated(keyId, keyPair) | ||
currentStore.updated(did, updatedStoredKeys) | ||
} | ||
|
||
override def removeKey(did: DID, keyId: String): Task[Option[ECKeyPair]] = store | ||
.getAndUpdate { currentStore => | ||
val currentStoredKeys = currentStore.getOrElse(did, Map.empty) | ||
val updatedStoredKeys = currentStoredKeys.removed(keyId) | ||
currentStore.updated(did, updatedStoredKeys) | ||
} | ||
.map(_.getOrElse(did, Map.empty).get(keyId)) | ||
|
||
} | ||
|
||
private[custodian] object InMemoryDIDKeyStorage { | ||
val layer: ULayer[DIDKeyStorage] = { | ||
ZLayer.fromZIO( | ||
Ref.make(Map.empty[DID, Map[String, ECKeyPair]]).map(store => InMemoryDIDKeyStorage(store)) | ||
) | ||
} | ||
} |
Oops, something went wrong.