zpay32: update parsing to use new lnwire.Sig API
This commit is contained in:
parent
6751cd8b9f
commit
9f0214428a
@ -327,8 +327,8 @@ func Decode(invoice string) (*Invoice, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var sigBytes [64]byte
|
var sig lnwire.Sig
|
||||||
copy(sigBytes[:], sigBase256[:64])
|
copy(sig[:], sigBase256[:64])
|
||||||
recoveryID := sigBase256[64]
|
recoveryID := sigBase256[64]
|
||||||
|
|
||||||
// The signature is over the hrp + the data the invoice, encoded in
|
// The signature is over the hrp + the data the invoice, encoded in
|
||||||
@ -347,8 +347,7 @@ func Decode(invoice string) (*Invoice, error) {
|
|||||||
// If the destination pubkey was provided as a tagged field, use that
|
// If the destination pubkey was provided as a tagged field, use that
|
||||||
// to verify the signature, if not do public key recovery.
|
// to verify the signature, if not do public key recovery.
|
||||||
if decodedInvoice.Destination != nil {
|
if decodedInvoice.Destination != nil {
|
||||||
var signature *btcec.Signature
|
signature, err := sig.ToSignature()
|
||||||
err := lnwire.DeserializeSigFromWire(&signature, sigBytes)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to deserialize "+
|
return nil, fmt.Errorf("unable to deserialize "+
|
||||||
"signature: %v", err)
|
"signature: %v", err)
|
||||||
@ -358,7 +357,7 @@ func Decode(invoice string) (*Invoice, error) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
headerByte := recoveryID + 27 + 4
|
headerByte := recoveryID + 27 + 4
|
||||||
compactSign := append([]byte{headerByte}, sigBytes[:]...)
|
compactSign := append([]byte{headerByte}, sig[:]...)
|
||||||
pubkey, _, err := btcec.RecoverCompact(btcec.S256(),
|
pubkey, _, err := btcec.RecoverCompact(btcec.S256(),
|
||||||
compactSign, hash)
|
compactSign, hash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -449,18 +448,18 @@ func (invoice *Invoice) Encode(signer MessageSigner) (string, error) {
|
|||||||
// From the header byte we can extract the recovery ID, and the last 64
|
// From the header byte we can extract the recovery ID, and the last 64
|
||||||
// bytes encode the signature.
|
// bytes encode the signature.
|
||||||
recoveryID := sign[0] - 27 - 4
|
recoveryID := sign[0] - 27 - 4
|
||||||
var sigBytes [64]byte
|
var sig lnwire.Sig
|
||||||
copy(sigBytes[:], sign[1:])
|
copy(sig[:], sign[1:])
|
||||||
|
|
||||||
// If the pubkey field was explicitly set, it must be set to the pubkey
|
// If the pubkey field was explicitly set, it must be set to the pubkey
|
||||||
// used to create the signature.
|
// used to create the signature.
|
||||||
if invoice.Destination != nil {
|
if invoice.Destination != nil {
|
||||||
var signature *btcec.Signature
|
signature, err := sig.ToSignature()
|
||||||
err = lnwire.DeserializeSigFromWire(&signature, sigBytes)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("unable to deserialize "+
|
return "", fmt.Errorf("unable to deserialize "+
|
||||||
"signature: %v", err)
|
"signature: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
valid := signature.Verify(hash, invoice.Destination)
|
valid := signature.Verify(hash, invoice.Destination)
|
||||||
if !valid {
|
if !valid {
|
||||||
return "", fmt.Errorf("signature does not match " +
|
return "", fmt.Errorf("signature does not match " +
|
||||||
@ -469,7 +468,7 @@ func (invoice *Invoice) Encode(signer MessageSigner) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Convert the signature to base32 before writing it to the buffer.
|
// Convert the signature to base32 before writing it to the buffer.
|
||||||
signBase32, err := bech32.ConvertBits(append(sigBytes[:], recoveryID), 8, 5, true)
|
signBase32, err := bech32.ConvertBits(append(sig[:], recoveryID), 8, 5, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user