Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
I believe all of these should work from https://github.com/multiformats/multicodec/blob/master/table.csv
name tag code description
identity multihash 0x00 raw binary
cidv1 ipld 0x01 CIDv1
cidv2 ipld 0x02 CIDv2
cidv3 ipld 0x03 CIDv3
ip4 multiaddr 0x04
tcp multiaddr 0x06
sha1 multihash 0x11
sha2-256 multihash 0x12
sha2-512 multihash 0x13
sha3-512 multihash 0x14
sha3-384 multihash 0x15
sha3-256 multihash 0x16
sha3-224 multihash 0x17
shake-128 multihash 0x18
shake-256 multihash 0x19
keccak-224 multihash 0x1a keccak has variable output length. The number specifies the core length
keccak-256 multihash 0x1b
keccak-384 multihash 0x1c
keccak-512 multihash 0x1d
blake3 multihash 0x1e BLAKE3 has a default 32 byte output length. The maximum length is (2^64)-1 bytes.
dccp multiaddr 0x21
murmur3-128 multihash 0x22
murmur3-32 multihash 0x23
ip6 multiaddr 0x29
ip6zone multiaddr 0x2a
path namespace 0x2f Namespace for string paths. Corresponds to `/` in ASCII.
multicodec multiformat 0x30
multihash multiformat 0x31
multiaddr multiformat 0x32
multibase multiformat 0x33
dns multiaddr 0x35
dns4 multiaddr 0x36
dns6 multiaddr 0x37
dnsaddr multiaddr 0x38
protobuf serialization 0x50 Protocol Buffers
cbor serialization 0x51 CBOR
raw ipld 0x55 raw binary
dbl-sha2-256 multihash 0x56
rlp serialization 0x60 recursive length prefix
bencode serialization 0x63 bencode
dag-pb ipld 0x70 MerkleDAG protobuf
dag-cbor ipld 0x71 MerkleDAG cbor
libp2p-key ipld 0x72 Libp2p Public Key
git-raw ipld 0x78 Raw Git object
torrent-info ipld 0x7b Torrent file info field (bencoded)
torrent-file ipld 0x7c Torrent file (bencoded)
However, once I get further down the https://github.com/multiformats/multicodec/blob/master/table.csv file
eofcoin-block ipld 0x81 Leofcoin Block
leofcoin-tx ipld 0x82 Leofcoin Transaction
leofcoin-pr ipld 0x83 Leofcoin Peer Reputation
sctp multiaddr 0x84
dag-jose ipld 0x85 MerkleDAG JOSE
dag-cose ipld 0x86 MerkleDAG COSE
....
I have a problem
const multicodec = require('../src')
const { nameToCode } = require('../src/maps')
const toString = require('uint8arrays/to-string')
const fromString = require('uint8arrays/from-string')
const publicKey = '7f235830dd3defa722ef1aa249d6a0ddbba4f990b0817538933f573640653542856da88d335f1fb25b8bcfbe089528dce09b1f7cb99fdd60f88300f4c2cc6d35'
const publicKeyByte = fromString(publicKey, 'base16')
const publickKeyBytewPrefix = multicodec.addPrefix('eth-tx', publicKeyByte)
console.info(toString(Uint8Array.from(publickKeyBytewPrefix), 'base16'))
yeilds:
93017f235830dd3defa722ef1aa249d6a0ddbba4f990b0817538933f573640653542856da88d335f1fb25b8bcfbe089528dce09b1f7cb99fdd60f88300f4c2cc6d35
I was hoping it would be:
937f235830dd3defa722ef1aa249d6a0ddbba4f990b0817538933f573640653542856da88d335f1fb25b8bcfbe089528dce09b1f7cb99fdd60f88300f4c2cc6d35
@bshambaugh

This comment has been minimized.

Copy link
Owner Author

@bshambaugh bshambaugh commented Feb 24, 2021

code:

const multicodec = require('../src')
//const uint8ArrayFromString = require('uint8arrays/from-string')
const { nameToCode } = require('../src/maps')

/**
const multicodec = require('multicodec')
const multibase = require('multibase')
*/
const toString = require('uint8arrays/to-string')
const fromString = require('uint8arrays/from-string')

