diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..03abf45 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,5 @@ +node_modules +.vscode +package.json +dist +.nyc_output \ No newline at end of file diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..9532646 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "tabWidth": 2, + "semi": false, + "singleQuote": true, + "trailingComma": "all" +} \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index f673af2..82b2b82 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,14 +1,15 @@ # Changelog + All notable changes to this project will be documented in this file. -The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) -(modification: no type change headlines) and this project adheres to +The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) +(modification: no type change headlines) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). - ## [v2.1.0] - 2018-06-28 + - Updated supported Node versions, PR [#13](https://github.com/ethereumjs/rlp/pull/13) -- Switched to ``safe-buffer`` for backwards compatibility, PR [#18](https://github.com/ethereumjs/rlp/pull/18) +- Switched to `safe-buffer` for backwards compatibility, PR [#18](https://github.com/ethereumjs/rlp/pull/18) - Increased test coverage, PR [#22](https://github.com/ethereumjs/rlp/pull/22) - Example code tweaks, PR [#12](https://github.com/ethereumjs/rlp/pull/12) - Fix test runs on Windows, Issue [#7](https://github.com/ethereumjs/rlp/issues/7) @@ -17,33 +18,39 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) [v2.1.0]: https://github.com/ethereumjs/rlp/compare/2.0.0...v2.1.0 ## [2.0.0] - 2015-09-23 -- User ``Buffer`` values as input for encoding + +- User `Buffer` values as input for encoding [2.0.0]: https://github.com/ethereumjs/rlp/compare/1.1.2...2.0.0 ## [1.1.2] - 2015-09-22 + - Fix zero encoding [1.1.2]: https://github.com/ethereumjs/rlp/compare/1.1.1...1.1.2 ## [1.1.1] - 2015-09-21 -- Fixes for ``bin`` + +- Fixes for `bin` [1.1.1]: https://github.com/ethereumjs/rlp/compare/1.1.0...1.1.1 ## [1.1.0] - 2015-09-21 -- Added ``getLength()`` method -- Added hex prefix stripping (``isHexPrefix()`` / ``stripHexPrefix()``) + +- Added `getLength()` method +- Added hex prefix stripping (`isHexPrefix()` / `stripHexPrefix()`) - Code formatting clean-ups [1.1.0]: https://github.com/ethereumjs/rlp/compare/1.0.1...1.1.0 ## [1.0.1] - 2015-06-27 + - Code formatting clean-ups [1.0.1]: https://github.com/ethereumjs/rlp/compare/1.0.0...1.0.1 ## [1.0.0] - 2015-06-06 + - Added check for invalid 0 - Hardened rlp @@ -53,4 +60,4 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) - [0.0.14](https://github.com/ethereumjs/rlp/compare/0.0.13...0.0.14) - 2015-03-31 - [0.0.13](https://github.com/ethereumjs/rlp/compare/0.0.12...0.0.13) - 2015-03-30 -- [0.0.12](https://github.com/ethereumjs/rlp/compare/0.0.11...0.0.12) - 2014-12-26 \ No newline at end of file +- [0.0.12](https://github.com/ethereumjs/rlp/compare/0.0.11...0.0.12) - 2014-12-26 diff --git a/README.md b/README.md index c6560e1..c928b61 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -SYNOPSIS -===== +# SYNOPSIS + [![NPM Package](https://img.shields.io/npm/v/rlp.svg?style=flat-square)](https://www.npmjs.org/package/rlp) [![Build Status](https://img.shields.io/travis/ethereumjs/rlp.svg?branch=master&style=flat-square)](https://travis-ci.org/ethereumjs/rlp) [![Coverage Status](https://img.shields.io/coveralls/ethereumjs/rlp.svg?style=flat-square)](https://coveralls.io/r/ethereumjs/rlp) @@ -7,47 +7,43 @@ SYNOPSIS [![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard) - [Recursive Length](https://github.com/ethereum/wiki/wiki/RLP) Prefix Encoding for node.js. -INSTALL -====== -`npm install rlp` +# INSTALL + +`npm install rlp` install with `-g` if you want to use the cli. -USAGE -======= +# USAGE ```javascript -var RLP = require('rlp'); -var assert = require('assert'); - -var nestedList = [ [], [[]], [ [], [[]] ] ]; -var encoded = RLP.encode(nestedList); -var decoded = RLP.decode(encoded); -assert.deepEqual(nestedList, decoded); - +var RLP = require('rlp') +var assert = require('assert') +var nestedList = [[], [[]], [[], [[]]]] +var encoded = RLP.encode(nestedList) +var decoded = RLP.decode(encoded) +assert.deepEqual(nestedList, decoded) ``` -API -===== +# API + `rlp.encode(plain)` - RLP encodes an `Array`, `Buffer` or `String` and returns a `Buffer`. `rlp.decode(encoded, [skipRemainderCheck=false])` - Decodes an RLP encoded `Buffer`, `Array` or `String` and returns a `Buffer` or an `Array` of `Buffers`. If `skipRemainderCheck` is enabled, `rlp` will just decode the first rlp sequence in the buffer. By default, it would throw an error if there are more bytes in Buffer than used by rlp sequence. -CLI -=== -`rlp decode ` -`rlp encode ` +# CLI + +`rlp decode ` +`rlp encode ` + +# TESTS + +Test uses mocha. To run tests and linting: `npm test`. To auto fix linting problems use: `npm run test:fix`. -TESTS -===== -Test uses mocha. To run `npm test` +# CODE COVERAGE -CODE COVERAGE -============= Install dev dependencies `npm install` diff --git a/package.json b/package.json index caa4f90..43d43dc 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,15 @@ "build": "tsc", "coverage": "nyc mocha --reporter spec --require ts-node/register 'test/index.ts'", "coveralls": "npm run coverage && nyc report --reporter=text-lcov | coveralls", - "lint": "standard", - "test": "mocha --reporter spec --require ts-node/register 'test/index.ts'", + "format": "prettier --list-different '**/*.{ts,json,md,gql}'", + "format:fix": "prettier --write '**/*.{ts,json,md,gql}'", + "tslint": "tslint -p ./tsconfig.json -e 'node_modules/**/*' -e '**/node_modules/**/*' -e 'dist/**/*' '**/*.ts'", + "tslint:fix": "tslint --fix --format stylish -p ./tsconfig.json -e 'node_modules/**/*' -e '**/node_modules/**/*' -e 'dist/**/*' '**/*.ts'", + "tsc": "tsc --noEmit", + "lint": "yarn format && yarn tslint && yarn tsc", + "lint:fix": "yarn format:fix && yarn tslint:fix && yarn tsc", + "test": "yarn lint && mocha --reporter spec --require ts-node/register 'test/index.ts'", + "test:fix": "yarn lint:fix && mocha --reporter spec --require ts-node/register 'test/index.ts'", "webtest": "browserify test/max.js | testling -u" }, "repository": { @@ -42,13 +49,15 @@ "@types/mocha": "^5.2.5", "@types/node": "^10.12.2", "bn.js": "^4.11.1", - "nyc": "^13.1.0", "coveralls": "^2.11.4", "ethereumjs-testing": "git+https://github.com/ethereumjs/ethereumjs-testing.git", "mocha": "4.1.0", - "standard": "^6.0.8", + "nyc": "^13.1.0", + "prettier": "^1.15.2", "ts-node": "^7.0.1", - "typescript": "^3.1.6" + "tslint": "^5.11.0", + "typescript": "^3.1.6", + "typestrict": "^1.0.1" }, "bin": { "rlp": "./bin/rlp" @@ -65,11 +74,5 @@ "ipad/6", "android-browser/latest" ] - }, - "standard": { - "globals": [ - "describe", - "it" - ] } } diff --git a/src/index.ts b/src/index.ts index d20a847..4a09625 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ -import { RLPInput, RLPDecoded } from "./types"; -import BN from 'bn.js'; +import { RLPInput, RLPDecoded } from './types' +import BN from 'bn.js' /** * RLP Encoding based on: https://github.com/ethereum/wiki/wiki/%5BEnglish%5D-RLP @@ -9,17 +9,17 @@ import BN from 'bn.js'; **/ export function encode(input: RLPInput): Buffer { if (input instanceof Array) { - const output: Buffer[] = []; + const output: Buffer[] = [] for (let i = 0; i < input.length; i++) { - output.push(encode(input[i])); + output.push(encode(input[i])) } - const buf = Buffer.concat(output); - return Buffer.concat([encodeLength(buf.length, 192), buf]); + const buf = Buffer.concat(output) + return Buffer.concat([encodeLength(buf.length, 192), buf]) } else { - const inputBuf = toBuffer(input); + const inputBuf = toBuffer(input) return inputBuf.length === 1 && inputBuf[0] < 128 ? inputBuf - : Buffer.concat([encodeLength(inputBuf.length, 128), inputBuf]); + : Buffer.concat([encodeLength(inputBuf.length, 128), inputBuf]) } } @@ -29,21 +29,21 @@ export function encode(input: RLPInput): Buffer { * @param base The base to parse the integer into */ function safeParseInt(v: string, base: number): number { - if (v.slice(0, 2) === "00") { - throw new Error("invalid RLP: extra zeros"); + if (v.slice(0, 2) === '00') { + throw new Error('invalid RLP: extra zeros') } - return parseInt(v, base); + return parseInt(v, base) } function encodeLength(len: number, offset: number): Buffer { if (len < 56) { - return Buffer.from([len + offset]); + return Buffer.from([len + offset]) } else { - const hexLength = intToHex(len); - const lLength = hexLength.length / 2; - const firstByte = intToHex(offset + 55 + lLength); - return Buffer.from(firstByte + hexLength, "hex"); + const hexLength = intToHex(len) + const lLength = hexLength.length / 2 + const firstByte = intToHex(offset + 55 + lLength) + return Buffer.from(firstByte + hexLength, 'hex') } } @@ -53,24 +53,27 @@ function encodeLength(len: number, offset: number): Buffer { * @param stream - Is the input a stream (false by default) * @returns - returns decode Array of Buffers containg the original message **/ -export function decode(input: Buffer, stream?: boolean): Buffer; -export function decode(input: Buffer[], stream?: boolean): Buffer[]; -export function decode(input: RLPInput, stream: boolean = false): Buffer[] | Buffer | RLPDecoded { +export function decode(input: Buffer, stream?: boolean): Buffer +export function decode(input: Buffer[], stream?: boolean): Buffer[] +export function decode( + input: RLPInput, + stream: boolean = false, +): Buffer[] | Buffer | RLPDecoded { if (!input || (input).length === 0) { - return Buffer.from([]); + return Buffer.from([]) } - const inputBuffer = toBuffer(input); - const decoded = _decode(inputBuffer); + const inputBuffer = toBuffer(input) + const decoded = _decode(inputBuffer) if (stream) { - return decoded; + return decoded } if (decoded.remainder.length !== 0) { - throw new Error("invalid remainder"); + throw new Error('invalid remainder') } - return decoded.data; + return decoded.data } /** @@ -80,144 +83,144 @@ export function decode(input: RLPInput, stream: boolean = false): Buffer[] | Buf */ export function getLength(input: RLPInput): Buffer | number { if (!input || (input).length === 0) { - return Buffer.from([]); + return Buffer.from([]) } - const inputBuffer = toBuffer(input); - const firstByte = inputBuffer[0]; + const inputBuffer = toBuffer(input) + const firstByte = inputBuffer[0] if (firstByte <= 0x7f) { - return inputBuffer.length; + return inputBuffer.length } else if (firstByte <= 0xb7) { - return firstByte - 0x7f; + return firstByte - 0x7f } else if (firstByte <= 0xbf) { - return firstByte - 0xb6; + return firstByte - 0xb6 } else if (firstByte <= 0xf7) { // a list between 0-55 bytes long - return firstByte - 0xbf; + return firstByte - 0xbf } else { // a list over 55 bytes long - const llength = firstByte - 0xf6; + const llength = firstByte - 0xf6 const length = safeParseInt( - inputBuffer.slice(1, llength).toString("hex"), - 16 - ); - return llength + length; + inputBuffer.slice(1, llength).toString('hex'), + 16, + ) + return llength + length } } /** Decode an input with RLP */ function _decode(input: Buffer): RLPDecoded { - var length, llength, data, innerRemainder, d; - var decoded = []; - var firstByte = input[0]; + let length, llength, data, innerRemainder, d + const decoded = [] + const firstByte = input[0] if (firstByte <= 0x7f) { // a single byte whose value is in the [0x00, 0x7f] range, that byte is its own RLP encoding. return { data: input.slice(0, 1), - remainder: input.slice(1) - }; + remainder: input.slice(1), + } } else if (firstByte <= 0xb7) { // string is 0-55 bytes long. A single byte with value 0x80 plus the length of the string followed by the string // The range of the first byte is [0x80, 0xb7] - length = firstByte - 0x7f; + length = firstByte - 0x7f // set 0x80 null to 0 if (firstByte === 0x80) { - data = Buffer.from([]); + data = Buffer.from([]) } else { - data = input.slice(1, length); + data = input.slice(1, length) } if (length === 2 && data[0] < 0x80) { - throw new Error("invalid rlp encoding: byte must be less 0x80"); + throw new Error('invalid rlp encoding: byte must be less 0x80') } return { data: data, - remainder: input.slice(length) - }; + remainder: input.slice(length), + } } else if (firstByte <= 0xbf) { - llength = firstByte - 0xb6; - length = safeParseInt(input.slice(1, llength).toString("hex"), 16); - data = input.slice(llength, length + llength); + llength = firstByte - 0xb6 + length = safeParseInt(input.slice(1, llength).toString('hex'), 16) + data = input.slice(llength, length + llength) if (data.length < length) { - throw new Error("invalid RLP"); + throw new Error('invalid RLP') } return { data: data, - remainder: input.slice(length + llength) - }; + remainder: input.slice(length + llength), + } } else if (firstByte <= 0xf7) { // a list between 0-55 bytes long - length = firstByte - 0xbf; - innerRemainder = input.slice(1, length); + length = firstByte - 0xbf + innerRemainder = input.slice(1, length) while (innerRemainder.length) { - d = _decode(innerRemainder); - decoded.push(d.data as Buffer); - innerRemainder = d.remainder; + d = _decode(innerRemainder) + decoded.push(d.data as Buffer) + innerRemainder = d.remainder } return { data: decoded, - remainder: input.slice(length) - }; + remainder: input.slice(length), + } } else { // a list over 55 bytes long - llength = firstByte - 0xf6; - length = safeParseInt(input.slice(1, llength).toString("hex"), 16); - const totalLength = llength + length; + llength = firstByte - 0xf6 + length = safeParseInt(input.slice(1, llength).toString('hex'), 16) + const totalLength = llength + length if (totalLength > input.length) { - throw new Error("invalid rlp: total length is larger than the data"); + throw new Error('invalid rlp: total length is larger than the data') } - innerRemainder = input.slice(llength, totalLength); + innerRemainder = input.slice(llength, totalLength) if (innerRemainder.length === 0) { - throw new Error("invalid rlp, List has a invalid length"); + throw new Error('invalid rlp, List has a invalid length') } while (innerRemainder.length) { - d = _decode(innerRemainder); - decoded.push(d.data as Buffer); - innerRemainder = d.remainder; + d = _decode(innerRemainder) + decoded.push(d.data as Buffer) + innerRemainder = d.remainder } return { data: decoded, - remainder: input.slice(totalLength) - }; + remainder: input.slice(totalLength), + } } } /** Check if a string is prefixed by 0x */ function isHexPrefixed(str: string): boolean { - return str.slice(0, 2) === "0x"; + return str.slice(0, 2) === '0x' } /** Removes 0x from a given String */ function stripHexPrefix(str: string): string { - if (typeof str !== "string") { - return str; + if (typeof str !== 'string') { + return str } - return isHexPrefixed(str) ? str.slice(2) : str; + return isHexPrefixed(str) ? str.slice(2) : str } /** Transform an integer into its hexadecimal value */ function intToHex(integer: number): string { - const hex = integer.toString(16); - return hex.length % 2 ? `0${hex}` : hex; + const hex = integer.toString(16) + return hex.length % 2 ? `0${hex}` : hex } /** Pad a string to be even */ function padToEven(a: string): string { - return a.length % 2 ? `0${a}` : a; + return a.length % 2 ? `0${a}` : a } /** Transform an integer into a Buffer */ function intToBuffer(integer: number): Buffer { - const hex = intToHex(integer); - return Buffer.from(hex, "hex"); + const hex = intToHex(integer) + return Buffer.from(hex, 'hex') } /** Transform anything into a Buffer */ @@ -225,42 +228,42 @@ function toBuffer(v: RLPInput): Buffer { if (!Buffer.isBuffer(v)) { if (isString(v)) { if (isHexPrefixed(v)) { - return Buffer.from(padToEven(stripHexPrefix(v)), "hex"); + return Buffer.from(padToEven(stripHexPrefix(v)), 'hex') } else { - return Buffer.from(v); + return Buffer.from(v) } } else if (isNumber(v)) { if (!v) { - return Buffer.from([]); + return Buffer.from([]) } else { - return intToBuffer(v); + return intToBuffer(v) } } else if (v === null || v === undefined) { - return Buffer.from([]); + return Buffer.from([]) } else if (v instanceof Uint8Array) { - return Buffer.from(v as any); + return Buffer.from(v as any) } else if (isBN(v)) { // converts a BN to a Buffer - return Buffer.from(v.toArray()); + return Buffer.from(v.toArray()) } else { - throw new Error("invalid type"); + throw new Error('invalid type') } } - return v as Buffer; + return v } // Check is input is a number function isString(input: RLPInput): input is string { - return typeof input === 'string'; + return typeof input === 'string' } // Check is input is a number function isNumber(input: RLPInput): input is number { - return typeof input === 'number'; + return typeof input === 'number' } // Check if an input is a BigNumber function isBN(input: RLPInput): input is BN { - if (!input) return false; - return !!input.hasOwnProperty('toArray'); -} \ No newline at end of file + if (!input) return false + return !!input.hasOwnProperty('toArray') +} diff --git a/src/types.ts b/src/types.ts index 91554fe..c13bbeb 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,14 +1,21 @@ -import BN from 'bn.js'; +import BN from 'bn.js' -export type RLPInput = Buffer | string | number | Uint8Array | BN | RLPObject | RLPArray | null; +export type RLPInput = + | Buffer + | string + | number + | Uint8Array + | BN + | RLPObject + | RLPArray + | null -export interface RLPArray extends Array {}; +export interface RLPArray extends Array {} interface RLPObject { - [x: string]: RLPInput; + [x: string]: RLPInput } - export interface RLPDecoded { - data: Buffer | Buffer[]; - remainder: Buffer; -} \ No newline at end of file + data: Buffer | Buffer[] + remainder: Buffer +} diff --git a/test/index.ts b/test/index.ts index 5d1cf6d..8a67f98 100644 --- a/test/index.ts +++ b/test/index.ts @@ -1,11 +1,12 @@ -import * as assert from "assert"; -import * as RLP from "../src"; -const BN = require('bn.js'); -const testing = require('ethereumjs-testing'); - -describe('invalid rlps', function () { - it('should not crash on an invalid rlp', function () { - var a = Buffer.from([239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 239, 191, 189, 29, 239, 191, 189, 77, 239, 191, 189, 239, 191, 189, 239, 191, 189, 93, 122, 239, 191, 189, 239, 191, 189, 239, 191, 189, 103, 239, 191, 189, 239, 191, 189, 239, 191, 189, 26, 239, 191, 189, 18, 69, 27, 239, 191, 189, 239, 191, 189, 116, 19, 239, 191, 189, 239, 191, 189, 66, 239, 191, 189, 64, 212, 147, 71, 239, 191, 189, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 239, 191, 189, 11, 222, 155, 122, 54, 42, 194, 169, 239, 191, 189, 70, 239, 191, 189, 72, 239, 191, 189, 239, 191, 189, 54, 53, 239, 191, 189, 100, 73, 239, 191, 189, 55, 239, 191, 189, 239, 191, 189, 59, 1, 239, 191, 189, 109, 239, 191, 189, 239, 191, 189, 93, 239, 191, 189, 208, 128, 239, 191, 189, 239, 191, 189, 0, 239, 191, 189, 239, 191, 189, 239, 191, 189, 15, 66, 64, 239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 4, 239, 191, 189, 79, 103, 239, 191, 189, 85, 239, 191, 189, 239, 191, 189, 239, 191, 189, 74, 239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 54, 239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 83, 239, 191, 189, 14, 239, 191, 189, 239, 191, 189, 239, 191, 189, 4, 63, 239, 191, 189, 63, 239, 191, 189, 41, 239, 191, 189, 239, 191, 189, 239, 191, 189, 67, 28, 239, 191, 189, 239, 191, 189, 11, 239, 191, 189, 31, 239, 191, 189, 239, 191, 189, 104, 96, 100, 239, 191, 189, 239, 191, 189, 12, 239, 191, 189, 239, 191, 189, 206, 152, 239, 191, 189, 239, 191, 189, 31, 112, 111, 239, 191, 189, 239, 191, 189, 65, 239, 191, 189, 41, 239, 191, 189, 239, 191, 189, 53, 84, 11, 239, 191, 189, 239, 191, 189, 12, 102, 24, 12, 42, 105, 109, 239, 191, 189, 58, 239, 191, 189, 4, 239, 191, 189, 104, 82, 9, 239, 191, 189, 6, 66, 91, 43, 38, 102, 117, 239, 191, 189, 105, 239, 191, 189, 239, 191, 189, 239, 191, 189, 89, 127, 239, 191, 189, 114]) +import * as assert from 'assert' +import * as RLP from '../src' +const BN = require('bn.js') +const testing = require('ethereumjs-testing') + +describe('invalid rlps', function() { + it('should not crash on an invalid rlp', function() { + // prettier-ignore + const a = Buffer.from([239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 239, 191, 189, 29, 239, 191, 189, 77, 239, 191, 189, 239, 191, 189, 239, 191, 189, 93, 122, 239, 191, 189, 239, 191, 189, 239, 191, 189, 103, 239, 191, 189, 239, 191, 189, 239, 191, 189, 26, 239, 191, 189, 18, 69, 27, 239, 191, 189, 239, 191, 189, 116, 19, 239, 191, 189, 239, 191, 189, 66, 239, 191, 189, 64, 212, 147, 71, 239, 191, 189, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 239, 191, 189, 11, 222, 155, 122, 54, 42, 194, 169, 239, 191, 189, 70, 239, 191, 189, 72, 239, 191, 189, 239, 191, 189, 54, 53, 239, 191, 189, 100, 73, 239, 191, 189, 55, 239, 191, 189, 239, 191, 189, 59, 1, 239, 191, 189, 109, 239, 191, 189, 239, 191, 189, 93, 239, 191, 189, 208, 128, 239, 191, 189, 239, 191, 189, 0, 239, 191, 189, 239, 191, 189, 239, 191, 189, 15, 66, 64, 239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 4, 239, 191, 189, 79, 103, 239, 191, 189, 85, 239, 191, 189, 239, 191, 189, 239, 191, 189, 74, 239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 54, 239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 239, 191, 189, 83, 239, 191, 189, 14, 239, 191, 189, 239, 191, 189, 239, 191, 189, 4, 63, 239, 191, 189, 63, 239, 191, 189, 41, 239, 191, 189, 239, 191, 189, 239, 191, 189, 67, 28, 239, 191, 189, 239, 191, 189, 11, 239, 191, 189, 31, 239, 191, 189, 239, 191, 189, 104, 96, 100, 239, 191, 189, 239, 191, 189, 12, 239, 191, 189, 239, 191, 189, 206, 152, 239, 191, 189, 239, 191, 189, 31, 112, 111, 239, 191, 189, 239, 191, 189, 65, 239, 191, 189, 41, 239, 191, 189, 239, 191, 189, 53, 84, 11, 239, 191, 189, 239, 191, 189, 12, 102, 24, 12, 42, 105, 109, 239, 191, 189, 58, 239, 191, 189, 4, 239, 191, 189, 104, 82, 9, 239, 191, 189, 6, 66, 91, 43, 38, 102, 117, 239, 191, 189, 105, 239, 191, 189, 239, 191, 189, 239, 191, 189, 89, 127, 239, 191, 189, 114]) try { RLP.decode(a) } catch (e) { @@ -15,15 +16,15 @@ describe('invalid rlps', function () { }) }) -describe('RLP encoding (string):', function () { - it('should return itself if single byte and less than 0x7f:', function () { - var encodedSelf = RLP.encode('a') +describe('RLP encoding (string):', function() { + it('should return itself if single byte and less than 0x7f:', function() { + const encodedSelf = RLP.encode('a') assert.equal(encodedSelf.toString(), 'a') assert.equal(RLP.getLength(encodedSelf), 1) }) - it('length of string 0-55 should return (0x80+len(data)) plus data', function () { - var encodedDog = RLP.encode('dog') + it('length of string 0-55 should return (0x80+len(data)) plus data', function() { + const encodedDog = RLP.encode('dog') assert.equal(4, encodedDog.length) assert.equal(RLP.getLength(encodedDog), 4) assert.equal(encodedDog[0], 131) @@ -32,8 +33,10 @@ describe('RLP encoding (string):', function () { assert.equal(encodedDog[3], 103) }) - it('length of string >55 should return 0xb7+len(len(data)) plus len(data) plus data', function () { - var encodedLongString = RLP.encode('zoo255zoo255zzzzzzzzzzzzssssssssssssssssssssssssssssssssssssssssssssss') + it('length of string >55 should return 0xb7+len(len(data)) plus len(data) plus data', function() { + const encodedLongString = RLP.encode( + 'zoo255zoo255zzzzzzzzzzzzssssssssssssssssssssssssssssssssssssssssssssss', + ) assert.equal(72, encodedLongString.length) assert.equal(RLP.getLength(encodedLongString), 2) assert.equal(encodedLongString[0], 184) @@ -44,9 +47,9 @@ describe('RLP encoding (string):', function () { }) }) -describe('RLP encoding (list):', function () { - it('length of list 0-55 should return (0xc0+len(data)) plus data', function () { - var encodedArrayOfStrings = RLP.encode(['dog', 'god', 'cat']) +describe('RLP encoding (list):', function() { + it('length of list 0-55 should return (0xc0+len(data)) plus data', function() { + const encodedArrayOfStrings = RLP.encode(['dog', 'god', 'cat']) assert.equal(13, encodedArrayOfStrings.length) assert.equal(encodedArrayOfStrings[0], 204) assert.equal(encodedArrayOfStrings[1], 131) @@ -54,101 +57,109 @@ describe('RLP encoding (list):', function () { assert.equal(encodedArrayOfStrings[12], 116) }) -// it('length of list >55 should return 0xf7+len(len(data)) plus len(data) plus data', function () { -// // need a test case here! -// }) + // it('length of list >55 should return 0xf7+len(len(data)) plus len(data) plus data', function () { + // // need a test case here! + // }) }) -describe('RLP encoding (integer):', function () { - it('length of int = 1, less than 0x7f, similar to string', function () { - var encodedNumber = RLP.encode(15) +describe('RLP encoding (integer):', function() { + it('length of int = 1, less than 0x7f, similar to string', function() { + const encodedNumber = RLP.encode(15) assert.equal(1, encodedNumber.length) assert.equal(encodedNumber[0], 15) }) - it('length of int > 55, similar to string', function () { - var encodedNumber = RLP.encode(1024) + it('length of int > 55, similar to string', function() { + const encodedNumber = RLP.encode(1024) assert.equal(3, encodedNumber.length) assert.equal(encodedNumber[0], 130) assert.equal(encodedNumber[1], 4) assert.equal(encodedNumber[2], 0) }) - it('it should handle zero', function () { + it('it should handle zero', function() { assert.equal(RLP.encode(0).toString('hex'), '80') }) }) -describe('RLP decoding (string):', function () { - it('first byte < 0x7f, return byte itself', function () { - var decodedStr = RLP.decode(Buffer.from([97])) +describe('RLP decoding (string):', function() { + it('first byte < 0x7f, return byte itself', function() { + const decodedStr = RLP.decode(Buffer.from([97])) assert.equal(1, decodedStr.length) assert.equal(decodedStr.toString(), 'a') }) - it('first byte < 0xb7, data is everything except first byte', function () { - var decodedStr = RLP.decode(Buffer.from([131, 100, 111, 103])) + it('first byte < 0xb7, data is everything except first byte', function() { + const decodedStr = RLP.decode(Buffer.from([131, 100, 111, 103])) assert.equal(3, decodedStr.length) assert.equal(decodedStr.toString(), 'dog') }) - it('array', function () { - var decodedBufferArray = RLP.decode(Buffer.from([204, 131, 100, 111, 103, 131, 103, 111, 100, 131, 99, 97, 116])) - assert.deepEqual(decodedBufferArray, [Buffer.from('dog'), Buffer.from('god'), Buffer.from('cat')]) + it('array', function() { + // prettier-ignore + const decodedBufferArray = RLP.decode(Buffer.from([204, 131, 100, 111, 103, 131, 103, 111, 100, 131, 99, 97, 116])) + assert.deepEqual(decodedBufferArray, [ + Buffer.from('dog'), + Buffer.from('god'), + Buffer.from('cat'), + ]) }) }) -describe('RLP decoding (int):', function () { - it('first byte < 0x7f, return itself', function () { - var decodedSmallNum = RLP.decode(Buffer.from([15])) +describe('RLP decoding (int):', function() { + it('first byte < 0x7f, return itself', function() { + const decodedSmallNum = RLP.decode(Buffer.from([15])) assert.equal(1, decodedSmallNum.length) assert.equal(decodedSmallNum[0], 15) }) - it('first byte < 0xb7, data is everything except first byte', function () { - var decodedNum = RLP.decode(Buffer.from([130, 4, 0])) + it('first byte < 0xb7, data is everything except first byte', function() { + const decodedNum = RLP.decode(Buffer.from([130, 4, 0])) assert.equal(2, decodedNum.length) assert.equal(decodedNum.toString('hex'), '0400') }) }) -describe('strings over 55 bytes long', function () { - const testString = 'This function takes in a data, convert it to buffer if not, and a length for recursion' +describe('strings over 55 bytes long', function() { + const testString = + 'This function takes in a data, convert it to buffer if not, and a length for recursion' const testBuffer = Buffer.from(testString) - let encoded:Buffer + let encoded: Buffer - it('should encode it', function () { + it('should encode it', function() { encoded = RLP.encode(testBuffer) assert.equal(encoded[0], 184) assert.equal(encoded[1], 86) }) - it('should decode', function () { - var decoded = RLP.decode(encoded) + it('should decode', function() { + const decoded = RLP.decode(encoded) assert.equal(decoded.toString(), testString) }) }) -describe('list over 55 bytes long', function () { +describe('list over 55 bytes long', function() { + // prettier-ignore const testString = ['This', 'function', 'takes', 'in', 'a', 'data', 'convert', 'it', 'to', 'buffer', 'if', 'not', 'and', 'a', 'length', 'for', 'recursion', 'a1', 'a2', 'a3', 'ia4', 'a5', 'a6', 'a7', 'a8', 'ba9'] let encoded: Buffer - it('should encode it', function () { + it('should encode it', function() { encoded = RLP.encode(testString) }) - it('should decode', function () { + it('should decode', function() { const decodedBuffer = RLP.decode(encoded) const decoded: string[] = [] - for (var i = 0; i < decodedBuffer.length; i++) { + for (let i = 0; i < decodedBuffer.length; i++) { decoded[i] = decodedBuffer[i].toString() } assert.deepEqual(decoded, testString) }) }) -describe('nested lists:', function () { - var nestedList = [ +describe('nested lists:', function() { + // prettier-ignore + const nestedList = [ [], [ [] @@ -160,138 +171,146 @@ describe('nested lists:', function () { ] ] ] - var valueList = [ + const valueList = [ [1, 2, 3], [ Buffer.from([4, 5, 6]), Buffer.from([7, 8, 9]), - [ - Buffer.from([0]), - Buffer.from('abcd', 'hex') - ] - ] + [Buffer.from([0]), Buffer.from('abcd', 'hex')], + ], ] - var encoded: Buffer - it('encode a nested list', function () { + let encoded: Buffer + it('encode a nested list', function() { encoded = RLP.encode(nestedList) - assert.deepEqual(encoded, Buffer.from([0xc7, 0xc0, 0xc1, 0xc0, 0xc3, 0xc0, 0xc1, 0xc0])) + assert.deepEqual( + encoded, + Buffer.from([0xc7, 0xc0, 0xc1, 0xc0, 0xc3, 0xc0, 0xc1, 0xc0]), + ) }) - it('should decode a nested list', function () { - var decoded = RLP.decode(encoded) + it('should decode a nested list', function() { + const decoded = RLP.decode(encoded) assert.deepEqual(nestedList, decoded) }) - it('should encode a list with values', function () { - var valueEncoded = RLP.encode(valueList) + it('should encode a list with values', function() { + const valueEncoded = RLP.encode(valueList) + // prettier-ignore assert.deepEqual(valueEncoded, Buffer.from([0xd2, 0xc3, 0x01, 0x02, 0x03, 0xcd, 0x83, 0x04, 0x05, 0x06, 0x83, 0x07, 0x08, 0x09, 0xc4, 0x00, 0x82, 0xab, 0xcd])) }) }) -describe('typed lists:', function () { - var valueList = [ +describe('typed lists:', function() { + const valueList = [ [1, 2, 3], [ new Uint8Array([4, 5, 6]), new Uint8Array([7, 8, 9]), - [ - new Uint8Array([0]), - Buffer.from('abcd', 'hex') - ] - ] + [new Uint8Array([0]), Buffer.from('abcd', 'hex')], + ], ] // equivalent to list of values above - it('encode a nested list', function () { - var valueEncoded = RLP.encode(valueList) + it('encode a nested list', function() { + const valueEncoded = RLP.encode(valueList) + // prettier-ignore assert.deepEqual(valueEncoded, new Buffer([0xd2, 0xc3, 0x01, 0x02, 0x03, 0xcd, 0x83, 0x04, 0x05, 0x06, 0x83, 0x07, 0x08, 0x09, 0xc4, 0x00, 0x82, 0xab, 0xcd])) }) }) -describe('null values', function () { - var nestedList = [null] - var encoded - it('encode a null array', function () { +describe('null values', function() { + const nestedList = [null] + let encoded + it('encode a null array', function() { encoded = RLP.encode(nestedList) assert.deepEqual(encoded, Buffer.from([0xc1, 0x80])) }) - it('should decode a null value', function () { + it('should decode a null value', function() { assert.deepEqual(Buffer.from([]), RLP.decode(Buffer.from('80', 'hex'))) }) }) -describe('zero values', function () { - var encoded - it('encode a zero', function () { +describe('zero values', function() { + let encoded + it('encode a zero', function() { encoded = RLP.encode(Buffer.from([0])) assert.deepEqual(encoded, Buffer.from([0])) }) - it('decode a zero', function () { - var decode = RLP.decode(Buffer.from([0])) + it('decode a zero', function() { + const decode = RLP.decode(Buffer.from([0])) assert.deepEqual(decode, Buffer.from([0])) }) }) -describe('empty values', function () { - var decoded - it('decode empty buffer', function () { +describe('empty values', function() { + let decoded + it('decode empty buffer', function() { decoded = RLP.decode(Buffer.from([])) assert.deepEqual(decoded, Buffer.from([])) }) }) -describe('bad values', function () { - it('wrong encoded a zero', function () { - var val = Buffer.from('f9005f030182520894b94f5374fce5edbc8e2a8697c15331677e6ebf0b0a801ca098ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4aa08887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3', 'hex') - var result +describe('bad values', function() { + it('wrong encoded a zero', function() { + const val = Buffer.from( + 'f9005f030182520894b94f5374fce5edbc8e2a8697c15331677e6ebf0b0a801ca098ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4aa08887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3', + 'hex', + ) + let result try { result = RLP.decode(val) } catch (e) {} assert.equal(result, undefined) }) - it('invalid length', function () { - var a = Buffer.from('f86081000182520894b94f5374fce5edbc8e2a8697c15331677e6ebf0b0a801ca098ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4aa08887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3', 'hex') + it('invalid length', function() { + const a = Buffer.from( + 'f86081000182520894b94f5374fce5edbc8e2a8697c15331677e6ebf0b0a801ca098ff921201554726367d2be8c804a7ff89ccf285ebc57dff8ae4c44b9c19ac4aa08887321be575c8095f789dd4c743dfe42c1820f9231f98a962b210e3ac2452a3', + 'hex', + ) - var result + let result try { result = RLP.decode(a) } catch (e) {} assert.equal(result, undefined) }) - it('extra data at end', function () { - var c = 'f90260f901f9a02a3c692012a15502ba9c39f3aebb36694eed978c74b52e6c0cf210d301dbf325a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0ef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017a0b6c9fd1447d0b414a1f05957927746f58ef5a2ebde17db631d460eaf6a93b18da0bc37d79753ad738a6dac4921e57392f145d8887476de3f783dfa7edae9283e52b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefd8825208845509814280a00451dd53d9c09f3cfb627b51d9d80632ed801f6330ee584bffc26caac9b9249f88c7bffe5ebd94cc2ff861f85f800a82c35094095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba098c3a099885a281885f487fd37550de16436e8c47874cd213531b10fe751617fa044b6b81011ce57bffcaf610bf728fb8a7237ad261ea2d937423d78eb9e137076c0ef' + it('extra data at end', function() { + const c = + 'f90260f901f9a02a3c692012a15502ba9c39f3aebb36694eed978c74b52e6c0cf210d301dbf325a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0ef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017a0b6c9fd1447d0b414a1f05957927746f58ef5a2ebde17db631d460eaf6a93b18da0bc37d79753ad738a6dac4921e57392f145d8887476de3f783dfa7edae9283e52b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefd8825208845509814280a00451dd53d9c09f3cfb627b51d9d80632ed801f6330ee584bffc26caac9b9249f88c7bffe5ebd94cc2ff861f85f800a82c35094095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba098c3a099885a281885f487fd37550de16436e8c47874cd213531b10fe751617fa044b6b81011ce57bffcaf610bf728fb8a7237ad261ea2d937423d78eb9e137076c0ef' - var a = Buffer.from(c, 'hex') + const a = Buffer.from(c, 'hex') - var result + let result try { result = RLP.decode(a) } catch (e) {} assert.equal(result, undefined) }) - it('extra data at end', function () { - var c = 'f9ffffffc260f901f9a02a3c692012a15502ba9c39f3aebb36694eed978c74b52e6c0cf210d301dbf325a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0ef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017a0b6c9fd1447d0b414a1f05957927746f58ef5a2ebde17db631d460eaf6a93b18da0bc37d79753ad738a6dac4921e57392f145d8887476de3f783dfa7edae9283e52b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefd8825208845509814280a00451dd53d9c09f3cfb627b51d9d80632ed801f6330ee584bffc26caac9b9249f88c7bffe5ebd94cc2ff861f85f800a82c35094095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba098c3a099885a281885f487fd37550de16436e8c47874cd213531b10fe751617fa044b6b81011ce57bffcaf610bf728fb8a7237ad261ea2d937423d78eb9e137076c0' + it('extra data at end', function() { + const c = + 'f9ffffffc260f901f9a02a3c692012a15502ba9c39f3aebb36694eed978c74b52e6c0cf210d301dbf325a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0ef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017a0b6c9fd1447d0b414a1f05957927746f58ef5a2ebde17db631d460eaf6a93b18da0bc37d79753ad738a6dac4921e57392f145d8887476de3f783dfa7edae9283e52b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefd8825208845509814280a00451dd53d9c09f3cfb627b51d9d80632ed801f6330ee584bffc26caac9b9249f88c7bffe5ebd94cc2ff861f85f800a82c35094095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba098c3a099885a281885f487fd37550de16436e8c47874cd213531b10fe751617fa044b6b81011ce57bffcaf610bf728fb8a7237ad261ea2d937423d78eb9e137076c0' - var a = Buffer.from(c, 'hex') + const a = Buffer.from(c, 'hex') - var result + let result try { result = RLP.decode(a) } catch (e) {} assert.equal(result, undefined) }) - it('list length longer than data', function () { - var c = 'f9ffffffc260f901f9a02a3c692012a15502ba9c39f3aebb36694eed978c74b52e6c0cf210d301dbf325a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0ef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017a0b6c9fd1447d0b414a1f05957927746f58ef5a2ebde17db631d460eaf6a93b18da0bc37d79753ad738a6dac4921e57392f145d8887476de3f783dfa7edae9283e52b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefd8825208845509814280a00451dd53d9c09f3cfb627b51d9d80632ed801f6330ee584bffc26caac9b9249f88c7bffe5ebd94cc2ff861f85f800a82c35094095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba098c3a099885a281885f487fd37550de16436e8c47874cd213531b10fe751617fa044b6b81011ce57bffcaf610bf728fb8a7237ad261ea2d937423d78eb9e137076c0' + it('list length longer than data', function() { + const c = + 'f9ffffffc260f901f9a02a3c692012a15502ba9c39f3aebb36694eed978c74b52e6c0cf210d301dbf325a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347948888f1f195afa192cfee860698584c030f4c9db1a0ef1552a40b7165c3cd773806b9e0c165b75356e0314bf0706f279c729f51e017a0b6c9fd1447d0b414a1f05957927746f58ef5a2ebde17db631d460eaf6a93b18da0bc37d79753ad738a6dac4921e57392f145d8887476de3f783dfa7edae9283e52b90100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008302000001832fefd8825208845509814280a00451dd53d9c09f3cfb627b51d9d80632ed801f6330ee584bffc26caac9b9249f88c7bffe5ebd94cc2ff861f85f800a82c35094095e7baea6a6c7c4c2dfeb977efac326af552d870a801ba098c3a099885a281885f487fd37550de16436e8c47874cd213531b10fe751617fa044b6b81011ce57bffcaf610bf728fb8a7237ad261ea2d937423d78eb9e137076c0' - var a = Buffer.from(c, 'hex') + const a = Buffer.from(c, 'hex') - var result + let result try { result = RLP.decode(a) } catch (e) {} @@ -299,28 +318,31 @@ describe('bad values', function () { }) }) -describe('hex prefix', function () { - it('should have the same value', function () { - var a = RLP.encode('0x88f') - var b = RLP.encode('88f') +describe('hex prefix', function() { + it('should have the same value', function() { + const a = RLP.encode('0x88f') + const b = RLP.encode('88f') assert.notEqual(a.toString('hex'), b.toString('hex')) }) }) -describe('offical tests', function () { - it('pass all tests', function (done) { +describe('offical tests', function() { + it('pass all tests', function(done) { const officalTests = testing.getSingleFile('RLPTests/rlptest.json') - for (var test in officalTests) { - var incoming = officalTests[test].in + for (const test in officalTests) { + let incoming = officalTests[test].in // if we are testing a big number if (incoming[0] === '#') { - var bn = new BN(incoming.slice(1)) + const bn = new BN(incoming.slice(1)) incoming = Buffer.from(bn.toArray()) } - var encoded = RLP.encode(incoming) - assert.equal(encoded.toString('hex'), officalTests[test].out.toLowerCase()) + const encoded = RLP.encode(incoming) + assert.equal( + encoded.toString('hex'), + officalTests[test].out.toLowerCase(), + ) } done() }) diff --git a/tsconfig.json b/tsconfig.json index 71e349a..9309c4b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,24 +1,19 @@ { - "compileOnSave": false, - "compilerOptions": { - "baseUrl": "./src", - "outDir": "./dist", - "sourceMap": false, - "declaration": false, - "module": "commonjs", - "moduleResolution": "node", - "emitDecoratorMetadata": false, - "experimentalDecorators": true, - "allowSyntheticDefaultImports": true, - "strict": true, - "noImplicitAny": true, - "target": "es5", - "typeRoots": [ - "node_modules/@types" - ], - "lib": [ - "es2018" - ] - } + "compileOnSave": false, + "compilerOptions": { + "baseUrl": "./src", + "outDir": "./dist", + "sourceMap": false, + "declaration": false, + "module": "commonjs", + "moduleResolution": "node", + "emitDecoratorMetadata": false, + "experimentalDecorators": true, + "allowSyntheticDefaultImports": true, + "strict": true, + "noImplicitAny": true, + "target": "es5", + "typeRoots": ["node_modules/@types"], + "lib": ["es2018"] } - \ No newline at end of file +} diff --git a/tslint.json b/tslint.json new file mode 100644 index 0000000..2fcd2c0 --- /dev/null +++ b/tslint.json @@ -0,0 +1,13 @@ +{ + "extends": "typestrict", + "rules": { + "no-console": true, + "no-debugger": true, + "mocha-avoid-only": true, + "prefer-const": true, + "no-var-keyword": true, + "interface-name": [true, "never-prefix"], + "no-commented-code": true, + "no-use-before-declare": false + } +}