Skip to content

feat: Extensions for all - #4021

Merged
motorina0 merged 127 commits into
devfrom
extensions_for_all
Jul 15, 2026
Merged

motorina0 merged 127 commits into
devfrom
extensions_for_all

Conversation

@motorina0

@motorina0 motorina0 commented Jun 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds a WASM extension framework for LNbits, allowing third-party extensions to run in a constrained runtime with explicit install-time permissions, sandboxed UI rendering, scoped storage, and host-mediated access to
LNbits functionality.

Backend request flow

• Client request
       |
       v
  /api/v1/ext/{ext_id}/{route}
       |
       v
  WASM API route handler
       |
       | 1. match route from extension config
       | 2. check auth if route is private
       | 3. read path/query/body payload
       v
  invoke_wasm_extension_export(ext_id, export_name, payload, user)
       |
       v
  Load WASM extension metadata
       |
       v
  Load cached WASM component
       |
       v
  Create ExtensionHostAPI(ext_id, permissions, user_id, access_token)
       |
       v
  Wire host functions into WASM linker
       |
       v
  Call WASM export function
       |
       v
  +-----------------------------+
  |       WASM extension        |
  |                             |
  | export handles request      |
  | and may call host imports   |
  +-------------+---------------+
                |
                | host function call
                v
  +-----------------------------+
  |      ExtensionHostAPI       |
  |                             |
  | checks permission/auth      |
  | scopes storage by owner     |
  | calls LNbits core services  |
  +-------------+---------------+
                |
                v
  LNbits core
  (wallets / payments / storage / utils / extension API / HTTP client)
                |
                v
  ExtensionHostAPI response
                |
                v
  WASM export returns JSON
                |
                v
  HTTP response to client

Frontend

• +-------------------------------------------------------------+
  |                         LNbits UI                           |
  |                                                             |
  |  Main layout                                                |
  |  - left menu                                                |
  |  - top bar                                                  |
  |  - authenticated user context                               |
  |                                                             |
  |        route: /ext/{ext_id}/...                             |
  |                           |                                 |
  |                           v                                 |
  |              +--------------------------+                   |
  |              | WasmExtensionComponent   |                   |
  |              |                          |                   |
  |              | - asks backend for frame |                   |
  |              | - owns bridge            |                   |
  |              | - checks allowed routes  |                   |
  |              | - handles QR / notify    |                   |
  |              +-------------+------------+                   |
  |                            |                                |
  |                            | creates sandboxed iframe       |
  |                            v                                |
  |              +--------------------------+                   |
  |              | sandboxed iframe         |                   |
  |              | /ext-frame/{ext_id}/{n}  |                   |
  |              |                          |                   |
  |              | - no cookies             |                   |
  |              | - no direct core access  |                   |
  |              | - strict CSP             |                   |
  |              +-------------+------------+                   |
  |                            ^                                |
  |                            | postMessage bridge             |
  |                            v                                |
  |              +--------------------------+                   |
  |              | Extension JS/HTML UI     |                   |
  |              |                          |                   |
  |              | calls SDK bridge methods |                   |
  |              +--------------------------+                   |
  |                                                             |
  +-------------------------------------------------------------+

Frontend Request flow:

  +-------------------+
  | Extension iframe  |
  +---------+---------+
            |
            | postMessage: api / notify / scan / payment watch
            v
  +------------------------+
  | WasmExtensionComponent |
  +---------+--------------+
            |
            | validates message source
            | validates allowed route/action
            v
  +------------------------+
  | LNbits frontend/core   |
  +---------+--------------+
            |
            | fetch /api/v1/ext/{ext_id}/...
            v
  +------------------------+
  | WASM backend route     |
  +------------------------+

What Changed

  • Added lnbits/core/wasm_ext with:

    • WASM module loading and invocation via wasmtime
    • ExtensionHostAPI host functions for storage, wallets, utilities, HTTP, and extension-to-extension calls
    • WASM route registration for APIs, UI wrappers, iframe pages, assets, and invoice-paid events
    • Owner-scoped WASM extension storage and migrations
    • Frame-token security for /ext-frame/... pages
  • Added WASM extension install/activation support:

    • extension_type: "wasm" detection
    • install-time permission grants
    • stored granted permissions in installed_extensions.permissions
    • separate activation/loading flow for WASM extensions
    • WASM extension links route to /ext/{ext_id}
  • Added sandboxed WASM UI support:

    • private/public pages served through LNbits wrapper at /ext/...
    • actual extension HTML served inside sandboxed iframe
    • strict CSP, no direct core access, and postMessage bridge
    • whitelisted static assets under /ext-assets/{ext_id}/...
    • approved LNbits UI assets proxied for extension use
  • Added extension permissions UI:

    • compact expandable permission list
    • risk badges for sensitive permissions
    • storage read/write merge
    • policy details for public storage, public invoice creation, extension API access, and external websites
  • Added WASM host capabilities:

    • extension storage CRUD and pagination
    • public storage reads with policy-limited fields
    • wallet listing, balance reads, invoice creation, public invoice creation, and invoice payment
    • utility functions for currencies and Lightning invoice helpers
    • extension.api.request for allow-listed extension calls
    • http.request for allow-listed external HTTPS origins
  • Added invoice-paid event dispatch:

    • paid invoice listener can dispatch to WASM extension event exports
    • WASM extensions can react to payment settlement through configured event handlers
  • Added tooling and tests:

    • TypeScript SDK generator under tools/codegen
    • make test-wasm-e2e
    • GitHub CI job for WASM e2e tests
    • dedicated WASM test extension fixture
    • unit and Playwright-backed e2e coverage for permissions, sandboxing, assets, frame tokens, bridge behavior, and HTTP policy checks

