{"id":51151565,"url":"https://github.com/shriyanss/cs-mast","last_synced_at":"2026-06-26T07:00:32.822Z","repository":{"id":364228316,"uuid":"1266999170","full_name":"shriyanss/cs-mast","owner":"shriyanss","description":"Context-Stratified Merkelized Abstract Syntax Tree","archived":false,"fork":false,"pushed_at":"2026-06-25T09:35:58.000Z","size":1596,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-25T11:06:58.431Z","etag":null,"topics":["ast","data-type","digital-signature-algorithm"],"latest_commit_sha":null,"homepage":"https://cs-mast.ss0x00.com","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shriyanss.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-06-12T06:14:55.000Z","updated_at":"2026-06-25T09:30:38.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/shriyanss/cs-mast","commit_stats":null,"previous_names":["shriyanss/cs-mast"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/shriyanss/cs-mast","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shriyanss%2Fcs-mast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shriyanss%2Fcs-mast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shriyanss%2Fcs-mast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shriyanss%2Fcs-mast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shriyanss","download_url":"https://codeload.github.com/shriyanss/cs-mast/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shriyanss%2Fcs-mast/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34806448,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-26T02:00:06.560Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ast","data-type","digital-signature-algorithm"],"created_at":"2026-06-26T07:00:20.461Z","updated_at":"2026-06-26T07:00:32.811Z","avatar_url":"https://github.com/shriyanss.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CS-MAST\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"docs/static/img/cs-mast-logo-plain-bg.png\" alt=\"CS-MAST Logo\" width=\"200\" /\u003e\n\u003c/p\u003e\n\n**Context-Stratified Merkelized Abstract Syntax Tree** — reference TypeScript implementation.\n\nCS-MAST extends an AST with Merkle-style cryptographic signatures (CS-MAST-S) on every node,\nenabling constant-time fingerprint lookup and deterministic subtree matching in SAST scanners.\nSee the specification paper for the full algorithm description.\n\n---\n\n## Install\n\n```bash\nnpm install @shriyanss/cs-mast\n```\n\n---\n\n## Quick Start\n\n```typescript\nimport { cs_mast_init, cs_mast_s_exists } from \"@shriyanss/cs-mast\";\n\nconst tree = cs_mast_init(`const greet = (name) =\u003e \"hello \" + name;`, {\n    hash: \"sha256\",\n    lang: \"js\",\n    lver: \"es2022\",\n    prsr: \"@babel/parser\",\n    scat: [\"lit\", \"val\", \"id\", \"name\", \"decl\"],\n    sinc: [],\n});\n\nconsole.log(tree.rootSignature);\n// $v=1$hash=sha256,lang=js,lver=es2022,prsr=-babel/parser,scat=lit_val_id_name_decl$\u003chex\u003e\n\nconsole.log(cs_mast_s_exists(tree, tree.rootSignature)); // true\nconsole.log(cs_mast_s_exists(tree, \"$v=1$...$fake\")); // false\n```\n\n---\n\n## API\n\n### `cs_mast_init(source, config, adapter?)`\n\nParses `source`, traverses post-order, attaches `cs-mast-s-hash` to every actively-hashed\nBabel node, and builds the O(1) signature hashmap.\n\n```typescript\ninterface CsMastTree {\n    root: AdapterNode; // File node — every descendant has computedHash set\n    rootHash: string; // 64-char hex of the File node\n    rootSignature: string; // full PHC signature of root (empty if root not actively hashed)\n    config: CsMastConfig;\n    adapter: IParserAdapter;\n    readonly _signatureMap: ReadonlyMap\u003cstring, string\u003e; // full-sig → pathKey\n}\n```\n\n### `cs_mast_s_exists(tree, signature)`\n\nO(1) boolean lookup backed by the hashmap built during init. Accepts the full PHC signature string.\n\n### `cs_mast_init_codebase(files, config, adapter?)`\n\nProcess multiple files with the same config, derive a codebase-level hash:\n\n```typescript\nconst result = cs_mast_init_codebase(\n    [\n        { filename: \"a.js\", source: \"...\" },\n        { filename: \"b.js\", source: \"...\" },\n    ],\n    config\n);\nresult.codebaseHash; // sha256(sorted([h1,h2,...]).join('')) — order-independent\nresult.codebaseSignature; // full PHC string with codebaseHash\n```\n\n### `parseSignature(sig)` / `buildSignature(parts)`\n\nEncode and decode CS-MAST-S PHC strings. `parseSignature` returns `null` for invalid input.\n\n---\n\n## Config (`CsMastConfig`)\n\n| Field  | Required | Description                                                            |\n| ------ | -------- | ---------------------------------------------------------------------- |\n| `hash` | yes      | Hash algorithm. Only `'sha256'` supported.                             |\n| `lang` | yes      | Shortest file extension, e.g. `'js'`.                                  |\n| `lver` | no       | Language version, e.g. `'es6'`, `'es2022'`.                            |\n| `prsr` | yes      | Parser name. Characters outside `[a-zA-Z0-9/+.-]` are replaced by `-`. |\n| `scat` | yes\\*    | Active scat category codes (see Table I below).                        |\n| `sinc` | yes\\*    | Exact Babel node type names to include verbatim.                       |\n\n\\*At least one of `scat` or `sinc` must be non-empty.\n\n### `scat` Categories (Table I from spec)\n\n| Code      | Babel Node Types                                                                         | Behaviour                                                                |\n| --------- | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |\n| `lit`     | StringLiteral, NumericLiteral, BooleanLiteral, RegExpLiteral, NullLiteral, BigIntLiteral | Hash literal type; add value if `val` also active                        |\n| `id`      | Identifier, PrivateName, JSXIdentifier                                                   | Hash node type; add name if `name` also active                           |\n| `op`      | Binary/Unary/Update/AssignmentExpression                                                 | Hash child hashes; add operator symbol if `op_name` active               |\n| `decl`    | VariableDeclaration, FunctionDeclaration, ClassDeclaration, ImportDeclaration            | Include node type/kind in hash                                           |\n| `loop`    | For/While/DoWhile/ForIn/ForOfStatement                                                   | `sha256(NodeType + sortedActiveChildHashes)`                             |\n| `cond`    | IfStatement, SwitchStatement, ConditionalExpression                                      | Double-hash: `sha256(sha256(NodeType)+sha256(Test?)+sha256(Consequent))` |\n| `name`    | Modifier — adds `.name` to identifier hashes                                             | —                                                                        |\n| `val`     | Modifier — adds `.value` to literal and conditional hashes                               | —                                                                        |\n| `op_name` | Modifier — adds `.operator` to operator hashes                                           | —                                                                        |\n\n---\n\n## CS-MAST-S Signature Format\n\n```\n$v=1$hash=sha256,lang=js,lver=es6,prsr=-babel/parser,scat=lit_val_id,sinc=IfStatement$\u003c64hex\u003e\n```\n\n- No salt — salting would break the determinism required for subtree matching.\n- Multiple `scat` / `sinc` values joined by `_`.\n- Hash portion: always 64-char lowercase SHA-256 hex.\n\n---\n\n## Mutation Guard\n\nCalling any of the following on a CS-MAST tree node path throws `MutationError`:\n`replaceWith`, `replaceWithMultiple`, `replaceWithSourceString`, `replaceInline`,\n`insertBefore`, `insertAfter`, `remove`, `pushContainer`, `unshiftContainer`.\n\nTo modify source code, call `cs_mast_init` again on the updated source.\n\n---\n\n## Extending to New Languages\n\nImplement `IParserAdapter` from `src/types/parser-adapter.ts`. See `src/adapters/README.md`.\n\n---\n\n## Spec Ambiguities\n\nSee `CLAUDE.md` sections A1–A11 for all documented assumptions where the spec leaves details\nunspecified (separator policy, unary operator handling, codebase hash construction, etc.).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshriyanss%2Fcs-mast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshriyanss%2Fcs-mast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshriyanss%2Fcs-mast/lists"}