Skip to content

Commit 23214a7

Browse files
borkdudeSohaltmk
authored
Move from multihash to multiformats library (#418)
And bump cas-client to nextjournal/cas-client@4eefd77 (which is also using multihash). Fixes #417. Co-authored-by: Paolo Holinski <[email protected]> Co-authored-by: Martin Kavalar <[email protected]>
1 parent c6dde30 commit 23214a7

File tree

5 files changed

+22
-24
lines changed

5 files changed

+22
-24
lines changed

bb.edn

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{:min-bb-version "0.9.159"
22
:paths ["bb"]
33
:deps {io.github.nextjournal/dejavu {:git/sha "4980e0cc18c9b09fb220874ace94ba6b57a749ca"}
4-
io.github.nextjournal/cas-client {:git/sha "534d8c6679cc005fd9ad99cfe3d5aeaa6411aee8"}
5-
mvxcvi/multihash {:git/url "https://github.com/borkdude/clj-multihash"
6-
:git/sha "7cd4d1fc1301aeea36d5ba80e65ebe2fdbaaa392"}}
4+
io.github.nextjournal/cas-client {:git/sha "4eefd77dd981b908591d91d518ba3f43bd8c361e"}}
75
:tasks
86
{:requires
97
([tasks :as t]

deps.edn

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
io.github.nextjournal/dejavu {:git/sha "4980e0cc18c9b09fb220874ace94ba6b57a749ca"}
1414

1515
com.taoensso/nippy {:mvn/version "3.2.0"}
16-
mvxcvi/multihash {:mvn/version "2.0.3"}
17-
javax.xml.bind/jaxb-api {:mvn/version "2.3.1"} ;; needed to make multihash work on JDK11+
16+
17+
mvxcvi/multiformats {:mvn/version "0.2.1"}
1818
com.pngencoder/pngencoder {:mvn/version "0.13.1"}
1919

2020
http-kit/http-kit {:mvn/version "2.6.0"}
@@ -41,7 +41,7 @@
4141
binaryage/devtools {:mvn/version "1.0.3"}
4242
cider/cider-nrepl {:mvn/version "0.29.0"}
4343
com.clojure-goes-fast/clj-async-profiler {:mvn/version "1.0.3"}
44-
io.github.nextjournal/cas-client {:git/sha "534d8c6679cc005fd9ad99cfe3d5aeaa6411aee8"}
44+
io.github.nextjournal/cas-client {:git/sha "4eefd77dd981b908591d91d518ba3f43bd8c361e"}
4545
org.slf4j/slf4j-nop {:mvn/version "1.7.36"}
4646
org.babashka/cli {:mvn/version "0.5.40"}}
4747
:extra-paths ["dev" "notebooks"]
@@ -70,9 +70,10 @@
7070
io.github.nextjournal/clerk-slideshow {:git/sha "5fe197ca0c8f28128379849dc677cd718be71524"}}}
7171

7272
:build {:deps {io.github.nextjournal/clerk {:local/root "."}
73-
io.github.nextjournal/cas-client {:git/sha "534d8c6679cc005fd9ad99cfe3d5aeaa6411aee8"}
73+
;; :exclusions needed until https://github.com/greglook/clj-multiformats/pull/2 is merged
74+
io.github.nextjournal/cas-client {:git/sha "4eefd77dd981b908591d91d518ba3f43bd8c361e"
75+
:exclusions [mvxcvi/multiformats]}
7476
io.github.clojure/tools.build {:git/tag "v0.6.1" :git/sha "515b334"}
75-
io.github.slipset/deps-deploy {:git/sha "b4359c5d67ca002d9ed0c4b41b710d7e5a82e3bf"}
76-
mvxcvi/multihash {:mvn/version "2.0.3"}}
77+
io.github.slipset/deps-deploy {:git/sha "b4359c5d67ca002d9ed0c4b41b710d7e5a82e3bf"}}
7778
:extra-paths ["bb" "src" "resources"] ;; for loading lookup-url in build
7879
:ns-default build}}}

