@@ -79,7 +79,13 @@ def create_withdraw_tx(
7979 return cls (lock_time , fee , memo , payload )
8080
8181 def _get_unsigned_bytes (self , buf : bytes ) -> bytes :
82- """Get unsigned bytes of the transaction, including the payload."""
82+ """
83+ Generate the unsigned representation of the transaction,
84+ including flags and payload.
85+
86+ This method appends various transaction components to the buffer
87+ in a specific order, ensuring correct serialization.
88+ """
8389 encoding .append_uint8 (buf , self .flags )
8490 encoding .append_uint8 (buf , self .version )
8591 encoding .append_uint32 (buf , self .lock_time )
@@ -90,17 +96,37 @@ def _get_unsigned_bytes(self, buf: bytes) -> bytes:
9096
9197 return buf
9298
93- def sign (self , private_key : PrivateKey ) -> str :
94- """Make a raw transaction, sign it and return the signed bytes."""
99+ def sign_bytes (self ) -> bytes :
100+ """
101+ Generate the transaction data that needs to be signed.
102+
103+ The signature should be computed over this data, excluding the
104+ transaction flags, which are removed before returning.
105+ """
106+ buf = bytearray ()
107+ sign_bytes = self ._get_unsigned_bytes (buf )
108+
109+ return sign_bytes [1 :] # flags is not part of the sign bytes.
110+
111+ def sign (self , private_key : PrivateKey ) -> bytes :
112+ """
113+ Generate the signed representation of the transaction,
114+ including the flags, payload, and cryptographic signature.
115+
116+ This method first generates the data needs to be signed,
117+ signs it using the provided private key, and then appends
118+ both the signature and the corresponding public key to ensure
119+ verifiability.
120+ """
95121 buf = bytearray ()
96122
97123 sign_bytes = self ._get_unsigned_bytes (buf )
98124 sig = private_key .sign (
99125 bytes (sign_bytes [1 :]),
100- ) # flags is not part of the sign bytes.
126+ )
101127 pub = private_key .public_key ()
102128
103129 encoding .append_fixed_bytes (buf , sig .raw_bytes ())
104130 encoding .append_fixed_bytes (buf , pub .raw_bytes ())
105131
106- return buf . hex ()
132+ return buf
0 commit comments