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

sdk v2.2.0 P-256 #90

Merged
merged 1 commit into from
Feb 13, 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
4 changes: 2 additions & 2 deletions VCL/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ android {
defaultConfig {
minSdk 24
targetSdk 33
versionName "2.1.0"
versionCode 126
versionName "2.2.0"
versionCode 127
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Created by Michael Avoyan on 08/02/2024.
*
* Copyright 2022 Velocity Career Labs inc.
* SPDX-License-Identifier: Apache-2.0
*/

package io.velocitycareerlabs.api

import com.nimbusds.jose.JWSAlgorithm
import com.nimbusds.jose.jwk.Curve

enum class VCLSignatureAlgorithm(val value: String) {
ES256("P-256"),
SECP256k1("secp256k1");

val curve: Curve get() = when(this) {
ES256 -> Curve.P_256
SECP256k1 -> Curve.SECP256K1
}

val jwsAlgorithm: JWSAlgorithm get() = when(this) {
ES256 -> JWSAlgorithm.ES256
SECP256k1 -> JWSAlgorithm.ES256K
}

companion object {
fun fromString(value: String) =
when (value) {
ES256.value -> ES256
SECP256k1.value -> SECP256k1
else -> ES256
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ data class VCLFinalizeOffersDescriptor(
val finalizeOffersUri: String get() = credentialManifest.finalizeOffersUri
val serviceTypes: VCLServiceTypes get() = credentialManifest.verifiedProfile.serviceTypes

fun generateRequestBody(jwt: VCLJwt): JSONObject {
fun generateRequestBody(proof: VCLJwt?): JSONObject {
val retVal = JSONObject(this.payload.toString())
val proof = JSONObject()
proof.put(CodingKeys.KeyProofType, CodingKeys.KeyJwt)
proof.put(CodingKeys.KeyJwt, jwt.encodedJwt)
retVal.put(CodingKeys.KeyProof, proof)
proof?.let {
val proofJson = JSONObject()
proofJson.put(CodingKeys.KeyProofType, CodingKeys.KeyJwt)
proofJson.put(CodingKeys.KeyJwt, it.encodedJwt)
retVal.put(CodingKeys.KeyProof, proofJson)
}
return retVal
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ data class VCLOffers (
val all: List<VCLOffer>,
val responseCode: Int,
val sessionToken: VCLToken,
val challenge: String,
val challenge: String? = null,
) {
companion object CodingKeys {
const val KeyOffers = "offers"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
package io.velocitycareerlabs.api.entities.initialization

import io.velocitycareerlabs.api.VCLCryptoServiceType
import io.velocitycareerlabs.api.VCLSignatureAlgorithm

data class VCLCryptoServicesDescriptor(
val cryptoServiceType: VCLCryptoServiceType = VCLCryptoServiceType.Local,
val signatureAlgorithm: VCLSignatureAlgorithm = VCLSignatureAlgorithm.ES256,
val injectedCryptoServicesDescriptor: VCLInjectedCryptoServicesDescriptor? = null,
val remoteCryptoServicesUrlsDescriptor: VCLRemoteCryptoServicesUrlsDescriptor? = null
)
2 changes: 2 additions & 0 deletions VCL/src/main/java/io/velocitycareerlabs/impl/GlobalConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ package io.velocitycareerlabs.impl

import io.velocitycareerlabs.BuildConfig
import io.velocitycareerlabs.api.VCLEnvironment
import io.velocitycareerlabs.api.VCLSignatureAlgorithm
import io.velocitycareerlabs.api.VCLXVnfProtocolVersion

internal object GlobalConfig {
const val VclPackage = BuildConfig.LIBRARY_PACKAGE_NAME

var CurrentEnvironment = VCLEnvironment.Prod
var XVnfProtocolVersion = VCLXVnfProtocolVersion.XVnfProtocolVersion1
var SignatureAlgorithm = VCLSignatureAlgorithm.ES256

var IsDebugOn = false //BuildConfig.DEBUG

Expand Down
64 changes: 31 additions & 33 deletions VCL/src/main/java/io/velocitycareerlabs/impl/VCLImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ internal class VCLImpl: VCL {

private const val ModelsToInitializeAmount = 3
}

private lateinit var initializationDescriptor: VCLInitializationDescriptor

private lateinit var credentialTypesModel: CredentialTypesModel
Expand Down Expand Up @@ -214,6 +215,8 @@ internal class VCLImpl: VCL {
private fun initGlobalConfigurations() {
GlobalConfig.CurrentEnvironment = initializationDescriptor.environment
GlobalConfig.XVnfProtocolVersion = initializationDescriptor.xVnfProtocolVersion
GlobalConfig.SignatureAlgorithm =
initializationDescriptor.cryptoServicesDescriptor.signatureAlgorithm
GlobalConfig.IsDebugOn = initializationDescriptor.isDebugOn
}

Expand Down Expand Up @@ -266,14 +269,12 @@ internal class VCLImpl: VCL {
presentationSubmissionUseCase.submit(
submission = presentationSubmission
) { presentationSubmissionResult ->
presentationSubmissionResult.handleResult(
{
successHandler(it)
},
{
logError("submit presentation", it)
errorHandler(it)
}
presentationSubmissionResult.handleResult({
successHandler(it)
}, {
logError("submit presentation", it)
errorHandler(it)
}
)
}
}
Expand All @@ -284,14 +285,12 @@ internal class VCLImpl: VCL {
errorHandler: (VCLError) -> Unit
) {
exchangeProgressUseCase.getExchangeProgress(exchangeDescriptor) { presentationSubmissionResult ->
presentationSubmissionResult.handleResult(
{
successHandler(it)
},
{
logError("getExchangeProgress", it)
errorHandler(it)
}
presentationSubmissionResult.handleResult({
successHandler(it)
}, {
logError("getExchangeProgress", it)
errorHandler(it)
}
)
}
}
Expand All @@ -302,14 +301,12 @@ internal class VCLImpl: VCL {
errorHandler: (VCLError) -> Unit
) {
organizationsUseCase.searchForOrganizations(organizationsSearchDescriptor) { organization ->
organization.handleResult(
{
successHandler(it)
},
{
logError("searchForOrganizations", it)
errorHandler(it)
}
organization.handleResult({
successHandler(it)
}, {
logError("searchForOrganizations", it)
errorHandler(it)
}
)
}
}
Expand All @@ -319,7 +316,10 @@ internal class VCLImpl: VCL {
successHandler: (VCLCredentialManifest) -> Unit,
errorHandler: (VCLError) -> Unit
) {
VCLLog.d(TAG, "credentialManifestDescriptor: ${credentialManifestDescriptor.toPropsString()}")
VCLLog.d(
TAG,
"credentialManifestDescriptor: ${credentialManifestDescriptor.toPropsString()}"
)
credentialManifestDescriptor.did?.let { did ->
profileServiceTypeVerifier.verifyServiceTypeOfVerifiedProfile(
verifiedProfileDescriptor = VCLVerifiedProfileDescriptor(did = did),
Expand All @@ -329,14 +329,12 @@ internal class VCLImpl: VCL {
credentialManifestDescriptor,
verifiedProfile
) { credentialManifest ->
credentialManifest.handleResult(
{
successHandler(it)
},
{
logError("getCredentialManifest", it)
errorHandler(it)
}
credentialManifest.handleResult({
successHandler(it)
}, {
logError("getCredentialManifest", it)
errorHandler(it)
}
)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal class FinalizeOffersRepositoryImpl(
override fun finalizeOffers(
finalizeOffersDescriptor: VCLFinalizeOffersDescriptor,
sessionToken: VCLToken,
proof: VCLJwt,
proof: VCLJwt?,
completionBlock: (VCLResult<List<VCLJwt>>) -> Unit
) {
networkService.sendRequest(
Expand All @@ -36,7 +36,7 @@ internal class FinalizeOffersRepositoryImpl(
Pair(HeaderKeys.Authorization, "${HeaderKeys.Bearer} ${sessionToken.value}"),
Pair(HeaderKeys.XVnfProtocolVersion, HeaderValues.XVnfProtocolVersion)
),
body = finalizeOffersDescriptor.generateRequestBody(jwt = proof).toString(),
body = finalizeOffersDescriptor.generateRequestBody(proof = proof).toString(),
method = Request.HttpMethod.POST,
contentType = Request.ContentTypeApplicationJson,
completionBlock = { result ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ internal class GenerateOffersRepositoryImpl(
),
responseCode = offersResponse.code,
sessionToken = sessionToken,
challenge = payload.optString(VCLOffers.CodingKeys.KeyChallenge) ?: ""
challenge = payload.optString(VCLOffers.CodingKeys.KeyChallenge)
)
} ?: run {
// VCLXVnfProtocolVersion.XVnfProtocolVersion1
Expand All @@ -80,7 +80,6 @@ internal class GenerateOffersRepositoryImpl(
all = Utils.offersFromJsonArray(offersJsonArray),
responseCode = offersResponse.code,
sessionToken = sessionToken,
challenge = ""
)
} ?: run {
// No offers
Expand All @@ -89,8 +88,7 @@ internal class GenerateOffersRepositoryImpl(
all = listOf(),
responseCode = offersResponse.code,
sessionToken = sessionToken,
challenge = ""
)
)
}
}
}
Expand Down
Loading
Loading