Created
May 19, 2018 14:00
-
-
Save alexbosworth/7c247c0a526d52b488b6306b693bbeb7 to your computer and use it in GitHub Desktop.
Using "javascript-opentimestamps": "0.4.0"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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