cross computer SEA changes

This commit is contained in:
Mark Nadal 2018-04-03 12:12:29 -07:00
parent 2ba37800d2
commit 05915395a5
5 changed files with 65 additions and 84 deletions

15
as.js
View File

@ -97,13 +97,15 @@
}, 99)); }, 99));
var u; var u;
window.as = as; window.as = as;
$.as = as;
}()); }());
;(function(){ ;(function(){
$('.page').not(':first').hide();
$(document).on('click', 'a, button', function(e){ $(document).on('click', 'a, button', function(e){
var tmp = $(this).attr('href') || '';
if(0 === tmp.indexOf('http')){ return }
e.preventDefault(); e.preventDefault();
r($(this).attr('href')); r(tmp);
}); });
function r(href){ function r(href){
if(!href){ return } if(!href){ return }
@ -130,11 +132,16 @@
}); });
return $data; return $data;
} }
setTimeout(function(){ r(location.hash.slice(1)) },1);
window.onhashchange = function(){ r(location.hash.slice(1)) }; window.onhashchange = function(){ r(location.hash.slice(1)) };
$.as && ($.as.route = r);
if(window.as){ if(window.as){
as.route = r; as.route = r;
} else { } else {
$.route = r; $.route = r;
} }
}()); }());
;$(function(){
$('.page').not(':first').hide();
$.as.route(location.hash.slice(1));
});

View File

