Skip to content

Commit

Permalink
example of using ex-multihash #8
Browse files Browse the repository at this point in the history
  • Loading branch information
RobStallion committed Jan 7, 2019
1 parent 3e8eb82 commit fc8c967
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 4 additions & 6 deletions lib/cid.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ defmodule Cid do
end

def make(input, length \\ 32) do
# dogma requires this extra line ... =(
hash = :crypto.hash(:sha512, input)
# so alpha numeric characters with UPPERCASE, lowercase and 0-9
# "ambiguous" chars are removed:
hash
hash1 = :crypto.hash(:sha512, input)
{:ok, <<_multihash_code, _length, hash2::binary>>} = Multihash.encode(:sha2_512, hash1)

hash2
|> Base.encode64()
|> String.replace(~r/[Il0oO=\/\+]/, "", global: true)
|> String.slice(0..(length - 1))
# |> String.length()
end

def stringify_map_values(input_map) do
Expand Down
3 changes: 1 addition & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ defmodule Rid.MixProject do
# Run "mix help deps" to learn about dependencies.
defp deps do
[
# {:dep_from_hexpm, "~> 0.3.0"},
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"},
{:ex_multihash, "~> 2.0"}
]
end
end
3 changes: 3 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
%{
"ex_multihash": {:hex, :ex_multihash, "2.0.0", "7fb36f842a2ec1c6bbba550f28fcd16d3c62981781b9466c9c1975c43d7db43c", [:mix], [], "hexpm"},
}

0 comments on commit fc8c967

Please sign in to comment.