{"name":"@ethereumjs/util","version":"8.0.4","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"}],"main":"dist/index.js","types":"dist/index.d.ts","scripts":{"build":"../../config/cli/ts-build.sh","clean":"../../config/cli/clean-package.sh","coverage":"../../config/cli/coverage.sh","docs:build":"npx typedoc --options typedoc.js","lint":"../../config/cli/lint.sh","lint:diff":"../../config/cli/lint-diff.sh","lint:fix":"../../config/cli/lint-fix.sh","prepublishOnly":"../../config/cli/prepublish.sh","tape":"tape -r ts-node/register","test":"npm run test:node && npm run test:browser","test:browser":"karma start karma.conf.js","test:node":"npm run tape -- test/*.spec.ts","tsc":"../../config/cli/ts-compile.sh"},"dependencies":{"@chainsafe/ssz":"^0.10.0","@ethereumjs/rlp":"^4.0.1","ethereum-cryptography":"^1.1.2"},"devDependencies":{"@types/bn.js":"^5.1.0","@types/secp256k1":"^4.0.1"},"engines":{"node":">=14"},"gitHead":"47c293da1f849f05000e7e70061d62d571ff3920","_id":"@ethereumjs/util@8.0.4","_nodeVersion":"18.13.0","_npmVersion":"8.19.3","dist":{"integrity":"sha512-tX2k9fG6eWBq5qby3VT1KgQT8iqnmwMYeDPJ/oyVdOcYKTiCBdkSBNtCWLh0vp3bIWUOjNRyPdwsYu73CyFCNA==","shasum":"a5bdf0009e2e23f2c821369f718f8a404f59def4","tarball":"http://registry-npm.ywwl.com/@ethereumjs/util/download/@ethereumjs/util-8.0.4.tgz","fileCount":73,"unpackedSize":223939,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCkJYSexm8z+RmfLZwXs5i8X4hSRJrUqcpJtAWHHxP7NgIgNCtrDjCy2Ic8AJhyLw74Naqh9Vr8UDhEEGFl733i6JM="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJj+H1SACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmr20RAAidEQFKjIOJDFvLpklPdND4VTtI/YA5ru73wDodKPq3t2SSJc\r\na3yvsi3IiT1yX1l2OmzJGgfw9+n1bEbZTXm/4dJSAf9Er5GaXhmCj8YEIIHs\r\n/XZYPQYAcovxxMAzNvgVnifdIjY23YWMkSuT2tq9NIuNlHCK5xNbJMBwzDty\r\n+x63iWGUgfh+lEsk/3Lemk7V1eibvJEmv+7NNbjvqlcxu3OQfuEVmUJe/PKa\r\nhBNTOWFC5hJW9o8Y9K+6kO1FIOLCND9hKZU1qBPMJG+x+fd+3KdFksSwZXnC\r\n2IPt9qaeTb3RoSvmHOvBhxE0Dj/Mrdh3bMCcmDM8NFaJlw0rwM+2KNPbZ/GF\r\nCrToFzsb5Pc88iQFn4VwhrC7MGEBmjz3fcE0vlMjs0VGkuWGQAQRPrDitBQ0\r\nJfI68garwg6fSaTpBTDGyC4wAHYXQ4/ykqwe8guqdPfTZr0oqcIVItNLQAAz\r\nhtU2byA3neDUNBRM+OmqsKhJGowJxXJz4CDTLIAsglqTj4fEuv8tMEUQyq+s\r\n/l9H8WsaL8TtlnOC+vaPltEODI4c/0NP4Wc5/kVBpYYBhXfAAF/29vr/TO6b\r\n/VioKDaxaY9HOh+v0RnakYCdLnUbPDsGxziO3fL8cGtypHfWMrglUcCgcBVe\r\nZddrWZbfFACqSSeSYequ9j+rFvashY4p5vw=\r\n=CwNi\r\n-----END PGP SIGNATURE-----\r\n","size":52858,"noattachment":false,"key":"/@ethereumjs/util/-/@ethereumjs/util-8.0.4.tgz"},"_npmUser":{"name":"holgerd77","email":"Holger.Drewes@gmail.com"},"directories":{},"maintainers":[{"name":"axic","email":"alex@rtfs.hu"},{"name":"holgerd77","email":"Holger.Drewes@gmail.com"},{"name":"ralxz","email":"ryan@ryanio.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/util_8.0.4_1677229394449_0.14420021598567234"},"_hasShrinkwrap":false,"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\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\nThis package contains the following modules providing respective helper methods, classes and commonly re-used constants.\n\nAll helpers are re-exported from the root level and deep imports are not necessary. So an import can be done like this:\n\n```ts\nimport { hexToBytes, isValidChecksumAddress } from '@ethereumjs/util'\n```\n\n### Module: [account](src/account.ts)\n\nClass representing an `Account` and providing private/public key and address-related functionality (creation, validation, conversion).\n\n```ts\n// ./examples/account.ts\n\nimport { Account } from '@ethereumjs/util'\n\nconst account = Account.fromAccountData({\n  nonce: '0x02',\n  balance: '0x0384',\n  storageRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421',\n  codeHash: '0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470',\n})\nconsole.log(`Account with nonce=${account.nonce} and balance=${account.balance} created`)\n```\n\n### Module: [address](src/address.ts)\n\nClass representing an Ethereum `Address` with instantiation helpers and validation methods.\n\n```ts\n// ./examples/address.ts\n\nimport { Address } from '@ethereumjs/util'\n\nconst address = Address.fromString('0x2f015c60e0be116b1f0cd534704db9c92118fb6a')\nconsole.log(`Ethereum address ${address.toString()} created`)\n```\n\n### Module: [blobs](src/blobs.ts)\n\nModule providing helpers for 4844 blobs and versioned hashes.\n\n```ts\n// ./examples/blobs.ts\n\nimport { bytesToHex, computeVersionedHash, getBlobs } from '@ethereumjs/util'\n\nconst blobs = getBlobs('test input')\n\nconsole.log('Created the following blobs:')\nconsole.log(blobs)\n\nconst commitment = new Uint8Array([1, 2, 3])\nconst blobCommitmentVersion = 0x01\nconst versionedHash = computeVersionedHash(commitment, blobCommitmentVersion)\n\nconsole.log(`Versioned hash ${bytesToHex(versionedHash)} computed`)\n```\n\n### Module: [bytes](src/bytes.ts)\n\nByte-related helper and conversion functions.\n\n```ts\n// ./examples/bytes.ts\n\nimport { bytesToBigInt } from '@ethereumjs/util'\n\nconst bytesValue = new Uint8Array([97])\nconst bigIntValue = bytesToBigInt(bytesValue)\n\nconsole.log(`Converted value: ${bigIntValue}`)\n```\n\n### Module: [constants](src/constants.ts)\n\nExposed constants (e.g. `KECCAK256_NULL_S` for string representation of Keccak-256 hash of null)\n\n```ts\n// ./examples/constants.ts\n\nimport { BIGINT_2EXP96, KECCAK256_NULL_S } from '@ethereumjs/util'\n\nconsole.log(`The keccak-256 hash of null: ${KECCAK256_NULL_S}`)\nconsole.log(`BigInt constants (performance), e.g. BIGINT_2EXP96: ${BIGINT_2EXP96}`)\n```\n\n### Module: [db](src/db.ts)\n\nDB interface for database abstraction (Blockchain, Trie), see e.g. [@ethereumjs/trie recipes](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/trie/recipes/level.ts)) for usage.\n\n### Module: [genesis](src/genesis.ts)\n\nGenesis related interfaces and helpers.\n\n### Module: [internal](src/internal.ts)\n\nInternalized simple helper methods like `isHexPrefixed`. Note that methods from this module might get deprectared in the future.\n\n### Module: [kzg](src/kzg.ts)\n\nKZG interface (used for 4844 blob txs), see [@ethereumjs/tx](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/tx/README.md#kzg-setup) README for main usage instructions.\n\n### Module: [mapDB](src/mapDB.ts)\n\nSimple map DB implementation using the `DB` interface (see above).\n\n### Module: [signature](src/signature.ts)\n\nFunctionality for signing, signature validation, conversion, recovery.\n\n```ts\n// ./examples/signature.ts\n\nimport { bytesToHex, ecrecover, hexToBytes } from '@ethereumjs/util'\n\nconst chainId = BigInt(3) // Ropsten\n\nconst echash = hexToBytes('0x82ff40c0a986c6a5cfad4ddf4c3aa6996f1a7837f9c398e17e5de5cbd5a12b28')\nconst r = hexToBytes('0x99e71a99cb2270b8cac5254f9e99b6210c6c10224a1579cf389ef88b20a1abe9')\nconst s = hexToBytes('0x129ff05af364204442bdb53ab6f18a99ab48acc9326fa689f228040429e3ca66')\nconst v = BigInt(41)\n\nconst pubkey = ecrecover(echash, v, r, s, chainId)\n\nconsole.log(`Recovered public key ${bytesToHex(pubkey)} from valid signature values`)\n```\n\n### Module: [types](src/types.ts)\n\nVarious TypeScript types. Direct usage is not recommended, type structure might change in the future.\n\n### Module: [withdrawal](src/withdrawal.ts)\n\nClass representing an `EIP-4895` `Withdrawal` with different constructors as well as conversion and output helpers.\n\n```ts\n// ./examples/withdrawal.ts\n\nimport { Withdrawal } from '@ethereumjs/util'\n\nconst withdrawal = Withdrawal.fromWithdrawalData({\n  index: 0n,\n  validatorIndex: 65535n,\n  address: '0x0000000000000000000000000000000000000000',\n  amount: 0n,\n})\n\nconsole.log('Withdrawal object created:')\nconsole.log(withdrawal.toJSON())\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### 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```ts\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```ts\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```ts\nimport { EthereumJSClass } from '@ethereumjs/[PACKAGE_NAME]'\n```\n\nIf you use Node.js specific `require`, the CJS build will be used:\n\n```ts\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```ts\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","publish_time":1677229394586,"_cnpm_publish_time":1677229394586,"dist-tags":{"alpha":"10.0.0-alpha.1","beta":"8.0.0-beta.3","latest":"10.1.3","nightly":"10.1.1-nightly.2","rc":"10.0.0-rc.1"}}