I actually use an implementation like the dice contract : https://github.com/EOSIO/eos/tree/v1.2.0/contracts/dice
You create a key and his hash with sha256, you first send the hash and then the key to the smart-contract. The contract use the function assert_sha256. I have difficulty for creating the hash with sha256 in Javascript. The encryption has to be the same than the EOS contract else assert_sha256 fail.
I try with the function sha256 of eosjs-ecc and other library without success.
In the dice contract example, they do it in shell like this
echo -n 'abc' | xxd -r -p | sha256sum -b | awk '{print $1}'
I don't understand all the parameters particularly xxd. It translates in binary ?
Thanks
EDIT :
Thanks Don, I spend a lot of time to understand how pass hex to binary, how xxd work, etc... but the answer was just in front of my eyes.
In the documentation of ecc : https://github.com/EOSIO/eosjs-ecc You just have to pass your hex key inside of this code
ecc.sha256(Buffer.from('02208b', 'hex'))
The first time, I probably didn't pass hex data so it's failed.