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

54 lines (13 loc) 1.71 kB
'use strict';Object.defineProperty(exports, "__esModule", { value: true });exports. padAddress = padAddress;exports. padBool = padBool;exports. padU32 = padU32;exports. padBytes = padBytes;exports. padFixedBytes = padFixedBytes;exports. padString = padString;var _bignumber = require('bignumber.js');var _bignumber2 = _interopRequireDefault(_bignumber);var _utf = require('utf8');var _utf2 = _interopRequireDefault(_utf);var _types = require('./types');function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}var ZERO_64 = '0000000000000000000000000000000000000000000000000000000000000000';function padAddress(input) {return ('' + ZERO_64 + input).slice(-64);}function padBool(input) {return ('' + ZERO_64 + (input ? '1' : '0')).slice(-64);}function padU32(input) {var bn = new _bignumber2.default(input);if (bn.lessThan(0)) {bn = new _bignumber2.default('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 16).plus(bn).plus(1);}return ('' + ZERO_64 + bn.toString(16)).slice(-64);}function padBytes(input) {var length = (0, _types.isArray)(input) ? input.length : ('' + input).length / 2;return '' + padU32(length) + padFixedBytes(input);}function padFixedBytes(input) {var sinput = void 0;if ((0, _types.isArray)(input)) {sinput = input.map(function (code) {return code.toString(16);}).join('');} else {sinput = '' + input;}var max = Math.floor((sinput.length + 63) / 64) * 64;return ('' + sinput + ZERO_64).substr(0, max);}function padString(input) { var encoded = _utf2.default.encode(input). split(''). map(function (char) {return char.charCodeAt(0).toString(16);}). join(''); return padBytes(encoded); }