UNPKG

3.94 kBMarkdownView Raw
1# ethereumjs-util
2
3[![NPM Package][util-npm-badge]][util-npm-link]
4[![GitHub Issues][util-issues-badge]][util-issues-link]
5[![Actions Status][util-actions-badge]][util-actions-link]
6[![Code Coverage][util-coverage-badge]][util-coverage-link]
7[![Discord][discord-badge]][discord-link]
8
9A collection of utility functions for Ethereum. It can be used in Node.js and in the browser with [browserify](http://browserify.org/).
10
11# INSTALL
12
13`npm install ethereumjs-util`
14
15# USAGE
16
17```js
18import assert from 'assert'
19import { isValidChecksumAddress, unpadBuffer, BN } from 'ethereumjs-util'
20
21assert.ok(isValidChecksumAddress('0x2F015C60E0be116B1f0CD534704Db9c92118FB6A'))
22
23assert.ok(unpadBuffer(Buffer.from('000000006600', 'hex')).equals(Buffer.from('6600', 'hex')))
24
25assert.ok(new BN('dead', 16).add(new BN('101010', 2)).eqn(57047))
26```
27
28# API
29
30## Documentation
31
32Read the [API docs](docs/).
33
34### Modules
35
36- [account](src/account.ts)
37 - Account class
38 - Private/public key and address-related functionality (creation, validation, conversion)
39- [address](src/address.ts)
40 - Address class and type
41- [bytes](src/bytes.ts)
42 - Byte-related helper and conversion functions
43- [constants](src/constants.ts)
44 - Exposed constants
45 - e.g. `KECCAK256_NULL_S` for string representation of Keccak-256 hash of null
46- [hash](src/hash.ts)
47 - Hash functions
48- [object](src/object.ts)
49 - Helper function for creating a binary object (`DEPRECATED`)
50- [signature](src/signature.ts)
51 - Signing, signature validation, conversion, recovery
52- [types](src/types.ts)
53 - Helpful TypeScript types
54- [internal](src/internal.ts)
55 - Internalized helper methods
56- [externals](src/externals.ts)
57 - Re-exports of `BN`, `rlp`
58
59### ethjs-util methods
60
61The following methods are available by an internalized version of the [ethjs-util](https://github.com/ethjs/ethjs-util) package (`MIT` license), see [internal.ts](src/internal.ts). The original package is not maintained any more and the original functionality will be replaced by own implementations over time (starting with the `v7.1.3` release, October 2021).
62
63- arrayContainsArray
64- getBinarySize
65- stripHexPrefix
66- isHexPrefixed
67- isHexString
68- padToEven
69- fromAscii
70- fromUtf8
71- toUtf8
72- toAscii
73- getKeys
74
75They can be imported by name:
76
77```js
78import { stripHexPrefix } from 'ethereumjs-util'
79```
80
81### Re-Exports
82
83`ethereumjs-util` re-exports the following commonly-used libraries:
84
85- [BN.js](https://github.com/indutny/bn.js) (version `5.x`)
86- [rlp](https://github.com/ethereumjs/rlp) (version `2.x`)
87
88They can be imported by name:
89
90```js
91import { BN, rlp } from 'ethereumjs-util'
92```
93
94# EthereumJS
95
96See our organizational [documentation](https://ethereumjs.readthedocs.io) for an introduction to `EthereumJS` as well as information on current standards and best practices.
97
98If you want to join for work or do improvements on the libraries have a look at our [contribution guidelines](https://ethereumjs.readthedocs.io/en/latest/contributing.html).
99
100# LICENSE
101
102MPL-2.0
103
104[util-npm-badge]: https://img.shields.io/npm/v/ethereumjs-util.svg
105[util-npm-link]: https://www.npmjs.org/package/ethereumjs-util
106[util-issues-badge]: https://img.shields.io/github/issues/ethereumjs/ethereumjs-monorepo/package:%20util?label=issues
107[util-issues-link]: https://github.com/ethereumjs/ethereumjs-monorepo/issues?q=is%3Aopen+is%3Aissue+label%3A"package%3A+util"
108[util-actions-badge]: https://github.com/ethereumjs/ethereumjs-monorepo/workflows/Util/badge.svg
109[util-actions-link]: https://github.com/ethereumjs/ethereumjs-monorepo/actions?query=workflow%3A%22Util%22
110[util-coverage-badge]: https://codecov.io/gh/ethereumjs/ethereumjs-monorepo/branch/master/graph/badge.svg?flag=util
111[util-coverage-link]: https://codecov.io/gh/ethereumjs/ethereumjs-monorepo/tree/master/packages/util
112[discord-badge]: https://img.shields.io/static/v1?logo=discord&label=discord&message=Join&color=blue
113[discord-link]: https://discord.gg/TNwARpR