Skip to content

Commit 021add9

Browse files
authored
Merge pull request #1 from ethereumjs/master
Merge
2 parents 58c2476 + d485939 commit 021add9

File tree

12 files changed

+94
-21
lines changed

12 files changed

+94
-21
lines changed

karma.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = function(config) {
22
config.set({
33
frameworks: ['mocha', 'karma-typescript'],
4+
exclude: ["src/@types/**"], // ref: https://github.com/monounity/karma-typescript/issues/254
45
files: ['src/**/*.ts', 'test/**/*.ts'],
56
preprocessors: {
67
'**/*.ts': ['karma-typescript'],

src/@types/ethjs-util/index.d.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
declare module 'ethjs-util' {
2+
/**
3+
* @description Returns a `Boolean` on whether or not the a `String` starts with '0x'
4+
*/
5+
export function isHexPrefixed(str: string): boolean
6+
7+
/**
8+
* @description Removes '0x' from a given `String` if present
9+
*/
10+
export function stripHexPrefix(str: string): string
11+
12+
/**
13+
* @description Pads a `String` to have an even length
14+
*/
15+
export function padToEven(value: string): string
16+
17+
/**
18+
* @description Converts a `Number` into a hex `String`
19+
*/
20+
export function intToHex(i: number): string
21+
22+
/**
23+
* @description Converts an `Number` to a `Buffer`
24+
*/
25+
export function intToBuffer(i: number): Buffer
26+
27+
/**
28+
* @description Get the binary size of a string
29+
*/
30+
export function getBinarySize(str: string): number
31+
32+
/**
33+
* @description Returns TRUE if the first specified array contains all elements
34+
* from the second one. FALSE otherwise. If `some` is true, will
35+
* return true if first specified array contain some elements of
36+
* the second.
37+
*/
38+
export function arrayContainsArray(superset: any[], subset: any[], some?: boolean): boolean
39+
40+
/**
41+
* @description Should be called to get utf8 from it's hex representation
42+
*/
43+
export function toUtf8(hex: string): string
44+
45+
/**
46+
* @description Should be called to get ascii from it's hex representation
47+
*/
48+
export function toAscii(hex: string): string
49+
50+
/**
51+
* @description Should be called to get hex representation (prefixed by 0x) of utf8 string
52+
*/
53+
export function fromUtf8(stringValue: string): string
54+
55+
/**
56+
* @description Should be called to get hex representation (prefixed by 0x) of ascii string
57+
*/
58+
export function fromAscii(stringValue: string): string
59+
60+
/**
61+
* @description getKeys([{a: 1, b: 2}, {a: 3, b: 4}], 'a') => [1, 3]
62+
*/
63+
export function getKeys(params: any[], key: string, allowEmpty?: boolean): any[]
64+
65+
/**
66+
* @description check if string is hex string of specific length
67+
*/
68+
export function isHexString(value: string, length?: number): boolean
69+
}

src/account.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const ethjsUtil = require('ethjs-util')
1+
import * as ethjsUtil from 'ethjs-util'
22
import * as assert from 'assert'
33
import * as secp256k1 from 'secp256k1'
44
import * as BN from 'bn.js'

src/bytes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const ethjsUtil = require('ethjs-util')
1+
import * as ethjsUtil from 'ethjs-util'
22
import * as BN from 'bn.js'
33
import { assertIsBuffer, assertIsArray, assertIsHexString } from './helpers'
44

src/externals.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
11
/**
22
* Re-exports commonly used modules:
3-
* * Adds [`ethjs-util`](https://github.com/ethjs/ethjs-util) methods.
43
* * Exports [`BN`](https://github.com/indutny/bn.js), [`rlp`](https://github.com/ethereumjs/rlp).
54
* @packageDocumentation
65
*/
76

8-
const ethjsUtil = require('ethjs-util')
97
import * as BN from 'bn.js'
108
import * as rlp from 'rlp'
119

12-
/**
13-
* [`ethjsUtil`](https://github.com/ethjs/ethjs-util)
14-
*/
15-
Object.assign(exports, ethjsUtil)
16-
1710
/**
1811
* [`BN`](https://github.com/indutny/bn.js)
1912
*/

src/hash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const createKeccakHash = require('keccak')
22
const createHash = require('create-hash')
3-
const ethjsUtil = require('ethjs-util')
3+
import * as ethjsUtil from 'ethjs-util'
44
import * as rlp from 'rlp'
55
import { toBuffer, setLengthLeft } from './bytes'
66
import { assertIsString, assertIsBuffer, assertIsArray, assertIsHexString } from './helpers'

src/helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const ethjsUtil = require('ethjs-util')
1+
import * as ethjsUtil from 'ethjs-util'
22

33
/**
44
* Throws if a string is not hex prefixed

src/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ export * from './bytes'
2929
export * from './object'
3030

3131
/**
32-
* External exports (ethjsUtil, BN, rlp, secp256k1)
32+
* External exports (BN, rlp, secp256k1)
3333
*/
3434
export * from './externals'
35+
36+
/**
37+
* Export ethjs-util methods
38+
*/
39+
export * from 'ethjs-util'

src/object.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const ethjsUtil = require('ethjs-util')
1+
import * as ethjsUtil from 'ethjs-util'
22
import * as assert from 'assert'
33
import * as rlp from 'rlp'
44
import { toBuffer, baToJSON, unpadBuffer } from './bytes'

test/externals.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,24 @@ describe('External ethjsUtil export', () => {
101101

102102
it('should use ethjsUtil functions correctly', () => {
103103
// should convert intToHex
104-
assert.equal((src as any).intToHex(new src.BN(0)), '0x0')
104+
assert.equal(src.intToHex(new src.BN(0).toNumber()), '0x0')
105105

106106
// should convert intToHex
107107
const i = 6003400
108-
const hex = (src as any).intToHex(i)
108+
const hex = src.intToHex(i)
109109
assert.equal(hex, '0x5b9ac8')
110110

111111
// should convert a int to a buffer
112112
const j = 6003400
113-
const buf = (src as any).intToBuffer(j)
113+
const buf = src.intToBuffer(j)
114114
assert.equal(buf.toString('hex'), '5b9ac8')
115115
})
116116

117117
it('should handle exceptions and invalid inputs', () => {
118118
// should throw when invalid abi
119-
assert.throws(() => (src as any).getKeys([], 3289), Error)
119+
assert.throws(() => src.getKeys([], (<unknown>3289) as string), Error)
120120

121121
// should detect invalid length hex string
122-
assert.equal((src as any).isHexString('0x0', 2), false)
122+
assert.equal(src.isHexString('0x0', 2), false)
123123
})
124124
})

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy