Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
ed25519 signature in ruby
require 'ed25519'
payload = 'plain text'
# generate key pair
signing_key = Ed25519::SigningKey.generate
verify_key = signing_key.verify_key
p signing_key
p verify_key
# sign
signature = signing_key.sign payload
puts "signature: #{signature.unpack 'H*'}"
result = verify_key.verify signature, payload
puts "verification result: #{result}"
wrong_payload = 'Different from original message'
verify_key.verify signature, wrong_payload
rescue => e
puts e.class
puts e.message
# serialize keys
signing_key_bytes = signing_key.to_bytes
verify_key_bytes = verify_key.to_bytes
puts "signing_key_bytes: #{signing_key_bytes.unpack 'H*'}"
puts "verify_key_bytes: #{verify_key_bytes.unpack 'H*'}"
# You can make instance form both serialized keys signing_key_bytes
restored_verify_key = verify_key_bytes
second_result = restored_verify_key.verify signature, payload
puts "verification result: #{second_result}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment