o3-dapi-core
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.o3dapi=e():t.o3dapi=e()}("undefined"!=typeof self?self:this,function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=1)}([function(t,e,r){"use strict";(function(t){var r="object"==typeof t&&t&&t.Object===Object&&t;e.a=r}).call(this,r(2))},function(t,e,r){t.exports=r(3)},function(t,e){var r;r=function(){return this}();try{r=r||Function("return this")()||(0,eval)("this")}catch(t){"object"==typeof window&&(r=window)}t.exports=r},function(t,e,r){"use strict";r.r(e);var n=Array.isArray,o=r(0),i="object"==typeof self&&self&&self.Object===Object&&self,a=o.a||i||Function("return this")(),u=a.Symbol,c=Object.prototype,s=c.hasOwnProperty,f=c.toString,l=u?u.toStringTag:void 0;var p=function(t){var e=s.call(t,l),r=t[l];try{t[l]=void 0;var n=!0}catch(t){}var o=f.call(t);return n&&(e?t[l]=r:delete t[l]),o},v=Object.prototype.toString;var d=function(t){return v.call(t)},h="[object Null]",y="[object Undefined]",_=u?u.toStringTag:void 0;var b=function(t){return null==t?void 0===t?y:h:_&&_ in Object(t)?p(t):d(t)};var g=function(t){return null!=t&&"object"==typeof t},m="[object Symbol]";var j=function(t){return"symbol"==typeof t||g(t)&&b(t)==m},w=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,O=/^\w*$/;var S=function(t,e){if(n(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!j(t))||O.test(t)||!w.test(t)||null!=e&&t in Object(e)};var x=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},P="[object AsyncFunction]",k="[object Function]",z="[object GeneratorFunction]",M="[object Proxy]";var $=function(t){if(!x(t))return!1;var e=b(t);return e==k||e==z||e==P||e==M},T=a["__core-js_shared__"],A=function(){var t=/[^.]+$/.exec(T&&T.keys&&T.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}();var E=function(t){return!!A&&A in t},F=Function.prototype.toString;var C=function(t){if(null!=t){try{return F.call(t)}catch(t){}try{return t+""}catch(t){}}return""},N=/^\[object .+?Constructor\]$/,R=Function.prototype,H=Object.prototype,I=R.toString,D=H.hasOwnProperty,J=RegExp("^"+I.call(D).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var q=function(t){return!(!x(t)||E(t))&&($(t)?J:N).test(C(t))};var G=function(t,e){return null==t?void 0:t[e]};var U=function(t,e){var r=G(t,e);return q(r)?r:void 0},Y=U(Object,"create");var B=function(){this.__data__=Y?Y(null):{},this.size=0};var K=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},L="__lodash_hash_undefined__",Q=Object.prototype.hasOwnProperty;var V=function(t){var e=this.__data__;if(Y){var r=e[t];return r===L?void 0:r}return Q.call(e,t)?e[t]:void 0},W=Object.prototype.hasOwnProperty;var X=function(t){var e=this.__data__;return Y?void 0!==e[t]:W.call(e,t)},Z="__lodash_hash_undefined__";var tt=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=Y&&void 0===e?Z:e,this};function et(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}et.prototype.clear=B,et.prototype.delete=K,et.prototype.get=V,et.prototype.has=X,et.prototype.set=tt;var rt=et;var nt=function(){this.__data__=[],this.size=0};var ot=function(t,e){return t===e||t!=t&&e!=e};var it=function(t,e){for(var r=t.length;r--;)if(ot(t[r][0],e))return r;return-1},at=Array.prototype.splice;var ut=function(t){var e=this.__data__,r=it(e,t);return!(r<0||(r==e.length-1?e.pop():at.call(e,r,1),--this.size,0))};var ct=function(t){var e=this.__data__,r=it(e,t);return r<0?void 0:e[r][1]};var st=function(t){return it(this.__data__,t)>-1};var ft=function(t,e){var r=this.__data__,n=it(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};function lt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}lt.prototype.clear=nt,lt.prototype.delete=ut,lt.prototype.get=ct,lt.prototype.has=st,lt.prototype.set=ft;var pt=lt,vt=U(a,"Map");var dt=function(){this.size=0,this.__data__={hash:new rt,map:new(vt||pt),string:new rt}};var ht=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var yt=function(t,e){var r=t.__data__;return ht(e)?r["string"==typeof e?"string":"hash"]:r.map};var _t=function(t){var e=yt(this,t).delete(t);return this.size-=e?1:0,e};var bt=function(t){return yt(this,t).get(t)};var gt=function(t){return yt(this,t).has(t)};var mt=function(t,e){var r=yt(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function jt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}jt.prototype.clear=dt,jt.prototype.delete=_t,jt.prototype.get=bt,jt.prototype.has=gt,jt.prototype.set=mt;var wt=jt,Ot="Expected a function";function St(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError(Ot);var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],i=r.cache;if(i.has(o))return i.get(o);var a=t.apply(this,n);return r.cache=i.set(o,a)||i,a};return r.cache=new(St.Cache||wt),r}St.Cache=wt;var xt=St,Pt=500;var kt=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,zt=/\\(\\)?/g,Mt=function(t){var e=xt(t,function(t){return r.size===Pt&&r.clear(),t}),r=e.cache;return e}(function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(kt,function(t,r,n,o){e.push(n?o.replace(zt,"$1"):r||t)}),e});var $t=function(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o},Tt=1/0,At=u?u.prototype:void 0,Et=At?At.toString:void 0;var Ft=function t(e){if("string"==typeof e)return e;if(n(e))return $t(e,t)+"";if(j(e))return Et?Et.call(e):"";var r=e+"";return"0"==r&&1/e==-Tt?"-0":r};var Ct=function(t){return null==t?"":Ft(t)};var Nt=function(t,e){return n(t)?t:S(t,e)?[t]:Mt(Ct(t))},Rt=1/0;var Ht=function(t){if("string"==typeof t||j(t))return t;var e=t+"";return"0"==e&&1/t==-Rt?"-0":e};var It=function(t,e){for(var r=0,n=(e=Nt(e,t)).length;null!=t&&r<n;)t=t[Ht(e[r++])];return r&&r==n?t:void 0};var Dt=function(t,e,r){var n=null==t?void 0:It(t,e);return void 0===n?r:n};const Jt="o3-dapi",qt={},Gt={};function Ut({blockchain:t,callback:e}){Gt[t]=e}function Yt({blockchain:t,version:e,command:r,data:n,network:o,timeout:i}){const a=t+e+r+(Date.now()+Math.random()).toString(),u={platform:Jt,messageId:a,blockchain:t,version:e,command:r,data:n,network:o};return new Promise((t,e)=>{const r=Dt(window,"window._o3dapi.messageHandler"),n=Dt(window,"window.webkit.messageHandlers.sendMessageHandler.postMessage");r?r(JSON.stringify(u)):n?n(u):e("O3 dapi provider not found."),(r||n)&&(qt[a]={resolve:t,reject:e,timeout:i&&setTimeout(()=>{delete qt[a],e("Request timeout.")},i)})})}window._o3dapi=window._o3dapi?window._o3dapi:{},_o3dapi.receiveMessage=(t=>{try{"string"==typeof t&&(t=JSON.parse(t));const{platform:e,blockchain:r,command:n,messageId:o,data:i,error:a,eventName:u}=t;if(e!==Jt)return;if("event"===n){if("READY"===u)return void Object.keys(Gt).map(t=>Gt[t]).forEach(t=>t(u,i));const t=Gt[r];return void(t&&t(u,i))}const c=qt[o];if(c){const{resolve:t,timeout:e,reject:r}=c;e&&clearTimeout(e),a?r(a):t(i)}}catch(t){}});const Bt={initPlugins:t=>{t.forEach(t=>{Bt[t.blockchain]=new t(Yt,Ut)})}};e.default=Bt}]).default}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.o3dapi=e():t.o3dapi=e()}("undefined"!=typeof self?self:this,function(){return function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=1)}([function(t,e,r){"use strict";(function(t){var r="object"==typeof t&&t&&t.Object===Object&&t;e.a=r}).call(this,r(2))},function(t,e,r){t.exports=r(3)},function(t,e){var r;r=function(){return this}();try{r=r||Function("return this")()||(0,eval)("this")}catch(t){"object"==typeof window&&(r=window)}t.exports=r},function(t,e,r){"use strict";r.r(e);var n=Array.isArray,o=r(0),i="object"==typeof self&&self&&self.Object===Object&&self,a=o.a||i||Function("return this")(),u=a.Symbol,c=Object.prototype,s=c.hasOwnProperty,f=c.toString,l=u?u.toStringTag:void 0;var p=function(t){var e=s.call(t,l),r=t[l];try{t[l]=void 0;var n=!0}catch(t){}var o=f.call(t);return n&&(e?t[l]=r:delete t[l]),o},v=Object.prototype.toString;var d=function(t){return v.call(t)},h="[object Null]",y="[object Undefined]",_=u?u.toStringTag:void 0;var b=function(t){return null==t?void 0===t?y:h:_&&_ in Object(t)?p(t):d(t)};var g=function(t){return null!=t&&"object"==typeof t},m="[object Symbol]";var j=function(t){return"symbol"==typeof t||g(t)&&b(t)==m},w=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,O=/^\w*$/;var S=function(t,e){if(n(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!j(t))||O.test(t)||!w.test(t)||null!=e&&t in Object(e)};var x=function(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)},P="[object AsyncFunction]",k="[object Function]",z="[object GeneratorFunction]",A="[object Proxy]";var M=function(t){if(!x(t))return!1;var e=b(t);return e==k||e==z||e==P||e==A},$=a["__core-js_shared__"],T=function(){var t=/[^.]+$/.exec($&&$.keys&&$.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}();var E=function(t){return!!T&&T in t},F=Function.prototype.toString;var C=function(t){if(null!=t){try{return F.call(t)}catch(t){}try{return t+""}catch(t){}}return""},N=/^\[object .+?Constructor\]$/,R=Function.prototype,H=Object.prototype,I=R.toString,D=H.hasOwnProperty,J=RegExp("^"+I.call(D).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");var q=function(t){return!(!x(t)||E(t))&&(M(t)?J:N).test(C(t))};var B=function(t,e){return null==t?void 0:t[e]};var G=function(t,e){var r=B(t,e);return q(r)?r:void 0},U=G(Object,"create");var Y=function(){this.__data__=U?U(null):{},this.size=0};var K=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},L="__lodash_hash_undefined__",Q=Object.prototype.hasOwnProperty;var V=function(t){var e=this.__data__;if(U){var r=e[t];return r===L?void 0:r}return Q.call(e,t)?e[t]:void 0},W=Object.prototype.hasOwnProperty;var X=function(t){var e=this.__data__;return U?void 0!==e[t]:W.call(e,t)},Z="__lodash_hash_undefined__";var tt=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=U&&void 0===e?Z:e,this};function et(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}et.prototype.clear=Y,et.prototype.delete=K,et.prototype.get=V,et.prototype.has=X,et.prototype.set=tt;var rt=et;var nt=function(){this.__data__=[],this.size=0};var ot=function(t,e){return t===e||t!=t&&e!=e};var it=function(t,e){for(var r=t.length;r--;)if(ot(t[r][0],e))return r;return-1},at=Array.prototype.splice;var ut=function(t){var e=this.__data__,r=it(e,t);return!(r<0||(r==e.length-1?e.pop():at.call(e,r,1),--this.size,0))};var ct=function(t){var e=this.__data__,r=it(e,t);return r<0?void 0:e[r][1]};var st=function(t){return it(this.__data__,t)>-1};var ft=function(t,e){var r=this.__data__,n=it(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};function lt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}lt.prototype.clear=nt,lt.prototype.delete=ut,lt.prototype.get=ct,lt.prototype.has=st,lt.prototype.set=ft;var pt=lt,vt=G(a,"Map");var dt=function(){this.size=0,this.__data__={hash:new rt,map:new(vt||pt),string:new rt}};var ht=function(t){var e=typeof t;return"string"==e||"number"==e||"symbol"==e||"boolean"==e?"__proto__"!==t:null===t};var yt=function(t,e){var r=t.__data__;return ht(e)?r["string"==typeof e?"string":"hash"]:r.map};var _t=function(t){var e=yt(this,t).delete(t);return this.size-=e?1:0,e};var bt=function(t){return yt(this,t).get(t)};var gt=function(t){return yt(this,t).has(t)};var mt=function(t,e){var r=yt(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function jt(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}jt.prototype.clear=dt,jt.prototype.delete=_t,jt.prototype.get=bt,jt.prototype.has=gt,jt.prototype.set=mt;var wt=jt,Ot="Expected a function";function St(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError(Ot);var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],i=r.cache;if(i.has(o))return i.get(o);var a=t.apply(this,n);return r.cache=i.set(o,a)||i,a};return r.cache=new(St.Cache||wt),r}St.Cache=wt;var xt=St,Pt=500;var kt=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,zt=/\\(\\)?/g,At=function(t){var e=xt(t,function(t){return r.size===Pt&&r.clear(),t}),r=e.cache;return e}(function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(kt,function(t,r,n,o){e.push(n?o.replace(zt,"$1"):r||t)}),e});var Mt=function(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o},$t=1/0,Tt=u?u.prototype:void 0,Et=Tt?Tt.toString:void 0;var Ft=function t(e){if("string"==typeof e)return e;if(n(e))return Mt(e,t)+"";if(j(e))return Et?Et.call(e):"";var r=e+"";return"0"==r&&1/e==-$t?"-0":r};var Ct=function(t){return null==t?"":Ft(t)};var Nt=function(t,e){return n(t)?t:S(t,e)?[t]:At(Ct(t))},Rt=1/0;var Ht=function(t){if("string"==typeof t||j(t))return t;var e=t+"";return"0"==e&&1/t==-Rt?"-0":e};var It=function(t,e){for(var r=0,n=(e=Nt(e,t)).length;null!=t&&r<n;)t=t[Ht(e[r++])];return r&&r==n?t:void 0};var Dt=function(t,e,r){var n=null==t?void 0:It(t,e);return void 0===n?r:n};const Jt="o3-dapi",qt={},Bt={};function Gt({blockchain:t,callback:e}){Bt[t]=e}function Ut({blockchain:t,version:e,command:r,data:n,network:o,timeout:i}){const a=t+e+r+(Date.now()+Math.random()).toString(),u={platform:Jt,messageId:a,blockchain:t,version:e,command:r,data:n,network:o};return new Promise((t,e)=>{const r=Dt(window,"window._o3dapi.messageHandler"),n=Dt(window,"window.webkit.messageHandlers.sendMessageHandler.postMessage");r?r(JSON.stringify(u)):n?n(u):e("O3 dapi provider not found."),(r||n)&&(qt[a]={resolve:t,reject:e,timeout:i&&setTimeout(()=>{delete qt[a],e("Request timeout.")},i)})})}window._o3dapi=window._o3dapi?window._o3dapi:{},_o3dapi.receiveMessage=(t=>{try{"string"==typeof t&&(t=JSON.parse(t));const{platform:e,blockchain:r,command:n,messageId:o,data:i,error:a,eventName:u}=t;if(e!==Jt)return;if("event"===n){if("READY"===u)return void Object.keys(Bt).map(t=>Bt[t]).forEach(t=>t(u,i));const t=Bt[r];return void(t&&t(u,i))}const c=qt[o];if(c){const{resolve:t,timeout:e,reject:r}=c;e&&clearTimeout(e),a?r(a):t(i)}}catch(t){}});const Yt={initPlugins:t=>{t.forEach(t=>{Yt[t.blockchain]=new t(Ut,Gt)})}};Yt.isAvailable=Boolean(window._o3dapi.isAvailable);e.default=Yt}]).default}); |
{ | ||
"name": "o3-dapi-core", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "O3 dapi core messaging protocol", | ||
@@ -5,0 +5,0 @@ "main": "./lib/node/o3-dapi-core.min.js", |
@@ -16,2 +16,4 @@ import { Plugin } from './types'; | ||
o3dapiCore.isAvailable = Boolean((window as any)._o3dapi.isAvailable); | ||
export default o3dapiCore; |
@@ -15,3 +15,2 @@ declare const window: any; | ||
const eventsListeners: {[blockchain: string]: EventHandler} = {}; | ||
let onReadyMessage; | ||
@@ -39,2 +38,5 @@ window._o3dapi = window._o3dapi ? window._o3dapi : {}; | ||
if (command === 'event') { | ||
// ready event is not specifc to any blockchain | ||
// so call all listeners on each blockchain plugin | ||
if (eventName === 'READY') { | ||
@@ -73,3 +75,2 @@ Object.keys(eventsListeners) | ||
}: SendMessageArgs): Promise<any> { | ||
debugger; | ||
const messageId = blockchain + version + command + (Date.now() + Math.random()).toString(); | ||
@@ -76,0 +77,0 @@ const message: Message = { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
106048
223