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

@shriyanss/cs-mast

v0.1.4

Published

Context-Stratified Merkelized Abstract Syntax Tree — reference TypeScript implementation

Readme

CS-MAST

Context-Stratified Merkelized Abstract Syntax Tree — reference TypeScript implementation.

CS-MAST extends an AST with Merkle-style cryptographic signatures (CS-MAST-S) on every node, enabling constant-time fingerprint lookup and deterministic subtree matching in SAST scanners. See the specification paper for the full algorithm description.


Install

npm install @shriyanss/cs-mast

Quick Start

import { cs_mast_init, cs_mast_s_exists } from "@shriyanss/cs-mast";

const tree = cs_mast_init(`const greet = (name) => "hello " + name;`, {
    hash: "sha256",
    lang: "js",
    lver: "es2022",
    prsr: "@babel/parser",
    scat: ["lit", "val", "id", "name", "decl"],
    sinc: [],
});

console.log(tree.rootSignature);
// $v=1$hash=sha256,lang=js,lver=es2022,prsr=-babel/parser,scat=lit_val_id_name_decl$<hex>

console.log(cs_mast_s_exists(tree, tree.rootSignature)); // true
console.log(cs_mast_s_exists(tree, "$v=1$...$fake")); // false

API

cs_mast_init(source, config, adapter?)

Parses source, traverses post-order, attaches cs-mast-s-hash to every actively-hashed Babel node, and builds the O(1) signature hashmap.

interface CsMastTree {
    root: AdapterNode; // File node — every descendant has computedHash set
    rootHash: string; // 64-char hex of the File node
    rootSignature: string; // full PHC signature of root (empty if root not actively hashed)
    config: CsMastConfig;
    adapter: IParserAdapter;
    readonly _signatureMap: ReadonlyMap<string, string>; // full-sig → pathKey
}

cs_mast_s_exists(tree, signature)

O(1) boolean lookup backed by the hashmap built during init. Accepts the full PHC signature string.

cs_mast_init_codebase(files, config, adapter?)

Process multiple files with the same config, derive a codebase-level hash:

const result = cs_mast_init_codebase(
    [
        { filename: "a.js", source: "..." },
        { filename: "b.js", source: "..." },
    ],
    config
);
result.codebaseHash; // sha256(sorted([h1,h2,...]).join('')) — order-independent
result.codebaseSignature; // full PHC string with codebaseHash

parseSignature(sig) / buildSignature(parts)

Encode and decode CS-MAST-S PHC strings. parseSignature returns null for invalid input.


Config (CsMastConfig)

| Field | Required | Description | | ------ | -------- | ---------------------------------------------------------------------- | | hash | yes | Hash algorithm. Only 'sha256' supported. | | lang | yes | Shortest file extension, e.g. 'js'. | | lver | no | Language version, e.g. 'es6', 'es2022'. | | prsr | yes | Parser name. Characters outside [a-zA-Z0-9/+.-] are replaced by -. | | scat | yes* | Active scat category codes (see Table I below). | | sinc | yes* | Exact Babel node type names to include verbatim. |

*At least one of scat or sinc must be non-empty.

scat Categories (Table I from spec)

| Code | Babel Node Types | Behaviour | | --------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ | | lit | StringLiteral, NumericLiteral, BooleanLiteral, RegExpLiteral, NullLiteral, BigIntLiteral | Hash literal type; add value if val also active | | id | Identifier, PrivateName, JSXIdentifier | Hash node type; add name if name also active | | op | Binary/Unary/Update/AssignmentExpression | Hash child hashes; add operator symbol if op_name active | | decl | VariableDeclaration, FunctionDeclaration, ClassDeclaration, ImportDeclaration | Include node type/kind in hash | | loop | For/While/DoWhile/ForIn/ForOfStatement | sha256(NodeType + sortedActiveChildHashes) | | cond | IfStatement, SwitchStatement, ConditionalExpression | Double-hash: sha256(sha256(NodeType)+sha256(Test?)+sha256(Consequent)) | | name | Modifier — adds .name to identifier hashes | — | | val | Modifier — adds .value to literal and conditional hashes | — | | op_name | Modifier — adds .operator to operator hashes | — |


CS-MAST-S Signature Format

$v=1$hash=sha256,lang=js,lver=es6,prsr=-babel/parser,scat=lit_val_id,sinc=IfStatement$<64hex>
  • No salt — salting would break the determinism required for subtree matching.
  • Multiple scat / sinc values joined by _.
  • Hash portion: always 64-char lowercase SHA-256 hex.

Mutation Guard

Calling any of the following on a CS-MAST tree node path throws MutationError: replaceWith, replaceWithMultiple, replaceWithSourceString, replaceInline, insertBefore, insertAfter, remove, pushContainer, unshiftContainer.

To modify source code, call cs_mast_init again on the updated source.


Extending to New Languages

Implement IParserAdapter from src/types/parser-adapter.ts. See src/adapters/README.md.


Spec Ambiguities

See CLAUDE.md sections A1–A11 for all documented assumptions where the spec leaves details unspecified (separator policy, unary operator handling, codebase hash construction, etc.).