UNPKG

3.84 kBMarkdownView Raw
1# SYNOPSIS
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
21const address = '0x2F015C60E0be116B1f0CD534704Db9c92118FB6A'
22assert.ok(isValidChecksumAddress(address))
23
24assert.equal(unpadBuffer(Buffer.from('000000006600', 'hex')), Buffer.from('6600', 'hex'))
25
26assert.equal(new BN('dead', 16).add(new BN('101010', 2)), 57047)
27```
28
29# API
30
31## Documentation
32
33### Modules
34
35- [account](src/account.md)
36 - Account class
37 - Private/public key and address-related functionality (creation, validation, conversion)
38- [address](src/address.md)
39 - Address class and type
40- [bytes](src/bytes.md)
41 - Byte-related helper and conversion functions
42- [constants](src/constants.md)
43 - Exposed constants
44 - e.g. KECCAK256_NULL_S for string representation of Keccak-256 hash of null
45- [hash](src/hash.md)
46 - Hash functions
47- [object](src/object.md)
48 - Helper function for creating a binary object (`DEPRECATED`)
49- [signature](src/signature.md)
50 - Signing, signature validation, conversion, recovery
51- [types](src/types.md)
52 - Helpful TypeScript types
53- [externals](src/externals.md)
54 - Helper methods from `ethjs-util`
55 - Re-exports of `BN`, `rlp`
56
57Also see [API docs](docs/).
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
88# EthereumJS
89
90See our organizational [documentation](https://ethereumjs.readthedocs.io) for an introduction to `EthereumJS` as well as information on current standards and best practices.
91
92If 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).
93
94# LICENSE
95
96MPL-2.0
97
98[util-npm-badge]: https://img.shields.io/npm/v/ethereumjs-util.svg
99[util-npm-link]: https://www.npmjs.org/package/ethereumjs-util
100[util-issues-badge]: https://img.shields.io/github/issues/ethereumjs/ethereumjs-monorepo/package:%20util?label=issues
101[util-issues-link]: https://github.com/ethereumjs/ethereumjs-monorepo/issues?q=is%3Aopen+is%3Aissue+label%3A"package%3A+util"
102[util-actions-badge]: https://github.com/ethereumjs/ethereumjs-monorepo/workflows/Util/badge.svg
103[util-actions-link]: https://github.com/ethereumjs/ethereumjs-monorepo/actions?query=workflow%3A%22Util%22
104[util-coverage-badge]: https://codecov.io/gh/ethereumjs/ethereumjs-monorepo/branch/master/graph/badge.svg?flag=util
105[util-coverage-link]: https://codecov.io/gh/ethereumjs/ethereumjs-monorepo/tree/master/packages/util
106[discord-badge]: https://img.shields.io/static/v1?logo=discord&label=discord&message=Join&color=blue
107[discord-link]: https://discord.gg/TNwARpR