Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(x25519): add x25519 implementation for ios, macos #80

Merged
merged 1 commit into from
Jul 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@ actual class KMMX25519KeyPair actual constructor(
actual val privateKey: KMMX25519PrivateKey,
actual val publicKey: KMMX25519PublicKey
) {
init {
throw NotImplementedError("X25519 is yet to be implemented in iOS")
}

actual companion object : X25519KeyPairGeneration {
override fun generateX25519KeyPair(): KMMX25519KeyPair {
throw NotImplementedError("X25519 is yet to be implemented in iOS")
val privateKey = KMMX25519PrivateKey()
return KMMX25519KeyPair(privateKey, privateKey.publicKey())
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,32 @@
package io.iohk.atala.prism.apollo.utils

import cocoapods.IOHKCryptoKit.X25519
import kotlinx.cinterop.ObjCObjectVar
import kotlinx.cinterop.alloc
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.ptr
import kotlinx.cinterop.value
import platform.Foundation.NSError

actual class KMMX25519PrivateKey {
init {
throw NotImplementedError("X25519 is yet to be implemented in iOS")
public val raw: ByteArray

constructor(raw: ByteArray) {
this.raw = raw
}

constructor() {
this.raw = X25519.createPrivateKey().toByteArray()
}

@Throws(RuntimeException::class)
public fun publicKey(): KMMX25519PublicKey {
memScoped {
val errorRef = alloc<ObjCObjectVar<NSError?>>()
val result = X25519.publicKeyWithPrivateKey(raw.toNSData(), errorRef.ptr)
errorRef.value?.let { throw RuntimeException(it.localizedDescription()) }
val publicRaw = result?.toByteArray() ?: throw RuntimeException("Null result")
return KMMX25519PublicKey(publicRaw)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.iohk.atala.prism.apollo.utils

actual class KMMX25519PublicKey {
init {
throw NotImplementedError("X25519 is yet to be implemented in iOS")
public val raw: ByteArray

constructor(raw: ByteArray) {
this.raw = raw
}
}