# @dsnp/hash-util

> A library to verify hashes compatible with DSNP

Latest version **0.0.2** (published 2025-09-18) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @dsnp/hash-util
pnpm add @dsnp/hash-util
yarn add @dsnp/hash-util
bun add @dsnp/hash-util
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; has provenance.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2025-09-18 |
| First published | 2024-04-09 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 16.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Author | Project Liberty |
| Maintainers | wesbiggs, dsnp_admin |

## Links

- npm: https://www.npmjs.com/package/@dsnp/hash-util
- Repository: https://github.com/LibertyDSNP/dsnp-hash-util
- Homepage: https://github.com/LibertyDSNP/dsnp-hash-util#readme
- Issues: https://github.com/LibertyDSNP/dsnp-hash-util/issues
- npm.io page: https://npm.io/package/@dsnp/hash-util

## Dependencies (1)

- [hash-wasm](https://npm.io/package/hash-wasm.md) 4.12.0

## Recent versions

- 0.0.2 (latest) — 2025-09-18
- 0.0.1 — 2024-07-28
- 0.0.0 — 2024-04-09

## README

# Overview

This package is a TypeScript implementation of hash-related utilities to support [DSNP](https://dsnp.org/) applications and services.

## Background

DSNP anchors content to announcements via a URL and hashes.
This ensures integrity of resources and also provides for relocatable content, as hashes can be generated and verified regardless of location.

This library provides a simple implementation that checks whether a data "file" matches at least one of the hash values provided.

## Dependencies

This library uses [hash-wasm](https://github.com/Daninet/hash-wasm), which has fast WASM implementations of hash algorithms and should work in both server-side and browser environments.

# Usage

Given a `Uint8Array` and an array of strings representing DSNP hashes, use the following function to verify if there is a matching hash.

```
import { compareBinaryToMultibaseHashes } from "@dsnp/hash-util";

const result = await compareBinaryToMultibaseHashes(binaryU8A, hashes);
```

# Compatibility

The library will verify the following types of hashes:

- multihash values
  - `base32` multibase encoding (leading `'b'` character)
  - `sha2-256` or `blake3` hash (leading `0x12` or `0x1e` byte)
  - 256-bit hash length (`0x20` after hash indicator)

# Limitations

All comparisons are done in-memory, meaning that there is no attempt to limit the size of the byte array or memory requirements.
Callers should therefore perform their own sanity checks.

# Development

```
npm i
npm run build
npm run test
```

Please use the github issues area to report bugs or suggest enhancements.
Pull requests are gratefully welcomed.

---
_Source: https://npm.io/package/@dsnp/hash-util · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
