@waves.exchange/provider-web 1.1.0 → 1.1.4

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/README.md CHANGED
@@ -12,7 +12,8 @@
12
12
  <a id="overview"></a>
13
13
  ## Overview
14
14
 
15
- ProviderWeb developed by Waves.Exchange implements a Signature Provider for [Signer](https://github.com/wavesplatform/signer) protocol library. Signer enables easy deploy dApps based on Waves blockchain. User's private key and SEED phrase are encrypted and stored in Waves.Exchange, so your web app does not have access to them.
15
+ ProviderWeb developed by Waves.Exchange implements a Signature Provider for [Signer](https://github.com/wavesplatform/signer) protocol library. Signer enables easy deploy dApps based on Waves blockchain. Users' encrypted private keys and SEED phrase are stored in waves.exchange domain of the local browser storage. Waves.Exchange and other apps do not have access to the local data as they are stored encrypted.
16
+
16
17
 
17
18
  > For now, signing is implemented for all types of transactions except exchange transactions.
18
19
 
@@ -1,12 +1,36 @@
1
1
  "use strict";
2
- var __assign = Object.assign;
3
- Object.defineProperty(exports, "__esModule", {value: true});
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
8
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __spreadValues = (a, b) => {
10
+ for (var prop in b || (b = {}))
11
+ if (__hasOwnProp.call(b, prop))
12
+ __defNormalProp(a, prop, b[prop]);
13
+ if (__getOwnPropSymbols)
14
+ for (var prop of __getOwnPropSymbols(b)) {
15
+ if (__propIsEnum.call(b, prop))
16
+ __defNormalProp(a, prop, b[prop]);
17
+ }
18
+ return a;
19
+ };
20
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
+ var __publicField = (obj, key, value) => {
22
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
23
+ return value;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
4
26
  exports[Symbol.toStringTag] = "Module";
5
27
  var wavesBrowserBus = require("@waves/waves-browser-bus");
6
28
  var typedTsEvents = require("typed-ts-events");
7
29
  class Queue {
8
30
  constructor(maxLength) {
9
- this._actions = [];
31
+ __publicField(this, "_actions", []);
32
+ __publicField(this, "_maxLength");
33
+ __publicField(this, "_active");
10
34
  this._maxLength = maxLength;
11
35
  }
12
36
  get length() {
@@ -32,7 +56,7 @@ class Queue {
32
56
  onEnd();
33
57
  reject(err);
34
58
  });
35
- this._actions.push({action: actionCallback, reject});
59
+ this._actions.push({ action: actionCallback, reject });
36
60
  if (this.length === 1) {
37
61
  this.run();
38
62
  }
@@ -56,23 +80,18 @@ class Queue {
56
80
  }
57
81
  }
58
82
  const createError = (error) => {
59
- const commonError = {
60
- code: 0,
61
- message: (error == null ? void 0 : error.message) || error
62
- };
63
- switch (error == null ? void 0 : error.message) {
64
- case "SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.":
65
- return __assign(__assign({}, commonError), {
66
- message: "Local storage is not available! It is possible that the Browser is in incognito mode!"
67
- });
68
- default:
69
- return commonError;
83
+ if (error && error.message === "SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.") {
84
+ return __spreadProps(__spreadValues({}, error), {
85
+ message: "Local storage is not available! It is possible that the Browser is in incognito mode!"
86
+ });
70
87
  }
88
+ return error;
71
89
  };
72
90
  class Transport {
73
91
  constructor(queueLength) {
74
- this._events = [];
75
- this._toRunEvents = [];
92
+ __publicField(this, "_queue");
93
+ __publicField(this, "_events", []);
94
+ __publicField(this, "_toRunEvents", []);
76
95
  this._queue = new Queue(queueLength);
77
96
  }
78
97
  dropConnection() {
@@ -125,9 +144,12 @@ class Transport {
125
144
  } : action;
126
145
  }
127
146
  }
128
- const TransportIframe2 = class extends Transport {
147
+ const _TransportIframe = class extends Transport {
129
148
  constructor(url, queueLength) {
130
149
  super(queueLength);
150
+ __publicField(this, "_url");
151
+ __publicField(this, "_iframe");
152
+ __publicField(this, "_bus");
131
153
  this._url = url;
132
154
  this._initIframe();
133
155
  }
@@ -205,11 +227,11 @@ const TransportIframe2 = class extends Transport {
205
227
  zIndex: "99999999"
206
228
  };
207
229
  this._applyStyle(shownStyles);
208
- if (TransportIframe2._timer != null) {
209
- clearTimeout(TransportIframe2._timer);
230
+ if (_TransportIframe._timer != null) {
231
+ clearTimeout(_TransportIframe._timer);
210
232
  }
211
- TransportIframe2._timer = setTimeout(() => {
212
- this._applyStyle({opacity: "1"});
233
+ _TransportIframe._timer = setTimeout(() => {
234
+ this._applyStyle({ opacity: "1" });
213
235
  }, 0);
214
236
  }
215
237
  _hideIframe() {
@@ -217,10 +239,10 @@ const TransportIframe2 = class extends Transport {
217
239
  opacity: "0"
218
240
  };
219
241
  this._applyStyle(hiddenStyle);
220
- if (TransportIframe2._timer != null) {
221
- clearTimeout(TransportIframe2._timer);
242
+ if (_TransportIframe._timer != null) {
243
+ clearTimeout(_TransportIframe._timer);
222
244
  }
223
- TransportIframe2._timer = setTimeout(() => {
245
+ _TransportIframe._timer = setTimeout(() => {
224
246
  this._applyStyle({
225
247
  width: "10px",
226
248
  height: "10px",
@@ -322,18 +344,14 @@ const TransportIframe2 = class extends Transport {
322
344
  });
323
345
  }
324
346
  };
325
- let TransportIframe = TransportIframe2;
326
- TransportIframe._timer = null;
327
- function isSafari() {
328
- const userAgent = navigator.userAgent.toLowerCase();
329
- const isSafariUA = userAgent.includes("safari") && !userAgent.includes("chrome");
330
- const iOS = navigator.platform != null && /iPad|iPhone|iPod/.test(navigator.platform);
331
- return iOS || isSafariUA;
332
- }
347
+ let TransportIframe = _TransportIframe;
348
+ __publicField(TransportIframe, "_timer", null);
333
349
  class ProviderWeb {
334
350
  constructor(clientUrl, logs) {
335
- this.user = null;
336
- this.emitter = new typedTsEvents.EventEmitter();
351
+ __publicField(this, "user", null);
352
+ __publicField(this, "_transport");
353
+ __publicField(this, "_clientUrl");
354
+ __publicField(this, "emitter", new typedTsEvents.EventEmitter());
337
355
  this._clientUrl = (clientUrl || "https://waves.exchange/signer/") + `?${ProviderWeb._getCacheClean()}`;
338
356
  this._transport = new TransportIframe(this._clientUrl, 3);
339
357
  if (logs === true) {
@@ -368,11 +386,9 @@ class ProviderWeb {
368
386
  return Promise.resolve(this.user);
369
387
  }
370
388
  const iframe = this._transport.get();
371
- if (isSafari()) {
372
- const win = (_a = iframe.contentWindow) == null ? void 0 : _a.open(this._clientUrl);
373
- if (!win) {
374
- throw new Error("Window was blocked");
375
- }
389
+ const win = (_a = iframe.contentWindow) == null ? void 0 : _a.open(this._clientUrl);
390
+ if (!win) {
391
+ throw new Error("Window was blocked");
376
392
  }
377
393
  iframe.src = this._clientUrl;
378
394
  return this._transport.dialog((bus) => bus.request("login").then((userData) => {
@@ -1,9 +1,33 @@
1
- var __assign = Object.assign;
2
- import {WindowAdapter, Bus, config} from "@waves/waves-browser-bus";
3
- import {EventEmitter} from "typed-ts-events";
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ var __publicField = (obj, key, value) => {
21
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
22
+ return value;
23
+ };
24
+ import { WindowAdapter, Bus, config } from "@waves/waves-browser-bus";
25
+ import { EventEmitter } from "typed-ts-events";
4
26
  class Queue {
5
27
  constructor(maxLength) {
6
- this._actions = [];
28
+ __publicField(this, "_actions", []);
29
+ __publicField(this, "_maxLength");
30
+ __publicField(this, "_active");
7
31
  this._maxLength = maxLength;
8
32
  }
9
33
  get length() {
@@ -29,7 +53,7 @@ class Queue {
29
53
  onEnd();
30
54
  reject(err);
31
55
  });
32
- this._actions.push({action: actionCallback, reject});
56
+ this._actions.push({ action: actionCallback, reject });
33
57
  if (this.length === 1) {
34
58
  this.run();
35
59
  }
@@ -53,23 +77,18 @@ class Queue {
53
77
  }
54
78
  }
55
79
  const createError = (error) => {
56
- const commonError = {
57
- code: 0,
58
- message: (error == null ? void 0 : error.message) || error
59
- };
60
- switch (error == null ? void 0 : error.message) {
61
- case "SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.":
62
- return __assign(__assign({}, commonError), {
63
- message: "Local storage is not available! It is possible that the Browser is in incognito mode!"
64
- });
65
- default:
66
- return commonError;
80
+ if (error && error.message === "SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.") {
81
+ return __spreadProps(__spreadValues({}, error), {
82
+ message: "Local storage is not available! It is possible that the Browser is in incognito mode!"
83
+ });
67
84
  }
85
+ return error;
68
86
  };
69
87
  class Transport {
70
88
  constructor(queueLength) {
71
- this._events = [];
72
- this._toRunEvents = [];
89
+ __publicField(this, "_queue");
90
+ __publicField(this, "_events", []);
91
+ __publicField(this, "_toRunEvents", []);
73
92
  this._queue = new Queue(queueLength);
74
93
  }
75
94
  dropConnection() {
@@ -122,9 +141,12 @@ class Transport {
122
141
  } : action;
123
142
  }
124
143
  }
125
- const TransportIframe2 = class extends Transport {
144
+ const _TransportIframe = class extends Transport {
126
145
  constructor(url, queueLength) {
127
146
  super(queueLength);
147
+ __publicField(this, "_url");
148
+ __publicField(this, "_iframe");
149
+ __publicField(this, "_bus");
128
150
  this._url = url;
129
151
  this._initIframe();
130
152
  }
@@ -202,11 +224,11 @@ const TransportIframe2 = class extends Transport {
202
224
  zIndex: "99999999"
203
225
  };
204
226
  this._applyStyle(shownStyles);
205
- if (TransportIframe2._timer != null) {
206
- clearTimeout(TransportIframe2._timer);
227
+ if (_TransportIframe._timer != null) {
228
+ clearTimeout(_TransportIframe._timer);
207
229
  }
208
- TransportIframe2._timer = setTimeout(() => {
209
- this._applyStyle({opacity: "1"});
230
+ _TransportIframe._timer = setTimeout(() => {
231
+ this._applyStyle({ opacity: "1" });
210
232
  }, 0);
211
233
  }
212
234
  _hideIframe() {
@@ -214,10 +236,10 @@ const TransportIframe2 = class extends Transport {
214
236
  opacity: "0"
215
237
  };
216
238
  this._applyStyle(hiddenStyle);
217
- if (TransportIframe2._timer != null) {
218
- clearTimeout(TransportIframe2._timer);
239
+ if (_TransportIframe._timer != null) {
240
+ clearTimeout(_TransportIframe._timer);
219
241
  }
220
- TransportIframe2._timer = setTimeout(() => {
242
+ _TransportIframe._timer = setTimeout(() => {
221
243
  this._applyStyle({
222
244
  width: "10px",
223
245
  height: "10px",
@@ -319,18 +341,14 @@ const TransportIframe2 = class extends Transport {
319
341
  });
320
342
  }
321
343
  };
322
- let TransportIframe = TransportIframe2;
323
- TransportIframe._timer = null;
324
- function isSafari() {
325
- const userAgent = navigator.userAgent.toLowerCase();
326
- const isSafariUA = userAgent.includes("safari") && !userAgent.includes("chrome");
327
- const iOS = navigator.platform != null && /iPad|iPhone|iPod/.test(navigator.platform);
328
- return iOS || isSafariUA;
329
- }
344
+ let TransportIframe = _TransportIframe;
345
+ __publicField(TransportIframe, "_timer", null);
330
346
  class ProviderWeb {
331
347
  constructor(clientUrl, logs) {
332
- this.user = null;
333
- this.emitter = new EventEmitter();
348
+ __publicField(this, "user", null);
349
+ __publicField(this, "_transport");
350
+ __publicField(this, "_clientUrl");
351
+ __publicField(this, "emitter", new EventEmitter());
334
352
  this._clientUrl = (clientUrl || "https://waves.exchange/signer/") + `?${ProviderWeb._getCacheClean()}`;
335
353
  this._transport = new TransportIframe(this._clientUrl, 3);
336
354
  if (logs === true) {
@@ -365,11 +383,9 @@ class ProviderWeb {
365
383
  return Promise.resolve(this.user);
366
384
  }
367
385
  const iframe = this._transport.get();
368
- if (isSafari()) {
369
- const win = (_a = iframe.contentWindow) == null ? void 0 : _a.open(this._clientUrl);
370
- if (!win) {
371
- throw new Error("Window was blocked");
372
- }
386
+ const win = (_a = iframe.contentWindow) == null ? void 0 : _a.open(this._clientUrl);
387
+ if (!win) {
388
+ throw new Error("Window was blocked");
373
389
  }
374
390
  iframe.src = this._clientUrl;
375
391
  return this._transport.dialog((bus) => bus.request("login").then((userData) => {
@@ -390,4 +406,4 @@ class ProviderWeb {
390
406
  return this.login().then(() => this._transport.dialog((bus) => bus.request("sign", toSign)));
391
407
  }
392
408
  }
393
- export {ProviderWeb};
409
+ export { ProviderWeb };
@@ -1 +1 @@
1
- var __assign=Object.assign;!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).providerWeb={})}(this,(function(e){"use strict";var t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function n(e){var t={exports:{}};return e(t,t.exports),t.exports}var o=function(e){return Object.keys(e)},r=Math.floor(Date.now()*Math.random()),i=0;var s=function(e){return e+"-"+r+"-"+i++};var a=function(e){return Array.isArray(e)?e:[e]};var c=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return function(t){return e.reduce((function(e,t){return t(e)}),t)}},u=Object.defineProperty({keys:o,uniqueId:s,toArray:a,pipe:c},"__esModule",{value:!0}),h=n((function(e,t){var n,o;Object.defineProperty(t,"__esModule",{value:!0}),n=t.config||(t.config={}),(o=n.console||(n.console={})).LOG_LEVEL={PRODUCTION:0,ERRORS:1,VERBOSE:2},o.logLevel=o.LOG_LEVEL.PRODUCTION,o.methodsData={log:{save:!1,logLevel:o.LOG_LEVEL.VERBOSE},info:{save:!1,logLevel:o.LOG_LEVEL.VERBOSE},warn:{save:!1,logLevel:o.LOG_LEVEL.VERBOSE},error:{save:!0,logLevel:o.LOG_LEVEL.ERRORS}}})),l=t&&t.__assign||function(){return(l=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)},d=("undefined"!=typeof self?self:t).console,f=Object.create(null);function p(e){f[e]||(f[e]=[])}function _(e,t){f[e].push(t)}var v,g=l({},u.keys(h.config.console.methodsData).reduce((function(e,t){return e[t]=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];h.config.console.logLevel<h.config.console.methodsData[t].logLevel?h.config.console.methodsData[t].save&&(p(t),_(t,e)):d[t].apply(d,e)},e}),Object.create(null)),{getSavedMessages:function(e){return f[e]||[]}}),y=Object.defineProperty({console:g},"__esModule",{value:!0}),m=function(){function e(e){this.size=0,this.hash=Object.create(null),e&&e.forEach(this.add,this)}return e.prototype.add=function(e){return this.hash[e]=!0,this.size=Object.keys(this.hash).length,this},e.prototype.has=function(e){return e in this.hash},e.prototype.toArray=function(){return Object.keys(this.hash)},e}(),w=Object.defineProperty({UniqPrimitiveCollection:m},"__esModule",{value:!0}),E=n((function(e,t){function n(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}Object.defineProperty(t,"__esModule",{value:!0}),n(u),n(y),n(w)})),b=n((function(e,t){var n,o;Object.defineProperty(t,"__esModule",{value:!0}),(n=t.EventType||(t.EventType={}))[n.Event=0]="Event",n[n.Action=1]="Action",n[n.Response=2]="Response",(o=t.ResponseStatus||(t.ResponseStatus={}))[o.Success=0]="Success",o[o.Error=1]="Error";var r=function(){function e(e,t){var n=this;this.id=E.uniqueId("bus"),this._timeout=t||5e3,this._adapter=e,this._adapter.addListener((function(e){return n._onMessage(e)})),this._eventHandlers=Object.create(null),this._activeRequestHash=Object.create(null),this._requestHandlers=Object.create(null),E.console.info('Create Bus with id "'+this.id+'"')}return e.prototype.dispatchEvent=function(t,n){return this._adapter.send(e._createEvent(t,n)),E.console.info('Dispatch event "'+t+'"',n),this},e.prototype.request=function(e,t,n){var o=this;return new Promise((function(r,i){var s,a=E.uniqueId(o.id+"-action"),c=n||o._timeout;-1!==(n||o._timeout)&&(s=setTimeout((function(){delete o._activeRequestHash[a];var t=new Error('Timeout error for request with name "'+e+'" and timeout '+c+"!");E.console.error(t),i(t)}),c));var u=function(){s&&clearTimeout(s)};o._activeRequestHash[a]={reject:function(t){u(),E.console.error('Error request with name "'+e+'"',t),i(t)},resolve:function(t){u(),E.console.info('Request with name "'+e+'" success resolved!',t),r(t)}},o._adapter.send({id:a,type:1,name:e,data:t}),E.console.info('Request with name "'+e+'"',t)}))},e.prototype.on=function(e,t,n){return this._addEventHandler(e,t,n,!1)},e.prototype.once=function(e,t,n){return this._addEventHandler(e,t,n,!0)},e.prototype.off=function(e,t){var n=this;return e?this._eventHandlers[e]?t?(this._eventHandlers[e]=this._eventHandlers[e].filter((function(e){return e.handler!==t})),this._eventHandlers[e].length||delete this._eventHandlers[e],this):(this._eventHandlers[e].slice().forEach((function(t){n.off(e,t.handler)})),this):this:(Object.keys(this._eventHandlers).forEach((function(e){return n.off(e,t)})),this)},e.prototype.registerRequestHandler=function(e,t){if(this._requestHandlers[e])throw new Error("Duplicate request handler!");return this._requestHandlers[e]=t,this},e.prototype.unregisterHandler=function(e){return this._requestHandlers[e]&&delete this._requestHandlers[e],this},e.prototype.changeAdapter=function(t){var n=this,o=new e(t,this._timeout);return Object.keys(this._eventHandlers).forEach((function(e){n._eventHandlers[e].forEach((function(t){t.once?o.once(e,t.handler,t.context):o.on(e,t.handler,t.context)}))})),Object.keys(this._requestHandlers).forEach((function(e){o.registerRequestHandler(e,n._requestHandlers[e])})),o},e.prototype.destroy=function(){E.console.info("Destroy Bus"),this.off(),this._adapter.destroy()},e.prototype._addEventHandler=function(e,t,n,o){return this._eventHandlers[e]||(this._eventHandlers[e]=[]),this._eventHandlers[e].push({handler:t,once:o,context:n}),this},e.prototype._onMessage=function(e){switch(e.type){case 0:E.console.info('Has event with name "'+String(e.name)+'"',e.data),this._fireEvent(String(e.name),e.data);break;case 1:E.console.info('Start action with id "'+e.id+'" and name "'+String(e.name)+'"',e.data),this._createResponse(e);break;case 2:E.console.info('Start response with name "'+e.id+'" and status "'+e.status+'"',e.content),this._fireEndAction(e)}},e.prototype._createResponse=function(t){var n=this,o=function(e){E.console.error(e),n._adapter.send({id:t.id,type:2,status:1,content:String(e)})};if(this._requestHandlers[String(t.name)])try{var r=this._requestHandlers[String(t.name)](t.data);e._isPromise(r)?r.then((function(e){n._adapter.send({id:t.id,type:2,status:0,content:e})}),o):this._adapter.send({id:t.id,type:2,status:0,content:r})}catch(i){o(i)}else o(new Error('Has no handler for "'+String(t.name)+'" action!'))},e.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)}delete this._activeRequestHash[e.id]}},e.prototype._fireEvent=function(e,t){this._eventHandlers[e]&&(this._eventHandlers[e]=this._eventHandlers[e].slice().filter((function(e){try{e.handler.call(e.context,t)}catch(n){E.console.warn(n)}return!e.once})),this._eventHandlers[e].length||delete this._eventHandlers[e])},e._createEvent=function(e,t){return{type:0,name:e,data:t}},e._isPromise=function(e){return e&&e.then&&"function"==typeof e.then},e}();t.Bus=r})),O=function(){},P=Object.defineProperty({Adapter:O},"__esModule",{value:!0}),L=n((function(e,t){var n,o;e.exports=(n={660:(e,t)=>{t.__esModule=!0,t.EventEmitter=void 0;var n=function(){function e(e){this._events=Object.create(null),this.catchHandler=e||function(){}}return e.prototype.hasListeners=function(e){return!(!this._events[e]||!this._events[e].length)},e.prototype.getActiveEvents=function(){var e=this;return Object.keys(this._events).filter((function(t){return e.hasListeners(t)}))},e.prototype.trigger=function(e,t){var n=this;this._events[e]&&(this._events[e].slice().forEach((function(o){try{o.handler.call(o.context,t)}catch(r){n.catchHandler(r)}o.once&&n.off(e,o.handler)})),this._events[e].length||delete this._events[e])},e.prototype.on=function(e,t,n){this._on(e,t,n,!1)},e.prototype.once=function(e,t,n){this._on(e,t,n,!0)},e.prototype.off=function(e,t){var n=this,o="string"==typeof e?e:null,r="function"==typeof t?t:"function"==typeof e?e:null;if(o)if(r){if(o in this._events){var i=this._events[o].map((function(e){return e.handler})).indexOf(r);this._events[o].splice(i,1)}}else delete this._events[o];else Object.keys(this._events).forEach((function(e){n.off(e,r)}))},e.prototype._on=function(e,t,n,o){this._events[e]||(this._events[e]=[]),this._events[e].push({handler:t,context:n,once:o})},e}();t.EventEmitter=n},607:function(e,t,n){var o=this&&this.__createBinding||(Object.create?function(e,t,n,o){void 0===o&&(o=n),Object.defineProperty(e,o,{enumerable:!0,get:function(){return t[n]}})}:function(e,t,n,o){void 0===o&&(o=n),e[o]=t[n]}),r=this&&this.__exportStar||function(e,t){for(var n in e)"default"===n||Object.prototype.hasOwnProperty.call(t,n)||o(t,e,n)};t.__esModule=!0;var i=n(660);r(n(660),t),t.default=i.EventEmitter}},o={},function e(t){if(o[t])return o[t].exports;var r=o[t]={exports:{}};return n[t].call(r.exports,r,r.exports,e),r.exports}(607))})),S=n((function(e,n){var o,r=t&&t.__extends||(o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)});Object.defineProperty(n,"__esModule",{value:!0});var i=function(e){function t(n,o){var r=e.call(this)||this;return r.win=n,r.type=o,r.handler=function(e){r.trigger("message",e)},o===t.PROTOCOL_TYPES.LISTEN&&r.win.addEventListener("message",r.handler,!1),r}var n;return r(t,e),t.prototype.dispatch=function(e){return this.win.postMessage(e,"*"),this},t.prototype.destroy=function(){this.type===t.PROTOCOL_TYPES.LISTEN&&this.win.removeEventListener("message",this.handler,!1),this.win=t._fakeWin},t._fakeWin={postMessage:n=function(){return null},addEventListener:n,removeEventListener:n},t}(L.EventEmitter);n.WindowProtocol=i,(i=n.WindowProtocol||(n.WindowProtocol={})).PROTOCOL_TYPES={LISTEN:"listen",DISPATCH:"dispatch"},n.WindowProtocol=i})),x=t&&t.__extends||(v=function(e,t){return(v=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)},function(e,t){function n(){this.constructor=e}v(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}),j=t&&t.__assign||function(){return(j=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e}).apply(this,arguments)},C={origins:[],availableChanelId:[]},H=function(e){function t(n,o,r){var i=e.call(this)||this;return i.id=R.uniqueId("wa"),i.callbacks=[],i.options=t.prepareOptions(r),i.listen=n,i.dispatch=o,i.listen.forEach((function(e){return e.on("message",i.onMessage,i)})),i}return x(t,e),t.prototype.addListener=function(e){return this.callbacks.push(e),R.console.info("WindowAdapter: Add iframe message listener"),this},t.prototype.send=function(e){var t=j({},e,{chanelId:this.options.chanelId});return this.dispatch.forEach((function(e){return e.dispatch(t)})),R.console.info("WindowAdapter: Send message",t),this},t.prototype.destroy=function(){this.listen.forEach((function(e){return e.destroy()})),this.dispatch.forEach((function(e){return e.destroy()})),R.console.info("WindowAdapter: Destroy")},t.prototype.onMessage=function(e){this.accessEvent(e)&&this.callbacks.forEach((function(t){try{t(e.data)}catch(n){R.console.warn("WindowAdapter: Unhandled exception!",n)}}))},t.prototype.accessEvent=function(e){if("object"!=typeof e.data||null==e.data.type)return R.console.info("WindowAdapter: Block event. Wrong event format!",e.data),!1;if(!this.options.origins.has("*")&&!this.options.origins.has(e.origin))return R.console.info('SimpleWindowAdapter: Block event by origin "'+e.origin+'"'),!1;if(!this.options.availableChanelId.size)return!0;var t=!(!e.data.chanelId||!this.options.availableChanelId.has(e.data.chanelId));return t||R.console.info('SimpleWindowAdapter: Block event by chanel id "'+e.data.chanelId+'"'),t},t.createSimpleWindowAdapter=function(e,n){var o=this,r=this.getContentOrigin(e),i=this.prepareOptions(n),s=[];r&&i.origins.add(r);var a=new S.WindowProtocol(window,S.WindowProtocol.PROTOCOL_TYPES.LISTEN),c=function(e){s.push(e)};return a.on("message",c),this.getIframeContent(e).then((function(e){var n=new S.WindowProtocol(e.win,S.WindowProtocol.PROTOCOL_TYPES.DISPATCH),r=new t([a],[n],o.unPrepareOptions(i));return s.forEach((function(e){r.onMessage(e)})),a.off("message",c),r}))},t.prepareOptions=function(e){void 0===e&&(e=C);var t=function(e,t){return u.pipe(R.toArray,(n=t,function(e){return e.reduce((function(e,t){return e.add(t)}),n)}))(e);var n},n=t(e.origins||[],new R.UniqPrimitiveCollection([window.location.origin])),o=t(e.availableChanelId||[],new R.UniqPrimitiveCollection);return j({},e,{origins:n,availableChanelId:o})},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(t,n){e.addEventListener("load",(function(){return t({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(t){return null}if(!(e instanceof HTMLIFrameElement))try{return window.top.origin}catch(t){return null}try{return new URL(e.src).origin||null}catch(t){return null}},t}(P.Adapter),I=Object.defineProperty({WindowAdapter:H},"__esModule",{value:!0}),R=n((function(e,t){function n(e){for(var n in e)t.hasOwnProperty(n)||(t[n]=e[n])}Object.defineProperty(t,"__esModule",{value:!0}),n(b),n(P),n(I),n(S),n(h),n(E)}));class q{constructor(e){this._actions=[],this._maxLength=e}get length(){return this._actions.length+(null==this._active?0:1)}push(e){if(this._actions.length>=this._maxLength)throw new Error("Cant't push action! Queue is full!");return new Promise(((t,n)=>{const o=()=>{this._active=void 0;const e=this._actions.map((e=>e.action)).indexOf(r);-1!==e&&this._actions.splice(e,1),this.run()},r=()=>e().then((e=>{o(),t(e)}),(e=>{o(),n(e)}));this._actions.push({action:r,reject:n}),1===this.length&&this.run()}))}clear(e){const t="string"==typeof(e=e||new Error("Rejection with clear queue!"))?new Error(e):e;this._actions.splice(0,this._actions.length).forEach((e=>e.reject(t))),this._active=void 0}canPush(){return this._actions.length<this._maxLength}run(){const e=this._actions.shift();null!=e&&(this._active=e.action())}}const T=e=>{const t={code:0,message:(null==e?void 0:e.message)||e};switch(null==e?void 0:e.message){case"SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.":return __assign(__assign({},t),{message:"Local storage is not available! It is possible that the Browser is in incognito mode!"});default:return t}};const A=class extends class{constructor(e){this._events=[],this._toRunEvents=[],this._queue=new q(e)}dropConnection(){this._queue.clear(new Error("User rejection!")),this._events.forEach((e=>this._toRunEvents.push(e))),this._dropTransportConnect()}sendEvent(e){this._events.push(e),this._toRunEvents.push(e)}dialog(e){return this._runBeforeShow(),this._getBus().then((t=>{const n=this._wrapAction((()=>e(t)));return this._runEvents(t),this._queue.canPush()?this._queue.push(n).then((e=>(this._runAfterShow(),e))).catch((e=>(this._runAfterShow(),Promise.reject(T(e))))):Promise.reject(new Error("Queue is full!"))}))}_runBeforeShow(){0===this._queue.length&&this._beforeShow()}_runAfterShow(){0===this._queue.length&&this._afterShow()}_runEvents(e){this._toRunEvents.splice(0,this._events.length).forEach((t=>t(e)))}_wrapAction(e){return this._toRunEvents?()=>{const t=e();return t.catch((()=>{this._events.forEach((e=>this._toRunEvents.push(e)))})),t}:e}}{constructor(e,t){super(t),this._url=e,this._initIframe()}get(){return this._iframe||this._initIframe(),this._iframe}_dropTransportConnect(){null!=this._iframe&&(document.body.removeChild(this._iframe),this._initIframe()),this._bus&&(this._bus.destroy(),this._bus=void 0)}_getBus(){return this._bus?Promise.resolve(this._bus):R.WindowAdapter.createSimpleWindowAdapter(this._iframe).then((e=>new Promise((t=>{this._bus=new R.Bus(e,-1),this._bus.once("ready",(()=>{t(this._bus)}))}))))}_beforeShow(){this._showIframe()}_afterShow(){this._hideIframe()}_initIframe(){this._iframe=this._createIframe(),this._addIframeToDom(this._iframe),this._listenFetchURLError(this._iframe),this._hideIframe()}_addIframeToDom(e){null!=document.body?document.body.appendChild(e):document.addEventListener("DOMContentLoaded",(()=>{document.body.appendChild(e)}))}_createIframe(){const e=document.createElement("iframe");return e.style.transition="opacity .2s",e.style.position="absolute",e.style.opacity="0",e.style.width="100%",e.style.height="100%",e.style.left="0",e.style.top="0",e.style.border="none",e.style.position="fixed",e}_showIframe(){this._applyStyle({width:"100%",height:"100%",left:"0",top:"0",border:"none",position:"fixed",display:"block",opacity:"0",zIndex:"99999999"}),null!=A._timer&&clearTimeout(A._timer),A._timer=setTimeout((()=>{this._applyStyle({opacity:"1"})}),0)}_hideIframe(){this._applyStyle({opacity:"0"}),null!=A._timer&&clearTimeout(A._timer),A._timer=setTimeout((()=>{this._applyStyle({width:"10px",height:"10px",left:"-100px",top:"-100px",position:"absolute",opacity:"0",zIndex:"0",display:"none"})}),200)}_applyStyle(e){Object.entries(e).forEach((([e,t])=>{null!=t&&this._iframe&&(this._iframe.style[e]=t)}))}_renderErrorPage(e,t,n){e.parentElement&&(e.parentElement.style.height="100%"),Object.assign(e.style,{position:"relative",boxSizing:"border-box",width:"100%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center",margin:"0px"});const o=document.createElement("div");Object.assign(o.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 i=document.createElement("div");i.textContent=n,Object.assign(i.style,{fontSize:"15px",lineHeight:"20px",color:"#fff",marginBottom:"40px",fontFamily:"Roboto, sans-serif"});const s=document.createElement("button");s.textContent="OK",s.addEventListener("click",(()=>t())),Object.assign(s.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(i),r.appendChild(s),e.appendChild(o),e.appendChild(r)}_listenFetchURLError(e){fetch(this._url).catch((()=>{e.addEventListener("load",(()=>{e.contentDocument&&(this._renderErrorPage(e.contentDocument.body,(()=>this.dropConnection()),"The request could not be processed. To resume your further work, disable the installed plugins."),this._showIframe())}))}))}};let W=A;W._timer=null;class k{constructor(e,t){this.user=null,this.emitter=new L.EventEmitter,this._clientUrl=(e||"https://waves.exchange/signer/")+`?${k._getCacheClean()}`,this._transport=new W(this._clientUrl,3),!0===t&&(R.config.console.logLevel=R.config.console.LOG_LEVEL.VERBOSE)}static _getCacheClean(){return String(Date.now()%6e4)}on(e,t){return this.emitter.on(e,t),this}once(e,t){return this.emitter.once(e,t),this}off(e,t){return this.emitter.once(e,t),this}connect(e){return Promise.resolve(this._transport.sendEvent((t=>t.dispatchEvent("connect",e))))}logout(){return this.user=null,Promise.resolve(this._transport.dropConnection())}login(){var e;if(this.user)return Promise.resolve(this.user);const t=this._transport.get();if(function(){const e=navigator.userAgent.toLowerCase(),t=e.includes("safari")&&!e.includes("chrome");return null!=navigator.platform&&/iPad|iPhone|iPod/.test(navigator.platform)||t}()){if(!(null==(e=t.contentWindow)?void 0:e.open(this._clientUrl)))throw new Error("Window was blocked")}return t.src=this._clientUrl,this._transport.dialog((e=>e.request("login").then((e=>(this.user=e,e))).catch((e=>(this._transport.dropConnection(),Promise.reject(T(e)))))))}signMessage(e){return this.login().then((()=>this._transport.dialog((t=>t.request("sign-message",e)))))}signTypedData(e){return this.login().then((()=>this._transport.dialog((t=>t.request("sign-typed-data",e)))))}sign(e){return this.login().then((()=>this._transport.dialog((t=>t.request("sign",e)))))}}e.ProviderWeb=k,Object.defineProperty(e,"__esModule",{value:!0}),e[Symbol.toStringTag]="Module"}));
1
+ var ut=Object.defineProperty,lt=Object.defineProperties;var ht=Object.getOwnPropertyDescriptors;var U=Object.getOwnPropertySymbols;var dt=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable;var k=(_,u,p)=>u in _?ut(_,u,{enumerable:!0,configurable:!0,writable:!0,value:p}):_[u]=p,V=(_,u)=>{for(var p in u||(u={}))dt.call(u,p)&&k(_,p,u[p]);if(U)for(var p of U(u))ft.call(u,p)&&k(_,p,u[p]);return _},z=(_,u)=>lt(_,ht(u));var v=(_,u,p)=>(k(_,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={},M={},C={},E={};Object.defineProperty(E,"__esModule",{value:!0});function F(o){return Object.keys(o)}E.keys=F;var G=Math.floor(Date.now()*Math.random()),N=0;function $(o){return o+"-"+G+"-"+N++}E.uniqueId=$;function Y(o){return Array.isArray(o)?o:[o]}E.toArray=Y;function Q(){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=Q;var j={},x={};(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={}))})(x);var H=u&&u.__assign||function(){return H=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},H.apply(this,arguments)};Object.defineProperty(j,"__esModule",{value:!0});var b=x,K=E,B=function(o){return o.console}(typeof self!="undefined"?self:u),O=Object.create(null);function J(o){O[o]||(O[o]=[])}function X(o,t){O[o].push(t)}function Z(){return K.keys(b.config.console.methodsData).reduce(function(o,t){return o[t]=function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];b.config.console.logLevel<b.config.console.methodsData[t].logLevel?b.config.console.methodsData[t].save&&(J(t),X(t,n)):B[t].apply(B,n)},o},Object.create(null))}j.console=H({},Z(),{getSavedMessages:function(o){return O[o]||[]}});var I={};Object.defineProperty(I,"__esModule",{value:!0});var tt=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=tt,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(j),t(I)}(C),function(o){Object.defineProperty(o,"__esModule",{value:!0});var t=C;(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}(M);var P={};Object.defineProperty(P,"__esModule",{value:!0});var et=function(){function o(){}return o}();P.Adapter=et;var q={},A={},R={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)})()})})(R),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=R.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 nt=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)}}(),L=u&&u.__assign||function(){return L=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},L.apply(this,arguments)};Object.defineProperty(q,"__esModule",{value:!0});var rt=P,w=p,S=A,it=E,ot={origins:[],availableChanelId:[]},st=function(o){nt(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=L({},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),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=ot);var r=function(a){return function(c){return c.reduce(function(l,h){return l.add(h)},a)}},e=function(a,c){return it.pipe(w.toArray,r(c))(a)},i=e(n.origins||[],new w.UniqPrimitiveCollection([window.location.origin])),s=e(n.availableChanelId||[],new w.UniqPrimitiveCollection);return L({},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}(rt.Adapter);q.WindowAdapter=st,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(P),t(q),t(A),t(x),t(C)}(p);class at{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 D=o=>o&&o.message==="SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document."?z(V({},o),{message:"Local storage is not available! It is possible that the Browser is in incognito mode!"}):o;class ct{constructor(t){v(this,"_queue");v(this,"_events",[]);v(this,"_toRunEvents",[]);this._queue=new at(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(D(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}}const m=class extends ct{constructor(t,n){super(n);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).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),m._timer!=null&&clearTimeout(m._timer),m._timer=setTimeout(()=>{this._applyStyle({opacity:"1"})},0)}_hideIframe(){const t={opacity:"0"};this._applyStyle(t),m._timer!=null&&clearTimeout(m._timer),m._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())})})}};let T=m;v(T,"_timer",null);class W{constructor(t,n){v(this,"user",null);v(this,"_transport");v(this,"_clientUrl");v(this,"emitter",new R.exports.EventEmitter);this._clientUrl=(t||"https://waves.exchange/signer/")+`?${W._getCacheClean()}`,this._transport=new T(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,this._transport.dialog(e=>e.request("login").then(i=>(this.user=i,i)).catch(i=>(this._transport.dropConnection(),Promise.reject(D(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=W,Object.defineProperty(_,"__esModule",{value:!0}),_[Symbol.toStringTag]="Module"});
@@ -20,4 +20,5 @@ export declare class TransportIframe extends Transport<HTMLIFrameElement> {
20
20
  private _renderErrorPage;
21
21
  private _listenFetchURLError;
22
22
  }
23
+ export declare function isBrave(): boolean;
23
24
  export declare function isSafari(): boolean;
@@ -1,4 +1 @@
1
- export declare const createError: (error: Error) => {
2
- code: number;
3
- message: string | Error;
4
- };
1
+ export declare const createError: (error: Error) => Error;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@waves.exchange/provider-web",
3
- "version": "1.1.0",
3
+ "version": "1.1.4",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -15,10 +15,10 @@
15
15
  ],
16
16
  "repository": {
17
17
  "type": "git",
18
- "url": "https://github.com/waves-exchange/provider-web.git"
18
+ "url": "https://github.com/waves-exchange/signer-providers.git"
19
19
  },
20
20
  "bugs": {
21
- "url": "https://github.com/waves-exchange/provider-web/issues",
21
+ "url": "https://github.com/waves-exchange/signer-providers/issues",
22
22
  "email": "support@waves.exchange"
23
23
  },
24
24
  "homepage": "https://waves.exchange",