diff --git a/src/base-table.js b/src/base-table.js index f163eae..aaedfb3 100644 --- a/src/base-table.js +++ b/src/base-table.js @@ -3,33 +3,27 @@ /* eslint-disable dot-notation */ 'use strict' -// miscellaneous -exports['raw'] = Buffer.from('55', 'hex') - -// serialization formats -exports['cbor'] = Buffer.from('51', 'hex') +// 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') -// multiformats +// 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') -// multihashes +// multihash exports['identity'] = Buffer.from('00', 'hex') -exports['md4'] = Buffer.from('d4', 'hex') -exports['md5'] = Buffer.from('d5', 'hex') exports['sha1'] = Buffer.from('11', 'hex') exports['sha2-256'] = Buffer.from('12', 'hex') exports['sha2-512'] = Buffer.from('13', 'hex') -exports['dbl-sha2-256'] = Buffer.from('56', 'hex') -exports['sha3-224'] = Buffer.from('17', 'hex') -exports['sha3-256'] = Buffer.from('16', 'hex') -exports['sha3-384'] = Buffer.from('15', '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') @@ -38,6 +32,10 @@ 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') @@ -360,42 +358,47 @@ exports['skein1024-1008'] = Buffer.from('b3de', 'hex') exports['skein1024-1016'] = Buffer.from('b3df', 'hex') exports['skein1024-1024'] = Buffer.from('b3e0', 'hex') -// multiaddrs +// multiaddr exports['ip4'] = Buffer.from('04', 'hex') -exports['ip6'] = Buffer.from('29', 'hex') -exports['ip6zone'] = Buffer.from('2a', 'hex') exports['tcp'] = Buffer.from('06', 'hex') -exports['udp'] = Buffer.from('0111', '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['http'] = Buffer.from('01e0', 'hex') exports['https'] = Buffer.from('01bb', 'hex') -exports['quic'] = Buffer.from('01cc', 'hex') -exports['ws'] = Buffer.from('01dd', 'hex') -exports['wss'] = Buffer.from('01de', 'hex') exports['onion'] = Buffer.from('01bc', 'hex') exports['onion3'] = Buffer.from('01bd', 'hex') exports['garlic64'] = Buffer.from('01be', 'hex') -exports['p2p-circuit'] = Buffer.from('0122', '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['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['p2p-stardust'] = Buffer.from('0115', 'hex') -exports['p2p-webrtc-star'] = Buffer.from('0113', 'hex') -exports['p2p-webrtc-direct'] = Buffer.from('0114', 'hex') -exports['unix'] = Buffer.from('0190', 'hex') +exports['http'] = Buffer.from('01e0', 'hex') -// IPLD formats +// ipld +exports['raw'] = Buffer.from('55', 'hex') exports['dag-pb'] = Buffer.from('70', 'hex') exports['dag-cbor'] = Buffer.from('71', 'hex') -exports['dag-json'] = Buffer.from('0129', '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') @@ -415,14 +418,23 @@ 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['leofcoin-block'] = Buffer.from('81', 'hex') -exports['leofcoin-tx'] = Buffer.from('82', 'hex') -exports['leofcoin-pr'] = Buffer.from('83', 'hex') -exports['torrent-info'] = Buffer.from('7b', 'hex') -exports['torrent-file'] = Buffer.from('7c', 'hex') -exports['ed25519-pub'] = Buffer.from('ed', 'hex') +exports['swarm-manifest'] = Buffer.from('fa', 'hex') +exports['swarm-feed'] = Buffer.from('fb', 'hex') +exports['dag-json'] = Buffer.from('0129', 'hex') -// Content Namespaces +// 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') + +// 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/constants.js b/src/constants.js index 598495c..5092410 100644 --- a/src/constants.js +++ b/src/constants.js @@ -4,33 +4,27 @@ 'use strict' module.exports = Object.freeze({ - // miscellaneous, - RAW: 0x55, - - // serialization formats, - CBOR: 0x51, + // serialization PROTOBUF: 0x50, + CBOR: 0x51, RLP: 0x60, BENCODE: 0x63, - // multiformats, + // multiformat MULTICODEC: 0x30, MULTIHASH: 0x31, MULTIADDR: 0x32, MULTIBASE: 0x33, - // multihashes, + // multihash IDENTITY: 0x00, - MD4: 0xd4, - MD5: 0xd5, SHA1: 0x11, SHA2_256: 0x12, SHA2_512: 0x13, - DBL_SHA2_256: 0x56, - SHA3_224: 0x17, - SHA3_256: 0x16, - SHA3_384: 0x15, SHA3_512: 0x14, + SHA3_384: 0x15, + SHA3_256: 0x16, + SHA3_224: 0x17, SHAKE_128: 0x18, SHAKE_256: 0x19, KECCAK_224: 0x1a, @@ -39,6 +33,10 @@ module.exports = Object.freeze({ 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, @@ -361,42 +359,47 @@ module.exports = Object.freeze({ SKEIN1024_1016: 0xb3df, SKEIN1024_1024: 0xb3e0, - // multiaddrs, + // multiaddr IP4: 0x04, - IP6: 0x29, - IP6ZONE: 0x2a, TCP: 0x06, - UDP: 0x0111, 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, - HTTP: 0x01e0, HTTPS: 0x01bb, - QUIC: 0x01cc, - WS: 0x01dd, - WSS: 0x01de, ONION: 0x01bc, ONION3: 0x01bd, GARLIC64: 0x01be, - P2P_CIRCUIT: 0x0122, - DNS: 0x35, - DNS4: 0x36, - DNS6: 0x37, - DNSADDR: 0x38, + QUIC: 0x01cc, + WS: 0x01dd, + WSS: 0x01de, P2P_WEBSOCKET_STAR: 0x01df, - P2P_STARDUST: 0x0115, - P2P_WEBRTC_STAR: 0x0113, - P2P_WEBRTC_DIRECT: 0x0114, - UNIX: 0x0190, + HTTP: 0x01e0, - // IPLD formats, + // ipld + RAW: 0x55, DAG_PB: 0x70, DAG_CBOR: 0x71, - DAG_JSON: 0x0129, 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, @@ -416,15 +419,24 @@ module.exports = Object.freeze({ DECRED_TX: 0xe1, DASH_BLOCK: 0xf0, DASH_TX: 0xf1, - LEOFCOIN_BLOCK: 0x81, - LEOFCOIN_TX: 0x82, - LEOFCOIN_PR: 0x83, - TORRENT_INFO: 0x7b, - TORRENT_FILE: 0x7c, - ED25519_PUB: 0xed, + SWARM_MANIFEST: 0xfa, + SWARM_FEED: 0xfb, + DAG_JSON: 0x0129, - // Content Namespaces, + // namespace + PATH: 0x2f, IPLD_NS: 0xe2, IPFS_NS: 0xe3, - SWARM_NS: 0xe4 + SWARM_NS: 0xe4, + + // 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 }) diff --git a/src/print.js b/src/print.js index 985657d..336599f 100644 --- a/src/print.js +++ b/src/print.js @@ -4,33 +4,27 @@ 'use strict' module.exports = Object.freeze({ - // miscellaneous, - 0x55: 'raw', - - // serialization formats, - 0x51: 'cbor', + // serialization 0x50: 'protobuf', + 0x51: 'cbor', 0x60: 'rlp', 0x63: 'bencode', - // multiformats, + // multiformat 0x30: 'multicodec', 0x31: 'multihash', 0x32: 'multiaddr', 0x33: 'multibase', - // multihashes, + // multihash 0x00: 'identity', - 0xd4: 'md4', - 0xd5: 'md5', 0x11: 'sha1', 0x12: 'sha2-256', 0x13: 'sha2-512', - 0x56: 'dbl-sha2-256', - 0x17: 'sha3-224', - 0x16: 'sha3-256', - 0x15: 'sha3-384', 0x14: 'sha3-512', + 0x15: 'sha3-384', + 0x16: 'sha3-256', + 0x17: 'sha3-224', 0x18: 'shake-128', 0x19: 'shake-256', 0x1a: 'keccak-224', @@ -39,6 +33,10 @@ module.exports = Object.freeze({ 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', @@ -361,41 +359,46 @@ module.exports = Object.freeze({ 0xb3df: 'skein1024-1016', 0xb3e0: 'skein1024-1024', - // multiaddrs, + // multiaddr 0x04: 'ip4', - 0x29: 'ip6', - 0x2a: 'ip6zone', 0x06: 'tcp', - 0x0111: 'udp', 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', - 0x01e0: 'http', 0x01bb: 'https', - 0x01cc: 'quic', - 0x01dd: 'ws', - 0x01de: 'wss', 0x01bc: 'onion', 0x01bd: 'onion3', 0x01be: 'garlic64', - 0x0122: 'p2p-circuit', - 0x35: 'dns', - 0x36: 'dns4', - 0x37: 'dns6', - 0x38: 'dnsaddr', + 0x01cc: 'quic', + 0x01dd: 'ws', + 0x01de: 'wss', 0x01df: 'p2p-websocket-star', - 0x0115: 'p2p-stardust', - 0x0113: 'p2p-webrtc-star', - 0x0114: 'p2p-webrtc-direct', - 0x0190: 'unix', + 0x01e0: 'http', - // IPLD formats, + // ipld + 0x55: 'raw', 0x70: 'dag-pb', 0x71: 'dag-cbor', - 0x0129: 'dag-json', 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', @@ -415,15 +418,24 @@ module.exports = Object.freeze({ 0xe1: 'decred-tx', 0xf0: 'dash-block', 0xf1: 'dash-tx', - 0x81: 'leofcoin-block', - 0x82: 'leofcoin-tx', - 0x83: 'leofcoin-pr', - 0x7b: 'torrent-info', - 0x7c: 'torrent-file', - 0xed: 'ed25519-pub', + 0xfa: 'swarm-manifest', + 0xfb: 'swarm-feed', + 0x0129: 'dag-json', - // Content Namespaces, + // namespace + 0x2f: 'path', 0xe2: 'ipld-ns', 0xe3: 'ipfs-ns', - 0xe4: 'swarm-ns' + 0xe4: 'swarm-ns', + + // 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' }) diff --git a/tools/update-table.py b/tools/update-table.py index 8f4dd8a..9b7f597 100755 --- a/tools/update-table.py +++ b/tools/update-table.py @@ -3,6 +3,7 @@ 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 @@ -16,6 +17,7 @@ 'use strict' ''' + def padded_hex(hexstring): """Creates a padded (starting with a 0 if odd) hex string""" number = int(row['code'], 16) @@ -26,6 +28,7 @@ def padded_hex(hexstring): prefix = '0x' return prefix + hexbytes + def unique_code(codecs): """Returns a list where every code exists only one. @@ -42,24 +45,34 @@ def unique_code(codecs): unique.append(codec) return unique -parsed = [] + +# 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: - # Skip over headlines and not yet defined codes - if row['code'] and row['code'] != '0x': - code = padded_hex(row['code']) - name_const = row['codec'].upper().replace('-', '_') - name_human = row['codec'] - parsed.append({ - 'const': name_const, - 'human': name_human, - 'code': code, - }) - # add headlines - if row['codec'] and not row['description'] and not row['code']: - parsed.append({ - 'headline': row['codec'] - }) + 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) @@ -67,11 +80,9 @@ def unique_code(codecs): print_file = os.path.join(output_dir, 'base-table.js') with open(print_file, 'w') as ff: ff.write(HEADER) - for index, codec in enumerate(parsed): - if 'headline' in codec: - ff.write("\n// {headline}\n".format(**codec)) - else: - # print('{} {} {:02x}'.format(codec['human'], codec['code'], codec['code'])) + 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)) @@ -80,25 +91,25 @@ def unique_code(codecs): with open(constants_file, 'w') as ff: ff.write(HEADER) ff.write('module.exports = Object.freeze({\n') - for index, codec in enumerate(parsed): - if index: - ff.write(',\n') - if 'headline' in codec: - ff.write("\n // {headline}".format(**codec)) - else: + 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') - unique = unique_code(parsed) - for index, codec in enumerate(unique): - if index: - ff.write(',\n') - if 'headline' in codec: - ff.write("\n // {headline}".format(**codec)) - else: + 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')