Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Todor/revocation notification test #161

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ Pods/
dependinces.log
node_modules
megalinter-reports
tests/end-to-end/target
1 change: 1 addition & 0 deletions edge-agent-sdk/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ kotlin {
implementation("io.iohk.atala.prism.anoncredskmp:anoncreds-kmp:0.4.6")
implementation("com.ionspin.kotlin:bignum:0.3.9")
implementation("org.bouncycastle:bcprov-jdk15on:1.68")
implementation(kotlin("reflect"))
}
}
val commonTest by getting {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ class AnoncredsTests {
polluxMock = PolluxMock()
mediationHandlerMock = MediationHandlerMock()
// Pairing will be removed in the future
connectionManager =
ConnectionManager(mercuryMock, castorMock, plutoMock, mediationHandlerMock, mutableListOf(), polluxMock)
connectionManager = ConnectionManagerImpl(mercuryMock, castorMock, plutoMock, mediationHandlerMock, mutableListOf())
json = Json {
ignoreUnknownKeys = true
prettyPrint = true
Expand All @@ -73,7 +72,7 @@ class AnoncredsTests {
val pollux = PolluxImpl(castorMock, apiMock)
plutoMock.getLinkSecretReturn = flow { emit(LinkSecret().getValue()) }

val agent = PrismAgent(
val agent = EdgeAgent(
apollo = apolloMock,
castor = castorMock,
pluto = plutoMock,
Expand Down Expand Up @@ -137,7 +136,7 @@ class AnoncredsTests {
)
plutoMock.getCredentialMetadataReturn = flow { emit(meta) }

val agent = PrismAgent(
val agent = EdgeAgent(
apollo = apolloMock,
castor = castorMock,
pluto = plutoMock,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package org.hyperledger.identus.walletsdk.castor

import io.iohk.atala.prism.apollo.base64.base64UrlDecodedBytes
import io.iohk.atala.prism.apollo.utils.KMMECSecp256k1PublicKey
import io.ipfs.multibase.Multibase
import org.hyperledger.identus.walletsdk.apollo.utils.Ed25519PublicKey
import org.hyperledger.identus.walletsdk.apollo.utils.Secp256k1PublicKey
import org.hyperledger.identus.walletsdk.apollo.utils.X25519PublicKey
import org.hyperledger.identus.walletsdk.castor.resolvers.LongFormPrismDIDResolver
import org.hyperledger.identus.walletsdk.castor.resolvers.PeerDIDResolver
import org.hyperledger.identus.walletsdk.castor.shared.CastorShared
Expand All @@ -11,6 +15,7 @@ import org.hyperledger.identus.walletsdk.domain.models.CastorError
import org.hyperledger.identus.walletsdk.domain.models.Curve
import org.hyperledger.identus.walletsdk.domain.models.DID
import org.hyperledger.identus.walletsdk.domain.models.DIDDocument
import org.hyperledger.identus.walletsdk.domain.models.DIDDocumentCoreProperty
import org.hyperledger.identus.walletsdk.domain.models.DIDResolver
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.KeyPair
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.PublicKey
Expand All @@ -33,10 +38,14 @@ constructor(
private val logger: PrismLogger = PrismLoggerImpl(LogComponent.CASTOR)
) : Castor {
var resolvers: Array<DIDResolver> = arrayOf(
PeerDIDResolver(),
LongFormPrismDIDResolver(this.apollo)
LongFormPrismDIDResolver(this.apollo),
PeerDIDResolver()
)

fun addResolver(resolver: DIDResolver) {
resolvers = resolvers.plus(resolver)
}

/**
* Parses a string representation of a Decentralized Identifier (DID) into a DID object.
*
Expand Down Expand Up @@ -108,8 +117,15 @@ constructor(
)
)
)
val resolver = CastorShared.getDIDResolver(did, resolvers)
return resolver.resolve(did)
val resolvers = CastorShared.getDIDResolver(did, resolvers)
resolvers.forEach { resolver ->
try {
val resolved = resolver.resolve(did)
return resolved
} catch (_: CastorError) {
}
}
throw Exception("No resolver could resolve the provided DID.")
}

/**
Expand All @@ -131,10 +147,10 @@ constructor(
): Boolean {
val document = resolveDID(did.toString())
val publicKeys: List<PublicKey> =
CastorShared.getKeyPairFromCoreProperties(document.coreProperties)
getPublicKeysFromCoreProperties(document.coreProperties)

if (publicKeys.isEmpty()) {
throw CastorError.InvalidKeyError("KeyPairs is empty")
throw CastorError.InvalidKeyError("DID was resolved, but does not contain public keys in its core properties.")
}

for (publicKey in publicKeys) {
Expand All @@ -151,4 +167,75 @@ constructor(

return false
}

/**
* Extract list of [PublicKey] from a list of [DIDDocumentCoreProperty].
*
* @param coreProperties list of [DIDDocumentCoreProperty] that we are going to extract a list of [DIDDocumentCoreProperty].
* @return List<[PublicKey]>
*/
override fun getPublicKeysFromCoreProperties(coreProperties: Array<DIDDocumentCoreProperty>): List<PublicKey> {
return coreProperties
.filterIsInstance<DIDDocument.Authentication>()
.flatMap { it.verificationMethods.toList() }
.mapNotNull { verificationMethod ->
when {
verificationMethod.publicKeyJwk != null -> {
extractPublicKeyFromJwk(verificationMethod.publicKeyJwk)
}

verificationMethod.publicKeyMultibase != null -> {
extractPublicKeyFromMultibase(
verificationMethod.publicKeyMultibase,
verificationMethod.type
)
}

else -> null
}
}
}

private fun extractPublicKeyFromJwk(jwk: Map<String, String>): PublicKey? {
if (jwk.containsKey("x") && jwk.containsKey("crv")) {
val x = jwk["x"]
val crv = jwk["crv"]
return when (DIDDocument.VerificationMethod.getCurveByType(crv!!)) {
Curve.SECP256K1 -> {
if (jwk.containsKey("y")) {
val y = jwk["y"]
val kmmSecp = KMMECSecp256k1PublicKey.secp256k1FromByteCoordinates(x!!.base64UrlDecodedBytes, y!!.base64UrlDecodedBytes)
Secp256k1PublicKey(kmmSecp.raw)
} else {
Secp256k1PublicKey(x!!.base64UrlDecodedBytes)
}
}

Curve.ED25519 -> {
Ed25519PublicKey(x!!.base64UrlDecodedBytes)
}

Curve.X25519 -> {
X25519PublicKey(x!!.base64UrlDecodedBytes)
}
}
}
return null
}

private fun extractPublicKeyFromMultibase(publicKey: String, type: String): PublicKey {
return when (DIDDocument.VerificationMethod.getCurveByType(type)) {
Curve.SECP256K1 -> {
Secp256k1PublicKey(Multibase.decode(publicKey))
}

Curve.ED25519 -> {
Ed25519PublicKey(Multibase.decode(publicKey))
}

Curve.X25519 -> {
X25519PublicKey(Multibase.decode(publicKey))
}
}
}
}
Loading