-
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
9121f60
commit d5a0484
Showing
14 changed files
with
566 additions
and
13 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
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
40 changes: 37 additions & 3 deletions
40
...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,42 @@ | ||
package io.iohk.atala.prism.apollo.utils | ||
|
||
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 | ||
|
||
actual class KMMEdPrivateKey { | ||
init { | ||
// TODO: To be investigated | ||
throw NotImplementedError("Ed25519 is yet to be implemented in iOS") | ||
public val raw: ByteArray | ||
|
||
constructor(raw: ByteArray) { | ||
this.raw = raw | ||
} | ||
|
||
constructor() { | ||
this.raw = 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) | ||
} | ||
} | ||
} |
25 changes: 22 additions & 3 deletions
25
...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,27 @@ | ||
package io.iohk.atala.prism.apollo.utils | ||
|
||
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 | ||
|
||
actual class KMMEdPublicKey { | ||
init { | ||
// TODO: To be investigated | ||
throw NotImplementedError("Ed25519 is yet to be implemented in iOS") | ||
public val raw: ByteArray | ||
|
||
constructor(raw: ByteArray) { | ||
this.raw = raw | ||
} | ||
|
||
@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.