So far I have now come up with the following P2SH template:
76a820
87637576a914
88ac6703
b17576a914
88ac68
which can be better understood as this:
OP_DUP
OP_SHA256
OP_EQUAL
OP_IF
OP_DROP
OP_DUP
OP_HASH160
OP_EQUALVERIFY
OP_CHECKSIG
OP_ELSE
OP_NOP2
OP_DROP
OP_DUP
OP_HASH160
OP_EQUALVERIFY
OP_CHECKSIG
OP_ENDIF
Noting that:
is the SHA256 hash of the "secret"
is the public key hash for the "reveal secret" redeem script
is the block number for a CLTV refund to occur at and
is the public key hash for the "CLTV refund" redeem script
The lengths of things being pushed onto the stack has been hard-coded in this template which is fine for the hashes but would not be fine if you changed
to instead be a timestamp (something I'll be looking into a little later).