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

@whiteflagprotocol/util

v1.0.0

Published

Whiteflag JS common utility and helper functions

Readme

WFJSL Utility Classes and Functions

Overview

The Whiteflag JavaScript Library (WFJSL) is an implementation of the Whiteflag Protocol written in TypeScript, and compiled to JavaScript, to support the development of Whiteflag-enabled applications in JavaScript.

The @whiteflagprotocol/util package provides common utilities for other Whiteflag packages. These utilities include common data conversions, generic helper functions, etc. for other Whiteflag packages. It should normally not be necessary to add this package as a dependency, but its functionality might be useful for other purposes.

This description provides a generic overview of the WFJSL utility package. Please see the WFJSL TypeDoc documentation for a detailed description of all classes and functions.

BinaryBuffer class

The binary module of the Whiteflag utility package provides the BinaryBuffer class. Objects of this class represent a binary encoded piece of data, e.g. a Whiteflag message, that can be manipulated at bit level.

Static methods to create a binary buffer:

  • BinaryBuffer.empty(): creates an empty binary buffer
  • BinaryBuffer.from(...): creates a binary buffer from another binary buffer
  • BinaryBuffer.fromBytes(...): creates a binary buffer from bytes in a number array
  • BinaryBuffer.fromHex(...): creates a binary buffer from a hexadecimal string
  • BinaryBuffer.fromU8a(...): creates a binary buffer from a Uint8Array

Public methods to manipulate a binary buffer:

  • BinaryBuffer.append(...): appends another binary buffer to the end of the binary buffer
  • BinaryBuffer.crop(...): shortens the binary buffer to the length of the specified bits
  • BinaryBuffer.extract(...): extracts the specified bits from the binary buffer
  • BinaryBuffer.insert(...): inserts another binary buffer at the start of the binary buffer
  • BinaryBuffer.shiftLeft(...): shifts bits in the buffer to the left, shrinking the buffer
  • BinaryBuffer.shiftRight(...): shifts bits in the buffer to the right, enlarging the buffer

Some of these functions have an equivalent that allow to use a different binary representation, e.g. appendHex(...) or insertU8a(...).

Data conversions

The encoding module provides generic functions to convert data from one encoding to another.

| Encoding | Description | Converts to | |-------------|---------------------------------------------------------------|-----------------------------------------| | Base64 | a string with a 64-character binary-to-text encoding | Base64url | | Base64url | a string with a URL-safe 64-character binary-to-text encoding | Base64, Hexadecimal, String, UInt8Array | | Hexadecimal | a string with a hexadecimal representation of a binary | Base64url, String, UInt8Array | | Object | a plain JavaScript object | Base64url | | Text | a string with UTF-8 characters | Base64url, Hexadecimal, UInt8Array | | UInt8Array | an array of bytes representing a binary encoding | Base64url, Hexadecimal, String |

For example hexToB64u(...) creates a base64url encoded string from a hexadecimal string. The module also provides some additional helper functions for different data encodings:

  • isObject(...) checks if something is an object
  • isString(...) checks if something is a string
  • isBase64(...) checks if a string is base64 encoded
  • isBase64u(...) checks if a string is base64url encoded
  • isHex(...) checks if a string is hexadecimal encoded
  • noHexPrefix(...) removes the '0x' hex prefix if present

JSON Web Signature (JWS)

Whiteflag uses JSON Web Signatures (JWS). To create, sign and convert JWSs the jws module provides a common Jws class to other Whiteflag packages.