Skip to content
Astrohacker

← Projects

Archived project · Cryptography

WebBuf

Binary buffers and cryptography for TypeScript.

WebBuf gave TypeScript programs a common way to handle bytes and run cryptographic operations backed by Rust and WebAssembly. The libraries were used in the EarthBucks software.

Astrohacker published WebBuf to npm and maintained a site for the library.

How it works

  • Keep the selected bytes intact

    WebBuf exposed byte-oriented operations to TypeScript while its cryptographic packages could call Rust compiled to WebAssembly. A view onto part of a larger buffer had to preserve its offset and length when crossing that boundary.

  • Compare hash implementations

    The archived tests compared SHA-256 and double SHA-256 results with Node’s crypto implementation. They also checked that computing a digest did not change the input, and that wiping an input did not destroy a previously returned digest.

Hash the middle of a buffer

Take the buffer containing _abc_ and pass its three middle bytes to the hash function. Hashing the whole backing allocation would produce a different result. A cross-language fixture like this lets an agent verify an optimization against an independent implementation.

const input = WebBuf.fromUtf8("_abc_").subarray(1, 4);
const digest = sha256Hash(input);

Project history

  1. The public source published the 4.0.1 release commit. WebBuf 4.0.1 source

  2. The September portfolio confirmed 4.0.1 was published. Portfolio update