nim-nitro/nitro/wallet/signedstate.nim

29 lines
725 B
Nim
Raw Normal View History

2021-03-17 13:38:17 +01:00
import ../basics
import ../protocol
2021-03-17 13:10:49 +01:00
{.push raises: [].}
2021-03-17 13:10:49 +01:00
type
SignedState* = object
state*: State
signatures*: seq[Signature]
2021-03-17 13:10:49 +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 =
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 =
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