Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 0 additions & 60 deletions Data/CharMultibase.idr

This file was deleted.

113 changes: 0 additions & 113 deletions Data/Multibase.idr

This file was deleted.

46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Idris-multihash

Multihash implementation for Idris. It depends on the [idris-bytes](https://github.com/ziman/idris-bytes) library
[Multihash](https://github.com/multiformats/multihash/) implementation for Idris.

Using the [idris-bytes](https://github.com/ziman/idris-bytes) library you can encode and decode types using the
`IMultihash` interface.

## How to install

Expand Down Expand Up @@ -33,6 +36,43 @@ idris -p idris-multihash
The `Data.Multihash` import gives you access to the Multihash error type and to `decode` and
`encode` functions which manipulate `Bytes`

## API


You can use the `encode` and `decode` functions from the `IMultihash` interface provided you have an instance for your time.

The current implementation support encoding and decoding `Bytes`.

### Encoding

```idris
||| Encode a digest along with the hash algorithm that was used
decode : hash -> Either MultihashError (Multihash hash)
```

Implement this function in order to decode a `hash` type into a `Multihash`. `MultihashError` can be either `CodeNotFound` or `ParseErrro`.

### Decoding

```idris
||| Attempts to decode raw bytes into a multihash
encode : HashAlgorithm -> hash -> Multihash hash
```

Implement this function in order to encode a `hash` given a supported `HashAlgorithm`.

The supported list of hashes are listed in the definition of `HashAlgorithm`:

```idris
data HashAlgorithm
= SHA1
| SHA256
| SHA512
| SHA3
| BLAKE2B
| BLAKE2S
```

## Bytes dependency

Since Multihash depends on bytes you might want to use it as well. Head to the [idris-bytes](https://github.com/ziman/idris-bytes) library in order to get more info. To summarize:
Expand All @@ -41,3 +81,7 @@ Since Multihash depends on bytes you might want to use it as well. Head to the [
- Install it
- Add `import Data.Bytes` (and maybe `import Data.ByteArray`) at the top of your file
- run idris with `-p bytes` (typically `idris -p idris-multihash -p bytes`)


In the future it would be possible to avoid this dependency by exposing a `String` based API by default and the `Bytes`
API as an additional import