From 80eeca19516d3c96aa1ed29d5ac852a28d77c966 Mon Sep 17 00:00:00 2001 From: andrey Date: Tue, 1 Sep 2020 14:24:20 +0200 Subject: [PATCH] [#10974] ENS resolving for IPNS names. --- src/status_im/browser/core.cljs | 13 ++++++------- src/status_im/utils/contenthash.cljs | 26 +++++++++++++------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/status_im/browser/core.cljs b/src/status_im/browser/core.cljs index 4177a4d52dcc..5782bd882ad5 100644 --- a/src/status_im/browser/core.cljs +++ b/src/status_im/browser/core.cljs @@ -24,9 +24,7 @@ [status-im.multiaccounts.update.core :as multiaccounts.update] [status-im.ui.components.bottom-sheet.core :as bottom-sheet] [status-im.browser.webview-ref :as webview-ref] - [alphabase.base58 :as alphabase.base58] - ["eth-phishing-detect" :as eth-phishing-detect] - ["hi-base32" :as hi-base32])) + ["eth-phishing-detect" :as eth-phishing-detect])) (fx/defn update-browser-option [{:keys [db]} option-key option-value] @@ -170,12 +168,13 @@ (defmulti storage-gateway :namespace) +(defmethod storage-gateway :ipns + [{:keys [hash]}] + hash) + (defmethod storage-gateway :ipfs [{:keys [hash]}] - (let [base32hash (-> (.encode ^js hi-base32 (alphabase.base58/decode hash)) - (string/replace #"=" "") - (string/lower-case))] - (str base32hash ".infura.status.im"))) + (str hash ".ipfs.cf-ipfs.com")) (defmethod storage-gateway :swarm [{:keys [hash]}] diff --git a/src/status_im/utils/contenthash.cljs b/src/status_im/utils/contenthash.cljs index df19be36a353..3ed2d795bdcc 100644 --- a/src/status_im/utils/contenthash.cljs +++ b/src/status_im/utils/contenthash.cljs @@ -3,6 +3,7 @@ implementing swarm and other protocols will come later" (:refer-clojure :exclude [cat]) (:require [alphabase.base58 :as b58] + ["hi-base32" :as hi-base32] [alphabase.hex :as hex] [clojure.string :as string] [status-im.ethereum.core :as ethereum] @@ -39,25 +40,24 @@ :hash hash}) (and (= 78 (count hex)) (string/starts-with? hex "0xe3010170")) - ;; for retrocompatibility with old CIDv0 {:namespace :ipfs + :hash (str "b" (-> hex + (subs 6) + hex/decode + ((fn [v] (.encode ^js hi-base32 v))) + (string/replace #"=" "") + string/lower-case))} + (and (string/starts-with? hex "0xe50101700")) + {:namespace :ipns :hash (-> hex - (subs 10) - hex/decode - b58/encode)} - (and (= 78 (count hex)) - (string/starts-with? hex "0xe30101")) - ;; new CIDv1 - {:namespace :ipfs - :hash (str "z" (-> hex - (subs 6) - hex/decode - b58/encode))}))) + (subs 14) + ((fn [v] (str "0x" v))) + (ethereum/hex-to-utf8))}))) (defn url-fn [hex] (let [{:keys [namespace hash]} (decode (ethereum/normalized-hex hex))] (case namespace - :ipfs (str "https://ipfs.infura.io/ipfs/" hash) + :ipfs (str "https://" hash ".ipfs.cf-ipfs.com") ""))) (def url (memoize url-fn))