diff --git a/dist/js/statuswidget.js b/dist/js/statuswidget.js index 383790c..3963a30 100644 --- a/dist/js/statuswidget.js +++ b/dist/js/statuswidget.js @@ -3495,4 +3495,4 @@ object-assign /*!**********************!*\ !*** util (ignored) ***! \**********************/ -/*! no static exports found */function(module,exports){eval("/* (ignored) */\n\n//# sourceURL=webpack://murmur/util_(ignored)?")}})},function(n,e,t){"use strict";t.r(e);var r=t(159),a=t.n(r),i=t(160),s=t.n(i);window.StatusWidget=function(n){var e=document.createElement("h3");e.innerHTML="#"+n;var t=document.createElement("div");t.id="chat";var r=document.createElement("input");r.type="input",r.id="post",r.placeholder="Type a message..",document.querySelectorAll("#status-chat-widget")[0].append(e),document.querySelectorAll("#status-chat-widget")[0].append(t),document.querySelectorAll("#status-chat-widget")[0].append(r);let i=new s.a({protocols:["libp2p"],signalServers:["/dns4/web-bridge.status.im/tcp/443/wss/p2p-webrtc-star"],bootnodes:[]});i.start();const o=new a.a;o.connectToProvider(i.provider,null),o.joinChat(n,()=>{o.onMessage(n,(n,e)=>{const t=JSON.parse(e.payload)[1][0],r=e.username,a=t;e.data.sig;let i=document.createElement("div");i.innerHTML=r+"> "+a,document.querySelectorAll("#chat")[0].append(i);var s=document.getElementById("chat");s.scrollTop=s.scrollHeight}),document.getElementById("post").addEventListener("keyup",function(e){if(13===e.keyCode){e.preventDefault();var t=document.getElementById("post").value;o.sendMessage(n,t),document.getElementById("post").value=""}})})}},function(n,e,t){"use strict";var r=t(51),a=r(t(163)),i=r(t(198)),s=r(t(200)),o=r(t(387)),l=r(t(391)),c=r(t(158)),u=r(t(392));"undefined"!=typeof window&&(window.web3=window.web3||{});const d="undefined"!=typeof window&&window.web3?new s.default(window.web3.currentProvider):s.default,{utils:{asciiToHex:f,hexToAscii:h}}=d;function p(n,e,t,r=!1){const a=c.default.messageTags.message;t<(new Date).getTime()&&(t=100*((new Date).getTime()+26784e5));const s=r?"content/json":"text/plain",o=(new Date).getTime();return f((0,i.default)([a,[n,s,e,t,o,["^ ","~:text",n]]]))}const m=new a.default;n.exports=class{constructor(){this.channels=void 0,this.contacts=void 0,this.userMessagesSubscription=void 0,this.mailservers=void 0,this.isHttpProvider=void 0,this.shh=void 0,this.chatRequestCb=void 0,this.channels={},this.contacts={},this.userMessagesSubscription=null,this.mailservers=null,this.isHttpProvider=!1}async connect(n,e){const r=new s.default;if(n.startsWith("ws://"))r.setProvider(new d.providers.WebsocketProvider(n,{headers:{Origin:"statusjs"}}));else if(n.startsWith("http://")||n.startsWith("https://"))r.setProvider(new d.providers.HttpProvider(n)),this.isHttpProvider=!0;else{const e=t(393);r.setProvider(new d.providers.IpcProvider(n,e))}this.shh=r.shh,this.mailservers=new l.default(r),await r.shh.setMinPoW(c.default.post.POW_TARGET),m.set(this,e?await this.generateWhisperKeyFromWallet(e):await r.shh.newKeyPair())}async connectToProvider(n,e){const t=new s.default(n);this.shh=t.shh,this.mailservers=new l.default(t),await t.shh.setMinPoW(c.default.post.POW_TARGET),m.set(this,e?await this.generateWhisperKeyFromWallet(e):await t.shh.newKeyPair())}isConnected(){return this.shh.isListening()}async generateWhisperKeyFromWallet(n){return await this.shh.addPrivateKey(n)}async getPublicKey(){return await this.shh.getPublicKey(m.get(this))}async getUserName(n){return n||(n=await this.getPublicKey()),o.default.generateUsernameFromSeed(n)}cleanChannelName(n){return n.startsWith("#")?n.substr(1):n}async joinChat(n,e){n=this.cleanChannelName(n);const t=await this.shh.generateSymKeyFromPassword(n);this.channels[n]={channelCode:d.utils.sha3(n).slice(0,10),channelKey:t,channelName:n,lastClockValue:0},e&&e()}async addContact(n,e){this.contacts[n]={lastClockValue:0,username:o.default.generateUsernameFromSeed(n)},e&&e()}leaveChat(n){n=this.cleanChannelName(n),this.isHttpProvider?this.shh.deleteMessageFilter(this.channels[n].filterId).then(()=>{clearInterval(this.channels[n].interval)}):this.channels[n].subscription.unsubscribe(),delete this.channels[n]}async removeContact(n){delete this.contacts[n]}isSubscribedTo(n){return n=this.cleanChannelName(n),!!this.channels[n]}onMessage(n,e){"function"==typeof n?this.onUserMessage(n):this.onChannelMessage(n,e)}onChatRequest(n){this.chatRequestCb=n}onChannelMessage(n,e){if(n=this.cleanChannelName(n),!this.channels[n])return e("unknown channel: "+n);const t={allowP2P:!0,symKeyID:this.channels[n].channelKey,topics:[this.channels[n].channelCode]},r=t=>{try{const r=o.default.generateUsernameFromSeed(t.sig),a=u.default.parse(h(t.payload));this.channels[n].lastClockValue{this.channels[n].filterId=t,this.channels[n].interval=setInterval(()=>{this.shh.getFilterMessages(t).then(n=>{n.map(n=>{r(n)})}).catch(n=>{e(n)})},250)}):this.channels[n].subscription=this.shh.subscribe("messages",t).on("data",r).on("error",n=>{e(n)})}onUserMessage(n){const e={allowP2P:!0,minPow:0,privateKeyID:m.get(this),topics:[c.default.topics.CONTACT_DISCOVERY_TOPIC]},t=e=>{this.contacts[e.sig]||this.addContact(e.sig);try{const t=u.default.parse(h(e.payload));this.contacts[e.sig].lastClockValue{this.userMessagesSubscription={},this.userMessagesSubscription.filterId=e,this.userMessagesSubscription.interval=setInterval(()=>{this.shh.getFilterMessages(e).then(n=>{n.map(n=>{t(n)})}).catch(e=>{n(e)})},250)}):this.userMessagesSubscription=this.shh.subscribe("messages",e).on("data",n=>{t(n)}).on("error",e=>{n(e)})}sendUserMessage(n,e,t){this.contacts[n]||this.addContact(n),this.contacts[n].lastClockValue++,this.shh.post({payload:p(e,c.default.messageTypes.USER_MESSAGE,this.contacts[n].lastClockValue),powTarget:c.default.post.POW_TARGET,powTime:c.default.post.POW_TIME,pubKey:n,sig:m.get(this),topic:c.default.topics.CONTACT_DISCOVERY_TOPIC,ttl:c.default.post.TTL}).then(()=>{t&&t(null,!0)}).catch(n=>{t&&t(n,!1)})}sendGroupMessage(n,e,t){if(n=this.cleanChannelName(n),!this.channels[n]){if(!t)return;return t("unknown channel: "+n)}this.channels[n].lastClockValue++,this.shh.post({payload:p(e,c.default.messageTypes.GROUP_MESSAGE,this.channels[n].lastClockValue),powTarget:c.default.post.POW_TARGET,powTime:c.default.post.POW_TIME,sig:m.get(this),symKeyID:this.channels[n].channelKey,topic:this.channels[n].channelCode,ttl:c.default.post.TTL}).then(()=>{t&&t(null,!0)}).catch(n=>{t&&t(n,!1)})}sendJsonMessage(n,e,t){c.default.regExp.CONTACT_CODE_REGEXP.test(n)?(this.contacts[n]||this.addContact(n),this.contacts[n].lastClockValue++,this.shh.post({payload:p(e,c.default.messageTypes.USER_MESSAGE,this.contacts[n].lastClockValue,!0),powTarget:c.default.post.POW_TARGET,powTime:c.default.post.POW_TIME,pubKey:n,sig:m.get(this),topic:c.default.topics.CONTACT_DISCOVERY_TOPIC,ttl:c.default.post.TTL}).then(()=>{t&&t(null,!0)}).catch(n=>{t&&t(n,!1)})):(this.channels[n].lastClockValue++,this.shh.post({payload:p((0,i.default)(e),c.default.messageTypes.GROUP_MESSAGE,this.channels[n].lastClockValue,!0),powTarget:c.default.post.POW_TARGET,powTime:c.default.post.POW_TIME,sig:m.get(this),symKeyID:this.channels[n].channelKey,topic:this.channels[n].channelCode,ttl:c.default.post.TTL}).then(()=>{t&&t(null,!0)}).catch(n=>{t&&t(n,!1)}))}sendMessage(n,e,t){c.default.regExp.CONTACT_CODE_REGEXP.test(n)?this.sendUserMessage(n,e,t):this.sendGroupMessage(n,e,t)}}},function(n,e,t){n.exports=t(164)},function(n,e,t){t(165),t(166),t(181),t(194),t(196),n.exports=t(27).WeakMap},function(n,e){},function(n,e,t){t(167);for(var r=t(13),a=t(16),i=t(26),s=t(14)("toStringTag"),o="CSSRuleList,CSSStyleDeclaration,CSSValueList,ClientRectList,DOMRectList,DOMStringList,DOMTokenList,DataTransferItemList,FileList,HTMLAllCollection,HTMLCollection,HTMLFormElement,HTMLSelectElement,MediaList,MimeTypeArray,NamedNodeMap,NodeList,PaintRequestList,Plugin,PluginArray,SVGLengthList,SVGNumberList,SVGPathSegList,SVGPointList,SVGStringList,SVGTransformList,SourceBufferList,StyleSheetList,TextTrackCueList,TextTrackList,TouchList".split(","),l=0;l=n.length?(this._t=void 0,a(1)):a(0,"keys"==e?t:"values"==e?n[t]:[t,n[t]])},"values"),i.Arguments=i.Array,r("keys"),r("values"),r("entries")},function(n,e){n.exports=function(){}},function(n,e){n.exports=function(n,e){return{value:e,done:!!n}}},function(n,e,t){"use strict";var r=t(83),a=t(39),i=t(87),s=t(16),o=t(26),l=t(173),c=t(58),u=t(180),d=t(14)("iterator"),f=!([].keys&&"next"in[].keys()),h=function(){return this};n.exports=function(n,e,t,p,m,b,g){l(t,e,p);var y,v,_,w=function(n){if(!f&&n in A)return A[n];switch(n){case"keys":case"values":return function(){return new t(this,n)}}return function(){return new t(this,n)}},k=e+" Iterator",x="values"==m,S=!1,A=n.prototype,E=A[d]||A["@@iterator"]||m&&A[m],T=E||w(m),C=m?x?w("entries"):T:void 0,I="Array"==e&&A.entries||E;if(I&&(_=u(I.call(new n)))!==Object.prototype&&_.next&&(c(_,k,!0),r||"function"==typeof _[d]||s(_,d,h)),x&&E&&"values"!==E.name&&(S=!0,T=function(){return E.call(this)}),r&&!g||!f&&!S&&A[d]||s(A,d,T),o[e]=T,o[k]=h,m)if(y={values:x?T:w("values"),keys:b?T:w("keys"),entries:C},g)for(v in y)v in A||i(A,v,y[v]);else a(a.P+a.F*(f||S),e,y);return y}},function(n,e,t){n.exports=!t(29)&&!t(30)(function(){return 7!=Object.defineProperty(t(85)("div"),"a",{get:function(){return 7}}).a})},function(n,e,t){var r=t(12);n.exports=function(n,e){if(!r(n))return n;var t,a;if(e&&"function"==typeof(t=n.toString)&&!r(a=t.call(n)))return a;if("function"==typeof(t=n.valueOf)&&!r(a=t.call(n)))return a;if(!e&&"function"==typeof(t=n.toString)&&!r(a=t.call(n)))return a;throw TypeError("Can't convert object to primitive value")}},function(n,e,t){"use strict";var r=t(174),a=t(86),i=t(58),s={};t(16)(s,t(14)("iterator"),function(){return this}),n.exports=function(n,e,t){n.prototype=r(s,{next:a(1,t)}),i(n,e+" Iterator")}},function(n,e,t){var r=t(21),a=t(175),i=t(91),s=t(56)("IE_PROTO"),o=function(){},l=function(){var n,e=t(85)("iframe"),r=i.length;for(e.style.display="none",t(179).appendChild(e),e.src="javascript:",(n=e.contentWindow.document).open(),n.write("