const publicKey = '7f235830dd3defa722ef1aa249d6a0ddbba4f990b0817538933f573640653542856da88d335f1fb25b8bcfbe089528dce09b1f7cb99fdd60f88300f4c2cc6d35'
console.log('the public key is'+publicKey)
const publicKeyByte = fromString(publicKey, 'base16')

console.log(publicKeyByte)

// console.log(multicodec)

const publickKeyBytewPrefix = multicodec.addPrefix('eth-tx', publicKeyByte)
console.log(publickKeyBytewPrefix)

console.info(toString(Uint8Array.from(publickKeyBytewPrefix), 'base16'))

const noPrefixpublickKeyBytewPrefix = multicodec.rmPrefix(publickKeyBytewPrefix)
console.info(toString(Uint8Array.from(noPrefixpublickKeyBytewPrefix), 'base16'))

output:

the public key is7f235830dd3defa722ef1aa249d6a0ddbba4f990b0817538933f573640653542856da88d335f1fb25b8bcfbe089528dce09b1f7cb99fdd60f88300f4c2cc6d35
Uint8Array(64) [
127, 35, 88, 48, 221, 61, 239, 167, 34, 239, 26,
162, 73, 214, 160, 221, 187, 164, 249, 144, 176, 129,
117, 56, 147, 63, 87, 54, 64, 101, 53, 66, 133,
109, 168, 141, 51, 95, 31, 178, 91, 139, 207, 190,
8, 149, 40, 220, 224, 155, 31, 124, 185, 159, 221,
96, 248, 131, 0, 244, 194, 204, 109, 53
]
Uint8Array(66) [
147, 1, 127, 35, 88, 48, 221, 61, 239, 167, 34,
239, 26, 162, 73, 214, 160, 221, 187, 164, 249, 144,
176, 129, 117, 56, 147, 63, 87, 54, 64, 101, 53,
66, 133, 109, 168, 141, 51, 95, 31, 178, 91, 139,
207, 190, 8, 149, 40, 220, 224, 155, 31, 124, 185,
159, 221, 96, 248, 131, 0, 244, 194, 204, 109, 53
]
93017f235830dd3defa722ef1aa249d6a0ddbba4f990b0817538933f573640653542856da88d335f1fb25b8bcfbe089528dce09b1f7cb99fdd60f88300f4c2cc6d35
7f235830dd3defa722ef1aa249d6a0ddbba4f990b0817538933f573640653542856da88d335f1fb25b8bcfbe089528dce09b1f7cb99fdd60f88300f4c2cc6d35

@bshambaugh

This comment has been minimized.

Copy link
Owner Author

@bshambaugh bshambaugh commented Feb 24, 2021

The hex looks a bit different due to varint:

const multicodec = require('../src')
//const uint8ArrayFromString = require('uint8arrays/from-string')
const { nameToCode } = require('../src/maps')

/**
const multicodec = require('multicodec')
const multibase = require('multibase')
*/
const toString = require('uint8arrays/to-string')
const fromString = require('uint8arrays/from-string')

const publicKey = '7f235830dd3defa722ef1aa249d6a0ddbba4f990b0817538933f573640653542856da88d335f1fb25b8bcfbe089528dce09b1f7cb99fdd60f88300f4c2cc6d35'
console.log('the public key is'+publicKey)
const publicKeyByte = fromString(publicKey, 'base16')

console.log(publicKeyByte)

// console.log(multicodec)

const publickKeyBytewPrefix = multicodec.addPrefix('p256-pub', publicKeyByte)
console.log(publickKeyBytewPrefix)

console.info(toString(Uint8Array.from(publickKeyBytewPrefix), 'base16'))

const noPrefixpublickKeyBytewPrefix = multicodec.rmPrefix(publickKeyBytewPrefix)
console.info(toString(Uint8Array.from(noPrefixpublickKeyBytewPrefix), 'base16'))

console.log('getCodeFromName :'+multicodec.getCodeFromName('p256-pub'))

const varint = multicodec.getVarintFromCode(4608)

console.log(varint)

console.log(toString(varint,'base16'))

//console.log(multicodec.util.varintEncode(300))

console.log(multicodec.getNameFromData(fromString('80247f235830dd3defa722ef1aa249d6a0ddbba4f990b0817538933f573640653542856da88d335f1fb25b8bcfbe089528dce09b1f7cb99fdd60f88300f4c2cc6d35','base16')))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment