@waves.exchange/provider-web 1.0.2 → 1.1.3
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 +2 -1
- package/dist/provider-web.cjs.js +63 -20
- package/dist/provider-web.es.js +65 -22
- package/dist/provider-web.min.js +1 -1
- package/dist/types/TransportIframe.d.ts +1 -0
- package/dist/types/createError.d.ts +1 -0
- package/package.json +3 -3
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.
|
|
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
|
|
package/dist/provider-web.cjs.js
CHANGED
|
@@ -1,11 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
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 });
|
|
3
26
|
exports[Symbol.toStringTag] = "Module";
|
|
4
27
|
var wavesBrowserBus = require("@waves/waves-browser-bus");
|
|
5
28
|
var typedTsEvents = require("typed-ts-events");
|
|
6
29
|
class Queue {
|
|
7
30
|
constructor(maxLength) {
|
|
8
|
-
this
|
|
31
|
+
__publicField(this, "_actions", []);
|
|
32
|
+
__publicField(this, "_maxLength");
|
|
33
|
+
__publicField(this, "_active");
|
|
9
34
|
this._maxLength = maxLength;
|
|
10
35
|
}
|
|
11
36
|
get length() {
|
|
@@ -31,7 +56,7 @@ class Queue {
|
|
|
31
56
|
onEnd();
|
|
32
57
|
reject(err);
|
|
33
58
|
});
|
|
34
|
-
this._actions.push({action: actionCallback, reject});
|
|
59
|
+
this._actions.push({ action: actionCallback, reject });
|
|
35
60
|
if (this.length === 1) {
|
|
36
61
|
this.run();
|
|
37
62
|
}
|
|
@@ -54,10 +79,19 @@ class Queue {
|
|
|
54
79
|
this._active = item.action();
|
|
55
80
|
}
|
|
56
81
|
}
|
|
82
|
+
const createError = (error) => {
|
|
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
|
+
});
|
|
87
|
+
}
|
|
88
|
+
return error;
|
|
89
|
+
};
|
|
57
90
|
class Transport {
|
|
58
91
|
constructor(queueLength) {
|
|
59
|
-
this
|
|
60
|
-
this
|
|
92
|
+
__publicField(this, "_queue");
|
|
93
|
+
__publicField(this, "_events", []);
|
|
94
|
+
__publicField(this, "_toRunEvents", []);
|
|
61
95
|
this._queue = new Queue(queueLength);
|
|
62
96
|
}
|
|
63
97
|
dropConnection() {
|
|
@@ -80,7 +114,7 @@ class Transport {
|
|
|
80
114
|
return result;
|
|
81
115
|
}).catch((error) => {
|
|
82
116
|
this._runAfterShow();
|
|
83
|
-
return Promise.reject(error);
|
|
117
|
+
return Promise.reject(createError(error));
|
|
84
118
|
});
|
|
85
119
|
} else {
|
|
86
120
|
return Promise.reject(new Error("Queue is full!"));
|
|
@@ -110,9 +144,12 @@ class Transport {
|
|
|
110
144
|
} : action;
|
|
111
145
|
}
|
|
112
146
|
}
|
|
113
|
-
const
|
|
147
|
+
const _TransportIframe = class extends Transport {
|
|
114
148
|
constructor(url, queueLength) {
|
|
115
149
|
super(queueLength);
|
|
150
|
+
__publicField(this, "_url");
|
|
151
|
+
__publicField(this, "_iframe");
|
|
152
|
+
__publicField(this, "_bus");
|
|
116
153
|
this._url = url;
|
|
117
154
|
this._initIframe();
|
|
118
155
|
}
|
|
@@ -190,11 +227,11 @@ const TransportIframe2 = class extends Transport {
|
|
|
190
227
|
zIndex: "99999999"
|
|
191
228
|
};
|
|
192
229
|
this._applyStyle(shownStyles);
|
|
193
|
-
if (
|
|
194
|
-
clearTimeout(
|
|
230
|
+
if (_TransportIframe._timer != null) {
|
|
231
|
+
clearTimeout(_TransportIframe._timer);
|
|
195
232
|
}
|
|
196
|
-
|
|
197
|
-
this._applyStyle({opacity: "1"});
|
|
233
|
+
_TransportIframe._timer = setTimeout(() => {
|
|
234
|
+
this._applyStyle({ opacity: "1" });
|
|
198
235
|
}, 0);
|
|
199
236
|
}
|
|
200
237
|
_hideIframe() {
|
|
@@ -202,10 +239,10 @@ const TransportIframe2 = class extends Transport {
|
|
|
202
239
|
opacity: "0"
|
|
203
240
|
};
|
|
204
241
|
this._applyStyle(hiddenStyle);
|
|
205
|
-
if (
|
|
206
|
-
clearTimeout(
|
|
242
|
+
if (_TransportIframe._timer != null) {
|
|
243
|
+
clearTimeout(_TransportIframe._timer);
|
|
207
244
|
}
|
|
208
|
-
|
|
245
|
+
_TransportIframe._timer = setTimeout(() => {
|
|
209
246
|
this._applyStyle({
|
|
210
247
|
width: "10px",
|
|
211
248
|
height: "10px",
|
|
@@ -307,8 +344,12 @@ const TransportIframe2 = class extends Transport {
|
|
|
307
344
|
});
|
|
308
345
|
}
|
|
309
346
|
};
|
|
310
|
-
let TransportIframe =
|
|
311
|
-
TransportIframe
|
|
347
|
+
let TransportIframe = _TransportIframe;
|
|
348
|
+
__publicField(TransportIframe, "_timer", null);
|
|
349
|
+
function isBrave() {
|
|
350
|
+
var _a;
|
|
351
|
+
return !!((_a = navigator.brave) == null ? void 0 : _a.isBrave);
|
|
352
|
+
}
|
|
312
353
|
function isSafari() {
|
|
313
354
|
const userAgent = navigator.userAgent.toLowerCase();
|
|
314
355
|
const isSafariUA = userAgent.includes("safari") && !userAgent.includes("chrome");
|
|
@@ -317,8 +358,10 @@ function isSafari() {
|
|
|
317
358
|
}
|
|
318
359
|
class ProviderWeb {
|
|
319
360
|
constructor(clientUrl, logs) {
|
|
320
|
-
this
|
|
321
|
-
this
|
|
361
|
+
__publicField(this, "user", null);
|
|
362
|
+
__publicField(this, "_transport");
|
|
363
|
+
__publicField(this, "_clientUrl");
|
|
364
|
+
__publicField(this, "emitter", new typedTsEvents.EventEmitter());
|
|
322
365
|
this._clientUrl = (clientUrl || "https://waves.exchange/signer/") + `?${ProviderWeb._getCacheClean()}`;
|
|
323
366
|
this._transport = new TransportIframe(this._clientUrl, 3);
|
|
324
367
|
if (logs === true) {
|
|
@@ -353,7 +396,7 @@ class ProviderWeb {
|
|
|
353
396
|
return Promise.resolve(this.user);
|
|
354
397
|
}
|
|
355
398
|
const iframe = this._transport.get();
|
|
356
|
-
if (isSafari()) {
|
|
399
|
+
if (isSafari() || isBrave()) {
|
|
357
400
|
const win = (_a = iframe.contentWindow) == null ? void 0 : _a.open(this._clientUrl);
|
|
358
401
|
if (!win) {
|
|
359
402
|
throw new Error("Window was blocked");
|
|
@@ -365,7 +408,7 @@ class ProviderWeb {
|
|
|
365
408
|
return userData;
|
|
366
409
|
}).catch((err) => {
|
|
367
410
|
this._transport.dropConnection();
|
|
368
|
-
return Promise.reject(err);
|
|
411
|
+
return Promise.reject(createError(err));
|
|
369
412
|
}));
|
|
370
413
|
}
|
|
371
414
|
signMessage(data) {
|
package/dist/provider-web.es.js
CHANGED
|
@@ -1,8 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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";
|
|
3
26
|
class Queue {
|
|
4
27
|
constructor(maxLength) {
|
|
5
|
-
this
|
|
28
|
+
__publicField(this, "_actions", []);
|
|
29
|
+
__publicField(this, "_maxLength");
|
|
30
|
+
__publicField(this, "_active");
|
|
6
31
|
this._maxLength = maxLength;
|
|
7
32
|
}
|
|
8
33
|
get length() {
|
|
@@ -28,7 +53,7 @@ class Queue {
|
|
|
28
53
|
onEnd();
|
|
29
54
|
reject(err);
|
|
30
55
|
});
|
|
31
|
-
this._actions.push({action: actionCallback, reject});
|
|
56
|
+
this._actions.push({ action: actionCallback, reject });
|
|
32
57
|
if (this.length === 1) {
|
|
33
58
|
this.run();
|
|
34
59
|
}
|
|
@@ -51,10 +76,19 @@ class Queue {
|
|
|
51
76
|
this._active = item.action();
|
|
52
77
|
}
|
|
53
78
|
}
|
|
79
|
+
const createError = (error) => {
|
|
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
|
+
});
|
|
84
|
+
}
|
|
85
|
+
return error;
|
|
86
|
+
};
|
|
54
87
|
class Transport {
|
|
55
88
|
constructor(queueLength) {
|
|
56
|
-
this
|
|
57
|
-
this
|
|
89
|
+
__publicField(this, "_queue");
|
|
90
|
+
__publicField(this, "_events", []);
|
|
91
|
+
__publicField(this, "_toRunEvents", []);
|
|
58
92
|
this._queue = new Queue(queueLength);
|
|
59
93
|
}
|
|
60
94
|
dropConnection() {
|
|
@@ -77,7 +111,7 @@ class Transport {
|
|
|
77
111
|
return result;
|
|
78
112
|
}).catch((error) => {
|
|
79
113
|
this._runAfterShow();
|
|
80
|
-
return Promise.reject(error);
|
|
114
|
+
return Promise.reject(createError(error));
|
|
81
115
|
});
|
|
82
116
|
} else {
|
|
83
117
|
return Promise.reject(new Error("Queue is full!"));
|
|
@@ -107,9 +141,12 @@ class Transport {
|
|
|
107
141
|
} : action;
|
|
108
142
|
}
|
|
109
143
|
}
|
|
110
|
-
const
|
|
144
|
+
const _TransportIframe = class extends Transport {
|
|
111
145
|
constructor(url, queueLength) {
|
|
112
146
|
super(queueLength);
|
|
147
|
+
__publicField(this, "_url");
|
|
148
|
+
__publicField(this, "_iframe");
|
|
149
|
+
__publicField(this, "_bus");
|
|
113
150
|
this._url = url;
|
|
114
151
|
this._initIframe();
|
|
115
152
|
}
|
|
@@ -187,11 +224,11 @@ const TransportIframe2 = class extends Transport {
|
|
|
187
224
|
zIndex: "99999999"
|
|
188
225
|
};
|
|
189
226
|
this._applyStyle(shownStyles);
|
|
190
|
-
if (
|
|
191
|
-
clearTimeout(
|
|
227
|
+
if (_TransportIframe._timer != null) {
|
|
228
|
+
clearTimeout(_TransportIframe._timer);
|
|
192
229
|
}
|
|
193
|
-
|
|
194
|
-
this._applyStyle({opacity: "1"});
|
|
230
|
+
_TransportIframe._timer = setTimeout(() => {
|
|
231
|
+
this._applyStyle({ opacity: "1" });
|
|
195
232
|
}, 0);
|
|
196
233
|
}
|
|
197
234
|
_hideIframe() {
|
|
@@ -199,10 +236,10 @@ const TransportIframe2 = class extends Transport {
|
|
|
199
236
|
opacity: "0"
|
|
200
237
|
};
|
|
201
238
|
this._applyStyle(hiddenStyle);
|
|
202
|
-
if (
|
|
203
|
-
clearTimeout(
|
|
239
|
+
if (_TransportIframe._timer != null) {
|
|
240
|
+
clearTimeout(_TransportIframe._timer);
|
|
204
241
|
}
|
|
205
|
-
|
|
242
|
+
_TransportIframe._timer = setTimeout(() => {
|
|
206
243
|
this._applyStyle({
|
|
207
244
|
width: "10px",
|
|
208
245
|
height: "10px",
|
|
@@ -304,8 +341,12 @@ const TransportIframe2 = class extends Transport {
|
|
|
304
341
|
});
|
|
305
342
|
}
|
|
306
343
|
};
|
|
307
|
-
let TransportIframe =
|
|
308
|
-
TransportIframe
|
|
344
|
+
let TransportIframe = _TransportIframe;
|
|
345
|
+
__publicField(TransportIframe, "_timer", null);
|
|
346
|
+
function isBrave() {
|
|
347
|
+
var _a;
|
|
348
|
+
return !!((_a = navigator.brave) == null ? void 0 : _a.isBrave);
|
|
349
|
+
}
|
|
309
350
|
function isSafari() {
|
|
310
351
|
const userAgent = navigator.userAgent.toLowerCase();
|
|
311
352
|
const isSafariUA = userAgent.includes("safari") && !userAgent.includes("chrome");
|
|
@@ -314,8 +355,10 @@ function isSafari() {
|
|
|
314
355
|
}
|
|
315
356
|
class ProviderWeb {
|
|
316
357
|
constructor(clientUrl, logs) {
|
|
317
|
-
this
|
|
318
|
-
this
|
|
358
|
+
__publicField(this, "user", null);
|
|
359
|
+
__publicField(this, "_transport");
|
|
360
|
+
__publicField(this, "_clientUrl");
|
|
361
|
+
__publicField(this, "emitter", new EventEmitter());
|
|
319
362
|
this._clientUrl = (clientUrl || "https://waves.exchange/signer/") + `?${ProviderWeb._getCacheClean()}`;
|
|
320
363
|
this._transport = new TransportIframe(this._clientUrl, 3);
|
|
321
364
|
if (logs === true) {
|
|
@@ -350,7 +393,7 @@ class ProviderWeb {
|
|
|
350
393
|
return Promise.resolve(this.user);
|
|
351
394
|
}
|
|
352
395
|
const iframe = this._transport.get();
|
|
353
|
-
if (isSafari()) {
|
|
396
|
+
if (isSafari() || isBrave()) {
|
|
354
397
|
const win = (_a = iframe.contentWindow) == null ? void 0 : _a.open(this._clientUrl);
|
|
355
398
|
if (!win) {
|
|
356
399
|
throw new Error("Window was blocked");
|
|
@@ -362,7 +405,7 @@ class ProviderWeb {
|
|
|
362
405
|
return userData;
|
|
363
406
|
}).catch((err) => {
|
|
364
407
|
this._transport.dropConnection();
|
|
365
|
-
return Promise.reject(err);
|
|
408
|
+
return Promise.reject(createError(err));
|
|
366
409
|
}));
|
|
367
410
|
}
|
|
368
411
|
signMessage(data) {
|
|
@@ -375,4 +418,4 @@ class ProviderWeb {
|
|
|
375
418
|
return this.login().then(() => this._transport.dialog((bus) => bus.request("sign", toSign)));
|
|
376
419
|
}
|
|
377
420
|
}
|
|
378
|
-
export {ProviderWeb};
|
|
421
|
+
export { ProviderWeb };
|
package/dist/provider-web.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!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,y=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]||[]}}),g=Object.defineProperty({console:y},"__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(g),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))})),x=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})),S=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=I.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 S(t,e),t.prototype.addListener=function(e){return this.callbacks.push(e),I.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)})),I.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()})),I.console.info("WindowAdapter: Destroy")},t.prototype.onMessage=function(e){this.accessEvent(e)&&this.callbacks.forEach((function(t){try{t(e.data)}catch(n){I.console.warn("WindowAdapter: Unhandled exception!",n)}}))},t.prototype.accessEvent=function(e){if("object"!=typeof e.data||null==e.data.type)return I.console.info("WindowAdapter: Block event. Wrong event format!",e.data),!1;if(!this.options.origins.has("*")&&!this.options.origins.has(e.origin))return I.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||I.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 x.WindowProtocol(window,x.WindowProtocol.PROTOCOL_TYPES.LISTEN),c=function(e){s.push(e)};return a.on("message",c),this.getIframeContent(e).then((function(e){var n=new x.WindowProtocol(e.win,x.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(I.toArray,(n=t,function(e){return e.reduce((function(e,t){return e.add(t)}),n)}))(e);var n},n=t(e.origins||[],new I.UniqPrimitiveCollection([window.location.origin])),o=t(e.availableChanelId||[],new I.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),R=Object.defineProperty({WindowAdapter:H},"__esModule",{value:!0}),I=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(R),n(x),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=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(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):I.WindowAdapter.createSimpleWindowAdapter(this._iframe).then((e=>new Promise((t=>{this._bus=new I.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!=T._timer&&clearTimeout(T._timer),T._timer=setTimeout((()=>{this._applyStyle({opacity:"1"})}),0)}_hideIframe(){this._applyStyle({opacity:"0"}),null!=T._timer&&clearTimeout(T._timer),T._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 A=T;A._timer=null;class W{constructor(e,t){this.user=null,this.emitter=new L.EventEmitter,this._clientUrl=(e||"https://waves.exchange/signer/")+`?${W._getCacheClean()}`,this._transport=new A(this._clientUrl,3),!0===t&&(I.config.console.logLevel=I.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(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=W,Object.defineProperty(e,"__esModule",{value:!0}),e[Symbol.toStringTag]="Module"}));
|
|
1
|
+
var ht=Object.defineProperty,dt=Object.defineProperties;var ft=Object.getOwnPropertyDescriptors;var U=Object.getOwnPropertySymbols;var pt=Object.prototype.hasOwnProperty,_t=Object.prototype.propertyIsEnumerable;var k=(_,u,p)=>u in _?ht(_,u,{enumerable:!0,configurable:!0,writable:!0,value:p}):_[u]=p,V=(_,u)=>{for(var p in u||(u={}))pt.call(u,p)&&k(_,p,u[p]);if(U)for(var p of U(u))_t.call(u,p)&&k(_,p,u[p]);return _},z=(_,u)=>dt(_,ft(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={},m={};Object.defineProperty(m,"__esModule",{value:!0});function F(o){return Object.keys(o)}m.keys=F;var G=Math.floor(Date.now()*Math.random()),N=0;function $(o){return o+"-"+G+"-"+N++}m.uniqueId=$;function Y(o){return Array.isArray(o)?o:[o]}m.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)}}m.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 A=u&&u.__assign||function(){return A=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},A.apply(this,arguments)};Object.defineProperty(j,"__esModule",{value:!0});var b=x,K=m,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=A({},Z(),{getSavedMessages:function(o){return O[o]||[]}});var H={};Object.defineProperty(H,"__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}();H.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(m),t(j),t(H)}(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 y=new Error('Timeout error for request with name "'+e+'" and timeout '+d+"!");t.console.error(y),l(y)},d));var g=function(){f&&clearTimeout(f)};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}(M);var P={};Object.defineProperty(P,"__esModule",{value:!0});var et=function(){function o(){}return o}();P.Adapter=et;var I={},q={},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 g=this._events[d].map(function(y){return y.handler}).indexOf(f);this._events[d].splice(g,1)}}else delete this._events[d];else Object.keys(this._events).forEach(function(y){h.off(y,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,g){g===void 0&&(g=f),Object.defineProperty(h,g,{enumerable:!0,get:function(){return d[f]}})}:function(h,d,f,g){g===void 0&&(g=f),h[g]=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}(q);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)}}(),S=u&&u.__assign||function(){return S=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},S.apply(this,arguments)};Object.defineProperty(I,"__esModule",{value:!0});var rt=P,w=p,L=q,it=m,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=S({},n,{chanelId:this.options.chanelId});return this.dispatch.forEach(function(e){return e.dispatch(r)}),w.console.info("WindowAdapter: Send message",r),this},t.prototype.destroy=function(){this.listen.forEach(function(n){return n.destroy()}),this.dispatch.forEach(function(n){return n.destroy()}),w.console.info("WindowAdapter: Destroy")},t.prototype.onMessage=function(n){this.accessEvent(n)&&this.callbacks.forEach(function(r){try{r(n.data)}catch(e){w.console.warn("WindowAdapter: Unhandled exception!",e)}})},t.prototype.accessEvent=function(n){if(typeof n.data!="object"||n.data.type==null)return w.console.info("WindowAdapter: Block event. Wrong event format!",n.data),!1;if(!this.options.origins.has("*")&&!this.options.origins.has(n.origin))return w.console.info('SimpleWindowAdapter: Block event by origin "'+n.origin+'"'),!1;if(!this.options.availableChanelId.size)return!0;var r=!!(n.data.chanelId&&this.options.availableChanelId.has(n.data.chanelId));return r||w.console.info('SimpleWindowAdapter: Block event by chanel id "'+n.data.chanelId+'"'),r},t.createSimpleWindowAdapter=function(n,r){var e=this,i=this.getContentOrigin(n),s=this.prepareOptions(r),a=[];i&&s.origins.add(i);var c=new L.WindowProtocol(window,L.WindowProtocol.PROTOCOL_TYPES.LISTEN),l=function(h){a.push(h)};return c.on("message",l),this.getIframeContent(n).then(function(h){var d=new L.WindowProtocol(h.win,L.WindowProtocol.PROTOCOL_TYPES.DISPATCH),f=new t([c],[d],e.unPrepareOptions(s));return a.forEach(function(g){f.onMessage(g)}),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 S({},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);I.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(I),t(q),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 E=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),E._timer!=null&&clearTimeout(E._timer),E._timer=setTimeout(()=>{this._applyStyle({opacity:"1"})},0)}_hideIframe(){const t={opacity:"0"};this._applyStyle(t),E._timer!=null&&clearTimeout(E._timer),E._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=E;v(T,"_timer",null);function ut(){var o;return!!((o=navigator.brave)==null?void 0:o.isBrave)}function lt(){const o=navigator.userAgent.toLowerCase(),t=o.includes("safari")&&!o.includes("chrome");return navigator.platform!=null&&/iPad|iPhone|iPod/.test(navigator.platform)||t}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 n;if(this.user)return Promise.resolve(this.user);const t=this._transport.get();if((lt()||ut())&&!((n=t.contentWindow)==null?void 0:n.open(this._clientUrl)))throw new Error("Window was blocked");return t.src=this._clientUrl,this._transport.dialog(r=>r.request("login").then(e=>(this.user=e,e)).catch(e=>(this._transport.dropConnection(),Promise.reject(D(e)))))}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"});
|
|
@@ -0,0 +1 @@
|
|
|
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.
|
|
3
|
+
"version": "1.1.3",
|
|
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/
|
|
18
|
+
"url": "https://github.com/waves-exchange/signer-providers.git"
|
|
19
19
|
},
|
|
20
20
|
"bugs": {
|
|
21
|
-
"url": "https://github.com/waves-exchange/
|
|
21
|
+
"url": "https://github.com/waves-exchange/signer-providers/issues",
|
|
22
22
|
"email": "support@waves.exchange"
|
|
23
23
|
},
|
|
24
24
|
"homepage": "https://waves.exchange",
|