Skip to content

Commit 27ffa76

Browse files
committed
util, devp2p -> monorepo transition: removed devp2p tsconfig.browser.json (build breaking, needs to be fixed), fixed linting
1 parent 2ddc2ae commit 27ffa76

19 files changed

+374
-388
lines changed

packages/devp2p/tsconfig.browser.json

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/util/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@
9696
"@types/node": "^11.13.4",
9797
"@types/secp256k1": "^4.0.1",
9898
"@types/tape": "^4.13.0",
99+
"eslint": "^6.8.0",
100+
"eslint-config-prettier": "^6.11.0",
101+
"eslint-plugin-implicit-dependencies": "^1.0.4",
99102
"karma": "^5.2.1",
100103
"karma-chrome-launcher": "^3.1.0",
101104
"karma-firefox-launcher": "^1.3.0",

packages/util/src/account.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
privateKeyVerify,
66
publicKeyCreate,
77
publicKeyVerify,
8-
publicKeyConvert
8+
publicKeyConvert,
99
} from 'ethereum-cryptography/secp256k1'
1010
import { stripHexPrefix } from 'ethjs-util'
1111
import { KECCAK256_RLP, KECCAK256_NULL } from './constants'
@@ -121,7 +121,7 @@ export class Account {
121121
/**
122122
* Checks if the address is a valid. Accepts checksummed addresses too.
123123
*/
124-
export const isValidAddress = function(hexAddress: string): boolean {
124+
export const isValidAddress = function (hexAddress: string): boolean {
125125
assertIsHexString(hexAddress)
126126
return /^0x[0-9a-fA-F]{40}$/.test(hexAddress)
127127
}
@@ -136,7 +136,7 @@ export const isValidAddress = function(hexAddress: string): boolean {
136136
* WARNING: Checksums with and without the chainId will differ. As of 2019-06-26, the most commonly
137137
* used variation in Ethereum was without the chainId. This may change in the future.
138138
*/
139-
export const toChecksumAddress = function(hexAddress: string, eip1191ChainId?: BNLike): string {
139+
export const toChecksumAddress = function (hexAddress: string, eip1191ChainId?: BNLike): string {
140140
assertIsHexString(hexAddress)
141141
const address = stripHexPrefix(hexAddress).toLowerCase()
142142

@@ -165,7 +165,7 @@ export const toChecksumAddress = function(hexAddress: string, eip1191ChainId?: B
165165
*
166166
* See toChecksumAddress' documentation for details about the eip1191ChainId parameter.
167167
*/
168-
export const isValidChecksumAddress = function(
168+
export const isValidChecksumAddress = function (
169169
hexAddress: string,
170170
eip1191ChainId?: BNLike
171171
): boolean {
@@ -177,7 +177,7 @@ export const isValidChecksumAddress = function(
177177
* @param from The address which is creating this new address
178178
* @param nonce The nonce of the from account
179179
*/
180-
export const generateAddress = function(from: Buffer, nonce: Buffer): Buffer {
180+
export const generateAddress = function (from: Buffer, nonce: Buffer): Buffer {
181181
assertIsBuffer(from)
182182
assertIsBuffer(nonce)
183183
const nonceBN = new BN(nonce)
@@ -198,7 +198,7 @@ export const generateAddress = function(from: Buffer, nonce: Buffer): Buffer {
198198
* @param salt A salt
199199
* @param initCode The init code of the contract being created
200200
*/
201-
export const generateAddress2 = function(from: Buffer, salt: Buffer, initCode: Buffer): Buffer {
201+
export const generateAddress2 = function (from: Buffer, salt: Buffer, initCode: Buffer): Buffer {
202202
assertIsBuffer(from)
203203
assertIsBuffer(salt)
204204
assertIsBuffer(initCode)
@@ -216,7 +216,7 @@ export const generateAddress2 = function(from: Buffer, salt: Buffer, initCode: B
216216
/**
217217
* Checks if the private key satisfies the rules of the curve secp256k1.
218218
*/
219-
export const isValidPrivate = function(privateKey: Buffer): boolean {
219+
export const isValidPrivate = function (privateKey: Buffer): boolean {
220220
return privateKeyVerify(privateKey)
221221
}
222222

@@ -226,7 +226,7 @@ export const isValidPrivate = function(privateKey: Buffer): boolean {
226226
* @param publicKey The two points of an uncompressed key, unless sanitize is enabled
227227
* @param sanitize Accept public keys in other formats
228228
*/
229-
export const isValidPublic = function(publicKey: Buffer, sanitize: boolean = false): boolean {
229+
export const isValidPublic = function (publicKey: Buffer, sanitize: boolean = false): boolean {
230230
assertIsBuffer(publicKey)
231231
if (publicKey.length === 64) {
232232
// Convert to SEC1 for secp256k1
@@ -246,7 +246,7 @@ export const isValidPublic = function(publicKey: Buffer, sanitize: boolean = fal
246246
* @param pubKey The two points of an uncompressed key, unless sanitize is enabled
247247
* @param sanitize Accept public keys in other formats
248248
*/
249-
export const pubToAddress = function(pubKey: Buffer, sanitize: boolean = false): Buffer {
249+
export const pubToAddress = function (pubKey: Buffer, sanitize: boolean = false): Buffer {
250250
assertIsBuffer(pubKey)
251251
if (sanitize && pubKey.length !== 64) {
252252
pubKey = Buffer.from(publicKeyConvert(pubKey, false).slice(1))
@@ -261,7 +261,7 @@ export const publicToAddress = pubToAddress
261261
* Returns the ethereum public key of a given private key.
262262
* @param privateKey A private key must be 256 bits wide
263263
*/
264-
export const privateToPublic = function(privateKey: Buffer): Buffer {
264+
export const privateToPublic = function (privateKey: Buffer): Buffer {
265265
assertIsBuffer(privateKey)
266266
// skip the type flag and use the X, Y points
267267
return Buffer.from(publicKeyCreate(privateKey, false)).slice(1)
@@ -271,14 +271,14 @@ export const privateToPublic = function(privateKey: Buffer): Buffer {
271271
* Returns the ethereum address of a given private key.
272272
* @param privateKey A private key must be 256 bits wide
273273
*/
274-
export const privateToAddress = function(privateKey: Buffer): Buffer {
274+
export const privateToAddress = function (privateKey: Buffer): Buffer {
275275
return publicToAddress(privateToPublic(privateKey))
276276
}
277277

278278
/**
279279
* Converts a public key to the Ethereum format.
280280
*/
281-
export const importPublic = function(publicKey: Buffer): Buffer {
281+
export const importPublic = function (publicKey: Buffer): Buffer {
282282
assertIsBuffer(publicKey)
283283
if (publicKey.length !== 64) {
284284
publicKey = Buffer.from(publicKeyConvert(publicKey, false).slice(1))
@@ -289,7 +289,7 @@ export const importPublic = function(publicKey: Buffer): Buffer {
289289
/**
290290
* Returns the zero address.
291291
*/
292-
export const zeroAddress = function(): string {
292+
export const zeroAddress = function (): string {
293293
const addressLength = 20
294294
const addr = zeros(addressLength)
295295
return bufferToHex(addr)
@@ -298,7 +298,7 @@ export const zeroAddress = function(): string {
298298
/**
299299
* Checks if a given address is the zero address.
300300
*/
301-
export const isZeroAddress = function(hexAddress: string): boolean {
301+
export const isZeroAddress = function (hexAddress: string): boolean {
302302
assertIsHexString(hexAddress)
303303
const zeroAddr = zeroAddress()
304304
return zeroAddr === hexAddress

packages/util/src/address.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
pubToAddress,
77
privateToAddress,
88
generateAddress,
9-
generateAddress2
9+
generateAddress2,
1010
} from './account'
1111

1212
export class Address {

packages/util/src/bytes.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { assertIsBuffer, assertIsArray, assertIsHexString } from './helpers'
77
* Returns a buffer filled with 0s.
88
* @param bytes the number of bytes the buffer should be
99
*/
10-
export const zeros = function(bytes: number): Buffer {
10+
export const zeros = function (bytes: number): Buffer {
1111
return Buffer.allocUnsafe(bytes).fill(0)
1212
}
1313

@@ -19,7 +19,7 @@ export const zeros = function(bytes: number): Buffer {
1919
* @param right whether to start padding form the left or right
2020
* @return (Buffer)
2121
*/
22-
const setLength = function(msg: Buffer, length: number, right: boolean) {
22+
const setLength = function (msg: Buffer, length: number, right: boolean) {
2323
const buf = zeros(length)
2424
if (right) {
2525
if (msg.length < length) {
@@ -43,7 +43,7 @@ const setLength = function(msg: Buffer, length: number, right: boolean) {
4343
* @param length the number of bytes the output should be
4444
* @return (Buffer)
4545
*/
46-
export const setLengthLeft = function(msg: Buffer, length: number) {
46+
export const setLengthLeft = function (msg: Buffer, length: number) {
4747
assertIsBuffer(msg)
4848
return setLength(msg, length, false)
4949
}
@@ -55,7 +55,7 @@ export const setLengthLeft = function(msg: Buffer, length: number) {
5555
* @param length the number of bytes the output should be
5656
* @return (Buffer)
5757
*/
58-
export const setLengthRight = function(msg: Buffer, length: number) {
58+
export const setLengthRight = function (msg: Buffer, length: number) {
5959
assertIsBuffer(msg)
6060
return setLength(msg, length, true)
6161
}
@@ -65,7 +65,7 @@ export const setLengthRight = function(msg: Buffer, length: number) {
6565
* @param a (Buffer|Array|String)
6666
* @return (Buffer|Array|String)
6767
*/
68-
const stripZeros = function(a: any): Buffer | number[] | string {
68+
const stripZeros = function (a: any): Buffer | number[] | string {
6969
let first = a[0]
7070
while (a.length > 0 && first.toString() === '0') {
7171
a = a.slice(1)
@@ -79,7 +79,7 @@ const stripZeros = function(a: any): Buffer | number[] | string {
7979
* @param a (Buffer)
8080
* @return (Buffer)
8181
*/
82-
export const unpadBuffer = function(a: Buffer): Buffer {
82+
export const unpadBuffer = function (a: Buffer): Buffer {
8383
assertIsBuffer(a)
8484
return stripZeros(a) as Buffer
8585
}
@@ -89,7 +89,7 @@ export const unpadBuffer = function(a: Buffer): Buffer {
8989
* @param a (number[])
9090
* @return (number[])
9191
*/
92-
export const unpadArray = function(a: number[]): number[] {
92+
export const unpadArray = function (a: number[]): number[] {
9393
assertIsArray(a)
9494
return stripZeros(a) as number[]
9595
}
@@ -99,7 +99,7 @@ export const unpadArray = function(a: number[]): number[] {
9999
* @param a (String)
100100
* @return (String)
101101
*/
102-
export const unpadHexString = function(a: string): string {
102+
export const unpadHexString = function (a: string): string {
103103
assertIsHexString(a)
104104
a = stripHexPrefix(a)
105105
return stripZeros(a) as string
@@ -122,7 +122,7 @@ export type ToBufferInputTypes =
122122
* Inputs supported: `Buffer`, `String`, `Number`, null/undefined, `BN` and other objects with a `toArray()` or `toBuffer()` method.
123123
* @param v the value
124124
*/
125-
export const toBuffer = function(v: ToBufferInputTypes): Buffer {
125+
export const toBuffer = function (v: ToBufferInputTypes): Buffer {
126126
if (v === null || v === undefined) {
127127
return Buffer.allocUnsafe(0)
128128
}
@@ -169,15 +169,15 @@ export const toBuffer = function(v: ToBufferInputTypes): Buffer {
169169
* @param buf `Buffer` object to convert
170170
* @throws If the input number exceeds 53 bits.
171171
*/
172-
export const bufferToInt = function(buf: Buffer): number {
172+
export const bufferToInt = function (buf: Buffer): number {
173173
return new BN(toBuffer(buf)).toNumber()
174174
}
175175

176176
/**
177177
* Converts a `Buffer` into a `0x`-prefixed hex `String`.
178178
* @param buf `Buffer` object to convert
179179
*/
180-
export const bufferToHex = function(buf: Buffer): string {
180+
export const bufferToHex = function (buf: Buffer): string {
181181
buf = toBuffer(buf)
182182
return '0x' + buf.toString('hex')
183183
}
@@ -186,22 +186,22 @@ export const bufferToHex = function(buf: Buffer): string {
186186
* Interprets a `Buffer` as a signed integer and returns a `BN`. Assumes 256-bit numbers.
187187
* @param num Signed integer value
188188
*/
189-
export const fromSigned = function(num: Buffer): BN {
189+
export const fromSigned = function (num: Buffer): BN {
190190
return new BN(num).fromTwos(256)
191191
}
192192

193193
/**
194194
* Converts a `BN` to an unsigned integer and returns it as a `Buffer`. Assumes 256-bit numbers.
195195
* @param num
196196
*/
197-
export const toUnsigned = function(num: BN): Buffer {
197+
export const toUnsigned = function (num: BN): Buffer {
198198
return Buffer.from(num.toTwos(256).toArray())
199199
}
200200

201201
/**
202202
* Adds "0x" to a given `String` if it does not already start with "0x".
203203
*/
204-
export const addHexPrefix = function(str: string): string {
204+
export const addHexPrefix = function (str: string): string {
205205
if (typeof str !== 'string') {
206206
return str
207207
}
@@ -214,7 +214,7 @@ export const addHexPrefix = function(str: string): string {
214214
* @param ba (Buffer|Array)
215215
* @return (Array|String|null)
216216
*/
217-
export const baToJSON = function(ba: any): any {
217+
export const baToJSON = function (ba: any): any {
218218
if (Buffer.isBuffer(ba)) {
219219
return `0x${ba.toString('hex')}`
220220
} else if (ba instanceof Array) {

0 commit comments

Comments
 (0)