@waves.exchange/provider-web 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/provider-web.cjs.js +2 -2
- package/dist/provider-web.es.js +2 -2
- package/dist/provider-web.min.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
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. Users' encrypted private keys and SEED phrase are stored in
|
|
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 wx.network domain of the local browser storage. WX.Network and other apps do not have access to the local data as they are stored encrypted.
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
> For now, signing is implemented for all types of transactions except exchange transactions.
|
|
@@ -48,7 +48,7 @@ Add library initialization to your app.
|
|
|
48
48
|
// Specify URL of the node on Testnet
|
|
49
49
|
NODE_URL: 'https://nodes-testnet.wavesnodes.com'
|
|
50
50
|
});
|
|
51
|
-
signer.setProvider(new ProviderWeb('https://testnet.
|
|
51
|
+
signer.setProvider(new ProviderWeb('https://testnet.wx.network/signer'));
|
|
52
52
|
```
|
|
53
53
|
|
|
54
54
|
* For Mainnet:
|
|
@@ -90,7 +90,7 @@ You can use optional parameters for debugging.
|
|
|
90
90
|
|
|
91
91
|
| Parameter | Default value | Description |
|
|
92
92
|
| :--- | :--- | :--- |
|
|
93
|
-
| clientOrigin | https://
|
|
93
|
+
| clientOrigin | https://wx.network/signer | URL of the ProviderWeb instance. For debugging, you can launch the ProviderWeb instance on your server. |
|
|
94
94
|
| logs | false | Logging level. If `true`, all events are logged |
|
|
95
95
|
|
|
96
96
|
**Usage:**
|
package/dist/provider-web.cjs.js
CHANGED
|
@@ -336,7 +336,7 @@ class TransportIframe extends Transport {
|
|
|
336
336
|
bodyElement.appendChild(wrapperElement);
|
|
337
337
|
}
|
|
338
338
|
_listenFetchURLError(iframe) {
|
|
339
|
-
fetch(this._url).catch(() => {
|
|
339
|
+
fetch(new URL(this._url).origin).catch(() => {
|
|
340
340
|
iframe.addEventListener("load", () => {
|
|
341
341
|
if (!iframe.contentDocument) {
|
|
342
342
|
return;
|
|
@@ -369,7 +369,7 @@ class ProviderWeb {
|
|
|
369
369
|
__publicField(this, "_transport");
|
|
370
370
|
__publicField(this, "_clientUrl");
|
|
371
371
|
__publicField(this, "emitter", new typedTsEvents.EventEmitter());
|
|
372
|
-
this._clientUrl = (clientUrl || "https://
|
|
372
|
+
this._clientUrl = (clientUrl || "https://wx.network/signer/") + `?${ProviderWeb._getCacheClean()}`;
|
|
373
373
|
this._transport = new TransportIframe(this._clientUrl, 3);
|
|
374
374
|
if (logs === true) {
|
|
375
375
|
wavesBrowserBus.config.console.logLevel = wavesBrowserBus.config.console.LOG_LEVEL.VERBOSE;
|
package/dist/provider-web.es.js
CHANGED
|
@@ -333,7 +333,7 @@ class TransportIframe extends Transport {
|
|
|
333
333
|
bodyElement.appendChild(wrapperElement);
|
|
334
334
|
}
|
|
335
335
|
_listenFetchURLError(iframe) {
|
|
336
|
-
fetch(this._url).catch(() => {
|
|
336
|
+
fetch(new URL(this._url).origin).catch(() => {
|
|
337
337
|
iframe.addEventListener("load", () => {
|
|
338
338
|
if (!iframe.contentDocument) {
|
|
339
339
|
return;
|
|
@@ -366,7 +366,7 @@ class ProviderWeb {
|
|
|
366
366
|
__publicField(this, "_transport");
|
|
367
367
|
__publicField(this, "_clientUrl");
|
|
368
368
|
__publicField(this, "emitter", new EventEmitter());
|
|
369
|
-
this._clientUrl = (clientUrl || "https://
|
|
369
|
+
this._clientUrl = (clientUrl || "https://wx.network/signer/") + `?${ProviderWeb._getCacheClean()}`;
|
|
370
370
|
this._transport = new TransportIframe(this._clientUrl, 3);
|
|
371
371
|
if (logs === true) {
|
|
372
372
|
config.console.logLevel = config.console.LOG_LEVEL.VERBOSE;
|
package/dist/provider-web.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var ut=Object.defineProperty,lt=Object.defineProperties;var ht=Object.getOwnPropertyDescriptors;var B=Object.getOwnPropertySymbols;var dt=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable;var T=(_,u,f)=>u in _?ut(_,u,{enumerable:!0,configurable:!0,writable:!0,value:f}):_[u]=f,D=(_,u)=>{for(var f in u||(u={}))dt.call(u,f)&&T(_,f,u[f]);if(B)for(var f of B(u))ft.call(u,f)&&T(_,f,u[f]);return _},U=(_,u)=>lt(_,ht(u));var v=(_,u,f)=>(T(_,typeof u!="symbol"?u+"":u,f),f);(function(_,u){typeof exports=="object"&&typeof module!="undefined"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(_=typeof globalThis!="undefined"?globalThis:_||self,u(_.providerWeb={}))})(this,function(_){"use strict";var u=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},f={},W={},L={},m={};Object.defineProperty(m,"__esModule",{value:!0});function V(o){return Object.keys(o)}m.keys=V;var $=Math.floor(Date.now()*Math.random()),z=0;function F(o){return o+"-"+$+"-"+z++}m.uniqueId=F;function G(o){return Array.isArray(o)?o:[o]}m.toArray=G;function N(){for(var o=[],t=0;t<arguments.length;t++)o[t]=arguments[t];return function(n){return o.reduce(function(r,e){return e(r)},n)}}m.pipe=N;var C={},j={};(function(o){Object.defineProperty(o,"__esModule",{value:!0}),function(t){(function(n){n.LOG_LEVEL={PRODUCTION:0,ERRORS:1,VERBOSE:2},n.logLevel=n.LOG_LEVEL.PRODUCTION,n.methodsData={log:{save:!1,logLevel:n.LOG_LEVEL.VERBOSE},info:{save:!1,logLevel:n.LOG_LEVEL.VERBOSE},warn:{save:!1,logLevel:n.LOG_LEVEL.VERBOSE},error:{save:!0,logLevel:n.LOG_LEVEL.ERRORS}}})(t.console||(t.console={}))}(o.config||(o.config={}))})(j);var x=u&&u.__assign||function(){return x=Object.assign||function(o){for(var t,n=1,r=arguments.length;n<r;n++){t=arguments[n];for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&(o[e]=t[e])}return o},x.apply(this,arguments)};Object.defineProperty(C,"__esModule",{value:!0});var E=j,Y=m,k=function(o){return o.console}(typeof self!="undefined"?self:u),b=Object.create(null);function Q(o){b[o]||(b[o]=[])}function K(o,t){b[o].push(t)}function J(){return Y.keys(E.config.console.methodsData).reduce(function(o,t){return o[t]=function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];E.config.console.logLevel<E.config.console.methodsData[t].logLevel?E.config.console.methodsData[t].save&&(Q(t),K(t,n)):k[t].apply(k,n)},o},Object.create(null))}C.console=x({},J(),{getSavedMessages:function(o){return b[o]||[]}});var I={};Object.defineProperty(I,"__esModule",{value:!0});var X=function(){function o(t){this.size=0,this.hash=Object.create(null),t&&t.forEach(this.add,this)}return o.prototype.add=function(t){return this.hash[t]=!0,this.size=Object.keys(this.hash).length,this},o.prototype.has=function(t){return t in this.hash},o.prototype.toArray=function(){return Object.keys(this.hash)},o}();I.UniqPrimitiveCollection=X,function(o){function t(n){for(var r in n)o.hasOwnProperty(r)||(o[r]=n[r])}Object.defineProperty(o,"__esModule",{value:!0}),t(m),t(C),t(I)}(L),function(o){Object.defineProperty(o,"__esModule",{value:!0});var t=L;(function(r){r[r.Event=0]="Event",r[r.Action=1]="Action",r[r.Response=2]="Response"})(o.EventType||(o.EventType={})),function(r){r[r.Success=0]="Success",r[r.Error=1]="Error"}(o.ResponseStatus||(o.ResponseStatus={}));var n=function(){function r(e,i){var s=this;this.id=t.uniqueId("bus"),this._timeout=i||5e3,this._adapter=e,this._adapter.addListener(function(a){return s._onMessage(a)}),this._eventHandlers=Object.create(null),this._activeRequestHash=Object.create(null),this._requestHandlers=Object.create(null),t.console.info('Create Bus with id "'+this.id+'"')}return r.prototype.dispatchEvent=function(e,i){return this._adapter.send(r._createEvent(e,i)),t.console.info('Dispatch event "'+e+'"',i),this},r.prototype.request=function(e,i,s){var a=this;return new Promise(function(c,l){var h=t.uniqueId(a.id+"-action"),d=s||a._timeout,p;(s||a._timeout)!==-1&&(p=setTimeout(function(){delete a._activeRequestHash[h];var y=new Error('Timeout error for request with name "'+e+'" and timeout '+d+"!");t.console.error(y),l(y)},d));var g=function(){p&&clearTimeout(p)};a._activeRequestHash[h]={reject:function(y){g(),t.console.error('Error request with name "'+e+'"',y),l(y)},resolve:function(y){g(),t.console.info('Request with name "'+e+'" success resolved!',y),c(y)}},a._adapter.send({id:h,type:1,name:e,data:i}),t.console.info('Request with name "'+e+'"',i)})},r.prototype.on=function(e,i,s){return this._addEventHandler(e,i,s,!1)},r.prototype.once=function(e,i,s){return this._addEventHandler(e,i,s,!0)},r.prototype.off=function(e,i){var s=this;return e?this._eventHandlers[e]?i?(this._eventHandlers[e]=this._eventHandlers[e].filter(function(a){return a.handler!==i}),this._eventHandlers[e].length||delete this._eventHandlers[e],this):(this._eventHandlers[e].slice().forEach(function(a){s.off(e,a.handler)}),this):this:(Object.keys(this._eventHandlers).forEach(function(a){return s.off(a,i)}),this)},r.prototype.registerRequestHandler=function(e,i){if(this._requestHandlers[e])throw new Error("Duplicate request handler!");return this._requestHandlers[e]=i,this},r.prototype.unregisterHandler=function(e){return this._requestHandlers[e]&&delete this._requestHandlers[e],this},r.prototype.changeAdapter=function(e){var i=this,s=new r(e,this._timeout);return Object.keys(this._eventHandlers).forEach(function(a){i._eventHandlers[a].forEach(function(c){c.once?s.once(a,c.handler,c.context):s.on(a,c.handler,c.context)})}),Object.keys(this._requestHandlers).forEach(function(a){s.registerRequestHandler(a,i._requestHandlers[a])}),s},r.prototype.destroy=function(){t.console.info("Destroy Bus"),this.off(),this._adapter.destroy()},r.prototype._addEventHandler=function(e,i,s,a){return this._eventHandlers[e]||(this._eventHandlers[e]=[]),this._eventHandlers[e].push({handler:i,once:a,context:s}),this},r.prototype._onMessage=function(e){switch(e.type){case 0:t.console.info('Has event with name "'+String(e.name)+'"',e.data),this._fireEvent(String(e.name),e.data);break;case 1:t.console.info('Start action with id "'+e.id+'" and name "'+String(e.name)+'"',e.data),this._createResponse(e);break;case 2:t.console.info('Start response with name "'+e.id+'" and status "'+e.status+'"',e.content),this._fireEndAction(e);break}},r.prototype._createResponse=function(e){var i=this,s=function(c){t.console.error(c),i._adapter.send({id:e.id,type:2,status:1,content:String(c)})};if(!this._requestHandlers[String(e.name)]){s(new Error('Has no handler for "'+String(e.name)+'" action!'));return}try{var a=this._requestHandlers[String(e.name)](e.data);r._isPromise(a)?a.then(function(c){i._adapter.send({id:e.id,type:2,status:0,content:c})},s):this._adapter.send({id:e.id,type:2,status:0,content:a})}catch(c){s(c)}},r.prototype._fireEndAction=function(e){if(this._activeRequestHash[e.id]){switch(e.status){case 1:this._activeRequestHash[e.id].reject(e.content);break;case 0:this._activeRequestHash[e.id].resolve(e.content);break}delete this._activeRequestHash[e.id]}},r.prototype._fireEvent=function(e,i){!this._eventHandlers[e]||(this._eventHandlers[e]=this._eventHandlers[e].slice().filter(function(s){try{s.handler.call(s.context,i)}catch(a){t.console.warn(a)}return!s.once}),this._eventHandlers[e].length||delete this._eventHandlers[e])},r._createEvent=function(e,i){return{type:0,name:e,data:i}},r._isPromise=function(e){return e&&e.then&&typeof e.then=="function"},r}();o.Bus=n}(W);var O={};Object.defineProperty(O,"__esModule",{value:!0});var Z=function(){function o(){}return o}();O.Adapter=Z;var H={},A={},q={exports:{}};(function(o,t){(function(n,r){o.exports=r()})(u,function(){return(()=>{var n={660:(e,i)=>{i.__esModule=!0,i.EventEmitter=void 0;var s=function(){function a(c){this._events=Object.create(null),this.catchHandler=c||function(){}}return a.prototype.hasListeners=function(c){return!(!this._events[c]||!this._events[c].length)},a.prototype.getActiveEvents=function(){var c=this;return Object.keys(this._events).filter(function(l){return c.hasListeners(l)})},a.prototype.trigger=function(c,l){var h=this;this._events[c]&&(this._events[c].slice().forEach(function(d){try{d.handler.call(d.context,l)}catch(p){h.catchHandler(p)}d.once&&h.off(c,d.handler)}),this._events[c].length||delete this._events[c])},a.prototype.on=function(c,l,h){this._on(c,l,h,!1)},a.prototype.once=function(c,l,h){this._on(c,l,h,!0)},a.prototype.off=function(c,l){var h=this,d=typeof c=="string"?c:null,p=typeof l=="function"?l:typeof c=="function"?c:null;if(d)if(p){if(d in this._events){var g=this._events[d].map(function(y){return y.handler}).indexOf(p);this._events[d].splice(g,1)}}else delete this._events[d];else Object.keys(this._events).forEach(function(y){h.off(y,p)})},a.prototype._on=function(c,l,h,d){this._events[c]||(this._events[c]=[]),this._events[c].push({handler:l,context:h,once:d})},a}();i.EventEmitter=s},607:function(e,i,s){var a=this&&this.__createBinding||(Object.create?function(h,d,p,g){g===void 0&&(g=p),Object.defineProperty(h,g,{enumerable:!0,get:function(){return d[p]}})}:function(h,d,p,g){g===void 0&&(g=p),h[g]=d[p]}),c=this&&this.__exportStar||function(h,d){for(var p in h)p==="default"||Object.prototype.hasOwnProperty.call(d,p)||a(d,h,p)};i.__esModule=!0;var l=s(660);c(s(660),i),i.default=l.EventEmitter}},r={};return function e(i){if(r[i])return r[i].exports;var s=r[i]={exports:{}};return n[i].call(s.exports,s,s.exports,e),s.exports}(607)})()})})(q),function(o){var t=u&&u.__extends||function(){var e=function(i,s){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(a,c){a.__proto__=c}||function(a,c){for(var l in c)c.hasOwnProperty(l)&&(a[l]=c[l])},e(i,s)};return function(i,s){e(i,s);function a(){this.constructor=i}i.prototype=s===null?Object.create(s):(a.prototype=s.prototype,new a)}}();Object.defineProperty(o,"__esModule",{value:!0});var n=q.exports,r=function(e){t(i,e);function i(s,a){var c=e.call(this)||this;return c.win=s,c.type=a,c.handler=function(l){c.trigger("message",l)},a===i.PROTOCOL_TYPES.LISTEN&&c.win.addEventListener("message",c.handler,!1),c}return i.prototype.dispatch=function(s){return this.win.postMessage(s,"*"),this},i.prototype.destroy=function(){this.type===i.PROTOCOL_TYPES.LISTEN&&this.win.removeEventListener("message",this.handler,!1),this.win=i._fakeWin},i._fakeWin=function(){var s=function(){return null};return{postMessage:s,addEventListener:s,removeEventListener:s}}(),i}(n.EventEmitter);o.WindowProtocol=r,function(e){e.PROTOCOL_TYPES={LISTEN:"listen",DISPATCH:"dispatch"}}(r=o.WindowProtocol||(o.WindowProtocol={})),o.WindowProtocol=r}(A);var tt=u&&u.__extends||function(){var o=function(t,n){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,e){r.__proto__=e}||function(r,e){for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i])},o(t,n)};return function(t,n){o(t,n);function r(){this.constructor=t}t.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}}(),P=u&&u.__assign||function(){return P=Object.assign||function(o){for(var t,n=1,r=arguments.length;n<r;n++){t=arguments[n];for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&(o[e]=t[e])}return o},P.apply(this,arguments)};Object.defineProperty(H,"__esModule",{value:!0});var et=O,w=f,S=A,nt=m,rt={origins:[],availableChanelId:[]},it=function(o){tt(t,o);function t(n,r,e){var i=o.call(this)||this;return i.id=w.uniqueId("wa"),i.callbacks=[],i.options=t.prepareOptions(e),i.listen=n,i.dispatch=r,i.listen.forEach(function(s){return s.on("message",i.onMessage,i)}),i}return t.prototype.addListener=function(n){return this.callbacks.push(n),w.console.info("WindowAdapter: Add iframe message listener"),this},t.prototype.send=function(n){var r=P({},n,{chanelId:this.options.chanelId});return this.dispatch.forEach(function(e){return e.dispatch(r)}),w.console.info("WindowAdapter: Send message",r),this},t.prototype.destroy=function(){this.listen.forEach(function(n){return n.destroy()}),this.dispatch.forEach(function(n){return n.destroy()}),w.console.info("WindowAdapter: Destroy")},t.prototype.onMessage=function(n){this.accessEvent(n)&&this.callbacks.forEach(function(r){try{r(n.data)}catch(e){w.console.warn("WindowAdapter: Unhandled exception!",e)}})},t.prototype.accessEvent=function(n){if(typeof n.data!="object"||n.data.type==null)return w.console.info("WindowAdapter: Block event. Wrong event format!",n.data),!1;if(!this.options.origins.has("*")&&!this.options.origins.has(n.origin))return w.console.info('SimpleWindowAdapter: Block event by origin "'+n.origin+'"'),!1;if(!this.options.availableChanelId.size)return!0;var r=!!(n.data.chanelId&&this.options.availableChanelId.has(n.data.chanelId));return r||w.console.info('SimpleWindowAdapter: Block event by chanel id "'+n.data.chanelId+'"'),r},t.createSimpleWindowAdapter=function(n,r){var e=this,i=this.getContentOrigin(n),s=this.prepareOptions(r),a=[];i&&s.origins.add(i);var c=new S.WindowProtocol(window,S.WindowProtocol.PROTOCOL_TYPES.LISTEN),l=function(h){a.push(h)};return c.on("message",l),this.getIframeContent(n).then(function(h){var d=new S.WindowProtocol(h.win,S.WindowProtocol.PROTOCOL_TYPES.DISPATCH),p=new t([c],[d],e.unPrepareOptions(s));return a.forEach(function(g){p.onMessage(g)}),c.off("message",l),p})},t.prepareOptions=function(n){n===void 0&&(n=rt);var r=function(a){return function(c){return c.reduce(function(l,h){return l.add(h)},a)}},e=function(a,c){return nt.pipe(w.toArray,r(c))(a)},i=e(n.origins||[],new w.UniqPrimitiveCollection([window.location.origin])),s=e(n.availableChanelId||[],new w.UniqPrimitiveCollection);return P({},n,{origins:i,availableChanelId:s})},t.unPrepareOptions=function(n){return{origins:n.origins.toArray(),availableChanelId:n.availableChanelId.toArray(),chanelId:n.chanelId}},t.getIframeContent=function(n){return n?n instanceof HTMLIFrameElement?n.contentWindow?Promise.resolve({win:n.contentWindow}):new Promise(function(r,e){n.addEventListener("load",function(){return r({win:n.contentWindow})},!1),n.addEventListener("error",e,!1)}):Promise.resolve({win:n}):Promise.resolve({win:window.opener||window.parent})},t.getContentOrigin=function(n){if(!n)try{return new URL(document.referrer).origin}catch{return null}if(!(n instanceof HTMLIFrameElement))try{return window.top.origin}catch{return null}try{return new URL(n.src).origin||null}catch{return null}},t}(et.Adapter);H.WindowAdapter=it,function(o){function t(n){for(var r in n)o.hasOwnProperty(r)||(o[r]=n[r])}Object.defineProperty(o,"__esModule",{value:!0}),t(W),t(O),t(H),t(A),t(j),t(L)}(f);class ot{constructor(t){v(this,"_actions",[]);v(this,"_maxLength");v(this,"_active");this._maxLength=t}get length(){return this._actions.length+(this._active==null?0:1)}push(t){if(this._actions.length>=this._maxLength)throw new Error("Cant't push action! Queue is full!");return new Promise((n,r)=>{const e=()=>{this._active=void 0;const s=this._actions.map(a=>a.action).indexOf(i);s!==-1&&this._actions.splice(s,1),this.run()},i=()=>t().then(s=>{e(),n(s)},s=>{e(),r(s)});this._actions.push({action:i,reject:r}),this.length===1&&this.run()})}clear(t){t=t||new Error("Rejection with clear queue!");const n=typeof t=="string"?new Error(t):t;this._actions.splice(0,this._actions.length).forEach(r=>r.reject(n)),this._active=void 0}canPush(){return this._actions.length<this._maxLength}run(){const t=this._actions.shift();t!=null&&(this._active=t.action())}}const M=o=>o&&o.message==="SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document."?U(D({},o),{message:"Local storage is not available! It is possible that the Browser is in incognito mode!"}):o;class st{constructor(t){v(this,"_queue");v(this,"_events",[]);v(this,"_toRunEvents",[]);this._queue=new ot(t)}dropConnection(){this._queue.clear(new Error("User rejection!")),this._events.forEach(t=>this._toRunEvents.push(t)),this._dropTransportConnect()}sendEvent(t){this._events.push(t),this._toRunEvents.push(t)}dialog(t){return this._runBeforeShow(),this._getBus().then(n=>{const r=this._wrapAction(()=>t(n));return this._runEvents(n),this._queue.canPush()?this._queue.push(r).then(e=>(this._runAfterShow(),e)).catch(e=>(this._runAfterShow(),Promise.reject(M(e)))):Promise.reject(new Error("Queue is full!"))})}_runBeforeShow(){this._queue.length===0&&this._beforeShow()}_runAfterShow(){this._queue.length===0&&this._afterShow()}_runEvents(t){this._toRunEvents.splice(0,this._events.length).forEach(n=>n(t))}_wrapAction(t){return this._toRunEvents?()=>{const n=t();return n.catch(()=>{this._events.forEach(r=>this._toRunEvents.push(r))}),n}:t}}class at extends st{constructor(t,n){super(n);v(this,"_timer",null);v(this,"_url");v(this,"_iframe");v(this,"_bus");this._url=t,this._initIframe()}get(){return this._iframe||this._initIframe(),this._iframe}_dropTransportConnect(){this._iframe!=null&&(document.body.removeChild(this._iframe),this._initIframe()),this._bus&&(this._bus.destroy(),this._bus=void 0)}_getBus(){return this._bus?Promise.resolve(this._bus):f.WindowAdapter.createSimpleWindowAdapter(this._iframe,{origins:["https://wx.network","https://testnet.wx.network"]}).then(t=>new Promise(n=>{this._bus=new f.Bus(t,-1),this._bus.once("ready",()=>{n(this._bus)})}))}_beforeShow(){this._showIframe()}_afterShow(){this._hideIframe()}_initIframe(){this._iframe=this._createIframe(),this._addIframeToDom(this._iframe),this._listenFetchURLError(this._iframe),this._hideIframe()}_addIframeToDom(t){document.body!=null?document.body.appendChild(t):document.addEventListener("DOMContentLoaded",()=>{document.body.appendChild(t)})}_createIframe(){const t=document.createElement("iframe");return t.style.transition="opacity .2s",t.style.position="absolute",t.style.opacity="0",t.style.width="100%",t.style.height="100%",t.style.left="0",t.style.top="0",t.style.border="none",t.style.position="fixed",t}_showIframe(){const t={width:"100%",height:"100%",left:"0",top:"0",border:"none",position:"fixed",display:"block",opacity:"0",zIndex:"99999999"};this._applyStyle(t),this._timer!=null&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._applyStyle({opacity:"1"})},0)}_hideIframe(){const t={opacity:"0"};this._applyStyle(t),this._timer!=null&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._applyStyle({width:"10px",height:"10px",left:"-100px",top:"-100px",position:"absolute",opacity:"0",zIndex:"0",display:"none"})},200)}_applyStyle(t){Object.entries(t).forEach(([n,r])=>{r!=null&&this._iframe&&(this._iframe.style[n]=r)})}_renderErrorPage(t,n,r){t.parentElement&&(t.parentElement.style.height="100%"),Object.assign(t.style,{position:"relative",boxSizing:"border-box",width:"100%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center",margin:"0px"});const e=document.createElement("div");Object.assign(e.style,{position:"fixed",zIndex:"-1",height:"100%",width:"100%",overflow:"hidden",backgroundColor:"#000",opacity:"0.6"});const i=document.createElement("div");Object.assign(i.style,{position:"fixed",display:"flex",justifyContent:"center",alignItems:"center",flexDirection:"column",margin:"0",backgroundColor:"#292F3C",width:"520px",borderRadius:"6px",padding:"40px",boxSizing:"border-box"});const s=document.createElement("div");s.textContent=r,Object.assign(s.style,{fontSize:"15px",lineHeight:"20px",color:"#fff",marginBottom:"40px",fontFamily:"Roboto, sans-serif"});const a=document.createElement("button");a.textContent="OK",a.addEventListener("click",()=>n()),Object.assign(a.style,{width:"100%",fontSize:"15px",lineHeight:"48px",padding:" 0 40px",color:"#fff",backgroundColor:"#5A81EA",outline:"none",border:"none",cursor:"pointer",fontFamily:"Roboto, sans-serif",borderRadius:"4px"}),i.appendChild(s),i.appendChild(a),t.appendChild(e),t.appendChild(i)}_listenFetchURLError(t){fetch(this._url).catch(()=>{t.addEventListener("load",()=>{!t.contentDocument||(this._renderErrorPage(t.contentDocument.body,()=>this.dropConnection(),"The request could not be processed. To resume your further work, disable the installed plugins."),this._showIframe())})})}}const ct=o=>f.WindowAdapter.createSimpleWindowAdapter(o,{origins:["*"]}).then(t=>new Promise(n=>{const r=new f.Bus(t,-1);r.once("ready",()=>{r.once("transferStorage",e=>{o.close(),t.destroy(),n(e)})})}));class R{constructor(t,n){v(this,"user",null);v(this,"_transport");v(this,"_clientUrl");v(this,"emitter",new q.exports.EventEmitter);this._clientUrl=(t||"https://waves.exchange/signer/")+`?${R._getCacheClean()}`,this._transport=new at(this._clientUrl,3),n===!0&&(f.config.console.logLevel=f.config.console.LOG_LEVEL.VERBOSE)}static _getCacheClean(){return String(Date.now()%(1e3*60))}on(t,n){return this.emitter.on(t,n),this}once(t,n){return this.emitter.once(t,n),this}off(t,n){return this.emitter.once(t,n),this}connect(t){return Promise.resolve(this._transport.sendEvent(n=>n.dispatchEvent("connect",t)))}logout(){return this.user=null,Promise.resolve(this._transport.dropConnection())}login(){if(this.user)return Promise.resolve(this.user);const t=window.screen.width-200,n=window.screen.height-200,r=window.open(`${this._clientUrl}?transferStorage=true`,"_blank",`left=${t},top=${n},width=100,height=100,location=no,scrollbars=no`);if(!r)throw new Error("Window was blocked");return ct(r).then(e=>{const i=this._transport.get();return i.src=`${this._clientUrl}?waitStorage=true`,this._transport.dialog(s=>s.request("login",e).then(a=>(this.user=a,a)).catch(a=>(this._transport.dropConnection(),Promise.reject(M(a)))))})}signMessage(t){return this.login().then(()=>this._transport.dialog(n=>n.request("sign-message",t)))}signTypedData(t){return this.login().then(()=>this._transport.dialog(n=>n.request("sign-typed-data",t)))}sign(t){return this.login().then(()=>this._transport.dialog(n=>n.request("sign",t)))}}_.ProviderWeb=R,Object.defineProperty(_,"__esModule",{value:!0}),_[Symbol.toStringTag]="Module"});
|
|
1
|
+
var ut=Object.defineProperty,lt=Object.defineProperties;var ht=Object.getOwnPropertyDescriptors;var B=Object.getOwnPropertySymbols;var dt=Object.prototype.hasOwnProperty,ft=Object.prototype.propertyIsEnumerable;var T=(_,u,f)=>u in _?ut(_,u,{enumerable:!0,configurable:!0,writable:!0,value:f}):_[u]=f,D=(_,u)=>{for(var f in u||(u={}))dt.call(u,f)&&T(_,f,u[f]);if(B)for(var f of B(u))ft.call(u,f)&&T(_,f,u[f]);return _},U=(_,u)=>lt(_,ht(u));var v=(_,u,f)=>(T(_,typeof u!="symbol"?u+"":u,f),f);(function(_,u){typeof exports=="object"&&typeof module!="undefined"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(_=typeof globalThis!="undefined"?globalThis:_||self,u(_.providerWeb={}))})(this,function(_){"use strict";var u=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{},f={},W={},L={},m={};Object.defineProperty(m,"__esModule",{value:!0});function V(o){return Object.keys(o)}m.keys=V;var $=Math.floor(Date.now()*Math.random()),z=0;function F(o){return o+"-"+$+"-"+z++}m.uniqueId=F;function G(o){return Array.isArray(o)?o:[o]}m.toArray=G;function N(){for(var o=[],t=0;t<arguments.length;t++)o[t]=arguments[t];return function(n){return o.reduce(function(r,e){return e(r)},n)}}m.pipe=N;var C={},j={};(function(o){Object.defineProperty(o,"__esModule",{value:!0}),function(t){(function(n){n.LOG_LEVEL={PRODUCTION:0,ERRORS:1,VERBOSE:2},n.logLevel=n.LOG_LEVEL.PRODUCTION,n.methodsData={log:{save:!1,logLevel:n.LOG_LEVEL.VERBOSE},info:{save:!1,logLevel:n.LOG_LEVEL.VERBOSE},warn:{save:!1,logLevel:n.LOG_LEVEL.VERBOSE},error:{save:!0,logLevel:n.LOG_LEVEL.ERRORS}}})(t.console||(t.console={}))}(o.config||(o.config={}))})(j);var x=u&&u.__assign||function(){return x=Object.assign||function(o){for(var t,n=1,r=arguments.length;n<r;n++){t=arguments[n];for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&(o[e]=t[e])}return o},x.apply(this,arguments)};Object.defineProperty(C,"__esModule",{value:!0});var E=j,Y=m,k=function(o){return o.console}(typeof self!="undefined"?self:u),b=Object.create(null);function Q(o){b[o]||(b[o]=[])}function K(o,t){b[o].push(t)}function J(){return Y.keys(E.config.console.methodsData).reduce(function(o,t){return o[t]=function(){for(var n=[],r=0;r<arguments.length;r++)n[r]=arguments[r];E.config.console.logLevel<E.config.console.methodsData[t].logLevel?E.config.console.methodsData[t].save&&(Q(t),K(t,n)):k[t].apply(k,n)},o},Object.create(null))}C.console=x({},J(),{getSavedMessages:function(o){return b[o]||[]}});var I={};Object.defineProperty(I,"__esModule",{value:!0});var X=function(){function o(t){this.size=0,this.hash=Object.create(null),t&&t.forEach(this.add,this)}return o.prototype.add=function(t){return this.hash[t]=!0,this.size=Object.keys(this.hash).length,this},o.prototype.has=function(t){return t in this.hash},o.prototype.toArray=function(){return Object.keys(this.hash)},o}();I.UniqPrimitiveCollection=X,function(o){function t(n){for(var r in n)o.hasOwnProperty(r)||(o[r]=n[r])}Object.defineProperty(o,"__esModule",{value:!0}),t(m),t(C),t(I)}(L),function(o){Object.defineProperty(o,"__esModule",{value:!0});var t=L;(function(r){r[r.Event=0]="Event",r[r.Action=1]="Action",r[r.Response=2]="Response"})(o.EventType||(o.EventType={})),function(r){r[r.Success=0]="Success",r[r.Error=1]="Error"}(o.ResponseStatus||(o.ResponseStatus={}));var n=function(){function r(e,i){var s=this;this.id=t.uniqueId("bus"),this._timeout=i||5e3,this._adapter=e,this._adapter.addListener(function(a){return s._onMessage(a)}),this._eventHandlers=Object.create(null),this._activeRequestHash=Object.create(null),this._requestHandlers=Object.create(null),t.console.info('Create Bus with id "'+this.id+'"')}return r.prototype.dispatchEvent=function(e,i){return this._adapter.send(r._createEvent(e,i)),t.console.info('Dispatch event "'+e+'"',i),this},r.prototype.request=function(e,i,s){var a=this;return new Promise(function(c,l){var h=t.uniqueId(a.id+"-action"),d=s||a._timeout,p;(s||a._timeout)!==-1&&(p=setTimeout(function(){delete a._activeRequestHash[h];var y=new Error('Timeout error for request with name "'+e+'" and timeout '+d+"!");t.console.error(y),l(y)},d));var g=function(){p&&clearTimeout(p)};a._activeRequestHash[h]={reject:function(y){g(),t.console.error('Error request with name "'+e+'"',y),l(y)},resolve:function(y){g(),t.console.info('Request with name "'+e+'" success resolved!',y),c(y)}},a._adapter.send({id:h,type:1,name:e,data:i}),t.console.info('Request with name "'+e+'"',i)})},r.prototype.on=function(e,i,s){return this._addEventHandler(e,i,s,!1)},r.prototype.once=function(e,i,s){return this._addEventHandler(e,i,s,!0)},r.prototype.off=function(e,i){var s=this;return e?this._eventHandlers[e]?i?(this._eventHandlers[e]=this._eventHandlers[e].filter(function(a){return a.handler!==i}),this._eventHandlers[e].length||delete this._eventHandlers[e],this):(this._eventHandlers[e].slice().forEach(function(a){s.off(e,a.handler)}),this):this:(Object.keys(this._eventHandlers).forEach(function(a){return s.off(a,i)}),this)},r.prototype.registerRequestHandler=function(e,i){if(this._requestHandlers[e])throw new Error("Duplicate request handler!");return this._requestHandlers[e]=i,this},r.prototype.unregisterHandler=function(e){return this._requestHandlers[e]&&delete this._requestHandlers[e],this},r.prototype.changeAdapter=function(e){var i=this,s=new r(e,this._timeout);return Object.keys(this._eventHandlers).forEach(function(a){i._eventHandlers[a].forEach(function(c){c.once?s.once(a,c.handler,c.context):s.on(a,c.handler,c.context)})}),Object.keys(this._requestHandlers).forEach(function(a){s.registerRequestHandler(a,i._requestHandlers[a])}),s},r.prototype.destroy=function(){t.console.info("Destroy Bus"),this.off(),this._adapter.destroy()},r.prototype._addEventHandler=function(e,i,s,a){return this._eventHandlers[e]||(this._eventHandlers[e]=[]),this._eventHandlers[e].push({handler:i,once:a,context:s}),this},r.prototype._onMessage=function(e){switch(e.type){case 0:t.console.info('Has event with name "'+String(e.name)+'"',e.data),this._fireEvent(String(e.name),e.data);break;case 1:t.console.info('Start action with id "'+e.id+'" and name "'+String(e.name)+'"',e.data),this._createResponse(e);break;case 2:t.console.info('Start response with name "'+e.id+'" and status "'+e.status+'"',e.content),this._fireEndAction(e);break}},r.prototype._createResponse=function(e){var i=this,s=function(c){t.console.error(c),i._adapter.send({id:e.id,type:2,status:1,content:String(c)})};if(!this._requestHandlers[String(e.name)]){s(new Error('Has no handler for "'+String(e.name)+'" action!'));return}try{var a=this._requestHandlers[String(e.name)](e.data);r._isPromise(a)?a.then(function(c){i._adapter.send({id:e.id,type:2,status:0,content:c})},s):this._adapter.send({id:e.id,type:2,status:0,content:a})}catch(c){s(c)}},r.prototype._fireEndAction=function(e){if(this._activeRequestHash[e.id]){switch(e.status){case 1:this._activeRequestHash[e.id].reject(e.content);break;case 0:this._activeRequestHash[e.id].resolve(e.content);break}delete this._activeRequestHash[e.id]}},r.prototype._fireEvent=function(e,i){!this._eventHandlers[e]||(this._eventHandlers[e]=this._eventHandlers[e].slice().filter(function(s){try{s.handler.call(s.context,i)}catch(a){t.console.warn(a)}return!s.once}),this._eventHandlers[e].length||delete this._eventHandlers[e])},r._createEvent=function(e,i){return{type:0,name:e,data:i}},r._isPromise=function(e){return e&&e.then&&typeof e.then=="function"},r}();o.Bus=n}(W);var O={};Object.defineProperty(O,"__esModule",{value:!0});var Z=function(){function o(){}return o}();O.Adapter=Z;var H={},A={},q={exports:{}};(function(o,t){(function(n,r){o.exports=r()})(u,function(){return(()=>{var n={660:(e,i)=>{i.__esModule=!0,i.EventEmitter=void 0;var s=function(){function a(c){this._events=Object.create(null),this.catchHandler=c||function(){}}return a.prototype.hasListeners=function(c){return!(!this._events[c]||!this._events[c].length)},a.prototype.getActiveEvents=function(){var c=this;return Object.keys(this._events).filter(function(l){return c.hasListeners(l)})},a.prototype.trigger=function(c,l){var h=this;this._events[c]&&(this._events[c].slice().forEach(function(d){try{d.handler.call(d.context,l)}catch(p){h.catchHandler(p)}d.once&&h.off(c,d.handler)}),this._events[c].length||delete this._events[c])},a.prototype.on=function(c,l,h){this._on(c,l,h,!1)},a.prototype.once=function(c,l,h){this._on(c,l,h,!0)},a.prototype.off=function(c,l){var h=this,d=typeof c=="string"?c:null,p=typeof l=="function"?l:typeof c=="function"?c:null;if(d)if(p){if(d in this._events){var g=this._events[d].map(function(y){return y.handler}).indexOf(p);this._events[d].splice(g,1)}}else delete this._events[d];else Object.keys(this._events).forEach(function(y){h.off(y,p)})},a.prototype._on=function(c,l,h,d){this._events[c]||(this._events[c]=[]),this._events[c].push({handler:l,context:h,once:d})},a}();i.EventEmitter=s},607:function(e,i,s){var a=this&&this.__createBinding||(Object.create?function(h,d,p,g){g===void 0&&(g=p),Object.defineProperty(h,g,{enumerable:!0,get:function(){return d[p]}})}:function(h,d,p,g){g===void 0&&(g=p),h[g]=d[p]}),c=this&&this.__exportStar||function(h,d){for(var p in h)p==="default"||Object.prototype.hasOwnProperty.call(d,p)||a(d,h,p)};i.__esModule=!0;var l=s(660);c(s(660),i),i.default=l.EventEmitter}},r={};return function e(i){if(r[i])return r[i].exports;var s=r[i]={exports:{}};return n[i].call(s.exports,s,s.exports,e),s.exports}(607)})()})})(q),function(o){var t=u&&u.__extends||function(){var e=function(i,s){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(a,c){a.__proto__=c}||function(a,c){for(var l in c)c.hasOwnProperty(l)&&(a[l]=c[l])},e(i,s)};return function(i,s){e(i,s);function a(){this.constructor=i}i.prototype=s===null?Object.create(s):(a.prototype=s.prototype,new a)}}();Object.defineProperty(o,"__esModule",{value:!0});var n=q.exports,r=function(e){t(i,e);function i(s,a){var c=e.call(this)||this;return c.win=s,c.type=a,c.handler=function(l){c.trigger("message",l)},a===i.PROTOCOL_TYPES.LISTEN&&c.win.addEventListener("message",c.handler,!1),c}return i.prototype.dispatch=function(s){return this.win.postMessage(s,"*"),this},i.prototype.destroy=function(){this.type===i.PROTOCOL_TYPES.LISTEN&&this.win.removeEventListener("message",this.handler,!1),this.win=i._fakeWin},i._fakeWin=function(){var s=function(){return null};return{postMessage:s,addEventListener:s,removeEventListener:s}}(),i}(n.EventEmitter);o.WindowProtocol=r,function(e){e.PROTOCOL_TYPES={LISTEN:"listen",DISPATCH:"dispatch"}}(r=o.WindowProtocol||(o.WindowProtocol={})),o.WindowProtocol=r}(A);var tt=u&&u.__extends||function(){var o=function(t,n){return o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,e){r.__proto__=e}||function(r,e){for(var i in e)e.hasOwnProperty(i)&&(r[i]=e[i])},o(t,n)};return function(t,n){o(t,n);function r(){this.constructor=t}t.prototype=n===null?Object.create(n):(r.prototype=n.prototype,new r)}}(),P=u&&u.__assign||function(){return P=Object.assign||function(o){for(var t,n=1,r=arguments.length;n<r;n++){t=arguments[n];for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&(o[e]=t[e])}return o},P.apply(this,arguments)};Object.defineProperty(H,"__esModule",{value:!0});var et=O,w=f,S=A,nt=m,rt={origins:[],availableChanelId:[]},it=function(o){tt(t,o);function t(n,r,e){var i=o.call(this)||this;return i.id=w.uniqueId("wa"),i.callbacks=[],i.options=t.prepareOptions(e),i.listen=n,i.dispatch=r,i.listen.forEach(function(s){return s.on("message",i.onMessage,i)}),i}return t.prototype.addListener=function(n){return this.callbacks.push(n),w.console.info("WindowAdapter: Add iframe message listener"),this},t.prototype.send=function(n){var r=P({},n,{chanelId:this.options.chanelId});return this.dispatch.forEach(function(e){return e.dispatch(r)}),w.console.info("WindowAdapter: Send message",r),this},t.prototype.destroy=function(){this.listen.forEach(function(n){return n.destroy()}),this.dispatch.forEach(function(n){return n.destroy()}),w.console.info("WindowAdapter: Destroy")},t.prototype.onMessage=function(n){this.accessEvent(n)&&this.callbacks.forEach(function(r){try{r(n.data)}catch(e){w.console.warn("WindowAdapter: Unhandled exception!",e)}})},t.prototype.accessEvent=function(n){if(typeof n.data!="object"||n.data.type==null)return w.console.info("WindowAdapter: Block event. Wrong event format!",n.data),!1;if(!this.options.origins.has("*")&&!this.options.origins.has(n.origin))return w.console.info('SimpleWindowAdapter: Block event by origin "'+n.origin+'"'),!1;if(!this.options.availableChanelId.size)return!0;var r=!!(n.data.chanelId&&this.options.availableChanelId.has(n.data.chanelId));return r||w.console.info('SimpleWindowAdapter: Block event by chanel id "'+n.data.chanelId+'"'),r},t.createSimpleWindowAdapter=function(n,r){var e=this,i=this.getContentOrigin(n),s=this.prepareOptions(r),a=[];i&&s.origins.add(i);var c=new S.WindowProtocol(window,S.WindowProtocol.PROTOCOL_TYPES.LISTEN),l=function(h){a.push(h)};return c.on("message",l),this.getIframeContent(n).then(function(h){var d=new S.WindowProtocol(h.win,S.WindowProtocol.PROTOCOL_TYPES.DISPATCH),p=new t([c],[d],e.unPrepareOptions(s));return a.forEach(function(g){p.onMessage(g)}),c.off("message",l),p})},t.prepareOptions=function(n){n===void 0&&(n=rt);var r=function(a){return function(c){return c.reduce(function(l,h){return l.add(h)},a)}},e=function(a,c){return nt.pipe(w.toArray,r(c))(a)},i=e(n.origins||[],new w.UniqPrimitiveCollection([window.location.origin])),s=e(n.availableChanelId||[],new w.UniqPrimitiveCollection);return P({},n,{origins:i,availableChanelId:s})},t.unPrepareOptions=function(n){return{origins:n.origins.toArray(),availableChanelId:n.availableChanelId.toArray(),chanelId:n.chanelId}},t.getIframeContent=function(n){return n?n instanceof HTMLIFrameElement?n.contentWindow?Promise.resolve({win:n.contentWindow}):new Promise(function(r,e){n.addEventListener("load",function(){return r({win:n.contentWindow})},!1),n.addEventListener("error",e,!1)}):Promise.resolve({win:n}):Promise.resolve({win:window.opener||window.parent})},t.getContentOrigin=function(n){if(!n)try{return new URL(document.referrer).origin}catch{return null}if(!(n instanceof HTMLIFrameElement))try{return window.top.origin}catch{return null}try{return new URL(n.src).origin||null}catch{return null}},t}(et.Adapter);H.WindowAdapter=it,function(o){function t(n){for(var r in n)o.hasOwnProperty(r)||(o[r]=n[r])}Object.defineProperty(o,"__esModule",{value:!0}),t(W),t(O),t(H),t(A),t(j),t(L)}(f);class ot{constructor(t){v(this,"_actions",[]);v(this,"_maxLength");v(this,"_active");this._maxLength=t}get length(){return this._actions.length+(this._active==null?0:1)}push(t){if(this._actions.length>=this._maxLength)throw new Error("Cant't push action! Queue is full!");return new Promise((n,r)=>{const e=()=>{this._active=void 0;const s=this._actions.map(a=>a.action).indexOf(i);s!==-1&&this._actions.splice(s,1),this.run()},i=()=>t().then(s=>{e(),n(s)},s=>{e(),r(s)});this._actions.push({action:i,reject:r}),this.length===1&&this.run()})}clear(t){t=t||new Error("Rejection with clear queue!");const n=typeof t=="string"?new Error(t):t;this._actions.splice(0,this._actions.length).forEach(r=>r.reject(n)),this._active=void 0}canPush(){return this._actions.length<this._maxLength}run(){const t=this._actions.shift();t!=null&&(this._active=t.action())}}const M=o=>o&&o.message==="SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document."?U(D({},o),{message:"Local storage is not available! It is possible that the Browser is in incognito mode!"}):o;class st{constructor(t){v(this,"_queue");v(this,"_events",[]);v(this,"_toRunEvents",[]);this._queue=new ot(t)}dropConnection(){this._queue.clear(new Error("User rejection!")),this._events.forEach(t=>this._toRunEvents.push(t)),this._dropTransportConnect()}sendEvent(t){this._events.push(t),this._toRunEvents.push(t)}dialog(t){return this._runBeforeShow(),this._getBus().then(n=>{const r=this._wrapAction(()=>t(n));return this._runEvents(n),this._queue.canPush()?this._queue.push(r).then(e=>(this._runAfterShow(),e)).catch(e=>(this._runAfterShow(),Promise.reject(M(e)))):Promise.reject(new Error("Queue is full!"))})}_runBeforeShow(){this._queue.length===0&&this._beforeShow()}_runAfterShow(){this._queue.length===0&&this._afterShow()}_runEvents(t){this._toRunEvents.splice(0,this._events.length).forEach(n=>n(t))}_wrapAction(t){return this._toRunEvents?()=>{const n=t();return n.catch(()=>{this._events.forEach(r=>this._toRunEvents.push(r))}),n}:t}}class at extends st{constructor(t,n){super(n);v(this,"_timer",null);v(this,"_url");v(this,"_iframe");v(this,"_bus");this._url=t,this._initIframe()}get(){return this._iframe||this._initIframe(),this._iframe}_dropTransportConnect(){this._iframe!=null&&(document.body.removeChild(this._iframe),this._initIframe()),this._bus&&(this._bus.destroy(),this._bus=void 0)}_getBus(){return this._bus?Promise.resolve(this._bus):f.WindowAdapter.createSimpleWindowAdapter(this._iframe,{origins:["https://wx.network","https://testnet.wx.network"]}).then(t=>new Promise(n=>{this._bus=new f.Bus(t,-1),this._bus.once("ready",()=>{n(this._bus)})}))}_beforeShow(){this._showIframe()}_afterShow(){this._hideIframe()}_initIframe(){this._iframe=this._createIframe(),this._addIframeToDom(this._iframe),this._listenFetchURLError(this._iframe),this._hideIframe()}_addIframeToDom(t){document.body!=null?document.body.appendChild(t):document.addEventListener("DOMContentLoaded",()=>{document.body.appendChild(t)})}_createIframe(){const t=document.createElement("iframe");return t.style.transition="opacity .2s",t.style.position="absolute",t.style.opacity="0",t.style.width="100%",t.style.height="100%",t.style.left="0",t.style.top="0",t.style.border="none",t.style.position="fixed",t}_showIframe(){const t={width:"100%",height:"100%",left:"0",top:"0",border:"none",position:"fixed",display:"block",opacity:"0",zIndex:"99999999"};this._applyStyle(t),this._timer!=null&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._applyStyle({opacity:"1"})},0)}_hideIframe(){const t={opacity:"0"};this._applyStyle(t),this._timer!=null&&clearTimeout(this._timer),this._timer=setTimeout(()=>{this._applyStyle({width:"10px",height:"10px",left:"-100px",top:"-100px",position:"absolute",opacity:"0",zIndex:"0",display:"none"})},200)}_applyStyle(t){Object.entries(t).forEach(([n,r])=>{r!=null&&this._iframe&&(this._iframe.style[n]=r)})}_renderErrorPage(t,n,r){t.parentElement&&(t.parentElement.style.height="100%"),Object.assign(t.style,{position:"relative",boxSizing:"border-box",width:"100%",height:"100%",display:"flex",justifyContent:"center",alignItems:"center",margin:"0px"});const e=document.createElement("div");Object.assign(e.style,{position:"fixed",zIndex:"-1",height:"100%",width:"100%",overflow:"hidden",backgroundColor:"#000",opacity:"0.6"});const i=document.createElement("div");Object.assign(i.style,{position:"fixed",display:"flex",justifyContent:"center",alignItems:"center",flexDirection:"column",margin:"0",backgroundColor:"#292F3C",width:"520px",borderRadius:"6px",padding:"40px",boxSizing:"border-box"});const s=document.createElement("div");s.textContent=r,Object.assign(s.style,{fontSize:"15px",lineHeight:"20px",color:"#fff",marginBottom:"40px",fontFamily:"Roboto, sans-serif"});const a=document.createElement("button");a.textContent="OK",a.addEventListener("click",()=>n()),Object.assign(a.style,{width:"100%",fontSize:"15px",lineHeight:"48px",padding:" 0 40px",color:"#fff",backgroundColor:"#5A81EA",outline:"none",border:"none",cursor:"pointer",fontFamily:"Roboto, sans-serif",borderRadius:"4px"}),i.appendChild(s),i.appendChild(a),t.appendChild(e),t.appendChild(i)}_listenFetchURLError(t){fetch(new URL(this._url).origin).catch(()=>{t.addEventListener("load",()=>{!t.contentDocument||(this._renderErrorPage(t.contentDocument.body,()=>this.dropConnection(),"The request could not be processed. To resume your further work, disable the installed plugins."),this._showIframe())})})}}const ct=o=>f.WindowAdapter.createSimpleWindowAdapter(o,{origins:["*"]}).then(t=>new Promise(n=>{const r=new f.Bus(t,-1);r.once("ready",()=>{r.once("transferStorage",e=>{o.close(),t.destroy(),n(e)})})}));class R{constructor(t,n){v(this,"user",null);v(this,"_transport");v(this,"_clientUrl");v(this,"emitter",new q.exports.EventEmitter);this._clientUrl=(t||"https://wx.network/signer/")+`?${R._getCacheClean()}`,this._transport=new at(this._clientUrl,3),n===!0&&(f.config.console.logLevel=f.config.console.LOG_LEVEL.VERBOSE)}static _getCacheClean(){return String(Date.now()%(1e3*60))}on(t,n){return this.emitter.on(t,n),this}once(t,n){return this.emitter.once(t,n),this}off(t,n){return this.emitter.once(t,n),this}connect(t){return Promise.resolve(this._transport.sendEvent(n=>n.dispatchEvent("connect",t)))}logout(){return this.user=null,Promise.resolve(this._transport.dropConnection())}login(){if(this.user)return Promise.resolve(this.user);const t=window.screen.width-200,n=window.screen.height-200,r=window.open(`${this._clientUrl}?transferStorage=true`,"_blank",`left=${t},top=${n},width=100,height=100,location=no,scrollbars=no`);if(!r)throw new Error("Window was blocked");return ct(r).then(e=>{const i=this._transport.get();return i.src=`${this._clientUrl}?waitStorage=true`,this._transport.dialog(s=>s.request("login",e).then(a=>(this.user=a,a)).catch(a=>(this._transport.dropConnection(),Promise.reject(M(a)))))})}signMessage(t){return this.login().then(()=>this._transport.dialog(n=>n.request("sign-message",t)))}signTypedData(t){return this.login().then(()=>this._transport.dialog(n=>n.request("sign-typed-data",t)))}sign(t){return this.login().then(()=>this._transport.dialog(n=>n.request("sign",t)))}}_.ProviderWeb=R,Object.defineProperty(_,"__esModule",{value:!0}),_[Symbol.toStringTag]="Module"});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@waves.exchange/provider-web",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"url": "https://github.com/waves-exchange/signer-providers/issues",
|
|
22
22
|
"email": "support@waves.exchange"
|
|
23
23
|
},
|
|
24
|
-
"homepage": "https://
|
|
24
|
+
"homepage": "https://wx.network",
|
|
25
25
|
"description": "ProviderWeb for Signer",
|
|
26
26
|
"scripts": {
|
|
27
27
|
"test": "jest",
|