Skip to content

Commit

Permalink
eth/signature: fix prefix_message for multibyte characters (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
kudohamu authored Jun 24, 2022
1 parent bb640c7 commit 7cba13b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/eth/signature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class SignatureError < StandardError; end
# @param message [String] the message string to be prefixed.
# @return [String] an EIP-191 prefixed string.
def prefix_message(message)
"#{EIP191_PREFIX_BYTE}Ethereum Signed Message:\n#{message.size}#{message}"
"#{EIP191_PREFIX_BYTE}Ethereum Signed Message:\n#{message.bytesize}#{message}"
end

# Dissects a signature blob of 65+ bytes into its `r`, `s`, and `v`
Expand Down
5 changes: 5 additions & 0 deletions spec/eth/signature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
proof = "This is proof that I, user A, have access to this address."
expect(Signature.prefix_message proof).to eq "\x19Ethereum Signed Message:\n58This is proof that I, user A, have access to this address."
end

it "can properly prefix messages with multibyte characters" do
hello = "Hello World!🌏"
expect(Signature.prefix_message hello).to eq "\x19Ethereum Signed Message:\n16Hello World!🌏"
end
end

describe ".dissect" do
Expand Down

0 comments on commit 7cba13b

Please sign in to comment.