watchtower/wtdb/breach_hint: redefine breach hint as sha(txid)
This commit is contained in:
1 file changed
+8
-4
@@ -1,23 +1,27 @@
|
|||||||
package blob
|
package blob
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
|
||||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
)
|
)
|
||||||
|
|
||||||
// BreachHintSize is the length of the txid prefix used to identify remote
|
// BreachHintSize is the length of the identifier used to detect remote
|
||||||
// commitment broadcasts.
|
// commitment broadcasts.
|
||||||
const BreachHintSize = 16
|
const BreachHintSize = 16
|
||||||
|
|
||||||
// BreachHint is the first 16-bytes of the txid belonging to a revoked
|
// BreachHint is the first 16-bytes of SHA256(txid), which is used to identify
|
||||||
// commitment transaction.
|
// the breach transaction.
|
||||||
type BreachHint [BreachHintSize]byte
|
type BreachHint [BreachHintSize]byte
|
||||||
|
|
||||||
// NewBreachHintFromHash creates a breach hint from a transaction ID.
|
// NewBreachHintFromHash creates a breach hint from a transaction ID.
|
||||||
func NewBreachHintFromHash(hash *chainhash.Hash) BreachHint {
|
func NewBreachHintFromHash(hash *chainhash.Hash) BreachHint {
|
||||||
|
h := sha256.New()
|
||||||
|
h.Write(hash[:])
|
||||||
|
|
||||||
var hint BreachHint
|
var hint BreachHint
|
||||||
copy(hint[:], hash[:BreachHintSize])
|
copy(hint[:], h.Sum(nil))
|
||||||
return hint
|
return hint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user