From c8c63b70dd408febc91f8919225da1bcf3a23a7e Mon Sep 17 00:00:00 2001 From: Alexander Osokin Date: Mon, 15 May 2023 15:16:14 +0300 Subject: [PATCH] IOS-3604 Add support for schnorr wallet creation --- .../TangemSdk/Common/Card/EllipticCurve.swift | 1 + TangemSdk/TangemSdk/Crypto/CryptoUtils.swift | 16 ++++++++-------- .../TangemSdk/Crypto/HDWallet/BIP32/BIP32.swift | 3 +++ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/TangemSdk/TangemSdk/Common/Card/EllipticCurve.swift b/TangemSdk/TangemSdk/Common/Card/EllipticCurve.swift index 713d8e684..3d06fe2ba 100644 --- a/TangemSdk/TangemSdk/Common/Card/EllipticCurve.swift +++ b/TangemSdk/TangemSdk/Common/Card/EllipticCurve.swift @@ -17,4 +17,5 @@ public enum EllipticCurve: String, StringCodable, CaseIterable { case bls12381_G2 case bls12381_G2_AUG case bls12381_G2_POP + case bip0340 } diff --git a/TangemSdk/TangemSdk/Crypto/CryptoUtils.swift b/TangemSdk/TangemSdk/Crypto/CryptoUtils.swift index 36658dbe4..0be332d37 100644 --- a/TangemSdk/TangemSdk/Crypto/CryptoUtils.swift +++ b/TangemSdk/TangemSdk/Crypto/CryptoUtils.swift @@ -57,8 +57,8 @@ public enum CryptoUtils { let sig = try P256.Signing.ECDSASignature(rawRepresentation: signature) return pubKey.isValidSignature(sig, for: message) - case .bls12381_G2, .bls12381_G2_AUG, .bls12381_G2_POP: - // TODO: Add support for BLS keys. + case .bls12381_G2, .bls12381_G2_AUG, .bls12381_G2_POP, .bip0340: + // TODO: implement throw TangemSdkError.unsupportedCurve } } @@ -73,8 +73,8 @@ public enum CryptoUtils { case .secp256r1: let key = try? P256.Signing.PrivateKey(rawRepresentation: privateKey) return key != nil - case .bls12381_G2, .bls12381_G2_AUG, .bls12381_G2_POP: - // TODO: Add support for BLS keys. + case .bls12381_G2, .bls12381_G2_AUG, .bls12381_G2_POP, .bip0340: + // TODO: implement throw TangemSdkError.unsupportedCurve } } @@ -90,8 +90,8 @@ public enum CryptoUtils { case .secp256r1: let key = try P256.Signing.PrivateKey(rawRepresentation: privateKey) return key.publicKey.rawRepresentation - case .bls12381_G2, .bls12381_G2_AUG, .bls12381_G2_POP: - // TODO: Add support for BLS keys. + case .bls12381_G2, .bls12381_G2_AUG, .bls12381_G2_POP, .bip0340: + // TODO: implement throw TangemSdkError.unsupportedCurve } } @@ -121,8 +121,8 @@ public enum CryptoUtils { let pubKey = try P256.Signing.PublicKey(x963Representation: publicKey) let sig = try P256.Signing.ECDSASignature(rawRepresentation: signature) return pubKey.isValidSignature(sig, for: CustomSha256Digest(hash: hash)) - case .bls12381_G2, .bls12381_G2_AUG, .bls12381_G2_POP: - // TODO: Add support for BLS keys. + case .bls12381_G2, .bls12381_G2_AUG, .bls12381_G2_POP, .bip0340: + // TODO: implement throw TangemSdkError.unsupportedCurve } } diff --git a/TangemSdk/TangemSdk/Crypto/HDWallet/BIP32/BIP32.swift b/TangemSdk/TangemSdk/Crypto/HDWallet/BIP32/BIP32.swift index 1e8537db1..6d61c4ff6 100644 --- a/TangemSdk/TangemSdk/Crypto/HDWallet/BIP32/BIP32.swift +++ b/TangemSdk/TangemSdk/Crypto/HDWallet/BIP32/BIP32.swift @@ -74,6 +74,9 @@ fileprivate extension EllipticCurve { case .bls12381_G2, .bls12381_G2_AUG, .bls12381_G2_POP: // https://eips.ethereum.org/EIPS/eip-2333#derive_master_sk fatalError("not applicable for this curve") + case .bip0340: + // TODO: https://tangem.atlassian.net/browse/IOS-3606 + fatalError("not applicable for this curve") } } }