shesek / minsc

A mini scripting language for all things Bitcoin
https://min.sc
MIT License
193 stars 19 forks source link
bitcoin bitcoin-script miniscript

Build Status crates.io npm MIT license Pull Requests Welcome

Minsc

A Miniscript-based scripting language for Bitcoin contracts

Minsc is a high-level scripting language for expressing Bitcoin Script spending conditions. It is based on the Miniscript Policy language, with additional features and syntactic sugar sprinkled on top, including variables, functions, infix notation, human-readable times and more.

Documentation & live playground are available on the website: https://min.sc

Support development: ⛓️ on-chain or ⚡ lightning via BTCPay

Examples

More examples are available on https://min.sc.

Local installation

Install Rust and:

$ cargo install minsc

# Compile a minsc file
$ minsc examples/htlc.minsc

# Compile from stdin
$ echo 'pk(A) && older(1 week)' | minsc -

# Dump AST
$ minsc examples/htlc.minsc --ast

Using the Rust API:

use minsc::{parse, run, eval};

let code = "pk(A) && older(1 week)";
let ast = parse(&code).unwrap();
let result = eval(ast).unwrap();
// or parse+eval in one go with `run(&code)`

let policy = result.into_policy().unwrap();
println!("{}", policy);

// also available: into_miniscript() and into_desc()

Full documentation for the Rust API is available here.

JavaScript WASM package

Install with npm install minsc and:

import { run } from 'minsc'

const policy = run('pk(A) && older(1 week)')
const miniscript = run('miniscript(pk(A) && older(1 week))')
const descriptor = run('wsh(miniscript(pk(A) && older(1 week)))')
const address = run('address(wsh(miniscript(pk(A) && older(1 week))))')
const address2 = run('address(pk(A) && older(1 week))')

console.log({ policy, miniscript, descriptor, address, address2 })

License

MIT