@@ -142,6 +142,11 @@ type Packet struct {
142142 // derived.
143143 XPubs []XPub
144144
145+ // GenericSignedMessage contains a BIP-0322 generic message to be
146+ // signed. An empty message is a valid message, that's why this field
147+ // is a nillable string.
148+ GenericSignedMessage * string
149+
145150 // Unknowns are the set of custom types (global only) within this PSBT.
146151 Unknowns []* Unknown
147152}
@@ -240,8 +245,9 @@ func NewFromRawBytes(r io.Reader, b64 bool) (*Packet, error) {
240245 // Next we parse any unknowns that may be present, making sure that we
241246 // break at the separator.
242247 var (
243- xPubSlice []XPub
244- unknownSlice []* Unknown
248+ xPubSlice []XPub
249+ genericSignedMessage * string
250+ unknownSlice []* Unknown
245251 )
246252 for {
247253 keyint , keydata , err := getKey (r )
@@ -275,6 +281,12 @@ func NewFromRawBytes(r io.Reader, b64 bool) (*Packet, error) {
275281
276282 xPubSlice = append (xPubSlice , * xPub )
277283
284+ case GenericSignedMessageType :
285+ // Golang's default string encoding is UTF-8, so we
286+ // don't need to worry about the encoding here.
287+ messageString := string (value )
288+ genericSignedMessage = & messageString
289+
278290 default :
279291 keyintanddata := []byte {byte (keyint )}
280292 keyintanddata = append (keyintanddata , keydata ... )
@@ -313,11 +325,12 @@ func NewFromRawBytes(r io.Reader, b64 bool) (*Packet, error) {
313325
314326 // Populate the new Packet object.
315327 newPsbt := Packet {
316- UnsignedTx : msgTx ,
317- Inputs : inSlice ,
318- Outputs : outSlice ,
319- XPubs : xPubSlice ,
320- Unknowns : unknownSlice ,
328+ UnsignedTx : msgTx ,
329+ Inputs : inSlice ,
330+ Outputs : outSlice ,
331+ XPubs : xPubSlice ,
332+ GenericSignedMessage : genericSignedMessage ,
333+ Unknowns : unknownSlice ,
321334 }
322335
323336 // Extended sanity checking is applied here to make sure the
@@ -369,6 +382,17 @@ func (p *Packet) Serialize(w io.Writer) error {
369382 }
370383 }
371384
385+ // Serialize the generic signed message.
386+ if p .GenericSignedMessage != nil {
387+ msgBytes := []byte (* p .GenericSignedMessage )
388+ err := serializeKVPairWithType (
389+ w , uint8 (GenericSignedMessageType ), nil , msgBytes ,
390+ )
391+ if err != nil {
392+ return err
393+ }
394+ }
395+
372396 // Unknown is a special case; we don't have a key type, only a key and
373397 // a value field
374398 for _ , kv := range p .Unknowns {
0 commit comments