Skip to content

Instantly share code, notes, and snippets.

@Tolsi
Created February 14, 2018 11:55
Embed
What would you like to do?
Sign Ed25519 As Whisper Systems Curve25519 used at Waves
package test
import com.muquit.libsodiumjna.SodiumLibrary
import scorex.crypto.encode.Base58
import scorex.crypto.signatures.Curve25519
object SignAsWaves extends App {
SodiumLibrary.setLibraryPath("/usr/local/Cellar/libsodium/1.0.16/lib/libsodium.dylib")
val message = "message"
val ed25519keyPair = SodiumLibrary.cryptoSignKeyPair()
val ed25519PrivateKey = ed25519keyPair.getPrivateKey
val ed25519PublicKey = ed25519keyPair.getPublicKey
println(s"ed private: ${Base58.encode(ed25519PrivateKey)}")
println(s"ed public: ${Base58.encode(ed25519PublicKey)}")
val curve25519PrivateKey = SodiumLibrary.cryptoSignEdSkTOcurveSk(ed25519keyPair.getPrivateKey)
val curve25519PublicKey = SodiumLibrary.cryptoSignEdPkTOcurvePk(ed25519keyPair.getPublicKey)
println(s"curve private: ${Base58.encode(curve25519PrivateKey)}")
println(s"curve public: ${Base58.encode(curve25519PublicKey)}")
val ed25519sign = SodiumLibrary.cryptoSign(message.getBytes, ed25519PrivateKey)
val curve25519sign = ed25519sign.clone().take(64)
val pk = ed25519keyPair.getPublicKey
var sign_bit = (pk(31) & 0x80).toByte
curve25519sign.update(63, (curve25519sign(63) | sign_bit).toByte)
println(s"ed25519 sign: ${Base58.encode(ed25519sign)}")
println(s"ed25519 sign len: ${ed25519sign.length}")
println(s"curve25519sign sign: ${Base58.encode(curve25519sign)}")
println(s"curve25519sign sign len: ${curve25519sign.length}")
println(s"ed25519 signature validation with ed25519: ${SodiumLibrary.cryptoSignVerifyDetached(ed25519sign, message.getBytes, ed25519PublicKey)}")
println(s"converted ed25519 signature validation with curve25519: ${Curve25519.verify(curve25519sign, message.getBytes, curve25519PublicKey)}")
}
@kraniet888
Copy link

https://{{api-host}}/api/v1/oauth2/token.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment