Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Remove type DID #1327

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ trait BackgroundJobsHelper {
case Some(Secp256k1KeyPair(publicKey, privateKey)) =>
ZIO.succeed(
JwtIssuer(
org.hyperledger.identus.pollux.vc.jwt.DID(jwtIssuerDID.toString),
jwtIssuerDID.did,
ES256KSigner(privateKey.toJavaPrivateKey),
publicKey.toJavaPublicKey
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import org.hyperledger.identus.pollux.core.service.{
URIDereferencer
}
import org.hyperledger.identus.pollux.vc.jwt.{
DID as PolluxDID,
DidResolver,
Issuer,
JWT,
Expand All @@ -24,7 +23,6 @@ import org.hyperledger.identus.pollux.vc.jwt.{
W3cCredentialPayload,
*
}
import org.hyperledger.identus.pollux.vc.jwt.DID.*
import org.hyperledger.identus.shared.models.*
import zio.*

Expand Down Expand Up @@ -179,7 +177,7 @@ case class OIDCCredentialIssuerServiceImpl(
}

def buildJwtVerifiableCredential(
issuerDid: PolluxDID,
issuerDid: DID,
subjectDid: Option[DID],
credentialIdentifier: Option[String],
credentialDefinition: CredentialDefinition,
Expand All @@ -194,7 +192,7 @@ case class OIDCCredentialIssuerServiceImpl(
`type` = Set(
"VerifiableCredential"
) ++ credentialDefinition.`type`, // TODO: This information should come from Schema registry by record.schemaId
issuer = Left(issuerDid.value),
issuer = Left(issuerDid.toString),
issuanceDate = Instant.now(),
maybeExpirationDate = None, // TODO: Add expiration date
maybeCredentialSchema = None, // TODO: Add schema from schema registry
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.hyperledger.identus.castor.core.service.MockDIDService
import org.hyperledger.identus.iam.authentication.AuthenticatorWithAuthZ
import org.hyperledger.identus.pollux.vc.jwt.*
import org.hyperledger.identus.pollux.vc.jwt.CredentialPayload.Implicits.*
import org.hyperledger.identus.pollux.vc.jwt.DID.*
import org.hyperledger.identus.verification.controller.http.*
import sttp.client3.{basicRequest, DeserializationException, Response, UriContext}
import sttp.client3.ziojson.*
Expand All @@ -31,13 +30,13 @@ object VcVerificationControllerImplSpec extends ZIOSpecDefault with VcVerificati
test("provide incorrect recordId to endpoint") {
for {
vcVerificationController <- ZIO.service[VcVerificationController]
verifier = DID("did:prism:verifier")
verifier = "did:prism:verifier"
currentTime = OffsetDateTime.parse("2010-01-01T00:00:00Z").toOption.get
jwtCredentialPayload = W3cCredentialPayload(
`@context` = Set("https://www.w3.org/2018/credentials/v1", "https://www.w3.org/2018/credentials/examples/v1"),
maybeId = Some("http://example.edu/credentials/3732"),
`type` = Set("VerifiableCredential", "UniversityDegreeCredential"),
issuer = Left(issuer.did.value),
issuer = Left(issuer.did.toString),
issuanceDate = Instant.parse("2010-01-01T00:00:00Z"),
maybeExpirationDate = Some(Instant.parse("2010-01-12T00:00:00Z")),
maybeValidFrom = Some(Instant.parse("2010-01-12T00:00:00Z")),
Expand Down Expand Up @@ -70,7 +69,7 @@ object VcVerificationControllerImplSpec extends ZIOSpecDefault with VcVerificati
),
maybeEvidence = Option.empty,
maybeTermsOfUse = Option.empty,
aud = Set(verifier.value)
aud = Set(verifier)
).toJwtCredentialPayload
signedJwtCredential = issuer.signer.encode(jwtCredentialPayload.asJson)
authenticator <- ZIO.service[AuthenticatorWithAuthZ[BaseEntity]]
Expand All @@ -88,10 +87,10 @@ object VcVerificationControllerImplSpec extends ZIOSpecDefault with VcVerificati
VcVerificationRequest(
signedJwtCredential.value,
List(
ParameterizableVcVerification(VcVerification.AudienceCheck, Some(DidParameter(verifier.value))),
ParameterizableVcVerification(VcVerification.AudienceCheck, Some(DidParameter(verifier))),
ParameterizableVcVerification(
VcVerification.IssuerIdentification,
Some(DidParameter(issuer.did.value))
Some(DidParameter(issuer.did.toString))
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ trait VcVerificationControllerTestTools extends PostgresTestContainerSupport {

protected val issuer =
Issuer(
did = org.hyperledger.identus.pollux.vc.jwt.DID(issuerDidData.id.did.toString),
did = issuerDidData.id.did,
signer = ES256KSigner(issuerKp.privateKey.toJavaPrivateKey),
publicKey = issuerKp.publicKey.toJavaPublicKey
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import org.hyperledger.identus.pollux.core.repository.{CredentialRepository, Cre
import org.hyperledger.identus.pollux.prex.{ClaimFormat, Jwt, PresentationDefinition}
import org.hyperledger.identus.pollux.sdjwt.*
import org.hyperledger.identus.pollux.vc.jwt.{Issuer as JwtIssuer, *}
import org.hyperledger.identus.pollux.vc.jwt.DID.*
import org.hyperledger.identus.shared.crypto.{Ed25519KeyPair, Ed25519PublicKey, Secp256k1KeyPair}
import org.hyperledger.identus.shared.http.{DataUrlResolver, GenericUriResolver}
import org.hyperledger.identus.shared.models.*
Expand Down Expand Up @@ -501,7 +500,7 @@ class CredentialServiceImpl(
maybeId = None,
`type` = Vector("VerifiablePresentation"),
verifiableCredential = IndexedSeq.empty,
holder = subject.did.value,
holder = subject.did.toString,
verifier = IndexedSeq.empty ++ maybeOptions.map(_.domain),
maybeIssuanceDate = None,
maybeExpirationDate = None
Expand Down Expand Up @@ -570,7 +569,7 @@ class CredentialServiceImpl(
.orDieAsUnmanagedFailure
Secp256k1KeyPair(publicKey, privateKey) = ecKeyPair
jwtIssuer = JwtIssuer(
org.hyperledger.identus.pollux.vc.jwt.DID(jwtIssuerDID.toString),
jwtIssuerDID.did,
ES256KSigner(privateKey.toJavaPrivateKey, keyId),
publicKey.toJavaPublicKey
)
Expand Down Expand Up @@ -611,7 +610,7 @@ class CredentialServiceImpl(
ed25519keyPair <- getEd25519SigningKeyPair(jwtIssuerDID, verificationRelationship)
} yield {
JwtIssuer(
org.hyperledger.identus.pollux.vc.jwt.DID(jwtIssuerDID.toString),
jwtIssuerDID.did,
EdSigner(ed25519keyPair, keyId),
Ed25519PublicKey.toJavaEd25519PublicKey(ed25519keyPair.publicKey.getEncoded)
)
Expand Down Expand Up @@ -1135,7 +1134,7 @@ class CredentialServiceImpl(
maybeId = None,
`type` =
Set("VerifiableCredential"), // TODO: This information should come from Schema registry by record.schemaId
issuer = Left(jwtIssuer.did.value),
issuer = Left(jwtIssuer.did.toString),
issuanceDate = issuanceDate,
maybeExpirationDate = record.validityPeriod.map(sec => issuanceDate.plusSeconds(sec.toLong)),
maybeCredentialSchema =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ private class PresentationServiceImpl(
maybeId = None,
`type` = Vector("VerifiablePresentation"),
verifiableCredential = vcs.toVector,
holder = prover.did.value,
holder = prover.did.toString,
verifier = Vector(options.domain),
maybeIssuanceDate = None,
maybeExpirationDate = None
Expand All @@ -645,7 +645,7 @@ private class PresentationServiceImpl(
maybeId = None,
`type` = Vector("VerifiablePresentation"),
verifiableCredential = vcs.toVector,
holder = prover.did.value,
holder = prover.did.toString,
verifier = Vector("https://example.verifier"), // TODO Fix this
maybeIssuanceDate = None,
maybeExpirationDate = None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ class CredentialStatusListRepositoryInMemory(

val id = UUID.randomUUID()
val issued = Instant.now()
val issuerDid = jwtIssuer.did.value
val canonical = PrismDID.fromString(issuerDid).fold(e => throw RuntimeException(e), _.asCanonical)
val issuerDid = jwtIssuer.did
val canonical = PrismDID.fromString(issuerDid.toString).fold(e => throw RuntimeException(e), _.asCanonical)

val embeddedProofCredential = for {
bitString <- BitString.getInstance().mapError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ object PresentationServiceSpec extends ZIOSpecDefault with PresentationServiceSp
Some(Seq(aIssueCredentialRecord.id.value)),
PresentationRecord.ProtocolState.RequestPending
)
issuer = createIssuer(DID("did:prism:issuer"))
issuer = createIssuer("did:prism:issuer")
aPresentationPayload <- svc.createJwtPresentationPayloadFromRecord(aRecord.id, issuer, Instant.now())
} yield {
assertTrue(aPresentationPayload.toJwtPresentationPayload.iss == "did:prism:issuer")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.hyperledger.identus.pollux.core.service

import com.nimbusds.jose.jwk.*
import org.hyperledger.identus.agent.walletapi.memory.GenericSecretStorageInMemory
import org.hyperledger.identus.castor.core.model.did.DID
import org.hyperledger.identus.mercury.{AgentPeerService, PeerDID}
import org.hyperledger.identus.mercury.model.{AttachmentDescriptor, DidId}
import org.hyperledger.identus.mercury.protocol.presentproof.*
Expand Down Expand Up @@ -42,14 +43,14 @@ trait PresentationServiceSpecHelper {
CredentialRepositoryInMemory.layer
) ++ defaultWalletLayer

def createIssuer(did: DID): Issuer = {
def createIssuer(did: String): Issuer = {

val keyPair = KmpSecp256k1KeyOps.generateKeyPair
val javaSKey = keyPair.privateKey.toJavaPrivateKey
val javaPKey = keyPair.publicKey.toJavaPublicKey

Issuer(
did = did,
did = DID.fromString(did).toOption.get,
signer = ES256KSigner(javaSKey),
publicKey = javaPKey
)
Expand Down
Loading
Loading