# Module BSV::Storage::Utils <a id="module-BSV-Storage-Utils"></a>

Helpers for encoding and decoding UHRP (Unified Hash Resource Protocol) URLs.

A UHRP URL is a Base58Check string with a two-byte `xCEx00` prefix prepended
to the SHA-256 hash of the content. This makes each URL self-verifying and
stable across storage providers.

## URL normalisation

`normalize_url` strips the <code>uhrp:</code> scheme (case-insensitive) and
the optional <code>//</code> authority prefix, matching the TS SDK contract
exactly. The `web+uhrp://` variant used by some browser extension manifests is
**not** normalised here — that diverges from the TS reference (Python
normalises it; we follow TS).

## Constants
### `UHRP_PREFIX` <a id="constant-UHRP_PREFIX"></a> <a id="UHRP_PREFIX-constant"></a>
Two-byte UHRP version prefix: 0xCE 0x00.

## Public Class Methods
### `get_hash_from_url(url)` <a id="method-c-get_hash_from_url"></a> <a id="get_hash_from_url-class_method"></a>
Decode a UHRP URL and return the 32-byte binary SHA-256 hash.

Accepts URLs with or without the <code>uhrp:</code> scheme and optional
<code>//</code> authority.
- **@param** `url` [String] UHRP URL (with or without `uhrp:` prefix)
- **@raise** [ArgumentError] if the URL is not a String, empty, has a bad prefix, or has wrong length
- **@raise** [BSV::Primitives::Base58::ChecksumError] if the Base58Check checksum fails
- **@return** [String] 32-byte binary SHA-256 hash

### `get_url_for_file(data)` <a id="method-c-get_url_for_file"></a> <a id="get_url_for_file-class_method"></a>
Compute the SHA-256 hash of `data` and encode it as a UHRP URL.
- **@param** `data` [String] binary file content
- **@return** [String] Base58Check-encoded UHRP URL

### `get_url_for_hash(hash)` <a id="method-c-get_url_for_hash"></a> <a id="get_url_for_hash-class_method"></a>
Encode a 32-byte binary SHA-256 hash as a UHRP URL.
- **@param** `hash` [String] 32-byte binary string (SHA-256 hash)
- **@raise** [ArgumentError] if hash is not exactly 32 bytes
- **@return** [String] Base58Check-encoded UHRP URL

### `normalize_url(url)` <a id="method-c-normalize_url"></a> <a id="normalize_url-class_method"></a>
Strip the <code>uhrp:</code> scheme (case-insensitive) and optional
<code>//</code> from a URL.

Follows the TS SDK contract: only <code>uhrp:</code> and <code>uhrp://</code>
are normalised. `web+uhrp://` is deliberately not stripped (TS does not strip
it; Python does).
- **@param** `url` [String] URL to normalise
- **@return** [String] normalised URL

### `valid_url?(url)` <a id="method-c-valid_url-3F"></a> <a id="valid_url?-class_method"></a>
Return `true` if `url` is a syntactically valid UHRP URL.
- **@param** `url` [String] URL to validate
- **@return** [Boolean]
