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:


  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.

  • Would anyone else find this feature useful? – Vlad Stan Nov 26 '20 at 17:39
  • I would look at Bitcoin script debugging tools like those described at 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 Nov 26 '20 at 21:58
  • 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 Nov 28 '20 at 0:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.