Skip to content

adyshimony/miniscript-studio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Miniscript Studio

A WebAssembly Miniscript Studio that runs entirely in the browser, powered by the Rust Miniscript crate. Compile Bitcoin policies to Miniscript and Bitcoin Script, lift scripts, generate addresses across Legacy, Segwit, and Taproot contexts, HD wallet descriptor support, key managment, educational examples and more.

🌐 Live Site: https://adys.dev/miniscript

Features

  • Policy Editor: Write spending conditions with syntax highlighting and auto-compilation
  • Miniscript Editor: Work with raw miniscript or compile from policies
  • Lift: Convert back Bitcoin Script β†’ Miniscript β†’ Policy
  • Taproot Support: Full support with branch selection and script path analysis
  • HD Wallet Descriptors: Range descriptors with index field and multipath support
  • Spending Analysis: Detailed cost analysis and satisfaction paths
  • Context Switching: Legacy, Segwit v0, and Taproot with automatic detection
  • Address Generation: Bitcoin addresses with mainnet/testnet toggle
  • Key Management: Auto-extract, generate, and manage key variables
  • Save & Share: Local storage and shareable URLs
  • Rich Examples: 20+ examples with educational descriptions
  • Local-First: All data stays in your browser - no server required

Policy Editor

  • Write high-level spending conditions with syntax highlighting
  • Auto-compilation on load (configurable)
  • Example descriptions (collapsible in settings)
  • Indent expressions for readability
  • Auto-clean invalid characters before compiling

Miniscript Editor

  • Works standalone or with Policy editor
  • Detailed compilation messages with spending analysis
  • Branch selection for Taproot OR conditions
  • Shows satisfaction paths and weight units
  • Load examples with rich educational descriptions

Script Output

  • Bitcoin Script in HEX and ASM formats
  • Editable fields for lifting operations
  • Bitcoin addresses with network toggle (mainnet/testnet)
  • Show/hide pushbytes operations
  • Show/hide key names to see actual values

Key Variables

Manage public keys with friendly names:

Extract Keys πŸ”‘

  • Missing variables: Write or(pk(Nadav),pk(Aviv)) β†’ auto-generate keys for undefined variables
  • Hex to variables: Convert long hex keys to named variables automatically
  • From errors: Generate missing keys directly from error messages

Key Management

  • Add/Edit/Delete: Full control over key variables
  • Generate: 🎲 creates context-appropriate test keys
  • Toggle Display: Show names or actual key values
  • Restore Defaults: Reset to default keys anytime
  • Key Types: Compressed (66 chars) for Legacy/Segwit, X-only (64 chars) for Taproot
  • Local Storage: Keys saved in browser, never sent to server

Lift

The Script HEX and ASM fields are editable - paste any Bitcoin Script to reverse it:

Bitcoin Script β†’ Miniscript

  • Input: Paste hex or ASM format into the editable script fields
  • Output: Automatically lifts to readable miniscript

Miniscript β†’ Policy

  • Input: Any miniscript expression
  • Output: High-level policy representation

Note: Not all scripts can be lifted (e.g., scripts with public key hashes)

Script Contexts

  • Legacy (P2SH): Traditional Bitcoin scripts, max compatibility
  • Segwit v0 (P2WSH): Native witness scripts, lower fees
  • Taproot: Privacy-enhanced scripts with multiple sub-contexts:
    • Single Leaf / key: A single script leaf, or key only when no script
    • Script Path: Multiple branches with cost analysis
    • Script + Key Path: Combined key and script spending paths

Taproot Features

Branch Selection

  • OR Conditions: Choose which branch to compile from policy
  • Script Paths: Visualize different spending paths with costs

Spending Analysis

  • Weight Units: Fee estimation for each path
  • Satisfaction Paths: All ways to spend the script
  • Descriptors: Full taproot descriptor display
  • Cost Comparison: Compare different contexts

HD Wallet Descriptors

Full support for xpub/tpub descriptors with range patterns:

Derivation Index Field

  • Auto-appears: When using wildcard patterns (/*)
  • Index input: Enter 0-2147483647 for specific derivations
  • No expression editing: Change index without modifying the descriptor

Multipath Support

  • Range descriptors: <0;1>/* for external/change branches
  • Path selector: Dropdown to choose External or Change
  • BIP389 Compliant: Modern HD wallet patterns
  • All contexts: Works in Legacy, Segwit, and Taproot

Save & Load

Persistent local storage for your work:

  • Save Policies: πŸ’Ύ button stores policy expressions (up to 20)
  • Save Expressions: πŸ’Ύ button stores compiled miniscript (up to 20)
  • Load: Click "Load" to restore saved items with context preserved
  • Local Storage: All data stays in your browser
  • Export: πŸ“‹ button copies expressions to clipboard

Share

Create shareable URLs for collaboration:

  • Create Link: πŸ”— button generates shareable URL
  • Formats: URL encoded (?policy=...) or compact JSON (?state=...)
  • Auto-load: Links automatically load expressions when opened

Settings

  • 🎨 Theme: Dark/Light mode switcher
  • πŸƒ Auto-compile: Automatically compile when loading examples or saved expressions
  • πŸ“– Show descriptions: Display helpful descriptions for example buttons
  • πŸ’‘ Editor tips: Show/hide helpful placeholder text in empty editors
  • πŸ”— Share format: Choose between URL encoded or JSON format for share links
  • πŸ‘οΈ Hide corner buttons: Hide GitHub and donation buttons (web only)
  • 🌳 Tree display: Script Compilation, Visual Hierarchy, or Hidden

Building from Source

Prerequisites

  • Rust (latest stable version)
  • wasm-pack for building WebAssembly modules

Build Steps

# Install wasm-pack if not already installed
cargo install wasm-pack

# Build the WebAssembly module
wasm-pack build --target web

# Serve the application (WebAssembly requires HTTP server)
python -m http.server 8000
# Then open http://localhost:8000 in your browser

Project Structure

miniscript-compiler/
β”œβ”€β”€ miniscript/
β”‚   β”œβ”€β”€ index.html          # Main web interface
β”‚   β”œβ”€β”€ script.js           # Entry point, imports modules
β”‚   β”œβ”€β”€ modules/
β”‚   β”‚   β”œβ”€β”€ compiler-core.js     # MiniscriptCompiler class
β”‚   β”‚   β”œβ”€β”€ window-functions.js  # Global window functions
β”‚   β”‚   └── constants.js         # Shared constants
β”‚   └── pkg/                # Generated WASM bindings
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ lib.rs              # WASM exports
β”‚   β”œβ”€β”€ compile/            # Compilation logic
β”‚   β”œβ”€β”€ descriptors/        # HD wallet descriptors
β”‚   β”œβ”€β”€ taproot/            # Taproot-specific logic
β”‚   β”œβ”€β”€ lift/               # Script lifting
β”‚   β”œβ”€β”€ keys/               # Key management
β”‚   β”œβ”€β”€ address/            # Address generation
β”‚   └── validation/         # Input validation
β”œβ”€β”€ tests/                  # Rust tests
β”œβ”€β”€ Cargo.toml              # Rust dependencies
└── README.md               # This file

Dependencies

License

This project is licensed under the MIT License. See the LICENSE file for details.

Resources

About

Miniscript Studio

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •