feat: resolve ens addresses pointing to IPFS
This commit is contained in:
parent
f85216e7f7
commit
ca2fef7c28
|
@ -1,5 +1,5 @@
|
|||
import NimQml
|
||||
import ../../status/status
|
||||
import ../../status/[status, ens, chat/stickers]
|
||||
import ../../status/libstatus/types
|
||||
import ../../status/libstatus/core
|
||||
import ../../status/libstatus/settings as status_settings
|
||||
|
@ -10,6 +10,10 @@ const AUTH_METHODS = toHashSet(["eth_accounts", "eth_coinbase", "eth_sendTransac
|
|||
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/"
|
||||
|
||||
logScope:
|
||||
topics = "provider-view"
|
||||
|
||||
|
@ -159,4 +163,17 @@ QtObject:
|
|||
proc getNetworkId*(self: Web3ProviderView): int {.slot.} = getCurrentNetworkDetails().config.networkId
|
||||
|
||||
QtProperty[int] networkId:
|
||||
read = getNetworkId
|
||||
read = getNetworkId
|
||||
|
||||
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
|
||||
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)
|
||||
|
||||
proc getHost*(self: Web3ProviderView, url: string): string {.slot.} =
|
||||
result = url_host(url)
|
||||
|
|
|
@ -127,6 +127,26 @@ proc address*(username: string): string =
|
|||
return ""
|
||||
result = "0x" & address.substr(26)
|
||||
|
||||
const contenthash_signature = "0xbc1c58d1" # contenthash(bytes32)
|
||||
proc contenthash*(ensAddr: string): string =
|
||||
var ensHash = namehash(ensAddr)
|
||||
ensHash.removePrefix("0x")
|
||||
let ensResolver = resolver(ensHash)
|
||||
let payload = %* [{
|
||||
"to": ensResolver,
|
||||
"from": "0x0000000000000000000000000000000000000000",
|
||||
"data": fmt"{contenthash_signature}{ensHash}"
|
||||
}, "latest"]
|
||||
|
||||
let response = callPrivateRPC("eth_call", payload)
|
||||
let bytesResponse = response.parseJson["result"].getStr;
|
||||
if bytesResponse == "0x":
|
||||
return "0x"
|
||||
|
||||
let size = fromHex(Stuint[256], bytesResponse[66..129]).toInt
|
||||
result = bytesResponse[130..129+size*2]
|
||||
|
||||
|
||||
proc getPrice*(): Stuint[256] =
|
||||
let
|
||||
contract = contracts.getContract("ens-usernames")
|
||||
|
|
|
@ -25,11 +25,19 @@ Item {
|
|||
Layout.fillHeight: true
|
||||
Layout.fillWidth: true
|
||||
|
||||
function determineRealURL(text){
|
||||
var url = utilsModel.urlFromUserInput(text);
|
||||
var host = web3Provider.getHost(url);
|
||||
if(host.endsWith(".eth")){
|
||||
url = web3Provider.ensResourceURL(host, url);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
property Component accessDialogComponent: ModalPopup {
|
||||
id: accessDialog
|
||||
|
||||
property var request: {"hostname": "", "permission": ""}
|
||||
property var request: {"hostname": "", "title": "", "permission": ""}
|
||||
|
||||
function postMessage(isAllowed){
|
||||
request.isAllowed = isAllowed;
|
||||
|
@ -44,17 +52,26 @@ Item {
|
|||
|
||||
StyledText {
|
||||
id: siteName
|
||||
text: request.hostname
|
||||
text: request.title
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: Style.current.padding
|
||||
width: parent.width
|
||||
wrapMode: Text.WordWrap
|
||||
}
|
||||
|
||||
StyledText {
|
||||
id: hostName
|
||||
text: request.hostname
|
||||
anchors.top: siteName.bottom
|
||||
anchors.topMargin: Style.current.padding
|
||||
width: parent.width
|
||||
wrapMode: Text.WordWrap
|
||||
}
|
||||
|
||||
StyledText {
|
||||
id: permission
|
||||
text: qsTr("Permission requested: %1").arg(request.permission)
|
||||
anchors.top: siteName.bottom
|
||||
anchors.top: hostName.bottom
|
||||
anchors.topMargin: Style.current.padding
|
||||
width: parent.width
|
||||
wrapMode: Text.WordWrap
|
||||
|
@ -369,7 +386,7 @@ Item {
|
|||
Keys.onPressed: {
|
||||
// TODO: disable browsing local files? file://
|
||||
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return){
|
||||
currentWebView.url = utilsModel.urlFromUserInput(text);
|
||||
currentWebView.url = determineRealURL(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -493,8 +510,8 @@ Item {
|
|||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
Component.onCompleted: {
|
||||
var tab = createEmptyTab(defaultProfile)
|
||||
tab.item.url = "https://status-im.github.io/dapp"
|
||||
var tab = createEmptyTab(defaultProfile);
|
||||
tab.item.url = determineRealURL("https://simpledapp.eth");
|
||||
}
|
||||
|
||||
// Add custom tab view style so we can customize the tabs to include a close button
|
||||
|
|
|
@ -849,7 +849,8 @@ You may add additional accurate notices of copyright ownership.
|
|||
});
|
||||
|
||||
const bridgeSend = data => {
|
||||
data.hostname = new URL(document.location).host
|
||||
data.hostname = new URL(document.location).host;
|
||||
data.title = document.title;
|
||||
backend.postMessage(JSON.stringify(data));
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 89d18b95c69b353ab33715caaf1699bc9fd0b26e
|
||||
Subproject commit 8a1478aab71e6c8840f19e0bf112393edfb7eeae
|
|
@ -1 +1 @@
|
|||
Subproject commit f1950c5d920860d9f2d0c86b7e4b7f022e32ae5b
|
||||
Subproject commit 2a1cc508b1cee4f80a310495998fc70288d8ed59
|
Loading…
Reference in New Issue