Skip to content

Repository files navigation

@adiom/hash

Small zero-dependency hash package for Node.js, browsers, and Next.js.

Algorithm

The implementation keeps the original djb2 variant:

hash = 5381
for each UTF-8 byte c:
  hash = hash * 33 + c  (unsigned 64-bit, wraps at 2^64)

The final value is encoded as 12 little-endian base-36 characters using lowercase letters and digits (a-z0-9). The algorithm is deterministic and does not provide cryptographic security.

Install

pnpm add @adiom/hash

Publishing

Published to npm from GitHub Actions only, via npm trusted publishing (OIDC), so no npm token or OTP is ever needed.

  1. Go to the package page on npmjs.com → Publishing and accessTrusted publishing → add a publisher for repository adiom/hash and workflow file publish.yml.
  2. Tag a release and push it:
    git tag v0.1.0 && git push origin v0.1.0
    or trigger the Publish npm package workflow manually from the Actions tab.
  3. The workflow runs pnpm test + pnpm pack --dry-run, then npm publish --access public --provenance. npm exchanges the runner's OIDC token for a short-lived publish credential; signature key is the user's security key + 2FA income via the browser, and the publish itself is tokenless.

Usage

import { generateHash } from '@adiom/hash';

const token = generateHash('adiomtimur');
console.log(token); // yo3fp69ffox0

The same function works in a Next.js Server Component, Route Handler, Server Action, or Client Component. A Client Component still needs 'use client' for its React state, not for the hash function itself:

'use client';

import { useState } from 'react';
import { generateHash } from '@adiom/hash';

export function HashInput() {
  const [value, setValue] = useState('');

  return (
    <>
      <input value={value} onChange={(event) => setValue(event.target.value)} />
      <code>{generateHash(value)}</code>
    </>
  );
}

The package also exports customHash, toBytes, CHARS, BASE, and LENGTH. customHash returns the raw 64-bit bigint; use generateHash for the stable 12-character token.

Local Development

pnpm install
pnpm build
pnpm test
npm pack --dry-run

The C CLI remains available as an independent parity implementation:

make
./hash adiomtimur
# Input: adiomtimur
# Generated Hash: yo3fp69ffox0

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages