~ev/tildeprotocol

3ac6f21b6f7919a01ad7d92eb178ae0d2e3fc9ed — Ev Bogue 4 years ago 296af14
add an import for bogbook keypairs and make sure whitespace gets cut out of nick@home file
3 files changed, 21 insertions(+), 3 deletions(-)

M bin.js
A import.js
M util.js
M bin.js => bin.js +7 -2
@@ 15,7 15,12 @@ tilde.keys().then(keys => {
    `)
    var home = 'guest@cyberspace'
  } else {
    var home = fs.readFileSync(__dirname + '/nick@home', 'UTF-8')
    var imported = fs.readFileSync(__dirname + '/nick@home', 'UTF-8')
    var lines = imported.toString().split('\n')
    if (lines.length > 1) {
      fs.writeFileSync(__dirname + '/nick@home', lines[0], 'UTF-8')  
    }
    var home = lines[0]
  }

  var input = process.argv[2]


@@ 33,7 38,7 @@ tilde.keys().then(keys => {
        })
      } 
      if (dest) {
        // publish asymetric encrypted message
        // publish asymmetric encrypted message
        tilde.box(input, dest, home, keys).then(msg => {
          console.log(msg)
        })

A import.js => import.js +11 -0
@@ 0,0 1,11 @@
// this is a tool for converting bogbook keypairs into tilde keypairs

var fs = require('fs')

var JSONkey = JSON.parse(fs.readFileSync(__dirname + '/key.json', 'UTF-8'))

console.log(JSONkey)

tildeKey = '~' + JSONkey.publicKey.substring(1) + '~' + JSONkey.privateKey

fs.writeFileSync(__dirname + '/keypair', tildeKey, 'UTF-8')

M util.js => util.js +3 -1
@@ 9,6 9,7 @@ async function open (msg) {
  tildemsg = msg.split('~')

  if (tildemsg.length > 2) {
    console.log(tildemsg)
    var pubkey = nacl.util.decodeBase64(tildemsg[1])
    var sig = nacl.util.decodeBase64(tildemsg[2])



@@ 74,9 75,10 @@ function generatekey () {
async function keys () {
  try {
    var keypair = fs.readFileSync(__dirname + '/keypair', 'UTF-8')
    // var keypair = fs.readFileSync(__dirname + '/keypair')
  } catch (err) {
    var keypair = generatekey()
      fs.writeFileSync(__dirname + '/keypair', keypair, 'UTF-8')
    fs.writeFileSync(__dirname + '/keypair', keypair, 'UTF-8')
  }
  return keypair
}