Skip to content

Commit

Permalink
add tests for Secp256k1
Browse files Browse the repository at this point in the history
  • Loading branch information
fluency03 committed May 6, 2018
1 parent e403833 commit 371ca5a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ object Secp256k1 {
def privateKeyToBytes(privateKey: PrivateKey): Bytes =
privateKey.asInstanceOf[ECPrivateKey].getD.toByteArray

def publicKeyToAddress(publicKey: String, networkBytes: String = "00"): String =
def publicKeyHexToAddress(publicKey: String, networkBytes: String = "00"): String =
Base58.checkEncode(networkBytes.hex2Bytes ++ publicKey.hex2Bytes.toHash160Digest)



def publicKeyToAddress(publicKey: PublicKey, networkBytes: String = "00"): String =
Base58.checkEncode(networkBytes.hex2Bytes ++ publicKeyToBytes(publicKey).toHash160Digest)

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@ class Secp256k1Test extends FlatSpec with Matchers {
recoverPublicKey(pair.getPublic.toHex) shouldEqual pair.getPublic
recoverPrivateKey(pair.getPrivate.toHex) shouldEqual pair.getPrivate

Secp256k1.publicKeyToAddress("04B4D653FCBB4B96000C99343F23B08A44FA306031E0587F9E657AB" +
Secp256k1.publicKeyHexToAddress("04B4D653FCBB4B96000C99343F23B08A44FA306031E0587F9E657AB" +
"4A2541129368D7D9BB05CD8AFBDF7705A6540D98028236965553F91BF1C5B4F70073F55B55D") shouldEqual
"1DU8Hi1sbHTpEP9vViBEkEw6noeUrgKkJH"

Secp256k1.publicKeyToAddress(recoverPublicKey("04B4D653FCBB4B96000C99343F23B08A44FA306031E0587F9E657AB" +
"4A2541129368D7D9BB05CD8AFBDF7705A6540D98028236965553F91BF1C5B4F70073F55B55D")) shouldEqual
"1DU8Hi1sbHTpEP9vViBEkEw6noeUrgKkJH"

Secp256k1.privateKeyToBytes(pair.getPrivate).toBigInt shouldEqual Secp256k1.privateKeyToHex(pair.getPrivate).hex2BigInt

}


Expand Down

0 comments on commit 371ca5a

Please sign in to comment.