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.
@@ -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
+}
