client/order: add new PendingChanKey function

The mapping in this function ensures that a given bid/ask pair will have
a unique deterministic pending channel ID to use when registering
funding shims and also making channels.
This commit is contained in:
Olaoluwa Osuntokun 2020-04-27 21:40:34 -07:00
parent 9f9e7d7cb6
commit 61ea03e4ee

View file

@ -426,3 +426,19 @@ type ServerOrderParams struct {
// trader's account key.
RawSig []byte
}
// PendingChanKey calculates the pending channel ID to be used for funding
// purposes for a given bid and ask. The pending channel ID must be unique, so
// we use the hash of the concatenation of the two nonces: sha256(askNonce ||
// bidNonce).
func PendingChanKey(askNonce, bidNonce Nonce) [32]byte {
var pid [32]byte
h := sha256.New()
_, _ = h.Write(askNonce[:])
_, _ = h.Write(bidNonce[:])
copy(pid[:], h.Sum(nil))
return pid
}