Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ensure b58 can decode hash #103

Merged
merged 3 commits into from
Nov 11, 2019
Merged

fix: ensure b58 can decode hash #103

merged 3 commits into from
Nov 11, 2019

Conversation

jacobheun
Copy link
Contributor

While working on the libp2p refactor tests I found an issue with #102, where if a base32 id contains non b58 characters (such as "l"), b58 would throw due to the unsupported character. This fixes that by getting the b58 string from the CID before decoding to a Buffer.

@jacobheun jacobheun requested a review from lidel November 11, 2019 13:57
Copy link
Member

@lidel lidel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, potential performance improvement below

src/convert.js Outdated
@@ -125,7 +126,7 @@ function buf2str (buf) {

function mh2buf (hash) {
// the address is a varint prefixed multihash string representation
const mh = Buffer.from(bs58.decode(hash))
const mh = bs58.decode((new CID(hash)).toString('base58btc'))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could remove 1 level of string serialization and use buffer already present in CID?

Suggested change
const mh = bs58.decode((new CID(hash)).toString('base58btc'))
const mh = new CID(hash).multihash

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 that's much better, and also resolves a toString() issue I was seeing (and added a test for)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants