Skip to content

Commit

Permalink
Add everything
Browse files Browse the repository at this point in the history
Signed-off-by: Shota Jolbordi <[email protected]>
  • Loading branch information
Shota Jolbordi committed Sep 27, 2024
1 parent 693dcc4 commit ab6c9ad
Show file tree
Hide file tree
Showing 113 changed files with 2,644 additions and 698 deletions.
2 changes: 2 additions & 0 deletions .sbtopts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
-Dquill.macro.log=false
-J-Xmx4G
-J-XX:+UseG1GC
12 changes: 11 additions & 1 deletion cloud-agent/client/kotlin/.openapi-generator-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ settings.gradle
build.gradle
docs

# igore broken files
# ignore broken files

src/main/kotlin/org/hyperledger/identus/client/models/UpdateManagedDIDServiceAction.kt
src/main/kotlin/org/hyperledger/identus/client/models/UpdateManagedDIDServiceActionType.kt

Expand All @@ -15,3 +16,12 @@ src/main/kotlin/org/hyperledger/identus/client/models/CredentialSubject.kt
src/main/kotlin/org/hyperledger/identus/client/models/DateTimeParameter.kt
src/main/kotlin/org/hyperledger/identus/client/models/DidParameter.kt
src/main/kotlin/org/hyperledger/identus/client/models/VcVerificationParameter.kt

src/test/kotlin/org/hyperledger/identus/client/models/UpdateManagedDIDServiceActionTest.kt
src/test/kotlin/org/hyperledger/identus/client/models/UpdateManagedDIDServiceActionTypeTest.kt

src/test/kotlin/org/hyperledger/identus/client/models/ServiceTest.kt
src/test/kotlin/org/hyperledger/identus/client/models/ServiceTypeTest.kt

src/test/kotlin/org/hyperledger/identus/client/models/StatusPurposeTest.kt
src/test/kotlin/org/hyperledger/identus/client/models/CredentialSubjectTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,52 @@
"ArrayInDataClass",
"EnumEntryName",
"RemoveRedundantQualifierName",
"UnusedImport"
"UnusedImport",
)

package org.hyperledger.identus.client.models

import org.hyperledger.identus.client.models.Json

import com.google.gson.*
import com.google.gson.annotations.JsonAdapter
import com.google.gson.annotations.SerializedName

/**
* A service expressed in the DID document. https://www.w3.org/TR/did-core/#services
*
* @param id The id of the service. Requires a URI fragment when use in create / update DID. Returns the full ID (with DID prefix) when resolving DID
* @param type
* @param serviceEndpoint
*/


data class Service (
import java.lang.reflect.Type

class StringOrStringArrayAdapter : JsonSerializer<List<String>>, JsonDeserializer<List<String>> {

// Deserialize logic: String or Array of Strings to List<String>
override fun deserialize(json: JsonElement?, typeOfT: Type?, context: JsonDeserializationContext?): List<String> {
return when {
json?.isJsonArray == true -> {
context!!.deserialize(json, typeOfT)
}
json?.isJsonPrimitive == true -> {
listOf(json.asString)
}
else -> throw JsonParseException("Unexpected type for field")
}
}

// Serialize logic: List<String> to String or Array of Strings
override fun serialize(src: List<String>?, typeOfSrc: Type?, context: JsonSerializationContext?): JsonElement {
return when {
src == null -> JsonNull.INSTANCE
src.size == 1 -> JsonPrimitive(src[0]) // If only one string, serialize as a single string
else -> context!!.serialize(src) // Otherwise, serialize as a list
}
}
}

data class Service(

/* The id of the service. Requires a URI fragment when use in create / update DID. Returns the full ID (with DID prefix) when resolving DID */
@SerializedName("id")
val id: kotlin.String,

@SerializedName("type")
@JsonAdapter(StringOrStringArrayAdapter::class)
val type: kotlin.collections.List<kotlin.String>? = null,

@SerializedName("serviceEndpoint")
val serviceEndpoint: Json
val serviceEndpoint: JsonElement? = null,

)

Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,23 @@
"ArrayInDataClass",
"EnumEntryName",
"RemoveRedundantQualifierName",
"UnusedImport"
"UnusedImport",
)

package org.hyperledger.identus.client.models

import org.hyperledger.identus.client.models.Json

import com.google.gson.JsonElement
import com.google.gson.annotations.SerializedName

/**
* A patch to existing Service. 'type' and 'serviceEndpoint' cannot both be empty.
*
* @param id The id of the service to update
* @param type
* @param serviceEndpoint
* @param type
* @param serviceEndpoint
*/


