Base58 encoding in ruby

0 votes

I am following the below mentioned steps to base58 encode:

# 1 - Take the corresponding public key generated with it (65 bytes, 1 byte 0x04, 32 bytes corresponding to X coordinate, 32 bytes corresponding to Y coordinate)

  sender = '028401a2e512b1b91b882ee1c9291cd407c10916bf791662f7189c9c805643e51c'

# 2 - Perform SHA-256 hashing on the public key

  sender = Digest::SHA256.new.update(sender)

# 3 - Perform RIPEMD-160 hashing on the result of SHA-256

  sender = Digest::RMD160.new.update(sender.to_s)

# 4 - Add version byte in front of RIPEMD-160 hash (0x00 for Main Network)

  sender = '00' + sender.to_s

# 5 - Perform SHA-256 hash on the extended RIPEMD-160 result

  checksum = Digest::SHA256.new.update(sender.to_s)

# 6 - Perform SHA-256 hash on the result of the previous SHA-256 hash

  checksum = Digest::SHA256.new.update(checksum.to_s)

# 7 - Take the first 4 bytes of the second SHA-256 hash. This is the address checksum

  checksum = checksum.to_s[0,8]

# 8 - Add the 4 checksum bytes from point 7 at the end of extended RIPEMD-160 hash from point 4. This is the 25-byte binary Bitcoin Address.

  sender += checksum

Everything works fine till step 8. But on step 9 I get an error:

/path/to/base58.rb:23:in `int_to_base58': Value passed is not an Integer. (ArgumentError)

Need help to find a solution.

Aug 22, 2018 in Blockchain by slayer
• 29,350 points
895 views

1 answer to this question.

0 votes

Seems like a hexadecimal number is stuck in a string, make it a number:

2.0.0p247 :001 > require 'base58'

 => true

2.0.0p247 :002 > x = '0073eb40b21b02c08e93f6ef1bec5828763ac89e456c2f6fec'

 => "0073eb40b21b02c08e93f6ef1bec5828763ac89e456c2f6fec"

2.0.0p247 :003 > Base58.encode(x.to_i(16))

 => "byVwGWzMZZ7HwsufSQx6T2pRapGZWdkAL"

This should work.

answered Aug 22, 2018 by digger
• 26,740 points

Related Questions In Blockchain

0 votes
1 answer

Why RLP encoding is used in Ethereum?

RLP is intended to be a highly ...READ MORE

answered Aug 4, 2018 in Blockchain by Mohini
• 260 points
1,428 views
0 votes
1 answer

How to generate Bitcoin address in Ruby?

In your generate_address_from_public_key_hash method, the checksum should be over ...READ MORE

answered Aug 22, 2018 in Blockchain by slayer
• 29,350 points
2,287 views
0 votes
1 answer

Bitstamp API signature in Ruby

Here is a code that works: require 'open-uri' require ...READ MORE

answered Aug 28, 2018 in Blockchain by slayer
• 29,350 points
852 views
0 votes
1 answer

Creating bitcoin address in ruby

When you calculate the SHA256 checksum, make ...READ MORE

answered Aug 28, 2018 in Blockchain by slayer
• 29,350 points
515 views
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,450 points
1,129 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,663 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,215 views
0 votes
1 answer

Encoding integers in solidity

There are different ways to do this ...READ MORE

answered Aug 13, 2018 in Blockchain by digger
• 26,740 points
734 views
0 votes
1 answer

How to use Proc/lamba returned from a method in Ruby?

You need to remove the colon: list.select(&valid_transaction) The & ...READ MORE

answered Aug 24, 2018 in Blockchain by digger
• 26,740 points
423 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP