-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Bassam Riman <[email protected]>
- Loading branch information
1 parent
ebf0328
commit 81c8390
Showing
8 changed files
with
416 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file renamed
BIN
+3.54 MB
.../lib/anoncreds/UniffiPOC-1.0-SNAPSHOT.jar → ...anoncreds/anoncreds-java-1.0-SNAPSHOT.jar
Binary file not shown.
Binary file added
BIN
+6.52 MB
pollux/lib/anoncreds/native-lib/NATIVE/darwin-aarch64/libuniffi_anoncreds.dylib
Binary file not shown.
Binary file modified
BIN
+50.2 KB
(100%)
pollux/lib/anoncreds/native-lib/NATIVE/linux/amd64/libuniffi_anoncreds.so
Binary file not shown.
119 changes: 119 additions & 0 deletions
119
pollux/lib/anoncreds/src/main/scala/io/iohk/atala/pollux/anoncreds/AnoncredLib.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package io.iohk.atala.pollux.anoncreds | ||
|
||
import uniffi.anoncreds | ||
|
||
import scala.jdk.CollectionConverters.* | ||
import scala.language.implicitConversions | ||
|
||
/** @see | ||
* https://hyperledger.github.io/anoncreds-spec/ | ||
*/ | ||
object AnoncredLib { | ||
|
||
val SCHEMA_ID = "mock:uri2" | ||
val CRED_DEF_ID = "mock:uri2" | ||
val ISSUER_DID = "mock:issuer_id/path&q=bar" | ||
|
||
// issuer or any | ||
def createSchema( | ||
name: String, // SCHEMA_ID | ||
version: String, // SCHEMA_Version | ||
attr_names: AttributeNames, | ||
issuer_id: IssuerId, // ISSUER_DID | ||
): SchemaDef = anoncreds.Schema.apply(name, version, attr_names.toSeq.asJava, issuer_id) | ||
|
||
// issuer | ||
def createCredDefinition( | ||
issuer_id: String, | ||
schema: SchemaDef, | ||
tag: String, | ||
supportRevocation: Boolean, | ||
signature_type: anoncreds.SignatureType.CL.type = anoncreds.SignatureType.CL | ||
) = { | ||
val credentialDefinition: anoncreds.IssuerCreateCredentialDefinitionReturn = | ||
anoncreds | ||
.Issuer() | ||
.createCredentialDefinition( | ||
schema.name, | ||
schema: anoncreds.Schema, | ||
issuer_id, | ||
tag, | ||
signature_type, | ||
anoncreds.CredentialDefinitionConfig(supportRevocation) | ||
) | ||
|
||
CreateCredentialDefinition( | ||
credentialDefinition.getCredentialDefinition(), | ||
credentialDefinition.getCredentialDefinitionPrivate(), | ||
credentialDefinition.getCredentialKeyCorrectnessProof() | ||
) | ||
} | ||
|
||
// issuer | ||
def createOffer( | ||
credentialDefinition: CreateCredentialDefinition, | ||
credentialDefinitionId: String | ||
): CredentialOffer = | ||
anoncreds | ||
.Issuer() | ||
.createCredentialOffer( | ||
credentialDefinition.cd.schemaId, // string schema_id, | ||
credentialDefinitionId, // string cred_def_id, | ||
credentialDefinition.proofKey // CredentialKeyCorrectnessProof correctness_proof | ||
) | ||
|
||
// holder | ||
def createCredentialRequest( | ||
linkSecret: LinkSecretWithId, | ||
credentialDefinition: CredentialDefinition, | ||
credentialOffer: CredentialOffer, | ||
entropy: String = { | ||
val tmp = scala.util.Random() | ||
tmp.setSeed(java.security.SecureRandom.getInstanceStrong().nextLong()) | ||
tmp.nextString(80) | ||
} | ||
): CreateCrendentialRequest = { | ||
val credentialRequest = | ||
anoncreds | ||
.Prover() | ||
.createCredentialRequest( | ||
entropy, // string? entropy, | ||
null, // string? prover_did, | ||
credentialDefinition, // CredentialDefinition cred_def, | ||
linkSecret.secret, // LinkSecret link_secret, | ||
linkSecret.id, // string link_secret_id, | ||
credentialOffer, // CredentialOffer credential_offer | ||
) | ||
|
||
CreateCrendentialRequest(credentialRequest.getRequest(), credentialRequest.getMetadata()) | ||
} | ||
|
||
// issuer | ||
def createCredential( | ||
credentialDefinition: CredentialDefinition, | ||
credentialDefinitionPrivate: CredentialDefinitionPrivate, | ||
credentialOffer: CredentialOffer, | ||
credentialRequest: CredentialRequest, | ||
attributeValues: Seq[(String, String)] | ||
// java.util.List[AttributeValues] : java.util.List[AttributeValues] | ||
// revocationRegistryId : String | ||
// revocationStatusList : RevocationStatusList | ||
// credentialRevocationConfig : CredentialRevocationConfig | ||
): Credential = { | ||
|
||
anoncreds | ||
.Issuer() | ||
.createCredential( | ||
credentialDefinition, // CredentialDefinition cred_def, | ||
credentialDefinitionPrivate, // CredentialDefinitionPrivate cred_def_private, | ||
credentialOffer, // CredentialOffer cred_offer, | ||
credentialRequest, // CredentialRequest cred_request, | ||
attributeValues | ||
.map(e => anoncreds.AttributeValues(e._1, e._2)) | ||
.asJava, // sequence<AttributeValues> cred_values, | ||
null, // RevocationRegistryId? rev_reg_id, | ||
null, // RevocationStatusList? rev_status_list, | ||
null, // CredentialRevocationConfig? revocation_config | ||
) | ||
} | ||
} |
Oops, something went wrong.