Settings

Theme

Show HN: Kokuin – A TypeScript library for deterministic JSON hashing

kokuin.vercel.app

2 points by smokeeaasd 2 days ago · 2 comments

Reader

rawling 2 days ago

  if (stack.has(obj)) {
    writer.writeByte(CIRCULAR)
    return
  }
Does this mean that if a nested object holds a reference to itself, it will produce the same hash as if it held a reference to any of the objects it is nested in?
  • smokeeaasdOP 2 days ago

    Yes.

    Any circular reference to an ancestor on the stack turns into the same CIRCULAR byte, so two structures with identical shape but whose cycle points to different ancestors in the nesting chain produce the same hash.

    This will be fixed in the next patch, which will encode the distance to the referenced ancestor instead of a flat marker, so self-reference and reference-to-parent will stop colliding. Note that every existing hash will change as a result, breaking any persisted hash (acceptable since this is pre-1.0). I could also bump the marker byte so new hashes can't accidentally collide with old ones, though the old ones remain broken either way.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection