Code Monkey home page Code Monkey logo

minsc's Introduction

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: ⛓️ bc1q43zm3sdeuehzvpskt2m0gy96pwe7mldxh9d9tatippin.me

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(H) ];
    $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, H, 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(user_desktop) && pk(user_mobile);
    $providers = [ pk(P1), pk(P2), pk(P3), pk(P4) ];
    
    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, compile};

let s = "pk(A) && older(1 week)";

let ast = parse(s).unwrap();
let policy = run(ast).unwrap().into_policy().unwrap();
println!("{}", policy);

// Or in one go
let policy = compile(s).unwrap();

JavaScript WASM package

Install with npm install minsc and:

import { compile } from 'minsc'

const policy = compile('pk(A) && older(1 week)')
console.log(policy)

License

MIT

minsc's People

Contributors

shesek avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.