예제 #1
1
    def test_builder_xdr(self):
        cold_account = self.cold.address().decode()
        hot_account = self.hot.address().decode()
        fund(cold_account)
        fund(hot_account)

        cold = Builder(self.cold.seed().decode())
        cold.append_trust_op(cold_account, 'BEER', 1000, hot_account)
        cold.append_payment_op(hot_account, 100, 'BEER', cold_account)
        cold.append_payment_op(cold_account, 2.222, 'BEER', cold_account, hot_account)

        xdr = cold.gen_xdr()
        hot = Builder(self.hot.seed().decode())
        hot.import_from_xdr(xdr)
        # hot.sign()

        try:
            response = hot.submit()
        except:
            assert False
예제 #2
0
    def test_verify_challenge_tx_contains_infinite_timebounds(self):
        server_kp = Keypair.random()
        client_kp = Keypair.random()
        timeout = 600
        network = 'TESTNET'
        archor_name = 'sdf'

        challenge = Builder(server_kp.seed().decode(),
                            network=network,
                            sequence=-1,
                            fee=100)
        now = int(time.time())
        challenge.add_time_bounds({'minTime': now, 'maxTime': 0})
        nonce = os.urandom(64)
        challenge.append_manage_data_op(
            data_name='{} auth'.format(archor_name),
            data_value=nonce,
            source=client_kp.address().decode())
        challenge.sign()
        challenge_tx_server_signed = challenge.gen_xdr()

        transaction = Builder(client_kp.seed().decode(),
                              network='TESTNET',
                              sequence=0,
                              fee=100)
        transaction.import_from_xdr(challenge_tx_server_signed)
        transaction.sign()
        challenge_tx = transaction.gen_xdr()
        with pytest.raises(
                InvalidSep10ChallengeError,
                match="Transaction requires non-infinite timebounds."):
            Builder.verify_challenge_tx(challenge_tx,
                                        server_kp.address().decode(),
                                        'TESTNET')
예제 #3
0
    def test_verify_challenge_tx_donot_contain_managedata_operation(self):
        server_kp = Keypair.random()
        client_kp = Keypair.random()
        timeout = 600
        network = 'TESTNET'

        challenge = Builder(server_kp.seed().decode(),
                            network=network,
                            sequence=-1,
                            fee=100)
        now = int(time.time())
        challenge.add_time_bounds({'minTime': now, 'maxTime': now + timeout})
        challenge.append_bump_sequence_op(12,
                                          source=client_kp.address().decode())
        challenge.sign()
        challenge_tx_server_signed = challenge.gen_xdr()

        transaction = Builder(client_kp.seed().decode(),
                              network='TESTNET',
                              sequence=0,
                              fee=100)

        transaction.import_from_xdr(challenge_tx_server_signed)
        transaction.sign()
        challenge_tx = transaction.gen_xdr()
        with pytest.raises(InvalidSep10ChallengeError,
                           match="Operation type should be ManageData."):
            Builder.verify_challenge_tx(challenge_tx,
                                        server_kp.address().decode(),
                                        'TESTNET')
예제 #4
0
    def test_verify_challenge_tx_source_is_different_to_server_account_id(
            self):
        server_kp = Keypair.random()
        client_kp = Keypair.random()
        network = 'TESTNET'

        challenge = Builder(server_kp.seed().decode(),
                            network=network,
                            sequence=-1,
                            fee=100)
        challenge.sign()
        challenge_tx_server_signed = challenge.gen_xdr()

        transaction = Builder(client_kp.seed().decode(),
                              network='TESTNET',
                              sequence=0,
                              fee=100)
        transaction.import_from_xdr(challenge_tx_server_signed)
        transaction.sign()
        challenge_tx = transaction.gen_xdr()
        with pytest.raises(
                InvalidSep10ChallengeError,
                match=
                "Transaction source account is not equal to server's account."
        ):
            Builder.verify_challenge_tx(challenge_tx,
                                        Keypair.random().address().decode(),
                                        'TESTNET')
예제 #5
0
    def test_verify_challenge_tx(self):
        server_kp = Keypair.random()
        client_kp = Keypair.random()
        timeout = 600
        network = 'Public Global Stellar Network ; September 2015'
        archor_name = "SDF"

        challenge = Builder.challenge_tx(
            server_secret=server_kp.seed().decode(),
            client_account_id=client_kp.address().decode(),
            archor_name=archor_name,
            network=network,
            timeout=timeout)
        challenge.sign()
        challenge_tx_server_signed = challenge.gen_xdr()

        transaction = Builder(
            client_kp.seed().decode(),
            network='Public Global Stellar Network ; September 2015',
            sequence=0,
            fee=100)
        transaction.import_from_xdr(challenge_tx_server_signed)
        transaction.sign()
        challenge_tx = transaction.gen_xdr()
        Builder.verify_challenge_tx(
            challenge_tx,
            server_kp.address().decode(),
            'Public Global Stellar Network ; September 2015')
예제 #6
0
def test_builder_xdr(setup, helpers, test_data):
    hot = Keypair.random()
    hot_account = hot.address().decode()
    hot_secret = hot.seed()

    helpers.fund_account(setup, hot_account)

    cold = Builder(secret=test_data.cold_secret, horizon=setup.horizon_endpoint_uri, network=setup.network) \
        .append_trust_op(test_data.cold_account, 'BEER', '1000', hot_account) \
        .append_allow_trust_op(hot_account, 'BEER', True, test_data.cold_account) \
        .append_payment_op(hot_account, '100', 'BEER', test_data.cold_account, test_data.cold_account) \
        .append_payment_op(test_data.cold_account, '2.222', 'BEER', test_data.cold_account, hot_account)
    cold.sign()

    xdr = cold.gen_xdr()

    hot = Builder(secret=hot_secret,
                  horizon=setup.horizon_endpoint_uri,
                  network=setup.network)
    hot.import_from_xdr(xdr)
    hot.sign()

    assert len(hot.te.signatures) == 2
    assert len(hot.ops) == 4

    response = hot.submit()
    assert response.get('hash') == hot.hash_hex()
