1

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.

3
  • Would anyone else find this feature useful?
    – Vlad Stan
    Nov 26, 2020 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. Nov 26, 2020 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, 2020 at 0:33

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.