From 4068b3cabedc937339c1aadaec4b8fad8620a660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDiga=20Kokelj?= Date: Tue, 19 Sep 2023 13:27:46 +0200 Subject: [PATCH] Fix --- tools/walletextension/api/staticOG/index.html | 5 ++- .../api/staticOG/javascript.js | 17 ++----- tools/walletextension/common/constants.go | 44 +++++++++---------- .../test/wallet_extension_test.go | 11 ++--- tools/walletextension/wallet_extension.go | 2 +- 5 files changed, 34 insertions(+), 45 deletions(-) diff --git a/tools/walletextension/api/staticOG/index.html b/tools/walletextension/api/staticOG/index.html index a0d5c0730c..c1b9e7df7c 100644 --- a/tools/walletextension/api/staticOG/index.html +++ b/tools/walletextension/api/staticOG/index.html @@ -4,7 +4,10 @@ Obscuro Gateway - + diff --git a/tools/walletextension/api/staticOG/javascript.js b/tools/walletextension/api/staticOG/javascript.js index c088431496..41e14e462f 100644 --- a/tools/walletextension/api/staticOG/javascript.js +++ b/tools/walletextension/api/staticOG/javascript.js @@ -117,20 +117,9 @@ function getRandomIntAsString(min, max) { async function getUserID() { - try { - const account = await requestAccounts(); // Request user accounts - if (account) { // Check if user granted permission - // call getStorageAt for 0x0 address and random value (to prevent MetaMask from caching requests) - const storageValue = await ethereum.request({ - method: 'eth_getStorageAt', - params: ["0x0000000000000000000000000000000000000000", getRandomIntAsString(0, 1000000)], - }); - return storageValue; - } - } catch (error) { - return "" - } - return "" + const provider = new ethers.providers.Web3Provider(window.ethereum); + const userID = await provider.send('eth_getStorageAt', ["getUserID", getRandomIntAsString(0, 1000)]) + return userID } async function requestAccounts() { diff --git a/tools/walletextension/common/constants.go b/tools/walletextension/common/constants.go index 0e183d0442..0d57916901 100644 --- a/tools/walletextension/common/constants.go +++ b/tools/walletextension/common/constants.go @@ -27,28 +27,28 @@ const ( ) const ( - PathRoot = "/" - PathReady = "/ready/" - PathViewingKeys = "/viewingkeys/" - PathGenerateViewingKey = "/generateviewingkey/" - PathSubmitViewingKey = "/submitviewingkey/" - PathJoin = "/join/" - PathAuthenticate = "/authenticate/" - PathQuery = "/query/" - PathRevoke = "/revoke/" - PathObscuroGateway = "/" - PathHealth = "/health/" - WSProtocol = "ws://" - DefaultUser = "defaultUser" - UserQueryParameter = "u" - AddressQueryParameter = "a" - MessageFormatRegex = `^Register\s(\w+)\sfor\s(\w+)$` - MessageUserIDLen = 64 - SignatureLen = 65 - PersonalSignMessagePrefix = "\x19Ethereum Signed Message:\n%d%s" - GetStorageAtUserIDRequestAddress = "0x0000000000000000000000000000000000000000" - SuccessMsg = "success" - APIVersion1 = "/v1" + PathRoot = "/" + PathReady = "/ready/" + PathViewingKeys = "/viewingkeys/" + PathGenerateViewingKey = "/generateviewingkey/" + PathSubmitViewingKey = "/submitviewingkey/" + PathJoin = "/join/" + PathAuthenticate = "/authenticate/" + PathQuery = "/query/" + PathRevoke = "/revoke/" + PathObscuroGateway = "/" + PathHealth = "/health/" + WSProtocol = "ws://" + DefaultUser = "defaultUser" + UserQueryParameter = "u" + AddressQueryParameter = "a" + MessageFormatRegex = `^Register\s(\w+)\sfor\s(\w+)$` + MessageUserIDLen = 64 + SignatureLen = 65 + PersonalSignMessagePrefix = "\x19Ethereum Signed Message:\n%d%s" + GetStorageAtUserIDRequestMethodName = "getUserID" + SuccessMsg = "success" + APIVersion1 = "/v1" ) var ( diff --git a/tools/walletextension/test/wallet_extension_test.go b/tools/walletextension/test/wallet_extension_test.go index 5e142deda8..7c1a92ae08 100644 --- a/tools/walletextension/test/wallet_extension_test.go +++ b/tools/walletextension/test/wallet_extension_test.go @@ -295,11 +295,8 @@ func TestGetStorageAtForReturningUserID(t *testing.T) { respJoin := makeHTTPEthJSONReqWithPath(walletHTTPPort, "v1/join") userID := string(respJoin) - specialAddressToGetUserID := "0x0000000000000000000000000000000000000000" - randomAddress := "0x123ABC0000000000000000000000000000000000" - // make a request to GetStorageAt with correct parameters to get userID that exists in the database - respBody := makeHTTPEthJSONReqWithUserID(walletHTTPPort, rpc.GetStorageAt, []interface{}{specialAddressToGetUserID, "0", nil}, userID) + respBody := makeHTTPEthJSONReqWithUserID(walletHTTPPort, rpc.GetStorageAt, []interface{}{"getUserID", "0", nil}, userID) validateJSONResponse(t, respBody) if !strings.Contains(string(respBody), userID) { @@ -308,20 +305,20 @@ func TestGetStorageAtForReturningUserID(t *testing.T) { // make a request to GetStorageAt with correct parameters, but userID that is not present in the database invalidUserID := "abc123" - respBody2 := makeHTTPEthJSONReqWithUserID(walletHTTPPort, rpc.GetStorageAt, []interface{}{specialAddressToGetUserID, "0", nil}, invalidUserID) + respBody2 := makeHTTPEthJSONReqWithUserID(walletHTTPPort, rpc.GetStorageAt, []interface{}{"getUserID", "0", nil}, invalidUserID) if !strings.Contains(string(respBody2), "method eth_getStorageAt cannot be called with an unauthorised client - no signed viewing keys found") { t.Fatalf("expected method eth_getStorageAt cannot be called with an unauthorised client - no signed viewing keys found, got '%s'", string(respBody2)) } // make a request to GetStorageAt with userID that is in the database, but wrong parameters - respBody3 := makeHTTPEthJSONReqWithUserID(walletHTTPPort, rpc.GetStorageAt, []interface{}{randomAddress, "0", nil}, userID) + respBody3 := makeHTTPEthJSONReqWithUserID(walletHTTPPort, rpc.GetStorageAt, []interface{}{"abc", "0", nil}, userID) if strings.Contains(string(respBody3), userID) { t.Fatalf("expected response not containing userID as the parameters are wrong ") } // make a request with wrong rpcMethod - respBody4 := makeHTTPEthJSONReqWithUserID(walletHTTPPort, rpc.GetBalance, []interface{}{specialAddressToGetUserID, "0", nil}, userID) + respBody4 := makeHTTPEthJSONReqWithUserID(walletHTTPPort, rpc.GetBalance, []interface{}{"getUserID", "0", nil}, userID) if strings.Contains(string(respBody4), userID) { t.Fatalf("expected response not containing userID as the parameters are wrong ") } diff --git a/tools/walletextension/wallet_extension.go b/tools/walletextension/wallet_extension.go index 28e1aa2942..d1db9e1f84 100644 --- a/tools/walletextension/wallet_extension.go +++ b/tools/walletextension/wallet_extension.go @@ -408,7 +408,7 @@ func (w *WalletExtension) checkParametersForInterceptedGetStorageAt(params []int } if methodName, ok := params[0].(string); ok { - return methodName == common.GetStorageAtUserIDRequestAddress + return methodName == common.GetStorageAtUserIDRequestMethodName } return false }