Concrete Signer implementation using a local private key
| 81 | |
| 82 | |
| 83 | class LocalSigner(Signer): |
| 84 | """Concrete Signer implementation using a local private key""" |
| 85 | |
| 86 | private_key: keys.PrivateKey |
| 87 | |
| 88 | def __init__(self, private_key: bytes) -> None: |
| 89 | self.private_key = keys.PrivateKey(private_key) |
| 90 | self.address = self.private_key.public_key.to_canonical_address() |
| 91 | |
| 92 | def sign(self, data: bytes, v: int = 27) -> Signature: |
| 93 | """Sign data hash with local private key""" |
| 94 | assert v in (0, 27), "Raiden is only signing messages with v in (0, 27)" |
| 95 | _hash = eth_sign_sha3(data) |
| 96 | signature = self.private_key.sign_msg_hash(message_hash=_hash) |
| 97 | sig_bytes = signature.to_bytes() |
| 98 | # adjust last byte to v |
| 99 | return sig_bytes[:-1] + bytes([sig_bytes[-1] + v]) |
no outgoing calls