fix SEA cb catches

This commit is contained in:
Mark Nadal 2018-06-29 17:11:04 -07:00
parent 736a530bcc
commit 9c9f64d36b
3 changed files with 26 additions and 30 deletions

View File

@ -113,7 +113,8 @@ function Radisk(opt){
Radix.map(rad, function(val, key){ Radix.map(rad, function(val, key){
if(key < start){ return } if(key < start){ return }
if(end && end < key){ return s.start = key } if(end && end < key){ return s.start = key }
disk(key, val); // PLUGIN: consider adding HAM as an extra layer of protection
disk(key, val); // merge batch[key] -> disk[key]
}); });
r.write(file, disk, s.next); r.write(file, disk, s.next);
}); });

View File

@ -11,30 +11,25 @@ if(typeof window === "undefined"){ //Not in the browser, Include from node
var gun = this, root = gun.back(-1); var gun = this, root = gun.back(-1);
var cb = (a instanceof Function && a) || (b instanceof Function && b); var cb = (a instanceof Function && a) || (b instanceof Function && b);
if(Gun.is(data)){ if(Gun.is(data)){
data = data._.soul; data.get(function(soul){
if(!data){ if(!soul){
/*data.get('_', function(msg, ev){ return cb && cb({err: "Timegraph cannot link `undefined`!"});
ev.off(); }
gun.time(Gun.val.link.ify(soul), a, b);
}) }, true);
return gun;*/ return gun;
cb && cb({err: "Only root level node references supported currently, hopefully will change this in the future."});
return gun;
}
data = Gun.val.link.ify(data);
} }
opt = (cb === a)? b : a; opt = (cb === a)? b : a;
opt = Gun.text.is(opt)? {key: opt} : opt || {}; opt = Gun.text.is(opt)? {key: opt} : opt || {};
var t = new Date(Gun.state()).toISOString().split(/[\-t\:\.z]/ig); var t = new Date(Gun.state()).toISOString().split(/[\-t\:\.z]/ig);
var p, tmp = t.pop(); var p, tmp = t.pop();
//gun.get('_', function(msg, ev){ ev.off(); gun.get(function(soul){
//var id = (msg.put && msg.put['#']) || (((gun._).soul || (root.back('opt.uuid') || Gun.text.random)(6)) + ':'); // TODO: BUG! THIS SHOULD NOT BE HARDCODED. var id = soul;
var id = (gun._).soul; // TODO: BUG! THIS SHOULD NOT BE HARDCODED.
p = id; p = id;
if(!p){ return cb({err: "For now, a timegraph can only be saved as a root node."}), this } if(!p){ id = p = (gun.back('opt.uuid') || Gun.text.random)(9) }
// could shrink this into a loop. Do later? // could shrink this into a loop. Do later?
t = [p].concat(t); t = [p].concat(t);
var rid = opt.key || (root.back('opt.uuid') || Gun.text.random)(9); var rid = opt.key || (gun.back('opt.uuid') || Gun.text.random)(9);
var milli = ify({}, t.join(':')); var milli = ify({}, t.join(':'));
milli[rid] = data; milli[rid] = data;
tmp = t.pop(); tmp = t.pop();
@ -59,15 +54,15 @@ if(typeof window === "undefined"){ //Not in the browser, Include from node
var time = ify({}, t.join(':') || id); var time = ify({}, t.join(':') || id);
time[tmp] = year; time[tmp] = year;
gun.put(time, cb); gun.put(time, cb);
//}) }, true);
return gun; return gun;
} }
function travel(cb, opt, b, gun){ function travel(cb, opt, b, gun){
var root = gun.back(-1), tmp; var root = gun.back(-1), tmp;
(opt = Gun.num.is(opt)? {last: opt} : opt || {}).seen = opt.seen || {}; (opt = Gun.num.is(opt)? {last: opt} : opt || {}).seen = opt.seen || {};
var t = now(); var t = now();
gun.get('_', function(msg, ev){ gun.on(function(msg, ev){
var id = (msg.put && msg.put['#']); var at = msg.$._, id = at.link || at.soul || Gun.node.soul(msg.put);
if(!id){ return } if(!id){ return }
if(false === opt.next){ ev.off() } if(false === opt.next){ ev.off() }
else { opt.next = true } else { opt.next = true }

20
sea.js
View File

@ -290,7 +290,7 @@
}, key, S.pbkdf2.ks * 8) }, key, S.pbkdf2.ks * 8)
data = shim.random(data.length) // Erase data in case of passphrase data = shim.random(data.length) // Erase data in case of passphrase
const r = shim.Buffer.from(result, 'binary').toString('utf8') const r = shim.Buffer.from(result, 'binary').toString('utf8')
if(cb){ cb(r) } if(cb){ try{ cb(r) }catch(e){console.log(e)} }
return r; return r;
} }
// For NodeJS crypto.pkdf2 rocks // For NodeJS crypto.pkdf2 rocks
@ -304,7 +304,7 @@
) )
data = shim.random(data.length) // Erase passphrase for app data = shim.random(data.length) // Erase passphrase for app
const r = hash && hash.toString('utf8') const r = hash && hash.toString('utf8')
if(cb){ cb(r) } if(cb){ try{ cb(r) }catch(e){console.log(e)} }
return r; return r;
} catch(e) { } catch(e) {
SEA.err = e; SEA.err = e;
@ -366,7 +366,7 @@
} dh = dh || {}; } dh = dh || {};
const r = { pub: sa.pub, priv: sa.priv, /* pubId, */ epub: dh.epub, epriv: dh.epriv } const r = { pub: sa.pub, priv: sa.priv, /* pubId, */ epub: dh.epub, epriv: dh.epriv }
if(cb){ cb(r) } if(cb){ try{ cb(r) }catch(e){console.log(e)} }
return r; return r;
} catch(e) { } catch(e) {
SEA.err = e; SEA.err = e;
@ -390,7 +390,7 @@
// TODO: This would prevent pair2 signing pair1's signature. // TODO: This would prevent pair2 signing pair1's signature.
// So we may want to change this in the future. // So we may want to change this in the future.
// but for now, we want to prevent duplicate double signature. // but for now, we want to prevent duplicate double signature.
if(cb){ cb(data) } if(cb){ try{ cb(data) }catch(e){console.log(e)} }
return data; return data;
} }
const pub = pair.pub const pub = pair.pub
@ -402,7 +402,7 @@
.then((key) => shim.subtle.sign(S.ecdsa.sign, key, new Uint8Array(hash))) // privateKey scope doesn't leak out from here! .then((key) => shim.subtle.sign(S.ecdsa.sign, key, new Uint8Array(hash))) // privateKey scope doesn't leak out from here!
const r = 'SEA'+JSON.stringify({m: msg, s: shim.Buffer.from(sig, 'binary').toString('utf8')}); const r = 'SEA'+JSON.stringify({m: msg, s: shim.Buffer.from(sig, 'binary').toString('utf8')});
if(cb){ cb(r) } if(cb){ try{ cb(r) }catch(e){console.log(e)} }
return r; return r;
} catch(e) { } catch(e) {
SEA.err = e; SEA.err = e;
@ -427,7 +427,7 @@
const raw = (json !== data)? const raw = (json !== data)?
(json.s && json.m)? parse(json.m) : data (json.s && json.m)? parse(json.m) : data
: json; : json;
if(cb){ cb(raw) } if(cb){ try{ cb(raw) }catch(e){console.log(e)} }
return raw; return raw;
} }
const pub = pair.pub || pair const pub = pair.pub || pair
@ -439,7 +439,7 @@
if(!check){ throw "Signature did not match." } if(!check){ throw "Signature did not match." }
const r = check? parse(json.m) : u; const r = check? parse(json.m) : u;
if(cb){ cb(r) } if(cb){ try{ cb(r) }catch(e){console.log(e)} }
return r; return r;
} catch(e) { } catch(e) {
SEA.err = e; SEA.err = e;
@ -485,7 +485,7 @@
s: rand.s.toString('utf8') s: rand.s.toString('utf8')
}); });
if(cb){ cb(r) } if(cb){ try{ cb(r) }catch(e){console.log(e)} }
return r; return r;
} catch(e) { } catch(e) {
SEA.err = e; SEA.err = e;
@ -513,7 +513,7 @@
}, aes, new Uint8Array(shim.Buffer.from(json.ct, 'utf8')))) }, aes, new Uint8Array(shim.Buffer.from(json.ct, 'utf8'))))
const r = parse(new shim.TextDecoder('utf8').decode(ct)) const r = parse(new shim.TextDecoder('utf8').decode(ct))
if(cb){ cb(r) } if(cb){ try{ cb(r) }catch(e){console.log(e)} }
return r; return r;
} catch(e) { } catch(e) {
SEA.err = e; SEA.err = e;
@ -547,7 +547,7 @@
return ecdhSubtle.exportKey('jwk', derivedKey).then(({ k }) => k) return ecdhSubtle.exportKey('jwk', derivedKey).then(({ k }) => k)
}) })
const r = derived; const r = derived;
if(cb){ cb(r) } if(cb){ try{ cb(r) }catch(e){console.log(e)} }
return r; return r;
} catch(e) { } catch(e) {
SEA.err = e; SEA.err = e;