once fix, clean sea

This commit is contained in:
Mark Nadal 2018-10-11 15:27:01 -07:00
parent 41482d25cc
commit 774fcc789b
8 changed files with 74 additions and 55 deletions

18
gun.js
View File

@ -1655,19 +1655,19 @@
var opt = this.as, cat = opt.at, gun = msg.$, at = gun._, data = at.put || msg.put, link, tmp;
if(tmp = msg.$$){
link = tmp = (msg.$$._);
if(u === tmp.put){
return;
if(u !== link.put){
data = link.put;
}
data = tmp.put;
}
if((tmp = eve.wait) && (tmp = tmp[at.id])){ clearTimeout(tmp) }
if((!to && (u === data || at.soul || at.link || (link && !(0 < link.ack))))
|| (u === data && (tmp = (obj_map(at.root.opt.peers, function(v,k,t){t(k)})||[]).length) && (link||at).ack <= tmp)){
|| (u === data && (tmp = (obj_map(at.root.opt.peers, function(v,k,t){t(k)})||[]).length) && (!to && (link||at).ack <= tmp))){
tmp = (eve.wait = {})[at.id] = setTimeout(function(){
val.call({as:opt}, msg, eve, tmp || 1);
}, opt.wait || 99);
return;
}
if(link && u === link.put && (tmp = rel.is(data))){ data = Gun.node.ify({}, tmp) }
eve.rid(msg);
opt.ok.call(gun || opt.$, data, msg.get);
}
@ -1774,10 +1774,12 @@
;USE(function(module){
if(typeof Gun === 'undefined'){ return } // TODO: localStorage is Browser only. But it would be nice if it could somehow plugin into NodeJS compatible localStorage APIs?
var root, noop = function(){}, u;
if(typeof window !== 'undefined'){ root = window }
var store = root.localStorage || {setItem: noop, removeItem: noop, getItem: noop};
var root, noop = function(){}, store, u;
try{store = (Gun.window||noop).localStorage}catch(e){}
if(!store){
console.log("Warning: No localStorage exists to persist data to!");
store = {setItem: noop, removeItem: noop, getItem: noop};
}
/*
NOTE: Both `lib/file.js` and `lib/memdisk.js` are based on this design!
If you update anything here, consider updating the other adapters as well.

2
gun.min.js vendored

File diff suppressed because one or more lines are too long

21
lib/super.js Normal file
View File

@ -0,0 +1,21 @@
;(function(){
var Gun = (typeof window !== "undefined")? window.Gun : require('../gun');
var Rad = (Gun.window||{}).Radix || require('./radix');
function input(msg){
var at = this.as, to = this.to, peer = (msg.mesh||empty).via;
var get = msg.get, soul, key;
if(!peer || !get){ return to.next(msg) }
console.log("super", msg);
if(soul = get['#']){
if(key = get['.']){
} else {
}
}
to.next(msg);
}
var empty = {}, u;
if(Gun.window){ return }
try{module.exports = input}catch(e){}
}());

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "gun",
"version": "0.9.99995",
"version": "0.9.99996",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "gun",
"version": "0.9.99996",
"version": "0.9.99997",
"description": "A realtime, decentralized, offline-first, graph data synchronization engine.",
"main": "index.js",
"browser": "gun.min.js",

80
sea.js
View File

@ -124,7 +124,7 @@
}
return buf
}
const byteLength = input.byteLength
const byteLength = input.byteLength // what is going on here? FOR MARTTI
const length = input.byteLength ? input.byteLength : input.length
if (length) {
let buf
@ -157,45 +157,40 @@
})(USE, './buffer');
;USE(function(module){
const SEA = USE('./root')
const Buffer = USE('./buffer')
const api = {Buffer: Buffer}
var o = {};
if (typeof window !== 'undefined') {
var crypto = window.crypto || window.msCrypto;
var subtle = crypto.subtle || crypto.webkitSubtle;
const TextEncoder = window.TextEncoder
const TextDecoder = window.TextDecoder
if(SEA.window){
api.crypto = window.crypto || window.msCrypto;
api.subtle = (api.crypto||o).subtle || (api.crypto||o).webkitSubtle;
api.TextEncoder = window.TextEncoder;
api.TextDecoder = window.TextDecoder;
api.random = (len) => Buffer.from(api.crypto.getRandomValues(new Uint8Array(Buffer.alloc(len))))
}
if(!api.crypto){try{
var crypto = USE('crypto', 1);
const { subtle } = USE('@trust/webcrypto', 1) // All but ECDH
const { TextEncoder, TextDecoder } = USE('text-encoding', 1)
Object.assign(api, {
crypto,
subtle,
TextEncoder,
TextDecoder,
random: (len) => Buffer.from(crypto.getRandomValues(new Uint8Array(Buffer.alloc(len))))
})
} else {
try{
var crypto = USE('crypto', 1);
const { subtle } = USE('@trust/webcrypto', 1) // All but ECDH
const { TextEncoder, TextDecoder } = USE('text-encoding', 1)
Object.assign(api, {
crypto,
subtle,
TextEncoder,
TextDecoder,
random: (len) => Buffer.from(crypto.randomBytes(len))
});
//try{
const WebCrypto = USE('node-webcrypto-ossl', 1)
api.ossl = new WebCrypto({directory: 'ossl'}).subtle // ECDH
//}catch(e){
//console.log("node-webcrypto-ossl is optionally needed for ECDH, please install if needed.");
//}
}catch(e){
console.log("@trust/webcrypto and text-encoding are not included by default, you must add it to your package.json!");
console.log("node-webcrypto-ossl is temporarily needed for ECDSA signature verification, and optionally needed for ECDH, please install if needed (currently necessary so add them to your package.json for now).");
TRUST_WEBCRYPTO_OR_TEXT_ENCODING_NOT_INSTALLED;
}
}
random: (len) => Buffer.from(crypto.randomBytes(len))
});
//try{
const WebCrypto = USE('node-webcrypto-ossl', 1)
api.ossl = new WebCrypto({directory: 'ossl'}).subtle // ECDH
//}catch(e){
//console.log("node-webcrypto-ossl is optionally needed for ECDH, please install if needed.");
//}
}catch(e){
console.log("@trust/webcrypto and text-encoding are not included by default, you must add it to your package.json!");
console.log("node-webcrypto-ossl is temporarily needed for ECDSA signature verification, and optionally needed for ECDH, please install if needed (currently necessary so add them to your package.json for now).");
TRUST_WEBCRYPTO_OR_TEXT_ENCODING_NOT_INSTALLED;
}}
module.exports = api
})(USE, './shim');
@ -436,6 +431,7 @@
if(cb){ try{ cb(raw) }catch(e){console.log(e)} }
return raw;
}
if(json === data){ throw "No signature on data." }
const pub = pair.pub || pair
const jwk = S.jwk(pub)
const key = await (shim.ossl || shim.subtle).importKey('jwk', jwk, S.ecdsa.pair, false, ['verify'])
@ -448,7 +444,7 @@
if(cb){ try{ cb(r) }catch(e){console.log(e)} }
return r;
} catch(e) {
console.log(e);
console.log(e); // mismatched owner FOR MARTTI
SEA.err = e;
if(cb){ cb() }
return;
@ -747,10 +743,10 @@
// TODO: 'salt' needed?
err = null
if(SEA.window){
var tmp = SEA.window.sessionStorage;
var tmp; try{tmp = window.sessionStorage}catch(e){}
if(tmp && gunRoot._.opt.remember){ // TODO: Bug! This needs to be moved to finalize?
SEA.window.sessionStorage.alias = alias;
SEA.window.sessionStorage.tmp = pass;
tmp.alias = alias;
tmp.tmp = pass;
}
}
return {priv: priv, pub: a.put.pub, salt: salt, epub: epub, epriv: epriv };
@ -1302,8 +1298,8 @@
delete user._.is;
delete user._.sea;
}
if(typeof window !== 'undefined'){
var tmp = window.sessionStorage;
if(SEA.window){
var tmp; try{tmp = window.sessionStorage}catch(e){}; tmp = tmp || {};
delete tmp.alias;
delete tmp.tmp;
}
@ -1339,10 +1335,10 @@
let validity
let opts
var o = setvalidity;
var o = setvalidity, tmp;
if(o && o.sessionStorage){
if(typeof window !== 'undefined'){
var tmp = window.sessionStorage;
if(SEA.window){
try{tmp = window.sessionStorage}catch(e){}
if(tmp){
gunRoot._.opt.remember = true;
if(tmp.alias && tmp.tmp){
@ -1658,7 +1654,7 @@
each.end = function(ctx){ // TODO: Can't you just switch this to each.end = cb?
if(each.err){ return }
if((each.err = ctx.err) || ctx.no){
console.log('NO!', each.err, msg.put);
console.log('NO!', each.err, msg.put); // 451 mistmached data FOR MARTTI
return;
}
if(!each.end.ed){ return }

View File

@ -64,7 +64,7 @@ function soul(gun, cb, opt, as){
var cat = gun._, tmp;
if(tmp = cat.soul){ return cb(tmp, as, cat), gun }
if(tmp = cat.link){ return cb(tmp, as, cat), gun }
gun.get(function(msg, ev){
gun.get(function(msg, ev){ // TODO: Bug! Needs once semantics?
ev.rid(msg);
var at = ((at = msg.$) && at._) || {};
tmp = at.link || at.soul || rel.is(msg.put) || node_soul(msg.put);

View File

@ -229,7 +229,7 @@ Gun.log.once = function(w,s,o){ return (o = Gun.log.once)[w] = o[w] || 0, o[w]++
Gun.log.once("welcome", "Hello wonderful person! :) Thanks for using GUN, feel free to ask for help on https://gitter.im/amark/gun and ask StackOverflow questions tagged with 'gun'!");
;"Please do not remove these messages unless you are paying for a monthly sponsorship, thanks!";
if(typeof window !== "undefined"){ (window.Gun = Gun).window = window }
if(typeof window !== "undefined"){ (window.GUN = window.Gun = Gun).window = window }
try{ if(typeof common !== "undefined"){ common.exports = Gun } }catch(e){}
module.exports = Gun;