Skip to content

Commit

Permalink
fix: adjust Kotlin and TypeScript HTTP client to use the schemaId f…
Browse files Browse the repository at this point in the history
…rom VCDM2.0 (string or list of strings)

Signed-off-by: Yurii Shynbuiev <yurii.shynbuiev@iohk.io>
  • Loading branch information
yshyn-iohk committed Oct 7, 2024
1 parent 65cc9a7 commit 4dfb04c
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 28 deletions.
5 changes: 5 additions & 0 deletions cloud-agent/client/kotlin/.openapi-generator-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ 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/main/kotlin/org/hyperledger/identus/client/models/CreateIssueCredentialRecordRequest.kt

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

Expand All @@ -25,3 +27,6 @@ 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

src/test/kotlin/org/hyperledger/identus/client/models/CreateIssueCredentialRecordRequestTest.kt

1 change: 0 additions & 1 deletion cloud-agent/client/kotlin/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@

rootProject.name = 'cloud-agent-client-kotlin'
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.hyperledger.identus.client.adapters

import com.google.gson.*
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 -> context.deserialize(json, typeOfT)
json.isJsonPrimitive -> listOf(json.asString)
json.isJsonNull -> emptyList()
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.isNullOrEmpty() -> 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
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
*
* Please note:
* This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* Do not edit this file manually.
*
*/

@file:Suppress(
"ArrayInDataClass",
"EnumEntryName",
"RemoveRedundantQualifierName",
"UnusedImport"
)

package org.hyperledger.identus.client.models

import com.google.gson.annotations.JsonAdapter
import com.google.gson.annotations.SerializedName
import org.hyperledger.identus.client.adapters.StringOrStringArrayAdapter

/**
*
*
* @param claims The set of claims that will be included in the issued credential. The JSON object should comply with the schema applicable for this offer (i.e. 'schemaId' or 'credentialDefinitionId').
* @param issuingDID The issuer Prism DID by which the verifiable credential will be issued. DID can be short for or long form.
* @param validityPeriod The validity period in seconds of the verifiable credential that will be issued.
* @param schemaId
* @param credentialDefinitionId The unique identifier (UUID) of the credential definition that will be used for this offer. It should be the identifier of a credential definition that exists in the issuer agent's database. Note that this parameter only applies when the offer is of type 'AnonCreds'.
* @param credentialFormat The credential format for this offer (defaults to 'JWT')
* @param automaticIssuance Specifies whether or not the credential should be automatically generated and issued when receiving the `CredentialRequest` from the holder. If set to `false`, a manual approval by the issuer via another API call will be required for the VC to be issued.
* @param issuingKid Specified the key ID (kid) of the DID, it will be used to sign credential. User should specify just the partial identifier of the key. The full id of the kid MUST be \"<issuingDID>#<kid>\" Note the cryto algorithm used with depend type of the key.
* @param connectionId The unique identifier of a DIDComm connection that already exists between the this issuer agent and the holder cloud or edeg agent. It should be the identifier of a connection that exists in the issuer agent's database. This connection will be used to execute the issue credential protocol. Note: connectionId is only required when the offer is from existing connection. connectionId is not required when the offer is from invitation for connectionless issuance.
* @param goalCode A self-attested code the receiver may want to display to the user or use in automatically deciding what to do with the out-of-band message. goalcode is optional and can be provided when the offer is from invitation for connectionless issuance.
* @param goal A self-attested string that the receiver may want to display to the user about the context-specific goal of the out-of-band message. goal is optional and can be provided when the offer is from invitation for connectionless issuance.
*/


data class CreateIssueCredentialRecordRequest(

/* The set of claims that will be included in the issued credential. The JSON object should comply with the schema applicable for this offer (i.e. 'schemaId' or 'credentialDefinitionId'). */
@SerializedName("claims")
val claims: kotlin.Any?,

/* The issuer Prism DID by which the verifiable credential will be issued. DID can be short for or long form. */
@SerializedName("issuingDID")
val issuingDID: kotlin.String,

/* The validity period in seconds of the verifiable credential that will be issued. */
@SerializedName("validityPeriod")
val validityPeriod: kotlin.Double? = null,

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

/* The unique identifier (UUID) of the credential definition that will be used for this offer. It should be the identifier of a credential definition that exists in the issuer agent's database. Note that this parameter only applies when the offer is of type 'AnonCreds'. */
@SerializedName("credentialDefinitionId")
val credentialDefinitionId: java.util.UUID? = null,

/* The credential format for this offer (defaults to 'JWT') */
@SerializedName("credentialFormat")
val credentialFormat: kotlin.String? = null,

/* Specifies whether or not the credential should be automatically generated and issued when receiving the `CredentialRequest` from the holder. If set to `false`, a manual approval by the issuer via another API call will be required for the VC to be issued. */
@SerializedName("automaticIssuance")
val automaticIssuance: kotlin.Boolean? = null,

/* Specified the key ID (kid) of the DID, it will be used to sign credential. User should specify just the partial identifier of the key. The full id of the kid MUST be \"<issuingDID>#<kid>\" Note the cryto algorithm used with depend type of the key. */
@SerializedName("issuingKid")
val issuingKid: kotlin.String? = null,

/* The unique identifier of a DIDComm connection that already exists between the this issuer agent and the holder cloud or edeg agent. It should be the identifier of a connection that exists in the issuer agent's database. This connection will be used to execute the issue credential protocol. Note: connectionId is only required when the offer is from existing connection. connectionId is not required when the offer is from invitation for connectionless issuance. */
@SerializedName("connectionId")
val connectionId: java.util.UUID? = null,

/* A self-attested code the receiver may want to display to the user or use in automatically deciding what to do with the out-of-band message. goalcode is optional and can be provided when the offer is from invitation for connectionless issuance. */
@SerializedName("goalCode")
val goalCode: kotlin.String? = null,

/* A self-attested string that the receiver may want to display to the user about the context-specific goal of the out-of-band message. goal is optional and can be provided when the offer is from invitation for connectionless issuance. */
@SerializedName("goal")
val goal: kotlin.String? = null

)

Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,7 @@ package org.hyperledger.identus.client.models
import com.google.gson.*
import com.google.gson.annotations.JsonAdapter
import com.google.gson.annotations.SerializedName
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
}
}
}
import org.hyperledger.identus.client.adapters.StringOrStringArrayAdapter

