-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ed25519): ios, macos implementation of ed25519
- Loading branch information
1 parent
dab7960
commit 53329fb
Showing
16 changed files
with
556 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...tric-encryption/src/commonMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdPrivateKey.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
2 changes: 1 addition & 1 deletion
2
...etric-encryption/src/commonMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdPublicKey.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 29 additions & 4 deletions
33
...mmetric-encryption/src/iosMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdPrivateKey.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
22 changes: 18 additions & 4 deletions
22
...ymmetric-encryption/src/iosMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdPublicKey.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.