From 4ce8b7dfa876513298c55426329c13f0b4ee7f81 Mon Sep 17 00:00:00 2001 From: mikeplotean Date: Mon, 12 Aug 2024 12:58:50 +0300 Subject: [PATCH] chore: clean leftover parameters, update according to sonarcloud suggestions --- .../main/kotlin/id/walt/issuer/NewIssuanceStub.kt | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/waltid-services/waltid-issuer-api/src/main/kotlin/id/walt/issuer/NewIssuanceStub.kt b/waltid-services/waltid-issuer-api/src/main/kotlin/id/walt/issuer/NewIssuanceStub.kt index 7e1bb0ef6..28c182620 100644 --- a/waltid-services/waltid-issuer-api/src/main/kotlin/id/walt/issuer/NewIssuanceStub.kt +++ b/waltid-services/waltid-issuer-api/src/main/kotlin/id/walt/issuer/NewIssuanceStub.kt @@ -6,7 +6,6 @@ import id.walt.credentials.CredentialBuilder import id.walt.credentials.CredentialBuilderType import id.walt.credentials.issuance.Issuer.baseIssue import id.walt.credentials.verification.policies.JwtSignaturePolicy -import id.walt.crypto.keys.Key import id.walt.crypto.keys.KeyType import id.walt.crypto.keys.jwk.JWKKey import id.walt.did.dids.DidService @@ -44,7 +43,7 @@ private val issuerDidKey by lazy { runBlocking { JWKKey.generate(KeyType.Ed25519 private val testIssuerDid by lazy { runBlocking { DidService.registerByKey("key", issuerDidKey).did } } private val CI_TOKEN_KEY = runBlocking { JWKKey.generate(KeyType.RSA) } -private fun signToken(target: TokenTarget, payload: JsonObject, header: JsonObject? = null, keyId: String? = null, privKey: Key? = null) = +private fun signToken(payload: JsonObject) = runBlocking { CI_TOKEN_KEY.signJws(payload.toString().toByteArray()) } @OptIn(ExperimentalEncodingApi::class) @@ -164,7 +163,6 @@ suspend fun main() { // TODO: Validate authorization code // TODO: generate access token val accessToken = signToken( - target = TokenTarget.ACCESS, payload = buildJsonObject { put(JWTClaims.Payload.subject, "test-issuance-session") put(JWTClaims.Payload.issuer, "http://blank?ci-provider=baseUrl") @@ -176,8 +174,8 @@ suspend fun main() { println("// -------- WALLET ----------") check(tokenResponse.isSuccess) - check(tokenResponse.accessToken != null) - check(tokenResponse.cNonce != null) + checkNotNull(tokenResponse.accessToken) + checkNotNull(tokenResponse.cNonce) println("// receive credential") val nonce = tokenResponse.cNonce!! @@ -196,7 +194,7 @@ suspend fun main() { println("// -------- CREDENTIAL ISSUER ----------") val parsedHolderKeyId = credReq.proof?.jwt?.let { JwtUtils.parseJWTHeader(it) }?.get("kid")?.jsonPrimitive?.content - check(parsedHolderKeyId != null) + checkNotNull(parsedHolderKeyId) check(parsedHolderKeyId.startsWith("did:")) val parsedHolderDid = parsedHolderKeyId.substringBefore("#") // todo: null check @@ -211,7 +209,7 @@ suspend fun main() { // todo: handle deferred issuance val generatedCredential = doGenerateCredential(credReq).credential - check(generatedCredential != null) + checkNotNull(generatedCredential) val credentialResponse: CredentialResponse = CredentialResponse.success(credReq.format, credential = generatedCredential) println("Credential response: $credentialResponse")