Skip to content

Commit

Permalink
fix: fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
elribonazo committed Nov 5, 2024
1 parent 553247c commit 052a206
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,11 @@ import org.hyperledger.identus.walletsdk.domain.models.keyManagement.PublicKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.RawKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.SeedKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.StorableKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.StorablePrivateKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.TypeKey
import org.hyperledger.identus.walletsdk.logger.LogComponent
import org.hyperledger.identus.walletsdk.logger.LogLevel
import org.hyperledger.identus.walletsdk.logger.Logger
import org.hyperledger.identus.walletsdk.logger.LoggerImpl
import pbandk.ByteArr

/**
* Apollo defines the set of cryptographic operations that are used in the Atala PRISM.
Expand Down Expand Up @@ -299,8 +297,8 @@ class ApolloImpl(
if (curvePointX != null && curvePointY != null) {
// Compressed key
val nativePublicKey = KMMECSecp256k1PublicKey.secp256k1FromByteCoordinates(
x = (curvePointX as ByteArr).array,
y = (curvePointY as ByteArr).array
x = (curvePointX as String).base64UrlDecodedBytes,
y = (curvePointY as String).base64UrlDecodedBytes
)
return Secp256k1PublicKey(nativePublicKey.raw)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ constructor(
try {
val resolved = resolver.resolve(did)
return resolved
} catch (_: CastorError) {
} catch (err: CastorError) {
println(err.message)
}
}
throw Exception("No resolver could resolve the provided DID.")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.hyperledger.identus.walletsdk.castor.did.prismdid

import org.hyperledger.identus.apollo.base64.base64DecodedBytes
import org.hyperledger.identus.apollo.base64.base64Encoded
import org.hyperledger.identus.apollo.base64.base64UrlDecodedBytes
import org.hyperledger.identus.apollo.base64.base64UrlEncoded
import org.hyperledger.identus.protos.CompressedECKeyData
import org.hyperledger.identus.protos.ECKeyData
import org.hyperledger.identus.protos.KeyUsage
Expand Down Expand Up @@ -79,8 +81,8 @@ class PrismDIDPublicKey {
properties = mapOf(
TypeKey().property to KeyTypes.EC,
CurveKey().property to ecKeyData.curve,
CurvePointXKey().property to ecKeyData.x,
CurvePointYKey().property to ecKeyData.y
CurvePointXKey().property to ecKeyData.x.array.base64UrlEncoded,
CurvePointYKey().property to ecKeyData.y.array.base64UrlEncoded
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ open class EdgeAgent {

ed25519PrivateKeyProperties[TypeKey().property] = KeyTypes.EC
ed25519PrivateKeyProperties[SeedKey().property] = seed.value.base64UrlEncoded
ed25519PrivateKeyProperties[CurveKey().property] = Curve.SECP256K1.value
ed25519PrivateKeyProperties[IndexKey().property] = index
ed25519PrivateKeyProperties[CurveKey().property] = Curve.ED25519.value
ed25519PrivateKeyProperties[IndexKey().property] = index+1

val masterKey = this.apollo.createPrivateKey(
secp256k1PrivateKeyProperties
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package org.hyperledger.identus.walletsdk.edgeagent

import io.iohk.atala.prism.didcomm.didpeer.base64.base64UrlDecoded
import io.iohk.atala.prism.didcomm.didpeer.base64.base64UrlDecodedBytes
import org.bouncycastle.util.encoders.Hex
import org.hyperledger.identus.walletsdk.apollo.utils.Ed25519KeyPair
import org.hyperledger.identus.walletsdk.apollo.utils.Ed25519PrivateKey
import org.hyperledger.identus.walletsdk.apollo.utils.Ed25519PublicKey
import org.hyperledger.identus.walletsdk.apollo.utils.Secp256k1PrivateKey
import org.hyperledger.identus.walletsdk.domain.buildingblocks.Apollo
import org.hyperledger.identus.walletsdk.domain.models.Curve
import org.hyperledger.identus.walletsdk.domain.models.Seed
import org.hyperledger.identus.walletsdk.domain.models.SeedWords
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.JWK
Expand All @@ -15,6 +19,8 @@ import org.hyperledger.identus.walletsdk.domain.models.keyManagement.PublicKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.StorableKey

class ApolloMock : Apollo {
val validRawBase64UrlSecp256k1Sk = Hex.decode("67E56582298859DDAE725F972992A07C6C4FB9F62A8FFF58CE3CA926A1063530".lowercase())
val validRawBase64UrlEd25519Sk = "JLIJQ5jlkyqtGmtOth6yggJLLC0zuRhUPiBhd1-rGPs".base64UrlDecodedBytes
var createRandomMnemonicsReturn: Array<String> = emptyArray()
var createSeedReturn: Seed = Seed(ByteArray(0))
var createRandomSeedReturn: SeedWords = SeedWords(emptyArray(), Seed(ByteArray(0)))
Expand All @@ -35,7 +41,13 @@ class ApolloMock : Apollo {
}

override fun createPrivateKey(properties: Map<String, Any>): PrivateKey {
return createPrivateKey ?: Secp256k1PrivateKey(ByteArray(0))
val curve = properties["curve"];
if (curve === Curve.SECP256K1.value) {
return Secp256k1PrivateKey(validRawBase64UrlSecp256k1Sk)
} else if (curve === Curve.ED25519.value) {
return Ed25519PrivateKey(validRawBase64UrlEd25519Sk)
}
TODO("Not yet implemented")
}

override fun createPublicKey(properties: Map<String, Any>): PublicKey {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ class EdgeAgentTests {
val apollo = ApolloImpl()
val castor = CastorImpl(apollo)
val agent = EdgeAgent(
apollo = apollo,
apollo = apolloMockOld,
castor = castor,
pluto = plutoMockOld,
mercury = mercuryMockOld,
Expand Down

0 comments on commit 052a206

Please sign in to comment.