-
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.
- Loading branch information
Pat Losoponkul
committed
Apr 17, 2023
1 parent
2764198
commit c6da28b
Showing
9 changed files
with
330 additions
and
108 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
51 changes: 51 additions & 0 deletions
51
...vice/server/src/main/scala/io/iohk/atala/castor/controller/http/DIDDocumentMetadata.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,51 @@ | ||
package io.iohk.atala.castor.controller.http | ||
|
||
import io.iohk.atala.api.http.Annotation | ||
import io.iohk.atala.castor.core.model.did.w3c | ||
import sttp.tapir.Schema | ||
import zio.json.{DeriveJsonDecoder, DeriveJsonEncoder, JsonEncoder, JsonDecoder} | ||
import sttp.tapir.Schema.annotations.{description, encodedExample} | ||
import io.iohk.atala.castor.controller.http.DIDDocumentMetadata.annotations | ||
|
||
@description("[DID document metadata](https://www.w3.org/TR/did-core/#did-document-metadata)") | ||
final case class DIDDocumentMetadata( | ||
@description(annotations.deactivated.description) | ||
@encodedExample(annotations.deactivated.example) | ||
deactivated: Option[Boolean] = None, | ||
@description(annotations.canonicalId.description) | ||
@encodedExample(annotations.canonicalId.example) | ||
canonicalId: Option[String] = None | ||
) | ||
|
||
object DIDDocumentMetadata { | ||
|
||
object annotations { | ||
object deactivated | ||
extends Annotation[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.", | ||
example = false | ||
) | ||
|
||
object canonicalId | ||
extends Annotation[String]( | ||
description = """ | ||
|A DID in canonical form. | ||
|If a DID is in long form and has been published, DID document metadata MUST contain a `canonicalId`` property with the short form DID as its value. | ||
|If a DID in short form or has not been published, DID document metadata MUST NOT contain a `canonicalId` property. | ||
|""".stripMargin, | ||
example = "did:prism:4a5b5cf0a513e83b598bbea25cd6196746747f361a73ef77068268bc9bd732ff" | ||
) | ||
} | ||
|
||
given encoder: JsonEncoder[DIDDocumentMetadata] = DeriveJsonEncoder.gen[DIDDocumentMetadata] | ||
given decoder: JsonDecoder[DIDDocumentMetadata] = DeriveJsonDecoder.gen[DIDDocumentMetadata] | ||
given schema: Schema[DIDDocumentMetadata] = Schema.derived | ||
|
||
given Conversion[w3c.DIDDocumentMetadataRepr, DIDDocumentMetadata] = | ||
(didDocumentMetadata: w3c.DIDDocumentMetadataRepr) => | ||
DIDDocumentMetadata( | ||
deactivated = Some(didDocumentMetadata.deactivated), | ||
canonicalId = Some(didDocumentMetadata.canonicalId) | ||
) | ||
} |
13 changes: 13 additions & 0 deletions
13
...m-agent/service/server/src/main/scala/io/iohk/atala/castor/controller/http/DIDInput.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,13 @@ | ||
package io.iohk.atala.castor.controller.http | ||
|
||
import sttp.tapir.* | ||
|
||
object DIDInput { | ||
|
||
val didRefPathSegment = path[String]("didRef") | ||
.description( | ||
"Prism DID according to [the Prism DID method syntax](https://github.com/input-output-hk/prism-did-method-spec/blob/main/w3c-spec/PRISM-method.md#prism-did-method-syntax)" | ||
) | ||
.example("did:prism:4a5b5cf0a513e83b598bbea25cd6196746747f361a73ef77068268bc9bd732ff") | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...ce/server/src/main/scala/io/iohk/atala/castor/controller/http/DIDResolutionMetadata.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,48 @@ | ||
package io.iohk.atala.castor.controller.http | ||
|
||
import io.iohk.atala.api.http.Annotation | ||
import io.iohk.atala.castor.controller.http.DIDResolutionMetadata.annotations | ||
import sttp.tapir.Schema | ||
import sttp.tapir.Schema.annotations.{description, encodedExample} | ||
import zio.json.{DeriveJsonDecoder, DeriveJsonEncoder, JsonEncoder, JsonDecoder} | ||
|
||
@description("[DID resolution metadata](https://www.w3.org/TR/did-core/#did-resolution-metadata)") | ||
final case class DIDResolutionMetadata( | ||
@description(annotations.error.description) | ||
@encodedExample(annotations.error.example) | ||
error: Option[String] = None, | ||
@description(annotations.errorMessage.description) | ||
@encodedExample(annotations.errorMessage.example) | ||
errorMessage: Option[String] = None, | ||
@description(annotations.contentType.description) | ||
@encodedExample(annotations.contentType.example) | ||
contentType: Option[String] = None | ||
) | ||
|
||
object DIDResolutionMetadata { | ||
|
||
object annotations { | ||
object error | ||
extends Annotation[String]( | ||
description = | ||
"Resolution error constant according to [DID spec registries](https://www.w3.org/TR/did-spec-registries/#error)", | ||
example = "invalidDid" | ||
) | ||
|
||
object errorMessage | ||
extends Annotation[String]( | ||
description = "Resolution error message", | ||
example = "The initialState does not match the suffix" | ||
) | ||
|
||
object contentType | ||
extends Annotation[String]( | ||
description = "The media type of the returned DID document", | ||
example = "application/did+ld+json" | ||
) | ||
} | ||
|
||
given encoder: JsonEncoder[DIDResolutionMetadata] = DeriveJsonEncoder.gen[DIDResolutionMetadata] | ||
given decoder: JsonDecoder[DIDResolutionMetadata] = DeriveJsonDecoder.gen[DIDResolutionMetadata] | ||
given schema: Schema[DIDResolutionMetadata] = Schema.derived | ||
} |
30 changes: 30 additions & 0 deletions
30
...vice/server/src/main/scala/io/iohk/atala/castor/controller/http/DIDResolutionResult.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,30 @@ | ||
package io.iohk.atala.castor.controller.http | ||
|
||
import io.iohk.atala.api.http.Annotation | ||
import sttp.tapir.Schema | ||
import sttp.tapir.Schema.annotations.{description, encodedExample} | ||
import zio.json.{DeriveJsonDecoder, DeriveJsonEncoder, JsonEncoder, JsonDecoder} | ||
import io.iohk.atala.castor.controller.http.DIDResolutionResult.annotations | ||
|
||
final case class DIDResolutionResult( | ||
@description(annotations.`@context`.description) | ||
@encodedExample(annotations.`@context`.example) | ||
`@context`: String, | ||
didDocument: Option[DIDDocument] = None, | ||
didDocumentMetadata: DIDDocumentMetadata, | ||
didResolutionMetadata: DIDResolutionMetadata | ||
) | ||
|
||
object DIDResolutionResult { | ||
object annotations { | ||
object `@context` | ||
extends Annotation[String]( | ||
description = "The JSON-LD context for the DID resolution result.", | ||
example = "https://w3id.org/did-resolution/v1" | ||
) | ||
} | ||
|
||
given encoder: JsonEncoder[DIDResolutionResult] = DeriveJsonEncoder.gen[DIDResolutionResult] | ||
given decoder: JsonDecoder[DIDResolutionResult] = DeriveJsonDecoder.gen[DIDResolutionResult] | ||
given schema: Schema[DIDResolutionResult] = Schema.derived | ||
} |
26 changes: 26 additions & 0 deletions
26
...ent/service/server/src/main/scala/io/iohk/atala/castor/controller/http/PublicKeyJwk.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,26 @@ | ||
package io.iohk.atala.castor.controller.http | ||
|
||
import io.iohk.atala.castor.core.model.did.w3c | ||
import sttp.tapir.Schema | ||
import zio.json.{DeriveJsonDecoder, DeriveJsonEncoder, JsonEncoder, JsonDecoder} | ||
|
||
final case class PublicKeyJwk( | ||
crv: Option[String] = None, | ||
x: Option[String] = None, | ||
y: Option[String] = None, | ||
kty: String | ||
) | ||
|
||
object PublicKeyJwk { | ||
given encoder: JsonEncoder[PublicKeyJwk] = DeriveJsonEncoder.gen[PublicKeyJwk] | ||
given decoder: JsonDecoder[PublicKeyJwk] = DeriveJsonDecoder.gen[PublicKeyJwk] | ||
given schema: Schema[PublicKeyJwk] = Schema.derived | ||
|
||
given Conversion[w3c.PublicKeyJwk, PublicKeyJwk] = (publicKeyJwk: w3c.PublicKeyJwk) => | ||
PublicKeyJwk( | ||
crv = Some(publicKeyJwk.crv), | ||
x = Some(publicKeyJwk.x), | ||
y = Some(publicKeyJwk.y), | ||
kty = publicKeyJwk.kty | ||
) | ||
} |
Oops, something went wrong.