Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

scatterjs-core

Package Overview
Dependencies
Maintainers
1
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

scatterjs-core - npm Package Compare versions

Comparing version 2.6.0 to 2.7.0

dist/models/WalletInterface.js

24

dist/index.js

@@ -1,23 +0,1 @@

"use strict";var _interopRequireWildcard=require("@babel/runtime/helpers/interopRequireWildcard"),_interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _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")),_PluginRepository=_interopRequireDefault(require("./plugins/PluginRepository")),_SocketService=_interopRequireDefault(require("./services/SocketService")),_Plugin=_interopRequireDefault(require("./plugins/Plugin")),PluginTypes=_interopRequireWildcard(require("./plugins/PluginTypes"));var origin,_Blockchains=require("./models/Blockchains"),_Network=_interopRequireDefault(require("./models/Network")),throwNoAuth=function(){if(!holder.scatter.isExtension&&!_SocketService.default.isConnected())throw new Error("Connect and Authenticate first - scatter.connect( pluginName )")},checkForExtension=function(a){var b=1<arguments.length&&arguments[1]!==void 0?arguments[1]:0;return 20<b?void 0:holder.scatter.isExtension?a(!0):void setTimeout(function(){return checkForExtension(a,b+1)},100)},EVENTS={Disconnected:"dced",LoggedOut:"logout"};Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"SocketService",{enumerable:!0,get:function get(){return _SocketService.default}}),Object.defineProperty(exports,"Plugin",{enumerable:!0,get:function get(){return _Plugin.default}}),Object.defineProperty(exports,"Blockchains",{enumerable:!0,get:function get(){return _Blockchains.Blockchains}}),Object.defineProperty(exports,"Network",{enumerable:!0,get:function get(){return _Network.default}}),exports.PluginTypes=exports.default=exports.EVENTS=void 0;exports.PluginTypes=PluginTypes;exports.EVENTS=EVENTS;var Index=/*#__PURE__*/function(){function a(){(0,_classCallCheck2.default)(this,a),this.isExtension=!1,this.identity=null}return(0,_createClass2.default)(a,[{key:"loadPlugin",value:function loadPlugin(a){var b=this;if(!a.isValid())throw new Error("".concat(a.name," doesn't seem to be a valid ScatterJS plugin."));_PluginRepository.default.loadPlugin(a),a.isSignatureProvider()&&(this[a.name]=a.signatureProvider(function noIdFunc(){if(!b.identity)throw new Error("No Identity")},function(){return b.identity}),this[a.name+"Hook"]=a.hookProvider)}},{key:"connect",value:function(){var a=(0,_asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function a(b,c){var d=this;return _regenerator.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.abrupt("return",new Promise(function(a){if(!b||!b.length)throw new Error("You must specify a name for this connection");// Setting options defaults
c=Object.assign({initTimeout:1e4,linkTimeout:3e4},c),setTimeout(function(){a(!1)},c.initTimeout),checkForExtension(a),_SocketService.default.init(b,c.linkTimeout),_SocketService.default.link().then(/*#__PURE__*/function(){var b=(0,_asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function b(c){return _regenerator.default.wrap(function(b){for(;;)switch(b.prev=b.next){case 0:if(c){b.next=2;break}return b.abrupt("return",!1);case 2:return d.addEventHandler(function(a,b){return d.eventHandler(a,b)},"internal"),b.next=5,d.getIdentityFromPermissions();case 5:return d.identity=b.sent,b.abrupt("return",a(!0));case 7:case"end":return b.stop();}},b,this)}));return function(){return b.apply(this,arguments)}}())}));case 1:case"end":return a.stop();}},a,this)}));return function connect(){return a.apply(this,arguments)}}()},{key:"disconnect",value:function disconnect(){return _SocketService.default.disconnect()}},{key:"isConnected",value:function isConnected(){return _SocketService.default.isConnected()}},{key:"isPaired",value:function isPaired(){return _SocketService.default.isPaired()}},{key:"addEventHandler",value:function addEventHandler(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null;_SocketService.default.addEventHandler(a,b)}},{key:"removeEventHandler",value:function removeEventHandler(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:null;_SocketService.default.removeEventHandler(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===EVENTS.Disconnected?3:a.t0===EVENTS.LoggedOut?5:9;break;case 3:return this.identity=null,a.abrupt("break",9);case 5:return a.next=7,this.getIdentityFromPermissions();case 7:return this.identity=a.sent,a.abrupt("break",9);case 9:case"end":return a.stop();}},a,this)}));return function eventHandler(){return a.apply(this,arguments)}}()},{key:"getVersion",value:function getVersion(){return _SocketService.default.sendApiRequest({type:"getVersion",payload:{}})}},{key:"listen",value:function listen(a){_SocketService.default.addEventHandler(a)}/***
* Logs a user into your application
* @param requiredFields
* @returns {Promise<any>}
*/},{key:"login",value:function login(a){var b=this;return throwNoAuth(),_SocketService.default.sendApiRequest({type:"getOrRequestIdentity",payload:{fields:a}}).then(function(a){return a&&(b.identity=a),a})}/***
* Check is a user is logged in by tapping
* their Scatter, but does not issue a popup
* @returns {Promise<any>}
*/},{key:"checkLogin",value:function checkLogin(){var a=this;return throwNoAuth(),_SocketService.default.sendApiRequest({type:"identityFromPermissions",payload:{}}).then(function(b){return b&&(a.identity=b),b})}/***
* Logs a user out of your application.
* @returns {Promise<any>}
*/},{key:"logout",value:function logout(){var a=this;return throwNoAuth(),_SocketService.default.sendApiRequest({type:"forgetIdentity",payload:{}}).then(function(b){return a.identity=null,b})}/***
* Authenticates a user's login using
* asymmetric encryption.
* @param nonce
* @param data - Optional data to sign ( fallback to appkey/origin )
* @param publicKey - Optional key to use ( fallback to identity key )
*/},{key:"authenticate",value:function authenticate(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 throwNoAuth(),_SocketService.default.sendApiRequest({type:"authenticate",payload:{nonce:a,data:b,publicKey:c}})}},{key:"getArbitrarySignature",value:function getArbitrarySignature(a,b){return throwNoAuth(),_SocketService.default.sendApiRequest({type:"requestArbitrarySignature",payload:{publicKey:a,data:b}})}},{key:"getPublicKey",value:function getPublicKey(a){return throwNoAuth(),_SocketService.default.sendApiRequest({type:"getPublicKey",payload:{blockchain:a}})}},{key:"linkAccount",value:function linkAccount(a,b){return throwNoAuth(),_SocketService.default.sendApiRequest({type:"linkAccount",payload:{account:a,network:b}})}},{key:"hasAccountFor",value:function hasAccountFor(a){return throwNoAuth(),_SocketService.default.sendApiRequest({type:"hasAccountFor",payload:{network:a}})}},{key:"suggestNetwork",value:function suggestNetwork(a){return throwNoAuth(),_SocketService.default.sendApiRequest({type:"requestAddNetwork",payload:{network:a}})}},{key:"requestTransfer",value:function requestTransfer(a,b,c){var d=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{};return _SocketService.default.sendApiRequest({type:"requestTransfer",payload:{network:a,to:b,amount:c,options:d}})}},{key:"requestSignature",value:function requestSignature(a){return throwNoAuth(),_SocketService.default.sendApiRequest({type:"requestSignature",payload:a})}},{key:"createTransaction",value:function createTransaction(a,b,c,d){return throwNoAuth(),_SocketService.default.sendApiRequest({type:"createTransaction",payload:{blockchain:a,actions:b,account:c,network:d}})}/******************************/ /******** DEPRECATED **********/ /******************************/ // @deprecated - Use `login(requiredFields)`
},{key:"getIdentity",value:function getIdentity(a){return this.login(a)}// @deprecated - Use `checkLogin()`
},{key:"getIdentityFromPermissions",value:function getIdentityFromPermissions(){return this.checkLogin()}// @deprecated - Use `logout()`
},{key:"forgetIdentity",value:function forgetIdentity(){return this.logout()}}]),a}(),Holder=/*#__PURE__*/function(){function a(b){(0,_classCallCheck2.default)(this,a),this.scatter=b}return(0,_createClass2.default)(a,[{key:"plugins",value:function plugins(){var a=this;if(!this.scatter.isExtension){for(var b=arguments.length,c=Array(b),d=0;d<b;d++)c[d]=arguments[d];c.map(function(b){return a.scatter.loadPlugin(b)})}}}]),a}(),holder=new Holder(new Index());if("undefined"!=typeof window){// Catching extension instead of Desktop
if("undefined"!=typeof document){var bindScatterClassic=function(){holder.scatter=window.scatter,holder.scatter.isExtension=!0,holder.scatter.connect=function(){return new Promise(function(a){return a(!0)})}};"undefined"==typeof window.scatter?document.addEventListener("scatterLoaded",function(){return bindScatterClassic()}):bindScatterClassic()}window.ScatterJS=holder}holder.Plugin=_Plugin.default,holder.PluginTypes=PluginTypes,holder.Blockchains=_Blockchains.Blockchains,holder.Network=_Network.default,holder.SocketService=_SocketService.default,holder.EVENTS=EVENTS;var _default=holder;exports.default=_default;
"use strict";var _interopRequireWildcard=require("@babel/runtime/helpers/interopRequireWildcard"),_interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"SocketService",{enumerable:!0,get:function a(){return _SocketService.default}}),Object.defineProperty(exports,"Plugin",{enumerable:!0,get:function a(){return _Plugin.default}}),Object.defineProperty(exports,"Blockchains",{enumerable:!0,get:function a(){return _Blockchains.Blockchains}}),Object.defineProperty(exports,"Network",{enumerable:!0,get:function a(){return _Network.default}}),Object.defineProperty(exports,"WalletInterface",{enumerable:!0,get:function a(){return _WalletInterface.default}}),Object.defineProperty(exports,"WALLET_METHODS",{enumerable:!0,get:function a(){return _WalletInterface.WALLET_METHODS}}),exports.PluginTypes=exports.default=exports.EVENTS=void 0;var _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")),_PluginRepository=_interopRequireDefault(require("./plugins/PluginRepository")),_SocketService=_interopRequireDefault(require("./services/SocketService")),_Plugin=_interopRequireDefault(require("./plugins/Plugin")),PluginTypes=_interopRequireWildcard(require("./plugins/PluginTypes"));exports.PluginTypes=PluginTypes;var origin,_Blockchains=require("./models/Blockchains"),_Network=_interopRequireDefault(require("./models/Network")),_WalletInterface=_interopRequireWildcard(require("./models/WalletInterface")),_Desktop=_interopRequireDefault(require("./wallets/Desktop")),_Extension=_interopRequireDefault(require("./wallets/Extension")),_Token=_interopRequireDefault(require("./models/Token")),EVENTS={Disconnected:"dced",LoggedOut:"logout"};exports.EVENTS=EVENTS;var socketService=_SocketService.default,socketSetters=[],holderFns={},Index=/*#__PURE__*/function(){function a(){(0,_classCallCheck2.default)(this,a),this.identity=null,this.network=null,_PluginRepository.default.loadPlugin(new _Desktop.default(this,holderFns)),_PluginRepository.default.loadPlugin(new _Extension.default(this,holderFns))}return(0,_createClass2.default)(a,[{key:"loadPlugin",value:function c(a){var b=this;if(!a.isValid())throw new Error("".concat(a.name," doesn't seem to be a valid ScatterJS plugin."));_PluginRepository.default.loadPlugin(a),a.type===PluginTypes.BLOCKCHAIN_SUPPORT&&(this[a.name]=a.signatureProvider(function a(){if(!b.identity)throw new Error("No Identity")},function(){return b.identity}),this[a.name+"Hook"]=a.hookProvider,socketSetters.push(a.setSocketService)),a.type===PluginTypes.WALLET_SUPPORT&&a.init(this,holderFns,socketSetters)}},{key:"connect",value:function(){var a=(0,_asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function a(b,c){var d;return _regenerator.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return c||(c={}),this.network=c.hasOwnProperty("network")?c.network:null,d=_PluginRepository.default.wallets(),a.next=5,Promise.race(d.map(function(a){return a.connect(b,c).then(/*#__PURE__*/(0,_asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function b(){return _regenerator.default.wrap(function(b){for(;;)switch(b.prev=b.next){case 0:if("function"!=typeof a.runBeforeInterfacing){b.next=3;break}return b.next=3,a.runBeforeInterfacing();case 3:if(new _WalletInterface.default(a.name,a.methods(),holderFns.get()),"function"!=typeof a.runAfterInterfacing){b.next=7;break}return b.next=7,a.runAfterInterfacing();case 7:return _WalletInterface.default.bindBasics(holderFns.get()),b.abrupt("return",!0);case 9:case"end":return b.stop();}},b,this)})))}).concat(new Promise(function(a){return setTimeout(function(){return a(!1)},c.initTimeout||5e3)})));case 5:return a.abrupt("return",a.sent);case 6:case"end":return a.stop();}},a,this)}));return function b(){return a.apply(this,arguments)}}()}]),a}(),Holder=/*#__PURE__*/function(){function a(b){(0,_classCallCheck2.default)(this,a),this.scatter=b}return(0,_createClass2.default)(a,[{key:"plugins",value:function e(){var a=this;if(!this.scatter.isExtension){for(var b=arguments.length,c=Array(b),d=0;d<b;d++)c[d]=arguments[d];c.map(function(b){return a.scatter.loadPlugin(b)})}}},{key:"connect",value:function b(){var a;return(a=this.scatter).connect.apply(a,arguments)}},{key:"catchAll",value:function a(){}}]),a}(),holder=new Proxy(new Holder(new Index()),{get:function c(a,b){return"undefined"==typeof a[b]?a.scatter[b]:a[b]}});holderFns.set=function(a){return holder.scatter=a},holderFns.get=function(){return holder.scatter},"undefined"!=typeof window&&(window.ScatterJS=holder),holder.Plugin=_Plugin.default,holder.PluginTypes=PluginTypes,holder.Blockchains=_Blockchains.Blockchains,holder.Network=_Network.default,holder.Token=_Token.default,holder.SocketService=_SocketService.default,holder.EVENTS=EVENTS,holder.WalletInterface=_WalletInterface.default,holder.WALLET_METHODS=_WalletInterface.WALLET_METHODS;var _default=holder;exports.default=_default;

