Skip to content

Commit

Permalink
feat: add publicKey to PrivateKeys (#96)
Browse files Browse the repository at this point in the history
Co-authored-by: Ahmed Moussa <[email protected]>
Signed-off-by: Cristian G <[email protected]>
  • Loading branch information
cristianIOHK and hamada147 committed May 20, 2024
1 parent 42d1d75 commit 305d64a
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ import org.bouncycastle.crypto.params.Ed25519PrivateKeyParameters
import org.bouncycastle.crypto.signers.Ed25519Signer

actual class KMMEdPrivateKey(val raw: ByteArray) {

fun publicKey(): KMMEdPublicKey {
val private = Ed25519PrivateKeyParameters(raw, 0)
val public = private.generatePublicKey()
return KMMEdPublicKey(public.encoded)
}

actual fun sign(message: ByteArray): ByteArray {
val privateKeyParameters = Ed25519PrivateKeyParameters(raw, 0)
val signer = Ed25519Signer()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
package io.iohk.atala.prism.apollo.utils

actual class KMMX25519PrivateKey(val raw: ByteArray)
import org.bouncycastle.crypto.params.X25519PrivateKeyParameters

actual class KMMX25519PrivateKey(val raw: ByteArray) {

fun publicKey(): KMMX25519PublicKey {
val private = X25519PrivateKeyParameters(raw, 0)
val public = private.generatePublicKey()
return KMMX25519PublicKey(public.encoded)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public actual class KMMEdPrivateKey(val raw: ByteArray) {
}

@Throws(RuntimeException::class)
public fun publicKey(): KMMEdPublicKey {
fun publicKey(): KMMEdPublicKey {
val result = Ed25519.publicKeyWithPrivateKey(raw.toNSData())
result.failure()?.let { throw RuntimeException(it.localizedDescription()) }
val publicRaw = result.success()?.toByteArray() ?: throw RuntimeException("Null result")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import java.io.ByteArrayInputStream

actual class KMMEdPrivateKey(val raw: ByteArray) {

fun publicKey(): KMMEdPublicKey {
val private = Ed25519PrivateKeyParameters(raw, 0)
val public = private.generatePublicKey()
return KMMEdPublicKey(public.encoded)
}

actual fun sign(message: ByteArray): ByteArray {
val privateKeyParameters = Ed25519PrivateKeyParameters(ByteArrayInputStream(raw))
val signer = Ed25519Signer()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
package io.iohk.atala.prism.apollo.utils

actual class KMMX25519PrivateKey(val raw: ByteArray)
import org.bouncycastle.crypto.params.X25519PrivateKeyParameters

actual class KMMX25519PrivateKey(val raw: ByteArray) {

fun publicKey(): KMMX25519PublicKey {
val private = X25519PrivateKeyParameters(raw, 0)
val public = private.generatePublicKey()
return KMMX25519PublicKey(public.encoded)
}
}

0 comments on commit 305d64a

Please sign in to comment.