Proposal: Update MultihashHasher interface so it could support multiple hashing algorithms

Aperta
#252 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
typescript

Direzione di ricerca

Inizia individuando l’interfaccia MultihashHasher e i suoi utilizzi nel codice sorgente TypeScript, quindi esamina l’issue js-car collegata per il requisito di verifica. Confronta i test e i controlli dei tipi esistenti prima di definire il comportamento di compatibilità e composizione descritto qui. Il lavoro è completato quando le interfacce proposte e il union type sono implementati senza rompere gli hashers esistenti, con una copertura per i casi d’uso con un singolo algoritmo e con più algoritmi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Goal

As per https://github.com/ipld/js-car/issues/123 we do need a solution for verifying hashes in CAR files without shipping all the MultihashHasher-s with the CAR library.

Proposal

  1. Introduce backwards compatible change to the MultihashHasher by introducing second OPTIONAL code argument to the digest method.
    • If omitted it would default to own code.
    • If different code is passed it would error.
  2. Rename MultihashHasher interface to MultihashHasherCase and repurpose it for single algorithm use cases.
  3. Introduce multi algorithm MultihashHasherVariant interface with the same digest method and a method that returns map of MultihashHasherCase it's comprised of.
  4. Define MultihashHasher as union type discriminated by code field.

Here is the the sketch:

interface MultihashHasherCase<Code extends number = number> {
    code: Code
    digest(bytes: Uint8Array, code?: Code): Digest<Code>
}

interface MultihashHasherVariant<Code extends number = number> {
    // We define `code` as optional which can never have a value. This will allow
    // us to `code` as a discriminant in the union
    code?: never

    cases(): Record<Code, MultihashHasherCase<Code>>

    digest <CodeCase extends Code> (bytes: Uint8Array, code?: CodeCase): Digest<CodeCase>
    
    or <Case extends number> (hasher: MultihashHasher<Case>): MultihashHasherVariant<Code|Case>
}

type MultihashHasher<Code extends number = number> =
    | MultihashHasherCase<Code>
    | MultihashHasherVariant<Code>

Note that above makes current MultihashHasher-s compatible with proposed MultihashHasher type that is to say code that will require new type will accept all existing hashers without changes to them.

  • With such a type in place js-car library would be able to require MultihashHasher parameter in order to be able to verify digests.
  • Added MultihashHasherVariant would allow composing many hashers into one.
Lingua principale
TypeScript
Stelle
269
Fork
58
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di multiformats/js-multiformats

Tutte le issue di multiformats/js-multiformats

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.