From 2cbaf066e9a0ea6a43bed5c48a89b204d8bb5b72 Mon Sep 17 00:00:00 2001 From: goncalo-frade-iohk Date: Thu, 13 Jul 2023 13:58:14 +0100 Subject: [PATCH] feat(ed25519): ios, macos implementation of ed25519 --- .../base_asymmetric_encryption.podspec | 1 + base-asymmetric-encryption/build.gradle.kts | 5 + .../prism/apollo/utils/KMMEdPrivateKey.kt | 2 +- .../prism/apollo/utils/KMMEdPublicKey.kt | 2 +- .../atala/prism/apollo/utils/KMMEdKeyPair.kt | 8 +- .../prism/apollo/utils/KMMEdPrivateKey.kt | 33 +- .../prism/apollo/utils/KMMEdPublicKey.kt | 22 +- iOSLibs/IOHKCryptoKit/IOHKCryptoKit.podspec | 36 ++ .../IOHKCryptoKit.xcodeproj/project.pbxproj | 371 ++++++++++++++++++ .../contents.xcworkspacedata | 7 + .../xcshareddata/IDEWorkspaceChecks.plist | 8 + .../IOHKCryptoKit/IOHKCryptoKit/Ed25519.swift | 24 ++ .../IOHKCryptoKit/IOHKCryptoKit.h | 18 + .../IOHKCryptoKit/IOHKCryptoKit/X25519.swift | 13 + iOSLibs/IOHKCryptoKit/LICENSE | 21 + 15 files changed, 555 insertions(+), 16 deletions(-) create mode 100644 iOSLibs/IOHKCryptoKit/IOHKCryptoKit.podspec create mode 100644 iOSLibs/IOHKCryptoKit/IOHKCryptoKit.xcodeproj/project.pbxproj create mode 100644 iOSLibs/IOHKCryptoKit/IOHKCryptoKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata create mode 100644 iOSLibs/IOHKCryptoKit/IOHKCryptoKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 iOSLibs/IOHKCryptoKit/IOHKCryptoKit/Ed25519.swift create mode 100644 iOSLibs/IOHKCryptoKit/IOHKCryptoKit/IOHKCryptoKit.h create mode 100644 iOSLibs/IOHKCryptoKit/IOHKCryptoKit/X25519.swift create mode 100644 iOSLibs/IOHKCryptoKit/LICENSE diff --git a/base-asymmetric-encryption/base_asymmetric_encryption.podspec b/base-asymmetric-encryption/base_asymmetric_encryption.podspec index 87fa239ac..e51505307 100644 --- a/base-asymmetric-encryption/base_asymmetric_encryption.podspec +++ b/base-asymmetric-encryption/base_asymmetric_encryption.podspec @@ -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' diff --git a/base-asymmetric-encryption/build.gradle.kts b/base-asymmetric-encryption/build.gradle.kts index f8b1221c8..0caae60ae 100644 --- a/base-asymmetric-encryption/build.gradle.kts +++ b/base-asymmetric-encryption/build.gradle.kts @@ -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")) + } } } diff --git a/base-asymmetric-encryption/src/commonMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdPrivateKey.kt b/base-asymmetric-encryption/src/commonMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdPrivateKey.kt index 461865cbe..8f0923e17 100644 --- a/base-asymmetric-encryption/src/commonMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdPrivateKey.kt +++ b/base-asymmetric-encryption/src/commonMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdPrivateKey.kt @@ -1,3 +1,3 @@ package io.iohk.atala.prism.apollo.utils -expect class KMMEdPrivateKey +public expect class KMMEdPrivateKey diff --git a/base-asymmetric-encryption/src/commonMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdPublicKey.kt b/base-asymmetric-encryption/src/commonMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdPublicKey.kt index 38d62162f..3f61406a8 100644 --- a/base-asymmetric-encryption/src/commonMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdPublicKey.kt +++ b/base-asymmetric-encryption/src/commonMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdPublicKey.kt @@ -1,3 +1,3 @@ package io.iohk.atala.prism.apollo.utils -expect class KMMEdPublicKey +public expect class KMMEdPublicKey diff --git a/base-asymmetric-encryption/src/iosMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdKeyPair.kt b/base-asymmetric-encryption/src/iosMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdKeyPair.kt index 63dbbefc1..dab463473 100644 --- a/base-asymmetric-encryption/src/iosMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdKeyPair.kt +++ b/base-asymmetric-encryption/src/iosMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdKeyPair.kt @@ -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()) } } } diff --git a/base-asymmetric-encryption/src/iosMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdPrivateKey.kt b/base-asymmetric-encryption/src/iosMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdPrivateKey.kt index 6f9ded6ff..3181a6f23 100644 --- a/base-asymmetric-encryption/src/iosMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdPrivateKey.kt +++ b/base-asymmetric-encryption/src/iosMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdPrivateKey.kt @@ -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>() + 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>() + 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) + } } } diff --git a/base-asymmetric-encryption/src/iosMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdPublicKey.kt b/base-asymmetric-encryption/src/iosMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdPublicKey.kt index f427a7c9d..d47febb59 100644 --- a/base-asymmetric-encryption/src/iosMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdPublicKey.kt +++ b/base-asymmetric-encryption/src/iosMain/kotlin/io/iohk/atala/prism/apollo/utils/KMMEdPublicKey.kt @@ -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>() + 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") + } } } diff --git a/iOSLibs/IOHKCryptoKit/IOHKCryptoKit.podspec b/iOSLibs/IOHKCryptoKit/IOHKCryptoKit.podspec new file mode 100644 index 000000000..cc19c6c26 --- /dev/null +++ b/iOSLibs/IOHKCryptoKit/IOHKCryptoKit.podspec @@ -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' => 'goncalo.frade@iohk.io' } + 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 diff --git a/iOSLibs/IOHKCryptoKit/IOHKCryptoKit.xcodeproj/project.pbxproj b/iOSLibs/IOHKCryptoKit/IOHKCryptoKit.xcodeproj/project.pbxproj new file mode 100644 index 000000000..8744b1e6c --- /dev/null +++ b/iOSLibs/IOHKCryptoKit/IOHKCryptoKit.xcodeproj/project.pbxproj @@ -0,0 +1,371 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { + +/* Begin PBXBuildFile section */ + EE2C944B2A5B530B0021E9B6 /* IOHKCryptoKit.h in Headers */ = {isa = PBXBuildFile; fileRef = EE2C944A2A5B530B0021E9B6 /* IOHKCryptoKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; + EE2C94522A5B539E0021E9B6 /* Ed25519.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE2C94512A5B539E0021E9B6 /* Ed25519.swift */; }; + EE2C94542A5B57580021E9B6 /* X25519.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE2C94532A5B57580021E9B6 /* X25519.swift */; }; + EE2C94562A5B5A4E0021E9B6 /* IOHKCryptoKit.podspec in Resources */ = {isa = PBXBuildFile; fileRef = EE2C94552A5B5A4E0021E9B6 /* IOHKCryptoKit.podspec */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + EE2C94472A5B530B0021E9B6 /* IOHKCryptoKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = IOHKCryptoKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + EE2C944A2A5B530B0021E9B6 /* IOHKCryptoKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IOHKCryptoKit.h; sourceTree = ""; }; + EE2C94512A5B539E0021E9B6 /* Ed25519.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Ed25519.swift; sourceTree = ""; }; + EE2C94532A5B57580021E9B6 /* X25519.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = X25519.swift; sourceTree = ""; }; + EE2C94552A5B5A4E0021E9B6 /* IOHKCryptoKit.podspec */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; fileEncoding = 4; path = IOHKCryptoKit.podspec; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + EE2C94442A5B530B0021E9B6 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + EE2C943D2A5B530B0021E9B6 = { + isa = PBXGroup; + children = ( + EE2C94552A5B5A4E0021E9B6 /* IOHKCryptoKit.podspec */, + EE2C94492A5B530B0021E9B6 /* IOHKCryptoKit */, + EE2C94482A5B530B0021E9B6 /* Products */, + ); + sourceTree = ""; + }; + EE2C94482A5B530B0021E9B6 /* Products */ = { + isa = PBXGroup; + children = ( + EE2C94472A5B530B0021E9B6 /* IOHKCryptoKit.framework */, + ); + name = Products; + sourceTree = ""; + }; + EE2C94492A5B530B0021E9B6 /* IOHKCryptoKit */ = { + isa = PBXGroup; + children = ( + EE2C944A2A5B530B0021E9B6 /* IOHKCryptoKit.h */, + EE2C94512A5B539E0021E9B6 /* Ed25519.swift */, + EE2C94532A5B57580021E9B6 /* X25519.swift */, + ); + path = IOHKCryptoKit; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXHeadersBuildPhase section */ + EE2C94422A5B530B0021E9B6 /* Headers */ = { + isa = PBXHeadersBuildPhase; + buildActionMask = 2147483647; + files = ( + EE2C944B2A5B530B0021E9B6 /* IOHKCryptoKit.h in Headers */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXHeadersBuildPhase section */ + +/* Begin PBXNativeTarget section */ + EE2C94462A5B530B0021E9B6 /* IOHKCryptoKit */ = { + isa = PBXNativeTarget; + buildConfigurationList = EE2C944E2A5B530B0021E9B6 /* Build configuration list for PBXNativeTarget "IOHKCryptoKit" */; + buildPhases = ( + EE2C94422A5B530B0021E9B6 /* Headers */, + EE2C94432A5B530B0021E9B6 /* Sources */, + EE2C94442A5B530B0021E9B6 /* Frameworks */, + EE2C94452A5B530B0021E9B6 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = IOHKCryptoKit; + productName = IOHKCryptoKit; + productReference = EE2C94472A5B530B0021E9B6 /* IOHKCryptoKit.framework */; + productType = "com.apple.product-type.framework"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + EE2C943E2A5B530B0021E9B6 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastUpgradeCheck = 1420; + TargetAttributes = { + EE2C94462A5B530B0021E9B6 = { + CreatedOnToolsVersion = 14.2; + LastSwiftMigration = 1420; + }; + }; + }; + buildConfigurationList = EE2C94412A5B530B0021E9B6 /* Build configuration list for PBXProject "IOHKCryptoKit" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = EE2C943D2A5B530B0021E9B6; + productRefGroup = EE2C94482A5B530B0021E9B6 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + EE2C94462A5B530B0021E9B6 /* IOHKCryptoKit */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + EE2C94452A5B530B0021E9B6 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + EE2C94562A5B5A4E0021E9B6 /* IOHKCryptoKit.podspec in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + EE2C94432A5B530B0021E9B6 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + EE2C94522A5B539E0021E9B6 /* Ed25519.swift in Sources */, + EE2C94542A5B57580021E9B6 /* X25519.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + EE2C944C2A5B530B0021E9B6 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Debug; + }; + EE2C944D2A5B530B0021E9B6 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + CURRENT_PROJECT_VERSION = 1; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SWIFT_COMPILATION_MODE = wholemodule; + SWIFT_OPTIMIZATION_LEVEL = "-O"; + VERSIONING_SYSTEM = "apple-generic"; + VERSION_INFO_PREFIX = ""; + }; + name = Release; + }; + EE2C944F2A5B530B0021E9B6 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = 89TW38X994; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + LD_RUNPATH_SEARCH_PATHS = ( + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = ( + "@executable_path/../Frameworks", + "@loader_path/Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 12.0; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = io.iohk.atala.prism.kmm.cryptoKit.IOHKCryptoKit; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SDKROOT = auto; + SKIP_INSTALL = YES; + SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx watchos watchsimulator"; + SUPPORTS_MACCATALYST = YES; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2,3,4"; + TVOS_DEPLOYMENT_TARGET = 13.0; + WATCHOS_DEPLOYMENT_TARGET = 8.0; + }; + name = Debug; + }; + EE2C94502A5B530B0021E9B6 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + CLANG_ENABLE_MODULES = YES; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = 89TW38X994; + DYLIB_COMPATIBILITY_VERSION = 1; + DYLIB_CURRENT_VERSION = 1; + DYLIB_INSTALL_NAME_BASE = "@rpath"; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_NSHumanReadableCopyright = ""; + INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; + LD_RUNPATH_SEARCH_PATHS = ( + "@executable_path/Frameworks", + "@loader_path/Frameworks", + ); + "LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = ( + "@executable_path/../Frameworks", + "@loader_path/Frameworks", + ); + MACOSX_DEPLOYMENT_TARGET = 12.0; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = io.iohk.atala.prism.kmm.cryptoKit.IOHKCryptoKit; + PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)"; + SDKROOT = auto; + SKIP_INSTALL = YES; + SUPPORTED_PLATFORMS = "appletvos appletvsimulator iphoneos iphonesimulator macosx watchos watchsimulator"; + SUPPORTS_MACCATALYST = YES; + SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = YES; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2,3,4"; + TVOS_DEPLOYMENT_TARGET = 13.0; + WATCHOS_DEPLOYMENT_TARGET = 8.0; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + EE2C94412A5B530B0021E9B6 /* Build configuration list for PBXProject "IOHKCryptoKit" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + EE2C944C2A5B530B0021E9B6 /* Debug */, + EE2C944D2A5B530B0021E9B6 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + EE2C944E2A5B530B0021E9B6 /* Build configuration list for PBXNativeTarget "IOHKCryptoKit" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + EE2C944F2A5B530B0021E9B6 /* Debug */, + EE2C94502A5B530B0021E9B6 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = EE2C943E2A5B530B0021E9B6 /* Project object */; +} diff --git a/iOSLibs/IOHKCryptoKit/IOHKCryptoKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/iOSLibs/IOHKCryptoKit/IOHKCryptoKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 000000000..919434a62 --- /dev/null +++ b/iOSLibs/IOHKCryptoKit/IOHKCryptoKit.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/iOSLibs/IOHKCryptoKit/IOHKCryptoKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/iOSLibs/IOHKCryptoKit/IOHKCryptoKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 000000000..18d981003 --- /dev/null +++ b/iOSLibs/IOHKCryptoKit/IOHKCryptoKit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/iOSLibs/IOHKCryptoKit/IOHKCryptoKit/Ed25519.swift b/iOSLibs/IOHKCryptoKit/IOHKCryptoKit/Ed25519.swift new file mode 100644 index 000000000..9b32aab00 --- /dev/null +++ b/iOSLibs/IOHKCryptoKit/IOHKCryptoKit/Ed25519.swift @@ -0,0 +1,24 @@ +import CryptoKit +import Foundation + +@objc public class Ed25519: NSObject { + @objc public class func createPrivateKey() -> Data { + Curve25519.Signing.PrivateKey().rawRepresentation + } + + @objc public class func sign(privateKey: Data, data: Data) throws -> Data { + try Curve25519.Signing.PrivateKey(rawRepresentation: privateKey).signature(for: data) + } + + @objc public class func publicKey(privateKey: Data) throws -> Data { + try Curve25519.Signing.PrivateKey(rawRepresentation: privateKey).publicKey.rawRepresentation + } + + @objc public class func verify(publicKey: Data, signature: Data, data: Data) throws -> NSNumber { + return NSNumber(booleanLiteral: try Curve25519 + .Signing + .PublicKey(rawRepresentation: publicKey) + .isValidSignature(signature, for: data) + ) + } +} diff --git a/iOSLibs/IOHKCryptoKit/IOHKCryptoKit/IOHKCryptoKit.h b/iOSLibs/IOHKCryptoKit/IOHKCryptoKit/IOHKCryptoKit.h new file mode 100644 index 000000000..5cebd974c --- /dev/null +++ b/iOSLibs/IOHKCryptoKit/IOHKCryptoKit/IOHKCryptoKit.h @@ -0,0 +1,18 @@ +// +// IOHKCryptoKit.h +// IOHKCryptoKit +// +// Created by Goncalo Frade IOHK on 09/07/2023. +// + +#import + +//! Project version number for IOHKCryptoKit. +FOUNDATION_EXPORT double IOHKCryptoKitVersionNumber; + +//! Project version string for IOHKCryptoKit. +FOUNDATION_EXPORT const unsigned char IOHKCryptoKitVersionString[]; + +// In this header, you should import all the public headers of your framework using statements like #import + + diff --git a/iOSLibs/IOHKCryptoKit/IOHKCryptoKit/X25519.swift b/iOSLibs/IOHKCryptoKit/IOHKCryptoKit/X25519.swift new file mode 100644 index 000000000..a7c13aec5 --- /dev/null +++ b/iOSLibs/IOHKCryptoKit/IOHKCryptoKit/X25519.swift @@ -0,0 +1,13 @@ +import CryptoKit +import Foundation + +@objc public class X25519: NSObject { + + @objc public class func createPrivateKey() -> Data { + Curve25519.KeyAgreement.PrivateKey().rawRepresentation + } + + @objc public class func publicKey(privateKey: Data) throws -> Data { + try Curve25519.KeyAgreement.PrivateKey(rawRepresentation: privateKey).publicKey.rawRepresentation + } +} diff --git a/iOSLibs/IOHKCryptoKit/LICENSE b/iOSLibs/IOHKCryptoKit/LICENSE new file mode 100644 index 000000000..5d3fc0625 --- /dev/null +++ b/iOSLibs/IOHKCryptoKit/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 IOG + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file