How blessnetwork/sdk-ts works
Project type and purpose
• This is a TypeScript‐based SDK plus CLI tool (@blockless/sdk-ts) that compiles user JS/TS code into a WebAssembly module targeting the BLESS Javy WASM Engine.
• It provides polyfills for missing Node/Web APIs (crypto, http/fetch, stdin) and dynamically bundles only the selected “plugins” (full, llm, crypto, fetch).
File structure
• Top level:
• .github/workflows: CI for publishing
• bundler/: CLI implementation (bundler/index.ts) for building and managing Javy/plugins
• lib/: core SDK code and polyfills (entry.ts, index.ts, polyfill/crypto.ts, stdin.ts, web.ts)
• examples/: sample user projects (crypto, env, fetch, llm, stdin)
• types/: TypeScript declarations
• package.json, tsconfig.json, biome.json: build/config files
• Patterns & configuration:
• CLI entry point in bundler
• SDK entryMain and InputProps abstractions in lib/entry.ts
• Plugin feature flags passed to the bundler CLI
• Output artifacts: .wasm modules in user’s outDirectory
README for technical stack & commands
• Build command: bls-sdk-ts build ./index.ts -o <outDir> -f <outFile>
• Example of building: node ./dist/bundler build ./examples/llm/index.ts … --features llm
• Uninstall/update manages Javy engine and plugins
• Supported SDK APIs: JSON, HTTP/fetch, crypto, stdin
a. Main components
• User Project / Source Code (examples or any npm project importing @blockless/sdk-ts)
• SDK Library (lib/*): entryMain, polyfills, type definitions
• Bundler CLI (bundler/index.ts)
• Javy WASM Engine & Plugins (crypto, fetch, llm, full)
• Host Environment for WASM (network, cryptography, stdin/stdout)
b. Relationships & data flow
1. Developer writes TS code that imports @blockless/sdk-ts → passes business logic into entryMain.
2. Bundler CLI runs under Node, invokes Javy CLI to compile TS → WASM, injecting only requested plugins.
3. Output .wasm is deployed or executed via the Javy Engine.
4. At runtime, the WASM module uses polyfills to talk to the engine’s host functions (e.g., crypto calls go to the engine’s crypto plugin).
5. InputProps JSON is fed in via stdin or Javy API; user callback executes; output JSON is returned.
c. Architectural patterns & design principles
• Plugin Architecture: feature flags selectively include / exclude host plugins.
• Layered Design:
– Build‐time (Node CLI, TypeScript → WASM)
– SDK Core (entry point + polyfills)
– Host Integration (Javy Engine + plugins)
• Separation of Concerns: User code vs. SDK vs. WASM runtime vs. host services
d. Key technologies & libraries
• TypeScript, Node.js for build tooling
• Javy WASM engine for running compiled modules
• Ethers AbiCoder in examples
• npm ecosystem for module resolution
• Custom polyfills in lib/polyfill