{"bugs":{"url":"https://github.com/trufflesuite/truffle/issues"},"dist":{"shasum":"2cb1851b5e2cefef5cd3398e8442d7b473e84485","tarball":"https://registry.npmjs.org/@truffle/abi-utils/-/abi-utils-0.3.10-visual-debugger.0.tgz","fileCount":39,"integrity":"sha512-klcAZdItF9L8iDPfXZWPrpqNInhAqdxO/wWD8cNG6km4woLBbbu9hXxlIjJ68yC7d6jJb6sXum4RXkmiV+jPaw==","signatures":[{"sig":"MEYCIQC17lzxY92szlUx5f8G55brb6PNidETvG88sKe7z4MxtwIhAOYUb2dCG5RvXj29DG8R05C1RuUzz70p8y5xQhwWkRFn","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":67807},"main":"dist/lib/index.js","name":"@truffle/abi-utils","types":"dist/lib/index.d.ts","author":{"name":"g. nicholas d'andrea","email":"gnidan@trufflesuite.com"},"readme":"# `@truffle/abi-utils`\n\nContains a few utilities for dealing with ABIs.\n\n## Contents\n\nThis package contains a few different components:\n\n- [Normalize ABIs](#normalize-abis)\n- [TypeScript types](#typescript-types)\n- [Selector and signature computation](#selector-and-signature-computation)\n- [Arbitrary random ABIs](#arbitrary-random-abis)\n\n## Normalize ABIs\n\n> ```typescript\n> // handle function entries omitting \"type\" from JSON\n> const isFunctionEntry = entry.type === \"function\" || !(\"type\" in entry);\n>\n> // handle:        v--- new way                           v--- old way     v--- default\n> const isPayable =\n>   entry.stateMutability === \"payable\" || entry.payable || false;\n>\n> // handle \"outputs\" possibly being undefined\n> const outputs = entry.outputs || [];\n> ```\n>\n> _^ Have you ever had to do this sort of thing?_ :scream:\n\nSolidity's official [JSON ABI specification](https://solidity.readthedocs.io/en/v0.7.3/abi-spec.html)\nis rather permissive, since it remains backwards compatible with older\nversions of the language and because it permits omitting fields with default\nvalues. This can get annoying if you're programmatically processing ABIs.\n\n:information_source: This package provides a `normalize` function to purge\nthese kinds of inconsistencies.\n\n```javascript\nconst { normalize } = require(\"@truffle/abi-utils\");\n```\n\n```typescript\nimport { normalize } from \"@truffle/abi-utils\";\n```\n\nSpecifically, this normalizes by:\n\n- Ensuring every ABI entry has a `type` field, since it's optional for\n  `type: \"function\"`\n- Populating default value `[]` for function `outputs` field\n- Removing all instances of the legacy `payable` and `constant` fields\n- Replacing those two fields with the newer `stateMutability` field\n\nTo use, provide the ABI as a JavaScript array, as the sole argument to the\nfunction:\n\n```typescript\n// accepts ABIs from Solidity versions back to 0.4.12 or earlier!\nconst abi = normalize([{\"type\": \"constructor\"/*, ...*/}/*, ...*/);\n\n// don't even worry about it\nconst isFunctionEntry = entry.type === \"function\";\nconst isPayable = entry.stateMutability === \"payable\";\n```\n\n## TypeScript types\n\nThis package exports the following types for **normalized** ABIs.\n\n- `Abi`, to represent the full ABI array\n- `Entry`, to represent items in ABI arrays\n- `FunctionEntry`, to represent named functions\n- `ConstructorEntry`, to represent constructors\n- `FallbackEntry`, to represent old or new fallback functions\n- `ReceiveEntry`, to represent receive functions\n- `Parameter`, to represent parameters defined in entry inputs or outputs\n- `EventParameter`, to represent event parameters\n\nTo use these, you should first call [`normalize`](#normalize-abis), described\nabove.\n\n```typescript\nimport * as Abi from \"@truffle/abi-utils\";\n\nconst abi: Abi.Abi = [{ type: \"constructor\" /*, ...*/ } /*, ...*/];\nconst parameter: Abi.Parameter = {\n  type: \"tuple[]\",\n  components: [\n    /*...*/\n  ]\n};\n// etc.\n```\n\n## Selector and signature computation\n\nThis package exports the following functions for computing signatures and selectors:\n\n- `abiSelector`: This function takes a `FunctionEntry`, `EventEntry`, or\n  `ErrorEntry` and computes its selector, returned as a hex string. This will\n  be 4 bytes for a function or error, and 32 bytes for an event.\n- `abiSignature`: This function takes a `FunctionEntry`, `EventEntry`, or\n  `ErrorEntry` and computes its written-out signature (e.g., `\"setStoredValue(uint256)\"`).\n- `abiTupleSignature`: This function takes a `Parameter[]` and computes the signature\n  of that tuple on its own; e.g., `\"(uint256,string)\"` for a `uint` and a `string`.\n- `abiTypeSignature`: This function takes an individual `Parameter` and computes\n  the signature of that type on its own; e.g., `uint256` for a `uint`.\n\nIn addition, the package also exports the constant `ShortSelectorSize`, which\nis equal to 4 (the number of bytes in a function or event selector).\n\n## Arbitrary random ABIs\n\n_Do you need to test all the different kinds of ABIs, including testing your\nsupport for the various quirks across different Solidity versions?_ :flushed:\n\nYou can use this package for generating all sorts of random ABIs, random ABI\nevents, random ABI parameter values, etc.\n\nThis package provides [fast-check](https://github.com/dubzzz/fast-check)\narbitraries for property-based testing methodologies. If you're not familiar\nwith fast-check or property-based testing, please see the link above for more\ninformation.\n\n```typescript\nimport * as fc from \"fast-check\";\nimport { Arbitrary } from \"@truffle/abi-utils\";\n\n// generate 10 random ABIs\nconst randomAbis = fc.sample(Arbitrary.Abi(), 10);\n```\n\nSee this package's [internal tests for `normalize`](./lib/normalize.test.ts)\nfor example usage in automated tests.\n","gitHead":"16365cc592b2c381ae597b7c0d51b67839fa8f62","license":"MIT","scripts":{"test":"jest lib/**","build":"tsc","prepare":"yarn build"},"_npmUser":{"name":"eggplantzzz","email":"pobol234@gmail.com"},"homepage":"https://github.com/trufflesuite/truffle/tree/master/packages/abi-utils#readme","keywords":["abi","ethereum","solidity"],"deprecated":"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.","repository":{"url":"git+https://github.com/trufflesuite/truffle.git","type":"git","directory":"packages/abi-utils"},"_npmVersion":"lerna/5.6.2/node@v14.21.2+x64 (darwin)","description":"Utilities for working with ABIs","directories":{},"maintainers":[{"name":"cliffoo","email":"cliffzhang08@gmail.com"},{"name":"kevinbluer","email":"kevin@bluer.com"},{"name":"gnidan","email":"nick@gnidan.org"},{"name":"haltman","email":"harry.j.altman@gmail.com"},{"name":"eggplantzzz","email":"pobol234@gmail.com"},{"name":"fainashalts","email":"fainashalts@gmail.com"},{"name":"cds-amal","email":"cds.sudama@gmail.com"}],"_nodeVersion":"14.21.2","dependencies":{"fast-check":"3.1.1","web3-utils":"1.8.2","change-case":"3.0.2"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jest":"29.1.2","ts-jest":"29.0.3","ts-node":"10.7.0","typescript":"^4.7.4","@types/jest":"27.4.1","@types/node":"~12.12.0","jest-extended":"^0.11.5","@fast-check/jest":"^1.0.1","jest-json-schema":"^2.1.0","@types/jest-json-schema":"^2.1.2","@truffle/contract-schema":"^3.4.14-visual-debugger.0"},"_npmOperationalInternal":{"tmp":"tmp/abi-utils_0.3.10-visual-debugger.0_1683934663782_0.8809440715079144","host":"s3://npm-registry-packages"},"_id":"@truffle/abi-utils@0.3.10-visual-debugger.0","version":"0.3.10-visual-debugger.0"}