Git Product home page Git Product logo

ruby-multihash's Introduction

ruby-multihash

Travis CI codecov.io

A simple Multihash implementation for ruby.

A multihash is a digest with an embedded hash function code (and length) ('cause you never know). It was developed primarily for use with IPFS, but is not specific to it.

Install

Add this line to your application's Gemfile:

gem 'multihashes'

And then execute:

$ bundle

Or install it yourself as:

$ gem install multihashes

Usage

This is a low-level library. Bring your own digest. A binary digest goes in, a binary digest goes out. To compute a sha256 multihash that would work nicely with IPFS:

require 'multihashes'
require 'digest'

digest = Digest::SHA256.digest 'Dade Murphy will never figure this one out'
multihash_binary_string = Multihashes.encode digest, 'sha2-256'

multihash_binary_string.unpack('H*').first # hex: "1220142711d38ca7a33c521841..."

out = Multihashes.decode multihash_binary_string
# => {:code=>18, :hash_function=>"sha2-256", :length=>32, :digest=>"\x14'\x11\xD3\x8C\xA7\xA3<R\x18Ao\x8F\xFC\xC6FH\xCAF\x16\xA6%\xB5\xE0\xA0\xAB=\xA1\x91\x1D]z"}

Hash function names (latest is here)

code name
0xd5 md5
0x11 sha1
0x12 sha2-256
0x13 sha2-512
0x14 sha3
0x40 blake2b
0x41 blake2s
# 0x00-0x0f reserved for application specific functions
# 0x10-0x3f reserved for SHA standard functions

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install.

Maintainers

@kyledrake

Contribute

Bug reports and pull requests are welcome on GitHub at https://github.com/multiformats/ruby-multihash.

Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS Code of Conduct.

Small note: If editing the README, please conform to the standard-readme specification.

License

The gem is available as open source under the terms of the MIT License © 2015 Kyle Drake.

ruby-multihash's People

Contributors

bmquinn avatar kyledrake avatar richardlitt avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.