~ev/lifelogger

1d5eb06fa75fd1f604488b2e7030b0eb0fc4e914 — Ev Bogue 2 years ago master
initial commit
4 files changed, 369 insertions(+), 0 deletions(-)

A README.md
A app.js
A package-lock.json
A package.json
A  => README.md +11 -0
@@ 1,11 @@
# lifelogger

It just generates a private key and then you create logfiles by passing an argument to the app.

Ex:

```
node app filename
```

When you type the command it will decrypt and read any of your previous logs, and then you will be prompted to add a new log to the file.

A  => app.js +93 -0
@@ 1,93 @@
const fs = require('fs')
const nacl = require('tweetnacl')
    nacl.util = require('tweetnacl-util')
const prompt = require('prompt')
const human = require('human-time')

prompt.start()

prompt.message = ''
prompt.delimiter = " > "

function generatekey () {
  var keypair = { publicKey : '@/'}
  console.log('generating new keypair')
  while (keypair.publicKey.includes('/')) {
    var genkey = nacl.box.keyPair()
    keypair.publicKey = '@' + nacl.util.encodeBase64(genkey.publicKey),
    keypair.privateKey = nacl.util.encodeBase64(genkey.secretKey)
  }
  return keypair
}

async function keys () {
  try {
    if (fs) {
      var keypair = JSON.parse(fs.readFileSync(__dirname + '/keypair'))
    } 
  } catch (err) {
    var keypair = generatekey()
    if (fs) {
      fs.writeFileSync(__dirname + '/keypair', JSON.stringify(keypair), 'UTF-8')
    }
  }
  return keypair
}

async function box (msg, recp, keys) {
  var nonce = nacl.randomBytes(nacl.box.nonceLength)
  var message = nacl.util.decodeUTF8(msg)
  var encrypted = nacl.box(message, nonce, nacl.util.decodeBase64(recp.substring(1)), nacl.util.decodeBase64(keys.privateKey))
  var nonceMsg = nacl.util.encodeBase64(nonce) + nacl.util.encodeBase64(encrypted)
  return nonceMsg
}

//bog.unbox -- decrypts a message sent to our pubkey
async function unbox (boxed, sender, keys) {
  var nonceMsg = nacl.util.decodeBase64(boxed)
  var nonce = nonceMsg.slice(0, nacl.box.nonceLength)
  var msg = nonceMsg.slice(nacl.box.nonceLength, nonceMsg.length)
  var message = nacl.util.encodeUTF8(nacl.box.open(msg, nonce, nacl.util.decodeBase64(sender.substring(1)), nacl.util.decodeBase64(keys.privateKey)))
  return message
}

var file = process.argv[2]

keys().then(key => {

  function getContent (data) {
    prompt.get(['content'], function (err, result) {
      var memo = { 
        content: result.content,
        timestamp: Date.now()
      }
      box(JSON.stringify(memo), key.publicKey, key).then(boxed => {
        data.notes.push(boxed)
        fs.writeFileSync(__dirname + '/' + file, JSON.stringify(data), 'utf-8')
      })
      console.log(memo.content + ' | ' + human(new Date(memo.timestamp)))
    })
  }

  console.log('You are: ' + key.publicKey)

  if (!file) {console.log('Please pass an email address as an argument. Ex: node app e@email.com')} else {
    if (fs.existsSync(__dirname + '/' + file)) {
      var data = JSON.parse(fs.readFileSync(__dirname + '/' + file, 'utf-8'))
      data.notes.forEach(note => {
        unbox(note, key.publicKey, key).then(unboxed => {
          var memo = JSON.parse(unboxed)
          console.log(memo.content + ' | ' + human(new Date(memo.timestamp)))
        })
      })
      setTimeout(function () {
        getContent(data)
      }, 1000)
    } else {
      var data = {
        notes: []
      }
      getContent(data)
    }
  }
})