@@ -1,1 +0,1 @@

"use strict";var _interopRequireWildcard=require("@babel/runtime/helpers/interopRequireWildcard"),_interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")),_createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass")),ErrorTypes=_interopRequireWildcard(require("./ErrorTypes")),ErrorCodes={NO_SIGNATURE:402,FORBIDDEN:403,TIMED_OUT:408,LOCKED:423,UPGRADE_REQUIRED:426,TOO_MANY_REQUESTS:429};Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.ErrorCodes=void 0;exports.ErrorCodes=ErrorCodes;var Error=/*#__PURE__*/function(){function a(b,c){var d=2<arguments.length&&void 0!==arguments[2]?arguments[2]:ErrorCodes.LOCKED;(0,_classCallCheck2.default)(this,a),this.type=b,this.message=c,this.code=d,this.isError=!0}return(0,_createClass2.default)(a,null,[{key:"locked",value:function locked(){return new a(ErrorTypes.LOCKED,"The user's Scatter is locked. They have been notified and should unlock before continuing.")}},{key:"maliciousEvent",value:function maliciousEvent(){return new a(ErrorTypes.MALICIOUS,"Malicious event discarded.",ErrorCodes.FORBIDDEN)}},{key:"signatureError",value:function signatureError(b,c){return new a(b,c,ErrorCodes.NO_SIGNATURE)}},{key:"requiresUpgrade",value:function requiresUpgrade(){return new a(ErrorTypes.UPGRADE_REQUIRED,"The required version is newer than the User's Scatter",ErrorCodes.UPGRADE_REQUIRED)}},{key:"noNetwork",value:function noNetwork(){return this.signatureError("no_network","You must bind a network first")}},{key:"usedKeyProvider",value:function usedKeyProvider(){return new a(ErrorTypes.MALICIOUS,"Do not use a `keyProvider` with a Scatter. Use a `signProvider` and return only signatures to this object. A malicious person could retrieve your keys otherwise.",ErrorCodes.NO_SIGNATURE)}}]),a}();exports.default=Error;
"use strict";var _interopRequireWildcard=require("@babel/runtime/helpers/interopRequireWildcard"),_interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.ErrorCodes=void 0;var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")),_createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass")),ErrorTypes=_interopRequireWildcard(require("./ErrorTypes")),ErrorCodes={NO_SIGNATURE:402,FORBIDDEN:403,TIMED_OUT:408,LOCKED:423,UPGRADE_REQUIRED:426,TOO_MANY_REQUESTS:429};exports.ErrorCodes=ErrorCodes;var Error=/*#__PURE__*/function(){function a(b,c){var d=2<arguments.length&&void 0!==arguments[2]?arguments[2]:ErrorCodes.LOCKED;(0,_classCallCheck2.default)(this,a),this.type=b,this.message=c,this.code=d,this.isError=!0}return(0,_createClass2.default)(a,null,[{key:"locked",value:function b(){return new a(ErrorTypes.LOCKED,"The user's Scatter is locked. They have been notified and should unlock before continuing.")}},{key:"maliciousEvent",value:function b(){return new a(ErrorTypes.MALICIOUS,"Malicious event discarded.",ErrorCodes.FORBIDDEN)}},{key:"signatureError",value:function d(b,c){return new a(b,c,ErrorCodes.NO_SIGNATURE)}},{key:"requiresUpgrade",value:function b(){return new a(ErrorTypes.UPGRADE_REQUIRED,"The required version is newer than the User's Scatter",ErrorCodes.UPGRADE_REQUIRED)}},{key:"noNetwork",value:function a(){return this.signatureError("no_network","You must bind a network first")}},{key:"usedKeyProvider",value:function b(){return new a(ErrorTypes.MALICIOUS,"Do not use a `keyProvider` with a Scatter. Use a `signProvider` and return only signatures to this object. A malicious person could retrieve your keys otherwise.",ErrorCodes.NO_SIGNATURE)}}]),a}();exports.default=Error;

