Skip to content

Commit 7d0a5c9

Browse files
fix: wrong casting KeyPair instead of PublicKey (#139)
Co-authored-by: Ahmed Moussa <[email protected]> Signed-off-by: Cristian G <[email protected]>
1 parent 8df3557 commit 7d0a5c9

File tree

1 file changed

+18
-12
lines changed
  • atala-prism-sdk/src/commonMain/kotlin/io/iohk/atala/prism/walletsdk/castor

1 file changed

+18
-12
lines changed

Diff for: atala-prism-sdk/src/commonMain/kotlin/io/iohk/atala/prism/walletsdk/castor/CastorImpl.kt

+18-12
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
package io.iohk.atala.prism.walletsdk.castor
22

3-
import io.iohk.atala.prism.walletsdk.apollo.utils.Ed25519KeyPair
43
import io.iohk.atala.prism.walletsdk.apollo.utils.Ed25519PublicKey
5-
import io.iohk.atala.prism.walletsdk.apollo.utils.Secp256k1KeyPair
64
import io.iohk.atala.prism.walletsdk.apollo.utils.Secp256k1PublicKey
75
import io.iohk.atala.prism.walletsdk.castor.resolvers.LongFormPrismDIDResolver
86
import io.iohk.atala.prism.walletsdk.castor.resolvers.PeerDIDResolver
@@ -102,7 +100,13 @@ constructor(
102100
override suspend fun resolveDID(did: String): DIDDocument {
103101
logger.debug(
104102
message = "Trying to resolve DID",
105-
metadata = arrayOf(Metadata.MaskedMetadataByLevel(key = "DID", value = did, level = LogLevel.DEBUG))
103+
metadata = arrayOf(
104+
Metadata.MaskedMetadataByLevel(
105+
key = "DID",
106+
value = did,
107+
level = LogLevel.DEBUG
108+
)
109+
)
106110
)
107111
val resolver = CastorShared.getDIDResolver(did, resolvers)
108112
return resolver.resolve(did)
@@ -120,25 +124,27 @@ constructor(
120124
* @throws [CastorError.InvalidKeyError] if the DID or signature data are invalid.
121125
*/
122126
@Throws(CastorError.InvalidKeyError::class)
123-
override suspend fun verifySignature(did: DID, challenge: ByteArray, signature: ByteArray): Boolean {
127+
override suspend fun verifySignature(
128+
did: DID,
129+
challenge: ByteArray,
130+
signature: ByteArray
131+
): Boolean {
124132
val document = resolveDID(did.toString())
125-
val keyPairs: List<PublicKey> =
133+
val publicKeys: List<PublicKey> =
126134
CastorShared.getKeyPairFromCoreProperties(document.coreProperties)
127135

128-
if (keyPairs.isEmpty()) {
136+
if (publicKeys.isEmpty()) {
129137
throw CastorError.InvalidKeyError("KeyPairs is empty")
130138
}
131139

132-
for (keyPair in keyPairs) {
133-
when (keyPair.getCurve()) {
140+
for (publicKey in publicKeys) {
141+
when (publicKey.getCurve()) {
134142
Curve.SECP256K1.value -> {
135-
val secp = keyPair as Secp256k1KeyPair
136-
return (secp.publicKey as Secp256k1PublicKey).verify(challenge, signature)
143+
return (publicKey as Secp256k1PublicKey).verify(challenge, signature)
137144
}
138145

139146
Curve.ED25519.value -> {
140-
val ed = keyPair as Ed25519KeyPair
141-
return (ed.publicKey as Ed25519PublicKey).verify(challenge, signature)
147+
return (publicKey as Ed25519PublicKey).verify(challenge, signature)
142148
}
143149
}
144150
}

0 commit comments

Comments
 (0)