mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-29 03:01:52 +01:00
lnwire: add MsgHash helper
This commit adds the MsgHash helper funcion which can be used to calculate the digest of a message to be signed using schnorr signatures.
This commit is contained in:
parent
81c83f39d3
commit
9be42b09a0
30
lnwire/msg_hash.go
Normal file
30
lnwire/msg_hash.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package lnwire
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||||
|
)
|
||||||
|
|
||||||
|
// MsgHashTag will prefix the message name and the field name in order to
|
||||||
|
// construct the message tag.
|
||||||
|
const MsgHashTag = "lightning"
|
||||||
|
|
||||||
|
// MsgTag computes the full tag that will be used to prefix a message before
|
||||||
|
// calculating the tagged hash. The tag is constructed as follows:
|
||||||
|
//
|
||||||
|
// tag = "lightning"||"msg_name"||"field_name"
|
||||||
|
func MsgTag(msgName, fieldName string) []byte {
|
||||||
|
tag := []byte(MsgHashTag)
|
||||||
|
tag = append(tag, []byte(msgName)...)
|
||||||
|
|
||||||
|
return append(tag, []byte(fieldName)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MsgHash computes the tagged hash of the given message as follows:
|
||||||
|
//
|
||||||
|
// tag = "lightning"||"msg_name"||"field_name"
|
||||||
|
// hash = sha256(sha246(tag) || sha256(tag) || msg)
|
||||||
|
func MsgHash(msgName, fieldName string, msg []byte) *chainhash.Hash {
|
||||||
|
tag := MsgTag(msgName, fieldName)
|
||||||
|
|
||||||
|
return chainhash.TaggedHash(tag, msg)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user