def account_from_seed(secret): seed = seed_from_human(secret) public_key = crypto.get_public_key(seed) account = crypto.hash160(public_key) account = account_to_human(account) return account
def register_user(name, email, token): # Generamos las claves para el nuevo usuario crypto.generate_rsa() # Obtenemos la clave publica public_key = crypto.get_public_key() # Completamos todos lo campos necesarios para realizar la solicitud url = URL_API_USERS + "/register" header = { 'Authorization': 'Bearer ' + token, } args = { 'nombre': name, 'email': email, 'publicKey': public_key.decode('utf-8'), } # Llamada a la API con los datos que hemos completado para crear el usuario. response = requests.post(url, headers=header, json=args) # No hay caso de fallo. La llamada a la API siempre devuelve HTTP 200 print("Identidad creada con los siguientes datos:") print("\t - Nombre: " + response.json()['nombre']) print("\t - Email: " + email) print("\t - Fecha creacion: " + time.strftime("%D %H:%M", time.localtime(response.json()['ts'])))
def generate_keypair(): """ Generate an address and a secret key """ seed = os.urandom(32) public_key = crypto.get_public_key(seed) account = crypto.hash160(public_key) account = address.account_to_human(account) seed = address.seed_to_human(seed) return account, seed
def initialize_own_device(**kwargs): own_device = Device(**kwargs) own_device.set_public_key(crypto.get_public_key()) own_device.sign(device=own_device) own_device.save(own_device=own_device) metadata = own_device.get_metadata() metadata.is_own_device = True metadata.is_trusted = settings.CENTRAL_SERVER metadata.save() return own_device
def sign(tx_json, secret, test=False): """ Signs a transaction with the secret and returns a tx_blob """ seed = address.seed_from_human(secret) pubkey = crypto.get_public_key(seed) tx_json['SigningPubKey'] = pubkey tx_blob = serialize.serialize_json(tx_json) signature = _sign_blob(tx_blob, seed, test) tx_json['TxnSignature'] = signature tx_blob = serialize.serialize_json(tx_json) return utils.to_hex(tx_blob)
def __init__(self): self.private_key = generate_key() self.public_key = get_public_key(self.private_key) self.public_key_serial = serialize_public_key(self.public_key) my_print("My pub key (serial): {0}".format(self.public_key_serial))