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


Python ecdsa.public_pair_for_secret_exponent函数代码示例

本文整理汇总了Python中pycoin.ecdsa.public_pair_for_secret_exponent函数的典型用法代码示例。如果您正苦于以下问题:Python public_pair_for_secret_exponent函数的具体用法?Python public_pair_for_secret_exponent怎么用?Python public_pair_for_secret_exponent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: test_build_spends

    def test_build_spends(self):
        # first, here is the tx database
        TX_DB = {}

        # create a coinbase Tx where we know the public & private key

        exponent = wif_to_secret_exponent("5JMys7YfK72cRVTrbwkq5paxU7vgkMypB55KyXEtN5uSnjV7K8Y")
        compressed = False

        public_key_sec = public_pair_to_sec(
            ecdsa.public_pair_for_secret_exponent(ecdsa.generator_secp256k1, exponent), compressed=compressed
        )

        the_coinbase_tx = Tx.coinbase_tx(public_key_sec, int(50 * 1e8), COINBASE_BYTES_FROM_80971)
        TX_DB[the_coinbase_tx.hash()] = the_coinbase_tx

        # now create a Tx that spends the coinbase

        compressed = False

        exponent_2 = int("137f3276686959c82b454eea6eefc9ab1b9e45bd4636fb9320262e114e321da1", 16)
        bitcoin_address_2 = public_pair_to_bitcoin_address(
            ecdsa.public_pair_for_secret_exponent(ecdsa.generator_secp256k1, exponent_2), compressed=compressed
        )

        self.assertEqual("12WivmEn8AUth6x6U8HuJuXHaJzDw3gHNZ", bitcoin_address_2)

        coins_from = [(the_coinbase_tx.hash(), 0, the_coinbase_tx.txs_out[0])]
        coins_to = [(int(50 * 1e8), bitcoin_address_2)]
        unsigned_coinbase_spend_tx = standard_tx(coins_from, coins_to)
        solver = build_hash160_lookup([exponent])

        coinbase_spend_tx = unsigned_coinbase_spend_tx.sign(solver)

        # now check that it validates
        self.assertEqual(coinbase_spend_tx.bad_signature_count(), 0)

        TX_DB[coinbase_spend_tx.hash()] = coinbase_spend_tx

        ## now try to respend from priv_key_2 to priv_key_3

        compressed = True

        exponent_3 = int("f8d39b8ecd0e1b6fee5a340519f239097569d7a403a50bb14fb2f04eff8db0ff", 16)
        bitcoin_address_3 = public_pair_to_bitcoin_address(
            ecdsa.public_pair_for_secret_exponent(ecdsa.generator_secp256k1, exponent_3), compressed=compressed
        )

        self.assertEqual("13zzEHPCH2WUZJzANymow3ZrxcZ8iFBrY5", bitcoin_address_3)

        coins_from = [(coinbase_spend_tx.hash(), 0, coinbase_spend_tx.txs_out[0])]
        unsigned_spend_tx = standard_tx(coins_from, [(int(50 * 1e8), bitcoin_address_3)])
        solver.update(build_hash160_lookup([exponent_2]))
        spend_tx = unsigned_spend_tx.sign(solver)

        # now check that it validates
        self.assertEqual(spend_tx.bad_signature_count(), 0)
开发者ID:mperklin,项目名称:pycoin,代码行数:57,代码来源:build_tx_test.py

示例2: importprivkey

 def importprivkey(self, wif):
     secret_exponent = wif_to_secret_exponent(wif) 
     public_pair = ecdsa.public_pair_for_secret_exponent(ecdsa.generator_secp256k1, secret_exponent)
     address = public_pair_to_bitcoin_address(public_pair)
     secret_exponent = hex(secret_exponent)[2:].encode('utf8')
     self.insertaddress(address, secret_exponent)
     return address
开发者ID:Bluejudy,项目名称:pyrpcwallet,代码行数:7,代码来源:wallet.py

示例3: do_test

 def do_test(secret_exponent, val_list):
     public_point = public_pair_for_secret_exponent(generator_secp256k1, secret_exponent)
     for v in val_list:
         signature = sign(generator_secp256k1, secret_exponent, v)
         r = verify(generator_secp256k1, public_point, v, signature)
         assert r == True
         signature = signature[0],signature[1]+1
         r = verify(generator_secp256k1, public_point, v, signature)
         assert r == False
