fix(BC)_: Fix personal_sign RPC event processing

The personal_sign RPC event parsing. Changed `params` from object array to string array.
This commit is contained in:
Alex Jbanca 2024-11-11 16:09:01 +02:00
parent d4239ac592
commit 43f355a391
No known key found for this signature in database
GPG Key ID: 6004079575C21C5D
3 changed files with 6 additions and 12 deletions

View File

@ -29,18 +29,17 @@ func (r *RPCRequest) getPersonalSignParams() (*PersonalSignParams, error) {
return nil, ErrEmptyRPCParams return nil, ErrEmptyRPCParams
} }
paramMap, ok := r.Params[0].(map[string]interface{}) if len(r.Params) < 2 {
if !ok {
return nil, ErrInvalidParamsStructure return nil, ErrInvalidParamsStructure
} }
// Extract the Challenge and Address fields from paramMap // Extract the Challenge and Address fields from paramsArray
challenge, ok := paramMap["challenge"].(string) challenge, ok := r.Params[0].(string)
if !ok { if !ok {
return nil, fmt.Errorf("missing or invalid 'challenge' field") return nil, fmt.Errorf("missing or invalid 'challenge' field")
} }
address, ok := paramMap["address"].(string) address, ok := r.Params[1].(string)
if !ok { if !ok {
return nil, fmt.Errorf("missing or invalid 'address' field") return nil, fmt.Errorf("missing or invalid 'address' field")
} }

View File

@ -12,12 +12,7 @@ import (
) )
func preparePersonalSignRequest(dApp signal.ConnectorDApp, challenge, address string) (RPCRequest, error) { func preparePersonalSignRequest(dApp signal.ConnectorDApp, challenge, address string) (RPCRequest, error) {
params := map[string]interface{}{ return ConstructRPCRequest("personal_sign", []interface{}{challenge, address}, &dApp)
"challenge": challenge,
"address": address,
}
return ConstructRPCRequest("personal_sign", []interface{}{params}, &dApp)
} }
func TestFailToPersonalSignWithMissingDAppFields(t *testing.T) { func TestFailToPersonalSignWithMissingDAppFields(t *testing.T) {

View File

@ -116,7 +116,7 @@ func TestRequestAccountsSwitchChainAndSendTransactionFlow(t *testing.T) {
assert.Equal(t, expectedHash.Hex(), response) assert.Equal(t, expectedHash.Hex(), response)
// Personal sign // Personal sign
request = "{\"method\": \"personal_sign\", \"params\":[{\"challenge\": \"0x506c65617365207369676e2074686973206d65737361676520746f20636f6e6669726d20796f7572206964656e746974792e\",\"address\":\"0x4B0897b0513FdBeEc7C469D9aF4fA6C0752aBea7\"}], \"url\": \"http://testDAppURL123\", \"name\": \"testDAppName\", \"iconUrl\": \"http://testDAppIconUrl\" }" request = "{\"method\": \"personal_sign\", \"params\":[\"0x506c65617365207369676e2074686973206d65737361676520746f20636f6e6669726d20796f7572206964656e746974792e\",\"0x4B0897b0513FdBeEc7C469D9aF4fA6C0752aBea7\"], \"url\": \"http://testDAppURL123\", \"name\": \"testDAppName\", \"iconUrl\": \"http://testDAppIconUrl\" }"
response, err = state.api.CallRPC(state.ctx, request) response, err = state.api.CallRPC(state.ctx, request)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, expectedSignature, response) assert.Equal(t, expectedSignature, response)