data class Service(

Expand Down
1 change: 1 addition & 0 deletions cloud-agent/client/typescript/.openapi-generator-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ models/CredentialRequest.ts
models/Proof2.ts
models/Service.ts
models/UpdateManagedDIDServiceAction.ts
models/CreateIssueCredentialRecordRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/**
* Identus Cloud Agent API Reference
* The Identus Cloud Agent API facilitates the integration and management of self-sovereign identity capabilities within applications. It supports DID (Decentralized Identifiers) management, verifiable credential exchange, and secure messaging based on DIDComm standards. The API is designed to be interoperable with various blockchain and DLT (Distributed Ledger Technology) platforms, ensuring wide compatibility and flexibility. Key features include connection management, credential issuance and verification, and secure, privacy-preserving communication between entities. Additional information and the full list of capabilities can be found in the [Open Enterprise Agent documentation](https://docs.atalaprism.io/docs/category/prism-cloud-agent)
*
* OpenAPI spec version: 1.39.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 { HttpFile } from '../http/http';

export class CreateIssueCredentialRecordRequest {
/**
* The validity period in seconds of the verifiable credential that will be issued.
*/
'validityPeriod'?: number;
'schemaId'?: string | Array<string>;
/**
* The unique identifier (UUID) of the credential definition that will be used for this offer. It should be the identifier of a credential definition that exists in the issuer agent\'s database. Note that this parameter only applies when the offer is of type \'AnonCreds\'.
*/
'credentialDefinitionId'?: string;
/**
* The credential format for this offer (defaults to \'JWT\')
*/
'credentialFormat'?: string;
/**
* The set of claims that will be included in the issued credential. The JSON object should comply with the schema applicable for this offer (i.e. \'schemaId\' or \'credentialDefinitionId\').
*/
'claims': any | null;
/**
* Specifies whether or not the credential should be automatically generated and issued when receiving the `CredentialRequest` from the holder. If set to `false`, a manual approval by the issuer via another API call will be required for the VC to be issued.
*/
'automaticIssuance'?: boolean;
/**
* The issuer Prism DID by which the verifiable credential will be issued. DID can be short for or long form.
*/
'issuingDID': string;
/**
* Specified the key ID (kid) of the DID, it will be used to sign credential. User should specify just the partial identifier of the key. The full id of the kid MUST be \"<issuingDID>#<kid>\" Note the cryto algorithm used with depend type of the key.
*/
'issuingKid'?: string;
/**
* The unique identifier of a DIDComm connection that already exists between the this issuer agent and the holder cloud or edeg agent. It should be the identifier of a connection that exists in the issuer agent\'s database. This connection will be used to execute the issue credential protocol. Note: connectionId is only required when the offer is from existing connection. connectionId is not required when the offer is from invitation for connectionless issuance.
*/
'connectionId'?: string;
/**
* A self-attested code the receiver may want to display to the user or use in automatically deciding what to do with the out-of-band message. goalcode is optional and can be provided when the offer is from invitation for connectionless issuance.
*/
'goalCode'?: string;
/**
* A self-attested string that the receiver may want to display to the user about the context-specific goal of the out-of-band message. goal is optional and can be provided when the offer is from invitation for connectionless issuance.
*/
'goal'?: string;

static readonly discriminator: string | undefined = undefined;

static readonly attributeTypeMap: Array<{name: string, baseName: string, type: string, format: string}> = [
{
"name": "validityPeriod",
"baseName": "validityPeriod",
"type": "number",
"format": "double"
},
{
"name": "schemaId",
"baseName": "schemaId",
"type": "CreateIssueCredentialRecordRequestSchemaId",
"format": ""
},
{
"name": "credentialDefinitionId",
"baseName": "credentialDefinitionId",
"type": "string",
"format": "uuid"
},
{
"name": "credentialFormat",
"baseName": "credentialFormat",
"type": "string",
"format": ""
},
{
"name": "claims",
"baseName": "claims",
"type": "any",
"format": ""
},
{
"name": "automaticIssuance",
"baseName": "automaticIssuance",
"type": "boolean",
"format": ""
},
{
"name": "issuingDID",
"baseName": "issuingDID",
"type": "string",
"format": ""
},
{
"name": "issuingKid",
"baseName": "issuingKid",
"type": "string",
"format": ""
},
{
"name": "connectionId",
"baseName": "connectionId",
"type": "string",
"format": "uuid"
},
{
"name": "goalCode",
"baseName": "goalCode",
"type": "string",
"format": ""
},
{
"name": "goal",
"baseName": "goal",
"type": "string",
"format": ""
} ];

static getAttributeTypeMap() {
return CreateIssueCredentialRecordRequest.attributeTypeMap;
}

public constructor() {
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class JwtCredentialSteps {
}

val credentialOfferRequest = CreateIssueCredentialRecordRequest(
schemaId = schemaId,
schemaId = schemaId?.let { listOf(it) },
claims = claims,
issuingDID = did,
connectionId = issuer.recall<Connection>("connection-with-${holder.name}").connectionId,
Expand Down

0 comments on commit 4dfb04c

Please sign in to comment.