mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-15 17:35:45 +00:00
Add Issuer to Cheque Object (#627)
* Add Issuer to Cheque Object closes #626 * Minor changes * Fix typo in comment * Improve docs * Fix Typo In Comment * Minor changes * Minor changes
This commit is contained in:
parent
2f53c2c60b
commit
c1763362d7
@ -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?
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user