multihash implementation.
$ npm install --save multihashes # node the name of the module is multihashes
var multihashes = require('multihashes')
Same as in Node.js, you just have to browserify the code before serving it. See the browserify repo for how to do that.
Make the multihashes.min.js available through your server and load it using a normal <script>
tag, this will export the multihashes
constructor on the window
object, such that:
var multihashes = window.multihashes
You will need to use Node.js Buffer
API compatible, if you are running inside the browser, you can access it by multihash.Buffer
or you can install Feross's Buffer.
> var multihash = require('multihashes')
> var buf = new Buffer('0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33', 'hex')
> var encoded = multihash.encode(buf, 'sha1')
> console.log(encoded)
<Buffer 11 14 0b ee c7 b5 ea 3f 0f db c9 5d 0d d4 7f 3c 5b c2 75 da 8a 33>
> multihash.decode(encoded)
{ code: 17,
name: 'sha1',
length: 20,
digest: <Buffer 0b ee c7 b5 ea 3f 0f db c9 5d 0d d4 7f 3c 5b c2 75 da 8a 33> }
For encoding and decoding, the bs58 module is recommended.
MIT