Beispiel #1
0
    def testKeyAddress(self):
        # when
        key_1 = Key('myseed')
        key_2 = Key('myseed')

        address_1 = Address(key_1)
        address_2 = Address(key_2)

        self.assertEquals(address_1.pubkey, address_2.pubkey)
Beispiel #2
0
    def test_bitcoinaddress(self):

        key = Key()
        keys_dict = key.generate()
        print(keys_dict)

        address = Address(key)
        address_dict = address.generate()
        print(address_dict)
Beispiel #3
0
def blockchain_address():
    """
    this function generate the wallet address
    :return:
    """
    key = Key()
    key_dict = key.generate()
    address = Address(key)
    address_dict = address.generate()
    return {"private_key": key_dict, "pair_pub_addr": address_dict}
Beispiel #4
0
    def testKeyAddressSeed(self):
        # when
        seed_1 = Seed('myseed')
        seed_2 = Seed('myseed')
        key_1 = Key(seed_1)
        key_2 = Key(seed_2)

        address_1 = Address(key_1)
        address_2 = Address(key_2)

        # then
        self.assertEqual(address_1.pubkey, address_2.pubkey)
Beispiel #5
0
    def test_generate_from_hex(self):
        # given
        key = Key()
        key.generate_from_hex(
            '669182eb2c3169e01cfc305034dc0b1df8328c274865e70d632c711ba62ec3d3')

        # then
        self.assertEqual(
            key.hex,
            '669182eb2c3169e01cfc305034dc0b1df8328c274865e70d632c711ba62ec3d3')
        self.assertEqual(
            key.wif, '5JbTZ4zCTn1rwCfdkPWLddFgqzieGaG9Qjp3iRhf7R8gNroj4KM')
        self.assertEqual(
            key.wif_c, 'Kzf6CYbTbBgoQEVXCWLVef1psFkoVjor7mxeyr2TDKWto7iHfXHh')
Beispiel #6
0
    def testFromRandomSeed(self):
        # given
        key = Key.of(Seed())

        # then
        self.assertEqual(len(key.hex), 64)
        self.assertEqual(len(key.mainnet.wif), 51)
        self.assertEqual(len(key.mainnet.wifc), 52)
Beispiel #7
0
def makeNewAddresses(addressNumber):
    with open("scriptAddress", "wt") as f:
        for i in tqdm(range(addressNumber)):

            userID = "user" + format(i, '03')

            private_key = RSA.generate(3072)
            public_key = private_key.publickey()

            with open("../key/private_key_{}.pem".format(userID), "wb") as f1:
                f1.write(private_key.export_key('PEM'))
            with open("../key/public_key_{}.pem".format(userID), "wb") as f2:
                f2.write(public_key.export_key('PEM'))

            key = Key()
            key.generate()

            address = Address(key)
            address._generate_publicaddress1_testnet()
            
            f.write("{}\n".format(address.pubaddr1_testnet))
Beispiel #8
0
    def testFromHex_L(self):
        # given
        key = Key.of(
            'c2814c56793485f803430ef28ea93ba34e1dc74a74cead43407378350a958792')

        # then
        self.assertEqual(
            key.hex,
            'c2814c56793485f803430ef28ea93ba34e1dc74a74cead43407378350a958792')
        self.assertEqual(
            key.mainnet.wif,
            '5KHwxCT8Nrb3MSiQRS5h6fqmAJWrXzi9min15xSzY1EuR3EgLHT')
        self.assertEqual(
            key.mainnet.wifc,
            'L3joYdYKZTsFPEVkNqhhz2SDv4JmdoidiPPdNsjiwr4NLr31PkqK')
Beispiel #9
0
    def testAddress(self):
        # when
        address = Address(Key())
        address_dict = address.generate()

        # then
        self.assertIn('pubkey', address_dict)
        self.assertEqual(len(address_dict['pubkey']), 130)
        self.assertIn('pubkeyc', address_dict)
        self.assertEqual(len(address_dict['pubkeyc']), 66)
        self.assertIn('pubaddr1', address_dict)
        self.assertEqual(len(address_dict['pubaddr1']), 34)
        self.assertIn('pubaddr3', address_dict)
        self.assertEqual(len(address_dict['pubaddr3']), 34)
        self.assertIn('pubaddrbc1_p2wsh', address_dict)
        self.assertEqual(len(address_dict['pubaddrbc1_p2wsh']), 62)
        self.assertIn('pubaddrbc1_p2wpkh', address_dict)
        self.assertEqual(len(address_dict['pubaddrbc1_p2wpkh']), 42)
        self.assertIn('testnet', address_dict)
