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.