View on GitHub

Whiteflag JavaScript Library

Reference implementation of the Whiteflag protocol in TypeScript / JavaScript

WFJSL Utility Classes and Functions

WFJSL Documentation Home WFJSL TypeDoc Reference Whiteflag Specification

Overview

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 Whiteflag utility package. Please refer to the 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:

Public methods to manipulate a binary 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:

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.