verifyBlindedComponent.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132
  1. export default (msg, round_pubkey, component_feerate) => {
  2. message_hash = sha256(msg.component)
  3. check(len(msg.signature) == 64, "bad message signature")
  4. check(schnorr.verify(round_pubkey, msg.signature, message_hash), "bad message signature")
  5. cmsg = proto_strict_parse(pb.Component(), msg.component)
  6. check(len(cmsg.salt_commitment) == 32, "bad salt commitment")
  7. ctype = cmsg.WhichOneof('component')
  8. if ctype == 'input':
  9. inp = cmsg.input
  10. check(len(inp.prev_txid) == 32, "bad txid")
  11. check( (len(inp.pubkey) == 33 and inp.pubkey[0] in (2,3))
  12. or (len(inp.pubkey) == 65 and inp.pubkey[0] == 4),
  13. "bad pubkey")
  14. sort_key = ('i', inp.prev_txid[::-1], inp.prev_index, cmsg.salt_commitment)
  15. elif ctype == 'output':
  16. out = cmsg.output
  17. atype, addr = get_address_from_output_script(out.scriptpubkey)
  18. check(atype == TYPE_ADDRESS, "output is not address")
  19. check(out.amount >= dust_limit(len(out.scriptpubkey)), "dust output")
  20. sort_key = ('o', out.amount, out.scriptpubkey, cmsg.salt_commitment)
  21. elif ctype == 'blank':
  22. sort_key = ('b', cmsg.salt_commitment)
  23. else:
  24. raise ValidationError('missing component details')
  25. # Note: for each sort type we use salt_commitment as a tie-breaker, just to
  26. # make sure that original ordering is forgotten. Of course salt_commitment
  27. # doesn't have to be unique, but it's unique for all honest players.
  28. return sort_key, component_contrib(cmsg, component_feerate)
  29. }