@waves.exchange/provider-web 1.2.2-alpha.0 → 1.3.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 +43 -32
- package/dist/provider-web.es.js +43 -32
- package/dist/provider-web.min.js +1 -1
- package/dist/types/ProviderWeb.d.ts +1 -4
- package/dist/types/TransferStorage.d.ts +6 -0
- package/dist/types/Transport.d.ts +0 -1
- package/dist/types/TransportIframe.d.ts +1 -1
- package/dist/types/interface.d.ts +7 -2
- package/package.json +1 -1
package/dist/provider-web.cjs.js
CHANGED
|
@@ -160,18 +160,6 @@ 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
|
-
}
|
|
175
163
|
_dropTransportConnect() {
|
|
176
164
|
if (this._iframe != null) {
|
|
177
165
|
document.body.removeChild(this._iframe);
|
|
@@ -204,6 +192,7 @@ class TransportIframe extends Transport {
|
|
|
204
192
|
_initIframe() {
|
|
205
193
|
this._iframe = this._createIframe();
|
|
206
194
|
this._addIframeToDom(this._iframe);
|
|
195
|
+
this._listenFetchURLError(this._iframe);
|
|
207
196
|
this._hideIframe();
|
|
208
197
|
}
|
|
209
198
|
_addIframeToDom(iframe) {
|
|
@@ -346,15 +335,40 @@ class TransportIframe extends Transport {
|
|
|
346
335
|
bodyElement.appendChild(backdropElement);
|
|
347
336
|
bodyElement.appendChild(wrapperElement);
|
|
348
337
|
}
|
|
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
|
+
const transferStorage = (win) => {
|
|
351
|
+
return wavesBrowserBus.WindowAdapter.createSimpleWindowAdapter(win, {
|
|
352
|
+
origins: ["*"]
|
|
353
|
+
}).then((adapter) => {
|
|
354
|
+
return new Promise((resolve) => {
|
|
355
|
+
const _bus = new wavesBrowserBus.Bus(adapter, -1);
|
|
356
|
+
_bus.once("ready", () => {
|
|
357
|
+
_bus.once("transferStorage", (data) => {
|
|
358
|
+
win.close();
|
|
359
|
+
adapter.destroy();
|
|
360
|
+
resolve(data);
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
};
|
|
350
366
|
class ProviderWeb {
|
|
351
367
|
constructor(clientUrl, logs) {
|
|
352
368
|
__publicField(this, "user", null);
|
|
353
369
|
__publicField(this, "_transport");
|
|
354
370
|
__publicField(this, "_clientUrl");
|
|
355
371
|
__publicField(this, "emitter", new typedTsEvents.EventEmitter());
|
|
356
|
-
__publicField(this, "iframe");
|
|
357
|
-
__publicField(this, "win");
|
|
358
372
|
this._clientUrl = (clientUrl || "https://waves.exchange/signer/") + `?${ProviderWeb._getCacheClean()}`;
|
|
359
373
|
this._transport = new TransportIframe(this._clientUrl, 3);
|
|
360
374
|
if (logs === true) {
|
|
@@ -383,30 +397,27 @@ class ProviderWeb {
|
|
|
383
397
|
this.user = null;
|
|
384
398
|
return Promise.resolve(this._transport.dropConnection());
|
|
385
399
|
}
|
|
386
|
-
openWindow() {
|
|
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
400
|
login() {
|
|
393
401
|
if (this.user) {
|
|
394
402
|
return Promise.resolve(this.user);
|
|
395
403
|
}
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
}
|
|
399
|
-
if (!
|
|
404
|
+
const left = window.screen.width - 200;
|
|
405
|
+
const top = window.screen.height - 200;
|
|
406
|
+
const win = window.open(`${this._clientUrl}?transferStorage=true`, "_blank", `left=${left},top=${top},width=100,height=100,location=no,scrollbars=no`);
|
|
407
|
+
if (!win) {
|
|
400
408
|
throw new Error("Window was blocked");
|
|
401
409
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
return userData
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
+
return transferStorage(win).then((storageData) => {
|
|
411
|
+
const iframe = this._transport.get();
|
|
412
|
+
iframe.src = `${this._clientUrl}?waitStorage=true`;
|
|
413
|
+
return this._transport.dialog((bus) => bus.request("login", storageData).then((userData) => {
|
|
414
|
+
this.user = userData;
|
|
415
|
+
return userData;
|
|
416
|
+
}).catch((err) => {
|
|
417
|
+
this._transport.dropConnection();
|
|
418
|
+
return Promise.reject(createError(err));
|
|
419
|
+
}));
|
|
420
|
+
});
|
|
410
421
|
}
|
|
411
422
|
signMessage(data) {
|
|
412
423
|
return this.login().then(() => this._transport.dialog((bus) => bus.request("sign-message", data)));
|
package/dist/provider-web.es.js
CHANGED
|
@@ -157,18 +157,6 @@ 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
|
-
}
|
|
172
160
|
_dropTransportConnect() {
|
|
173
161
|
if (this._iframe != null) {
|
|
174
162
|
document.body.removeChild(this._iframe);
|
|
@@ -201,6 +189,7 @@ class TransportIframe extends Transport {
|
|
|
201
189
|
_initIframe() {
|
|
202
190
|
this._iframe = this._createIframe();
|
|
203
191
|
this._addIframeToDom(this._iframe);
|
|
192
|
+
this._listenFetchURLError(this._iframe);
|
|
204
193
|
this._hideIframe();
|
|
205
194
|
}
|
|
206
195
|
_addIframeToDom(iframe) {
|
|
@@ -343,15 +332,40 @@ class TransportIframe extends Transport {
|
|
|
343
332
|
bodyElement.appendChild(backdropElement);
|
|
344
333
|
bodyElement.appendChild(wrapperElement);
|
|
345
334
|
}
|
|
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
|
+
const transferStorage = (win) => {
|
|
348
|
+
return WindowAdapter.createSimpleWindowAdapter(win, {
|
|
349
|
+
origins: ["*"]
|
|
350
|
+
}).then((adapter) => {
|
|
351
|
+
return new Promise((resolve) => {
|
|
352
|
+
const _bus = new Bus(adapter, -1);
|
|
353
|
+
_bus.once("ready", () => {
|
|
354
|
+
_bus.once("transferStorage", (data) => {
|
|
355
|
+
win.close();
|
|
356
|
+
adapter.destroy();
|
|
357
|
+
resolve(data);
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
});
|
|
362
|
+
};
|
|
347
363
|
class ProviderWeb {
|
|
348
364
|
constructor(clientUrl, logs) {
|
|
349
365
|
__publicField(this, "user", null);
|
|
350
366
|
__publicField(this, "_transport");
|
|
351
367
|
__publicField(this, "_clientUrl");
|
|
352
368
|
__publicField(this, "emitter", new EventEmitter());
|
|
353
|
-
__publicField(this, "iframe");
|
|
354
|
-
__publicField(this, "win");
|
|
355
369
|
this._clientUrl = (clientUrl || "https://waves.exchange/signer/") + `?${ProviderWeb._getCacheClean()}`;
|
|
356
370
|
this._transport = new TransportIframe(this._clientUrl, 3);
|
|
357
371
|
if (logs === true) {
|
|
@@ -380,30 +394,27 @@ class ProviderWeb {
|
|
|
380
394
|
this.user = null;
|
|
381
395
|
return Promise.resolve(this._transport.dropConnection());
|
|
382
396
|
}
|
|
383
|
-
openWindow() {
|
|
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
397
|
login() {
|
|
390
398
|
if (this.user) {
|
|
391
399
|
return Promise.resolve(this.user);
|
|
392
400
|
}
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
}
|
|
396
|
-
if (!
|
|
401
|
+
const left = window.screen.width - 200;
|
|
402
|
+
const top = window.screen.height - 200;
|
|
403
|
+
const win = window.open(`${this._clientUrl}?transferStorage=true`, "_blank", `left=${left},top=${top},width=100,height=100,location=no,scrollbars=no`);
|
|
404
|
+
if (!win) {
|
|
397
405
|
throw new Error("Window was blocked");
|
|
398
406
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
return userData
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
+
return transferStorage(win).then((storageData) => {
|
|
408
|
+
const iframe = this._transport.get();
|
|
409
|
+
iframe.src = `${this._clientUrl}?waitStorage=true`;
|
|
410
|
+
return this._transport.dialog((bus) => bus.request("login", storageData).then((userData) => {
|
|
411
|
+
this.user = userData;
|
|
412
|
+
return userData;
|
|
413
|
+
}).catch((err) => {
|
|
414
|
+
this._transport.dropConnection();
|
|
415
|
+
return Promise.reject(createError(err));
|
|
416
|
+
}));
|
|
417
|
+
});
|
|
407
418
|
}
|
|
408
419
|
signMessage(data) {
|
|
409
420
|
return this.login().then(() => this._transport.dialog((bus) => bus.request("sign-message", data)));
|
package/dist/provider-web.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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"});
|
|
1
|
+
var ut=Object.defineProperty,lt=Object.defineProperties;var ht=Object.getOwnPropertyDescriptors;var B=Object.getOwnPropertySymbols;var dt=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable;var T=(_,u,f)=>u in _?ut(_,u,{enumerable:!0,configurable:!0,writable:!0,value:f}):_[u]=f,D=(_,u)=>{for(var f in u||(u={}))dt.call(u,f)&&T(_,f,u[f]);if(B)for(var f of B(u))ft.call(u,f)&&T(_,f,u[f]);return _},U=(_,u)=>lt(_,ht(u));var v=(_,u,f)=>(T(_,typeof u!="symbol"?u+"":u,f),f);(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:{},f={},W={},L={},m={};Object.defineProperty(m,"__esModule",{value:!0});function V(o){return Object.keys(o)}m.keys=V;var $=Math.floor(Date.now()*Math.random()),z=0;function F(o){return o+"-"+$+"-"+z++}m.uniqueId=F;function G(o){return Array.isArray(o)?o:[o]}m.toArray=G;function N(){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)}}m.pipe=N;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 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 n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];E.config.console.logLevel<E.config.console.methodsData[t].logLevel?E.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(m),t(C),t(I)}(L),function(o){Object.defineProperty(o,"__esModule",{value:!0});var t=L;(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,p;(s||a._timeout)!==-1&&(p=setTimeout(function(){delete a._activeRequestHash[h];var y=new Error('Timeout error for request with name "'+e+'" and timeout '+d+"!");t.console.error(y),l(y)},d));var g=function(){p&&clearTimeout(p)};a._activeRequestHash[h]={reject:function(y){g(),t.console.error('Error request with name "'+e+'"',y),l(y)},resolve:function(y){g(),t.console.info('Request with name "'+e+'" success resolved!',y),c(y)}},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={},A={},q={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(p){h.catchHandler(p)}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,p=typeof l=="function"?l:typeof c=="function"?c:null;if(d)if(p){if(d in this._events){var g=this._events[d].map(function(y){return y.handler}).indexOf(p);this._events[d].splice(g,1)}}else delete this._events[d];else Object.keys(this._events).forEach(function(y){h.off(y,p)})},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,p,g){g===void 0&&(g=p),Object.defineProperty(h,g,{enumerable:!0,get:function(){return d[p]}})}:function(h,d,p,g){g===void 0&&(g=p),h[g]=d[p]}),c=this&&this.__exportStar||function(h,d){for(var p in h)p==="default"||Object.prototype.hasOwnProperty.call(d,p)||a(d,h,p)};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)})()})})(q),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=q.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}(A);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=f,S=A,nt=m,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 S.WindowProtocol(window,S.WindowProtocol.PROTOCOL_TYPES.LISTEN),l=function(h){a.push(h)};return c.on("message",l),this.getIframeContent(n).then(function(h){var d=new S.WindowProtocol(h.win,S.WindowProtocol.PROTOCOL_TYPES.DISPATCH),p=new t([c],[d],e.unPrepareOptions(s));return a.forEach(function(g){p.onMessage(g)}),c.off("message",l),p})},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(A),t(j),t(L)}(f);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):f.WindowAdapter.createSimpleWindowAdapter(this._iframe,{origins:["https://wx.network","https://testnet.wx.network"]}).then(t=>new Promise(n=>{this._bus=new f.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())})})}}const ct=o=>f.WindowAdapter.createSimpleWindowAdapter(o,{origins:["*"]}).then(t=>new Promise(n=>{const r=new f.Bus(t,-1);r.once("ready",()=>{r.once("transferStorage",e=>{o.close(),t.destroy(),n(e)})})}));class R{constructor(t,n){v(this,"user",null);v(this,"_transport");v(this,"_clientUrl");v(this,"emitter",new q.exports.EventEmitter);this._clientUrl=(t||"https://waves.exchange/signer/")+`?${R._getCacheClean()}`,this._transport=new at(this._clientUrl,3),n===!0&&(f.config.console.logLevel=f.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(){if(this.user)return Promise.resolve(this.user);const t=window.screen.width-200,n=window.screen.height-200,r=window.open(`${this._clientUrl}?transferStorage=true`,"_blank",`left=${t},top=${n},width=100,height=100,location=no,scrollbars=no`);if(!r)throw new Error("Window was blocked");return ct(r).then(e=>{const i=this._transport.get();return i.src=`${this._clientUrl}?waitStorage=true`,this._transport.dialog(s=>s.request("login",e).then(a=>(this.user=a,a)).catch(a=>(this._transport.dropConnection(),Promise.reject(M(a)))))})}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"});
|
|
@@ -4,8 +4,6 @@ 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;
|
|
9
7
|
constructor(clientUrl?: string, logs?: boolean);
|
|
10
8
|
private static _getCacheClean;
|
|
11
9
|
on<EVENT extends keyof AuthEvents>(event: EVENT, handler: Handler<AuthEvents[EVENT]>): Provider;
|
|
@@ -13,8 +11,7 @@ export declare class ProviderWeb implements Provider {
|
|
|
13
11
|
off<EVENT extends keyof AuthEvents>(event: EVENT, handler: Handler<AuthEvents[EVENT]>): Provider;
|
|
14
12
|
connect(options: ConnectOptions): Promise<void>;
|
|
15
13
|
logout(): Promise<void>;
|
|
16
|
-
|
|
17
|
-
login(): Promise<UserData>;
|
|
14
|
+
login(): Promise<any>;
|
|
18
15
|
signMessage(data: string | number): Promise<string>;
|
|
19
16
|
signTypedData(data: Array<TypedData>): Promise<string>;
|
|
20
17
|
sign<T extends Array<SignerTx>>(toSign: T): Promise<SignedTx<T>>;
|
|
@@ -12,7 +12,6 @@ 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;
|
|
16
15
|
protected abstract _dropTransportConnect(): void;
|
|
17
16
|
protected abstract _beforeShow(): void;
|
|
18
17
|
protected abstract _afterShow(): void;
|
|
@@ -7,7 +7,6 @@ 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;
|
|
11
10
|
protected _dropTransportConnect(): void;
|
|
12
11
|
protected _getBus(): Promise<TBus>;
|
|
13
12
|
protected _beforeShow(): void;
|
|
@@ -19,6 +18,7 @@ export declare class TransportIframe extends Transport<HTMLIFrameElement> {
|
|
|
19
18
|
private _hideIframe;
|
|
20
19
|
private _applyStyle;
|
|
21
20
|
private _renderErrorPage;
|
|
21
|
+
private _listenFetchURLError;
|
|
22
22
|
}
|
|
23
23
|
export declare function isBrave(): boolean;
|
|
24
24
|
export declare function isSafari(): boolean;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { ConnectOptions, SignedTx, SignerTx, TypedData, UserData } from '@waves/signer';
|
|
2
2
|
import { Bus } from '@waves/waves-browser-bus';
|
|
3
|
+
export interface IStorageTransferData {
|
|
4
|
+
multiAccountUsers: string | null;
|
|
5
|
+
multiAccountHash: string | null;
|
|
6
|
+
}
|
|
3
7
|
export declare type TBusHandlers = {
|
|
4
|
-
login: (data?:
|
|
8
|
+
login: (data?: IStorageTransferData) => Promise<UserData>;
|
|
5
9
|
'sign-custom-bytes': (data: string) => Promise<string>;
|
|
6
10
|
'sign-message': (data: string | number) => Promise<string>;
|
|
7
11
|
'sign-typed-data': (data: Array<TypedData>) => Promise<string>;
|
|
@@ -13,11 +17,12 @@ export interface IBusEvents {
|
|
|
13
17
|
connect: ConnectOptions;
|
|
14
18
|
close: void;
|
|
15
19
|
ready: void;
|
|
20
|
+
passLoginData: void;
|
|
21
|
+
catchStorage: void;
|
|
16
22
|
}
|
|
17
23
|
export declare type TBus = Bus<IBusEvents, TBusHandlers>;
|
|
18
24
|
export interface ITransport<T> {
|
|
19
25
|
get(): T;
|
|
20
|
-
listenFetchURLError(): void;
|
|
21
26
|
dialog<T>(callback: (bus: TBus) => Promise<T>): Promise<T>;
|
|
22
27
|
sendEvent(callback: (bus: TBus) => unknown): void;
|
|
23
28
|
dropConnection(): void;
|