Skip to content

Instantly share code, notes, and snippets.

@alexbosworth
Created May 19, 2018 14:00
Show Gist options
  • Save alexbosworth/7c247c0a526d52b488b6306b693bbeb7 to your computer and use it in GitHub Desktop.
Save alexbosworth/7c247c0a526d52b488b6306b693bbeb7 to your computer and use it in GitHub Desktop.
Using "javascript-opentimestamps": "0.4.0"
const OpenTimestamps = require('javascript-opentimestamps');
/** Timestamp text
{
text: <Text String>
}
@returns via cbk
{
[ots]: <OpenTimestamps Base64 Proof String>
}
*/
module.exports = ({text}, cbk) => {
if (!text) {
return cbk(400, 'ExpectedTimestampText');
}
const sha = new OpenTimestamps.Ops.OpSHA256();
const textBuf = Buffer.from(text);
const detach = OpenTimestamps.DetachedTimestampFile.fromBytes(sha, textBuf);
OpenTimestamps.stamp(detach)
.then(() => {
const fileOts = detach.serializeToBytes();
return cbk(null, {ots: new Buffer(fileOts).toString('base64')});
})
.catch(err => cbk(null, {ots: null}));
return;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment