-
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.
feat(prism-agent): check issuing DID validity when creating a VC offe…
…r + return 'metaRetries' (#740) Signed-off-by: Benjamin Voiturier <[email protected]> Signed-off-by: Milos Backonja <[email protected]> Signed-off-by: Anton Baliasnikov <[email protected]> Signed-off-by: Pat Losoponkul <[email protected]> Co-authored-by: Milos Backonja <[email protected]> Co-authored-by: atala-dev <[email protected]> Co-authored-by: patlo-iog <[email protected]> Signed-off-by: Shota Jolbordi <[email protected]>
- Loading branch information
1 parent
33c90c1
commit 3a55455
Showing
32 changed files
with
286 additions
and
75 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
94 changes: 94 additions & 0 deletions
94
castor/lib/core/src/main/scala/io/iohk/atala/castor/core/service/MockDIDService.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,94 @@ | ||
package io.iohk.atala.castor.core.service | ||
|
||
import io.iohk.atala.castor.core.model.did.* | ||
import io.iohk.atala.castor.core.model.error | ||
import io.iohk.atala.prism.crypto.EC | ||
import io.iohk.atala.prism.crypto.keys.ECKeyPair | ||
import io.iohk.atala.shared.models.Base64UrlString | ||
import zio.mock.{Expectation, Mock, Proxy} | ||
import zio.test.Assertion | ||
import zio.{IO, URLayer, ZIO, ZLayer, mock} | ||
|
||
import scala.collection.immutable.ArraySeq | ||
|
||
object MockDIDService extends Mock[DIDService] { | ||
|
||
object ScheduleOperation extends Effect[SignedPrismDIDOperation, error.DIDOperationError, ScheduleDIDOperationOutcome] | ||
// FIXME leaving this out for now as it gives a "java.lang.AssertionError: assertion failed: class Array" compilation error | ||
// object GetScheduledDIDOperationDetail extends Effect[Array[Byte], error.DIDOperationError, Option[ScheduledDIDOperationDetail]] | ||
object ResolveDID extends Effect[PrismDID, error.DIDResolutionError, Option[(DIDMetadata, DIDData)]] | ||
|
||
override val compose: URLayer[mock.Proxy, DIDService] = | ||
ZLayer { | ||
for { | ||
proxy <- ZIO.service[Proxy] | ||
} yield new DIDService { | ||
override def scheduleOperation( | ||
operation: SignedPrismDIDOperation | ||
): IO[error.DIDOperationError, ScheduleDIDOperationOutcome] = | ||
proxy(ScheduleOperation, operation) | ||
|
||
override def getScheduledDIDOperationDetail( | ||
operationId: Array[Byte] | ||
): IO[error.DIDOperationError, Option[ScheduledDIDOperationDetail]] = | ||
??? | ||
|
||
override def resolveDID(did: PrismDID): IO[error.DIDResolutionError, Option[(DIDMetadata, DIDData)]] = | ||
proxy(ResolveDID, did) | ||
} | ||
} | ||
|
||
def createDID( | ||
verificationRelationship: VerificationRelationship | ||
): (PrismDIDOperation.Create, ECKeyPair, DIDMetadata, DIDData) = { | ||
val masterKeyPair = EC.INSTANCE.generateKeyPair() | ||
val keyPair = EC.INSTANCE.generateKeyPair() | ||
val createOperation = PrismDIDOperation.Create( | ||
publicKeys = Seq( | ||
InternalPublicKey( | ||
id = "master-0", | ||
purpose = InternalKeyPurpose.Master, | ||
publicKeyData = PublicKeyData.ECCompressedKeyData( | ||
crv = EllipticCurve.SECP256K1, | ||
data = Base64UrlString.fromByteArray(masterKeyPair.getPublicKey.getEncodedCompressed) | ||
) | ||
), | ||
PublicKey( | ||
id = "key-0", | ||
purpose = verificationRelationship, | ||
publicKeyData = PublicKeyData.ECCompressedKeyData( | ||
crv = EllipticCurve.SECP256K1, | ||
data = Base64UrlString.fromByteArray(keyPair.getPublicKey.getEncodedCompressed) | ||
) | ||
), | ||
), | ||
services = Nil, | ||
context = Nil, | ||
) | ||
val longFormDid = PrismDID.buildLongFormFromOperation(createOperation) | ||
// val canonicalDid = longFormDid.asCanonical | ||
|
||
val didMetadata = | ||
DIDMetadata( | ||
lastOperationHash = ArraySeq.from(longFormDid.stateHash.toByteArray), | ||
canonicalId = None, // unpublished DID must not contain canonicalId | ||
deactivated = false, // unpublished DID cannot be deactivated | ||
created = None, // unpublished DID cannot have timestamp | ||
updated = None // unpublished DID cannot have timestamp | ||
) | ||
val didData = DIDData( | ||
id = longFormDid.asCanonical, | ||
publicKeys = createOperation.publicKeys.collect { case pk: PublicKey => pk }, | ||
services = createOperation.services, | ||
internalKeys = createOperation.publicKeys.collect { case pk: InternalPublicKey => pk }, | ||
context = createOperation.context | ||
) | ||
(createOperation, keyPair, didMetadata, didData) | ||
} | ||
|
||
def resolveDIDExpectation(didMetadata: DIDMetadata, didData: DIDData): Expectation[DIDService] = | ||
MockDIDService.ResolveDID( | ||
assertion = Assertion.anything, | ||
result = Expectation.value(Some(didMetadata, didData)) | ||
) | ||
} |
9 changes: 4 additions & 5 deletions
9
pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/model/IssueCredentialRecord.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
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
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
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
Oops, something went wrong.