From 91babdb221bfe5d09d00d987b5bc41d7d5675261 Mon Sep 17 00:00:00 2001 From: Mark Nadal Date: Fri, 13 Jul 2018 12:59:56 -0700 Subject: [PATCH] progress with @jadbox who setup the tests! --- sea.js | 19 ++++++++++++++++--- test/sea/sea2.js | 11 ++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/sea.js b/sea.js index 71ee0259..569f777d 100644 --- a/sea.js +++ b/sea.js @@ -382,9 +382,11 @@ var shim = USE('./shim'); var S = USE('./settings'); var sha256hash = USE('./sha256'); + var u; SEA.sign = async (data, pair, cb) => { try { - if(data.slice + // TODO: how should undefined be handled? + if((u !== data) && data.slice && 'SEA{' === data.slice(0,4) && '"m":' === data.slice(4,8)){ // TODO: This would prevent pair2 signing pair1's signature. @@ -1150,13 +1152,24 @@ const epub = await SEA.sign(pairs.epub, pairs) if(u === epub){ throw SEA.err } // to keep the private key safe, we AES encrypt it with the proof of work! - const auth = await SEA.encrypt({ priv: priv, epriv: epriv }, proof) + var auth = {}; + auth.priv = priv; + if(epriv){ + auth.epriv = epriv; + } + auth = await SEA.encrypt(auth, proof) .then((auth) => // TODO: So signedsalt isn't needed? // SEA.sign(salt, pairs).then((signedsalt) => SEA.sign({ek: auth, s: salt}, pairs) // ) ).catch((e) => { Gun.log('SEA.en or SEA.write calls failed!'); cat.ing = false; gun.leave(); reject(e) }) - const user = { alias: alias, pub: pub, epub: epub, auth: auth } + const user = {}; + user.alias = alias; + user.pub = pub; + user.auth = auth; + if(epub){ + user.epub = epub; + } const tmp = '~'+pairs.pub; // awesome, now we can actually save the user with their public key as their ID. try{ diff --git a/test/sea/sea2.js b/test/sea/sea2.js index a920f579..6a7cbdfa 100644 --- a/test/sea/sea2.js +++ b/test/sea/sea2.js @@ -41,16 +41,17 @@ describe('SEA', function(){ }) it('register users', async done => { - user.create('bob', 'test123', err => { - console.log('sea', SEA.err) - expect(err).toHaveProperty('ok') + user.create('bob', 'test123', ack => { + expect(ack.err).to.not.be.ok(); setTimeout(done, 30) }) }) it('login users', async done => { - user.auth('bob', 'test123', err => { - expect(err).toHaveProperty('ok') + console.log("------------------"); + user.auth('bob', 'test123', ack => { + console.log("?????", ack, SEA.err); + expect(ack.err).to.not.be.ok(); done() }) })