当前位置: 首页>>代码示例>>Python>>正文


Python Key.public_pair方法代码示例

本文整理汇总了Python中pycoin.key.Key.public_pair方法的典型用法代码示例。如果您正苦于以下问题:Python Key.public_pair方法的具体用法?Python Key.public_pair怎么用?Python Key.public_pair使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pycoin.key.Key的用法示例。


在下文中一共展示了Key.public_pair方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _build_signature

# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import public_pair [as 别名]
def _build_signature(key, tbs, network):
    ''' Takes a utility.ECPrivateKey() as key, tbs as rfc2459.TBSCertificate, and network as pycoin.NETWORK_NAMES
    '''
    secret_exponent = encoding.to_long(256, encoding.byte_to_int, key[0][1].asOctets())[0]
    coin  = Key(secret_exponent=secret_exponent, netcode=network)
    public_pair = coin.public_pair()
    coin_address = coin.address()
    print "building signature for %s address %s" % (network, coin_address)
    pubkeybitstring = (key[0].getComponentByPosition(2), key[0].getComponentByPosition(3))
    tbsder = encoder.encode(tbs)
    hashvalue = SHA256.new(tbsder)
    dgst = hashvalue.digest()
    dgstaslong = encoding.to_long(256, encoding.byte_to_int, dgst)[0]
    order2 = pycoin.ecdsa.generator_secp256k1.order()
    ## random sign
    generator = pycoin.ecdsa.generator_secp256k1
    rawsig2 = randomsign(generator, secret_exponent, dgstaslong)
    # deterministic sign
    ##rawsig2 = pycoin.ecdsa.sign(pycoin.ecdsa.generator_secp256k1, secret_exponent, dgstaslong)
    r2, s2 = rawsig2
    print "signature: r: %x s: %x" % (r2, s2)
    if not pycoin.ecdsa.verify(generator, coin.public_pair(), dgstaslong, rawsig2):
        raise SignatureVerifyException("Generated signature r: %x s: %x does not verify against public key %s" % (r2, s2, public_pair))
    signature = utility.ECDSASigValue()
    signature.setComponentByName('r', r2)
    signature.setComponentByName('s', s2)
    dersig = encoder.encode(signature)
    signaturevalue = "'{0}'H".format(binascii.hexlify(dersig))
    bitstring = univ.BitString( value=signaturevalue )
    return rfc2314.Signature( bitstring )
开发者ID:1-Hash,项目名称:UTXOC,代码行数:32,代码来源:utxocsign.py

示例2: test_against_myself

# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import public_pair [as 别名]
def test_against_myself():
    """
        Test code that verifies against ourselves only. Useful but not so great.
    """
    from pycoin.key import Key, msg_signing
    from pycoin.encoding import bitcoin_address_to_hash160_sec_with_prefix
    from pycoin.encoding import wif_to_tuple_of_secret_exponent_compressed
    from pycoin.key.msg_signing import parse_signed_message

    for wif, right_addr in [
                    ('L4gXBvYrXHo59HLeyem94D9yLpRkURCHmCwQtPuWW9m6o1X8p8sp',
                            '1LsPb3D1o1Z7CzEt1kv5QVxErfqzXxaZXv'),
                    ('5KYZdUEo39z3FPrtuX2QbbwGnNP5zTd7yyr2SC1j299sBCnWjss',
                            '1HZwkjkeaoZfTSaJxDw6aKkxp45agDiEzN'),
                ]:
        se, comp = wif_to_tuple_of_secret_exponent_compressed(wif)

        k = Key(secret_exponent=se, is_compressed=comp)
        assert k.address() == right_addr

        #print("\nAddr %s compressed=%s" % (right_addr, comp))

        vk = Key(public_pair=k.public_pair(), is_compressed=comp)
        assert vk.address() == right_addr

        h160, pubpre = bitcoin_address_to_hash160_sec_with_prefix(right_addr)
        vk2 = Key(hash160=h160)
        assert vk2.address() == right_addr

        for i in range(1, 30, 10):
            msg = 'test message %s' % ('A'*i)
            sig = msg_signing.sign_message(k, msg, verbose=1)
            #print(sig)
            assert right_addr in sig

            # check parsing works
            m,a,s = parse_signed_message(sig)
            assert m == msg, m
            assert a == right_addr, a

            sig2 = msg_signing.sign_message(k, msg, verbose=0)
            assert sig2 in sig, (sig, sig2)

            assert s == sig2, s

            ok = msg_signing.verify_message(k, sig2, msg)
            #print("verifies: %s" % ("Ok" if ok else "WRONG"))
            assert ok
