diff --git a/as.js b/as.js index 2c0bf4f8..39e20c13 100644 --- a/as.js +++ b/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; } -}()); \ No newline at end of file +}()); + +;$(function(){ + $('.page').not(':first').hide(); + $.as.route(location.hash.slice(1)); +}); \ No newline at end of file diff --git a/examples/style.css b/examples/style.css index 3b9cd063..1822dfce 100644 --- a/examples/style.css +++ b/examples/style.css @@ -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; @@ -314,4 +314,15 @@ ul, li { 50% {color: #4D79D8;} 75% {color: #33cc33;} 100% {color: #f2b919;} +} + +.pulse { + animation: pulse 2s infinite; +} + +@keyframes pulse +{ + 0% {opacity: 1;} + 50% {opacity: 0.5;} + 100% {opacity: 1;} } \ No newline at end of file diff --git a/gun.js b/gun.js index d2b6b076..cb8edfcc 100644 --- a/gun.js +++ b/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 }); diff --git a/sea.js b/sea.js index a4b8c832..b8a841e4 100644 --- a/sea.js +++ b/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,34 +1418,24 @@ 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]){ + if((tmp = soul.split('~')) && 2 == tmp.length){ 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 + "'.", }) } + 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){ - 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; + if(pub === tmp[1]){ + (at.sea.own[rel] = at.sea.own[rel] || {})[pub] = true; + } } check['any'+soul+key] = 0; each.end({ok: 1}); @@ -1475,12 +1443,6 @@ 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); - return; - } at.on('secure', function(msg){ this.off(); check['any'+soul+key] = 0; each.end(msg || {err: "Data cannot be modified."}); @@ -1489,26 +1451,26 @@ 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}); - }); + 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? diff --git a/test/user.html b/test/user.html index d532ab87..4837bf66 100644 --- a/test/user.html +++ b/test/user.html @@ -39,7 +39,7 @@ gun.on('auth', function(){ $('#said').on('submit', function(e){ e.preventDefault(); - if(!user.is){ return } + if(!user.is){ return } user.get('said').set($('#say').val()); $('#say').val(""); });