Mastering Bitcoin chapter 4 - 04 Address from public key

{:deps {org.clojure/clojure {:mvn/version "1.11.1"}
        base58 {:git/url "https://github.com/fjsousa/base58"
                :sha "807fba7f9f38175531be81c4f4c4a682fc380433"}
        buddy/buddy-core {:mvn/version "1.10.413"}
        org.bouncycastle/bcprov-jdk15on {:mvn/version "1.70"}
        ;; complient is used for autocompletion
        ;; add your libs here (and restart the runtime to pick up changes)
        compliment/compliment {:mvn/version "0.3.9"}}}
Extensible Data Notation
(ns adress-from-public-key
  (:require
   [buddy.core.hash :as hash]
   [buddy.core.codecs :as codecs]
   [base58.core :as base58])
  (:import java.math.BigInteger
   [org.bouncycastle.jce ECNamedCurveTable]))
1.3s

Using public key from previous notebook:

(def public-key
  (str
    "04"
    "F028892BAD7ED57D2FB57BF33081D5CFCF6F9ED3D3D7F159C2E2FFF579DC341A"
    "07CF33DA18BD734C600B96A72BBC4749D5141C90EC8AC328AE52DDFE2E505BDB"))
0.1s

Follow this algorithm:

(def public-key-hash
  (->>
  public-key
  codecs/hex->bytes
  hash/sha256
  hash/ripemd160
  codecs/bytes->hex
  (str "00")))
0.0s
(def bitcoin-address
  (base58/encode (codecs/hex->bytes public-key-hash)))
0.0s
0.0s

Runtimes (1)