开发者ID:opendime,项目名称:pycoin,代码行数:50,代码来源:msg_signing_test.py

示例3: test_points

# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import public_pair [as 别名]

#.........这里部分代码省略.........
        test_points.append((k, x, y))
        k = 115792089237316195423570985008687907852837564279074904382605163141518161494320
        x = 0xDEFDEA4CDB677750A420FEE807EACF21EB9898AE79B9768766E4FAA04A2D4A34
        y = 0xBDEE54F96B9CAE9716684F152D56C251312E0B5FB56A3F09304E660861A910B8
        test_points.append((k, x, y))
        k = 115792089237316195423570985008687907852837564279074904382605163141518161494321
        x = 0xE60FCE93B59E9EC53011AABC21C23E97B2A31369B87A5AE9C44EE89E2A6DEC0A
        y = 0x081CAF8C661A6A6D624660CB0A86C8EFED6976E1BB2DC0F41E0CD330969E940E
        test_points.append((k, x, y))
        k = 115792089237316195423570985008687907852837564279074904382605163141518161494322
        x = 0xD7924D4F7D43EA965A465AE3095FF41131E5946F3C85F79E44ADBCF8E27E080E
        y = 0xA7E1D78D57938D597C7BD13DD733921015BF50D427692C5A3AFB235F095D90D7
        test_points.append((k, x, y))
        k = 115792089237316195423570985008687907852837564279074904382605163141518161494323
        x = 0x499FDF9E895E719CFD64E67F07D38E3226AA7B63678949E6E49B241A60E823E4
        y = 0x353D093B4AB17AAE6F0FBB1B584C2B9BB9BD863D85C06A4339A0BF2AFC5EBCD4
        test_points.append((k, x, y))
        k = 115792089237316195423570985008687907852837564279074904382605163141518161494324
        x = 0xF28773C2D975288BC7D1D205C3748651B075FBC6610E58CDDEEDDF8F19405AA8
        y = 0xF54F6FD17277F5768A7DED149A3250B8C5E5F925ADE056E0D64A34AC24FC0EAE
        test_points.append((k, x, y))
        k = 115792089237316195423570985008687907852837564279074904382605163141518161494325
        x = 0xD01115D548E7561B15C38F004D734633687CF4419620095BC5B0F47070AFE85A
        y = 0x560CB00237EA1F285749BAC81E8427EA86DC73A2265792AD94FAE4EB0BF9D908
        test_points.append((k, x, y))
        k = 115792089237316195423570985008687907852837564279074904382605163141518161494326
        x = 0x774AE7F858A9411E5EF4246B70C65AAC5649980BE5C17891BBEC17895DA008CB
        y = 0x267B5FCD1494A1E6FDBC22A928484C9AC8D24E1D20062957CFE28B3536AC3614
        test_points.append((k, x, y))
        k = 115792089237316195423570985008687907852837564279074904382605163141518161494327
        x = 0xA0434D9E47F3C86235477C7B1AE6AE5D3442D49B1943C2B752A68E2A47E247C7
        y = 0x76C545BDABE643D85C4938196C5DB3969086B3D127885EA6C3411AC3FC8C9358
        test_points.append((k, x, y))
        k = 115792089237316195423570985008687907852837564279074904382605163141518161494328
        x = 0xACD484E2F0C7F65309AD178A9F559ABDE09796974C57E714C35F110DFC27CCBE
        y = 0x33CC76DE4F5826029BC7F68E89C49E165227775BC8A071F0FA33D9D439B05FF8
        test_points.append((k, x, y))
        k = 115792089237316195423570985008687907852837564279074904382605163141518161494329
        x = 0x2F01E5E15CCA351DAFF3843FB70F3C2F0A1BDD05E5AF888A67784EF3E10A2A01
        y = 0xA3B25758BEAC66B6D6C2F7D5ECD2EC4B3D1DEC2945A489E84A25D3479342132B
        test_points.append((k, x, y))
        k = 115792089237316195423570985008687907852837564279074904382605163141518161494330
        x = 0x5CBDF0646E5DB4EAA398F365F2EA7A0E3D419B7E0330E39CE92BDDEDCAC4F9BC
        y = 0x951435BF45DAA69F5CE8729279E5AB2457EC2F47EC02184A5AF7D9D6F78D9755
        test_points.append((k, x, y))
        k = 115792089237316195423570985008687907852837564279074904382605163141518161494331
        x = 0xFFF97BD5755EEEA420453A14355235D382F6472F8568A18B2F057A1460297556
        y = 0x51ED8885530449DF0C4169FE80BA3A9F217F0F09AE701B5FC378F3C84F8A0998
        test_points.append((k, x, y))
        k = 115792089237316195423570985008687907852837564279074904382605163141518161494332
        x = 0x2F8BDE4D1A07209355B4A7250A5C5128E88B84BDDC619AB7CBA8D569B240EFE4
        y = 0x2753DDD9C91A1C292B24562259363BD90877D8E454F297BF235782C459539959
        test_points.append((k, x, y))
        k = 115792089237316195423570985008687907852837564279074904382605163141518161494333
        x = 0xE493DBF1C10D80F3581E4904930B1404CC6C13900EE0758474FA94ABE8C4CD13
        y = 0xAE1266C15F2BAA48A9BD1DF6715AEBB7269851CC404201BF30168422B88C630D
        test_points.append((k, x, y))
        k = 115792089237316195423570985008687907852837564279074904382605163141518161494334
        x = 0xF9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9
        y = 0xC77084F09CD217EBF01CC819D5C80CA99AFF5666CB3DDCE4934602897B4715BD
        test_points.append((k, x, y))
        k = 115792089237316195423570985008687907852837564279074904382605163141518161494335
        x = 0xC6047F9441ED7D6D3045406E95C07CD85C778E4B8CEF3CA7ABAC09B95C709EE5
        y = 0xE51E970159C23CC65C3A7BE6B99315110809CD9ACD992F1EDC9BCE55AF301705
        test_points.append((k, x, y))
        k = 115792089237316195423570985008687907852837564279074904382605163141518161494336
        x = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798
        y = 0xB7C52588D95C3B9AA25B0403F1EEF75702E84BB7597AABE663B82F6F04EF2777
        test_points.append((k, x, y))
        k = 0xaa5e28d6a97a2479a65527f7290311a3624d4cc0fa1578598ee3c2613bf99522
        x = 0x34f9460f0e4f08393d192b3c5133a6ba099aa0ad9fd54ebccfacdfa239ff49c6
        y = 0x0b71ea9bd730fd8923f6d25a7a91e7dd7728a960686cb5a901bb419e0f2ca232
        test_points.append((k, x, y))
        k = 0x7e2b897b8cebc6361663ad410835639826d590f393d90a9538881735256dfae3
        x = 0xd74bf844b0862475103d96a611cf2d898447e288d34b360bc885cb8ce7c00575
        y = 0x131c670d414c4546b88ac3ff664611b1c38ceb1c21d76369d7a7a0969d61d97d
        test_points.append((k, x, y))
        k = 0x6461e6df0fe7dfd05329f41bf771b86578143d4dd1f7866fb4ca7e97c5fa945d
        x = 0xe8aecc370aedd953483719a116711963ce201ac3eb21d3f3257bb48668c6a72f
        y = 0xc25caf2f0eba1ddb2f0f3f47866299ef907867b7d27e95b3873bf98397b24ee1
        test_points.append((k, x, y))
        k = 0x376a3a2cdcd12581efff13ee4ad44c4044b8a0524c42422a7e1e181e4deeccec
        x = 0x14890e61fcd4b0bd92e5b36c81372ca6fed471ef3aa60a3e415ee4fe987daba1
        y = 0x297b858d9f752ab42d3bca67ee0eb6dcd1c2b7b0dbe23397e66adc272263f982
        test_points.append((k, x, y))
        k = 0x1b22644a7be026548810c378d0b2994eefa6d2b9881803cb02ceff865287d1b9
        x = 0xf73c65ead01c5126f28f442d087689bfa08e12763e0cec1d35b01751fd735ed3
        y = 0xf449a8376906482a84ed01479bd18882b919c140d638307f0c0934ba12590bde
        test_points.append((k, x, y))

        for k, x, y in test_points:
            p = Point(secp256k1_curve, x, y)
            self.assertTrue(secp256k1_curve.contains_point(p.x(), p.y()))
            K = Key(public_pair=(x, y))
            k = Key(secret_exponent=k)
            self.assertEqual(K.public_pair(), k.public_pair())

        x = y = 0
        self.assertRaises(NoSuchPointError, Point, secp256k1_curve, x, y)
        self.assertRaises(InvalidPublicPairError, Key, public_pair=(0, 0))
