Skip to content

Commit

Permalink
feature: add publicKey to PrivateKeys (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianIOHK authored Sep 27, 2023
1 parent 21c33e4 commit 5acd175
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 5acd175

Please sign in to comment.