-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.iced
32 lines (27 loc) · 967 Bytes
/
main.iced
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
fs = require 'fs'
path = require 'path'
mkdirp = require 'mkdirp'
Stampery = require 'stampery'
class Stamper
constructor : (params) ->
@file = params.path
@proofsDir = params.proofsDir
@fileName = @file.split('/').pop()
@path = path.resolve "#{@proofsDir}/#{@file.split('/').slice(0, -1).join('/')}"
console.log "Proof path will be #{@path}"
await mkdirp @path, defer err
@stampery = new Stampery params.secret
@stampery.on 'proof', @proofStore
@stampery.on 'ready', @stampery.receiveMissedProofs
receiver : ({cur}) =>
await @stampery.hash cur.content, defer digest
@stampery.stamp digest
proofStore : (hash, proof) =>
proofFile = path.resolve "#{@path}/#{@fileName}.csv"
console.log "Storing proof as #{proofFile}"
line = "#{new Date()};t#{hash};t#{JSON.stringify proof}\n"
try
fs.appendFile proofFile, line
catch e
fs.writeFile proofFile, line, 'utf8'
module.exports = Stamper