Skip to content

Commit

Permalink
IOS-4286 Set implementation library bls into bls utils
Browse files Browse the repository at this point in the history
  • Loading branch information
skibinalexander committed Aug 15, 2023
1 parent 56abd16 commit 627c683
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions TangemSdk/TangemSdk/Crypto/BLS/BLSUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 627c683

Please sign in to comment.