mirror of
https://github.com/amark/gun.git
synced 2025-06-03 20:56:43 +00:00
fix SEA cb catches
This commit is contained in:
parent
736a530bcc
commit
9c9f64d36b
@ -113,7 +113,8 @@ function Radisk(opt){
|
||||
Radix.map(rad, function(val, key){
|
||||
if(key < start){ return }
|
||||
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);
|
||||
});
|
||||
|
33
lib/time.js
33
lib/time.js
@ -11,30 +11,25 @@ if(typeof window === "undefined"){ //Not in the browser, Include from node
|
||||
var gun = this, root = gun.back(-1);
|
||||
var cb = (a instanceof Function && a) || (b instanceof Function && b);
|
||||
if(Gun.is(data)){
|
||||
data = data._.soul;
|
||||
if(!data){
|
||||
/*data.get('_', function(msg, ev){
|
||||
ev.off();
|
||||
|
||||
})
|
||||
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);
|
||||
data.get(function(soul){
|
||||
if(!soul){
|
||||
return cb && cb({err: "Timegraph cannot link `undefined`!"});
|
||||
}
|
||||
gun.time(Gun.val.link.ify(soul), a, b);
|
||||
}, true);
|
||||
return gun;
|
||||
}
|
||||
opt = (cb === a)? b : a;
|
||||
opt = Gun.text.is(opt)? {key: opt} : opt || {};
|
||||
var t = new Date(Gun.state()).toISOString().split(/[\-t\:\.z]/ig);
|
||||
var p, tmp = t.pop();
|
||||
//gun.get('_', function(msg, ev){ ev.off();
|
||||
//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 = (gun._).soul; // TODO: BUG! THIS SHOULD NOT BE HARDCODED.
|
||||
gun.get(function(soul){
|
||||
var id = soul;
|
||||
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?
|
||||
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(':'));
|
||||
milli[rid] = data;
|
||||
tmp = t.pop();
|
||||
@ -59,15 +54,15 @@ if(typeof window === "undefined"){ //Not in the browser, Include from node
|
||||
var time = ify({}, t.join(':') || id);
|
||||
time[tmp] = year;
|
||||
gun.put(time, cb);
|
||||
//})
|
||||
}, true);
|
||||
return gun;
|
||||
}
|
||||
function travel(cb, opt, b, gun){
|
||||
var root = gun.back(-1), tmp;
|
||||
(opt = Gun.num.is(opt)? {last: opt} : opt || {}).seen = opt.seen || {};
|
||||
var t = now();
|
||||
gun.get('_', function(msg, ev){
|
||||
var id = (msg.put && msg.put['#']);
|
||||
gun.on(function(msg, ev){
|
||||
var at = msg.$._, id = at.link || at.soul || Gun.node.soul(msg.put);
|
||||
if(!id){ return }
|
||||
if(false === opt.next){ ev.off() }
|
||||
else { opt.next = true }
|
||||
|
20
sea.js
20
sea.js
@ -290,7 +290,7 @@
|
||||
}, key, S.pbkdf2.ks * 8)
|
||||
data = shim.random(data.length) // Erase data in case of passphrase
|
||||
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;
|
||||
}
|
||||
// For NodeJS crypto.pkdf2 rocks
|
||||
@ -304,7 +304,7 @@
|
||||
)
|
||||
data = shim.random(data.length) // Erase passphrase for app
|
||||
const r = hash && hash.toString('utf8')
|
||||
if(cb){ cb(r) }
|
||||
if(cb){ try{ cb(r) }catch(e){console.log(e)} }
|
||||
return r;
|
||||
} catch(e) {
|
||||
SEA.err = e;
|
||||
@ -366,7 +366,7 @@
|
||||
} dh = dh || {};
|
||||
|
||||
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;
|
||||
} catch(e) {
|
||||
SEA.err = e;
|
||||
@ -390,7 +390,7 @@
|
||||
// TODO: This would prevent pair2 signing pair1's signature.
|
||||
// So we may want to change this in the future.
|
||||
// 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;
|
||||
}
|
||||
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!
|
||||
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;
|
||||
} catch(e) {
|
||||
SEA.err = e;
|
||||
@ -427,7 +427,7 @@
|
||||
const raw = (json !== data)?
|
||||
(json.s && json.m)? parse(json.m) : data
|
||||
: json;
|
||||
if(cb){ cb(raw) }
|
||||
if(cb){ try{ cb(raw) }catch(e){console.log(e)} }
|
||||
return raw;
|
||||
}
|
||||
const pub = pair.pub || pair
|
||||
@ -439,7 +439,7 @@
|
||||
if(!check){ throw "Signature did not match." }
|
||||
const r = check? parse(json.m) : u;
|
||||
|
||||
if(cb){ cb(r) }
|
||||
if(cb){ try{ cb(r) }catch(e){console.log(e)} }
|
||||
return r;
|
||||
} catch(e) {
|
||||
SEA.err = e;
|
||||
@ -485,7 +485,7 @@
|
||||
s: rand.s.toString('utf8')
|
||||
});
|
||||
|
||||
if(cb){ cb(r) }
|
||||
if(cb){ try{ cb(r) }catch(e){console.log(e)} }
|
||||
return r;
|
||||
} catch(e) {
|
||||
SEA.err = e;
|
||||
@ -513,7 +513,7 @@
|
||||
}, aes, new Uint8Array(shim.Buffer.from(json.ct, 'utf8'))))
|
||||
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;
|
||||
} catch(e) {
|
||||
SEA.err = e;
|
||||
@ -547,7 +547,7 @@
|
||||
return ecdhSubtle.exportKey('jwk', derivedKey).then(({ k }) => k)
|
||||
})
|
||||
const r = derived;
|
||||
if(cb){ cb(r) }
|
||||
if(cb){ try{ cb(r) }catch(e){console.log(e)} }
|
||||
return r;
|
||||
} catch(e) {
|
||||
SEA.err = e;
|
||||
|
Loading…
x
Reference in New Issue
Block a user