<p>My question is if something exists to do the job in the opposite direction of miniscript.</p>
<p>Miniscript's intention is to help:</p>
<blockquote>
<p>    ...writing (a subset of) Bitcoin Scripts in a structured way, enabling analysis, composition, generic signing and more</p>
</blockquote>
<p> So, for example, given the below Bitcoin Script:</p>
<pre><code>OP_SIZE 
32 
OP_EQUAL
OP_IF 
  OP_HASH160 
  'dea3...' 
  OP_EQUALVERIFY 
  '301...'
OP_ELSE 
  OP_CHECKLOCKTIMEVERIFY 
  '19323434...' 
  OP_DROP 
  '303...'
OP_CHECKSIGVERIFY 
</code></pre>
<p>  It would create something of this form (in JavaScript):</p>
<pre><code>function canUnlock(preImageOrSig) {
    let pubKey1 = null;
    if (preImageOrSig.size() === 32) {
        if (hash(preImageOrSig) !== 'dea3...') {
            return false;
        }
        pubKey1 = '301...';
    } else {
        if (!checkLockTime('19323434...')) {
            return false;
        }
        pubKey1 = '303...';
    }
    if (!checkSignature(pubKey1, preImageOrSig)) {
        return false;
    }
    return true;
}
</code></pre>
<p>  The resulting JS code is NOT to be executed or compiled back to Bitcoin Script, but only to help a developer reason about the logic of the original Bitcoin Script.</p>

CC BY-SA 4.0
2020-11-26T17:39:29.363Z
Would anyone else find this feature useful?
Vlad Stan
CC BY-SA 4.0
2020-11-26T21:58:46.503Z
I would look at Bitcoin script debugging tools like those described at https://bitcoin.stackexchange.com/q/42576/13866, I'm not sure I would be comfortable with a tool that translates a stack-based reverse-polish language to javascript.
RedGrittyBrick
CC BY-SA 4.0
2020-11-28T00:33:00.260Z
Your code is more complex than a miniscript expression. A miniscript expression is intended to succeed completely without failure - because that's how bitcoin scripts operate. It's basically your code without all the IF + return true/return false lines.
karimkorun
<script><javascript><miniscript>
Bitcoin Script - Beautify
Vlad Stan
# Bitcoin Script - Beautify

(Asked by: username_0 on 2020-11-26)

My question is if something exists to do the job in the opposite direction of miniscript.

Miniscript's intention is to help:

>     ...writing (a subset of) Bitcoin Scripts in a structured way, enabling analysis, composition, generic signing and more

 So, for example, given the below Bitcoin Script:

```
OP_SIZE 
32 
OP_EQUAL
OP_IF 
  OP_HASH160 
  'dea3...' 
  OP_EQUALVERIFY 
  '301...'
OP_ELSE 
  OP_CHECKLOCKTIMEVERIFY 
  '19323434...' 
  OP_DROP 
  '303...'
OP_CHECKSIGVERIFY 

```

  It would create something of this form (in JavaScript):

```
function canUnlock(preImageOrSig) {
    let pubKey1 = null;
    if (preImageOrSig.size() === 32) {
        if (hash(preImageOrSig) !== 'dea3...') {
            return false;
        }
        pubKey1 = '301...';
    } else {
        if (!checkLockTime('19323434...')) {
            return false;
        }
        pubKey1 = '303...';
    }
    if (!checkSignature(pubKey1, preImageOrSig)) {
        return false;
    }
    return true;
}

```

  The resulting JS code is NOT to be executed or compiled back to Bitcoin Script, but only to help a developer reason about the logic of the original Bitcoin Script.

**Tags:** script, javascript, miniscript

> **Comments:**
> **username_0**: Would anyone else find this feature useful?  
> **username_1**: I would look at Bitcoin script debugging tools like those described at https://bitcoin.stackexchange.com/q/42576/13866, I'm not sure I would be comfortable with a tool that translates a stack-based reverse-polish language to javascript.  
> **username_2**: Your code is more complex than a miniscript expression. A miniscript expression is intended to succeed completely without failure - because that's how bitcoin scripts operate. It's basically your code without all the IF + return true/return false lines.  

---

## 0 answers

