def broadcast(name, data_hash, consensus_hash, private_key, blockchain_client, blockchain_broadcaster=None, pay_fee=True, tx_only=False, public_key=None, testset=False): """ Write a name update into the blockchain. Returns a JSON object with 'data' set to the nulldata and 'transaction_hash' set to the transaction hash on success. """ # sanity check if public_key is None and private_key is None: raise Exception("Missing both public and private key") if not tx_only and private_key is None: raise Exception("Need private key for broadcasting") if blockchain_broadcaster is None: blockchain_broadcaster = blockchain_client from_address = None inputs = None private_key_obj = None if private_key is not None: # ordering directly pubk = BitcoinPrivateKey( private_key ).public_key() public_key = pubk.to_hex() # get inputs and from address using private key private_key_obj, from_address, inputs = analyze_private_key(private_key, blockchain_client) elif public_key is not None: # subsidizing pubk = BitcoinPublicKey( public_key ) from_address = pubk.address() # get inputs from utxo provider inputs = get_unspents( from_address, blockchain_client ) nulldata = build(name, consensus_hash, data_hash=data_hash, testset=testset) outputs = make_op_return_outputs( nulldata, inputs, from_address, fee=DEFAULT_OP_RETURN_FEE, format='hex' ) if tx_only: unsigned_tx = serialize_transaction( inputs, outputs ) return {'unsigned_tx': unsigned_tx} else: signed_tx = tx_serialize_and_sign( inputs, outputs, private_key_obj ) response = broadcast_transaction( signed_tx, blockchain_broadcaster, format='hex') response.update({'data': nulldata}) return response
def broadcast(name, private_key, register_addr, consensus_hash, blockchain_client, fee, blockchain_broadcaster=None, tx_only=False, pay_fee=True, public_key=None, testset=False): """ Builds and broadcasts a preorder transaction. """ # sanity check if public_key is None and private_key is None: raise Exception("Missing both public and private key") if not tx_only and private_key is None: raise Exception("Need private key for broadcasting") if blockchain_broadcaster is None: blockchain_broadcaster = blockchain_client from_address = None inputs = None private_key_obj = None if private_key is not None: # ordering directly pubk = BitcoinPrivateKey( private_key ).public_key() public_key = pubk.to_hex() # get inputs and from address using private key private_key_obj, from_address, inputs = analyze_private_key(private_key, blockchain_client) elif public_key is not None: # subsidizing pubk = BitcoinPublicKey( public_key ) from_address = pubk.address() # get inputs from utxo provider inputs = get_unspents( from_address, blockchain_client ) script_pubkey = get_script_pubkey( public_key ) nulldata = build( name, script_pubkey, register_addr, consensus_hash, testset=testset) # build custom outputs here outputs = make_outputs(nulldata, inputs, from_address, fee, pay_fee=pay_fee, format='hex') if tx_only: unsigned_tx = serialize_transaction( inputs, outputs ) return {"unsigned_tx": unsigned_tx} else: # serialize, sign, and broadcast the tx response = serialize_sign_and_broadcast(inputs, outputs, private_key_obj, blockchain_client) response.update({'data': nulldata}) return response
class AuthResponse(AuthMessage): """ Interface for creating signed auth response tokens, as well as decoding and verifying them. """ verify_methods = [ is_expiration_date_valid, is_issuance_date_valid, do_signatures_match_public_keys, do_public_keys_match_issuer, do_public_keys_match_username ] def __init__(self, private_key, profile=None, username=None, expires_after=None, crypto_backend=default_backend()): """ private_key should be provided in HEX, WIF or binary format profile should be a dictionary username should be a string expires_after should be a float number of seconds """ if not private_key: raise ValueError('Private key is missing') if not profile: profile = {} if not expires_after: expires_after = 30 * 24 * 3600 # next month self.private_key = private_key self.public_key = BitcoinPrivateKey(self.private_key).public_key() self.address = self.public_key.address() self.profile = profile self.username = username self.expires_after = expires_after self.tokenizer = Tokenizer(crypto_backend=crypto_backend) def _payload(self): now = time.time() return { 'jti': str(uuid.uuid4()), 'iat': str(now), 'exp': str(now + self.expires_after), 'iss': make_did_from_address(self.address), 'public_keys': [self.public_key.to_hex()], 'profile': self.profile, 'username': self.username }
def _payload(self): now = time.time() payload = { 'jti': str(uuid.uuid4()), 'iat': str(now), 'exp': str(now + self.expires_after), 'iss': None, 'public_keys': [], 'domain_name': self.domain_name, 'manifest_uri': self.manifest_uri, 'redirect_uri': self.redirect_uri, 'scopes': self.scopes } if self.private_key: public_key = BitcoinPrivateKey(self.private_key).public_key() address = public_key.address() payload['public_keys'] = [public_key.to_hex()] payload['iss'] = make_did_from_address(address) return payload
def broadcast(name, data_hash, consensus_hash, private_key, blockchain_client, blockchain_broadcaster=None, pay_fee=True, tx_only=False, public_key=None, testset=False): """ Write a name update into the blockchain. Returns a JSON object with 'data' set to the nulldata and 'transaction_hash' set to the transaction hash on success. """ # sanity check if public_key is None and private_key is None: raise Exception("Missing both public and private key") if not tx_only and private_key is None: raise Exception("Need private key for broadcasting") if blockchain_broadcaster is None: blockchain_broadcaster = blockchain_client from_address = None inputs = None private_key_obj = None if private_key is not None: # ordering directly pubk = BitcoinPrivateKey(private_key).public_key() public_key = pubk.to_hex() # get inputs and from address using private key private_key_obj, from_address, inputs = analyze_private_key( private_key, blockchain_client) elif public_key is not None: # subsidizing pubk = BitcoinPublicKey(public_key) from_address = pubk.address() # get inputs from utxo provider inputs = get_unspents(from_address, blockchain_client) nulldata = build(name, consensus_hash, data_hash=data_hash, testset=testset) outputs = make_op_return_outputs(nulldata, inputs, from_address, fee=DEFAULT_OP_RETURN_FEE, format='hex') if tx_only: unsigned_tx = serialize_transaction(inputs, outputs) return {'unsigned_tx': unsigned_tx} else: signed_tx = tx_serialize_and_sign(inputs, outputs, private_key_obj) response = broadcast_transaction(signed_tx, blockchain_broadcaster, format='hex') response.update({'data': nulldata}) return response
def broadcast(name, private_key, register_addr, consensus_hash, blockchain_client, fee, blockchain_broadcaster=None, tx_only=False, pay_fee=True, public_key=None, testset=False): """ Builds and broadcasts a preorder transaction. """ # sanity check if public_key is None and private_key is None: raise Exception("Missing both public and private key") if not tx_only and private_key is None: raise Exception("Need private key for broadcasting") if blockchain_broadcaster is None: blockchain_broadcaster = blockchain_client from_address = None inputs = None private_key_obj = None if private_key is not None: # ordering directly pubk = BitcoinPrivateKey(private_key).public_key() public_key = pubk.to_hex() # get inputs and from address using private key private_key_obj, from_address, inputs = analyze_private_key( private_key, blockchain_client) elif public_key is not None: # subsidizing pubk = BitcoinPublicKey(public_key) from_address = pubk.address() # get inputs from utxo provider inputs = get_unspents(from_address, blockchain_client) script_pubkey = get_script_pubkey(public_key) nulldata = build(name, script_pubkey, register_addr, consensus_hash, testset=testset) # build custom outputs here outputs = make_outputs(nulldata, inputs, from_address, fee, pay_fee=pay_fee, format='hex') if tx_only: unsigned_tx = serialize_transaction(inputs, outputs) return {"unsigned_tx": unsigned_tx} else: # serialize, sign, and broadcast the tx response = serialize_sign_and_broadcast(inputs, outputs, private_key_obj, blockchain_client) response.update({'data': nulldata}) return response