data class UpdateManagedDIDServiceAction (
data class UpdateManagedDIDServiceAction(

/* The id of the service to update */
@SerializedName("id")
Expand All @@ -38,7 +36,6 @@ data class UpdateManagedDIDServiceAction (
val type: kotlin.collections.List<kotlin.String>? = null,

@SerializedName("serviceEndpoint")
val serviceEndpoint: Json? = null
val serviceEndpoint: JsonElement? = null,

)

16 changes: 1 addition & 15 deletions cloud-agent/client/typescript/models/Service.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
/**
* Prism Agent
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* OpenAPI spec version: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

import { Json } from '../models/Json';

/**
* A service expressed in the DID document. https://www.w3.org/TR/did-core/#services
*/
Expand All @@ -21,7 +7,7 @@ export class Service {
*/
'id': string;
'type': Array<string>;
'serviceEndpoint': Json;
'serviceEndpoint': string | Array<string> | object;

static readonly discriminator: string | undefined = undefined;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
/**
* Prism Agent
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* OpenAPI spec version: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/

import { Json } from '../models/Json';

/**
* A patch to existing Service. \'type\' and \'serviceEndpoint\' cannot both be empty.
*/
Expand All @@ -21,7 +7,7 @@ export class UpdateManagedDIDServiceAction {
*/
'id': string;
'type'?: Array<string>;
'serviceEndpoint'?: Json;
'serviceEndpoint'?: string | Array<string> | object;

static readonly discriminator: string | undefined = undefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ agent {
port = 8085
port =${?AGENT_HTTP_PORT}
}
serviceName = "agent-base-url"
publicEndpointUrl = "https://host.docker.internal:8080/cloud-agent"
publicEndpointUrl = ${?REST_SERVICE_URL}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.hyperledger.identus.pollux.prex.PresentationExchangeServerEndpoints
import org.hyperledger.identus.pollux.vc.jwt.DidResolver as JwtDidResolver
import org.hyperledger.identus.presentproof.controller.PresentProofServerEndpoints
import org.hyperledger.identus.resolvers.DIDResolver
import org.hyperledger.identus.shared.http.UriResolver
import org.hyperledger.identus.shared.models.{HexString, WalletAccessContext, WalletAdministrationContext, WalletId}
import org.hyperledger.identus.shared.utils.DurationOps.toMetricsSeconds
import org.hyperledger.identus.system.controller.SystemServerEndpoints
Expand Down Expand Up @@ -68,8 +69,8 @@ object CloudAgentApp {
} yield ()

private val presentProofExchangeJob: RIO[
AppConfig & DidOps & DIDResolver & JwtDidResolver & HttpClient & PresentationService & CredentialService &
DIDNonSecretStorage & DIDService & ManagedDIDService,
AppConfig & DidOps & UriResolver & DIDResolver & JwtDidResolver & HttpClient & PresentationService &
CredentialService & DIDNonSecretStorage & DIDService & ManagedDIDService,
Unit
] =
for {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ trait ControllerHelper {
protected def extractPrismDIDFromString(maybeDid: String): IO[ErrorResponse, PrismDID] =
ZIO
.fromEither(PrismDID.fromString(maybeDid))
.mapError(e => ErrorResponse.badRequest(detail = Some(s"Error parsing string as PrismDID: ${e}")))
.mapError(e => ErrorResponse.badRequest(detail = Some(s"Error parsing string as PrismDID: $e")))

protected def getLongFormPrismDID(
did: PrismDID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import org.hyperledger.identus.agent.walletapi.sql.{
}
import org.hyperledger.identus.agent.walletapi.storage.GenericSecretStorage
import org.hyperledger.identus.castor.controller.{DIDControllerImpl, DIDRegistrarControllerImpl}
import org.hyperledger.identus.castor.core.model.did.{
Service as DidDocumentService,
ServiceEndpoint as DidDocumentServiceEndpoint,
ServiceType as DidDocumentServiceType
}
import org.hyperledger.identus.castor.core.service.DIDServiceImpl
import org.hyperledger.identus.castor.core.util.DIDOperationValidator
import org.hyperledger.identus.connect.controller.ConnectionControllerImpl
Expand Down Expand Up @@ -142,6 +147,24 @@ object MainApp extends ZIOAppDefault {
|""".stripMargin)
.ignore

appConfig <- ZIO.service[AppConfig].provide(SystemModule.configLayer)
// these services are added to any DID document by default when they are created.
defaultDidDocumentServices = Set(
DidDocumentService(
id = appConfig.agent.httpEndpoint.serviceName,
serviceEndpoint = DidDocumentServiceEndpoint
.Single(
DidDocumentServiceEndpoint.UriOrJsonEndpoint
.Uri(
DidDocumentServiceEndpoint.UriValue
.fromString(appConfig.agent.httpEndpoint.publicEndpointUrl.toString)
.toOption
.get // This will fail if URL is invalid, which will prevent app from starting since public endpoint in config is invalid
)
),
`type` = DidDocumentServiceType.Single(DidDocumentServiceType.Name.fromStringUnsafe("LinkedResourceV1"))
)
)
_ <- preMigrations
_ <- migrations

Expand Down Expand Up @@ -178,7 +201,7 @@ object MainApp extends ZIOAppDefault {
AppModule.didJwtResolverLayer,
DIDOperationValidator.layer(),
DIDResolver.layer,
HttpURIDereferencerImpl.layer,
GenericUriResolverImpl.layer,
PresentationDefinitionValidatorImpl.layer,
// service
ConnectionServiceImpl.layer >>> ConnectionServiceNotifier.layer,
Expand All @@ -188,7 +211,7 @@ object MainApp extends ZIOAppDefault {
LinkSecretServiceImpl.layer >>> CredentialServiceImpl.layer >>> CredentialServiceNotifier.layer,
DIDServiceImpl.layer,
EntityServiceImpl.layer,
ManagedDIDServiceWithEventNotificationImpl.layer,
ZLayer.succeed(defaultDidDocumentServices) >>> ManagedDIDServiceWithEventNotificationImpl.layer,
LinkSecretServiceImpl.layer >>> PresentationServiceImpl.layer >>> PresentationServiceNotifier.layer,
VerificationPolicyServiceImpl.layer,
WalletManagementServiceImpl.layer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ final case class DatabaseConfig(
DbConfig(
username = if (appUser) appUsername else username,
password = if (appUser) appPassword else password,
jdbcUrl = s"jdbc:postgresql://${host}:${port}/${databaseName}",
jdbcUrl = s"jdbc:postgresql://$host:$port/${databaseName}",
awaitConnectionThreads = awaitConnectionThreads
)
}
Expand Down Expand Up @@ -187,7 +187,7 @@ final case class AgentConfig(

}

final case class HttpEndpointConfig(http: HttpConfig, publicEndpointUrl: java.net.URL)
final case class HttpEndpointConfig(http: HttpConfig, serviceName: String, publicEndpointUrl: java.net.URL)

final case class DidCommEndpointConfig(http: HttpConfig, publicEndpointUrl: java.net.URL)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
/*DIDSecretStorageError | PresentationError | CredentialServiceError | BackgroundJobError | TransportError | */
CastorDIDResolutionError | GetManagedDIDError | Failure

private type RESOURCES = COMMON_RESOURCES & CredentialService & JwtDidResolver & DIDService & AppConfig &
MESSAGING_RESOURCES
private type RESOURCES = COMMON_RESOURCES & CredentialService & JwtDidResolver & UriResolver & DIDService &
AppConfig & MESSAGING_RESOURCES

private type COMMON_RESOURCES = PresentationService & DIDNonSecretStorage & ManagedDIDService

Expand Down Expand Up @@ -1035,7 +1035,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
credentialFormat: CredentialFormat,
invitation: Option[Invitation]
): ZIO[
AppConfig & JwtDidResolver & COMMON_RESOURCES & MESSAGING_RESOURCES,
AppConfig & JwtDidResolver & UriResolver & COMMON_RESOURCES & MESSAGING_RESOURCES,
Failure,
Unit
] = {
Expand Down Expand Up @@ -1069,7 +1069,7 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
presentation: Presentation,
invitation: Option[Invitation]
): ZIO[
AppConfig & JwtDidResolver & COMMON_RESOURCES & MESSAGING_RESOURCES,
AppConfig & JwtDidResolver & UriResolver & COMMON_RESOURCES & MESSAGING_RESOURCES,
Failure,
Unit
] = {
Expand Down Expand Up @@ -1114,28 +1114,12 @@ object PresentBackgroundJobs extends BackgroundJobsHelper {
// https://www.w3.org/TR/vc-data-model/#proofs-signatures-0
// A proof is typically attached to a verifiable presentation for authentication purposes
// and to a verifiable credential as a method of assertion.
httpLayer <- ZIO.service[HttpClient]
httpUrlResolver = new UriResolver {
override def resolve(uri: String): IO[GenericUriResolverError, String] = {
val res = HttpClient
.get(uri)
.map(x => x.bodyAsString)
.provideSomeLayer(ZLayer.succeed(httpLayer))
res.mapError(err => SchemaSpecificResolutionError("http", err))
}
}
genericUriResolver = GenericUriResolver(
Map(
"data" -> DataUrlResolver(),
"http" -> httpUrlResolver,
"https" -> httpUrlResolver
)
)
uriResolver <- ZIO.service[UriResolver]
result <- JwtPresentation
.verify(
JWT(base64Decoded),
verificationConfig.toPresentationVerificationOptions()
)(didResolverService, genericUriResolver)(clock)
)(didResolverService, uriResolver)(clock)
.mapError(error => PresentationError.PresentationVerificationError(error.mkString))
} yield result

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,13 @@ object ServiceType {
case Single(value) => Left(value)
case Multiple(values) => Right(values.toArray)
}
given decoder: JsonDecoder[ServiceType] = JsonDecoder.string
.orElseEither(JsonDecoder.array[String])
.map[ServiceType] {
case Left(value) => Single(value)
case Right(values) => Multiple(values.toSeq)
}

given decoder: JsonDecoder[ServiceType] = JsonDecoder[String]
.map(Single.apply)
.orElse(
JsonDecoder[Seq[String]].map(Multiple.apply)
)

given schema: Schema[ServiceType] = Schema
.schemaForEither(Schema.schemaForString, Schema.schemaForArray[String])
.map[ServiceType] {
Expand Down
Loading

0 comments on commit ab6c9ad

Please sign in to comment.