lnwallet: update state hint derivation to match BOLT-0003

This commit is contained in:
Olaoluwa Osuntokun 2017-07-29 18:39:58 -07:00
parent ca45ae7524
commit 7b002175f4
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -1339,22 +1339,24 @@ func (l *LightningWallet) deriveMasterRevocationRoot() (*btcec.PrivateKey, error
}
// deriveStateHintObfuscator derives the bytes to be used for obfuscating the
// state hints from the root to be used for a new channel. The
// obfuscator is generated by performing an additional sha256 hash of the first
// child derived from the revocation root. The leading 4 bytes are used for the
// obfuscator.
func deriveStateHintObfuscator(producer shachain.Producer) ([StateHintSize]byte, error) {
// state hints from the root to be used for a new channel. The obsfucsator is
// generated via the following computation:
//
// * sha256(initiatorKey || responderKey)[:6]
// * where both keys are the multi-sig keys of the respective parties
//
// The first 6 bytes of the resulting hash are used as the state hint.
func deriveStateHintObfuscator(key1, key2 *btcec.PublicKey) [StateHintSize]byte {
h := sha256.New()
h.Write(key1.SerializeCompressed())
h.Write(key2.SerializeCompressed())
sha := h.Sum(nil)
var obfuscator [StateHintSize]byte
copy(obfuscator[:], sha[:])
firstChild, err := producer.AtIndex(0)
if err != nil {
return obfuscator, err
}
grandChild := sha256.Sum256(firstChild[:])
copy(obfuscator[:], grandChild[:])
return obfuscator, nil
return obfuscator
}
// initStateHints properly sets the obsfucated state hints on both commitment
@ -1408,8 +1410,8 @@ func selectInputs(amt btcutil.Amount, coins []*Utxo) (btcutil.Amount, []*wire.Ou
return satSelected, selectedUtxos, nil
}
// coinSelect attemps to select a sufficient amount of coins, including a
// change output to fund amt satoshis, adhearing to the specified fee rate. The
// coinSelect attempts to select a sufficient amount of coins, including a
// change output to fund amt satoshis, adhering to the specified fee rate. The
// specified fee rate should be expressed in sat/byte for coin selection to
// function properly.
func coinSelect(feeRate uint64, amt btcutil.Amount,