Skip to content

Instantly share code, notes, and snippets.

@feulf
Created October 21, 2017 22:39
Show Gist options
  • Select an option

  • Save feulf/824965174e315039210370fccbe799d8 to your computer and use it in GitHub Desktop.

Select an option

Save feulf/824965174e315039210370fccbe799d8 to your computer and use it in GitHub Desktop.
function saveOts(otsFilename, buffer) {
fs.exists(otsFilename, fileExist => {
if (fileExist) {
console.log('The timestamp proof \'' + otsFilename + '\' already exists');
} else {
fs.writeFile(otsFilename, buffer, 'binary', err => {
if (err) {
return console.log(err);
}
console.log('The timestamp proof \'' + otsFilename + '\' has been created!');
});
}
});
}
const OpenTimestamps = require('javascript-opentimestamps');
var infoResult;
const file = Buffer.from('5468652074696d657374616d70206f6e20746869732066696c6520697320696e636f6d706c6574652c20616e642063616e2062652075706772616465642e0a','hex');
const detached = OpenTimestamps.DetachedTimestampFile.fromBytes(new OpenTimestamps.Ops.OpSHA256(), file);
const Context = require('./node_modules/javascript-opentimestamps/src/context.js'); // loading directly from node_modules... ew
const ctx = new Context.StreamSerialization();
detached.serialize(ctx);
var buffer = new Buffer(detached.getOutput());
var otsFilename = 'fed.ots';
saveOts(otsFilename, buffer);
@RCasatta
Copy link
Copy Markdown

@RCasatta
Copy link
Copy Markdown

The problems were:

  • #L24 ctx.getOutput() instead of detached.getOutput()
  • No need to require the Context from a require, it is accessible with OpenTimestams.Context
  • You are not calling the stamp function (which I suppose is the reason of the script)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment