UNPKG

ethereum-web-token

Version:

EWT bundles Ethereum function-calls into [JWT](https://jwt.io/)-like tokens. It simplifies the use of ECDSA signatures for webapps and the development of [Smart Oracles](https://github.com/codius/codius/wiki/Smart-Oracles:-A-Simple,-Powerful-Approach-to-S

49 lines (24 loc) 2.14 kB
'use strict';Object.defineProperty(exports, "__esModule", { value: true });var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);var _createClass2 = require('babel-runtime/helpers/createClass');var _createClass3 = _interopRequireDefault(_createClass2);var _decoder = require('../decoder/decoder');var _decoder2 = _interopRequireDefault(_decoder); var _encoder = require('../encoder/encoder');var _encoder2 = _interopRequireDefault(_encoder); var _param = require('./param');var _param2 = _interopRequireDefault(_param); var _sig = require('../util/sig');function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}var Func = function () { function Func(abi) {(0, _classCallCheck3.default)(this, Func); this._name = abi.name; this._constant = !!abi.constant; this._inputs = _param2.default.toParams(abi.inputs || []); this._outputs = _param2.default.toParams(abi.outputs || []); this._signature = (0, _sig.methodSignature)(this._name, this.inputParamTypes()); }(0, _createClass3.default)(Func, [{ key: 'inputParamTypes', value: function inputParamTypes() { return this._inputs.map(function (input) {return input.kind;}); } }, { key: 'outputParamTypes', value: function outputParamTypes() { return this._outputs.map(function (output) {return output.kind;}); } }, { key: 'encodeCall', value: function encodeCall( tokens) { return '' + this._signature + _encoder2.default.encode(tokens); } }, { key: 'decodeOutput', value: function decodeOutput( data) { return _decoder2.default.decode(this.outputParamTypes(), data); } }, { key: 'constant', get: function get() {return this._constant;} }, { key: 'name', get: function get() {return this._name;} }, { key: 'inputs', get: function get() {return this._inputs;} }, { key: 'outputs', get: function get() {return this._outputs;} }, { key: 'signature', get: function get() {return this._signature;} }]);return Func;}();exports.default = Func;module.exports = exports['default'];