• Stars
    star
    188
  • Rank 205,563 (Top 5 %)
  • Language
    Rust
  • License
    MIT License
  • Created over 4 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An highly-specialized DSL scripting language for Bitcoin Script and 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

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

    pk(user_pk) && (pk(service_pk) || older(90 days))

    ▶️ Try it live

  • Traditional preimage-based HTLC

    $redeem = pk(A) && sha256(H);
    $refund = pk(B) && older(10);
    
    $redeem || $refund

    ▶️ Try it live

  • Liquid-like federated pegin, with emergency recovery keys that become active after a timeout

    $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);
    
    likely@$federation || ($timeout && $recovery)

    ▶️ Try it live

  • The BOLT #3 received HTLC policy

    fn bolt3_htlc_received($revoke_pk, $local_pk, $remote_pk, $secret, $delay) {
      $success = pk($local_pk) && hash160($secret);
      $timeout = older($delay);
    
      pk($revoke_pk) || (pk($remote_pk) && ($success || $timeout))
    }
    
    bolt3_htlc_received(A, B, C, H1, 2 hours)

    ▶️ Try it live

  • Advanced 2FA where the user has a 2-of-2 setup and the service provider is a 3-of-4 federation

    fn two_factor($user, $provider, $delay) =
      $user && (likely@$provider || older($delay));
    
    $user = pk(desktop_pk) && pk(mobile_pk);
    $providers = [ pk(A), pk(B), pk(C), pk(D) ];
    
    two_factor($user, 3 of $providers, 4 months)

    ▶️ 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:

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

More Repositories

1

spark-wallet

⚡️ A minimalistic wallet GUI for c-lightning, accessible over the web or through mobile and desktop apps.
JavaScript
343
star
2

bitrated

Bitrated v1
CoffeeScript
145
star
3

btproof

btproof.com - trusted digital timestamping on the bitcoin blockchain
JavaScript
65
star
4

bitcoin-ssid-ticker

Real time price ticker for Bitcoin over wifi SSID names
Shell
30
star
5

bcash-instadump

CLI tools for insta-dumping bcash in exchange for bitcoins (via ShapeShift), creating bcash-compatible transactions, and more
JavaScript
28
star
6

onionfile

Simple file sharing over tor hidden services (v3)
JavaScript
28
star
7

proof-of-hodl

provable bitcoin HODLing
JavaScript
22
star
8

cypher-query

Node query builder for Cypher (tiny wrapper around string expressions)
CoffeeScript
17
star
9

iferr

Higher-order functions for easier error handling
CoffeeScript
13
star
10

trello-hide-lists

User script to hide lists on Trello
CoffeeScript
12
star
11

btcd

NodeJS client for btcd WebSocket API
CoffeeScript
9
star
12

qruri

NodeJS port of Kang Seonghoon's qr.js
JavaScript
8
star
13

github-notifications

Get notifications from GitHub to Chrome Desktop Notifications
8
star
14

bitcoinuri

Create bitcoin payment URIs with amounts that are dynamically adjusted to reflect the current bitcoin exchange rate.
JavaScript
8
star
15

move-decimal-point

Move the decimal point of string numbers
CoffeeScript
6
star
16

backbone-attrs

ES5 getters/setters for Backbone models
CoffeeScript
3
star
17

fmtbtc

Format and convert bitcoin's display units (msat, sat, bit, milli and btc)
JavaScript
3
star
18

trust-trade

CoffeeScript
3
star
19

node-php-template

Execute PHP templates under node.js
CoffeeScript
1
star
20

jquery-widget-markup

A tiny jQuery plugin to create widgets from HTML markup
1
star
21

express-subroute

Sub routes for express, with support for automatic OPTIONS response and 405 Method Not Allowed.
CoffeeScript
1
star
22

redis-to-sse

Redis to SSE
JavaScript
1
star
23

electrumd

Utility to run a regtest Electrum wallet daemon, useful in integration testing environment
Rust
1
star