nim-nitro/nitro/wallet/signedstate.nim

28 lines
787 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
include questionable/errorban
type
SignedState* = object
state*: State
2021-03-18 14:15:58 +01:00
signatures*: Signatures
Signatures* = seq[(EthAddress, 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 (signer, signature) in signed.signatures:
if signer == account and signature.verify(signed.state, signer):
return true
false
2021-03-17 13:10:49 +01:00
func verifySignatures*(signed: SignedState): bool =
for (participant, signature) in signed.signatures:
if not signed.hasParticipant(participant):
2021-03-17 13:10:49 +01:00
return false
if not signature.verify(signed.state, participant):
return false
true