Skip to content

Commit

Permalink
feat(prism-agent): upgrade castor and pollux and align OAS to the DID…
Browse files Browse the repository at this point in the history
… spec (#342)

* fix(prism-agent): upgrade castor

* feat(prism-agent): update OAS to be compliant with DID spec

* fix(prism-agent): make OAS update compile

* fix(prism-agent): remove versionId from did metadata

* fix(prism-agent): only use serviceType defined in DID core spec

* doc(prism-agent): minor adjustment to OAS documentation

* feat(prism-agent): bump dependency versions
  • Loading branch information
patlo-iog authored Feb 6, 2023
1 parent a53ac6f commit b8643a8
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 30 deletions.
51 changes: 38 additions & 13 deletions prism-agent/service/api/http/castor/schemas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ components:

DID:
type: object
description: |
A core DID data model capable of being transformed into W3C compliant representation.
required:
- id
properties:
Expand All @@ -37,19 +39,23 @@ components:
authentication:
type: array
items:
$ref: "#/components/schemas/VerificationMethod"
$ref: "#/components/schemas/VerificationMethodOrRef"
assertionMethod:
type: array
items:
$ref: "#/components/schemas/VerificationMethod"
$ref: "#/components/schemas/VerificationMethodOrRef"
keyAgreement:
type: array
items:
$ref: "#/components/schemas/VerificationMethod"
$ref: "#/components/schemas/VerificationMethodOrRef"
capabilityInvocation:
type: array
items:
$ref: "#/components/schemas/VerificationMethod"
$ref: "#/components/schemas/VerificationMethodOrRef"
capabilityDelegation:
type: array
items:
$ref: "#/components/schemas/VerificationMethodOrRef"
service:
type: array
items:
Expand All @@ -63,9 +69,6 @@ components:
deactivated:
type: boolean
description: If a DID has been deactivated, DID document metadata MUST include this property with the boolean value true. If a DID has not been deactivated, this property is OPTIONAL, but if included, MUST have the boolean value false.
versionId:
type: string
description: A hexstring representing the last operation applied to the DID Document
canonicalId:
type: string
description: A DID in canonical form
Expand All @@ -90,6 +93,28 @@ components:
publicKeyJwk:
$ref: "#/components/schemas/PublicKeyJwk"

VerificationMethodOrRef:
type: object
description: |
An embedded verificationMethod as JSON or a referenced key as a URI.
Referenced key and embedded key are mutually exclusive.
If the type is EMBEDDED, `uri` field must be present.
Otherwise `verificationMethod` field must be present.
required:
- type
properties:
type:
type: string
example: EMBEDDED
enum:
- EMBEDDED
- REFERENCED
uri:
type: string
example: did:example:123#key-1
verificationMethod:
$ref: "#/components/schemas/VerificationMethod"

CreateManagedDidRequest:
type: object
required:
Expand Down Expand Up @@ -174,13 +199,13 @@ components:
properties:
id:
type: string
description: ID of service to remove from DID document
description: ID of existing service to update in the DID document
example: service1
type:
type: string
enum:
- MediatorService
example: MediatorService
- LinkedDomains
example: LinkedDomains
serviceEndpoint:
type: array
items:
Expand All @@ -204,7 +229,7 @@ components:
example: did:prism:abc:123
status:
type: string
description: A status indicating whether this is published DID or not. Does not represent DID full lifecyle (e.g. deactivated, recovered, updated).
description: A status indicating whether this is already published from the wallet or not. Does not represent DID full lifecyle (e.g. deactivated, recovered, updated).
enum:
- CREATED
- PUBLICATION_PENDING
Expand Down Expand Up @@ -244,8 +269,8 @@ components:
type:
type: string
enum:
- MediatorService
example: MediatorService
- LinkedDomains
example: LinkedDomains
serviceEndpoint:
type: array
items:
Expand Down
5 changes: 4 additions & 1 deletion prism-agent/service/api/http/prism-agent-openapi-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ paths:
description: List all DIDs stored in PrismAgent's wallet
responses:
"200":
description: List managed DIDs
description: List PrismAgent managed DIDs
content:
application/json:
schema:
Expand Down Expand Up @@ -138,6 +138,9 @@ paths:
summary: Update DID in PrismAgent's wallet and post update operation to blockchain
description: |
Update DID in PrismAgent's wallet and post update operation to blockchain.
This endpoint updates the DID document from last confirmed operation.
Submitting multiple update operations without waiting for confirmation will result in
some operation being rejected as only one operation can be appended from last confirmed operation.
requestBody:
required: true
content:
Expand Down
4 changes: 2 additions & 2 deletions prism-agent/service/project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ object Dependencies {
val zioInteropCats = "3.3.0" // scala-steward:off
val akka = "2.6.20"
val akkaHttp = "10.2.9"
val castor = "0.7.0"
val pollux = "0.21.0"
val castor = "0.8.0"
val pollux = "0.22.0"
val connect = "0.7.0"
val bouncyCastle = "1.70"
val logback = "1.4.5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ import io.iohk.atala.agent.walletapi.sql.{JdbcDIDNonSecretStorage, JdbcDIDSecret
import io.iohk.atala.resolvers.DIDResolver
import io.iohk.atala.agent.walletapi.storage.DIDSecretStorage
import io.iohk.atala.pollux.vc.jwt.DidResolver as JwtDidResolver
import io.iohk.atala.castor.core.model.error.DIDOperationError.TooManyDidServiceAccess
import io.iohk.atala.pollux.vc.jwt.PrismDidResolver
import io.iohk.atala.mercury.DidAgent

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ trait JsonSupport extends SprayJsonSupport with DefaultJsonProtocol {
CreateManagedDidRequestDocumentTemplate.apply
)
given RootJsonFormat[CreateManagedDIDResponse] = jsonFormat1(CreateManagedDIDResponse.apply)
given RootJsonFormat[DID] = jsonFormat8(DID.apply)
given RootJsonFormat[DIDDocumentMetadata] = jsonFormat3(DIDDocumentMetadata.apply)
given RootJsonFormat[DID] = jsonFormat9(DID.apply)
given RootJsonFormat[DIDDocumentMetadata] = jsonFormat2(DIDDocumentMetadata.apply)
given RootJsonFormat[DIDOperationResponse] = jsonFormat1(DIDOperationResponse.apply)
given RootJsonFormat[DidOperationSubmission] = jsonFormat2(DidOperationSubmission.apply)
given RootJsonFormat[DIDResponse] = jsonFormat2(DIDResponse.apply)
Expand All @@ -46,6 +46,7 @@ trait JsonSupport extends SprayJsonSupport with DefaultJsonProtocol {
UpdateManagedDIDRequestActionsInnerUpdateService.apply
)
given RootJsonFormat[VerificationMethod] = jsonFormat4(VerificationMethod.apply)
given RootJsonFormat[VerificationMethodOrRef] = jsonFormat3(VerificationMethodOrRef.apply)

// Issue Credential Protocol
implicit object UUIDFormat extends JsonFormat[UUID] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import io.iohk.atala.agent.openapi.model.{
Service,
UpdateManagedDIDRequestActionsInner,
UpdateManagedDIDRequestActionsInnerUpdateService,
VerificationMethod
VerificationMethod,
VerificationMethodOrRef
}
import io.iohk.atala.castor.core.model.did as castorDomain
import io.iohk.atala.agent.walletapi.model as walletDomain
Expand All @@ -37,6 +38,7 @@ import io.iohk.atala.mercury.model.Base64
import zio.ZIO
import io.iohk.atala.agent.server.http.model.HttpServiceError.InvalidPayload
import io.iohk.atala.agent.walletapi.model.ManagedDIDState
import io.iohk.atala.castor.core.model.did.w3c.PublicKeyRepr
import io.iohk.atala.castor.core.model.did.{LongFormPrismDID, PrismDID, ServiceType}

import java.util.UUID
Expand Down Expand Up @@ -242,7 +244,6 @@ trait OASDomainModelHelper {
),
metadata = DIDDocumentMetadata(
deactivated = metadata.deactivated,
versionId = Some(metadata.versionId),
canonicalId = Some(metadata.canonicalId)
)
)
Expand All @@ -260,6 +261,15 @@ trait OASDomainModelHelper {
}
}

