def test_already_signed_raise(self):
     # GDF5O4OWEMVBY5FLDHWA5RZTYSV2U276XGKZZ6VSHDDR3THSQ6OQS7UM
     source = Keypair.from_secret(
         "SCCS5ZBI7WVIJ4SW36WGOQQIWJYCL3VOAULSXX3FB57USIO25EDOYQHH")
     destination = "GDJJRRMBK4IWLEPJGIE6SXD2LP7REGZODU7WDC3I2D6MR37F4XSHBKX2"
     amount = "1000.0"
     sequence = 1
     memo = IdMemo(100)
     fee = 200
     asset = Asset.native()
     time_bounds = TimeBounds(12345, 56789)
     ops = [
         Payment(destination, asset, amount),
         ManageData("hello", "world")
     ]
     tx = Transaction(source, sequence, fee, ops, memo, time_bounds)
     te = TransactionEnvelope(tx, Network.PUBLIC_NETWORK_PASSPHRASE)
     assert binascii.hexlify(te.hash()).decode() == te.hash_hex()
     # te.sign(source)
     te.sign("SCCS5ZBI7WVIJ4SW36WGOQQIWJYCL3VOAULSXX3FB57USIO25EDOYQHH")
     hashx = bytes.fromhex(
         "94e8223a518ac16a8cb110ab1952ef14da2c10b264645c38c8b3d82bd2b20000")
     te.sign_hashx(hashx)
     with pytest.raises(SignatureExistError,
                        match="The keypair has already signed."):
         te.sign(source)
     with pytest.raises(SignatureExistError,
                        match="The preimage has already signed."):
         te.sign_hashx(hashx)
 def test_can_sign(self):
     can_sign_kp = Keypair.from_secret(
         "SD7X7LEHBNMUIKQGKPARG5TDJNBHKC346OUARHGZL5ITC6IJPXHILY36")
     can_not_sign_kp = Keypair.from_public_key(
         "GAXDYNIBA5E4DXR5TJN522RRYESFQ5UNUXHIPTFGVLLD5O5K552DF5ZH")
     assert can_sign_kp.can_sign() is True
     assert can_not_sign_kp.can_sign() is False
 def test_create_from_secret(self):
     secret = "SD7X7LEHBNMUIKQGKPARG5TDJNBHKC346OUARHGZL5ITC6IJPXHILY36"
     kp = Keypair.from_secret(secret)
     assert isinstance(kp, Keypair)
     assert (kp.public_key ==
             "GDFQVQCYYB7GKCGSCUSIQYXTPLV5YJ3XWDMWGQMDNM4EAXAL7LITIBQ7")
     assert kp.secret == secret
 def test_to_xdr(self):
     # GDF5O4OWEMVBY5FLDHWA5RZTYSV2U276XGKZZ6VSHDDR3THSQ6OQS7UM
     source = Keypair.from_secret(
         "SCCS5ZBI7WVIJ4SW36WGOQQIWJYCL3VOAULSXX3FB57USIO25EDOYQHH")
     destination = "GDJJRRMBK4IWLEPJGIE6SXD2LP7REGZODU7WDC3I2D6MR37F4XSHBKX2"
     amount = "1000.0"
     sequence = 1
     memo = IdMemo(100)
     fee = 200
     asset = Asset.native()
     time_bounds = TimeBounds(12345, 56789)
     ops = [
         Payment(destination, asset, amount),
         ManageData("hello", "world")
     ]
     tx = Transaction(source, sequence, fee, ops, memo, time_bounds)
     te = TransactionEnvelope(tx, Network.PUBLIC_NETWORK_PASSPHRASE)
     assert binascii.hexlify(te.hash()).decode() == te.hash_hex()
     te.sign(source)
     hashx = bytes.fromhex(
         "94e8223a518ac16a8cb110ab1952ef14da2c10b264645c38c8b3d82bd2b20000")
     te.sign_hashx(hashx)
     te_xdr = "AAAAAMvXcdYjKhx0qxnsDsczxKuqa/65lZz6sjjHHczyh50JAAAAyAAAAAAAAAABAAAAAQAAAAAAADA5AAAAAAAA3dUAAAACAAAAAAAAAGQAAAACAAAAAAAAAAEAAAAA0pjFgVcRZZHpMgnpXHpb/xIbLh0/YYto0PzI7+Xl5HAAAAAAAAAAAlQL5AAAAAAAAAAACgAAAAVoZWxsbwAAAAAAAAEAAAAFd29ybGQAAAAAAAAAAAAAAvKHnQkAAABAM4dg0J1LEFBmbDESJ5d+60WCuZC8lnA80g45qyEgz2oRBSNw1mOfZETnL/BgrebkG/K03oI2Wqcs9lvDKrDGDE0sOBsAAAAglOgiOlGKwWqMsRCrGVLvFNosELJkZFw4yLPYK9KyAAA="
     assert te.to_xdr() == te_xdr
     restore_te = TransactionEnvelope.from_xdr(
         te_xdr, Network.PUBLIC_NETWORK_PASSPHRASE)
     assert restore_te.to_xdr() == te_xdr
 def test_sign_and_verify(self):
     kp = Keypair.from_secret(
         "SAQVS3IPN6U3TBMTXQH32ZESY7SUOZGLEFBH6XWMA6DVNPJ4CLO5M54B")
     data = b"Hello, overcat!"
     signature = kp.sign(data)
     assert (
         signature.hex() ==
         "ff7c4346977144019e7be0c12c033e99f412e70361924e298e6152dd924c88f2"
         "725c60c56067f20c35a8ff29c936b983f652b4df2d9de8f2851605df2f680c06")
     kp.verify(data, signature)
 def test_verify_failed_raise(self):
     kp = Keypair.from_secret(
         "SAQVS3IPN6U3TBMTXQH32ZESY7SUOZGLEFBH6XWMA6DVNPJ4CLO5M54B")
     data = b"Hello, Paydex!"
     signature = kp.sign(data)
     with pytest.raises(BadSignatureError,
                        match="Signature verification failed."):
         kp.verify(data, signature + b"failed")
     with pytest.raises(BadSignatureError,
                        match="Signature verification failed."):
         kp.verify(b"test_verify_failed", signature)
    def test_set_keypair_raise(self):
        secret = "SD7X7LEHBNMUIKQGKPARG5TDJNBHKC346OUARHGZL5ITC6IJPXHILY36"
        kp = Keypair.from_secret(secret)
        with pytest.raises(
                AttributeError,
                match=
                "Please use `Keypair.from_secret` to generate a new Keypair object.",
        ):
            kp.secret = "SAMWF63FZ5ZNHY75SNYNAFMWTL5FPBMIV7DLB3UDAVLL7DKPI5ZFS2S6"

        with pytest.raises(
                AttributeError,
                match=
                "Please use `Keypair.from_public_key` to generate a new Keypair object.",
        ):
            kp.public_key = "GAXDYNIBA5E4DXR5TJN522RRYESFQ5UNUXHIPTFGVLLD5O5K552DF5ZH"
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)
Beispiel #9
0
from paydex_base_sdk.keypair import Keypair

