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

@leachain/ctejs

v1.0.1

Published

JavaScript wrapper for the CTE WASM library providing encoding and decoding capabilities.

Downloads

10

Readme

A JavaScript library providing a high-level wrapper around a WebAssembly (WASM) implementation of the Compact Transaction Encoding (CTE) specification v1.0. This library allows easy encoding and decoding of CTE data streams in both Node.js and browser environments.

It uses a WASM module compiled from the CTE reference C code and provides a simplified API, hiding the complexities of direct WASM memory management.

For full details, please refer to the CTE v1.0 Specification. ## Features

  • Cross-Platform: Bundled builds provided for Node.js (ESM, CJS) and Browsers (ESM, IIFE).

Installation

npm install @leachain/ctejs

Usage

Encoding

Use the CteEncoder class to build your CTE transaction.

import { CteEncoder, PUBLIC_KEY_SIZE, SIGNATURE_SIZE } from '@leachain/ctejs';

async function encodeData() {
    try {
        // Create an encoder instance
        const encoder = await CteEncoder.create();

        // Prepare your data
        const pubKey1 = new Uint8Array(PUBLIC_KEY_SIZE).fill(0x11);
        const pubKey2 = new Uint8Array(PUBLIC_KEY_SIZE).fill(0x22);
        const signature1 = new Uint8Array(SIGNATURE_SIZE).fill(0xAA);
        const commandPayload = "Hello from JS via WASM!"; // String or Uint8Array

        // Add fields in the desired order
        encoder.addPublicKeyList([pubKey1, pubKey2]);
        encoder.addSignatureList([signature1]);
        encoder.addIndexReference(5);
        encoder.addCommandData(commandPayload);

        // Finalize and get the encoded buffer
        const encodedBuffer = encoder.getEncodedBuffer();
        console.log('Encoded CTE Buffer:', encodedBuffer);
        // WASM VM will be garbage collected.

        return encodedBuffer;

    } catch (error) {
        console.error("Encoding Error:", error);
    }
}

encodeData();

Decoding

Use the CteDecoder class to read fields sequentially from an encoded buffer.

import { CteDecoder } from '@leachain/ctejs';

async function decodeData(encodedBuffer) {
    try {
        // Create a decoder instance
        const decoder = await CteDecoder.create(encodedBuffer);

        // Iterate through fields
        let field;
        while ((field = decoder.nextField()) !== null) {
            console.log("Decoded Field:", field);

            // Access specific data based on type
            switch(field.typeName) {
                case "PublicKeyList":
                    console.log(`  Got ${field.count} public keys.`);
                    // field.keys is an array of Uint8Array
                    break;
                case "SignatureList":
                    console.log(`  Got ${field.count} signatures.`);
                    // field.signatures is an array of Uint8Array
                    break;
                case "IndexReference":
                    console.log(`  Got index: ${field.value}`);
                    break;
                case "CommandData":
                    console.log(`  Got command data (${field.length} bytes).`);
                    console.log(`  Command Text: "${field.text}"`); // UTF-8 string (if possible)
                    console.log("  Command Data: ", field.data);    // Uint8Array
                    break;
                default:
                    console.log(`  Got unknown field type: ${field.type}`);
            }
        }
    } catch (error) {
        console.error("Decoding Error:", error);
    }
}

// Example assuming encodeData() returns the buffer
encodeData().then(buffer => decodeData(buffer));

Building from Source

  1. Install development dependencies: npm install
  2. Run the build command: npm run build

This will generate the different distributable files in the dist/ directory.

Underlying Mechanism

This library wraps a WebAssembly module compiled from C reference code implementing the CTE specification. For security and state isolation, each CteEncoder or CteDecoder object instantiates its own independent WASM virtual machine. This VM is discarded when the corresponding JavaScript object is garbage collected.

About

This project is part of the LEA Project.

Author

Developed by Allwin Ketnawang.

License

This project is licensed under the MIT License.