예제 #7
0
def submit(systemdb, Account, ptxnum):
	key = 'ptx'+str(ptxnum)
	q = Query()
	xdr = systemdb.search(q.name==key)[0]['xdr']
	a_sk = systemdb.search(q.name == Account)[0]['sk']

	b = Builder(secret = a_sk, network='TESTNET')
	b.import_from_xdr(xdr)
	print b.submit()
예제 #8
0
    def test_builder_xdr(self):
        cold_account = self.cold.address().decode()
        hot_account = self.hot.address().decode()
        fund(cold_account)
        fund(hot_account)

        cold = Builder(self.cold.seed().decode())
        cold.append_trust_op(cold_account, 'BEER', 1000, hot_account)
        cold.append_payment_op(hot_account, 100, 'BEER', cold_account)
        cold.append_payment_op(cold_account, 2.222, 'BEER', cold_account, hot_account)
        xdr = cold.gen_xdr()
        hot = Builder(self.hot.seed().decode())
        hot.import_from_xdr(xdr)
        # hot.sign()

        try:
            response = hot.submit()
        except:
            assert False
예제 #9
0
def signsend(text):
    cont = session.prompt(u'You want to sign or send? (sign/send) > ')
    data = text.split()[1]
    if cont.lower() == 'sign':
        print(' signing ' + data)
        sign = Builder(CONF['private_key'], network=CONF['network'])
        sign.import_from_xdr(data)
        #key = session.prompt(u'Enter who you sign for? %s > ' % CONF['multisig'])
        sign.sign()
        print("send this to the other wallet and ask them to signsend it\n")
        print(sign.gen_xdr())
        return
    print(' signing and sending ' + data)
    c = Builder(CONF['private_key'], network=CONF['network'])
    c.import_from_xdr(data)
    c.sign()
    data = c.submit()
    print(data)
    return
예제 #10
0
    def test_verify_challenge_tx_sequence_not_zero(self):
        server_kp = Keypair.random()
        client_kp = Keypair.random()

        challenge = Builder(server_kp.seed().decode(), sequence=10086, fee=100)
        challenge.sign()
        challenge_tx_server_signed = challenge.gen_xdr()

        transaction = Builder(
            client_kp.seed().decode(),
            network='Public Global Stellar Network ; September 2015',
            sequence=0,
            fee=100)
        transaction.import_from_xdr(challenge_tx_server_signed)
        transaction.sign()
        challenge_tx = transaction.gen_xdr()
        with pytest.raises(
                InvalidSep10ChallengeError,
                match="The transaction sequence number should be zero."):
            Builder.verify_challenge_tx(
                challenge_tx,
                server_kp.address().decode(),
                'Public Global Stellar Network ; September 2015')
예제 #11
0
    def test_verify_challenge_tx_operation_value_is_not_a_64_bytes_base64_string(
            self):
        server_kp = Keypair.random()
        client_kp = Keypair.random()
        timeout = 600
        network = 'TESTNET'
        archor_name = 'sdf'

        challenge = Builder(server_kp.seed().decode(),
                            network=network,
                            sequence=-1,
                            fee=100)
        now = int(time.time())
        challenge.add_time_bounds({'minTime': now, 'maxTime': now + timeout})
        nonce = os.urandom(32)
        challenge.append_manage_data_op(
            data_name='{} auth'.format(archor_name),
            data_value=nonce,
            source=client_kp.address().decode())
        challenge.sign()
        challenge_tx_server_signed = challenge.gen_xdr()

        transaction = Builder(client_kp.seed().decode(),
                              network='TESTNET',
                              sequence=0,
                              fee=100)

        transaction.import_from_xdr(challenge_tx_server_signed)
        transaction.sign()
        challenge_tx = transaction.gen_xdr()
        with pytest.raises(
                InvalidSep10ChallengeError,
                match=
                "Operation value should be a 64 bytes base64 random string."):
            Builder.verify_challenge_tx(challenge_tx,
                                        server_kp.address().decode(),
                                        'TESTNET')
예제 #12
0
파일: sign.py 프로젝트: smn/pool
from stellar_base.keypair import Keypair
from stellar_base.horizon import horizon_testnet, horizon_livenet

network = "TESTNET"

transactions_unsigned = []
with open("transactions.json", 'r') as tfile:
    transactions_unsigned = json.load(tfile)

key = input("Signing Key: ")
amt_signed = 0
needed = 3
transactions = []
for xdr in transactions_unsigned:
    builder = Builder(secret=key, network=network)
    builder.import_from_xdr(xdr)
    amt_signed = len(builder.te.signatures) + 1
    builder.sign()
    transactions.append(builder.gen_xdr().decode("utf-8"))

print("Added signature. Transactions now signed by %s/%s parties." %
      (str(amt_signed), str(needed)))

if amt_signed >= needed:
    print("Submitting " + str(len(transactions)) + "transactions")
    i = 1
    for xdr in transactions:
        try:
            response = horizon.submit(self.gen_xdr())
            print("Transaction " + str(i) + " link: ",
                  response["_links"]["transaction"]["href"])