@@ -1,1 +0,1 @@

"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")),_createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass")),_Blockchains=require("./Blockchains"),_Token=_interopRequireDefault(require("./Token")),Network=/*#__PURE__*/function(){function a(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"https",d=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"",e=3<arguments.length&&void 0!==arguments[3]?arguments[3]:0,f=4<arguments.length&&void 0!==arguments[4]?arguments[4]:_Blockchains.Blockchains.EOS,g=5<arguments.length&&void 0!==arguments[5]?arguments[5]:"";(0,_classCallCheck2.default)(this,a),this.name=b,this.protocol=c,this.host=d,this.port=e,this.blockchain=f,this.chainId=g.toString(),this.token=null}return(0,_createClass2.default)(a,[{key:"fullhost",value:function fullhost(){return"".concat(this.protocol,"://").concat(this.host).concat(this.port?":":"").concat(this.port)}}],[{key:"placeholder",value:function placeholder(){return new a}},{key:"fromJson",value:function fromJson(b){var c=Object.assign(a.placeholder(),b);return c.chainId=c.chainId?c.chainId.toString():"",c.token=b.hasOwnProperty("token")&&b.token?_Token.default.fromJson(b.token):null,c}}]),a}();Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;exports.default=Network;
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")),_createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass")),_Blockchains=require("./Blockchains"),_Token=_interopRequireDefault(require("./Token")),Network=/*#__PURE__*/function(){function a(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"https",d=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"",e=3<arguments.length&&void 0!==arguments[3]?arguments[3]:0,f=4<arguments.length&&void 0!==arguments[4]?arguments[4]:_Blockchains.Blockchains.EOS,g=5<arguments.length&&void 0!==arguments[5]?arguments[5]:"";(0,_classCallCheck2.default)(this,a),this.name=b,this.protocol=c,this.host=d,this.port=e,this.blockchain=f,this.chainId=g.toString(),this.token=null}return(0,_createClass2.default)(a,[{key:"fullhost",value:function a(){return"".concat(this.protocol,"://").concat(this.host).concat(this.port?":":"").concat(this.port)}}],[{key:"placeholder",value:function b(){return new a}},{key:"fromJson",value:function d(b){var c=Object.assign(a.placeholder(),b);return c.chainId=c.chainId?c.chainId.toString():"",c.token=b.hasOwnProperty("token")&&b.token?_Token.default.fromJson(b.token):null,c}}]),a}();exports.default=Network;

@@ -1,1 +0,1 @@

"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")),_createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass")),_PluginRepository=_interopRequireDefault(require("../plugins/PluginRepository")),_Blockchains=require("./Blockchains"),Token=/*#__PURE__*/function(){function a(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:_Blockchains.Blockchains.EOS,c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",d=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"",e=3<arguments.length&&void 0!==arguments[3]?arguments[3]:null,f=4<arguments.length&&void 0!==arguments[4]?arguments[4]:null;(0,_classCallCheck2.default)(this,a),this.blockchain=b,this.contract=c,this.symbol=d,this.name=e?e:d,this.decimals=f}return(0,_createClass2.default)(a,null,[{key:"placeholder",value:function placeholder(){return new a}},{key:"fromJson",value:function fromJson(a){return Object.assign(this.placeholder(),a)}}]),a}();Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;exports.default=Token;
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")),_createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass")),_Blockchains=require("./Blockchains"),Token=/*#__PURE__*/function(){function a(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:_Blockchains.Blockchains.EOS,c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"",d=2<arguments.length&&void 0!==arguments[2]?arguments[2]:"",e=3<arguments.length&&void 0!==arguments[3]?arguments[3]:null,f=4<arguments.length&&void 0!==arguments[4]?arguments[4]:null;(0,_classCallCheck2.default)(this,a),this.blockchain=b,this.contract=c,this.symbol=d,this.name=e?e:d,this.decimals=f}return(0,_createClass2.default)(a,null,[{key:"placeholder",value:function b(){return new a}},{key:"fromJson",value:function b(a){return Object.assign(this.placeholder(),a)}}]),a}();exports.default=Token;

