def ValidateAddress(cls, address): ''' Validate the given Stellar address. Args: address: The public address of a Stellar account. Return: True if public address is valid, False otherwise. ''' try: decode_check('account', address) return True except: return False
def validate_address(address): if len(address) != 56: raise ValueError('invalid address') decoded = decode_check('account', address) if len(decoded) != 32: raise ValueError('invalid address')
def validate_seed(seed): if len(seed) != 56: raise ValueError('invalid seed') decoded = decode_check('seed', seed) if len(decoded) != 32: raise ValueError('invalid seed')
def is_valid_address(address): """Determines if the provided string is a valid Stellar address. :param str address: address to check :return: True if this is a correct address :rtype: boolean """ if len(address) != 56: return False try: decode_check('account', address) return True except: return False
def is_valid_secret_key(key): """Determines if the provided string is a valid Stellar key (seed). :param str key: key to check :return: True if this is a correct seed :rtype: boolean """ if len(key) != 56: return False try: decode_check('seed', key) return True except: return False
async def generate_payment_from_request(request: web.Request) -> web.Response: """AIOHttp Request unsigned transfer transaction""" body = await request.json() source_account = request.match_info.get("wallet_address", "") transaction_source_address = body['transaction_source_address'] target_address = body['target_address'] amount_hot = body.get('amount_htkn') amount_xlm = body.get('amount_xlm') tax_amount_hot = body.get('tax_amount_htkn', None) sequence_number = body.get('sequence_number', None) memo = body.get('memo', None) memo_on = body.get('memo_on', 'source') await get_wallet(source_account) if memo_on not in ['destination', 'source']: raise web.HTTPBadRequest( reason='memo_on should be only "source" or "destination"') try: decode_check('account', target_address) except DecodeError as e: raise web.HTTPBadRequest( reason='Invalid value : {}'.format(target_address)) if memo: focus_address = target_address if memo_on == 'destination' else source_account url_get_transaction = await get_transaction_by_memo( focus_address, memo) if url_get_transaction: raise web.HTTPBadRequest(reason="Transaction is already submitted") if not sequence_number: wallet = await get_stellar_wallet(transaction_source_address) sequence_number = wallet.sequence result = await generate_payment( transaction_source_address, source_account, target_address, amount_hot, amount_xlm, tax_amount_hot, sequence_number, memo, ) return web.json_response(result)
def ValidateSeed(cls, seed): ''' Validate the given private Stellar key. Args: seed: The private key of a Stellar account. Return: True if the secret key is valid, False otherwise. ''' return decode_check('seed', seed)
def __addressToPk(cls, address): ''' Transform the stellar address (encoded ed25519 public key) to the coresponding curve25519 public key. Args: address: This is your Stellar address starting with letter 'G'. Returns: curve25519 public key as byte array. ''' return VerifyKey(decode_check('account', address)).to_curve25519_public_key()._public_key
def test_decode_check(self): assert type(utils.decode_check('account', self.account)) is bytes
def test_decode_check_raise(self): with pytest.raises(DecodeError, match='Invalid version byte'): utils.decode_check( 'seed', 'GD6H3MA2SIQ3HLSKUVAJ5SJDXM7UWJ4L5N4HMIG3QBDB22GZ5MQPRAGF')
def test_decode_check(self): assert type(utils.decode_check('account', self.account)) is bytes