@jadbox/iframe-provider
Advanced tools
Comparing version 0.1.15 to 0.1.16
@@ -242,2 +242,7 @@ 'use strict'; | ||
switch (message.method) { | ||
case 'eth_subscription': | ||
_this7.emitEthSubNotification(message.params); | ||
break; | ||
case 'notification': | ||
@@ -429,2 +434,6 @@ _this7.emitNotification(message.params); | ||
_proto.emitEthSubNotification = function emitEthSubNotification(result) { | ||
this.emit('eth_subscription', result); | ||
}; | ||
_proto.emitNotification = function emitNotification(result) { | ||
@@ -431,0 +440,0 @@ this.emit('notification', result); |
@@ -1,2 +0,2 @@ | ||
"use strict";var e=require("eventemitter3");function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function r(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function n(e){return(n=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function o(e,t){return(o=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function i(e,t,r){return(i=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&o(i,r.prototype),i}).apply(null,arguments)}function c(e){var t="function"==typeof Map?new Map:void 0;return(c=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return i(e,arguments,n(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),o(r,e)})(e)}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var a="*",u=6e4,s="2.0",l=function(e){function t(t,r){var n;return(n=e.call(this,t+": "+r)||this).isRpcError=!0,n.code=t,n.reason=r,n}return r(t,e),t}(c(Error));exports.IFrameEthereumProvider=function(e){function n(t){var r,n=void 0===t?{}:t,o=n.targetOrigin,i=void 0===o?a:o,c=n.timeoutMilliseconds,l=void 0===c?u:c,f=n.eventSource,m=void 0===f?window:f,d=n.eventTarget,h=void 0===d?window.parent:d;return(r=e.call(this)||this).enabled=null,r.completers={},r.handleEventSourceMessage=function(e){var t=e.data;if(t){var n=t;if(n.jsonrpc===s){if(null!=n.id){var o=r.completers[""+n.id];o&&("error"in n||"result"in n?o.resolve(n):o.reject(new Error("Response from provider did not have error or result key")),delete r.completers[n.id])}if("method"in n)switch(n.method){case"notification":r.emitNotification(n.params);break;case"connect":r.emitConnect();break;case"close":r.emitClose(n.params[0],n.params[1]);break;case"chainChanged":r.emitChainChanged(n.params[0]);break;case"networkChanged":r.emitNetworkChanged(n.params[0]);break;case"accountsChanged":r.emitAccountsChanged(n.params[0])}}}},r.targetOrigin=i,r.timeoutMilliseconds=l,r.eventSource=m,r.eventTarget=h,r.eventSource.addEventListener("message",r.handleEventSourceMessage),r}r(n,e);var o,i=n.prototype;return i.execute=function(e,r,n){try{var o=this,i=null!=n?n:Math.floor(Math.random()*Number.MAX_SAFE_INTEGER),c=t({jsonrpc:s,id:i,method:e},void 0===r?null:{params:r}),a=new Promise(function(e,t){return o.completers[i]={resolve:e,reject:t}});return o.eventTarget.postMessage(c,o.targetOrigin),setTimeout(function(){o.completers[i]&&(o.completers[i].reject(new Error('RPC ID "'+i+'" timed out after '+o.timeoutMilliseconds+" milliseconds")),delete o.completers[i])},o.timeoutMilliseconds),Promise.resolve(a)}catch(e){return Promise.reject(e)}},i.request=function(e,t){try{return Promise.resolve(this.execute(e,t)).then(function(e){if("error"in e)throw new l(e.error.code,e.error.message);return e.result})}catch(e){return Promise.reject(e)}},i.send=function(e,t){try{return Promise.resolve(this.execute(e,t)).then(function(e){if("error"in e)throw new l(e.error.code,e.error.message);return e.result})}catch(e){return Promise.reject(e)}},i.enable=function(){try{var e=this;if(null===e.enabled)var t=e.enabled=e.send("enable").catch(function(r){throw e.enabled===t&&(e.enabled=null),r});return Promise.resolve(e.enabled)}catch(e){return Promise.reject(e)}},i.sendAsync=function(e,t){try{var r=this,n=function(n,o){try{var i=Promise.resolve(r.execute(e.method,e.params,e.id)).then(function(e){t(null,e)})}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(e){t(e,null)});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},i.emitNotification=function(e){this.emit("notification",e)},i.emitConnect=function(){null===this.enabled&&(this.enabled=Promise.resolve([])),this.emit("connect")},i.emitClose=function(e,t){this.emit("close",e,t)},i.emitChainChanged=function(e){this.emit("chainChanged",e)},i.emitNetworkChanged=function(e){this.emit("networkChanged",e)},i.emitAccountsChanged=function(e){this.enabled=Promise.resolve(e),this.emit("accountsChanged",e)},(o=[{key:"isIFrame",get:function(){return!0}},{key:"currentProvider",get:function(){return this}}])&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(n.prototype,o),n}(e.EventEmitter),exports.RpcError=l; | ||
"use strict";var e=require("eventemitter3");function t(){return(t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function r(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function n(e){return(n=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function o(e,t){return(o=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function i(e,t,r){return(i=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var i=new(Function.bind.apply(e,n));return r&&o(i,r.prototype),i}).apply(null,arguments)}function c(e){var t="function"==typeof Map?new Map:void 0;return(c=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return i(e,arguments,n(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),o(r,e)})(e)}"undefined"!=typeof Symbol&&(Symbol.iterator||(Symbol.iterator=Symbol("Symbol.iterator"))),"undefined"!=typeof Symbol&&(Symbol.asyncIterator||(Symbol.asyncIterator=Symbol("Symbol.asyncIterator")));var a="*",u=6e4,s="2.0",l=function(e){function t(t,r){var n;return(n=e.call(this,t+": "+r)||this).isRpcError=!0,n.code=t,n.reason=r,n}return r(t,e),t}(c(Error));exports.IFrameEthereumProvider=function(e){function n(t){var r,n=void 0===t?{}:t,o=n.targetOrigin,i=void 0===o?a:o,c=n.timeoutMilliseconds,l=void 0===c?u:c,f=n.eventSource,m=void 0===f?window:f,h=n.eventTarget,d=void 0===h?window.parent:h;return(r=e.call(this)||this).enabled=null,r.completers={},r.handleEventSourceMessage=function(e){var t=e.data;if(t){var n=t;if(n.jsonrpc===s){if(null!=n.id){var o=r.completers[""+n.id];o&&("error"in n||"result"in n?o.resolve(n):o.reject(new Error("Response from provider did not have error or result key")),delete r.completers[n.id])}if("method"in n)switch(n.method){case"eth_subscription":r.emitEthSubNotification(n.params);break;case"notification":r.emitNotification(n.params);break;case"connect":r.emitConnect();break;case"close":r.emitClose(n.params[0],n.params[1]);break;case"chainChanged":r.emitChainChanged(n.params[0]);break;case"networkChanged":r.emitNetworkChanged(n.params[0]);break;case"accountsChanged":r.emitAccountsChanged(n.params[0])}}}},r.targetOrigin=i,r.timeoutMilliseconds=l,r.eventSource=m,r.eventTarget=d,r.eventSource.addEventListener("message",r.handleEventSourceMessage),r}r(n,e);var o,i=n.prototype;return i.execute=function(e,r,n){try{var o=this,i=null!=n?n:Math.floor(Math.random()*Number.MAX_SAFE_INTEGER),c=t({jsonrpc:s,id:i,method:e},void 0===r?null:{params:r}),a=new Promise(function(e,t){return o.completers[i]={resolve:e,reject:t}});return o.eventTarget.postMessage(c,o.targetOrigin),setTimeout(function(){o.completers[i]&&(o.completers[i].reject(new Error('RPC ID "'+i+'" timed out after '+o.timeoutMilliseconds+" milliseconds")),delete o.completers[i])},o.timeoutMilliseconds),Promise.resolve(a)}catch(e){return Promise.reject(e)}},i.request=function(e,t){try{return Promise.resolve(this.execute(e,t)).then(function(e){if("error"in e)throw new l(e.error.code,e.error.message);return e.result})}catch(e){return Promise.reject(e)}},i.send=function(e,t){try{return Promise.resolve(this.execute(e,t)).then(function(e){if("error"in e)throw new l(e.error.code,e.error.message);return e.result})}catch(e){return Promise.reject(e)}},i.enable=function(){try{var e=this;if(null===e.enabled)var t=e.enabled=e.send("enable").catch(function(r){throw e.enabled===t&&(e.enabled=null),r});return Promise.resolve(e.enabled)}catch(e){return Promise.reject(e)}},i.sendAsync=function(e,t){try{var r=this,n=function(n,o){try{var i=Promise.resolve(r.execute(e.method,e.params,e.id)).then(function(e){t(null,e)})}catch(e){return o(e)}return i&&i.then?i.then(void 0,o):i}(0,function(e){t(e,null)});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},i.emitEthSubNotification=function(e){this.emit("eth_subscription",e)},i.emitNotification=function(e){this.emit("notification",e)},i.emitConnect=function(){null===this.enabled&&(this.enabled=Promise.resolve([])),this.emit("connect")},i.emitClose=function(e,t){this.emit("close",e,t)},i.emitChainChanged=function(e){this.emit("chainChanged",e)},i.emitNetworkChanged=function(e){this.emit("networkChanged",e)},i.emitAccountsChanged=function(e){this.enabled=Promise.resolve(e),this.emit("accountsChanged",e)},(o=[{key:"isIFrame",get:function(){return!0}},{key:"currentProvider",get:function(){return this}}])&&function(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}(n.prototype,o),n}(e.EventEmitter),exports.RpcError=l; | ||
//# sourceMappingURL=iframe-provider.cjs.production.min.js.map |
@@ -240,2 +240,7 @@ import { EventEmitter } from 'eventemitter3'; | ||
switch (message.method) { | ||
case 'eth_subscription': | ||
_this7.emitEthSubNotification(message.params); | ||
break; | ||
case 'notification': | ||
@@ -427,2 +432,6 @@ _this7.emitNotification(message.params); | ||
_proto.emitEthSubNotification = function emitEthSubNotification(result) { | ||
this.emit('eth_subscription', result); | ||
}; | ||
_proto.emitNotification = function emitNotification(result) { | ||
@@ -429,0 +438,0 @@ this.emit('notification', result); |
@@ -17,3 +17,3 @@ import { EventEmitter } from 'eventemitter3'; | ||
} | ||
export declare type IFrameEthereumProviderEventTypes = 'connect' | 'close' | 'notification' | 'chainChanged' | 'networkChanged' | 'accountsChanged'; | ||
export declare type IFrameEthereumProviderEventTypes = 'connect' | 'close' | 'notification' | 'chainChanged' | 'networkChanged' | 'accountsChanged' | 'eth_subscription'; | ||
/** | ||
@@ -26,2 +26,3 @@ * Export the type information about the different events that are emitted. | ||
on(event: 'notification', handler: (result: any) => void): this; | ||
on(event: 'eth_subscription', handler: (result: any) => void): this; | ||
on(event: 'chainChanged', handler: (chainId: string) => void): this; | ||
@@ -101,2 +102,3 @@ on(event: 'networkChanged', handler: (networkId: string) => void): this; | ||
private handleEventSourceMessage; | ||
private emitEthSubNotification; | ||
private emitNotification; | ||
@@ -103,0 +105,0 @@ private emitConnect; |
{ | ||
"name": "@jadbox/iframe-provider", | ||
"version": "0.1.15", | ||
"version": "0.1.16", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "module": "dist/ethereumprovider.esm.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
165992
912