Skip to content

Commit

Permalink
feat(ed25519): ios, macos implementation of ed25519
Browse files Browse the repository at this point in the history
  • Loading branch information
goncalo-frade-iohk committed Jul 14, 2023
1 parent 9121f60 commit 0fc6ef8
Show file tree
Hide file tree
Showing 16 changed files with 556 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
APPLY_FIXES_MODE: commit
VALIDATE_ALL_CODEBASE: ${{ github.ref_name == 'main' }}
DISABLE: COPYPASTE,SPELL
DISABLE_LINTERS: REPOSITORY_CHECKOV,REPOSITORY_GITLEAKS,BASH_SHELLCHECK,
DISABLE_LINTERS: REPOSITORY_CHECKOV,REPOSITORY_GITLEAKS,BASH_SHELLCHECK,MARKDOWN_MARKDOWN_LINK_CHECK,C_CPPLINT,CPP_CPPLINT,BASH_EXEC
GITHUB_TOKEN: ${{ secrets.ATALA_GITHUB_TOKEN }}
steps:
- name: Checkout Code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Pod::Spec.new do |spec|
spec.osx.deployment_target = '12.0'
spec.tvos.deployment_target = '13.0'
spec.watchos.deployment_target = '8.0'
spec.dependency 'IOHKCryptoKit', '1.0.0'
spec.dependency 'IOHKRSA', '1.0.0'
spec.dependency 'IOHKSecureRandomGeneration', '1.0.0'

Expand Down
5 changes: 5 additions & 0 deletions base-asymmetric-encryption/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ kotlin {
packageName = "IOHKSecureRandomGeneration1"
source = path(project.file("../iOSLibs/IOHKSecureRandomGeneration"))
}

pod("IOHKCryptoKit") {
version = "1.0.0"
source = path(project.file("../iOSLibs/IOHKCryptoKit"))
}
}
}

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

expect class KMMEdPrivateKey
public expect class KMMEdPrivateKey
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package io.iohk.atala.prism.apollo.utils

expect class KMMEdPublicKey
public expect class KMMEdPublicKey
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ actual class KMMEdKeyPair actual constructor(
actual val privateKey: KMMEdPrivateKey,
actual val publicKey: KMMEdPublicKey
) {
init {
// TODO: To be investigated
throw NotImplementedError("Ed25519 is yet to be implemented in iOS")
}

actual companion object : Ed25519KeyPairGeneration {
override fun generateEd25519KeyPair(): KMMEdKeyPair {
// TODO: To be investigated
throw NotImplementedError("Ed25519 is yet to be implemented in iOS")
val privateKey = KMMEdPrivateKey()
return KMMEdKeyPair(privateKey, privateKey.publicKey())
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
package io.iohk.atala.prism.apollo.utils

actual class KMMEdPrivateKey {
init {
// TODO: To be investigated
throw NotImplementedError("Ed25519 is yet to be implemented in iOS")
import cocoapods.IOHKCryptoKit.Ed25519
import kotlinx.cinterop.ObjCObjectVar
import kotlinx.cinterop.alloc
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.ptr
import kotlinx.cinterop.value
import platform.Foundation.NSError

public actual class KMMEdPrivateKey(val raw: ByteArray = Ed25519.createPrivateKey().toByteArray()) {

@Throws(RuntimeException::class)
public fun sign(data: ByteArray): ByteArray {
memScoped {
val errorRef = alloc<ObjCObjectVar<NSError?>>()
val result = Ed25519.signWithPrivateKey(raw.toNSData(), data.toNSData(), errorRef.ptr)
errorRef.value?.let { throw RuntimeException(it.localizedDescription()) }
return result?.toByteArray() ?: throw RuntimeException("Null result")
}
}

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

actual class KMMEdPublicKey {
init {
// TODO: To be investigated
throw NotImplementedError("Ed25519 is yet to be implemented in iOS")
import cocoapods.IOHKCryptoKit.Ed25519
import kotlinx.cinterop.ObjCObjectVar
import kotlinx.cinterop.alloc
import kotlinx.cinterop.memScoped
import kotlinx.cinterop.ptr
import kotlinx.cinterop.value
import platform.Foundation.NSError

public actual class KMMEdPublicKey(val raw: ByteArray) {

@Throws(RuntimeException::class)
public fun verify(data: ByteArray, sig: ByteArray): Boolean {
memScoped {
val errorRef = alloc<ObjCObjectVar<NSError?>>()
val result = Ed25519.verifyWithPublicKey(raw.toNSData(), sig.toNSData(), data.toNSData(), errorRef.ptr)
errorRef.value?.let { throw RuntimeException(it.localizedDescription()) }
return result?.boolValue ?: throw RuntimeException("Null result")
}
}
}
36 changes: 36 additions & 0 deletions iOSLibs/IOHKCryptoKit/IOHKCryptoKit.podspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#
# Be sure to run `pod lib lint IOHKSecureRandomGeneration.podspec' to ensure this is a
# valid spec before submitting.
#
# Any lines starting with a # are optional, but their use is encouraged
# To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html
#

Pod::Spec.new do |s|
s.name = 'IOHKCryptoKit'
s.version = '1.0.0'
s.summary = 'IOHKCryptoKit contains Ed25519, X25519 CryptoKit functionalities.'

# This description is used to generate tags and improve search results.
# * Think: What does it do? Why did you write it? What is the focus?
# * Try to keep it short, snappy and to the point.
# * Write the description between the DESC delimiters below.
# * Finally, don't worry about the indent, CocoaPods strips it!

s.description = <<-DESC
IOHKCryptoKit contains Ed25519, X25519 CryptoKit functionalities.
DESC

s.homepage = 'https://github.com/input-output-hk/atala-prism-apollo'
s.author = { 'Gonçalo Frade' => '[email protected]' }
s.source = { :git => 'https://github.com/input-output-hk/atala-prism-apollo.git', :tag => s.version.to_s }
s.swift_version = '5.7'
s.cocoapods_version = '>= 1.10.0'

s.ios.deployment_target = '13.0'
s.osx.deployment_target = '12.0'
s.tvos.deployment_target = '13.0'
s.watchos.deployment_target = '8.0'

s.source_files = 'IOHKCryptoKit/**/*.swift'
end
Loading

0 comments on commit 0fc6ef8

Please sign in to comment.