def setup_multisig(): client_master_account = server.load_account( client_master_keypair.public_key) te = TransactionBuilder(client_master_account, network_passphrase) \ .append_ed25519_public_key_signer(client_signer_keypair1.public_key, 40) \ .append_ed25519_public_key_signer(client_signer_keypair2.public_key, 60) \ .append_set_options_op(master_weight=0, low_threshold=1, med_threshold=10, high_threshold=100) \ .build() te.sign(client_master_keypair) resp = server.submit_transaction(te) print(resp)
def test_verify_challenge_tx_sequence_not_zero(self): server_kp = Keypair.random() client_kp = Keypair.random() network_passphrase = Network.PUBLIC_NETWORK_PASSPHRASE anchor_name = "SDF" now = int(time.time()) nonce = os.urandom(48) nonce_encoded = base64.b64encode(nonce) server_account = Account(server_kp.public_key, 10086) challenge_te = (TransactionBuilder( server_account, network_passphrase, 100).append_manage_data_op( data_name="{} auth".format(anchor_name), data_value=nonce_encoded, source=client_kp.public_key, ).add_time_bounds(now, now + 900).build()) challenge_te.sign(server_kp) challenge_te.sign(client_kp) challenge_tx_signed = challenge_te.to_xdr() with pytest.raises( InvalidSep10ChallengeError, match="The transaction sequence number should be zero.", ): verify_challenge_transaction(challenge_tx_signed, server_kp.public_key, network_passphrase)
def test_verify_challenge_tx_not_within_range_of_the_specified_timebounds( self): server_kp = Keypair.random() client_kp = Keypair.random() network_passphrase = Network.PUBLIC_NETWORK_PASSPHRASE anchor_name = "SDF" now = int(time.time()) nonce = os.urandom(48) nonce_encoded = base64.b64encode(nonce) server_account = Account(server_kp.public_key, -1) challenge_te = (TransactionBuilder( server_account, network_passphrase, 100).append_manage_data_op( data_name="{} auth".format(anchor_name), data_value=nonce_encoded, source=client_kp.public_key, ).add_time_bounds(now - 100, now - 50).build()) challenge_te.sign(server_kp) challenge_te.sign(client_kp) challenge_tx_signed = challenge_te.to_xdr() with pytest.raises( InvalidSep10ChallengeError, match= "Transaction is not within range of the specified timebounds.", ): verify_challenge_transaction(challenge_tx_signed, server_kp.public_key, network_passphrase)
def test_verify_challenge_tx_transaction_is_not_signed_by_the_server(self): server_kp = Keypair.random() client_kp = Keypair.random() network_passphrase = Network.PUBLIC_NETWORK_PASSPHRASE anchor_name = "SDF" timeout = 900 now = int(time.time()) server_keypair = Keypair.from_secret(server_kp.secret) server_account = Account(account_id=server_keypair.public_key, sequence=-1) transaction_builder = TransactionBuilder(server_account, network_passphrase, 100) transaction_builder.add_time_bounds(min_time=now, max_time=now + timeout) nonce = os.urandom(48) nonce_encoded = base64.b64encode(nonce) transaction_builder.append_manage_data_op( data_name="{} auth".format(anchor_name), data_value=nonce_encoded, source=client_kp.public_key, ) challenge = transaction_builder.build().to_xdr() transaction = TransactionEnvelope.from_xdr(challenge, network_passphrase) transaction.sign(client_kp) challenge_tx = transaction.to_xdr() with pytest.raises( InvalidSep10ChallengeError, match="Transaction not signed by server: {}".format( server_kp.public_key), ): verify_challenge_transaction(challenge_tx, server_kp.public_key, network_passphrase)
def test_verify_transaction_signatures_raise_no_signature(self): server_kp = Keypair.random() client_kp = Keypair.random() network_passphrase = Network.PUBLIC_NETWORK_PASSPHRASE anchor_name = "SDF" now = int(time.time()) nonce = os.urandom(48) nonce_encoded = base64.b64encode(nonce) server_account = Account(server_kp.public_key, -1) challenge_te = (TransactionBuilder( server_account, network_passphrase, 100).append_manage_data_op( data_name="{} auth".format(anchor_name), data_value=nonce_encoded, source=client_kp.public_key, ).add_time_bounds(now, now + 900).build()) signers = [] with pytest.raises(InvalidSep10ChallengeError, match="Transaction has no signatures."): _verify_transaction_signatures(challenge_te, signers)
def test_verify_challenge_tx_donot_contain_managedata_operation(self): server_kp = Keypair.random() client_kp = Keypair.random() network_passphrase = Network.PUBLIC_NETWORK_PASSPHRASE now = int(time.time()) server_account = Account(server_kp.public_key, -1) challenge_te = (TransactionBuilder( server_account, network_passphrase, 100).append_set_options_op().add_time_bounds(now, now + 900).build()) challenge_te.sign(server_kp) challenge_te.sign(client_kp) challenge_tx_signed = challenge_te.to_xdr() with pytest.raises(InvalidSep10ChallengeError, match="Operation type should be ManageData."): verify_challenge_transaction(challenge_tx_signed, server_kp.public_key, network_passphrase)
async def main(): # Configure paydexSdk to talk to the horizon instance hosted by paydex.org # When we use the `with` syntax, it automatically releases the resources it occupies. async with Server(horizon_url="https://testhorizon.paydex.io//", client=AiohttpClient()) as server: # Transactions require a valid sequence number that is specific to this account. # We can fetch the current sequence number for the source account from Horizon. source_account = await server.load_account(source_public_key) base_fee = await server.fetch_base_fee() # we are going to submit the transaction to the test network, # so network_passphrase is `Network.TESTNET_NETWORK_PASSPHRASE`, # if you want to submit to the public network, please use `Network.PUBLIC_NETWORK_PASSPHRASE`. transaction = ( TransactionBuilder( source_account=source_account, network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE, base_fee=base_fee, ).add_text_memo("Hello, paydex!") # Add a memo # Add a payment operation to the transaction # Send 350.1234567 PAYDEX to receiver # Specify 350.1234567 lumens. Lumens are divisible to seven digits past the decimal. .append_payment_op(receiver_public_key, "350.1234567", "PAYDEX"). set_timeout( 30) # Make this transaction valid for the next 30 seconds only .build()) # Sign this transaction with the secret key # NOTE: signing is transaction is network specific. Test network transactions # won't work in the public network. To switch networks, use the Network object # as explained above (look for paydex_base_sdk.network.Network). transaction.sign(source_keypair) # Let's see the XDR (encoded in base64) of the transaction we just built print(transaction.to_xdr()) # Submit the transaction to the Horizon server. # The Horizon server will then submit the transaction into the network for us. response = await server.submit_transaction(transaction) print(response)
def test_verify_challenge_tx_dont_contains_timebound(self): server_kp = Keypair.random() client_kp = Keypair.random() network_passphrase = Network.PUBLIC_NETWORK_PASSPHRASE anchor_name = "SDF" nonce = os.urandom(48) nonce_encoded = base64.b64encode(nonce) server_account = Account(server_kp.public_key, -1) challenge_te = (TransactionBuilder( server_account, network_passphrase, 100).append_manage_data_op( data_name="{} auth".format(anchor_name), data_value=nonce_encoded, source=client_kp.public_key, ).build()) challenge_te.sign(server_kp) challenge_te.sign(client_kp) challenge_tx_signed = challenge_te.to_xdr() with pytest.raises(InvalidSep10ChallengeError, match="Transaction requires timebounds."): verify_challenge_transaction(challenge_tx_signed, server_kp.public_key, network_passphrase)
from paydex_base_sdk.asset import Asset from paydex_base_sdk.keypair import Keypair from paydex_base_sdk.network import Network from paydex_base_sdk.server import Server from paydex_base_sdk.transaction_builder import TransactionBuilder server = Server(horizon_url="https://testhorizon.paydex.io//") source_keypair = Keypair.from_secret( "SA6XHAH4GNLRWWWF6TEVEWNS44CBNFAJWHWOPZCVZOUXSQA7BOYN7XHC") source_account = server.load_account(account_id=source_keypair.public_key) path = [ Asset("USD", "GBBM6BKZPEHWYO3E3YKREDPQXMS4VK35YLNU7NFBRI26RAN7GI5POFBB"), Asset("EUR", "GDTNXRLOJD2YEBPKK7KCMR7J33AAG5VZXHAJTHIG736D6LVEFLLLKPDL") ] transaction = TransactionBuilder( source_account=source_account, network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE, base_fee=100) \ .append_path_payment_op(destination="GBBM6BKZPEHWYO3E3YKREDPQXMS4VK35YLNU7NFBRI26RAN7GI5POFBB", send_code="PAYDEX", send_issuer=None, send_max="1000", dest_code="GBP", dest_issuer="GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW", dest_amount="5.50", path=path) \ .set_timeout(30) \ .build() transaction.sign(source_keypair) response = server.submit_transaction(transaction)
from paydex_base_sdk.account import Account from paydex_base_sdk.keypair import Keypair from paydex_base_sdk.network import Network from paydex_base_sdk.transaction_builder import TransactionBuilder root_keypair = Keypair.from_secret("SA6XHAH4GNLRWWWF6TEVEWNS44CBNFAJWHWOPZCVZOUXSQA7BOYN7XHC") # Create an Account object from an address and sequence number. root_account = Account(account_id=root_keypair.public_key, sequence=1) transaction = TransactionBuilder(source_account=root_account, network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE, base_fee=100).add_text_memo("Happy birthday!").append_payment_op( destination="GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW", amount="2000", asset_code="PAYDEX").set_timeout(30).build()
server = Server(horizon_url="https://testhorizon.paydex.io/") # Transactions require a valid sequence number that is specific to this account. source_account = server.load_account(source_public_key) base_fee = server.fetch_base_fee() transaction = ( TransactionBuilder( source_account=source_account, network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE, base_fee=base_fee, ) .add_text_memo("Hello, Paydex!") # Add a memo # Add a payment operation to the transaction # Send 350.1234567 PAYDEX to receiver # Specify 350.1234567 lumens. Lumens are divisible to seven digits past the decimal. .append_payment_op(receiver_public_key, "350.1234567", "PAYDEX") .set_timeout(30) # Make this transaction valid for the next 30 seconds only .build() ) # Sign this transaction with the secret key transaction.sign(source_keypair) # Let's see the XDR (encoded in base64) of the transaction we just built print(transaction.to_xdr()) response = server.submit_transaction(transaction)
from paydex_base_sdk.account import Account from paydex_base_sdk.keypair import Keypair from paydex_base_sdk.network import Network from paydex_base_sdk.transaction_builder import TransactionBuilder root_keypair = Keypair.from_secret( "SA6XHAH4GNLRWWWF6TEVEWNS44CBNFAJWHWOPZCVZOUXSQA7BOYN7XHC") # Create an Account object from an address and sequence number. root_account = Account(account_id=root_keypair.public_key, sequence=1) transaction = TransactionBuilder( source_account=root_account, network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE, base_fee=100) \ .append_payment_op( # add a payment operation to the transaction destination="GASOCNHNNLYFNMDJYQ3XFMI7BYHIOCFW3GJEOWRPEGK2TDPGTG2E5EDW", asset_code="PAYDEX", amount="125.5") \ .append_set_options_op( # add a set options operation to the transaction home_domain="overcat.me") \ .set_timeout(30) \ .build() # mark this transaction as valid only for the next 30 seconds
server = Server(horizon_url="https://testhorizon.paydex.io//") root_keypair = Keypair.from_secret( "SA6XHAH4GNLRWWWF6TEVEWNS44CBNFAJWHWOPZCVZOUXSQA7BOYN7XHC") root_account = server.load_account(account_id=root_keypair.public_key) secondary_keypair = Keypair.from_secret( "SAMZUAAPLRUH62HH3XE7NVD6ZSMTWPWGM6DS4X47HLVRHEBKP4U2H5E7") secondary_signer = Signer.ed25519_public_key( account_id=secondary_keypair.public_key, weight=1) transaction = TransactionBuilder( source_account=root_account, network_passphrase=Network.TESTNET_NETWORK_PASSPHRASE, base_fee=100) \ .append_set_options_op( master_weight=1, # set master key weight low_threshold=1, med_threshold=2, # a payment is medium threshold high_threshold=2, # make sure to have enough weight to add up to the high threshold! signer=secondary_signer) \ .set_timeout(30) \ .build() # only need to sign with the root signer as the 2nd signer won't # be added to the account till after this transaction completes transaction.sign(root_keypair) response = server.submit_transaction(transaction) print(response) # now create a payment with the account that has two signers destination = "GBA5SMM5OYAOOPL6R773MV7O3CCLUDVLCWHIVVL3W4XTD3DA5FJ4JSEZ" transaction = TransactionBuilder(