Skip to content

Commit

Permalink
refactor: use the new method implemented in rust
Browse files Browse the repository at this point in the history
Signed-off-by: Ahmed Moussa <[email protected]>
  • Loading branch information
hamada147 committed Jan 2, 2024
1 parent e8976ea commit 2179c77
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
2 changes: 1 addition & 1 deletion atala-prism-sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ kotlin {

api("org.lighthousegames:logging:1.1.2")

implementation("io.iohk.atala.prism.anoncredskmp:anoncreds-kmp:0.3.4")
implementation("io.iohk.atala.prism.anoncredskmp:anoncreds-kmp:0.4.1")
implementation("com.ionspin.kotlin:bignum:0.3.8")
implementation("org.bouncycastle:bcprov-jdk15on:1.68")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import anoncreds_wrapper.Presentation
import anoncreds_wrapper.PresentationRequest
import anoncreds_wrapper.Prover
import anoncreds_wrapper.RequestedAttribute
import anoncreds_wrapper.RequestedPredicate
import anoncreds_wrapper.Schema
import anoncreds_wrapper.SchemaId
import com.nimbusds.jose.JWSAlgorithm
Expand Down Expand Up @@ -218,6 +219,32 @@ class PolluxImpl(
)
}

/**
* Converts the map of [anoncreds_wrapper.AttributeInfoValue] values to a list of [RequestedAttribute].
*
* @return The list of [RequestedAttribute].
*/
private fun Map<String, anoncreds_wrapper.AttributeInfoValue>.toListRequestedAttribute(): List<RequestedAttribute> {
return this.values.toList().map {
RequestedAttribute(
referent = it.getName(),
revealed = true
)
}
}

/**
* Converts the map of [anoncreds_wrapper.PredicateInfoValue] values to a list of [RequestedPredicate].
*
* @receiver The map of [anoncreds_wrapper.PredicateInfoValue] values.
* @return The list of [RequestedPredicate].
*/
private fun Map<String, anoncreds_wrapper.PredicateInfoValue>.toListRequestedPredicate(): List<RequestedPredicate> {
return this.values.toList().map {
RequestedPredicate(it.getName())
}
}

override suspend fun createVerifiablePresentationAnoncred(
request: RequestPresentation,
credential: AnonCredential,
Expand All @@ -231,19 +258,11 @@ class PolluxImpl(
val presentationRequest = PresentationRequest(attachmentBase64.base64.base64UrlDecoded)
val cred = anoncreds_wrapper.Credential(credential.id)

// TODO: Replace this piece of code with the new expose methods Ahmed provided on the newer version of anoncreds wrapper.
val jsonElement = Json.parseToJsonElement(attachmentBase64.base64.base64UrlDecoded)
val attributes = (jsonElement as JsonObject)["requested_attributes"]
val attr = (attributes as JsonObject)["attribute_1"] as JsonObject
val name = attr["name"]?.jsonPrimitive?.content ?: throw Exception("")
val requestedAttributes = presentationRequest.getRequestedAttributes().toListRequestedAttribute()
val requestedPredicate = presentationRequest.getRequestedPredicates().toListRequestedPredicate()

val requestedAttributes = listOf(
RequestedAttribute(
referent = "attribute_1",
revealed = true
)
)
// TODO: Until here
// TODO: which to put in the [CredentialRequests], requestedAttributes or requestedPredicate
// TODO: What is the logic to send one of them or the both of them

val credentialRequests = CredentialRequests(
credential = cred,
Expand Down
7 changes: 0 additions & 7 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,6 @@ allprojects {
this.password = System.getenv("ATALA_GITHUB_TOKEN")
}
}
maven {
this.url = uri("https://github.com/input-output-hk/anoncreds-rs/")
credentials {
this.username = System.getenv("ATALA_GITHUB_ACTOR")
this.password = System.getenv("ATALA_GITHUB_TOKEN")
}
}
}

configurations.all {
Expand Down

0 comments on commit 2179c77

Please sign in to comment.