diff --git a/waku/v2/protocol/waku_swap/waku_swap.nim b/waku/v2/protocol/waku_swap/waku_swap.nim index a31439fcc..5e9ae5d65 100644 --- a/waku/v2/protocol/waku_swap/waku_swap.nim +++ b/waku/v2/protocol/waku_swap/waku_swap.nim @@ -121,6 +121,7 @@ proc sendCheque*(ws: WakuSwap) {.async.} = # TODO We get this from the setup of swap setup, dynamic, should be part of setup # TODO Add beneficiary, etc var aliceSwapAddress = "0x6C3d502f1a97d4470b881015b83D9Dd1062172e1" + var aliceWalletAddress = "0x6C3d502f1a97d4470b881015b83D9Dd1062172e1" var signature: string var res = waku_swap_contracts.signCheque(aliceSwapAddress) @@ -132,9 +133,9 @@ proc sendCheque*(ws: WakuSwap) {.async.} = # To test code paths, this should look different in a production setting warn "Something went wrong when signing cheque, sending anyway" - info "Signed Cheque", swapAddress = aliceSwapAddress, signature = signature + info "Signed Cheque", swapAddress = aliceSwapAddress, signature = signature, issuerAddress = aliceWalletAddress let sigBytes = cast[seq[byte]](signature) - await connOpt.get().writeLP(Cheque(amount: 1, signature: sigBytes).encode().buffer) + await connOpt.get().writeLP(Cheque(amount: 1, signature: sigBytes, issuerAddress: aliceWalletAddress).encode().buffer) # Set new balance let peerId = peer.peerId @@ -148,6 +149,14 @@ proc handleCheque*(ws: WakuSwap, cheque: Cheque) = let peerOpt = ws.peerManager.selectPeer(WakuSwapCodec) let peerId = peerOpt.get().peerId + # Get the original signer using web3. For now, a static value (0x6C3d502f1a97d4470b881015b83D9Dd1062172e1) will be used. + # Check if web3.eth.personal.ecRecover(messageHash, signature); or an equivalent function has been implemented in nim-web3 + let signer = "0x6C3d502f1a97d4470b881015b83D9Dd1062172e1" + + # Verify that the Issuer was the signer of the signature + if signer != cheque.issuerAddress: + warn "Invalid cheque: The address of the issuer is different from the signer." + # TODO Redeem cheque here var signature = cast[string](cheque.signature) # TODO Where should Alice Swap Address come from? Handshake probably? diff --git a/waku/v2/protocol/waku_swap/waku_swap_types.nim b/waku/v2/protocol/waku_swap/waku_swap_types.nim index 603142398..7d34ca2f9 100644 --- a/waku/v2/protocol/waku_swap/waku_swap_types.nim +++ b/waku/v2/protocol/waku_swap/waku_swap_types.nim @@ -21,14 +21,14 @@ type disconnectThreshold* : int Beneficiary* = seq[byte] - + # TODO Consider adding payment threshhold and terms field Handshake* = object beneficiary*: Beneficiary - # XXX I'm confused by lack of signature here, most important thing... # TODO Look over these data structures again Cheque* = object + issuerAddress*: string beneficiary*: Beneficiary date*: uint32 amount*: uint32