diff --git a/Sources/ThresholdKey/Common/KeyPoint.swift b/Sources/ThresholdKey/Common/KeyPoint.swift index bd2ff5d..4d4492f 100644 --- a/Sources/ThresholdKey/Common/KeyPoint.swift +++ b/Sources/ThresholdKey/Common/KeyPoint.swift @@ -3,6 +3,21 @@ import Foundation import lib #endif + +public enum PublicKeyEncoding : Equatable, Hashable { + case EllipticCompress + case FullAddress + + public var value : String { + switch self { + case .EllipticCompress: + return "elliptic-compressed" + case .FullAddress : + return "" + } + } +} + public final class KeyPoint: Equatable { /// Compares two KeyPoint objects @@ -107,10 +122,10 @@ public final class KeyPoint: Equatable { /// - Returns: Serialized form of `KeyPoint` as `String` /// /// - Throws: `RuntimeError`, indicates either the underlying pointer is invalid or the co-ordinate pair is not a valid PublicKey. - public func getAsCompressedPublicKey(format: String) throws -> String { + public func getPublicKey(format: PublicKeyEncoding) throws -> String { var errorCode: Int32 = -1 - let encoder_format = UnsafeMutablePointer(mutating: (format as NSString).utf8String) + let encoder_format = UnsafeMutablePointer(mutating: (format.value as NSString).utf8String) let result = withUnsafeMutablePointer(to: &errorCode, { error in key_point_encode(pointer, encoder_format, error) }) diff --git a/Tests/tkeypkgTests/tkey_pkgKeyDetailsTest.swift b/Tests/tkeypkgTests/tkey_pkgKeyDetailsTest.swift index 2741ae1..84ba9a1 100644 --- a/Tests/tkeypkgTests/tkey_pkgKeyDetailsTest.swift +++ b/Tests/tkeypkgTests/tkey_pkgKeyDetailsTest.swift @@ -25,7 +25,7 @@ final class tkey_pkgKeyDetailsTests: XCTestCase { } func test_public_key_point() { - XCTAssertNotEqual(try! data.pub_key.getAsCompressedPublicKey(format: "elliptic-compressed").count,0) + XCTAssertNotEqual(try! data.pub_key.getPublicKey(format: .EllipticCompress).count,0) } func test_threshold() { diff --git a/Tests/tkeypkgTests/tkey_pkgKeyPointTests.swift b/Tests/tkeypkgTests/tkey_pkgKeyPointTests.swift index d659800..d6f49ed 100644 --- a/Tests/tkeypkgTests/tkey_pkgKeyPointTests.swift +++ b/Tests/tkeypkgTests/tkey_pkgKeyPointTests.swift @@ -34,7 +34,7 @@ final class tkey_pkgKeyPointTests: XCTestCase { } func test_required_shares() { - XCTAssertNotEqual(try data.getAsCompressedPublicKey(format: "elliptic-compressed").count,0) + XCTAssertNotEqual(try data.getPublicKey(format: .EllipticCompress).count,0) } func test_create_x_y() {