Skip to content

Fix SEA.keyid: missing sha1hash import and hashing an empty buffer - #1435

Merged
amark merged 1 commit into
amark:masterfrom
mikeua:fix-sea-keyid
Nov 18, 2026
Merged

amark merged 1 commit into
amark:masterfrom
mikeua:fix-sea-keyid

Conversation

@mikeua

@mikeua mikeua commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

SEA.keyid() (PGPv4-style KeyID from a public key) is broken in two ways:

  1. sha1hash is never imported in the module that defines SEA.keyid (sea.js bundle and sea/sea.js), so every call throws ReferenceError: sha1hash is not defined.
  2. The SHA-1 module hashes an empty buffer. ossl.digest({name: 'SHA-1'}, new ArrayBuffer(b)): passing a Buffer to the ArrayBuffer constructor coerces it to a length of 0, so the digest is always da39a3ee… (SHA-1 of empty input) and every key would get the same KeyID.

Fix: add var sha1hash = USE('./sha1') (and require('./sha1') in the unbuilt source) next to the other imports, and pass the Buffer to digest() directly, since a Buffer is already a valid BufferSource.

Checked in Node with WebCrypto: before, new ArrayBuffer(buf).byteLength === 0 and two different inputs give the same hash. After, two different public keys give different 16-hex-char KeyIDs.

- sea.js / sea/sea.js: SEA.keyid() calls sha1hash(), but it was never
  imported in that module, so every call throws
  'ReferenceError: sha1hash is not defined'.
- sha1 module: 'new ArrayBuffer(b)' with a Buffer argument creates an
  empty 0-byte ArrayBuffer, so the SHA-1 was always the hash of empty
  input (da39a3ee...) and every key would get the same KeyID. Pass the
  Buffer to digest() directly.
@amark

amark commented Nov 18, 2026

Copy link
Copy Markdown
Owner

embarrassing ! @mikeua thanks.

@amark
amark merged commit 52d183d into amark:master Nov 18, 2026
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