Skip to content

Chess: use multisig scripts #389

@ClemensLey

Description

@ClemensLey

The script in the payment object should be roughly like this:

OP_2 ${publicKeyW} ${publicKeyB} ${operatorPublicKey} OP_3 OP_CHECKMULTISIG
  • Initially, the two players should jointly sign and broadcast a transaction that spends the wagers to the winner
  • If a certain number of blocks has passed where the looser refuses to sign, the winner can contact the operator with a partially signed transaction. The operator would check who the winner is and that the partially signed transaction pays to the winner. In that case the operator would sign and bradcast the transaction.

Possible implementation

In the test

  1. Copy the last test in apps.async-test and tests spending from a 2-of-3 multisig script (as above)

In the game

  1. Update the _owners property of the Payment class to be the above multi-sig script
  2. Update the getASM function to return the same script
  3. Copy the spendWithSecret function and call it spendWithSecret2
  4. Winner creates an unsinged transaction redeemTx
  5. Winner creates their signature using bscript.signature.encode(hdPrivateKey.sign(sigHash), Transaction.SIGHASH_ALL)
  6. Winner then send the redeemTx and their signature to the operator
  7. The operator syncs against the game and determines if the output script pays to the winner (this check can be implemented when the rest works). If not the operator returns an error.
  8. The operator also created a signature using bscript.signature.encode(hdPrivateKey.sign(sigHash), Transaction.SIGHASH_ALL)
  9. The operator adds both signatures as the input script as in the end of the spendWithSecret function
  10. The operator broadcasts the transaction

Notes

  • The white player calls makeTx to build the partially signed transaction that the white player send to the black player in the URL
  • The black player then calls the completeTx function to complete the transaction
  • The winner calls the spend function once the game is over. This function accessed the /secret route on the server
  • The winner build the spending transaction in the spendWithSecret function

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions