npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

minsc

v0.2.0

Published

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

Downloads

77

Readme

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))

    :arrow_forward: Try it live

  • Traditional preimage-based HTLC

    $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

    $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)

    :arrow_forward: 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)

    :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

    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)

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

use minsc::{parse, run};

let code = "pk(A) && older(1 week)";
let ast = parse(code).unwrap();
let result = run(ast).unwrap();

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