@@ -1,1 +0,1 @@

"use strict";var _interopRequireWildcard=require("@babel/runtime/helpers/interopRequireWildcard"),_interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")),_createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass")),PluginTypes=_interopRequireWildcard(require("./PluginTypes")),Plugin=/*#__PURE__*/function(){function a(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"";(0,_classCallCheck2.default)(this,a),this.name=b,this.type=c}return(0,_createClass2.default)(a,[{key:"isSignatureProvider",value:function isSignatureProvider(){return this.type===PluginTypes.BLOCKCHAIN_SUPPORT}},{key:"isValid",value:function isValid(){return Object.keys(PluginTypes).map(function(a){return PluginTypes[a]}).includes(this.type)}}],[{key:"placeholder",value:function placeholder(){return new a}},{key:"fromJson",value:function fromJson(b){return Object.assign(a.placeholder(),b)}}]),a}();Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;exports.default=Plugin;
"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 _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")),_createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass")),PluginTypes=_interopRequireWildcard(require("./PluginTypes")),Plugin=/*#__PURE__*/function(){function a(){var b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"",c=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"";(0,_classCallCheck2.default)(this,a),this.name=b,this.type=c}return(0,_createClass2.default)(a,[{key:"isSignatureProvider",value:function a(){return this.type===PluginTypes.BLOCKCHAIN_SUPPORT}},{key:"isValid",value:function a(){return Object.keys(PluginTypes).map(function(a){return PluginTypes[a]}).includes(this.type)}}],[{key:"placeholder",value:function b(){return new a}},{key:"fromJson",value:function c(b){return Object.assign(a.placeholder(),b)}}]),a}();exports.default=Plugin;

@@ -1,1 +0,1 @@

"use strict";var _interopRequireWildcard=require("@babel/runtime/helpers/interopRequireWildcard"),_interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _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")),PluginTypes=_interopRequireWildcard(require("./PluginTypes")),PluginRepositorySingleton=/*#__PURE__*/function(){function a(){(0,_classCallCheck2.default)(this,a),this.plugins=[]}return(0,_createClass2.default)(a,[{key:"loadPlugin",value:function loadPlugin(a){this.plugin(a.name)||this.plugins.push(a)}},{key:"signatureProviders",value:function signatureProviders(){return this.plugins.filter(function(a){return a.type===PluginTypes.BLOCKCHAIN_SUPPORT})}},{key:"supportedBlockchains",value:function supportedBlockchains(){return this.signatureProviders().map(function(){return name})}},{key:"plugin",value:function plugin(a){return this.plugins.find(function(b){return b.name===a})}},{key:"endorsedNetworks",value:function(){var a=(0,_asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function a(){return _regenerator.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,Promise.all(this.signatureProviders().map(/*#__PURE__*/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:return a.next=2,b.getEndorsedNetwork();case 2:return a.abrupt("return",a.sent);case 3:case"end":return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}}()));case 2:return a.abrupt("return",a.sent);case 3:case"end":return a.stop();}},a,this)}));return function endorsedNetworks(){return a.apply(this,arguments)}}()}]),a}(),PluginRepository=new PluginRepositorySingleton,_default=PluginRepository;Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;exports.default=_default;
"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 _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")),PluginTypes=_interopRequireWildcard(require("./PluginTypes")),PluginRepositorySingleton=/*#__PURE__*/function(){function a(){(0,_classCallCheck2.default)(this,a),this.plugins=[]}return(0,_createClass2.default)(a,[{key:"loadPlugin",value:function b(a){this.plugin(a.name)||this.plugins.push(a)}},{key:"wallets",value:function a(){return this.plugins.filter(function(a){return a.type===PluginTypes.WALLET_SUPPORT})}},{key:"signatureProviders",value:function a(){return this.plugins.filter(function(a){return a.type===PluginTypes.BLOCKCHAIN_SUPPORT})}},{key:"supportedBlockchains",value:function a(){return this.signatureProviders().map(function(){return name})}},{key:"plugin",value:function b(a){return this.plugins.find(function(b){return b.name===a})}},{key:"endorsedNetworks",value:function(){var a=(0,_asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function a(){return _regenerator.default.wrap(function(a){for(;;)switch(a.prev=a.next){case 0:return a.next=2,Promise.all(this.signatureProviders().map(/*#__PURE__*/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:return a.next=2,b.getEndorsedNetwork();case 2:return a.abrupt("return",a.sent);case 3:case"end":return a.stop();}},a,this)}));return function(){return a.apply(this,arguments)}}()));case 2:return a.abrupt("return",a.sent);case 3:case"end":return a.stop();}},a,this)}));return function b(){return a.apply(this,arguments)}}()}]),a}(),PluginRepository=new PluginRepositorySingleton,_default=PluginRepository;exports.default=_default;

@@ -1,1 +0,1 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.BLOCKCHAIN_SUPPORT=void 0;var BLOCKCHAIN_SUPPORT="blockchain_support";exports.BLOCKCHAIN_SUPPORT="blockchain_support";
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.WALLET_SUPPORT=exports.BLOCKCHAIN_SUPPORT=void 0;var BLOCKCHAIN_SUPPORT="blockchain_support";exports.BLOCKCHAIN_SUPPORT="blockchain_support";var WALLET_SUPPORT="wallet_support";exports.WALLET_SUPPORT="wallet_support";

@@ -1,5 +0,5 @@

"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");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(){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();Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;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 init(a){var b=1<arguments.length&&void 0!==arguments[1]?arguments[1]:6e4;plugin=a,this.timeout=b}},{key:"addEventHandler",value:function addEventHandler(a,b){b||(b="app"),eventHandlers[b]=a}},{key:"removeEventHandler",value:function removeEventHandler(a){a||(a="app"),delete eventHandlers[a]}},{key:"link",value:function link(){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
"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 isConnected(){return connected}},{key:"isPaired",value:function isPaired(){return paired}},{key:"disconnect",value:function disconnect(){return socket&&socket.disconnect(),!0}},{key:"sendApiRequest",value:function sendApiRequest(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:"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;
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 _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")),_createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass")),storage={},getWindow=function(){return"undefined"==typeof window?{localStorage:{setItem:function setItem(a,b){return storage[a]=b},getItem:function getItem(a){return storage[a]||null},removeItem:function removeItem(a){return delete storage[a]}}}:window},StorageService=/*#__PURE__*/function(){function a(){(0,_classCallCheck2.default)(this,a)}return(0,_createClass2.default)(a,null,[{key:"setAppKey",value:function setAppKey(a){getWindow().localStorage.setItem("appkey",a)}},{key:"getAppKey",value:function getAppKey(){return getWindow().localStorage.getItem("appkey")}},{key:"removeAppKey",value:function removeAppKey(){return getWindow().localStorage.removeItem("appkey")}},{key:"setNonce",value:function setNonce(a){getWindow().localStorage.setItem("nonce",a)}},{key:"getNonce",value:function getNonce(){return getWindow().localStorage.getItem("nonce")}},{key:"removeNonce",value:function removeNonce(){return getWindow().localStorage.removeItem("nonce")}}]),a}();Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;exports.default=StorageService;
"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")),_createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass")),storage={},getWindow=function(){return"undefined"==typeof window?{localStorage:{setItem:function c(a,b){return storage[a]=b},getItem:function b(a){return storage[a]||null},removeItem:function b(a){return delete storage[a]}}}:window},StorageService=/*#__PURE__*/function(){function a(){(0,_classCallCheck2.default)(this,a)}return(0,_createClass2.default)(a,null,[{key:"setAppKey",value:function b(a){getWindow().localStorage.setItem("appkey",a)}},{key:"getAppKey",value:function a(){return getWindow().localStorage.getItem("appkey")}},{key:"removeAppKey",value:function a(){return getWindow().localStorage.removeItem("appkey")}},{key:"setNonce",value:function b(a){getWindow().localStorage.setItem("nonce",a)}},{key:"getNonce",value:function a(){return getWindow().localStorage.getItem("nonce")}},{key:"removeNonce",value:function a(){return getWindow().localStorage.removeItem("nonce")}}]),a}();exports.default=StorageService;
{
"name": "scatterjs-core",
"version": "2.6.0",
"version": "2.7.0",
"main": "dist/index.js",

@@ -13,3 +13,3 @@ "license": "MIT",

},
"gitHead": "72e8da397819e3d1200bb4eb0e67a74382fc60bb"
"gitHead": "b4155e3ae1fda4af6cabbb4f34c2606387c477e7"
}

