I have been reading about the role of script in transactions and I gather it should be possible to do a Bitcoin transfer to a receiver who knows a password. Instead of checking an address, the script would check that the hash of an input corresponds to the value given by the sender.
I have a few doubts on how this would work exactly. The script I have in mind, following the notation used in https://en.bitcoin.it/wiki/Script for standard and IP transactions, is:
scriptPubKey: OP_HASH160 <passwordHash> OP_EQUALVERIFY OP_CHECKSIG
scriptSig: <sig><pubKey><password>
The transfer would have six steps:
- Stack: Empty Script: <sig><pubKey><password> OP_HASH160 <passwordHash> OP_EQUALVERIFY OP_CHECKSIG
- Stack: <sig><pubKey><password> Script: OP_HASH160 <passwordHash> OP_EQUALVERIFY OP_CHECKSIG
- Stack: <sig><pubKey><passwordhashA> Script: <passwordHash> OP_EQUALVERIFY OP_CHECKSIG
- Stack: <sig><pubKey><passwordhashA><passwordHash> Script: OP_EQUALVERIFY OP_CHECKSIG
- Stack: <sig><pubKey> Script: OP_CHECKSIG
- Stack: true Script: Empty
I have left OP_HASH160 because it is already being used so no new operation is needed, but the other hashes in script should be possible. The protocol has some nice properties like making the password public when the coins are transferred.
Is this code correct? Is there something similar in the blockchain? I would like to try it, but I'm not really sure how to connect to the network with such a script. Should I first create a transaction to a "Bitcoin Limbo" and then try to recover it to the final address?