开发者ID:Bluejudy,项目名称:pycoin,代码行数:9,代码来源:ecdsa_test.py

示例4: gen_address

def gen_address(private_key, compressed=True):
    # private_key = codecs.encode(os.urandom(32), 'hex').decode()
    secret_exponent = int('0x' + private_key, 0)
    print('WIF: ' + encoding.secret_exponent_to_wif(secret_exponent, compressed=compressed))
    public_pair = ecdsa.public_pair_for_secret_exponent(ecdsa.secp256k1.generator_secp256k1, secret_exponent)
    print('public pair:', public_pair)
    hash160 = encoding.public_pair_to_hash160_sec(public_pair, compressed=compressed)
    print("hash160: {}".format(hash160.hex()))
    return encoding.hash160_sec_to_bitcoin_address(hash160, address_prefix=b'\0')
开发者ID:memoryboxes,项目名称:learn123,代码行数:9,代码来源:genaddr.py

示例5: private_key_to_public_key

def private_key_to_public_key (private_key_wif):
    try:
        secret_exponent, compressed = wif_to_tuple_of_secret_exponent_compressed(private_key_wif, [wif_prefix(is_test=config.TESTNET)])
    except EncodingError:
        raise exceptions.AltcoinSupportError('pycoin: unsupported WIF prefix')
    public_pair = public_pair_for_secret_exponent(generator_secp256k1, secret_exponent)
    public_key = public_pair_to_sec(public_pair, compressed=compressed)
    public_key_hex = binascii.hexlify(public_key).decode('utf-8')
    return public_key_hex
开发者ID:LeeAbell79,项目名称:dogepartyd,代码行数:9,代码来源:bitcoin.py

示例6: test_build_spends

    def test_build_spends(self):
        # create a coinbase Tx where we know the public & private key

        exponent = wif_to_secret_exponent("5JMys7YfK72cRVTrbwkq5paxU7vgkMypB55KyXEtN5uSnjV7K8Y")
        compressed = False

        public_key_sec = public_pair_to_sec(ecdsa.public_pair_for_secret_exponent(ecdsa.generator_secp256k1, exponent), compressed=compressed)

        the_coinbase_tx = Tx.coinbase_tx(public_key_sec, int(50 * 1e8), COINBASE_BYTES_FROM_80971)

        # now create a Tx that spends the coinbase

        compressed = False

        exponent_2 = int("137f3276686959c82b454eea6eefc9ab1b9e45bd4636fb9320262e114e321da1", 16)
        bitcoin_address_2 = public_pair_to_bitcoin_address(
                ecdsa.public_pair_for_secret_exponent(ecdsa.generator_secp256k1, exponent_2),
                compressed=compressed)

        self.assertEqual("12WivmEn8AUth6x6U8HuJuXHaJzDw3gHNZ", bitcoin_address_2)

        TX_DB = dict((tx.hash(), tx) for tx in [the_coinbase_tx])

        coins_from = [(the_coinbase_tx.hash(), 0)]
        coins_to = [(int(50 * 1e8), bitcoin_address_2)]
        coinbase_spend_tx = Tx.standard_tx(coins_from, coins_to, TX_DB, [exponent])
        coinbase_spend_tx.validate(TX_DB)

        ## now try to respend from priv_key_2 to priv_key_3

        compressed = True

        exponent_3 = int("f8d39b8ecd0e1b6fee5a340519f239097569d7a403a50bb14fb2f04eff8db0ff", 16)
        bitcoin_address_3 = public_pair_to_bitcoin_address(
                ecdsa.public_pair_for_secret_exponent(ecdsa.generator_secp256k1, exponent_3),
                compressed=compressed)

        self.assertEqual("13zzEHPCH2WUZJzANymow3ZrxcZ8iFBrY5", bitcoin_address_3)

        TX_DB = dict((tx.hash(), tx) for tx in [coinbase_spend_tx])

        spend_tx = Tx.standard_tx([(coinbase_spend_tx.hash(), 0)], [(int(50 * 1e8), bitcoin_address_3)], TX_DB, [exponent_2])

        spend_tx.validate(TX_DB)
开发者ID:Luis-Fernando-Molina,项目名称:pycoin,代码行数:44,代码来源:build_tx_test.py

示例7: main

def main():
    parser = argparse.ArgumentParser(description="Bitcoin utilities. WARNING: obsolete. Use ku instead.")

    parser.add_argument('-a', "--address", help='show as Bitcoin address', action='store_true')
    parser.add_argument('-1', "--hash160", help='show as hash 160', action='store_true')
    parser.add_argument('-v', "--verbose", help='dump all information available', action='store_true')
    parser.add_argument('-w', "--wif", help='show as Bitcoin WIF', action='store_true')
    parser.add_argument('-n', "--uncompressed", help='show in uncompressed form', action='store_true')
    parser.add_argument('item', help='a WIF, secret exponent, X/Y public pair, SEC (as hex), hash160 (as hex), Bitcoin address', nargs="+")
    args = parser.parse_args()

    for c in args.item:
        # figure out what it is:
        #  - secret exponent
        #  - WIF
        #  - X/Y public key (base 10 or hex)
        #  - sec
        #  - hash160
        #  - Bitcoin address
        secret_exponent = parse_as_private_key(c)
        if secret_exponent:
            public_pair = ecdsa.public_pair_for_secret_exponent(secp256k1.generator_secp256k1, secret_exponent)
            print("secret exponent: %d" % secret_exponent)
            print("  hex:           %x" % secret_exponent)
            print("WIF:             %s" % encoding.secret_exponent_to_wif(secret_exponent, compressed=True))
            print("  uncompressed:  %s" % encoding.secret_exponent_to_wif(secret_exponent, compressed=False))
        else:
            public_pair = parse_as_public_pair(c)
        if public_pair:
            bitcoin_address_uncompressed = encoding.public_pair_to_bitcoin_address(public_pair, compressed=False)
            bitcoin_address_compressed = encoding.public_pair_to_bitcoin_address(public_pair, compressed=True)
            print("public pair x:   %d" % public_pair[0])
            print("public pair y:   %d" % public_pair[1])
            print("  x as hex:      %x" % public_pair[0])
            print("  y as hex:      %x" % public_pair[1])
            print("y parity:        %s" % "odd" if (public_pair[1] & 1) else "even")
            print("key pair as sec: %s" % b2h(encoding.public_pair_to_sec(public_pair, compressed=True)))
            s = b2h(encoding.public_pair_to_sec(public_pair, compressed=False))
            print("  uncompressed:  %s\\\n                   %s" % (s[:66], s[66:]))
            hash160 = encoding.public_pair_to_hash160_sec(public_pair, compressed=True)
            hash160_unc = encoding.public_pair_to_hash160_sec(public_pair, compressed=False)
            myeccpoint = encoding.public_pair_to_sec(public_pair, compressed=True)
            myhash     = encoding.ripemd160( myeccpoint ).digest(  )
            print("BTSX PubKey:     %s" % BTS_ADDRESS_PREFIX + encoding.b2a_base58(myeccpoint + myhash[ :4 ]))
        else:
            hash160 = parse_as_address(c)
            hash160_unc = None
        if not hash160:
            sys.stderr.write("can't decode input %s\n" % c)
            sys.exit(1)
        print("hash160:         %s" % b2h(hash160))
        if hash160_unc:
            print("  uncompressed:  %s" % b2h(hash160_unc))
        print("Bitcoin address: %s" % encoding.hash160_sec_to_bitcoin_address(hash160))
        if hash160_unc:
            print("  uncompressed:  %s" % encoding.hash160_sec_to_bitcoin_address(hash160_unc))
开发者ID:fedaykinofdune,项目名称:pytshares,代码行数:56,代码来源:bu-mod.py

