diff --git a/.aegir.js b/.aegir.js new file mode 100644 index 00000000..7267952d --- /dev/null +++ b/.aegir.js @@ -0,0 +1,17 @@ +"use strict" + +module.exports = { + // Have not used webpack so just copied proposed setup from + // https://babeljs.io/docs/setup/#installation + webpack: { + module: { + rules: [ + { + test: /\.js$/, + exclude: /node_modules/, + loader: "babel-loader" + } + ] + } + } +} diff --git a/.babelrc b/.babelrc new file mode 100644 index 00000000..0a4cc4b2 --- /dev/null +++ b/.babelrc @@ -0,0 +1,34 @@ +{ + "env": { + "development": { + "sourceMaps": "inline", + "comments": false, + "presets": [ + [ + "env", + { + "targets": { + "node": "current" + } + } + ], + "flow-node" + ] + }, + "umd": { + "comments": false, + "presets": [ + [ + "env", + { + "modules": false, + "targets": { + "browsers": "last 2 versions" + } + } + ], + "flow-node" + ] + } + } +} diff --git a/.flowconfig b/.flowconfig new file mode 100644 index 00000000..57c6722d --- /dev/null +++ b/.flowconfig @@ -0,0 +1,9 @@ +[ignore] +.*/node_modules/documentation/* + +[libs] + +[include] + +[options] +suppress_comment= \\(.\\|\n\\)*\\@FlowIgnore diff --git a/.gitignore b/.gitignore index 68363e01..070f6bd0 100644 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ node_modules dist docs +lib diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..03d9dffe --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "editor.formatOnSave": false, + "json.format.enable": false +} \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index 046bf910..bc74b9d1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -24,6 +24,7 @@ install: - npm install test_script: + - npm run build:node - npm run test:node build: off diff --git a/package.json b/package.json index ed8cb184..18d13334 100644 --- a/package.json +++ b/package.json @@ -2,19 +2,30 @@ "name": "multihashes", "version": "0.4.13", "description": "multihash implementation", - "main": "src/index.js", + "main": "lib/index.js", "scripts": { - "lint": "aegir lint", + "lint": "lint-staged && npm run type-check", "test:browser": "aegir test --target browser", "test:node": "aegir test --target node", - "build": "aegir build", - "test": "aegir test", + "type-check": "flow check", + "build": "npm run build:node && BABEL_ENV=umd aegir build", + "test": "npm run build:node && aegir test", "docs": "aegir docs", "release": "aegir release --docs", "release-minor": "aegir release --type minor --docs", "release-major": "aegir release --type major --docs", "coverage": "aegir coverage", - "coverage-publish": "aegir coverage --provider coveralls" + "coverage-publish": "aegir coverage --provider coveralls", + "build:types": "flow-copy-source --verbose src lib", + "build:lib": "babel --out-dir lib src", + "build:node": "npm run build:types && npm run build:lib", + "start": "flow-copy-source --watch --verbose src lib & babel --watch --out-dir lib src" + }, + "lint-staged": { + "*.js": [ + "prettier --no-semi --write", + "git add" + ] }, "pre-commit": [ "lint", @@ -43,10 +54,21 @@ }, "devDependencies": { "aegir": "^12.3.0", + "babel-cli": "6.26.0", + "babel-core": "6.26.0", + "babel-loader": "7.1.2", + "babel-preset-flow-node": "2.0.1", "buffer-equal": "1.0.0", "chai": "^4.1.2", "dirty-chai": "^2.0.1", - "pre-commit": "^1.2.2" + "flow-bin": "^0.66.0", + "flow-copy-source": "^1.2.0", + "lint-staged": "^6.0.0", + "pre-commit": "^1.2.2", + "prettier": "1.10.2", + "rollup": "0.56.1", + "rollup.config.flow": "1.0.0", + "source-map-support": "0.5.3" }, "contributors": [ "Alan Shaw ", diff --git a/src/constants.js b/src/constants.js index bb088164..011e9cab 100644 --- a/src/constants.js +++ b/src/constants.js @@ -1,8 +1,10 @@ +/* @flow */ /* eslint quote-props: off */ /* eslint key-spacing: off */ 'use strict' -exports.names = Object.freeze({ + +export const names = Object.freeze({ 'sha1': 0x11, 'sha2-256': 0x12, 'sha2-512': 0x13, @@ -341,684 +343,687 @@ exports.names = Object.freeze({ 'Skein1024-1024': 0xb3e0 }) -exports.codes = Object.freeze({ - 0x11: 'sha1', - 0x12: 'sha2-256', - 0x13: 'sha2-512', - 0x56: 'dbl-sha2-256', - 0x17: 'sha3-224', - 0x16: 'sha3-256', - 0x15: 'sha3-384', - 0x14: 'sha3-512', - 0x18: 'shake-128', - 0x19: 'shake-256', - 0x1A: 'keccak-224', - 0x1B: 'keccak-256', - 0x1C: 'keccak-384', - 0x1D: 'keccak-512', - 0x22: 'murmur3-128', - 0x23: 'murmur3-32', +export type Name = $Keys +export type Code = $Values + +export const codes:{[Code]:Name} = Object.freeze({ + [0x11]: 'sha1', + [0x12]: 'sha2-256', + [0x13]: 'sha2-512', + [0x56]: 'dbl-sha2-256', + [0x17]: 'sha3-224', + [0x16]: 'sha3-256', + [0x15]: 'sha3-384', + [0x14]: 'sha3-512', + [0x18]: 'shake-128', + [0x19]: 'shake-256', + [0x1A]: 'keccak-224', + [0x1B]: 'keccak-256', + [0x1C]: 'keccak-384', + [0x1D]: 'keccak-512', + [0x22]: 'murmur3-128', + [0x23]: 'murmur3-32', // blake2 - 0xb201: 'blake2b-8', - 0xb202: 'blake2b-16', - 0xb203: 'blake2b-24', - 0xb204: 'blake2b-32', - 0xb205: 'blake2b-40', - 0xb206: 'blake2b-48', - 0xb207: 'blake2b-56', - 0xb208: 'blake2b-64', - 0xb209: 'blake2b-72', - 0xb20a: 'blake2b-80', - 0xb20b: 'blake2b-88', - 0xb20c: 'blake2b-96', - 0xb20d: 'blake2b-104', - 0xb20e: 'blake2b-112', - 0xb20f: 'blake2b-120', - 0xb210: 'blake2b-128', - 0xb211: 'blake2b-136', - 0xb212: 'blake2b-144', - 0xb213: 'blake2b-152', - 0xb214: 'blake2b-160', - 0xb215: 'blake2b-168', - 0xb216: 'blake2b-176', - 0xb217: 'blake2b-184', - 0xb218: 'blake2b-192', - 0xb219: 'blake2b-200', - 0xb21a: 'blake2b-208', - 0xb21b: 'blake2b-216', - 0xb21c: 'blake2b-224', - 0xb21d: 'blake2b-232', - 0xb21e: 'blake2b-240', - 0xb21f: 'blake2b-248', - 0xb220: 'blake2b-256', - 0xb221: 'blake2b-264', - 0xb222: 'blake2b-272', - 0xb223: 'blake2b-280', - 0xb224: 'blake2b-288', - 0xb225: 'blake2b-296', - 0xb226: 'blake2b-304', - 0xb227: 'blake2b-312', - 0xb228: 'blake2b-320', - 0xb229: 'blake2b-328', - 0xb22a: 'blake2b-336', - 0xb22b: 'blake2b-344', - 0xb22c: 'blake2b-352', - 0xb22d: 'blake2b-360', - 0xb22e: 'blake2b-368', - 0xb22f: 'blake2b-376', - 0xb230: 'blake2b-384', - 0xb231: 'blake2b-392', - 0xb232: 'blake2b-400', - 0xb233: 'blake2b-408', - 0xb234: 'blake2b-416', - 0xb235: 'blake2b-424', - 0xb236: 'blake2b-432', - 0xb237: 'blake2b-440', - 0xb238: 'blake2b-448', - 0xb239: 'blake2b-456', - 0xb23a: 'blake2b-464', - 0xb23b: 'blake2b-472', - 0xb23c: 'blake2b-480', - 0xb23d: 'blake2b-488', - 0xb23e: 'blake2b-496', - 0xb23f: 'blake2b-504', - 0xb240: 'blake2b-512', - 0xb241: 'blake2s-8', - 0xb242: 'blake2s-16', - 0xb243: 'blake2s-24', - 0xb244: 'blake2s-32', - 0xb245: 'blake2s-40', - 0xb246: 'blake2s-48', - 0xb247: 'blake2s-56', - 0xb248: 'blake2s-64', - 0xb249: 'blake2s-72', - 0xb24a: 'blake2s-80', - 0xb24b: 'blake2s-88', - 0xb24c: 'blake2s-96', - 0xb24d: 'blake2s-104', - 0xb24e: 'blake2s-112', - 0xb24f: 'blake2s-120', - 0xb250: 'blake2s-128', - 0xb251: 'blake2s-136', - 0xb252: 'blake2s-144', - 0xb253: 'blake2s-152', - 0xb254: 'blake2s-160', - 0xb255: 'blake2s-168', - 0xb256: 'blake2s-176', - 0xb257: 'blake2s-184', - 0xb258: 'blake2s-192', - 0xb259: 'blake2s-200', - 0xb25a: 'blake2s-208', - 0xb25b: 'blake2s-216', - 0xb25c: 'blake2s-224', - 0xb25d: 'blake2s-232', - 0xb25e: 'blake2s-240', - 0xb25f: 'blake2s-248', - 0xb260: 'blake2s-256', + [0xb201]: 'blake2b-8', + [0xb202]: 'blake2b-16', + [0xb203]: 'blake2b-24', + [0xb204]: 'blake2b-32', + [0xb205]: 'blake2b-40', + [0xb206]: 'blake2b-48', + [0xb207]: 'blake2b-56', + [0xb208]: 'blake2b-64', + [0xb209]: 'blake2b-72', + [0xb20a]: 'blake2b-80', + [0xb20b]: 'blake2b-88', + [0xb20c]: 'blake2b-96', + [0xb20d]: 'blake2b-104', + [0xb20e]: 'blake2b-112', + [0xb20f]: 'blake2b-120', + [0xb210]: 'blake2b-128', + [0xb211]: 'blake2b-136', + [0xb212]: 'blake2b-144', + [0xb213]: 'blake2b-152', + [0xb214]: 'blake2b-160', + [0xb215]: 'blake2b-168', + [0xb216]: 'blake2b-176', + [0xb217]: 'blake2b-184', + [0xb218]: 'blake2b-192', + [0xb219]: 'blake2b-200', + [0xb21a]: 'blake2b-208', + [0xb21b]: 'blake2b-216', + [0xb21c]: 'blake2b-224', + [0xb21d]: 'blake2b-232', + [0xb21e]: 'blake2b-240', + [0xb21f]: 'blake2b-248', + [0xb220]: 'blake2b-256', + [0xb221]: 'blake2b-264', + [0xb222]: 'blake2b-272', + [0xb223]: 'blake2b-280', + [0xb224]: 'blake2b-288', + [0xb225]: 'blake2b-296', + [0xb226]: 'blake2b-304', + [0xb227]: 'blake2b-312', + [0xb228]: 'blake2b-320', + [0xb229]: 'blake2b-328', + [0xb22a]: 'blake2b-336', + [0xb22b]: 'blake2b-344', + [0xb22c]: 'blake2b-352', + [0xb22d]: 'blake2b-360', + [0xb22e]: 'blake2b-368', + [0xb22f]: 'blake2b-376', + [0xb230]: 'blake2b-384', + [0xb231]: 'blake2b-392', + [0xb232]: 'blake2b-400', + [0xb233]: 'blake2b-408', + [0xb234]: 'blake2b-416', + [0xb235]: 'blake2b-424', + [0xb236]: 'blake2b-432', + [0xb237]: 'blake2b-440', + [0xb238]: 'blake2b-448', + [0xb239]: 'blake2b-456', + [0xb23a]: 'blake2b-464', + [0xb23b]: 'blake2b-472', + [0xb23c]: 'blake2b-480', + [0xb23d]: 'blake2b-488', + [0xb23e]: 'blake2b-496', + [0xb23f]: 'blake2b-504', + [0xb240]: 'blake2b-512', + [0xb241]: 'blake2s-8', + [0xb242]: 'blake2s-16', + [0xb243]: 'blake2s-24', + [0xb244]: 'blake2s-32', + [0xb245]: 'blake2s-40', + [0xb246]: 'blake2s-48', + [0xb247]: 'blake2s-56', + [0xb248]: 'blake2s-64', + [0xb249]: 'blake2s-72', + [0xb24a]: 'blake2s-80', + [0xb24b]: 'blake2s-88', + [0xb24c]: 'blake2s-96', + [0xb24d]: 'blake2s-104', + [0xb24e]: 'blake2s-112', + [0xb24f]: 'blake2s-120', + [0xb250]: 'blake2s-128', + [0xb251]: 'blake2s-136', + [0xb252]: 'blake2s-144', + [0xb253]: 'blake2s-152', + [0xb254]: 'blake2s-160', + [0xb255]: 'blake2s-168', + [0xb256]: 'blake2s-176', + [0xb257]: 'blake2s-184', + [0xb258]: 'blake2s-192', + [0xb259]: 'blake2s-200', + [0xb25a]: 'blake2s-208', + [0xb25b]: 'blake2s-216', + [0xb25c]: 'blake2s-224', + [0xb25d]: 'blake2s-232', + [0xb25e]: 'blake2s-240', + [0xb25f]: 'blake2s-248', + [0xb260]: 'blake2s-256', // skein - 0xb301: 'Skein256-8', - 0xb302: 'Skein256-16', - 0xb303: 'Skein256-24', - 0xb304: 'Skein256-32', - 0xb305: 'Skein256-40', - 0xb306: 'Skein256-48', - 0xb307: 'Skein256-56', - 0xb308: 'Skein256-64', - 0xb309: 'Skein256-72', - 0xb30a: 'Skein256-80', - 0xb30b: 'Skein256-88', - 0xb30c: 'Skein256-96', - 0xb30d: 'Skein256-104', - 0xb30e: 'Skein256-112', - 0xb30f: 'Skein256-120', - 0xb310: 'Skein256-128', - 0xb311: 'Skein256-136', - 0xb312: 'Skein256-144', - 0xb313: 'Skein256-152', - 0xb314: 'Skein256-160', - 0xb315: 'Skein256-168', - 0xb316: 'Skein256-176', - 0xb317: 'Skein256-184', - 0xb318: 'Skein256-192', - 0xb319: 'Skein256-200', - 0xb31a: 'Skein256-208', - 0xb31b: 'Skein256-216', - 0xb31c: 'Skein256-224', - 0xb31d: 'Skein256-232', - 0xb31e: 'Skein256-240', - 0xb31f: 'Skein256-248', - 0xb320: 'Skein256-256', - 0xb321: 'Skein512-8', - 0xb322: 'Skein512-16', - 0xb323: 'Skein512-24', - 0xb324: 'Skein512-32', - 0xb325: 'Skein512-40', - 0xb326: 'Skein512-48', - 0xb327: 'Skein512-56', - 0xb328: 'Skein512-64', - 0xb329: 'Skein512-72', - 0xb32a: 'Skein512-80', - 0xb32b: 'Skein512-88', - 0xb32c: 'Skein512-96', - 0xb32d: 'Skein512-104', - 0xb32e: 'Skein512-112', - 0xb32f: 'Skein512-120', - 0xb330: 'Skein512-128', - 0xb331: 'Skein512-136', - 0xb332: 'Skein512-144', - 0xb333: 'Skein512-152', - 0xb334: 'Skein512-160', - 0xb335: 'Skein512-168', - 0xb336: 'Skein512-176', - 0xb337: 'Skein512-184', - 0xb338: 'Skein512-192', - 0xb339: 'Skein512-200', - 0xb33a: 'Skein512-208', - 0xb33b: 'Skein512-216', - 0xb33c: 'Skein512-224', - 0xb33d: 'Skein512-232', - 0xb33e: 'Skein512-240', - 0xb33f: 'Skein512-248', - 0xb340: 'Skein512-256', - 0xb341: 'Skein512-264', - 0xb342: 'Skein512-272', - 0xb343: 'Skein512-280', - 0xb344: 'Skein512-288', - 0xb345: 'Skein512-296', - 0xb346: 'Skein512-304', - 0xb347: 'Skein512-312', - 0xb348: 'Skein512-320', - 0xb349: 'Skein512-328', - 0xb34a: 'Skein512-336', - 0xb34b: 'Skein512-344', - 0xb34c: 'Skein512-352', - 0xb34d: 'Skein512-360', - 0xb34e: 'Skein512-368', - 0xb34f: 'Skein512-376', - 0xb350: 'Skein512-384', - 0xb351: 'Skein512-392', - 0xb352: 'Skein512-400', - 0xb353: 'Skein512-408', - 0xb354: 'Skein512-416', - 0xb355: 'Skein512-424', - 0xb356: 'Skein512-432', - 0xb357: 'Skein512-440', - 0xb358: 'Skein512-448', - 0xb359: 'Skein512-456', - 0xb35a: 'Skein512-464', - 0xb35b: 'Skein512-472', - 0xb35c: 'Skein512-480', - 0xb35d: 'Skein512-488', - 0xb35e: 'Skein512-496', - 0xb35f: 'Skein512-504', - 0xb360: 'Skein512-512', - 0xb361: 'Skein1024-8', - 0xb362: 'Skein1024-16', - 0xb363: 'Skein1024-24', - 0xb364: 'Skein1024-32', - 0xb365: 'Skein1024-40', - 0xb366: 'Skein1024-48', - 0xb367: 'Skein1024-56', - 0xb368: 'Skein1024-64', - 0xb369: 'Skein1024-72', - 0xb36a: 'Skein1024-80', - 0xb36b: 'Skein1024-88', - 0xb36c: 'Skein1024-96', - 0xb36d: 'Skein1024-104', - 0xb36e: 'Skein1024-112', - 0xb36f: 'Skein1024-120', - 0xb370: 'Skein1024-128', - 0xb371: 'Skein1024-136', - 0xb372: 'Skein1024-144', - 0xb373: 'Skein1024-152', - 0xb374: 'Skein1024-160', - 0xb375: 'Skein1024-168', - 0xb376: 'Skein1024-176', - 0xb377: 'Skein1024-184', - 0xb378: 'Skein1024-192', - 0xb379: 'Skein1024-200', - 0xb37a: 'Skein1024-208', - 0xb37b: 'Skein1024-216', - 0xb37c: 'Skein1024-224', - 0xb37d: 'Skein1024-232', - 0xb37e: 'Skein1024-240', - 0xb37f: 'Skein1024-248', - 0xb380: 'Skein1024-256', - 0xb381: 'Skein1024-264', - 0xb382: 'Skein1024-272', - 0xb383: 'Skein1024-280', - 0xb384: 'Skein1024-288', - 0xb385: 'Skein1024-296', - 0xb386: 'Skein1024-304', - 0xb387: 'Skein1024-312', - 0xb388: 'Skein1024-320', - 0xb389: 'Skein1024-328', - 0xb38a: 'Skein1024-336', - 0xb38b: 'Skein1024-344', - 0xb38c: 'Skein1024-352', - 0xb38d: 'Skein1024-360', - 0xb38e: 'Skein1024-368', - 0xb38f: 'Skein1024-376', - 0xb390: 'Skein1024-384', - 0xb391: 'Skein1024-392', - 0xb392: 'Skein1024-400', - 0xb393: 'Skein1024-408', - 0xb394: 'Skein1024-416', - 0xb395: 'Skein1024-424', - 0xb396: 'Skein1024-432', - 0xb397: 'Skein1024-440', - 0xb398: 'Skein1024-448', - 0xb399: 'Skein1024-456', - 0xb39a: 'Skein1024-464', - 0xb39b: 'Skein1024-472', - 0xb39c: 'Skein1024-480', - 0xb39d: 'Skein1024-488', - 0xb39e: 'Skein1024-496', - 0xb39f: 'Skein1024-504', - 0xb3a0: 'Skein1024-512', - 0xb3a1: 'Skein1024-520', - 0xb3a2: 'Skein1024-528', - 0xb3a3: 'Skein1024-536', - 0xb3a4: 'Skein1024-544', - 0xb3a5: 'Skein1024-552', - 0xb3a6: 'Skein1024-560', - 0xb3a7: 'Skein1024-568', - 0xb3a8: 'Skein1024-576', - 0xb3a9: 'Skein1024-584', - 0xb3aa: 'Skein1024-592', - 0xb3ab: 'Skein1024-600', - 0xb3ac: 'Skein1024-608', - 0xb3ad: 'Skein1024-616', - 0xb3ae: 'Skein1024-624', - 0xb3af: 'Skein1024-632', - 0xb3b0: 'Skein1024-640', - 0xb3b1: 'Skein1024-648', - 0xb3b2: 'Skein1024-656', - 0xb3b3: 'Skein1024-664', - 0xb3b4: 'Skein1024-672', - 0xb3b5: 'Skein1024-680', - 0xb3b6: 'Skein1024-688', - 0xb3b7: 'Skein1024-696', - 0xb3b8: 'Skein1024-704', - 0xb3b9: 'Skein1024-712', - 0xb3ba: 'Skein1024-720', - 0xb3bb: 'Skein1024-728', - 0xb3bc: 'Skein1024-736', - 0xb3bd: 'Skein1024-744', - 0xb3be: 'Skein1024-752', - 0xb3bf: 'Skein1024-760', - 0xb3c0: 'Skein1024-768', - 0xb3c1: 'Skein1024-776', - 0xb3c2: 'Skein1024-784', - 0xb3c3: 'Skein1024-792', - 0xb3c4: 'Skein1024-800', - 0xb3c5: 'Skein1024-808', - 0xb3c6: 'Skein1024-816', - 0xb3c7: 'Skein1024-824', - 0xb3c8: 'Skein1024-832', - 0xb3c9: 'Skein1024-840', - 0xb3ca: 'Skein1024-848', - 0xb3cb: 'Skein1024-856', - 0xb3cc: 'Skein1024-864', - 0xb3cd: 'Skein1024-872', - 0xb3ce: 'Skein1024-880', - 0xb3cf: 'Skein1024-888', - 0xb3d0: 'Skein1024-896', - 0xb3d1: 'Skein1024-904', - 0xb3d2: 'Skein1024-912', - 0xb3d3: 'Skein1024-920', - 0xb3d4: 'Skein1024-928', - 0xb3d5: 'Skein1024-936', - 0xb3d6: 'Skein1024-944', - 0xb3d7: 'Skein1024-952', - 0xb3d8: 'Skein1024-960', - 0xb3d9: 'Skein1024-968', - 0xb3da: 'Skein1024-976', - 0xb3db: 'Skein1024-984', - 0xb3dc: 'Skein1024-992', - 0xb3dd: 'Skein1024-1000', - 0xb3de: 'Skein1024-1008', - 0xb3df: 'Skein1024-1016', - 0xb3e0: 'Skein1024-1024' + [0xb301]: 'Skein256-8', + [0xb302]: 'Skein256-16', + [0xb303]: 'Skein256-24', + [0xb304]: 'Skein256-32', + [0xb305]: 'Skein256-40', + [0xb306]: 'Skein256-48', + [0xb307]: 'Skein256-56', + [0xb308]: 'Skein256-64', + [0xb309]: 'Skein256-72', + [0xb30a]: 'Skein256-80', + [0xb30b]: 'Skein256-88', + [0xb30c]: 'Skein256-96', + [0xb30d]: 'Skein256-104', + [0xb30e]: 'Skein256-112', + [0xb30f]: 'Skein256-120', + [0xb310]: 'Skein256-128', + [0xb311]: 'Skein256-136', + [0xb312]: 'Skein256-144', + [0xb313]: 'Skein256-152', + [0xb314]: 'Skein256-160', + [0xb315]: 'Skein256-168', + [0xb316]: 'Skein256-176', + [0xb317]: 'Skein256-184', + [0xb318]: 'Skein256-192', + [0xb319]: 'Skein256-200', + [0xb31a]: 'Skein256-208', + [0xb31b]: 'Skein256-216', + [0xb31c]: 'Skein256-224', + [0xb31d]: 'Skein256-232', + [0xb31e]: 'Skein256-240', + [0xb31f]: 'Skein256-248', + [0xb320]: 'Skein256-256', + [0xb321]: 'Skein512-8', + [0xb322]: 'Skein512-16', + [0xb323]: 'Skein512-24', + [0xb324]: 'Skein512-32', + [0xb325]: 'Skein512-40', + [0xb326]: 'Skein512-48', + [0xb327]: 'Skein512-56', + [0xb328]: 'Skein512-64', + [0xb329]: 'Skein512-72', + [0xb32a]: 'Skein512-80', + [0xb32b]: 'Skein512-88', + [0xb32c]: 'Skein512-96', + [0xb32d]: 'Skein512-104', + [0xb32e]: 'Skein512-112', + [0xb32f]: 'Skein512-120', + [0xb330]: 'Skein512-128', + [0xb331]: 'Skein512-136', + [0xb332]: 'Skein512-144', + [0xb333]: 'Skein512-152', + [0xb334]: 'Skein512-160', + [0xb335]: 'Skein512-168', + [0xb336]: 'Skein512-176', + [0xb337]: 'Skein512-184', + [0xb338]: 'Skein512-192', + [0xb339]: 'Skein512-200', + [0xb33a]: 'Skein512-208', + [0xb33b]: 'Skein512-216', + [0xb33c]: 'Skein512-224', + [0xb33d]: 'Skein512-232', + [0xb33e]: 'Skein512-240', + [0xb33f]: 'Skein512-248', + [0xb340]: 'Skein512-256', + [0xb341]: 'Skein512-264', + [0xb342]: 'Skein512-272', + [0xb343]: 'Skein512-280', + [0xb344]: 'Skein512-288', + [0xb345]: 'Skein512-296', + [0xb346]: 'Skein512-304', + [0xb347]: 'Skein512-312', + [0xb348]: 'Skein512-320', + [0xb349]: 'Skein512-328', + [0xb34a]: 'Skein512-336', + [0xb34b]: 'Skein512-344', + [0xb34c]: 'Skein512-352', + [0xb34d]: 'Skein512-360', + [0xb34e]: 'Skein512-368', + [0xb34f]: 'Skein512-376', + [0xb350]: 'Skein512-384', + [0xb351]: 'Skein512-392', + [0xb352]: 'Skein512-400', + [0xb353]: 'Skein512-408', + [0xb354]: 'Skein512-416', + [0xb355]: 'Skein512-424', + [0xb356]: 'Skein512-432', + [0xb357]: 'Skein512-440', + [0xb358]: 'Skein512-448', + [0xb359]: 'Skein512-456', + [0xb35a]: 'Skein512-464', + [0xb35b]: 'Skein512-472', + [0xb35c]: 'Skein512-480', + [0xb35d]: 'Skein512-488', + [0xb35e]: 'Skein512-496', + [0xb35f]: 'Skein512-504', + [0xb360]: 'Skein512-512', + [0xb361]: 'Skein1024-8', + [0xb362]: 'Skein1024-16', + [0xb363]: 'Skein1024-24', + [0xb364]: 'Skein1024-32', + [0xb365]: 'Skein1024-40', + [0xb366]: 'Skein1024-48', + [0xb367]: 'Skein1024-56', + [0xb368]: 'Skein1024-64', + [0xb369]: 'Skein1024-72', + [0xb36a]: 'Skein1024-80', + [0xb36b]: 'Skein1024-88', + [0xb36c]: 'Skein1024-96', + [0xb36d]: 'Skein1024-104', + [0xb36e]: 'Skein1024-112', + [0xb36f]: 'Skein1024-120', + [0xb370]: 'Skein1024-128', + [0xb371]: 'Skein1024-136', + [0xb372]: 'Skein1024-144', + [0xb373]: 'Skein1024-152', + [0xb374]: 'Skein1024-160', + [0xb375]: 'Skein1024-168', + [0xb376]: 'Skein1024-176', + [0xb377]: 'Skein1024-184', + [0xb378]: 'Skein1024-192', + [0xb379]: 'Skein1024-200', + [0xb37a]: 'Skein1024-208', + [0xb37b]: 'Skein1024-216', + [0xb37c]: 'Skein1024-224', + [0xb37d]: 'Skein1024-232', + [0xb37e]: 'Skein1024-240', + [0xb37f]: 'Skein1024-248', + [0xb380]: 'Skein1024-256', + [0xb381]: 'Skein1024-264', + [0xb382]: 'Skein1024-272', + [0xb383]: 'Skein1024-280', + [0xb384]: 'Skein1024-288', + [0xb385]: 'Skein1024-296', + [0xb386]: 'Skein1024-304', + [0xb387]: 'Skein1024-312', + [0xb388]: 'Skein1024-320', + [0xb389]: 'Skein1024-328', + [0xb38a]: 'Skein1024-336', + [0xb38b]: 'Skein1024-344', + [0xb38c]: 'Skein1024-352', + [0xb38d]: 'Skein1024-360', + [0xb38e]: 'Skein1024-368', + [0xb38f]: 'Skein1024-376', + [0xb390]: 'Skein1024-384', + [0xb391]: 'Skein1024-392', + [0xb392]: 'Skein1024-400', + [0xb393]: 'Skein1024-408', + [0xb394]: 'Skein1024-416', + [0xb395]: 'Skein1024-424', + [0xb396]: 'Skein1024-432', + [0xb397]: 'Skein1024-440', + [0xb398]: 'Skein1024-448', + [0xb399]: 'Skein1024-456', + [0xb39a]: 'Skein1024-464', + [0xb39b]: 'Skein1024-472', + [0xb39c]: 'Skein1024-480', + [0xb39d]: 'Skein1024-488', + [0xb39e]: 'Skein1024-496', + [0xb39f]: 'Skein1024-504', + [0xb3a0]: 'Skein1024-512', + [0xb3a1]: 'Skein1024-520', + [0xb3a2]: 'Skein1024-528', + [0xb3a3]: 'Skein1024-536', + [0xb3a4]: 'Skein1024-544', + [0xb3a5]: 'Skein1024-552', + [0xb3a6]: 'Skein1024-560', + [0xb3a7]: 'Skein1024-568', + [0xb3a8]: 'Skein1024-576', + [0xb3a9]: 'Skein1024-584', + [0xb3aa]: 'Skein1024-592', + [0xb3ab]: 'Skein1024-600', + [0xb3ac]: 'Skein1024-608', + [0xb3ad]: 'Skein1024-616', + [0xb3ae]: 'Skein1024-624', + [0xb3af]: 'Skein1024-632', + [0xb3b0]: 'Skein1024-640', + [0xb3b1]: 'Skein1024-648', + [0xb3b2]: 'Skein1024-656', + [0xb3b3]: 'Skein1024-664', + [0xb3b4]: 'Skein1024-672', + [0xb3b5]: 'Skein1024-680', + [0xb3b6]: 'Skein1024-688', + [0xb3b7]: 'Skein1024-696', + [0xb3b8]: 'Skein1024-704', + [0xb3b9]: 'Skein1024-712', + [0xb3ba]: 'Skein1024-720', + [0xb3bb]: 'Skein1024-728', + [0xb3bc]: 'Skein1024-736', + [0xb3bd]: 'Skein1024-744', + [0xb3be]: 'Skein1024-752', + [0xb3bf]: 'Skein1024-760', + [0xb3c0]: 'Skein1024-768', + [0xb3c1]: 'Skein1024-776', + [0xb3c2]: 'Skein1024-784', + [0xb3c3]: 'Skein1024-792', + [0xb3c4]: 'Skein1024-800', + [0xb3c5]: 'Skein1024-808', + [0xb3c6]: 'Skein1024-816', + [0xb3c7]: 'Skein1024-824', + [0xb3c8]: 'Skein1024-832', + [0xb3c9]: 'Skein1024-840', + [0xb3ca]: 'Skein1024-848', + [0xb3cb]: 'Skein1024-856', + [0xb3cc]: 'Skein1024-864', + [0xb3cd]: 'Skein1024-872', + [0xb3ce]: 'Skein1024-880', + [0xb3cf]: 'Skein1024-888', + [0xb3d0]: 'Skein1024-896', + [0xb3d1]: 'Skein1024-904', + [0xb3d2]: 'Skein1024-912', + [0xb3d3]: 'Skein1024-920', + [0xb3d4]: 'Skein1024-928', + [0xb3d5]: 'Skein1024-936', + [0xb3d6]: 'Skein1024-944', + [0xb3d7]: 'Skein1024-952', + [0xb3d8]: 'Skein1024-960', + [0xb3d9]: 'Skein1024-968', + [0xb3da]: 'Skein1024-976', + [0xb3db]: 'Skein1024-984', + [0xb3dc]: 'Skein1024-992', + [0xb3dd]: 'Skein1024-1000', + [0xb3de]: 'Skein1024-1008', + [0xb3df]: 'Skein1024-1016', + [0xb3e0]: 'Skein1024-1024' }) -exports.defaultLengths = Object.freeze({ - 0x11: 20, - 0x12: 32, - 0x13: 64, - 0x56: 32, - 0x17: 28, - 0x16: 32, - 0x15: 48, - 0x14: 64, - 0x18: 32, - 0x19: 64, - 0x1A: 28, - 0x1B: 32, - 0x1C: 48, - 0x1D: 64, - 0x22: 32, +export const defaultLengths:{[Code]:number} = Object.freeze({ + [0x11]: 20, + [0x12]: 32, + [0x13]: 64, + [0x56]: 32, + [0x17]: 28, + [0x16]: 32, + [0x15]: 48, + [0x14]: 64, + [0x18]: 32, + [0x19]: 64, + [0x1A]: 28, + [0x1B]: 32, + [0x1C]: 48, + [0x1D]: 64, + [0x22]: 32, - 0xb201: 0x01, - 0xb202: 0x02, - 0xb203: 0x03, - 0xb204: 0x04, - 0xb205: 0x05, - 0xb206: 0x06, - 0xb207: 0x07, - 0xb208: 0x08, - 0xb209: 0x09, - 0xb20a: 0x0a, - 0xb20b: 0x0b, - 0xb20c: 0x0c, - 0xb20d: 0x0d, - 0xb20e: 0x0e, - 0xb20f: 0x0f, - 0xb210: 0x10, - 0xb211: 0x11, - 0xb212: 0x12, - 0xb213: 0x13, - 0xb214: 0x14, - 0xb215: 0x15, - 0xb216: 0x16, - 0xb217: 0x17, - 0xb218: 0x18, - 0xb219: 0x19, - 0xb21a: 0x1a, - 0xb21b: 0x1b, - 0xb21c: 0x1c, - 0xb21d: 0x1d, - 0xb21e: 0x1e, - 0xb21f: 0x1f, - 0xb220: 0x20, - 0xb221: 0x21, - 0xb222: 0x22, - 0xb223: 0x23, - 0xb224: 0x24, - 0xb225: 0x25, - 0xb226: 0x26, - 0xb227: 0x27, - 0xb228: 0x28, - 0xb229: 0x29, - 0xb22a: 0x2a, - 0xb22b: 0x2b, - 0xb22c: 0x2c, - 0xb22d: 0x2d, - 0xb22e: 0x2e, - 0xb22f: 0x2f, - 0xb230: 0x30, - 0xb231: 0x31, - 0xb232: 0x32, - 0xb233: 0x33, - 0xb234: 0x34, - 0xb235: 0x35, - 0xb236: 0x36, - 0xb237: 0x37, - 0xb238: 0x38, - 0xb239: 0x39, - 0xb23a: 0x3a, - 0xb23b: 0x3b, - 0xb23c: 0x3c, - 0xb23d: 0x3d, - 0xb23e: 0x3e, - 0xb23f: 0x3f, - 0xb240: 0x40, - 0xb241: 0x01, - 0xb242: 0x02, - 0xb243: 0x03, - 0xb244: 0x04, - 0xb245: 0x05, - 0xb246: 0x06, - 0xb247: 0x07, - 0xb248: 0x08, - 0xb249: 0x09, - 0xb24a: 0x0a, - 0xb24b: 0x0b, - 0xb24c: 0x0c, - 0xb24d: 0x0d, - 0xb24e: 0x0e, - 0xb24f: 0x0f, - 0xb250: 0x10, - 0xb251: 0x11, - 0xb252: 0x12, - 0xb253: 0x13, - 0xb254: 0x14, - 0xb255: 0x15, - 0xb256: 0x16, - 0xb257: 0x17, - 0xb258: 0x18, - 0xb259: 0x19, - 0xb25a: 0x1a, - 0xb25b: 0x1b, - 0xb25c: 0x1c, - 0xb25d: 0x1d, - 0xb25e: 0x1e, - 0xb25f: 0x1f, - 0xb260: 0x20, - 0xb301: 0x01, - 0xb302: 0x02, - 0xb303: 0x03, - 0xb304: 0x04, - 0xb305: 0x05, - 0xb306: 0x06, - 0xb307: 0x07, - 0xb308: 0x08, - 0xb309: 0x09, - 0xb30a: 0x0a, - 0xb30b: 0x0b, - 0xb30c: 0x0c, - 0xb30d: 0x0d, - 0xb30e: 0x0e, - 0xb30f: 0x0f, - 0xb310: 0x10, - 0xb311: 0x11, - 0xb312: 0x12, - 0xb313: 0x13, - 0xb314: 0x14, - 0xb315: 0x15, - 0xb316: 0x16, - 0xb317: 0x17, - 0xb318: 0x18, - 0xb319: 0x19, - 0xb31a: 0x1a, - 0xb31b: 0x1b, - 0xb31c: 0x1c, - 0xb31d: 0x1d, - 0xb31e: 0x1e, - 0xb31f: 0x1f, - 0xb320: 0x20, - 0xb321: 0x01, - 0xb322: 0x02, - 0xb323: 0x03, - 0xb324: 0x04, - 0xb325: 0x05, - 0xb326: 0x06, - 0xb327: 0x07, - 0xb328: 0x08, - 0xb329: 0x09, - 0xb32a: 0x0a, - 0xb32b: 0x0b, - 0xb32c: 0x0c, - 0xb32d: 0x0d, - 0xb32e: 0x0e, - 0xb32f: 0x0f, - 0xb330: 0x10, - 0xb331: 0x11, - 0xb332: 0x12, - 0xb333: 0x13, - 0xb334: 0x14, - 0xb335: 0x15, - 0xb336: 0x16, - 0xb337: 0x17, - 0xb338: 0x18, - 0xb339: 0x19, - 0xb33a: 0x1a, - 0xb33b: 0x1b, - 0xb33c: 0x1c, - 0xb33d: 0x1d, - 0xb33e: 0x1e, - 0xb33f: 0x1f, - 0xb340: 0x20, - 0xb341: 0x21, - 0xb342: 0x22, - 0xb343: 0x23, - 0xb344: 0x24, - 0xb345: 0x25, - 0xb346: 0x26, - 0xb347: 0x27, - 0xb348: 0x28, - 0xb349: 0x29, - 0xb34a: 0x2a, - 0xb34b: 0x2b, - 0xb34c: 0x2c, - 0xb34d: 0x2d, - 0xb34e: 0x2e, - 0xb34f: 0x2f, - 0xb350: 0x30, - 0xb351: 0x31, - 0xb352: 0x32, - 0xb353: 0x33, - 0xb354: 0x34, - 0xb355: 0x35, - 0xb356: 0x36, - 0xb357: 0x37, - 0xb358: 0x38, - 0xb359: 0x39, - 0xb35a: 0x3a, - 0xb35b: 0x3b, - 0xb35c: 0x3c, - 0xb35d: 0x3d, - 0xb35e: 0x3e, - 0xb35f: 0x3f, - 0xb360: 0x40, - 0xb361: 0x01, - 0xb362: 0x02, - 0xb363: 0x03, - 0xb364: 0x04, - 0xb365: 0x05, - 0xb366: 0x06, - 0xb367: 0x07, - 0xb368: 0x08, - 0xb369: 0x09, - 0xb36a: 0x0a, - 0xb36b: 0x0b, - 0xb36c: 0x0c, - 0xb36d: 0x0d, - 0xb36e: 0x0e, - 0xb36f: 0x0f, - 0xb370: 0x10, - 0xb371: 0x11, - 0xb372: 0x12, - 0xb373: 0x13, - 0xb374: 0x14, - 0xb375: 0x15, - 0xb376: 0x16, - 0xb377: 0x17, - 0xb378: 0x18, - 0xb379: 0x19, - 0xb37a: 0x1a, - 0xb37b: 0x1b, - 0xb37c: 0x1c, - 0xb37d: 0x1d, - 0xb37e: 0x1e, - 0xb37f: 0x1f, - 0xb380: 0x20, - 0xb381: 0x21, - 0xb382: 0x22, - 0xb383: 0x23, - 0xb384: 0x24, - 0xb385: 0x25, - 0xb386: 0x26, - 0xb387: 0x27, - 0xb388: 0x28, - 0xb389: 0x29, - 0xb38a: 0x2a, - 0xb38b: 0x2b, - 0xb38c: 0x2c, - 0xb38d: 0x2d, - 0xb38e: 0x2e, - 0xb38f: 0x2f, - 0xb390: 0x30, - 0xb391: 0x31, - 0xb392: 0x32, - 0xb393: 0x33, - 0xb394: 0x34, - 0xb395: 0x35, - 0xb396: 0x36, - 0xb397: 0x37, - 0xb398: 0x38, - 0xb399: 0x39, - 0xb39a: 0x3a, - 0xb39b: 0x3b, - 0xb39c: 0x3c, - 0xb39d: 0x3d, - 0xb39e: 0x3e, - 0xb39f: 0x3f, - 0xb3a0: 0x40, - 0xb3a1: 0x41, - 0xb3a2: 0x42, - 0xb3a3: 0x43, - 0xb3a4: 0x44, - 0xb3a5: 0x45, - 0xb3a6: 0x46, - 0xb3a7: 0x47, - 0xb3a8: 0x48, - 0xb3a9: 0x49, - 0xb3aa: 0x4a, - 0xb3ab: 0x4b, - 0xb3ac: 0x4c, - 0xb3ad: 0x4d, - 0xb3ae: 0x4e, - 0xb3af: 0x4f, - 0xb3b0: 0x50, - 0xb3b1: 0x51, - 0xb3b2: 0x52, - 0xb3b3: 0x53, - 0xb3b4: 0x54, - 0xb3b5: 0x55, - 0xb3b6: 0x56, - 0xb3b7: 0x57, - 0xb3b8: 0x58, - 0xb3b9: 0x59, - 0xb3ba: 0x5a, - 0xb3bb: 0x5b, - 0xb3bc: 0x5c, - 0xb3bd: 0x5d, - 0xb3be: 0x5e, - 0xb3bf: 0x5f, - 0xb3c0: 0x60, - 0xb3c1: 0x61, - 0xb3c2: 0x62, - 0xb3c3: 0x63, - 0xb3c4: 0x64, - 0xb3c5: 0x65, - 0xb3c6: 0x66, - 0xb3c7: 0x67, - 0xb3c8: 0x68, - 0xb3c9: 0x69, - 0xb3ca: 0x6a, - 0xb3cb: 0x6b, - 0xb3cc: 0x6c, - 0xb3cd: 0x6d, - 0xb3ce: 0x6e, - 0xb3cf: 0x6f, - 0xb3d0: 0x70, - 0xb3d1: 0x71, - 0xb3d2: 0x72, - 0xb3d3: 0x73, - 0xb3d4: 0x74, - 0xb3d5: 0x75, - 0xb3d6: 0x76, - 0xb3d7: 0x77, - 0xb3d8: 0x78, - 0xb3d9: 0x79, - 0xb3da: 0x7a, - 0xb3db: 0x7b, - 0xb3dc: 0x7c, - 0xb3dd: 0x7d, - 0xb3de: 0x7e, - 0xb3df: 0x7f, - 0xb3e0: 0x80 + [0xb201]: 0x01, + [0xb202]: 0x02, + [0xb203]: 0x03, + [0xb204]: 0x04, + [0xb205]: 0x05, + [0xb206]: 0x06, + [0xb207]: 0x07, + [0xb208]: 0x08, + [0xb209]: 0x09, + [0xb20a]: 0x0a, + [0xb20b]: 0x0b, + [0xb20c]: 0x0c, + [0xb20d]: 0x0d, + [0xb20e]: 0x0e, + [0xb20f]: 0x0f, + [0xb210]: 0x10, + [0xb211]: 0x11, + [0xb212]: 0x12, + [0xb213]: 0x13, + [0xb214]: 0x14, + [0xb215]: 0x15, + [0xb216]: 0x16, + [0xb217]: 0x17, + [0xb218]: 0x18, + [0xb219]: 0x19, + [0xb21a]: 0x1a, + [0xb21b]: 0x1b, + [0xb21c]: 0x1c, + [0xb21d]: 0x1d, + [0xb21e]: 0x1e, + [0xb21f]: 0x1f, + [0xb220]: 0x20, + [0xb221]: 0x21, + [0xb222]: 0x22, + [0xb223]: 0x23, + [0xb224]: 0x24, + [0xb225]: 0x25, + [0xb226]: 0x26, + [0xb227]: 0x27, + [0xb228]: 0x28, + [0xb229]: 0x29, + [0xb22a]: 0x2a, + [0xb22b]: 0x2b, + [0xb22c]: 0x2c, + [0xb22d]: 0x2d, + [0xb22e]: 0x2e, + [0xb22f]: 0x2f, + [0xb230]: 0x30, + [0xb231]: 0x31, + [0xb232]: 0x32, + [0xb233]: 0x33, + [0xb234]: 0x34, + [0xb235]: 0x35, + [0xb236]: 0x36, + [0xb237]: 0x37, + [0xb238]: 0x38, + [0xb239]: 0x39, + [0xb23a]: 0x3a, + [0xb23b]: 0x3b, + [0xb23c]: 0x3c, + [0xb23d]: 0x3d, + [0xb23e]: 0x3e, + [0xb23f]: 0x3f, + [0xb240]: 0x40, + [0xb241]: 0x01, + [0xb242]: 0x02, + [0xb243]: 0x03, + [0xb244]: 0x04, + [0xb245]: 0x05, + [0xb246]: 0x06, + [0xb247]: 0x07, + [0xb248]: 0x08, + [0xb249]: 0x09, + [0xb24a]: 0x0a, + [0xb24b]: 0x0b, + [0xb24c]: 0x0c, + [0xb24d]: 0x0d, + [0xb24e]: 0x0e, + [0xb24f]: 0x0f, + [0xb250]: 0x10, + [0xb251]: 0x11, + [0xb252]: 0x12, + [0xb253]: 0x13, + [0xb254]: 0x14, + [0xb255]: 0x15, + [0xb256]: 0x16, + [0xb257]: 0x17, + [0xb258]: 0x18, + [0xb259]: 0x19, + [0xb25a]: 0x1a, + [0xb25b]: 0x1b, + [0xb25c]: 0x1c, + [0xb25d]: 0x1d, + [0xb25e]: 0x1e, + [0xb25f]: 0x1f, + [0xb260]: 0x20, + [0xb301]: 0x01, + [0xb302]: 0x02, + [0xb303]: 0x03, + [0xb304]: 0x04, + [0xb305]: 0x05, + [0xb306]: 0x06, + [0xb307]: 0x07, + [0xb308]: 0x08, + [0xb309]: 0x09, + [0xb30a]: 0x0a, + [0xb30b]: 0x0b, + [0xb30c]: 0x0c, + [0xb30d]: 0x0d, + [0xb30e]: 0x0e, + [0xb30f]: 0x0f, + [0xb310]: 0x10, + [0xb311]: 0x11, + [0xb312]: 0x12, + [0xb313]: 0x13, + [0xb314]: 0x14, + [0xb315]: 0x15, + [0xb316]: 0x16, + [0xb317]: 0x17, + [0xb318]: 0x18, + [0xb319]: 0x19, + [0xb31a]: 0x1a, + [0xb31b]: 0x1b, + [0xb31c]: 0x1c, + [0xb31d]: 0x1d, + [0xb31e]: 0x1e, + [0xb31f]: 0x1f, + [0xb320]: 0x20, + [0xb321]: 0x01, + [0xb322]: 0x02, + [0xb323]: 0x03, + [0xb324]: 0x04, + [0xb325]: 0x05, + [0xb326]: 0x06, + [0xb327]: 0x07, + [0xb328]: 0x08, + [0xb329]: 0x09, + [0xb32a]: 0x0a, + [0xb32b]: 0x0b, + [0xb32c]: 0x0c, + [0xb32d]: 0x0d, + [0xb32e]: 0x0e, + [0xb32f]: 0x0f, + [0xb330]: 0x10, + [0xb331]: 0x11, + [0xb332]: 0x12, + [0xb333]: 0x13, + [0xb334]: 0x14, + [0xb335]: 0x15, + [0xb336]: 0x16, + [0xb337]: 0x17, + [0xb338]: 0x18, + [0xb339]: 0x19, + [0xb33a]: 0x1a, + [0xb33b]: 0x1b, + [0xb33c]: 0x1c, + [0xb33d]: 0x1d, + [0xb33e]: 0x1e, + [0xb33f]: 0x1f, + [0xb340]: 0x20, + [0xb341]: 0x21, + [0xb342]: 0x22, + [0xb343]: 0x23, + [0xb344]: 0x24, + [0xb345]: 0x25, + [0xb346]: 0x26, + [0xb347]: 0x27, + [0xb348]: 0x28, + [0xb349]: 0x29, + [0xb34a]: 0x2a, + [0xb34b]: 0x2b, + [0xb34c]: 0x2c, + [0xb34d]: 0x2d, + [0xb34e]: 0x2e, + [0xb34f]: 0x2f, + [0xb350]: 0x30, + [0xb351]: 0x31, + [0xb352]: 0x32, + [0xb353]: 0x33, + [0xb354]: 0x34, + [0xb355]: 0x35, + [0xb356]: 0x36, + [0xb357]: 0x37, + [0xb358]: 0x38, + [0xb359]: 0x39, + [0xb35a]: 0x3a, + [0xb35b]: 0x3b, + [0xb35c]: 0x3c, + [0xb35d]: 0x3d, + [0xb35e]: 0x3e, + [0xb35f]: 0x3f, + [0xb360]: 0x40, + [0xb361]: 0x01, + [0xb362]: 0x02, + [0xb363]: 0x03, + [0xb364]: 0x04, + [0xb365]: 0x05, + [0xb366]: 0x06, + [0xb367]: 0x07, + [0xb368]: 0x08, + [0xb369]: 0x09, + [0xb36a]: 0x0a, + [0xb36b]: 0x0b, + [0xb36c]: 0x0c, + [0xb36d]: 0x0d, + [0xb36e]: 0x0e, + [0xb36f]: 0x0f, + [0xb370]: 0x10, + [0xb371]: 0x11, + [0xb372]: 0x12, + [0xb373]: 0x13, + [0xb374]: 0x14, + [0xb375]: 0x15, + [0xb376]: 0x16, + [0xb377]: 0x17, + [0xb378]: 0x18, + [0xb379]: 0x19, + [0xb37a]: 0x1a, + [0xb37b]: 0x1b, + [0xb37c]: 0x1c, + [0xb37d]: 0x1d, + [0xb37e]: 0x1e, + [0xb37f]: 0x1f, + [0xb380]: 0x20, + [0xb381]: 0x21, + [0xb382]: 0x22, + [0xb383]: 0x23, + [0xb384]: 0x24, + [0xb385]: 0x25, + [0xb386]: 0x26, + [0xb387]: 0x27, + [0xb388]: 0x28, + [0xb389]: 0x29, + [0xb38a]: 0x2a, + [0xb38b]: 0x2b, + [0xb38c]: 0x2c, + [0xb38d]: 0x2d, + [0xb38e]: 0x2e, + [0xb38f]: 0x2f, + [0xb390]: 0x30, + [0xb391]: 0x31, + [0xb392]: 0x32, + [0xb393]: 0x33, + [0xb394]: 0x34, + [0xb395]: 0x35, + [0xb396]: 0x36, + [0xb397]: 0x37, + [0xb398]: 0x38, + [0xb399]: 0x39, + [0xb39a]: 0x3a, + [0xb39b]: 0x3b, + [0xb39c]: 0x3c, + [0xb39d]: 0x3d, + [0xb39e]: 0x3e, + [0xb39f]: 0x3f, + [0xb3a0]: 0x40, + [0xb3a1]: 0x41, + [0xb3a2]: 0x42, + [0xb3a3]: 0x43, + [0xb3a4]: 0x44, + [0xb3a5]: 0x45, + [0xb3a6]: 0x46, + [0xb3a7]: 0x47, + [0xb3a8]: 0x48, + [0xb3a9]: 0x49, + [0xb3aa]: 0x4a, + [0xb3ab]: 0x4b, + [0xb3ac]: 0x4c, + [0xb3ad]: 0x4d, + [0xb3ae]: 0x4e, + [0xb3af]: 0x4f, + [0xb3b0]: 0x50, + [0xb3b1]: 0x51, + [0xb3b2]: 0x52, + [0xb3b3]: 0x53, + [0xb3b4]: 0x54, + [0xb3b5]: 0x55, + [0xb3b6]: 0x56, + [0xb3b7]: 0x57, + [0xb3b8]: 0x58, + [0xb3b9]: 0x59, + [0xb3ba]: 0x5a, + [0xb3bb]: 0x5b, + [0xb3bc]: 0x5c, + [0xb3bd]: 0x5d, + [0xb3be]: 0x5e, + [0xb3bf]: 0x5f, + [0xb3c0]: 0x60, + [0xb3c1]: 0x61, + [0xb3c2]: 0x62, + [0xb3c3]: 0x63, + [0xb3c4]: 0x64, + [0xb3c5]: 0x65, + [0xb3c6]: 0x66, + [0xb3c7]: 0x67, + [0xb3c8]: 0x68, + [0xb3c9]: 0x69, + [0xb3ca]: 0x6a, + [0xb3cb]: 0x6b, + [0xb3cc]: 0x6c, + [0xb3cd]: 0x6d, + [0xb3ce]: 0x6e, + [0xb3cf]: 0x6f, + [0xb3d0]: 0x70, + [0xb3d1]: 0x71, + [0xb3d2]: 0x72, + [0xb3d3]: 0x73, + [0xb3d4]: 0x74, + [0xb3d5]: 0x75, + [0xb3d6]: 0x76, + [0xb3d7]: 0x77, + [0xb3d8]: 0x78, + [0xb3d9]: 0x79, + [0xb3da]: 0x7a, + [0xb3db]: 0x7b, + [0xb3dc]: 0x7c, + [0xb3dd]: 0x7d, + [0xb3de]: 0x7e, + [0xb3df]: 0x7f, + [0xb3e0]: 0x80 }) diff --git a/src/index.js b/src/index.js index 3cbd9bc7..c1c3b3d4 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,5 @@ +// @flow + /** * Multihash implementation in JavaScript. * @@ -5,15 +7,24 @@ */ 'use strict' -const bs58 = require('bs58') +import bs58 from 'bs58' +import varint from 'varint' +import {names, codes, defaultLengths, type Name, type Code} from "./constants" + -const cs = require('./constants') +export {names, codes, defaultLengths} -exports.names = cs.names -exports.codes = cs.codes -exports.defaultLengths = cs.defaultLengths -const varint = require('varint') +export type Multihash = Buffer +export type MultihashPrefix = Buffer +export type B58Buffer = Buffer +export type HexString = string +export type MultihashData = { + code: Code, + name: Name, + length: number, + digest: Buffer +} /** * Convert the given multihash to a hex encoded string. @@ -21,7 +32,7 @@ const varint = require('varint') * @param {Buffer} hash * @returns {string} */ -exports.toHexString = function toHexString (hash) { +export function toHexString (hash:Multihash):HexString { if (!Buffer.isBuffer(hash)) { throw new Error('must be passed a buffer') } @@ -35,17 +46,18 @@ exports.toHexString = function toHexString (hash) { * @param {string} hash * @returns {Buffer} */ -exports.fromHexString = function fromHexString (hash) { +export function fromHexString (hash:HexString):Multihash { return Buffer.from(hash, 'hex') } +export type B58String = string /** * Convert the given multihash to a base58 encoded string. * * @param {Buffer} hash * @returns {string} */ -exports.toB58String = function toB58String (hash) { +export function toB58String (hash:Multihash):B58String { if (!Buffer.isBuffer(hash)) { throw new Error('must be passed a buffer') } @@ -59,7 +71,7 @@ exports.toB58String = function toB58String (hash) { * @param {string|Buffer} hash * @returns {Buffer} */ -exports.fromB58String = function fromB58String (hash) { +export function fromB58String (hash:B58String|B58Buffer):Multihash { let encoded = hash if (Buffer.isBuffer(hash)) { encoded = hash.toString() @@ -74,7 +86,7 @@ exports.fromB58String = function fromB58String (hash) { * @param {Buffer} buf * @returns {{code: number, name: string, length: number, digest: Buffer}} result */ -exports.decode = function decode (buf) { +export function decode (buf:Multihash):MultihashData { if (!(Buffer.isBuffer(buf))) { throw new Error('multihash must be a Buffer') } @@ -84,7 +96,7 @@ exports.decode = function decode (buf) { } let code = varint.decode(buf) - if (!exports.isValidCode(code)) { + if (!isValidCode(code)) { throw new Error(`multihash unknown function code: 0x${code.toString(16)}`) } buf = buf.slice(varint.decode.bytes) @@ -101,7 +113,7 @@ exports.decode = function decode (buf) { return { code: code, - name: cs.codes[code], + name: codes[code], length: len, digest: buf } @@ -117,13 +129,13 @@ exports.decode = function decode (buf) { * @param {number} [length] * @returns {Buffer} */ -exports.encode = function encode (digest, code, length) { +export function encode (digest:Buffer, code:Code, length:number):Multihash { if (!digest || !code) { throw new Error('multihash encode requires at least two args: digest, code') } // ensure it's a hashfunction code. - const hashfn = exports.coerceCode(code) + const hashfn = coerceCode(code) if (!(Buffer.isBuffer(digest))) { throw new Error('digest should be a Buffer') @@ -150,21 +162,22 @@ exports.encode = function encode (digest, code, length) { * @param {string|number} name * @returns {number} */ -exports.coerceCode = function coerceCode (name) { +// TODO: Sholud we just allow Name here instead ? +export function coerceCode (name:Name|Code):Code { let code = name if (typeof name === 'string') { - if (!cs.names[name]) { + if (!names[name]) { throw new Error(`Unrecognized hash function named: ${name}`) } - code = cs.names[name] + code = names[name] } if (typeof code !== 'number') { throw new Error(`Hash function code should be a number. Got: ${code}`) } - if (!cs.codes[code] && !exports.isAppCode(code)) { + if (!codes[code] && !exports.isAppCode(code)) { throw new Error(`Unrecognized function code: ${code}`) } @@ -177,7 +190,7 @@ exports.coerceCode = function coerceCode (name) { * @param {number} code * @returns {boolean} */ -exports.isAppCode = function appCode (code) { +export function isAppCode (code:number):boolean { return code > 0 && code < 0x10 } @@ -187,12 +200,12 @@ exports.isAppCode = function appCode (code) { * @param {number} code * @returns {boolean} */ -exports.isValidCode = function validCode (code) { - if (exports.isAppCode(code)) { +export function isValidCode(code:number):boolean { + if (isAppCode(code)) { return true } - if (cs.codes[code]) { + if (codes[(code:any)]) { return true } @@ -206,19 +219,18 @@ exports.isValidCode = function validCode (code) { * @returns {undefined} * @throws {Error} */ -function validate (multihash) { - exports.decode(multihash) // throws if bad. +export function validate (multihash:Buffer) { + decode(multihash) // throws if bad. } -exports.validate = validate /** * Returns a prefix from a valid multihash. Throws an error if it is not valid. * * @param {Buffer} multihash - * @returns {undefined} + * @returns {Buffer} * @throws {Error} */ -exports.prefix = function prefix (multihash) { +export function prefix (multihash:Multihash):MultihashPrefix { validate(multihash) return multihash.slice(0, 2) diff --git a/test/index.spec.js b/test/index.spec.js index d103d777..6abc4860 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -9,8 +9,8 @@ const expect = chai.expect const bufeq = require('buffer-equal') const bs58 = require('bs58') -const mh = require('../src') -const constants = require('../src/constants') +const mh = require('../lib') +const constants = require('../lib/constants') const validCases = require('./fixtures/valid') const invalidCases = require('./fixtures/invalid') diff --git a/test/node.js b/test/node.js new file mode 100644 index 00000000..0998241b --- /dev/null +++ b/test/node.js @@ -0,0 +1,4 @@ +// TODO: Instead mocha should be passed additional arg +// `--require source-map-support/register` but as things stand now there is +// no way to do it without changes to aegir so we do this instead for now. +require("source-map-support/register")