MCPcopy Index your code
hub / github.com/jimmysong/programmingbitcoin / sign_input

Method sign_input

code-ch08/tx.py:232–247  ·  view source on GitHub ↗

Signs the input using the private key

(self, input_index, private_key)

Source from the content-addressed store, hash-verified

230 return True
231
232 def sign_input(self, input_index, private_key):
233 '''Signs the input using the private key'''
234 # get the signature hash (z)
235 z = self.sig_hash(input_index)
236 # get der signature of z from private key
237 der = private_key.sign(z).der()
238 # append the SIGHASH_ALL to der (use SIGHASH_ALL.to_bytes(1, 'big'))
239 sig = der + SIGHASH_ALL.to_bytes(1, 'big')
240 # calculate the sec
241 sec = private_key.point.sec()
242 # initialize a new script with [sig, sec] as the cmds
243 script_sig = Script([sig, sec])
244 # change input's script_sig to new script
245 self.tx_ins[input_index].script_sig = script_sig
246 # return whether sig is valid using self.verify_input
247 return self.verify_input(input_index)
248
249
250class TxIn:

Callers 1

test_sign_inputMethod · 0.45

Calls 6

sig_hashMethod · 0.95
verify_inputMethod · 0.95
ScriptClass · 0.90
derMethod · 0.45
signMethod · 0.45
secMethod · 0.45

Tested by 1

test_sign_inputMethod · 0.36