{"id":16717162,"url":"https://github.com/mseri/crypto-multihash","last_synced_at":"2025-06-12T23:35:58.325Z","repository":{"id":56843289,"uuid":"61389594","full_name":"mseri/crypto-multihash","owner":"mseri","description":"Multihash library on top of haskell's cryptonite crypto library","archived":false,"fork":false,"pushed_at":"2016-08-27T12:35:50.000Z","size":48,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-27T07:05:12.273Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Haskell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mseri.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-17T17:08:46.000Z","updated_at":"2016-09-24T11:33:19.000Z","dependencies_parsed_at":"2022-09-09T04:12:34.564Z","dependency_job_id":null,"html_url":"https://github.com/mseri/crypto-multihash","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mseri%2Fcrypto-multihash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mseri%2Fcrypto-multihash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mseri%2Fcrypto-multihash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mseri%2Fcrypto-multihash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mseri","download_url":"https://codeload.github.com/mseri/crypto-multihash/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mseri%2Fcrypto-multihash/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":258240482,"owners_count":22670217,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T21:30:21.673Z","updated_at":"2025-06-12T23:35:58.302Z","avatar_url":"https://github.com/mseri.png","language":"Haskell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Crypto Multihash\n\n[![Build Status](https://travis-ci.org/mseri/crypto-multihash.svg?branch=master)](https://travis-ci.org/mseri/crypto-multihash)\n[![Hackage](https://img.shields.io/hackage/v/crypto-multihash.svg)](http://hackage.haskell.org/package/crypto-multihash)\n![Hackage Dependencies](https://img.shields.io/hackage-deps/v/crypto-multihash.svg)\n![Haskell Programming Language](https://img.shields.io/badge/language-Haskell-blue.svg)\n![BSD3 License](http://img.shields.io/badge/license-BSD3-brightgreen.svg)\n\n\nMultihash library implemented on top of [cryptonite](https://hackage.haskell.org/package/cryptonite) cryptographic library. \nMultihash is a protocol for encoding the hash algorithm and digest length at the start of the digest, see the official [multihash github page](https://github.com/jbenet/multihash/).\n\nThis library is still experimental and the api is not guaranteed stable. \nI will increment the version number appropriately in case of breaking changes.\n\nFor the moment the library implements all the expected hashing algorithms with the exception of shake-128 and shake-256. A Multihash can be encoded in hex (`Base16`), base 32 (`Base32`), bitcoin base58 (`Base58`) and base64 (`Base64`). \n\n# Usage\n\n```{.haskell}\n-- in ghci `:set -XOverloadedStrings`\n{-# LANGUAGE OverloadedStrings #-}\n\n-- `:m +Crypto.Multihash`\nimport Crypto.Multihash\nimport Data.ByteString (ByteString)\n\nmain = do\n    let v = \"test\"::ByteString\n    let m = multihash SHA256 v\n\n    -- If using the Weak module\n    -- let m' = weakMultihash \"sha256\" v\n    \n    putStrLn $ \"Base16: \" ++ (encode' Base16 m)\n    -- You might need to specify the encoded string type\n    putStrLn $ \"Base58: \" ++ (encode' Base58 m :: String)\n\n    -- `encode` is the safe interface returning an `Either` type\n    putStrLn $ \"Base64: \" ++ show (encode Base64 m :: Either String String)\n    \n    let h = encode' Base58 m :: ByteString\n    -- You can check that a multihash corresponds to some data `v`\n    checkMultihash h v\n    -- Right True\n    \n    -- Or if you have a Multihash to compare you can use it\n    check h m\n    -- Right True\n\n    -- There is also an unsafe version, as for encode\n    -- note that sometimes you will need to specify the string types\n    checkMultihash' (\"whatever\"::String) v\n    -- *** Exception: Unable to infer an encoding\n    checkMultihash' (\"Eiwhatever\"::ByteString) v\n    -- *** Exception: base64: input: invalid length\n    check' (\"EiCfhtCBiEx9ZZov6qDFWtAVo79PGysLgizRXWwVsPA1CA==\"::ByteString) m\n    -- False\n\n    checkMultihash' h v\n    -- True\n    check' h m\n    -- True\n```\n\nThe of `import Crypto.Multihash.Weak` is almost identical, but it additionally introduces the function `toWeakMultihash` that tries to import a string as a `WeakMultihashDigest`.\n\n# Test\n\nSome preliminary tests can be performed with `stack test`. \n\nA simple example encoder is in `app/Main.hs`. \nYou can run it on files\n\n```{.bash}\necho -n test | stack exec mh -- somefile someotherfile\n```\n\nor read data from the standard input \n\n```{.bash}\necho -n test | stack exec mh -- -\n```\n\n# Contribution\n\n1. Fork repository\n2. Do some changes\n3. Create pull request\n4. Wait for CI build and review\n\nYou can use stack to build the project: `stack build`\n\nTo run tests: `stack test`\n\n# TODO\n\n- ~~Test the new `getBase` implementation using quickcheck~~\n- Accurately test the correct support of truncated multihashes, including the truncation length that triggers easy failures in `getBase`\n- Implement benchmarks, then start optimising the code where possible\n- ~~Use the hash length in `checkPayload` to treat correctly truncated hashes (see https://github.com/jbenet/multihash/issues/1#issuecomment-91783612)~~\n- Improve documentation\n- Implement `shake-128` and `shake-256` multihashes\n- ~~Implement `Base32` encoding~~ waiting for https://github.com/jbenet/multihash/issues/31 to be resolved)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmseri%2Fcrypto-multihash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmseri%2Fcrypto-multihash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmseri%2Fcrypto-multihash/lists"}