Skip to content

Commit

Permalink
Promise signer can pay for service consumer
Browse files Browse the repository at this point in the history
  • Loading branch information
tadovas committed Jun 1, 2018
1 parent a8c435f commit 6f31d9c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 2 additions & 2 deletions contracts/IdentityPromises.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ contract IdentityPromises is IdentityRegistry , IdentityBalances {

}

function clearPromise(bytes32 receiverAndSigns, uint256 seq, uint256 amount,
function clearPromise(bytes32 receiverAndSigns, bytes32 extraDataHash, uint256 seq, uint256 amount,
bytes32 sender_R, bytes32 sender_S,
bytes32 receiver_R, bytes32 receiver_S) public returns (bool) {
(address receiver, uint8 sender_V, uint8 receiver_V) = Utils.unpackSignatureAndSigns(receiverAndSigns);
bytes32 promiseHash = keccak256(abi.encodePacked(ISSUER_PREFIX, receiver , seq , amount));
bytes32 promiseHash = keccak256(abi.encodePacked(ISSUER_PREFIX, extraDataHash, receiver, seq , amount));

address sender = ecrecover(promiseHash, sender_V , sender_R, sender_S);
address recoveredReceiver = ecrecover(keccak256(abi.encodePacked(RECEIVER_PREFIX, promiseHash , sender)), receiver_V , receiver_R, receiver_S);
Expand Down
5 changes: 5 additions & 0 deletions promises/clearing.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ func (pc *PromiseClearing) ClearReceivedPromise(promise * ReceivedPromise) error
var packedAddressAndSigns [32]byte
addressAndSigns := append([]byte{issuerSig.V, receiverSig.V} , promise.Receiver.Bytes()...)
copy(packedAddressAndSigns[10:32] , addressAndSigns)

var extraDataHash[32]byte
copy(extraDataHash[:], promise.ConsumerHash())

_ , err = pc.ClearPromise(
packedAddressAndSigns,
extraDataHash,
big.NewInt(promise.SeqNo),
big.NewInt(promise.Amount),
issuerSig.R,
Expand Down
7 changes: 6 additions & 1 deletion promises/promise.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@ import (
)

type Promise struct {
ServiceConsumer common.Address
Receiver common.Address
SeqNo int64
Amount int64
}

const issuerPrefix = "Issuer prefix:"

func (p * Promise) ConsumerHash() []byte {
return crypto.Keccak256(p.ServiceConsumer.Bytes())
}

func (p * Promise) HashBytes() []byte {
return crypto.Keccak256([]byte(issuerPrefix) , p.Receiver.Bytes(), abi.U256(big.NewInt(p.SeqNo)), abi.U256(big.NewInt(p.Amount)))
return crypto.Keccak256([]byte(issuerPrefix) , p.ConsumerHash(), p.Receiver.Bytes(), abi.U256(big.NewInt(p.SeqNo)), abi.U256(big.NewInt(p.Amount)))
}


Expand Down

0 comments on commit 6f31d9c

Please sign in to comment.