{"id":13912390,"url":"https://github.com/zksecurity/wasmati","last_synced_at":"2025-10-13T14:25:17.636Z","repository":{"id":154633953,"uuid":"622467320","full_name":"zksecurity/wasmati","owner":"zksecurity","description":"Write low-level WebAssembly, from JavaScript","archived":false,"fork":false,"pushed_at":"2024-10-31T08:39:46.000Z","size":218,"stargazers_count":219,"open_issues_count":3,"forks_count":6,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-11-16T22:36:57.597Z","etag":null,"topics":["wasm","webassembly"],"latest_commit_sha":null,"homepage":"","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/zksecurity.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2023-04-02T07:43:04.000Z","updated_at":"2024-11-10T06:52:46.000Z","dependencies_parsed_at":null,"dependency_job_id":"8b801255-1931-4ab3-8e91-46d010589c6a","html_url":"https://github.com/zksecurity/wasmati","commit_stats":null,"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zksecurity%2Fwasmati","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zksecurity%2Fwasmati/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zksecurity%2Fwasmati/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zksecurity%2Fwasmati/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zksecurity","download_url":"https://codeload.github.com/zksecurity/wasmati/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226403764,"owners_count":17619720,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["wasm","webassembly"],"created_at":"2024-08-07T01:01:24.447Z","updated_at":"2025-10-13T14:25:12.599Z","avatar_url":"https://github.com/zksecurity.png","language":"TypeScript","funding_links":[],"categories":["others","TypeScript"],"sub_categories":[],"readme":"# wasmati 🍚 \u0026nbsp; [![npm version](https://img.shields.io/npm/v/wasmati.svg?style=flat)](https://www.npmjs.com/package/wasmati)\n\n_Write low-level WebAssembly, from JavaScript_\n\n**wasmati** is a TS library that lets you create Wasm modules by writing out their instructions.\n\n- 🥷 You want to create low-level, hand-optimized Wasm libraries? wasmati is the tool to do so effectively.\n- 🚀 You want to sprinkle some Wasm in your JS app, to speed up critical parts? wasmati gives you a JS-native way to achieve that.\n- ⚠️ You want to compile Wasm modules from a high-level language, like Rust or C? wasmati is not for you.\n\n```sh\nnpm i wasmati\n```\n\n```ts\n// example.ts\nimport { i64, func, Module } from \"wasmati\";\n\nconst myMultiply = func({ in: [i64, i64], out: [i64] }, ([x, y]) =\u003e {\n  i64.mul(x, y);\n});\n\nlet module = Module({ exports: { myMultiply } });\nlet { instance } = await module.instantiate();\n\nlet result = instance.exports.myMultiply(5n, 20n);\nconsole.log({ result });\n```\n\n```\n$ node --experimental-strip-types example.ts\n{ result: 100n }\n```\n\n## Features\n\n- Works in all modern browsers, `node` and `deno`\n\n- **Parity with WebAssembly.** The API directly corresponds to Wasm opcodes, like `i32.add` etc. All opcodes and language features of the [latest WebAssembly spec (2.0)](https://webassembly.github.io/spec/core/index.html) are supported.  \n  In addition, wasmati supports the following extensions which are not part of the spec at the time of writing:\n\n  - [threads and atomics](https://github.com/WebAssembly/threads/blob/master/proposals/threads/Overview.md)\n  - [relaxed simd](https://github.com/WebAssembly/relaxed-simd/blob/main/proposals/relaxed-simd/Overview.md)\n\n- **Readability.** Wasm code looks imperative - like writing WAT by hand, just with better DX:\n\n```ts\nconst myFunction = func({ in: [i32, i32], out: [i32] }, ([x, y]) =\u003e {\n  local.get(x);\n  local.get(y);\n  i32.add();\n  i32.const(2);\n  i32.shl();\n  call(otherFunction);\n});\n```\n\n- Optional syntax sugar to reduce boilerplate assembly like `local.get` and `i32.const`\n\n```ts\nconst myFunction = func({ in: [i32, i32], out: [i32] }, ([x, y]) =\u003e {\n  i32.add(x, y); // local.get(x), local.get(y) are filled in\n  i32.shl($, 2); // $ is the top of the stack; i32.const(2) is filled in\n  call(otherFunction);\n});\n\n// or also\n\nconst myFunction = func({ in: [i32, i32], out: [i32] }, ([x, y]) =\u003e {\n  let z = i32.add(x, y);\n  call(otherFunction, [i32.shl(z, 2)]);\n});\n```\n\n- **Type-safe.** Example: Local variables are typed; instructions know their input types:\n\n```ts\nconst myFunction = func(\n  { in: [i32, i32], locals: [i64], out: [i32] },\n  ([x, y], [u]) =\u003e {\n    i32.add(x, u); // type error: Type '\"i64\"' is not assignable to type '\"i32\"'.\n  }\n);\n```\n\n- **Great debugging DX.** Stack traces point to the exact line in your code where an invalid opcode is called:\n\n```\nError: i32.add: Expected i32 on the stack, got i64.\n    ...\n    at file:///home/gregor/code/wasmati/examples/example.ts:16:9\n```\n\n- **Easy construction of modules.** Just declare exports; dependencies and imports are collected for you. Nothing ends up in the module which isn't needed by any of its exports or its start function.\n\n```ts\nlet mem = memory({ min: 10 });\n\nlet module = Module({ exports: { myFunction, mem } });\nlet instance = await module.instantiate();\n```\n\n- **Excellent type inference.** Example: Exported function types are inferred from `func` definitions:\n\n```ts\ninstance.exports.myFunction;\n//                 ^ (arg_0: number, arg_1: number) =\u003e number\n```\n\n- **Atomic import declaration.** Imports are declared as types along with their JS values. Abstracts away the global \"import object\" that is separate from \"import declaration\".\n\n```ts\nconst consoleLog = importFunc({ in: [i32], out: [] }, (x) =\u003e\n  console.log(\"logging from wasm:\", x)\n);\n\nconst myFunction = func({ in: [i32, i32], out: [i32] }, ([x, y]) =\u003e {\n  call(consoleLog, [x]);\n  i32.add(x, y);\n});\n```\n\n- Great composability and IO\n  - Internal representation of modules / funcs / etc is a readable JSON object\n    - close to [the spec's type layout](https://webassembly.github.io/spec/core/syntax/modules.html#modules) (but improves readability or JS ergonomics where necessary)\n  - Convert to/from Wasm bytecode with `module.toBytes()`, `Module.fromBytes(bytes)`\n\n### Features that aren't implemented yet\n\n_PRs welcome!_\n\n- **Wasmati build.** We want to add an optional build step which takes as input a file that exports your `Module`, and compiles it to a file which doesn't depend on wasmati at runtime. Instead, it hard-codes the Wasm bytecode as base64 string, correctly imports all dependencies (imports) for the instantiation like the original file did, instantiates the module (top-level await) and exports the module's exports.\n\n```ts\n// example.ts\nlet module = Module({ exports: { myFunction, mem } });\n\nexport { module as default };\n```\n\n```ts\nimport { myFunction } from \"./example.wasm.js\"; // example.wasm.js does not depend on wasmati at runtime\n```\n\n- **Experimental Wasm opcodes.** We want to support opcodes from recently standardized or in-progress feature proposals ([like this one](https://github.com/WebAssembly/gc/blob/main/proposals/gc/Overview.md)) which haven't yet made it to the spec. The eventual goal is to support proposals as soon as they are implemented in at least one JS engine.\n\n- **Custom module sections.** We want to support creation and parsing of \"custom sections\" like the [name section](https://webassembly.github.io/spec/core/appendix/custom.html#name-section)\n\n### Some ideas that are a bit further out:\n\n- **Decompiler**: take _any_ Wasm file and create wasmati TS code from it -- to modify it, debug it etc\n- **Source maps**, so you can look at the culprit JS code when Wasm throws an error\n- Optional JS interpreter which can take DSL code and execute it _in JS_\n  - could enable even more flexible debugging -- inspect the stack, global/local scope etc\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzksecurity%2Fwasmati","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzksecurity%2Fwasmati","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzksecurity%2Fwasmati/lists"}