1

I should compare two hashes and the scenario is the following:

I create a new record in the contract as I pass eosjs-ecc sha256 generated hash as string. Let name it hashA. When I want to update the record, I should pass the plain data to the contract and the contract should hash it. Let name the resulted hash - hashB.
Unfortunately when I am comparing the hashA to hashB, they are always different

The code example is here:

1) eosjs-ecc hashing ->

let a = eosECC.sha256(JSON.stringify("Hello)); eosECC.sha256(Buffer.from(a, 'hex'))

2) Contract hashing ->

ACTION mycontract::update(name account, const string data)
{
   require_auth(account);

    auto iteratorDataRecord = recordTable.find(0);

    checksum256 sum = sha256(const_cast<char *>(data.c_str()), data.size());

    print("EOS cpp hash", sum);

    // iteratorDataRecord->hashed_data is string
    print("eosjs-ecc hash", iteratorDataRecord->hashed_data);
}

I am calling the contract action in this way :

cleos push action mycontract update '{"account": "myself", "data":"Hello"}' -p myself@active

Do I have to convert from checksum to hex and if so how to do that ?

2

Check the output of JSON.stringify, I think you'll be surprised to see that it adds quotation marks around the string. "Hello" is not the same as JSON.stringify("Hello")

JSON.stringify("Hello")=="\"Hello\""
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.