Skip to content

Commit

Permalink
fix PR requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianIOHK committed Sep 22, 2023
1 parent a7abb20 commit a5b62eb
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import com.ionspin.kotlin.bignum.integer.Sign
import java.math.BigInteger

fun BigInteger.toUnsignedByteArray(): ByteArray {
return toByteArray().dropWhile { it == 0.toByte() }.toByteArray()
val comparedValue = 0.toByte()
return toByteArray().dropWhile { it == comparedValue }.toByteArray()
}

fun BigInteger.toKotlinBigInteger(): com.ionspin.kotlin.bignum.integer.BigInteger {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import io.iohk.atala.prism.apollo.utils.KMMECPoint
import io.iohk.atala.prism.apollo.utils.KMMECSecp256k1PublicKey
import io.iohk.atala.prism.apollo.utils.KMMEllipticCurve
import io.iohk.atala.prism.walletsdk.apollo.config.ECConfig
import io.iohk.atala.prism.walletsdk.apollo.utils.ec._ECPoint
import io.iohk.atala.prism.walletsdk.apollo.utils.ec.KMMECPoint
import io.iohk.atala.prism.walletsdk.domain.models.Curve
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.CurveKey
import io.iohk.atala.prism.walletsdk.domain.models.keyManagement.CustomKey
Expand Down Expand Up @@ -93,9 +93,9 @@ class Secp256k1PublicKey(nativeValue: ByteArray) : PublicKey(), VerifiableKey {
}

companion object {
fun computeCurvePoint(key: BCECPublicKey): _ECPoint {
fun computeCurvePoint(key: BCECPublicKey): io.iohk.atala.prism.walletsdk.apollo.utils.ec.KMMECPoint {
val javaPoint = key.w
return _ECPoint(javaPoint.affineX.toKotlinBigInteger(), javaPoint.affineY.toKotlinBigInteger())
return KMMECPoint(javaPoint.affineX.toKotlinBigInteger(), javaPoint.affineY.toKotlinBigInteger())
}

fun secp256k1FromCompressed(compressed: ByteArray): Secp256k1PublicKey {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package io.iohk.atala.prism.walletsdk.apollo.utils.ec
import com.ionspin.kotlin.bignum.integer.BigInteger
import io.iohk.atala.prism.walletsdk.apollo.helpers.padStart

class _ECCoordinate(val coordinate: BigInteger) {
class KMMECCoordinate(val coordinate: BigInteger) {

fun bytes(): ByteArray = coordinate.toByteArray().padStart(PRIVATE_KEY_BYTE_SIZE, 0)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.iohk.atala.prism.walletsdk.apollo.utils.ec

import com.ionspin.kotlin.bignum.integer.BigInteger

class KMMECPoint(val x: KMMECCoordinate, val y: KMMECCoordinate) {
constructor(x: String, y: String) : this(
KMMECCoordinate(BigInteger.parseString(x)),
KMMECCoordinate(BigInteger.parseString(y))
)

constructor(x: BigInteger, y: BigInteger) : this(
KMMECCoordinate(x),
KMMECCoordinate(y)
)
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
package io.iohk.atala.prism.walletsdk.domain.models.keyManagement

import io.iohk.atala.prism.walletsdk.domain.models.Curve

abstract class PrivateKey : Key() {

fun getCurve(): String {
return this.getProperty(CurveKey().property)
}

fun getCurveInstance(): Curve? {
return try {
Curve.valueOf(this.getProperty(CurveKey().property))
} catch (e: Exception) {
null
}
}

fun getIndex(): String {
return this.getProperty(IndexKey().property)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
package io.iohk.atala.prism.walletsdk.domain.models.keyManagement

import io.iohk.atala.prism.walletsdk.domain.models.Curve

abstract class PublicKey : Key() {

fun getCurve(): String {
return this.getProperty(CurveKey().property)
}

fun getCurveInstance(): Curve? {
return try {
Curve.valueOf(this.getProperty(CurveKey().property))
} catch (e: Exception) {
null
}
}

fun getValue(): ByteArray {
return this.raw
}
Expand Down

0 comments on commit a5b62eb

Please sign in to comment.