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
64 lines (21 loc) • 1.91 kB
JavaScript
;Object.defineProperty(exports, "__esModule", { value: true });exports.
toParamType = toParamType;exports.
fromParamType = fromParamType;var _paramType = require('./paramType');var _paramType2 = _interopRequireDefault(_paramType);function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function toParamType(type) {if (type[type.length - 1] === ']') {var last = type.lastIndexOf('[');var length = type.substr(last + 1, type.length - last - 2);var subtype = toParamType(type.substr(0, last));if (length.length === 0) {return new _paramType2.default('array', subtype);}return new _paramType2.default('fixedArray', subtype, parseInt(length, 10));}switch (type) {case 'address':case 'bool':case 'bytes':case 'string':return new _paramType2.default(type);case 'int':case 'uint':return new _paramType2.default(type, null, 256);default:if (type.indexOf('uint') === 0) {return new _paramType2.default('uint', null, parseInt(type.substr(4), 10));} else if (type.indexOf('int') === 0) {return new _paramType2.default('int', null, parseInt(type.substr(3), 10));} else if (type.indexOf('bytes') === 0) {return new _paramType2.default('fixedBytes', null, parseInt(type.substr(5), 10));}throw new Error('Cannot convert ' + type + ' to valid ParamType');}}function fromParamType(paramType) {
switch (paramType.type) {
case 'address':
case 'bool':
case 'bytes':
case 'string':
return paramType.type;
case 'int':
case 'uint':
return '' + paramType.type + paramType.length;
case 'fixedBytes':
return 'bytes' + paramType.length;
case 'fixedArray':
return fromParamType(paramType.subtype) + '[' + paramType.length + ']';
case 'array':
return fromParamType(paramType.subtype) + '[]';
default:
throw new Error('Cannot convert from ParamType ' + paramType.type);}
}