Skip to content

Commit

Permalink
feat: support 'pollux.domain' config param (#1483)
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Voiturier <benjamin.voiturier@iohk.io>
  • Loading branch information
bvoiturier authored Dec 18, 2024
1 parent 7524ec7 commit 81350ea
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ pollux {
presentationInvitationExpiry = ${?PRESENTATION_INVITATION_EXPIRY}
issuanceInvitationExpiry = 300 seconds
issuanceInvitationExpiry = ${?ISSUANCE_INVITATION_EXPIRY}
defaultJwtVCOfferDomain = "default-domain"
defaultJwtVCOfferDomain = ${?DEFAULT_JWT_VC_OFFER_DOMAIN}
}

connect {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ final case class PolluxConfig(
didStateSyncTriggerRecurrenceDelay: Duration,
presentationInvitationExpiry: Duration,
issuanceInvitationExpiry: Duration,
defaultJwtVCOfferDomain: String
)
final case class ConnectConfig(
database: DatabaseConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ class IssueControllerImpl(
goalCode = offerContext.goalCode,
goal = offerContext.goal,
expirationDuration = offerContext.expirationDuration,
connectionId = request.connectionId
connectionId = request.connectionId,
domain = request.domain.getOrElse(appConfig.pollux.defaultJwtVCOfferDomain)
)
} yield record
case SDJWT =>
Expand All @@ -108,7 +109,8 @@ class IssueControllerImpl(
goalCode = offerContext.goalCode,
goal = offerContext.goal,
expirationDuration = offerContext.expirationDuration,
connectionId = request.connectionId
connectionId = request.connectionId,
domain = request.domain.getOrElse(appConfig.pollux.defaultJwtVCOfferDomain)
)
} yield record
case AnonCreds =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ final case class CreateIssueCredentialRecordRequest(
@description(annotations.goal.description)
@encodedExample(annotations.goal.example)
goal: Option[String] = None,
@description(annotations.domain.description)
@encodedExample(annotations.domain.example)
domain: Option[String] = None,
@description(annotations.jwtVcPropertiesV1.description)
jwtVcPropertiesV1: Option[JwtVCPropertiesV1] = None,
@description(annotations.anoncredsVcPropertiesV1.description)
Expand Down Expand Up @@ -372,6 +375,15 @@ object CreateIssueCredentialRecordRequest {
example = Some("To issue a Faber College Graduate credential")
)

object domain
extends Annotation[Option[String]](
description = """
| A string that specifies the intended scope or audience for the offer request. The 'domain' field binds the proof or presentation to a particular context (e.g., application, service, or verifier) to prevent misuse.
| It is often used alongside a 'challenge' field to ensure the freshness and uniqueness of the proof. The 'domain' field adds context to validate the origin or purpose of the proof.
|""".stripMargin,
example = Some("faber-college-jwt-vc")
)

object jwtVcPropertiesV1
extends Annotation[Option[JwtVCPropertiesV1]](
description = """
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ trait CredentialService {
goal: Option[String],
expirationDuration: Option[Duration],
connectionId: Option[UUID],
domain: String
): URIO[WalletAccessContext, IssueCredentialRecord]

def createSDJWTIssueCredentialRecord(
Expand All @@ -53,6 +54,7 @@ trait CredentialService {
goal: Option[String],
expirationDuration: Option[Duration],
connectionId: Option[UUID],
domain: String
): URIO[WalletAccessContext, IssueCredentialRecord]

def createAnonCredsIssueCredentialRecord(
Expand All @@ -67,7 +69,7 @@ trait CredentialService {
goalCode: Option[String],
goal: Option[String],
expirationDuration: Option[Duration],
connectionId: Option[UUID],
connectionId: Option[UUID]
): URIO[WalletAccessContext, IssueCredentialRecord]

/** Return a list of records as well as a count of all filtered items */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class CredentialServiceImpl(
goal: Option[String],
expirationDuration: Option[Duration],
connectionId: Option[UUID],
domain: String
): URIO[WalletAccessContext, IssueCredentialRecord] = {
for {
_ <- validateClaimsAgainstSchemaIfAny(claims, credentialSchemaRef.map(List(_)))
Expand All @@ -221,7 +222,7 @@ class CredentialServiceImpl(
claims = attributes,
thid = thid,
UUID.randomUUID().toString,
"domain", // TODO remove the hardcoded domain
domain,
IssueCredentialOfferFormat.JWT
)
record <- createIssueCredentialRecord(
Expand Down Expand Up @@ -258,6 +259,7 @@ class CredentialServiceImpl(
goal: Option[String],
expirationDuration: Option[Duration],
connectionId: Option[UUID],
domain: String
): URIO[WalletAccessContext, IssueCredentialRecord] = {
val maybeSchemaIds = credentialSchemaRef.map(ref => List(ref.id))
for {
Expand All @@ -270,7 +272,7 @@ class CredentialServiceImpl(
claims = attributes,
thid = thid,
UUID.randomUUID().toString,
"domain",
domain,
IssueCredentialOfferFormat.SDJWT
)
record <- createIssueCredentialRecord(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class CredentialServiceNotifier(
goal: Option[String],
expirationDuration: Option[Duration],
connectionId: Option[UUID],
domain: String
): URIO[WalletAccessContext, IssueCredentialRecord] =
notifyOnSuccess(
svc.createJWTIssueCredentialRecord(
Expand All @@ -53,7 +54,8 @@ class CredentialServiceNotifier(
goalCode,
goal,
expirationDuration,
connectionId
connectionId,
domain
)
)

Expand All @@ -71,6 +73,7 @@ class CredentialServiceNotifier(
goal: Option[String],
expirationDuration: Option[Duration],
connectionId: Option[UUID],
domain: String
): URIO[WalletAccessContext, IssueCredentialRecord] =
notifyOnSuccess(
svc.createSDJWTIssueCredentialRecord(
Expand All @@ -86,7 +89,8 @@ class CredentialServiceNotifier(
goalCode,
goal,
expirationDuration,
connectionId
connectionId,
domain
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ trait CredentialServiceSpecHelper {
goalCode = None,
goal = None,
expirationDuration = None,
connectionId = Some(UUID.randomUUID())
connectionId = Some(UUID.randomUUID()),
domain = "domain"
)
} yield record

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ object MockCredentialService extends Mock[CredentialService] {
goalCode: Option[String],
goal: Option[String],
expirationDuration: Option[Duration],
connectionId: Option[UUID]
connectionId: Option[UUID],
domain: String
): URIO[WalletAccessContext, IssueCredentialRecord] =
proxy(
CreateJWTIssueCredentialRecord,
Expand Down Expand Up @@ -170,7 +171,8 @@ object MockCredentialService extends Mock[CredentialService] {
goalCode: Option[String],
goal: Option[String],
expirationDuration: Option[Duration],
connectionId: Option[UUID]
connectionId: Option[UUID],
domain: String
): URIO[WalletAccessContext, IssueCredentialRecord] =
proxy(
CreateSDJWTIssueCredentialRecord,
Expand Down

0 comments on commit 81350ea

Please sign in to comment.