zpay32: add payment metadata field

This commit is contained in:
Joost Jager committed 2022-04-13 22:55:38 +02:00
1 parent 044286ae2c
commit 135e27ddd3
4 files changed
+75 -5

No files matched your search

+15
View File
@@ -229,6 +229,15 @@ func parseTaggedFields(invoice *Invoice, fields []byte, net *chaincfg.Params) er
}
invoice.Description, err = parseDescription(base32Data)
case fieldTypeM:
if invoice.Metadata != nil {
// We skip the field if we have already seen a
// supported one.
continue
}
invoice.Metadata, err = parseMetadata(base32Data)
case fieldTypeN:
if invoice.Destination != nil {
// We skip the field if we have already seen a
@@ -345,6 +354,12 @@ func parseDescription(data []byte) (*string, error) {
return &description, nil
}
// parseMetadata converts the data (encoded in base32) into a byte slice to use
// as the metadata.
func parseMetadata(data []byte) ([]byte, error) {
return bech32.ConvertBits(data, 5, 8, false)
}
// parseDestination converts the data (encoded in base32) into a 33-byte public
// key of the payee node.
func parseDestination(data []byte) (*btcec.PublicKey, error) {