@@ -7,269 +7,60 @@ import PluginRepository from './plugins/PluginRepository';

import Network from './models/Network';
import WalletInterface, {WALLET_METHODS} from './models/WalletInterface';
import Desktop from "./wallets/Desktop";
import Extension from "./wallets/Extension";
import Token from "./models/Token";
let origin;
const throwNoAuth = () => {
if(!holder.scatter.isExtension && !SocketService.isConnected())
throw new Error('Connect and Authenticate first - scatter.connect( pluginName )');
};
const checkForExtension = (resolve, tries = 0) => {
if(tries > 20) return;
if(holder.scatter.isExtension) return resolve(true);
setTimeout(() => checkForExtension(resolve, tries + 1), 100);
};
const EVENTS = {
Disconnected:'dced',
LoggedOut:'logout',
}
};
let socketService = SocketService;
let socketSetters = [];
let holderFns = {};
class Index {
constructor(){
this.isExtension = false;
this.identity = null;
}
constructor(){
this.identity = null;
this.network = null;
PluginRepository.loadPlugin(new Desktop(this, holderFns));
PluginRepository.loadPlugin(new Extension(this, holderFns));
}
loadPlugin(plugin){
const noIdFunc = () => { if(!this.identity) throw new Error('No Identity') };
if(!plugin.isValid()) throw new Error(`${plugin.name} doesn't seem to be a valid ScatterJS plugin.`);
if(!plugin.isValid()) throw new Error(`${plugin.name} doesn't seem to be a valid ScatterJS plugin.`);
PluginRepository.loadPlugin(plugin);
if(plugin.isSignatureProvider()){
this[plugin.name] = plugin.signatureProvider(noIdFunc, () => this.identity);
this[plugin.name+'Hook'] = plugin.hookProvider;
}
}
if(plugin.type === PluginTypes.BLOCKCHAIN_SUPPORT){
this[plugin.name] = plugin.signatureProvider(noIdFunc, () => this.identity);
this[plugin.name+'Hook'] = plugin.hookProvider;
socketSetters.push(plugin.setSocketService);
}
async connect(pluginName, options){
return new Promise(resolve => {
if(!pluginName || !pluginName.length) throw new Error("You must specify a name for this connection");
// Setting options defaults
options = Object.assign({initTimeout:10000, linkTimeout:30000}, options);
// Auto failer
setTimeout(() => {
resolve(false);
}, options.initTimeout);
// Defaults to scatter extension if exists
checkForExtension(resolve);
// Tries to set up Desktop Connection
SocketService.init(pluginName, options.linkTimeout);
SocketService.link().then(async authenticated => {
if(!authenticated) return false;
this.addEventHandler((t,x) => this.eventHandler(t,x), 'internal');
this.identity = await this.getIdentityFromPermissions();
return resolve(true);
});
})
}
disconnect(){
return SocketService.disconnect();
}
isConnected(){
return SocketService.isConnected();
}
isPaired(){
return SocketService.isPaired();
}
addEventHandler(handler, key = null){ SocketService.addEventHandler(handler, key); }
removeEventHandler(key = null){ SocketService.removeEventHandler(key); }
async eventHandler(event, payload){
switch(event){
case EVENTS.Disconnected:
this.identity = null;
break;
case EVENTS.LoggedOut:
this.identity = await this.getIdentityFromPermissions();
break;
if(plugin.type === PluginTypes.WALLET_SUPPORT){
plugin.init(this, holderFns, socketSetters);
}
}
getVersion(){
return SocketService.sendApiRequest({
type:'getVersion',
payload:{}
});
}
async connect(pluginName, options){
if(!options) options = {};
this.network = options.hasOwnProperty('network') ? options.network : null;
listen(handler){
SocketService.addEventHandler(handler);
}
const wallets = PluginRepository.wallets();
return await Promise.race(wallets.map(wallet => {
return wallet.connect(pluginName, options).then(async () => {
if(typeof wallet.runBeforeInterfacing === 'function') await wallet.runBeforeInterfacing();
new WalletInterface(wallet.name, wallet.methods(), holderFns.get());
if(typeof wallet.runAfterInterfacing === 'function') await wallet.runAfterInterfacing();
WalletInterface.bindBasics(holderFns.get());
return true;
})
}).concat(new Promise(r => setTimeout(() => r(false), options.initTimeout || 5000))));
/***
* Logs a user into your application
* @param requiredFields
* @returns {Promise<any>}
*/
login(requiredFields){
throwNoAuth();
return SocketService.sendApiRequest({
type:'getOrRequestIdentity',
payload:{
fields:requiredFields
}
}).then(id => {
if(id) this.identity = id;
return id;
});
}
/***
* Check is a user is logged in by tapping
* their Scatter, but does not issue a popup
* @returns {Promise<any>}
*/
checkLogin(){
throwNoAuth();
return SocketService.sendApiRequest({
type:'identityFromPermissions',
payload:{}
}).then(id => {
if(id) this.identity = id;
return id;
});
}
/***
* Logs a user out of your application.
* @returns {Promise<any>}
*/
logout(){
throwNoAuth();
return SocketService.sendApiRequest({
type:'forgetIdentity',
payload:{}
}).then(res => {
this.identity = null;
return res;
});
}
/***
* Authenticates a user's login using
* asymmetric encryption.
* @param nonce
* @param data - Optional data to sign ( fallback to appkey/origin )
* @param publicKey - Optional key to use ( fallback to identity key )
*/
authenticate(nonce, data = null, publicKey = null){
throwNoAuth();
return SocketService.sendApiRequest({
type:'authenticate',
payload:{ nonce, data, publicKey }
});
}
getArbitrarySignature(publicKey, data){
throwNoAuth();
return SocketService.sendApiRequest({
type:'requestArbitrarySignature',
payload:{
publicKey,
data
}
});
}
getPublicKey(blockchain){
throwNoAuth();
return SocketService.sendApiRequest({
type:'getPublicKey',
payload:{ blockchain }
});
}
linkAccount(account, network){
throwNoAuth();
return SocketService.sendApiRequest({
type:'linkAccount',
payload:{ account, network }
});
}
hasAccountFor(network){
throwNoAuth();
return SocketService.sendApiRequest({
type:'hasAccountFor',
payload:{
network
}
});
}
suggestNetwork(network){
throwNoAuth();
return SocketService.sendApiRequest({
type:'requestAddNetwork',
payload:{
network
}
});
}
requestTransfer(network, to, amount, options = {}){
const payload = {network, to, amount, options};
return SocketService.sendApiRequest({
type:'requestTransfer',
payload
});
}
requestSignature(payload){
throwNoAuth();
return SocketService.sendApiRequest({
type:'requestSignature',
payload
});
}
createTransaction(blockchain, actions, account, network){
throwNoAuth();
return SocketService.sendApiRequest({
type:'createTransaction',
payload:{
blockchain,
actions,
account,
network
}
});
}
/******************************/
/******** DEPRECATED **********/
/******************************/
// @deprecated - Use `login(requiredFields)`
getIdentity(requiredFields){
return this.login(requiredFields);
}
// @deprecated - Use `checkLogin()`
getIdentityFromPermissions(){
return this.checkLogin();
}
// @deprecated - Use `logout()`
forgetIdentity(){
return this.logout();
}
}

@@ -288,23 +79,24 @@

}
}
connect(...params){
return this.scatter.connect(...params);
}
let holder = new Holder(new Index());
if(typeof window !== 'undefined') {
catchAll(...params){
// Catching extension instead of Desktop
if(typeof document !== 'undefined'){
const bindScatterClassic = () => {
holder.scatter = window.scatter;
holder.scatter.isExtension = true;
holder.scatter.connect = () => new Promise(resolve => resolve(true));
};
}
}
if(typeof window.scatter !== 'undefined') bindScatterClassic();
else document.addEventListener('scatterLoaded', () => bindScatterClassic());
}
window.ScatterJS = holder;
}
let holder = new Proxy(new Holder(new Index()), {
get(target,name) {
if(typeof target[name] !== 'undefined') return target[name];
return target.scatter[name];
}
});
holderFns.set = s => holder.scatter = s;
holderFns.get = () => holder.scatter;
if(typeof window !== 'undefined') window.ScatterJS = holder;
holder.Plugin = Plugin;