Beispiel #10
0
    def testFromRandomSeed(self):
        # when
        key = Key.of(Seed())
        address = address = Address.of(key)

        # then
        self.assertEqual(len(address.pubkey), 130)
        self.assertEqual(len(address.pubkeyc), 66)

        self.assertEqual(len(address.mainnet.pubaddr1), 34)
        self.assertEqual(len(address.mainnet.pubaddr1c), 34)
        self.assertEqual(len(address.mainnet.pubaddr3), 34)
        self.assertEqual(len(address.mainnet.pubaddrbc1_P2WSH), 62)
        self.assertEqual(len(address.mainnet.pubaddrbc1_P2WPKH), 42)

        self.assertEqual(len(address.testnet.pubaddr1), 34)
        self.assertEqual(len(address.testnet.pubaddr1c), 34)
        self.assertEqual(len(address.testnet.pubaddr3), 35)
        self.assertEqual(len(address.testnet.pubaddrtb1_P2WSH), 62)
        self.assertEqual(len(address.testnet.pubaddrtb1_P2WPKH), 42)
Beispiel #11
0
    def testFromWIF(self):
        # given
        key = Key.of('5JbTZ4zCTn1rwCfdkPWLddFgqzieGaG9Qjp3iRhf7R8gNroj4KM')
        address = Address.of(key)

        # then
        self.assertEqual(
            address.pubkey.upper(),
            "04E61341F46B529B0FAC2C5E15A67AF7AFFCEB2BE7544AF18D14206FFF041C02C04D6CA36C97F458CFE5754CE15A8F32D4C917B5F0F5E336042EE3BE77C3F58222"
        )
        self.assertEqual(
            address.pubkeyc.upper(),
            "02E61341F46B529B0FAC2C5E15A67AF7AFFCEB2BE7544AF18D14206FFF041C02C0"
        )

        self.assertEqual(address.mainnet.pubaddr1,
                         "1NaChZV4JJysct8QYcMKFHnQ2SNFpnBund")
        self.assertEqual(address.mainnet.pubaddr1c,
                         "1D7XaU5PbsPxfZeYBcGGyMEqiVvPhtFMUF")
        self.assertEqual(address.mainnet.pubaddr3,
                         "34QhdWUjZjv3HLyvNYgb4AR7ikAfcdzfCW")
        self.assertEqual(
            address.mainnet.pubaddrbc1_P2WSH,
            "bc1qup6umurcl7s6zw42gcxfzl346psazws74x72ty6gmlvkaxz6kv4sqsth99")
        self.assertEqual(address.mainnet.pubaddrbc1_P2WPKH,
                         "bc1qsnwc0y43fpljyl2ep0e2gtsqa55utcj4ntzwlf")

        self.assertEqual(address.testnet.pubaddr1,
                         "n369zca37LR8Pzc2GBKh5CzitRxxhkHDhK")
        self.assertEqual(address.testnet.pubaddr1c,
                         "msdUsXANQtqDSg89uBEeoGTAaVX6bWK3dW")
        self.assertEqual(address.testnet.pubaddr3,
                         "2MuxuhFQmBCRPV8cU3gJTg7QNw6NqTuUm2A")
        self.assertEqual(
            address.testnet.pubaddrtb1_P2WSH,
            "tb1qup6umurcl7s6zw42gcxfzl346psazws74x72ty6gmlvkaxz6kv4shcacl2")
        self.assertEqual(address.testnet.pubaddrtb1_P2WPKH,
                         "tb1qsnwc0y43fpljyl2ep0e2gtsqa55utcj4edeay6")
Beispiel #12
0
    def testIntegrationKeySeed(self):
        # when
        key1 = Key()
        keys_dict_1 = key1.generate()

        key2 = Key('myseed')
        keys_dict_2 = key2.generate()

        key3 = Key('myseed')
        keys_dict_3 = key3.generate()

        key4 = Key('myseed2')
        keys_dict_4 = key4.generate()

        # then
        self.assertIn('hex', keys_dict_1)
        self.assertEqual(len(keys_dict_1['hex']), 64)
        self.assertIn('wif', keys_dict_1)
        self.assertEqual(len(keys_dict_1['wif']), 51)
        self.assertIn('wifc', keys_dict_1)
        self.assertEqual(len(keys_dict_1['wifc']), 52)
        self.assertIn('testnet', keys_dict_1)

        self.assertTrue(keys_dict_1 != keys_dict_2)
        self.assertFalse(keys_dict_2 != keys_dict_3)
        self.assertTrue(keys_dict_3 != keys_dict_4)