session-ios/SessionUtilitiesKit/Crypto/ECKeyPair+Hexadecimal.swift
Morgan Pretty dbead5e3c8 Got the '/inbox' APIs and encryption/decryption/validation working
Added a few types to make the code more readable
Added the inbox request to the polling
Added a couple of properties to the TSContactThread to indicate the originating open group to support SOGS DMs
Added code to store the latest message id for an open group inbox
Added a bunch of documentation from the API docs into the OpenGroupAPI (and associated models)
Updated the OpenGroupAPI to match the latest docs
Fixed the incorrect structure of the SendDirectMessageRequest
Fixed an incorrect inbox endpoint path
Tweaked the batch response handling so it wouldn't fail to parse all responses if a single one failed
Renamed IdPrefix to SessionId.Prefix and cleaned up the type to be more readable & self-documenting
2022-02-25 11:59:29 +11:00

27 lines
1 KiB
Swift

import Curve25519Kit
public extension ECKeyPair {
@objc var hexEncodedPrivateKey: String {
return privateKey.map { String(format: "%02hhx", $0) }.joined()
}
@objc var hexEncodedPublicKey: String {
// Prefixing with 'SessionId.Prefix.standard' is necessary for what seems to be a sort of Signal public key versioning system
return SessionId(.standard, publicKey: publicKey.bytes).hexString
}
@objc static func isValidHexEncodedPublicKey(candidate: String) -> Bool {
// Note: If the logic in here changes ensure it doesn't break `SessionId.Prefix(from:)`
// Check that it's a valid hexadecimal encoding
guard Hex.isValid(candidate) else { return false }
// Check that it has length 66 and a valid prefix
guard candidate.count == 66 && SessionId.Prefix.allCases.first(where: { candidate.hasPrefix($0.rawValue) }) != nil else {
return false
}
// It appears to be a valid public key
return true
}
}