Skip to content

Commit

Permalink
Fix psbt serializations to always be consistent
Browse files Browse the repository at this point in the history
Sort items before serializing so that the same psbt will always be
serialized the same way.
  • Loading branch information
achow101 committed Dec 4, 2018
1 parent d01cbae commit a277ac2
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions hwilib/serializations.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ def DeserializeHDKeypath(f, key, hd_keypaths):

def SerializeHDKeypath(hd_keypaths, type):
r = b""
for pubkey, path in hd_keypaths.items():
for pubkey, path in sorted(hd_keypaths.items()):
r += ser_string(type + pubkey)
packed = struct.pack("<" + "I" * len(path), *path)
r += ser_string(packed)
Expand Down Expand Up @@ -638,7 +638,7 @@ def serialize(self):
r += ser_string(tx)

if len(self.final_script_sig) == 0 and self.final_script_witness.is_null():
for pubkey, sig in self.partial_sigs.items():
for pubkey, sig in sorted(self.partial_sigs.items()):
r += ser_string(b"\x02" + pubkey)
r += ser_string(sig)

Expand All @@ -664,7 +664,7 @@ def serialize(self):
r += ser_string(b"\x08")
r += self.final_script_witness.serialize()

for key, value in self.unknown:
for key, value in sorted(self.unknown.items()):
r += ser_string(key)
r += ser_string(value)

Expand Down Expand Up @@ -745,7 +745,7 @@ def serialize(self):

r += SerializeHDKeypath(self.hd_keypaths, b"\x02")

for key, value in self.unknown:
for key, value in sorted(self.unknown.items()):
r += ser_string(key)
r += ser_string(value)

Expand All @@ -762,7 +762,7 @@ def __init__(self, tx = None):
self.tx = CTransaction()
self.inputs = []
self.outputs = []
self.unknown = []
self.unknown = {}

def deserialize(self, psbt):
hexstring = Base64ToHex(psbt.strip())
Expand Down Expand Up @@ -860,7 +860,7 @@ def serialize(self):
r += b"\x00"

# unknowns
for key, value in self.unknown:
for key, value in sorted(self.unknown.items()):
r += ser_string(key)
r += ser_string(value)

Expand Down

0 comments on commit a277ac2

Please sign in to comment.