├── src ├── types.d.ts ├── index.js └── constants.js ├── tsconfig.json ├── .github ├── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md └── workflows │ └── main.yml ├── .gitignore ├── test ├── fixtures │ ├── invalid.js │ └── valid.js └── index.spec.js ├── LICENSE ├── update-constants.js ├── types └── varint │ └── index.d.ts ├── package.json ├── README.md └── CHANGELOG.md /src/types.d.ts: -------------------------------------------------------------------------------- 1 | import type { HashCode, HashName } from './constants.js' 2 | 3 | export type CodeNameMap = Record 4 | export type NameCodeMap = Record 5 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./node_modules/aegir/src/config/tsconfig.aegir.json", 3 | "compilerOptions": { 4 | "outDir": "dist", 5 | "baseUrl": "./", 6 | "paths": { 7 | "*": ["./types/*"] 8 | } 9 | }, 10 | "include": [ 11 | "test", // remove this line if you don't want to type-check tests 12 | "src", 13 | "types" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | package-lock.json 2 | 3 | **/node_modules/ 4 | **/*.log 5 | test/repo-tests* 6 | 7 | # Logs 8 | logs 9 | *.log 10 | 11 | coverage 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | 24 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 25 | .grunt 26 | 27 | # node-waf configuration 28 | .lock-wscript 29 | 30 | build 31 | 32 | # Dependency directory 33 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 34 | node_modules 35 | 36 | dist 37 | docs 38 | yarn.lock 39 | .nyc_output -------------------------------------------------------------------------------- /test/fixtures/invalid.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | module.exports = [{ 4 | code: 0x00, 5 | size: 32, 6 | hex: '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33' 7 | }, { 8 | code: 0x11, 9 | size: 21, 10 | hex: '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33' 11 | }, { 12 | code: 0x11, 13 | size: 20, 14 | hex: '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a' 15 | }, { 16 | code: 0x11, 17 | size: 20, 18 | hex: '' 19 | }, { 20 | code: 0x31, 21 | size: 20, 22 | hex: '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33' 23 | }, { 24 | code: 0x12, 25 | size: 32, 26 | hex: '2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7' 27 | }, { 28 | code: 0xb205, 29 | size: 5, 30 | hex: '2c26b' 31 | }, { 32 | code: 0xb23f, 33 | size: 0x3f, 34 | hex: '2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e72c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e' 35 | }] 36 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020 Protocol Labs Inc. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /update-constants.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const fs = require('fs') 4 | const path = require('path') 5 | const http = require('ipfs-utils/src/http') 6 | const url = 'https://raw.githubusercontent.com/multiformats/multicodec/master/table.csv' 7 | 8 | const run = async () => { 9 | const rsp = await http.get(url) 10 | const lines = (await rsp.text()).split('\n') 11 | const names = [] 12 | const codes = [] 13 | const processed = lines 14 | .slice(1, lines.length - 1) 15 | .map(l => { 16 | const [name, tag, code] = l.split(',') 17 | return [name.trim(), tag.trim(), code.trim()] 18 | }) 19 | .filter(l => l[1] === 'multihash') 20 | .reduce((acc, l, index, arr) => { 21 | names.push(`"${l[0]}"`) 22 | codes.push(`${l[2].replace('\'', '')}`) 23 | acc += ` '${l[0]}': ${l[2].replace('\'', '')}` 24 | 25 | if (index !== arr.length - 1) { 26 | acc += ',\n' 27 | } 28 | return acc 29 | }, '') 30 | 31 | const template = `/* eslint quote-props: off */ 32 | 'use strict' 33 | 34 | /** 35 | * Names for all available hashes 36 | * 37 | * @typedef { ${names.join(' | ')} } HashName 38 | */ 39 | /** 40 | * Codes for all available hashes 41 | * 42 | * @typedef { ${codes.join(' | ')} } HashCode 43 | */ 44 | 45 | /** 46 | * @type { Record } 47 | */ 48 | const names = Object.freeze({ 49 | ${processed} 50 | }) 51 | 52 | module.exports = { names } 53 | ` 54 | 55 | fs.writeFileSync(path.join(__dirname, 'src/constants.js'), template) 56 | } 57 | 58 | run() 59 | -------------------------------------------------------------------------------- /types/varint/index.d.ts: -------------------------------------------------------------------------------- 1 | export const encode: { 2 | /** 3 | * Encodes `num` into `buffer` starting at `offset`. returns `buffer`, with the encoded varint written into it. 4 | * `varint.encode.bytes` will now be set to the number of bytes modified. 5 | */ 6 | (num: number, buffer: Uint8Array, offset?: number): Uint8Array 7 | 8 | /** 9 | * Encodes `num` into `array` starting at `offset`. returns `array`, with the encoded varint written into it. 10 | * If `array` is not provided, it will default to a new array. 11 | * `varint.encode.bytes` will now be set to the number of bytes modified. 12 | */ 13 | (num: number, array?: number[], offset?: number): number[] 14 | 15 | /** 16 | * Similar to `decode.bytes` when encoding a number it can be useful to know how many bytes where written (especially if you pass an output array). 17 | * You can access this via `varint.encode.bytes` which holds the number of bytes written in the last encode. 18 | */ 19 | bytes: number 20 | } 21 | 22 | export const decode: { 23 | /** 24 | * Decodes `data`, which can be either a buffer or array of integers, from position `offset` or default 0 and returns the decoded original integer. 25 | * Throws a `RangeError` when `data` does not represent a valid encoding. 26 | */ 27 | (buf: Uint8Array | Buffer | number[], offset?: number): number 28 | 29 | /** 30 | * If you also require the length (number of bytes) that were required to decode the integer you can access it via `varint.decode.bytes`. 31 | * This is an integer property that will tell you the number of bytes that the last .decode() call had to use to decode. 32 | */ 33 | bytes: number 34 | } 35 | 36 | /** 37 | * returns the number of bytes this number will be encoded as, up to a maximum of 8. 38 | */ 39 | export function encodingLength (num: number): number 40 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: ci 2 | on: 3 | push: 4 | branches: 5 | - master 6 | pull_request: 7 | branches: 8 | - master 9 | 10 | jobs: 11 | check: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v2 15 | - uses: actions/setup-node@v2 16 | with: 17 | node-version: 14 18 | - run: npm install 19 | - run: npx aegir lint 20 | - uses: gozala/typescript-error-reporter-action@v1.0.8 21 | - run: npx aegir build 22 | - run: npx aegir dep-check 23 | - uses: ipfs/aegir/actions/bundle-size@master 24 | with: 25 | github_token: ${{ secrets.GITHUB_TOKEN }} 26 | test-node: 27 | needs: check 28 | runs-on: ${{ matrix.os }} 29 | strategy: 30 | matrix: 31 | os: [windows-latest, ubuntu-latest, macos-latest] 32 | node: [14, 15] 33 | fail-fast: true 34 | steps: 35 | - uses: actions/checkout@v2 36 | - uses: actions/setup-node@v1 37 | with: 38 | node-version: ${{ matrix.node }} 39 | - run: npm install 40 | - run: npx aegir test -t node --bail --cov 41 | - uses: codecov/codecov-action@v1 42 | test-chrome: 43 | needs: check 44 | runs-on: ubuntu-latest 45 | steps: 46 | - uses: actions/checkout@v2 47 | - uses: microsoft/playwright-github-action@v1 48 | - run: npm install 49 | - run: npx aegir test -t browser -t webworker --bail 50 | - uses: codecov/codecov-action@v1 51 | test-firefox: 52 | needs: check 53 | runs-on: ubuntu-latest 54 | steps: 55 | - uses: actions/checkout@v2 56 | - uses: microsoft/playwright-github-action@v1 57 | - run: npm install 58 | - run: npx aegir test -t browser -t webworker --bail -- --browser firefox 59 | test-webkit: 60 | needs: check 61 | runs-on: ubuntu-latest 62 | steps: 63 | - uses: actions/checkout@v2 64 | - uses: microsoft/playwright-github-action@v1 65 | - run: npm install 66 | - run: npx aegir test -t browser -t webworker --bail -- --browser webkit 67 | test-electron-main: 68 | needs: check 69 | runs-on: ubuntu-latest 70 | steps: 71 | - uses: actions/checkout@v2 72 | - run: npm install 73 | - run: npx xvfb-maybe aegir test -t electron-main --bail 74 | test-electron-renderer: 75 | needs: check 76 | runs-on: ubuntu-latest 77 | steps: 78 | - uses: actions/checkout@v2 79 | - run: npm install 80 | - run: npx xvfb-maybe aegir test -t electron-renderer --bail -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "multihashes", 3 | "version": "4.0.3", 4 | "description": "multihash implementation", 5 | "keywords": [ 6 | "multihash", 7 | "multiformats", 8 | "ipfs", 9 | "hash" 10 | ], 11 | "homepage": "https://github.com/multiformats/js-multihash", 12 | "bugs": "https://github.com/multiformats/js-multihash/issues", 13 | "license": "MIT", 14 | "leadMaintainer": "Hugo Dias ", 15 | "files": [ 16 | "src", 17 | "dist" 18 | ], 19 | "scripts": { 20 | "prepare": "aegir build --no-bundle", 21 | "lint": "aegir lint", 22 | "test:browser": "aegir test --target browser", 23 | "test:node": "aegir test --target node", 24 | "test": "aegir test", 25 | "docs": "aegir docs", 26 | "release": "aegir release --docs", 27 | "release-minor": "aegir release --type minor --docs", 28 | "release-major": "aegir release --type major --docs", 29 | "update-constants": "node update-constants.js" 30 | }, 31 | "main": "src/index.js", 32 | "types": "dist/src/index.d.ts", 33 | "repository": "github:multiformats/js-multihash", 34 | "dependencies": { 35 | "multibase": "^4.0.1", 36 | "uint8arrays": "^3.0.0", 37 | "varint": "^5.0.2" 38 | }, 39 | "devDependencies": { 40 | "aegir": "^35.0.1", 41 | "ipfs-utils": "^8.1.4", 42 | "util": "^0.12.4" 43 | }, 44 | "eslintConfig": { 45 | "extends": "ipfs" 46 | }, 47 | "aegir": { 48 | "build": { 49 | "bundlesizeMax": "10.3kB" 50 | } 51 | }, 52 | "contributors": [ 53 | "David Dias ", 54 | "Hugo Dias ", 55 | "Juan Benet ", 56 | "Jacob Heun ", 57 | "Friedel Ziegelmayer ", 58 | "Richard Littauer ", 59 | "ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ ", 60 | "Rod Vagg ", 61 | "Pedro Teixeira ", 62 | "Alex Potsides ", 63 | "kumavis ", 64 | "Linus Unnebäck ", 65 | "Vasco Santos ", 66 | "Irakli Gozalishvili ", 67 | "Trond Arne Bråthen ", 68 | "Volker Mische ", 69 | "William Cotton ", 70 | "nginnever ", 71 | "Fil ", 72 | "Lars Gierth ", 73 | "Nate Foss ", 74 | "Alan Shaw ", 75 | "Donald Tsang " 76 | ], 77 | "engines": { 78 | "node": ">=12.0.0", 79 | "npm": ">=6.0.0" 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /test/fixtures/valid.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | /** 4 | * @typedef {import('../../src/constants').HashCode} HashCode 5 | * @typedef {import('../../src/constants').HashName} HashName 6 | */ 7 | /** @type {Array<{encoding: {code: HashCode, name: HashName, varint?: string}, hex: string, size: number }>} */ 8 | module.exports = [ 9 | { 10 | encoding: { 11 | code: 0x11, 12 | name: 'sha1' 13 | }, 14 | hex: '0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33', 15 | size: 20 16 | }, 17 | { 18 | encoding: { 19 | code: 0x11, 20 | name: 'sha1' 21 | }, 22 | hex: '0beec7b8', 23 | size: 4 24 | }, 25 | { 26 | encoding: { 27 | code: 0x12, 28 | name: 'sha2-256' 29 | }, 30 | hex: '2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae', 31 | size: 32 32 | }, 33 | { 34 | encoding: { 35 | code: 0x12, 36 | name: 'sha2-256' 37 | }, 38 | hex: '2c26b46b', 39 | size: 4 40 | }, 41 | { 42 | encoding: { 43 | code: 0x0, 44 | name: 'identity' 45 | }, 46 | hex: '7465737420737472696e6720f09f918d', 47 | size: 16 48 | }, 49 | { 50 | encoding: { 51 | code: 0x0, 52 | name: 'identity' 53 | }, 54 | hex: '2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae', 55 | size: 32 56 | }, 57 | { 58 | encoding: { 59 | code: 0x00, 60 | name: 'identity' 61 | }, 62 | hex: '', 63 | size: 0 64 | }, 65 | { 66 | encoding: { 67 | code: 0x11, 68 | name: 'sha1' 69 | }, 70 | hex: '0beec7b5', 71 | size: 4 72 | }, 73 | { 74 | encoding: { 75 | code: 0xb240, 76 | name: 'blake2b-512', 77 | varint: 'c0e402' 78 | }, 79 | hex: '2c26b46b68ffc68ff99b453c1d30413413', 80 | size: 17 81 | }, 82 | { 83 | encoding: { 84 | code: 0x22, 85 | name: 'murmur3-128' 86 | }, 87 | hex: '243ddb9e', 88 | size: 4 89 | }, 90 | { 91 | encoding: { 92 | code: 0x1b, 93 | name: 'keccak-256' 94 | }, 95 | hex: 'f00ba4', 96 | size: 3 97 | }, 98 | { 99 | encoding: { 100 | code: 0x18, 101 | name: 'shake-128' 102 | }, 103 | hex: 'f84e95cb5fbd2038863ab27d3cdeac295ad2d4ab96ad1f4b070c0bf36078ef08', 104 | size: 32 105 | }, 106 | { 107 | encoding: { 108 | code: 0x19, 109 | name: 'shake-256' 110 | }, 111 | hex: 112 | '1af97f7818a28edfdfce5ec66dbdc7e871813816d7d585fe1f12475ded5b6502b7723b74e2ee36f2651a10a8eaca72aa9148c3c761aaceac8f6d6cc64381ed39', 113 | size: 64 114 | }, 115 | { 116 | encoding: { 117 | code: 0x14, 118 | name: 'sha3-512' 119 | }, 120 | hex: 121 | '4bca2b137edc580fe50a88983ef860ebaca36c857b1f492839d6d7392452a63c82cbebc68e3b70a2a1480b4bb5d437a7cba6ecf9d89f9ff3ccd14cd6146ea7e7', 122 | size: 64 123 | }, 124 | { 125 | encoding: { 126 | code: 0xd5, 127 | name: 'md5', 128 | varint: 'd501' 129 | }, 130 | hex: 'd41d8cd98f00b204e9800998ecf8427e', 131 | size: 16 132 | } 133 | ] 134 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # js-multihash 2 | 3 | [![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io) 4 | [![](https://img.shields.io/badge/project-multiformats-blue.svg?style=flat-square)](https://github.com/multiformats/multiformats) 5 | [![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](https://webchat.freenode.net/?channels=%23ipfs) 6 | [![codecov](https://img.shields.io/codecov/c/github/multiformats/js-multihash.svg?style=flat-square)](https://codecov.io/gh/multiformats/js-multihash) 7 | [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/multiformats/js-multihash/ci?label=ci&style=flat-square)](https://github.com/multiformats/js-multihash/actions?query=branch%3Amaster+workflow%3Aci+) 8 | 9 | > multihash implementation in node.js 10 | 11 | This is the [multihash](//github.com/multiformats/multihash) implementation in Node. 12 | It is extended by [js-multihashing](https://github.com/multiformats/js-multihashing) 13 | and [js-multihashing-async](https://github.com/multiformats/js-multihashing-async), 14 | so give those a look as well. 15 | 16 | ## Lead Maintainer 17 | 18 | [Hugo Dias](http://github.com/hugomrdias/) 19 | 20 | ## Table of Contents 21 | 22 | - [Install](#install) 23 | - [Using npm](#using-npm) 24 | - [Using a ` 45 | ``` 46 | 47 | ## Usage 48 | 49 | ```js 50 | > var multihash = require('multihashes') 51 | > var bytes = Uint8Array.from([0, 1, 2, 3...]) 52 | 53 | > var encoded = multihash.encode(bytes, 'sha1') 54 | > console.log(encoded) 55 | 56 | 57 | > multihash.decode(encoded) 58 | { code: 17, 59 | name: 'sha1', 60 | length: 20, 61 | digest: } 62 | ``` 63 | 64 | ## API 65 | 66 | https://multiformats.github.io/js-multihash/ 67 | 68 | ## Update Constants 69 | 70 | To update the constants table run the command below. This will fetch the main codec list from https://raw.githubusercontent.com/multiformats/multicodec/master/table.csv and filter only the multihash codecs and update the `constants.js` file in this repo. 71 | 72 | ```sh 73 | npm run update-constants 74 | ``` 75 | 76 | 77 | ## Contribute 78 | 79 | Contributions welcome. Please check out [the issues](https://github.com/multiformats/js-multihash/issues). 80 | 81 | Check out our [contributing document](https://github.com/multiformats/multiformats/blob/master/contributing.md) for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md). 82 | 83 | Small note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification. 84 | 85 | ## License 86 | 87 | [MIT](LICENSE) © Protocol Labs Inc. 88 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Multihash implementation in JavaScript. 3 | */ 4 | 'use strict' 5 | 6 | const multibase = require('multibase') 7 | const varint = require('varint') 8 | const { names } = require('./constants') 9 | const { toString: uint8ArrayToString } = require('uint8arrays/to-string') 10 | const { fromString: uint8ArrayFromString } = require('uint8arrays/from-string') 11 | const { concat: uint8ArrayConcat } = require('uint8arrays/concat') 12 | 13 | const codes = /** @type {import('./types').CodeNameMap} */({}) 14 | 15 | // eslint-disable-next-line guard-for-in 16 | for (const key in names) { 17 | const name = /** @type {HashName} */(key) 18 | codes[names[name]] = name 19 | } 20 | Object.freeze(codes) 21 | 22 | /** 23 | * Convert the given multihash to a hex encoded string. 24 | * 25 | * @param {Uint8Array} hash 26 | * @returns {string} 27 | */ 28 | function toHexString (hash) { 29 | if (!(hash instanceof Uint8Array)) { 30 | throw new Error('must be passed a Uint8Array') 31 | } 32 | 33 | return uint8ArrayToString(hash, 'base16') 34 | } 35 | 36 | /** 37 | * Convert the given hex encoded string to a multihash. 38 | * 39 | * @param {string} hash 40 | * @returns {Uint8Array} 41 | */ 42 | function fromHexString (hash) { 43 | return uint8ArrayFromString(hash, 'base16') 44 | } 45 | 46 | /** 47 | * Convert the given multihash to a base58 encoded string. 48 | * 49 | * @param {Uint8Array} hash 50 | * @returns {string} 51 | */ 52 | function toB58String (hash) { 53 | if (!(hash instanceof Uint8Array)) { 54 | throw new Error('must be passed a Uint8Array') 55 | } 56 | 57 | return uint8ArrayToString(multibase.encode('base58btc', hash)).slice(1) 58 | } 59 | 60 | /** 61 | * Convert the given base58 encoded string to a multihash. 62 | * 63 | * @param {string|Uint8Array} hash 64 | * @returns {Uint8Array} 65 | */ 66 | function fromB58String (hash) { 67 | const encoded = hash instanceof Uint8Array 68 | ? uint8ArrayToString(hash) 69 | : hash 70 | 71 | return multibase.decode('z' + encoded) 72 | } 73 | 74 | /** 75 | * Decode a hash from the given multihash. 76 | * 77 | * @param {Uint8Array} bytes 78 | * @returns {{code: HashCode, name: HashName, length: number, digest: Uint8Array}} result 79 | */ 80 | function decode (bytes) { 81 | if (!(bytes instanceof Uint8Array)) { 82 | throw new Error('multihash must be a Uint8Array') 83 | } 84 | 85 | if (bytes.length < 2) { 86 | throw new Error('multihash too short. must be > 2 bytes.') 87 | } 88 | 89 | const code = /** @type {HashCode} */(varint.decode(bytes)) 90 | if (!isValidCode(code)) { 91 | throw new Error(`multihash unknown function code: 0x${code.toString(16)}`) 92 | } 93 | bytes = bytes.slice(varint.decode.bytes) 94 | 95 | const len = varint.decode(bytes) 96 | if (len < 0) { 97 | throw new Error(`multihash invalid length: ${len}`) 98 | } 99 | bytes = bytes.slice(varint.decode.bytes) 100 | 101 | if (bytes.length !== len) { 102 | throw new Error(`multihash length inconsistent: 0x${uint8ArrayToString(bytes, 'base16')}`) 103 | } 104 | 105 | return { 106 | code, 107 | name: codes[code], 108 | length: len, 109 | digest: bytes 110 | } 111 | } 112 | 113 | /** 114 | * Encode a hash digest along with the specified function code. 115 | * 116 | * > **Note:** the length is derived from the length of the digest itself. 117 | * 118 | * @param {Uint8Array} digest 119 | * @param {HashName | HashCode} code 120 | * @param {number} [length] 121 | * @returns {Uint8Array} 122 | */ 123 | function encode (digest, code, length) { 124 | if (!digest || code === undefined) { 125 | throw new Error('multihash encode requires at least two args: digest, code') 126 | } 127 | 128 | // ensure it's a hashfunction code. 129 | const hashfn = coerceCode(code) 130 | 131 | if (!(digest instanceof Uint8Array)) { 132 | throw new Error('digest should be a Uint8Array') 133 | } 134 | 135 | if (length == null) { 136 | length = digest.length 137 | } 138 | 139 | if (length && digest.length !== length) { 140 | throw new Error('digest length should be equal to specified length.') 141 | } 142 | 143 | const hash = varint.encode(hashfn) 144 | const len = varint.encode(length) 145 | return uint8ArrayConcat([hash, len, digest], hash.length + len.length + digest.length) 146 | } 147 | 148 | /** 149 | * Converts a hash function name into the matching code. 150 | * If passed a number it will return the number if it's a valid code. 151 | * 152 | * @param {HashName | number} name 153 | * @returns {number} 154 | */ 155 | function coerceCode (name) { 156 | let code = name 157 | 158 | if (typeof name === 'string') { 159 | if (names[name] === undefined) { 160 | throw new Error(`Unrecognized hash function named: ${name}`) 161 | } 162 | code = names[name] 163 | } 164 | 165 | if (typeof code !== 'number') { 166 | throw new Error(`Hash function code should be a number. Got: ${code}`) 167 | } 168 | 169 | // @ts-ignore 170 | if (codes[code] === undefined && !isAppCode(code)) { 171 | throw new Error(`Unrecognized function code: ${code}`) 172 | } 173 | 174 | return code 175 | } 176 | 177 | /** 178 | * Checks if a code is part of the app range 179 | * 180 | * @param {number} code 181 | * @returns {boolean} 182 | */ 183 | function isAppCode (code) { 184 | return code > 0 && code < 0x10 185 | } 186 | 187 | /** 188 | * Checks whether a multihash code is valid. 189 | * 190 | * @param {HashCode} code 191 | * @returns {boolean} 192 | */ 193 | function isValidCode (code) { 194 | if (isAppCode(code)) { 195 | return true 196 | } 197 | 198 | if (codes[code]) { 199 | return true 200 | } 201 | 202 | return false 203 | } 204 | 205 | /** 206 | * Check if the given buffer is a valid multihash. Throws an error if it is not valid. 207 | * 208 | * @param {Uint8Array} multihash 209 | * @returns {void} 210 | * @throws {Error} 211 | */ 212 | function validate (multihash) { 213 | decode(multihash) // throws if bad. 214 | } 215 | 216 | /** 217 | * Returns a prefix from a valid multihash. Throws an error if it is not valid. 218 | * 219 | * @param {Uint8Array} multihash 220 | * @returns {Uint8Array} 221 | * @throws {Error} 222 | */ 223 | function prefix (multihash) { 224 | validate(multihash) 225 | 226 | return multihash.subarray(0, 2) 227 | } 228 | 229 | module.exports = { 230 | names, 231 | codes, 232 | toHexString, 233 | fromHexString, 234 | toB58String, 235 | fromB58String, 236 | decode, 237 | encode, 238 | coerceCode, 239 | isAppCode, 240 | validate, 241 | prefix, 242 | isValidCode 243 | } 244 | 245 | /** 246 | * @typedef { import("./constants").HashCode } HashCode 247 | * @typedef { import("./constants").HashName } HashName 248 | */ 249 | -------------------------------------------------------------------------------- /test/index.spec.js: -------------------------------------------------------------------------------- 1 | /* eslint-env mocha */ 2 | /* eslint max-nested-callbacks: off */ 3 | 'use strict' 4 | 5 | const { expect } = require('aegir/utils/chai') 6 | const multibase = require('multibase') 7 | const mh = require('../src') 8 | const constants = require('../src/constants') 9 | const validCases = require('./fixtures/valid') 10 | const invalidCases = require('./fixtures/invalid') 11 | const { toString: uint8ArrayToString } = require('uint8arrays/to-string') 12 | const { fromString: uint8ArrayFromString } = require('uint8arrays/from-string') 13 | const { equals: uint8ArrayEquals } = require('uint8arrays/equals') 14 | 15 | /** 16 | * @typedef {import('../src/constants.js').HashName} HashName 17 | * @typedef {import('../src/constants.js').HashCode} HashCode 18 | */ 19 | 20 | /** 21 | * @param {string | number} code 22 | * @param {number} size 23 | * @param {string} hex 24 | */ 25 | function sample (code, size, hex) { 26 | /** 27 | * @param {number | string} i 28 | */ 29 | const toHex = (i) => { 30 | if (typeof i === 'string') { 31 | return i 32 | } 33 | const h = i.toString(16) 34 | return h.length % 2 === 1 ? `0${h}` : h 35 | } 36 | return uint8ArrayFromString(`${toHex(code)}${toHex(size)}${hex}`, 'base16') 37 | } 38 | 39 | /** 40 | * @param {string} description 41 | * @param {(test: { encodeText: (text: string) => Uint8Array, encodeHex: (text: string) => Uint8Array }) => void} test 42 | */ 43 | const they = (description, test) => { 44 | it(description, () => test({ 45 | encodeText: (text) => uint8ArrayFromString(text), 46 | encodeHex: (text) => uint8ArrayFromString(text, 'base16') 47 | })) 48 | } 49 | 50 | describe('multihash', () => { 51 | describe('toHexString', () => { 52 | they('valid', ({ encodeHex }) => { 53 | validCases.forEach((test) => { 54 | const code = /** @type { import("../src/constants").HashCode} */(test.encoding.code) 55 | const buf = mh.encode(encodeHex(test.hex), code) 56 | expect( 57 | mh.toHexString(buf) 58 | ).to.be.eql( 59 | uint8ArrayToString(buf, 'base16') 60 | ) 61 | }) 62 | }) 63 | 64 | it('invalid', () => { 65 | expect( 66 | // @ts-ignore 67 | () => mh.toHexString('hello world') 68 | ).to.throw( 69 | /must be passed a Uint8Array/ 70 | ) 71 | }) 72 | }) 73 | 74 | describe('fromHexString', () => { 75 | they('valid', ({ encodeHex }) => { 76 | validCases.forEach((test) => { 77 | const code = test.encoding.code 78 | const buf = mh.encode(encodeHex(test.hex), code) 79 | expect( 80 | uint8ArrayToString(mh.fromHexString(uint8ArrayToString(buf, 'base16')), 'base16') 81 | ).to.be.eql( 82 | uint8ArrayToString(buf, 'base16') 83 | ) 84 | }) 85 | }) 86 | }) 87 | 88 | describe('toB58String', () => { 89 | they('valid', ({ encodeHex }) => { 90 | validCases.forEach((test) => { 91 | const code = test.encoding.code 92 | const buf = mh.encode(encodeHex(test.hex), code) 93 | expect( 94 | mh.toB58String(buf) 95 | ).to.be.eql( 96 | uint8ArrayToString(multibase.encode('base58btc', buf)).slice(1) 97 | ) 98 | }) 99 | }) 100 | 101 | it('invalid', () => { 102 | expect( 103 | // @ts-expect-error 104 | () => mh.toB58String('hello world') 105 | ).to.throw( 106 | /must be passed a Uint8Array/ 107 | ) 108 | }) 109 | }) 110 | 111 | describe('fromB58String', () => { 112 | they('valid', ({ encodeHex, encodeText }) => { 113 | const src = 'QmPfjpVaf593UQJ9a5ECvdh2x17XuJYG5Yanv5UFnH3jPE' 114 | const expected = encodeHex('122013bf801597d74a660453412635edd8c34271e5998f801fac5d700c6ce8d8e461') 115 | 116 | expect( 117 | mh.fromB58String(src) 118 | ).to.be.eql( 119 | expected 120 | ) 121 | 122 | expect( 123 | mh.fromB58String(encodeText(src)) 124 | ).to.be.eql( 125 | expected 126 | ) 127 | }) 128 | }) 129 | 130 | describe('decode', () => { 131 | it('valid', () => { 132 | validCases.forEach((test) => { 133 | const code = test.encoding.code 134 | const buf = sample(test.encoding.varint || code, test.size, test.hex) 135 | const name = test.encoding.name 136 | const d1 = uint8ArrayFromString(test.hex, 'base16') 137 | const length = d1.length 138 | 139 | const r = mh.decode(buf) 140 | const d2 = r.digest 141 | 142 | expect(r.code).to.equal(code) 143 | expect(r.name).to.equal(name) 144 | expect(r.length).to.equal(length) 145 | expect(uint8ArrayEquals(d1, d2)).to.equal(true) 146 | }) 147 | }) 148 | 149 | it('invalid', () => { 150 | expect( 151 | // @ts-expect-error 152 | () => mh.decode('hello') 153 | ).to.throw( 154 | /multihash must be a Uint8Array/ 155 | ) 156 | }) 157 | }) 158 | 159 | describe('encode', () => { 160 | they('valid', ({ encodeHex }) => { 161 | validCases.forEach((test) => { 162 | const code = test.encoding.code 163 | const name = test.encoding.name 164 | const buf = sample(test.encoding.varint || code, test.size, test.hex) 165 | const results = [ 166 | mh.encode(encodeHex(test.hex), code), 167 | mh.encode(encodeHex(test.hex), name) 168 | ] 169 | 170 | results.forEach((res) => { 171 | expect( 172 | uint8ArrayToString(res, 'base16') 173 | ).to.be.eql( 174 | uint8ArrayToString(buf, 'base16') 175 | ) 176 | }) 177 | }) 178 | }) 179 | 180 | they('invalid', ({ encodeText }) => { 181 | expect( 182 | // @ts-expect-error 183 | () => mh.encode() 184 | ).to.throw( 185 | /requires at least two args/ 186 | ) 187 | 188 | expect( 189 | // @ts-expect-error 190 | () => mh.encode('hello', 0x11) 191 | ).to.throw( 192 | /digest should be a Uint8Array/ 193 | ) 194 | 195 | expect( 196 | () => mh.encode(encodeText('hello'), 0x11, 2) 197 | ).to.throw( 198 | /length should be equal/ 199 | ) 200 | }) 201 | }) 202 | 203 | describe('validate', () => { 204 | it('valid', () => { 205 | validCases.forEach((test) => { 206 | expect( 207 | () => mh.validate(sample(test.encoding.varint || test.encoding.code, test.size, test.hex)) 208 | ).to.not.throw() 209 | }) 210 | }) 211 | 212 | it('invalid', () => { 213 | invalidCases.forEach((test) => { 214 | expect( 215 | () => mh.validate(sample(test.code, test.size, test.hex)) 216 | ).to.throw() 217 | }) 218 | 219 | const longBuffer = new Uint8Array(150).fill(0) 220 | expect( 221 | () => mh.validate(longBuffer) 222 | ).to.throw() 223 | }) 224 | }) 225 | 226 | describe('isValidCode', () => { 227 | it('valid', () => { 228 | expect( 229 | // @ts-expect-error - app code 230 | mh.isValidCode(2) 231 | ).to.be.eql( 232 | true 233 | ) 234 | 235 | expect( 236 | mh.isValidCode(0x13) 237 | ).to.be.eql( 238 | true 239 | ) 240 | }) 241 | 242 | it('invalid', () => { 243 | expect( 244 | // @ts-expect-error 245 | mh.isValidCode(0x10) 246 | ).to.be.eql( 247 | false 248 | ) 249 | 250 | expect( 251 | // @ts-expect-error 252 | mh.isValidCode(0x90) 253 | ).to.be.eql( 254 | false 255 | ) 256 | }) 257 | }) 258 | 259 | describe('isAppCode', () => { 260 | it('valid', () => { 261 | for (let n = 1; n < 0x10; n++) { 262 | expect( 263 | mh.isAppCode(n) 264 | ).to.equal( 265 | true 266 | ) 267 | } 268 | }) 269 | 270 | it('invalid', () => { 271 | expect( 272 | mh.isAppCode(0) 273 | ).to.equal( 274 | false 275 | ) 276 | 277 | for (let m = 0x10; m <= 0xff; m++) { 278 | expect( 279 | mh.isAppCode(m) 280 | ).to.equal( 281 | false 282 | ) 283 | } 284 | }) 285 | }) 286 | 287 | describe('coerceCode', () => { 288 | it('valid', () => { 289 | const names = { 290 | sha1: 0x11, 291 | 'sha2-256': 0x12, 292 | 'sha2-512': 0x13, 293 | 'sha3-512': 0x14 294 | } 295 | /** @type {keyof typeof names} */ 296 | let name 297 | // eslint-disable-next-line guard-for-in 298 | for (name in names) { 299 | expect( 300 | mh.coerceCode(name) 301 | ).to.be.eql( 302 | names[name] 303 | ) 304 | 305 | expect( 306 | mh.coerceCode(names[name]) 307 | ).to.be.eql( 308 | names[name] 309 | ) 310 | } 311 | }) 312 | 313 | they('invalid', ({ encodeText }) => { 314 | const invalidNames = [ 315 | 'sha256', 316 | 'sha9', 317 | 'Blake4b' 318 | ] 319 | 320 | invalidNames.forEach((name) => { 321 | expect( 322 | // @ts-ignore 323 | () => mh.coerceCode(name) 324 | ).to.throw( 325 | `Unrecognized hash function named: ${name}` 326 | ) 327 | }) 328 | 329 | expect( 330 | // @ts-expect-error 331 | () => mh.coerceCode(encodeText('hello')) 332 | ).to.throw( 333 | /should be a number/ 334 | ) 335 | 336 | expect( 337 | () => mh.coerceCode(0x99) 338 | ).to.throw( 339 | /Unrecognized function code/ 340 | ) 341 | }) 342 | }) 343 | 344 | they('prefix', ({ encodeText }) => { 345 | const multihash = mh.encode(encodeText('hey'), 0x11, 3) 346 | const prefix = mh.prefix(multihash) 347 | expect(uint8ArrayToString(prefix, 'base16')).to.eql('1103') 348 | }) 349 | 350 | they('prefix throws on invalid multihash', ({ encodeText }) => { 351 | const multihash = encodeText('definitely not valid') 352 | 353 | expect(() => mh.prefix(multihash)).to.throw() 354 | }) 355 | 356 | describe('constants', () => { 357 | it('exported', () => { 358 | expect(mh.names).to.equal(constants.names) 359 | }) 360 | 361 | it('frozen', () => { 362 | expect(Object.isFrozen(mh.names)).to.be.true() 363 | expect(Object.isFrozen(mh.codes)).to.be.true() 364 | }) 365 | }) 366 | }) 367 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## [4.0.3](https://github.com/multiformats/js-multihash/compare/v4.0.2...v4.0.3) (2021-08-24) 2 | 3 | 4 | 5 | ## [4.0.2](https://github.com/multiformats/js-multihash/compare/v4.0.1...v4.0.2) (2021-03-03) 6 | 7 | 8 | ### Bug Fixes 9 | 10 | * revert to node12 ([adf5a6c](https://github.com/multiformats/js-multihash/commit/adf5a6c1af5176ef2ba7dd6bb9d429b043c7c88d)) 11 | 12 | 13 | 14 | ## [4.0.1](https://github.com/multiformats/js-multihash/compare/v4.0.0...v4.0.1) (2021-03-01) 15 | 16 | 17 | ### Bug Fixes 18 | 19 | * downgrade varint ([#118](https://github.com/multiformats/js-multihash/issues/118)) ([e84aabb](https://github.com/multiformats/js-multihash/commit/e84aabbd906fa7a5cdea69c4633d4bb87e01a898)) 20 | 21 | 22 | 23 | # [4.0.0](https://github.com/multiformats/js-multihash/compare/v3.1.2...v4.0.0) (2021-03-01) 24 | 25 | 26 | ### Bug Fixes 27 | 28 | * update to new aegir ([#115](https://github.com/multiformats/js-multihash/issues/115)) ([1d8348d](https://github.com/multiformats/js-multihash/commit/1d8348d11d7c8b5cebd22b74ffbd9cf4a69ac786)) 29 | 30 | 31 | ### BREAKING CHANGES 32 | 33 | * No longer supports deep type imports only from the entrypoint. 34 | 35 | 36 | 37 | ## [3.1.3-0](https://github.com/multiformats/js-multihash/compare/v3.1.2...v3.1.3-0) (2021-02-13) 38 | 39 | 40 | 41 | ## [3.1.2](https://github.com/multiformats/js-multihash/compare/v3.1.1...v3.1.2) (2021-01-26) 42 | 43 | 44 | ### Bug Fixes 45 | 46 | * temp fix for types ([#113](https://github.com/multiformats/js-multihash/issues/113)) ([241efe9](https://github.com/multiformats/js-multihash/commit/241efe9c4648e054f9c6fc0aacff585764284ebf)) 47 | 48 | 49 | 50 | ## [3.1.1](https://github.com/multiformats/js-multihash/compare/v3.1.0...v3.1.1) (2021-01-13) 51 | 52 | 53 | ### Bug Fixes 54 | 55 | * update dep and fix types ([#111](https://github.com/multiformats/js-multihash/issues/111)) ([666c4ad](https://github.com/multiformats/js-multihash/commit/666c4adefbd458409996e6d07c16a07385c85b45)) 56 | 57 | 58 | 59 | # [3.1.0](https://github.com/multiformats/js-multihash/compare/v3.0.1...v3.1.0) (2020-11-24) 60 | 61 | 62 | ### Features 63 | 64 | * add ts types ([#104](https://github.com/multiformats/js-multihash/issues/104)) ([5a1e7d7](https://github.com/multiformats/js-multihash/commit/5a1e7d73bfd377477a0853d41657c000fd84a4ae)) 65 | 66 | 67 | 68 | 69 | ## [3.0.1](https://github.com/multiformats/js-multihash/compare/v3.0.0...v3.0.1) (2020-08-03) 70 | 71 | 72 | ### Bug Fixes 73 | 74 | * remove text decoder ([#93](https://github.com/multiformats/js-multihash/issues/93)) ([91525fa](https://github.com/multiformats/js-multihash/commit/91525fa)) 75 | 76 | 77 | 78 | 79 | # [3.0.0](https://github.com/multiformats/js-multihash/compare/v2.0.0...v3.0.0) (2020-08-03) 80 | 81 | 82 | ### Bug Fixes 83 | 84 | * replace node buffers with uint8arrays ([#92](https://github.com/multiformats/js-multihash/issues/92)) ([b5dbaca](https://github.com/multiformats/js-multihash/commit/b5dbaca)) 85 | 86 | 87 | ### BREAKING CHANGES 88 | 89 | * - Where node `Buffer`s were returned, now `Uint8Array`s are 90 | 91 | 92 | 93 | 94 | # [2.0.0](https://github.com/multiformats/js-multihash/compare/v1.0.1...v2.0.0) (2020-07-30) 95 | 96 | 97 | ### Features 98 | 99 | * accept Uint8Arrays input in place of Buffers ([#88](https://github.com/multiformats/js-multihash/issues/88)) ([4bc2a05](https://github.com/multiformats/js-multihash/commit/4bc2a05)) 100 | 101 | 102 | 103 | 104 | ## [1.0.1](https://github.com/multiformats/js-multihash/compare/v1.0.0...v1.0.1) (2020-06-19) 105 | 106 | 107 | 108 | 109 | # [1.0.0](https://github.com/multiformats/js-multihash/compare/v0.4.20...v1.0.0) (2020-06-19) 110 | 111 | 112 | ### Features 113 | 114 | * update constants ([66e7132](https://github.com/multiformats/js-multihash/commit/66e7132)) 115 | 116 | 117 | 118 | 119 | ## [0.4.20](https://github.com/multiformats/js-multihash/compare/v0.4.19...v0.4.20) (2020-06-18) 120 | 121 | 122 | ### Bug Fixes 123 | 124 | * change maintainer, add docs ([0e7152e](https://github.com/multiformats/js-multihash/commit/0e7152e)) 125 | * update multibase and add buffer in the test ([#83](https://github.com/multiformats/js-multihash/issues/83)) ([a42bcc7](https://github.com/multiformats/js-multihash/commit/a42bcc7)) 126 | 127 | 128 | ### Features 129 | 130 | * updates multihash table ([a8c8838](https://github.com/multiformats/js-multihash/commit/a8c8838)) 131 | 132 | 133 | ### BREAKING CHANGES 134 | 135 | * defaultLengths removed 136 | 137 | 138 | 139 | 140 | ## [0.4.19](https://github.com/multiformats/js-multihash/compare/v0.4.18...v0.4.19) (2020-03-31) 141 | 142 | 143 | ### Bug Fixes 144 | 145 | * add missing md{4,5} hash codes ([010f8cd](https://github.com/multiformats/js-multihash/commit/010f8cd)) 146 | * support zero-length multihashes ([86f556f](https://github.com/multiformats/js-multihash/commit/86f556f)) 147 | * sync test fixtures with go-multihash ([00d5e23](https://github.com/multiformats/js-multihash/commit/00d5e23)) 148 | 149 | 150 | 151 | 152 | ## [0.4.18](https://github.com/multiformats/js-multihash/compare/v0.4.17...v0.4.18) (2020-03-24) 153 | 154 | 155 | 156 | 157 | ## [0.4.17](https://github.com/multiformats/js-multihash/compare/v0.4.16...v0.4.17) (2020-03-17) 158 | 159 | 160 | ### Bug Fixes 161 | 162 | * remove unnecessary deps ([#72](https://github.com/multiformats/js-multihash/issues/72)) ([1e0ac42](https://github.com/multiformats/js-multihash/commit/1e0ac42)) 163 | 164 | 165 | 166 | 167 | ## [0.4.16](https://github.com/multiformats/js-multihash/compare/v0.4.15...v0.4.16) (2020-03-16) 168 | 169 | 170 | ### Bug Fixes 171 | 172 | * add buffer dependency ([#71](https://github.com/multiformats/js-multihash/issues/71)) ([1e91e64](https://github.com/multiformats/js-multihash/commit/1e91e64)) 173 | 174 | 175 | 176 | 177 | ## [0.4.15](https://github.com/multiformats/js-multihash/compare/v0.4.14...v0.4.15) (2019-07-10) 178 | 179 | 180 | ### Features 181 | 182 | * support identity hashes ([b85999d](https://github.com/multiformats/js-multihash/commit/b85999d)) 183 | 184 | 185 | 186 | 187 | ## [0.4.14](https://github.com/multiformats/js-multihash/compare/v0.4.13...v0.4.14) (2018-08-08) 188 | 189 | 190 | ### Bug Fixes 191 | 192 | * missing id name constant ([42b9f0c](https://github.com/multiformats/js-multihash/commit/42b9f0c)) 193 | 194 | 195 | 196 | 197 | ## [0.4.13](https://github.com/multiformats/js-multihash/compare/v0.4.12...v0.4.13) (2018-01-04) 198 | 199 | 200 | ### Bug Fixes 201 | 202 | * add missing dbl-sha2-256 ([#44](https://github.com/multiformats/js-multihash/issues/44)) ([4421157](https://github.com/multiformats/js-multihash/commit/4421157)), closes [#38](https://github.com/multiformats/js-multihash/issues/38) 203 | 204 | 205 | 206 | 207 | ## [0.4.12](https://github.com/multiformats/js-multihash/compare/v0.4.11...v0.4.12) (2017-10-20) 208 | 209 | 210 | ### Bug Fixes 211 | 212 | * add missing blake2s-256 ([72b856f](https://github.com/multiformats/js-multihash/commit/72b856f)) 213 | 214 | 215 | 216 | 217 | ## [0.4.11](https://github.com/multiformats/js-multihash/compare/v0.4.10...v0.4.11) (2017-10-20) 218 | 219 | 220 | 221 | 222 | ## [0.4.10](https://github.com/multiformats/js-multihash/compare/v0.4.9...v0.4.10) (2017-10-13) 223 | 224 | 225 | ### Features 226 | 227 | * Adding Skein hash to the mix ([#34](https://github.com/multiformats/js-multihash/issues/34)) ([edf94d5](https://github.com/multiformats/js-multihash/commit/edf94d5)) 228 | 229 | 230 | 231 | 232 | ## [0.4.9](https://github.com/multiformats/js-multihash/compare/v0.4.8...v0.4.9) (2017-09-01) 233 | 234 | 235 | 236 | 237 | ## [0.4.8](https://github.com/multiformats/js-multihash/compare/v0.4.7...v0.4.8) (2017-08-23) 238 | 239 | 240 | 241 | 242 | ## [0.4.7](https://github.com/multiformats/js-multihash/compare/v0.4.6...v0.4.7) (2017-08-23) 243 | 244 | 245 | 246 | 247 | ## [0.4.6](https://github.com/multiformats/js-multihash/compare/v0.4.5...v0.4.6) (2017-08-23) 248 | 249 | 250 | 251 | 252 | ## [0.4.5](https://github.com/multiformats/js-multihash/compare/v0.4.4...v0.4.5) (2017-03-23) 253 | 254 | 255 | ### Bug Fixes 256 | 257 | * changed name of murmur3 codec to murmur3-128 ([34a9496](https://github.com/multiformats/js-multihash/commit/34a9496)) 258 | 259 | 260 | 261 | 262 | ## [0.4.4](https://github.com/multiformats/js-multihash/compare/v0.4.3...v0.4.4) (2017-03-16) 263 | 264 | 265 | 266 | 267 | ## [0.4.3](https://github.com/multiformats/js-multihash/compare/0.4.2...v0.4.3) (2017-02-24) 268 | 269 | 270 | 271 | 272 | ## [0.4.2](https://github.com/multiformats/js-multihash/compare/v0.4.1...0.4.2) (2017-02-24) 273 | 274 | 275 | 276 | 277 | ## [0.4.1](https://github.com/multiformats/js-multihash/compare/v0.4.0...v0.4.1) (2017-02-24) 278 | 279 | 280 | 281 | 282 | # [0.4.0](https://github.com/multiformats/js-multihash/compare/v0.3.3...v0.4.0) (2017-02-24) 283 | 284 | 285 | 286 | 287 | ## [0.3.3](https://github.com/multiformats/js-multihash/compare/v0.3.2...v0.3.3) (2017-02-09) 288 | 289 | 290 | 291 | 292 | ## [0.3.2](https://github.com/multiformats/js-multihash/compare/v0.3.1...v0.3.2) (2017-01-27) 293 | 294 | 295 | 296 | 297 | ## [0.3.1](https://github.com/multiformats/js-multihash/compare/v0.3.0...v0.3.1) (2016-12-16) 298 | 299 | 300 | ### Features 301 | 302 | * add .prefix function ([8fd714c](https://github.com/multiformats/js-multihash/commit/8fd714c)) 303 | 304 | 305 | 306 | 307 | # [0.3.0](https://github.com/multiformats/js-multihash/compare/v0.2.2...v0.3.0) (2016-11-26) 308 | 309 | 310 | ### Bug Fixes 311 | 312 | * update package.json ([bca3681](https://github.com/multiformats/js-multihash/commit/bca3681)) 313 | 314 | 315 | 316 | 317 | ## [0.2.2](https://github.com/multiformats/js-multihash/compare/v0.2.1...v0.2.2) (2016-05-16) 318 | 319 | 320 | ### Bug Fixes 321 | 322 | * Throw errors, do not return them ([1215fa6](https://github.com/multiformats/js-multihash/commit/1215fa6)) 323 | 324 | 325 | 326 | 327 | ## 0.2.1 (2016-04-17) 328 | 329 | 330 | 331 | -------------------------------------------------------------------------------- /src/constants.js: -------------------------------------------------------------------------------- 1 | /* eslint quote-props: off */ 2 | 'use strict' 3 | 4 | /** 5 | * Names for all available hashes 6 | * 7 | * @typedef { "identity" | "sha1" | "sha2-256" | "sha2-512" | "sha3-512" | "sha3-384" | "sha3-256" | "sha3-224" | "shake-128" | "shake-256" | "keccak-224" | "keccak-256" | "keccak-384" | "keccak-512" | "blake3" | "murmur3-128" | "murmur3-32" | "dbl-sha2-256" | "md4" | "md5" | "bmt" | "sha2-256-trunc254-padded" | "ripemd-128" | "ripemd-160" | "ripemd-256" | "ripemd-320" | "x11" | "kangarootwelve" | "sm3-256" | "blake2b-8" | "blake2b-16" | "blake2b-24" | "blake2b-32" | "blake2b-40" | "blake2b-48" | "blake2b-56" | "blake2b-64" | "blake2b-72" | "blake2b-80" | "blake2b-88" | "blake2b-96" | "blake2b-104" | "blake2b-112" | "blake2b-120" | "blake2b-128" | "blake2b-136" | "blake2b-144" | "blake2b-152" | "blake2b-160" | "blake2b-168" | "blake2b-176" | "blake2b-184" | "blake2b-192" | "blake2b-200" | "blake2b-208" | "blake2b-216" | "blake2b-224" | "blake2b-232" | "blake2b-240" | "blake2b-248" | "blake2b-256" | "blake2b-264" | "blake2b-272" | "blake2b-280" | "blake2b-288" | "blake2b-296" | "blake2b-304" | "blake2b-312" | "blake2b-320" | "blake2b-328" | "blake2b-336" | "blake2b-344" | "blake2b-352" | "blake2b-360" | "blake2b-368" | "blake2b-376" | "blake2b-384" | "blake2b-392" | "blake2b-400" | "blake2b-408" | "blake2b-416" | "blake2b-424" | "blake2b-432" | "blake2b-440" | "blake2b-448" | "blake2b-456" | "blake2b-464" | "blake2b-472" | "blake2b-480" | "blake2b-488" | "blake2b-496" | "blake2b-504" | "blake2b-512" | "blake2s-8" | "blake2s-16" | "blake2s-24" | "blake2s-32" | "blake2s-40" | "blake2s-48" | "blake2s-56" | "blake2s-64" | "blake2s-72" | "blake2s-80" | "blake2s-88" | "blake2s-96" | "blake2s-104" | "blake2s-112" | "blake2s-120" | "blake2s-128" | "blake2s-136" | "blake2s-144" | "blake2s-152" | "blake2s-160" | "blake2s-168" | "blake2s-176" | "blake2s-184" | "blake2s-192" | "blake2s-200" | "blake2s-208" | "blake2s-216" | "blake2s-224" | "blake2s-232" | "blake2s-240" | "blake2s-248" | "blake2s-256" | "skein256-8" | "skein256-16" | "skein256-24" | "skein256-32" | "skein256-40" | "skein256-48" | "skein256-56" | "skein256-64" | "skein256-72" | "skein256-80" | "skein256-88" | "skein256-96" | "skein256-104" | "skein256-112" | "skein256-120" | "skein256-128" | "skein256-136" | "skein256-144" | "skein256-152" | "skein256-160" | "skein256-168" | "skein256-176" | "skein256-184" | "skein256-192" | "skein256-200" | "skein256-208" | "skein256-216" | "skein256-224" | "skein256-232" | "skein256-240" | "skein256-248" | "skein256-256" | "skein512-8" | "skein512-16" | "skein512-24" | "skein512-32" | "skein512-40" | "skein512-48" | "skein512-56" | "skein512-64" | "skein512-72" | "skein512-80" | "skein512-88" | "skein512-96" | "skein512-104" | "skein512-112" | "skein512-120" | "skein512-128" | "skein512-136" | "skein512-144" | "skein512-152" | "skein512-160" | "skein512-168" | "skein512-176" | "skein512-184" | "skein512-192" | "skein512-200" | "skein512-208" | "skein512-216" | "skein512-224" | "skein512-232" | "skein512-240" | "skein512-248" | "skein512-256" | "skein512-264" | "skein512-272" | "skein512-280" | "skein512-288" | "skein512-296" | "skein512-304" | "skein512-312" | "skein512-320" | "skein512-328" | "skein512-336" | "skein512-344" | "skein512-352" | "skein512-360" | "skein512-368" | "skein512-376" | "skein512-384" | "skein512-392" | "skein512-400" | "skein512-408" | "skein512-416" | "skein512-424" | "skein512-432" | "skein512-440" | "skein512-448" | "skein512-456" | "skein512-464" | "skein512-472" | "skein512-480" | "skein512-488" | "skein512-496" | "skein512-504" | "skein512-512" | "skein1024-8" | "skein1024-16" | "skein1024-24" | "skein1024-32" | "skein1024-40" | "skein1024-48" | "skein1024-56" | "skein1024-64" | "skein1024-72" | "skein1024-80" | "skein1024-88" | "skein1024-96" | "skein1024-104" | "skein1024-112" | "skein1024-120" | "skein1024-128" | "skein1024-136" | "skein1024-144" | "skein1024-152" | "skein1024-160" | "skein1024-168" | "skein1024-176" | "skein1024-184" | "skein1024-192" | "skein1024-200" | "skein1024-208" | "skein1024-216" | "skein1024-224" | "skein1024-232" | "skein1024-240" | "skein1024-248" | "skein1024-256" | "skein1024-264" | "skein1024-272" | "skein1024-280" | "skein1024-288" | "skein1024-296" | "skein1024-304" | "skein1024-312" | "skein1024-320" | "skein1024-328" | "skein1024-336" | "skein1024-344" | "skein1024-352" | "skein1024-360" | "skein1024-368" | "skein1024-376" | "skein1024-384" | "skein1024-392" | "skein1024-400" | "skein1024-408" | "skein1024-416" | "skein1024-424" | "skein1024-432" | "skein1024-440" | "skein1024-448" | "skein1024-456" | "skein1024-464" | "skein1024-472" | "skein1024-480" | "skein1024-488" | "skein1024-496" | "skein1024-504" | "skein1024-512" | "skein1024-520" | "skein1024-528" | "skein1024-536" | "skein1024-544" | "skein1024-552" | "skein1024-560" | "skein1024-568" | "skein1024-576" | "skein1024-584" | "skein1024-592" | "skein1024-600" | "skein1024-608" | "skein1024-616" | "skein1024-624" | "skein1024-632" | "skein1024-640" | "skein1024-648" | "skein1024-656" | "skein1024-664" | "skein1024-672" | "skein1024-680" | "skein1024-688" | "skein1024-696" | "skein1024-704" | "skein1024-712" | "skein1024-720" | "skein1024-728" | "skein1024-736" | "skein1024-744" | "skein1024-752" | "skein1024-760" | "skein1024-768" | "skein1024-776" | "skein1024-784" | "skein1024-792" | "skein1024-800" | "skein1024-808" | "skein1024-816" | "skein1024-824" | "skein1024-832" | "skein1024-840" | "skein1024-848" | "skein1024-856" | "skein1024-864" | "skein1024-872" | "skein1024-880" | "skein1024-888" | "skein1024-896" | "skein1024-904" | "skein1024-912" | "skein1024-920" | "skein1024-928" | "skein1024-936" | "skein1024-944" | "skein1024-952" | "skein1024-960" | "skein1024-968" | "skein1024-976" | "skein1024-984" | "skein1024-992" | "skein1024-1000" | "skein1024-1008" | "skein1024-1016" | "skein1024-1024" | "poseidon-bls12_381-a2-fc1" | "poseidon-bls12_381-a2-fc1-sc" } HashName 8 | */ 9 | /** 10 | * Codes for all available hashes 11 | * 12 | * @typedef { 0x00 | 0x11 | 0x12 | 0x13 | 0x14 | 0x15 | 0x16 | 0x17 | 0x18 | 0x19 | 0x1a | 0x1b | 0x1c | 0x1d | 0x1e | 0x22 | 0x23 | 0x56 | 0xd4 | 0xd5 | 0xd6 | 0x1012 | 0x1052 | 0x1053 | 0x1054 | 0x1055 | 0x1100 | 0x1d01 | 0x534d | 0xb201 | 0xb202 | 0xb203 | 0xb204 | 0xb205 | 0xb206 | 0xb207 | 0xb208 | 0xb209 | 0xb20a | 0xb20b | 0xb20c | 0xb20d | 0xb20e | 0xb20f | 0xb210 | 0xb211 | 0xb212 | 0xb213 | 0xb214 | 0xb215 | 0xb216 | 0xb217 | 0xb218 | 0xb219 | 0xb21a | 0xb21b | 0xb21c | 0xb21d | 0xb21e | 0xb21f | 0xb220 | 0xb221 | 0xb222 | 0xb223 | 0xb224 | 0xb225 | 0xb226 | 0xb227 | 0xb228 | 0xb229 | 0xb22a | 0xb22b | 0xb22c | 0xb22d | 0xb22e | 0xb22f | 0xb230 | 0xb231 | 0xb232 | 0xb233 | 0xb234 | 0xb235 | 0xb236 | 0xb237 | 0xb238 | 0xb239 | 0xb23a | 0xb23b | 0xb23c | 0xb23d | 0xb23e | 0xb23f | 0xb240 | 0xb241 | 0xb242 | 0xb243 | 0xb244 | 0xb245 | 0xb246 | 0xb247 | 0xb248 | 0xb249 | 0xb24a | 0xb24b | 0xb24c | 0xb24d | 0xb24e | 0xb24f | 0xb250 | 0xb251 | 0xb252 | 0xb253 | 0xb254 | 0xb255 | 0xb256 | 0xb257 | 0xb258 | 0xb259 | 0xb25a | 0xb25b | 0xb25c | 0xb25d | 0xb25e | 0xb25f | 0xb260 | 0xb301 | 0xb302 | 0xb303 | 0xb304 | 0xb305 | 0xb306 | 0xb307 | 0xb308 | 0xb309 | 0xb30a | 0xb30b | 0xb30c | 0xb30d | 0xb30e | 0xb30f | 0xb310 | 0xb311 | 0xb312 | 0xb313 | 0xb314 | 0xb315 | 0xb316 | 0xb317 | 0xb318 | 0xb319 | 0xb31a | 0xb31b | 0xb31c | 0xb31d | 0xb31e | 0xb31f | 0xb320 | 0xb321 | 0xb322 | 0xb323 | 0xb324 | 0xb325 | 0xb326 | 0xb327 | 0xb328 | 0xb329 | 0xb32a | 0xb32b | 0xb32c | 0xb32d | 0xb32e | 0xb32f | 0xb330 | 0xb331 | 0xb332 | 0xb333 | 0xb334 | 0xb335 | 0xb336 | 0xb337 | 0xb338 | 0xb339 | 0xb33a | 0xb33b | 0xb33c | 0xb33d | 0xb33e | 0xb33f | 0xb340 | 0xb341 | 0xb342 | 0xb343 | 0xb344 | 0xb345 | 0xb346 | 0xb347 | 0xb348 | 0xb349 | 0xb34a | 0xb34b | 0xb34c | 0xb34d | 0xb34e | 0xb34f | 0xb350 | 0xb351 | 0xb352 | 0xb353 | 0xb354 | 0xb355 | 0xb356 | 0xb357 | 0xb358 | 0xb359 | 0xb35a | 0xb35b | 0xb35c | 0xb35d | 0xb35e | 0xb35f | 0xb360 | 0xb361 | 0xb362 | 0xb363 | 0xb364 | 0xb365 | 0xb366 | 0xb367 | 0xb368 | 0xb369 | 0xb36a | 0xb36b | 0xb36c | 0xb36d | 0xb36e | 0xb36f | 0xb370 | 0xb371 | 0xb372 | 0xb373 | 0xb374 | 0xb375 | 0xb376 | 0xb377 | 0xb378 | 0xb379 | 0xb37a | 0xb37b | 0xb37c | 0xb37d | 0xb37e | 0xb37f | 0xb380 | 0xb381 | 0xb382 | 0xb383 | 0xb384 | 0xb385 | 0xb386 | 0xb387 | 0xb388 | 0xb389 | 0xb38a | 0xb38b | 0xb38c | 0xb38d | 0xb38e | 0xb38f | 0xb390 | 0xb391 | 0xb392 | 0xb393 | 0xb394 | 0xb395 | 0xb396 | 0xb397 | 0xb398 | 0xb399 | 0xb39a | 0xb39b | 0xb39c | 0xb39d | 0xb39e | 0xb39f | 0xb3a0 | 0xb3a1 | 0xb3a2 | 0xb3a3 | 0xb3a4 | 0xb3a5 | 0xb3a6 | 0xb3a7 | 0xb3a8 | 0xb3a9 | 0xb3aa | 0xb3ab | 0xb3ac | 0xb3ad | 0xb3ae | 0xb3af | 0xb3b0 | 0xb3b1 | 0xb3b2 | 0xb3b3 | 0xb3b4 | 0xb3b5 | 0xb3b6 | 0xb3b7 | 0xb3b8 | 0xb3b9 | 0xb3ba | 0xb3bb | 0xb3bc | 0xb3bd | 0xb3be | 0xb3bf | 0xb3c0 | 0xb3c1 | 0xb3c2 | 0xb3c3 | 0xb3c4 | 0xb3c5 | 0xb3c6 | 0xb3c7 | 0xb3c8 | 0xb3c9 | 0xb3ca | 0xb3cb | 0xb3cc | 0xb3cd | 0xb3ce | 0xb3cf | 0xb3d0 | 0xb3d1 | 0xb3d2 | 0xb3d3 | 0xb3d4 | 0xb3d5 | 0xb3d6 | 0xb3d7 | 0xb3d8 | 0xb3d9 | 0xb3da | 0xb3db | 0xb3dc | 0xb3dd | 0xb3de | 0xb3df | 0xb3e0 | 0xb401 | 0xb402 } HashCode 13 | */ 14 | 15 | /** 16 | * @type { Record } 17 | */ 18 | const names = Object.freeze({ 19 | 'identity': 0x00, 20 | 'sha1': 0x11, 21 | 'sha2-256': 0x12, 22 | 'sha2-512': 0x13, 23 | 'sha3-512': 0x14, 24 | 'sha3-384': 0x15, 25 | 'sha3-256': 0x16, 26 | 'sha3-224': 0x17, 27 | 'shake-128': 0x18, 28 | 'shake-256': 0x19, 29 | 'keccak-224': 0x1a, 30 | 'keccak-256': 0x1b, 31 | 'keccak-384': 0x1c, 32 | 'keccak-512': 0x1d, 33 | 'blake3': 0x1e, 34 | 'murmur3-128': 0x22, 35 | 'murmur3-32': 0x23, 36 | 'dbl-sha2-256': 0x56, 37 | 'md4': 0xd4, 38 | 'md5': 0xd5, 39 | 'bmt': 0xd6, 40 | 'sha2-256-trunc254-padded': 0x1012, 41 | 'ripemd-128': 0x1052, 42 | 'ripemd-160': 0x1053, 43 | 'ripemd-256': 0x1054, 44 | 'ripemd-320': 0x1055, 45 | 'x11': 0x1100, 46 | 'kangarootwelve': 0x1d01, 47 | 'sm3-256': 0x534d, 48 | 'blake2b-8': 0xb201, 49 | 'blake2b-16': 0xb202, 50 | 'blake2b-24': 0xb203, 51 | 'blake2b-32': 0xb204, 52 | 'blake2b-40': 0xb205, 53 | 'blake2b-48': 0xb206, 54 | 'blake2b-56': 0xb207, 55 | 'blake2b-64': 0xb208, 56 | 'blake2b-72': 0xb209, 57 | 'blake2b-80': 0xb20a, 58 | 'blake2b-88': 0xb20b, 59 | 'blake2b-96': 0xb20c, 60 | 'blake2b-104': 0xb20d, 61 | 'blake2b-112': 0xb20e, 62 | 'blake2b-120': 0xb20f, 63 | 'blake2b-128': 0xb210, 64 | 'blake2b-136': 0xb211, 65 | 'blake2b-144': 0xb212, 66 | 'blake2b-152': 0xb213, 67 | 'blake2b-160': 0xb214, 68 | 'blake2b-168': 0xb215, 69 | 'blake2b-176': 0xb216, 70 | 'blake2b-184': 0xb217, 71 | 'blake2b-192': 0xb218, 72 | 'blake2b-200': 0xb219, 73 | 'blake2b-208': 0xb21a, 74 | 'blake2b-216': 0xb21b, 75 | 'blake2b-224': 0xb21c, 76 | 'blake2b-232': 0xb21d, 77 | 'blake2b-240': 0xb21e, 78 | 'blake2b-248': 0xb21f, 79 | 'blake2b-256': 0xb220, 80 | 'blake2b-264': 0xb221, 81 | 'blake2b-272': 0xb222, 82 | 'blake2b-280': 0xb223, 83 | 'blake2b-288': 0xb224, 84 | 'blake2b-296': 0xb225, 85 | 'blake2b-304': 0xb226, 86 | 'blake2b-312': 0xb227, 87 | 'blake2b-320': 0xb228, 88 | 'blake2b-328': 0xb229, 89 | 'blake2b-336': 0xb22a, 90 | 'blake2b-344': 0xb22b, 91 | 'blake2b-352': 0xb22c, 92 | 'blake2b-360': 0xb22d, 93 | 'blake2b-368': 0xb22e, 94 | 'blake2b-376': 0xb22f, 95 | 'blake2b-384': 0xb230, 96 | 'blake2b-392': 0xb231, 97 | 'blake2b-400': 0xb232, 98 | 'blake2b-408': 0xb233, 99 | 'blake2b-416': 0xb234, 100 | 'blake2b-424': 0xb235, 101 | 'blake2b-432': 0xb236, 102 | 'blake2b-440': 0xb237, 103 | 'blake2b-448': 0xb238, 104 | 'blake2b-456': 0xb239, 105 | 'blake2b-464': 0xb23a, 106 | 'blake2b-472': 0xb23b, 107 | 'blake2b-480': 0xb23c, 108 | 'blake2b-488': 0xb23d, 109 | 'blake2b-496': 0xb23e, 110 | 'blake2b-504': 0xb23f, 111 | 'blake2b-512': 0xb240, 112 | 'blake2s-8': 0xb241, 113 | 'blake2s-16': 0xb242, 114 | 'blake2s-24': 0xb243, 115 | 'blake2s-32': 0xb244, 116 | 'blake2s-40': 0xb245, 117 | 'blake2s-48': 0xb246, 118 | 'blake2s-56': 0xb247, 119 | 'blake2s-64': 0xb248, 120 | 'blake2s-72': 0xb249, 121 | 'blake2s-80': 0xb24a, 122 | 'blake2s-88': 0xb24b, 123 | 'blake2s-96': 0xb24c, 124 | 'blake2s-104': 0xb24d, 125 | 'blake2s-112': 0xb24e, 126 | 'blake2s-120': 0xb24f, 127 | 'blake2s-128': 0xb250, 128 | 'blake2s-136': 0xb251, 129 | 'blake2s-144': 0xb252, 130 | 'blake2s-152': 0xb253, 131 | 'blake2s-160': 0xb254, 132 | 'blake2s-168': 0xb255, 133 | 'blake2s-176': 0xb256, 134 | 'blake2s-184': 0xb257, 135 | 'blake2s-192': 0xb258, 136 | 'blake2s-200': 0xb259, 137 | 'blake2s-208': 0xb25a, 138 | 'blake2s-216': 0xb25b, 139 | 'blake2s-224': 0xb25c, 140 | 'blake2s-232': 0xb25d, 141 | 'blake2s-240': 0xb25e, 142 | 'blake2s-248': 0xb25f, 143 | 'blake2s-256': 0xb260, 144 | 'skein256-8': 0xb301, 145 | 'skein256-16': 0xb302, 146 | 'skein256-24': 0xb303, 147 | 'skein256-32': 0xb304, 148 | 'skein256-40': 0xb305, 149 | 'skein256-48': 0xb306, 150 | 'skein256-56': 0xb307, 151 | 'skein256-64': 0xb308, 152 | 'skein256-72': 0xb309, 153 | 'skein256-80': 0xb30a, 154 | 'skein256-88': 0xb30b, 155 | 'skein256-96': 0xb30c, 156 | 'skein256-104': 0xb30d, 157 | 'skein256-112': 0xb30e, 158 | 'skein256-120': 0xb30f, 159 | 'skein256-128': 0xb310, 160 | 'skein256-136': 0xb311, 161 | 'skein256-144': 0xb312, 162 | 'skein256-152': 0xb313, 163 | 'skein256-160': 0xb314, 164 | 'skein256-168': 0xb315, 165 | 'skein256-176': 0xb316, 166 | 'skein256-184': 0xb317, 167 | 'skein256-192': 0xb318, 168 | 'skein256-200': 0xb319, 169 | 'skein256-208': 0xb31a, 170 | 'skein256-216': 0xb31b, 171 | 'skein256-224': 0xb31c, 172 | 'skein256-232': 0xb31d, 173 | 'skein256-240': 0xb31e, 174 | 'skein256-248': 0xb31f, 175 | 'skein256-256': 0xb320, 176 | 'skein512-8': 0xb321, 177 | 'skein512-16': 0xb322, 178 | 'skein512-24': 0xb323, 179 | 'skein512-32': 0xb324, 180 | 'skein512-40': 0xb325, 181 | 'skein512-48': 0xb326, 182 | 'skein512-56': 0xb327, 183 | 'skein512-64': 0xb328, 184 | 'skein512-72': 0xb329, 185 | 'skein512-80': 0xb32a, 186 | 'skein512-88': 0xb32b, 187 | 'skein512-96': 0xb32c, 188 | 'skein512-104': 0xb32d, 189 | 'skein512-112': 0xb32e, 190 | 'skein512-120': 0xb32f, 191 | 'skein512-128': 0xb330, 192 | 'skein512-136': 0xb331, 193 | 'skein512-144': 0xb332, 194 | 'skein512-152': 0xb333, 195 | 'skein512-160': 0xb334, 196 | 'skein512-168': 0xb335, 197 | 'skein512-176': 0xb336, 198 | 'skein512-184': 0xb337, 199 | 'skein512-192': 0xb338, 200 | 'skein512-200': 0xb339, 201 | 'skein512-208': 0xb33a, 202 | 'skein512-216': 0xb33b, 203 | 'skein512-224': 0xb33c, 204 | 'skein512-232': 0xb33d, 205 | 'skein512-240': 0xb33e, 206 | 'skein512-248': 0xb33f, 207 | 'skein512-256': 0xb340, 208 | 'skein512-264': 0xb341, 209 | 'skein512-272': 0xb342, 210 | 'skein512-280': 0xb343, 211 | 'skein512-288': 0xb344, 212 | 'skein512-296': 0xb345, 213 | 'skein512-304': 0xb346, 214 | 'skein512-312': 0xb347, 215 | 'skein512-320': 0xb348, 216 | 'skein512-328': 0xb349, 217 | 'skein512-336': 0xb34a, 218 | 'skein512-344': 0xb34b, 219 | 'skein512-352': 0xb34c, 220 | 'skein512-360': 0xb34d, 221 | 'skein512-368': 0xb34e, 222 | 'skein512-376': 0xb34f, 223 | 'skein512-384': 0xb350, 224 | 'skein512-392': 0xb351, 225 | 'skein512-400': 0xb352, 226 | 'skein512-408': 0xb353, 227 | 'skein512-416': 0xb354, 228 | 'skein512-424': 0xb355, 229 | 'skein512-432': 0xb356, 230 | 'skein512-440': 0xb357, 231 | 'skein512-448': 0xb358, 232 | 'skein512-456': 0xb359, 233 | 'skein512-464': 0xb35a, 234 | 'skein512-472': 0xb35b, 235 | 'skein512-480': 0xb35c, 236 | 'skein512-488': 0xb35d, 237 | 'skein512-496': 0xb35e, 238 | 'skein512-504': 0xb35f, 239 | 'skein512-512': 0xb360, 240 | 'skein1024-8': 0xb361, 241 | 'skein1024-16': 0xb362, 242 | 'skein1024-24': 0xb363, 243 | 'skein1024-32': 0xb364, 244 | 'skein1024-40': 0xb365, 245 | 'skein1024-48': 0xb366, 246 | 'skein1024-56': 0xb367, 247 | 'skein1024-64': 0xb368, 248 | 'skein1024-72': 0xb369, 249 | 'skein1024-80': 0xb36a, 250 | 'skein1024-88': 0xb36b, 251 | 'skein1024-96': 0xb36c, 252 | 'skein1024-104': 0xb36d, 253 | 'skein1024-112': 0xb36e, 254 | 'skein1024-120': 0xb36f, 255 | 'skein1024-128': 0xb370, 256 | 'skein1024-136': 0xb371, 257 | 'skein1024-144': 0xb372, 258 | 'skein1024-152': 0xb373, 259 | 'skein1024-160': 0xb374, 260 | 'skein1024-168': 0xb375, 261 | 'skein1024-176': 0xb376, 262 | 'skein1024-184': 0xb377, 263 | 'skein1024-192': 0xb378, 264 | 'skein1024-200': 0xb379, 265 | 'skein1024-208': 0xb37a, 266 | 'skein1024-216': 0xb37b, 267 | 'skein1024-224': 0xb37c, 268 | 'skein1024-232': 0xb37d, 269 | 'skein1024-240': 0xb37e, 270 | 'skein1024-248': 0xb37f, 271 | 'skein1024-256': 0xb380, 272 | 'skein1024-264': 0xb381, 273 | 'skein1024-272': 0xb382, 274 | 'skein1024-280': 0xb383, 275 | 'skein1024-288': 0xb384, 276 | 'skein1024-296': 0xb385, 277 | 'skein1024-304': 0xb386, 278 | 'skein1024-312': 0xb387, 279 | 'skein1024-320': 0xb388, 280 | 'skein1024-328': 0xb389, 281 | 'skein1024-336': 0xb38a, 282 | 'skein1024-344': 0xb38b, 283 | 'skein1024-352': 0xb38c, 284 | 'skein1024-360': 0xb38d, 285 | 'skein1024-368': 0xb38e, 286 | 'skein1024-376': 0xb38f, 287 | 'skein1024-384': 0xb390, 288 | 'skein1024-392': 0xb391, 289 | 'skein1024-400': 0xb392, 290 | 'skein1024-408': 0xb393, 291 | 'skein1024-416': 0xb394, 292 | 'skein1024-424': 0xb395, 293 | 'skein1024-432': 0xb396, 294 | 'skein1024-440': 0xb397, 295 | 'skein1024-448': 0xb398, 296 | 'skein1024-456': 0xb399, 297 | 'skein1024-464': 0xb39a, 298 | 'skein1024-472': 0xb39b, 299 | 'skein1024-480': 0xb39c, 300 | 'skein1024-488': 0xb39d, 301 | 'skein1024-496': 0xb39e, 302 | 'skein1024-504': 0xb39f, 303 | 'skein1024-512': 0xb3a0, 304 | 'skein1024-520': 0xb3a1, 305 | 'skein1024-528': 0xb3a2, 306 | 'skein1024-536': 0xb3a3, 307 | 'skein1024-544': 0xb3a4, 308 | 'skein1024-552': 0xb3a5, 309 | 'skein1024-560': 0xb3a6, 310 | 'skein1024-568': 0xb3a7, 311 | 'skein1024-576': 0xb3a8, 312 | 'skein1024-584': 0xb3a9, 313 | 'skein1024-592': 0xb3aa, 314 | 'skein1024-600': 0xb3ab, 315 | 'skein1024-608': 0xb3ac, 316 | 'skein1024-616': 0xb3ad, 317 | 'skein1024-624': 0xb3ae, 318 | 'skein1024-632': 0xb3af, 319 | 'skein1024-640': 0xb3b0, 320 | 'skein1024-648': 0xb3b1, 321 | 'skein1024-656': 0xb3b2, 322 | 'skein1024-664': 0xb3b3, 323 | 'skein1024-672': 0xb3b4, 324 | 'skein1024-680': 0xb3b5, 325 | 'skein1024-688': 0xb3b6, 326 | 'skein1024-696': 0xb3b7, 327 | 'skein1024-704': 0xb3b8, 328 | 'skein1024-712': 0xb3b9, 329 | 'skein1024-720': 0xb3ba, 330 | 'skein1024-728': 0xb3bb, 331 | 'skein1024-736': 0xb3bc, 332 | 'skein1024-744': 0xb3bd, 333 | 'skein1024-752': 0xb3be, 334 | 'skein1024-760': 0xb3bf, 335 | 'skein1024-768': 0xb3c0, 336 | 'skein1024-776': 0xb3c1, 337 | 'skein1024-784': 0xb3c2, 338 | 'skein1024-792': 0xb3c3, 339 | 'skein1024-800': 0xb3c4, 340 | 'skein1024-808': 0xb3c5, 341 | 'skein1024-816': 0xb3c6, 342 | 'skein1024-824': 0xb3c7, 343 | 'skein1024-832': 0xb3c8, 344 | 'skein1024-840': 0xb3c9, 345 | 'skein1024-848': 0xb3ca, 346 | 'skein1024-856': 0xb3cb, 347 | 'skein1024-864': 0xb3cc, 348 | 'skein1024-872': 0xb3cd, 349 | 'skein1024-880': 0xb3ce, 350 | 'skein1024-888': 0xb3cf, 351 | 'skein1024-896': 0xb3d0, 352 | 'skein1024-904': 0xb3d1, 353 | 'skein1024-912': 0xb3d2, 354 | 'skein1024-920': 0xb3d3, 355 | 'skein1024-928': 0xb3d4, 356 | 'skein1024-936': 0xb3d5, 357 | 'skein1024-944': 0xb3d6, 358 | 'skein1024-952': 0xb3d7, 359 | 'skein1024-960': 0xb3d8, 360 | 'skein1024-968': 0xb3d9, 361 | 'skein1024-976': 0xb3da, 362 | 'skein1024-984': 0xb3db, 363 | 'skein1024-992': 0xb3dc, 364 | 'skein1024-1000': 0xb3dd, 365 | 'skein1024-1008': 0xb3de, 366 | 'skein1024-1016': 0xb3df, 367 | 'skein1024-1024': 0xb3e0, 368 | 'poseidon-bls12_381-a2-fc1': 0xb401, 369 | 'poseidon-bls12_381-a2-fc1-sc': 0xb402 370 | }) 371 | 372 | module.exports = { names } 373 | --------------------------------------------------------------------------------