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: define sync multihash hasher interface #160

Merged
merged 3 commits into from
Jan 19, 2022
Merged

Conversation

Gozala
Copy link
Contributor

@Gozala Gozala commented Jan 19, 2022

This implements proposal #159

@@ -28,13 +28,21 @@
"skipLibCheck": true,
"stripInternal": true,
"resolveJsonModule": true,
"noEmit": true
"noEmit": true,
"paths": {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

😭 I am having a really bad day with TS today 😖 I thought #157 took care of this, but as it turns out node_modules/multiformats takes precedence without this

code: 0x0,
encode: (input) => coerce(input)
})
/** @type {import('./interface').SyncMultihashHasher<typeof code>} */
Copy link
Member

Choose a reason for hiding this comment

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

How much does this matter here? Is it just for internal consistency within this file? Is it showing up in the exported types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should have added a code comment, this is mostly to ensure that module will end up compatible with desired interface as there is no way to say module @implements {SyncMultihashHasher<typeof code>}

Copy link
Member

@rvagg rvagg left a comment

Choose a reason for hiding this comment

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

👍

My only hesitance is that we could give a similar treatment to sha2.js; although not sha2-browser.js. By passing the hashers in sha2.js through from() we get an async digest() function involved even though the crypto calls are sync. While I'd be fine exporting those hashers as the original MultihashHasher type, it'd be nice if the user could feature-detect the output of digest to see if it's a Promise or not and act accordingly. When you're in the browser you'll have to await but when on Node.js you shouldn't need to, which would be really nice.

@Gozala Gozala requested a review from rvagg January 19, 2022 09:38
@Gozala Gozala merged commit c3a650c into master Jan 19, 2022
@Gozala Gozala deleted the feat/sync-multihasher branch January 19, 2022 18:14
github-actions bot pushed a commit that referenced this pull request Jan 19, 2022
## [9.6.0](v9.5.9...v9.6.0) (2022-01-19)

### Features

* add sync multihash hasher ([#160](#160)) ([c3a650c](c3a650c))
@github-actions
Copy link

🎉 This PR is included in version 9.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Gozala added a commit that referenced this pull request Jan 20, 2022
Fix API unintentional API change introduced by #160 which removed `encode` method.
rvagg pushed a commit that referenced this pull request Jan 20, 2022
Fix API unintentional API change introduced by #160 which removed `encode` method.
github-actions bot pushed a commit that referenced this pull request Jan 20, 2022
### [9.6.2](v9.6.1...v9.6.2) (2022-01-20)

### Bug Fixes

* add encode to identity ([2724f8a](2724f8a)), closes [#160](#160)
* coverage by using encode ([132d829](132d829))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants