예제 #1
0
def create_multiple_keypair():
    print("Create multiple keypair")
    sm = StellarMnemonic()
    secret_phrase = sm.generate()
    kp0 = Keypair.deterministic(secret_phrase, index=0)
    kp1 = Keypair.deterministic(secret_phrase, index=1)
    kp2 = Keypair.deterministic(secret_phrase, index=2)
    for keypair in (kp0, kp1, kp2):
        print("Public key / Account address:\n", keypair.address().decode())
        print("Seed / Your secret to keep it on local:\n",
              keypair.seed().decode())
예제 #2
0
def create_keypair_determinist_english():
    print("Create keypair determinist english")
    mnemonic = ('illness spike retreat truth genius clock brain pass '
                'fit cave bargain toe')
    keypair = Keypair.deterministic(mnemonic)
    print("Public key / Account address:\n", keypair.address().decode())
    print("Seed / Your secret to keep it on local:\n", keypair.seed().decode())
예제 #3
0
async def test_builder_(setup, test_data):
    hot = Keypair.random()
    hot_account = hot.address().decode()
    hot_secret = hot.seed()

    cold = Builder(secret=test_data.cold_secret, horizon=test_data.horizon, network_name=setup.network, fee=100) \
        .append_create_account_op(hot_account, '200') \
        .append_set_options_op(inflation_dest=test_data.cold_account, set_flags=1,
                               home_domain='256kw.com', master_weight=10,
                               low_threshold=5, ) \
        .append_change_trust_op('BEER', test_data.cold_account, '1000', hot_account) \
        .append_allow_trust_op(hot_account, 'BEER', True)
    # append twice for test
    cold.append_payment_op(hot_account, '50.123', 'BEER', test_data.cold_account) \
        .append_payment_op(hot_account, '50.123', 'BEER', test_data.cold_account)
    # TODO: append_bump_sequence_op test
    await cold.update_sequence()
    cold.sign()
    cold.sign(hot_secret)
    # try to sign twice
    with pytest.raises(SignatureExistError):
        cold.sign(hot_secret)

    assert len(cold.te.signatures) == 2
    assert len(cold.ops) == 5

    response = await cold.submit()
    assert response.get('hash') == cold.hash_hex()
