def test_generate_pair_pem(self): seed, pubkey = generate_pair() pem_file = Path(self.testdata_out, "foo.pem") pem.write(pem_file, seed, pubkey) parsed_seed, parsed_pubkey = pem.parse(pem_file) self.assertEqual(seed, parsed_seed) self.assertEqual(pubkey, parsed_pubkey)
def test_pem_parse_multiple(self): pem_file = self.testdata.joinpath("keys", "walletKey.pem") seed, address = pem.parse(pem_file, index=0) self.assertEqual("1f4dd8b7d18b5d0785c9d0802ec14d553dba356812b85c7e3414373388472010", seed.hex()) self.assertEqual(Address("erd1sjsk3n2d0krq3pyxxtgf0q7j3t56sgusqaujj4n82l39t9h7jers6gslr4").hex(), address.hex()) seed, address = pem.parse(pem_file, index=1) self.assertEqual("2565dbbdb62301e4c7b12b8a41cd3b2fbd7ae687c8d9741937aa48cf246aeb25", seed.hex()) self.assertEqual(Address("erd10536tc3s886yqxtln74u6mztuwl5gy9k9gp8fttxda0klgxg979srtg5wt").hex(), address.hex()) seed, address = pem.parse(pem_file, index=2) self.assertEqual("08de69d398f4a5ffdce0f1a8569704dbc8b58aaf7ba3e726134e32f1e8bf04ad", seed.hex()) self.assertEqual(Address("erd1n230jlgfepdvf28vqt3zeawexg2jhvxqxjuqdfsss0xc62xcqcps9k54ag").hex(), address.hex()) seed, address = pem.parse(pem_file, index=3) self.assertEqual("4d9dcc1c09a6d00c4c9a389e662d9fe26e0bf4c859776d4d338b5a9c41fc12d4", seed.hex()) self.assertEqual(Address("erd143907zxv0ujxr9q4mda7rmczn2xwhmqn7p9lfz666z8hd2lcks2szt5yql").hex(), address.hex())
def test_pem_parse(self): pem_file = self.devnet_wallets.joinpath("users", "alice.pem") seed, address = pem.parse(pem_file) self.assertEqual( "413f42575f7f26fad3317a778771212fdb80245850981e48b58a4f25e344e8f9", seed.hex()) self.assertEqual( "0139472eff6886771a982f3083da5d421f24c29181e63888228dc81ca60d69e1", address.hex())
def sign_transaction(transaction, pem_file): seed, _ = pem.parse(pem_file) signing_key = nacl.signing.SigningKey(seed) data_json = transaction.to_json() signed = signing_key.sign(data_json) signature = signed.signature signature_hex = signature.hex() return signature_hex
def __init__(self, address=None, pem_file=None): self.private_key_seed = None self.address = Address(address) self.pem_file = pem_file self.nonce = 0 if pem_file: seed, pubkey = pem.parse(pem_file) self.private_key_seed = seed.hex() self.address = Address(pubkey)
def __init__(self, address: Any = None, pem_file: Union[str, None] = None, pem_index: int = 0, key_file: str = "", pass_file: str = ""): self.address = Address(address) self.pem_file = pem_file self.pem_index = int(pem_index) self.nonce: int = 0 if pem_file: seed, pubkey = pem.parse(self.pem_file, self.pem_index) self.private_key_seed = seed.hex() self.address = Address(pubkey) elif key_file and pass_file: password = get_password(pass_file) address_from_key_file, seed = load_from_key_file(key_file, password) self.private_key_seed = seed.hex() self.address = Address(address_from_key_file)
def test_pem_parse(self): pem_file = self.testdata.joinpath("keys", "alice.pem") seed, address = pem.parse(pem_file) self.assertEqual("1a927e2af5306a9bb2ea777f73e06ecc0ac9aaa72fb4ea3fecf659451394cccf", seed.hex()) self.assertEqual("fd691bb5e85d102687d81079dffce842d4dc328276d2d4c60d8fd1c3433c3293", address.hex())