bitcoinops / taproot-workshop

Taproot & Schnorr Python Library & Documentation.
MIT License
369 stars 111 forks source link

impl add/mul/sub/div for ints over ECKey/ECPubkey #105

Closed elichai closed 4 years ago

elichai commented 4 years ago

I'm not sure if it's possible in python. but it's weird that 5*key doesn't work but key*5 does.

jnewbery commented 4 years ago

It's possible. There's a __mul__() method and an __rmul__() (and similar 'r' methods for other operations). In fact, I overloaded __radd__() for the special case of 0 so that the sum() built-in function would work: https://github.com/bitcoinops/taproot-workshop/blob/b6d40e52095a83eb9d8a01097edabe1f2c0fe180/test_framework/key.py#L381. We could easily extend this for the more general case.