示例8: __init__

 def __init__(self, secret_exponents):
     super(OfflineAwareSolver, self).__init__(secret_exponents)
     STANDARD_SCRIPT_OUT = "OP_DUP OP_HASH160 %s OP_EQUALVERIFY OP_CHECKSIG"
     self.script_hash160 = []
     for se in secret_exponents:
         pp = public_pair_for_secret_exponent(generator_secp256k1, se)
         h160sec = public_pair_to_hash160_sec(pp, False)
         script_text = STANDARD_SCRIPT_OUT % b2h(h160sec)
         print script_text
         self.script_hash160.append(compile(script_text))
开发者ID:nelisky,项目名称:pycoin,代码行数:10,代码来源:proxy.py

示例9: test_signature_hash

    def test_signature_hash(self):
        compressed = False
        exponent_2 = int("137f3276686959c82b454eea6eefc9ab1b9e45bd4636fb9320262e114e321da1", 16)
        bitcoin_address_2 = public_pair_to_bitcoin_address(
                ecdsa.public_pair_for_secret_exponent(ecdsa.generator_secp256k1, exponent_2),
                compressed=compressed)
        exponent = wif_to_secret_exponent("5JMys7YfK72cRVTrbwkq5paxU7vgkMypB55KyXEtN5uSnjV7K8Y")

        public_key_sec = public_pair_to_sec(ecdsa.public_pair_for_secret_exponent(ecdsa.generator_secp256k1, exponent), compressed=compressed)

        the_coinbase_tx = Tx.coinbase_tx(public_key_sec, int(50 * 1e8), COINBASE_BYTES_FROM_80971)
        coins_from = [(the_coinbase_tx.hash(), 0, the_coinbase_tx.txs_out[0])]
        coins_to = [(int(50 * 1e8), bitcoin_address_2)]
        unsigned_coinbase_spend_tx = standard_tx(coins_from, coins_to)

        tx_out_script_to_check = the_coinbase_tx.txs_out[0].script
        idx = 0
        actual_hash = unsigned_coinbase_spend_tx.signature_hash(tx_out_script_to_check, idx, hash_type=SIGHASH_ALL)
        self.assertEqual(actual_hash, 29819170155392455064899446505816569230970401928540834591675173488544269166940)
开发者ID:Bluejudy,项目名称:pycoin,代码行数:19,代码来源:build_tx_test.py

示例10: __init__

    def __init__(self, secret_exponent=None, public_pair=None, hash160=None,
                 prefer_uncompressed=None, is_compressed=True, is_pay_to_script=False, netcode=None):
        """
        secret_exponent:
            a long representing the secret exponent
        public_pair:
            a tuple of long integers on the ecdsa curve
        hash160:
            a hash160 value corresponding to a bitcoin address

        Include at most one of secret_exponent, public_pair or hash160.

        prefer_uncompressed:
            whether or not to produce text outputs as compressed or uncompressed.

        is_pay_to_script:
            whether or not this key is for a pay-to-script style transaction

        netcode:
            the code for the network (as defined in pycoin.networks)

        Include at most one of secret_exponent, public_pair or hash160.
        prefer_uncompressed, is_compressed (booleans) are optional.
        """

        if netcode is None:
            netcode = get_current_netcode()
        if [secret_exponent, public_pair, hash160].count(None) != 2:
            raise ValueError("exactly one of secret_exponent, public_pair, hash160 must be passed.")
        if prefer_uncompressed is None:
            prefer_uncompressed = not is_compressed
        self._prefer_uncompressed = prefer_uncompressed
        self._secret_exponent = secret_exponent
        self._public_pair = public_pair
        self._hash160_uncompressed = None
        self._hash160_compressed = None
        if hash160:
            if is_compressed:
                self._hash160_compressed = hash160
            else:
                self._hash160_uncompressed = hash160
        self._netcode = netcode

        if self._public_pair is None and self._secret_exponent is not None:
            if self._secret_exponent < 1 \
                    or self._secret_exponent >= ecdsa.generator_secp256k1.order():
                raise InvalidSecretExponentError()
            public_pair = ecdsa.public_pair_for_secret_exponent(
                ecdsa.generator_secp256k1, self._secret_exponent)
            self._public_pair = public_pair

        if self._public_pair is not None \
                and (None in self._public_pair or
                     not ecdsa.is_public_pair_valid(ecdsa.generator_secp256k1, self._public_pair)):
            raise InvalidPublicPairError()
开发者ID:XertroV,项目名称:pycoin,代码行数:55,代码来源:Key.py

示例11: dumppubkey

 def dumppubkey(self, address):
     if is_valid_bitcoin_address(address)==False:
         return Exception("Invalid address %s" % address)
     try:
         secret_exponent = self.getsecretexponent(address)
         public_pair = ecdsa.public_pair_for_secret_exponent(ecdsa.generator_secp256k1, secret_exponent)
         pubkey = public_pair_to_sec(public_pair, compressed=True)
         pubkey = b2h(pubkey)
     except:
         raise Exception("Unknown address: %s" % address)
     return pubkey
开发者ID:Bluejudy,项目名称:pyrpcwallet,代码行数:11,代码来源:wallet.py

示例12: do_test

 def do_test(secret_exponent, val_list):
     public_point = public_pair_for_secret_exponent(generator_secp256k1, secret_exponent)
     for v in val_list:
         signature = sign(generator_secp256k1, secret_exponent, v)
         r = verify(generator_secp256k1, public_point, v, signature)
         # Check that the 's' value is 'low', to prevent possible transaction malleability as per
         # https://github.com/bitcoin/bips/blob/master/bip-0062.mediawiki#low-s-values-in-signatures
         assert signature[1] <= 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0
         assert r == True
         signature = signature[0],signature[1]+1
         r = verify(generator_secp256k1, public_point, v, signature)
         assert r == False
开发者ID:greenaddress,项目名称:pycoin,代码行数:12,代码来源:ecdsa_test.py

示例13: public_pair

    def public_pair(self):
        """
        Return a pair of integers representing the public key (or None).
        """
        if self._public_pair is None and self.secret_exponent():
            public_pair = ecdsa.public_pair_for_secret_exponent(
                ecdsa.generator_secp256k1, self._secret_exponent)
            if not ecdsa.is_public_pair_valid(ecdsa.generator_secp256k1, public_pair):
                raise InvalidKeyGeneratedError(
                    "this key would produce an invalid public pair; please skip it")
            self._public_pair = public_pair

        return self._public_pair
开发者ID:Bluejudy,项目名称:pycoin,代码行数:13,代码来源:Key.py

示例14: private_key_to_public_key

def private_key_to_public_key (private_key_wif):
    if config.TESTNET:
        allowable_wif_prefixes = [config.PRIVATEKEY_VERSION_TESTNET]
    else:
        allowable_wif_prefixes = [config.PRIVATEKEY_VERSION_MAINNET]
    try:
        secret_exponent, compressed = wif_to_tuple_of_secret_exponent_compressed(
                private_key_wif, allowable_wif_prefixes=allowable_wif_prefixes)
    except EncodingError:
        raise AltcoinSupportError('pycoin: unsupported WIF prefix')
    public_pair = public_pair_for_secret_exponent(generator_secp256k1, secret_exponent)
    public_key = public_pair_to_sec(public_pair, compressed=compressed)
    public_key_hex = binascii.hexlify(public_key).decode('utf-8')
    return public_key_hex
开发者ID:FuzzyBearBTC,项目名称:counterpartyd,代码行数:14,代码来源:bitcoin.py

示例15: create_coinbase_tx

def create_coinbase_tx(parser):
    args = parser.parse_args()
    try:
        if len(args.txinfo) != 1:
            parser.error("coinbase transactions need exactly one output parameter (wif/BTC count)")
        wif, btc_amount = args.txinfo[0].split("/")
        satoshi_amount = btc_to_satoshi(btc_amount)
        secret_exponent, compressed = encoding.wif_to_tuple_of_secret_exponent_compressed(wif)
        public_pair = ecdsa.public_pair_for_secret_exponent(ecdsa.secp256k1.generator_secp256k1, secret_exponent)
        public_key_sec = encoding.public_pair_to_sec(public_pair, compressed=compressed)
        coinbase_tx = Tx.coinbase_tx(public_key_sec, satoshi_amount)
        return coinbase_tx
    except Exception:
        parser.error("coinbase transactions need exactly one output parameter (wif/BTC count)")
开发者ID:Bluejudy,项目名称:pycoin,代码行数:14,代码来源:spend.py


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