From e8183f3a9ff0c3e33b009298480fe47a405caa40 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Wed, 30 Sep 2020 13:46:51 -0400 Subject: [PATCH] feat: use base32 + status infura ipfs for ens contenthash --- .gitmodules | 6 ++++++ src/app/provider/view.nim | 19 ++++++++++++++----- src/status/ens.nim | 2 +- vendor/nbaser | 1 + vendor/nim-base32 | 1 + 5 files changed, 23 insertions(+), 6 deletions(-) create mode 160000 vendor/nbaser create mode 160000 vendor/nim-base32 diff --git a/.gitmodules b/.gitmodules index 80ebcf3a87..af5c52aed7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -85,3 +85,9 @@ [submodule "vendor/nim-eth"] path = vendor/nim-eth url = https://github.com/status-im/nim-eth +[submodule "vendor/nbaser"] + path = vendor/nbaser + url = https://github.com/D-Nice/nbaser/ +[submodule "vendor/nim-base32"] + path = vendor/nim-base32 + url = https://github.com/elktree/nim-base32 diff --git a/src/app/provider/view.nim b/src/app/provider/view.nim index 43a06351de..99bf569421 100644 --- a/src/app/provider/view.nim +++ b/src/app/provider/view.nim @@ -5,14 +5,17 @@ import ../../status/libstatus/core import ../../status/libstatus/settings as status_settings import json, json_serialization, sets, strutils import chronicles +import nbaser +from base32 import nil const AUTH_METHODS = toHashSet(["eth_accounts", "eth_coinbase", "eth_sendTransaction", "eth_sign", "keycard_signTypedData", "eth_signTypedData", "personal_sign", "personal_ecRecover"]) const SIGN_METHODS = toHashSet(["eth_sendTransaction", "personal_sign", "eth_signTypedData", "eth_signTypedData_v3"]) const ACC_METHODS = toHashSet(["eth_accounts", "eth_coinbase"]) const IPFS_SCHEME = "https" -const IPFS_GATEWAY = "ipfs.status.im" -const IPFS_PATH_PREFIX = "/ipfs/" +const IPFS_GATEWAY = ".infura.status.im" + +const base58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" logScope: topics = "provider-view" @@ -165,15 +168,21 @@ QtObject: QtProperty[int] networkId: read = getNetworkId + proc toString(bytes: openarray[byte]): string = + result = newString(bytes.len) + copyMem(result[0].addr, bytes[0].unsafeAddr, bytes.len) + proc ensResourceURL*(self: Web3ProviderView, ens: string, url: string): string {.slot.} = # TODO: add support for swarm: "swarm-gateways.net/bzz:/...." and ipns let contentHash = contenthash(ens) - if contentHash == "0x": # ENS does not have a content hash + if contentHash == "": # ENS does not have a content hash return url_replaceHostAndAddPath(url, IPFS_SCHEME, url_host(url), "") - let path = IPFS_PATH_PREFIX & contentHash.decodeContentHash() & "/" - result = url_replaceHostAndAddPath(url, IPFS_SCHEME, IPFS_GATEWAY, path) + let decodedContentHash = contentHash.decodeContentHash() + let base32Hash = base32.encode(base58.decode(decodedContentHash).toString()).toLowerAscii().replace("=", "") + result = url_replaceHostAndAddPath(url, IPFS_SCHEME, base32Hash & IPFS_GATEWAY) + proc getHost*(self: Web3ProviderView, url: string): string {.slot.} = result = url_host(url) diff --git a/src/status/ens.nim b/src/status/ens.nim index 09932e1984..674ecd55b5 100644 --- a/src/status/ens.nim +++ b/src/status/ens.nim @@ -141,7 +141,7 @@ proc contenthash*(ensAddr: string): string = let response = callPrivateRPC("eth_call", payload) let bytesResponse = response.parseJson["result"].getStr; if bytesResponse == "0x": - return "0x" + return "" let size = fromHex(Stuint[256], bytesResponse[66..129]).toInt result = bytesResponse[130..129+size*2] diff --git a/vendor/nbaser b/vendor/nbaser new file mode 160000 index 0000000000..0c989e0d95 --- /dev/null +++ b/vendor/nbaser @@ -0,0 +1 @@ +Subproject commit 0c989e0d9580b4a6c14e11976dba3a0d503ecfcd diff --git a/vendor/nim-base32 b/vendor/nim-base32 new file mode 160000 index 0000000000..660680c1cb --- /dev/null +++ b/vendor/nim-base32 @@ -0,0 +1 @@ +Subproject commit 660680c1cbdf6b1294b669fdb8b6e9c89794cb5b