@ -31,6 +31,10 @@ button, input, textarea {
color: black; color: black;
} }
a {
color: white;
}
input, textarea { input, textarea {
width: 100%; width: 100%;
} }
@ -66,6 +70,9 @@ ul, li {
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
} }
.flush {
line-height: 0em;
}
.sit { margin-bottom: 0; } .sit { margin-bottom: 0; }
.row { width: 100%; } .row { width: 100%; }
@ -88,6 +95,10 @@ ul, li {
.gap { .gap {
padding: 3%; padding: 3%;
} }
.ditch {
margin-top: 2em;
margin-bottom: 2em;
}
.loud { .loud {
font-size: 150%; font-size: 150%;
@ -145,17 +156,6 @@ ul, li {
color: white; color: white;
} }
.pulse {
animation: pulse 2s infinite;
}
@keyframes pulse
{
0% {opacity: 1;}
50% {opacity: 0.5;}
100% {opacity: 1;}
}
.hue { .hue {
background: #4D79D8; background: #4D79D8;
-webkit-animation: hue 900s infinite; -webkit-animation: hue 900s infinite;
@ -314,4 +314,15 @@ ul, li {
50% {color: #4D79D8;} 50% {color: #4D79D8;}
75% {color: #33cc33;} 75% {color: #33cc33;}
100% {color: #f2b919;} 100% {color: #f2b919;}
}
.pulse {
animation: pulse 2s infinite;
}
@keyframes pulse
{
0% {opacity: 1;}
50% {opacity: 0.5;}
100% {opacity: 1;}
} }

1
gun.js
View File

@ -1374,6 +1374,7 @@
var tmp = cat.root.now; obj.del(cat.root, 'now'); cat.root.PUT = true; var tmp = cat.root.now; obj.del(cat.root, 'now'); cat.root.PUT = true;
var tmp2 = cat.root.stop; var tmp2 = cat.root.stop;
(as.ref._).now = true; (as.ref._).now = true;
console.log("PUT!", as.env.graph);
(as.ref._).on('out', { (as.ref._).on('out', {
gun: as.ref, put: as.out = as.env.graph, opt: as.opt, '#': ask gun: as.ref, put: as.out = as.env.graph, opt: as.opt, '#': ask
}); });

98
sea.js
View File

@ -1290,12 +1290,11 @@
at.sea = {own: {}}; at.sea = {own: {}};
var uuid = at.opt.uuid || Gun.state.lex; var uuid = at.opt.uuid || Gun.state.lex;
at.opt.uuid = function(cb){ // TODO: consider async/await and drop callback pattern... at.opt.uuid = function(cb){ // TODO: consider async/await and drop callback pattern...
if(!cb){ return } var id = uuid(), pub = at.user;
var id = uuid(), pair = at.user && (at.user._).sea; if(!pub || !(pub = at.user._.sea) || !(pub = pub.pub)){ return id }
if(!pair){ return id } id = id + '~' + pub;
SEA.sign(id, pair).then(function(sig){ if(cb){ cb(null, id) }
cb(null, id + '~' + sig); return id;
}).catch(function(e){cb(e)});
} }
at.on('in', security, at); // now listen to all input data, acting as a firewall. at.on('in', security, at); // now listen to all input data, acting as a firewall.
at.on('out', signature, at); // and output listeners, to encrypt outgoing data. at.on('out', signature, at); // and output listeners, to encrypt outgoing data.
@ -1331,19 +1330,6 @@
d = true; d = true;
if(d && !c){ to.next(msg) } if(d && !c){ to.next(msg) }
return; return;
/*var to = this.to, ctx = this.as;
var own = ctx.sea.own, soul = msg.get, c = 0;
var pub = own[soul] || soul.slice(4), vertex = (msg.gun._).put;
Gun.node.is(msg.put, function(val, key, node){ c++; // for each property on the node.
SEA.read(val, pub).then(function(data){ c--;
vertex[key] = node[key] = val = data; // verify signature and get plain value.
if(val && val['#'] && (key = Gun.val.rel.is(val))){ // if it is a relation / edge
if('alias/' !== soul.slice(0,6)){ own[key] = pub; } // associate the public key with a node if it is itself
}
if(!c && (c = -1)){ to.next(msg) }
});
});
if(!c){ to.next(msg) }*/
} }
// signature handles data output, it is a proxy to the security function. // signature handles data output, it is a proxy to the security function.
@ -1377,7 +1363,7 @@
} }
if(msg.put){ if(msg.put){
// potentially parallel async operations!!! // potentially parallel async operations!!!
var check = {}, on = Gun.on(), each = {}, u; var check = {}, each = {}, u;
each.node = function(node, soul){ each.node = function(node, soul){
if(Gun.obj.empty(node, '_')){ return check['node'+soul] = 0 } // ignore empty updates, don't reject them. if(Gun.obj.empty(node, '_')){ return check['node'+soul] = 0 } // ignore empty updates, don't reject them.
Gun.obj.map(node, each.way, {soul: soul, node: node}); Gun.obj.map(node, each.way, {soul: soul, node: node});
@ -1396,15 +1382,6 @@
} }
each.any(val, key, node, soul, msg.user); return; each.any(val, key, node, soul, msg.user); return;
return each.end({err: "No other data allowed!"}); return each.end({err: "No other data allowed!"});
/*if(!(tmp = at.user)){ return }
if(soul.slice(4) === (tmp = tmp._).pub){ // not a special case, if we are logged in and have outbound data on us.
each.user(val, key, node, soul, {
pub: tmp.pub, priv: tmp.sea.priv, epub: tmp.sea.epub, epriv: tmp.sea.epriv
});
}
if((tmp = sea.own[soul])){ // not special case, if we receive an update on an ID associated with a public key, then
each.own(val, key, node, soul, tmp);
}*/
}; };
each.alias = function(val, key, node, soul){ // Example: {_:#alias, alias/alice: {#alias/alice}} each.alias = function(val, key, node, soul){ // Example: {_:#alias, alias/alice: {#alias/alice}}
if(!val){ return each.end({err: "Data must exist!"}) } // data MUST exist if(!val){ return each.end({err: "Data must exist!"}) } // data MUST exist
@ -1423,8 +1400,8 @@
} }
check['user'+soul+key] = 1; check['user'+soul+key] = 1;
if(user && (user = user._) && user.sea && pub === user.pub){ if(user && (user = user._) && user.sea && pub === user.pub){
var id = Gun.text.random(3); //var id = Gun.text.random(3);
SEA.write(val, Gun.obj.to(user.sea, {pub: user.pub, epub: user.epub})).then(function(data){ var rel; SEA.write(val, user.sea).then(function(data){ var rel;
if(rel = Gun.val.rel.is(val)){ if(rel = Gun.val.rel.is(val)){
(at.sea.own[rel] = at.sea.own[rel] || {})[pub] = true; (at.sea.own[rel] = at.sea.own[rel] || {})[pub] = true;
} }
@ -1432,6 +1409,7 @@
check['user'+soul+key] = 0; check['user'+soul+key] = 0;
each.end({ok: 1}); each.end({ok: 1});
}); });
// TODO: Handle error!!!!
return; return;
} }
// TODO: consider async/await and drop callback pattern... // TODO: consider async/await and drop callback pattern...
@ -1440,34 +1418,24 @@
return each.end({err: "Unverified data."}); // reject any updates that are signed with a mismatched account. return each.end({err: "Unverified data."}); // reject any updates that are signed with a mismatched account.
} }
if((rel = Gun.val.rel.is(data)) && (tmp = rel.split('~')) && 2 === tmp.length){ if((rel = Gun.val.rel.is(data)) && (tmp = rel.split('~')) && 2 === tmp.length){
SEA.verify(tmp[0], pub, tmp[1]).then(function(ok){ if(pub === tmp[1]){
if(!ok){ return each.end({err: "Signature did not match account."}) }
(at.sea.own[rel] = at.sea.own[rel] || {})[pub] = true; (at.sea.own[rel] = at.sea.own[rel] || {})[pub] = true;
check['user'+soul+key] = 0; }
each.end({ok: 1});
});
return;
} }
check['user'+soul+key] = 0; check['user'+soul+key] = 0;
each.end({ok: 1}); each.end({ok: 1});
}); });
}; };
each.any = function(val, key, node, soul, user){ var tmp; each.any = function(val, key, node, soul, user){ var tmp, pub;
if(!user || !(user = user._) || !(user = user.sea)){ if(!user || !(user = user._) || !(user = user.sea)){
if(user = at.sea.own[soul]){ if((tmp = soul.split('~')) && 2 == tmp.length){
check['any'+soul+key] = 1; check['any'+soul+key] = 1;
user = Gun.obj.map(user, function(a,b){ return b }); SEA.read(val, (pub = tmp[1])).then(function(data){ var rel;
// TODO: consider async/await and drop callback pattern... if(!data){ return each.end({err: "Mismatched owner on '" + key + "'."}) }
SEA.read(val, user).then(function(data){ var rel;
if(!data){ return each.end({err: "Mismatched owner on '" + key + "'.", }) }
if((rel = Gun.val.rel.is(data)) && (tmp = rel.split('~')) && 2 === tmp.length){ if((rel = Gun.val.rel.is(data)) && (tmp = rel.split('~')) && 2 === tmp.length){
SEA.verify(tmp[0], user, tmp[1]).then(function(ok){ if(pub === tmp[1]){
if(!ok){ return each.end({err: "Signature did not match account."}) } (at.sea.own[rel] = at.sea.own[rel] || {})[pub] = true;
(at.sea.own[rel] = at.sea.own[rel] || {})[user] = true; }
check['any'+soul+key] = 0;
each.end({ok: 1});
});
return;
} }
check['any'+soul+key] = 0; check['any'+soul+key] = 0;
each.end({ok: 1}); each.end({ok: 1});
@ -1475,12 +1443,6 @@
return; return;
} }
check['any'+soul+key] = 1; check['any'+soul+key] = 1;
if((tmp = soul.split('~')) && 2 == tmp.length){
setTimeout(function(){ // hacky idea, what would be better?
each.any(val, key, node, soul);
},1);
return;
}
at.on('secure', function(msg){ this.off(); at.on('secure', function(msg){ this.off();
check['any'+soul+key] = 0; check['any'+soul+key] = 0;
each.end(msg || {err: "Data cannot be modified."}); each.end(msg || {err: "Data cannot be modified."});
@ -1489,26 +1451,26 @@
return; return;
} }
if(!(tmp = soul.split('~')) || 2 !== tmp.length){ if(!(tmp = soul.split('~')) || 2 !== tmp.length){
each.end({err: "Soul is not signed at '" + key + "'."}); each.end({err: "Soul is missing public key at '" + key + "'."});
return; return;
} }
var other = Gun.obj.map(at.sea.own[soul], function(v, p){ var pub = tmp[1];
if(pub !== user.pub){
each.any(val, key, node, soul);
return;
}
/*var other = Gun.obj.map(at.sea.own[soul], function(v, p){
if(user.pub !== p){ return p } if(user.pub !== p){ return p }
}); });
if(other){ if(other){
each.any(val, key, node, soul); each.any(val, key, node, soul);
return; return;
} }*/
check['any'+soul+key] = 1; check['any'+soul+key] = 1;
// TODO: consider async/await and drop callback pattern... SEA.write(val, user).then(function(data){
SEA.verify(tmp[0], user.pub, tmp[1]).then(function(ok){ node[key] = data;
if(!ok){ return each.end({err: "Signature did not match account at '" + key + "'."}) } check['any'+soul+key] = 0;
(at.sea.own[soul] = at.sea.own[soul] || {})[user.pub] = true; each.end({ok: 1});
SEA.write(val, user).then(function(data){
node[key] = data;
check['any'+soul+key] = 0;
each.end({ok: 1});
});
}); });
} }
each.end = function(ctx){ // TODO: Can't you just switch this to each.end = cb? each.end = function(ctx){ // TODO: Can't you just switch this to each.end = cb?

View File

@ -39,7 +39,7 @@ gun.on('auth', function(){
$('#said').on('submit', function(e){ $('#said').on('submit', function(e){
e.preventDefault(); e.preventDefault();
if(!user.is){ return } if(!user.is){ return }
user.get('said').set($('#say').val()); user.get('said').set($('#say').val());
$('#say').val(""); $('#say').val("");
}); });