scatterjs-core
Advanced tools
Comparing version 2.7.5 to 2.7.6
@@ -1,1 +0,1 @@ | ||
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.WALLET_METHODS=void 0;var _ALTERNATES,_classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")),_createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass")),_defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty")),WALLET_METHODS={disconnect:"disconnect",isConnected:"isConnected",isPaired:"isPaired",addEventHandler:"addEventHandler",removeEventHandler:"removeEventHandler",listen:"listen",getVersion:"getVersion",getIdentity:"getIdentity",getIdentityFromPermissions:"getIdentityFromPermissions",forgetIdentity:"forgetIdentity",authenticate:"authenticate",getArbitrarySignature:"getArbitrarySignature",getPublicKey:"getPublicKey",linkAccount:"linkAccount",hasAccountFor:"hasAccountFor",suggestNetwork:"suggestNetwork",requestTransfer:"requestTransfer",requestSignature:"requestSignature",createTransaction:"createTransaction",addToken:"addToken"};exports.WALLET_METHODS=WALLET_METHODS;var ALTERNATES=(_ALTERNATES={},(0,_defineProperty2.default)(_ALTERNATES,WALLET_METHODS.getIdentity,"login"),(0,_defineProperty2.default)(_ALTERNATES,WALLET_METHODS.forgetIdentity,"logout"),(0,_defineProperty2.default)(_ALTERNATES,WALLET_METHODS.getIdentityFromPermissions,"checkLogin"),_ALTERNATES),WalletInterface=/*#__PURE__*/function(){function a(b,c,d){(0,_classCallCheck2.default)(this,a);var e=function(a){return function(){throw new Error("".concat(b," does not support the ").concat(a," method."))}},f=function(a,b){"undefined"==typeof d[b]&&(d[b]=a?a:e(b)),ALTERNATES[b]&&"undefined"==typeof d[ALTERNATES[b]]&&(d[ALTERNATES[b]]=d[b]?d[b]:e(b))};Object.keys(WALLET_METHODS).map(function(a){return f(c[a],a)})}return(0,_createClass2.default)(a,null,[{key:"bindBasics",value:function b(a){a.account=function(b){return a.identity?a.identity.accounts?a.identity.accounts.find(function(a){return a.blockchain===b}):void 0:void 0}}}]),a}();exports.default=WalletInterface; | ||
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.WALLET_METHODS=void 0;var _ALTERNATES,_classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")),_createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass")),_defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty")),WALLET_METHODS={disconnect:"disconnect",isConnected:"isConnected",isPaired:"isPaired",addEventHandler:"addEventHandler",removeEventHandler:"removeEventHandler",listen:"listen",getVersion:"getVersion",getIdentity:"getIdentity",getIdentityFromPermissions:"getIdentityFromPermissions",forgetIdentity:"forgetIdentity",updateIdentity:"updateIdentity",authenticate:"authenticate",getArbitrarySignature:"getArbitrarySignature",getPublicKey:"getPublicKey",linkAccount:"linkAccount",hasAccountFor:"hasAccountFor",suggestNetwork:"suggestNetwork",requestTransfer:"requestTransfer",requestSignature:"requestSignature",createTransaction:"createTransaction",addToken:"addToken"};exports.WALLET_METHODS=WALLET_METHODS;var ALTERNATES=(_ALTERNATES={},(0,_defineProperty2.default)(_ALTERNATES,WALLET_METHODS.getIdentity,"login"),(0,_defineProperty2.default)(_ALTERNATES,WALLET_METHODS.forgetIdentity,"logout"),(0,_defineProperty2.default)(_ALTERNATES,WALLET_METHODS.getIdentityFromPermissions,"checkLogin"),_ALTERNATES),WalletInterface=/*#__PURE__*/function(){function a(b,c,d){(0,_classCallCheck2.default)(this,a);var e=function(a){return function(){throw new Error("".concat(b," does not support the ").concat(a," method."))}},f=function(a,b){"undefined"==typeof d[b]&&(d[b]=a?a:e(b)),ALTERNATES[b]&&"undefined"==typeof d[ALTERNATES[b]]&&(d[ALTERNATES[b]]=d[b]?d[b]:e(b))};Object.keys(WALLET_METHODS).map(function(a){return f(c[a],a)})}return(0,_createClass2.default)(a,null,[{key:"bindBasics",value:function b(a){a.account=function(b){return a.identity?a.identity.accounts?a.identity.accounts.find(function(a){return a.blockchain===b}):void 0:void 0}}}]),a}();exports.default=WalletInterface; |
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var plugin,_regenerator=_interopRequireDefault(require("@babel/runtime/regenerator")),_typeof2=_interopRequireDefault(require("@babel/runtime/helpers/typeof")),_slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")),_asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")),_classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")),_createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass")),_StorageService=_interopRequireDefault(require("./StorageService")),_getRandomValues=_interopRequireDefault(require("get-random-values")),_createHash=_interopRequireDefault(require("create-hash")),_isomorphicWs=_interopRequireDefault(require("isomorphic-ws")),suffix="/socket.io/?EIO=3&transport=websocket",socket=null,connected=!1,paired=!1,openRequests=[],allowReconnects=!0,reconnectionTimeout=null,sha256=function(a){return(0,_createHash.default)("sha256").update(a).digest("hex")},random=function(){var a=new Uint8Array(24);return(0,_getRandomValues.default)(a),a.join("")},_getOrigin=function b(){var a;return a="undefined"==typeof location?plugin:location.hasOwnProperty("hostname")&&location.hostname.length&&"localhost"!==location.hostname?location.hostname:plugin,"www."===a.substr(0,4)&&(a=a.replace("www.","")),a},appkey=_StorageService.default.getAppKey();appkey||(appkey="appkey:"+random());var send=function(){var a=0<arguments.length&&arguments[0]!==void 0?arguments[0]:null,b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:null;null===a&&null===b?socket.send("40/scatter"):socket.send("42/scatter,"+JSON.stringify([a,b]))},pairingPromise=null,pair=function(){var a=!!(0<arguments.length&&arguments[0]!==void 0)&&arguments[0];return new Promise(function(b,c){pairingPromise={resolve:b,reject:c},send("pair",{data:{appkey:appkey,origin:_getOrigin(),passthrough:a},plugin:plugin})})},eventHandlers={},SocketService=/*#__PURE__*/function(){function a(){(0,_classCallCheck2.default)(this,a)}return(0,_createClass2.default)(a,null,[{key:"init",value:function c(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:6e4;plugin=a,this.timeout=b}},{key:"getOrigin",value:function a(){return _getOrigin()}},{key:"addEventHandler",value:function c(a,b){b||(b="app"),eventHandlers[b]=a}},{key:"removeEventHandler",value:function b(a){a||(a="app"),delete eventHandlers[a]}},{key:"link",value:function b(){var a=this;return Promise.race([new Promise(function(b){return setTimeout(function(){connected||(b(!1),socket&&(socket.disconnect(),socket=null))},a.timeout)}),new Promise(/*#__PURE__*/function(){var a=(0,_asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function a(b){var c,d;return _regenerator.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return c=function(){socket.onmessage=function(e){// Handshaking/Upgrading | ||
if(-1===e.data.indexOf("42/scatter"))return!1;// Real message | ||
var f=JSON.parse(e.data.replace("42/scatter,","")),g=(0,_slicedToArray2.default)(f,2),h=g[0],i=g[1];return"paired"===h?a(i):"rekey"===h?b():"api"===h?c(i):"event"===h?d(i):void 0};var a=function(a){if(paired=a,paired){var b=_StorageService.default.getAppKey(),c=-1<appkey.indexOf("appkey:")?sha256(appkey):appkey;b&&b===c||(_StorageService.default.setAppKey(c),appkey=_StorageService.default.getAppKey())}pairingPromise.resolve(a)},b=function(){appkey="appkey:"+random(),send("rekeyed",{data:{appkey:appkey,origin:_getOrigin()},plugin:plugin})},c=function(a){var b=openRequests.find(function(b){return b.id===a.id});if(b){openRequests=openRequests.filter(function(b){return b.id!==a.id});var c="object"===(0,_typeof2.default)(a.result)&&null!==a.result&&a.result.hasOwnProperty("isError");c?b.reject(a.result):b.resolve(a.result)}},d=function(a){var b=a.event,c=a.payload;Object.keys(eventHandlers).length&&Object.keys(eventHandlers).map(function(a){eventHandlers[a](b,c)})}},d=function(){var a,e=!(0<arguments.length&&void 0!==arguments[0])||arguments[0],f=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null;f||(a=new Promise(function(a){return f=a}));var g=e?"local.get-scatter.com:50006":"127.0.0.1:50005",h=e?"wss://":"ws://",i="".concat(h).concat(g).concat(suffix),j=new _isomorphicWs.default(i);return j.onerror=function(){e?d(!1,f):(b(!1),f(!1))},j.onopen=function(){socket=j,send(),clearTimeout(reconnectionTimeout),connected=!0,pair(!0).then(function(){b(!0),f(!0)}),c()},a},a.next=4,d();case 4:case"end":return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}}())])}},{key:"isConnected",value:function a(){return connected}},{key:"isPaired",value:function a(){return paired}},{key:"disconnect",value:function a(){return socket&&socket.disconnect(),!0}},{key:"sendApiRequest",value:function b(a){return new Promise(function(b,c){return"identityFromPermissions"!==a.type||paired?void pair().then(function(){if(!paired)return c({code:"not_paired",message:"The user did not allow this app to connect to their Scatter"});// Request ID used for resolving promises | ||
var f=JSON.parse(e.data.replace("42/scatter,","")),g=(0,_slicedToArray2.default)(f,2),h=g[0],i=g[1];return"paired"===h?a(i):"rekey"===h?b():"api"===h?c(i):"event"===h?d(i):void 0};var a=function(a){if(paired=a,paired){var b=_StorageService.default.getAppKey(),c=-1<appkey.indexOf("appkey:")?sha256(appkey):appkey;b&&b===c||(_StorageService.default.setAppKey(c),appkey=_StorageService.default.getAppKey())}pairingPromise.resolve(a)},b=function(){appkey="appkey:"+random(),send("rekeyed",{data:{appkey:appkey,origin:_getOrigin()},plugin:plugin})},c=function(a){var b=openRequests.find(function(b){return b.id===a.id});if(b){openRequests=openRequests.filter(function(b){return b.id!==a.id});var c="object"===(0,_typeof2.default)(a.result)&&null!==a.result&&a.result.hasOwnProperty("isError");c?b.reject(a.result):b.resolve(a.result)}},d=function(a){var b=a.event,c=a.payload;Object.keys(eventHandlers).length&&Object.keys(eventHandlers).map(function(a){eventHandlers[a](b,c)})}},d=function(){var a,e=!(0<arguments.length&&void 0!==arguments[0])||arguments[0],f=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null;f||(a=new Promise(function(a){return f=a}));var g=e?"local.get-scatter.com:50006":"127.0.0.1:50005",h=e?"wss://":"ws://",i="".concat(h).concat(g).concat(suffix),j=new _isomorphicWs.default(i);return j.onerror=function(){e?d(!1,f):(b(!1),f(!1))},j.onopen=function(){socket=j,send(),clearTimeout(reconnectionTimeout),connected=!0,pair(!0).then(function(){b(!0),f(!0)}),c()},a},a.next=4,d();case 4:case"end":return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}}())])}},{key:"isConnected",value:function a(){return connected}},{key:"isPaired",value:function a(){return paired}},{key:"disconnect",value:function a(){return socket&&socket.disconnect(),!0}},{key:"removeAppKeys",value:function a(){_StorageService.default.removeAppKey(),_StorageService.default.removeNonce()}},{key:"sendApiRequest",value:function b(a){return new Promise(function(b,c){return"identityFromPermissions"!==a.type||paired?void pair().then(function(){if(!paired)return c({code:"not_paired",message:"The user did not allow this app to connect to their Scatter"});// Request ID used for resolving promises | ||
a.id=random(),a.appkey=appkey,a.nonce=_StorageService.default.getNonce()||0;// Next nonce used to authenticate the next request | ||
var d=random();a.nextNonce=sha256(d),_StorageService.default.setNonce(d),a.hasOwnProperty("payload")&&!a.payload.hasOwnProperty("origin")&&(a.payload.origin=_getOrigin()),openRequests.push(Object.assign(a,{resolve:b,reject:c})),send("api",{data:a,plugin:plugin})}):b(!1)})}}]),a}();exports.default=SocketService; |
@@ -1,1 +0,1 @@ | ||
"use strict";var _interopRequireWildcard=require("@babel/runtime/helpers/interopRequireWildcard"),_interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty")),_regenerator=_interopRequireDefault(require("@babel/runtime/regenerator")),_asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")),_classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")),_createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass")),_possibleConstructorReturn2=_interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")),_getPrototypeOf2=_interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")),_inherits2=_interopRequireDefault(require("@babel/runtime/helpers/inherits")),_Plugin2=_interopRequireDefault(require("../plugins/Plugin")),_Blockchains=require("../models/Blockchains"),PluginTypes=_interopRequireWildcard(require("../plugins/PluginTypes")),_SocketService=_interopRequireDefault(require("../services/SocketService")),_index=require("../index"),Desktop=/*#__PURE__*/function(a){function b(a){var c;return(0,_classCallCheck2.default)(this,b),c=(0,_possibleConstructorReturn2.default)(this,(0,_getPrototypeOf2.default)(b).call(this,_Blockchains.Blockchains.EOS,PluginTypes.WALLET_SUPPORT)),c.name="ScatterSockets",c.context=a,c}return(0,_inherits2.default)(b,a),(0,_createClass2.default)(b,[{key:"connect",value:function d(a){var b=this,c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return new Promise(function(d){if(!a||!a.length)throw new Error("You must specify a name for this connection");c=Object.assign({initTimeout:1e4,linkTimeout:3e4},c),_SocketService.default.init(a,c.linkTimeout),_SocketService.default.link().then(/*#__PURE__*/function(){var a=(0,_asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function a(c){return _regenerator.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(c){a.next=2;break}return a.abrupt("return",!1);case 2:return b.context.isExtension=!1,a.abrupt("return",d(!0));case 4:case"end":return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}}())})}},{key:"runAfterInterfacing",value:function(){var a=(0,_asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function a(){var b=this;return _regenerator.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return this.context.addEventHandler(function(a,c){return b.eventHandler(a,c)},"internal"),a.next=3,this.context.getIdentityFromPermissions();case 3:return this.context.identity=a.sent,a.abrupt("return",!0);case 5:case"end":return a.stop();}},a,this)}));return function b(){return a.apply(this,arguments)}}()},{key:"methods",value:function d(){var a,b=this,c=function(a,c){return(a||c)&&(b.context.identity=a),c||a};return a={},(0,_defineProperty2.default)(a,_index.WALLET_METHODS.disconnect,function(){return _SocketService.default.disconnect()}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.isConnected,function(){return _SocketService.default.isConnected()}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.isPaired,function(){return _SocketService.default.isPaired()}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.addEventHandler,function(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null;return _SocketService.default.addEventHandler(a,b)}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.removeEventHandler,function(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:null;return _SocketService.default.removeEventHandler(a)}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.listen,function(a){return _SocketService.default.addEventHandler(a)}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.getVersion,function(){return _SocketService.default.sendApiRequest({type:"getVersion",payload:{}})}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.getIdentity,function(a){return _SocketService.default.sendApiRequest({type:"getOrRequestIdentity",payload:{fields:a?a:{accounts:[b.context.network]}}}).then(c)}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.getIdentityFromPermissions,function(){return _SocketService.default.sendApiRequest({type:"identityFromPermissions",payload:{}}).then(c)}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.forgetIdentity,function(){return _SocketService.default.sendApiRequest({type:"forgetIdentity",payload:{}}).then(function(a){return c(null,a)})}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.authenticate,function(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:null;return _SocketService.default.sendApiRequest({type:"authenticate",payload:{nonce:a,data:b,publicKey:c}})}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.getArbitrarySignature,function(a,b){return _SocketService.default.sendApiRequest({type:"requestArbitrarySignature",payload:{publicKey:a,data:b}})}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.getPublicKey,function(a){return _SocketService.default.sendApiRequest({type:"getPublicKey",payload:{blockchain:a}})}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.linkAccount,function(a,c){return _SocketService.default.sendApiRequest({type:"linkAccount",payload:{account:a,network:c||b.context.network}})}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.hasAccountFor,function(a){return _SocketService.default.sendApiRequest({type:"hasAccountFor",payload:{network:a||b.context.network}})}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.suggestNetwork,function(a){return _SocketService.default.sendApiRequest({type:"requestAddNetwork",payload:{network:a||b.context.network}})}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.requestTransfer,function(a,c,d){var e=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{};return _SocketService.default.sendApiRequest({type:"requestTransfer",payload:{network:a||b.context.network,to:c,amount:d,options:e}})}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.requestSignature,function(a){return _SocketService.default.sendApiRequest({type:"requestSignature",payload:a})}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.createTransaction,function(a,c,d,e){return _SocketService.default.sendApiRequest({type:"createTransaction",payload:{blockchain:a,actions:c,account:d,network:e||b.context.network}})}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.addToken,function(a,c){return _SocketService.default.sendApiRequest({type:"addToken",payload:{token:a,network:c||b.context.network}})}),a}},{key:"eventHandler",value:function(){var a=(0,_asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function a(b){return _regenerator.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:a.t0=b,a.next=a.t0===_index.EVENTS.Disconnected?3:a.t0===_index.EVENTS.LoggedOut?5:9;break;case 3:return this.context.identity=null,a.abrupt("break",9);case 5:return a.next=7,this.context.getIdentityFromPermissions();case 7:return this.context.identity=a.sent,a.abrupt("break",9);case 9:case"end":return a.stop();}},a,this)}));return function b(){return a.apply(this,arguments)}}()}]),b}(_Plugin2.default);exports.default=Desktop; | ||
"use strict";var _interopRequireWildcard=require("@babel/runtime/helpers/interopRequireWildcard"),_interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty")),_regenerator=_interopRequireDefault(require("@babel/runtime/regenerator")),_asyncToGenerator2=_interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator")),_classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")),_createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass")),_possibleConstructorReturn2=_interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")),_getPrototypeOf2=_interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")),_inherits2=_interopRequireDefault(require("@babel/runtime/helpers/inherits")),_Plugin2=_interopRequireDefault(require("../plugins/Plugin")),_Blockchains=require("../models/Blockchains"),PluginTypes=_interopRequireWildcard(require("../plugins/PluginTypes")),_SocketService=_interopRequireDefault(require("../services/SocketService")),_index=require("../index"),Desktop=/*#__PURE__*/function(a){function b(a,c){var d;return(0,_classCallCheck2.default)(this,b),d=(0,_possibleConstructorReturn2.default)(this,(0,_getPrototypeOf2.default)(b).call(this,_Blockchains.Blockchains.EOS,PluginTypes.WALLET_SUPPORT)),d.name="ScatterSockets",d.context=a,d.holderFns=c,d}return(0,_inherits2.default)(b,a),(0,_createClass2.default)(b,[{key:"connect",value:function d(a){var b=this,c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return new Promise(function(d){if(!a||!a.length)throw new Error("You must specify a name for this connection");c=Object.assign({initTimeout:1e4,linkTimeout:3e4},c),_SocketService.default.init(a,c.linkTimeout),_SocketService.default.link().then(/*#__PURE__*/function(){var a=(0,_asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function a(c){return _regenerator.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:if(c){a.next=2;break}return a.abrupt("return",!1);case 2:return b.holderFns.get().isExtension=!1,a.abrupt("return",d(!0));case 4:case"end":return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}}())})}},{key:"runAfterInterfacing",value:function(){var a=(0,_asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function a(){var b=this;return _regenerator.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return this.holderFns.get().addEventHandler(function(a,c){return b.eventHandler(a,c)},"internal"),a.next=3,this.holderFns.get().getIdentityFromPermissions();case 3:return this.holderFns.get().identity=a.sent,a.abrupt("return",!0);case 5:case"end":return a.stop();}},a,this)}));return function b(){return a.apply(this,arguments)}}()},{key:"methods",value:function d(){var a,b=this,c=function(a,c){return(a||c)&&(b.holderFns.get().identity=a),c&&_SocketService.default.removeAppKeys(),c||a};return a={},(0,_defineProperty2.default)(a,_index.WALLET_METHODS.disconnect,function(){return _SocketService.default.disconnect()}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.isConnected,function(){return _SocketService.default.isConnected()}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.isPaired,function(){return _SocketService.default.isPaired()}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.addEventHandler,function(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null;return _SocketService.default.addEventHandler(a,b)}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.removeEventHandler,function(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:null;return _SocketService.default.removeEventHandler(a)}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.listen,function(a){return _SocketService.default.addEventHandler(a)}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.getVersion,function(){return _SocketService.default.sendApiRequest({type:"getVersion",payload:{}})}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.getIdentity,function(a){return _SocketService.default.sendApiRequest({type:"getOrRequestIdentity",payload:{fields:a?a:{accounts:[b.holderFns.get().network]}}}).then(c)}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.getIdentityFromPermissions,function(){return _SocketService.default.sendApiRequest({type:"identityFromPermissions",payload:{}}).then(c)}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.forgetIdentity,function(){return _SocketService.default.sendApiRequest({type:"forgetIdentity",payload:{}}).then(function(a){return c(null,a)})}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.updateIdentity,function(a){var b=a.name,d=a.kyc;return _SocketService.default.sendApiRequest({type:"updateIdentity",payload:{name:b,kyc:d}}).then(function(a){return a?c(a):null})}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.authenticate,function(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null,c=2<arguments.length&&void 0!==arguments[2]?arguments[2]:null;return _SocketService.default.sendApiRequest({type:"authenticate",payload:{nonce:a,data:b,publicKey:c}})}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.getArbitrarySignature,function(a,b){return _SocketService.default.sendApiRequest({type:"requestArbitrarySignature",payload:{publicKey:a,data:b}})}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.getPublicKey,function(a){return _SocketService.default.sendApiRequest({type:"getPublicKey",payload:{blockchain:a}})}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.linkAccount,function(a,c){return _SocketService.default.sendApiRequest({type:"linkAccount",payload:{account:a,network:c||b.holderFns.get().network}})}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.hasAccountFor,function(a){return _SocketService.default.sendApiRequest({type:"hasAccountFor",payload:{network:a||b.holderFns.get().network}})}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.suggestNetwork,function(a){return _SocketService.default.sendApiRequest({type:"requestAddNetwork",payload:{network:a||b.holderFns.get().network}})}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.requestTransfer,function(a,c,d){var e=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{};return _SocketService.default.sendApiRequest({type:"requestTransfer",payload:{network:a||b.holderFns.get().network,to:c,amount:d,options:e}})}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.requestSignature,function(a){return _SocketService.default.sendApiRequest({type:"requestSignature",payload:a})}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.createTransaction,function(a,c,d,e){return _SocketService.default.sendApiRequest({type:"createTransaction",payload:{blockchain:a,actions:c,account:d,network:e||b.holderFns.get().network}})}),(0,_defineProperty2.default)(a,_index.WALLET_METHODS.addToken,function(a,c){return _SocketService.default.sendApiRequest({type:"addToken",payload:{token:a,network:c||b.holderFns.get().network}})}),a}},{key:"eventHandler",value:function(){var a=(0,_asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function a(b){return _regenerator.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:a.t0=b,a.next=a.t0===_index.EVENTS.Disconnected?3:a.t0===_index.EVENTS.LoggedOut?5:9;break;case 3:return this.holderFns.get().identity=null,a.abrupt("break",9);case 5:return a.next=7,this.holderFns.get().getIdentityFromPermissions();case 7:return this.holderFns.get().identity=a.sent,a.abrupt("break",9);case 9:case"end":return a.stop();}},a,this)}));return function b(){return a.apply(this,arguments)}}()}]),b}(_Plugin2.default);exports.default=Desktop; |
{ | ||
"name": "scatterjs-core", | ||
"version": "2.7.5", | ||
"version": "2.7.6", | ||
"main": "dist/index.js", | ||
@@ -13,3 +13,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "38e1a6704d3589b93afcae4bbe04f23542418365" | ||
"gitHead": "8a6d4a145e1126518cb20d02f7495909efd3ca2b" | ||
} |
@@ -13,2 +13,3 @@ export const WALLET_METHODS = { | ||
forgetIdentity:'forgetIdentity', | ||
updateIdentity:'updateIdentity', | ||
authenticate:'authenticate', | ||
@@ -15,0 +16,0 @@ getArbitrarySignature:'getArbitrarySignature', |
@@ -39,6 +39,2 @@ import StorageService from './StorageService' | ||
// StorageService.removeAppKey(); | ||
// StorageService.removeNonce(); | ||
let appkey = StorageService.getAppKey(); | ||
@@ -208,2 +204,7 @@ if(!appkey) appkey = 'appkey:'+random(); | ||
static removeAppKeys(){ | ||
StorageService.removeAppKey(); | ||
StorageService.removeNonce(); | ||
} | ||
static sendApiRequest(request){ | ||
@@ -210,0 +211,0 @@ return new Promise((resolve, reject) => { |
@@ -9,6 +9,7 @@ import Plugin from "../plugins/Plugin"; | ||
export default class Desktop extends Plugin { | ||
constructor(context){ | ||
constructor(context, holderFns){ | ||
super(Blockchains.EOS, PluginTypes.WALLET_SUPPORT); | ||
this.name = 'ScatterSockets'; | ||
this.context = context; | ||
this.holderFns = holderFns; | ||
} | ||
@@ -26,3 +27,3 @@ | ||
if(!authenticated) return false; | ||
this.context.isExtension = false; | ||
this.holderFns.get().isExtension = false; | ||
return resolve(true); | ||
@@ -34,4 +35,4 @@ }); | ||
async runAfterInterfacing(){ | ||
this.context.addEventHandler((t,x) => this.eventHandler(t,x), 'internal'); | ||
this.context.identity = await this.context.getIdentityFromPermissions(); | ||
this.holderFns.get().addEventHandler((t,x) => this.eventHandler(t,x), 'internal'); | ||
this.holderFns.get().identity = await this.holderFns.get().getIdentityFromPermissions(); | ||
return true; | ||
@@ -42,3 +43,4 @@ } | ||
const setAndReturnId = (id, forget) => { | ||
if(id || forget) this.context.identity = id; | ||
if(id || forget) this.holderFns.get().identity = id; | ||
if(forget) SocketService.removeAppKeys(); | ||
return forget || id; | ||
@@ -57,3 +59,3 @@ }; | ||
type:'getOrRequestIdentity', | ||
payload:{ fields:requiredFields ? requiredFields : {accounts:[this.context.network]} } | ||
payload:{ fields:requiredFields ? requiredFields : {accounts:[this.holderFns.get().network]} } | ||
}).then(setAndReturnId), | ||
@@ -68,2 +70,6 @@ [WALLET_METHODS.getIdentityFromPermissions]:() => SocketService.sendApiRequest({ | ||
}).then(res => setAndReturnId(null, res)), | ||
[WALLET_METHODS.updateIdentity]:({name, kyc}) => SocketService.sendApiRequest({ | ||
type:'updateIdentity', | ||
payload:{name, kyc} | ||
}).then(id => id ? setAndReturnId(id) : null), | ||
[WALLET_METHODS.authenticate]:(nonce, data = null, publicKey = null) => SocketService.sendApiRequest({ | ||
@@ -83,15 +89,15 @@ type:'authenticate', | ||
type:'linkAccount', | ||
payload:{ account, network:network || this.context.network } | ||
payload:{ account, network:network || this.holderFns.get().network } | ||
}), | ||
[WALLET_METHODS.hasAccountFor]:(network) => SocketService.sendApiRequest({ | ||
type:'hasAccountFor', | ||
payload:{ network:network || this.context.network } | ||
payload:{ network:network || this.holderFns.get().network } | ||
}), | ||
[WALLET_METHODS.suggestNetwork]:(network) => SocketService.sendApiRequest({ | ||
type:'requestAddNetwork', | ||
payload:{ network:network || this.context.network } | ||
payload:{ network:network || this.holderFns.get().network } | ||
}), | ||
[WALLET_METHODS.requestTransfer]:(network, to, amount, options = {}) => SocketService.sendApiRequest({ | ||
type:'requestTransfer', | ||
payload:{network:network || this.context.network, to, amount, options} | ||
payload:{network:network || this.holderFns.get().network, to, amount, options} | ||
}), | ||
@@ -104,7 +110,7 @@ [WALLET_METHODS.requestSignature]:(payload) => SocketService.sendApiRequest({ | ||
type:'createTransaction', | ||
payload:{ blockchain, actions, account, network:network || this.context.network } | ||
payload:{ blockchain, actions, account, network:network || this.holderFns.get().network } | ||
}), | ||
[WALLET_METHODS.addToken]:(token, network) => SocketService.sendApiRequest({ | ||
type:'addToken', | ||
payload:{ token, network:network || this.context.network } | ||
payload:{ token, network:network || this.holderFns.get().network } | ||
}), | ||
@@ -117,6 +123,6 @@ } | ||
case EVENTS.Disconnected: | ||
this.context.identity = null; | ||
this.holderFns.get().identity = null; | ||
break; | ||
case EVENTS.LoggedOut: | ||
this.context.identity = await this.context.getIdentityFromPermissions(); | ||
this.holderFns.get().identity = await this.holderFns.get().getIdentityFromPermissions(); | ||
break; | ||
@@ -123,0 +129,0 @@ } |
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
71462
895