mirror of
https://github.com/amark/gun.git
synced 2025-06-05 21:56:51 +00:00
cross computer SEA changes
This commit is contained in:
parent
2ba37800d2
commit
05915395a5
13
as.js
13
as.js
@ -97,13 +97,15 @@
|
||||
}, 99));
|
||||
var u;
|
||||
window.as = as;
|
||||
$.as = as;
|
||||
}());
|
||||
|
||||
;(function(){
|
||||
$('.page').not(':first').hide();
|
||||
$(document).on('click', 'a, button', function(e){
|
||||
var tmp = $(this).attr('href') || '';
|
||||
if(0 === tmp.indexOf('http')){ return }
|
||||
e.preventDefault();
|
||||
r($(this).attr('href'));
|
||||
r(tmp);
|
||||
});
|
||||
function r(href){
|
||||
if(!href){ return }
|
||||
@ -130,11 +132,16 @@
|
||||
});
|
||||
return $data;
|
||||
}
|
||||
setTimeout(function(){ r(location.hash.slice(1)) },1);
|
||||
window.onhashchange = function(){ r(location.hash.slice(1)) };
|
||||
$.as && ($.as.route = r);
|
||||
if(window.as){
|
||||
as.route = r;
|
||||
} else {
|
||||
$.route = r;
|
||||
}
|
||||
}());
|
||||
|
||||
;$(function(){
|
||||
$('.page').not(':first').hide();
|
||||
$.as.route(location.hash.slice(1));
|
||||
});
|
@ -31,6 +31,10 @@ button, input, textarea {
|
||||
color: black;
|
||||
}
|
||||
|
||||
a {
|
||||
color: white;
|
||||
}
|
||||
|
||||
input, textarea {
|
||||
width: 100%;
|
||||
}
|
||||
@ -66,6 +70,9 @@ ul, li {
|
||||
margin-left: auto;
|
||||
margin-right: auto;
|
||||
}
|
||||
.flush {
|
||||
line-height: 0em;
|
||||
}
|
||||
|
||||
.sit { margin-bottom: 0; }
|
||||
.row { width: 100%; }
|
||||
@ -88,6 +95,10 @@ ul, li {
|
||||
.gap {
|
||||
padding: 3%;
|
||||
}
|
||||
.ditch {
|
||||
margin-top: 2em;
|
||||
margin-bottom: 2em;
|
||||
}
|
||||
|
||||
.loud {
|
||||
font-size: 150%;
|
||||
@ -145,17 +156,6 @@ ul, li {
|
||||
color: white;
|
||||
}
|
||||
|
||||
.pulse {
|
||||
animation: pulse 2s infinite;
|
||||
}
|
||||
|
||||
@keyframes pulse
|
||||
{
|
||||
0% {opacity: 1;}
|
||||
50% {opacity: 0.5;}
|
||||
100% {opacity: 1;}
|
||||
}
|
||||
|
||||
.hue {
|
||||
background: #4D79D8;
|
||||
-webkit-animation: hue 900s infinite;
|
||||
@ -315,3 +315,14 @@ ul, li {
|
||||
75% {color: #33cc33;}
|
||||
100% {color: #f2b919;}
|
||||
}
|
||||
|
||||
.pulse {
|
||||
animation: pulse 2s infinite;
|
||||
}
|
||||
|
||||
@keyframes pulse
|
||||
{
|
||||
0% {opacity: 1;}
|
||||
50% {opacity: 0.5;}
|
||||
100% {opacity: 1;}
|
||||
}
|
1
gun.js
1
gun.js
@ -1374,6 +1374,7 @@
|
||||
var tmp = cat.root.now; obj.del(cat.root, 'now'); cat.root.PUT = true;
|
||||
var tmp2 = cat.root.stop;
|
||||
(as.ref._).now = true;
|
||||
console.log("PUT!", as.env.graph);
|
||||
(as.ref._).on('out', {
|
||||
gun: as.ref, put: as.out = as.env.graph, opt: as.opt, '#': ask
|
||||
});
|
||||
|
102
sea.js
102
sea.js
@ -1290,12 +1290,11 @@
|
||||
at.sea = {own: {}};
|
||||
var uuid = at.opt.uuid || Gun.state.lex;
|
||||
at.opt.uuid = function(cb){ // TODO: consider async/await and drop callback pattern...
|
||||
if(!cb){ return }
|
||||
var id = uuid(), pair = at.user && (at.user._).sea;
|
||||
if(!pair){ return id }
|
||||
SEA.sign(id, pair).then(function(sig){
|
||||
cb(null, id + '~' + sig);
|
||||
}).catch(function(e){cb(e)});
|
||||
var id = uuid(), pub = at.user;
|
||||
if(!pub || !(pub = at.user._.sea) || !(pub = pub.pub)){ return id }
|
||||
id = id + '~' + pub;
|
||||
if(cb){ cb(null, id) }
|
||||
return id;
|
||||
}
|
||||
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.
|
||||
@ -1331,19 +1330,6 @@
|
||||
d = true;
|
||||
if(d && !c){ to.next(msg) }
|
||||
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.
|
||||
@ -1377,7 +1363,7 @@
|
||||
}
|
||||
if(msg.put){
|
||||
// potentially parallel async operations!!!
|
||||
var check = {}, on = Gun.on(), each = {}, u;
|
||||
var check = {}, each = {}, u;
|
||||
each.node = function(node, soul){
|
||||
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});
|
||||
@ -1396,15 +1382,6 @@
|
||||
}
|
||||
each.any(val, key, node, soul, msg.user); return;
|
||||
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}}
|
||||
if(!val){ return each.end({err: "Data must exist!"}) } // data MUST exist
|
||||
@ -1423,8 +1400,8 @@
|
||||
}
|
||||
check['user'+soul+key] = 1;
|
||||
if(user && (user = user._) && user.sea && pub === user.pub){
|
||||
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;
|
||||
//var id = Gun.text.random(3);
|
||||
SEA.write(val, user.sea).then(function(data){ var rel;
|
||||
if(rel = Gun.val.rel.is(val)){
|
||||
(at.sea.own[rel] = at.sea.own[rel] || {})[pub] = true;
|
||||
}
|
||||
@ -1432,6 +1409,7 @@
|
||||
check['user'+soul+key] = 0;
|
||||
each.end({ok: 1});
|
||||
});
|
||||
// TODO: Handle error!!!!
|
||||
return;
|
||||
}
|
||||
// TODO: consider async/await and drop callback pattern...
|
||||
@ -1440,47 +1418,31 @@
|
||||
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){
|
||||
SEA.verify(tmp[0], pub, tmp[1]).then(function(ok){
|
||||
if(!ok){ return each.end({err: "Signature did not match account."}) }
|
||||
if(pub === tmp[1]){
|
||||
(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;
|
||||
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 = at.sea.own[soul]){
|
||||
check['any'+soul+key] = 1;
|
||||
user = Gun.obj.map(user, function(a,b){ return b });
|
||||
// TODO: consider async/await and drop callback pattern...
|
||||
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){
|
||||
SEA.verify(tmp[0], user, tmp[1]).then(function(ok){
|
||||
if(!ok){ return each.end({err: "Signature did not match account."}) }
|
||||
(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;
|
||||
each.end({ok: 1});
|
||||
});
|
||||
return;
|
||||
}
|
||||
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);
|
||||
check['any'+soul+key] = 1;
|
||||
SEA.read(val, (pub = tmp[1])).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(pub === tmp[1]){
|
||||
(at.sea.own[rel] = at.sea.own[rel] || {})[pub] = true;
|
||||
}
|
||||
}
|
||||
check['any'+soul+key] = 0;
|
||||
each.end({ok: 1});
|
||||
});
|
||||
return;
|
||||
}
|
||||
check['any'+soul+key] = 1;
|
||||
at.on('secure', function(msg){ this.off();
|
||||
check['any'+soul+key] = 0;
|
||||
each.end(msg || {err: "Data cannot be modified."});
|
||||
@ -1489,27 +1451,27 @@
|
||||
return;
|
||||
}
|
||||
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;
|
||||
}
|
||||
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(other){
|
||||
each.any(val, key, node, soul);
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
check['any'+soul+key] = 1;
|
||||
// TODO: consider async/await and drop callback pattern...
|
||||
SEA.verify(tmp[0], user.pub, tmp[1]).then(function(ok){
|
||||
if(!ok){ return each.end({err: "Signature did not match account at '" + key + "'."}) }
|
||||
(at.sea.own[soul] = at.sea.own[soul] || {})[user.pub] = true;
|
||||
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?
|
||||
if(each.err){ return }
|
||||
|
Loading…
x
Reference in New Issue
Block a user