-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwallet.py
40 lines (32 loc) · 1014 Bytes
/
wallet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import binascii
import Crypto
import Crypto.Random
from Crypto.Hash import SHA
from Crypto.PublicKey import RSA
from Crypto.Signature import PKCS1_v1_5
import hashlib
import json
from time import time
from urllib.parse import urlparse
from uuid import uuid4
from utils import create_logger
logger = create_logger(__name__)
class Wallet:
def __init__(self, utxos_arg=[]):
self.public_key, self.private_key = self.generate_rsa()
self.utxos = utxos_arg
def balance(self):
ret = 0
for utxo in self.utxos:
ret = ret + utxo.amount
return ret
def generate_rsa(self, bits=2048):
'''
Generate an RSA keypair with an exponent of 65537 in PEM format
param: bits The key length in bits
Return private key and public key
'''
new_key = RSA.generate(bits, e=65537)
public_key = new_key.publickey().exportKey("PEM")
private_key = new_key.exportKey("PEM")
return public_key, private_key