From a4a9e3cd7e856b0a11cf656badeb4ba4329df145 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=BDiga=20Kokelj?= Date: Tue, 2 Apr 2024 11:59:45 +0200 Subject: [PATCH] Ziga/fix gateway frontend issues after geth rpc (#1857) --- tools/walletextension/common/constants.go | 1 + .../frontend/src/api/ethRequests.ts | 2 +- .../frontend/src/lib/constants.ts | 2 +- tools/walletextension/httpapi/routes.go | 21 +++++++++++++++++-- tools/walletextension/httpapi/utils.go | 6 +++--- tools/walletextension/lib/client_lib.go | 4 ++-- tools/walletextension/main/main.go | 2 +- 7 files changed, 28 insertions(+), 10 deletions(-) diff --git a/tools/walletextension/common/constants.go b/tools/walletextension/common/constants.go index aa81df8b64..bf14a59f5f 100644 --- a/tools/walletextension/common/constants.go +++ b/tools/walletextension/common/constants.go @@ -29,6 +29,7 @@ const ( EncryptedTokenQueryParameter = "token" AddressQueryParameter = "a" MessageUserIDLen = 40 + MessageUserIDLenWithPrefix = 42 EthereumAddressLen = 42 GetStorageAtUserIDRequestMethodName = "0x0000000000000000000000000000000000000000" SuccessMsg = "success" diff --git a/tools/walletextension/frontend/src/api/ethRequests.ts b/tools/walletextension/frontend/src/api/ethRequests.ts index b4f5f2eecc..650c9eb621 100644 --- a/tools/walletextension/frontend/src/api/ethRequests.ts +++ b/tools/walletextension/frontend/src/api/ethRequests.ts @@ -151,7 +151,7 @@ export async function authenticateAccountWithTenGatewayEIP712( ...typedData, message: { ...typedData.message, - "Encryption Token": "0x" + token, + "Encryption Token": token, }, }; const signature = await getSignature(account, data); diff --git a/tools/walletextension/frontend/src/lib/constants.ts b/tools/walletextension/frontend/src/lib/constants.ts index 3be0cb1716..bd8814dba9 100644 --- a/tools/walletextension/frontend/src/lib/constants.ts +++ b/tools/walletextension/frontend/src/lib/constants.ts @@ -35,7 +35,7 @@ export const testnetUrls = { }; export const SWITCHED_CODE = 4902; -export const tokenHexLength = 40; +export const tokenHexLength = 42; export const tenGatewayVersion = "v1"; export const tenChainIDDecimal = 443; diff --git a/tools/walletextension/httpapi/routes.go b/tools/walletextension/httpapi/routes.go index 4f05e5b62f..3ddbd3e073 100644 --- a/tools/walletextension/httpapi/routes.go +++ b/tools/walletextension/httpapi/routes.go @@ -283,11 +283,28 @@ func networkHealthRequestHandler(walletExt *rpcapi.Services, userConn UserConn) return } + // call `obscuro-health` rpc method to get the health status of the node healthStatus, err := walletExt.GetTenNodeHealthStatus() + // create the response in the required format + type HealthStatus struct { + Errors []string `json:"Errors"` + OverallHealth bool `json:"OverallHealth"` + } + + errorStrings := make([]string, 0) + if err != nil { + errorStrings = append(errorStrings, err.Error()) + } + healthStatusResponse := HealthStatus{ + Errors: errorStrings, + OverallHealth: healthStatus, + } + data, err := json.Marshal(map[string]interface{}{ - "result": healthStatus, - "error": err, + "id": "1", + "jsonrpc": "2.0", + "result": healthStatusResponse, }) if err != nil { walletExt.Logger().Error("error marshaling response", log.ErrKey, err) diff --git a/tools/walletextension/httpapi/utils.go b/tools/walletextension/httpapi/utils.go index cc7c50fe1a..c7acc16b8c 100644 --- a/tools/walletextension/httpapi/utils.go +++ b/tools/walletextension/httpapi/utils.go @@ -25,10 +25,10 @@ func getUserID(conn UserConn) ([]byte, error) { // try getting userID (`token`) from query parameters and return it if successful userID, err := getQueryParameter(conn.ReadRequestParams(), common.EncryptedTokenQueryParameter) if err == nil { - if len(userID) != common.MessageUserIDLen { - return nil, fmt.Errorf(fmt.Sprintf("wrong length of userID from URL. Got: %d, Expected: %d", len(userID), common.MessageUserIDLen)) + if len(userID) != common.MessageUserIDLenWithPrefix { + return nil, fmt.Errorf(fmt.Sprintf("wrong length of userID from URL. Got: %d, Expected: %d", len(userID), common.MessageUserIDLenWithPrefix)) } - return hexutils.HexToBytes(userID), err + return hexutils.HexToBytes(userID[2:]), err } return nil, fmt.Errorf("missing token field") diff --git a/tools/walletextension/lib/client_lib.go b/tools/walletextension/lib/client_lib.go index 3e63a1a22e..72eda7b77c 100644 --- a/tools/walletextension/lib/client_lib.go +++ b/tools/walletextension/lib/client_lib.go @@ -74,7 +74,7 @@ func (o *TGLib) RegisterAccount(pk *ecdsa.PrivateKey, addr gethcommon.Address) e req, err := http.NewRequestWithContext( context.Background(), http.MethodPost, - o.httpURL+"/v1/authenticate/?token="+hexutils.BytesToHex(o.userID), + o.httpURL+"/v1/authenticate/?token=0x"+hexutils.BytesToHex(o.userID), strings.NewReader(payload), ) if err != nil { @@ -124,7 +124,7 @@ func (o *TGLib) RegisterAccountPersonalSign(pk *ecdsa.PrivateKey, addr gethcommo req, err := http.NewRequestWithContext( context.Background(), http.MethodPost, - o.httpURL+"/v1/authenticate/?token="+hexutils.BytesToHex(o.userID), + o.httpURL+"/v1/authenticate/?token=0x"+hexutils.BytesToHex(o.userID), strings.NewReader(payload), ) if err != nil { diff --git a/tools/walletextension/main/main.go b/tools/walletextension/main/main.go index 4b200968c0..61eaed1ddf 100644 --- a/tools/walletextension/main/main.go +++ b/tools/walletextension/main/main.go @@ -69,7 +69,7 @@ func main() { walletExtensionAddr := fmt.Sprintf("%s:%d", common.Localhost, config.WalletExtensionPortHTTP) fmt.Printf("💡 Wallet extension started \n") // Some tests rely on seeing this message. Removed in next PR. - fmt.Printf("💡 Obscuro Gateway started - visit http://%s to use it.\n", walletExtensionAddr) + fmt.Printf("💡 Obscuro Gateway started - visit http://%s/static to use it.\n", walletExtensionAddr) select {} }