Skip to content
This repository has been archived by the owner on Nov 27, 2019. It is now read-only.

Commit

Permalink
feat: message verification (#7)
Browse files Browse the repository at this point in the history
* feat: initial step for verifying messages

* add mesage hash generation

* message verification attempt

* refactor: move message.ex to correct folder

* feat: message verification

* test: add message signing and verification test
  • Loading branch information
ItsANameToo authored and faustbrian committed Jul 13, 2018
1 parent 6d7a419 commit e4b82e7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -24,3 +24,6 @@ ark_elixir-*.tar

# Ignore package lock file
mix.lock

# Ignore osx .DS_Store
.DS_Store
4 changes: 1 addition & 3 deletions lib/message.ex → lib/arkecosystem/crypto/message.ex
Expand Up @@ -12,8 +12,6 @@ defmodule ArkEcosystem.Crypto.Message do

@spec verify(String.t(), String.t(), String.t()) :: Boolean.t()
def verify(message, signature, public_key) do
IO.puts(message)
IO.puts(signature)
IO.puts(public_key)
EcKey.verify(message, signature, public_key)
end
end
19 changes: 19 additions & 0 deletions test/crypto/message_test.exs
@@ -0,0 +1,19 @@
defmodule ArkEcosystem.Crypto.MessageTest do
use ExUnit.Case, async: false
alias ArkEcosystem.Crypto.Message

test "should be able to sign a message" do
signed = Message.sign("hello", "world")
assert(signed[:message] == "hello")
assert(signed[:publickey] == "039b101edcbe1ee37ff6b2318526a425b629e823d7d8d9154417880595a28000ee")
assert(signed[:signature] == "3045022100ff2007e57064946fb80f4280dca2a9d312c8ec9a101f706700eae732947b65f302207a6a0fbd07d4084aba6dcd53d0c3ef531bd42d0281079323709ac2026420a8a7")
end

test "should be able to verify a message" do
signed = Message.sign("hello", "world")
assert(Message.verify(signed[:message], signed[:signature], signed[:publickey]) == true)
# Change last character of signature, as verify should then return false
assert(Message.verify(signed[:message], "3045022100ff2007e57064946fb80f4280dca2a9d312c8ec9a101f706700eae732947b65f302207a6a0fbd07d4084aba6dcd53d0c3ef531bd42d0281079323709ac2026420a8a2", signed[:publickey]) == false)
end

end

0 comments on commit e4b82e7

Please sign in to comment.