scatterjs-plugin-eosjs
Advanced tools
Comparing version 1.1.0 to 1.1.1
@@ -1,109 +0,9 @@ | ||
import { Plugin, PluginTypes, Blockchains, Network, SocketService } from 'scatterjs-core'; | ||
const proxy = (dummy, handler) => new Proxy(dummy, handler); | ||
export default class ScatterEOS extends Plugin { | ||
constructor() { | ||
super(Blockchains.EOS, PluginTypes.BLOCKCHAIN_SUPPORT); | ||
} | ||
signatureProvider(...args) { | ||
const throwIfNoIdentity = args[0]; // Protocol will be deprecated. | ||
return (network, _eos, _options = {}) => { | ||
network = Network.fromJson(network); | ||
if (!network.isValid()) throw Error.noNetwork(); | ||
const httpEndpoint = `${network.protocol}://${network.hostport()}`; | ||
const chainId = network.hasOwnProperty('chainId') && network.chainId.length ? network.chainId : _options.chainId; // The proxy stands between the eosjs object and scatter. | ||
// This is used to add special functionality like adding `requiredFields` arrays to transactions | ||
return proxy(_eos({ | ||
httpEndpoint, | ||
chainId | ||
}), { | ||
get(eosInstance, method) { | ||
let returnedFields = null; | ||
return (...args) => { | ||
if (args.find(arg => arg.hasOwnProperty('keyProvider'))) throw Error.usedKeyProvider(); // The signature provider which gets elevated into the user's Scatter | ||
const signProvider = async signargs => { | ||
throwIfNoIdentity(); | ||
const requiredFields = args.find(arg => arg.hasOwnProperty('requiredFields')) || { | ||
requiredFields: {} | ||
}; | ||
const payload = Object.assign(signargs, { | ||
blockchain: Blockchains.EOS, | ||
network, | ||
requiredFields: requiredFields.requiredFields | ||
}); | ||
const result = await SocketService.sendApiRequest({ | ||
type: 'requestSignature', | ||
payload | ||
}); // No signature | ||
if (!result) return null; | ||
if (result.hasOwnProperty('signatures')) { | ||
// Holding onto the returned fields for the final result | ||
returnedFields = result.returnedFields; // Grabbing buf signatures from local multi sig sign provider | ||
let multiSigKeyProvider = args.find(arg => arg.hasOwnProperty('signProvider')); | ||
if (multiSigKeyProvider) { | ||
result.signatures.push(multiSigKeyProvider.signProvider(signargs.buf, signargs.sign)); | ||
} // Returning only the signatures to eosjs | ||
return result.signatures; | ||
} | ||
return result; | ||
}; // TODO: We need to check about the implications of multiple eosjs instances | ||
return new Promise((resolve, reject) => { | ||
_eos(Object.assign(_options, { | ||
httpEndpoint, | ||
signProvider, | ||
chainId | ||
}))[method](...args).then(result => { | ||
// Standard method ( ie. not contract ) | ||
if (!result.hasOwnProperty('fc')) { | ||
result = Object.assign(result, { | ||
returnedFields | ||
}); | ||
resolve(result); | ||
return; | ||
} // Catching chained promise methods ( contract .then action ) | ||
const contractProxy = proxy(result, { | ||
get(instance, method) { | ||
if (method === 'then') return instance[method]; | ||
return (...args) => { | ||
return new Promise(async (res, rej) => { | ||
instance[method](...args).then(actionResult => { | ||
res(Object.assign(actionResult, { | ||
returnedFields | ||
})); | ||
}).catch(rej); | ||
}); | ||
}; | ||
} | ||
}); | ||
resolve(contractProxy); | ||
}).catch(error => reject(error)); | ||
}); | ||
}; | ||
} | ||
}); // Proxy | ||
}; | ||
} | ||
} | ||
if (typeof window !== 'undefined') { | ||
window.ScatterEOS = ScatterEOS; | ||
} | ||
"use strict";var _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")),_possibleConstructorReturn2=_interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")),_getPrototypeOf2=_interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")),_inherits2=_interopRequireDefault(require("@babel/runtime/helpers/inherits")),_scatterjsCore=require("scatterjs-core"),proxy=function(a,b){return new Proxy(a,b)},ScatterEOS=/*#__PURE__*/function(a){function b(){return(0,_classCallCheck2.default)(this,b),(0,_possibleConstructorReturn2.default)(this,(0,_getPrototypeOf2.default)(b).call(this,_scatterjsCore.Blockchains.EOS,_scatterjsCore.PluginTypes.BLOCKCHAIN_SUPPORT))}return(0,_inherits2.default)(b,a),(0,_createClass2.default)(b,[{key:"signatureProvider",value:function signatureProvider(){var a=0>=arguments.length?void 0:arguments[0];// Protocol will be deprecated. | ||
return function(b,c){var d=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};if(b=_scatterjsCore.Network.fromJson(b),!b.isValid())throw Error.noNetwork();var e="".concat(b.protocol,"://").concat(b.hostport()),f=b.hasOwnProperty("chainId")&&b.chainId.length?b.chainId:d.chainId;// The proxy stands between the eosjs object and scatter. | ||
// This is used to add special functionality like adding `requiredFields` arrays to transactions | ||
return proxy(c({httpEndpoint:e,chainId:f}),{get:function get(g,h){var i=null;return function(){for(var g=arguments.length,j=Array(g),k=0;k<g;k++)j[k]=arguments[k];if(j.find(function(a){return a.hasOwnProperty("keyProvider")}))throw Error.usedKeyProvider();// The signature provider which gets elevated into the user's Scatter | ||
var l=/*#__PURE__*/function(){var c=(0,_asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function c(d){var e,f,g,h;return _regenerator.default.wrap(function(c){for(;;)switch(c.prev=c.next){case 0:return a(),e=j.find(function(a){return a.hasOwnProperty("requiredFields")})||{requiredFields:{}},f=Object.assign(d,{blockchain:_scatterjsCore.Blockchains.EOS,network:b,requiredFields:e.requiredFields}),c.next=5,_scatterjsCore.SocketService.sendApiRequest({type:"requestSignature",payload:f});case 5:if(g=c.sent,g){c.next=8;break}return c.abrupt("return",null);case 8:if(!g.hasOwnProperty("signatures")){c.next=13;break}return i=g.returnedFields,h=j.find(function(a){return a.hasOwnProperty("signProvider")}),h&&g.signatures.push(h.signProvider(d.buf,d.sign)),c.abrupt("return",g.signatures);case 13:return c.abrupt("return",g);case 14:case"end":return c.stop();}},c,this)}));return function(){return c.apply(this,arguments)}}();// TODO: We need to check about the implications of multiple eosjs instances | ||
return new Promise(function(a,b){var g;(g=c(Object.assign(d,{httpEndpoint:e,signProvider:l,chainId:f})))[h].apply(g,j).then(function(b){// Standard method ( ie. not contract ) | ||
if(!b.hasOwnProperty("fc"))return b=Object.assign(b,{returnedFields:i}),void a(b);// Catching chained promise methods ( contract .then action ) | ||
var c=proxy(b,{get:function get(a,b){return"then"===b?a[b]:function(){for(var c=arguments.length,d=Array(c),e=0;e<c;e++)d[e]=arguments[e];return new Promise(/*#__PURE__*/function(){var c=(0,_asyncToGenerator2.default)(/*#__PURE__*/_regenerator.default.mark(function c(e,f){return _regenerator.default.wrap(function(c){for(;;)switch(c.prev=c.next){case 0:a[b].apply(a,d).then(function(a){e(Object.assign(a,{returnedFields:i}))}).catch(f);case 1:case"end":return c.stop();}},c,this)}));return function(){return c.apply(this,arguments)}}())}}});a(c)}).catch(function(a){return b(a)})})}}});// Proxy | ||
}}}]),b}(_scatterjsCore.Plugin);Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;exports.default=ScatterEOS,"undefined"!=typeof window&&(window.ScatterEOS=ScatterEOS); |
{ | ||
"name": "scatterjs-plugin-eosjs", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"main": "dist/index.js", | ||
@@ -9,3 +9,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "4772f85f3b41e162293463965ad51a48c976bcb2" | ||
"gitHead": "4f1ef7480d04b514619c41ca38210d991ae797ff" | ||
} |
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
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
9442
5
105
2