예제 #4
0
async def test_builder_xdr(setup, helpers, test_data, aio_session):
    hot = Keypair.random()
    hot_account = hot.address().decode()
    hot_secret = hot.seed()

    await helpers.fund_account(setup, hot_account, aio_session)

    cold = Builder(secret=test_data.cold_secret, horizon=test_data.horizon, network_name=setup.network, fee=100) \
        .append_change_trust_op('BEER', test_data.cold_account, '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)
    await cold.update_sequence()
    cold.sign()

    xdr = cold.gen_xdr()

    hot = Builder(
        secret=hot_secret,
        horizon=test_data.horizon,
        network_name=setup.network, fee=100)
    hot.import_from_xdr(xdr)
    hot.sign()

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

    response = await hot.submit()
    assert response.get('hash') == hot.hash_hex()
예제 #5
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_uri=setup.horizon_endpoint_uri, network=setup.network) \
        .append_change_trust_op('BEER', test_data.cold_account, '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_uri=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()
예제 #6
0
 def do(self, network, op):
     tx = Transaction(self.source, sequence=1)
     tx.add_operation(op)
     envelope = Te(tx, network_id=network)
     signer = Keypair.from_seed(self.seed)
     envelope.sign(signer)
     envelope_b64 = envelope.xdr()
     return envelope_b64
예제 #7
0
 def do(self, network, opts):
     tx = Transaction(self.source, **opts)
     tx.add_operation(Inflation())
     envelope = Te(tx, network_id=network)
     signer = Keypair.from_seed(self.seed)
     envelope.sign(signer)
     envelope_b64 = envelope.xdr()
     print(envelope_b64)
     return envelope_b64
예제 #8
0
def test_data(setup, helpers):
    class Struct:
        def __init__(self, **entries):
            self.__dict__.update(entries)

    cold = Keypair.random()
    cold_secret = cold.seed()
    cold_account = cold.address().decode()

    helpers.fund_account(setup, cold.address().decode())

    return Struct(cold_secret=cold_secret, cold_account=cold_account)
예제 #9
0
 def make_envelope(self, network, *args, **kwargs):
     opts = {'sequence': 2, 'fee': 100 * len(args)}
     for opt, value in kwargs.items():
         opts[opt] = value
     tx = Transaction(self.address, **opts)
     for count, op in enumerate(args):
         tx.add_operation(op)
     envelope = Te(tx, network_id=network)
     signer = Keypair.from_seed(self.seed)
     envelope.sign(signer)
     envelope_b64 = envelope.xdr()
     print(envelope_b64)
     return envelope_b64
예제 #10
0
def test_submit(setup, helpers):
    kp = Keypair.random()
    address = kp.address().decode()
    seed = kp.seed()

    helpers.fund_account(setup, address)

    horizon = Horizon(setup.horizon_endpoint_uri)

    envelope_xdr = make_envelope(
        setup.network, horizon, address, seed,
        Payment(destination=address, asset=Asset.native(), amount="0.0001618"))
    response = horizon.submit(envelope_xdr)
    assert 'hash' in response
예제 #11
0
async def test_data(setup, helpers, aio_session):
    class Struct:
        def __init__(self, **entries):
            self.__dict__.update(entries)

    cold = Keypair.random()
    cold_secret = cold.seed()
    cold_account = cold.address().decode()
    horizon = Horizon(setup.horizon_endpoint_uri)

    await helpers.fund_account(setup, cold.address().decode(), aio_session)

    yield Struct(cold_secret=cold_secret, cold_account=cold_account, horizon=horizon)
    await horizon.close()
예제 #12
0
async def test_sse(setup, helpers, aio_session):
    kp = Keypair.random()
    address = kp.address().decode()

    events = []
    async def sse_handler(events):
        async with Horizon(setup.horizon_endpoint_uri) as horizon:
            async for event in await horizon.account_transactions('GA3FLH3EVYHZUHTPQZU63JPX7ECJQL2XZFCMALPCLFYMSYC4JKVLAJWM',
                                                            sse=True):
                events.append(event)
                break
    handler = asyncio.ensure_future(sse_handler(events))
    await helpers.fund_account(setup, address, aio_session)
    await asyncio.sleep(5)
    assert len(events) == 1
예제 #13
0
async def make_envelope(network, horizon, address, seed, *args, **kwargs):
    opts = {
        'sequence': int((await horizon.account(address))['sequence']) + 1,
        'fee': 100 * len(args)
    }
    for opt, value in kwargs.items():
        opts[opt] = value
    tx = Transaction(address, **opts)
    for count, op in enumerate(args):
        tx.add_operation(op)
    envelope = Te(tx, network_id=network)
    signer = Keypair.from_seed(seed)
    envelope.sign(signer)
    envelope_xdr = envelope.xdr()
    return envelope_xdr
예제 #14
0
async def test_submit(setup, helpers, aio_session):
    kp = Keypair.random()
    address = kp.address().decode()
    seed = kp.seed()

    await helpers.fund_account(setup, address, aio_session)

    async with Horizon(setup.horizon_endpoint_uri) as horizon:
        envelope_xdr = await make_envelope(setup.network, horizon, address, seed,
                                     Payment(
                                         destination=address,
                                         asset=Asset.native(),
                                         amount="0.1618"))
        response = await horizon.submit(envelope_xdr.decode())
        assert 'hash' in response
예제 #15
0
def setup():
    class Struct:
        """Handy variable holder"""
        def __init__(self, **entries):
            self.__dict__.update(entries)

    issuer_keypair = Keypair.random()
    test_asset = Asset('TEST', issuer_keypair.address().decode())

    # local testnet (kinecosystem docker)
    from kin_base.network import NETWORKS
    # we will leave this passphrase instead of changing every envelop in the test suite
    NETWORKS['CUSTOM'] = 'Integration Test Network ; zulucrypto'
    return Struct(type='local',
                  network='CUSTOM',
                  issuer_keypair=issuer_keypair,
                  test_asset=test_asset,
                  horizon_endpoint_uri='http://localhost:8008',
                  friendbot_url='http://localhost:8001')
예제 #16
0
async def test_sse_event_timeout(setup, helpers, aio_session):
    kp = Keypair.random()
    address = kp.address().decode()

    events = []

    async def sse_handler(events):
        async with Horizon(setup.horizon_endpoint_uri) as horizon:
            async for event in await horizon.account_transactions(
                    'GA3FLH3EVYHZUHTPQZU63JPX7ECJQL2XZFCMALPCLFYMSYC4JKVLAJWM',
                    sse=True, sse_timeout=15):
                events.append(event)

    handler = asyncio.ensure_future(sse_handler(events))
    await helpers.fund_account(setup, address, aio_session)
    await asyncio.sleep(5)
    assert len(events) == 1
    await asyncio.sleep(20)
    # Make sure that the sse generator raised timeout error
    with pytest.raises(asyncio.TimeoutError):
        raise handler.exception()
예제 #17
0
def test_sep0005():
    # https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0005.md
    mnemonic = 'illness spike retreat truth genius clock brain pass fit cave bargain toe'
    seed = Keypair.deterministic(mnemonic).seed()
    assert seed == b'SDBKOVHBX2UFDTSEESHEEHR76OMJ5GMOWISBDC7BQOSF7FA2E23JRZLS'
    address = Keypair.deterministic(mnemonic, index=6).address().decode()
    assert address == 'GB37PRJSTEGB6CWTRU7DCSJWD4A22IYTGSHFEN73IJ3AM3CETFAZPRJO'

    mnemonic = 'cable spray genius state float twenty onion head street palace net private method loan turn phrase state blanket interest dry amazing dress blast tube'
    seed = Keypair.deterministic(mnemonic, passphrase='p4ssphr4se').seed()
    assert seed == b'SBRC5DWN6RPRY5IJABDVEUESPJBMQEIA5HNKEMERYUOKJ5VUCIXTSF6J'
    address = Keypair.deterministic(
        mnemonic, passphrase='p4ssphr4se', index=9).address().decode()
    assert address == 'GDPJJCIKGNOM73NXVYX5R76PNATGDP7IW4TWSOY5HOARGKZY2ZSBTVEA'

    mnemonic = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
    seed = Keypair.deterministic(mnemonic).seed()
    assert seed == b'SDRX36LJA7O4S5GZ3PF7CCLO5S5XEXO6SAV7SFCHRCQHAASE2HOJY6TX'
    address = Keypair.deterministic(mnemonic, index=8).address().decode()
    assert address == 'GCAZEAOQBCGBJKH7OKJO35NIHAVGNP3A5NN2MUNB37Z4MI35AIC7K5PC'
예제 #18
0
def test_sep0005():
    # https://github.com/stellar/stellar-protocol/blob/master/ecosystem/sep-0005.md
    mnemonic = 'illness spike retreat truth genius clock brain pass fit cave bargain toe'
    seed = Keypair.deterministic(mnemonic).seed()
    assert seed == b'SBGWSG6BTNCKCOB3DIFBGCVMUPQFYPA2G4O34RMTB343OYPXU5DJDVMN'
    address = Keypair.deterministic(mnemonic, index=6).address().decode()
    assert address == 'GBY27SJVFEWR3DUACNBSMJB6T4ZPR4C7ZXSTHT6GMZUDL23LAM5S2PQX'

    mnemonic = 'cable spray genius state float twenty onion head street palace net private method loan turn phrase state blanket interest dry amazing dress blast tube'
    seed = Keypair.deterministic(mnemonic, passphrase='p4ssphr4se').seed()
    assert seed == b'SAFWTGXVS7ELMNCXELFWCFZOPMHUZ5LXNBGUVRCY3FHLFPXK4QPXYP2X'
    address = Keypair.deterministic(
        mnemonic, passphrase='p4ssphr4se', index=9).address().decode()
    assert address == 'GBOSMFQYKWFDHJWCMCZSMGUMWCZOM4KFMXXS64INDHVCJ2A2JAABCYRR'

    mnemonic = 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
    seed = Keypair.deterministic(mnemonic).seed()
    assert seed == b'SBUV3MRWKNS6AYKZ6E6MOUVF2OYMON3MIUASWL3JLY5E3ISDJFELYBRZ'
    address = Keypair.deterministic(mnemonic, index=8).address().decode()
    assert address == 'GABTYCZJMCP55SS6I46SR76IHETZDLG4L37MLZRZKQDGBLS5RMP65TSX'
예제 #19
0
 def test_sign_missing_signing_key_raise(self):
     keypair = Keypair.from_address(self.keypair0.address())
     raises(MissingSigningKeyError, keypair.sign, "")
예제 #20
0
# See: https://www.stellar.org/developers/guides/issuing-assets.html

from kin_base.keypair import Keypair
from kin_base.asset import Asset
from kin_base.builder import Builder

# Keys for accounts to issue and receive the new asset
issuing_secret = 'SCBHQEGSNBTT4S7Y73YAF3M3JSVSTSNBGAVU5M4XVFGUF7664EUXQHFU'
issuing_public = Keypair.from_seed(issuing_secret).address().decode()

receiving_secret = 'SB6MJ6M3BPJZUGFP2QCODUIKWQWF6AIN4Z6L3J6PWL3QGDW4L6YR3QIU'
receiving_public = Keypair.from_seed(receiving_secret).address().decode()

# Create an object to represent the new asset
my_asset = Asset('Hello', issuing_public)

# First, the receiving account must trust the asset
builder = Builder(receiving_secret, network='TESTNET').append_trust_op(
    destination=my_asset.issuer, code=my_asset.code)
builder.sign()
resp = builder.submit()
print(resp)

# Second, the issuing account actually sends a payment using the asset
builder = Builder(issuing_secret, network='TESTNET').append_payment_op(
    destination=receiving_public,
    amount='1000',
    asset_code=my_asset.code,
    asset_issuer=my_asset.issuer)
builder.sign()
resp = builder.submit()
from kin_base.keypair import Keypair
from kin_base.asset import Asset
from kin_base.operation import Payment, SetOptions
from kin_base.transaction import Transaction
from kin_base.transaction_envelope import TransactionEnvelope as Te
from kin_base.memo import TextMemo
from kin_base.horizon import horizon_testnet, horizon_livenet

alice_seed = 'SBUORYV26AZ3ULEEC5FQ4NKPVRO7MBAWTW26YKCDPPKFGMK7WAYNX4UN'
bob_address = 'GBZF7GQJXXHD3OL3B5IOUICFDYIATZZ3F3XQ7SOQ5PXLVQMDSOI5ACEE'

Alice = Keypair.from_seed(alice_seed)
horizon = horizon_testnet()  # for TESTNET
# horizon = horizon_livenet() # for LIVENET

# create op
payment_op = Payment(
    # source=Alice.address().decode(),
    destination=bob_address,
    asset=Asset('XLM'),
    amount='10.5')

set_home_domain_op = SetOptions(home_domain='fed.network')

# create a memo
msg = TextMemo('Buy yourself a beer!')

# get sequence of Alice
# Python 3
sequence = horizon.account(Alice.address().decode('utf-8')).get('sequence')
# Python 2
예제 #22
0
def generate_random_keypair():
    print("Generate random keypair")
    keypair = Keypair.random()
    print("Public key / Account address:\n", keypair.address().decode())
    print("Seed / Your secret to keep it on local:\n", keypair.seed().decode())
예제 #23
0
def get_proxy_address(address: str, salt: str) -> str:
    """Generate a deterministic keypair using an address and a salt"""
    raw_seed = sha256((address + salt).encode()).digest()
    keypair = BaseKeypair.from_raw_seed(raw_seed)
    return keypair.address().decode()
예제 #24
0
 def test_from_seed(self):
     keypair = Keypair.from_seed(self.keypair0.seed())
     assert self.keypair0.address() == keypair.address()
예제 #25
0
 def setUpClass(cls):
     cls.mnemonic = ('illness spike retreat truth genius clock brain pass '
                     'fit cave bargain toe')
     cls.keypair0 = Keypair.deterministic(cls.mnemonic)
예제 #26
0
# https://www.stellar.org/developers/guides/concepts/multi-sig.html
import time

from kin_base.keypair import Keypair
from kin_base.builder import Builder

alice_seed = 'SDW74JLSQCDDJELC3S6EP4V4SGIM6MSFFVT73PMKIH4BAAJX6OZY4PCC'  # GCDCDLVJNSLJWWHH2Q36IGBYZP6O6MFZOMXSW2DNBUCWKZDCRTIT73DP
bob_seed = 'SCEQG2XD2HPDKBLIFHFT2CFC5FLOHNT2HNHTTPAXFXS6YDW4UCP57V2H'  # GCNT7JJDVQ5ZAZ4OLHXUJPONYATFE5YOTRTKMPI2EQCGU2SK4QGCETJ5
dav_seed = 'SDE2CEJ3HMXPAO5TBKLRTV3WYI2DHIRQ6ZESKRMHEDLCOHLCZPU3TFPH'  # GCPITREYLKN3WHVPYBM7SNW2V7ZPYYPZHARPBWEC3XTZASUI3MGFYLWF
eve_address = 'GDQ6L5ULMQPY5S363O7HXALMVIQ4OLS4PZJSPRF6R4FC5QMX2BJFJYX7'

alice_kp = Keypair.from_seed(alice_seed)
bob_kp = Keypair.from_seed(bob_seed)
dav_kp = Keypair.from_seed(dav_seed)


def setup_threshold():
    builder = Builder(dav_seed).append_set_options_op(
        source=dav_kp.address().decode(),
        high_threshold=3,
        med_threshold=3,
        low_threshold=3,
        master_weight=1,
        signer_type='ed25519PublicKey',
        signer_weight=1,
        signer_address=alice_kp.address().decode()).append_set_options_op(
            source=dav_kp.address().decode(),
            signer_type='ed25519PublicKey',
            signer_weight=1,
            signer_address=bob_kp.address().decode(
            ))  # append more signers here