src/nextjournal/clerk/analyzer.clj

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
[clojure.tools.analyzer.ast :as ana-ast]
1313
[clojure.tools.analyzer.jvm :as ana-jvm]
1414
[clojure.tools.analyzer.utils :as ana-utils]
15-
[multihash.core :as multihash]
16-
[multihash.digest :as digest]
15+
[multiformats.base.b58 :as b58]
16+
[multiformats.hash :as hash]
1717
[nextjournal.clerk.parser :as parser]
1818
[nextjournal.clerk.classpath :as cp]
1919
[nextjournal.clerk.config :as config]
@@ -46,7 +46,10 @@
4646
#_(no-cache? '^{:nextjournal.clerk/no-cache false} (def ^:nextjournal.clerk/no-cache my-rand (rand-int 10)))
4747

4848
(defn sha1-base58 [s]
49-
(-> s digest/sha1 multihash/base58))
49+
(->> s hash/sha1 hash/encode b58/format-btc))
50+
51+
(defn sha2-base58 [s]
52+
(->> s hash/sha2-512 hash/encode b58/format-btc))
5053

5154
#_(sha1-base58 "hello")
5255

@@ -265,7 +268,7 @@
265268
(let [id->count @!id->count
266269
id (if var
267270
var
268-
(let [hash-fn #(-> % nippy/fast-freeze digest/sha1 multihash/base58)]
271+
(let [hash-fn #(-> % nippy/fast-freeze sha1-base58)]
269272
(symbol (str *ns*)
270273
(case type
271274
:code (str "anon-expr-" (hash-fn (cond-> form (instance? clojure.lang.IObj form) (with-meta {}))))
@@ -587,12 +590,11 @@
587590
([value] (valuehash :sha512 value))
588591
([hash-type value]
589592
(let [digest-fn (case hash-type
590-
:sha1 digest/sha1
591-
:sha512 digest/sha2-512)]
593+
:sha1 sha1-base58
594+
:sha512 sha2-base58)]
592595
(-> value
593596
nippy/fast-freeze
594-
digest-fn
595-
multihash/base58))))
597+
digest-fn))))
596598

597599
#_(valuehash (range 100))
598600
#_(valuehash :sha1 (range 100))

src/nextjournal/clerk/eval.clj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
[clojure.java.io :as io]
55
[clojure.main :as main]
66
[clojure.string :as str]
7-
[multihash.core :as multihash]
8-
[multihash.digest :as digest]
7+
[multiformats.base.b58 :as b58]
98
[nextjournal.clerk.analyzer :as analyzer]
109
[nextjournal.clerk.config :as config]
1110
[nextjournal.clerk.parser :as parser]
@@ -32,13 +31,13 @@
3231

3332
(defn wrapped-with-metadata [value hash]
3433
(cond-> {:nextjournal/value value}
35-
hash (assoc :nextjournal/blob-id (cond-> hash (not (string? hash)) multihash/base58))))
34+
hash (assoc :nextjournal/blob-id (cond-> hash (not (string? hash)) b58/format-btc))))
3635

3736
#_(wrap-with-blob-id :test "foo")
3837

3938
(defn hash+store-in-cas! [x]
4039
(let [^bytes ba (nippy/freeze x)
41-
multihash (multihash/base58 (digest/sha2-512 ba))
40+
multihash (analyzer/sha2-base58 ba)
4241
file (->cache-file multihash)]
4342
(when-not (fs/exists? file)
4443
(with-open [out (io/output-stream (io/file file))]

src/nextjournal/clerk/viewer.cljc

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
#?@(:clj [[babashka.fs :as fs]
88
[clojure.repl :refer [demunge]]
99
[editscript.edit]
10-
[multihash.core :as multihash]
11-
[multihash.digest :as digest]
1210
[nextjournal.clerk.config :as config]
1311
[nextjournal.clerk.analyzer :as analyzer]]
1412
:cljs [[goog.crypt]
@@ -406,7 +404,7 @@
406404
#?(:clj
407405
(defn store+get-cas-url! [{:keys [out-path ext]} content]
408406
(assert out-path) (assert ext)
409-
(let [cas-url (str "_data/" (multihash/base58 (digest/sha2-512 content)) "." ext)
407+
(let [cas-url (str "_data/" (analyzer/sha2-base58 content) "." ext)
410408
cas-path (fs/path out-path cas-url)]
411409
(fs/create-dirs (fs/parent cas-path))
412410
(when-not (fs/exists? cas-path)

0 commit comments

Comments
 (0)