gun-eth 1.3.6 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. package/README.md +18 -207
  2. package/dist/gun-eth-protocol.cjs.js +11528 -0
  3. package/dist/gun-eth-protocol.esm.js +11503 -0
  4. package/dist/gun-eth-protocol.js +18 -0
  5. package/dist/gun-eth-protocol.react.js +11503 -0
  6. package/dist/gun-eth-protocol.umd.js +18 -0
  7. package/jsdoc.json +7 -0
  8. package/package.json +28 -25
  9. package/rollup.config.js +80 -0
  10. package/src/index.js +160 -512
  11. package/src/lib/authentication/index.js +13 -0
  12. package/src/lib/authentication/isAuthenticated.js +20 -0
  13. package/src/lib/authentication/login.js +25 -0
  14. package/src/lib/authentication/register.js +58 -0
  15. package/src/lib/blockchain/ethereum.js +74 -0
  16. package/src/lib/blockchain/shine.js +204 -0
  17. package/src/lib/certificates/friendsCertificates.js +92 -0
  18. package/src/lib/certificates/index.js +44 -0
  19. package/src/lib/certificates/messagingCertificates.js +94 -0
  20. package/src/lib/friends/acceptFriendRequest.js +69 -0
  21. package/src/lib/friends/addFriendRequest.js +49 -0
  22. package/src/lib/friends/friendRequests.js +51 -0
  23. package/src/lib/friends/friendsList.js +57 -0
  24. package/src/lib/friends/index.js +36 -0
  25. package/src/lib/friends/rejectFriendRequest.js +31 -0
  26. package/src/lib/messaging/chatsList.js +42 -0
  27. package/src/lib/messaging/createChat.js +132 -0
  28. package/src/lib/messaging/index.js +36 -0
  29. package/src/lib/messaging/messageList.js +106 -0
  30. package/src/lib/messaging/sendMessage.js +132 -0
  31. package/src/lib/messaging/sendVoiceMessage.js +119 -0
  32. package/src/lib/notes/createNote.js +41 -0
  33. package/src/lib/notes/deleteNote.js +12 -0
  34. package/src/lib/notes/getNote.js +25 -0
  35. package/src/lib/notes/getUserNote.js +59 -0
  36. package/src/lib/notes/index.js +8 -0
  37. package/src/lib/notes/updateNotes.js +35 -0
  38. package/src/lib/post/createPost.js +17 -0
  39. package/src/lib/post/decryptPost.js +14 -0
  40. package/src/lib/post/deletePost.js +13 -0
  41. package/src/lib/post/encryptPost,js +16 -0
  42. package/src/lib/post/getPost.js +36 -0
  43. package/src/lib/post/index.js +9 -0
  44. package/src/lib/post/updatePost.js +16 -0
  45. package/src/state/gun.js +33 -0
  46. package/types/types.d.ts +244 -0
  47. package/TUTORIAL.md +0 -103
  48. package/src/examples/eth2gun.html +0 -163
  49. package/src/examples/gun2eth.html +0 -164
  50. package/src/examples/shine.html +0 -256
  51. /package/src/{abis → lib/blockchain/abis}/SHINE.json +0 -0
  52. /package/src/{contracts → lib/blockchain/contracts}/SHINE.sol +0 -0
