Skip to content

fix!: identity hash is Hasher<"identity", 0>#314

Closed
SgtPooki wants to merge 3 commits into
masterfrom
313-bug-identity-hash-doesnt-export-proper-type-of-hashername-code
Closed

fix!: identity hash is Hasher<"identity", 0>#314
SgtPooki wants to merge 3 commits into
masterfrom
313-bug-identity-hash-doesnt-export-proper-type-of-hashername-code

Conversation

@SgtPooki
Copy link
Copy Markdown

@SgtPooki SgtPooki commented Dec 2, 2024

Breaking change because return type no longer supports sync (aligns with other hashers)

Fixes #313

@SgtPooki SgtPooki linked an issue Dec 2, 2024 that may be closed by this pull request
@SgtPooki SgtPooki self-assigned this Dec 2, 2024
@SgtPooki
Copy link
Copy Markdown
Author

SgtPooki commented Feb 4, 2025

@achingbrain any qualms against this one?

Comment thread test/test-multihash.spec.ts
@SgtPooki SgtPooki requested a review from achingbrain February 5, 2025 13:03
Comment thread test/test-multihash.spec.ts Outdated
Co-authored-by: Alex Potsides <alex@achingbrain.net>
@achingbrain
Copy link
Copy Markdown
Member

achingbrain commented Jul 29, 2025

With hindsight identity should be a SyncMultihashHasher.

E.g.

// identity.ts
import type { SyncMultihashHasher } from './interface.js'

// ... other code

export const identity: SyncMultihashHasher<0x00> = { code, name, encode, digest }

One problem is that identity then does not have type overlap with other Hasher instances as MultihashHasher and SyncMultihashHasher don't expose an encode property so the above will fail to compile without removing the encode prop from the export.

One (breaking) solution would be remove the encode prop above and also change the return type of from to use the MultihashHasher interface instead of the Hasher concrete implementation.

Alternatively (non-breaking) we can add the encode sig to MultihashHasher and SyncMultihashHasher though it doesn't make much sense for it to be there.

Actually having .encode is useful for where you want to hash a value but not have it returned with a multihash prefix.

@achingbrain
Copy link
Copy Markdown
Member

Implementation of identity as SyncMultihashHasher<0> here: #337

achingbrain added a commit that referenced this pull request May 7, 2026
…to enable passing it where `MultihashHasher<Code>` instances are expected.

It was also necessary to update the returned type of `from` to be `MultihashHasher<Code>` instead of the concrete `Hasher` type which has extra properties that are not part of hashing.

Fixes #313
Supersedes #314

BREAKING CHANGE: all `Hasher`s are now `MultihashHasher<Code>`s
achingbrain added a commit that referenced this pull request May 7, 2026
Updates the type of the identity hash to `SyncMultihashHasher<0x00>` to enable passing it where `MultihashHasher<Code>` instances are expected.

It was also necessary to update the returned type of `from` to be `MultihashHasher<Code>` instead of the concrete `Hasher` type which has extra properties that are not part of hashing.

Fixes #313
Supersedes #314

BREAKING CHANGE: all `Hasher`s are now `MultihashHasher<Code>`s
achingbrain added a commit that referenced this pull request May 7, 2026
Updates the type of the identity hash to `SyncMultihashHasher<0x00>` to enable passing it where `MultihashHasher<Code>` instances are expected.

It was also necessary to update the returned type of `from` to be `MultihashHasher<Code>` instead of the concrete `Hasher` type which has extra properties that are not part of hashing.

Fixes #313
Supersedes #314

BREAKING CHANGE: all `Hasher`s are now `MultihashHasher<Code>`s
achingbrain added a commit that referenced this pull request May 7, 2026
Updates the type of the identity hash to `SyncMultihashHasher<0x00>` to enable passing it where `MultihashHasher<Code>` instances are expected.

It was also necessary to update the returned type of `from` to be `MultihashHasher<Code>` instead of the concrete `Hasher` type which has extra properties that are not part of hashing.

Fixes #313
Supersedes #314

BREAKING CHANGE: all `Hasher`s are now `MultihashHasher<Code>`s
achingbrain added a commit that referenced this pull request May 7, 2026
Updates the type of the identity hash to `SyncMultihashHasher<0x00>` to enable passing it where `MultihashHasher<Code>` instances are expected.

It was also necessary to update the returned type of `from` to be `MultihashHasher<Code>` instead of the concrete `Hasher` type which has extra properties that are not part of hashing.

Fixes #313
Supersedes #314

BREAKING CHANGE: all `Hasher`s are now `MultihashHasher<Code>`s
@achingbrain
Copy link
Copy Markdown
Member

Closing in favour of #337

@achingbrain achingbrain closed this May 7, 2026
github-actions Bot pushed a commit that referenced this pull request May 7, 2026
## [14.0.0](v13.4.2...v14.0.0) (2026-05-07)

### ⚠ BREAKING CHANGES

* all `Hasher`s are now `MultihashHasher<Code>`s
* Returned `Uint8Array`s are now `Uint8Array<ArrayBuffer>`

### Bug Fixes

* identity hash is SyncMultihashHasher<0> ([#337](#337)) ([9b5b12b](9b5b12b)), closes [#313](#313) [#314](#314)
* specify type of backing buffer when Uint8Arrays are returned ([#335](#335)) ([bac2da5](bac2da5))
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.

bug: identity hash doesn't export proper type of Hasher<Name, Code>

3 participants