Skip to content

Commit

Permalink
pr cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Pat Losoponkul committed Mar 29, 2023
1 parent eae4a68 commit 0c69c02
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ private[castor] trait ProtoModelHelper {
serviceEndpoints = endpoints.map(_.toString)
)
)
case UpdateDIDAction.PatchContext(context) =>
node_models.UpdateDIDAction.Action.PatchContext(node_models.PatchContextAction(context))
}
node_models.UpdateDIDAction(action = a)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,6 @@ object UpdateDIDAction {
final case class RemoveService(id: String) extends UpdateDIDAction
final case class UpdateService(id: String, `type`: Option[ServiceType] = None, endpoints: Seq[Uri] = Nil)
extends UpdateDIDAction

final case class PatchContext(context: Seq[String]) extends UpdateDIDAction
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ private[castor] trait W3CModelHelper {
)
}

// Reference: https://github.com/input-output-hk/prism-did-method-spec/blob/main/w3c-spec/PRISM-method.md#constructing-a-json-ld-did-document
private def deriveContext(keys: Seq[PublicKeyRepr], services: Seq[ServiceRepr]): Seq[String] = {
val mandatoryContext = Seq("https://www.w3.org/ns/did/v1")
val additionalContext = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ private object UpdateOperationValidator extends BaseOperationValidator {
case _: UpdateDIDAction.AddService => None
case _: UpdateDIDAction.RemoveService => None
case _: UpdateDIDAction.UpdateService => None
case _: UpdateDIDAction.PatchContext => None
}

private def extractServiceIds(operation: PrismDIDOperation.Update): Seq[String] = operation.actions.flatMap {
Expand All @@ -157,6 +158,7 @@ private object UpdateOperationValidator extends BaseOperationValidator {
case UpdateDIDAction.AddService(service) => Some(service.id)
case UpdateDIDAction.RemoveService(id) => Some(id)
case UpdateDIDAction.UpdateService(id, _, _) => Some(id)
case _: UpdateDIDAction.PatchContext => None
}

private def extractServiceEndpoint(operation: PrismDIDOperation.Update): Seq[(String, Seq[Uri])] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ object ProtoModelHelperSpec extends ZIOSpecDefault {
deletedOn = deletedOn
)

override def spec = suite("ProtoModelHelper")(conversionSpec, didDataFilterSpec)

extension (i: Instant) {
def toLedgerData: node_models.LedgerData = {
val timestamp = Timestamp.of(i.getEpochSecond, i.getNano)
Expand All @@ -53,6 +51,8 @@ object ProtoModelHelperSpec extends ZIOSpecDefault {
}
}

override def spec = suite("ProtoModelHelper")(conversionSpec, didDataFilterSpec)

private val conversionSpec = suite("round trip model conversion does not change data of models")(
test("PublicKeyData") {
check(GenUtils.publicKeyData) { pkd =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ object W3CModelHelperSpec extends ZIOSpecDefault {
masterKey <- generateInternalPublicKey(masterKeyId)
keys <- ZIO.foreach(keyIds) { case (id, purpose) => generatePublicKey(id, purpose) }
services <- ZIO.foreach(serviceIds)(generateService)
} yield DIDData(id = did, publicKeys = keys, services = services, internalKeys = Seq(masterKey), context = context)
} yield DIDData(did, keys, services, Seq(masterKey), context)

override def spec = suite("W3CModelHelper")(
test("convert DIDData to w3c DID document representation") {
Expand Down Expand Up @@ -110,13 +110,12 @@ object W3CModelHelperSpec extends ZIOSpecDefault {
)
didDataNoKeys = didData.copy(publicKeys = Seq())
didDataNoService = didData.copy(services = Seq())
} yield
// TODO: add assertion on JsonWebKey2020 context when align the key type (ATL-3788)
assert(didData.toW3C(did).context)(
} yield assert(didData.toW3C(did).context)(
hasSameElements(
Seq(
"https://www.w3.org/ns/did/v1",
"https://identity.foundation/.well-known/did-configuration/v1",
// "https://w3id.org/security/suites/jws-2020/v1", // TODO: enable when align the key type (ATL-3788)
"user-defined-context"
)
)
Expand All @@ -134,6 +133,7 @@ object W3CModelHelperSpec extends ZIOSpecDefault {
hasSameElements(
Seq(
"https://www.w3.org/ns/did/v1",
// "https://w3id.org/security/suites/jws-2020/v1", // TODO: enable when align the key type (ATL-3788)
"user-defined-context"
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object GenUtils {

val uri: Gen[Any, String] =
for {
scheme <- Gen.fromIterable(Seq("http", "https", "ftp", "ws", "wss"))
scheme <- Gen.fromIterable(Seq("http", "https", "ftp", "ws", "wss", "file", "imap", "ssh"))
host <- Gen.alphaNumericStringBounded(1, 10)
path <- Gen.listOfBounded(0, 5)(Gen.alphaNumericStringBounded(1, 10)).map(_.mkString("/"))
uri <- Gen.const(s"$scheme://$host/$path").map(UriUtils.normalizeUri).collect { case Some(uri) => uri }
Expand All @@ -25,10 +25,9 @@ object GenUtils {
pk <- Gen.fromZIO(ZIO.attempt(EC.INSTANCE.generateKeyPair().getPublicKey).orDie)
x = Base64UrlString.fromByteArray(pk.getCurvePoint.getX.bytes())
y = Base64UrlString.fromByteArray(pk.getCurvePoint.getY.bytes())
compressedX = Base64UrlString.fromByteArray(pk.getEncodedCompressed)
uncompressedGen = PublicKeyData.ECKeyData(curve, x, y)
compressedGen = PublicKeyData.ECCompressedKeyData(curve, compressedX)
generated <- Gen.fromIterable(Seq(uncompressedGen, compressedGen))
uncompressedKey = PublicKeyData.ECKeyData(curve, x, y)
compressedKey = PublicKeyData.ECCompressedKeyData(curve, Base64UrlString.fromByteArray(pk.getEncodedCompressed))
generated <- Gen.fromIterable(Seq(uncompressedKey, compressedKey))
} yield generated

val publicKey: Gen[Any, PublicKey] =
Expand Down

0 comments on commit 0c69c02

Please sign in to comment.