Skip to content

Commit a604795

Browse files
committed
Update README
1 parent 945c2c1 commit a604795

File tree

1 file changed

+101
-28
lines changed

1 file changed

+101
-28
lines changed

README.md

Lines changed: 101 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,58 @@
1-
[![Build Status](https://travis-ci.org/shesek/minsc.svg?branch=master)](https://travis-ci.org/shesek/minsc)
1+
[![Build Status](https://github.com/shesek/minsc/actions/workflows/minsc.yml/badge.svg)](https://github.com/shesek/minsc/actions/workflows/minsc.yml)
22
[![crates.io](https://img.shields.io/crates/v/minsc.svg)](https://crates.io/crates/minsc)
33
[![npm](https://img.shields.io/npm/v/minsc.svg?color=blue)](https://www.npmjs.com/package/minsc)
44
[![MIT license](https://img.shields.io/github/license/shesek/minsc.svg?color=yellow)](https://github.com/shesek/minsc/blob/master/LICENSE)
55
![Pull Requests Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)
66

77
# Minsc
88

9-
### A Miniscript-based scripting language for Bitcoin contracts
10-
11-
Minsc is a high-level scripting language for expressing Bitcoin Script spending conditions.
9+
### A mini scripting language for all things Bitcoin
10+
11+
Minsc is a high-level, domain-specific, embeddable language for Bitcoin scripting that simplifies the creation and fulfillment of complex spending conditions, using an expressive pseudo-code-like syntax.
12+
13+
It includes built-in support for Descriptors, Miniscript, Script, Transactions, PSBT, Taproot, Xpubs/Xprvs, CTV and more.
14+
15+
The language is dynamically typed, purely functional and immutable.
16+
17+
> [!NOTE]
18+
> The documentation and playground on the [`min.sc`](https://min.sc/) website are severely outdated.
19+
>
20+
> To explore some of Minsc's new abilities, check out the [`min.sc/v0.3`](https://min.sc/v0.3/) playground and the following examples:
21+
>
22+
> #### Descriptors, Miniscript & PSBT
23+
> - [Simple Taproot](https://min.sc/v0.3/#github=examples/taproot-psbt-simple.minsc) (P2TR key-path)
24+
> - [Simple Multisig](https://min.sc/v0.3/#github=examples/multisig-simple.minsc) (P2WSH 2-of-2)
25+
> - [Co-signer with expiry](https://min.sc/v0.3/#github=examples/cosigner-with-expiry.minsc) (P2TR with Miniscript, Green-like)
26+
> - [Multisig 3-of-3 into 2-of-3](https://min.sc/v0.3/#github=examples/3of3-into-2of3.minsc) (decays after a timeout)
27+
> - [Hashed Timelock Contract](https://min.sc/v0.3/#github=examples/htlc.minsc) (traditional HTLC)
28+
> - [Recovery after a delay period](https://min.sc/v0.3/#github=examples/recovery-after-delay.minsc) (simple CSV-based, delay period since the coins last moved)
29+
> - [Inheritance after a contest period](https://min.sc/v0.3/#github=examples/inheritance-after-contest-presigned.minsc) (2-stage using pre-signed txs, contest delay period following the 'trigger')
30+
>
31+
> #### Manual Scripting/Signing
32+
> - [Manual Signing](https://min.sc/v0.3/#github=examples/manual-signing-p2wpkh.minsc) (P2WPKH *without* Descriptors, Miniscript or PSBT)
33+
> - [Manual Scripting & Signing](https://min.sc/v0.3/#github=examples/manual-scripting-signing-p2wsh.minsc) (P2WSH *without* Descriptors, Miniscript or PSBT)
34+
> - [Simple CTV Whitelist](https://min.sc/v0.3/#github=examples/ctv-simple.minsc) (P2TR with raw Script)
35+
> - [CTV Vault](https://min.sc/v0.3/#github=examples/ctv-vault.minsc) (P2TR with raw Script)
36+
> - [Simplest CAT](https://min.sc/v0.3/#github=examples/cat-simplest.minsc)
37+
> - More scripting examples are available in [the playground's default code](https://min.sc/v0.3/)
38+
>
39+
> #### Elements/Liquid Introspection
40+
> - [Dutch Auction](https://min.sc/v0.3/#github=examples/elements-dutch-auction.minsc)
41+
> - [Token Sale with royalty](https://min.sc/v0.3/#github=examples/elements-sale-royalty.minsc) (recursive stateful contract, WIP code)
42+
>
43+
> To learn more about the language internals, you can also check out the Minsc standard library parts implemented in Minsc:
44+
>
45+
> - [`src/stdlib/stdlib.minsc`](https://min.sc/v0.3/#github=src/stdlib/stdlib.minsc) (utilities for arrays, strings, testing and more)
46+
> - [`src/stdlib/btc.minsc`](https://min.sc/v0.3/#github=src/stdlib/btc.minsc) (transaction utilities, script opcodes, loop unrolling, control structures and more)
47+
> - [`src/stdlib/elements.minsc`](https://min.sc/v0.3/#github=src/stdlib/elements.minsc) (Elements introspection, 64-bit arithmetic and more)
48+
49+
<!-- Minsc is a high-level scripting language for expressing Bitcoin Script spending conditions.
1250
It is based on the [Miniscript](http://bitcoin.sipa.be/miniscript/) Policy language,
1351
with additional features and syntactic sugar sprinkled on top, including variables, functions, infix notation, human-readable times and more.
1452
15-
Documentation & live playground are available on the website: https://min.sc
53+
Documentation & live playground are available on the website: https://min.sc
1654
17-
Support development: [⛓️ on-chain or ⚡ lightning via BTCPay](https://btcpay.shesek.info/)
55+
Support development: [⛓️ on-chain or ⚡ lightning via BTCPay](https://btcpay.shesek.info/)
1856
1957
## Examples
2058
@@ -68,7 +106,7 @@ Support development: [⛓️ on-chain or ⚡ lightning via BTCPay](https://btcpa
68106
```
69107
[:arrow_forward: Try it live](https://min.sc/#c=%2F%2F%20Two%20factor%20authentication%20with%20a%20timeout%20recovery%20clause%0Afn%20two_factor%28%24user%2C%20%24provider%2C%20%24delay%29%20%3D%20%0A%20%20%24user%20%26%26%20%28likely%40%24provider%20%7C%7C%20older%28%24delay%29%29%3B%0A%0A%2F%2F%202FA%20where%20the%20user%20has%20a%202-of-2%20setup%20and%20the%20provider%20is%20a%203-of-4%20federation%0A%0A%24user%20%3D%20pk%28desktop_pk%29%20%26%26%20pk%28mobile_pk%29%3B%0A%24providers%20%3D%20%5B%20pk%28A%29%2C%20pk%28B%29%2C%20pk%28C%29%2C%20pk%28D%29%20%5D%3B%0A%0Atwo_factor%28%24user%2C%203%20of%20%24providers%2C%204%20months%29)
70108
71-
More examples are available on https://min.sc.
109+
More examples are available on https://min.sc.-->
72110

73111
## Local installation
74112

@@ -77,29 +115,26 @@ More examples are available on https://min.sc.
77115
```bash
78116
$ cargo install minsc
79117

80-
# Compile a minsc file
118+
# Execute a minsc file
81119
$ minsc examples/htlc.minsc
82120

83-
# Compile from stdin
84-
$ echo 'pk(A) && older(1 week)' | minsc -
121+
# Execute from stdin
122+
$ echo 'pk(d0de0aaeaefad02b8bdc8a01a1b8b11c696bd3d66a2c5f10780d95b7df42645c) && older(1 week)' | minsc -
85123

86124
# Dump AST
87125
$ minsc examples/htlc.minsc --ast
88126
```
89127

90128
Using the Rust API:
91129
```rust
92-
use minsc::{parse, run, eval};
93-
94-
let code = "pk(A) && older(1 week)";
95-
let ast = parse(&code).unwrap();
96-
let result = eval(ast).unwrap();
97-
// or parse+eval in one go with `run(&code)`
130+
use minsc::eval;
98131

99-
let policy = result.into_policy().unwrap();
100-
println!("{}", policy);
132+
let code = "pk(d0de0aaeaefad02b8bdc8a01a1b8b11c696bd3d66a2c5f10780d95b7df42645c) && older(1 week)";
133+
let res = eval(&code).unwrap(); // a minsc::Value
134+
println!("{}", res);
101135

102-
// also available: into_miniscript() and into_desc()
136+
// Extract the miniscript::Policy
137+
let policy = res.into_policy().unwrap();
103138
```
104139

105140
Full documentation for the Rust API is [available here](https://docs.rs/minsc/).
@@ -109,15 +144,53 @@ Full documentation for the Rust API is [available here](https://docs.rs/minsc/).
109144
Install with `npm install minsc` and:
110145

111146
```js
112-
import { run } from 'minsc'
113-
114-
const policy = run('pk(A) && older(1 week)')
115-
const miniscript = run('miniscript(pk(A) && older(1 week))')
116-
const descriptor = run('wsh(miniscript(pk(A) && older(1 week)))')
117-
const address = run('address(wsh(miniscript(pk(A) && older(1 week))))')
118-
const address2 = run('address(pk(A) && older(1 week))')
119-
120-
console.log({ policy, miniscript, descriptor, address, address2 })
147+
import m from 'minsc'
148+
149+
// A multisig between Alice and Bob
150+
const alice_pk = 'xpub661MyMwAqRbcFjVEmr9dDxeGKJznf41v5bEd83wMwu7CJ6PFeqJk3cSECPTh6wzsh32xceVsPvBgJ1q3Cqqie2dvH9nMFdL5865WrtRNhiB'
151+
, bob_pk = 'xpub661MyMwAqRbcFG1mzmcbw7oZss2Fn9y3d27D1KVjyKQdYGqNsZ8nSvLSexZAtkCNwvhFrAkTWAixvN9wjmnLNR22EsQczTiKccAJoLYW8CK'
152+
153+
const multisig = m`wsh(${alice_pk}/0/* && ${bob_pk}/0/*)`
154+
155+
// Generate receive address #0
156+
const address = m`address(${multisig}/0)`
157+
console.log(`Address: ${address}`)
158+
159+
// An output funding address #0
160+
const prevout = '72877bd944be3433d5030ef102922e52f7c40de8b5ca26fa8b7c724d341e936e:1'
161+
, amount = '0.5 BTC'
162+
163+
// Create PSBT
164+
const psbt = m`psbt[
165+
"input": [
166+
"prevout": ${prevout},
167+
"utxo": ${multisig}/0:${amount},
168+
],
169+
"outputs": [
170+
bcrt1ql8nqx3q3v7napchr6ewy4tpyq5y08ywat84pen: 0.4 BTC,
171+
(${multisig}/1): 0.099 BTC, // change back to multisig
172+
],
173+
]`
174+
175+
// Export PSBT for external signing
176+
const psbt_base64 = m.base64(psbt)
177+
178+
// Or sign with Minsc:
179+
const alice_sk = 'xprv9s21ZrQH143K3FQmfpccrphXmHAJFbJ4iNK2KfXkPZaDRJ477HzVVp7kM7RV3ihdLh4Wy163wJahwXcdcrpu4R6xSu6CUvKYwftQYCbowYM'
180+
, bob_sk = 'xprv9s21ZrQH143K2mwJtk5bZyrqKqBmNhFCFoBcCw68QysefUWEL1pXu81xoeva2ZWpCjsJzzmYqph6vw6FjCMjg3q8obNzxYY9bCVgt9bKoHQ'
181+
182+
const signed = m`psbt::sign(${psbt}, ${[ alice_sk, bob_sk ]})`
183+
184+
// Finalize & Extract
185+
const tx = m`psbt::extract(psbt::finalize(${signed}))`
186+
console.log(m.pretty(tx))
187+
console.log(m.bytes(tx).toString('hex'))
188+
189+
// Alternative style, with Minsc functions as JavaScript methods (translated into the same as above)
190+
const address = m.address(m.wsh(m.and(m`${alice_pk}/0/1`, m`${bob_pk}/0/1`)))
191+
const psbt = m.psbt({ inputs: [ ... ], outputs: [ ... ] })
192+
const signed = m.psbt.sign(psbt, [ alice_sk, bob_sk ])
193+
const tx = m.psbt.extract(m.psbt.finalize(signed))
121194
```
122195

123196

0 commit comments

Comments
 (0)