core: Add utilities for parsing/serialising pubkeys as base58

This commit is contained in:
Andras Slemmer 2016-07-29 16:40:57 +01:00
parent 918de94a22
commit 1cebae633d

View File

@ -146,6 +146,11 @@ fun PrivateKey.signWithECDSA(bitsToSign: ByteArray, publicKey: PublicKey): Digit
return DigitalSignature.WithKey(publicKey, signWithECDSA(bitsToSign).bits)
}
val ed25519Curve = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.CURVE_ED25519_SHA512)
fun String.toPublicKey(): PublicKey = EdDSAPublicKey(EdDSAPublicKeySpec(Base58.decode(this), ed25519Curve))
fun PublicKey.toBase58String() = Base58.encode((this as EdDSAPublicKey).abyte)
fun KeyPair.signWithECDSA(bitsToSign: ByteArray) = private.signWithECDSA(bitsToSign, public)
fun KeyPair.signWithECDSA(bitsToSign: OpaqueBytes) = private.signWithECDSA(bitsToSign.bits, public)
fun KeyPair.signWithECDSA(bitsToSign: OpaqueBytes, party: Party) = signWithECDSA(bitsToSign.bits, party)