@@ -314,7 +106,10 @@ holder.PluginTypes = PluginTypes;

holder.Network = Network;
holder.Token = Token;
holder.SocketService = SocketService;
holder.EVENTS = EVENTS;
export {Plugin, PluginTypes, Blockchains, Network, SocketService, EVENTS};
holder.WalletInterface = WalletInterface;
holder.WALLET_METHODS = WALLET_METHODS;
export {Plugin, PluginTypes, Blockchains, Network, SocketService, EVENTS, WalletInterface, WALLET_METHODS};
export default holder;

@@ -1,2 +0,1 @@

import PluginRepository from "../plugins/PluginRepository";
import {Blockchains} from "./Blockchains";

@@ -3,0 +2,0 @@

@@ -19,2 +19,6 @@ import * as PluginTypes from './PluginTypes';

wallets(){
return this.plugins.filter(plugin => plugin.type === PluginTypes.WALLET_SUPPORT);
}
signatureProviders(){

@@ -21,0 +25,0 @@ return this.plugins.filter(plugin => plugin.type === PluginTypes.BLOCKCHAIN_SUPPORT);

@@ -1,1 +0,2 @@

export const BLOCKCHAIN_SUPPORT = 'blockchain_support';
export const BLOCKCHAIN_SUPPORT = 'blockchain_support';
export const WALLET_SUPPORT = 'wallet_support';

@@ -68,2 +68,6 @@ import StorageService from './StorageService'

static getOrigin(){
return getOrigin();
}
static addEventHandler(handler, key){

@@ -110,2 +114,3 @@ if(!key) key = 'app';

const msg_paired = result => {

@@ -112,0 +117,0 @@ paired = result;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc