From 627c6830a5325b910f5e458997eb9c886b722c87 Mon Sep 17 00:00:00 2001 From: Skibin Alexander Date: Tue, 15 Aug 2023 16:19:40 +0300 Subject: [PATCH] IOS-4286 Set implementation library bls into bls utils --- TangemSdk/TangemSdk/Crypto/BLS/BLSUtils.swift | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/TangemSdk/TangemSdk/Crypto/BLS/BLSUtils.swift b/TangemSdk/TangemSdk/Crypto/BLS/BLSUtils.swift index f0effd52a..29af7d0f4 100644 --- a/TangemSdk/TangemSdk/Crypto/BLS/BLSUtils.swift +++ b/TangemSdk/TangemSdk/Crypto/BLS/BLSUtils.swift @@ -8,9 +8,16 @@ import Foundation import CryptoKit +import Bls_Signature @available(iOS 13.0, *) struct BLSUtils { + // MARK: - Init + + public init() {} + + // MARK: - Implementation + /// hkdf_mod_r() implementaion (KeyGen) /// https://eips.ethereum.org/EIPS/eip-2333#hkdf_mod_r-1 /// https://www.ietf.org/archive/id/draft-irtf-cfrg-bls-signature-05.html#name-keygen @@ -62,3 +69,41 @@ extension BLSUtils { case keyGenerationFailed } } + +// MARK: - Bls_Signature Implementation + +@available(iOS 13.0, *) +extension BLSUtils { + /// Obtain G2 point for bls curve + /// - Parameters: + /// - publicKey: Public key hash + /// - message: Message hash + /// - Returns: Hash of G2Element point + public func augSchemeMplG2Map(publicKey: String, message: String) throws -> String { + try BlsSignatureSwift.augSchemeMplG2Map(publicKey: publicKey, message: message) + } + + /// Perform Aggregate hash signatures + /// - Parameter signatures: Signatures hash's + /// - Returns: Hash of result aggreate signature at bls-signature library + public func aggregate(signatures: [String]) throws -> String { + try BlsSignatureSwift.aggregate(signatures: signatures) + } + + /// Obtain public key from private key + /// - Parameter privateKey: Private key hash string + /// - Returns: Public key hash + public func publicKey(from privateKey: String) throws -> String { + try BlsSignatureSwift.publicKey(from: privateKey) + } + + /// Verify message payload for signatures + /// - Parameters: + /// - signatures: Hash signatures + /// - publicKey: Hash public key + /// - message: Has payload message + /// - Returns: Bool result of valid or no + public func verify(signatures: [String], with publicKey: String, message: String) throws -> Bool { + try BlsSignatureSwift.verify(signatures: signatures, with: publicKey, message: message) + } +}