A simple cross-compiled Clojure(Script) library to handle encoding binary data in different bases using defined alphabets. If you've ever wanted a simple way to encode a byte array as hexadecimal or base58, this library is for you!
Library releases are published on Clojars. To use the latest version with Leiningen, add the following dependency to your project definition:
alphabase.bytes
namespace for generic byte-array handlingalphabase.core
with arbitrary alphabet supportalphabase.hex
, alphabase.base32
, and alphabase.base58
=> (require '[alphabase.bytes :as b]
'[alphabase.base32 :as b32]
'[alphabase.base58 :as b58]
'[alphabase.hex :as hex])
=> (def data (b/random-bytes 32))
=> (hex/encode data)
"333a0fc9d17e07ff9a75afca02df9ab32fdb9eb71565e810e981773bdd1e0c90"
=> (b/bytes= data (hex/decode *1))
true
=> (b32/encode data)
"MZ2B7E5C7QH76NHLL6KALPZVMZP3OPLOFLF5AIOTALXHPOR4DEQ"
=> (b/bytes= data (b32/decode *1))
true
;; base32 is case-insensitive
=> (b/bytes= data (b32/decode (clojure.string/lower-case *2)))
true
=> (b58/encode data)
"4Sy9GnemD6QbtaLtVTkZsZeZXExFmvGk7dJy1gDnBJCF"
=> (b/bytes= data (b58/decode *1))
true
The unit tests can be run using the following commands:
# Clojure tests
lein clj:test
# ClojureScript tests on Node
lein cljs:test
For a REPL, you can use these:
# Clojure REPL
lein repl
# ClojureScript REPL
rlwrap lein cljs:repl
This is free and unencumbered software released into the public domain. See the UNLICENSE file for more information.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close