A  => package-lock.json +244 -0
@@ 1,244 @@
{
  "requires": true,
  "lockfileVersion": 1,
  "dependencies": {
    "async": {
      "version": "0.9.2",
      "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz",
      "integrity": "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0="
    },
    "balanced-match": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
      "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c="
    },
    "brace-expansion": {
      "version": "1.1.11",
      "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
      "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
      "requires": {
        "balanced-match": "^1.0.0",
        "concat-map": "0.0.1"
      }
    },
    "colors": {
      "version": "1.4.0",
      "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
      "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA=="
    },
    "concat-map": {
      "version": "0.0.1",
      "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
      "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
    },
    "cycle": {
      "version": "1.0.3",
      "resolved": "https://registry.npmjs.org/cycle/-/cycle-1.0.3.tgz",
      "integrity": "sha1-IegLK+hYD5i0aPN5QwZisEbDStI="
    },
    "deep-equal": {
      "version": "0.2.2",
      "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-0.2.2.tgz",
      "integrity": "sha1-hLdFiW80xoTpjyzg5Cq69Du6AX0="
    },
    "eyes": {
      "version": "0.1.8",
      "resolved": "https://registry.npmjs.org/eyes/-/eyes-0.1.8.tgz",
      "integrity": "sha1-Ys8SAjTGg3hdkCNIqADvPgzCC8A="
    },
    "fs.realpath": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
      "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
    },
    "glob": {
      "version": "7.1.6",
      "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz",
      "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==",
      "requires": {
        "fs.realpath": "^1.0.0",
        "inflight": "^1.0.4",
        "inherits": "2",
        "minimatch": "^3.0.4",
        "once": "^1.3.0",
        "path-is-absolute": "^1.0.0"
      }
    },
    "human-time": {
      "version": "0.0.2",
      "resolved": "https://registry.npmjs.org/human-time/-/human-time-0.0.2.tgz",
      "integrity": "sha512-sbYI90YhYmstslPTb70BLGjy6mdESa0lxL7uDR4fIVAx9Iobz8fLEqi7FqF4Q/6vblrzZALg//MsYJlIPBU8SA=="
    },
    "i": {
      "version": "0.3.6",
      "resolved": "https://registry.npmjs.org/i/-/i-0.3.6.tgz",
      "integrity": "sha1-2WyScyB28HJxG2sQ/X1PZa2O4j0="
    },
    "inflight": {
      "version": "1.0.6",
      "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
      "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
      "requires": {
        "once": "^1.3.0",
        "wrappy": "1"
      }
    },
    "inherits": {
      "version": "2.0.4",
      "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
      "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
    },
    "isstream": {
      "version": "0.1.2",
      "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
      "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo="
    },
    "minimatch": {
      "version": "3.0.4",
      "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
      "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
      "requires": {
        "brace-expansion": "^1.1.7"
      }
    },
    "minimist": {
      "version": "0.0.8",
      "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz",
      "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0="
    },
    "mkdirp": {
      "version": "0.5.1",
      "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz",
      "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=",
      "requires": {
        "minimist": "0.0.8"
      }
    },
    "mute-stream": {
      "version": "0.0.8",
      "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz",
      "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA=="
    },
    "ncp": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/ncp/-/ncp-1.0.1.tgz",
      "integrity": "sha1-0VNn5cuHQyuhF9K/gP30Wuz7QkY="
    },
    "once": {
      "version": "1.4.0",
      "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
      "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
      "requires": {
        "wrappy": "1"
      }
    },
    "path-is-absolute": {
      "version": "1.0.1",
      "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
      "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
    },
    "pkginfo": {
      "version": "0.4.1",
      "resolved": "https://registry.npmjs.org/pkginfo/-/pkginfo-0.4.1.tgz",
      "integrity": "sha1-tUGO8EOd5UJfxJlQQtztFPsqhP8="
    },
    "prompt": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/prompt/-/prompt-1.0.0.tgz",
      "integrity": "sha1-jlcSPDlquYiJf7Mn/Trtw+c15P4=",
      "requires": {
        "colors": "^1.1.2",
        "pkginfo": "0.x.x",
        "read": "1.0.x",
        "revalidator": "0.1.x",
        "utile": "0.3.x",
        "winston": "2.1.x"
      }
    },
    "read": {
      "version": "1.0.7",
      "resolved": "https://registry.npmjs.org/read/-/read-1.0.7.tgz",
      "integrity": "sha1-s9oZvQUkMal2cdRKQmNK33ELQMQ=",
      "requires": {
        "mute-stream": "~0.0.4"
      }
    },
    "revalidator": {
      "version": "0.1.8",
      "resolved": "https://registry.npmjs.org/revalidator/-/revalidator-0.1.8.tgz",
      "integrity": "sha1-/s5hv6DBtSoga9axgZgYS91SOjs="
    },
    "rimraf": {
      "version": "2.7.1",
      "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz",
      "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==",
      "requires": {
        "glob": "^7.1.3"
      }
    },
    "stack-trace": {
      "version": "0.0.10",
      "resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz",
      "integrity": "sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA="
    },
    "tweetnacl": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.2.tgz",
      "integrity": "sha512-+8aPRjmXgf1VqvyxSlBUzKzeYqVS9Ai8vZ28g+mL7dNQl1jlUTCMDZnvNQdAS1xTywMkIXwJsfipsR/6s2+syw=="
    },
    "tweetnacl-util": {
      "version": "0.15.0",
      "resolved": "https://registry.npmjs.org/tweetnacl-util/-/tweetnacl-util-0.15.0.tgz",
      "integrity": "sha1-RXbBzuXi1j0gf+5S8boCgZSAvHU="
    },
    "utile": {
      "version": "0.3.0",
      "resolved": "https://registry.npmjs.org/utile/-/utile-0.3.0.tgz",
      "integrity": "sha1-E1LDQOuCDk2N26A5pPv6oy7U7zo=",
      "requires": {
        "async": "~0.9.0",
        "deep-equal": "~0.2.1",
        "i": "0.3.x",
        "mkdirp": "0.x.x",
        "ncp": "1.0.x",
        "rimraf": "2.x.x"
      }
    },
    "winston": {
      "version": "2.1.1",
      "resolved": "https://registry.npmjs.org/winston/-/winston-2.1.1.tgz",
      "integrity": "sha1-PJNJ0ZYgf9G9/51LxD73JRDjoS4=",
      "requires": {
        "async": "~1.0.0",
        "colors": "1.0.x",
        "cycle": "1.0.x",
        "eyes": "0.1.x",
        "isstream": "0.1.x",
        "pkginfo": "0.3.x",
        "stack-trace": "0.0.x"
      },
      "dependencies": {
        "async": {
          "version": "1.0.0",
          "resolved": "https://registry.npmjs.org/async/-/async-1.0.0.tgz",
          "integrity": "sha1-+PwEyjoTeErenhZBr5hXjPvWR6k="
        },
        "colors": {
          "version": "1.0.3",
          "resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz",
          "integrity": "sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs="
        },
        "pkginfo": {
          "version": "0.3.1",
          "resolved": "https://registry.npmjs.org/pkginfo/-/pkginfo-0.3.1.tgz",
          "integrity": "sha1-Wyn2qB9wcXFC4J52W76rl7T4HiE="
        }
      }
    },
    "wrappy": {
      "version": "1.0.2",
      "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
      "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
    }
  }
}

A  => package.json +21 -0
@@ 1,21 @@
{
  "name": "lifelogger",
  "version": "1.0.0",
  "description": "It just generates a private key and then you create logfiles by passing an argument to the app.",
  "main": "app.js",
  "directories": {
    "lib": "lib"
  },
  "dependencies": {
    "human-time": "^0.0.2",
    "prompt": "^1.0.0",
    "tweetnacl": "^1.0.2",
    "tweetnacl-util": "^0.15.0"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "MIT"
}