-
Notifications
You must be signed in to change notification settings - Fork 15
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): align DID document service handling with the spec (#…
…582) * Rebase only castor * make prismNodeClient compile [skip ci] * make castor compile [skip ci] * resolve conflict [skip ci] * fix serviceEndpoint model and make validator compiled * make tests compile [skip ci] * feat(castor): validate max id size * test(castor): max id validation tests [skip ci] * context validation and tests [skip ci] * serviceType and serviceEndpoint length validation * Fix compile issue * it works! * implement encoder / decoder / schema for service type * Fix incorrect swagger doc * update service type parsing logic * update tests for new logic * serviceType serviceEndpoitn encode tests * tests: update e2e scenario for service type ABNF * chore: pr cleanup * ci: disable coverage for generated code * chore: pr cleanup * fix: remove URI normalization check * chore: resolve merge conflict * chore: fix warnings * ci: update node version in docker-compose * chore: address pr review * chore: update node version
- Loading branch information
Showing
28 changed files
with
1,124 additions
and
463 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
16 changes: 4 additions & 12 deletions
16
castor/lib/core/src/main/scala/io/iohk/atala/castor/core/model/did/Service.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 |
---|---|---|
@@ -1,19 +1,11 @@ | ||
package io.iohk.atala.castor.core.model.did | ||
|
||
import io.iohk.atala.castor.core.util.UriUtils | ||
import io.lemonlabs.uri.Uri | ||
|
||
final case class Service( | ||
id: String, | ||
`type`: ServiceType, | ||
serviceEndpoint: Seq[Uri] | ||
serviceEndpoint: ServiceEndpoint | ||
) { | ||
def normalizeServiceEndpoint(): Service = { | ||
val normalizedUris = serviceEndpoint.flatMap { uri => | ||
UriUtils.normalizeUri(uri.toString).map { normalizedUri => | ||
Uri.parse(normalizedUri) | ||
} | ||
} | ||
this.copy(serviceEndpoint = normalizedUris) | ||
} | ||
|
||
def normalizeServiceEndpoint(): Service = copy(serviceEndpoint = serviceEndpoint.normalize()) | ||
|
||
} |
61 changes: 61 additions & 0 deletions
61
castor/lib/core/src/main/scala/io/iohk/atala/castor/core/model/did/ServiceEndpoint.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,61 @@ | ||
package io.iohk.atala.castor.core.model.did | ||
|
||
import io.circe.JsonObject | ||
import io.iohk.atala.castor.core.util.UriUtils | ||
|
||
sealed trait ServiceEndpoint { | ||
def normalize(): ServiceEndpoint | ||
} | ||
|
||
object ServiceEndpoint { | ||
|
||
opaque type UriValue = String | ||
|
||
object UriValue { | ||
def fromString(uri: String): Either[String, UriValue] = { | ||
val isUri = UriUtils.isValidUriString(uri) | ||
if (isUri) Right(uri) else Left(s"unable to parse service endpoint URI: \"$uri\"") | ||
} | ||
} | ||
|
||
extension (uri: UriValue) { | ||
def value: String = uri | ||
|
||
def normalize(): UriValue = { | ||
UriUtils.normalizeUri(uri).get // uri is already validated | ||
} | ||
} | ||
|
||
sealed trait UriOrJsonEndpoint { | ||
def normalize(): UriOrJsonEndpoint | ||
} | ||
|
||
object UriOrJsonEndpoint { | ||
final case class Uri(uri: UriValue) extends UriOrJsonEndpoint { | ||
override def normalize(): UriOrJsonEndpoint = copy(uri = uri.normalize()) | ||
} | ||
|
||
final case class Json(json: JsonObject) extends UriOrJsonEndpoint { | ||
override def normalize(): UriOrJsonEndpoint = this | ||
} | ||
|
||
given Conversion[UriValue, UriOrJsonEndpoint] = Uri(_) | ||
given Conversion[JsonObject, UriOrJsonEndpoint] = Json(_) | ||
} | ||
|
||
final case class Single(value: UriOrJsonEndpoint) extends ServiceEndpoint { | ||
override def normalize(): Single = copy(value = value.normalize()) | ||
} | ||
|
||
final case class Multiple(head: UriOrJsonEndpoint, tail: Seq[UriOrJsonEndpoint]) extends ServiceEndpoint { | ||
def values: Seq[UriOrJsonEndpoint] = head +: tail | ||
|
||
override def normalize(): Multiple = { | ||
Multiple( | ||
head = head.normalize(), | ||
tail = tail.map(_.normalize()) | ||
) | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.