@waves.exchange/provider-web 1.2.0 → 1.2.2-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/provider-web.cjs.js +25 -17
- package/dist/provider-web.es.js +25 -17
- package/dist/provider-web.min.js +1 -1
- package/dist/types/ProviderWeb.d.ts +3 -0
- package/dist/types/Transport.d.ts +1 -0
- package/dist/types/TransportIframe.d.ts +1 -1
- package/dist/types/interface.d.ts +1 -0
- package/package.json +1 -1
package/dist/provider-web.cjs.js
CHANGED
|
@@ -160,6 +160,18 @@ class TransportIframe extends Transport {
|
|
|
160
160
|
}
|
|
161
161
|
return this._iframe;
|
|
162
162
|
}
|
|
163
|
+
listenFetchURLError() {
|
|
164
|
+
const iframe = this.get();
|
|
165
|
+
fetch(this._url).catch(() => {
|
|
166
|
+
this.get().addEventListener("load", () => {
|
|
167
|
+
if (!iframe.contentDocument) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
this._renderErrorPage(iframe.contentDocument.body, () => this.dropConnection(), "The request could not be processed. To resume your further work, disable the installed plugins.");
|
|
171
|
+
this._showIframe();
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
}
|
|
163
175
|
_dropTransportConnect() {
|
|
164
176
|
if (this._iframe != null) {
|
|
165
177
|
document.body.removeChild(this._iframe);
|
|
@@ -192,7 +204,6 @@ class TransportIframe extends Transport {
|
|
|
192
204
|
_initIframe() {
|
|
193
205
|
this._iframe = this._createIframe();
|
|
194
206
|
this._addIframeToDom(this._iframe);
|
|
195
|
-
this._listenFetchURLError(this._iframe);
|
|
196
207
|
this._hideIframe();
|
|
197
208
|
}
|
|
198
209
|
_addIframeToDom(iframe) {
|
|
@@ -335,17 +346,6 @@ class TransportIframe extends Transport {
|
|
|
335
346
|
bodyElement.appendChild(backdropElement);
|
|
336
347
|
bodyElement.appendChild(wrapperElement);
|
|
337
348
|
}
|
|
338
|
-
_listenFetchURLError(iframe) {
|
|
339
|
-
fetch(this._url).catch(() => {
|
|
340
|
-
iframe.addEventListener("load", () => {
|
|
341
|
-
if (!iframe.contentDocument) {
|
|
342
|
-
return;
|
|
343
|
-
}
|
|
344
|
-
this._renderErrorPage(iframe.contentDocument.body, () => this.dropConnection(), "The request could not be processed. To resume your further work, disable the installed plugins.");
|
|
345
|
-
this._showIframe();
|
|
346
|
-
});
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
349
|
}
|
|
350
350
|
class ProviderWeb {
|
|
351
351
|
constructor(clientUrl, logs) {
|
|
@@ -353,6 +353,8 @@ class ProviderWeb {
|
|
|
353
353
|
__publicField(this, "_transport");
|
|
354
354
|
__publicField(this, "_clientUrl");
|
|
355
355
|
__publicField(this, "emitter", new typedTsEvents.EventEmitter());
|
|
356
|
+
__publicField(this, "iframe");
|
|
357
|
+
__publicField(this, "win");
|
|
356
358
|
this._clientUrl = (clientUrl || "https://waves.exchange/signer/") + `?${ProviderWeb._getCacheClean()}`;
|
|
357
359
|
this._transport = new TransportIframe(this._clientUrl, 3);
|
|
358
360
|
if (logs === true) {
|
|
@@ -381,17 +383,23 @@ class ProviderWeb {
|
|
|
381
383
|
this.user = null;
|
|
382
384
|
return Promise.resolve(this._transport.dropConnection());
|
|
383
385
|
}
|
|
384
|
-
|
|
386
|
+
openWindow() {
|
|
385
387
|
var _a;
|
|
388
|
+
this.iframe = this._transport.get();
|
|
389
|
+
this.win = (_a = this.iframe.contentWindow) == null ? void 0 : _a.open(this._clientUrl);
|
|
390
|
+
this._transport.listenFetchURLError();
|
|
391
|
+
}
|
|
392
|
+
login() {
|
|
386
393
|
if (this.user) {
|
|
387
394
|
return Promise.resolve(this.user);
|
|
388
395
|
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
396
|
+
if (!this.win || !this.iframe) {
|
|
397
|
+
this.openWindow();
|
|
398
|
+
}
|
|
399
|
+
if (!this.win) {
|
|
392
400
|
throw new Error("Window was blocked");
|
|
393
401
|
}
|
|
394
|
-
iframe.src = `${this._clientUrl}?openWindow=true`;
|
|
402
|
+
this.iframe.src = `${this._clientUrl}?openWindow=true`;
|
|
395
403
|
return this._transport.dialog((bus) => bus.request("login").then((userData) => {
|
|
396
404
|
this.user = userData;
|
|
397
405
|
return userData;
|
package/dist/provider-web.es.js
CHANGED
|
@@ -157,6 +157,18 @@ class TransportIframe extends Transport {
|
|
|
157
157
|
}
|
|
158
158
|
return this._iframe;
|
|
159
159
|
}
|
|
160
|
+
listenFetchURLError() {
|
|
161
|
+
const iframe = this.get();
|
|
162
|
+
fetch(this._url).catch(() => {
|
|
163
|
+
this.get().addEventListener("load", () => {
|
|
164
|
+
if (!iframe.contentDocument) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
this._renderErrorPage(iframe.contentDocument.body, () => this.dropConnection(), "The request could not be processed. To resume your further work, disable the installed plugins.");
|
|
168
|
+
this._showIframe();
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
}
|
|
160
172
|
_dropTransportConnect() {
|
|
161
173
|
if (this._iframe != null) {
|
|
162
174
|
document.body.removeChild(this._iframe);
|
|
@@ -189,7 +201,6 @@ class TransportIframe extends Transport {
|
|
|
189
201
|
_initIframe() {
|
|
190
202
|
this._iframe = this._createIframe();
|
|
191
203
|
this._addIframeToDom(this._iframe);
|
|
192
|
-
this._listenFetchURLError(this._iframe);
|
|
193
204
|
this._hideIframe();
|
|
194
205
|
}
|
|
195
206
|
_addIframeToDom(iframe) {
|
|
@@ -332,17 +343,6 @@ class TransportIframe extends Transport {
|
|
|
332
343
|
bodyElement.appendChild(backdropElement);
|
|
333
344
|
bodyElement.appendChild(wrapperElement);
|
|
334
345
|
}
|
|
335
|
-
_listenFetchURLError(iframe) {
|
|
336
|
-
fetch(this._url).catch(() => {
|
|
337
|
-
iframe.addEventListener("load", () => {
|
|
338
|
-
if (!iframe.contentDocument) {
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
this._renderErrorPage(iframe.contentDocument.body, () => this.dropConnection(), "The request could not be processed. To resume your further work, disable the installed plugins.");
|
|
342
|
-
this._showIframe();
|
|
343
|
-
});
|
|
344
|
-
});
|
|
345
|
-
}
|
|
346
346
|
}
|
|
347
347
|
class ProviderWeb {
|
|
348
348
|
constructor(clientUrl, logs) {
|
|
@@ -350,6 +350,8 @@ class ProviderWeb {
|
|
|
350
350
|
__publicField(this, "_transport");
|
|
351
351
|
__publicField(this, "_clientUrl");
|
|
352
352
|
__publicField(this, "emitter", new EventEmitter());
|
|
353
|
+
__publicField(this, "iframe");
|
|
354
|
+
__publicField(this, "win");
|
|
353
355
|
this._clientUrl = (clientUrl || "https://waves.exchange/signer/") + `?${ProviderWeb._getCacheClean()}`;
|
|
354
356
|
this._transport = new TransportIframe(this._clientUrl, 3);
|
|
355
357
|
if (logs === true) {
|
|
@@ -378,17 +380,23 @@ class ProviderWeb {
|
|
|
378
380
|
this.user = null;
|
|
379
381
|
return Promise.resolve(this._transport.dropConnection());
|
|
380
382
|
}
|
|
381
|
-
|
|
383
|
+
openWindow() {
|
|
382
384
|
var _a;
|
|
385
|
+
this.iframe = this._transport.get();
|
|
386
|
+
this.win = (_a = this.iframe.contentWindow) == null ? void 0 : _a.open(this._clientUrl);
|
|
387
|
+
this._transport.listenFetchURLError();
|
|
388
|
+
}
|
|
389
|
+
login() {
|
|
383
390
|
if (this.user) {
|
|
384
391
|
return Promise.resolve(this.user);
|
|
385
392
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
393
|
+
if (!this.win || !this.iframe) {
|
|
394
|
+
this.openWindow();
|
|
395
|
+
}
|
|
396
|
+
if (!this.win) {
|
|
389
397
|
throw new Error("Window was blocked");
|
|
390
398
|
}
|
|
391
|
-
iframe.src = `${this._clientUrl}?openWindow=true`;
|
|
399
|
+
this.iframe.src = `${this._clientUrl}?openWindow=true`;
|
|
392
400
|
return this._transport.dialog((bus) => bus.request("login").then((userData) => {
|
|
393
401
|
this.user = userData;
|
|
394
402
|
return userData;
|
package/dist/provider-web.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var ct=Object.defineProperty,ut=Object.defineProperties;var lt=Object.getOwnPropertyDescriptors;var B=Object.getOwnPropertySymbols;var ht=Object.prototype.hasOwnProperty,dt=Object.prototype.propertyIsEnumerable;var T=(_,u,p)=>u in _?ct(_,u,{enumerable:!0,configurable:!0,writable:!0,value:p}):_[u]=p,D=(_,u)=>{for(var p in u||(u={}))ht.call(u,p)&&T(_,p,u[p]);if(B)for(var p of B(u))dt.call(u,p)&&T(_,p,u[p]);return _},U=(_,u)=>ut(_,lt(u));var v=(_,u,p)=>(T(_,typeof u!="symbol"?u+"":u,p),p);(function(_,u){typeof exports=="object"&&typeof module!="undefined"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(_=typeof globalThis!="undefined"?globalThis:_||self,u(_.providerWeb={}))})(this,function(_){"use strict";var u=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},p={},W={},S={},E={};Object.defineProperty(E,"__esModule",{value:!0});function V(o){return Object.keys(o)}E.keys=V;var z=Math.floor(Date.now()*Math.random()),F=0;function G(o){return o+"-"+z+"-"+F++}E.uniqueId=G;function N(o){return Array.isArray(o)?o:[o]}E.toArray=N;function $(){for(var o=[],t=0;t<arguments.length;t++)o[t]=arguments[t];return function(n){return o.reduce(function(r,e){return e(r)},n)}}E.pipe=$;var C={},j={};(function(o){Object.defineProperty(o,"__esModule",{value:!0}),function(t){(function(n){n.LOG_LEVEL={PRODUCTION:0,ERRORS:1,VERBOSE:2},n.logLevel=n.LOG_LEVEL.PRODUCTION,n.methodsData={log:{save:!1,logLevel:n.LOG_LEVEL.VERBOSE},info:{save:!1,logLevel:n.LOG_LEVEL.VERBOSE},warn:{save:!1,logLevel:n.LOG_LEVEL.VERBOSE},error:{save:!0,logLevel:n.LOG_LEVEL.ERRORS}}})(t.console||(t.console={}))}(o.config||(o.config={}))})(j);var x=u&&u.__assign||function(){return x=Object.assign||function(o){for(var t,n=1,r=arguments.length;n<r;n++){t=arguments[n];for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&(o[e]=t[e])}return o},x.apply(this,arguments)};Object.defineProperty(C,"__esModule",{value:!0});var m=j,Y=E,k=function(o){return o.console}(typeof self!="undefined"?self:u),b=Object.create(null);function Q(o){b[o]||(b[o]=[])}function K(o,t){b[o].push(t)}function J(){return Y.keys(m.config.console.methodsData).reduce(function(o,t){return o[t]=function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];m.config.console.logLevel<m.config.console.methodsData[t].logLevel?m.config.console.methodsData[t].save&&(Q(t),K(t,n)):k[t].apply(k,n)},o},Object.create(null))}C.console=x({},J(),{getSavedMessages:function(o){return b[o]||[]}});var I={};Object.defineProperty(I,"__esModule",{value:!0});var X=function(){function o(t){this.size=0,this.hash=Object.create(null),t&&t.forEach(this.add,this)}return o.prototype.add=function(t){return this.hash[t]=!0,this.size=Object.keys(this.hash).length,this},o.prototype.has=function(t){return t in this.hash},o.prototype.toArray=function(){return Object.keys(this.hash)},o}();I.UniqPrimitiveCollection=X,function(o){function t(n){for(var r in n)o.hasOwnProperty(r)||(o[r]=n[r])}Object.defineProperty(o,"__esModule",{value:!0}),t(E),t(C),t(I)}(S),function(o){Object.defineProperty(o,"__esModule",{value:!0});var t=S;(function(r){r[r.Event=0]="Event",r[r.Action=1]="Action",r[r.Response=2]="Response"})(o.EventType||(o.EventType={})),function(r){r[r.Success=0]="Success",r[r.Error=1]="Error"}(o.ResponseStatus||(o.ResponseStatus={}));var n=function(){function r(e,i){var s=this;this.id=t.uniqueId("bus"),this._timeout=i||5e3,this._adapter=e,this._adapter.addListener(function(a){return s._onMessage(a)}),this._eventHandlers=Object.create(null),this._activeRequestHash=Object.create(null),this._requestHandlers=Object.create(null),t.console.info('Create Bus with id "'+this.id+'"')}return r.prototype.dispatchEvent=function(e,i){return this._adapter.send(r._createEvent(e,i)),t.console.info('Dispatch event "'+e+'"',i),this},r.prototype.request=function(e,i,s){var a=this;return new Promise(function(c,l){var h=t.uniqueId(a.id+"-action"),d=s||a._timeout,f;(s||a._timeout)!==-1&&(f=setTimeout(function(){delete a._activeRequestHash[h];var g=new Error('Timeout error for request with name "'+e+'" and timeout '+d+"!");t.console.error(g),l(g)},d));var y=function(){f&&clearTimeout(f)};a._activeRequestHash[h]={reject:function(g){y(),t.console.error('Error request with name "'+e+'"',g),l(g)},resolve:function(g){y(),t.console.info('Request with name "'+e+'" success resolved!',g),c(g)}},a._adapter.send({id:h,type:1,name:e,data:i}),t.console.info('Request with name "'+e+'"',i)})},r.prototype.on=function(e,i,s){return this._addEventHandler(e,i,s,!1)},r.prototype.once=function(e,i,s){return this._addEventHandler(e,i,s,!0)},r.prototype.off=function(e,i){var s=this;return e?this._eventHandlers[e]?i?(this._eventHandlers[e]=this._eventHandlers[e].filter(function(a){return a.handler!==i}),this._eventHandlers[e].length||delete this._eventHandlers[e],this):(this._eventHandlers[e].slice().forEach(function(a){s.off(e,a.handler)}),this):this:(Object.keys(this._eventHandlers).forEach(function(a){return s.off(a,i)}),this)},r.prototype.registerRequestHandler=function(e,i){if(this._requestHandlers[e])throw new Error("Duplicate request handler!");return this._requestHandlers[e]=i,this},r.prototype.unregisterHandler=function(e){return this._requestHandlers[e]&&delete this._requestHandlers[e],this},r.prototype.changeAdapter=function(e){var i=this,s=new r(e,this._timeout);return Object.keys(this._eventHandlers).forEach(function(a){i._eventHandlers[a].forEach(function(c){c.once?s.once(a,c.handler,c.context):s.on(a,c.handler,c.context)})}),Object.keys(this._requestHandlers).forEach(function(a){s.registerRequestHandler(a,i._requestHandlers[a])}),s},r.prototype.destroy=function(){t.console.info("Destroy Bus"),this.off(),this._adapter.destroy()},r.prototype._addEventHandler=function(e,i,s,a){return this._eventHandlers[e]||(this._eventHandlers[e]=[]),this._eventHandlers[e].push({handler:i,once:a,context:s}),this},r.prototype._onMessage=function(e){switch(e.type){case 0:t.console.info('Has event with name "'+String(e.name)+'"',e.data),this._fireEvent(String(e.name),e.data);break;case 1:t.console.info('Start action with id "'+e.id+'" and name "'+String(e.name)+'"',e.data),this._createResponse(e);break;case 2:t.console.info('Start response with name "'+e.id+'" and status "'+e.status+'"',e.content),this._fireEndAction(e);break}},r.prototype._createResponse=function(e){var i=this,s=function(c){t.console.error(c),i._adapter.send({id:e.id,type:2,status:1,content:String(c)})};if(!this._requestHandlers[String(e.name)]){s(new Error('Has no handler for "'+String(e.name)+'" action!'));return}try{var a=this._requestHandlers[String(e.name)](e.data);r._isPromise(a)?a.then(function(c){i._adapter.send({id:e.id,type:2,status:0,content:c})},s):this._adapter.send({id:e.id,type:2,status:0,content:a})}catch(c){s(c)}},r.prototype._fireEndAction=function(e){if(this._activeRequestHash[e.id]){switch(e.status){case 1:this._activeRequestHash[e.id].reject(e.content);break;case 0:this._activeRequestHash[e.id].resolve(e.content);break}delete this._activeRequestHash[e.id]}},r.prototype._fireEvent=function(e,i){!this._eventHandlers[e]||(this._eventHandlers[e]=this._eventHandlers[e].slice().filter(function(s){try{s.handler.call(s.context,i)}catch(a){t.console.warn(a)}return!s.once}),this._eventHandlers[e].length||delete this._eventHandlers[e])},r._createEvent=function(e,i){return{type:0,name:e,data:i}},r._isPromise=function(e){return e&&e.then&&typeof e.then=="function"},r}();o.Bus=n}(W);var O={};Object.defineProperty(O,"__esModule",{value:!0});var Z=function(){function o(){}return o}();O.Adapter=Z;var H={},q={},A={exports:{}};(function(o,t){(function(n,r){o.exports=r()})(u,function(){return(()=>{var n={660:(e,i)=>{i.__esModule=!0,i.EventEmitter=void 0;var s=function(){function a(c){this._events=Object.create(null),this.catchHandler=c||function(){}}return a.prototype.hasListeners=function(c){return!(!this._events[c]||!this._events[c].length)},a.prototype.getActiveEvents=function(){var c=this;return Object.keys(this._events).filter(function(l){return c.hasListeners(l)})},a.prototype.trigger=function(c,l){var h=this;this._events[c]&&(this._events[c].slice().forEach(function(d){try{d.handler.call(d.context,l)}catch(f){h.catchHandler(f)}d.once&&h.off(c,d.handler)}),this._events[c].length||delete this._events[c])},a.prototype.on=function(c,l,h){this._on(c,l,h,!1)},a.prototype.once=function(c,l,h){this._on(c,l,h,!0)},a.prototype.off=function(c,l){var h=this,d=typeof c=="string"?c:null,f=typeof l=="function"?l:typeof c=="function"?c:null;if(d)if(f){if(d in this._events){var y=this._events[d].map(function(g){return g.handler}).indexOf(f);this._events[d].splice(y,1)}}else delete this._events[d];else Object.keys(this._events).forEach(function(g){h.off(g,f)})},a.prototype._on=function(c,l,h,d){this._events[c]||(this._events[c]=[]),this._events[c].push({handler:l,context:h,once:d})},a}();i.EventEmitter=s},607:function(e,i,s){var a=this&&this.__createBinding||(Object.create?function(h,d,f,y){y===void 0&&(y=f),Object.defineProperty(h,y,{enumerable:!0,get:function(){return d[f]}})}:function(h,d,f,y){y===void 0&&(y=f),h[y]=d[f]}),c=this&&this.__exportStar||function(h,d){for(var f in h)f==="default"||Object.prototype.hasOwnProperty.call(d,f)||a(d,h,f)};i.__esModule=!0;var l=s(660);c(s(660),i),i.default=l.EventEmitter}},r={};return function e(i){if(r[i])return r[i].exports;var s=r[i]={exports:{}};return n[i].call(s.exports,s,s.exports,e),s.exports}(607)})()})})(A),function(o){var t=u&&u.__extends||function(){var e=function(i,s){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(a,c){a.__proto__=c}||function(a,c){for(var l in c)c.hasOwnProperty(l)&&(a[l]=c[l])},e(i,s)};return function(i,s){e(i,s);function a(){this.constructor=i}i.prototype=s===null?Object.create(s):(a.prototype=s.prototype,new a)}}();Object.defineProperty(o,"__esModule",{value:!0});var n=A.exports,r=function(e){t(i,e);function i(s,a){var c=e.call(this)||this;return c.win=s,c.type=a,c.handler=function(l){c.trigger("message",l)},a===i.PROTOCOL_TYPES.LISTEN&&c.win.addEventListener("message",c.handler,!1),c}return i.prototype.dispatch=function(s){return this.win.postMessage(s,"*"),this},i.prototype.destroy=function(){this.type===i.PROTOCOL_TYPES.LISTEN&&this.win.removeEventListener("message",this.handler,!1),this.win=i._fakeWin},i._fakeWin=function(){var s=function(){return null};return{postMessage:s,addEventListener:s,removeEventListener:s}}(),i}(n.EventEmitter);o.WindowProtocol=r,function(e){e.PROTOCOL_TYPES={LISTEN:"listen",DISPATCH:"dispatch"}}(r=o.WindowProtocol||(o.WindowProtocol={})),o.WindowProtocol=r}(q);var tt=u&&u.__extends||function(){var o=function(t,n){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,e){r.__proto__=e}||function(r,e){for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i])},o(t,n)};return function(t,n){o(t,n);function r(){this.constructor=t}t.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}}(),P=u&&u.__assign||function(){return P=Object.assign||function(o){for(var t,n=1,r=arguments.length;n<r;n++){t=arguments[n];for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&(o[e]=t[e])}return o},P.apply(this,arguments)};Object.defineProperty(H,"__esModule",{value:!0});var et=O,w=p,L=q,nt=E,rt={origins:[],availableChanelId:[]},it=function(o){tt(t,o);function t(n,r,e){var i=o.call(this)||this;return i.id=w.uniqueId("wa"),i.callbacks=[],i.options=t.prepareOptions(e),i.listen=n,i.dispatch=r,i.listen.forEach(function(s){return s.on("message",i.onMessage,i)}),i}return t.prototype.addListener=function(n){return this.callbacks.push(n),w.console.info("WindowAdapter: Add iframe message listener"),this},t.prototype.send=function(n){var r=P({},n,{chanelId:this.options.chanelId});return this.dispatch.forEach(function(e){return e.dispatch(r)}),w.console.info("WindowAdapter: Send message",r),this},t.prototype.destroy=function(){this.listen.forEach(function(n){return n.destroy()}),this.dispatch.forEach(function(n){return n.destroy()}),w.console.info("WindowAdapter: Destroy")},t.prototype.onMessage=function(n){this.accessEvent(n)&&this.callbacks.forEach(function(r){try{r(n.data)}catch(e){w.console.warn("WindowAdapter: Unhandled exception!",e)}})},t.prototype.accessEvent=function(n){if(typeof n.data!="object"||n.data.type==null)return w.console.info("WindowAdapter: Block event. Wrong event format!",n.data),!1;if(!this.options.origins.has("*")&&!this.options.origins.has(n.origin))return w.console.info('SimpleWindowAdapter: Block event by origin "'+n.origin+'"'),!1;if(!this.options.availableChanelId.size)return!0;var r=!!(n.data.chanelId&&this.options.availableChanelId.has(n.data.chanelId));return r||w.console.info('SimpleWindowAdapter: Block event by chanel id "'+n.data.chanelId+'"'),r},t.createSimpleWindowAdapter=function(n,r){var e=this,i=this.getContentOrigin(n),s=this.prepareOptions(r),a=[];i&&s.origins.add(i);var c=new L.WindowProtocol(window,L.WindowProtocol.PROTOCOL_TYPES.LISTEN),l=function(h){a.push(h)};return c.on("message",l),this.getIframeContent(n).then(function(h){var d=new L.WindowProtocol(h.win,L.WindowProtocol.PROTOCOL_TYPES.DISPATCH),f=new t([c],[d],e.unPrepareOptions(s));return a.forEach(function(y){f.onMessage(y)}),c.off("message",l),f})},t.prepareOptions=function(n){n===void 0&&(n=rt);var r=function(a){return function(c){return c.reduce(function(l,h){return l.add(h)},a)}},e=function(a,c){return nt.pipe(w.toArray,r(c))(a)},i=e(n.origins||[],new w.UniqPrimitiveCollection([window.location.origin])),s=e(n.availableChanelId||[],new w.UniqPrimitiveCollection);return P({},n,{origins:i,availableChanelId:s})},t.unPrepareOptions=function(n){return{origins:n.origins.toArray(),availableChanelId:n.availableChanelId.toArray(),chanelId:n.chanelId}},t.getIframeContent=function(n){return n?n instanceof HTMLIFrameElement?n.contentWindow?Promise.resolve({win:n.contentWindow}):new Promise(function(r,e){n.addEventListener("load",function(){return r({win:n.contentWindow})},!1),n.addEventListener("error",e,!1)}):Promise.resolve({win:n}):Promise.resolve({win:window.opener||window.parent})},t.getContentOrigin=function(n){if(!n)try{return new URL(document.referrer).origin}catch{return null}if(!(n instanceof HTMLIFrameElement))try{return window.top.origin}catch{return null}try{return new URL(n.src).origin||null}catch{return null}},t}(et.Adapter);H.WindowAdapter=it,function(o){function t(n){for(var r in n)o.hasOwnProperty(r)||(o[r]=n[r])}Object.defineProperty(o,"__esModule",{value:!0}),t(W),t(O),t(H),t(q),t(j),t(S)}(p);class ot{constructor(t){v(this,"_actions",[]);v(this,"_maxLength");v(this,"_active");this._maxLength=t}get length(){return this._actions.length+(this._active==null?0:1)}push(t){if(this._actions.length>=this._maxLength)throw new Error("Cant't push action! Queue is full!");return new Promise((n,r)=>{const e=()=>{this._active=void 0;const s=this._actions.map(a=>a.action).indexOf(i);s!==-1&&this._actions.splice(s,1),this.run()},i=()=>t().then(s=>{e(),n(s)},s=>{e(),r(s)});this._actions.push({action:i,reject:r}),this.length===1&&this.run()})}clear(t){t=t||new Error("Rejection with clear queue!");const n=typeof t=="string"?new Error(t):t;this._actions.splice(0,this._actions.length).forEach(r=>r.reject(n)),this._active=void 0}canPush(){return this._actions.length<this._maxLength}run(){const t=this._actions.shift();t!=null&&(this._active=t.action())}}const M=o=>o&&o.message==="SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document."?U(D({},o),{message:"Local storage is not available! It is possible that the Browser is in incognito mode!"}):o;class st{constructor(t){v(this,"_queue");v(this,"_events",[]);v(this,"_toRunEvents",[]);this._queue=new ot(t)}dropConnection(){this._queue.clear(new Error("User rejection!")),this._events.forEach(t=>this._toRunEvents.push(t)),this._dropTransportConnect()}sendEvent(t){this._events.push(t),this._toRunEvents.push(t)}dialog(t){return this._runBeforeShow(),this._getBus().then(n=>{const r=this._wrapAction(()=>t(n));return this._runEvents(n),this._queue.canPush()?this._queue.push(r).then(e=>(this._runAfterShow(),e)).catch(e=>(this._runAfterShow(),Promise.reject(M(e)))):Promise.reject(new Error("Queue is full!"))})}_runBeforeShow(){this._queue.length===0&&this._beforeShow()}_runAfterShow(){this._queue.length===0&&this._afterShow()}_runEvents(t){this._toRunEvents.splice(0,this._events.length).forEach(n=>n(t))}_wrapAction(t){return this._toRunEvents?()=>{const n=t();return n.catch(()=>{this._events.forEach(r=>this._toRunEvents.push(r))}),n}:t}}class at extends st{constructor(t,n){super(n);v(this,"_timer",null);v(this,"_url");v(this,"_iframe");v(this,"_bus");this._url=t,this._initIframe()}get(){return this._iframe||this._initIframe(),this._iframe}_dropTransportConnect(){this._iframe!=null&&(document.body.removeChild(this._iframe),this._initIframe()),this._bus&&(this._bus.destroy(),this._bus=void 0)}_getBus(){return this._bus?Promise.resolve(this._bus):p.WindowAdapter.createSimpleWindowAdapter(this._iframe,{origins:["https://wx.network","https://testnet.wx.network"]}).then(t=>new Promise(n=>{this._bus=new p.Bus(t,-1),this._bus.once("ready",()=>{n(this._bus)})}))}_beforeShow(){this._showIframe()}_afterShow(){this._hideIframe()}_initIframe(){this._iframe=this._createIframe(),this._addIframeToDom(this._iframe),this._listenFetchURLError(this._iframe),this._hideIframe()}_addIframeToDom(t){document.body!=null?document.body.appendChild(t):document.addEventListener("DOMContentLoaded",()=>{document.body.appendChild(t)})}_createIframe(){const t=document.createElement("iframe");return t.style.transition="opacity .2s",t.style.position="absolute",t.style.opacity="0",t.style.width="100%",t.style.height="100%",t.style.left="0",t.style.top="0",t.style.border="none",t.style.position="fixed",t}_showIframe(){const t={width:"100%",height:"100%",left:"0",top:"0",border:"none",position:"fixed",display:"block",opacity:"0",zIndex:"99999999"};this._applyStyle(t),this._timer!=null&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._applyStyle({opacity:"1"})},0)}_hideIframe(){const t={opacity:"0"};this._applyStyle(t),this._timer!=null&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._applyStyle({width:"10px",height:"10px",left:"-100px",top:"-100px",position:"absolute",opacity:"0",zIndex:"0",display:"none"})},200)}_applyStyle(t){Object.entries(t).forEach(([n,r])=>{r!=null&&this._iframe&&(this._iframe.style[n]=r)})}_renderErrorPage(t,n,r){t.parentElement&&(t.parentElement.style.height="100%"),Object.assign(t.style,{position:"relative",boxSizing:"border-box",width:"100%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center",margin:"0px"});const e=document.createElement("div");Object.assign(e.style,{position:"fixed",zIndex:"-1",height:"100%",width:"100%",overflow:"hidden",backgroundColor:"#000",opacity:"0.6"});const i=document.createElement("div");Object.assign(i.style,{position:"fixed",display:"flex",justifyContent:"center",alignItems:"center",flexDirection:"column",margin:"0",backgroundColor:"#292F3C",width:"520px",borderRadius:"6px",padding:"40px",boxSizing:"border-box"});const s=document.createElement("div");s.textContent=r,Object.assign(s.style,{fontSize:"15px",lineHeight:"20px",color:"#fff",marginBottom:"40px",fontFamily:"Roboto, sans-serif"});const a=document.createElement("button");a.textContent="OK",a.addEventListener("click",()=>n()),Object.assign(a.style,{width:"100%",fontSize:"15px",lineHeight:"48px",padding:" 0 40px",color:"#fff",backgroundColor:"#5A81EA",outline:"none",border:"none",cursor:"pointer",fontFamily:"Roboto, sans-serif",borderRadius:"4px"}),i.appendChild(s),i.appendChild(a),t.appendChild(e),t.appendChild(i)}_listenFetchURLError(t){fetch(this._url).catch(()=>{t.addEventListener("load",()=>{!t.contentDocument||(this._renderErrorPage(t.contentDocument.body,()=>this.dropConnection(),"The request could not be processed. To resume your further work, disable the installed plugins."),this._showIframe())})})}}class R{constructor(t,n){v(this,"user",null);v(this,"_transport");v(this,"_clientUrl");v(this,"emitter",new A.exports.EventEmitter);this._clientUrl=(t||"https://waves.exchange/signer/")+`?${R._getCacheClean()}`,this._transport=new at(this._clientUrl,3),n===!0&&(p.config.console.logLevel=p.config.console.LOG_LEVEL.VERBOSE)}static _getCacheClean(){return String(Date.now()%(1e3*60))}on(t,n){return this.emitter.on(t,n),this}once(t,n){return this.emitter.once(t,n),this}off(t,n){return this.emitter.once(t,n),this}connect(t){return Promise.resolve(this._transport.sendEvent(n=>n.dispatchEvent("connect",t)))}logout(){return this.user=null,Promise.resolve(this._transport.dropConnection())}login(){var r;if(this.user)return Promise.resolve(this.user);const t=this._transport.get();if(!((r=t.contentWindow)==null?void 0:r.open(this._clientUrl)))throw new Error("Window was blocked");return t.src=`${this._clientUrl}?openWindow=true`,this._transport.dialog(e=>e.request("login").then(i=>(this.user=i,i)).catch(i=>(this._transport.dropConnection(),Promise.reject(M(i)))))}signMessage(t){return this.login().then(()=>this._transport.dialog(n=>n.request("sign-message",t)))}signTypedData(t){return this.login().then(()=>this._transport.dialog(n=>n.request("sign-typed-data",t)))}sign(t){return this.login().then(()=>this._transport.dialog(n=>n.request("sign",t)))}}_.ProviderWeb=R,Object.defineProperty(_,"__esModule",{value:!0}),_[Symbol.toStringTag]="Module"});
|
|
1
|
+
var ct=Object.defineProperty,ut=Object.defineProperties;var ht=Object.getOwnPropertyDescriptors;var B=Object.getOwnPropertySymbols;var lt=Object.prototype.hasOwnProperty,dt=Object.prototype.propertyIsEnumerable;var T=(_,u,p)=>u in _?ct(_,u,{enumerable:!0,configurable:!0,writable:!0,value:p}):_[u]=p,D=(_,u)=>{for(var p in u||(u={}))lt.call(u,p)&&T(_,p,u[p]);if(B)for(var p of B(u))dt.call(u,p)&&T(_,p,u[p]);return _},U=(_,u)=>ut(_,ht(u));var v=(_,u,p)=>(T(_,typeof u!="symbol"?u+"":u,p),p);(function(_,u){typeof exports=="object"&&typeof module!="undefined"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(_=typeof globalThis!="undefined"?globalThis:_||self,u(_.providerWeb={}))})(this,function(_){"use strict";var u=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},p={},W={},S={},m={};Object.defineProperty(m,"__esModule",{value:!0});function V(o){return Object.keys(o)}m.keys=V;var z=Math.floor(Date.now()*Math.random()),F=0;function G(o){return o+"-"+z+"-"+F++}m.uniqueId=G;function N(o){return Array.isArray(o)?o:[o]}m.toArray=N;function $(){for(var o=[],t=0;t<arguments.length;t++)o[t]=arguments[t];return function(e){return o.reduce(function(i,n){return n(i)},e)}}m.pipe=$;var C={},j={};(function(o){Object.defineProperty(o,"__esModule",{value:!0}),function(t){(function(e){e.LOG_LEVEL={PRODUCTION:0,ERRORS:1,VERBOSE:2},e.logLevel=e.LOG_LEVEL.PRODUCTION,e.methodsData={log:{save:!1,logLevel:e.LOG_LEVEL.VERBOSE},info:{save:!1,logLevel:e.LOG_LEVEL.VERBOSE},warn:{save:!1,logLevel:e.LOG_LEVEL.VERBOSE},error:{save:!0,logLevel:e.LOG_LEVEL.ERRORS}}})(t.console||(t.console={}))}(o.config||(o.config={}))})(j);var x=u&&u.__assign||function(){return x=Object.assign||function(o){for(var t,e=1,i=arguments.length;e<i;e++){t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(o[n]=t[n])}return o},x.apply(this,arguments)};Object.defineProperty(C,"__esModule",{value:!0});var E=j,Y=m,k=function(o){return o.console}(typeof self!="undefined"?self:u),b=Object.create(null);function Q(o){b[o]||(b[o]=[])}function K(o,t){b[o].push(t)}function J(){return Y.keys(E.config.console.methodsData).reduce(function(o,t){return o[t]=function(){for(var e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];E.config.console.logLevel<E.config.console.methodsData[t].logLevel?E.config.console.methodsData[t].save&&(Q(t),K(t,e)):k[t].apply(k,e)},o},Object.create(null))}C.console=x({},J(),{getSavedMessages:function(o){return b[o]||[]}});var I={};Object.defineProperty(I,"__esModule",{value:!0});var X=function(){function o(t){this.size=0,this.hash=Object.create(null),t&&t.forEach(this.add,this)}return o.prototype.add=function(t){return this.hash[t]=!0,this.size=Object.keys(this.hash).length,this},o.prototype.has=function(t){return t in this.hash},o.prototype.toArray=function(){return Object.keys(this.hash)},o}();I.UniqPrimitiveCollection=X,function(o){function t(e){for(var i in e)o.hasOwnProperty(i)||(o[i]=e[i])}Object.defineProperty(o,"__esModule",{value:!0}),t(m),t(C),t(I)}(S),function(o){Object.defineProperty(o,"__esModule",{value:!0});var t=S;(function(i){i[i.Event=0]="Event",i[i.Action=1]="Action",i[i.Response=2]="Response"})(o.EventType||(o.EventType={})),function(i){i[i.Success=0]="Success",i[i.Error=1]="Error"}(o.ResponseStatus||(o.ResponseStatus={}));var e=function(){function i(n,r){var s=this;this.id=t.uniqueId("bus"),this._timeout=r||5e3,this._adapter=n,this._adapter.addListener(function(a){return s._onMessage(a)}),this._eventHandlers=Object.create(null),this._activeRequestHash=Object.create(null),this._requestHandlers=Object.create(null),t.console.info('Create Bus with id "'+this.id+'"')}return i.prototype.dispatchEvent=function(n,r){return this._adapter.send(i._createEvent(n,r)),t.console.info('Dispatch event "'+n+'"',r),this},i.prototype.request=function(n,r,s){var a=this;return new Promise(function(c,h){var l=t.uniqueId(a.id+"-action"),d=s||a._timeout,f;(s||a._timeout)!==-1&&(f=setTimeout(function(){delete a._activeRequestHash[l];var g=new Error('Timeout error for request with name "'+n+'" and timeout '+d+"!");t.console.error(g),h(g)},d));var y=function(){f&&clearTimeout(f)};a._activeRequestHash[l]={reject:function(g){y(),t.console.error('Error request with name "'+n+'"',g),h(g)},resolve:function(g){y(),t.console.info('Request with name "'+n+'" success resolved!',g),c(g)}},a._adapter.send({id:l,type:1,name:n,data:r}),t.console.info('Request with name "'+n+'"',r)})},i.prototype.on=function(n,r,s){return this._addEventHandler(n,r,s,!1)},i.prototype.once=function(n,r,s){return this._addEventHandler(n,r,s,!0)},i.prototype.off=function(n,r){var s=this;return n?this._eventHandlers[n]?r?(this._eventHandlers[n]=this._eventHandlers[n].filter(function(a){return a.handler!==r}),this._eventHandlers[n].length||delete this._eventHandlers[n],this):(this._eventHandlers[n].slice().forEach(function(a){s.off(n,a.handler)}),this):this:(Object.keys(this._eventHandlers).forEach(function(a){return s.off(a,r)}),this)},i.prototype.registerRequestHandler=function(n,r){if(this._requestHandlers[n])throw new Error("Duplicate request handler!");return this._requestHandlers[n]=r,this},i.prototype.unregisterHandler=function(n){return this._requestHandlers[n]&&delete this._requestHandlers[n],this},i.prototype.changeAdapter=function(n){var r=this,s=new i(n,this._timeout);return Object.keys(this._eventHandlers).forEach(function(a){r._eventHandlers[a].forEach(function(c){c.once?s.once(a,c.handler,c.context):s.on(a,c.handler,c.context)})}),Object.keys(this._requestHandlers).forEach(function(a){s.registerRequestHandler(a,r._requestHandlers[a])}),s},i.prototype.destroy=function(){t.console.info("Destroy Bus"),this.off(),this._adapter.destroy()},i.prototype._addEventHandler=function(n,r,s,a){return this._eventHandlers[n]||(this._eventHandlers[n]=[]),this._eventHandlers[n].push({handler:r,once:a,context:s}),this},i.prototype._onMessage=function(n){switch(n.type){case 0:t.console.info('Has event with name "'+String(n.name)+'"',n.data),this._fireEvent(String(n.name),n.data);break;case 1:t.console.info('Start action with id "'+n.id+'" and name "'+String(n.name)+'"',n.data),this._createResponse(n);break;case 2:t.console.info('Start response with name "'+n.id+'" and status "'+n.status+'"',n.content),this._fireEndAction(n);break}},i.prototype._createResponse=function(n){var r=this,s=function(c){t.console.error(c),r._adapter.send({id:n.id,type:2,status:1,content:String(c)})};if(!this._requestHandlers[String(n.name)]){s(new Error('Has no handler for "'+String(n.name)+'" action!'));return}try{var a=this._requestHandlers[String(n.name)](n.data);i._isPromise(a)?a.then(function(c){r._adapter.send({id:n.id,type:2,status:0,content:c})},s):this._adapter.send({id:n.id,type:2,status:0,content:a})}catch(c){s(c)}},i.prototype._fireEndAction=function(n){if(this._activeRequestHash[n.id]){switch(n.status){case 1:this._activeRequestHash[n.id].reject(n.content);break;case 0:this._activeRequestHash[n.id].resolve(n.content);break}delete this._activeRequestHash[n.id]}},i.prototype._fireEvent=function(n,r){!this._eventHandlers[n]||(this._eventHandlers[n]=this._eventHandlers[n].slice().filter(function(s){try{s.handler.call(s.context,r)}catch(a){t.console.warn(a)}return!s.once}),this._eventHandlers[n].length||delete this._eventHandlers[n])},i._createEvent=function(n,r){return{type:0,name:n,data:r}},i._isPromise=function(n){return n&&n.then&&typeof n.then=="function"},i}();o.Bus=e}(W);var O={};Object.defineProperty(O,"__esModule",{value:!0});var Z=function(){function o(){}return o}();O.Adapter=Z;var H={},q={},A={exports:{}};(function(o,t){(function(e,i){o.exports=i()})(u,function(){return(()=>{var e={660:(n,r)=>{r.__esModule=!0,r.EventEmitter=void 0;var s=function(){function a(c){this._events=Object.create(null),this.catchHandler=c||function(){}}return a.prototype.hasListeners=function(c){return!(!this._events[c]||!this._events[c].length)},a.prototype.getActiveEvents=function(){var c=this;return Object.keys(this._events).filter(function(h){return c.hasListeners(h)})},a.prototype.trigger=function(c,h){var l=this;this._events[c]&&(this._events[c].slice().forEach(function(d){try{d.handler.call(d.context,h)}catch(f){l.catchHandler(f)}d.once&&l.off(c,d.handler)}),this._events[c].length||delete this._events[c])},a.prototype.on=function(c,h,l){this._on(c,h,l,!1)},a.prototype.once=function(c,h,l){this._on(c,h,l,!0)},a.prototype.off=function(c,h){var l=this,d=typeof c=="string"?c:null,f=typeof h=="function"?h:typeof c=="function"?c:null;if(d)if(f){if(d in this._events){var y=this._events[d].map(function(g){return g.handler}).indexOf(f);this._events[d].splice(y,1)}}else delete this._events[d];else Object.keys(this._events).forEach(function(g){l.off(g,f)})},a.prototype._on=function(c,h,l,d){this._events[c]||(this._events[c]=[]),this._events[c].push({handler:h,context:l,once:d})},a}();r.EventEmitter=s},607:function(n,r,s){var a=this&&this.__createBinding||(Object.create?function(l,d,f,y){y===void 0&&(y=f),Object.defineProperty(l,y,{enumerable:!0,get:function(){return d[f]}})}:function(l,d,f,y){y===void 0&&(y=f),l[y]=d[f]}),c=this&&this.__exportStar||function(l,d){for(var f in l)f==="default"||Object.prototype.hasOwnProperty.call(d,f)||a(d,l,f)};r.__esModule=!0;var h=s(660);c(s(660),r),r.default=h.EventEmitter}},i={};return function n(r){if(i[r])return i[r].exports;var s=i[r]={exports:{}};return e[r].call(s.exports,s,s.exports,n),s.exports}(607)})()})})(A),function(o){var t=u&&u.__extends||function(){var n=function(r,s){return n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(a,c){a.__proto__=c}||function(a,c){for(var h in c)c.hasOwnProperty(h)&&(a[h]=c[h])},n(r,s)};return function(r,s){n(r,s);function a(){this.constructor=r}r.prototype=s===null?Object.create(s):(a.prototype=s.prototype,new a)}}();Object.defineProperty(o,"__esModule",{value:!0});var e=A.exports,i=function(n){t(r,n);function r(s,a){var c=n.call(this)||this;return c.win=s,c.type=a,c.handler=function(h){c.trigger("message",h)},a===r.PROTOCOL_TYPES.LISTEN&&c.win.addEventListener("message",c.handler,!1),c}return r.prototype.dispatch=function(s){return this.win.postMessage(s,"*"),this},r.prototype.destroy=function(){this.type===r.PROTOCOL_TYPES.LISTEN&&this.win.removeEventListener("message",this.handler,!1),this.win=r._fakeWin},r._fakeWin=function(){var s=function(){return null};return{postMessage:s,addEventListener:s,removeEventListener:s}}(),r}(e.EventEmitter);o.WindowProtocol=i,function(n){n.PROTOCOL_TYPES={LISTEN:"listen",DISPATCH:"dispatch"}}(i=o.WindowProtocol||(o.WindowProtocol={})),o.WindowProtocol=i}(q);var tt=u&&u.__extends||function(){var o=function(t,e){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,n){i.__proto__=n}||function(i,n){for(var r in n)n.hasOwnProperty(r)&&(i[r]=n[r])},o(t,e)};return function(t,e){o(t,e);function i(){this.constructor=t}t.prototype=e===null?Object.create(e):(i.prototype=e.prototype,new i)}}(),P=u&&u.__assign||function(){return P=Object.assign||function(o){for(var t,e=1,i=arguments.length;e<i;e++){t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(o[n]=t[n])}return o},P.apply(this,arguments)};Object.defineProperty(H,"__esModule",{value:!0});var et=O,w=p,L=q,nt=m,it={origins:[],availableChanelId:[]},rt=function(o){tt(t,o);function t(e,i,n){var r=o.call(this)||this;return r.id=w.uniqueId("wa"),r.callbacks=[],r.options=t.prepareOptions(n),r.listen=e,r.dispatch=i,r.listen.forEach(function(s){return s.on("message",r.onMessage,r)}),r}return t.prototype.addListener=function(e){return this.callbacks.push(e),w.console.info("WindowAdapter: Add iframe message listener"),this},t.prototype.send=function(e){var i=P({},e,{chanelId:this.options.chanelId});return this.dispatch.forEach(function(n){return n.dispatch(i)}),w.console.info("WindowAdapter: Send message",i),this},t.prototype.destroy=function(){this.listen.forEach(function(e){return e.destroy()}),this.dispatch.forEach(function(e){return e.destroy()}),w.console.info("WindowAdapter: Destroy")},t.prototype.onMessage=function(e){this.accessEvent(e)&&this.callbacks.forEach(function(i){try{i(e.data)}catch(n){w.console.warn("WindowAdapter: Unhandled exception!",n)}})},t.prototype.accessEvent=function(e){if(typeof e.data!="object"||e.data.type==null)return w.console.info("WindowAdapter: Block event. Wrong event format!",e.data),!1;if(!this.options.origins.has("*")&&!this.options.origins.has(e.origin))return w.console.info('SimpleWindowAdapter: Block event by origin "'+e.origin+'"'),!1;if(!this.options.availableChanelId.size)return!0;var i=!!(e.data.chanelId&&this.options.availableChanelId.has(e.data.chanelId));return i||w.console.info('SimpleWindowAdapter: Block event by chanel id "'+e.data.chanelId+'"'),i},t.createSimpleWindowAdapter=function(e,i){var n=this,r=this.getContentOrigin(e),s=this.prepareOptions(i),a=[];r&&s.origins.add(r);var c=new L.WindowProtocol(window,L.WindowProtocol.PROTOCOL_TYPES.LISTEN),h=function(l){a.push(l)};return c.on("message",h),this.getIframeContent(e).then(function(l){var d=new L.WindowProtocol(l.win,L.WindowProtocol.PROTOCOL_TYPES.DISPATCH),f=new t([c],[d],n.unPrepareOptions(s));return a.forEach(function(y){f.onMessage(y)}),c.off("message",h),f})},t.prepareOptions=function(e){e===void 0&&(e=it);var i=function(a){return function(c){return c.reduce(function(h,l){return h.add(l)},a)}},n=function(a,c){return nt.pipe(w.toArray,i(c))(a)},r=n(e.origins||[],new w.UniqPrimitiveCollection([window.location.origin])),s=n(e.availableChanelId||[],new w.UniqPrimitiveCollection);return P({},e,{origins:r,availableChanelId:s})},t.unPrepareOptions=function(e){return{origins:e.origins.toArray(),availableChanelId:e.availableChanelId.toArray(),chanelId:e.chanelId}},t.getIframeContent=function(e){return e?e instanceof HTMLIFrameElement?e.contentWindow?Promise.resolve({win:e.contentWindow}):new Promise(function(i,n){e.addEventListener("load",function(){return i({win:e.contentWindow})},!1),e.addEventListener("error",n,!1)}):Promise.resolve({win:e}):Promise.resolve({win:window.opener||window.parent})},t.getContentOrigin=function(e){if(!e)try{return new URL(document.referrer).origin}catch{return null}if(!(e instanceof HTMLIFrameElement))try{return window.top.origin}catch{return null}try{return new URL(e.src).origin||null}catch{return null}},t}(et.Adapter);H.WindowAdapter=rt,function(o){function t(e){for(var i in e)o.hasOwnProperty(i)||(o[i]=e[i])}Object.defineProperty(o,"__esModule",{value:!0}),t(W),t(O),t(H),t(q),t(j),t(S)}(p);class ot{constructor(t){v(this,"_actions",[]);v(this,"_maxLength");v(this,"_active");this._maxLength=t}get length(){return this._actions.length+(this._active==null?0:1)}push(t){if(this._actions.length>=this._maxLength)throw new Error("Cant't push action! Queue is full!");return new Promise((e,i)=>{const n=()=>{this._active=void 0;const s=this._actions.map(a=>a.action).indexOf(r);s!==-1&&this._actions.splice(s,1),this.run()},r=()=>t().then(s=>{n(),e(s)},s=>{n(),i(s)});this._actions.push({action:r,reject:i}),this.length===1&&this.run()})}clear(t){t=t||new Error("Rejection with clear queue!");const e=typeof t=="string"?new Error(t):t;this._actions.splice(0,this._actions.length).forEach(i=>i.reject(e)),this._active=void 0}canPush(){return this._actions.length<this._maxLength}run(){const t=this._actions.shift();t!=null&&(this._active=t.action())}}const M=o=>o&&o.message==="SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document."?U(D({},o),{message:"Local storage is not available! It is possible that the Browser is in incognito mode!"}):o;class st{constructor(t){v(this,"_queue");v(this,"_events",[]);v(this,"_toRunEvents",[]);this._queue=new ot(t)}dropConnection(){this._queue.clear(new Error("User rejection!")),this._events.forEach(t=>this._toRunEvents.push(t)),this._dropTransportConnect()}sendEvent(t){this._events.push(t),this._toRunEvents.push(t)}dialog(t){return this._runBeforeShow(),this._getBus().then(e=>{const i=this._wrapAction(()=>t(e));return this._runEvents(e),this._queue.canPush()?this._queue.push(i).then(n=>(this._runAfterShow(),n)).catch(n=>(this._runAfterShow(),Promise.reject(M(n)))):Promise.reject(new Error("Queue is full!"))})}_runBeforeShow(){this._queue.length===0&&this._beforeShow()}_runAfterShow(){this._queue.length===0&&this._afterShow()}_runEvents(t){this._toRunEvents.splice(0,this._events.length).forEach(e=>e(t))}_wrapAction(t){return this._toRunEvents?()=>{const e=t();return e.catch(()=>{this._events.forEach(i=>this._toRunEvents.push(i))}),e}:t}}class at extends st{constructor(t,e){super(e);v(this,"_timer",null);v(this,"_url");v(this,"_iframe");v(this,"_bus");this._url=t,this._initIframe()}get(){return this._iframe||this._initIframe(),this._iframe}listenFetchURLError(){const t=this.get();fetch(this._url).catch(()=>{this.get().addEventListener("load",()=>{!t.contentDocument||(this._renderErrorPage(t.contentDocument.body,()=>this.dropConnection(),"The request could not be processed. To resume your further work, disable the installed plugins."),this._showIframe())})})}_dropTransportConnect(){this._iframe!=null&&(document.body.removeChild(this._iframe),this._initIframe()),this._bus&&(this._bus.destroy(),this._bus=void 0)}_getBus(){return this._bus?Promise.resolve(this._bus):p.WindowAdapter.createSimpleWindowAdapter(this._iframe,{origins:["https://wx.network","https://testnet.wx.network"]}).then(t=>new Promise(e=>{this._bus=new p.Bus(t,-1),this._bus.once("ready",()=>{e(this._bus)})}))}_beforeShow(){this._showIframe()}_afterShow(){this._hideIframe()}_initIframe(){this._iframe=this._createIframe(),this._addIframeToDom(this._iframe),this._hideIframe()}_addIframeToDom(t){document.body!=null?document.body.appendChild(t):document.addEventListener("DOMContentLoaded",()=>{document.body.appendChild(t)})}_createIframe(){const t=document.createElement("iframe");return t.style.transition="opacity .2s",t.style.position="absolute",t.style.opacity="0",t.style.width="100%",t.style.height="100%",t.style.left="0",t.style.top="0",t.style.border="none",t.style.position="fixed",t}_showIframe(){const t={width:"100%",height:"100%",left:"0",top:"0",border:"none",position:"fixed",display:"block",opacity:"0",zIndex:"99999999"};this._applyStyle(t),this._timer!=null&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._applyStyle({opacity:"1"})},0)}_hideIframe(){const t={opacity:"0"};this._applyStyle(t),this._timer!=null&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._applyStyle({width:"10px",height:"10px",left:"-100px",top:"-100px",position:"absolute",opacity:"0",zIndex:"0",display:"none"})},200)}_applyStyle(t){Object.entries(t).forEach(([e,i])=>{i!=null&&this._iframe&&(this._iframe.style[e]=i)})}_renderErrorPage(t,e,i){t.parentElement&&(t.parentElement.style.height="100%"),Object.assign(t.style,{position:"relative",boxSizing:"border-box",width:"100%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center",margin:"0px"});const n=document.createElement("div");Object.assign(n.style,{position:"fixed",zIndex:"-1",height:"100%",width:"100%",overflow:"hidden",backgroundColor:"#000",opacity:"0.6"});const r=document.createElement("div");Object.assign(r.style,{position:"fixed",display:"flex",justifyContent:"center",alignItems:"center",flexDirection:"column",margin:"0",backgroundColor:"#292F3C",width:"520px",borderRadius:"6px",padding:"40px",boxSizing:"border-box"});const s=document.createElement("div");s.textContent=i,Object.assign(s.style,{fontSize:"15px",lineHeight:"20px",color:"#fff",marginBottom:"40px",fontFamily:"Roboto, sans-serif"});const a=document.createElement("button");a.textContent="OK",a.addEventListener("click",()=>e()),Object.assign(a.style,{width:"100%",fontSize:"15px",lineHeight:"48px",padding:" 0 40px",color:"#fff",backgroundColor:"#5A81EA",outline:"none",border:"none",cursor:"pointer",fontFamily:"Roboto, sans-serif",borderRadius:"4px"}),r.appendChild(s),r.appendChild(a),t.appendChild(n),t.appendChild(r)}}class R{constructor(t,e){v(this,"user",null);v(this,"_transport");v(this,"_clientUrl");v(this,"emitter",new A.exports.EventEmitter);v(this,"iframe");v(this,"win");this._clientUrl=(t||"https://waves.exchange/signer/")+`?${R._getCacheClean()}`,this._transport=new at(this._clientUrl,3),e===!0&&(p.config.console.logLevel=p.config.console.LOG_LEVEL.VERBOSE)}static _getCacheClean(){return String(Date.now()%(1e3*60))}on(t,e){return this.emitter.on(t,e),this}once(t,e){return this.emitter.once(t,e),this}off(t,e){return this.emitter.once(t,e),this}connect(t){return Promise.resolve(this._transport.sendEvent(e=>e.dispatchEvent("connect",t)))}logout(){return this.user=null,Promise.resolve(this._transport.dropConnection())}openWindow(){var t;this.iframe=this._transport.get(),this.win=(t=this.iframe.contentWindow)==null?void 0:t.open(this._clientUrl),this._transport.listenFetchURLError()}login(){if(this.user)return Promise.resolve(this.user);if((!this.win||!this.iframe)&&this.openWindow(),!this.win)throw new Error("Window was blocked");return this.iframe.src=`${this._clientUrl}?openWindow=true`,this._transport.dialog(t=>t.request("login").then(e=>(this.user=e,e)).catch(e=>(this._transport.dropConnection(),Promise.reject(M(e)))))}signMessage(t){return this.login().then(()=>this._transport.dialog(e=>e.request("sign-message",t)))}signTypedData(t){return this.login().then(()=>this._transport.dialog(e=>e.request("sign-typed-data",t)))}sign(t){return this.login().then(()=>this._transport.dialog(e=>e.request("sign",t)))}}_.ProviderWeb=R,Object.defineProperty(_,"__esModule",{value:!0}),_[Symbol.toStringTag]="Module"});
|
|
@@ -4,6 +4,8 @@ export declare class ProviderWeb implements Provider {
|
|
|
4
4
|
private readonly _transport;
|
|
5
5
|
private readonly _clientUrl;
|
|
6
6
|
private readonly emitter;
|
|
7
|
+
private iframe;
|
|
8
|
+
private win;
|
|
7
9
|
constructor(clientUrl?: string, logs?: boolean);
|
|
8
10
|
private static _getCacheClean;
|
|
9
11
|
on<EVENT extends keyof AuthEvents>(event: EVENT, handler: Handler<AuthEvents[EVENT]>): Provider;
|
|
@@ -11,6 +13,7 @@ export declare class ProviderWeb implements Provider {
|
|
|
11
13
|
off<EVENT extends keyof AuthEvents>(event: EVENT, handler: Handler<AuthEvents[EVENT]>): Provider;
|
|
12
14
|
connect(options: ConnectOptions): Promise<void>;
|
|
13
15
|
logout(): Promise<void>;
|
|
16
|
+
openWindow(): void;
|
|
14
17
|
login(): Promise<UserData>;
|
|
15
18
|
signMessage(data: string | number): Promise<string>;
|
|
16
19
|
signTypedData(data: Array<TypedData>): Promise<string>;
|
|
@@ -12,6 +12,7 @@ export declare abstract class Transport<T> implements ITransport<T> {
|
|
|
12
12
|
private _runEvents;
|
|
13
13
|
private _wrapAction;
|
|
14
14
|
abstract get(): T;
|
|
15
|
+
abstract listenFetchURLError(): void;
|
|
15
16
|
protected abstract _dropTransportConnect(): void;
|
|
16
17
|
protected abstract _beforeShow(): void;
|
|
17
18
|
protected abstract _afterShow(): void;
|
|
@@ -7,6 +7,7 @@ export declare class TransportIframe extends Transport<HTMLIFrameElement> {
|
|
|
7
7
|
private _bus;
|
|
8
8
|
constructor(url: string, queueLength: number);
|
|
9
9
|
get(): HTMLIFrameElement;
|
|
10
|
+
listenFetchURLError(): void;
|
|
10
11
|
protected _dropTransportConnect(): void;
|
|
11
12
|
protected _getBus(): Promise<TBus>;
|
|
12
13
|
protected _beforeShow(): void;
|
|
@@ -18,7 +19,6 @@ export declare class TransportIframe extends Transport<HTMLIFrameElement> {
|
|
|
18
19
|
private _hideIframe;
|
|
19
20
|
private _applyStyle;
|
|
20
21
|
private _renderErrorPage;
|
|
21
|
-
private _listenFetchURLError;
|
|
22
22
|
}
|
|
23
23
|
export declare function isBrave(): boolean;
|
|
24
24
|
export declare function isSafari(): boolean;
|
|
@@ -17,6 +17,7 @@ export interface IBusEvents {
|
|
|
17
17
|
export declare type TBus = Bus<IBusEvents, TBusHandlers>;
|
|
18
18
|
export interface ITransport<T> {
|
|
19
19
|
get(): T;
|
|
20
|
+
listenFetchURLError(): void;
|
|
20
21
|
dialog<T>(callback: (bus: TBus) => Promise<T>): Promise<T>;
|
|
21
22
|
sendEvent(callback: (bus: TBus) => unknown): void;
|
|
22
23
|
dropConnection(): void;
|