Quick example using the library found by David Berger:
https://github.com/emn178/js-sha256/blob/master/src/sha256.js
(downloading file from the web, then computing the hash).
Probably it would be wiser to use an external REST service to compute the hash (maybe with https://hyperledger.github.io/composer/integrating/call-out, but headers are missing?)
Edit: It works only using playground (client side), see Function in logic.js works in playground but not in REST server, right still learning... Maybe I should try with https://www.npmjs.com/package/request... or my own external REST service.
/**
* This part will only work on playground. Should try with
* @param {String} documentUrl
*/
function getContent(documentUrl)
{
return fetch(documentUrl, {
method: 'GET'
}).then((response) => {
return response.text()
.then((text) => {
return text;
});
});
}
/**
* @param {String} documentUrl
*/
function generateHash(documentUrl)
{
return getContent(documentUrl)
.then((documentContent) => {
let hash = sha256.create();
hash.update(documentContent);
return hash.hex();
});
}
So, case closed, but it was - I must admit - an easy one. Now I'm facing more complicated problems calling external rest APIs using Http, rest endpoints instead of using wrappers... The good point: the code will be stripped of unnecessary stuff. Still, the learning curve of hyperleder composer is far less steep than hyperledger fabric alone. Great tool!