@@ -0,0 +1,18 @@
1
+ var GunEthProtocol=function(e,t){"use strict";var r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function n(e){throw new Error('Could not dynamically require "'+e+'". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.')}var o,i={exports:{}};o=i,function(){function e(t,r){return r?n(t):t.slice?e[o(t)]:function(r,n){t(r={exports:{}}),e[o(n)]=r.exports};function o(e){return e.split("/").slice(-1).toString().replace(".js","")}}var t=o;e((function(e){String.random=function(e,t){var r="";for(e=e||24,t=t||"0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";e-- >0;)r+=t.charAt(Math.floor(Math.random()*t.length));return r},String.match=function(e,t){var r,n;return"string"==typeof e&&("string"==typeof t&&(t={"=":t}),e===(r=(t=t||{})["="]||t["*"]||t[">"]||t["<"])||n===t["="]&&(r=t["*"]||t[">"],e.slice(0,(r||"").length)===r||n===t["*"]&&(n!==t[">"]&&n!==t["<"]?e>=t[">"]&&e<=t["<"]:n!==t[">"]&&e>=t[">"]||n!==t["<"]&&e<=t["<"])))},String.hash=function(e,t){if("string"==typeof e){if(t=t||0,!e.length)return t;for(var r=0,n=e.length;r<n;++r)t=(t<<5)-t+e.charCodeAt(r),t|=0;return t}};var t,r,n,o,i=Object.prototype.hasOwnProperty;Object.plain=function(e){return!!e&&(e instanceof Object&&e.constructor===Object||"Object"===Object.prototype.toString.call(e).match(/^\[object (\w+)\]$/)[1])},Object.empty=function(e,t){for(var r in e)if(i.call(e,r)&&(!t||-1==t.indexOf(r)))return!1;return!0},Object.keys=Object.keys||function(e){var t=[];for(var r in e)i.call(e,r)&&t.push(r);return t},t=setTimeout,r=0,n=0,o=typeof setImmediate!=""+void 0&&setImmediate||t,t.poll=t.poll||function(e){1>=+new Date-r&&n++<3333?e():o((function(){r=+new Date,e()}),n=0)},function(){var e,t=setTimeout,r=t.turn=t.turn||function(e){1==n.push(e)&&o(a)},n=r.s=[],o=t.poll,i=0,a=function(){(e=n[i++])&&e(),i!=n.length&&99!=i||(n=r.s=n.slice(i),i=0),n.length&&o(a)}}(),function(){var e,t=setTimeout,r=t.turn;(t.each=t.each||function(t,n,o,i){i=i||9,function a(s,u,c){if(u=(s=(t||[]).splice(0,i)).length){for(var f=0;f<u&&e===(c=n(s[f]));f++);if(e===c)return void r(a)}o&&o(c)}()})()}()}))(e,"./shim"),e((function(e){e.exports=function e(t,r,n){if(!t)return{to:e};var o="function"==typeof r;if(t=(this.tag||(this.tag={}))[t]||o&&(this.tag[t]={tag:t,to:e._={next:function(e){var t;(t=this.to)&&t.next(e)}}}),o){var i={off:e.off||(e.off=function(){if(this.next===e._.next)return!0;this===this.the.last&&(this.the.last=this.back),this.to.back=this.back,this.next=e._.next,this.back.to=this.to,this.the.last===this.the&&delete this.on.tag[this.the.tag]}),to:e._,next:r,the:t,on:this,as:n};return(i.back=t.last||t).to=i,t.last=i}return(t=t.to)&&void 0!==r&&t.next(r),t}}))(e,"./onto"),e((function(t){e("./shim"),t.exports=function(e){return void 0!==e&&(null===e||e!==1/0&&e==e&&("string"==typeof e||"boolean"==typeof e||"number"==typeof e||!(!e||"string"!=typeof(e["#"]||0)||!Object.empty(e,["#"]))&&e["#"]))}}))(e,"./valid"),e((function(t){function r(){var e=+new Date;return s<e?(i=0,s=e+r.drift):s=e+(i+=1)/a+r.drift}e("./shim"),r.drift=0;var n,o=-1/0,i=0,a=999,s=o;r.is=function(e,t,r){var n=t&&e&&e._&&e._[">"]||r;if(n)return"number"==typeof(n=n[t])?n:o},r.ify=function(e,t,r,o,i){(e=e||{})._=e._||{},i&&(e._["#"]=i);var a=e._[">"]||(e._[">"]={});return n!==t&&"_"!==t&&("number"==typeof r&&(a[t]=r),n!==o&&(e[t]=o)),e},t.exports=r}))(e,"./state"),e((function(t){e("./shim"),t.exports=function(e){var t={s:{}},r=t.s;e=e||{max:999,age:9e3},t.check=function(e){return!!r[e]&&n(e)};var n=t.track=function(n){var o=r[n]||(r[n]={});return o.was=t.now=+new Date,t.to||(t.to=setTimeout(t.drop,e.age+9)),o};return t.drop=function(n){t.to=null,t.now=+new Date;var o=Object.keys(r);console.STAT&&console.STAT(t.now,+new Date-t.now,"dup drop keys"),setTimeout.each(o,(function(o){var i=r[o];i&&(n||e.age)>t.now-i.was||delete r[o]}),0,99)},t}}))(e,"./dup"),e((function(t){e("./onto"),t.exports=function(e,t){if(this.on){var n=(this.opt||{}).lack||9e3;if("function"!=typeof e){if(!e)return;var o=e["#"]||e,i=(this.tag||"")[o];if(!i)return;return t&&(i=this.on(o,t),clearTimeout(i.err),i.err=setTimeout((function(){i.off()}),n)),!0}if(o=t&&t["#"]||r(9),!e)return o;var a=this.on(o,e,t);return a.err=a.err||setTimeout((function(){a.off(),a.next({err:"Error: No ACK yet.",lack:!0})}),n),o}};var r=String.random||function(){return Math.random().toString(36).slice(2)}}))(e,"./ask"),e((function(r){function n(e){return e instanceof n?(this._={$:this}).$:this instanceof n?n.create(this._={$:this,opt:e}):new n(e)}n.is=function(e){return e instanceof n||e&&e._&&e===e._.$||!1},n.version=.202,n.chain=n.prototype,n.chain.toJSON=function(){},e("./shim"),n.valid=e("./valid"),n.state=e("./state"),n.on=e("./onto"),n.dup=e("./dup"),n.ask=e("./ask"),function(){function e(r){if(r)if(r.out!==e){var o,i=this.as,u=i.at||i,c=u.$,f=u.dup,l=r.DBG;if((o=r["#"])||(o=r["#"]=s(9)),!f.check(o)){if(f.track(o),o=r._,r._="function"==typeof o?o:function(){},r.$&&r.$===(r.$._||"").$||(r.$=c),r["@"]&&!r.put&&function(e){var t,r=e["@"]||"";(t=r._)&&(t.acks=(t.acks||0)+1,(t.err=e.err)&&(e["@"]=t["#"],a(t)),t.stop||t.crack||(t.crack=t.match&&t.match.push((function(){d(t)}))),d(t))}(r),!u.ask(r["@"],r)){if(l&&(l.u=+new Date),r.put)return void t(r);r.get&&n.on.get(r,c)}l&&(l.uc=+new Date),this.to.next(r),l&&(l.ua=+new Date),r.nts||r.NTS||(r.out=e,u.on("out",r),l&&(l.ue=+new Date))}}else this.to.next(r)}function t(t){if(t){var n=t._||"",i=n.root=((n.$=t.$||"")._||"").root;if(t["@"]&&n.faith&&!n.miss)return t.out=e,void i.on("out",t);n.latch=i.hatch,n.match=i.hatch=[];var s=t.put,f=n.DBG=t.DBG,l=+new Date;if(!s["#"]||!s["."]){f&&(f.p=l),n["#"]=t["#"],n.msg=t,n.all=0,n.stun=1;var p=Object.keys(s);console.STAT&&console.STAT(l,((f||n).pk=+new Date)-l,"put sort");var d,y,v,w,b,m,k,S=0;!function e(i){if(d!=S){if(d=S,!(v=p[S]))return console.STAT&&console.STAT(l,((f||n).pd=+new Date)-l,"put"),void a(n);(w=s[v])?(k=w._)?v!==k["#"]?m=h+g(v)+"soul not same.":(b=k[">"])||(m=h+g(v)+"no state."):m=h+g(v)+"no meta.":m=h+g(v)+"no node.",y=Object.keys(w||{})}if(m)return t.err=n.err=m,void a(n);var x,_=0;for(i=i||0;i++<9&&(x=y[_++]);)if("_"!==x){var A=w[x],T=b[x];if(o===T){m=h+g(x)+"on"+g(v)+"no state.";break}if(!c(A)){m=h+g(x)+"on"+g(v)+"bad "+typeof A+g(A);break}r(A,x,v,T,t)}(y=y.slice(_)).length?u(e):(++S,y=null,e(i))}()}}}function r(e,t,n,o,i){var a,s=i._||"",u=s.root,c=u.graph,l=c[n]||p,d=f(l,t,1),h=l[t],g=s.DBG;(a=console.STAT)&&(c[n]&&h||(a.has=(a.has||0)+1));var b=w();if(o>b)return setTimeout((function(){r(e,t,n,o,i)}),(a=o-b)>v?v:a),void(console.STAT&&console.STAT((g||s).Hf=+new Date,a,"future"));if((!(o<d)||s.miss)&&(s.faith||o!==d||!(e===h||y(e)<=y(h))||s.miss)){s.stun++;var m=i["#"]+s.all++,k={toString:function(){return m},_:s};k.toJSON=k.toString,g&&(g.ph=g.ph||+new Date),u.on("put",{"#":k,"@":i["@"],put:{"#":n,".":t,":":e,">":o},_:s})}}function i(e){var t;(t=(e._||"").DBG)&&(t.pa=+new Date,t.pm=t.pm||+new Date);var r,n=this.as,o=n.graph,i=e._,s=e.put,u=s["#"],c=s["."],f=s[":"],p=s[">"];e["#"],(r=i.msg)&&(r=r.put)&&(r=r[u])&&l(r,c,p,f,u),o[u]=l(o[u],c,p,f,u),(r=(n.next||"")[u])&&r.on("in",e),a(i),this.to.next(e)}function a(t,r){var n;if(!t.stop&&(t.err||!(0<--t.stun))&&(t.stop=1,n=t.root)){var o=t.match;o.end=1,o===n.hatch&&(!(o=t.latch)||o.end?delete n.hatch:n.hatch=o),t.hatch&&t.hatch(),setTimeout.each(t.match,(function(e){e&&e()})),!(r=t.msg)||t.err||r.err||(r.out=e,t.root.on("out",r))}}function d(e){e&&e.root&&(e.stun||e.acks!==e.all||e.root.on("in",{"@":e["#"],err:e.err,ok:e.err?o:{"":1}}))}n.create=function(t){t.root=t.root||t,t.graph=t.graph||{},t.on=t.on||n.on,t.ask=t.ask||n.ask,t.dup=t.dup||n.dup();var r=t.$.opt(t.opt);return t.once||(t.on("in",e,t),t.on("out",e,t),t.on("put",i,t),n.on("create",t),t.on("create",t)),t.once=1,r},n.on.put=t;var h="Error: Invalid graph!",g=function(e){return" '"+(""+e).slice(0,9)+"...' "},y=JSON.stringify,v=2147483647,w=n.state}(),function(){function e(e,t){var r=+new Date,n=e._||{},i=n.DBG=e.DBG,a=e["#"],u=s(9),c=Object.keys(t||"").sort(),p=((t||"")._||"")["#"];c.length;var d=e.$._.root,h=t===d.graph[p];console.STAT&&console.STAT(r,((i||n).gk=+new Date)-r,"got keys"),t&&function e(){r=+new Date;for(var n,g,y,v=0,w={};v<9&&(n=c[v++]);)l(w,n,f(t,n),t[n],p);c=c.slice(v),(g={})[p]=w,w=g,h&&((y=function(){}).ram=y.faith=!0),g=c.length,console.STAT&&console.STAT(r,-(r-(r=+new Date)),"got copied some"),i&&(i.ga=+new Date),d.on("in",{"@":a,"#":u,put:w,"%":g?u=s(9):o,$:d.$,_:y,DBG:i}),console.STAT&&console.STAT(r,+new Date-r,"got in"),g&&setTimeout.turn(e)}(),t||d.on("in",{"@":e["#"]})}n.on.get=function(t,r){var n=r._,i=t.get,a=i["#"],s=n.graph[a],u=i["."];(n.next||(n.next={}))[a];var c=(t._||{}).DBG=t.DBG;if(c&&(c.g=+new Date),!s)return n.on("get",t);if(u){if("string"!=typeof u||o===s[u])return n.on("get",t);s=l({},u,f(s,u),s[u],a)}s&&e(t,s),n.on("get",t)},n.on.get.ack=e}(),n.chain.opt=function(e){e=e||{};var t=this._,r=e.peers||e;return Object.plain(e)||(e={}),Object.plain(t.opt)||(t.opt=e),"string"==typeof r&&(r=[r]),r instanceof Array&&(Object.plain(t.opt.peers)||(t.opt.peers={}),r.forEach((function(e){var r={};r.id=r.url=e,t.opt.peers[e]=t.opt.peers[e]||r}))),t.opt.peers=t.opt.peers||{},a(e,(function e(t){var r=this[t];this&&this.hasOwnProperty(t)||"string"==typeof r||Object.empty(r)?this[t]=r:(!r||r.constructor===Object||r instanceof Array)&&a(r,e)})),n.on("opt",t),t.opt.uuid=t.opt.uuid||function(e){return n.state().toString(36).replace(".","")+String.random(e||12)},this};var o,i,a=function(e,t){Object.keys(e).forEach(t,e)},s=String.random,u=setTimeout.turn,c=n.valid,f=n.state.is,l=n.state.ify,p={};n.log=function(){return!n.log.off&&i.log.apply(i,arguments),[].slice.call(arguments).join(" ")},n.log.once=function(e,t,r){return(r=n.log.once)[e]=r[e]||0,r[e]++||n.log(t)},"undefined"!=typeof window&&((window.GUN=window.Gun=n).window=window);try{void 0!==t&&(t.exports=n)}catch(e){}r.exports=n,(n.window||{}).console=(n.window||{}).console||{log:function(){}},(i=console).only=function(e,t){return i.only.i&&e===i.only.i&&i.only.i++&&(i.log.apply(i,arguments)||t)},n.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!")}))(e,"./root"),e((function(t){e("./root").chain.back=function(e,t){if(-1===(e=e||1)||1/0===e)return this._.root.$;if(1===e)return(this._.back||this._).$;var o=this._;if("string"==typeof e&&(e=e.split(".")),e instanceof Array){for(var i=0,a=e.length,s=o;i<a;i++)s=(s||n)[e[i]];return r!==s?t?this:s:(s=o.back)?s.$.back(e,t):void 0}if("function"==typeof e){var u;for(s={back:o};(s=s.back)&&r===(u=e(s,t)););return u}return"number"==typeof e?(o.back||o).$.back(e-1):this};var r,n={}}))(e,"./back"),e((function(t){var r=e("./root");function n(e,t){if(t=t||this.as||e.$._,(!e.$$||this===r.on)&&e.put&&!t.soul){var n=e.put||"",o=n["="]||n[":"],i=t.root,a=i.$.get(n["#"]).get(n["."])._;if("string"==typeof(o=c(o))){if(!(a.echo||(a.echo={}))[t.id]||(i.pass||"")[t.id]){if(s=i.pass){if(s[o+t.id])return;s[o+t.id]=1}(a.echo||(a.echo={}))[t.id]=t,t.has&&(t.link=o);var s,u=i.$.get(a.link=o)._;(u.echo||(u.echo={}))[a.id]=a,((s=t.ask||"")[""]||t.lex)&&u.on("out",{get:{"#":o}}),setTimeout.each(Object.keys(s),(function(e,t){e&&(t=s[e])&&t.on("out",{get:{"#":o,".":e}})}),0,99)}}else this===r.on&&((a.echo||(a.echo={}))[t.id]=t)}}function o(e,t){var r,n,i=e.put||"",s=a!==i["="]?i["="]:i[":"],u=t.root;if(a===s){if(t.soul&&a!==t.put)return;if(n=(e.$$||e.$||"")._||"",e["@"]&&(a!==n.put||a!==t.put))return;return(r=t.link||e.linked)&&delete(u.$.get(r)._.echo||"")[t.id],t.has&&(t.link=null),t.put=a,void setTimeout.each(Object.keys(t.next||""),(function(e,n){(n=t.next[e])&&(r&&delete(u.$.get(r).get(e)._.echo||"")[n.id],n.on("in",{get:e,put:a,$:n.$}))}),0,99)}t.soul||e.$$||(r=c(s),n=e.$._||"",(r!==n.link&&(!t.has||n.link)||(u.pass||"")[t.id]&&"string"!=typeof r)&&(delete(n.echo||"")[t.id],o({get:t.get,put:a,$:e.$,linked:e.linked=e.linked||n.link},t)))}function i(e,t){var n=this.as,o=n.$._;o.root;var i=n.get||"",s=(e.put||"")[i["#"]]||"";if(!e.put||"string"==typeof i["."]&&a===s[i["."]]){if(a!==o.put)return;if(!o.soul&&!o.has)return;return o.ack=(o.ack||0)+1,void o.on("in",{get:o.get,put:o.put=a,$:o.$,"@":e["@"]})}(e._||{}).miss=1,r.on.put(e)}r.chain.chain=function(e){var t,n=this,o=n._,i=new(e||n).constructor(n),a=i._;return a.root=t=o.root,a.id=++t.once,a.back=n._,a.on=r.on,a.on("in",r.on.in,a),a.on("out",r.on.out,a),i},r.on.out=function(e){var t,r,n=this.as,o=n.back,s=n.root;if(e.$||(e.$=n.$),this.to.next(e),!n.err){if(t=e.get){if(s.pass&&(s.pass[n.id]=n),n.lex&&Object.keys(n.lex).forEach((function(e){r[e]=n.lex[e]}),r=e.get=e.get||{}),t["#"]||n.soul){if(t["#"]=t["#"]||n.soul,e["#"]||(e["#"]=u(9)),o=s.$.get(t["#"])._,t=t["."]){if(f(o.put,t)&&(r=o.ask&&o.ask[t],(o.ask||(o.ask={}))[t]=o.$.get(t)._,o.on("in",{get:t,put:{"#":o.soul,".":t,":":o.put[t],">":p(s.graph[o.soul],t)}}),r))return}else{if(r=o.ask&&o.ask[""],(o.ask||(o.ask={}))[""]=o,a!==o.put&&(o.on("in",o),r))return;e.$=o.$}return s.ask(i,e),s.on("in",e)}if(t["."])return n.get?(e={get:{".":n.get},$:n.$},(o.ask||(o.ask={}))[n.get]=e.$._,o.on("out",e)):(e={get:n.lex?e.get:{},$:n.$},o.on("out",e));if((n.ask||(n.ask={}))[""]=n,n.get)return t["."]=n.get,(o.ask||(o.ask={}))[n.get]=e.$._,o.on("out",e)}return o.on("out",e)}n.on("in",{put:n.put=a,$:n.$})},r.on.in=function(e,t){var r,i=(t=t||this.as).root,u=e.$||(e.$=t.$),f=(u||"")._||s,l=e.put||"",h=l["#"],g=l["."],y=a!==l["="]?l["="]:l[":"],v=l[">"]||-1/0;if(a!==e.put&&(a===l["#"]||a===l["."]||a===l[":"]&&a===l["="]||a===l[">"]))return c(l)?void t.on("in",{$:f.back.$,put:{"#":h=f.back.soul,".":g=f.has||f.get,"=":l,">":p(f.back.put,g)},via:e}):(h=((l||"")._||"")["#"])?(u=t.root.$.get(h),setTimeout.each(Object.keys(l).sort(),(function(r){"_"!=r&&a!==(v=p(l,r))&&t.on("in",{$:u,put:{"#":h,".":r,"=":l[r],">":v},VIA:e})}))):void console.log("chain not yet supported for",l,"...",e,t);(e.seen||"")[t.id]||((e.seen||(e.seen=function(){}))[t.id]=t,t!==f&&(Object.keys(e).forEach((function(t){l[t]=e[t]}),l={}),l.get=t.get||l.get,t.soul||t.has?f.soul&&(l.$=t.$,l.$$=l.$$||f.$):l.$$$=l.$$$||t.$,e=l),o(e,t),(t.soul||e.$$)&&v>=p(i.graph[h],g)&&((l=i.$.get(h)._).put=d(l.put,g,v,y,h)),!f.soul&&v>=p(i.graph[h],g)&&(r=(i.$.get(h)._.next||"")[g])&&(r.put=y,"string"==typeof(l=c(y))&&(r.put=i.$.get(l)._.put||y)),this.to&&this.to.next(e),t.any&&setTimeout.each(Object.keys(t.any),(function(r){(r=t.any[r])&&r(e)}),0,99),t.echo&&setTimeout.each(Object.keys(t.echo),(function(r){(r=t.echo[r])&&r.on("in",e)}),0,99),((e.$$||"")._||f).soul&&(r=t.next)&&(r=r[g])&&(l={},Object.keys(e).forEach((function(t){l[t]=e[t]})),l.$=(e.$$||e.$).get(l.get=g),delete l.$$,delete l.$$$,r.on("in",l)),n(e,t))},r.on.link=n,r.on.unlink=o;var a,s={},u=String.random,c=r.valid,f=function(e,t){return e&&Object.prototype.hasOwnProperty.call(e,t)},l=r.state,p=l.is,d=l.ify}))(e,"./chain"),e((function(t){var r=e("./root");function n(e){var t=this.at||this.on;if(!e||t.soul||t.has)return this.off();if(e=(e=(e=e.$||e)._||e).id){var r;if(t.map,(r=this.seen||(this.seen={}))[e])return!0;r[e]=!0}}r.chain.get=function(e,t,s){var u,c;if("string"==typeof e){if(0==e.length)return(u=this.chain())._.err={err:r.log("0 length key!",e)},t&&t.call(u,u._.err),u;(u=((l=this._).next||i)[e])||(u=e&&function(e,t){var r=t._,n=r.next,o=t.chain(),i=o._;return n||(n=r.next={}),n[i.get=e]=i,t===r.root.$?i.soul=e:(r.soul||r.has)&&(i.has=e),i}(e,this)),u=u&&u.$}else{if("function"==typeof e){if(!0===t)return function(e,t,n,i){var a,s=e._,u=0;(a=s.soul||s.link)?t(a,i,s):s.jam?s.jam.push([t,i]):(s.jam=[[t,i]],e.get((function(e,t){if(!(o===e.put&&!s.root.opt.super&&(a=Object.keys(s.root.opt.peers).length)&&++u<=a)){t.rid(e);var n,i=(i=e.$)&&i._||{},c=0;for(a=s.jam,delete s.jam;n=a[c++];){var f=n[0];n=n[1],f&&f(i.link||i.soul||r.valid(e.put)||((e.put||{})._||{})["#"],n,e,t)}}}),{out:{get:{".":!0}}}))}(this,e,0,s),this;var f,l=(u=this)._,p=t||{},d=l.root;p.at=l,p.ok=e;var h={};function g(e,t,n){if(!g.stun&&(!(i=d.pass)||i[f])){var i,a=e.$._,s=(e.$$||"")._,u=(s||a).put,c=!a.has&&!a.soul,y={};if((c||o===u)&&(u=o===((i=e.put)||"")["="]?o===(i||"")[":"]?i:i[":"]:i["="]),"string"==typeof(i=r.valid(u))&&(u=o===(i=d.$.get(i)._.put)?p.not?o:u:i),!p.not||o!==u){if(o===p.stun){if((i=d.stun)&&i.on&&(l.$.back((function(e){if(i.on(""+e.id,y={}),(y.run||0)<g.id)return y})),!y.run&&i.on(""+a.id,y={}),!y.run&&s&&i.on(""+s.id,y={}),g.id>y.run&&(y.stun&&!y.stun.end||(y.stun=i.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(e,t,1)});if(o===u&&(n=0),(i=d.hatch)&&!i.end&&o===p.hatch&&!n){if(h[a.$._.id])return;return h[a.$._.id]=1,void i.push((function(){g(e,t,1)}))}h={}}if(d.pass){if(d.pass[f+a.id])return;d.pass[f+a.id]=1}p.on?p.ok.call(a.$,u,a.get,e,t||g):p.v2020?p.ok(e,t||g):(Object.keys(e).forEach((function(t){i[t]=e[t]}),i={}),(e=i).put=u,p.ok.call(p.as,e,t||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=n,g.id=p.run||++d.once,c=d.pass,(d.pass={})[f]=1,p.out=p.out||{get:{}},l.on("out",p.out),d.pass=c,u}if("number"==typeof e)return this.get(""+e,t,s);if("string"==typeof(c=a(e)))return this.get(c,t,s);(c=this.get.next)&&(u=c(this,e))}return u?(t&&"function"==typeof t&&u.get(t,s),u):((u=this.chain())._.err={err:r.log("Invalid get request!",e)},t&&t.call(u,u._.err),u)};var o,i={},a=r.valid}))(e,"./get"),e((function(t){var r=e("./root");function n(e,t){if(t){t=(t._||"").id||t;var n,o=e.root.stun||(e.root.stun={on:r.on}),i={};e.stun||(e.stun=o.on("stun",(function(){}))),(n=o.on(""+t))&&n.the.last.next(i),i.run>=e.run||o.on(""+t,(function(t){if(e.stun.end)return this.off(),void this.to.next(t);t.run=t.run||e.run,t.stun=t.stun||e.stun}))}}function o(e){if(e.err)o.end(e.stun,e.root);else if(!e.todo.length&&!e.end&&Object.empty(e.wait)){e.end=1;var t,n=e.$.back(-1)._,i=n.root,a=n.ask((function(t){i.on("ack",t),t.err&&r.log(t),++s>(e.acks||0)&&this.off(),e.ack&&e.ack(t,this)}),e.opt),s=0,u=e.stun;(t=function(){u&&(o.end(u,i),setTimeout.each(Object.keys(u=u.add||""),(function(e){(e=u[e])&&e()})))}).hatch=t,e.via._.on("out",{put:e.out=e.graph,opt:e.opt,"#":a,_:t})}}r.chain.put=function(e,t,f){var l=this,p=l._,d=p.root;(f=f||{}).root=p.root,f.run||(f.run=d.once),n(f,p.id),f.ack=f.ack||t,f.via=f.via||l,f.data=f.data||e,f.soul||(f.soul=p.soul||"string"==typeof t&&t);var h=f.state=f.state||r.state();return"function"==typeof e?(e((function(e){f.data=e,l.put(i,i,f)})),l):f.soul?(f.$=d.$.get(f.soul),f.todo=[{it:f.data,ref:f.$}],f.turn=f.turn||s,f.ran=f.ran||o,function e(){var t,o,i,s,l,p=f.todo,d=p.pop(),g=d.it;if(d.ref&&d.ref._.id,n(f,d.ref),(s=d.todo)&&(g=g[o=s.pop()],s.length&&p.push(d)),o&&(p.path||(p.path=[])).push(o),!(t=u(g))&&!(l=r.is(g))){if(!Object.plain(g))return(f.ack||a).call(f,f.out={err:f.err=r.log("Invalid data: "+(g&&(s=g.constructor)&&s.name||typeof g)+" at "+(f.via.back((function(e){e.get&&s.push(e.get)}),s=[])||s.join("."))+"."+(p.path||[]).join("."))}),void f.ran(f);for(var y=f.seen||(f.seen=[]),v=y.length;v--;)if(g===(s=y[v]).it){t=g=s.link;break}}if(o&&t)d.node=c(d.node,o,h,g);else{f.seen.push(i={it:g,link:{},todo:l?[]:Object.keys(g).sort().reverse(),path:(p.path||[]).slice(),up:d}),d.node=c(d.node,o,h,i.link),!l&&i.todo.length&&p.push(i);var w=f.seen.length;function b(e,t){var r=i.link["#"];t&&(t.off(),t.rid(e));var o=r||e.soul||(s=(e.$$||e.$)._||"").soul||s.link||((s=s.put||"")._||"")["#"]||s["#"]||((s=e.put||"")&&e.$$?s["#"]:(s["="]||s[":"]||"")["#"]);!r&&n(f,e.$),o||d.link["#"]?(o||(o=[],(e.$$||e.$).back((function(e){if(s=e.soul||e.link)return o.push(s);o.push(e.get)})),o=o.reverse().join("/")),i.link["#"]=o,!l&&(((f.graph||(f.graph={}))[o]=i.node||(i.node={_:{}}))._["#"]=o),delete f.wait[w],i.wait&&setTimeout.each(i.wait,(function(e){e&&e()})),f.ran(f)):(d.wait||(d.wait=[])).push((function(){b(e,t)}))}(f.wait||(f.wait={}))[w]="",s=(i.ref=l?g:o?d.ref.get(o):d.ref)._,(s=g&&(g._||"")["#"]||s.soul||s.link)?b({soul:s}):i.ref.get(b,{run:f.run,v2020:1,out:{get:{".":" "}}})}if(!p.length)return f.ran(f);f.turn(e)}(),l):(function(e){var t,r=e.via._;e.via=e.via.back((function(r){if(r.soul||!r.get)return r.$;t=e.data,(e.data={})[r.get]=t})),e.via&&e.via._.soul||(e.via=r.root.$.get(((e.data||"")._||"")["#"]||r.$.back("opt.uuid")())),e.via.put(e.data,e.ack,e)}(f),l)},o.end=function(e,t){e.end=a,e.the.to===e&&e===e.the.last&&delete t.stun,e.off()};var i,a=function(){},s=setTimeout.turn,u=r.valid,c=r.state.ify}))(e,"./put"),e((function(t){var r=e("./root");e("./chain"),e("./back"),e("./put"),e("./get"),t.exports=r}))(e,"./index"),e((function(t){var r,n=e("./index");n.chain.on=function(e,t,r,n){var o,i=this,a=i._;if(a.root,"string"==typeof e)return t?(o=a.on(e,t,r||a,n),r&&r.$&&(r.subs||(r.subs=[])).push(o),i):a.on(e);var s=t;return(s=!0===s?{change:!0}:s||{}).not=1,s.on=1,i.get(e,s),i},n.chain.once=function(e,t){if(t=t||{},!e)return function(e,t,r){return n.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."),(r=e.chain())._.nix=e.once((function(e,t){r._.on("in",this._)})),r._.lex=e._.lex,r}(this);var o=this,i=o._,a=i.root;i.put;var s,u=String.random(7);return o.get((function(o,c,f,l){var p=this,d=p._,h=d.one||(d.one={});function g(){d.has||d.soul||(d={put:o,get:c}),r===(s=d.put)&&(s=((f.$$||"")._||"").put),"string"==typeof n.valid(s)&&(s=a.$.get(s)._.put)===r||l.stun||""!==h[u]&&(h[u]="",(i.soul||i.has)&&l.off(),e.call(p,s,d.get))}l.stun||""!==h[u]&&(!0!==(s=n.valid(o))?"string"!=typeof s&&(clearTimeout((i.one||"")[u]),clearTimeout(h[u]),h[u]=setTimeout(g,t.wait||99)):g())}),{on:1}),o},n.chain.off=function(){var e,t=this._,r=t.back;if(r)return t.ack=0,(e=r.next)&&e[t.get]&&delete e[t.get],(e=r.ask)&&delete e[t.get],(e=r.put)&&delete e[t.get],(e=t.soul)&&delete r.root.graph[e],(e=t.map)&&Object.keys(e).forEach((function(t,n){(n=e[t]).link&&r.root.$.get(n.link).off()})),(e=t.next)&&Object.keys(e).forEach((function(t,r){e[t].$.off()})),t.on("off",{}),this}}))(e,"./on"),e((function(t){var r=e("./index"),n=r.chain.get.next;function o(e){this.to.next(e);var t,n=this.as,o=e.$._,i=e.put;(o.soul||e.$$)&&((t=n.lex)&&!String.match(e.get||(i||"")["."],t["."]||t["#"]||t)||r.on.link(e,n))}r.chain.get.next=function(e,t){var r;return Object.plain(t)?(r=((r=t["#"])||"")["="]||r)?e.get(r):((r=e.chain()._).lex=t,e.on("in",(function(e){String.match(e.get||(e.put||"")["."],t["."]||t["#"]||t)&&r.on("in",e),this.to.next(e)})),r.$):(n||a)(e,t)},r.chain.map=function(e,t,n){var s,u,c=this,f=c._;return Object.plain(e)&&(s=e["."]?e:{".":e},e=i),e?(r.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(t,n,o,s){var c=(e||a).call(this,t,n,o,s);if(i!==c){if(t===c)return u._.on("in",o);if(r.is(c))return u._.on("in",c._);var f={};Object.keys(o.put).forEach((function(e){f[e]=o.put[e]}),f),f["="]=c,u._.on("in",{get:n,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",o,u._)),u)};var i,a=function(){}}))(e,"./map"),e((function(t){var r=e("./index");r.chain.set=function(e,t,n){var o,i,a=this,s=a.back(-1);return t=t||function(){},(n=n||{}).item=n.item||e,(o=((e||"")._||"")["#"])&&((e={})["#"]=o),"string"==typeof(i=r.valid(e))?a.get(o=i).put(e,t,n):r.is(e)?(a.put((function(n){e.get((function(e,o,s){if(!e)return t.call(a,{err:r.log('Only a node can be linked! Not "'+s.put+'"!')});(i={})[e]={"#":e},n(i)}),!0)})),e):(Object.plain(e)&&(e=s.get(o=a.back("opt.uuid")()).put(e)),a.get(o||s.back("opt.uuid")(7)).put(e,t,n))}}))(e,"./set"),e((function(t){var r;e("./shim");try{t.exports=function(e){var t=function(){},n=e.opt||{};n.log=n.log||console.log,n.gap=n.gap||n.wait||0,n.max=n.max||.3*(n.memory?999*n.memory*999:3e8),n.pack=n.pack||.01*n.max*.01,n.puff=n.puff||9;var o=setTimeout.turn||setTimeout,i=JSON.parseAsync||function(e,t,r){try{t(void 0,JSON.parse(e,r))}catch(e){t(e)}},a=JSON.stringifyAsync||function(e,t,r,n){try{t(void 0,JSON.stringify(e,r,n))}catch(e){t(e)}},s=e.dup,u=s.check,c=s.track,f=t.hear=function(e,r){if(e){if(n.max<=e.length)return t.say({dam:"!",err:"Message too big!"},r);t===this&&(f.d+=e.length||0,++f.c);var a,s=r.SH=+new Date,u=e[0];return"["===u?(i(e,(function(e,i){if(e||!i)return t.say({dam:"!",err:"DAM JSON parse error."},r);console.STAT&&console.STAT(+new Date,i.length,"# on hear batch");var a=n.puff;!function e(){for(var t,n=+new Date,s=0;s<a&&(t=i[s++]);)f(t,r);i=i.slice(s),console.STAT&&console.STAT(n,+new Date-n,"hear loop"),l(r),i.length&&o(e,0)}()})),void(e="")):"{"===u||(e["#"]||Object.plain(e))&&(a=e)?a?f.one(a,r,s):void i(e,(function(e,n){if(e||!n)return t.say({dam:"!",err:"DAM JSON parse error."},r);f.one(n,r,s)})):void 0}};function l(e){var t=e.batch,r="string"==typeof t;if(r&&(t+="]"),e.batch=e.tail=null,t&&!(r?3>t.length:!t.length)){if(!r)try{t=1===t.length?t[0]:JSON.stringify(t)}catch(e){return n.log("DAM JSON stringify error",e)}t&&p(t,e)}}function p(e,r){try{var n=r.wire;r.say?r.say(e):n.send&&n.send(e),t.say.d+=e.length||0,++t.say.c}catch(t){(r.queue=r.queue||[]).push(e)}}f.one=function(r,n,o){var i,a,f,l,p;if(r.DBG&&(r.DBG=p={DBG:r.DBG}),p&&(p.h=o),p&&(p.hp=+new Date),(i=r["#"])||(i=r["#"]=String.random(9)),!((f=u(i))||(a=r["##"])&&(f=r["@"]||r.get&&i)&&s.check(l=f+a))){if((r._=function(){}).via=t.leap=n,(f=r["><"])&&"string"==typeof f&&f.slice(0,99).split(",").forEach((function(e){this[e]=1}),r._.yo={}),f=r.dam)return(f=t.hear[f])&&f(r,n,e),void c(i);o=+new Date,p&&(p.is=o),n.SI=i,e.on("in",t.last=r),p&&(p.hd=+new Date),console.STAT&&console.STAT(o,+new Date-o,r.get?"msg get":r.put?"msg put":"msg"),(f=c(i)).via=n,r.get&&(f.it=r),l&&c(l),t.leap=t.last=null}},f.c=f.d=0,function(){var e,i=0;function f(e,t){var r;return t instanceof Object?(Object.keys(t).sort().forEach(d,{to:r={},on:t}),r):t}function d(e){this.to[e]=this.on[e]}t.hash=function(e,t){var r,n,i,s=+new Date;a(e.put,(function a(u,c){var f=(n||(n=i=c||"")).slice(0,32768);r=String.hash(f,r),(n=n.slice(32768))?o(a,0):(console.STAT&&console.STAT(s,+new Date-s,"say json+hash"),e._.$put=i,e["##"]=r,h(e,t),delete e._.$put)}),f)};var h=t.say=function(a,u){var f;if((f=this)&&(f=f.to)&&f.next&&f.next(a),!a)return!1;var d,g,y=a["@"],v=a._||(a._=function(){}),w=a.DBG,b=+new Date;if(v.y=v.y||b,u||w&&(w.y=b),(d=a["#"])||(d=a["#"]=String.random(9)),!e&&c(d),a.put&&(a.err||(s.s[d]||"").err))return!1;if(a["##"]||r===a.put||v.via||!y){if(!u&&y&&(u=(f=s.s[y])&&(f.via||(f=f.it)&&(f=f._)&&f.via)||(f=t.last)&&y===f["#"]&&t.leap),!u&&y){if(s.s[y])return;return console.STAT&&console.STAT(+new Date,++i,"total no peer to ack to"),!1}if(!u&&t.way)return t.way(a);if(w&&(w.yh=+new Date),g=v.raw){if(w&&(w.yr=+new Date),!u||!u.id){if(!Object.plain(u||n.peers))return!1;b=+new Date,n.puff;var m=n.peers,k=Object.keys(u||n.peers||{});return console.STAT&&console.STAT(b,+new Date-b,"peer keys"),void function t(){var r=+new Date;e=1;var n=v.raw;v.raw=g;for(var i,s=0;s<9&&(i=(k||"")[s++]);)(i=m[i])&&h(a,i);v.raw=n,e=0,k=k.slice(s),console.STAT&&console.STAT(r,+new Date-r,"say loop"),k.length&&(o(t,0),y&&c(y))}()}if(!u.wire&&t.wire&&t.wire(u),d!==u.last){if(u.last=d,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,((w||v).yp=+new Date)-(v.y||b),"say prep"),!e&&y&&c(y),u.batch){if(u.tail=(f=u.tail||0)+g.length,u.tail<=n.pack)return void(u.batch+=(f?",":"")+g);l(u)}u.batch="[";var S=+new Date;setTimeout((function(){console.STAT&&console.STAT(S,+new Date-S,"0ms TO"),l(u)}),n.gap),p(g,u),console.STAT&&y===u.SI&&console.STAT(b,+new Date-u.SH,"say ack")}}else t.raw(a,u)}else t.hash(a,u)};t.say.c=t.say.d=0,t.raw=function(e,o){if(!e)return"";var i,c,f=e._||{};if(c=f.raw)return c;if("string"==typeof e)return e;var l=e["##"],p=e["@"];if(l&&p){if(!f.via&&u(p+l))return!1;if((c=(s.s[p]||"").it)||(c=t.last)&&p===c["#"]){if(l===c["##"])return!1;c["##"]||(c["##"]=l)}}if(!e.dam){var d=0,g=[];for(var y in c=n.peers){var v=c[y];if(g.push(v.url||v.pid||v.id),++d>6)break}d>1&&(e["><"]=g.join())}if(i=f.$put)return c={},Object.keys(e).forEach((function(t){c[t]=e[t]})),c.put=":])([:",void a(c,(function(e,t){if(!e){var n=+new Date;c=t.indexOf('"put":":])([:"'),w(r,t=t.slice(0,c+6)+i+t.slice(c+14)),console.STAT&&console.STAT(n,+new Date-n,"say slice")}}));function w(t,r){t||(f.raw=r,h(e,o))}a(e,w)}}(),t.hi=function(r){var o=r.wire||{};r.id?n.peers[r.url||r.id]=r:(o=r.id=r.id||String.random(9),t.say({dam:"?",pid:e.opt.pid},n.peers[o]=r),delete s.s[r.last]),r.met=r.met||+new Date,o.hied||e.on(o.hied="hi",r),o=r.queue,r.queue=[],setTimeout.each(o||[],(function(e){p(e,r)}),0,9)},t.bye=function(r){e.on("bye",r);var n=+new Date;n-=r.met||n,t.bye.time=((t.bye.time||n)+n)/2},t.hear["!"]=function(e,t){n.log("Error:",e.err)},t.hear["?"]=function(e,r){e.pid&&(r.pid||(r.pid=e.pid),e["@"])||(t.say({dam:"?",pid:n.pid,"@":e["#"]},r),delete s.s[r.last])},e.on("create",(function(e){e.opt.pid=e.opt.pid||String.random(9),this.to.next(e),e.on("out",t.say)})),e.on("bye",(function(e,t){e=n.peers[e.id||e]||e,this.to.next(e),e.bye?e.bye():(t=e.wire)&&t.close&&t.close(),delete n.peers[e.id],e.wire=null}));var d={};return e.on("bye",(function(e,t){this.to.next(e),(t=console.STAT)&&(t.peers=(t.peers||0)-1),(t=e.url)&&(d[t]=!0,setTimeout((function(){delete d[t]}),n.lack||9e3))})),e.on("hi",(function(r,o){this.to.next(r),(o=console.STAT)&&(o.peers=(o.peers||0)+1),(o=r.url)&&d[o]&&(delete d[o],n.super||setTimeout.each(Object.keys(e.next),(function(n){e.next[n],(o={})[n]=e.graph[n],o=String.hash(o),t.say({"##":o,get:{"#":n}},r)})))})),t}}catch(e){}}))(e,"./mesh"),e((function(t){var r=e("../index");r.Mesh=e("./mesh"),r.on("opt",(function(e){if(this.to.next(e),!e.once){var t=e.opt;if(!1!==t.WebSocket){var n=r.window||{},o=t.WebSocket||n.WebSocket||n.webkitWebSocket||n.mozWebSocket;if(o){t.WebSocket=o;var i=t.mesh=t.mesh||r.Mesh(e);i.wire||t.wire,i.wire=t.wire=u,setTimeout((function(){!t.super&&e.on("out",{dam:"hi"})}),1);var a=1998,s=""+void 0!=typeof document&&document}}}function u(e){try{if(!e||!e.url)return n&&n(e);var r=e.url.replace(/^http/,"ws"),n=e.wire=new t.WebSocket(r);return n.onclose=function(){t.mesh.bye(e),c(e)},n.onerror=function(t){c(e)},n.onopen=function(){t.mesh.hi(e)},n.onmessage=function(r){r&&t.mesh.hear(r.data||r,e)},n}catch(e){}}function c(e){clearTimeout(e.defer),s&&e.retry<=0||(e.retry=(e.retry||t.retry+1||60)-(-e.tried+(e.tried=+new Date)<4*a?1:0),e.defer=setTimeout((function t(){if(s&&s.hidden)return setTimeout(t,a);u(e)}),a))}}))}))(e,"./websocket"),e((function(e){if("undefined"!=typeof Gun){var t;try{t=(Gun.window||function(){}).localStorage}catch(e){}t||(Gun.log("Warning: No localStorage exists to persist data to!"),t={setItem:function(e,t){this[e]=t},removeItem:function(e){delete this[e]},getItem:function(e){return this[e]}}),Gun.on("create",(function e(r){this.to.next(r);var n=r.opt;r.graph;var o,i,a=[];if(!1!==n.localStorage){n.prefix=n.file||"gun/";try{o=e[n.prefix]=e[n.prefix]||JSON.parse(t.getItem(n.prefix))||{}}catch(t){o=e[n.prefix]={}}r.on("get",(function(e){this.to.next(e);var t,r,n,i=e.get;i&&(t=i["#"])&&((r=o[t]||void 0)&&(n=i["."])&&!Object.plain(n)&&(r=Gun.state.ify({},n,Gun.state.is(r,n),r[n],t)),Gun.on.get.ack(e,r))})),r.on("put",(function(e){this.to.next(e);var t=e.put,r=t["#"],u=t["."];o[r]=Gun.state.ify(o[r],u,t[">"],t[":"],r),e["@"]||a.push(e["#"]),i||(i=setTimeout(s,n.wait||1))}))}function s(){var e,s=a;clearTimeout(i),i=!1,a=[];try{t.setItem(n.prefix,JSON.stringify(o))}catch(t){Gun.log((e=t||"localStorage failure")+" Consider using GUN's IndexedDB plugin for RAD for more storage space, https://gun.eco/docs/RAD#install"),r.on("localStorage:error",{err:e,get:n.prefix,put:o})}(e||Object.empty(n.peers))&&setTimeout.each(s,(function(t){r.on("in",{"@":t,err:e,ok:0})}))}}))}}))(e,"./localStorage")}(),function(){if(""+S!=typeof Gun){var e=function(e){console.log("Warning! Deprecated internal utility will break in next version:",e)},t=Gun;t.fn=t.fn||{is:function(t){return e("fn"),!!t&&"function"==typeof t}},t.bi=t.bi||{is:function(t){return e("bi"),t instanceof Boolean||"boolean"==typeof t}},t.num=t.num||{is:function(t){return e("num"),!n(t)&&(t-parseFloat(t)+1>=0||1/0===t||-1/0===t)}},t.text=t.text||{is:function(t){return e("text"),"string"==typeof t}},t.text.ify=t.text.ify||function(r){return e("text.ify"),t.text.is(r)?r:"undefined"!=typeof JSON?JSON.stringify(r):r&&r.toString?r.toString():r},t.text.random=t.text.random||function(t,r){e("text.random");var n="";for(t=t||24,r=r||"0123456789ABCDEFGHIJKLMNOPQRSTUVWXZabcdefghijklmnopqrstuvwxyz";t>0;)n+=r.charAt(Math.floor(Math.random()*r.length)),t--;return n},t.text.match=t.text.match||function(t,r){var n,o;return e("text.match"),"string"==typeof t&&("string"==typeof r&&(r={"=":r}),t===(n=(r=r||{})["="]||r["*"]||r[">"]||r["<"])||o===r["="]&&(n=r["*"]||r[">"]||r["<"],t.slice(0,(n||"").length)===n||o===r["*"]&&(o!==r[">"]&&o!==r["<"]?t>=r[">"]&&t<=r["<"]:o!==r[">"]&&t>=r[">"]||o!==r["<"]&&t<=r["<"])))},t.text.hash=t.text.hash||function(t,r){if(e("text.hash"),"string"==typeof t){if(r=r||0,!t.length)return r;for(var n=0,o=t.length;n<o;++n)r=(r<<5)-r+t.charCodeAt(n),r|=0;return r}},t.list=t.list||{is:function(t){return e("list"),t instanceof Array}},t.list.slit=t.list.slit||Array.prototype.slice,t.list.sort=t.list.sort||function(t){return e("list.sort"),function(e,r){return e&&r?(e=e[t])<(r=r[t])?-1:e>r?1:0:0}},t.list.map=t.list.map||function(t,r,n){return e("list.map"),a(t,r,n)},t.list.index=1,t.obj=t.boj||{is:function(t){return e("obj"),!!t&&(t instanceof Object&&t.constructor===Object||"Object"===Object.prototype.toString.call(t).match(/^\[object (\w+)\]$/)[1])}},t.obj.put=t.obj.put||function(t,r,n){return e("obj.put"),(t||{})[r]=n,t},t.obj.has=t.obj.has||function(t,r){return e("obj.has"),t&&Object.prototype.hasOwnProperty.call(t,r)},t.obj.del=t.obj.del||function(t,r){if(e("obj.del"),t)return t[r]=null,delete t[r],t},t.obj.as=t.obj.as||function(t,r,n,o){return e("obj.as"),t[r]=t[r]||(o===n?{}:n)},t.obj.ify=t.obj.ify||function(t){if(e("obj.ify"),o(t))return t;try{t=JSON.parse(t)}catch(e){t={}}return t},function(){function r(e,t){i(this,t)&&void 0!==this[t]||(this[t]=e)}t.obj.to=t.obj.to||function(t,n){return e("obj.to"),a(t,r,n=n||{}),n}}(),t.obj.copy=t.obj.copy||function(t){return e("obj.copy"),t?JSON.parse(JSON.stringify(t)):t},function(){function r(e,t){var r=this.n;if(!r||!(t===r||o(r)&&i(r,t)))return void 0!==t||void 0}t.obj.empty=t.obj.empty||function(t,n){return e("obj.empty"),!t||!a(t,r,{n:n})}}(),function(){function r(e,t){if(2===arguments.length)return r.r=r.r||{},void(r.r[e]=t);r.r=r.r||[],r.r.push(e)}var a,s=Object.keys;Object.keys=Object.keys||function(e){return a(e,(function(e,t,r){r(t)}))},t.obj.map=a=t.obj.map||function(a,u,c){e("obj.map");var f,l,p,d,h,g=0,y="function"==typeof u;if(r.r=f,s&&o(a)&&(d=s(a),h=!0),c=c||{},n(a)||d)for(l=(d||a).length;g<l;g++){var v=g+t.list.index;if(y){if((p=h?u.call(c,a[d[g]],d[g],r):u.call(c,a[g],v,r))!==f)return p}else if(u===a[h?d[g]:g])return d?d[g]:v}else for(g in a)if(y){if(i(a,g)&&(p=c?u.call(c,a[g],g,r):u(a[g],g,r))!==f)return p}else if(u===a[g])return g;return y?r.r:t.list.index?0:-1}}(),t.time=t.time||{},t.time.is=t.time.is||function(t){return e("time"),t?t instanceof Date:+(new Date).getTime()};var r=t.fn.is,n=t.list.is,o=(k=t.obj).is,i=k.has,a=k.map,s={is:function(t){return e("val.is"),t!==S&&(null===t||t!==1/0&&(!!(l(t)||c(t)||f(t))||s.link.is(t)||!1))}};s.link=s.rel={_:"#"},function(){function t(e,t){var r=this;return r.id?r.id=!1:t==u&&l(e)?void(r.id=e):r.id=!1}s.link.is=function(r){if(e("val.link.is"),r&&r[u]&&!r._&&o(r)){var n={};if(a(r,t,n),n.id)return n.id}return!1}}(),s.link.ify=function(t){return e("val.link.ify"),p({},u,t)},t.obj.has._=".";var u=s.link._,c=t.bi.is,f=t.num.is,l=t.text.is,p=(o=(k=t.obj).is,k.put);a=k.map,t.val=t.val||s;var d={_:"_",soul:function(t,r){return e("node.soul"),t&&t._&&t._[r||y]}};d.soul.ify=function(t,r){return e("node.soul.ify"),r="string"==typeof r?{soul:r}:r||{},(t=t||{})._=t._||{},t._[y]=r.soul||t._[y]||g(),t},d.soul._=s.link._,function(){function t(e,t){if(t!==d._)return!s.is(e)||void(this.cb&&this.cb.call(this.as,e,t,this.n,this.s))}d.is=function(r,n,i){var s;return e("node.is"),!!o(r)&&!!(s=d.soul(r))&&!a(r,t,{as:i,cb:n,s:s,n:r})}}(),function(){function t(e,t){var r,n=this.o;n.map?void 0===(r=n.map.call(this.as,e,""+t,n.node))?h(n.node,t):n.node&&(n.node[t]=r):s.is(e)&&(n.node[t]=e)}d.ify=function(r,n,o){return e("node.ify"),n?"string"==typeof n?n={soul:n}:"function"==typeof n&&(n={map:n}):n={},n.map&&(n.node=n.map.call(o,r,S,n.node||{})),(n.node=d.soul.ify(n.node||{},n))&&a(r,t,{o:n,as:o}),n.node}}(),o=(k=t.obj).is;var h=k.del,g=(a=k.map,t.text.random),y=d.soul._;t.node=t.node||d;var v=t.state;v.lex=function(){return e("state.lex"),v().toString(36).replace(".","")},v.to=function(t,r,n){e("state.to");var i=(t||{})[r];return o(i)&&(i=w(i)),v.ify(n,r,v.is(t,r),i,d.soul(t))},function(){function t(e,t){b!==t&&v.ify(this.o,t,this.s)}v.map=function(n,s,u){var c;e("state.map");var l=o(l=n||s)?l:null;return n=r(n=n||s)?n:null,l&&!n?(s=f(s)?s:v(),l[b]=l[b]||{},a(l,t,{o:l,s:s}),l):(u=u||o(s)?s:c,s=f(s)?s:v(),function(e,r,o,a){if(!n)return t.call({o:o,s:s},e,r),e;n.call(u||this||{},e,r,o,a),i(o,r)&&c===o[r]||t.call({o:o,s:s},e,r)})}}(),(k=t.obj).as,i=k.has,o=k.is,a=k.map;var w=k.copy,b=(f=t.num.is,r=t.fn.is,d._),m={};!function(){function t(e,t){if(!e||t!==d.soul(e)||!d.is(e,this.fn,this.as))return!0;this.cb&&(r.n=e,r.as=this.as,this.cb.call(r.as,e,t,r))}function r(e){e&&d.is(r.n,e,r.as)}m.is=function(r,n,i,s){return e("graph.is"),!(!r||!o(r)||x(r)||a(r,t,{cb:n,fn:i,as:s}))}}(),function(){function r(e,t){var r;return(r=function(e,t){for(var r,n=e.seen,o=n.length;o--;)if(r=n[o],t.obj===r.obj)return r;n.push(t)}(e,t))?r:(t.env=e,t.soul=a,d.ify(t.obj,n,t)&&(t.link=t.link||s.link.ify(d.soul(t.node)),t.obj!==e.shell&&(e.graph[s.link.is(t.link)]=t.node)),t)}function n(e,t,n){var o,a,c=this,f=c.env;if(d._===t&&i(e,s.link._))return n._;if(o=u(e,t,n,c,f)){if(t||(c.node=c.node||n||{},i(e,d._)&&d.soul(e)&&(c.node._=w(e._)),c.node=d.soul.ify(c.node,s.link.is(c.link)),c.link=c.link||s.link.ify(d.soul(c.node))),(a=f.map)&&(a.call(f.as||{},e,t,n,c),i(n,t))){if(e=n[t],S===e)return void h(n,t);if(!(o=u(e,t,n,c,f)))return}if(!t)return c.node;if(!0===o)return e;if((a=r(f,{obj:e,path:c.path.concat(t)})).node)return a.link}}function a(e){var t=this,r=s.link.is(t.link),n=t.env.graph;t.link=t.link||s.link.ify(e),t.link[s.link._]=e,t.node&&t.node[d._]&&(t.node[d._][s.link._]=e),i(n,r)&&(n[e]=n[r],h(n,r))}function u(e,r,n,i,a){var c;return!!s.is(e)||(o(e)?1:(c=a.invalid)?u(e=c.call(a.as||{},e,r,n),r,n,i,a):(a.err="Invalid value at '"+i.path.concat(r).join(".")+"'!",void(t.list.is(e)&&(a.err+=" Use `.set(item)` instead of an Array."))))}m.ify=function(t,n,o){e("graph.ify");var i={path:[],obj:t};return n?"string"==typeof n?n={soul:n}:"function"==typeof n&&(n.map=n):n={},"string"==typeof o&&(n.soul=n.soul||o,o=S),n.soul&&(i.link=s.link.ify(n.soul)),n.shell=(o||{}).shell,n.graph=n.graph||{},n.seen=n.seen||[],n.as=n.as||o,r(n,i),n.root=i.node,n.graph}}(),m.node=function(t){e("graph.node");var r=d.soul(t);if(r)return p({},r,t)},function(){function t(e,t){var r,n;if(d._!==t)(r=s.link.is(e))?(n=this.opt.seen[r])?this.obj[t]=n:this.obj[t]=this.opt.seen[r]=m.to(this.graph,r,this.opt):this.obj[t]=e;else{if(x(e,s.link._))return;this.obj[t]=w(e)}}m.to=function(r,n,o){if(e("graph.to"),r){var i={};return o=o||{seen:{}},a(r[n],t,{obj:i,graph:r,opt:o}),i}}}(),r=t.fn.is,o=(k=t.obj).is,h=k.del,i=k.has;var k,S,x=k.empty;p=k.put,a=k.map,w=k.copy,t.graph=t.graph||m}}();var a=i.exports;!function(e){!function(){function t(e,r){return r?n(e):e.slice?t[o(e)]:function(r,n){e(r={exports:{}}),t[o(n)]=r.exports};function o(e){return e.split("/").slice(-1).toString().replace(".js","")}}var o=e;t((function(e){"undefined"!=typeof window&&(e.window=window);var t=(e.window||e).SEA||{};(t.window=e.window)&&(t.window.SEA=t);try{undefined+""!=typeof o&&(o.exports=t)}catch(e){}e.exports=t}))(t,"./root"),t((function(e){var r=t("./root");try{r.window&&location.protocol.indexOf("s")<0&&location.host.indexOf("localhost")<0&&!/^127\.\d+\.\d+\.\d+$/.test(location.hostname)&&location.protocol.indexOf("file:")<0&&(console.warn("HTTPS needed for WebCrypto in SEA, redirecting..."),location.protocol="https:")}catch(e){}}))(t,"./https"),t((function(e){var n;if(n+""==typeof btoa){if(n+""==typeof Buffer)try{r.Buffer=t("buffer",1).Buffer}catch(e){console.log("Please `npm install buffer` or add it to your package.json !")}r.btoa=function(e){return Buffer.from(e,"binary").toString("base64")},r.atob=function(e){return Buffer.from(e,"base64").toString("binary")}}}))(t,"./base64"),t((function(e){function r(){}t("./base64"),Object.assign(r,{from:Array.from}),r.prototype=Object.create(Array.prototype),r.prototype.toString=function(e,t,r){e=e||"utf8",t=t||0;const n=this.length;if("hex"===e){const e=new Uint8Array(this);return[...Array((r&&r+1||n)-t).keys()].map((r=>e[r+t].toString(16).padStart(2,"0"))).join("")}return"utf8"===e?Array.from({length:(r||n)-t},((e,r)=>String.fromCharCode(this[r+t]))).join(""):"base64"===e?btoa(this):void 0},e.exports=r}))(t,"./array"),t((function(e){t("./base64");var r=t("./array");function n(...e){return console.warn("new SafeBuffer() is depreciated, please use SafeBuffer.from()"),n.from(...e)}n.prototype=Object.create(Array.prototype),Object.assign(n,{from(){if(!Object.keys(arguments).length||null==arguments[0])throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.");const e=arguments[0];let t;if("string"==typeof e){const n=arguments[1]||"utf8";if("hex"===n){const n=e.match(/([\da-fA-F]{2})/g).map((e=>parseInt(e,16)));if(!n||!n.length)throw new TypeError("Invalid first argument for type 'hex'.");t=r.from(n)}else if("utf8"===n||"binary"===n){const n=e.length,o=new Uint16Array(n);Array.from({length:n},((t,r)=>o[r]=e.charCodeAt(r))),t=r.from(o)}else if("base64"===n){const n=atob(e),o=n.length,i=new Uint8Array(o);Array.from({length:o},((e,t)=>i[t]=n.charCodeAt(t))),t=r.from(i)}else"binary"===n?t=r.from(e):console.info("SafeBuffer.from unknown encoding: "+n);return t}e.byteLength;if(e.byteLength?e.byteLength:e.length){let t;return e instanceof ArrayBuffer&&(t=new Uint8Array(e)),r.from(t||e)}},alloc:(e,t=0)=>r.from(new Uint8Array(Array.from({length:e},(()=>t)))),allocUnsafe:e=>r.from(new Uint8Array(Array.from({length:e}))),concat(e){if(!Array.isArray(e))throw new TypeError("First argument must be Array containing ArrayBuffer or Uint8Array instances.");return r.from(e.reduce(((e,t)=>e.concat(Array.from(t))),[]))}}),n.prototype.from=n.from,n.prototype.toString=r.prototype.toString,e.exports=n}))(t,"./buffer"),t((function(e){const r=t("./root"),n={Buffer:t("./buffer")};var i={};if(JSON.parseAsync=JSON.parseAsync||function(e,t,r){try{t(undefined,JSON.parse(e,r))}catch(e){t(e)}},JSON.stringifyAsync=JSON.stringifyAsync||function(e,t,r,n){try{t(undefined,JSON.stringify(e,r,n))}catch(e){t(e)}},n.parse=function(e,t){return new Promise((function(r,n){JSON.parseAsync(e,(function(e,t){e?n(e):r(t)}),t)}))},n.stringify=function(e,t,r){return new Promise((function(n,o){JSON.stringifyAsync(e,(function(e,t){e?o(e):n(t)}),t,r)}))},r.window&&(n.crypto=window.crypto||window.msCrypto,n.subtle=(n.crypto||i).subtle||(n.crypto||i).webkitSubtle,n.TextEncoder=window.TextEncoder,n.TextDecoder=window.TextDecoder,n.random=e=>n.Buffer.from(n.crypto.getRandomValues(new Uint8Array(n.Buffer.alloc(e))))),!n.TextDecoder){const{TextEncoder:e,TextDecoder:r}=t((undefined+""==typeof o?".":"")+"./lib/text-encoding",1);n.TextDecoder=r,n.TextEncoder=e}if(!n.crypto)try{var a=t("crypto",1);Object.assign(n,{crypto:a,random:e=>n.Buffer.from(a.randomBytes(e))});const{Crypto:e}=t("@peculiar/webcrypto",1);n.ossl=n.subtle=new e({directory:"ossl"}).subtle}catch(e){console.log("Please `npm install @peculiar/webcrypto` or add it to your package.json !")}e.exports=n}))(t,"./shim"),t((function(e){var r=t("./root"),n=t("./shim"),o={pbkdf2:{hash:{name:"SHA-256"},iter:1e5,ks:64},ecdsa:{pair:{name:"ECDSA",namedCurve:"P-256"},sign:{name:"ECDSA",hash:{name:"SHA-256"}}},ecdh:{name:"ECDH",namedCurve:"P-256"},jwk:function(e,t){var r={kty:"EC",crv:"P-256",x:(e=e.split("."))[0],y:e[1],ext:!0};return r.key_ops=t?["sign"]:["verify"],t&&(r.d=t),r},keyToJwk:function(e){return{kty:"oct",k:e.toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,""),ext:!1,alg:"A256GCM"}},recall:{validity:43200,hook:function(e){return e}},check:function(e){return"string"==typeof e&&"SEA{"===e.slice(0,4)},parse:async function(e){try{var t="string"==typeof e;return t&&"SEA{"===e.slice(0,4)&&(e=e.slice(3)),t?await n.parse(e):e}catch(e){}return e}};r.opt=o,e.exports=o}))(t,"./settings"),t((function(e){var r=t("./shim");e.exports=async function(e,t){var n="string"==typeof e?e:await r.stringify(e),o=await r.subtle.digest({name:t||"SHA-256"},(new r.TextEncoder).encode(n));return r.Buffer.from(o)}}))(t,"./sha256"),t((function(e){const r=t("./shim"),n=r.subtle,o=r.ossl?r.ossl:n;e.exports=e=>o.digest({name:"SHA-1"},new ArrayBuffer(e))}))(t,"./sha1"),t((function(e){var r=t("./root"),n=t("./shim"),o=t("./settings"),i=t("./sha256");r.work=r.work||(async(e,t,a,s)=>{try{var u=(t||{}).epub||t;if(s=s||{},u instanceof Function&&(a=u,u=undefined),e="string"==typeof e?e:await n.stringify(e),"sha"===(s.name||"").toLowerCase().slice(0,3)){var c=n.Buffer.from(await i(e,s.name),"binary").toString(s.encode||"base64");if(a)try{a(c)}catch(e){console.log(e)}return c}u=u||n.random(9);var f=await(n.ossl||n.subtle).importKey("raw",(new n.TextEncoder).encode(e),{name:s.name||"PBKDF2"},!1,["deriveBits"]),l=await(n.ossl||n.subtle).deriveBits({name:s.name||"PBKDF2",iterations:s.iterations||o.pbkdf2.iter,salt:(new n.TextEncoder).encode(s.salt||u),hash:s.hash||o.pbkdf2.hash},f,s.length||8*o.pbkdf2.ks);e=n.random(e.length);var p=n.Buffer.from(l,"binary").toString(s.encode||"base64");if(a)try{a(p)}catch(e){console.log(e)}return p}catch(e){if(console.log(e),r.err=e,r.throw)throw e;return void(a&&a())}}),e.exports=r.work}))(t,"./work"),t((function(e){var r=t("./root"),n=t("./shim");t("./settings"),r.name=r.name||(async(e,t)=>{try{if(e)try{e()}catch(e){console.log(e)}return}catch(t){if(console.log(t),r.err=t,r.throw)throw t;return void(e&&e())}}),r.pair=r.pair||(async(e,t)=>{try{var o=n.ossl||n.subtle,i=await n.subtle.generateKey({name:"ECDSA",namedCurve:"P-256"},!0,["sign","verify"]).then((async e=>{var t={};t.priv=(await n.subtle.exportKey("jwk",e.privateKey)).d;var r=await n.subtle.exportKey("jwk",e.publicKey);return t.pub=r.x+"."+r.y,t}));try{var a=await o.generateKey({name:"ECDH",namedCurve:"P-256"},!0,["deriveKey"]).then((async e=>{var t={};t.epriv=(await o.exportKey("jwk",e.privateKey)).d;var r=await o.exportKey("jwk",e.publicKey);return t.epub=r.x+"."+r.y,t}))}catch(e){if(r.window)throw e;if("Error: ECDH is not a supported algorithm"!=e)throw e;console.log("Ignoring ECDH...")}a=a||{};var s={pub:i.pub,priv:i.priv,epub:a.epub,epriv:a.epriv};if(e)try{e(s)}catch(e){console.log(e)}return s}catch(t){if(console.log(t),r.err=t,r.throw)throw t;return void(e&&e())}}),e.exports=r.pair}))(t,"./pair"),t((function(e){var r,n=t("./root"),o=t("./shim"),i=t("./settings"),a=t("./sha256");n.sign=n.sign||(async(e,t,s,u)=>{try{if(u=u||{},!(t||u).priv){if(!n.I)throw"No signing key.";t=await n.I(null,{what:e,how:"sign",why:u.why})}if(r===e)throw"`undefined` not allowed.";var c=await i.parse(e),f=u.check=u.check||c;if(n.verify&&(n.opt.check(f)||f&&f.s&&f.m)&&r!==await n.verify(f,t)){var l=await i.parse(f);if(u.raw||(l="SEA"+await o.stringify(l)),s)try{s(l)}catch(e){console.log(e)}return l}var p=t.pub,d=t.priv,h=i.jwk(p,d),g=await a(c),y=await(o.ossl||o.subtle).importKey("jwk",h,{name:"ECDSA",namedCurve:"P-256"},!1,["sign"]).then((e=>(o.ossl||o.subtle).sign({name:"ECDSA",hash:{name:"SHA-256"}},e,new Uint8Array(g))));l={m:c,s:o.Buffer.from(y,"binary").toString(u.encode||"base64")};if(u.raw||(l="SEA"+await o.stringify(l)),s)try{s(l)}catch(e){console.log(e)}return l}catch(e){if(console.log(e),n.err=e,n.throw)throw e;return void(s&&s())}}),e.exports=n.sign}))(t,"./sign"),t((function(e){var r,n=t("./root"),o=t("./shim"),i=t("./settings"),a=t("./sha256");n.verify=n.verify||(async(e,t,s,u)=>{try{var c=await i.parse(e);if(!1===t){var f=await i.parse(c.m);if(s)try{s(f)}catch(e){console.log(e)}return f}u=u||{};var l,p,d,h=t.pub||t,g=n.opt.slow_leak?await n.opt.slow_leak(h):await(o.ossl||o.subtle).importKey("jwk",i.jwk(h),{name:"ECDSA",namedCurve:"P-256"},!1,["verify"]),y=await a(c.m);try{if(l=o.Buffer.from(c.s,u.encode||"base64"),p=new Uint8Array(l),!(d=await(o.ossl||o.subtle).verify({name:"ECDSA",hash:{name:"SHA-256"}},g,p,new Uint8Array(y))))throw"Signature did not match."}catch(r){if(n.opt.fallback)return await n.opt.fall_verify(e,t,s,u)}var v=d?await i.parse(c.m):r;if(s)try{s(v)}catch(e){console.log(e)}return v}catch(e){if(console.log(e),n.err=e,n.throw)throw e;return void(s&&s())}}),e.exports=n.verify;var s={};n.opt.slow_leak=e=>{if(s[e])return s[e];var t=i.jwk(e);return s[e]=(o.ossl||o.subtle).importKey("jwk",t,{name:"ECDSA",namedCurve:"P-256"},!1,["verify"]),s[e]};var u=n.opt;n.opt.fall_verify=async function(e,t,s,c,f){if(f===n.opt.fallback)throw"Signature did not match";f=f||1;var l=e||"";e=n.opt.unpack(e)||e;var p,d,h,g=await i.parse(e),y=t.pub||t,v=await n.opt.slow_leak(y),w=f<=n.opt.fallback?o.Buffer.from(await o.subtle.digest({name:"SHA-256"},(new o.TextEncoder).encode(await i.parse(g.m)))):await a(g.m);try{if(p=o.Buffer.from(g.s,c.encode||"base64"),d=new Uint8Array(p),!(h=await(o.ossl||o.subtle).verify({name:"ECDSA",hash:{name:"SHA-256"}},v,d,new Uint8Array(w))))throw"Signature did not match."}catch(e){try{p=o.Buffer.from(g.s,"utf8"),d=new Uint8Array(p),h=await(o.ossl||o.subtle).verify({name:"ECDSA",hash:{name:"SHA-256"}},v,d,new Uint8Array(w))}catch(e){if(!h)throw"Signature did not match."}}var b=h?await i.parse(g.m):r;if(u.fall_soul=l["#"],u.fall_key=l["."],u.fall_val=e,u.fall_state=l[">"],s)try{s(b)}catch(e){console.log(e)}return b},n.opt.fallback=2}))(t,"./verify"),t((function(e){var r=t("./shim"),n=t("./settings"),o=t("./sha256");e.exports=async(e,t,i)=>{const a=e+(t||r.random(8)).toString("utf8"),s=r.Buffer.from(await o(a),"binary"),u=n.keyToJwk(s);return await r.subtle.importKey("jwk",u,{name:"AES-GCM"},!1,["encrypt","decrypt"])}}))(t,"./aeskey"),t((function(e){var r=t("./root"),n=t("./shim");t("./settings");var o=t("./aeskey");r.encrypt=r.encrypt||(async(e,t,i,a)=>{try{a=a||{};var s=(t||a).epriv||t;if(undefined===e)throw"`undefined` not allowed.";if(!s){if(!r.I)throw"No encryption key.";s=(t=await r.I(null,{what:e,how:"encrypt",why:a.why})).epriv||t}var u="string"==typeof e?e:await n.stringify(e),c={s:n.random(9),iv:n.random(15)},f=await o(s,c.s,a).then((e=>n.subtle.encrypt({name:a.name||"AES-GCM",iv:new Uint8Array(c.iv)},e,(new n.TextEncoder).encode(u)))),l={ct:n.Buffer.from(f,"binary").toString(a.encode||"base64"),iv:c.iv.toString(a.encode||"base64"),s:c.s.toString(a.encode||"base64")};if(a.raw||(l="SEA"+await n.stringify(l)),i)try{i(l)}catch(e){console.log(e)}return l}catch(e){if(console.log(e),r.err=e,r.throw)throw e;return void(i&&i())}}),e.exports=r.encrypt}))(t,"./encrypt"),t((function(e){var r=t("./root"),n=t("./shim"),o=t("./settings"),i=t("./aeskey");r.decrypt=r.decrypt||(async(e,t,a,s)=>{try{s=s||{};var u=(t||s).epriv||t;if(!u){if(!r.I)throw"No decryption key.";u=(t=await r.I(null,{what:e,how:"decrypt",why:s.why})).epriv||t}var c,f,l,p=await o.parse(e);try{c=n.Buffer.from(p.s,s.encode||"base64"),f=n.Buffer.from(p.iv,s.encode||"base64"),l=n.Buffer.from(p.ct,s.encode||"base64");var d=await i(u,c,s).then((e=>n.subtle.decrypt({name:s.name||"AES-GCM",iv:new Uint8Array(f),tagLength:128},e,new Uint8Array(l))))}catch(n){if("utf8"===s.encode)throw"Could not decrypt";if(r.opt.fallback)return s.encode="utf8",await r.decrypt(e,t,a,s)}var h=await o.parse(new n.TextDecoder("utf8").decode(d));if(a)try{a(h)}catch(e){console.log(e)}return h}catch(e){if(console.log(e),r.err=e,r.throw)throw e;return void(a&&a())}}),e.exports=r.decrypt}))(t,"./decrypt"),t((function(e){var r=t("./root"),n=t("./shim");t("./settings"),r.secret=r.secret||(async(e,t,i,a)=>{try{if(a=a||{},!t||!t.epriv||!t.epub){if(!r.I)throw"No secret mix.";t=await r.I(null,{what:e,how:"secret",why:a.why})}var s=e.epub||e,u=t.epub,c=t.epriv,f=n.ossl||n.subtle,l=o(s),p=Object.assign({public:await f.importKey(...l,!0,[])},{name:"ECDH",namedCurve:"P-256"}),d=o(u,c),h=await f.importKey(...d,!1,["deriveBits"]).then((async e=>{var t=await f.deriveBits(p,e,256),r=new Uint8Array(t),n=await f.importKey("raw",r,{name:"AES-GCM",length:256},!0,["encrypt","decrypt"]);return f.exportKey("jwk",n).then((({k:e})=>e))}));if(i)try{i(h)}catch(e){console.log(e)}return h}catch(e){if(console.log(e),r.err=e,r.throw)throw e;return void(i&&i())}});var o=(e,t)=>{var[r,n]=e.split("."),o=t?{d:t}:{};return["jwk",Object.assign(o,{x:r,y:n,kty:"EC",crv:"P-256",ext:!0}),{name:"ECDH",namedCurve:"P-256"}]};e.exports=r.secret}))(t,"./secret"),t((function(e){var r=t("./root");r.certify=r.certify||(async(e,t={},n,o,i={})=>{try{if(console.log("SEA.certify() is an early experimental community supported method that may change API behavior without warning in any future version."),e=(()=>{var t=[];if(e){if(("string"==typeof e||Array.isArray(e))&&e.indexOf("*")>-1)return"*";if("string"==typeof e)return e;if(Array.isArray(e)){if(1===e.length&&e[0])return"object"==typeof e[0]&&e[0].pub?e[0].pub:"string"==typeof e[0]?e[0]:null;e.map((e=>{"string"==typeof e?t.push(e):"object"==typeof e&&e.pub&&t.push(e.pub)}))}return"object"==typeof e&&e.pub?e.pub:t.length>0?t:null}})(),!e)return console.log("No certificant found.");const s=!i.expiry||"number"!=typeof i.expiry&&"string"!=typeof i.expiry?null:parseFloat(i.expiry),u=(t||{}).read?t.read:null,c=(t||{}).write?t.write:"string"==typeof t||Array.isArray(t)||t["+"]||t["#"]||t["."]||t["="]||t["*"]||t[">"]||t["<"]?t:null,f=(i||{}).block||(i||{}).blacklist||(i||{}).ban||{},l=f.read&&("string"==typeof f.read||(f.read||{})["#"])?f.read:null,p="string"==typeof f?f:f.write&&("string"==typeof f.write||f.write["#"])?f.write:null;if(!u&&!c)return console.log("No policy found.");const d=JSON.stringify({c:e,...s?{e:s}:{},...u?{r:u}:{},...c?{w:c}:{},...l?{rb:l}:{},...p?{wb:p}:{}});var a=await r.sign(d,n,null,{raw:1});if(i.raw||(a="SEA"+JSON.stringify(a)),o)try{o(a)}catch(e){console.log(e)}return a}catch(e){if(r.err=e,r.throw)throw e;return void(o&&o())}}),e.exports=r.certify}))(t,"./certify"),t((function(e){var r=t("./shim"),n=t("./root");n.work=t("./work"),n.sign=t("./sign"),n.verify=t("./verify"),n.encrypt=t("./encrypt"),n.decrypt=t("./decrypt"),n.certify=t("./certify"),n.random=n.random||r.random,n.Buffer=n.Buffer||t("./buffer"),n.keyid=n.keyid||(async e=>{try{const t=r.Buffer.concat(e.replace(/-/g,"+").replace(/_/g,"/").split(".").map((e=>r.Buffer.from(e,"base64")))),n=r.Buffer.concat([r.Buffer.from([153,t.length/256,t.length%256]),t]),o=await sha1hash(n),i=r.Buffer.from(o,"binary");return i.toString("hex",i.length-8)}catch(e){throw console.log(e),e}}),((n.window||{}).GUN||{}).SEA=n,e.exports=n}))(t,"./sea"),t((function(e){var r,n=t("./sea");function i(e){this._={$:this}}function a(){return r.state().toString(36).replace(".","")}r=n.window?n.window.GUN||{chain:{}}:t((undefined+""==typeof o?".":"")+"./gun",1),n.GUN=r,i.prototype=function(){function e(){}return e.prototype=r.chain,new e}(),i.prototype.constructor=i,r.chain.user=function(e){var t,r=this.back(-1);if(e)return e=n.opt.pub((e._||"")["#"])||e,r.get("~"+e);if(t=r.back("user"))return t;var o=r=r._,s=o.opt.uuid||a;return(o=(t=o.user=this.chain(new i))._).opt={},o.opt.uuid=function(e){var t=s(),n=r.user;return n&&(n=n.is)&&(n=n.pub)?(t="~"+n+"/"+t,e&&e.call&&e(null,t),t):t},t},r.User=i,i.GUN=r,i.SEA=r.SEA=n,e.exports=i}))(t,"./user"),t((function(e){var r;(""+r!=typeof window?window.Gun||{chain:{}}:t((""+r==typeof o?".":"")+"./gun",1)).chain.then=function(e,t){var r=this,n=new Promise((function(e,n){r.once(e,t)}));return e?n.then(e):n}}))(t,"./then"),t((function(e){var r=t("./user"),n=r.SEA,o=r.GUN,i=function(){};r.prototype.create=function(...e){var t,r="object"==typeof e[0]&&(e[0].pub||e[0].epub)?e[0]:"object"==typeof e[1]&&(e[1].pub||e[1].epub)?e[1]:null,a=r&&(r.pub||r.epub)?r.pub:"string"==typeof e[0]?e[0]:null,s=r&&(r.pub||r.epub)?r:a&&"string"==typeof e[1]?e[1]:null,u=e.filter((e=>"function"==typeof e))[0]||null,c=e&&e.length>1&&"object"==typeof e[e.length-1]?e[e.length-1]:{},f=this,l=f._,p=f.back(-1);if((u=u||i,!1!==(c=c||{}).check)&&(a||(t="No user."),(s||"").length<8&&(t="Password too short!"),t))return u({err:o.log(t)}),f;if(l.ing)return(u||i)({err:o.log("User is already being created or authenticated!"),wait:!0}),f;l.ing=!0;var d={a:function(e){if(d.pubs=e,e&&!c.already){var t={err:o.log("User already created!")};return l.ing=!1,(u||i)(t),void f.leave()}d.salt=String.random(64),n.work(s,d.salt,d.b)},b:function(e){d.proof=e,r?d.c(r):n.pair(d.c)},c:function(e){var t;d.pair=e||{},(t=l.root.user)&&(t._.sea=e,t.is={pub:e.pub,epub:e.epub,alias:a}),d.data={pub:e.pub},d.d()},d:function(){d.data.alias=a,d.e()},e:function(){d.data.epub=d.pair.epub,n.encrypt({priv:d.pair.priv,epriv:d.pair.epriv},d.proof,d.f,{raw:1})},f:function(e){d.data.auth=JSON.stringify({ek:e,s:d.salt}),d.g(d.data.auth)},g:function(e){var t;d.data.auth=d.data.auth||e,p.get(t="~"+d.pair.pub).put(d.data).on(d.h);var r={};r[t]={"#":t},p.get("~@"+a).put(r).get(t).on(d.i)},h:function(e,t,r,n){n.off(),d.h.ok=1,d.i()},i:function(e,t,n,o){o&&(d.i.ok=1,o.off()),d.h.ok&&d.i.ok&&(l.ing=!1,u({ok:0,pub:d.pair.pub}),i===u&&(r?f.auth(r):f.auth(a,s)))}};return p.get("~@"+a).once(d.a),f},r.prototype.leave=function(e,t){var r=this.back(-1)._.user;if(r&&(delete r.is,delete r._.is,delete r._.sea),n.window)try{var o={};delete(o=window.sessionStorage).recall,delete o.pair}catch(e){}return this}}))(t,"./create"),t((function(e){var r=t("./user"),n=r.SEA,o=r.GUN,i=function(){};function a(e){if("string"!=typeof e)return e;try{e=JSON.parse(e)}catch(t){e={}}return e}r.prototype.auth=function(...e){var t="object"==typeof e[0]&&(e[0].pub||e[0].epub)?e[0]:"object"==typeof e[1]&&(e[1].pub||e[1].epub)?e[1]:null,r=t||"string"!=typeof e[0]?null:e[0],s=r&&"string"==typeof e[1]?e[1]:null,u=e.filter((e=>"function"==typeof e))[0]||null,c=e&&e.length>1&&"object"==typeof e[e.length-1]?e[e.length-1]:{},f=this,l=f._,p=f.back(-1);if(l.ing)return(u||i)({err:o.log("User is already being created or authenticated!"),wait:!0}),f;l.ing=!0;var d,h={};return h.a=function(e){if(!e)return h.b();if(!e.pub){var t=[];return Object.keys(e).forEach((function(r){"_"!=r&&t.push(e[r])})),h.b(t)}if(h.name)return h.f(e);h.c((h.data=e).auth)},h.b=function(e){var t=(h.list=(h.list||[]).concat(e||[])).shift();if(d===t)return h.name?h.err("Your user account is not published for dApps to access, please consider syncing it online, or allowing local access by adding your device as a peer."):h.err("Wrong user or password.");p.get(t).once(h.a)},h.c=function(e){return d===e?h.b():"string"==typeof e?h.c(a(e)):void n.work(s,(h.auth=e).s,h.d,h.enc)},h.d=function(e){n.decrypt(h.auth.ek,e,h.e,h.enc)},h.e=function(e){if(d===e)return h.enc?(h.enc=null,h.b()):(h.enc={encode:"utf8"},h.c(h.auth));h.half=e,h.f(h.data)},h.f=function(e){var t=h.half||{},r=h.data||{};h.g(h.lol={pub:e.pub||r.pub,epub:e.epub||r.epub,priv:e.priv||t.priv,epriv:e.epriv||t.epriv})},h.g=function(e){if(!e||!e.pub||!e.epub)return h.b();h.pair=e;var t=p._.user,g=t._;g.tag;var y=g.opt;(g=t._=p.get("~"+e.pub)._).opt=y,t.is={pub:e.pub,epub:e.epub,alias:r||e.pub},g.sea=h.pair,l.ing=!1;try{s&&d==(a(l.root.graph["~"+e.pub].auth)||"")[":"]&&(c.shuffle=c.change=s)}catch(e){}if(c.change?h.z():(u||i)(g),n.window&&(f.back("user")._.opt||c).remember)try{var v={};(v=window.sessionStorage).recall=!0,v.pair=JSON.stringify(e)}catch(e){}try{p._.tag.auth?p._.on("auth",g):setTimeout((function(){p._.on("auth",g)}),1)}catch(e){o.log("Your 'auth' callback crashed with:",e)}},h.z=function(){h.salt=String.random(64),n.work(c.change,h.salt,h.y)},h.y=function(e){n.encrypt({priv:h.pair.priv,epriv:h.pair.epriv},e,h.x,{raw:1})},h.x=function(e){h.w(JSON.stringify({ek:e,s:h.salt}))},h.w=function(e){if(c.shuffle){console.log("migrate core account from UTF8 & shuffle");var t={};Object.keys(h.data).forEach((function(e){t[e]=h.data[e]})),delete t._,t.auth=e,p.get("~"+h.pair.pub).put(t)}p.get("~"+h.pair.pub).get("auth").put(e,u||i)},h.err=function(e){var t={err:o.log(e||"User cannot be found!")};l.ing=!1,(u||i)(t)},h.plugin=function(e){if(!(h.name=e))return h.err();var t=[e];"~"!==e[0]&&(t[1]="~"+e,t[2]="~@"+e),h.b(t)},t?h.g(t):r?p.get("~@"+r).once(h.a):r||s||n.name(h.plugin),f}}))(t,"./auth"),t((function(e){var r=t("./user"),n=r.SEA;r.GUN,r.prototype.recall=function(e,t){var r=this,o=r.back(-1);if((e=e||{})&&e.sessionStorage){if(n.window)try{var i;(i=window.sessionStorage)&&(o._.opt.remember=!0,(r.back("user")._.opt||e).remember=!0,(i.recall||i.pair)&&o.user().auth(JSON.parse(i.pair),t))}catch(e){}return r}return r}}))(t,"./recall"),t((function(e){var r=t("./user"),n=r.SEA,o=r.GUN,i=function(){};r.prototype.pair=function(){var e,t=this;try{e=new Proxy({DANGER:"☠"},{get:function(e,r,n){if(t.is&&(t._||"").sea)return t._.sea[r]}})}catch(e){}return e},r.prototype.delete=async function(e,t,r){console.log("user.delete() IS DEPRECATED AND WILL BE MOVED TO A MODULE!!!");var n=this;n.back(-1);var a=n.back("user");try{a.auth(e,t,(function(e){(a.is||{}).pub;a.map().once((function(){this.put(null)})),a.leave(),(r||i)({ok:0})}))}catch(e){o.log("User.delete failed! Error:",e)}return n},r.prototype.alive=async function(){console.log("user.alive() IS DEPRECATED!!!");const e=this.back(-1);try{return await authRecall(e),e._.user._}catch(e){const t="No session!";throw o.log(t),{err:t}}},r.prototype.trust=async function(e){console.log("`.trust` API MAY BE DELETED OR CHANGED OR RENAMED, DO NOT USE!"),o.is(e)&&e.get("pub").get(((e,t)=>{console.log(e,t)})),e.get("trust").get(path).put(theirPubkey)},r.prototype.grant=function(e,t){console.log("`.grant` API MAY BE DELETED OR CHANGED OR RENAMED, DO NOT USE!");var r=this,o=r.back(-1).user(),i=o._.sea,a="";return r.back((function(e){e.is||(a+=e.get||"")})),async function(){var r,s=await o.get("grant").get(i.pub).get(a).then();(s=await n.decrypt(s,i))||(s=n.random(16).toString(),r=await n.encrypt(s,i),o.get("grant").get(i.pub).get(a).put(r));var u=e.get("pub").then(),c=e.get("epub").then();u=await u,c=await c;var f=await n.secret(c,i);r=await n.encrypt(s,f),o.get("grant").get(u).get(a).put(r,t)}(),r},r.prototype.secret=function(e,t){console.log("`.secret` API MAY BE DELETED OR CHANGED OR RENAMED, DO NOT USE!");var r=this,o=r.back(-1).user(),i=o.pair(),a="";return r.back((function(e){e.is||(a+=e.get||"")})),async function(){var s,u=await o.get("trust").get(i.pub).get(a).then();(u=await n.decrypt(u,i))||(u=n.random(16).toString(),s=await n.encrypt(u,i),o.get("trust").get(i.pub).get(a).put(s)),s=await n.encrypt(e,u),r.put(s,t)}(),r},e.exports=r}))(t,"./share"),t((function(e){var r,n=t("./sea"),i=t("./settings"),a=""+r!=typeof window?window.Gun||{on:function(){}}:t((""+r==typeof o?".":"")+"./gun",1);function s(e){var t,r=this,o=r.as,i=e.put,u=i["#"],c=i["."],f=i[":"],l=i[">"],p=e["#"];if(u&&c)if((e._||"").faith&&(o.opt||"").faith&&"function"==typeof e._)n.opt.pack(i,(function(t){n.verify(t,!1,(function(t){i["="]=n.opt.unpack(t),r.to.next(e)}))}));else{var d=function(t){o.on("in",{"@":p,err:e.err=t})};(e._||"").DBG&&((e._||"").DBG.c=+new Date),0<=u.indexOf("<?")&&(t=parseFloat(u.split("<?")[1]||""))&&l<a.state()-1e3*t?(t=e._)&&t.stun&&t.stun--:"~@"!==u?"~@"!==u.slice(0,2)?(t=n.opt.pub(u))?s.pub(r,e,f,c,u,o,d,o.user||"",t):0<=u.indexOf("#")?s.hash(r,e,f,c,u,o,d):s.any(r,e,f,c,u,o,d,o.user||""):s.pubs(r,e,f,c,u,o,d):s.alias(r,e,f,c,u,o,d)}}a.on("opt",(function(e){e.sea||(e.sea={own:{}},e.on("put",s,e)),this.to.next(e)})),s.hash=function(e,t,r,o,i,a,s){n.work(r,null,(function(r){if(r&&r===o.split("#").slice(-1)[0])return e.to.next(t);s("Data hash not same as hash!")}),{name:"SHA-256"})},s.alias=function(e,t,r,n,o,i,a){return r?"~@"+n===c(r)?e.to.next(t):void a("Alias not same!"):a("Data must exist!")},s.pubs=function(e,t,r,n,o,i,a){return r?n===c(r)?e.to.next(t):void a("Alias not same!"):a("Alias must exist!")},s.pub=async function(e,t,o,s,u,f,l,p,d){var h;const g=await i.parse(o)||{},y=(o,i,c)=>{if(o.m&&o.s&&i&&d)return n.verify(o,d,(n=>{if(r!==n&&r!==n.e&&t.put[">"]&&t.put[">"]>parseFloat(n.e))return l("Certificate expired.");if(r!==n&&n.c&&n.w&&(n.c===i||n.c.indexOf("*")>-1)){let t=u.indexOf("/")>-1?u.replace(u.substring(0,u.indexOf("/")+1),""):"";String.match=String.match||a.text.match;const r=Array.isArray(n.w)?n.w:"object"==typeof n.w||"string"==typeof n.w?[n.w]:[];for(const a of r)if(String.match(t,a["#"])&&String.match(s,a["."])||!a["."]&&String.match(t,a["#"])||!a["#"]&&String.match(s,a["."])||String.match(t?t+"/"+s:s,a["#"]||a)){if(a["+"]&&a["+"].indexOf("*")>-1&&t&&-1==t.indexOf(i)&&-1==s.indexOf(i))return l(`Path "${t}" or key "${s}" must contain string "${i}".`);if(n.wb&&("string"==typeof n.wb||(n.wb||{})["#"])){var o=e.as.root.$.back(-1);return"string"==typeof n.wb&&"~"!==n.wb.slice(0,1)&&(o=o.get("~"+d)),o.get(n.wb).get(i).once((e=>!e||1!==e&&!0!==e?c(n):l(`Certificant ${i} blocked.`)))}return c(n)}return l("Certificate verification fail.")}}))};if("pub"===s&&"~"+d===u)return o===d?e.to.next(t):l("Account not same!");(h=p.is)&&h.pub&&!g["*"]&&!g["+"]&&(d===h.pub||d!==h.pub&&((t._.msg||{}).opt||{}).cert)?n.opt.pack(t.put,(a=>{n.sign(a,p._.sea,(async function(a){if(r===a)return l(n.err||"Signature fail.");if(t.put[":"]={":":h=n.opt.unpack(a.m),"~":a.s},t.put["="]=h,d===p.is.pub)return(h=c(o))&&((f.sea.own[h]=f.sea.own[h]||{})[d]=1),void JSON.stringifyAsync(t.put[":"],(function(r,n){return r?l(r||"Stringify error."):(t.put[":"]=n,e.to.next(t))}));if(d!==p.is.pub&&((t._.msg||{}).opt||{}).cert){const r=await i.parse(t._.msg.opt.cert);r&&r.m&&r.s&&y(r,p.is.pub,(n=>{t.put[":"]["+"]=r,t.put[":"]["*"]=p.is.pub,JSON.stringifyAsync(t.put[":"],(function(r,n){return r?l(r||"Stringify error."):(t.put[":"]=n,e.to.next(t))}))}))}}),{raw:1})})):n.opt.pack(t.put,(o=>{n.verify(o,g["*"]||d,(function(o){var i;return o=n.opt.unpack(o),r===o?l("Unverified data."):((i=c(o))&&d===n.opt.pub(i)&&((f.sea.own[i]=f.sea.own[i]||{})[d]=1),g["+"]&&g["+"].m&&g["+"].s&&g["*"]?void y(g["+"],g["*"],(r=>(t.put["="]=o,e.to.next(t)))):(t.put["="]=o,e.to.next(t)))}))}))},s.any=function(e,t,r,n,o,i,a,s){if(i.opt.secure)return a("Soul missing public key at '"+n+"'.");i.on("secure",(function(t){if(this.off(),!i.opt.secure)return e.to.next(t);a("Data cannot be changed.")})).on.on("secure",t)};var u=a.valid,c=function(e,t){return"string"==typeof(t=u(e))&&t};(a.state||"").ify;var f=/[^\w_-]/;n.opt.pub=function(e){if(e&&(e=e.split("~"))&&(e=e[1])&&(e=e.split(f).slice(0,2))&&2==e.length&&"@"!==(e[0]||"")[0])return e=e.slice(0,2).join(".")},n.opt.stringy=function(e){},n.opt.pack=function(e,t,o,i,s){var u,c;if(n.opt.check(e))return t(e);e&&e["#"]&&e["."]&&e[">"]&&(u=e[":"],c=1),JSON.parseAsync(c?u:e,(function(n,u){var c=r!==(u||"")[":"]&&(u||"")["~"];t(c?{m:{"#":s||e["#"],".":o||e["."],":":(u||"")[":"],">":e[">"]||a.state.is(i,o)},s:c}:e)}))};var l=n.opt;n.opt.unpack=function(e,t,o){var i;if(r!==e){if(e&&r!==(i=e[":"]))return i;if(t=t||l.fall_key,!o&&l.fall_val&&((o={})[t]=l.fall_val),t&&o){if(e===o[t])return e;if(!n.opt.check(o[t]))return e;var s=o&&o._&&o._["#"]||l.fall_soul,u=a.state.is(o,t)||l.fall_state;return e&&4===e.length&&s===e[0]&&t===e[1]&&p(u)===p(e[3])?e[2]:u<n.opt.shuffle_attack?e:void 0}}},n.opt.shuffle_attack=15463296e5;var p=Math.floor}))(t,"./index")}()}({exports:{}});var s={exports:{}};!function(){function e(){var n=function(i,a,s){if(n.unit=0,s||t===a||(n.last=""+i<n.last?n.last:""+i,delete(n.$||{})[o]),s=s||n.$||(n.$={}),!i&&Object.keys(s).length)return s;for(var u,c,f=0,l=(i=""+i).length-1,p=i[f];!(u=s[p])&&f<l;)p+=i[++f];if(u){if(f!=l)return t!==a&&delete u[o],n(i.slice(++f),a,u||(u={}));if(t===a)return t===(c=u[""])?u:(n.unit=1)&&c;u[""]=a}else{if(!r(s,(function(r,n){var o=0,u="";if((n||"").length)for(;n[o]==i[o];)u+=n[o++];if(u){if(t===a){if(o<=l)return;return(c||(c={}))[n.slice(o)]=r,r}var f={};return f[n.slice(o)]=r,""===(o=i.slice(o))?f[""]=a:(f[o]={})[""]=a,s[u]=f,e.debug&&"undefined"==""+u&&console.log(0,u),delete s[n],!0}}))){if(t===a)return;(s[p]||(s[p]={}))[""]=a,e.debug&&"undefined"==""+p&&console.log(1,p)}if(t===a)return c}};return n}if(e.map=function r(i,a,s,u){u=u||[];var c="function"==typeof i?i.$||{}:i;
2
+ //!opt && console.log("WHAT IS T?", JSON.stringify(t).length);
3
+ if(c)if("string"!=typeof c){var f,l=(c[o]||n).sort||(c[o]=function e(){return e.sort=Object.keys(c).sort(),e}()).sort;(f=(s=!0===s?{branch:!0}:s||{}).reverse)&&(l=l.slice(0).reverse());for(var p=s.start,d=s.end,h=0,g=l.length;h<g;h++){var y,v,w,b=l[h],m=c[b];if(m&&""!==b&&o!==b&&((v=u.slice(0)).push(b),w=v.join(""),!(t!==p&&w<(p||"").slice(0,w.length)||t!==d&&(d||"￿")<w))){if(f&&(y=r(m,a,s,v),t!==y))return y;if(t!==(y=m[""])){var k=1;if(t!==p&&w<(p||"")&&(k=0),t!==d&&w>(d||"￿")&&(k=0),k&&(y=a(y,w,b,u),t!==y))return y}else if(s.branch&&(y=a(t,w,b,u),t!==y))return y;if(u=v,!f&&(y=r(m,a,s,u),t!==y))return y;u.pop()}}}else if(e.debug)throw["BUG:",i,a,s,u]},"undefined"!=typeof window)window.Radix=e;else try{s.exports=e}catch(e){}var t,r=e.object=function(e,r,n){for(var o in e)if(e.hasOwnProperty(o)&&(n=r(e[o],o))!==t)return n},n={},o=String.fromCharCode(24)}();var u={exports:{}};!function(e){!function(){var t,r={},n=setTimeout.turn||typeof setImmediate!=""+t&&setImmediate||setTimeout;function o(e){var t=parseFloat(e);return isNaN(t)?"true"==(e=e.trim())||"false"!=e&&("null"==e?null:void 0):t}r.parseAsync=function(e,r,i,a){if("string"==typeof e){var s={i:0,text:e,done:r,l:e.length,up:[]};a=a||32768,function r(){var i,u,c=s.text,f=s.i,l=s.l,p=0,d=s.w;for(;p++<a;){var h=c[f++];if(f>l){s.end=!0;break}if(d)f=c.indexOf('"',f-1),h=c[f],u="\\"==c[f-1],i=i||u,'"'!=h||u||(d=t,u=s.s,s.a?(u=c.slice(s.sl,f),(i||1+u.indexOf("\\u"))&&(u=JSON.parse('"'+u+'"')),s.at instanceof Array?s.at.push(s.s=u):(s.at||(s.end=p=a,u=t),(s.at||{})[s.s]=s.s=u)):(s.s=c.slice(s.sl,f),(i||1+s.s.indexOf("\\u"))&&(s.s=JSON.parse('"'+s.s+'"'))),s.a=i=t),++f;else switch(h){case'"':s.sl=f,d=!0;break;case":":s.ai=f,s.a=!0;break;case",":(s.a||s.at instanceof Array)&&(u=c.slice(s.ai,f-1))&&t!==(u=o(u))&&(s.at instanceof Array?s.at.push(u):s.at[s.s]=u),s.a=t,s.at instanceof Array&&(s.a=!0,s.ai=f);break;case"{":s.up.push(s.at||(s.at={})),s.at instanceof Array?s.at.push(s.at={}):t!==(u=s.s)&&(s.at[u]=s.at={}),s.a=t;break;case"}":s.a&&(u=c.slice(s.ai,f-1))&&t!==(u=o(u))&&(s.at instanceof Array?s.at.push(u):(s.at||(s.end=p=a,u=t),(s.at||{})[s.s]=u)),s.a=t,s.at=s.up.pop();break;case"[":t!==(u=s.s)?(s.up.push(s.at),s.at[u]=s.at=[]):s.at||s.up.push(s.at=[]),s.a=!0,s.ai=f;break;case"]":s.a&&(u=c.slice(s.ai,f-1))&&t!==(u=o(u))&&(s.at instanceof Array?s.at.push(u):s.at[s.s]=u),s.a=t,s.at=s.up.pop()}}if(s.s=t,s.i=f,s.w=d,s.end){if(u=s.at,t===u)try{u=JSON.parse(e)}catch(e){return s.done(e)}s.done(t,u)}else n(r)}()}else try{r(t,JSON.parse(e))}catch(e){r(e)}},r.stringifyAsync=function(e,r,o,i,a){(a=a||{}).text=a.text||"",a.up=[a.at={d:e}],a.done=r,a.i=0;var s=0;!function e(){var r,o=a.at,i=o.d,u="";o.i&&o.i-o.j>0&&(u+=",");t!==(r=o.k)&&(u+=JSON.stringify(r)+":");switch(typeof i){case"boolean":u+=""+i;break;case"string":u+=JSON.stringify(i);break;case"number":u+=i;break;case"object":if(!i){u+="null";break}if(i instanceof Array){u+="[",(o={i:-1,as:i,up:o,j:0}).l=i.length,a.up.push(a.at=o);break}if("function"!=typeof(i||"").toJSON){u+="{",(o={i:-1,ok:Object.keys(i).sort(),as:i,up:o,j:0}).l=o.ok.length,a.up.push(a.at=o);break}if(r=i.toJSON()){u+=r;break}case"function":if(o.as instanceof Array){u+="null";break}default:u="",o.j++}a.text+=u;for(;1+o.i>=o.l;)a.text+=o.ok?"}":"]",o=a.at=o.up;if(++o.i<o.l)return(r=o.ok)?o.d=o.as[o.k=r[o.i]]:o.d=o.as[o.i],++s<9?e():(s=0,void n(e));a.done(t,a.text)}()},typeof window!=""+t&&(window.YSON=r);try{e.exports=r}catch(e){}typeof JSON!=""+t&&(JSON.parseAsync=r.parseAsync,JSON.stringifyAsync=r.stringifyAsync)}()}({exports:{}}),function(){function e(t){(t=t||{}).log=t.log||console.log,t.file=String(t.file||"radata");var o=(e.has||(e.has={}))[t.file];if(o)return o;function i(e){return encodeURIComponent(e).replace(/\*/g,"%2A")}t.max=t.max||.3*(t.memory?999*t.memory*999:3e8),t.until=t.until||t.wait||250,t.batch=t.batch||1e4,t.chunk=t.chunk||1048576,t.code=t.code||{},t.code.from=t.code.from||"!",t.jsonify=!0;var a=""+y==typeof setImmediate?setTimeout:setImmediate,s=setTimeout.turn||a,u=n.object,c=0;if(!t.store)return t.log("ERROR: Radisk needs `opt.store` interface with `{get: fn, put: fn (, list: fn)}`!");if(!t.store.put)return t.log("ERROR: Radisk needs `store.put` interface with `(file, data, cb)`!");if(!t.store.get)return t.log("ERROR: Radisk needs `store.get` interface with `(file, cb)`!");t.store.list;var f=JSON.parseAsync||function(e,t,r){try{t(undefined,JSON.parse(e,r))}catch(e){t(e)}},l=function(e,t,r,n,o){if("function"==typeof t){var i=r||{};return r=t,void l.read(e,r,i,o||n)}l.save(e,t,r,n,o)};l.save=function(e,r,o,a,s){var u,c,f={key:e};f.find=function(e){var r;f.file=e||(e=t.code.from),s&&(s=s[e]=s[e]||{}),s&&(s.sf=s.sf||+new Date),(r=l.disk[e])?f.mix(y,r):l.parse(e,f.mix,y,s)},f.mix=function(i,u){if(s&&(s.sml=+new Date),s&&(s.sm=s.sm||+new Date),f.err=i||f.err)o(i);else{var c,p=f.file=(u||"").file||f.file;if(!u&&p!==t.code.from)return l.find.bad(p),void l.save(e,r,o,a);(u=l.disk[p]||(l.disk[p]=u||n())).file||(u.file=p),t.compare&&(r=t.compare(u(e),r,e,p),y===r)?o(i,-1):((f.disk=u)(e,r),a&&((c=(c=u.tags||(u.tags={}))[a]||(c[a]=l.tags[a]||(l.tags[a]={})))[p]||(c[p]=l.one[a]||(l.one[a]=o)),o=null),s&&(s.st=s.st||+new Date),u.Q?o&&u.Q.push(o):(u.Q=o?[o]:[],u.to=setTimeout(f.write,t.until)))}},f.write=function(){s&&(s.sto=s.sto||+new Date);var e=u=f.file,t=f.disk;c=f.q=t.Q,f.tags=t.tags,delete t.Q,delete l.disk[e],delete t.tags,l.write(e,t,f.ack,y,s)},f.ack=function(e,t){var r,n;for(var o in s&&(s.sa=s.sa||+new Date),s&&(s.sal=c.length),l.tags)if(l.tags.hasOwnProperty(o)){var a=l.tags[o];if(!((n=l.disk[u])&&(n=n.tags)&&n[a])){var p;for(var d in r=a[u],delete a[u],a)if(a.hasOwnProperty(d)){p=!0;break}p||(delete l.tags[a],r&&r(e,t))}}!c&&(c="");for(var h=c.length,g=0,y=+new Date;g<h;g++)(r=c[g])&&r(e,t);console.STAT&&console.STAT(y,+new Date-y,"rad acks",i(f.file)),console.STAT&&console.STAT(y,c.length,"rad acks #",i(f.file))},o||(o=function(e,t){}),l.find(e,f.find)},l.disk={},l.one={},l.tags={};var p,d,h,g=0;l.write=function(r,o,a,s,u){if(o){s="object"==typeof s?s:{force:s};var f,p,d=function(){};d.text="",d.file=r=o.file||(o.file=r),r?(d.write=function(){var e=o.raw=d.text;l.disk[r=o.file||d.file||r]=o;var n=+new Date;u&&(u.wd=n),l.find.add(r,(function(s){u&&(u.wa=+new Date),s?a(s):t.store.put(i(r),e,(function(e,t){u&&(u.wp=+new Date),console.STAT&&console.STAT(n,c=+new Date-n,"wrote disk",JSON.stringify(r),++g,"total all writes."),a(e,t||1),o.Q||delete l.disk[r]}))}))},d.split=function(){var e=+new Date;u&&(u.wf=e),d.text="",d.count||(d.count=0,n.map(o,(function(){d.count++}))),u&&(u.wfc=d.count),d.limit=Math.ceil(d.count/2);var t=d.count;return d.count=0,u&&(u.wf1=+new Date),d.sub=n(),n.map(o,d.slice,{reverse:1}),u&&(u.wf2=+new Date),l.write(d.end,d.sub,d.both,s),u&&(u.wf3=+new Date),d.hub=n(),n.map(o,d.stop),u&&(u.wf4=+new Date),l.write(o.file,d.hub,d.both,s),u&&(u.wf5=+new Date),console.STAT&&console.STAT(e,+new Date-e,"rad split",i(o.file),t),!0},d.slice=function(e,t){if(d.sub(d.end=t,e),d.limit<=++d.count)return!0},d.stop=function(e,t){if(t>=d.end)return!0;d.hub(t,e)},d.both=function(e,t){u&&(u.wfd=+new Date),p?a(e||p):f?a(e,t):(f=!0,p=e)},d.each=function(r,n,o,i){if(y!==r&&d.count++,t.max<=(r||"").length)return a("Data too big!"),!0;var u=e.encode(i.length)+"#"+e.encode(o)+(y===r?"":":"+e.encode(r))+"\n";if(t.chunk<d.text.length+u.length&&1<d.count&&!s.force)return d.split();d.text+=u},t.jsonify?l.write.jsonify(d,o,a,s,u):n.map(o,d.each,!0)||d.write()):a("What file?")}else a("No radix!")},l.write.jsonify=function(e,r,o,i,a){var s,u=+new Date;a&&(a.w=u);try{s=JSON.stringify(r.$)}catch(e){return void o("Cannot radisk!")}if(a&&(a.ws=+new Date),console.STAT&&console.STAT(u,+new Date-u,"rad stringified JSON"),t.chunk<s.length&&!i.force){var c=0;if(n.map(r,(function(){if(c++)return!0})),c>1)return e.split()}e.text=s,e.write()},l.range=function(e,t){if(e&&t){if(y===t.start&&y===t.end)return e;if(y!==(r=e)&&(!r||"object"!=typeof r))return e;var r,o=n();return n.map(e,(function(e,t){o(t,e)}),t),o("")}},l.read=function(e,r,o,u){o=o||{};var c={key:e,find:function(e){var r;c.file=e||(e=t.code.from),u&&(u=u[e]=u[e]||{}),u&&(u.rf=u.rf||+new Date),(r=l.disk[c.file=e])?c.check(y,r):l.parse(e,c.check,y,u)},get:function(i,s,f){if(u&&(u.rgl=+new Date),u&&(u.rg=u.rg||+new Date),c.err=i||c.err)r(i);else{var p=c.file=(s||"").file||c.file;if(!s&&p!==t.code.from)return l.find.bad(p),void l.read(e,r,o);if(s=l.disk[p]||(l.disk[p]=s)){s.file||(s.file=p);var d=l.range(s(e),o);if(u&&(u.rr=+new Date),o.unit=s.unit,o.chunks=(o.chunks||0)+1,o.parsed=(o.parsed||0)+((f||"").parsed||o.chunks*t.chunk),o.more=1,o.next=y,n.map(l.list,(function(e,t){if(e&&p!==t)return o.next=t,1}),o.reverse?{reverse:1,end:p}:{start:p}),u&&(u.rl=+new Date),o.next||(o.more=0),o.next&&(!o.reverse&&(e<o.next&&0!=o.next.indexOf(e)||y!==o.end&&(o.end||"￿")<o.next)&&(o.more=0),o.reverse&&(e>o.next&&0!=e.indexOf(o.next)||y!==o.start&&(o.start||"")>o.next&&p<=o.start)&&(o.more=0)),o.more){if(d&&r(c.err,d,o),!(o.parsed>=o.limit)){var h=+new Date;u&&(u.rm=h);var g=o.next;a((function(){console.STAT&&console.STAT(h,+new Date-h,"rad more"),l.parse(g,c.check)}),0)}}else r(c.err,d,o)}else r(p===t.code.from?y:"No file!")}},check:function(e,r,o){if(c.get(e,r,o),r&&!r.check){r.check=1;var a=+new Date;(o||(o={})).file||(o.file=c.file),n.map(r,(function(e,r){l.find(r,(function(n){if((n||(n=t.code.from))!==o.file){var a=(""+Math.random()).slice(-3);s((function(){l.save(r,e,(function t(s,u){s?l.save(r,e,t):console.STAT&&console.STAT("MISLOCATED DATA CORRECTED",a,i(r),i(o.file),i(n))}))}),0)}}))})),console.STAT&&console.STAT(a,+new Date-a,"rad check")}}};l.find(e||(o.reverse?o.end||"":o.start||""),c.find)},p=0,d={},h=String.fromCharCode(31),l.parse=function(r,o,a,u){var g;if(!r)return o();if(g=d[r])g.push(o);else{g=d[r]=[o];var v=function(){},w={file:r};(v.disk=n()).file=r,v.read=function(e,n){if(u&&(u.rpg=+new Date),console.STAT&&console.STAT(b,+new Date-b,"read disk",JSON.stringify(r),++p,"total all parses."),(v.err=e)||(v.not=!n))return delete d[r],void v.map(g,v.ack);if("string"!=typeof n){try{t.max<=n.length?v.err="Chunk too big!":n=n.toString()}catch(e){v.err=e}if(v.err)return delete d[r],void v.map(g,v.ack)}w.parsed=n.length,u&&(u.rpl=w.parsed),u&&(u.rpa=g.length),b=+new Date,t.jsonify||"{"===n[0]?f(n,(function(e,t){return e?"{"===n[0]?(delete d[r],v.err="JSON error!",void v.map(g,v.ack)):void v.radec(e,n):(delete d[r],v.disk.$=t,console.STAT&&(c=+new Date-b)>9&&console.STAT(b,c,"rad parsed JSON"),u&&(u.rpd=+new Date),void v.map(g,v.ack))})):v.radec(e,n)},v.map=function(){if(g&&g.length){for(var e,t=+new Date,n=v.err,o=v.not?y:v.disk,a=0;a<9&&(e=g[a++]);)e(n,o,w);console.STAT&&console.STAT(t,+new Date-t,"rad packs",i(r)),console.STAT&&console.STAT(t,a,"rad packs #",i(r)),(g=g.slice(a)).length&&s(v.map,0)}},v.ack=function(e){e&&(v.err||v.not?e(v.err,y,w):e(y,v.disk,w))},v.radec=function(e,t){delete d[r],b=+new Date;var n,o,i,a=v.split(t),s=[];if(!a||0!==a[1])return v.err="File '"+r+"' does not have root radix! ",void v.map(g,v.ack);for(;a;)o=i=y,n=a[1],"#"==(a=v.split(a[2])||"")[0]&&(o=a[1],n<=(s=s.slice(0,n)).length&&s.push(o)),"\n"!=(a=v.split(a[2])||"")[0]&&("="!=a[0]&&":"!=a[0]||(i=a[1]),y!==o&&y!==i&&v.disk(s.join(""),i),a=v.split(a[2]));console.STAT&&console.STAT(b,+new Date-b,"parsed RAD"),v.map(g,v.ack)},v.split=function(t){if(t){var r,n,o=[],i={};if(r=t.indexOf(h),t[r])return n=t.slice(0,r),o[0]=n,o[1]=e.decode(t.slice(r),i),o[2]=t.slice(r+i.i),o}},l.disk&&(a||(a=(l.disk[r]||"").raw));var b=+new Date;if(u&&(u.rp=b),a)return s((function(){v.read(y,a)}),0);t.store.get(i(r),v.read)}},function(){var e,r,o=String.fromCharCode(28);function i(r,s){if(r)return t.log("list",r),void setTimeout((function(){l.parse(o,i)}),1e3);s?a(s):(e=e||s||n(),t.store.list?t.store.list((function(t){t?l.find.add(t,v):a(e)})):a(e))}function a(t,n){(e=e||t).file=o,n=r,r=null,u(n,(function(e){l.find(e[0],e[1])}))}l.find=function(a,s){if(!e)return r?void r.push([a,s]):(r=[[a,s]],void l.parse(o,i));n.map(l.list=e,(function(e,t){if(e)return s(t)||!0}),{reverse:1,end:a})||s(t.code.from)},l.find.add=function(t,r){e(t)||t===o?r(y,1):(e(t,1),r.found=(r.found||0)+1,l.write(o,e,(function(e,t){e?r(e):(r.found=(r.found||0)-1,0===r.found&&r(y,1))}),!0))},l.find.bad=function(t,r){e(t,0),l.write(o,e,r||v)}}();try{!r.window&&require("./radmigtmp")(l)}catch(e){}var y,v=function(){};return e.has[t.file]=l,l}var t;if(t=String.fromCharCode(31),e.encode=function(e,r,n){var o=n=n||t;if("string"==typeof e){for(var i=e.indexOf(n);-1!=i;)o+=n,i=e.indexOf(n,i+1);return o+'"'+e+n}return e&&e["#"]&&1==Object.keys(e).length?o+"#"+void 0+o:"number"==typeof e?o+"+"+(e||0)+o:null===e?o+" "+o:!0===e?o+"+"+o:!1===e?o+"-"+o:void 0},e.decode=function(e,r,n){var o,i,a,s=-1,u=0;if((n=n||t)===e[0]){for(;n===e[++s];)++u;for(a=e[i=u]||!0;--u>=0;)s=e.indexOf(n,s+1);return-1==s&&(s=e.length),o=e.slice(i+1,s),r&&(r.i=s+1),'"'===a?o:"#"===a?{"#":o}:"+"===a?0===o.length||parseFloat(o):" "===a?null:"-"!==a&&void 0}},"undefined"!=typeof window){var r=window.Gun,n=window.Radix;window.Radisk=e}else{r=i.exports,n=s.exports;try{u.exports=e}catch(e){}}e.Radix=n}();var c="undefined"!=typeof window?window.Gun:i.exports;c.on("create",(function(e){c.TESTING&&(e.opt.file="radatatest"),this.to.next(e);var t,r=e.opt;if(!1!==r.rad&&!1!==r.radisk&&(t+""==typeof process||"false"!=""+(process.env||"").RAD)){var n=c.window&&c.window.Radisk||u.exports,o=n.Radix,i=n(r),a=String.fromCharCode(27),s=0;e.on("put",(function(t){if(this.to.next(t),!(t._||"").rad){var r=t["#"],n=t.put,o=n["#"],s=n["."],u=n[":"],c=n[">"],f=(t._||"").DBG;f&&(f.sp=f.sp||+new Date);var l=(t._||"").RPS||((t._||"").RPS=+new Date);i(o+a+s,{":":u,">":c},(function(t,n){f&&(f.spd=f.spd||+new Date),console.STAT&&console.STAT(l,+new Date-l,"put"),t?e.on("in",{"@":r,err:t,DBG:f}):e.on("in",{"@":r,ok:n,DBG:f})}),!1,f&&(f.r=f.r||{})),f&&(f.sps=f.sps||+new Date)}})),e.on("get",(function(u){this.to.next(u);var l=(u._||"").DBG=u.DBG;l&&(l.sg=+new Date);var p,d,h,g,y=u["#"],v=u.get,w=u.get["#"],b=u.get["."]||"",m={};if("string"==typeof w?d=w:w&&(t!==(h=w["*"])&&(m.limit=g=1),t!==w[">"]&&(m.start=w[">"]),t!==w["<"]&&(m.end=w["<"]),d=g?""+h:h||w["="],g=null),d&&!m.limit&&("string"==typeof b?d=d+a+(m.atom=b):b&&(t!==b[">"]&&(m.start=b[">"],m.limit=1),t!==b["<"]&&(m.end=b["<"],m.limit=1),t!==(h=b["*"])&&(m.limit=g=1),d&&(d=d+a+(g?""+(h||""):h||(m.atom=b["="]||""))))),((h=v["%"])||m.limit)&&(m.limit=h<=(m.pack||1e5)?h:1),(b["-"]||(w||{})["-"]||v["-"])&&(m.reverse=!0),(h=(e.next||"")[w])&&h.put)if(m.atom){if((h=(h.next||"")[m.atom])&&h.rad)return}else if(h&&h.rad)return;var k=c.state(),S=+new Date,x=0;function _(e,t,r,o){if(x++,e){var i=(t=(d+t).split(a)).slice(0,1)[0];if(t=t.slice(-1)[0],m.limit&&m.limit<=m.count)return!0;var s,u,f=i,l=t;if("string"!=typeof e)return s=e[":"],u=e[">"],(p=p||{})[f]=c.state.ify(p[f],l,u,s,f),void(m.count=(m.count||0)+((s||"").length||9));m.count=(m.count||0)+e.length;var h=e.lastIndexOf(">"),g=n.decode(e.slice(h+1),null,a);e=n.decode(e.slice(0,h),null,a),(p=p||{})[i]=c.state.ify(p[i],t,g,e,i)}}l&&(l.sgm=S),i(d||"",(function(n,i,u){l&&(l.sgr=+new Date),l&&(l.sgi=u);try{r.store.stats.get.time[f%50]=+new Date-S,++f,r.store.stats.get.count++,n&&(r.store.stats.get.err=n)}catch(e){}var h,g;if(console.STAT&&console.STAT(S,+new Date-S,"got",JSON.stringify(d)),S=+new Date,(u=u||"").unit&&i&&t!==(h=i[":"])&&t!==(g=i[">"])){var A=d.split(a),T=A[0],D=A[1];(p=p||{})[T]=c.state.ify(p[T],D,g,h,T),e.$.get(T).get(D)._.rad=k}else i&&("string"!=typeof i&&(m.atom?i=t:o.map(i,_,m)),!p&&i&&_(i,""),!m.atom&&!b&"string"==typeof w&&!m.limit&&!m.more&&(e.$.get(w)._.rad=k));l&&(l.sgp=+new Date),console.STAT&&(s=+new Date-S)>9&&(console.STAT(S,s,"got prep time"),console.STAT(S,x,"got prep #")),x=0,S=+new Date;var O=function(){};O.faith=!0,O.rad=v,e.on("in",{"@":y,put:p,"%":u.more?1:t,err:n||t,_:O,DBG:l}),console.STAT&&(s=+new Date-S)>9&&console.STAT(S,s,"got emit",Object.keys(p||{}).length),p=t}),m,l&&(l.r=l.r||{})),l&&(l.sgd=+new Date),console.STAT&&(s=+new Date-S)>9&&console.STAT(S,s,"get call")})),c.valid,(r.store||{}).stats={get:{time:{},count:0},put:{time:{},count:0}};var f=0}}));var f={exports:{}};!function(){function e(t){(t=t||{}).file=String(t.file||"radata");var r=e[t.file],n=null;if(r)return console.log("Warning: reusing same IndexedDB store and options as 1st."),e[t.file];r=e[t.file]=function(){};try{t.indexedDB=t.indexedDB||e.indexedDB||indexedDB}catch(e){}try{if(!t.indexedDB||"file:"==location.protocol){var o=r.d||(r.d={});return r.put=function(e,t,r){o[e]=t,setTimeout((function(){r(null,1)}),250)},r.get=function(e,t){setTimeout((function(){t(null,o[e]||undefined)}),5)},console.log("Warning: No indexedDB exists to persist data to!"),r}}catch(e){}return r.start=function(){var e=indexedDB.open(t.file,1);e.onupgradeneeded=function(e){e.target.result.createObjectStore(t.file)},e.onsuccess=function(){n=e.result},e.onerror=function(e){console.log(e||1)}},r.start(),r.put=function(e,o,i){if(n){var a=n.transaction([t.file],"readwrite"),s=a.objectStore(t.file),u=s.put(o,""+e);u.onsuccess=s.onsuccess=a.onsuccess=function(){i(null,1)},u.onabort=s.onabort=a.onabort=function(e){i(e||"put.tx.abort")},u.onerror=s.onerror=a.onerror=function(e){i(e||"put.tx.error")}}else setTimeout((function(){r.put(e,o,i)}),1)},r.get=function(e,o){if(n){var i=n.transaction([t.file],"readonly").objectStore(t.file).get(""+e);i.onsuccess=function(){o(null,i.result)},i.onabort=function(e){o(e||4)},i.onerror=function(e){o(e||5)}}else setTimeout((function(){r.get(e,o)}),9)},setInterval((function(){n&&n.close(),n=null,r.start()}),15e3),r}if("undefined"!=typeof window)(e.window=window).RindexedDB=e,e.indexedDB=window.indexedDB;else try{f.exports=e}catch(e){}try{(e.window.Gun||require("../gun")).on("create",(function(t){this.to.next(t),t.opt.store=t.opt.store||e(t.opt)}))}catch(e){}}();let l=new a({peers:["https://gun-relay.scobrudot.dev/gun"],axe:!1,localStorage:!1,radisk:!0}),p=l.user().recall({sessionStorage:!0});
4
+ /*! *****************************************************************************
5
+ Copyright (c) Microsoft Corporation.
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any
8
+ purpose with or without fee is hereby granted.
9
+
10
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
11
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
12
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
13
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
14
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
15
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
16
+ PERFORMANCE OF THIS SOFTWARE.
17
+ ***************************************************************************** */
18
+ var d=function(e,t){return d=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])},d(e,t)};function h(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function r(){this.constructor=e}d(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}function g(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function y(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,i=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return a}function v(e,t){for(var r=0,n=t.length,o=e.length;r<n;r++,o++)e[o]=t[r];return e}function w(e){return"function"==typeof e}function b(e){var t=e((function(e){Error.call(e),e.stack=(new Error).stack}));return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}var m=b((function(e){return function(t){e(this),this.message=t?t.length+" errors occurred during unsubscription:\n"+t.map((function(e,t){return t+1+") "+e.toString()})).join("\n "):"",this.name="UnsubscriptionError",this.errors=t}}));function k(e,t){if(e){var r=e.indexOf(t);0<=r&&e.splice(r,1)}}var S=function(){function e(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._teardowns=null}var t;return e.prototype.unsubscribe=function(){var e,t,r,n,o;if(!this.closed){this.closed=!0;var i=this._parentage;if(i)if(this._parentage=null,Array.isArray(i))try{for(var a=g(i),s=a.next();!s.done;s=a.next()){s.value.remove(this)}}catch(t){e={error:t}}finally{try{s&&!s.done&&(t=a.return)&&t.call(a)}finally{if(e)throw e.error}}else i.remove(this);var u=this.initialTeardown;if(w(u))try{u()}catch(e){o=e instanceof m?e.errors:[e]}var c=this._teardowns;if(c){this._teardowns=null;try{for(var f=g(c),l=f.next();!l.done;l=f.next()){var p=l.value;try{A(p)}catch(e){o=null!=o?o:[],e instanceof m?o=v(v([],y(o)),y(e.errors)):o.push(e)}}}catch(e){r={error:e}}finally{try{l&&!l.done&&(n=f.return)&&n.call(f)}finally{if(r)throw r.error}}}if(o)throw new m(o)}},e.prototype.add=function(t){var r;if(t&&t!==this)if(this.closed)A(t);else{if(t instanceof e){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._teardowns=null!==(r=this._teardowns)&&void 0!==r?r:[]).push(t)}},e.prototype._hasParent=function(e){var t=this._parentage;return t===e||Array.isArray(t)&&t.includes(e)},e.prototype._addParent=function(e){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(e),t):t?[t,e]:e},e.prototype._removeParent=function(e){var t=this._parentage;t===e?this._parentage=null:Array.isArray(t)&&k(t,e)},e.prototype.remove=function(t){var r=this._teardowns;r&&k(r,t),t instanceof e&&t._removeParent(this)},e.EMPTY=((t=new e).closed=!0,t),e}(),x=S.EMPTY;function _(e){return e instanceof S||e&&"closed"in e&&w(e.remove)&&w(e.add)&&w(e.unsubscribe)}function A(e){w(e)?e():e.unsubscribe()}var T={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},D={setTimeout:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var r=D.delegate;return((null==r?void 0:r.setTimeout)||setTimeout).apply(void 0,v([],y(e)))},clearTimeout:function(e){var t=D.delegate;return((null==t?void 0:t.clearTimeout)||clearTimeout)(e)},delegate:void 0};function O(){}var j=null;function E(e){if(T.useDeprecatedSynchronousErrorHandling){var t=!j;if(t&&(j={errorThrown:!1,error:null}),e(),t){var r=j,n=r.errorThrown,o=r.error;if(j=null,n)throw o}}else e()}var $=function(e){function t(t){var r=e.call(this)||this;return r.isStopped=!1,t?(r.destination=t,_(t)&&t.add(r)):r.destination=M,r}return h(t,e),t.create=function(e,t,r){return new C(e,t,r)},t.prototype.next=function(e){this.isStopped||this._next(e)},t.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(S),C=function(e){function t(t,r,n){var o,i=e.call(this)||this;if(w(t))o=t;else if(t){var a;o=t.next,r=t.error,n=t.complete,i&&T.useDeprecatedNextContext?(a=Object.create(t)).unsubscribe=function(){return i.unsubscribe()}:a=t,o=null==o?void 0:o.bind(a),r=null==r?void 0:r.bind(a),n=null==n?void 0:n.bind(a)}return i.destination={next:o?N(o):O,error:N(null!=r?r:B),complete:n?N(n):O},i}return h(t,e),t}($);function N(e,t){return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];try{e.apply(void 0,v([],y(t)))}catch(e){!function(e){D.setTimeout((function(){throw e}))}(e)}}}function B(e){throw e}var M={closed:!0,next:O,error:B,complete:O},G="function"==typeof Symbol&&Symbol.observable||"@@observable";function P(e){return e}var J=function(){function e(e){e&&(this._subscribe=e)}return e.prototype.lift=function(t){var r=new e;return r.source=this,r.operator=t,r},e.prototype.subscribe=function(e,t,r){var n,o=this,i=(n=e)&&n instanceof $||function(e){return e&&w(e.next)&&w(e.error)&&w(e.complete)}(n)&&_(n)?e:new C(e,t,r);return E((function(){var e=o,t=e.operator,r=e.source;i.add(t?t.call(i,r):r?o._subscribe(i):o._trySubscribe(i))})),i},e.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(t){e.error(t)}},e.prototype.forEach=function(e,t){var r=this;return new(t=R(t))((function(t,n){var o;o=r.subscribe((function(t){try{e(t)}catch(e){n(e),null==o||o.unsubscribe()}}),n,t)}))},e.prototype._subscribe=function(e){var t;return null===(t=this.source)||void 0===t?void 0:t.subscribe(e)},e.prototype[G]=function(){return this},e.prototype.pipe=function(){for(var e,t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return(0===(e=t).length?P:1===e.length?e[0]:function(t){return e.reduce((function(e,t){return t(e)}),t)})(this)},e.prototype.toPromise=function(e){var t=this;return new(e=R(e))((function(e,r){var n;t.subscribe((function(e){return n=e}),(function(e){return r(e)}),(function(){return e(n)}))}))},e.create=function(t){return new e(t)},e}();function R(e){var t;return null!==(t=null!=e?e:T.Promise)&&void 0!==t?t:Promise}var I=b((function(e){return function(){e(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}})),U=function(e){function t(){var t=e.call(this)||this;return t.closed=!1,t.observers=[],t.isStopped=!1,t.hasError=!1,t.thrownError=null,t}return h(t,e),t.prototype.lift=function(e){var t=new q(this,this);return t.operator=e,t},t.prototype._throwIfClosed=function(){if(this.closed)throw new I},t.prototype.next=function(e){var t=this;E((function(){var r,n;if(t._throwIfClosed(),!t.isStopped){var o=t.observers.slice();try{for(var i=g(o),a=i.next();!a.done;a=i.next()){a.value.next(e)}}catch(e){r={error:e}}finally{try{a&&!a.done&&(n=i.return)&&n.call(i)}finally{if(r)throw r.error}}}}))},t.prototype.error=function(e){var t=this;E((function(){if(t._throwIfClosed(),!t.isStopped){t.hasError=t.isStopped=!0,t.thrownError=e;for(var r=t.observers;r.length;)r.shift().error(e)}}))},t.prototype.complete=function(){var e=this;E((function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;for(var t=e.observers;t.length;)t.shift().complete()}}))},t.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=null},Object.defineProperty(t.prototype,"observed",{get:function(){var e;return(null===(e=this.observers)||void 0===e?void 0:e.length)>0},enumerable:!1,configurable:!0}),t.prototype._trySubscribe=function(t){return this._throwIfClosed(),e.prototype._trySubscribe.call(this,t)},t.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},t.prototype._innerSubscribe=function(e){var t=this,r=t.hasError,n=t.isStopped,o=t.observers;return r||n?x:(o.push(e),new S((function(){return k(o,e)})))},t.prototype._checkFinalizedStatuses=function(e){var t=this,r=t.hasError,n=t.thrownError,o=t.isStopped;r?e.error(n):o&&e.complete()},t.prototype.asObservable=function(){var e=new J;return e.source=this,e},t.create=function(e,t){return new q(e,t)},t}(J),q=function(e){function t(t,r){var n=e.call(this)||this;return n.destination=t,n.source=r,n}return h(t,e),t.prototype.next=function(e){var t,r;null===(r=null===(t=this.destination)||void 0===t?void 0:t.next)||void 0===r||r.call(t,e)},t.prototype.error=function(e){var t,r;null===(r=null===(t=this.destination)||void 0===t?void 0:t.error)||void 0===r||r.call(t,e)},t.prototype.complete=function(){var e,t;null===(t=null===(e=this.destination)||void 0===e?void 0:e.complete)||void 0===t||t.call(e)},t.prototype._subscribe=function(e){var t,r;return null!==(r=null===(t=this.source)||void 0===t?void 0:t.subscribe(e))&&void 0!==r?r:x},t}(U);let F=new U;l.on("auth",(()=>F.next(!0)));var H=Object.freeze({__proto__:null,checkAuth:()=>p.is?F.next(!0):F.next(!1),isAuthenticated:F,loginUser:(e={},t=()=>{})=>{p.auth(e.username,e.password,(({err:e,pub:r})=>t(e?{errMessage:e,errCode:"gun-auth-error"}:{errMessage:void 0,errCode:void 0,pub:r,message:"Successfully authenticated user."})))},registerUser:(e={},t=()=>{})=>{console.log("Credentials",e),console.log("Registering user..."),(async()=>{if(await(async e=>void 0!==await l.get(`~@${e}`))(e.username))return t({errMessage:"Username in use.",errCode:"username-inuse"});p.create(e.username,e.password,(({err:e,pub:r})=>t(e?{errMessage:e,errCode:"gun-auth-error"}:{errMessage:void 0,errCode:void 0,pub:r,message:"Successfully created user."})))})()},logout:()=>{l.user().leave(),F.next(!1)}}),K=i.exports;let W=async(e,t=()=>{})=>{if(await l.user().get("certificates").get(e).get("addFriend").once())return;let r=await K.SEA.certify([e],[{"*":"friends"}],await l.user().pair(),null);l.user().get("certificates").get(e).get("addFriend").put(r,(({err:e})=>t(e?{errMessage:e,errCode:"gun-put-error",success:void 0}:{errMessage:void 0,errCode:void 0,certificate:r,success:"Generated certificate for requested friend to add user back."})))};var L=Object.freeze({__proto__:null,generateAddFriendCertificate:W,generateFriendRequestsCertificate:async(e=()=>{})=>{if(await l.user().get("certificates").get("friendRequests").once())return;let t=await K.SEA.certify(["*"],[{"*":"friendRequests"}],await l.user().pair(),null);l.user().get("certificates").get("friendRequests").put(t,(({err:r})=>e(r?{errMessage:r,errCode:"gun-put-error",success:void 0}:{errMessage:void 0,errCode:void 0,certificate:t,success:"Generated new friend requests certificate."})))},createChatsCertificate:async(e,t=()=>{})=>{if(await l.user().get("certificates").get(e).get("chats").once())return;let r=await K.SEA.certify([e],[{"*":"chats"}],await l.user().pair(),null);l.user().get("certificates").get(e).get("chats").put(r,(({err:e})=>t(e?{errMessage:e,errCode:"chats-certificate-creation-error",success:void 0}:{errMessage:void 0,errCode:void 0,certificate:r,success:"Generated new chats certificate."})))},createMessagesCertificate:async(e,t=()=>{})=>{if(await l.user().get("certificates").get(e).get("messages").once())return;let r=await K.SEA.certify([e],[{"*":"messages"}],await l.user().pair(),null);l.user().get("certificates").get(e).get("messages").put(r,(({err:e})=>t(e?{errMessage:e,errCode:"messages-certificate-creation-error",success:void 0}:{errMessage:void 0,errCode:void 0,certificate:r,success:"Generated new messages certificate."})))}});let z=new J((e=>{l.user().get("friendRequests").map(((t,r)=>{t?l.user(t).once((t=>{t&&t.info&&t.pub&&t.alias?l.get(t.info["#"]).on((n=>{e.next({key:r,pub:t.pub,alias:t.alias,displayName:n.displayName,about:n.about||void 0})})):t&&t.pub&&t.alias&&e.next({key:r,pub:t.pub,alias:t.alias})})):e.next(void 0)}))})),V=new J((e=>{l.user().get("friends").map(((t,r)=>{t?l.user(t).once((t=>{t&&t.info&&t.pub&&t.alias?l.get(t.info["#"]).on((n=>{e.next({key:r,pub:t.pub,alias:t.alias,displayName:n.displayName,about:n.about||void 0})})):t&&t.pub&&t.alias&&e.next({key:r,pub:t.pub,alias:t.alias})})):e.next(void 0)}))}));var Q=Object.freeze({__proto__:null,addFriendRequest:async(e,t=()=>{})=>{let r=await l.user(e).get("certificates").get("friendRequests");l.user(e).get("friendRequests").set(p.is.pub,(({err:r})=>{if(r)return t({errMessage:r,errCode:"friend-request-error",success:void 0});W(e,(({errMessage:e,errCode:r,success:n})=>t(e?{errMessage:e,errCode:r,success:n}:{errMessage:void 0,errCode:void 0,success:"Friend request sent successfully."})))}),{opt:{cert:r}})},acceptFriendRequest:({key:e,publicKey:t},r=()=>{})=>{l.user().get("friendRequests").get(e).put(null,(async({err:e})=>{if(e)return r({errMessage:e,errCode:"accept-friend-request-failed",success:void 0});{let e=await l.user(t).get("certificates").get(p.is.pub).get("addFriend");l.user(t).get("friends").set(p.is.pub,(({err:e})=>{if(e)return r({errMessage:e,errCode:"add-friend-failed",success:void 0});l.user().get("friends").set(t,(({err:e})=>r(e?{errMessage:e,errCode:"add-friend-failed",success:void 0}:{errMessage:void 0,errCode:void 0,success:"Added friend successfully."})))}),{opt:{cert:e}})}}))},rejectFriendRequest:(e,t=()=>{})=>{l.user().get("friendRequests").get(e).put(null,(async({err:e})=>t(e?{errMessage:e,errCode:"reject-friend-request-failed",success:void 0}:{errMessage:void 0,errCode:void 0,success:"Friend request removed successfully."})))},friendRequests:z,friendsList:V});let Y=new J((e=>{l.user().get("chats").on(((t,r)=>{for(let r in t)try{let n=JSON.parse(t[r]);n&&e.next({roomId:n.roomId,pub:n.pub,latestMessage:n.latestMessage})}catch(e){}}))}));var X,Z=new Uint8Array(16);function ee(){if(!X&&!(X="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return X(Z)}var te=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var re=[],ne=0;ne<256;++ne)re.push((ne+256).toString(16).substr(1));function oe(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,r=(re[e[t+0]]+re[e[t+1]]+re[e[t+2]]+re[e[t+3]]+"-"+re[e[t+4]]+re[e[t+5]]+"-"+re[e[t+6]]+re[e[t+7]]+"-"+re[e[t+8]]+re[e[t+9]]+"-"+re[e[t+10]]+re[e[t+11]]+re[e[t+12]]+re[e[t+13]]+re[e[t+14]]+re[e[t+15]]).toLowerCase();if(!function(e){return"string"==typeof e&&te.test(e)}(r))throw TypeError("Stringified UUID is invalid");return r}function ie(e,t,r){var n=(e=e||{}).random||(e.rng||ee)();if(n[6]=15&n[6]|64,n[8]=63&n[8]|128,t){r=r||0;for(var o=0;o<16;++o)t[r+o]=n[o];return t}return oe(n)}var ae=Object.freeze({__proto__:null,createChat:async(e,t=()=>{})=>{l.user().get("chats").get(e).once((async r=>{if(r)return t({errMessage:"The chat already exists. Opening it now.",errCode:"chat-already-exists",chat:JSON.parse(r),success:void 0});let n=await l.user(e).once(),o=await l.user().pair().pub;if(!o)return t({errMessage:"Could not find pub.",errCode:"failed-to-find-pub",success:void 0});if(!n)return t({errMessage:"Could not find friend.",errCode:"failed-to-find-friend",success:void 0});let i=await l.user(e).get("certificates").get(o).get("chats");if(!i)return t({errMessage:"Could not find friend certificate to create chat",errCode:"failed-to-find-friend-chats-certificate",success:void 0});let a=ie();l.user(e).get("chats").get(o).put(JSON.stringify({pub:o,roomId:a,latestMessage:{}}),(({err:r})=>{if(r)return t({errMessage:r,errCode:"chat-creation-error",success:void 0});l.user().get("chats").get(e).put(JSON.stringify({pub:n.pub,roomId:a,latestMessage:{}}),(({err:e})=>t(e?{errMessage:e,errCode:"chat-creation-error",success:void 0}:{errMessage:void 0,errCode:void 0,chat:{pub:n.pub,roomId:a},success:"Created a chat with friend."})))}),{opt:{cert:i}})}))},chatsList:Y,messageList:(e,t)=>new J((async r=>{let n=await l.user()._.sea,o=await l.user(t);l.user().get("messages").get(e).once((t=>{(async()=>{let i=[];for(let e in t){let r=t[e].toString(),a=await SEA.secret(o.epub,n),s=await SEA.decrypt(r,a);if(s){let e={...s,encrypted:!0},t=void 0!==i.filter((t=>t.id===e.id))[0];console.log(t),t||i.push(e)}}r.next({initial:i,individual:void 0}),l.user().get("messages").get(e).map().once((async e=>{if(e.toString().startsWith("SEA")){let t=await SEA.secret(o.epub,n),a=await SEA.decrypt(e,t);if(a){let e={...a,encrypted:!0};if(!(void 0!==i.filter((t=>t.id===e.id))[0]))return r.next({initial:void 0,individual:e})}}}))})()}))})),sendMessage:(e,t,r,n=()=>{})=>{(async(n=()=>{})=>{let o=await l.user().pair().pub,i=await l.user()._.sea,a=await l.user(t);if(!o)return n({errMessage:"Impossibile trovare la chiave pubblica.",errCode:"failed-to-find-pub",success:void 0});let s=await l.user(t).get("certificates").get(o).get("messages");if(!s)return n({errMessage:"Impossibile trovare il certificato dell'amico per creare il messaggio",errCode:"failed-to-find-friend-messages-certificate",success:void 0});let u=await l.user(t).get("certificates").get(o).get("chats");if(!u)return n({errMessage:"Impossibile trovare il certificato dell'amico per aggiungere metadati alla chat",errCode:"failed-to-find-friend-chats-certificate",success:void 0});let c=ie(),f=Date.now(),p=await K.SEA.secret(a.epub,i),d=await K.SEA.encrypt(JSON.stringify({id:c,content:r,timeSent:f,sender:o,type:"text"}),p);l.user().get("chats").get(e).get("latestMessage").put(d),l.user(t).get("chats").get(e).get("latestMessage").put(d,null,{opt:{cert:u}}),l.user().get("messages").get(e).set(d,(({err:r})=>{if(r)return n({errMessage:r,errCode:"message-creation-error",success:void 0});l.user(t).get("messages").get(e).set(d,(({err:e})=>n(e?{errMessage:e,errCode:"message-creation-error",success:void 0}:{errMessage:void 0,errCode:void 0,success:"Messaggio creato con successo con l'amico."})),{opt:{cert:s}})}))})(n)},sendVoiceMessage:(e,t,r,n=()=>{})=>{(async(n=()=>{})=>{let o=await l.user().pair().pub;if(await l.user()._.sea,await l.user(t),!o)return n({errMessage:"Could not find pub.",errCode:"failed-to-find-pub",success:void 0});let i=await l.user(t).get("certificates").get(o).get("messages");if(!i)return n({errMessage:"Could not find friend certificate to create message",errCode:"failed-to-find-friend-messages-certificate",success:void 0});let a=await l.user(t).get("certificates").get(o).get("chats");if(!a)return n({errMessage:"Could not find friend certificate to add meta to chat",errCode:"failed-to-find-friend-chats-certificate",success:void 0});l.user().get("chats").get(e).get("latestMessage").put(r),l.user(t).get("chats").get(e).get("latestMessage").put(r,null,{opt:{cert:a}}),l.user().get("messages").get(e).set(r,(({err:o})=>{if(o)return n({errMessage:o,errCode:"message-creation-error",success:void 0});l.user(t).get("messages").get(e).set(r,(({err:e})=>n(e?{errMessage:e,errCode:"message-creation-error",success:void 0}:{errMessage:void 0,errCode:void 0,success:"Created a voice message with friend."})),{opt:{cert:i}})}))})(n)}});let se="",ue="";async function ce(){if(se&&ue){const e=new t.ethers.JsonRpcProvider(se);return new t.ethers.Wallet(ue,e)}if("undefined"!=typeof window&&void 0!==window.ethereum){await window.ethereum.request({method:"eth_requestAccounts"});return new t.ethers.BrowserProvider(window.ethereum).getSigner()}throw new Error("No valid Ethereum provider found")}async function fe(e){const r=await async function(){if(se&&ue)return new t.ethers.JsonRpcProvider(se);if("undefined"!=typeof window&&void 0!==window.ethereum)return new t.ethers.BrowserProvider(window.ethereum);throw new Error("No valid Ethereum provider found")}();try{const t=await r.lookupAddress(e);return t?(console.log(`The ENS name for address ${e} is: ${t}`),t):(console.log(`No ENS name found for address ${e}`),null)}catch(e){return console.error("Error while looking up ENS name:",e),null}}K.chain.GunEth=function(e,t,r){return console.log("gunEth called"),console.log("gun in gunEth:",e),{shine:(t,r,n,o)=>K.chain.shine.call(e,t,r,n,o),setStandaloneConfig:(e,t)=>(console.log("setStandaloneConfig called with:",e,t),function(e,t){se=e,ue=t}(e,t),console.log("Standalone configuration set"),this.gun),verifySignature:async(e,t)=>{try{return r.verifyMessage(e,t)}catch(e){return console.error("Error verifying signature:",e),null}},generatePassword:e=>{try{const t=r.hexlify(e),n=r.keccak256(t);return console.log("Generated password:",n),n}catch(e){return console.error("Error generating password:",e),null}},createSignature:async()=>{try{const e=await ce(),t=await e.signMessage("GunDB access with Ethereum");return console.log("Signature created:",t),t}catch(e){return console.error("Error creating signature:",e),null}},createAndStoreEncryptedPair:async(r,n)=>{try{const o=await p._.sea,i=await t.encrypt(JSON.stringify(o),n);let a;try{const e=await fe(r);a=e||r}catch(e){console.error("Error getting ENS name:",e),a=r}const s={pub:i.pub,address:r,ensName:a};await e.get("gun-eth").get("users").get(r).put({encryptedPair:i}),await e.get("gun-eth").get("usersData").get(i.pub).put({data:s}),await e.get(`~${i.pub}`).get("safe").get("enc").put({encryptedPair:i}),console.log("Encrypted pair stored for:",r)}catch(e){console.error("Error creating and storing encrypted pair:",e)}},getAndDecryptPair:async(r,n)=>{try{const o=await e.get("gun-eth").get("users").get(r).get("encryptedPair").then();if(!o)throw new Error("No encrypted data found for this address");const i=await t.decrypt(o,n);return console.log(i),i}catch(e){return console.error("Error retrieving and decrypting pair:",e),null}},gunToEthAccount:e=>{const t="0x"+(e=>{const t="=".repeat((4-e.length%4)%4),r=e.replace(/-/g,"+").replace(/_/g,"/")+t,n=atob(r);return Array.from(n,(e=>e.charCodeAt(0).toString(16).padStart(2,"0"))).join("")})(e),n=new r.Wallet(t);return{account:n,publicKey:n.address}}}};return"undefined"!=typeof window&&(window.Gun=l,window.GunEthProtocol={authentication:H,certificates:L,friends:Q,messaging:ae,gun:l,user:p},window.User=p),e.authentication=H,e.certificates=L,e.friends=Q,e.gun=l,e.messaging=ae,e.user=p,Object.defineProperty(e,"__esModule",{value:!0}),e}({},ethers);