Security Notes

  • WASM extension UI runs in a sandboxed iframe.
  • Extension code does not receive LNbits access tokens directly.
  • Core access goes through host functions or the parent bridge.
  • Static assets are restricted by extension, file type, MIME type, and HTML-like content checks.
  • Frame pages require one-time frame tokens, bound to user context where available.
  • Storage rows are owner-scoped through LNbits-managed owner IDs.

Comment thread lnbits/app.py Resolved
@bitkarrot

This comment was marked as resolved.

@motorina0
motorina0 force-pushed the extensions_for_all branch from 864947e to f4cb8a6 Compare June 30, 2026 12:10
@codecov

codecov Bot commented Jun 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 70.54835% with 999 lines in your changes missing coverage. Please review.
✅ Project coverage is 65.37%. Comparing base (8c7e5c2) to head (4515340).
⚠️ Report is 179 commits behind head on dev.

Files with missing lines Patch % Lines
lnbits/core/views/extension_api.py 52.44% 107 Missing ⚠️
lnbits/core/wasm_ext/storage/crud.py 76.16% 87 Missing ⚠️
lnbits/core/wasm_ext/routes/ui.py 46.49% 84 Missing ⚠️
lnbits/core/wasm_ext/wasm/invoke.py 26.31% 84 Missing ⚠️
lnbits/core/wasm_ext/api/host.py 66.94% 80 Missing ⚠️
lnbits/core/wasm_ext/api/utils.py 49.29% 72 Missing ⚠️
lnbits/core/wasm_ext/api/runtime.py 32.92% 55 Missing ⚠️
lnbits/core/wasm_ext/routes/api.py 65.49% 49 Missing ⚠️
lnbits/core/wasm_ext/api/background_payments.py 25.00% 48 Missing ⚠️
lnbits/core/services/extensions.py 83.09% 47 Missing ⚠️
... and 19 more
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #4021      +/-   ##
==========================================
+ Coverage   56.50%   65.37%   +8.87%     
==========================================
  Files         123      157      +34     
  Lines       16914    22351    +5437     
==========================================
+ Hits         9557    14612    +5055     
- Misses       7357     7739     +382     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@motorina0
motorina0 force-pushed the extensions_for_all branch from 07a4dbb to 6702c16 Compare July 1, 2026 13:57
Comment thread lnbits/templates/wasm_extension.html Outdated
</style>
{% endblock %} {% block page_container %}
<q-page-container>
<!-- # todo:revisit this -->

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revisit

@motorina0
motorina0 marked this pull request as ready for review July 10, 2026 07:39
@motorina0

Copy link
Copy Markdown
Collaborator Author

@arcbtc

arcbtc commented Jul 10, 2026 •

Copy link
Copy Markdown
Member

A reliable prompt


  You are building an LNbits WASM extension.

  Before coding, read and follow:

  - `data/extensions/tips/agent.md`

  Use these existing extensions as examples:

  - `data/extensions/tips`
  - `data/extensions/bigpayment`

  Treat them as sample/reference extensions only. Do not copy blindly, and do not modify them. Use their structure, config style, storage patterns, SDK usage, UI layout, and build flow as
  guidance.

  Goal:
  Build a new WASM extension called `{extension_id}`.
  (where possible use LNbits existing frontend utilities like lnbits-qrcode)

  Extension idea:
  {describe_what_the_extension_should_do}

async def update_installed_extension_wasm_runtime_limits(
*, ext_id: str, limits: dict, conn: Connection | None = None
) -> None:
if not await _has_installed_extension_wasm_runtime_limits_column(conn=conn):

@dni dni Jul 13, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is incorrect, it just checks, if the core version >= 48... which has obviously ran, when installing this update.

Comment thread lnbits/core/services/notifications.py Resolved
dni

This comment was marked as outdated.

@motorina0
motorina0 merged commit 61ed636 into dev Jul 15, 2026
58 of 61 checks passed
@motorina0
motorina0 deleted the extensions_for_all branch July 15, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants