2021-03-17 13:38:17 +01:00
|
|
|
import ../basics
|
|
|
|
|
import ../protocol
|
2021-03-17 13:10:49 +01:00
|
|
|
|
2025-12-10 20:44:01 +01:00
|
|
|
{.push raises: [].}
|
2021-03-17 13:10:49 +01:00
|
|
|
|
|
|
|
|
type
|
|
|
|
|
SignedState* = object
|
|
|
|
|
state*: State
|
2021-03-22 14:23:14 +01:00
|
|
|
signatures*: seq[Signature]
|
2021-03-17 13:10:49 +01:00
|
|
|
|
2021-03-17 13:21:02 +01:00
|
|
|
func hasParticipant*(signed: SignedState, participant: EthAddress): bool =
|
|
|
|
|
signed.state.channel.participants.contains(participant)
|
2021-03-17 13:10:49 +01:00
|
|
|
|
2021-03-22 14:04:28 +01:00
|
|
|
func isSignedBy*(signed: SignedState, account: EthAddress): bool =
|
2021-03-22 14:23:14 +01:00
|
|
|
for signature in signed.signatures:
|
|
|
|
|
if signer =? signature.recover(signed.state):
|
|
|
|
|
if signer == account:
|
|
|
|
|
return true
|
2021-03-22 14:04:28 +01:00
|
|
|
false
|
|
|
|
|
|
2021-03-17 13:10:49 +01:00
|
|
|
func verifySignatures*(signed: SignedState): bool =
|
2021-03-22 14:23:14 +01:00
|
|
|
for signature in signed.signatures:
|
|
|
|
|
if signer =? signature.recover(signed.state):
|
|
|
|
|
if not signed.hasParticipant(signer):
|
|
|
|
|
return false
|
|
|
|
|
else:
|
2021-03-17 13:10:49 +01:00
|
|
|
return false
|
|
|
|
|
true
|