Skip to content

Commit

Permalink
Ziga/fix gateway frontend issues after geth rpc (#1857)
Browse files Browse the repository at this point in the history
  • Loading branch information
zkokelj authored Apr 2, 2024
1 parent 55ef73e commit a4a9e3c
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 10 deletions.
1 change: 1 addition & 0 deletions tools/walletextension/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const (
EncryptedTokenQueryParameter = "token"
AddressQueryParameter = "a"
MessageUserIDLen = 40
MessageUserIDLenWithPrefix = 42
EthereumAddressLen = 42
GetStorageAtUserIDRequestMethodName = "0x0000000000000000000000000000000000000000"
SuccessMsg = "success"
Expand Down
2 changes: 1 addition & 1 deletion tools/walletextension/frontend/src/api/ethRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tools/walletextension/frontend/src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
21 changes: 19 additions & 2 deletions tools/walletextension/httpapi/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions tools/walletextension/httpapi/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions tools/walletextension/lib/client_lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion tools/walletextension/main/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
}

0 comments on commit a4a9e3c

Please sign in to comment.