mirror of
https://github.com/aljazceru/breez-sdk-liquid.git
synced 2025-12-22 16:34:23 +01:00
* Add Swift notification plugin * Hash the metadata * Validate min sendable amount * Remove initializer as base class, UNNotificationServiceExtension, has no default initializer * Set the PaymentMethod * Handle PaymentDetails in SwapUpdated * Improve payment text
36 lines
1.0 KiB
Swift
36 lines
1.0 KiB
Swift
import Foundation
|
|
import CommonCrypto
|
|
|
|
extension Data {
|
|
public func sha256() -> String {
|
|
return hexStringFromData(input: digest(input: self as NSData))
|
|
}
|
|
|
|
private func digest(input : NSData) -> NSData {
|
|
let digestLength = Int(CC_SHA256_DIGEST_LENGTH)
|
|
var hash = [UInt8](repeating: 0, count: digestLength)
|
|
CC_SHA256(input.bytes, UInt32(input.length), &hash)
|
|
return NSData(bytes: hash, length: digestLength)
|
|
}
|
|
|
|
private func hexStringFromData(input: NSData) -> String {
|
|
var bytes = [UInt8](repeating: 0, count: input.length)
|
|
input.getBytes(&bytes, length: input.length)
|
|
|
|
var hexString = ""
|
|
for byte in bytes {
|
|
hexString += String(format:"%02x", UInt8(byte))
|
|
}
|
|
|
|
return hexString
|
|
}
|
|
}
|
|
|
|
public extension String {
|
|
func sha256() -> String {
|
|
if let stringData = self.data(using: String.Encoding.utf8) {
|
|
return stringData.sha256()
|
|
}
|
|
return ""
|
|
}
|
|
} |