fix(browser-provider): fix browser provider not asking for authorization
Fixes #4721
This commit is contained in:
parent
268d7fcd36
commit
d4410c1aa7
|
@ -1,4 +1,4 @@
|
|||
import tables
|
||||
import strutils
|
||||
import controller_interface
|
||||
import io_interface
|
||||
|
||||
|
@ -45,7 +45,7 @@ method disconnect*(self: Controller) =
|
|||
discard self.dappPermissionsService.revoke("web3".toPermission())
|
||||
|
||||
method postMessage*(self: Controller, requestType: string, message: string): string =
|
||||
return self.providerService.postMessage(requestType, message)
|
||||
return self.providerService.postMessage(parseEnum[RequestTypes](requestType), message)
|
||||
|
||||
method hasPermission*(self: Controller, hostname: string, permission: string): bool =
|
||||
return self.dappPermissionsService.hasPermission(hostname, permission.toPermission())
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
import json
|
||||
import ../dapp_permissions/service as dapp_permissions_service
|
||||
|
||||
const HTTPS_SCHEME* = "https"
|
||||
const IPFS_GATEWAY* = ".infura.status.im"
|
||||
const SWARM_GATEWAY* = "swarm-gateways.net"
|
||||
|
||||
type
|
||||
RequestTypes* {.pure.} = enum
|
||||
Web3SendAsyncReadOnly = "web3-send-async-read-only",
|
||||
HistoryStateChanged = "history-state-changed",
|
||||
APIRequest = "api-request"
|
||||
Unknown = "unknown"
|
||||
|
||||
ResponseTypes* {.pure.} = enum
|
||||
Web3SendAsyncCallback = "web3-send-async-callback",
|
||||
APIResponse = "api-response",
|
||||
Web3ResponseError = "web3-response-error"
|
||||
|
||||
type
|
||||
Payload* = ref object
|
||||
id*: JsonNode
|
||||
rpcMethod*: string
|
||||
|
||||
Web3SendAsyncReadOnly* = ref object
|
||||
messageId*: JsonNode
|
||||
payload*: Payload
|
||||
request*: string
|
||||
hostname*: string
|
||||
|
||||
APIRequest* = ref object
|
||||
isAllowed*: bool
|
||||
messageId*: JsonNode
|
||||
permission*: Permission
|
||||
hostname*: string
|
|
@ -21,39 +21,6 @@ export service_interface
|
|||
logScope:
|
||||
topics = "provider-service"
|
||||
|
||||
const HTTPS_SCHEME* = "https"
|
||||
const IPFS_GATEWAY* = ".infura.status.im"
|
||||
const SWARM_GATEWAY* = "swarm-gateways.net"
|
||||
|
||||
type
|
||||
RequestTypes {.pure.} = enum
|
||||
Web3SendAsyncReadOnly = "web3-send-async-read-only",
|
||||
HistoryStateChanged = "history-state-changed",
|
||||
APIRequest = "api-request"
|
||||
Unknown = "unknown"
|
||||
|
||||
ResponseTypes {.pure.} = enum
|
||||
Web3SendAsyncCallback = "web3-send-async-callback",
|
||||
APIResponse = "api-response",
|
||||
Web3ResponseError = "web3-response-error"
|
||||
|
||||
type
|
||||
Payload = ref object
|
||||
id: JsonNode
|
||||
rpcMethod: string
|
||||
|
||||
Web3SendAsyncReadOnly = ref object
|
||||
messageId: JsonNode
|
||||
payload: Payload
|
||||
request: string
|
||||
hostname: string
|
||||
|
||||
APIRequest = ref object
|
||||
isAllowed: bool
|
||||
messageId: JsonNode
|
||||
permission: Permission
|
||||
hostname: string
|
||||
|
||||
const AUTH_METHODS = toHashSet(["eth_accounts", "eth_coinbase", "eth_sendTransaction", "eth_sign", "keycard_signTypedData", "eth_signTypedData", "eth_signTypedData_v3", "personal_sign", "personal_ecRecover"])
|
||||
const SIGN_METHODS = toHashSet(["eth_sign", "personal_sign", "eth_signTypedData", "eth_signTypedData_v3"])
|
||||
const ACC_METHODS = toHashSet(["eth_accounts", "eth_coinbase"])
|
||||
|
@ -289,8 +256,8 @@ proc process(self: Service, data: APIRequest): string =
|
|||
"data": value
|
||||
}
|
||||
|
||||
method postMessage*(self: Service, message: string): string =
|
||||
case message.requestType():
|
||||
method postMessage*(self: Service, requestType: RequestTypes, message: string): string =
|
||||
case requestType:
|
||||
of RequestTypes.Web3SendAsyncReadOnly: self.process(message.toWeb3SendAsyncReadOnly())
|
||||
of RequestTypes.HistoryStateChanged: """{"type":"TODO-IMPLEMENT-THIS"}""" ############# TODO:
|
||||
of RequestTypes.APIRequest: self.process(message.toAPIRequest())
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
import dto
|
||||
export dto
|
||||
|
||||
type
|
||||
ServiceInterface* {.pure inheritable.} = ref object of RootObj
|
||||
## Abstract class for this service access.
|
||||
|
@ -8,7 +11,7 @@ method delete*(self: ServiceInterface) {.base.} =
|
|||
method init*(self: ServiceInterface) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method postMessage*(self: ServiceInterface, requestType: string, message: string): string {.base.} =
|
||||
method postMessage*(self: ServiceInterface, requestType: RequestTypes, message: string): string {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method ensResourceURL*(self: ServiceInterface, ens: string, url: string): (string, string, string, string, bool) =
|
||||
|
|
|
@ -33,7 +33,7 @@ StatusModal {
|
|||
interactedWith = true
|
||||
request.isAllowed = isAllowed;
|
||||
RootStore.currentTabConnected = isAllowed
|
||||
web3Response(Web3ProviderStore.web3ProviderInst.postMessage(JSON.stringify(request)))
|
||||
web3Response(Web3ProviderStore.web3ProviderInst.postMessage(Constants.api_request, JSON.stringify(request)))
|
||||
}
|
||||
|
||||
onClosed: {
|
||||
|
|
|
@ -27,7 +27,7 @@ QtObject {
|
|||
return RootStore.getAscii2Hex(input)
|
||||
}
|
||||
|
||||
function postMessage(data) {
|
||||
function postMessage(requestType, data) {
|
||||
var request;
|
||||
try {
|
||||
request = JSON.parse(data)
|
||||
|
@ -41,7 +41,7 @@ QtObject {
|
|||
request.hostname = ensAddr;
|
||||
}
|
||||
|
||||
if (request.type === Constants.api_request) {
|
||||
if (requestType === Constants.api_request) {
|
||||
if (!Web3ProviderStore.web3ProviderInst.hasPermission(request.hostname, request.permission)) {
|
||||
RootStore.currentTabConnected = false
|
||||
var dialog = createAccessDialogComponent()
|
||||
|
@ -49,15 +49,15 @@ QtObject {
|
|||
dialog.open();
|
||||
} else {
|
||||
RootStore.currentTabConnected = true
|
||||
request.isAllowed = true;
|
||||
web3Response(Web3ProviderStore.web3ProviderInst.postMessage(JSON.stringify(request)));
|
||||
request.isAllowed = true
|
||||
web3Response(Web3ProviderStore.web3ProviderInst.postMessage(requestType, JSON.stringify(request)));
|
||||
}
|
||||
} else if (request.type === Constants.web3SendAsyncReadOnly &&
|
||||
} else if (requestType === Constants.web3SendAsyncReadOnly &&
|
||||
request.payload.method === "eth_sendTransaction") {
|
||||
var acc = WalletStore.dappBrowserAccount
|
||||
const value = RootStore.getWei2Eth(request.payload.params[0].value, 18);
|
||||
const sendDialog = createSendTransactionModalComponent(request)
|
||||
|
||||
// TODO change sendTransaction function to the postMessage one
|
||||
sendDialog.sendTransaction = function (selectedGasLimit, selectedGasPrice, selectedTipLimit, selectedOverallLimit, enteredPassword) {
|
||||
request.payload.selectedGasLimit = selectedGasLimit
|
||||
request.payload.selectedGasPrice = selectedGasPrice
|
||||
|
@ -66,7 +66,7 @@ QtObject {
|
|||
request.payload.password = enteredPassword
|
||||
request.payload.params[0].value = value
|
||||
|
||||
const response = Web3ProviderStore.web3ProviderInst.postMessage(JSON.stringify(request))
|
||||
const response = Web3ProviderStore.web3ProviderInst.postMessage(requestType, JSON.stringify(request))
|
||||
provider.web3Response(response)
|
||||
|
||||
let responseObj
|
||||
|
@ -76,6 +76,7 @@ QtObject {
|
|||
if (responseObj.error) {
|
||||
throw new Error(responseObj.error)
|
||||
}
|
||||
|
||||
showToastMessage(responseObj.result.result)
|
||||
} catch (e) {
|
||||
if (Utils.isInvalidPasswordMessage(e.message)){
|
||||
|
@ -92,7 +93,7 @@ QtObject {
|
|||
|
||||
sendDialog.open();
|
||||
WalletStore.getGasPrice()
|
||||
} else if (request.type === Constants.web3SendAsyncReadOnly && ["eth_sign", "personal_sign", "eth_signTypedData", "eth_signTypedData_v3"].indexOf(request.payload.method) > -1) {
|
||||
} else if (requestType === Constants.web3SendAsyncReadOnly && ["eth_sign", "personal_sign", "eth_signTypedData", "eth_signTypedData_v3"].indexOf(request.payload.method) > -1) {
|
||||
const signDialog = createSignMessageModalComponent(request)
|
||||
signDialog.web3Response = web3Response
|
||||
signDialog.signMessage = function (enteredPassword) {
|
||||
|
@ -104,12 +105,12 @@ QtObject {
|
|||
case Constants.eth_sign:
|
||||
request.payload.params[1] = signValue(request.payload.params[1]);
|
||||
}
|
||||
const response = Web3ProviderStore.web3ProviderInst.postMessage(JSON.stringify(request));
|
||||
const response = Web3ProviderStore.web3ProviderInst.postMessage(requestType, JSON.stringify(request));
|
||||
provider.web3Response(response);
|
||||
try {
|
||||
let responseObj = JSON.parse(response)
|
||||
if (responseObj.error) {
|
||||
throw new Error(responseObj.error)
|
||||
throw new Error(responseObj.error.message)
|
||||
}
|
||||
} catch (e) {
|
||||
if (Utils.isInvalidPasswordMessage(e.message)){
|
||||
|
@ -128,7 +129,7 @@ QtObject {
|
|||
} else if (request.type === Constants.web3DisconnectAccount) {
|
||||
web3Response(data);
|
||||
} else {
|
||||
web3Response(Web3ProviderStore.web3ProviderInst.postMessage(data));
|
||||
web3Response(Web3ProviderStore.web3ProviderInst.postMessage(requestType, data));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue