Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
bower_components
.idea
.idea
.project
3 changes: 1 addition & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,7 @@ <h3 class="card-header primary-color white-text">VERIFY OTS PROOF</h3>
<!-- MDB core JavaScript -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mdbootstrap/4.5.0/js/mdb.min.js"></script>
<!-- OpenTimestamps JavaScript (use the default opentimestamps.org one, or any local version -->
<script src="https://opentimestamps.org/assets/javascripts/vendor/opentimestamps.min.js"></script>
<!-- script src="../javascript-opentimestamps/dist/opentimestamps.js"></script -->
<script src="../assets/javascripts/vendor/opentimestamps.min.js"></script>
<!-- Moment JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.22.1/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment-timezone/0.5.17/moment-timezone-with-data-2012-2022.min.js"></script>
Expand Down
53 changes: 48 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -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...
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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())
Expand Down