Skip to content

Commit

Permalink
chore: clean leftover parameters, update according to sonarcloud sugg…
Browse files Browse the repository at this point in the history
…estions
  • Loading branch information
mikeplotean committed Aug 12, 2024
1 parent f3fea2b commit 4ce8b7d
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand All @@ -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!!
Expand All @@ -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
Expand All @@ -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")
Expand Down

0 comments on commit 4ce8b7d

Please sign in to comment.