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

feat: initial implementation #1

Merged
merged 6 commits into from
Mar 10, 2023
Merged

Conversation

vasco-santos
Copy link
Contributor

@vasco-santos vasco-santos commented Mar 10, 2023

Adds initial implementation to validate @ipld/car blocks for the supported formats by web3.storage. It verifies if block is encoded with one of the hashers supported, as well as if bytes are not bad for the hash

@vasco-santos vasco-santos force-pushed the feat/initial-implementation branch from 4326122 to 7fec9d1 Compare March 10, 2023 11:23
@vasco-santos vasco-santos force-pushed the feat/initial-implementation branch from 7fec9d1 to 7675777 Compare March 10, 2023 11:24
src/index.js Outdated
Comment on lines 45 to 54
function getHasher (multihashCode) {
switch (multihashCode) {
case sha256.code:
return sha256
case sha512.code:
return sha512
case murmur3128.code:
return murmur3128
case murmur332.code:
return murmur332

Choose a reason for hiding this comment

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

it's really hard to spot if we get one of these wrong... I kinda love this style, where you convert a list of things to the map init format:

const hashMap = new Map([sha256, sha512, murmer3128, ...].map(hash => [hash.code, hash]))

e.g https://github.com/web3-storage/linkdex/pull/12/files#diff-c73abcf5e120d37e1deaae000d2b9fa15409ea2829918774125681f66cf76c2dR14

src/index.js Outdated
Comment on lines 32 to 35
console.log('hasher', hasher, block.bytes)
const bytesHash = await hasher.digest(block.bytes)

console.log('has', bytesHash)

Choose a reason for hiding this comment

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

Suggested change
console.log('hasher', hasher, block.bytes)
const bytesHash = await hasher.digest(block.bytes)
console.log('has', bytesHash)
const bytesHash = await hasher.digest(block.bytes)

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@vasco-santos vasco-santos requested a review from olizilla March 10, 2023 11:59
src/index.js Outdated Show resolved Hide resolved
Copy link

@olizilla olizilla left a comment

Choose a reason for hiding this comment

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

minor, but we could re-use the wording from https://github.com/multiformats/js-multiformats/blob/master/src/block.js#L261

so the same error has the same string.

src/index.js Outdated Show resolved Hide resolved
@vasco-santos vasco-santos merged commit 6477d3f into main Mar 10, 2023
@vasco-santos vasco-santos deleted the feat/initial-implementation branch March 10, 2023 12:16
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