Need help with minsc?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

shesek
146 Stars 14 Forks MIT License 144 Commits 5 Opened issues

Description

A Miniscript-based high-level scripting language for Bitcoin contracts

Services available

!
?

Need anything else?

Contributors list

# 64,260
CSS
WordPre...
Rust
Express
144 commits

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

  • A user and a 2FA service need to sign off, but after 90 days the user alone is enough

    hack
    pk(user_pk) && (pk(service_pk) || older(90 days))
    
    :arrow_forward: Try it live
  • Traditional preimage-based HTLC ```hack $redeem = pk(A) && sha256(H); $refund = pk(B) && older(10);

$redeem || $refund ``` :arrow_forward: Try it live

  • Liquid-like federated pegin, with emergency recovery keys that become active after a timeout ```hack $federation = 4 of [ pk(A), pk(B), pk(C), pk(D), pk(E) ]; $recovery = 2 of [ pk(F), pk(G), pk(I) ]; $timeout = older(3 months);

[email protected]$federation || ($timeout && $recovery) ``` :arrow_forward: Try it live

  • The BOLT #3 received HTLC policy ```hack fn bolt3htlcreceived($revokepk, $localpk, $remotepk, $secret, $delay) { $success = pk($localpk) && hash160($secret); $timeout = older($delay);

    pk($revokepk) || (pk($remotepk) && ($success || $timeout)) }

bolt3htlcreceived(A, B, C, H1, 2 hours) ``` :arrow_forward: Try it live

  • Advanced 2FA where the user has a 2-of-2 setup and the service provider is a 3-of-4 federation ```hack fn two_factor($user, $provider, $delay) = $user && ([email protected]$provider || older($delay));

$user = pk(desktoppk) && pk(mobilepk); $providers = [ pk(A), pk(B), pk(C), pk(D) ];

two_factor($user, 3 of $providers, 4 months) ``` :arrow_forward: Try it live

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: ```rust 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: intominiscript() and intodesc() ```

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

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.