开发者ID:Stevengu999,项目名称:pycoin,代码行数:104,代码来源:key_validate_test.py

示例4: main

# 需要导入模块: from pycoin.key import Key [as 别名]
# 或者: from pycoin.key.Key import public_pair [as 别名]
def main():
    parser = argparse.ArgumentParser(
        description='ECkey2coin.py by [email protected] for UTXO based Certificates UTXOC.',
        epilog='Known networks codes:\n  ' \
                + ', '.join(['%s (%s)'%(i, full_network_name_for_netcode(i)) for i in NETWORK_NAMES])
    )
    parser.add_argument('-k', '--key', required=False, type=argparse.FileType('r'), help='The EC private key in PEM format')
    parser.add_argument('-q', '--qrfilename', required=False, help='QR code output filename')
    parser.add_argument('-n', "--network", help='specify network (default: BTC = Bitcoin)',
                                default='BTC', choices=NETWORK_NAMES)
    args = parser.parse_args()
    network = args.network
    inputprivatekey = ''
    if args.key:
        keyfile = args.key        
        while True:
            line = keyfile.readline().strip()
            if not line: break
            inputprivatekey += line + '\n'
        print 'Loaded EC Key from %s' % keyfile
    else:    
        print ('Please enter EC KEY in pem format:')
        inputprivatekey  = ''
        while True:
            line = raw_input().strip()
            if not line: break
            inputprivatekey += line + '\n'
    if not args.qrfilename:
        qrfilename = raw_input("Please enter qrcode output filename: ")
    else:
        qrfilename = args.qrfilename
    pkey = decoder.decode(read_pem(inputprivatekey), asn1Spec=ECPrivateKey())
    print 'Key loaded'
    if not isValidECKey(pkey[0]):
        print "EC Key Supplied cannot be used"
        exit
    print "Key Validated OK"
    inputkey = encoding.to_long(256, pycoin.encoding.byte_to_int, pkey[0][1].asOctets())[0]
    if inputkey:
        key = Key(secret_exponent=inputkey, netcode=network)
        btcsecret = key.secret_exponent()
        btcpublic = key.public_pair()
        hash160_c = key.hash160(use_uncompressed=False)
        hash160_u = key.hash160(use_uncompressed=True)
        qrimg = qrcode.QRCode (
            version=1,
            error_correction=qrcode.constants.ERROR_CORRECT_L,
            box_size=10,
            border=4,
        )
        qrimg.add_data(key.address(use_uncompressed=False))
        qrimg.make(fit=True)
        img = qrimg.make_image()
        img.save(qrfilename)
    print"----------------- BEGIN EC PRIVATE KEYS -----------------"
    print "Secret:     %d" % btcsecret
    print "Secret hex: %x" % btcsecret
    print "wif:        %s" % key.wif(use_uncompressed=False)
    print "----------------- END EC PRIVATE KEYS -----------------------------"
    print "----------------- BEGIN PUBLIC KEY -----------------------------"
    print "Public X: %d" % btcpublic[0]
    print "Public Y: %d" % btcpublic[1]
    print "hash160 uncompressed: %s" % b2h(hash160_u)
    print "Sec: (uncompressed): %s" % b2h(key.sec(use_uncompressed=True))
    print "%s address: %s (uncompressed)" % (key._netcode, key.address(use_uncompressed=True))
    print "Public X (hex): %x" % btcpublic[0]
    print "Public Y (hex): %x" % btcpublic[1]
    print "Sec: %s" % b2h(key.sec(use_uncompressed=False))
    print "hash160 compressed: %s" % b2h(hash160_c)
    print "----------------- END PUBLIC KEYS -----------------------------"
    print "------------------ BEGIN %s ADDRESSES -------------------------" % key._netcode
    print "%s address: %s" % (key._netcode, key.address(use_uncompressed=False))
    print "------------------ END %s ADDRESSES -------------------------" % key._netcode
开发者ID:1-Hash,项目名称:UTXOC,代码行数:75,代码来源:eckey2coin.py


注:本文中的pycoin.key.Key.public_pair方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。