{"name":"@taquito/utils","version":"24.1.0","keywords":["tezos","blockchain","michelson","smart-contract"],"author":{"name":"Simon Boissonneault-Robert","email":"simon@ecadlabs.com"},"license":"Apache-2.0","_id":"@taquito/utils@24.1.0","maintainers":[{"name":"jevonearth","email":"jev@ecadlabs.com"},{"name":"roxaneletourneau","email":"roxane@ecadlabs.com"},{"name":"hui-an.yang","email":"hui-an.yang@ecadlabs.com"},{"name":"gimbrailo.ecad","email":"gino@ecadlabs.com"}],"dist":{"shasum":"7e36119d9932d7a492374d8b210ca55db57703cc","tarball":"http://registry-npm.ywwl.com/@taquito/utils/download/@taquito/utils-24.1.0.tgz","fileCount":24,"integrity":"sha512-3dcrXXLUyghzwydvHYyWSMEsTkIj4tZG9sqLk4sLPMsbX1XDL2bq+1s3V9hAHl+E83BgPxiysu+QjcGj0YFqEQ==","signatures":[{"sig":"MEYCIQCN085sM5saK7M4tKDRL9AdC4lSOEo8VAkTbV9zdcR9HwIhAPwyh/OKvEOPcpmiUhLuqKp5aeyOtkO4U8znzpB0efRw","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":316163,"size":69196,"noattachment":false,"key":"/@taquito/utils/-/@taquito/utils-24.1.0.tgz"},"jest":{"testRegex":"(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$","transform":{".(ts|tsx)":"ts-jest"},"testEnvironment":"node","collectCoverageFrom":["src/**/*.{js,ts}"],"moduleFileExtensions":["ts","tsx","js"],"coveragePathIgnorePatterns":["/node_modules/","/test/"]},"main":"dist/taquito-utils.umd.js","module":"dist/taquito-utils.es6.js","engines":{"node":">=20"},"gitHead":"dc65bb045c8e7a7d8ba9fcca97c03b7d6892c95c","scripts":{"lint":"eslint --ext .js,.ts .","test":"jest","build":"tsc --project ./tsconfig.prod.json --module commonjs && rollup -c rollup.config.ts --bundleConfigAsCjs","start":"rollup -c rollup.config.ts --bundleConfigAsCjs -w","prebuild":"rimraf dist","precommit":"lint-staged","version-stamp":"node ../taquito/version-stamping.js"},"typings":"dist/types/taquito-utils.d.ts","_npmUser":{"name":"hui-an.yang","email":"hui-an.yang@ecadlabs.com"},"repository":{"url":"","type":"git"},"_npmVersion":"lerna/9.0.4/node@v20.19.5+arm64 (darwin)","description":"converts michelson data and types into convenient JS/TS objects","directories":{},"lint-staged":{"{src,test}/**/*.ts":["prettier --write","eslint --fix"]},"_nodeVersion":"20.19.5","dependencies":{"buffer":"^6.0.3","blakejs":"^1.2.1","bs58check":"^3.0.1","bignumber.js":"^9.1.2","@noble/curves":"^1.9.7","@taquito/core":"^24.1.0","@types/bs58check":"^2.1.2","@stablelib/blake2b":"^1.0.1","@stablelib/ed25519":"^1.0.3","typedarray-to-buffer":"^4.0.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.7.0","colors":"^1.4.0","eslint":"^8.57.0","prompt":"^1.3.0","rimraf":"^6.0.1","rollup":"^4.22.4","shelljs":"^0.8.5","ts-jest":"^29.2.3","ts-node":"^10.9.2","prettier":"^3.3.3","coveralls":"^3.1.1","cross-env":"^7.0.3","typescript":"~5.5.4","@types/jest":"^29.5.12","@types/node":"^20","jest-config":"^29.7.0","lint-staged":"^15.2.7","ts-toolbelt":"^9.6.0","@types/bluebird":"^3.5.42","replace-in-file":"^8.1.0","lodash.camelcase":"^4.3.0","rollup-plugin-json":"^4.0.0","@typescript-eslint/parser":"^6.21.0","rollup-plugin-typescript2":"^0.36.0","@types/typedarray-to-buffer":"^4.0.4","rollup-plugin-polyfill-node":"^0.13.0","@typescript-eslint/eslint-plugin":"^6.21.0"},"_npmOperationalInternal":{"tmp":"tmp/utils_24.1.0_1772247507093_0.4011830978290769","host":"s3://npm-registry-packages-npm-production"},"readme":"# Taquito Utils package\n*TypeDoc style documentation is available on-line [here](https://taquito.io/typedoc/modules/_taquito_utils.html)*\n\n`@taquito/utils` is an npm package that provides developers with utility functionality for Taquito.\n\n## Install\n\n```\nnpm i --save @taquito/utils\n```\n\n## Usage\n\n### Validation functions\n\nTaquito provides functions that allow seeing if an address, a chain, a key hash, a contract address, a public key, a signature, a block hash, an operation hash, or a protocol hash is valid based on checksums.\n\nThe `ValidationResult` returned by these functions is an enum that can take the following values:\n\n```\n0 = NO_PREFIX_MATCHED,\n1 = INVALID_CHECKSUM,\n2 = INVALID_LENGTH,\n3 = VALID,\n4 = PREFIX_NOT_ALLOWED,\n5 = INVALID_ENCODING,\n6 = OTHER,\n```\n\n**Address validation (tz1, tz2, tz3, KT1)**\n\n```ts\nimport { validateAddress } from '@taquito/utils';\n\nconst pkh = 'tz1L9r8mWmRPndRhuvMCWESLGSVeFzQ9NAWx';\nconsole.log(validateAddress(pkh));\n// output: 3 which is valid\n```\n\n**Key hash validation**\n\n```ts\nimport { validateKeyHash } from '@taquito/utils';\n\nconst keyHash = 'tz1L9r8mWmRPndRhuvMCWESLGSVeFzQ9NAWx';\nconsole.log(validateKeyHash(keyHash));\n// output: 3 which is valid\n```\n\n**Contract address validation**\n\n```ts\nimport { validateContractAddress } from '@taquito/utils';\n\nconst contractAddress = 'KT1J4E79F1qL6kGBSQ3yXBdXmuq5j4FNThK2';\nconsole.log(validateContractAddress(contractAddress));\n// output: 3 which is valid\n```\n\n**Chain id validation**\n\n```ts\nimport { validateChain } from '@taquito/utils';\n\nconst chainId = 'NetXdQprcVkpaWU';\nconsole.log(validateChain(chainId));\n// output: 3 which is valid\n```\n\n**Public key validation**\n\n```ts\nimport { validatePublicKey } from '@taquito/utils';\n\nconst publicKey = 'edpkvS5QFv7KRGfa3b87gg9DBpxSm3NpSwnjhUjNBQrRUUR66F7C9g';\nconsole.log(validatePublicKey(publicKey));\n// output: 3 which is valid\n```\n\n**Signature validation**\n\n```ts\nimport { validateSignature } from '@taquito/utils';\n\nconst signature = 'edsigtkpiSSschcaCt9pUVrpNPf7TTcgvgDEDD6NCEHMy8NNQJCGnMfLZzYoQj74yLjo9wx6MPVV29CvVzgi7qEcEUok3k7AuMg';\nconsole.log(validateSignature(signature));\n// output: 3 which is valid\n```\n\n**Block hash validation**\n\n```ts\nimport { validateBlock } from '@taquito/utils';\n\nconst block ='BLJjnzaPtSsxykZ9pLTFLSfsKuiN3z7SjSPDPWwbE4Q68u5EpBw';\nconsole.log(validateBlock(block));\n// output: 3 which is valid\n```\n\n**Operation hash validation**\n\n```ts\nimport { validateOperation } from '@taquito/utils';\n\nconst operation ='ood2Y1FLHH9izvYghVcDGGAkvJFo1CgSEjPfWvGsaz3qypCmeUj';\nconsole.log(validateOperation(operation));\n// output: 3 which is valid\n```\n\n**Protocol hash validation**\n\n```ts\nimport { validateProtocol } from '@taquito/utils';\n\n//valid\nconst protocol ='PtHangz2aRngywmSRGGvrcTyMbbdpWdpFKuS4uMWxg2RaH9i1qx';\nconsole.log(validateProtocol(protocol));\n// output: 3 which is valid\n```\n\n### Verification of a signature\n\nThe function takes a message, a public key, and a signature as parameters and returns a boolean indicating if the signature matches.\n\n```ts\nimport { verifySignature } from '@taquito/utils';\n\nconst message = '03d0c10e3ed11d7c6e3357f6ef335bab9e8f2bd54d0ce20c482e241191a6e4b8ce6c01be917311d9ac46959750e405d57e268e2ed9e174a80794fbd504e12a4a000141eb3781afed2f69679ff2bbe1c5375950b0e40d00ff000000005e05050505050507070100000024747a32526773486e74516b72794670707352466261313652546656503539684b72654a4d07070100000024747a315a6672455263414c42776d4171776f6e525859565142445439426a4e6a42484a750001';\nconst pk = 'sppk7c7hkPj47yjYFEHX85q46sFJGw6RBrqoVSHwAJAT4e14KJwzoey';\nconst sig = 'spsig1cdLkp1RLgUHAp13aRFkZ6MQDPp7xCnjAExGL3MBSdMDmT6JgQSX8cufyDgJRM3sinFtiCzLbsyP6d365EHoNevxhT47nx'\n\nconst isValid = verifySignature(message, pk, sig);\nconsole.log(isValid);\n// output: true\n```\n\n### Utility functions\n\n**Conversion between hexadecimal and ASCII strings**\n```ts\nimport { stringToBytes, bytesToString } from '@taquito/utils';\n\nconst url = 'https://storage.googleapis.com/tzip-16/fa2-views.json';\nconst hex = '68747470733a2f2f73746f726167652e676f6f676c65617069732e636f6d2f747a69702d31362f6661322d76696577732e6a736f6e';\n\nconsole.log(stringToBytes(url));\n// output: 68747470733a2f2f73746f726167652e676f6f676c65617069732e636f6d2f747a69702d31362f6661322d76696577732e6a736f6e\n\nconsole.log(bytesToString(hex));\n// output: https://storage.googleapis.com/tzip-16/fa2-views.json\n```\n\n**Conversion between buffer and hexadecimal strings**\n\n```ts\nimport { buf2hex, hex2buf } from '@taquito/utils';\n\nconst buffer = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);\nconst hex = '627566666572'\n\nconsole.log(buf2hex(buffer));\n// output: 627566666572\n\nconsole.log(hex2buf(hex));\n// output: Uint8Array(6) [ 98, 117, 102, 102, 101, 114 ]\n```\n\n**Merge 2 buffers together**\n\n```ts\nimport { mergebuf } from '@taquito/utils';\n\nconst buff = new Uint8Array([1,2]);\nconst buff2 = new Uint8Array([3,4]);\n\nconsole.log(mergebuf(buff, buff2));\n// output: Uint8Array(4) [ 1, 2, 3, 4 ]\n```\n\n**Base58 encode a key hash according to its prefix**\n\n```ts\nimport { encodeKeyHash } from '@taquito/utils';\n\nconsole.log(encodeKeyHash('01106d79a502c4135b10e61e92f4c5a72ca740fb87'));\n// output: tz29p6csejX9FcHXgQERr5sXsAinLvxmVerM\n```\n\n**Base58 encode a public key according to its prefix**\n\n```ts\nimport { encodeKey } from '@taquito/utils';\n\nconsole.log(encodeKey('0060842d4ba23a9940ef5dcf4404fdaa430cfaaccb5029fad06cb5ea894e4562ae'));\n// output: edpkuNjKKT48xBoT5asPrWdmuM1Yw8D93MwgFgVvtca8jb5pstzaCh\n```\n\n**Base58 encode an address using a predefined prefix**\n```ts\nimport { encodeAddress } from '@taquito/utils';\n\nconsole.log(encodeAddress('0000e96b9f8b19af9c7ffa0c0480e1977b295850961f'));\n// output: tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM\n\nconsole.log(encodeAddress('01f9b689a478253793bd92357c5e08e5ebcd8db47600'));\n// output: KT1XM8VUFBiM9AC5czWU15fEeE9nmuEYWt3Y\n```\n\n**Base58 decode a address with a predefined prefix**\n\n```ts\nimport { b58DecodeAddress } from '@taquito/utils';\n\nconsole.log(b58DecodeAddress('tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM'));\n// output: 0000e96b9f8b19af9c7ffa0c0480e1977b295850961f\n```\n\n**Base58 decode a string and remove the prefix from it**\n\n```ts\nimport { b58DecodeAndCheckPrefix, PrefixV2 } from '@taquito/utils';\n\nconsole.log(b58DecodeAndCheckPrefix('tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM', [PrefixV2.Ed25519PublicKeyHash], true));\n// output: <Buffer e9 6b 9f 8b 19 af 9c 7f fa 0c 04 80 e1 97 7b 29 58 50 96 1f>\n```\n\n**Base58 encode a string or a Uint8Array and append a prefix to it**\n\n```ts\nimport { b58Encode } from '@taquito/utils';\n\nconsole.log(b58Encode('e96b9f8b19af9c7ffa0c0480e1977b295850961f', PrefixV2.Ed25519PublicKeyHash));\n// output: tz1gvF4cD2dDtqitL3ZTraggSR1Mju2BKFEM\n```\n\n**Return the operation hash of a signed operation**\n\n```ts\nimport { encodeOpHash } from '@taquito/utils';\n\nconst opBytesSigned = '0f185d8a30061e8134c162dbb7a6c3ab8f5fdb153363ccd6149b49a33481156a6c00b2e19a9e74440d86c59f13dab8a18ff873e889eaa304ab05da13000001f1585a7384f36e45fb43dc37e8ce172bced3e05700ff0000000002002110c033f3a990c2e46a3d6054ecc2f74072aae7a34b5ac4d9ce9edc11c2410a97695682108951786f05b361da03b97245dc9897e1955e08b5b8d9e153b0bdeb0d';\nconsole.log(encodeOpHash(opBytesSigned));\n// output: opapqvVXmebRTCFd2GQFydr4tJj3V5QocQuTmuhbatcHm4Seo2t\n```\n\n**Generate expression hash**\n\nHash a string using the BLAKE2b algorithm, base58 encode the hash obtained and append the prefix 'expr' to it.\n\n```ts\nimport { encodeExpr } from '@taquito/utils';\n\nconsole.log(encodeExpr('050a000000160000b2e19a9e74440d86c59f13dab8a18ff873e889ea'));\n\n// output: exprv6UsC1sN3Fk2XfgcJCL8NCerP5rCGy1PRESZAqr7L2JdzX55EN\n```\n\n**Obtain the public key hash given a public key**\n\n```ts\nimport { getPkhfromPk } from '@taquito/utils';\n\nconst publicKey = 'sppk7czKu6So3zDWjhBPBv9wgCrBAfbEFoKYzEaKUsjhNr5Ug6E4Sn1';\nconsole.log(getPkhfromPk(publicKey));\n// output: 'tz2Gsf1Q857wUzkNGzHsJNC98z881UutMwjg\n```\n\n## Additional info\n\nSee the top-level [https://github.com/ecadlabs/taquito](https://github.com/ecadlabs/taquito) file for details on reporting issues, contributing, and versioning.\n\n## Disclaimer\n\nTHIS SOFTWARE IS PROVIDED \"AS IS\" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n","publish_time":1772247507247,"_cnpm_publish_time":1772247507247,"dist-tags":{"latest":"25.1.1","next":"25.2.0-beta0"}}