{"_id":"@doomjs/ethereumjs-util","name":"@doomjs/ethereumjs-util","dist-tags":{"latest":"9.0.0"},"versions":{"9.0.0":{"name":"@doomjs/ethereumjs-util","version":"9.0.0","description":"A collection of utility functions for Ethereum","keywords":["ethereum","utilities","utils"],"homepage":"https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/util#readme","bugs":{"url":"https://github.com/ethereumjs/ethereumjs-monorepo/issues?q=is%3Aissue+label%3A%22package%3A+util%22"},"repository":{"type":"git","url":"git+https://github.com/ethereumjs/ethereumjs-monorepo.git"},"license":"MPL-2.0","author":{"name":"EthereumJS Team"},"contributors":[{"name":"Tim Coulter","email":"tim@timothyjcoulter.com","url":"https://github.com/tcoulter"},{"name":"Nick Dodson","url":"https://github.com/SilentCicero"},{"name":"Mr. Chico","url":"https://github.com/MrChico"},{"name":"Dũng Trần","email":"tad88.dev@gmail.com","url":"https://github.com/tad88dev"},{"name":"Alex Beregszaszi","email":"alex@rtfs.hu","url":"https://github.com/axic"},{"name":"Taylor Gerring","url":"https://github.com/tgerring"},{"name":"Kirill Fomichev","email":"fanatid@ya.ru","url":"https://github.com/fanatid"},{"name":"kumavis","email":"aaron@kumavis.me","url":"https://github.com/kumavis"},{"name":"Alexander Sinyagin","email":"sinyagin.alexander@gmail.com","url":"https://github.com/asinyagin"}],"type":"commonjs","main":"dist/cjs/index.js","module":"dist/esm/index.js","exports":{".":{"import":"./dist/esm/index.js","require":"./dist/cjs/index.js"}},"scripts":{"build":"../../config/cli/ts-build.sh","clean":"../../config/cli/clean-package.sh","coverage":"npx vitest run --coverage.enabled --coverage.reporter=lcov","docs:build":"npx typedoc --options typedoc.cjs","examples":"ts-node ../../scripts/examples-runner.ts -- util","lint":"../../config/cli/lint.sh","lint:diff":"../../config/cli/lint-diff.sh","lint:fix":"../../config/cli/lint-fix.sh","test":"npm run test:node && npm run test:browser","test:browser":"npx vitest run --config=./vitest.config.browser.ts --browser.name=chrome --browser.headless","test:node":"npx vitest run","tsc":"../../config/cli/ts-compile.sh"},"dependencies":{"@doomjs/ethereumjs-rlp":"5.0.0","ethereum-cryptography":"^2.1.2"},"devDependencies":{},"peerDependencies":{"c-kzg":"^2.1.0"},"peerDependenciesMeta":{"c-kzg":{"optional":true}},"engines":{"node":">=18"},"publishConfig":{"access":"public","registry":"https://registry.npmjs.org/"},"types":"./dist/cjs/index.d.ts","gitHead":"c1950acac1518ff15dc128d58253df4de81760b8","_id":"@doomjs/ethereumjs-util@9.0.0","_nodeVersion":"18.17.0","_npmVersion":"9.6.7","dist":{"integrity":"sha512-L6ahGOD25CDKqQSgVXFy3ViWHl+T97zctB6ivfOMds82AR0MQYfKnYydqHCazm3AER47p3DiCNfIGWhGa7WEcg==","shasum":"134e256b86ab60c7807f679be4b8d0eaa7fe6fa4","tarball":"https://registry.npmjs.org/@doomjs/ethereumjs-util/-/ethereumjs-util-9.0.0.tgz","fileCount":169,"unpackedSize":462738,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQD5TLFpK38NpEVIGNEs/LGcyxe89i41zh+umLZFL2kaDgIhAPaWukY1KgemK7ESd1HksbKBzRKeEWhDVgQ3B64Tyd4m"}]},"_npmUser":{"name":"luoxm","email":"luoxianmingg@gmail.com"},"directories":{},"maintainers":[{"name":"luoxm","email":"luoxianmingg@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/ethereumjs-util_9.0.0_1689867326301_0.4021634319195644"},"_hasShrinkwrap":false}},"time":{"created":"2023-07-20T15:35:26.191Z","9.0.0":"2023-07-20T15:35:26.455Z","modified":"2023-07-20T15:35:26.747Z"},"maintainers":[{"name":"luoxm","email":"luoxianmingg@gmail.com"}],"description":"A collection of utility functions for Ethereum","homepage":"https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/util#readme","keywords":["ethereum","utilities","utils"],"repository":{"type":"git","url":"git+https://github.com/ethereumjs/ethereumjs-monorepo.git"},"contributors":[{"name":"Tim Coulter","email":"tim@timothyjcoulter.com","url":"https://github.com/tcoulter"},{"name":"Nick Dodson","url":"https://github.com/SilentCicero"},{"name":"Mr. Chico","url":"https://github.com/MrChico"},{"name":"Dũng Trần","email":"tad88.dev@gmail.com","url":"https://github.com/tad88dev"},{"name":"Alex Beregszaszi","email":"alex@rtfs.hu","url":"https://github.com/axic"},{"name":"Taylor Gerring","url":"https://github.com/tgerring"},{"name":"Kirill Fomichev","email":"fanatid@ya.ru","url":"https://github.com/fanatid"},{"name":"kumavis","email":"aaron@kumavis.me","url":"https://github.com/kumavis"},{"name":"Alexander Sinyagin","email":"sinyagin.alexander@gmail.com","url":"https://github.com/asinyagin"}],"author":{"name":"EthereumJS Team"},"bugs":{"url":"https://github.com/ethereumjs/ethereumjs-monorepo/issues?q=is%3Aissue+label%3A%22package%3A+util%22"},"license":"MPL-2.0","readme":"# @ethereumjs/util\n\n[![NPM Package][util-npm-badge]][util-npm-link]\n[![GitHub Issues][util-issues-badge]][util-issues-link]\n[![Actions Status][util-actions-badge]][util-actions-link]\n[![Code Coverage][util-coverage-badge]][util-coverage-link]\n[![Discord][discord-badge]][discord-link]\n\nNote: this README has been updated containing the changes from our next breaking release round [UNRELEASED] targeted for Summer 2023. See the README files from the [maintenance-v6](https://github.com/ethereumjs/ethereumjs-monorepo/tree/maintenance-v6/) branch for documentation matching our latest releases.\n\n| A collection of utility functions for Ethereum. |\n| ----------------------------------------------- |\n\n## Installation\n\nTo obtain the latest version, simply require the project using `npm`:\n\n```shell\nnpm install @ethereumjs/util\n```\n\n## Usage\n\n```js\nimport { hexToBytes, isValidChecksumAddress } from '@ethereumjs/util'\n\nisValidChecksumAddress('0x2F015C60E0be116B1f0CD534704Db9c92118FB6A') // true\n\nhexToBytes('0x342770c0')\n```\n\n## Browser\n\nWith the breaking release round in Summer 2023 we have added hybrid ESM/CJS builds for all our libraries (see section below) and have eliminated many of the caveats which had previously prevented a frictionless browser usage.\n\nIt is now easily possible to run a browser build of one of the EthereumJS libraries within a modern browser using the provided ESM build. For a setup example see [./examples/browser.html](./examples/browser.html).\n\n## API\n\n### Documentation\n\nRead the [API docs](docs/).\n\n### Modules\n\n- [account](src/account.ts)\n  - Account class\n  - Private/public key and address-related functionality (creation, validation, conversion)\n- [address](src/address.ts)\n  - Address class and type\n- [blobs](src/blobs.ts)\n  - Helpers for 4844 blobs and versioned hashes\n- [bytes](src/bytes.ts)\n  - Byte-related helper and conversion functions\n- [constants](src/constants.ts)\n  - Exposed constants (e.g. `KECCAK256_NULL_S` for string representation of Keccak-256 hash of null)\n- [db](src/db.ts)\n  - DB interface for database abstraction (Blockchain, Trie)\n- [genesis](src/genesis.ts)\n  - Genesis related interfaces and helpers\n- [internal](src/internal.ts)\n  - Internalized helper methods\n- [kzg](src/kzg.ts)\n  - KZG interface (used for 4844 blob txs)\n- [mapDB](src/mapDB.ts)\n  - Simple map DB implementation using the `DB` interface\n- [signature](src/signature.ts)\n  - Signing, signature validation, conversion, recovery\n- [types](src/types.ts)\n  - Helpful TypeScript types\n- [withdrawal](src/withdrawal.ts)\n  - Withdrawal class (EIP-4895)\n\n### Upgrade Helpers in bytes-Module\n\nDepending on the extend of `Buffer` usage within your own libraries and other planning considerations, there are the two upgrade options to do the switch to `Uint8Array` yourself or keep `Buffer` and do transitions for input and output values.\n\nWe have updated the `@ethereumjs/util` `bytes` module with helpers for the most common conversions:\n\n```typescript\nBuffer.alloc(97) // Allocate a Buffer with length 97\nnew Uint8Array(97) // Allocate a Uint8Array with length 97\n\nBuffer.from('342770c0', 'hex') // Convert a hex string to a Buffer\nhexToBytes('0x342770c0') // Convert a prefixed hex string to a Uint8Array, Util.hexToBytes()\n\n`0x${myBuffer.toString('hex')}` // Convert a Buffer to a prefixed hex string\nbytesToHex(myUint8Array) // Convert a Uint8Array to a prefixed hex string\n\nintToBuffer(9) // Convert an integer to a Buffer, old (removed)\nintToBytes(9) // Convert an integer to a Uint8Array, Util.intToBytes()\nbytesToInt(myUint8Array) // Convert a Uint8Array to an integer, Util.bytesToInt()\n\nbigIntToBytes(myBigInt) // Convert a BigInt to a Uint8Array, Util.bigIntToBytes()\nbytesToBigInt(myUint8Array) // Convert a Uint8Array to a BigInt, Util.bytesToInt()\n\nutf8ToBytes(myUtf8String) // Converts a UTF-8 string to a Uint8Array, Util.utf8ToBytes()\nbytesToUtf8(myUint8Array) // Converts a Uint8Array to a UTF-8 string, Util.bytesToUtf8()\n\ntoBuffer(v: ToBufferInputTypes) // Converts various byte compatible types to Buffer, old (removed)\ntoBytes(v: ToBytesInputTypes) // Converts various byte compatible types to Uint8Array, Util.toBytes()\n```\n\nHelper methods can be imported like this:\n\n```typescript\nimport { hexToBytes } from '@ethereumjs/util'\n```\n\n### Hybrid CJS/ESM Builds\n\nWith the breaking releases from Summer 2023 we have started to ship our libraries with both CommonJS (`cjs` folder) and ESM builds (`esm` folder), see `package.json` for the detailed setup.\n\nIf you use an ES6-style `import` in your code files from the ESM build will be used:\n\n```typescript\nimport { EthereumJSClass } from '@ethereumjs/[PACKAGE_NAME]'\n```\n\nIf you use Node.js specific `require`, the CJS build will be used:\n\n```typescript\nconst { EthereumJSClass } = require('@ethereumjs/[PACKAGE_NAME]')\n```\n\nUsing ESM will give you additional advantages over CJS beyond browser usage like static code analysis / Tree Shaking which CJS can not provide.\n\n### Buffer -> Uint8Array\n\nWith the breaking releases from Summer 2023 we have removed all Node.js specific `Buffer` usages from our libraries and replace these with [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) representations, which are available both in Node.js and the browser (`Buffer` is a subclass of `Uint8Array`).\n\nWe have converted existing Buffer conversion methods to Uint8Array conversion methods in the [@ethereumjs/util](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/util) `bytes` module, see the respective README section for guidance.\n\n### BigInt Support\n\nStarting with Util v8 the usage of [BN.js](https://github.com/indutny/bn.js/) for big numbers has been removed from the library and replaced with the usage of the native JS [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) data type (introduced in `ES2020`).\n\nPlease note that number-related API signatures have changed along with this version update and the minimal build target has been updated to `ES2020`.\n\n### ethjs-util methods\n\nThe 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).\n\n- arrayContainsArray\n- getBinarySize\n- stripHexPrefix\n- isHexPrefixed\n- isHexString\n- padToEven\n- fromAscii\n- fromUtf8\n- toUtf8\n- toAscii\n- getKeys\n\nThey can be imported by name:\n\n```typescript\nimport { stripHexPrefix } from '@ethereumjs/util'\n```\n\n## EthereumJS\n\nSee our organizational [documentation](https://ethereumjs.readthedocs.io) for an introduction to `EthereumJS` as well as information on current standards and best practices. If you want to join for work or carry out improvements on the libraries, please review our [contribution guidelines](https://ethereumjs.readthedocs.io/en/latest/contributing.html) first.\n\n## License\n\n[MPL-2.0](<https://tldrlegal.com/license/mozilla-public-license-2.0-(mpl-2)>)\n\n[util-npm-badge]: https://img.shields.io/npm/v/@ethereumjs/util.svg\n[util-npm-link]: https://www.npmjs.org/package/@ethereumjs/util\n[util-issues-badge]: https://img.shields.io/github/issues/ethereumjs/ethereumjs-monorepo/package:%20util?label=issues\n[util-issues-link]: https://github.com/ethereumjs/ethereumjs-monorepo/issues?q=is%3Aopen+is%3Aissue+label%3A\"package%3A+util\"\n[util-actions-badge]: https://github.com/ethereumjs/ethereumjs-monorepo/workflows/Util/badge.svg\n[util-actions-link]: https://github.com/ethereumjs/ethereumjs-monorepo/actions?query=workflow%3A%22Util%22\n[util-coverage-badge]: https://codecov.io/gh/ethereumjs/ethereumjs-monorepo/branch/master/graph/badge.svg?flag=util\n[util-coverage-link]: https://codecov.io/gh/ethereumjs/ethereumjs-monorepo/tree/master/packages/util\n[discord-badge]: https://img.shields.io/static/v1?logo=discord&label=discord&message=Join&color=blue\n[discord-link]: https://discord.gg/TNwARpR\n","readmeFilename":"README.md"}