extension (publicKeyReprOrRef: castorDomain.w3c.PublicKeyReprOrRef) {
def toOAS: VerificationMethodOrRef = {
publicKeyReprOrRef match {
case s: String => VerificationMethodOrRef(`type` = "REFERENCED", uri = Some(s))
case pk: PublicKeyRepr => VerificationMethodOrRef(`type` = "EMBEDDED", verificationMethod = Some(pk.toOAS))
}
}
}

extension (publicKeyJwk: castorDomain.w3c.PublicKeyJwk) {
def toOAS: PublicKeyJwk = {
PublicKeyJwk(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.iohk.atala.agent.walletapi.model.error

import io.iohk.atala.castor.core.model.did.PrismDID
import io.iohk.atala.castor.core.model.error.DIDOperationError
import io.iohk.atala.castor.core.model.error as castor

sealed trait CreateManagedDIDError extends Throwable

Expand All @@ -10,5 +10,5 @@ object CreateManagedDIDError {
final case class DIDAlreadyExists(did: PrismDID) extends CreateManagedDIDError
final case class KeyGenerationError(cause: Throwable) extends CreateManagedDIDError
final case class WalletStorageError(cause: Throwable) extends CreateManagedDIDError
final case class OperationError(cause: DIDOperationError) extends CreateManagedDIDError
final case class InvalidOperation(cause: castor.OperationValidationError) extends CreateManagedDIDError
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.iohk.atala.agent.walletapi.model.error

import io.iohk.atala.castor.core.model.did.CanonicalPrismDID
import io.iohk.atala.castor.core.model.error.{DIDOperationError, DIDResolutionError}
import io.iohk.atala.castor.core.model.error as castor

sealed trait UpdateManagedDIDError

Expand All @@ -12,7 +12,8 @@ object UpdateManagedDIDError {
final case class InvalidArgument(msg: String) extends UpdateManagedDIDError
final case class KeyGenerationError(cause: Throwable) extends UpdateManagedDIDError
final case class WalletStorageError(cause: Throwable) extends UpdateManagedDIDError
final case class OperationError(cause: DIDOperationError) extends UpdateManagedDIDError
final case class ResolutionError(cause: DIDResolutionError) extends UpdateManagedDIDError
final case class OperationError(cause: castor.DIDOperationError) extends UpdateManagedDIDError
final case class InvalidOperation(cause: castor.OperationValidationError) extends UpdateManagedDIDError
final case class ResolutionError(cause: castor.DIDResolutionError) extends UpdateManagedDIDError
final case class CryptographyError(cause: Throwable) extends UpdateManagedDIDError
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ final class ManagedDIDService private[walletapi] (
(createOperation, secret) = generated
longFormDID = PrismDID.buildLongFormFromOperation(createOperation)
did = longFormDID.asCanonical
_ <- ZIO.fromEither(didOpValidator.validate(createOperation)).mapError(CreateManagedDIDError.OperationError.apply)
_ <- ZIO
.fromEither(didOpValidator.validate(createOperation))
.mapError(CreateManagedDIDError.InvalidOperation.apply)
_ <- nonSecretStorage
.getManagedDIDState(did)
.mapError(CreateManagedDIDError.WalletStorageError.apply)
Expand Down Expand Up @@ -208,7 +210,9 @@ final class ManagedDIDService private[walletapi] (
previousOperationHash <- getPreviousOperationHash[UpdateManagedDIDError](did, didState.createOperation)
generated <- generateUpdateOperation(did, previousOperationHash, actions)
(updateOperation, secret) = generated
_ <- ZIO.fromEither(didOpValidator.validate(updateOperation)).mapError(UpdateManagedDIDError.OperationError.apply)
_ <- ZIO
.fromEither(didOpValidator.validate(updateOperation))
.mapError(UpdateManagedDIDError.InvalidOperation.apply)
outcome <- doUpdate(updateOperation, secret)
} yield outcome
}
Expand Down Expand Up @@ -237,7 +241,7 @@ final class ManagedDIDService private[walletapi] (
deactivateOperation = PrismDIDOperation.Deactivate(did, ArraySeq.from(previousOperationHash))
_ <- ZIO
.fromEither(didOpValidator.validate(deactivateOperation))
.mapError(UpdateManagedDIDError.OperationError.apply)
.mapError(UpdateManagedDIDError.InvalidOperation.apply)
outcome <- doDeactivate(deactivateOperation)
} yield outcome
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object ManagedDIDTemplateValidatorSpec extends ZIOSpecDefault {
services = Seq(
Service(
id = "service0",
`type` = ServiceType.MediatorService,
`type` = ServiceType.LinkedDomains,
serviceEndpoint = Seq(URI.create("http://example.com"))
)
)
Expand Down

0 comments on commit b8643a8

Please sign in to comment.