Skip to content

Commit

Permalink
Merge pull request #45 from tkey/fix/keypoint-pubkey
Browse files Browse the repository at this point in the history
fix: keypoint-pubkey
  • Loading branch information
metalurgical authored Aug 15, 2023
2 parents 873a0bc + dd2b825 commit aa1a2ce
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
19 changes: 17 additions & 2 deletions Sources/ThresholdKey/Common/KeyPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<Int8>(mutating: (format as NSString).utf8String)
let encoder_format = UnsafeMutablePointer<Int8>(mutating: (format.value as NSString).utf8String)
let result = withUnsafeMutablePointer(to: &errorCode, { error in
key_point_encode(pointer, encoder_format, error)
})
Expand Down
2 changes: 1 addition & 1 deletion Tests/tkeypkgTests/tkey_pkgKeyDetailsTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion Tests/tkeypkgTests/tkey_pkgKeyPointTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit aa1a2ce

Please sign in to comment.