-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Sajjon/expose_ec_methods
Expose Decode Point from Public Key method
- Loading branch information
Showing
7 changed files
with
101 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
Tests/BitcoinKitTests/DecodePointFromCompressedKeyTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// DecodePointFromCompressedKeyTests.swift | ||
// BitcoinKitTests | ||
// | ||
// Created by Alexander Cyon on 2019-03-22. | ||
// Copyright © 2019 BitcoinKit developers. All rights reserved. | ||
// | ||
|
||
#if BitcoinKitXcode | ||
import Foundation | ||
@testable import BitcoinKit | ||
import XCTest | ||
|
||
class DecodePointTests: XCTestCase { | ||
func testPointDecoding() { | ||
do { | ||
let wifUncompressed = "5K6EwEiKWKNnWGYwbNtrXjA8KKNntvxNKvepNqNeeLpfW7FSG1v" | ||
let wifCompresssed = "L2r8WPXNgQ79rBdyxjdscd5HHr7BaD9P8Xov7NWZ9pVNw12TFSDZ" | ||
let privateKeyFromUncompressed = try PrivateKey(wif: wifUncompressed) | ||
let publicKeyUncompressed = privateKeyFromUncompressed.publicKey() | ||
XCTAssertFalse(publicKeyUncompressed.isCompressed) | ||
|
||
let decodedFromUncompressed: PointOnCurve = try PointOnCurve.decodePointFromPublicKey(publicKeyUncompressed) | ||
let expectedY = "ccfca71eff2101ad68238112e7585110e0f2c32d345225985356dc7cab8fdcc9" | ||
XCTAssertEqual(decodedFromUncompressed.y.data.hex, expectedY) | ||
|
||
let privateKeyFromCompressed = try PrivateKey(wif: wifCompresssed) | ||
let publicKeyCompressed = privateKeyFromCompressed.publicKey() | ||
XCTAssertTrue(publicKeyCompressed.isCompressed) | ||
|
||
let decodedFromCompressed: PointOnCurve = try PointOnCurve.decodePointFromPublicKey(publicKeyCompressed) | ||
XCTAssertEqual(decodedFromCompressed.y.data.hex, expectedY) | ||
XCTAssertEqual(decodedFromCompressed.y.data.hex, decodedFromUncompressed.y.data.hex) | ||
|
||
} catch { | ||
XCTFail("Error: \(error)") | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters