gun-eth 1.3.6 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ !function(t,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n(require("gun/sea"),require("ethers")):"function"==typeof define&&define.amd?define(["gun/sea","ethers"],n):(t="undefined"!=typeof globalThis?globalThis:t||self).GunEth=n(t.SEA,t.ethers)}(this,(function(t,n){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function o(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var i={exports:{}};var r,a={exports:{}};function s(){return r||(r=1,function(t){!function(){function n(t,e){return e?function(t){throw new Error('Could not dynamically require "'+t+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}(t):t.slice?n[o(t)]:function(e,i){t(e={exports:{}}),n[o(i)]=e.exports};function o(t){return t.split("/").slice(-1).toString().replace(".js","")}}var e=t;n((function(t){String.random=function(t,n){var e="";for(t=t||24,n=n||"0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";t-- >0;)e+=n.charAt(Math.floor(Math.random()*n.length));return e},String.match=function(t,n){var e,o;return"string"==typeof t&&("string"==typeof n&&(n={"=":n}),t===(e=(n=n||{})["="]||n["*"]||n[">"]||n["<"])||o===n["="]&&(e=n["*"]||n[">"],t.slice(0,(e||"").length)===e||o===n["*"]&&(o!==n[">"]&&o!==n["<"]?t>=n[">"]&&t<=n["<"]:o!==n[">"]&&t>=n[">"]||o!==n["<"]&&t<=n["<"])))},String.hash=function(t,n){if("string"==typeof t){if(n=n||0,!t.length)return n;for(var e=0,o=t.length;e<o;++e)n=(n<<5)-n+t.charCodeAt(e),n|=0;return n}};var n,e,o,i,r,a,s=Object.prototype.hasOwnProperty;Object.plain=function(t){return!!t&&(t instanceof Object&&t.constructor===Object||"Object"===Object.prototype.toString.call(t).match(/^\[object (\w+)\]$/)[1])},Object.empty=function(t,n){for(var e in t)if(s.call(t,e)&&(!n||-1==n.indexOf(e)))return!1;return!0},Object.keys=Object.keys||function(t){var n=[];for(var e in t)s.call(t,e)&&n.push(e);return n},e=setTimeout,o=0,i=0,r=typeof setImmediate!=""+n&&setImmediate||function(t,o){return typeof MessageChannel==""+n?e:((t=new MessageChannel).port1.onmessage=function(t){""==t.data&&o()},function(n){o=n,t.port2.postMessage("")})}(),a=e.check=e.check||typeof performance!=""+n&&performance||{now:function(){return+new Date}},e.hold=e.hold||9,e.poll=e.poll||function(t){e.hold>=a.now()-o&&i++<3333?t():r((function(){o=a.now(),t()}),i=0)},function(){var t,n=setTimeout,e=n.turn=n.turn||function(t){1==o.push(t)&&i(a)},o=e.s=[],i=n.poll,r=0,a=function(){(t=o[r++])&&t(),r!=o.length&&99!=r||(o=e.s=o.slice(r),r=0),o.length&&i(a)}}(),function(){var t,n=setTimeout,e=n.turn;(n.each=n.each||function(n,o,i,r){r=r||9,function a(s,u,c){if(u=(s=(n||[]).splice(0,r)).length){for(var f=0;f<u&&t===(c=o(s[f]));f++);if(t===c)return void e(a)}i&&i(c)}()})()}()}))(n,"./shim"),n((function(t){t.exports=function t(n,e,o){if(!n)return{to:t};var i="function"==typeof e;n=(this.tag||(this.tag={}))[n]||i&&(this.tag[n]={tag:n,to:t._={next:function(t){var n;(n=this.to)&&n.next(t)}}});if(i){var r={off:t.off||(t.off=function(){if(this.next===t._.next)return!0;this===this.the.last&&(this.the.last=this.back),this.to.back=this.back,this.next=t._.next,this.back.to=this.to,this.the.last===this.the&&delete this.on.tag[this.the.tag]}),to:t._,next:e,the:n,on:this,as:o};return(r.back=n.last||n).to=r,n.last=r}return(n=n.to)&&undefined!==e&&n.next(e),n}}))(n,"./onto"),n((function(t){t.exports=function(t){return null===t||"string"==typeof t||"boolean"==typeof t||"number"==typeof t&&t!=1/0&&t!=-1/0&&t==t||!!t&&"string"==typeof t["#"]&&1===Object.keys(t).length&&t["#"]}}))(n,"./valid"),n((function(t){function e(){var t=+new Date;return s<t?(r=0,s=t+e.drift):s=t+(r+=1)/a+e.drift}n("./shim"),e.drift=0;var o,i=-1/0,r=0,a=999,s=i;e.is=function(t,n,e){var o=n&&t&&t._&&t._[">"]||e;if(o)return"number"==typeof(o=o[n])?o:i},e.ify=function(t,n,e,i,r){(t=t||{})._=t._||{},r&&(t._["#"]=r);var a=t._[">"]||(t._[">"]={});return o!==n&&"_"!==n&&("number"==typeof e&&(a[n]=e),o!==i&&(t[n]=i)),t},t.exports=e}))(n,"./state"),n((function(t){n("./shim"),t.exports=function(t){var n={s:{}},e=n.s;t=t||{max:999,age:9e3},n.check=function(t){return!!e[t]&&o(t)};var o=n.track=function(i){var r=e[i]||(e[i]={});return r.was=n.now=+new Date,n.to||(n.to=setTimeout(n.drop,t.age+9)),o.ed&&o.ed(i),r};return n.drop=function(o){n.to=null,n.now=+new Date;var i=Object.keys(e);console.STAT&&console.STAT(n.now,+new Date-n.now,"dup drop keys"),setTimeout.each(i,(function(i){var r=e[i];r&&(o||t.age)>n.now-r.was||delete e[i]}),0,99)},n}}))(n,"./dup"),n((function(t){n("./onto"),t.exports=function(t,n){if(this.on){var o=(this.opt||{}).lack||9e3;if("function"!=typeof t){if(!t)return;var i=t["#"]||t,r=(this.tag||"")[i];if(!r)return;return n&&(r=this.on(i,n),clearTimeout(r.err),r.err=setTimeout((function(){r.off()}),o)),!0}i=n&&n["#"]||e(9);if(!t)return i;var a=this.on(i,t,n);return a.err=a.err||setTimeout((function(){a.off(),a.next({err:"Error: No ACK yet.",lack:!0})}),o),i}};var e=String.random||function(){return Math.random().toString(36).slice(2)}}))(n,"./ask"),n((function(t){function o(t){return t instanceof o?(this._={$:this}).$:this instanceof o?o.create(this._={$:this,opt:t}):new o(t)}o.is=function(t){return t instanceof o||t&&t._&&t===t._.$||!1},o.version=.202,o.chain=o.prototype,o.chain.toJSON=function(){},n("./shim"),o.valid=n("./valid"),o.state=n("./state"),o.on=n("./onto"),o.dup=n("./dup"),o.ask=n("./ask"),function(){function t(e){if(e)if(e.out!==t){var i,r=this.as,u=r.at||r,c=u.$,f=u.dup,l=e.DBG;if((i=e["#"])||(i=e["#"]=s(9)),!f.check(i)){if(f.track(i),i=e._,e._="function"==typeof i?i:function(){},e.$&&e.$===(e.$._||"").$||(e.$=c),e["@"]&&!e.put&&function(t){var n,e=t["@"]||"";if(!(n=e._)){var o=(o=t.$)&&(o=o._)&&(o=o.root)&&(o=o.dup);if(!(o=o.check(e)))return;return void(t["@"]=o["#"]||t["@"])}n.acks=(n.acks||0)+1,(n.err=t.err)&&(t["@"]=n["#"],a(n));n.ok=t.ok||n.ok,n.stop||n.crack||(n.crack=n.match&&n.match.push((function(){h(n)})));h(n)}(e),!u.ask(e["@"],e)){if(l&&(l.u=+new Date),e.put)return void n(e);e.get&&o.on.get(e,c)}l&&(l.uc=+new Date),this.to.next(e),l&&(l.ua=+new Date),e.nts||e.NTS||(e.out=t,u.on("out",e),l&&(l.ue=+new Date))}}else this.to.next(e)}function n(n){if(n){var o=n._||"",r=o.root=((o.$=n.$||"")._||"").root;if(n["@"]&&o.faith&&!o.miss)return n.out=t,void r.on("out",n);o.latch=r.hatch,o.match=r.hatch=[];var s=n.put,f=o.DBG=n.DBG,l=+new Date;if(d=d||l,!s["#"]||!s["."]){f&&(f.p=l),o["#"]=n["#"],o.msg=n,o.all=0,o.stun=1;var p=Object.keys(s);console.STAT&&console.STAT(l,((f||o).pk=+new Date)-l,"put sort");var h,v,m,b,w,_,T,x=0;!function t(r){if(h!=x){if(h=x,!(m=p[x]))return console.STAT&&console.STAT(l,((f||o).pd=+new Date)-l,"put"),void a(o);(b=s[m])?(T=b._)?m!==T["#"]?_=g+y(m)+"soul not same.":(w=T[">"])||(_=g+y(m)+"no state."):_=g+y(m)+"no meta.":_=g+y(m)+"no node.",v=Object.keys(b||{})}if(_)return n.err=o.err=_,void a(o);var d,$=0;for(r=r||0;r++<9&&(d=v[$++]);)if("_"!==d){var j=b[d],S=w[d];if(i===S){_=g+y(d)+"on"+y(m)+"no state.";break}if(!c(j)){_=g+y(d)+"on"+y(m)+"bad "+typeof j+y(j);break}e(j,d,m,S,n),++k}(v=v.slice($)).length?u(t):(++x,v=null,t(r))}()}}}function e(t,n,o,i,r){var a,s=r._||"",u=s.root,c=u.graph,l=c[o]||p,h=f(l,n,1),d=l[n],g=s.DBG;(a=console.STAT)&&(c[o]&&d||(a.has=(a.has||0)+1));var y=b();if(i>y)return setTimeout((function(){e(t,n,o,i,r)}),(a=i-y)>m?m:a),void(console.STAT&&console.STAT((g||s).Hf=+new Date,a,"future"));if(!(i<h)&&(s.faith||i!==h||!(t===d||v(t)<=v(d))||s.miss)){s.stun++;var k=r["#"]+s.all++,w={toString:function(){return k},_:s};w.toJSON=w.toString,u.dup.track(w)["#"]=r["#"],g&&(g.ph=g.ph||+new Date),u.on("put",{"#":w,"@":r["@"],put:{"#":o,".":n,":":t,">":i},ok:r.ok,_:s})}}function r(t){var n;(n=(t._||"").DBG)&&(n.pa=+new Date,n.pm=n.pm||+new Date);var e,o=this.as,i=o.graph,r=t._,s=t.put,u=s["#"],c=s["."],f=s[":"],p=s[">"];t["#"],(e=r.msg)&&(e=e.put)&&(e=e[u])&&l(e,c,p,f,u),i[u]=l(i[u],c,p,f,u),(e=(o.next||"")[u])&&e.on("in",t),a(r),this.to.next(t)}function a(n,e){var o;if(!n.stop&&(n.err||!(0<--n.stun))&&(n.stop=1,o=n.root)){var i=n.match;i.end=1,i===o.hatch&&(!(i=n.latch)||i.end?delete o.hatch:o.hatch=i),n.hatch&&n.hatch(),setTimeout.each(n.match,(function(t){t&&t()})),!(e=n.msg)||n.err||e.err||(e.out=t,n.root.on("out",e),w())}}function h(t){t&&t.root&&(t.stun||t.acks!==t.all||t.root.on("in",{"@":t["#"],err:t.err,ok:t.err?i:t.ok||{"":1}}))}o.create=function(n){n.root=n.root||n,n.graph=n.graph||{},n.on=n.on||o.on,n.ask=n.ask||o.ask,n.dup=n.dup||o.dup();var e=n.$.opt(n.opt);return n.once||(n.on("in",t,n),n.on("out",t,n),n.on("put",r,n),o.on("create",n),n.on("create",n)),n.once=1,e},o.on.put=n;var d,g="Error: Invalid graph!",y=function(t){return" '"+(""+t).slice(0,9)+"...' "},v=JSON.stringify,m=2147483647,b=o.state,k=0,w=function(){k>999&&k/-(d-(d=+new Date))>1&&(o.window&&console.log("Warning: You're syncing 1K+ records a second, faster than DOM can update - consider limiting query."),w=function(){k=0})}}(),function(){function t(t,n){var e=+new Date,o=t._||{},r=o.DBG=t.DBG,a=t["#"],u=s(9),c=Object.keys(n||"").sort(),p=((n||"")._||"")["#"];c.length;var h=t.$._.root,d=n===h.graph[p];console.STAT&&console.STAT(e,((r||o).gk=+new Date)-e,"got keys"),n&&function t(){e=+new Date;for(var o,g,y,v=0,m={};v<9&&(o=c[v++]);)l(m,o,f(n,o),n[o],p);c=c.slice(v),(g={})[p]=m,m=g,d&&((y=function(){}).ram=y.faith=!0),g=c.length,console.STAT&&console.STAT(e,-(e-(e=+new Date)),"got copied some"),r&&(r.ga=+new Date),h.on("in",{"@":a,"#":u,put:m,"%":g?u=s(9):i,$:h.$,_:y,DBG:r,FOO:1}),console.STAT&&console.STAT(e,+new Date-e,"got in"),g&&setTimeout.turn(t)}(),n||h.on("in",{"@":t["#"]})}o.on.get=function(n,e){var o=e._,r=n.get,a=r["#"],s=o.graph[a],u=r["."],c=(o.next||(o.next={}))[a],p=(n._||{}).DBG=n.DBG;if(p&&(p.g=+new Date),!s)return o.on("get",n);if(u){if(("string"!=typeof u||i===s[u])&&!((c||"").next||"")[u])return void o.on("get",n);s=l({},u,f(s,u),s[u],a)}s&&t(n,s),o.on("get",n)},o.on.get.ack=t}(),o.chain.opt=function(t){t=t||{};var n=this._,e=t.peers||t;return Object.plain(t)||(t={}),Object.plain(n.opt)||(n.opt=t),"string"==typeof e&&(e=[e]),Object.plain(n.opt.peers)||(n.opt.peers={}),e instanceof Array&&(t.peers={},e.forEach((function(e){var o={};o.id=o.url=e,t.peers[e]=n.opt.peers[e]=n.opt.peers[e]||o}))),a(t,(function t(n){var e=this[n];this&&this.hasOwnProperty(n)||"string"==typeof e||Object.empty(e)?this[n]=e:(!e||e.constructor===Object||e instanceof Array)&&a(e,t)})),n.opt.from=t,o.on("opt",n),n.opt.uuid=n.opt.uuid||function(t){return o.state().toString(36).replace(".","")+String.random(t||12)},this};var i,r,a=function(t,n){Object.keys(t).forEach(n,t)},s=String.random,u=setTimeout.turn,c=o.valid,f=o.state.is,l=o.state.ify,p={};o.log=function(){return!o.log.off&&r.log.apply(r,arguments),[].slice.call(arguments).join(" ")},o.log.once=function(t,n,e){return(e=o.log.once)[t]=e[t]||0,e[t]++||o.log(n)},"undefined"!=typeof window&&((window.GUN=window.Gun=o).window=window);try{void 0!==e&&(e.exports=o)}catch(t){}t.exports=o,(o.window||{}).console=(o.window||{}).console||{log:function(){}},(r=console).only=function(t,n){return r.only.i&&t===r.only.i&&r.only.i++&&(r.log.apply(r,arguments)||n)},o.log.once("welcome","Hello wonderful person! :) Thanks for using GUN, please ask for help on http://chat.gun.eco if anything takes you longer than 5min to figure out!")}))(n,"./root"),n((function(t){n("./root").chain.back=function(t,n){if(-1===(t=t||1)||1/0===t)return this._.root.$;if(1===t)return(this._.back||this._).$;var i=this._;if("string"==typeof t&&(t=t.split(".")),t instanceof Array){for(var r=0,a=t.length,s=i;r<a;r++)s=(s||o)[t[r]];return e!==s?n?this:s:(s=i.back)?s.$.back(t,n):void 0}if("function"==typeof t){var u;for(s={back:i};(s=s.back)&&e===(u=t(s,n)););return u}return"number"==typeof t?(i.back||i).$.back(t-1):this};var e,o={}}))(n,"./back"),n((function(t){var e=n("./root");function o(t,n){if(n=n||this.as||t.$._,(!t.$$||this===e.on)&&t.put&&!n.soul){var o=t.put||"",i=o["="]||o[":"],r=n.root,a=r.$.get(o["#"]).get(o["."])._;if("string"==typeof(i=c(i))){if(!(a.echo||(a.echo={}))[n.id]||(r.pass||"")[n.id]){if(s=r.pass){if(s[i+n.id])return;s[i+n.id]=1}(a.echo||(a.echo={}))[n.id]=n,n.has&&(n.link=i);var s,u=r.$.get(a.link=i)._;(u.echo||(u.echo={}))[a.id]=a,((s=n.ask||"")[""]||n.lex)&&u.on("out",{get:{"#":i}}),setTimeout.each(Object.keys(s),(function(t,n){t&&(n=s[t])&&n.on("out",{get:{"#":i,".":t}})}),0,99)}}else this===e.on&&((a.echo||(a.echo={}))[n.id]=n)}}function i(t,n){var e,o,r=t.put||"",s=a!==r["="]?r["="]:r[":"],u=n.root;if(a===s){if(n.soul&&a!==n.put)return;if(o=(t.$$||t.$||"")._||"",t["@"]&&(a!==o.put||a!==n.put))return;return(e=n.link||t.linked)&&delete(u.$.get(e)._.echo||"")[n.id],n.has&&(n.link=null),n.put=a,void setTimeout.each(Object.keys(n.next||""),(function(t,o){(o=n.next[t])&&(e&&delete(u.$.get(e).get(t)._.echo||"")[o.id],o.on("in",{get:t,put:a,$:o.$}))}),0,99)}n.soul||t.$$||(e=c(s),o=t.$._||"",(e!==o.link&&(!n.has||o.link)||(u.pass||"")[n.id]&&"string"!=typeof e)&&(delete(o.echo||"")[n.id],i({get:n.get,put:a,$:t.$,linked:t.linked=t.linked||o.link},n)))}function r(t,n){var o=this.as,i=o.$._;i.root;var r=o.get||"",s=(t.put||"")[r["#"]]||"";if(!t.put||"string"==typeof r["."]&&a===s[r["."]]){if(a!==i.put)return;if(!i.soul&&!i.has)return;return i.ack=(i.ack||0)+1,void i.on("in",{get:i.get,put:i.put=a,$:i.$,"@":t["@"]})}(t._||{}).miss=1,e.on.put(t)}e.chain.chain=function(t){var n,o=this,i=o._,r=new(t||o).constructor(o),a=r._;return a.root=n=i.root,a.id=++n.once,a.back=o._,a.on=e.on,a.on("in",e.on.in,a),a.on("out",e.on.out,a),r},e.on.out=function(t){var n,e,o=this.as,i=o.back,s=o.root;if(t.$||(t.$=o.$),this.to.next(t),!o.err){if(n=t.get){if(s.pass&&(s.pass[o.id]=o),o.lex&&Object.keys(o.lex).forEach((function(t){e[t]=o.lex[t]}),e=t.get=t.get||{}),n["#"]||o.soul){if(n["#"]=n["#"]||o.soul,t["#"]||(t["#"]=u(9)),i=s.$.get(n["#"])._,n=n["."]){if(f(i.put,n)&&(e=i.ask&&i.ask[n],(i.ask||(i.ask={}))[n]=i.$.get(n)._,i.on("in",{get:n,put:{"#":i.soul,".":n,":":i.put[n],">":p(s.graph[i.soul],n)}}),e))return}else{if(e=i.ask&&i.ask[""],(i.ask||(i.ask={}))[""]=i,a!==i.put&&(i.on("in",i),e))return;t.$=i.$}return s.ask(r,t),s.on("in",t)}if(n["."])return o.get?(t={get:{".":o.get},$:o.$},(i.ask||(i.ask={}))[o.get]=t.$._,i.on("out",t)):(t={get:o.lex?t.get:{},$:o.$},i.on("out",t));if((o.ask||(o.ask={}))[""]=o,o.get)return n["."]=o.get,(i.ask||(i.ask={}))[o.get]=t.$._,i.on("out",t)}return i.on("out",t)}o.on("in",{put:o.put=a,$:o.$})},e.on.in=function(t,n){var e,r=(n=n||this.as).root,u=t.$||(t.$=n.$),f=(u||"")._||s,l=t.put||"",d=l["#"],g=l["."],y=a!==l["="]?l["="]:l[":"],v=l[">"]||-1/0;if(a!==t.put&&(a===l["#"]||a===l["."]||a===l[":"]&&a===l["="]||a===l[">"]))return c(l)?void n.on("in",{$:f.back.$,put:{"#":d=f.back.soul,".":g=f.has||f.get,"=":l,">":p(f.back.put,g)},via:t}):(d=((l||"")._||"")["#"])?(u=n.root.$.get(d),setTimeout.each(Object.keys(l).sort(),(function(e){"_"!=e&&a!==(v=p(l,e))&&n.on("in",{$:u,put:{"#":d,".":e,"=":l[e],">":v},VIA:t})}))):void console.log("chain not yet supported for",l,"...",t,n);(t.seen||"")[n.id]||((t.seen||(t.seen=function(){}))[n.id]=n,n!==f&&(Object.keys(t).forEach((function(n){l[n]=t[n]}),l={}),l.get=n.get||l.get,n.soul||n.has?f.soul&&(l.$=n.$,l.$$=l.$$||f.$):l.$$$=l.$$$||n.$,t=l),i(t,n),(n.soul||t.$$)&&v>=p(r.graph[d],g)&&((l=r.$.get(d)._).put=h(l.put,g,v,y,d)),!f.soul&&v>=p(r.graph[d],g)&&(e=(r.$.get(d)._.next||"")[g])&&(e.put=y,"string"==typeof(l=c(y))&&(e.put=r.$.get(l)._.put||y)),this.to&&this.to.next(t),n.any&&setTimeout.each(Object.keys(n.any),(function(e){(e=n.any[e])&&e(t)}),0,99),n.echo&&setTimeout.each(Object.keys(n.echo),(function(e){(e=n.echo[e])&&e.on("in",t)}),0,99),((t.$$||"")._||f).soul&&(e=n.next)&&(e=e[g])&&(l={},Object.keys(t).forEach((function(n){l[n]=t[n]})),l.$=(t.$$||t.$).get(l.get=g),delete l.$$,delete l.$$$,e.on("in",l)),o(t,n))},e.on.link=o,e.on.unlink=i;var a,s={},u=String.random,c=e.valid,f=function(t,n){return t&&Object.prototype.hasOwnProperty.call(t,n)},l=e.state,p=l.is,h=l.ify}))(n,"./chain"),n((function(t){var e=n("./root");function o(t){var n=this.at||this.on;if(!t||n.soul||n.has)return this.off();if(t=(t=(t=t.$||t)._||t).id){var e;if(n.map,(e=this.seen||(this.seen={}))[t])return!0;e[t]=!0}}e.chain.get=function(t,n,s){var u,c;if("string"==typeof t){if(0==t.length)return(u=this.chain())._.err={err:e.log("0 length key!",t)},n&&n.call(u,u._.err),u;(u=((l=this._).next||r)[t])||(u=t&&function(t,n){var e=n._,o=e.next,i=n.chain(),r=i._;o||(o=e.next={});o[r.get=t]=r,n===e.root.$?r.soul=t:(e.soul||e.has)&&(r.has=t);return r}(t,this)),u=u&&u.$}else{if("function"==typeof t){if(!0===n)return function(t,n,o,r){var a,s=t._,u=0;if(a=s.soul||s.link)return n(a,r,s);if(s.jam)return s.jam.push([n,r]);s.jam=[[n,r]],t.get((function(t,n){if(!(i===t.put&&!s.root.opt.super&&(a=Object.keys(s.root.opt.peers).length)&&++u<=a)){n.rid(t);var o,r=(r=t.$)&&r._||{},c=0;for(a=s.jam,delete s.jam;o=a[c++];){var f=o[0];o=o[1],f&&f(r.link||r.soul||e.valid(t.put)||((t.put||{})._||{})["#"],o,t,n)}}}),{out:{get:{".":!0}}})}(this,t,0,s),this;var f,l=(u=this)._,p=n||{},h=l.root;p.at=l,p.ok=t;var d={};function g(t,n,o){if(!g.stun&&(!(r=h.pass)||r[f])){var r,a=t.$._,s=(t.$$||"")._,u=(s||a).put,c=!a.has&&!a.soul,y={};if((c||i===u)&&(u=i===((r=t.put)||"")["="]?i===(r||"")[":"]?r:r[":"]:r["="]),"string"==typeof(r=e.valid(u))&&(u=i===(r=h.$.get(r)._.put)?p.not?i:u:r),!p.not||i!==u){if(i===p.stun){if((r=h.stun)&&r.on&&(l.$.back((function(t){if(r.on(""+t.id,y={}),(y.run||0)<g.id)return y})),!y.run&&r.on(""+a.id,y={}),!y.run&&s&&r.on(""+s.id,y={}),g.id>y.run&&(y.stun&&!y.stun.end||(y.stun=r.on("stun"),y.stun=y.stun&&y.stun.last),y.stun&&!y.stun.end)))return void((y.stun.add||(y.stun.add={}))[f]=function(){g(t,n,1)});if(i===u&&(o=0),(r=h.hatch)&&!r.end&&i===p.hatch&&!o){if(d[a.$._.id])return;return d[a.$._.id]=1,void r.push((function(){g(t,n,1)}))}d={}}if(h.pass){if(h.pass[f+a.id])return;h.pass[f+a.id]=1}p.on?p.ok.call(a.$,u,a.get,t,n||g):p.v2020?p.ok(t,n||g):(Object.keys(t).forEach((function(n){r[n]=t[n]}),r={}),(t=r).put=u,p.ok.call(p.as,t,n||g))}}}return g.at=l,(l.any||(l.any={}))[f=String.random(7)]=g,g.off=function(){g.stun=1,l.any&&delete l.any[f]},g.rid=o,g.id=p.run||++h.once,c=h.pass,(h.pass={})[f]=1,p.out=p.out||{get:{}},l.on("out",p.out),h.pass=c,u}if("number"==typeof t)return this.get(""+t,n,s);if("string"==typeof(c=a(t)))return this.get(c,n,s);(c=this.get.next)&&(u=c(this,t))}return u?(n&&"function"==typeof n&&u.get(n,s),u):((u=this.chain())._.err={err:e.log("Invalid get request!",t)},n&&n.call(u,u._.err),u)};var i,r={},a=e.valid}))(n,"./get"),n((function(t){var e=n("./root");function o(t,n){if(n){n=(n._||"").id||n;var o,i=t.root.stun||(t.root.stun={on:e.on}),r={};t.stun||(t.stun=i.on("stun",(function(){}))),(o=i.on(""+n))&&o.the.last.next(r),r.run>=t.run||i.on(""+n,(function(n){if(t.stun.end)return this.off(),void this.to.next(n);n.run=n.run||t.run,n.stun=n.stun||t.stun}))}}function i(t){if(t.err)i.end(t.stun,t.root);else if(!t.todo.length&&!t.end&&Object.empty(t.wait)){t.end=1;var n,o=t.$.back(-1)._,r=o.root,a=o.ask((function(n){r.on("ack",n),n.err&&!n.lack&&e.log(n),++s>(t.acks||0)&&this.off(),t.ack&&t.ack(n,this)}),t.opt),s=0,u=t.stun;(n=function(){u&&(i.end(u,r),setTimeout.each(Object.keys(u=u.add||""),(function(t){(t=u[t])&&t()})))}).hatch=n,t.ack&&!t.ok&&(t.ok=t.acks||9),t.via._.on("out",{put:t.out=t.graph,ok:t.ok&&{"@":t.ok+1},opt:t.opt,"#":a,_:n})}}e.chain.put=function(t,n,a){var f=this,l=f._,p=l.root;(a=a||{}).root=l.root,a.run||(a.run=p.once),o(a,l.id),a.ack=a.ack||n,a.via=a.via||f,a.data=a.data||t,a.soul||(a.soul=l.soul||"string"==typeof n&&n);var h=a.state=a.state||e.state();return"function"==typeof t?(t((function(t){a.data=t,f.put(r,r,a)})),f):a.soul?(a.$=p.$.get(a.soul),a.todo=[{it:a.data,ref:a.$}],a.turn=a.turn||s,a.ran=a.ran||i,function t(){var n,r,s,f,l,p=a.todo,d=p.pop(),g=d.it;if(d.ref&&d.ref._.id,o(a,d.ref),(f=d.todo)&&(g=g[r=f.pop()],f.length&&p.push(d)),r&&(p.path||(p.path=[])).push(r),!(n=u(g))&&!(l=e.is(g))){if(!Object.plain(g))return void i.err(a,"Invalid data: "+function(t,n){return t&&(n=t.constructor)&&n.name||typeof t}(g)+" at "+(a.via.back((function(t){t.get&&f.push(t.get)}),f=[])||f.join("."))+"."+(p.path||[]).join("."));for(var y=a.seen||(a.seen=[]),v=y.length;v--;)if(g===(f=y[v]).it){n=g=f.link;break}}if(r&&n)d.node=c(d.node,r,h,g);else{if(!a.seen)return void i.err(a,"Data at root of graph must be a node (an object).");a.seen.push(s={it:g,link:{},todo:l?[]:Object.keys(g).sort().reverse(),path:(p.path||[]).slice(),up:d}),d.node=c(d.node,r,h,s.link),!l&&s.todo.length&&p.push(s);var m=a.seen.length;function b(t,n){var e=s.link["#"];n&&(n.off(),n.rid(t));var i=e||t.soul||(f=(t.$$||t.$)._||"").soul||f.link||((f=f.put||"")._||"")["#"]||f["#"]||((f=t.put||"")&&t.$$?f["#"]:(f["="]||f[":"]||"")["#"]);!e&&o(a,t.$),i||d.link["#"]?(i||(i=[],(t.$$||t.$).back((function(t){if(f=t.soul||t.link)return i.push(f);i.push(t.get)})),i=i.reverse().join("/")),s.link["#"]=i,!l&&(((a.graph||(a.graph={}))[i]=s.node||(s.node={_:{}}))._["#"]=i),delete a.wait[m],s.wait&&setTimeout.each(s.wait,(function(t){t&&t()})),a.ran(a)):(d.wait||(d.wait=[])).push((function(){b(t,n)}))}(a.wait||(a.wait={}))[m]="",f=(s.ref=l?g:r?d.ref.get(r):d.ref)._,(f=g&&(g._||"")["#"]||f.soul||f.link)?b({soul:f}):s.ref.get(b,{run:a.run,v2020:1,out:{get:{".":" "}}})}if(!p.length)return a.ran(a);a.turn(t)}(),f):(function(t){var n,e=t.via._;t.via=t.via.back((function(e){if(e.soul||!e.get)return e.$;n=t.data,(t.data={})[e.get]=n})),t.via&&t.via._.soul||(t.via=e.root.$.get(((t.data||"")._||"")["#"]||e.$.back("opt.uuid")()));t.via.put(t.data,t.ack,t)}(a),f)},i.end=function(t,n){t.end=a,t.the.to===t&&t===t.the.last&&delete n.stun,t.off()},i.err=function(t,n){(t.ack||a).call(t,t.out={err:t.err=e.log(n)}),t.ran(t)};var r,a=function(){},s=setTimeout.turn,u=e.valid,c=e.state.ify}))(n,"./put"),n((function(t){var e=n("./root");n("./chain"),n("./back"),n("./put"),n("./get"),t.exports=e}))(n,"./index"),n((function(t){var e,o=n("./index");o.chain.on=function(t,n,e,o){var i,r=this,a=r._;if(a.root,"string"==typeof t)return n?(i=a.on(t,n,e||a,o),e&&e.$&&(e.subs||(e.subs=[])).push(i),r):a.on(t);var s=n;return(s=!0===s?{change:!0}:s||{}).not=1,s.on=1,r.get(t,s),r},o.chain.once=function(t,n){if(n=n||{},!t)return function(t,n,e){return o.log.once("valonce","Chainable val is experimental, its behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it."),(e=t.chain())._.nix=t.once((function(t,n){e._.on("in",this._)})),e._.lex=t._.lex,e}(this);var i=this,r=i._,a=r.root;r.put;var s,u=String.random(7);return i.get((function(i,c,f,l){var p=this,h=p._,d=h.one||(h.one={});function g(y){h.has||h.soul||(h={put:i,get:c}),e===(s=h.put)&&(s=((f.$$||"")._||"").put),"string"!=typeof o.valid(s)||(s=a.$.get(s)._.put)!==e||y?l.stun||""!==d[u]&&(d[u]="",(r.soul||r.has)&&l.off(),t.call(p,s,h.get),clearTimeout(d[u])):d[u]=setTimeout((function(){g(1)}),n.wait||99)}l.stun||""!==d[u]&&(!0!==(s=o.valid(i))?"string"!=typeof s&&(clearTimeout((r.one||"")[u]),clearTimeout(d[u]),d[u]=setTimeout(g,n.wait||99)):g())}),{on:1}),i},o.chain.off=function(){var t,n=this._,e=n.back;if(e)return n.ack=0,(t=e.next)&&t[n.get]&&delete t[n.get],(t=e.any)&&(delete e.any,e.any={}),(t=e.ask)&&delete t[n.get],(t=e.put)&&delete t[n.get],(t=n.soul)&&delete e.root.graph[t],(t=n.map)&&Object.keys(t).forEach((function(n,o){(o=t[n]).link&&e.root.$.get(o.link).off()})),(t=n.next)&&Object.keys(t).forEach((function(n,e){t[n].$.off()})),n.on("off",{}),this}}))(n,"./on"),n((function(t){var e=n("./index"),o=e.chain.get.next;function i(t){this.to.next(t);var n,o=this.as,i=t.$._,r=t.put;(i.soul||t.$$)&&((n=o.lex)&&!String.match(t.get||(r||"")["."],n["."]||n["#"]||n)||e.on.link(t,o))}e.chain.get.next=function(t,n){var e;return Object.plain(n)?(e=((e=n["#"])||"")["="]||e)?t.get(e):((e=t.chain()._).lex=n,t.on("in",(function(t){String.match(t.get||(t.put||"")["."],n["."]||n["#"]||n)&&e.on("in",t),this.to.next(t)})),e.$):(o||a)(t,n)},e.chain.map=function(t,n,o){var s,u,c=this,f=c._;return Object.plain(t)&&(s=t["."]?t:{".":t},t=r),t?(e.log.once("mapfn","Map functions are experimental, their behavior and API may change moving forward. Please play with it and report bugs and ideas on how to improve it."),u=c.chain(),c.map().on((function(n,o,i,s){var c=(t||a).call(this,n,o,i,s);if(r!==c){if(n===c)return u._.on("in",i);if(e.is(c))return u._.on("in",c._);var f={};Object.keys(i.put).forEach((function(t){f[t]=i.put[t]}),f),f["="]=c,u._.on("in",{get:o,put:f})}})),u):((u=f.each)||((f.each=u=c.chain())._.lex=s||u._.lex||f.lex,u._.nix=c.back("nix"),c.on("in",i,u._)),u)};var r,a=function(){}}))(n,"./map"),n((function(t){var e=n("./index");e.chain.set=function(t,n,o){var i,r,a=this,s=a.back(-1);return n=n||function(){},(o=o||{}).item=o.item||t,(i=((t||"")._||"")["#"])&&((t={})["#"]=i),"string"==typeof(r=e.valid(t))?a.get(i=r).put(t,n,o):e.is(t)?(a.put((function(o){t.get((function(t,i,s){if(!t)return n.call(a,{err:e.log('Only a node can be linked! Not "'+s.put+'"!')});(r={})[t]={"#":t},o(r)}),!0)})),t):(Object.plain(t)&&(t=s.get(i=a.back("opt.uuid")()).put(t)),a.get(i||s.back("opt.uuid")(7)).put(t,n,o))}}))(n,"./set"),n((function(t){n("./shim");var e,o=function(){},i=JSON.parseAsync||function(t,n,e){var o=+new Date;try{n(undefined,JSON.parse(t,e),r.sucks(+new Date-o))}catch(t){n(t)}},r=JSON.stringifyAsync||function(t,n,e,o){var i=+new Date;try{n(undefined,JSON.stringify(t,e,o),r.sucks(+new Date-i))}catch(t){n(t)}};r.sucks=function(t){t>99&&(console.log("Warning: JSON blocking CPU detected. Add `gun/lib/yson.js` to fix."),r.sucks=o)};try{t.exports=function(t){var n=function(){},o=t.opt||{};o.log=o.log||console.log,o.gap=o.gap||o.wait||0,o.max=o.max||.3*(o.memory?999*o.memory*999:3e8),o.pack=o.pack||.01*o.max*.01,o.puff=o.puff||9;var a=setTimeout.turn||setTimeout,s=t.dup,u=s.check,c=s.track,f=n.hear=function(t,e){if(t){if(o.max<=t.length)return n.say({dam:"!",err:"Message too big!"},e);n===this&&(f.d+=t.length||0,++f.c);var r,s=e.SH=+new Date,u=t[0];return"["===u?(i(t,(function(t,i){if(t||!i)return n.say({dam:"!",err:"DAM JSON parse error."},e);console.STAT&&console.STAT(+new Date,i.length,"# on hear batch");var r=o.puff;!function t(){for(var o,s=+new Date,u=0;u<r&&(o=i[u++]);)n.hear(o,e);i=i.slice(u),console.STAT&&console.STAT(s,+new Date-s,"hear loop"),l(e),i.length&&a(t,0)}()})),void(t="")):"{"===u||(t["#"]||Object.plain(t))&&(r=t)?r?f.one(r,e,s):void i(t,(function(t,o){if(t||!o)return n.say({dam:"!",err:"DAM JSON parse error."},e);f.one(o,e,s)})):void 0}};function l(t){var n=t.batch,e="string"==typeof n;if(e&&(n+="]"),t.batch=t.tail=null,n&&!(e?3>n.length:!n.length)){if(!e)try{n=1===n.length?n[0]:JSON.stringify(n)}catch(t){return o.log("DAM JSON stringify error",t)}n&&p(n,t)}}function p(t,e){try{var o=e.wire;e.say?e.say(t):o.send&&o.send(t),n.say.d+=t.length||0,++n.say.c}catch(n){(e.queue=e.queue||[]).push(t)}}return f.one=function(e,o,i){var r,a,f,l,p;if(e.DBG&&(e.DBG=p={DBG:e.DBG}),p&&(p.h=i),p&&(p.hp=+new Date),(r=e["#"])||(r=e["#"]=String.random(9)),!((f=u(r))||(a=e["##"])&&(f=e["@"]||e.get&&r)&&s.check(l=f+a))){if((e._=function(){}).via=n.leap=o,(f=e["><"])&&"string"==typeof f&&f.slice(0,99).split(",").forEach((function(t){this[t]=1}),e._.yo={}),f=e.dam)return(f=n.hear[f])&&f(e,o,t),void c(r);(f=e.ok)&&(e._.near=f["/"]),i=+new Date,p&&(p.is=i),o.SI=r,c.ed=function(t){r===t&&(c.ed=0,(t=s.s[r])&&(t.via=o,e.get&&(t.it=e)))},t.on("in",n.last=e),p&&(p.hd=+new Date),console.STAT&&console.STAT(i,+new Date-i,e.get?"msg get":e.put?"msg put":"msg"),c(r),l&&c(l),n.leap=n.last=null}},f.c=f.d=0,function(){var t,i=0;function f(t,n){var e;return n instanceof Object?(Object.keys(n).sort().forEach(h,{to:e={},on:n}),e):n}function h(t){this.to[t]=this.on[t]}n.hash=function(t,e){var o,i,s,u=+new Date;r(t.put,(function r(c,f){var l=(i||(i=s=f||"")).slice(0,32768);o=String.hash(l,o),(i=i.slice(32768))?a(r,0):(console.STAT&&console.STAT(u,+new Date-u,"say json+hash"),t._.$put=s,t["##"]=o,n.say(t,e),delete t._.$put)}),f)},(n.say=function(r,u){var f;if((f=this)&&(f=f.to)&&f.next&&f.next(r),!r)return!1;var h,d,g,y=r["@"],v=r._||(r._=function(){}),m=r.DBG,b=+new Date;if(v.y=v.y||b,u||m&&(m.y=b),(h=r["#"])||(h=r["#"]=String.random(9)),!t&&c(h),(d=r["##"])||e===r.put||v.via||!y){if(!u&&y&&(u=(f=s.s[y])&&(f.via||(f=f.it)&&(f=f._)&&f.via)||(f=n.last)&&y===f["#"]&&n.leap),!u&&y){if(s.s[y])return;return console.STAT&&console.STAT(+new Date,++i,"total no peer to ack to"),!1}if(y&&!r.put&&!d&&((s.s[y]||"").it||"")["##"])return!1;if(!u&&n.way)return n.way(r);if(m&&(m.yh=+new Date),g=v.raw){if(m&&(m.yr=+new Date),!u||!u.id){if(!Object.plain(u||o.peers))return!1;b=+new Date,o.puff;var k=o.peers,w=Object.keys(u||o.peers||{});return console.STAT&&console.STAT(b,+new Date-b,"peer keys"),void function e(){var o=+new Date;t=1;var i=v.raw;v.raw=g;for(var s,f=0;f<9&&(s=(w||"")[f++]);)(s=k[s]||(u||"")[s])&&n.say(r,s);v.raw=i,t=0,w=w.slice(f),console.STAT&&console.STAT(o,+new Date-o,"say loop"),w.length&&(a(e,0),y&&c(y))}()}if(!u.wire&&n.wire&&n.wire(u),h!==u.last){if(u.last=h,u===v.via)return!1;if((f=v.yo)&&(f[u.url]||f[u.pid]||f[u.id]))return!1;if(console.STAT&&console.STAT(b,((m||v).yp=+new Date)-(v.y||b),"say prep"),!t&&y&&c(y),u.batch){if(u.tail=(f=u.tail||0)+g.length,u.tail<=o.pack)return void(u.batch+=(f?",":"")+g);l(u)}u.batch="[";var _=+new Date;setTimeout((function(){console.STAT&&console.STAT(_,+new Date-_,"0ms TO"),l(u)}),o.gap),p(g,u),console.STAT&&y===u.SI&&console.STAT(b,+new Date-u.SH,"say ack")}}else n.raw(r,u)}else n.hash(r,u)}).c=n.say.d=0,n.raw=function(t,i){if(!t)return"";var a,c,f=t._||{};if(c=f.raw)return c;if("string"==typeof t)return t;var l=t["##"],p=t["@"];if(l&&p){if(!f.via&&u(p+l))return!1;if(c=(s.s[p]||"").it){if(l===c["##"])return!1;c["##"]||(c["##"]=l)}}if(!t.dam&&!t["@"]){var h=0,d=[];for(var g in c=o.peers){var y=c[g];if(d.push(y.url||y.pid||y.id),++h>6)break}h>1&&(t["><"]=d.join())}if(t.put&&(c=t.ok)&&(t.ok={"@":(c["@"]||1)-1,"/":c["/"]==t._.near?n.near:c["/"]}),a=f.$put)return c={},Object.keys(t).forEach((function(n){c[n]=t[n]})),c.put=":])([:",void r(c,(function(t,n){if(!t){var o=+new Date;c=n.indexOf('"put":":])([:"'),v(e,n=n.slice(0,c+6)+a+n.slice(c+14)),console.STAT&&console.STAT(o,+new Date-o,"say slice")}}));function v(e,o){e||(f.raw=o,n.say(t,i))}r(t,v)}}(),n.near=0,n.hi=function(e){var i;e.wire?(e.id?o.peers[e.url||e.id]=e:(i=e.id=e.id||e.url||String.random(9),n.say({dam:"?",pid:t.opt.pid},o.peers[i]=e),delete s.s[e.last]),e.met||(n.near++,e.met=+new Date,t.on("hi",e)),i=e.queue,e.queue=[],setTimeout.each(i||[],(function(t){p(t,e)}),0,9)):n.wire(e.length&&{url:e,id:e}||e)},n.bye=function(e){e.met&&--n.near,delete e.met,t.on("bye",e);var o=+new Date;o-=e.met||o,n.bye.time=((n.bye.time||o)+o)/2},n.hear["!"]=function(t,n){o.log("Error:",t.err)},n.hear["?"]=function(t,e){t.pid&&(e.pid||(e.pid=t.pid),t["@"])||(n.say({dam:"?",pid:o.pid,"@":t["#"]},e),delete s.s[e.last])},n.hear.mob=function(t,e){if(t.peers){var o=Object.keys(t.peers),i=o[Math.random()*o.length|0];i&&(n.bye(e),n.hi(i))}},t.on("create",(function(t){t.opt.pid=t.opt.pid||String.random(9),this.to.next(t),t.on("out",n.say)})),t.on("bye",(function(t,n){t=o.peers[t.id||t]||t,this.to.next(t),t.bye?t.bye():(n=t.wire)&&n.close&&n.close(),delete o.peers[t.id],t.wire=null})),t.on("bye",(function(t,e){this.to.next(t),(e=console.STAT)&&(e.peers=n.near),(e=t.url)&&setTimeout((function(){}),o.lack||9e3)})),t.on("hi",(function(e,i){if(this.to.next(e),(i=console.STAT)&&(i.peers=n.near),!o.super){var r=Object.keys(t.next||"");r.length>9999&&!console.SUBS&&console.log(console.SUBS="Warning: You have more than 10K live GETs, which might use more bandwidth than your screen can show - consider `.off()`."),setTimeout.each(r,(function(i){var r=t.next[i];o.super||(r.ask||"")[""]?n.say({get:{"#":i}},e):setTimeout.each(Object.keys(r.ask||""),(function(o){o&&n.say({"##":String.hash((t.graph[i]||"")[o]),get:{"#":i,".":o}},e)}))}))}})),n}}catch(t){}}))(n,"./mesh"),n((function(t){var e=n("./index");e.Mesh=n("./mesh"),e.on("opt",(function(t){if(this.to.next(t),!t.once){var n=t.opt;if(!1!==n.WebSocket){var o=e.window||{},i=n.WebSocket||o.WebSocket||o.webkitWebSocket||o.mozWebSocket;if(i){n.WebSocket=i;var r=n.mesh=n.mesh||e.Mesh(t);r.wire||n.wire,r.wire=n.wire=u,setTimeout((function(){!n.super&&t.on("out",{dam:"hi"})}),1);var a=1998,s=""+undefined!=typeof document&&document}}}function u(t){try{if(!t||!t.url)return o&&o(t);var e=t.url.replace(/^http/,"ws"),o=t.wire=new n.WebSocket(e);return o.onclose=function(){c(t),n.mesh.bye(t)},o.onerror=function(n){c(t)},o.onopen=function(){n.mesh.hi(t)},o.onmessage=function(e){e&&n.mesh.hear(e.data||e,t)},o}catch(e){n.mesh.bye(t)}}function c(t){clearTimeout(t.defer),n.peers[t.url]&&(s&&t.retry<=0||(t.retry=(t.retry||n.retry+1||60)-(-t.tried+(t.tried=+new Date)<4*a?1:0),t.defer=setTimeout((function n(){if(s&&s.hidden)return setTimeout(n,a);u(t)}),a)))}}))}))(n,"./websocket"),n((function(t){if("undefined"!=typeof Gun){var n;try{n=(Gun.window||function(){}).localStorage}catch(t){}n||(Gun.log("Warning: No localStorage exists to persist data to!"),n={setItem:function(t,n){this[t]=n},removeItem:function(t){delete this[t]},getItem:function(t){return this[t]}});var e=JSON.stringifyAsync||function(t,n,e,o){try{n(undefined,JSON.stringify(t,e,o))}catch(t){n(t)}};Gun.on("create",(function t(o){this.to.next(o);var i=o.opt;o.graph;var r,a,s,u,c=[];if(!1!==i.localStorage){i.prefix=i.file||"gun/";try{r=t[i.prefix]=t[i.prefix]||JSON.parse(s=n.getItem(i.prefix))||{}}catch(n){r=t[i.prefix]={}}s=(s||"").length,o.on("get",(function(t){this.to.next(t);var n,e,o,i=t.get;i&&(n=i["#"])&&((e=r[n]||undefined)&&(o=i["."])&&!Object.plain(o)&&(e=Gun.state.ify({},o,Gun.state.is(e,o),e[o],n)),Gun.on.get.ack(t,e))})),o.on("put",(function(t){this.to.next(t);var n=t.put,e=n["#"],i=n["."],l=t["#"],p=t.ok||"";r[e]=Gun.state.ify(r[e],i,n[">"],n[":"],e),u&&s>4999880?o.on("in",{"@":l,err:"localStorage max!"}):(t["@"]||t._.via&&!(Math.random()<p["@"]/p["/"])||c.push(l),a||(a=setTimeout(f,9+s/333)))}))}function f(){if(c.length||!((setTimeout.turn||"").s||"").length){var t=c;clearTimeout(a),a=!1,c=[],e(r,(function(e,a){try{!e&&n.setItem(i.prefix,a)}catch(t){e=u=t||"localStorage failure"}e&&(Gun.log(e+" Consider using GUN's IndexedDB plugin for RAD for more storage space, https://gun.eco/docs/RAD#install"),o.on("localStorage:error",{err:e,get:i.prefix,put:r})),s=a.length,setTimeout.each(t,(function(t){o.on("in",{"@":t,err:e,ok:0})}),0,99)}))}else setTimeout(f,99)}}))}}))(n,"./localStorage")}(),function(){if(""+_!=typeof Gun){var t=function(t){console.warn("Warning! Deprecated internal utility will break in next version:",t)},n=Gun;n.fn=n.fn||{is:function(n){return t("fn"),!!n&&"function"==typeof n}},n.bi=n.bi||{is:function(n){return t("bi"),n instanceof Boolean||"boolean"==typeof n}},n.num=n.num||{is:function(n){return t("num"),!o(n)&&(n-parseFloat(n)+1>=0||1/0===n||-1/0===n)}},n.text=n.text||{is:function(n){return t("text"),"string"==typeof n}},n.text.ify=n.text.ify||function(e){return t("text.ify"),n.text.is(e)?e:"undefined"!=typeof JSON?JSON.stringify(e):e&&e.toString?e.toString():e},n.text.random=n.text.random||function(n,e){t("text.random");var o="";for(n=n||24,e=e||"0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";n>0;)o+=e.charAt(Math.floor(Math.random()*e.length)),n--;return o},n.text.match=n.text.match||function(n,e){var o,i;return t("text.match"),"string"==typeof n&&("string"==typeof e&&(e={"=":e}),n===(o=(e=e||{})["="]||e["*"]||e[">"]||e["<"])||i===e["="]&&(o=e["*"]||e[">"]||e["<"],n.slice(0,(o||"").length)===o||i===e["*"]&&(i!==e[">"]&&i!==e["<"]?n>=e[">"]&&n<=e["<"]:i!==e[">"]&&n>=e[">"]||i!==e["<"]&&n<=e["<"])))},n.text.hash=n.text.hash||function(n,e){if(t("text.hash"),"string"==typeof n){if(e=e||0,!n.length)return e;for(var o=0,i=n.length;o<i;++o)e=(e<<5)-e+n.charCodeAt(o),e|=0;return e}},n.list=n.list||{is:function(n){return t("list"),n instanceof Array}},n.list.slit=n.list.slit||Array.prototype.slice,n.list.sort=n.list.sort||function(n){return t("list.sort"),function(t,e){return t&&e?(t=t[n])<(e=e[n])?-1:t>e?1:0:0}},n.list.map=n.list.map||function(n,e,o){return t("list.map"),a(n,e,o)},n.list.index=1,n.obj=n.boj||{is:function(n){return t("obj"),!!n&&(n instanceof Object&&n.constructor===Object||"Object"===Object.prototype.toString.call(n).match(/^\[object (\w+)\]$/)[1])}},n.obj.put=n.obj.put||function(n,e,o){return t("obj.put"),(n||{})[e]=o,n},n.obj.has=n.obj.has||function(n,e){return t("obj.has"),n&&Object.prototype.hasOwnProperty.call(n,e)},n.obj.del=n.obj.del||function(n,e){if(t("obj.del"),n)return n[e]=null,delete n[e],n},n.obj.as=n.obj.as||function(n,e,o,i){return t("obj.as"),n[e]=n[e]||(i===o?{}:o)},n.obj.ify=n.obj.ify||function(n){if(t("obj.ify"),i(n))return n;try{n=JSON.parse(n)}catch(t){n={}}return n},function(){function e(t,n){r(this,n)&&undefined!==this[n]||(this[n]=t)}n.obj.to=n.obj.to||function(n,o){return t("obj.to"),a(n,e,o=o||{}),o}}(),n.obj.copy=n.obj.copy||function(n){return t("obj.copy"),n?JSON.parse(JSON.stringify(n)):n},function(){function e(t,n){var e=this.n;if(!e||!(n===e||i(e)&&r(e,n)))return undefined!==n||void 0}n.obj.empty=n.obj.empty||function(n,o){return t("obj.empty"),!n||!a(n,e,{n:o})}}(),function(){function e(t,n){if(2===arguments.length)return e.r=e.r||{},void(e.r[t]=n);e.r=e.r||[],e.r.push(t)}var a,s=Object.keys;Object.keys=Object.keys||function(t){return a(t,(function(t,n,e){e(n)}))},n.obj.map=a=n.obj.map||function(a,u,c){t("obj.map");var f,l,p,h,d,g=0,y="function"==typeof u;if(e.r=f,s&&i(a)&&(h=s(a),d=!0),c=c||{},o(a)||h)for(l=(h||a).length;g<l;g++){var v=g+n.list.index;if(y){if((p=d?u.call(c,a[h[g]],h[g],e):u.call(c,a[g],v,e))!==f)return p}else if(u===a[d?h[g]:g])return h?h[g]:v}else for(g in a)if(y){if(r(a,g)&&(p=c?u.call(c,a[g],g,e):u(a[g],g,e))!==f)return p}else if(u===a[g])return g;return y?e.r:n.list.index?0:-1}}(),n.time=n.time||{},n.time.is=n.time.is||function(n){return t("time"),n?n instanceof Date:+(new Date).getTime()};var e=n.fn.is,o=n.list.is,i=(w=n.obj).is,r=w.has,a=w.map,s={is:function(n){return t("val.is"),n!==_&&(null===n||n!==1/0&&(!!(l(n)||c(n)||f(n))||(s.link.is(n)||!1)))}};s.link=s.rel={_:"#"},function(){function n(t,n){var e=this;return e.id?e.id=!1:n==u&&l(t)?void(e.id=t):e.id=!1}s.link.is=function(e){if(t("val.link.is"),e&&e[u]&&!e._&&i(e)){var o={};if(a(e,n,o),o.id)return o.id}return!1}}(),s.link.ify=function(n){return t("val.link.ify"),p({},u,n)},n.obj.has._=".";var u=s.link._,c=n.bi.is,f=n.num.is,l=n.text.is,p=(i=(w=n.obj).is,w.put);a=w.map;n.val=n.val||s;var h={_:"_",soul:function(n,e){return t("node.soul"),n&&n._&&n._[e||y]}};h.soul.ify=function(n,e){return t("node.soul.ify"),e="string"==typeof e?{soul:e}:e||{},(n=n||{})._=n._||{},n._[y]=e.soul||n._[y]||g(),n},h.soul._=s.link._,function(){function n(t,n){if(n!==h._)return!s.is(t)||void(this.cb&&this.cb.call(this.as,t,n,this.n,this.s))}h.is=function(e,o,r){var s;return t("node.is"),!!i(e)&&(!!(s=h.soul(e))&&!a(e,n,{as:r,cb:o,s:s,n:e}))}}(),function(){function n(t,n){var e,o=this.o;o.map?undefined===(e=o.map.call(this.as,t,""+n,o.node))?d(o.node,n):o.node&&(o.node[n]=e):s.is(t)&&(o.node[n]=t)}h.ify=function(e,o,i){return t("node.ify"),o?"string"==typeof o?o={soul:o}:"function"==typeof o&&(o={map:o}):o={},o.map&&(o.node=o.map.call(i,e,_,o.node||{})),(o.node=h.soul.ify(o.node||{},o))&&a(e,n,{o:o,as:i}),o.node}}();i=(w=n.obj).is;var d=w.del,g=(a=w.map,n.text.random),y=h.soul._;n.node=n.node||h;var v=n.state;v.lex=function(){return t("state.lex"),v().toString(36).replace(".","")},v.to=function(n,e,o){t("state.to");var r=(n||{})[e];return i(r)&&(r=m(r)),v.ify(o,e,v.is(n,e),r,h.soul(n))},function(){function n(t,n){b!==n&&v.ify(this.o,n,this.s)}v.map=function(o,s,u){var c;t("state.map");var l=i(l=o||s)?l:null;return o=e(o=o||s)?o:null,l&&!o?(s=f(s)?s:v(),l[b]=l[b]||{},a(l,n,{o:l,s:s}),l):(u=u||i(s)?s:c,s=f(s)?s:v(),function(t,e,i,a){if(!o)return n.call({o:i,s:s},t,e),t;o.call(u||this||{},t,e,i,a),r(i,e)&&c===i[e]||n.call({o:i,s:s},t,e)})}}(),(w=n.obj).as;r=w.has,i=w.is,a=w.map;var m=w.copy,b=(f=n.num.is,e=n.fn.is,h._),k={};!function(){function n(t,n){if(!t||n!==h.soul(t)||!h.is(t,this.fn,this.as))return!0;this.cb&&(e.n=t,e.as=this.as,this.cb.call(e.as,t,n,e))}function e(t){t&&h.is(e.n,t,e.as)}k.is=function(e,o,r,s){return t("graph.is"),!(!e||!i(e)||T(e))&&!a(e,n,{cb:o,fn:r,as:s})}}(),function(){function e(t,n){var e;return(e=function(t,n){var e,o=t.seen,i=o.length;for(;i--;)if(e=o[i],n.obj===e.obj)return e;o.push(n)}(t,n))?e:(n.env=t,n.soul=a,h.ify(n.obj,o,n)&&(n.link=n.link||s.link.ify(h.soul(n.node)),n.obj!==t.shell&&(t.graph[s.link.is(n.link)]=n.node)),n)}function o(t,n,o){var i,a,c=this,f=c.env;if(h._===n&&r(t,s.link._))return o._;if(i=u(t,n,o,c,f)){if(n||(c.node=c.node||o||{},r(t,h._)&&h.soul(t)&&(c.node._=m(t._)),c.node=h.soul.ify(c.node,s.link.is(c.link)),c.link=c.link||s.link.ify(h.soul(c.node))),(a=f.map)&&(a.call(f.as||{},t,n,o,c),r(o,n))){if(t=o[n],_===t)return void d(o,n);if(!(i=u(t,n,o,c,f)))return}if(!n)return c.node;if(!0===i)return t;if((a=e(f,{obj:t,path:c.path.concat(n)})).node)return a.link}}function a(t){var n=this,e=s.link.is(n.link),o=n.env.graph;n.link=n.link||s.link.ify(t),n.link[s.link._]=t,n.node&&n.node[h._]&&(n.node[h._][s.link._]=t),r(o,e)&&(o[t]=o[e],d(o,e))}function u(t,e,o,r,a){var c;return!!s.is(t)||(i(t)?1:(c=a.invalid)?u(t=c.call(a.as||{},t,e,o),e,o,r,a):(a.err="Invalid value at '"+r.path.concat(e).join(".")+"'!",void(n.list.is(t)&&(a.err+=" Use `.set(item)` instead of an Array."))))}k.ify=function(n,o,i){t("graph.ify");var r={path:[],obj:n};return o?"string"==typeof o?o={soul:o}:"function"==typeof o&&(o.map=o):o={},"string"==typeof i&&(o.soul=o.soul||i,i=_),o.soul&&(r.link=s.link.ify(o.soul)),o.shell=(i||{}).shell,o.graph=o.graph||{},o.seen=o.seen||[],o.as=o.as||i,e(o,r),o.root=r.node,o.graph}}(),k.node=function(n){t("graph.node");var e=h.soul(n);if(e)return p({},e,n)},function(){function n(t,n){var e,o;if(h._!==n)(e=s.link.is(t))?(o=this.opt.seen[e])?this.obj[n]=o:this.obj[n]=this.opt.seen[e]=k.to(this.graph,e,this.opt):this.obj[n]=t;else{if(T(t,s.link._))return;this.obj[n]=m(t)}}k.to=function(e,o,i){if(t("graph.to"),e){var r={};return i=i||{seen:{}},a(e[o],n,{obj:r,graph:e,opt:i}),r}}}();e=n.fn.is,i=(w=n.obj).is,d=w.del,r=w.has;var w,_,T=w.empty;p=w.put,a=w.map,m=w.copy;n.graph=n.graph||k}}()}(a)),a.exports}return function(o){var i,r;i="undefined"!=typeof self?self:e,r=function(t,n,e){console.log("Factory del plugin Gun-Eth chiamata");const o="Accesso a GunDB con Ethereum";let i,r=[{anonymous:!1,inputs:[{indexed:!0,internalType:"bytes",name:"nodeId",type:"bytes"},{indexed:!1,internalType:"bytes32",name:"contentHash",type:"bytes32"},{indexed:!1,internalType:"address",name:"updater",type:"address"}],name:"DataUpdated",type:"event"},{inputs:[{internalType:"bytes[]",name:"nodeIds",type:"bytes[]"},{internalType:"bytes32[]",name:"contentHashes",type:"bytes32[]"}],name:"batchUpdateData",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes",name:"nodeId",type:"bytes"}],name:"getLatestRecord",outputs:[{internalType:"bytes32",name:"",type:"bytes32"},{internalType:"uint256",name:"",type:"uint256"},{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes",name:"",type:"bytes"}],name:"nodeData",outputs:[{internalType:"bytes32",name:"contentHash",type:"bytes32"},{internalType:"uint256",name:"timestamp",type:"uint256"},{internalType:"address",name:"updater",type:"address"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes",name:"nodeId",type:"bytes"},{internalType:"bytes32",name:"contentHash",type:"bytes32"}],name:"updateData",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bytes",name:"nodeId",type:"bytes"},{internalType:"bytes32",name:"contentHash",type:"bytes32"}],name:"verifyData",outputs:[{internalType:"bool",name:"",type:"bool"},{internalType:"uint256",name:"",type:"uint256"},{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"}],a="",s="";const u=async()=>{if(a&&s){const t=new e.JsonRpcProvider(a);return new e.Wallet(s,t)}if("undefined"!=typeof window&&void 0!==window.ethereum)return await window.ethereum.request({method:"eth_requestAccounts"}),new e.BrowserProvider(window.ethereum).getSigner();throw new Error("No valid Ethereum provider found")};t.chain.setStandaloneConfig=function(t,n){return a=t,s=n,console.log("Standalone configuration set"),this},t.chain.verifySignature=async function(t,n){try{return e.verifyMessage(t,n)}catch(t){return console.error("Error verifying signature:",t),null}},t.chain.generatePassword=function(t){try{const n=e.hexlify(t),o=e.keccak256(n);return console.log("Generated password:",o),o}catch(t){return console.error("Error generating password:",t),null}},t.chain.createSignature=async function(t){try{if(t!==o)throw new Error("Invalid message, valid message is: "+o);const n=await u(),e=await n.signMessage(t);return console.log("Signature created:",e),e}catch(t){return console.error("Error creating signature:",t),null}},t.chain.createAndStoreEncryptedPair=async function(t,e){try{const o=this,i=await n.pair(),r=await n.encrypt(JSON.stringify(i),e);await o.get("gun-eth").get("users").get(t).put({encryptedPair:r}),console.log("Encrypted pair stored for:",t)}catch(t){console.error("Error creating and storing encrypted pair:",t)}},t.chain.getAndDecryptPair=async function(t,e){try{const o=this,i=await o.get("gun-eth").get("users").get(t).get("encryptedPair").then();if(!i)throw new Error("No encrypted data found for this address");const r=await n.decrypt(i,e);return console.log(r),r}catch(t){return console.error("Error retrieving and decrypting pair:",t),null}},t.chain.shine=function(n,o,a,s){if(console.log("SHINE plugin called with:",{chain:n,nodeId:o,data:a}),!(void 0===e?(console.error("Ethers.js non è disponibile. Assicurati che sia caricato prima di questo script."),0):(console.log("Ethers version:",e.version),1)))return s&&s({err:"Ethers.js non è disponibile"}),this;if("function"!=typeof s)return console.error("Callback must be a function"),this;const c=this;if("optimismSepolia"!==n)throw new Error("Chain not supported");if(i="0x43D838b683F772F08f321E5FA265ad3e333BE9C2",o&&!a)c.get(o).once((async t=>{if(!t)return void(s&&s({err:"Node not found in GunDB"}));console.log("existingData",t);const n=t._contentHash;if(console.log("contentHash",n),n)try{const{isValid:t,timestamp:a,updater:c}=await(async(t,n)=>{console.log("Verifying on chain:",{nodeId:t,contentHash:n});const o=await u(),a=new e.Contract(i,r,o),[s,c,f]=await a.verifyData(e.toUtf8Bytes(t),n);return console.log("Verification result:",{isValid:s,timestamp:c,updater:f}),{isValid:s,timestamp:c,updater:f}})(o,n),f=await(async t=>{const n=await u(),o=new e.Contract(i,r,n),[a,s,c]=await o.getLatestRecord(e.toUtf8Bytes(t));return console.log("Latest record from blockchain:",{nodeId:t,contentHash:a,timestamp:s,updater:c}),{contentHash:a,timestamp:s,updater:c}})(o);t?s&&s({ok:!0,message:"Data verified on blockchain",timestamp:a,updater:c,latestRecord:f}):s&&s({ok:!1,message:"Data not verified on blockchain",latestRecord:f})}catch(t){s&&s({err:t.message})}else s&&s({err:"No content hash found for this node"})}));else if(a&&!o){const n=t.text.random(),o=JSON.stringify(a),f=e.keccak256(e.toUtf8Bytes(o));c.get(n).put({...a,_contentHash:f},(async t=>{if(console.log("ack",t),t.err)s&&s({err:"Error saving data to GunDB"});else try{const t=await(async(t,n)=>{console.log("Writing on chain:",{nodeId:t,contentHash:n});const o=await u(),a=new e.Contract(i,r,o),s=await a.updateData(e.toUtf8Bytes(t),n);console.log("Transaction sent:",s.hash);const c=await s.wait();return console.log("Transaction confirmed:",c),s})(n,f);s&&s({ok:!0,message:"Data written to GunDB and blockchain",nodeId:n,txHash:t.hash})}catch(t){s&&s({err:t.message})}}))}else s&&s({err:"Invalid input. Provide either nodeId or data, not both."});return c},t.chain.gunToEthAccount=function(t){const n="0x"+(t=>{const n="=".repeat((4-t.length%4)%4),e=t.replace(/-/g,"+").replace(/_/g,"/")+n,o=atob(e);return Array.from(o,(t=>t.charCodeAt(0).toString(16).padStart(2,"0"))).join("")})(t),o=new e.Wallet(n);return{account:o,publicKey:o.address}},console.log("Plugin Gun-Eth successfully loaded")},o.exports?o.exports=r(s(),t,n):r(i.Gun,i.SEA,i.ethers)}(i),o(i.exports)}));
package/package.json CHANGED
@@ -1,15 +1,51 @@
1
1
  {
2
2
  "name": "gun-eth",
3
- "version": "1.3.6",
3
+ "version": "1.4.0",
4
4
  "description": "A GunDB plugin for Ethereum, and Web3",
5
- "main": "./src/index.js",
5
+ "main": "dist/gun-eth.cjs.js",
6
+ "module": "dist/gun-eth.esm.js",
7
+ "browser": "dist/gun-eth.min.js",
8
+ "type": "module",
6
9
  "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
10
+ "test": "echo \"Error: no test specified\" && exit 1",
11
+ "start-gun": "node startGun.js",
12
+ "compile": "hardhat compile",
13
+ "start-node": "hardhat node",
14
+ "deploy-local": "hardhat run scripts/start-local-node.cjs --network localhost",
15
+ "test-stealth": "cross-env NODE_ENV=development node --experimental-json-modules src/examples/stealth-example.js",
16
+ "test-proof": "cross-env NODE_ENV=development node --experimental-json-modules src/examples/proof-example.js",
17
+ "build": "rollup -c",
18
+ "build:watch": "rollup -c -w"
8
19
  },
9
20
  "dependencies": {
10
21
  "ethers": "^6.0.0",
22
+ "express": "^4.21.1",
11
23
  "gun": "^0.2020.1239"
12
24
  },
25
+ "devDependencies": {
26
+ "@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
27
+ "@nomicfoundation/hardhat-ethers": "^3.0.0",
28
+ "@nomicfoundation/hardhat-network-helpers": "^1.0.0",
29
+ "@nomicfoundation/hardhat-toolbox": "^3.0.0",
30
+ "@nomicfoundation/hardhat-verify": "^1.0.0",
31
+ "@typechain/ethers-v6": "^0.4.0",
32
+ "@typechain/hardhat": "^8.0.0",
33
+ "@types/chai": "^4.2.0",
34
+ "@types/mocha": "^10.0.1",
35
+ "chai": "^4.2.0",
36
+ "cross-env": "^7.0.3",
37
+ "hardhat": "^2.17.0",
38
+ "hardhat-gas-reporter": "^1.0.8",
39
+ "solidity-coverage": "^0.8.1",
40
+ "ts-node": "^10.9.1",
41
+ "typechain": "^8.2.0",
42
+ "typescript": "^5.0.0",
43
+ "@rollup/plugin-commonjs": "^25.0.0",
44
+ "@rollup/plugin-node-resolve": "^15.0.0",
45
+ "@rollup/plugin-json": "^6.0.0",
46
+ "@rollup/plugin-terser": "^0.4.0",
47
+ "rollup": "^3.0.0"
48
+ },
13
49
  "author": "scobru",
14
50
  "repository": {
15
51
  "type": "git",
@@ -29,5 +65,8 @@
29
65
  "bugs": {
30
66
  "url": "https://github.com/scobru/gun-eth/issues"
31
67
  },
32
- "homepage": "https://github.com/scobru/gun-eth#readme"
68
+ "homepage": "https://github.com/scobru/gun-eth#readme",
69
+ "files": [
70
+ "dist"
71
+ ]
33
72
  }
package/TUTORIAL.md DELETED
@@ -1,103 +0,0 @@
1
- # Tutorial: Illuminating Your Data with SHINE in GunDB 🌟
2
-
3
- Hey there, GunDB aficionado! Ready to take your decentralized data game to the next level? Enter SHINE: your ticket to blockchain-verified data integrity. It's not just about storing data anymore; it's about making it cryptographically awesome!
4
-
5
- ## Step 0: Wallet Integration - Your Blockchain Passport
6
-
7
- Before we dive into the SHINE pool, remember: this plugin requires a browser-based wallet provider. Think of it as your blockchain passport. Here's how to check if you're ready to roll:
8
-
9
- ```javascript
10
- async function connectWallet() {
11
- if (typeof window.ethereum !== "undefined") {
12
- console.log("Ethereum object detected");
13
- try {
14
- await window.ethereum.request({ method: "eth_requestAccounts" });
15
- console.log("Wallet connected successfully");
16
- return true;
17
- } catch (error) {
18
- console.error("Wallet connection denied:", error);
19
- return false;
20
- }
21
- } else {
22
- console.log(
23
- "Please install MetaMask or another Ethereum-compatible wallet"
24
- );
25
- return false;
26
- }
27
- }
28
-
29
- // Make sure to call this before using SHINE
30
- await connectWallet();
31
- ```
32
-
33
- Pro tip: Always ensure your wallet is connected before invoking SHINE functions. No wallet, no blockchain magic!
34
-
35
- ## Step 1: Installation - Equipping Your Toolbelt
36
-
37
- Let's add SHINE to your development arsenal:
38
-
39
- ```bash
40
- npm install gun-eth
41
- ```
42
-
43
- If your terminal responds without errors, you're locked and loaded!
44
-
45
- ## Step 2: Import - Assembling the Pieces
46
-
47
- Time to bring Gun and SHINE into your JavaScript playground:
48
-
49
- ```javascript
50
- import Gun from "gun";
51
- import "gun-eth";
52
- const gun = Gun();
53
- ```
54
-
55
- ## Step 3: SHINE in Action - Blockchain Meets Database
56
-
57
- Let's say you've got some mission-critical data to store. Here's how you'd use SHINE to give it that blockchain-grade integrity:
58
-
59
- ```javascript
60
- const criticalData = {
61
- key1: "Encrypted message",
62
- key2: "Top secret algorithm",
63
- key3: "42",
64
- };
65
-
66
- gun.shine("optimismSepolia", null, criticalData, (ack) => {
67
- if (ack.ok) {
68
- console.log("Data successfully anchored to the blockchain");
69
- console.log("Node ID for future reference:", ack.nodeId);
70
- } else {
71
- console.error("Blockchain anchoring failed:", ack.err);
72
- }
73
- });
74
- ```
75
-
76
- Remember, your wallet needs to be ready to sign this transaction. It's like pushing code without commit access - it just won't fly!
77
-
78
- ## Step 4: Verification - Trust the Crypto, Not the Hearsay
79
-
80
- When it's time to verify your data's integrity:
81
-
82
- ```javascript
83
- const nodeId = "your-data-node-id";
84
- gun.shine("optimismSepolia", nodeId, null, (ack) => {
85
- if (ack.ok) {
86
- console.log("Data integrity verified on the blockchain");
87
- console.log("Timestamp:", ack.timestamp);
88
- console.log("Last updater:", ack.updater);
89
- } else {
90
- console.error("Integrity check failed:", ack.err);
91
- }
92
- });
93
- ```
94
-
95
- Again, wallet connection is crucial. No blockchain access, no verification!
96
-
97
- ## Step 5: Reap the Benefits
98
-
99
- Congratulations! You've just leveled up your data management game. Your data is now cryptographically verifiable, tamper-evident, and blockchain-secured.
100
-
101
- Remember: With SHINE, you're not just storing data; you're creating a cryptographic proof of its existence and integrity. Use this power wisely!
102
-
103
- P.S. SHINE responsibly. With great cryptographic power comes great responsibility. Happy coding, and may your data always maintain its integrity! 🚀🔐
@@ -1,262 +0,0 @@
1
- {
2
- "address": "0x43D838b683F772F08f321E5FA265ad3e333BE9C2",
3
- "abi": [
4
- {
5
- "anonymous": false,
6
- "inputs": [
7
- {
8
- "indexed": true,
9
- "internalType": "bytes",
10
- "name": "nodeId",
11
- "type": "bytes"
12
- },
13
- {
14
- "indexed": false,
15
- "internalType": "bytes32",
16
- "name": "contentHash",
17
- "type": "bytes32"
18
- },
19
- {
20
- "indexed": false,
21
- "internalType": "address",
22
- "name": "updater",
23
- "type": "address"
24
- }
25
- ],
26
- "name": "DataUpdated",
27
- "type": "event"
28
- },
29
- {
30
- "inputs": [
31
- {
32
- "internalType": "bytes[]",
33
- "name": "nodeIds",
34
- "type": "bytes[]"
35
- },
36
- {
37
- "internalType": "bytes32[]",
38
- "name": "contentHashes",
39
- "type": "bytes32[]"
40
- }
41
- ],
42
- "name": "batchUpdateData",
43
- "outputs": [],
44
- "stateMutability": "nonpayable",
45
- "type": "function"
46
- },
47
- {
48
- "inputs": [
49
- {
50
- "internalType": "bytes",
51
- "name": "nodeId",
52
- "type": "bytes"
53
- }
54
- ],
55
- "name": "getLatestRecord",
56
- "outputs": [
57
- {
58
- "internalType": "bytes32",
59
- "name": "",
60
- "type": "bytes32"
61
- },
62
- {
63
- "internalType": "uint256",
64
- "name": "",
65
- "type": "uint256"
66
- },
67
- {
68
- "internalType": "address",
69
- "name": "",
70
- "type": "address"
71
- }
72
- ],
73
- "stateMutability": "view",
74
- "type": "function"
75
- },
76
- {
77
- "inputs": [
78
- {
79
- "internalType": "bytes",
80
- "name": "",
81
- "type": "bytes"
82
- }
83
- ],
84
- "name": "nodeData",
85
- "outputs": [
86
- {
87
- "internalType": "bytes32",
88
- "name": "contentHash",
89
- "type": "bytes32"
90
- },
91
- {
92
- "internalType": "uint256",
93
- "name": "timestamp",
94
- "type": "uint256"
95
- },
96
- {
97
- "internalType": "address",
98
- "name": "updater",
99
- "type": "address"
100
- }
101
- ],
102
- "stateMutability": "view",
103
- "type": "function"
104
- },
105
- {
106
- "inputs": [
107
- {
108
- "internalType": "bytes",
109
- "name": "nodeId",
110
- "type": "bytes"
111
- },
112
- {
113
- "internalType": "bytes32",
114
- "name": "contentHash",
115
- "type": "bytes32"
116
- }
117
- ],
118
- "name": "updateData",
119
- "outputs": [],
120
- "stateMutability": "nonpayable",
121
- "type": "function"
122
- },
123
- {
124
- "inputs": [
125
- {
126
- "internalType": "bytes",
127
- "name": "nodeId",
128
- "type": "bytes"
129
- },
130
- {
131
- "internalType": "bytes32",
132
- "name": "contentHash",
133
- "type": "bytes32"
134
- }
135
- ],
136
- "name": "verifyData",
137
- "outputs": [
138
- {
139
- "internalType": "bool",
140
- "name": "",
141
- "type": "bool"
142
- },
143
- {
144
- "internalType": "uint256",
145
- "name": "",
146
- "type": "uint256"
147
- },
148
- {
149
- "internalType": "address",
150
- "name": "",
151
- "type": "address"
152
- }
153
- ],
154
- "stateMutability": "view",
155
- "type": "function"
156
- }
157
- ],
158
- "transactionHash": "0xc00b134812b2cb32d6a412fd1d1a4c9661777b0ee29ed0ff05b09c7c0b1f6f0d",
159
- "receipt": {
160
- "to": null,
161
- "from": "0x8aA5F726d9F868a21a8bd748E2f1E43bA31eb670",
162
- "contractAddress": "0x43D838b683F772F08f321E5FA265ad3e333BE9C2",
163
- "transactionIndex": 2,
164
- "gasUsed": "419514",
165
- "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
166
- "blockHash": "0xc8bd27a2f9bf4ec35e2c61c2c2e62b47b70aa10f587ea48d4802611c36116dd6",
167
- "transactionHash": "0xc00b134812b2cb32d6a412fd1d1a4c9661777b0ee29ed0ff05b09c7c0b1f6f0d",
168
- "logs": [],
169
- "blockNumber": 17723163,
170
- "cumulativeGasUsed": "551282",
171
- "status": 1,
172
- "byzantium": true
173
- },
174
- "args": [],
175
- "numDeployments": 4,
176
- "solcInputHash": "40cece70198a47ff2f958bd8d77d352d",
177
- "metadata": "{\"compiler\":{\"version\":\"0.8.17+commit.8df45f5f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"anonymous\":false,\"inputs\":[{\"indexed\":true,\"internalType\":\"bytes\",\"name\":\"nodeId\",\"type\":\"bytes\"},{\"indexed\":false,\"internalType\":\"bytes32\",\"name\":\"contentHash\",\"type\":\"bytes32\"},{\"indexed\":false,\"internalType\":\"address\",\"name\":\"updater\",\"type\":\"address\"}],\"name\":\"DataUpdated\",\"type\":\"event\"},{\"inputs\":[{\"internalType\":\"bytes[]\",\"name\":\"nodeIds\",\"type\":\"bytes[]\"},{\"internalType\":\"bytes32[]\",\"name\":\"contentHashes\",\"type\":\"bytes32[]\"}],\"name\":\"batchUpdateData\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"nodeId\",\"type\":\"bytes\"}],\"name\":\"getLatestRecord\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"\",\"type\":\"bytes\"}],\"name\":\"nodeData\",\"outputs\":[{\"internalType\":\"bytes32\",\"name\":\"contentHash\",\"type\":\"bytes32\"},{\"internalType\":\"uint256\",\"name\":\"timestamp\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"updater\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"nodeId\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"contentHash\",\"type\":\"bytes32\"}],\"name\":\"updateData\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"bytes\",\"name\":\"nodeId\",\"type\":\"bytes\"},{\"internalType\":\"bytes32\",\"name\":\"contentHash\",\"type\":\"bytes32\"}],\"name\":\"verifyData\",\"outputs\":[{\"internalType\":\"bool\",\"name\":\"\",\"type\":\"bool\"},{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"},{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"contracts/SHINE.sol\":\"SHINE\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\",\"useLiteralContent\":true},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[]},\"sources\":{\"contracts/SHINE.sol\":{\"content\":\"// SPDX-License-Identifier: MIT\\r\\npragma solidity ^0.8.0;\\r\\n\\r\\ncontract SHINE {\\r\\n\\tstruct DataRecord {\\r\\n\\t\\tbytes32 contentHash;\\r\\n\\t\\tuint256 timestamp;\\r\\n\\t\\taddress updater;\\r\\n\\t}\\r\\n\\r\\n\\tmapping(bytes => DataRecord) public nodeData;\\r\\n\\r\\n\\tevent DataUpdated(\\r\\n\\t\\tbytes indexed nodeId,\\r\\n\\t\\tbytes32 contentHash,\\r\\n\\t\\taddress updater\\r\\n\\t);\\r\\n\\r\\n\\tfunction updateData(bytes memory nodeId, bytes32 contentHash) public {\\r\\n\\t\\tnodeData[nodeId] = DataRecord(contentHash, block.timestamp, msg.sender);\\r\\n\\t\\temit DataUpdated(nodeId, contentHash, msg.sender);\\r\\n\\t}\\r\\n\\r\\n\\tfunction verifyData(\\r\\n\\t\\tbytes memory nodeId,\\r\\n\\t\\tbytes32 contentHash\\r\\n\\t) public view returns (bool, uint256, address) {\\r\\n\\t\\tDataRecord memory record = nodeData[nodeId];\\r\\n\\t\\tbool isValid = record.contentHash == contentHash;\\r\\n\\t\\treturn (isValid, record.timestamp, record.updater);\\r\\n\\t}\\r\\n\\r\\n\\tfunction getLatestRecord(\\r\\n\\t\\tbytes memory nodeId\\r\\n\\t) public view returns (bytes32, uint256, address) {\\r\\n\\t\\tDataRecord memory record = nodeData[nodeId];\\r\\n\\t\\treturn (record.contentHash, record.timestamp, record.updater);\\r\\n\\t}\\r\\n\\r\\n\\tfunction batchUpdateData(\\r\\n\\t\\tbytes[] memory nodeIds,\\r\\n\\t\\tbytes32[] memory contentHashes\\r\\n\\t) public {\\r\\n\\t\\trequire(\\r\\n\\t\\t\\tnodeIds.length == contentHashes.length,\\r\\n\\t\\t\\t\\\"Arrays length mismatch\\\"\\r\\n\\t\\t);\\r\\n\\t\\tfor (uint i = 0; i < nodeIds.length; i++) {\\r\\n\\t\\t\\tupdateData(nodeIds[i], contentHashes[i]);\\r\\n\\t\\t}\\r\\n\\t}\\r\\n}\\r\\n\",\"keccak256\":\"0x1ed77b1882586a77f3e6d5bf176009c5f00b9d91f71cfd6153ca2d57ef30831d\",\"license\":\"MIT\"}},\"version\":1}",
178
- "bytecode": "0x608060405234801561001057600080fd5b506106a0806100206000396000f3fe608060405234801561001057600080fd5b50600436106100575760003560e01c80630d36830e1461005c5780630f07e48514610071578063d236feda14610084578063d54193d7146100c2578063d58a3de3146100f9575b600080fd5b61006f61006a3660046104a8565b61013c565b005b61006f61007f36600461057c565b6101e9565b61009761009236600461057c565b6102a2565b60408051931515845260208401929092526001600160a01b0316908201526060015b60405180910390f35b6100d56100d03660046105c1565b610302565b6040805193845260208401929092526001600160a01b0316908201526060016100b9565b6100d56101073660046105c1565b80516020818301810180516000825292820191909301209152805460018201546002909201549091906001600160a01b031683565b805182511461018a5760405162461bcd60e51b8152602060048201526016602482015275082e4e4c2f2e640d8cadccee8d040dad2e6dac2e8c6d60531b604482015260640160405180910390fd5b60005b82518110156101e4576101d28382815181106101ab576101ab6105fe565b60200260200101518383815181106101c5576101c56105fe565b60200260200101516101e9565b806101dc81610614565b91505061018d565b505050565b604080516060810182528281524260208201523381830152905160009061021190859061063b565b908152604080516020928190038301812084518155928401516001840155920151600290910180546001600160a01b0319166001600160a01b0390921691909117905561025f90839061063b565b60408051918290038220838352336020840152917fac3d4f3cbf6818c9329b6b8c61e41d9dc52fc1cc580fff6af273be3ebc1d423f910160405180910390a25050565b6000806000806000866040516102b8919061063b565b9081526040805160209281900383018120606082018352805480835260018201549483018590526002909101546001600160a01b0316919092018190529614979096509350505050565b600080600080600085604051610318919061063b565b9081526040805160209281900383018120606082018352805480835260018201549483018590526002909101546001600160a01b0316919092018190529097919650945092505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156103a1576103a1610362565b604052919050565b600067ffffffffffffffff8211156103c3576103c3610362565b5060051b60200190565b600082601f8301126103de57600080fd5b813567ffffffffffffffff8111156103f8576103f8610362565b61040b601f8201601f1916602001610378565b81815284602083860101111561042057600080fd5b816020850160208301376000918101602001919091529392505050565b600082601f83011261044e57600080fd5b8135602061046361045e836103a9565b610378565b82815260059290921b8401810191818101908684111561048257600080fd5b8286015b8481101561049d5780358352918301918301610486565b509695505050505050565b600080604083850312156104bb57600080fd5b823567ffffffffffffffff808211156104d357600080fd5b818501915085601f8301126104e757600080fd5b813560206104f761045e836103a9565b82815260059290921b8401810191818101908984111561051657600080fd5b8286015b8481101561054e578035868111156105325760008081fd5b6105408c86838b01016103cd565b84525091830191830161051a565b509650508601359250508082111561056557600080fd5b506105728582860161043d565b9150509250929050565b6000806040838503121561058f57600080fd5b823567ffffffffffffffff8111156105a657600080fd5b6105b2858286016103cd565b95602094909401359450505050565b6000602082840312156105d357600080fd5b813567ffffffffffffffff8111156105ea57600080fd5b6105f6848285016103cd565b949350505050565b634e487b7160e01b600052603260045260246000fd5b60006001820161063457634e487b7160e01b600052601160045260246000fd5b5060010190565b6000825160005b8181101561065c5760208186018101518583015201610642565b50600092019182525091905056fea2646970667358221220c3ea212644c861f0e892deb0129df945a7fa2af5971e51e4b97810c73fc547f764736f6c63430008110033",
179
- "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100575760003560e01c80630d36830e1461005c5780630f07e48514610071578063d236feda14610084578063d54193d7146100c2578063d58a3de3146100f9575b600080fd5b61006f61006a3660046104a8565b61013c565b005b61006f61007f36600461057c565b6101e9565b61009761009236600461057c565b6102a2565b60408051931515845260208401929092526001600160a01b0316908201526060015b60405180910390f35b6100d56100d03660046105c1565b610302565b6040805193845260208401929092526001600160a01b0316908201526060016100b9565b6100d56101073660046105c1565b80516020818301810180516000825292820191909301209152805460018201546002909201549091906001600160a01b031683565b805182511461018a5760405162461bcd60e51b8152602060048201526016602482015275082e4e4c2f2e640d8cadccee8d040dad2e6dac2e8c6d60531b604482015260640160405180910390fd5b60005b82518110156101e4576101d28382815181106101ab576101ab6105fe565b60200260200101518383815181106101c5576101c56105fe565b60200260200101516101e9565b806101dc81610614565b91505061018d565b505050565b604080516060810182528281524260208201523381830152905160009061021190859061063b565b908152604080516020928190038301812084518155928401516001840155920151600290910180546001600160a01b0319166001600160a01b0390921691909117905561025f90839061063b565b60408051918290038220838352336020840152917fac3d4f3cbf6818c9329b6b8c61e41d9dc52fc1cc580fff6af273be3ebc1d423f910160405180910390a25050565b6000806000806000866040516102b8919061063b565b9081526040805160209281900383018120606082018352805480835260018201549483018590526002909101546001600160a01b0316919092018190529614979096509350505050565b600080600080600085604051610318919061063b565b9081526040805160209281900383018120606082018352805480835260018201549483018590526002909101546001600160a01b0316919092018190529097919650945092505050565b634e487b7160e01b600052604160045260246000fd5b604051601f8201601f1916810167ffffffffffffffff811182821017156103a1576103a1610362565b604052919050565b600067ffffffffffffffff8211156103c3576103c3610362565b5060051b60200190565b600082601f8301126103de57600080fd5b813567ffffffffffffffff8111156103f8576103f8610362565b61040b601f8201601f1916602001610378565b81815284602083860101111561042057600080fd5b816020850160208301376000918101602001919091529392505050565b600082601f83011261044e57600080fd5b8135602061046361045e836103a9565b610378565b82815260059290921b8401810191818101908684111561048257600080fd5b8286015b8481101561049d5780358352918301918301610486565b509695505050505050565b600080604083850312156104bb57600080fd5b823567ffffffffffffffff808211156104d357600080fd5b818501915085601f8301126104e757600080fd5b813560206104f761045e836103a9565b82815260059290921b8401810191818101908984111561051657600080fd5b8286015b8481101561054e578035868111156105325760008081fd5b6105408c86838b01016103cd565b84525091830191830161051a565b509650508601359250508082111561056557600080fd5b506105728582860161043d565b9150509250929050565b6000806040838503121561058f57600080fd5b823567ffffffffffffffff8111156105a657600080fd5b6105b2858286016103cd565b95602094909401359450505050565b6000602082840312156105d357600080fd5b813567ffffffffffffffff8111156105ea57600080fd5b6105f6848285016103cd565b949350505050565b634e487b7160e01b600052603260045260246000fd5b60006001820161063457634e487b7160e01b600052601160045260246000fd5b5060010190565b6000825160005b8181101561065c5760208186018101518583015201610642565b50600092019182525091905056fea2646970667358221220c3ea212644c861f0e892deb0129df945a7fa2af5971e51e4b97810c73fc547f764736f6c63430008110033",
180
- "devdoc": {
181
- "kind": "dev",
182
- "methods": {},
183
- "version": 1
184
- },
185
- "userdoc": {
186
- "kind": "user",
187
- "methods": {},
188
- "version": 1
189
- },
190
- "storageLayout": {
191
- "storage": [
192
- {
193
- "astId": 13,
194
- "contract": "contracts/SHINE.sol:SHINE",
195
- "label": "nodeData",
196
- "offset": 0,
197
- "slot": "0",
198
- "type": "t_mapping(t_bytes_memory_ptr,t_struct(DataRecord)8_storage)"
199
- }
200
- ],
201
- "types": {
202
- "t_address": {
203
- "encoding": "inplace",
204
- "label": "address",
205
- "numberOfBytes": "20"
206
- },
207
- "t_bytes32": {
208
- "encoding": "inplace",
209
- "label": "bytes32",
210
- "numberOfBytes": "32"
211
- },
212
- "t_bytes_memory_ptr": {
213
- "encoding": "bytes",
214
- "label": "bytes",
215
- "numberOfBytes": "32"
216
- },
217
- "t_mapping(t_bytes_memory_ptr,t_struct(DataRecord)8_storage)": {
218
- "encoding": "mapping",
219
- "key": "t_bytes_memory_ptr",
220
- "label": "mapping(bytes => struct SHINE.DataRecord)",
221
- "numberOfBytes": "32",
222
- "value": "t_struct(DataRecord)8_storage"
223
- },
224
- "t_struct(DataRecord)8_storage": {
225
- "encoding": "inplace",
226
- "label": "struct SHINE.DataRecord",
227
- "members": [
228
- {
229
- "astId": 3,
230
- "contract": "contracts/SHINE.sol:SHINE",
231
- "label": "contentHash",
232
- "offset": 0,
233
- "slot": "0",
234
- "type": "t_bytes32"
235
- },
236
- {
237
- "astId": 5,
238
- "contract": "contracts/SHINE.sol:SHINE",
239
- "label": "timestamp",
240
- "offset": 0,
241
- "slot": "1",
242
- "type": "t_uint256"
243
- },
244
- {
245
- "astId": 7,
246
- "contract": "contracts/SHINE.sol:SHINE",
247
- "label": "updater",
248
- "offset": 0,
249
- "slot": "2",
250
- "type": "t_address"
251
- }
252
- ],
253
- "numberOfBytes": "96"
254
- },
255
- "t_uint256": {
256
- "encoding": "inplace",
257
- "label": "uint256",
258
- "numberOfBytes": "32"
259
- }
260
- }
261
- }
262
- }
@@ -1,52 +0,0 @@
1
- // SPDX-License-Identifier: MIT
2
- pragma solidity ^0.8.0;
3
-
4
- contract SHINE {
5
- struct DataRecord {
6
- bytes32 contentHash;
7
- uint256 timestamp;
8
- address updater;
9
- }
10
-
11
- mapping(bytes => DataRecord) public nodeData;
12
-
13
- event DataUpdated(
14
- bytes indexed nodeId,
15
- bytes32 contentHash,
16
- address updater
17
- );
18
-
19
- function updateData(bytes memory nodeId, bytes32 contentHash) public {
20
- nodeData[nodeId] = DataRecord(contentHash, block.timestamp, msg.sender);
21
- emit DataUpdated(nodeId, contentHash, msg.sender);
22
- }
23
-
24
- function verifyData(
25
- bytes memory nodeId,
26
- bytes32 contentHash
27
- ) public view returns (bool, uint256, address) {
28
- DataRecord memory record = nodeData[nodeId];
29
- bool isValid = record.contentHash == contentHash;
30
- return (isValid, record.timestamp, record.updater);
31
- }
32
-
33
- function getLatestRecord(
34
- bytes memory nodeId
35
- ) public view returns (bytes32, uint256, address) {
36
- DataRecord memory record = nodeData[nodeId];
37
- return (record.contentHash, record.timestamp, record.updater);
38
- }
39
-
40
- function batchUpdateData(
41
- bytes[] memory nodeIds,
42
- bytes32[] memory contentHashes
43
- ) public {
44
- require(
45
- nodeIds.length == contentHashes.length,
46
- "Arrays length mismatch"
47
- );
48
- for (uint i = 0; i < nodeIds.length; i++) {
49
- updateData(nodeIds[i], contentHashes[i]);
50
- }
51
- }
52
- }