I want to validate user signatures in my smart contract. As I understood, I am supposed to do that with recover_key function from crypto.h
I am using JavaScript with eosjs and eosjs-ecc for integration. There i sign some data and pass it to my contract action:
let data = "Some Data"
let sig = ecc.sign(data, keyProvider)
let result = await eos.transaction('contract', contract => {
contract.testrecover(data, sig, pubkey, tester_options)
})
In my contract I want to recover and verify a public key from this signature. Because recover_key function requires a char*, and ABI doesn't support passing char* to actions, I use following code:
void testrecover( std::string data, std::string sig, std::string pub ) {
char* datachar = new char[data.size() + 1];
std::copy(data.begin(), data.end(), datachar);
datachar[data.size()] = '\0';
char* sigchar = new char[sig.size() + 1];
std::copy(sig.begin(), sig.end(), sigchar);
sigchar[sig.size()] = '\0';
char* pubchar = new char[pub.size() + 1];
std::copy(pub.begin(), pub.end(), pubchar);
pubchar[pub.size()] = '\0';
checksum256* digest;
sha256(datachar, data.size(), digest);
assert_recover_key(digest, sigchar, sig.size(), pubchar, pub.size());
}
But when running, contract action execution fails with the following error:
2018-07-31T15:49:33.376 thread-0 http_plugin.cpp:475
handle_exception ] FC Exception encountered while processing chain.push_transaction 2018-07-31T15:49:33.376 thread-0
http_plugin.cpp:476 handle_exception ] Exception Details: 3070002 wasm_execution_error: Runtime Error Processing WASM access violation {} thread-0 binaryen.hpp:81 assert_memory_is_accessible
I have no idea why it is appearing. Hoping for your help.