-
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.
fix(prism-agent): fix concurrent requests breaking DID index counter (#…
…571) * chore: fix test typo * chore: refactor create did handler * fix: createDID with only 1 permit semaphore * chore: pr cleanup * ci: use undeprecated vault image * chore: pr cleanup
- Loading branch information
Showing
6 changed files
with
124 additions
and
50 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
58 changes: 58 additions & 0 deletions
58
...t-api/src/main/scala/io/iohk/atala/agent/walletapi/service/handler/DIDCreateHandler.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,58 @@ | ||
package io.iohk.atala.agent.walletapi.service.handler | ||
|
||
import io.iohk.atala.agent.walletapi.crypto.Apollo | ||
import io.iohk.atala.agent.walletapi.model.CreateDIDHdKey | ||
import io.iohk.atala.agent.walletapi.model.ManagedDIDState | ||
import io.iohk.atala.agent.walletapi.model.ManagedDIDTemplate | ||
import io.iohk.atala.agent.walletapi.model.error.CreateManagedDIDError | ||
import io.iohk.atala.agent.walletapi.storage.DIDNonSecretStorage | ||
import io.iohk.atala.castor.core.model.did.PrismDIDOperation | ||
import zio.* | ||
import io.iohk.atala.agent.walletapi.util.OperationFactory | ||
import io.iohk.atala.agent.walletapi.model.PublicationState | ||
|
||
private[walletapi] class DIDCreateHandler( | ||
apollo: Apollo, | ||
nonSecretStorage: DIDNonSecretStorage | ||
)( | ||
seed: Array[Byte], | ||
masterKeyId: String | ||
) { | ||
def materialize( | ||
didTemplate: ManagedDIDTemplate | ||
): IO[CreateManagedDIDError, DIDCreateMaterial] = { | ||
val operationFactory = OperationFactory(apollo) | ||
for { | ||
didIndex <- nonSecretStorage | ||
.getMaxDIDIndex() | ||
.mapBoth( | ||
CreateManagedDIDError.WalletStorageError.apply, | ||
maybeIdx => maybeIdx.map(_ + 1).getOrElse(0) | ||
) | ||
generated <- operationFactory.makeCreateOperationHdKey(masterKeyId, seed)(didIndex, didTemplate) | ||
(createOperation, hdKey) = generated | ||
state = ManagedDIDState(createOperation, didIndex, PublicationState.Created()) | ||
} yield DIDCreateMaterialImpl(nonSecretStorage)(createOperation, state, hdKey) | ||
} | ||
} | ||
|
||
private[walletapi] trait DIDCreateMaterial { | ||
def operation: PrismDIDOperation.Create | ||
def state: ManagedDIDState | ||
def persist: Task[Unit] | ||
} | ||
|
||
private[walletapi] class DIDCreateMaterialImpl(nonSecretStorage: DIDNonSecretStorage)( | ||
val operation: PrismDIDOperation.Create, | ||
val state: ManagedDIDState, | ||
hdKey: CreateDIDHdKey | ||
) extends DIDCreateMaterial { | ||
def persist: Task[Unit] = { | ||
val did = operation.did | ||
for { | ||
_ <- nonSecretStorage | ||
.insertManagedDID(did, state, hdKey.keyPaths ++ hdKey.internalKeyPaths) | ||
.mapError(CreateManagedDIDError.WalletStorageError.apply) | ||
} yield () | ||
} | ||
} |
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