Skip to content

Commit 989e720

Browse files
author
Vizeet Srivastava
committed
added priv key generation for hd wallet, added interfaces for offline txn signing
1 parent 491de3d commit 989e720

5 files changed

+75
-4
lines changed

hd_wallet.py

+25-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,34 @@
33
import hmac
44
import pbkdf2
55
import binascii
6+
import optparse
67

7-
def generate_seed_from_str(code: str, seed: str):
8-
seed = pbkdf2.pbkdf2(hashlib.sha512, code, seed, 2048, 64)
8+
def generateSeedFromStr(code: str, salt: str):
9+
seed = pbkdf2.pbkdf2(hashlib.sha512, code, salt, 2048, 64)
910
print('seed = %s' % bytes.decode(binascii.hexlify(seed)))
1011
return seed
1112

13+
def generatePrivateKey(seed: bytes, code: str):
14+
h = hmac.new(seed, code.encode('utf-8'), hashlib.sha512).digest()
15+
private_key = h[0:32]
16+
chaincode = h[32:64]
17+
return private_key, chaincode
18+
19+
# K = k * G
20+
def getPubkeyFromPrivkey(private_key: bytes):
21+
pass
22+
1223
if __name__ == '__main__':
24+
parser = optparse.OptionParser(usage="python3 hd_wallet.py -s <Salt>")
25+
parser.add_option('-s', '--salt', action='store', dest='salt', help='Add salt to secret')
26+
(args, _) = parser.parse_args()
27+
if args.salt == None:
28+
logging.error ("Missing required argument")
29+
sys.exit(1)
30+
1331
mnemonic_code = mnemonic_code.getMnemonicWordCodeString()
14-
generate_seed_from_str(mnemonic_code, 'testnewseed')
32+
seed = generateSeedFromStr(mnemonic_code, args.salt)
33+
34+
private_key, chaincode = generatePrivateKey(seed, mnemonic_code)
35+
36+
print('privake key = %s' % bytes.decode(binascii.hexlify(private_key)))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
def getNewAddress():
2+
pass
3+
4+
def pushRawP2PKHTxn():
5+
pass
6+
7+
def pushRawP2SHTxn():
8+
pass
9+
10+
def pushRawBareP2WPKHTxn():
11+
pass
12+
13+
def pushRawBareP2WSHTxn():
14+
pass
15+
16+
def pushRawP2SH_P2WPKHTxn():
17+
pass
18+
19+
def pushRawP2SH_P2WSHTxn():
20+
pass
21+
22+
def getSignedTxn():
23+
pass

perform_transaction.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import requests
2+
3+
def getUnspentTxnList(address: str):
4+
url = 'https://blockchain.info/unspent?active=%s' % address
5+
response = requests.get(url)
6+
jsonobj = json.loads(response.text)
7+
return jsonobj
8+
9+
# just be little smart here
10+
def selectUnspentTxnsForAmount(jsonobj, amount: str):
11+
pass
12+
13+
def askNewAddress():
14+
pass
15+
16+
def

random_number_generator.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,21 @@ def getRawMicOutput():
4444

4545
def get256BitRandomNumber():
4646
h = hashlib.sha256()
47+
48+
# update with raw camera output
4749
raw_photo = getRawCameraOutput()
4850
h.update(raw_photo)
51+
52+
# update with raw mic output
4953
raw_sound = getRawMicOutput()
50-
print('raw sound = %s' % bytes.decode(binascii.hexlify(raw_sound)))
54+
# print('raw sound = %s' % bytes.decode(binascii.hexlify(raw_sound)))
5155
h.update(raw_sound)
56+
57+
# update with system random number
58+
sys_rand = '%x' % random.SystemRandom().randint(0, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)
59+
sys_rand_b = binascii.unhexlify(sys_rand)
60+
h.update(sys_rand_b)
61+
5262
h_b = h.digest()
5363
return h_b
5464

sign_transaction.py

Whitespace-only changes.

0 commit comments

Comments
 (0)