Skip to content

Commit

Permalink
test: finish zkp presentation flow scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
amagyar-iohk committed Apr 25, 2024
1 parent 523cb36 commit 5a38513
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 16 deletions.
2 changes: 1 addition & 1 deletion tests/end-to-end/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ repositories {

dependencies {
testImplementation("io.iohk.atala.prism.walletsdk:atala-prism-sdk:3.0.0")
testImplementation("io.iohk.atala.prism:prism-kotlin-client:1.28.0")
testImplementation("io.iohk.atala.prism:prism-kotlin-client:1.31.0")
testImplementation("io.iohk.atala:atala-automation:0.3.2")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ object Environment {
anoncredSchema.name = "Automation Anoncred"
anoncredSchema.version = "1.0"
anoncredSchema.issuerId = this.publishedDid
anoncredSchema.attrNames = mutableListOf("name", "age")
anoncredSchema.attrNames = mutableListOf("name", "age", "gender")

val credentialSchemaInput = CredentialSchemaInput(
author = this.publishedDid,
Expand Down Expand Up @@ -219,7 +219,7 @@ object Environment {
author = publishedDid,
schemaId = "${agentUrl}/schema-registry/schemas/${newSchemaGuid}/schema",
signatureType = "CL",
supportRevocation = true,
supportRevocation = false,
description = "Test Automation Auto-Generated"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ class CloudAgentSteps {
cloudAgentWorkflow.askForPresentProof(cloudAgent)
}

@When("{actor} asks for present-proof for anoncred")
fun `Cloud Agent asks for present-proof for anoncred`(cloudAgent: Actor) {
cloudAgentWorkflow.askForPresentProofForAnoncred(cloudAgent)
}

@Then("{actor} should have the connection status updated to '{}'")
fun `Cloud Agent should have the connection status updated`(cloudAgent: Actor, expectedState: String) {
cloudAgentWorkflow.waitForConnectionState(cloudAgent, expectedState)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EdgeAgentSteps {
edgeAgentWorkflow.connect(edgeAgent)
}

@When("{actor} has {} credentials issued by {actor}")
@When("{actor} has '{}' credentials issued by {actor}")
fun `Edge Agent has {} issued credential`(edgeAgent: Actor, numberOfCredentialsIssued: Int, cloudAgent: Actor) {
repeat(numberOfCredentialsIssued) {
cloudAgentWorkflow.offerCredential(cloudAgent)
Expand All @@ -35,6 +35,18 @@ class EdgeAgentSteps {
}
}

@When("{actor} has '{}' anonymous credentials issued by {actor}")
fun `Edge Agent has {} anonymous issued credential`(edgeAgent: Actor, numberOfCredentialsIssued: Int, cloudAgent: Actor) {
repeat(numberOfCredentialsIssued) {
cloudAgentWorkflow.offerAnonymousCredential(cloudAgent)
edgeAgentWorkflow.waitForCredentialOffer(edgeAgent, 1)
edgeAgentWorkflow.acceptCredential(edgeAgent)
cloudAgentWorkflow.verifyCredentialState(cloudAgent, cloudAgent.recall("recordId"), "CredentialSent")
edgeAgentWorkflow.waitToReceiveCredentialIssuance(edgeAgent, 1)
edgeAgentWorkflow.processIssuedCredential(edgeAgent, 1)
}
}

@When("{actor} accepts {} credential offer sequentially from {actor}")
fun `Edge Agent accepts multiple credentials offer sequentially from Cloud Agent`(
edgeAgent: Actor,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.iohk.atala.prism.utils

import java.security.SecureRandom

object Utils {
/**
static generateNonce(length: number): string {
let result = ""
while (result.length < length) {
const byte = crypto.randomBytes(1)[0]
if (byte >= 250) {
continue
}
const randomDigit = byte % 10
result += randomDigit.toString()
}
return result
}
*/
fun generateNonce(length: Int): String {
var result = ""
val secureRandom = SecureRandom()
while (result.length < length) {
val byte = ByteArray(1)
secureRandom.nextBytes(byte)
val int = byte[0].toInt() and 0xFF
if (int > 250) {
continue
}
val digit = int % 10
result += digit
}
return result
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ import io.iohk.atala.automation.serenity.ensure.Ensure
import io.iohk.atala.automation.serenity.interactions.PollingWait
import io.iohk.atala.automation.serenity.questions.HttpRequest
import io.iohk.atala.prism.configuration.Environment
import io.iohk.atala.prism.models.*
import io.iohk.atala.prism.models.AnoncredPresentationRequestV1
import io.iohk.atala.prism.models.AnoncredRequestedAttributeV1
import io.iohk.atala.prism.models.AnoncredRequestedPredicateV1
import io.iohk.atala.prism.models.CreateConnectionRequest
import io.iohk.atala.prism.models.CreateIssueCredentialRecordRequest
import io.iohk.atala.prism.models.Options
import io.iohk.atala.prism.models.ProofRequestAux
import io.iohk.atala.prism.models.RequestPresentationInput
import io.iohk.atala.prism.utils.Utils
import net.serenitybdd.rest.SerenityRest.lastResponse
import net.serenitybdd.screenplay.Actor
import net.serenitybdd.screenplay.rest.interactions.Post
Expand Down Expand Up @@ -64,13 +72,18 @@ class CloudAgentWorkflow {
fun offerAnonymousCredential(cloudAgent: Actor) {
val connectionId = cloudAgent.recall<String>("connectionId")
val credential = CreateIssueCredentialRecordRequest(
claims = mapOf(Pair("name", "automation"), Pair("age", "99")),
claims = mapOf(
"name" to "automation",
"age" to "99",
"gender" to "M"
),
automaticIssuance = true,
issuingDID = Environment.publishedDid,
connectionId = UUID.fromString(connectionId),
credentialFormat = "AnonCreds",
credentialDefinitionId = UUID.fromString(Environment.anoncredDefinitionId)
)

cloudAgent.attemptsTo(
Post.to("/issue-credentials/credential-offers").body(credential),
Ensure.thatTheLastResponse().statusCode().isEqualTo(HttpStatus.SC_CREATED)
Expand Down Expand Up @@ -103,6 +116,50 @@ class CloudAgentWorkflow {
cloudAgent.remember("presentationId", lastResponse().get<String>("presentationId"))
}

fun askForPresentProofForAnoncred(cloudAgent: Actor) {
val credentialDefinitionId = Environment.agentUrl +
"/credential-definition-registry/definitions/" +
Environment.anoncredDefinitionId +
"/definition"
val anoncredsPresentationRequestV1 = AnoncredPresentationRequestV1(
requestedAttributes = mapOf(
"gender" to AnoncredRequestedAttributeV1(
name = "gender",
restrictions = listOf(
mapOf(
"attr::gender::value" to "M",
"cred_def_id" to credentialDefinitionId
)
)
)
),
requestedPredicates = mapOf(
"age" to AnoncredRequestedPredicateV1(
name = "age",
pType = ">",
pValue = 18,
restrictions = emptyList()
)
),
name = "proof_req_1",
nonce = Utils.generateNonce(25),
version = "0.1"
)

val presentProofRequest = RequestPresentationInput(
connectionId = UUID.fromString(cloudAgent.recall("connectionId")),
credentialFormat = "AnonCreds",
anoncredPresentationRequest = anoncredsPresentationRequestV1,
proofs = emptyList()
)

cloudAgent.attemptsTo(
Post.to("/present-proof/presentations").body(presentProofRequest),
Ensure.thatTheLastResponse().statusCode().isEqualTo(HttpStatus.SC_CREATED)
)
cloudAgent.remember("presentationId", lastResponse().get<String>("presentationId"))
}

fun verifyCredentialState(cloudAgent: Actor, recordId: String, state: String) {
cloudAgent.attemptsTo(
PollingWait.until(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
@proof @anoncred
Feature: Respond to request proof
The Edge Agent should be able to respond to a proof-of-request
Feature: Respond to anoncred request proof
The Edge Agent should be able to respond to an anoncred proof-of-request

Scenario: Respond to request proof
Scenario: Respond to anoncred request proof
Given Cloud Agent is connected to Edge Agent
And Edge Agent has '1' anonymous credentials issued by Cloud Agent
When Cloud Agent asks for present-proof for anoncred
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
@proof @jwt
Feature: Respond to request proof
The Edge Agent should be able to respond to a proof-of-request

Scenario: Respond to request proof
Given Cloud Agent is connected to Edge Agent
And Edge Agent has 1 credentials issued by Cloud Agent
And Edge Agent has '1' credentials issued by Cloud Agent
When Cloud Agent asks for present-proof
And Edge Agent sends the present-proof
Then Cloud Agent should see the present-proof is verified

0 comments on commit 5a38513

Please sign in to comment.