diff --git a/.gitignore b/.gitignore index c88e5e8..1d13986 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ bower_components -.idea \ No newline at end of file +.idea +.project diff --git a/index.html b/index.html index 3c1689f..1698b80 100644 --- a/index.html +++ b/index.html @@ -268,8 +268,7 @@

VERIFY OTS PROOF

- - + diff --git a/index.js b/index.js index 2ef8159..0c73ea4 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,44 @@ +/* OpenTimestamps functions */ + const OpenTimestamps = window.OpenTimestamps +// an empty list would be equivalent to the default calendars +const calendarsList = [ + 'https://test-calendar.aniasafe.it', // testnet + 'https://calendar.aniasafe.it', // mainet + 'https://alice.btc.calendar.opentimestamps.org', + 'https://bob.btc.calendar.opentimestamps.org', + 'https://finney.calendar.eternitywall.com' +] + +// an empty list is not acceptable here +const wcalendars = [ + 'https://test-calendar.aniasafe.it', // testnet + 'https://calendar.aniasafe.it', // mainet + 'https://alice.btc.calendar.opentimestamps.org', + 'https://bob.btc.calendar.opentimestamps.org', + 'https://finney.calendar.eternitywall.com' +] +const whitelistedCalendars = new OpenTimestamps.Calendar.UrlWhitelist(wcalendars) + +const blockexplorers = { + bitcoin: { + explorers: [ + {url: 'https://blockstream.info/api', type: 'blockstream'}, + {url: 'https://blockexplorer.com/api', type: 'insight'} + ], + timeout: 5 + }, + bitcoinTestnet: { + explorers: [ + {url: 'https://blockstream.info/testnet/api', type: 'blockstream'}, + {url: 'https://testnet.blockexplorer.com/api', type: 'insight'} + ], + timeout: 5 + } +} + + $("#btn-hash").click(function(event) { event.preventDefault() // begin processing... @@ -63,11 +102,13 @@ $("#btn-stamp").click(function(event) { const hashValue = $("#stamp-hashValue").val() const hashData = hexToBytes(hashValue) - const detachedOriginal = OpenTimestamps.DetachedTimestampFile.fromHash(op, hashData) const filename = $("#stamp-filename").val() - OpenTimestamps.stamp(detachedOriginal).then( () => { + const detachedOriginal = OpenTimestamps.DetachedTimestampFile.fromHash(op, hashData) + const options = { calendars: calendarsList } + + OpenTimestamps.stamp(detachedOriginal, options).then( () => { const byteots = detachedOriginal.serializeToBytes() const hexots = bytesToHex(byteots) $("#stamp-output").val(hexots) @@ -165,7 +206,8 @@ $("#btn-upgrade").click(function(event) { const filename = $("#upgrade-filename").val() $("#verify-filename").val(filename) - OpenTimestamps.upgrade(detachedStamped).then( (changed)=>{ + const upgradeOptions = { whitelist: whitelistedCalendars } + OpenTimestamps.upgrade(detachedStamped, upgradeOptions).then( (changed)=>{ const timestampBytes = detachedStamped.serializeToBytes() const hexots = bytesToHex(timestampBytes) if (changed === true) { @@ -205,7 +247,8 @@ $("#btn-verify").click(function(event) { const filename = $("#verify-filename").val() var outputText = "" - OpenTimestamps.upgrade(detachedStamped).then( (changed)=>{ + const upgradeOptions = { whitelist: whitelistedCalendars } + OpenTimestamps.upgrade(detachedStamped, upgradeOptions).then( (changed)=>{ const timestampBytes = detachedStamped.serializeToBytes() hexots = bytesToHex(timestampBytes) if (changed === true) { @@ -225,7 +268,7 @@ $("#btn-verify").click(function(event) { outputText += "No proof upgrade available" } $("#verify-output").val(outputText + "\nWaiting for verification results...") - return OpenTimestamps.verifyTimestamp(detachedStamped.timestamp) + return OpenTimestamps.verifyTimestamp(detachedStamped.timestamp, blockexplorers) }).then( (results)=>{ if (Object.keys(results).length === 0) { if (!detachedStamped.timestamp.isTimestampComplete())