print("create a random keypair")
kp = Keypair.random()
print("Secret: {}".format(kp.secret))
print("Public Key: {}".format(kp.public_key))
print("")

# create a keypair from secret
print("create a keypair from secret")
secret = "SBRR6ZPBHHTDXYSFRZR2QZCGDZURNE5ON4M4F3HQA42G3Z62SFCR7EEJ"
kp = Keypair.from_secret(secret)
print("Secret: {}".format(kp.secret))
print("Public Key: {}".format(kp.public_key))
print("")

# create a keypair from public key
print("create a keypair from public key")
public_key = "GDCZ6JDZMWYORTIHEO2E4ZXKBQ2TLXNRQJPJH5RCFN7Q7I24G4RGLXP6"
kp = Keypair.from_public_key(public_key)
print("Public Key: {}".format(kp.public_key))
Beispiel #10
0
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

source_secret_key = "SBFZCHU5645DOKRWYBXVOXY2ELGJKFRX6VGGPRYUWHQ7PMXXJNDZFMKD"

# Derive Keypair object and public key (that starts with a G) from the secret
source_keypair = Keypair.from_secret(source_secret_key)
source_public_key = source_keypair.public_key

receiver_public_key = "GA7YNBW5CBTJZ3ZZOWX3ZNBKD6OE7A7IHUQVWMY62W2ZBG2SGZVOOPVH"


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
 def test_create_from_invalid_secret_raise(self, invalid_secret):
     with pytest.raises(
             Ed25519SecretSeedInvalidError,
             match="Invalid Ed25519 Secret Seed: {}".format(invalid_secret),
     ):
         Keypair.from_secret(invalid_secret)
 def test_secret_equal(self, kp1, kp2, equal):
     assert (Keypair.from_secret(kp1) == Keypair.from_secret(kp2)) is equal
 def test_signature_hint(self, secret, hint):
     assert Keypair.from_secret(secret).signature_hint().hex() == hint
from paydex_base_sdk.exceptions import NotFoundError
from paydex_base_sdk.keypair import Keypair
from paydex_base_sdk.network import Network
from paydex_base_sdk.sep.exceptions import InvalidSep10ChallengeError
from paydex_base_sdk.sep.paydex_web_authentication import build_challenge_transaction, read_challenge_transaction, \
    verify_challenge_transaction_threshold, verify_challenge_transaction_signed_by_client_master_key
from paydex_base_sdk.server import Server
from paydex_base_sdk.transaction_builder import TransactionBuilder

server_keypair = Keypair.from_secret(
    "SBGCNEOQGECW5R4A55C26ZFS736IONKCHY5PPPSFZVXSJSU63MWNM4K6")
client_master_keypair = Keypair.from_secret(
    "SDWZHXKWSHTQ2YGPT6YQQSOJWJX5JX2IEU7KOLGQ2XEJEECIQHUU3RMR")
client_signer_keypair1 = Keypair.from_secret(
    "SCKJFEF2H767XINUY5YFBORUO7AAWOAXSTQ2B2YHSI6N4UF23HFV42I7")
client_signer_keypair2 = Keypair.from_secret(
    "SCE2JBZ6FKPTQ5LM4X4NIZOOZPIC5DXVG6VP2TKSBZCQAGXABJV55IN5")

server = Server("https://testhorizon.paydex.io/")
anchor_name = "hello"
network_passphrase = Network.TESTNET_NETWORK_PASSPHRASE


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()
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.signer import Signer
from paydex_base_sdk.transaction_builder import TransactionBuilder

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)