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

Method sign_input

code-ch13/tx.py:358–373  ·  view source on GitHub ↗

Signs the input using the private key

(self, input_index, private_key)

Source from the content-addressed store, hash-verified

356 return True
357
358 def sign_input(self, input_index, private_key):
359 '''Signs the input using the private key'''
360 # get the signature hash (z)
361 z = self.sig_hash(input_index)
362 # get der signature of z from private key
363 der = private_key.sign(z).der()
364 # append the SIGHASH_ALL to der (use SIGHASH_ALL.to_bytes(1, 'big'))
365 sig = der + SIGHASH_ALL.to_bytes(1, 'big')
366 # calculate the sec
367 sec = private_key.point.sec()
368 # initialize a new script with [sig, sec] as the cmds
369 script_sig = Script([sig, sec])
370 # change input's script_sig to new script
371 self.tx_ins[input_index].script_sig = script_sig
372 # return whether sig is valid using self.verify_input
373 return self.verify_input(input_index)
374
375 def is_coinbase(self):
376 '''Returns whether this transaction is a coinbase transaction or not'''

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