diff --git a/src/status_im/ethereum/ens.cljs b/src/status_im/ethereum/ens.cljs index 753d2374f9..19cb86654d 100644 --- a/src/status_im/ethereum/ens.cljs +++ b/src/status_im/ethereum/ens.cljs @@ -7,7 +7,8 @@ (:refer-clojure :exclude [name]) (:require [clojure.string :as string] [status-im.ethereum.core :as ethereum] - [status-im.ethereum.json-rpc :as json-rpc])) + [status-im.ethereum.json-rpc :as json-rpc] + [status-im.ethereum.abi-spec :as abi-spec])) ;; this is the addresses of ens registries for the different networks (def ens-registries @@ -105,10 +106,21 @@ :on-success (fn [raw-hash] ;; NOTE: it would be better if our abi-spec/decode was able to do that - (let [hash (subs raw-hash 130) - [cid & hash-and-zeros] (string/split hash "1b20") - hash (str "0x" cid "1b20" (subs (apply str hash-and-zeros) 0 64))] - (cb hash)))})) + (let [;; ignore hex prefix + [_ raw-hash-rest] (split-at 2 raw-hash) + ;; the first field gives us the length of the next one in hex and has + ;; a length of 32 bytes + ;; 1 byte is 2 chars here + [next-field-length-hex raw-hash-rest] (split-at 64 raw-hash-rest) + next-field-length (* ^number (abi-spec/hex-to-number (string/join next-field-length-hex)) 2) + ;; we get the next field which is the length of the hash and is + ;; expected to be 32 bytes as well + [hash-field-length-hex raw-hash-rest] (split-at next-field-length + raw-hash-rest) + hash-field-length (* ^number (abi-spec/hex-to-number (string/join hash-field-length-hex)) 2) + ;; we get the hash + [hash _] (split-at hash-field-length raw-hash-rest)] + (cb (string/join "0x" hash))))})) (defn content [resolver ens-name cb] diff --git a/src/status_im/utils/contenthash.cljs b/src/status_im/utils/contenthash.cljs index 5e6e466a3e..df19be36a3 100644 --- a/src/status_im/utils/contenthash.cljs +++ b/src/status_im/utils/contenthash.cljs @@ -32,10 +32,9 @@ (cond (and (string/starts-with? hex "0xe40101")) ;; content type can be 2 or 4 bytes - ;; we expect 1b20 (hash algorithm and hash length 64) + ;; we expect 1b20 (hash algorithm keccak256 and hash length 64) ;; before the hash so we split the contenthash there (when-let [hash (second (string/split hex "1b20"))] - (when (= 0x20 (count hash))) {:namespace :swarm :hash hash}) (and (= 78 (count hex))