From 2422b098936e39bc29b52e4a6a02d25f454d1203 Mon Sep 17 00:00:00 2001 From: Mikeal Rogers Date: Thu, 5 Dec 2019 08:04:30 -0800 Subject: [PATCH] feat: reduce bundle size by 1/3 (#49) License: MIT Signed-off-by: Henrique Dias --- README.md | 2 +- example.js | 1 + package.json | 7 +- src/base-table.js | 446 ----------------------------------------- src/base-table.json | 429 ++++++++++++++++++++++++++++++++++++++++ src/constants.js | 450 +----------------------------------------- src/name-table.js | 14 +- src/print.js | 449 +---------------------------------------- src/util.js | 7 +- src/varint-table.js | 15 +- tools/update-table.js | 30 +++ tools/update-table.py | 115 ----------- 12 files changed, 500 insertions(+), 1465 deletions(-) delete mode 100644 src/base-table.js create mode 100644 src/base-table.json create mode 100755 tools/update-table.js delete mode 100755 tools/update-table.py diff --git a/README.md b/README.md index 75c4b3b..e840831 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ Updating the lookup table is done with a script. The source of truth is the [multicodec default table](https://github.com/multiformats/multicodec/blob/master/table.csv). Update the table with running: - curl -X GET https://raw.githubusercontent.com/multiformats/multicodec/master/table.csv | ./tools/update-table.py + node ./tools/update-table.js ## Contribute diff --git a/example.js b/example.js index 6024c4b..3c0b39b 100644 --- a/example.js +++ b/example.js @@ -4,5 +4,6 @@ const multicodec = require('multicodec') const prefixedProtobuf = multicodec.addPrefix('protobuf', Buffer.from('some protobuf code')) +// eslint-disable-next-line no-console console.log(prefixedProtobuf) // => prefixedProtobuf 0x50... diff --git a/package.json b/package.json index aa45548..2b435f6 100644 --- a/package.json +++ b/package.json @@ -43,10 +43,11 @@ "varint": "^5.0.0" }, "devDependencies": { - "aegir": "^18.2.2", + "aegir": "^20.2.0", + "bent": "^7.0.1", "chai": "^4.2.0", - "pre-push": "~0.1.1", - "dirty-chai": "^2.0.1" + "dirty-chai": "^2.0.1", + "pre-push": "~0.1.1" }, "contributors": [ "David Dias ", diff --git a/src/base-table.js b/src/base-table.js deleted file mode 100644 index 24eeb3f..0000000 --- a/src/base-table.js +++ /dev/null @@ -1,446 +0,0 @@ -// THIS FILE IS GENERATED, DO NO EDIT MANUALLY -// For more information see the README.md -/* eslint-disable dot-notation */ -'use strict' - -// serialization -exports['protobuf'] = Buffer.from('50', 'hex') -exports['cbor'] = Buffer.from('51', 'hex') -exports['rlp'] = Buffer.from('60', 'hex') -exports['bencode'] = Buffer.from('63', 'hex') -exports['json'] = Buffer.from('0200', 'hex') -exports['messagepack'] = Buffer.from('0201', 'hex') - -// multiformat -exports['multicodec'] = Buffer.from('30', 'hex') -exports['multihash'] = Buffer.from('31', 'hex') -exports['multiaddr'] = Buffer.from('32', 'hex') -exports['multibase'] = Buffer.from('33', 'hex') - -// multihash -exports['identity'] = Buffer.from('00', 'hex') -exports['sha1'] = Buffer.from('11', 'hex') -exports['sha2-256'] = Buffer.from('12', 'hex') -exports['sha2-512'] = Buffer.from('13', 'hex') -exports['sha3-512'] = Buffer.from('14', 'hex') -exports['sha3-384'] = Buffer.from('15', 'hex') -exports['sha3-256'] = Buffer.from('16', 'hex') -exports['sha3-224'] = Buffer.from('17', 'hex') -exports['shake-128'] = Buffer.from('18', 'hex') -exports['shake-256'] = Buffer.from('19', 'hex') -exports['keccak-224'] = Buffer.from('1a', 'hex') -exports['keccak-256'] = Buffer.from('1b', 'hex') -exports['keccak-384'] = Buffer.from('1c', 'hex') -exports['keccak-512'] = Buffer.from('1d', 'hex') -exports['murmur3-128'] = Buffer.from('22', 'hex') -exports['murmur3-32'] = Buffer.from('23', 'hex') -exports['dbl-sha2-256'] = Buffer.from('56', 'hex') -exports['md4'] = Buffer.from('d4', 'hex') -exports['md5'] = Buffer.from('d5', 'hex') -exports['bmt'] = Buffer.from('d6', 'hex') -exports['x11'] = Buffer.from('1100', 'hex') -exports['blake2b-8'] = Buffer.from('b201', 'hex') -exports['blake2b-16'] = Buffer.from('b202', 'hex') -exports['blake2b-24'] = Buffer.from('b203', 'hex') -exports['blake2b-32'] = Buffer.from('b204', 'hex') -exports['blake2b-40'] = Buffer.from('b205', 'hex') -exports['blake2b-48'] = Buffer.from('b206', 'hex') -exports['blake2b-56'] = Buffer.from('b207', 'hex') -exports['blake2b-64'] = Buffer.from('b208', 'hex') -exports['blake2b-72'] = Buffer.from('b209', 'hex') -exports['blake2b-80'] = Buffer.from('b20a', 'hex') -exports['blake2b-88'] = Buffer.from('b20b', 'hex') -exports['blake2b-96'] = Buffer.from('b20c', 'hex') -exports['blake2b-104'] = Buffer.from('b20d', 'hex') -exports['blake2b-112'] = Buffer.from('b20e', 'hex') -exports['blake2b-120'] = Buffer.from('b20f', 'hex') -exports['blake2b-128'] = Buffer.from('b210', 'hex') -exports['blake2b-136'] = Buffer.from('b211', 'hex') -exports['blake2b-144'] = Buffer.from('b212', 'hex') -exports['blake2b-152'] = Buffer.from('b213', 'hex') -exports['blake2b-160'] = Buffer.from('b214', 'hex') -exports['blake2b-168'] = Buffer.from('b215', 'hex') -exports['blake2b-176'] = Buffer.from('b216', 'hex') -exports['blake2b-184'] = Buffer.from('b217', 'hex') -exports['blake2b-192'] = Buffer.from('b218', 'hex') -exports['blake2b-200'] = Buffer.from('b219', 'hex') -exports['blake2b-208'] = Buffer.from('b21a', 'hex') -exports['blake2b-216'] = Buffer.from('b21b', 'hex') -exports['blake2b-224'] = Buffer.from('b21c', 'hex') -exports['blake2b-232'] = Buffer.from('b21d', 'hex') -exports['blake2b-240'] = Buffer.from('b21e', 'hex') -exports['blake2b-248'] = Buffer.from('b21f', 'hex') -exports['blake2b-256'] = Buffer.from('b220', 'hex') -exports['blake2b-264'] = Buffer.from('b221', 'hex') -exports['blake2b-272'] = Buffer.from('b222', 'hex') -exports['blake2b-280'] = Buffer.from('b223', 'hex') -exports['blake2b-288'] = Buffer.from('b224', 'hex') -exports['blake2b-296'] = Buffer.from('b225', 'hex') -exports['blake2b-304'] = Buffer.from('b226', 'hex') -exports['blake2b-312'] = Buffer.from('b227', 'hex') -exports['blake2b-320'] = Buffer.from('b228', 'hex') -exports['blake2b-328'] = Buffer.from('b229', 'hex') -exports['blake2b-336'] = Buffer.from('b22a', 'hex') -exports['blake2b-344'] = Buffer.from('b22b', 'hex') -exports['blake2b-352'] = Buffer.from('b22c', 'hex') -exports['blake2b-360'] = Buffer.from('b22d', 'hex') -exports['blake2b-368'] = Buffer.from('b22e', 'hex') -exports['blake2b-376'] = Buffer.from('b22f', 'hex') -exports['blake2b-384'] = Buffer.from('b230', 'hex') -exports['blake2b-392'] = Buffer.from('b231', 'hex') -exports['blake2b-400'] = Buffer.from('b232', 'hex') -exports['blake2b-408'] = Buffer.from('b233', 'hex') -exports['blake2b-416'] = Buffer.from('b234', 'hex') -exports['blake2b-424'] = Buffer.from('b235', 'hex') -exports['blake2b-432'] = Buffer.from('b236', 'hex') -exports['blake2b-440'] = Buffer.from('b237', 'hex') -exports['blake2b-448'] = Buffer.from('b238', 'hex') -exports['blake2b-456'] = Buffer.from('b239', 'hex') -exports['blake2b-464'] = Buffer.from('b23a', 'hex') -exports['blake2b-472'] = Buffer.from('b23b', 'hex') -exports['blake2b-480'] = Buffer.from('b23c', 'hex') -exports['blake2b-488'] = Buffer.from('b23d', 'hex') -exports['blake2b-496'] = Buffer.from('b23e', 'hex') -exports['blake2b-504'] = Buffer.from('b23f', 'hex') -exports['blake2b-512'] = Buffer.from('b240', 'hex') -exports['blake2s-8'] = Buffer.from('b241', 'hex') -exports['blake2s-16'] = Buffer.from('b242', 'hex') -exports['blake2s-24'] = Buffer.from('b243', 'hex') -exports['blake2s-32'] = Buffer.from('b244', 'hex') -exports['blake2s-40'] = Buffer.from('b245', 'hex') -exports['blake2s-48'] = Buffer.from('b246', 'hex') -exports['blake2s-56'] = Buffer.from('b247', 'hex') -exports['blake2s-64'] = Buffer.from('b248', 'hex') -exports['blake2s-72'] = Buffer.from('b249', 'hex') -exports['blake2s-80'] = Buffer.from('b24a', 'hex') -exports['blake2s-88'] = Buffer.from('b24b', 'hex') -exports['blake2s-96'] = Buffer.from('b24c', 'hex') -exports['blake2s-104'] = Buffer.from('b24d', 'hex') -exports['blake2s-112'] = Buffer.from('b24e', 'hex') -exports['blake2s-120'] = Buffer.from('b24f', 'hex') -exports['blake2s-128'] = Buffer.from('b250', 'hex') -exports['blake2s-136'] = Buffer.from('b251', 'hex') -exports['blake2s-144'] = Buffer.from('b252', 'hex') -exports['blake2s-152'] = Buffer.from('b253', 'hex') -exports['blake2s-160'] = Buffer.from('b254', 'hex') -exports['blake2s-168'] = Buffer.from('b255', 'hex') -exports['blake2s-176'] = Buffer.from('b256', 'hex') -exports['blake2s-184'] = Buffer.from('b257', 'hex') -exports['blake2s-192'] = Buffer.from('b258', 'hex') -exports['blake2s-200'] = Buffer.from('b259', 'hex') -exports['blake2s-208'] = Buffer.from('b25a', 'hex') -exports['blake2s-216'] = Buffer.from('b25b', 'hex') -exports['blake2s-224'] = Buffer.from('b25c', 'hex') -exports['blake2s-232'] = Buffer.from('b25d', 'hex') -exports['blake2s-240'] = Buffer.from('b25e', 'hex') -exports['blake2s-248'] = Buffer.from('b25f', 'hex') -exports['blake2s-256'] = Buffer.from('b260', 'hex') -exports['skein256-8'] = Buffer.from('b301', 'hex') -exports['skein256-16'] = Buffer.from('b302', 'hex') -exports['skein256-24'] = Buffer.from('b303', 'hex') -exports['skein256-32'] = Buffer.from('b304', 'hex') -exports['skein256-40'] = Buffer.from('b305', 'hex') -exports['skein256-48'] = Buffer.from('b306', 'hex') -exports['skein256-56'] = Buffer.from('b307', 'hex') -exports['skein256-64'] = Buffer.from('b308', 'hex') -exports['skein256-72'] = Buffer.from('b309', 'hex') -exports['skein256-80'] = Buffer.from('b30a', 'hex') -exports['skein256-88'] = Buffer.from('b30b', 'hex') -exports['skein256-96'] = Buffer.from('b30c', 'hex') -exports['skein256-104'] = Buffer.from('b30d', 'hex') -exports['skein256-112'] = Buffer.from('b30e', 'hex') -exports['skein256-120'] = Buffer.from('b30f', 'hex') -exports['skein256-128'] = Buffer.from('b310', 'hex') -exports['skein256-136'] = Buffer.from('b311', 'hex') -exports['skein256-144'] = Buffer.from('b312', 'hex') -exports['skein256-152'] = Buffer.from('b313', 'hex') -exports['skein256-160'] = Buffer.from('b314', 'hex') -exports['skein256-168'] = Buffer.from('b315', 'hex') -exports['skein256-176'] = Buffer.from('b316', 'hex') -exports['skein256-184'] = Buffer.from('b317', 'hex') -exports['skein256-192'] = Buffer.from('b318', 'hex') -exports['skein256-200'] = Buffer.from('b319', 'hex') -exports['skein256-208'] = Buffer.from('b31a', 'hex') -exports['skein256-216'] = Buffer.from('b31b', 'hex') -exports['skein256-224'] = Buffer.from('b31c', 'hex') -exports['skein256-232'] = Buffer.from('b31d', 'hex') -exports['skein256-240'] = Buffer.from('b31e', 'hex') -exports['skein256-248'] = Buffer.from('b31f', 'hex') -exports['skein256-256'] = Buffer.from('b320', 'hex') -exports['skein512-8'] = Buffer.from('b321', 'hex') -exports['skein512-16'] = Buffer.from('b322', 'hex') -exports['skein512-24'] = Buffer.from('b323', 'hex') -exports['skein512-32'] = Buffer.from('b324', 'hex') -exports['skein512-40'] = Buffer.from('b325', 'hex') -exports['skein512-48'] = Buffer.from('b326', 'hex') -exports['skein512-56'] = Buffer.from('b327', 'hex') -exports['skein512-64'] = Buffer.from('b328', 'hex') -exports['skein512-72'] = Buffer.from('b329', 'hex') -exports['skein512-80'] = Buffer.from('b32a', 'hex') -exports['skein512-88'] = Buffer.from('b32b', 'hex') -exports['skein512-96'] = Buffer.from('b32c', 'hex') -exports['skein512-104'] = Buffer.from('b32d', 'hex') -exports['skein512-112'] = Buffer.from('b32e', 'hex') -exports['skein512-120'] = Buffer.from('b32f', 'hex') -exports['skein512-128'] = Buffer.from('b330', 'hex') -exports['skein512-136'] = Buffer.from('b331', 'hex') -exports['skein512-144'] = Buffer.from('b332', 'hex') -exports['skein512-152'] = Buffer.from('b333', 'hex') -exports['skein512-160'] = Buffer.from('b334', 'hex') -exports['skein512-168'] = Buffer.from('b335', 'hex') -exports['skein512-176'] = Buffer.from('b336', 'hex') -exports['skein512-184'] = Buffer.from('b337', 'hex') -exports['skein512-192'] = Buffer.from('b338', 'hex') -exports['skein512-200'] = Buffer.from('b339', 'hex') -exports['skein512-208'] = Buffer.from('b33a', 'hex') -exports['skein512-216'] = Buffer.from('b33b', 'hex') -exports['skein512-224'] = Buffer.from('b33c', 'hex') -exports['skein512-232'] = Buffer.from('b33d', 'hex') -exports['skein512-240'] = Buffer.from('b33e', 'hex') -exports['skein512-248'] = Buffer.from('b33f', 'hex') -exports['skein512-256'] = Buffer.from('b340', 'hex') -exports['skein512-264'] = Buffer.from('b341', 'hex') -exports['skein512-272'] = Buffer.from('b342', 'hex') -exports['skein512-280'] = Buffer.from('b343', 'hex') -exports['skein512-288'] = Buffer.from('b344', 'hex') -exports['skein512-296'] = Buffer.from('b345', 'hex') -exports['skein512-304'] = Buffer.from('b346', 'hex') -exports['skein512-312'] = Buffer.from('b347', 'hex') -exports['skein512-320'] = Buffer.from('b348', 'hex') -exports['skein512-328'] = Buffer.from('b349', 'hex') -exports['skein512-336'] = Buffer.from('b34a', 'hex') -exports['skein512-344'] = Buffer.from('b34b', 'hex') -exports['skein512-352'] = Buffer.from('b34c', 'hex') -exports['skein512-360'] = Buffer.from('b34d', 'hex') -exports['skein512-368'] = Buffer.from('b34e', 'hex') -exports['skein512-376'] = Buffer.from('b34f', 'hex') -exports['skein512-384'] = Buffer.from('b350', 'hex') -exports['skein512-392'] = Buffer.from('b351', 'hex') -exports['skein512-400'] = Buffer.from('b352', 'hex') -exports['skein512-408'] = Buffer.from('b353', 'hex') -exports['skein512-416'] = Buffer.from('b354', 'hex') -exports['skein512-424'] = Buffer.from('b355', 'hex') -exports['skein512-432'] = Buffer.from('b356', 'hex') -exports['skein512-440'] = Buffer.from('b357', 'hex') -exports['skein512-448'] = Buffer.from('b358', 'hex') -exports['skein512-456'] = Buffer.from('b359', 'hex') -exports['skein512-464'] = Buffer.from('b35a', 'hex') -exports['skein512-472'] = Buffer.from('b35b', 'hex') -exports['skein512-480'] = Buffer.from('b35c', 'hex') -exports['skein512-488'] = Buffer.from('b35d', 'hex') -exports['skein512-496'] = Buffer.from('b35e', 'hex') -exports['skein512-504'] = Buffer.from('b35f', 'hex') -exports['skein512-512'] = Buffer.from('b360', 'hex') -exports['skein1024-8'] = Buffer.from('b361', 'hex') -exports['skein1024-16'] = Buffer.from('b362', 'hex') -exports['skein1024-24'] = Buffer.from('b363', 'hex') -exports['skein1024-32'] = Buffer.from('b364', 'hex') -exports['skein1024-40'] = Buffer.from('b365', 'hex') -exports['skein1024-48'] = Buffer.from('b366', 'hex') -exports['skein1024-56'] = Buffer.from('b367', 'hex') -exports['skein1024-64'] = Buffer.from('b368', 'hex') -exports['skein1024-72'] = Buffer.from('b369', 'hex') -exports['skein1024-80'] = Buffer.from('b36a', 'hex') -exports['skein1024-88'] = Buffer.from('b36b', 'hex') -exports['skein1024-96'] = Buffer.from('b36c', 'hex') -exports['skein1024-104'] = Buffer.from('b36d', 'hex') -exports['skein1024-112'] = Buffer.from('b36e', 'hex') -exports['skein1024-120'] = Buffer.from('b36f', 'hex') -exports['skein1024-128'] = Buffer.from('b370', 'hex') -exports['skein1024-136'] = Buffer.from('b371', 'hex') -exports['skein1024-144'] = Buffer.from('b372', 'hex') -exports['skein1024-152'] = Buffer.from('b373', 'hex') -exports['skein1024-160'] = Buffer.from('b374', 'hex') -exports['skein1024-168'] = Buffer.from('b375', 'hex') -exports['skein1024-176'] = Buffer.from('b376', 'hex') -exports['skein1024-184'] = Buffer.from('b377', 'hex') -exports['skein1024-192'] = Buffer.from('b378', 'hex') -exports['skein1024-200'] = Buffer.from('b379', 'hex') -exports['skein1024-208'] = Buffer.from('b37a', 'hex') -exports['skein1024-216'] = Buffer.from('b37b', 'hex') -exports['skein1024-224'] = Buffer.from('b37c', 'hex') -exports['skein1024-232'] = Buffer.from('b37d', 'hex') -exports['skein1024-240'] = Buffer.from('b37e', 'hex') -exports['skein1024-248'] = Buffer.from('b37f', 'hex') -exports['skein1024-256'] = Buffer.from('b380', 'hex') -exports['skein1024-264'] = Buffer.from('b381', 'hex') -exports['skein1024-272'] = Buffer.from('b382', 'hex') -exports['skein1024-280'] = Buffer.from('b383', 'hex') -exports['skein1024-288'] = Buffer.from('b384', 'hex') -exports['skein1024-296'] = Buffer.from('b385', 'hex') -exports['skein1024-304'] = Buffer.from('b386', 'hex') -exports['skein1024-312'] = Buffer.from('b387', 'hex') -exports['skein1024-320'] = Buffer.from('b388', 'hex') -exports['skein1024-328'] = Buffer.from('b389', 'hex') -exports['skein1024-336'] = Buffer.from('b38a', 'hex') -exports['skein1024-344'] = Buffer.from('b38b', 'hex') -exports['skein1024-352'] = Buffer.from('b38c', 'hex') -exports['skein1024-360'] = Buffer.from('b38d', 'hex') -exports['skein1024-368'] = Buffer.from('b38e', 'hex') -exports['skein1024-376'] = Buffer.from('b38f', 'hex') -exports['skein1024-384'] = Buffer.from('b390', 'hex') -exports['skein1024-392'] = Buffer.from('b391', 'hex') -exports['skein1024-400'] = Buffer.from('b392', 'hex') -exports['skein1024-408'] = Buffer.from('b393', 'hex') -exports['skein1024-416'] = Buffer.from('b394', 'hex') -exports['skein1024-424'] = Buffer.from('b395', 'hex') -exports['skein1024-432'] = Buffer.from('b396', 'hex') -exports['skein1024-440'] = Buffer.from('b397', 'hex') -exports['skein1024-448'] = Buffer.from('b398', 'hex') -exports['skein1024-456'] = Buffer.from('b399', 'hex') -exports['skein1024-464'] = Buffer.from('b39a', 'hex') -exports['skein1024-472'] = Buffer.from('b39b', 'hex') -exports['skein1024-480'] = Buffer.from('b39c', 'hex') -exports['skein1024-488'] = Buffer.from('b39d', 'hex') -exports['skein1024-496'] = Buffer.from('b39e', 'hex') -exports['skein1024-504'] = Buffer.from('b39f', 'hex') -exports['skein1024-512'] = Buffer.from('b3a0', 'hex') -exports['skein1024-520'] = Buffer.from('b3a1', 'hex') -exports['skein1024-528'] = Buffer.from('b3a2', 'hex') -exports['skein1024-536'] = Buffer.from('b3a3', 'hex') -exports['skein1024-544'] = Buffer.from('b3a4', 'hex') -exports['skein1024-552'] = Buffer.from('b3a5', 'hex') -exports['skein1024-560'] = Buffer.from('b3a6', 'hex') -exports['skein1024-568'] = Buffer.from('b3a7', 'hex') -exports['skein1024-576'] = Buffer.from('b3a8', 'hex') -exports['skein1024-584'] = Buffer.from('b3a9', 'hex') -exports['skein1024-592'] = Buffer.from('b3aa', 'hex') -exports['skein1024-600'] = Buffer.from('b3ab', 'hex') -exports['skein1024-608'] = Buffer.from('b3ac', 'hex') -exports['skein1024-616'] = Buffer.from('b3ad', 'hex') -exports['skein1024-624'] = Buffer.from('b3ae', 'hex') -exports['skein1024-632'] = Buffer.from('b3af', 'hex') -exports['skein1024-640'] = Buffer.from('b3b0', 'hex') -exports['skein1024-648'] = Buffer.from('b3b1', 'hex') -exports['skein1024-656'] = Buffer.from('b3b2', 'hex') -exports['skein1024-664'] = Buffer.from('b3b3', 'hex') -exports['skein1024-672'] = Buffer.from('b3b4', 'hex') -exports['skein1024-680'] = Buffer.from('b3b5', 'hex') -exports['skein1024-688'] = Buffer.from('b3b6', 'hex') -exports['skein1024-696'] = Buffer.from('b3b7', 'hex') -exports['skein1024-704'] = Buffer.from('b3b8', 'hex') -exports['skein1024-712'] = Buffer.from('b3b9', 'hex') -exports['skein1024-720'] = Buffer.from('b3ba', 'hex') -exports['skein1024-728'] = Buffer.from('b3bb', 'hex') -exports['skein1024-736'] = Buffer.from('b3bc', 'hex') -exports['skein1024-744'] = Buffer.from('b3bd', 'hex') -exports['skein1024-752'] = Buffer.from('b3be', 'hex') -exports['skein1024-760'] = Buffer.from('b3bf', 'hex') -exports['skein1024-768'] = Buffer.from('b3c0', 'hex') -exports['skein1024-776'] = Buffer.from('b3c1', 'hex') -exports['skein1024-784'] = Buffer.from('b3c2', 'hex') -exports['skein1024-792'] = Buffer.from('b3c3', 'hex') -exports['skein1024-800'] = Buffer.from('b3c4', 'hex') -exports['skein1024-808'] = Buffer.from('b3c5', 'hex') -exports['skein1024-816'] = Buffer.from('b3c6', 'hex') -exports['skein1024-824'] = Buffer.from('b3c7', 'hex') -exports['skein1024-832'] = Buffer.from('b3c8', 'hex') -exports['skein1024-840'] = Buffer.from('b3c9', 'hex') -exports['skein1024-848'] = Buffer.from('b3ca', 'hex') -exports['skein1024-856'] = Buffer.from('b3cb', 'hex') -exports['skein1024-864'] = Buffer.from('b3cc', 'hex') -exports['skein1024-872'] = Buffer.from('b3cd', 'hex') -exports['skein1024-880'] = Buffer.from('b3ce', 'hex') -exports['skein1024-888'] = Buffer.from('b3cf', 'hex') -exports['skein1024-896'] = Buffer.from('b3d0', 'hex') -exports['skein1024-904'] = Buffer.from('b3d1', 'hex') -exports['skein1024-912'] = Buffer.from('b3d2', 'hex') -exports['skein1024-920'] = Buffer.from('b3d3', 'hex') -exports['skein1024-928'] = Buffer.from('b3d4', 'hex') -exports['skein1024-936'] = Buffer.from('b3d5', 'hex') -exports['skein1024-944'] = Buffer.from('b3d6', 'hex') -exports['skein1024-952'] = Buffer.from('b3d7', 'hex') -exports['skein1024-960'] = Buffer.from('b3d8', 'hex') -exports['skein1024-968'] = Buffer.from('b3d9', 'hex') -exports['skein1024-976'] = Buffer.from('b3da', 'hex') -exports['skein1024-984'] = Buffer.from('b3db', 'hex') -exports['skein1024-992'] = Buffer.from('b3dc', 'hex') -exports['skein1024-1000'] = Buffer.from('b3dd', 'hex') -exports['skein1024-1008'] = Buffer.from('b3de', 'hex') -exports['skein1024-1016'] = Buffer.from('b3df', 'hex') -exports['skein1024-1024'] = Buffer.from('b3e0', 'hex') - -// multiaddr -exports['ip4'] = Buffer.from('04', 'hex') -exports['tcp'] = Buffer.from('06', 'hex') -exports['dccp'] = Buffer.from('21', 'hex') -exports['ip6'] = Buffer.from('29', 'hex') -exports['ip6zone'] = Buffer.from('2a', 'hex') -exports['dns'] = Buffer.from('35', 'hex') -exports['dns4'] = Buffer.from('36', 'hex') -exports['dns6'] = Buffer.from('37', 'hex') -exports['dnsaddr'] = Buffer.from('38', 'hex') -exports['sctp'] = Buffer.from('84', 'hex') -exports['udp'] = Buffer.from('0111', 'hex') -exports['p2p-webrtc-star'] = Buffer.from('0113', 'hex') -exports['p2p-webrtc-direct'] = Buffer.from('0114', 'hex') -exports['p2p-stardust'] = Buffer.from('0115', 'hex') -exports['p2p-circuit'] = Buffer.from('0122', 'hex') -exports['udt'] = Buffer.from('012d', 'hex') -exports['utp'] = Buffer.from('012e', 'hex') -exports['unix'] = Buffer.from('0190', 'hex') -exports['p2p'] = Buffer.from('01a5', 'hex') -exports['ipfs'] = Buffer.from('01a5', 'hex') -exports['https'] = Buffer.from('01bb', 'hex') -exports['onion'] = Buffer.from('01bc', 'hex') -exports['onion3'] = Buffer.from('01bd', 'hex') -exports['garlic64'] = Buffer.from('01be', 'hex') -exports['garlic32'] = Buffer.from('01bf', 'hex') -exports['quic'] = Buffer.from('01cc', 'hex') -exports['ws'] = Buffer.from('01dd', 'hex') -exports['wss'] = Buffer.from('01de', 'hex') -exports['p2p-websocket-star'] = Buffer.from('01df', 'hex') -exports['http'] = Buffer.from('01e0', 'hex') - -// ipld -exports['raw'] = Buffer.from('55', 'hex') -exports['dag-pb'] = Buffer.from('70', 'hex') -exports['dag-cbor'] = Buffer.from('71', 'hex') -exports['libp2p-key'] = Buffer.from('72', 'hex') -exports['git-raw'] = Buffer.from('78', 'hex') -exports['torrent-info'] = Buffer.from('7b', 'hex') -exports['torrent-file'] = Buffer.from('7c', 'hex') -exports['leofcoin-block'] = Buffer.from('81', 'hex') -exports['leofcoin-tx'] = Buffer.from('82', 'hex') -exports['leofcoin-pr'] = Buffer.from('83', 'hex') -exports['eth-block'] = Buffer.from('90', 'hex') -exports['eth-block-list'] = Buffer.from('91', 'hex') -exports['eth-tx-trie'] = Buffer.from('92', 'hex') -exports['eth-tx'] = Buffer.from('93', 'hex') -exports['eth-tx-receipt-trie'] = Buffer.from('94', 'hex') -exports['eth-tx-receipt'] = Buffer.from('95', 'hex') -exports['eth-state-trie'] = Buffer.from('96', 'hex') -exports['eth-account-snapshot'] = Buffer.from('97', 'hex') -exports['eth-storage-trie'] = Buffer.from('98', 'hex') -exports['bitcoin-block'] = Buffer.from('b0', 'hex') -exports['bitcoin-tx'] = Buffer.from('b1', 'hex') -exports['zcash-block'] = Buffer.from('c0', 'hex') -exports['zcash-tx'] = Buffer.from('c1', 'hex') -exports['stellar-block'] = Buffer.from('d0', 'hex') -exports['stellar-tx'] = Buffer.from('d1', 'hex') -exports['decred-block'] = Buffer.from('e0', 'hex') -exports['decred-tx'] = Buffer.from('e1', 'hex') -exports['dash-block'] = Buffer.from('f0', 'hex') -exports['dash-tx'] = Buffer.from('f1', 'hex') -exports['swarm-manifest'] = Buffer.from('fa', 'hex') -exports['swarm-feed'] = Buffer.from('fb', 'hex') -exports['dag-json'] = Buffer.from('0129', 'hex') - -// namespace -exports['path'] = Buffer.from('2f', 'hex') -exports['ipld-ns'] = Buffer.from('e2', 'hex') -exports['ipfs-ns'] = Buffer.from('e3', 'hex') -exports['swarm-ns'] = Buffer.from('e4', 'hex') -exports['ipns-ns'] = Buffer.from('e5', 'hex') -exports['zeronet'] = Buffer.from('e6', 'hex') - -// key -exports['ed25519-pub'] = Buffer.from('ed', 'hex') - -// holochain -exports['holochain-adr-v0'] = Buffer.from('807124', 'hex') -exports['holochain-adr-v1'] = Buffer.from('817124', 'hex') -exports['holochain-key-v0'] = Buffer.from('947124', 'hex') -exports['holochain-key-v1'] = Buffer.from('957124', 'hex') -exports['holochain-sig-v0'] = Buffer.from('a27124', 'hex') -exports['holochain-sig-v1'] = Buffer.from('a37124', 'hex') diff --git a/src/base-table.json b/src/base-table.json new file mode 100644 index 0000000..f47f317 --- /dev/null +++ b/src/base-table.json @@ -0,0 +1,429 @@ +{ + "identity": 0, + "ip4": 4, + "tcp": 6, + "sha1": 17, + "sha2-256": 18, + "sha2-512": 19, + "sha3-512": 20, + "sha3-384": 21, + "sha3-256": 22, + "sha3-224": 23, + "shake-128": 24, + "shake-256": 25, + "keccak-224": 26, + "keccak-256": 27, + "keccak-384": 28, + "keccak-512": 29, + "dccp": 33, + "murmur3-128": 34, + "murmur3-32": 35, + "ip6": 41, + "ip6zone": 42, + "path": 47, + "multicodec": 48, + "multihash": 49, + "multiaddr": 50, + "multibase": 51, + "dns": 53, + "dns4": 54, + "dns6": 55, + "dnsaddr": 56, + "protobuf": 80, + "cbor": 81, + "raw": 85, + "dbl-sha2-256": 86, + "rlp": 96, + "bencode": 99, + "dag-pb": 112, + "dag-cbor": 113, + "libp2p-key": 114, + "git-raw": 120, + "torrent-info": 123, + "torrent-file": 124, + "leofcoin-block": 129, + "leofcoin-tx": 130, + "leofcoin-pr": 131, + "sctp": 132, + "eth-block": 144, + "eth-block-list": 145, + "eth-tx-trie": 146, + "eth-tx": 147, + "eth-tx-receipt-trie": 148, + "eth-tx-receipt": 149, + "eth-state-trie": 150, + "eth-account-snapshot": 151, + "eth-storage-trie": 152, + "bitcoin-block": 176, + "bitcoin-tx": 177, + "zcash-block": 192, + "zcash-tx": 193, + "stellar-block": 208, + "stellar-tx": 209, + "md4": 212, + "md5": 213, + "bmt": 214, + "decred-block": 224, + "decred-tx": 225, + "ipld-ns": 226, + "ipfs-ns": 227, + "swarm-ns": 228, + "ipns-ns": 229, + "zeronet": 230, + "ed25519-pub": 237, + "dash-block": 240, + "dash-tx": 241, + "swarm-manifest": 250, + "swarm-feed": 251, + "udp": 273, + "p2p-webrtc-star": 275, + "p2p-webrtc-direct": 276, + "p2p-stardust": 277, + "p2p-circuit": 290, + "dag-json": 297, + "udt": 301, + "utp": 302, + "unix": 400, + "p2p": 421, + "ipfs": 421, + "https": 443, + "onion": 444, + "onion3": 445, + "garlic64": 446, + "garlic32": 447, + "tls": 448, + "quic": 460, + "ws": 477, + "wss": 478, + "p2p-websocket-star": 479, + "http": 480, + "json": 512, + "messagepack": 513, + "x11": 4352, + "blake2b-8": 45569, + "blake2b-16": 45570, + "blake2b-24": 45571, + "blake2b-32": 45572, + "blake2b-40": 45573, + "blake2b-48": 45574, + "blake2b-56": 45575, + "blake2b-64": 45576, + "blake2b-72": 45577, + "blake2b-80": 45578, + "blake2b-88": 45579, + "blake2b-96": 45580, + "blake2b-104": 45581, + "blake2b-112": 45582, + "blake2b-120": 45583, + "blake2b-128": 45584, + "blake2b-136": 45585, + "blake2b-144": 45586, + "blake2b-152": 45587, + "blake2b-160": 45588, + "blake2b-168": 45589, + "blake2b-176": 45590, + "blake2b-184": 45591, + "blake2b-192": 45592, + "blake2b-200": 45593, + "blake2b-208": 45594, + "blake2b-216": 45595, + "blake2b-224": 45596, + "blake2b-232": 45597, + "blake2b-240": 45598, + "blake2b-248": 45599, + "blake2b-256": 45600, + "blake2b-264": 45601, + "blake2b-272": 45602, + "blake2b-280": 45603, + "blake2b-288": 45604, + "blake2b-296": 45605, + "blake2b-304": 45606, + "blake2b-312": 45607, + "blake2b-320": 45608, + "blake2b-328": 45609, + "blake2b-336": 45610, + "blake2b-344": 45611, + "blake2b-352": 45612, + "blake2b-360": 45613, + "blake2b-368": 45614, + "blake2b-376": 45615, + "blake2b-384": 45616, + "blake2b-392": 45617, + "blake2b-400": 45618, + "blake2b-408": 45619, + "blake2b-416": 45620, + "blake2b-424": 45621, + "blake2b-432": 45622, + "blake2b-440": 45623, + "blake2b-448": 45624, + "blake2b-456": 45625, + "blake2b-464": 45626, + "blake2b-472": 45627, + "blake2b-480": 45628, + "blake2b-488": 45629, + "blake2b-496": 45630, + "blake2b-504": 45631, + "blake2b-512": 45632, + "blake2s-8": 45633, + "blake2s-16": 45634, + "blake2s-24": 45635, + "blake2s-32": 45636, + "blake2s-40": 45637, + "blake2s-48": 45638, + "blake2s-56": 45639, + "blake2s-64": 45640, + "blake2s-72": 45641, + "blake2s-80": 45642, + "blake2s-88": 45643, + "blake2s-96": 45644, + "blake2s-104": 45645, + "blake2s-112": 45646, + "blake2s-120": 45647, + "blake2s-128": 45648, + "blake2s-136": 45649, + "blake2s-144": 45650, + "blake2s-152": 45651, + "blake2s-160": 45652, + "blake2s-168": 45653, + "blake2s-176": 45654, + "blake2s-184": 45655, + "blake2s-192": 45656, + "blake2s-200": 45657, + "blake2s-208": 45658, + "blake2s-216": 45659, + "blake2s-224": 45660, + "blake2s-232": 45661, + "blake2s-240": 45662, + "blake2s-248": 45663, + "blake2s-256": 45664, + "skein256-8": 45825, + "skein256-16": 45826, + "skein256-24": 45827, + "skein256-32": 45828, + "skein256-40": 45829, + "skein256-48": 45830, + "skein256-56": 45831, + "skein256-64": 45832, + "skein256-72": 45833, + "skein256-80": 45834, + "skein256-88": 45835, + "skein256-96": 45836, + "skein256-104": 45837, + "skein256-112": 45838, + "skein256-120": 45839, + "skein256-128": 45840, + "skein256-136": 45841, + "skein256-144": 45842, + "skein256-152": 45843, + "skein256-160": 45844, + "skein256-168": 45845, + "skein256-176": 45846, + "skein256-184": 45847, + "skein256-192": 45848, + "skein256-200": 45849, + "skein256-208": 45850, + "skein256-216": 45851, + "skein256-224": 45852, + "skein256-232": 45853, + "skein256-240": 45854, + "skein256-248": 45855, + "skein256-256": 45856, + "skein512-8": 45857, + "skein512-16": 45858, + "skein512-24": 45859, + "skein512-32": 45860, + "skein512-40": 45861, + "skein512-48": 45862, + "skein512-56": 45863, + "skein512-64": 45864, + "skein512-72": 45865, + "skein512-80": 45866, + "skein512-88": 45867, + "skein512-96": 45868, + "skein512-104": 45869, + "skein512-112": 45870, + "skein512-120": 45871, + "skein512-128": 45872, + "skein512-136": 45873, + "skein512-144": 45874, + "skein512-152": 45875, + "skein512-160": 45876, + "skein512-168": 45877, + "skein512-176": 45878, + "skein512-184": 45879, + "skein512-192": 45880, + "skein512-200": 45881, + "skein512-208": 45882, + "skein512-216": 45883, + "skein512-224": 45884, + "skein512-232": 45885, + "skein512-240": 45886, + "skein512-248": 45887, + "skein512-256": 45888, + "skein512-264": 45889, + "skein512-272": 45890, + "skein512-280": 45891, + "skein512-288": 45892, + "skein512-296": 45893, + "skein512-304": 45894, + "skein512-312": 45895, + "skein512-320": 45896, + "skein512-328": 45897, + "skein512-336": 45898, + "skein512-344": 45899, + "skein512-352": 45900, + "skein512-360": 45901, + "skein512-368": 45902, + "skein512-376": 45903, + "skein512-384": 45904, + "skein512-392": 45905, + "skein512-400": 45906, + "skein512-408": 45907, + "skein512-416": 45908, + "skein512-424": 45909, + "skein512-432": 45910, + "skein512-440": 45911, + "skein512-448": 45912, + "skein512-456": 45913, + "skein512-464": 45914, + "skein512-472": 45915, + "skein512-480": 45916, + "skein512-488": 45917, + "skein512-496": 45918, + "skein512-504": 45919, + "skein512-512": 45920, + "skein1024-8": 45921, + "skein1024-16": 45922, + "skein1024-24": 45923, + "skein1024-32": 45924, + "skein1024-40": 45925, + "skein1024-48": 45926, + "skein1024-56": 45927, + "skein1024-64": 45928, + "skein1024-72": 45929, + "skein1024-80": 45930, + "skein1024-88": 45931, + "skein1024-96": 45932, + "skein1024-104": 45933, + "skein1024-112": 45934, + "skein1024-120": 45935, + "skein1024-128": 45936, + "skein1024-136": 45937, + "skein1024-144": 45938, + "skein1024-152": 45939, + "skein1024-160": 45940, + "skein1024-168": 45941, + "skein1024-176": 45942, + "skein1024-184": 45943, + "skein1024-192": 45944, + "skein1024-200": 45945, + "skein1024-208": 45946, + "skein1024-216": 45947, + "skein1024-224": 45948, + "skein1024-232": 45949, + "skein1024-240": 45950, + "skein1024-248": 45951, + "skein1024-256": 45952, + "skein1024-264": 45953, + "skein1024-272": 45954, + "skein1024-280": 45955, + "skein1024-288": 45956, + "skein1024-296": 45957, + "skein1024-304": 45958, + "skein1024-312": 45959, + "skein1024-320": 45960, + "skein1024-328": 45961, + "skein1024-336": 45962, + "skein1024-344": 45963, + "skein1024-352": 45964, + "skein1024-360": 45965, + "skein1024-368": 45966, + "skein1024-376": 45967, + "skein1024-384": 45968, + "skein1024-392": 45969, + "skein1024-400": 45970, + "skein1024-408": 45971, + "skein1024-416": 45972, + "skein1024-424": 45973, + "skein1024-432": 45974, + "skein1024-440": 45975, + "skein1024-448": 45976, + "skein1024-456": 45977, + "skein1024-464": 45978, + "skein1024-472": 45979, + "skein1024-480": 45980, + "skein1024-488": 45981, + "skein1024-496": 45982, + "skein1024-504": 45983, + "skein1024-512": 45984, + "skein1024-520": 45985, + "skein1024-528": 45986, + "skein1024-536": 45987, + "skein1024-544": 45988, + "skein1024-552": 45989, + "skein1024-560": 45990, + "skein1024-568": 45991, + "skein1024-576": 45992, + "skein1024-584": 45993, + "skein1024-592": 45994, + "skein1024-600": 45995, + "skein1024-608": 45996, + "skein1024-616": 45997, + "skein1024-624": 45998, + "skein1024-632": 45999, + "skein1024-640": 46000, + "skein1024-648": 46001, + "skein1024-656": 46002, + "skein1024-664": 46003, + "skein1024-672": 46004, + "skein1024-680": 46005, + "skein1024-688": 46006, + "skein1024-696": 46007, + "skein1024-704": 46008, + "skein1024-712": 46009, + "skein1024-720": 46010, + "skein1024-728": 46011, + "skein1024-736": 46012, + "skein1024-744": 46013, + "skein1024-752": 46014, + "skein1024-760": 46015, + "skein1024-768": 46016, + "skein1024-776": 46017, + "skein1024-784": 46018, + "skein1024-792": 46019, + "skein1024-800": 46020, + "skein1024-808": 46021, + "skein1024-816": 46022, + "skein1024-824": 46023, + "skein1024-832": 46024, + "skein1024-840": 46025, + "skein1024-848": 46026, + "skein1024-856": 46027, + "skein1024-864": 46028, + "skein1024-872": 46029, + "skein1024-880": 46030, + "skein1024-888": 46031, + "skein1024-896": 46032, + "skein1024-904": 46033, + "skein1024-912": 46034, + "skein1024-920": 46035, + "skein1024-928": 46036, + "skein1024-936": 46037, + "skein1024-944": 46038, + "skein1024-952": 46039, + "skein1024-960": 46040, + "skein1024-968": 46041, + "skein1024-976": 46042, + "skein1024-984": 46043, + "skein1024-992": 46044, + "skein1024-1000": 46045, + "skein1024-1008": 46046, + "skein1024-1016": 46047, + "skein1024-1024": 46048, + "holochain-adr-v0": 8417572, + "holochain-adr-v1": 8483108, + "holochain-key-v0": 9728292, + "holochain-key-v1": 9793828, + "holochain-sig-v0": 10645796, + "holochain-sig-v1": 10711332 +} \ No newline at end of file diff --git a/src/constants.js b/src/constants.js index ea511d3..a0234e6 100644 --- a/src/constants.js +++ b/src/constants.js @@ -1,448 +1,12 @@ -// THIS FILE IS GENERATED, DO NO EDIT MANUALLY -// For more information see the README.md -/* eslint-disable dot-notation */ 'use strict' -module.exports = Object.freeze({ - // serialization - PROTOBUF: 0x50, - CBOR: 0x51, - RLP: 0x60, - BENCODE: 0x63, - JSON: 0x0200, - MESSAGEPACK: 0x0201, +const table = require('./base-table.json') - // multiformat - MULTICODEC: 0x30, - MULTIHASH: 0x31, - MULTIADDR: 0x32, - MULTIBASE: 0x33, +// map for codecConstant -> code +const constants = {} - // multihash - IDENTITY: 0x00, - SHA1: 0x11, - SHA2_256: 0x12, - SHA2_512: 0x13, - SHA3_512: 0x14, - SHA3_384: 0x15, - SHA3_256: 0x16, - SHA3_224: 0x17, - SHAKE_128: 0x18, - SHAKE_256: 0x19, - KECCAK_224: 0x1a, - KECCAK_256: 0x1b, - KECCAK_384: 0x1c, - KECCAK_512: 0x1d, - MURMUR3_128: 0x22, - MURMUR3_32: 0x23, - DBL_SHA2_256: 0x56, - MD4: 0xd4, - MD5: 0xd5, - BMT: 0xd6, - X11: 0x1100, - BLAKE2B_8: 0xb201, - BLAKE2B_16: 0xb202, - BLAKE2B_24: 0xb203, - BLAKE2B_32: 0xb204, - BLAKE2B_40: 0xb205, - BLAKE2B_48: 0xb206, - BLAKE2B_56: 0xb207, - BLAKE2B_64: 0xb208, - BLAKE2B_72: 0xb209, - BLAKE2B_80: 0xb20a, - BLAKE2B_88: 0xb20b, - BLAKE2B_96: 0xb20c, - BLAKE2B_104: 0xb20d, - BLAKE2B_112: 0xb20e, - BLAKE2B_120: 0xb20f, - BLAKE2B_128: 0xb210, - BLAKE2B_136: 0xb211, - BLAKE2B_144: 0xb212, - BLAKE2B_152: 0xb213, - BLAKE2B_160: 0xb214, - BLAKE2B_168: 0xb215, - BLAKE2B_176: 0xb216, - BLAKE2B_184: 0xb217, - BLAKE2B_192: 0xb218, - BLAKE2B_200: 0xb219, - BLAKE2B_208: 0xb21a, - BLAKE2B_216: 0xb21b, - BLAKE2B_224: 0xb21c, - BLAKE2B_232: 0xb21d, - BLAKE2B_240: 0xb21e, - BLAKE2B_248: 0xb21f, - BLAKE2B_256: 0xb220, - BLAKE2B_264: 0xb221, - BLAKE2B_272: 0xb222, - BLAKE2B_280: 0xb223, - BLAKE2B_288: 0xb224, - BLAKE2B_296: 0xb225, - BLAKE2B_304: 0xb226, - BLAKE2B_312: 0xb227, - BLAKE2B_320: 0xb228, - BLAKE2B_328: 0xb229, - BLAKE2B_336: 0xb22a, - BLAKE2B_344: 0xb22b, - BLAKE2B_352: 0xb22c, - BLAKE2B_360: 0xb22d, - BLAKE2B_368: 0xb22e, - BLAKE2B_376: 0xb22f, - BLAKE2B_384: 0xb230, - BLAKE2B_392: 0xb231, - BLAKE2B_400: 0xb232, - BLAKE2B_408: 0xb233, - BLAKE2B_416: 0xb234, - BLAKE2B_424: 0xb235, - BLAKE2B_432: 0xb236, - BLAKE2B_440: 0xb237, - BLAKE2B_448: 0xb238, - BLAKE2B_456: 0xb239, - BLAKE2B_464: 0xb23a, - BLAKE2B_472: 0xb23b, - BLAKE2B_480: 0xb23c, - BLAKE2B_488: 0xb23d, - BLAKE2B_496: 0xb23e, - BLAKE2B_504: 0xb23f, - BLAKE2B_512: 0xb240, - BLAKE2S_8: 0xb241, - BLAKE2S_16: 0xb242, - BLAKE2S_24: 0xb243, - BLAKE2S_32: 0xb244, - BLAKE2S_40: 0xb245, - BLAKE2S_48: 0xb246, - BLAKE2S_56: 0xb247, - BLAKE2S_64: 0xb248, - BLAKE2S_72: 0xb249, - BLAKE2S_80: 0xb24a, - BLAKE2S_88: 0xb24b, - BLAKE2S_96: 0xb24c, - BLAKE2S_104: 0xb24d, - BLAKE2S_112: 0xb24e, - BLAKE2S_120: 0xb24f, - BLAKE2S_128: 0xb250, - BLAKE2S_136: 0xb251, - BLAKE2S_144: 0xb252, - BLAKE2S_152: 0xb253, - BLAKE2S_160: 0xb254, - BLAKE2S_168: 0xb255, - BLAKE2S_176: 0xb256, - BLAKE2S_184: 0xb257, - BLAKE2S_192: 0xb258, - BLAKE2S_200: 0xb259, - BLAKE2S_208: 0xb25a, - BLAKE2S_216: 0xb25b, - BLAKE2S_224: 0xb25c, - BLAKE2S_232: 0xb25d, - BLAKE2S_240: 0xb25e, - BLAKE2S_248: 0xb25f, - BLAKE2S_256: 0xb260, - SKEIN256_8: 0xb301, - SKEIN256_16: 0xb302, - SKEIN256_24: 0xb303, - SKEIN256_32: 0xb304, - SKEIN256_40: 0xb305, - SKEIN256_48: 0xb306, - SKEIN256_56: 0xb307, - SKEIN256_64: 0xb308, - SKEIN256_72: 0xb309, - SKEIN256_80: 0xb30a, - SKEIN256_88: 0xb30b, - SKEIN256_96: 0xb30c, - SKEIN256_104: 0xb30d, - SKEIN256_112: 0xb30e, - SKEIN256_120: 0xb30f, - SKEIN256_128: 0xb310, - SKEIN256_136: 0xb311, - SKEIN256_144: 0xb312, - SKEIN256_152: 0xb313, - SKEIN256_160: 0xb314, - SKEIN256_168: 0xb315, - SKEIN256_176: 0xb316, - SKEIN256_184: 0xb317, - SKEIN256_192: 0xb318, - SKEIN256_200: 0xb319, - SKEIN256_208: 0xb31a, - SKEIN256_216: 0xb31b, - SKEIN256_224: 0xb31c, - SKEIN256_232: 0xb31d, - SKEIN256_240: 0xb31e, - SKEIN256_248: 0xb31f, - SKEIN256_256: 0xb320, - SKEIN512_8: 0xb321, - SKEIN512_16: 0xb322, - SKEIN512_24: 0xb323, - SKEIN512_32: 0xb324, - SKEIN512_40: 0xb325, - SKEIN512_48: 0xb326, - SKEIN512_56: 0xb327, - SKEIN512_64: 0xb328, - SKEIN512_72: 0xb329, - SKEIN512_80: 0xb32a, - SKEIN512_88: 0xb32b, - SKEIN512_96: 0xb32c, - SKEIN512_104: 0xb32d, - SKEIN512_112: 0xb32e, - SKEIN512_120: 0xb32f, - SKEIN512_128: 0xb330, - SKEIN512_136: 0xb331, - SKEIN512_144: 0xb332, - SKEIN512_152: 0xb333, - SKEIN512_160: 0xb334, - SKEIN512_168: 0xb335, - SKEIN512_176: 0xb336, - SKEIN512_184: 0xb337, - SKEIN512_192: 0xb338, - SKEIN512_200: 0xb339, - SKEIN512_208: 0xb33a, - SKEIN512_216: 0xb33b, - SKEIN512_224: 0xb33c, - SKEIN512_232: 0xb33d, - SKEIN512_240: 0xb33e, - SKEIN512_248: 0xb33f, - SKEIN512_256: 0xb340, - SKEIN512_264: 0xb341, - SKEIN512_272: 0xb342, - SKEIN512_280: 0xb343, - SKEIN512_288: 0xb344, - SKEIN512_296: 0xb345, - SKEIN512_304: 0xb346, - SKEIN512_312: 0xb347, - SKEIN512_320: 0xb348, - SKEIN512_328: 0xb349, - SKEIN512_336: 0xb34a, - SKEIN512_344: 0xb34b, - SKEIN512_352: 0xb34c, - SKEIN512_360: 0xb34d, - SKEIN512_368: 0xb34e, - SKEIN512_376: 0xb34f, - SKEIN512_384: 0xb350, - SKEIN512_392: 0xb351, - SKEIN512_400: 0xb352, - SKEIN512_408: 0xb353, - SKEIN512_416: 0xb354, - SKEIN512_424: 0xb355, - SKEIN512_432: 0xb356, - SKEIN512_440: 0xb357, - SKEIN512_448: 0xb358, - SKEIN512_456: 0xb359, - SKEIN512_464: 0xb35a, - SKEIN512_472: 0xb35b, - SKEIN512_480: 0xb35c, - SKEIN512_488: 0xb35d, - SKEIN512_496: 0xb35e, - SKEIN512_504: 0xb35f, - SKEIN512_512: 0xb360, - SKEIN1024_8: 0xb361, - SKEIN1024_16: 0xb362, - SKEIN1024_24: 0xb363, - SKEIN1024_32: 0xb364, - SKEIN1024_40: 0xb365, - SKEIN1024_48: 0xb366, - SKEIN1024_56: 0xb367, - SKEIN1024_64: 0xb368, - SKEIN1024_72: 0xb369, - SKEIN1024_80: 0xb36a, - SKEIN1024_88: 0xb36b, - SKEIN1024_96: 0xb36c, - SKEIN1024_104: 0xb36d, - SKEIN1024_112: 0xb36e, - SKEIN1024_120: 0xb36f, - SKEIN1024_128: 0xb370, - SKEIN1024_136: 0xb371, - SKEIN1024_144: 0xb372, - SKEIN1024_152: 0xb373, - SKEIN1024_160: 0xb374, - SKEIN1024_168: 0xb375, - SKEIN1024_176: 0xb376, - SKEIN1024_184: 0xb377, - SKEIN1024_192: 0xb378, - SKEIN1024_200: 0xb379, - SKEIN1024_208: 0xb37a, - SKEIN1024_216: 0xb37b, - SKEIN1024_224: 0xb37c, - SKEIN1024_232: 0xb37d, - SKEIN1024_240: 0xb37e, - SKEIN1024_248: 0xb37f, - SKEIN1024_256: 0xb380, - SKEIN1024_264: 0xb381, - SKEIN1024_272: 0xb382, - SKEIN1024_280: 0xb383, - SKEIN1024_288: 0xb384, - SKEIN1024_296: 0xb385, - SKEIN1024_304: 0xb386, - SKEIN1024_312: 0xb387, - SKEIN1024_320: 0xb388, - SKEIN1024_328: 0xb389, - SKEIN1024_336: 0xb38a, - SKEIN1024_344: 0xb38b, - SKEIN1024_352: 0xb38c, - SKEIN1024_360: 0xb38d, - SKEIN1024_368: 0xb38e, - SKEIN1024_376: 0xb38f, - SKEIN1024_384: 0xb390, - SKEIN1024_392: 0xb391, - SKEIN1024_400: 0xb392, - SKEIN1024_408: 0xb393, - SKEIN1024_416: 0xb394, - SKEIN1024_424: 0xb395, - SKEIN1024_432: 0xb396, - SKEIN1024_440: 0xb397, - SKEIN1024_448: 0xb398, - SKEIN1024_456: 0xb399, - SKEIN1024_464: 0xb39a, - SKEIN1024_472: 0xb39b, - SKEIN1024_480: 0xb39c, - SKEIN1024_488: 0xb39d, - SKEIN1024_496: 0xb39e, - SKEIN1024_504: 0xb39f, - SKEIN1024_512: 0xb3a0, - SKEIN1024_520: 0xb3a1, - SKEIN1024_528: 0xb3a2, - SKEIN1024_536: 0xb3a3, - SKEIN1024_544: 0xb3a4, - SKEIN1024_552: 0xb3a5, - SKEIN1024_560: 0xb3a6, - SKEIN1024_568: 0xb3a7, - SKEIN1024_576: 0xb3a8, - SKEIN1024_584: 0xb3a9, - SKEIN1024_592: 0xb3aa, - SKEIN1024_600: 0xb3ab, - SKEIN1024_608: 0xb3ac, - SKEIN1024_616: 0xb3ad, - SKEIN1024_624: 0xb3ae, - SKEIN1024_632: 0xb3af, - SKEIN1024_640: 0xb3b0, - SKEIN1024_648: 0xb3b1, - SKEIN1024_656: 0xb3b2, - SKEIN1024_664: 0xb3b3, - SKEIN1024_672: 0xb3b4, - SKEIN1024_680: 0xb3b5, - SKEIN1024_688: 0xb3b6, - SKEIN1024_696: 0xb3b7, - SKEIN1024_704: 0xb3b8, - SKEIN1024_712: 0xb3b9, - SKEIN1024_720: 0xb3ba, - SKEIN1024_728: 0xb3bb, - SKEIN1024_736: 0xb3bc, - SKEIN1024_744: 0xb3bd, - SKEIN1024_752: 0xb3be, - SKEIN1024_760: 0xb3bf, - SKEIN1024_768: 0xb3c0, - SKEIN1024_776: 0xb3c1, - SKEIN1024_784: 0xb3c2, - SKEIN1024_792: 0xb3c3, - SKEIN1024_800: 0xb3c4, - SKEIN1024_808: 0xb3c5, - SKEIN1024_816: 0xb3c6, - SKEIN1024_824: 0xb3c7, - SKEIN1024_832: 0xb3c8, - SKEIN1024_840: 0xb3c9, - SKEIN1024_848: 0xb3ca, - SKEIN1024_856: 0xb3cb, - SKEIN1024_864: 0xb3cc, - SKEIN1024_872: 0xb3cd, - SKEIN1024_880: 0xb3ce, - SKEIN1024_888: 0xb3cf, - SKEIN1024_896: 0xb3d0, - SKEIN1024_904: 0xb3d1, - SKEIN1024_912: 0xb3d2, - SKEIN1024_920: 0xb3d3, - SKEIN1024_928: 0xb3d4, - SKEIN1024_936: 0xb3d5, - SKEIN1024_944: 0xb3d6, - SKEIN1024_952: 0xb3d7, - SKEIN1024_960: 0xb3d8, - SKEIN1024_968: 0xb3d9, - SKEIN1024_976: 0xb3da, - SKEIN1024_984: 0xb3db, - SKEIN1024_992: 0xb3dc, - SKEIN1024_1000: 0xb3dd, - SKEIN1024_1008: 0xb3de, - SKEIN1024_1016: 0xb3df, - SKEIN1024_1024: 0xb3e0, +for (const [name, code] of Object.entries(table)) { + constants[name.toUpperCase().replace(/-/g, '_')] = code +} - // multiaddr - IP4: 0x04, - TCP: 0x06, - DCCP: 0x21, - IP6: 0x29, - IP6ZONE: 0x2a, - DNS: 0x35, - DNS4: 0x36, - DNS6: 0x37, - DNSADDR: 0x38, - SCTP: 0x84, - UDP: 0x0111, - P2P_WEBRTC_STAR: 0x0113, - P2P_WEBRTC_DIRECT: 0x0114, - P2P_STARDUST: 0x0115, - P2P_CIRCUIT: 0x0122, - UDT: 0x012d, - UTP: 0x012e, - UNIX: 0x0190, - P2P: 0x01a5, - IPFS: 0x01a5, - HTTPS: 0x01bb, - ONION: 0x01bc, - ONION3: 0x01bd, - GARLIC64: 0x01be, - GARLIC32: 0x01bf, - QUIC: 0x01cc, - WS: 0x01dd, - WSS: 0x01de, - P2P_WEBSOCKET_STAR: 0x01df, - HTTP: 0x01e0, - - // ipld - RAW: 0x55, - DAG_PB: 0x70, - DAG_CBOR: 0x71, - LIBP2P_KEY: 0x72, - GIT_RAW: 0x78, - TORRENT_INFO: 0x7b, - TORRENT_FILE: 0x7c, - LEOFCOIN_BLOCK: 0x81, - LEOFCOIN_TX: 0x82, - LEOFCOIN_PR: 0x83, - ETH_BLOCK: 0x90, - ETH_BLOCK_LIST: 0x91, - ETH_TX_TRIE: 0x92, - ETH_TX: 0x93, - ETH_TX_RECEIPT_TRIE: 0x94, - ETH_TX_RECEIPT: 0x95, - ETH_STATE_TRIE: 0x96, - ETH_ACCOUNT_SNAPSHOT: 0x97, - ETH_STORAGE_TRIE: 0x98, - BITCOIN_BLOCK: 0xb0, - BITCOIN_TX: 0xb1, - ZCASH_BLOCK: 0xc0, - ZCASH_TX: 0xc1, - STELLAR_BLOCK: 0xd0, - STELLAR_TX: 0xd1, - DECRED_BLOCK: 0xe0, - DECRED_TX: 0xe1, - DASH_BLOCK: 0xf0, - DASH_TX: 0xf1, - SWARM_MANIFEST: 0xfa, - SWARM_FEED: 0xfb, - DAG_JSON: 0x0129, - - // namespace - PATH: 0x2f, - IPLD_NS: 0xe2, - IPFS_NS: 0xe3, - SWARM_NS: 0xe4, - IPNS_NS: 0xe5, - ZERONET: 0xe6, - - // key - ED25519_PUB: 0xed, - - // holochain - HOLOCHAIN_ADR_V0: 0x807124, - HOLOCHAIN_ADR_V1: 0x817124, - HOLOCHAIN_KEY_V0: 0x947124, - HOLOCHAIN_KEY_V1: 0x957124, - HOLOCHAIN_SIG_V0: 0xa27124, - HOLOCHAIN_SIG_V1: 0xa37124 -}) +module.exports = Object.freeze(constants) diff --git a/src/name-table.js b/src/name-table.js index 636a0e4..bdd4edd 100644 --- a/src/name-table.js +++ b/src/name-table.js @@ -1,12 +1,12 @@ 'use strict' -const baseTable = require('./base-table') - -// this creates a map for code as hexString -> codecName +const baseTable = require('./base-table.json') +// map for hexString -> codecName const nameTable = {} -module.exports = nameTable -for (let encodingName in baseTable) { - let code = baseTable[encodingName] - nameTable[code.toString('hex')] = encodingName +for (const encodingName in baseTable) { + const code = baseTable[encodingName] + nameTable[code.toString(16)] = encodingName } + +module.exports = Object.freeze(nameTable) diff --git a/src/print.js b/src/print.js index ddc31de..0523f3c 100644 --- a/src/print.js +++ b/src/print.js @@ -1,447 +1,12 @@ -// THIS FILE IS GENERATED, DO NO EDIT MANUALLY -// For more information see the README.md -/* eslint-disable dot-notation */ 'use strict' -module.exports = Object.freeze({ - // serialization - 0x50: 'protobuf', - 0x51: 'cbor', - 0x60: 'rlp', - 0x63: 'bencode', - 0x0200: 'json', - 0x0201: 'messagepack', +const table = require('./base-table.json') - // multiformat - 0x30: 'multicodec', - 0x31: 'multihash', - 0x32: 'multiaddr', - 0x33: 'multibase', +// map for code -> print friendly name +const tableByCode = {} - // multihash - 0x00: 'identity', - 0x11: 'sha1', - 0x12: 'sha2-256', - 0x13: 'sha2-512', - 0x14: 'sha3-512', - 0x15: 'sha3-384', - 0x16: 'sha3-256', - 0x17: 'sha3-224', - 0x18: 'shake-128', - 0x19: 'shake-256', - 0x1a: 'keccak-224', - 0x1b: 'keccak-256', - 0x1c: 'keccak-384', - 0x1d: 'keccak-512', - 0x22: 'murmur3-128', - 0x23: 'murmur3-32', - 0x56: 'dbl-sha2-256', - 0xd4: 'md4', - 0xd5: 'md5', - 0xd6: 'bmt', - 0x1100: 'x11', - 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', - 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', +for (const [name, code] of Object.entries(table)) { + if (tableByCode[code] === undefined) tableByCode[code] = name +} - // multiaddr - 0x04: 'ip4', - 0x06: 'tcp', - 0x21: 'dccp', - 0x29: 'ip6', - 0x2a: 'ip6zone', - 0x35: 'dns', - 0x36: 'dns4', - 0x37: 'dns6', - 0x38: 'dnsaddr', - 0x84: 'sctp', - 0x0111: 'udp', - 0x0113: 'p2p-webrtc-star', - 0x0114: 'p2p-webrtc-direct', - 0x0115: 'p2p-stardust', - 0x0122: 'p2p-circuit', - 0x012d: 'udt', - 0x012e: 'utp', - 0x0190: 'unix', - 0x01a5: 'p2p', - 0x01bb: 'https', - 0x01bc: 'onion', - 0x01bd: 'onion3', - 0x01be: 'garlic64', - 0x01bf: 'garlic32', - 0x01cc: 'quic', - 0x01dd: 'ws', - 0x01de: 'wss', - 0x01df: 'p2p-websocket-star', - 0x01e0: 'http', - - // ipld - 0x55: 'raw', - 0x70: 'dag-pb', - 0x71: 'dag-cbor', - 0x72: 'libp2p-key', - 0x78: 'git-raw', - 0x7b: 'torrent-info', - 0x7c: 'torrent-file', - 0x81: 'leofcoin-block', - 0x82: 'leofcoin-tx', - 0x83: 'leofcoin-pr', - 0x90: 'eth-block', - 0x91: 'eth-block-list', - 0x92: 'eth-tx-trie', - 0x93: 'eth-tx', - 0x94: 'eth-tx-receipt-trie', - 0x95: 'eth-tx-receipt', - 0x96: 'eth-state-trie', - 0x97: 'eth-account-snapshot', - 0x98: 'eth-storage-trie', - 0xb0: 'bitcoin-block', - 0xb1: 'bitcoin-tx', - 0xc0: 'zcash-block', - 0xc1: 'zcash-tx', - 0xd0: 'stellar-block', - 0xd1: 'stellar-tx', - 0xe0: 'decred-block', - 0xe1: 'decred-tx', - 0xf0: 'dash-block', - 0xf1: 'dash-tx', - 0xfa: 'swarm-manifest', - 0xfb: 'swarm-feed', - 0x0129: 'dag-json', - - // namespace - 0x2f: 'path', - 0xe2: 'ipld-ns', - 0xe3: 'ipfs-ns', - 0xe4: 'swarm-ns', - 0xe5: 'ipns-ns', - 0xe6: 'zeronet', - - // key - 0xed: 'ed25519-pub', - - // holochain - 0x807124: 'holochain-adr-v0', - 0x817124: 'holochain-adr-v1', - 0x947124: 'holochain-key-v0', - 0x957124: 'holochain-key-v1', - 0xa27124: 'holochain-sig-v0', - 0xa37124: 'holochain-sig-v1' -}) +module.exports = Object.freeze(tableByCode) diff --git a/src/util.js b/src/util.js index 08aaf8f..87d0a0e 100644 --- a/src/util.js +++ b/src/util.js @@ -5,7 +5,8 @@ module.exports = { numberToBuffer, bufferToNumber, varintBufferEncode, - varintBufferDecode + varintBufferDecode, + varintEncode } function bufferToNumber (buf) { @@ -27,3 +28,7 @@ function varintBufferEncode (input) { function varintBufferDecode (input) { return numberToBuffer(varint.decode(input)) } + +function varintEncode (num) { + return Buffer.from(varint.encode(num)) +} diff --git a/src/varint-table.js b/src/varint-table.js index 09f202b..21af1b8 100644 --- a/src/varint-table.js +++ b/src/varint-table.js @@ -1,13 +1,14 @@ 'use strict' -const baseTable = require('./base-table') -const varintBufferEncode = require('./util').varintBufferEncode -// this creates a map for codecName -> codeVarintBuffer +const baseTable = require('./base-table.json') +const varintEncode = require('./util').varintEncode +// map for codecName -> codeVarintBuffer const varintTable = {} -module.exports = varintTable -for (let encodingName in baseTable) { - let code = baseTable[encodingName] - varintTable[encodingName] = varintBufferEncode(code) +for (const encodingName in baseTable) { + const code = baseTable[encodingName] + varintTable[encodingName] = varintEncode(code) } + +module.exports = Object.freeze(varintTable) diff --git a/tools/update-table.js b/tools/update-table.js new file mode 100755 index 0000000..a4ecaeb --- /dev/null +++ b/tools/update-table.js @@ -0,0 +1,30 @@ +'use strict' + +const bent = require('bent') +const path = require('path') + +const get = bent('string') +const url = 'https://raw.githubusercontent.com/multiformats/multicodec/master/table.csv' +const fs = require('fs') + +const parse = async function * () { + const str = await get(url) + const lines = str.split('\n') + lines.shift() + for (const line of lines) { + if (!line.length) continue + const [name, tag, code] = line.split(',') + yield { name: name.trim(), tag: tag.trim(), code: parseInt(code.trim(), 16) } + } +} + +const run = async () => { + const table = {} + + for await (const { name, code } of parse()) { + table[name] = code + } + + fs.writeFileSync(path.join(__dirname, '../src/base-table.json'), JSON.stringify(table, null, 2)) +} +run() diff --git a/tools/update-table.py b/tools/update-table.py deleted file mode 100755 index 9b7f597..0000000 --- a/tools/update-table.py +++ /dev/null @@ -1,115 +0,0 @@ -#!/usr/bin/env python3 - -import csv -import os -import sys -from collections import OrderedDict - -# This is relative to where this script resides. Though you can also define -# an absolute path -DEFAULT_OUTPUT_DIR = '../src' - -# The header of the generated files -HEADER = '''\ -// THIS FILE IS GENERATED, DO NO EDIT MANUALLY -// For more information see the README.md -/* eslint-disable dot-notation */ -'use strict' -''' - - -def padded_hex(hexstring): - """Creates a padded (starting with a 0 if odd) hex string""" - number = int(row['code'], 16) - hexbytes = '{:x}'.format(number) - if len(hexbytes) % 2: - prefix = '0x0' - else: - prefix = '0x' - return prefix + hexbytes - - -def unique_code(codecs): - """Returns a list where every code exists only one. - - The first item in the list is taken - """ - seen = [] - unique = [] - for codec in codecs: - if 'code' in codec: - if codec['code'] in seen: - continue - else: - seen.append(codec['code']) - unique.append(codec) - return unique - - -# Preserve the order from earlier versions. New tags are appended -parsed = OrderedDict([ - ('serialization', []), - ('multiformat', []), - ('multihash', []), - ('multiaddr', []), - ('ipld', []), - ('namespace', []), - ('key', []), - ('holochain', []), -]) - -multicodec_reader = csv.DictReader(sys.stdin, skipinitialspace=True) -for row in multicodec_reader: - code = padded_hex(row['code']) - name_const = row['name'].upper().replace('-', '_') - name_human = row['name'] - tag = row['tag'] - value = { - 'const': name_const, - 'human': name_human, - 'code': code - } - if tag not in parsed: - parsed[tag] = [] - - parsed[tag].append(value) - -tools_dir = os.path.dirname(os.path.abspath(__file__)) -output_dir = os.path.join(tools_dir, DEFAULT_OUTPUT_DIR) - -print_file = os.path.join(output_dir, 'base-table.js') -with open(print_file, 'w') as ff: - ff.write(HEADER) - for tag, codecs in parsed.items(): - ff.write(f"\n// {tag}\n") - for codec in codecs: - hexstring = codec['code'][2:] - ff.write("exports['{}'] = Buffer.from('{}', 'hex')\n" - .format(codec['human'], hexstring)) - -constants_file = os.path.join(output_dir, 'constants.js') -with open(constants_file, 'w') as ff: - ff.write(HEADER) - ff.write('module.exports = Object.freeze({\n') - for tagindex, (tag, codecs) in enumerate(parsed.items()): - ff.write(f"\n // {tag}\n") - for codecindex, codec in enumerate(codecs): - ff.write(" {const}: {code}".format(**codec)) - # Add a trailing comma except for the last item in the dict - if tagindex < len(parsed) - 1 or codecindex < len(codecs) - 1: - ff.write(',\n') - ff.write('\n})\n') - -print_file = os.path.join(output_dir, 'print.js') -with open(print_file, 'w') as ff: - ff.write(HEADER) - ff.write('module.exports = Object.freeze({\n') - for tagindex, (tag, codecs) in enumerate(parsed.items()): - ff.write(f"\n // {tag}\n") - unique = unique_code(codecs) - for codecindex, codec in enumerate(unique): - ff.write(" {code}: '{human}'".format(**codec)) - # Add a trailing comma except for the last item in the dict - if tagindex < len(parsed) - 1 or codecindex < len(codecs) - 1: - ff.write(',\n') - ff.write('\n})\n')