-
Notifications
You must be signed in to change notification settings - Fork 54
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
Proposal: Update MultihashHasher interface so it could support multiple hashing algorithms #252
Comments
OK, I like the direction, the details are worth discussing though:
export interface MultihashHasher<Code extends number = number> {
digest: (input: Uint8Array) => Promise<MultihashDigest<Code>> | MultihashDigest<Code>
name: string
code: Code
}
export interface SyncMultihashHasher<Code extends number = number> extends MultihashHasher<Code> {
digest: (input: Uint8Array) => MultihashDigest<Code>
} Did you just leave off the
|
That was an accident, I didn’t mean to change return type
We can keep
Every time I try to hide distinction I find myself regretting it for one reason or the other. I think having two distinct when you care and third unified (type union) when you don’t is the best compromise.
We could impose
so you could decompose it into individual hashers. Also makes it possible to have |
Sure I’m fine with whatever names. Out of proposed ones I’d pick
P.S.: I would use Multi prefix if it was not overloaded in this context |
Yes, I just left out to reduce noise
I don’t think it would even though it would multiply number of types. |
Goal
As per ipld/js-car#123 we do need a solution for verifying hashes in CAR files without shipping all the
MultihashHasher
-s with the CAR library.Proposal
MultihashHasher
by introducing second OPTIONALcode
argument to thedigest
method.code
.MultihashHasher
interface toMultihashHasherCase
and repurpose it for single algorithm use cases.MultihashHasherVariant
interface with the samedigest
method and a method that returns map ofMultihashHasherCase
it's comprised of.MultihashHasher
as union type discriminated bycode
field.Here is the the sketch:
Note that above makes current
MultihashHasher
-s compatible with proposedMultihashHasher
type that is to say code that will require new type will accept all existing hashers without changes to them.js-car
library would be able to requireMultihashHasher
parameter in order to be able to verify digests.MultihashHasherVariant
would allow composing many hashers into one.The text was updated successfully, but these errors were encountered: