From 61ea03e4ee955c35aeb45b8dfc7c9fb2558ff232 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 27 Apr 2020 21:40:34 -0700 Subject: [PATCH] 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. --- order/interface.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/order/interface.go b/order/interface.go index ca39433..3c231b7 100644 --- a/order/interface.go +++ b/order/interface.go @@ -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 +}