• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python encoding.sec_to_public_pair函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: test_sec

 def test_sec(self):
     pair_blob = h2b(
         "0679be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"
     )
     public_pair = encoding.sec_to_public_pair(pair_blob, strict=False)
     try:
         public_pair = encoding.sec_to_public_pair(pair_blob, strict=True)
         self.fail("sec_to_public_pair unexpectedly succeeded")
     except encoding.EncodingError:
         pass
开发者ID:mperklin,项目名称:pycoin,代码行数:10,代码来源:encoding_test.py


示例2: decrypt

    def decrypt(self, raw, mac=16):
        """Decrypt a message sent to the holder of this key.
        """
        # get the nonce-point
        x, y = sec_to_public_pair(raw[:33])
        # validation that this point lies on the curve happens in
        #  initialization
        nonce_point = PubKey(BasePoint.curve(), x, y)

        # message gives us the ciphered message
        message = raw[33:-mac]
        # checksum makes sure everything is transmitted properly
        checksum = raw[-mac:]

        # calculate the shared secret
        tmp = nonce_point * self.exponent
        shared_secret = PubKey(tmp.curve(), tmp.x(), tmp.y())

        # derive keys
        key = nonce_point.kdf(shared_secret)
        cipher = AES.new(key[:32])

        # verify the checksum
        checksum_maker = hmac.new(key[32:], digestmod=hashlib.sha256)
        checksum_maker.update(message)
        if checksum_maker.digest()[:mac] != checksum:
            raise RuntimeError("Invalid checksum on encoded message string")

        return cipher.decrypt(message)
开发者ID:RagnarDanneskjold,项目名称:coinmessage,代码行数:29,代码来源:encrypt.py


示例3: is_pubkey_valid

def is_pubkey_valid(pubkey):
    try:
        sec=encoding.binascii.unhexlify(pubkey)
        public_pair=encoding.sec_to_public_pair(sec)
        return curves.ecdsa.point_is_valid(ecdsa.generator_secp256k1, public_pair[0], public_pair[1])
    except TypeError:
        return False
开发者ID:achamely,项目名称:recoverCompromisedFunds,代码行数:7,代码来源:createSpecial.py


示例4: pcode_to_public_node

def pcode_to_public_node(pcode):
    pcode_bytes = b58_to_pcode(pcode)
    sec = pcode_bytes[2:35]
    public_pair = encoding.sec_to_public_pair(sec)
    chain_code = pcode_bytes[36:68]
    node = BIP32Node( netcode=NETCODE, chain_code=chain_code, public_pair=public_pair )
    return node
开发者ID:metamarcdw,项目名称:pycoin_wallet,代码行数:7,代码来源:wallet.py


示例5: solve_finalize_commit

    def solve_finalize_commit(self, **kwargs):
        hash160_lookup = kwargs.get("hash160_lookup")
        sign_value = kwargs.get("sign_value")
        signature_type = kwargs.get("signature_type")
        existing_script = kwargs.get("existing_script")

        # FIXME validate on receiving the commit
        # validate payer sig
        opcode, data, pc = tools.get_opcode(existing_script, 0)  # OP_0
        opcode, payer_sig, pc = tools.get_opcode(existing_script, pc)
        sig_pair, actual_signature_type = parse_signature_blob(payer_sig)
        try:
            public_pair = encoding.sec_to_public_pair(self.payer_sec)
            sig_pair, signature_type = parse_signature_blob(payer_sig)
            valid = ecdsa.verify(ecdsa.generator_secp256k1, public_pair,
                                 sign_value, sig_pair)
            if not valid:
                raise Exception("Invalid payer public_pair!")
        except (encoding.EncodingError, UnexpectedDER):
            raise Exception("Invalid payer public_pair!")

        # sign
        private_key = hash160_lookup.get(encoding.hash160(self.payee_sec))
        secret_exponent, public_pair, compressed = private_key
        payee_sig = self._create_script_signature(
            secret_exponent, sign_value, signature_type
        )

        script_text = "OP_0 {payer_sig} {payee_sig} OP_1".format(
            payer_sig=b2h(payer_sig), payee_sig=b2h(payee_sig)
        )
        return tools.compile(script_text)
开发者ID:super3,项目名称:picopayments,代码行数:32,代码来源:scripts.py


示例6: encrypt_message

def encrypt_message(address, message):
    """Encrypts a message to an address.
    """
    hex_public_key = get_public_key_from_address(address)
    x, y = sec_to_public_pair(hex_public_key.decode('hex'))
    public_key = PubKey(BasePoint.curve(), x, y)
    encrypted = b64encode(public_key.encrypt(message))
    return encrypted
开发者ID:RagnarDanneskjold,项目名称:coinmessage,代码行数:8,代码来源:__init__.py


示例7: parse_sig

    def parse_sig(script_hex):
        """Takes a hex string of the script signature and returns the corresponding user obj
        Its in the format: [3a05e435... 027efd7...]
                    where: [Signature,  Sec_pubkey]

        """         
        
        pubkey_hex = script_hex.split(' ')[1]
        sec = sec_to_public_pair(a2b_hex(pubkey_hex))
        addr = public_pair_to_bitcoin_address(sec, address_prefix=NETWORK)
        return Username(addr)
开发者ID:NSkelsey,项目名称:jeffcoin,代码行数:11,代码来源:models.py


示例8: do_test

 def do_test(as_public_pair, as_sec, is_compressed, as_hash160_sec, as_bitcoin_address):
     self.assertEqual(encoding.sec_to_public_pair(as_sec), as_public_pair)
     self.assertEqual(encoding.public_pair_to_sec(as_public_pair, compressed=is_compressed), as_sec)
     self.assertEqual(encoding.is_sec_compressed(as_sec), is_compressed)
     self.assertEqual(encoding.public_pair_to_hash160_sec(as_public_pair, compressed=is_compressed),
                      as_hash160_sec)
     self.assertEqual(encoding.hash160_sec_to_bitcoin_address(as_hash160_sec), as_bitcoin_address)
     self.assertEqual(encoding.public_pair_to_bitcoin_address(as_public_pair, compressed=is_compressed), as_bitcoin_address)
     self.assertTrue(encoding.is_valid_bitcoin_address(as_bitcoin_address))
     bad_address = as_bitcoin_address[:17] + chr(ord(as_bitcoin_address[17]) + 1) + as_bitcoin_address[18:]
     self.assertFalse(encoding.is_valid_bitcoin_address(bad_address))
开发者ID:BitcoinSolution,项目名称:proofofexistence,代码行数:11,代码来源:encoding_test.py


示例9: do_test

        def do_test(exp_hex, wif, c_wif, public_pair_sec, c_public_pair_sec, address_b58, c_address_b58):
            secret_exponent = int(exp_hex, 16)
            sec = h2b(public_pair_sec)
            c_sec = h2b(c_public_pair_sec)

            self.assertEqual(secret_exponent_to_wif(secret_exponent, compressed=False), wif)
            self.assertEqual(secret_exponent_to_wif(secret_exponent, compressed=True), c_wif)

            exponent, compressed = wif_to_tuple_of_secret_exponent_compressed(wif)
            self.assertEqual(exponent, secret_exponent)
            self.assertFalse(compressed)

            exponent, compressed = wif_to_tuple_of_secret_exponent_compressed(c_wif)
            self.assertEqual(exponent, secret_exponent)
            self.assertTrue(compressed)

            public_pair = secret_exponent * secp256k1_generator

            pk_public_pair = sec_to_public_pair(sec)
            compressed = is_sec_compressed(sec)
            self.assertEqual(pk_public_pair, public_pair)
            self.assertFalse(is_sec_compressed(sec))
            self.assertEqual(public_pair_to_sec(pk_public_pair, compressed=False), sec)

            pk_public_pair = sec_to_public_pair(c_sec)
            compressed = is_sec_compressed(c_sec)
            self.assertEqual(pk_public_pair, public_pair)
            self.assertTrue(compressed)
            self.assertEqual(public_pair_to_sec(pk_public_pair, compressed=True), c_sec)

            bca = public_pair_to_bitcoin_address(pk_public_pair, compressed=True)
            self.assertEqual(bca, c_address_b58)

            self.assertEqual(bitcoin_address_to_hash160_sec(c_address_b58),
                             public_pair_to_hash160_sec(pk_public_pair, compressed=True))

            bca = public_pair_to_bitcoin_address(pk_public_pair, compressed=False)
            self.assertEqual(bca, address_b58)

            self.assertEqual(bitcoin_address_to_hash160_sec(address_b58),
                             public_pair_to_hash160_sec(pk_public_pair, compressed=False))
开发者ID:onestarshang,项目名称:pycoin,代码行数:41,代码来源:key_translation_test.py


示例10: address_h160_from_script

 def address_h160_from_script (script):
     s = disassemble(script).split(' ')
     if 'OP_HASH160' in s:
         p = s.index('OP_HASH160')
         if len(s) > p+1:
             return h2b(s[p+1])
     elif 'OP_CHECKSIG' in s:
         p = s.index('OP_CHECKSIG')
         if len(s[p-1]) in (66, 130):
             # public key
             sec = h2b(s[p-1])
             return public_pair_to_hash160_sec(sec_to_public_pair(sec), is_sec_compressed(sec))
     else:
         logger.warn("Can't parse address from script: %s" % (s))
         return None
开发者ID:nelisky,项目名称:pycoin,代码行数:15,代码来源:proxy.py


示例11: bitcoin_address_for_script

 def bitcoin_address_for_script(self, is_test=False):
     try:
         r = self.match_script_to_templates()
         if len(r) != 1 or len(r[0]) != 2:
             return None
         if r[0][0] == opcodes.OP_PUBKEYHASH:
             return hash160_sec_to_bitcoin_address(r[0][1], is_test=is_test)
         if r[0][0] == opcodes.OP_PUBKEY:
             sec = r[0][1]
             return public_pair_to_bitcoin_address(
                 sec_to_public_pair(sec),
                 compressed=is_sec_compressed(sec),
                 is_test=is_test)
     except SolvingError:
         pass
     return None
开发者ID:Bluejudy,项目名称:pyrpcwallet,代码行数:16,代码来源:tx_script.py


示例12: parse_as_public_pair

def parse_as_public_pair(s):
    try:
        if s[:2] in (["02", "03", "04"]):
            return encoding.sec_to_public_pair(encoding.h2b(s))
    except (encoding.EncodingError, binascii.Error):
        pass
    for c in ",/":
        if c in s:
            s0, s1 = s.split(c, 1)
            v0 = parse_as_number(s0)
            if v0:
                if s1 in ("even", "odd"):
                    return ecdsa.public_pair_for_x(ecdsa.generator_secp256k1, v0, is_even=(s1=='even'))
                v1 = parse_as_number(s1)
                if v1:
                    if not ecdsa.is_public_pair_valid(ecdsa.generator_secp256k1, (v0, v1)):
                        sys.stderr.write("invalid (x, y) pair\n")
                        sys.exit(1)
                    return (v0, v1)
开发者ID:BitcoinSolution,项目名称:proofofexistence,代码行数:19,代码来源:bitcoin_utils.py


示例13: __call__

    def __call__(self, tx_out_script, signature_hash, signature_type):
        """Figure out how to create a signature for the incoming transaction, and sign it.

        tx_out_script: the tx_out script that needs to be "solved"
        signature_hash: the bignum hash value of the new transaction reassigning the coins
        signature_type: always SIGHASH_ALL (1)
        """

        if signature_hash == 0:
            raise SolvingError("signature_hash can't be 0")

        tx_script = TxScript(tx_out_script)
        opcode_value_list = tx_script.match_script_to_templates()

        ba = bytearray()

        compressed = True
        for opcode, v in opcode_value_list:
            if opcode == opcodes.OP_PUBKEY:
                public_pair = sec_to_public_pair(v)
                bitcoin_address = public_pair_to_bitcoin_address(public_pair, compressed=compressed)
            elif opcode == opcodes.OP_PUBKEYHASH:
                bitcoin_address = hash160_sec_to_bitcoin_address(v)
            else:
                raise SolvingError("can't determine how to sign this script")

            secret_exponent = self.wallet.getsecretexponent(bitcoin_address)

            r, s = ecdsa.sign(ecdsa.generator_secp256k1, secret_exponent, signature_hash)
            sig = der.sigencode_der(r, s) + bytes_from_int(signature_type)
            ba += tools.compile(binascii.hexlify(sig).decode("utf8"))
            if opcode == opcodes.OP_PUBKEYHASH:
                public_pair = ecdsa.public_pair_for_secret_exponent(ecdsa.generator_secp256k1, secret_exponent)
                ba += tools.compile(
                    binascii.hexlify(public_pair_to_sec(public_pair, compressed=compressed)).decode("utf8")
                )

        return bytes(ba)
开发者ID:CounterpartyXCP,项目名称:pyrpcwallet,代码行数:38,代码来源:secret_exponent_solver.py


示例14: add_sec_annotations

def add_sec_annotations(a1, data, address_prefix):
    pair = sec_to_public_pair(data)
    is_compressed = is_sec_compressed(data)
    a1.append("SEC for %scompressed %s" % (
            "" if is_compressed else "un", public_pair_to_bitcoin_address(
                pair, compressed=is_compressed, address_prefix=address_prefix)))
开发者ID:Zibbo,项目名称:pycoin,代码行数:6,代码来源:disassemble.py


示例15: onJoin

    def onJoin(self, data):
        print('Welcome to GreenAddress mnemonic login example')
        print('\nThis script will login to GA in full mode')
        self.mnemonic_phrase = getpass('Please write your mnemonic phrase and press enter: ')
        self.mnemonic_phrase = "hotel helmet envelope amazing often proud scorpion myth shaft differ put expand equal scout piece million hair crater annual echo net eye middle replace"
        
        #Generate GA-side wallet path and key info
        GA_pubkey = binascii.unhexlify("036307e560072ed6ce0aa5465534fb5c258a2ccfbc257f369e8e7a181b16d897b3")
        GA_pair = sec_to_public_pair(GA_pubkey)
        GA_chaincode = binascii.unhexlify("b60befcc619bb1c212732770fe181f2f1aa824ab89f8aab49f2e13e3a56f0f04")
        gawallet = BIP32Node.BIP32Node('XTN', GA_chaincode, public_pair=GA_pair)
        if sys.version_info.major < 3:
            m = hmac.new(bytearray(self.mnemonic_phrase), bytearray('GreenAddress!!!'), hashlib.sha512)
        else:
            m = hmac.new(bytearray(self.mnemonic_phrase, 'utf-8'), bytearray('GreenAddress!!!', 'utf-8'), hashlib.sha512)
        gawalletpath = binascii.hexlify(m.digest())
        gawalletpath_bin = binascii.unhexlify(gawalletpath)
        gawalletpath_str = '/'.join(str(struct.unpack('!H', gawalletpath_bin[i*2:(i+1)*2])[0]) for i in range(32))

        # 1. Master wallet
        seed = mnemonic.Mnemonic.to_seed(self.mnemonic_phrase)
        self.wallet = BIP32Node.BIP32Node.from_master_secret(seed, 'XTN')
        # Change 'BTC' to 'XTN' for Testnet

        # 2. Login wallet
        path = '%X' % random.randint(0, 2**64-1)
        while len(path) < 16:
            path = '0' + path
        path_bin = binascii.unhexlify(path)
        path_str = '/'.join(str(struct.unpack('!H', path_bin[i*2:(i+1)*2])[0]) for i in range(4))
        wallet_login = self.wallet.subkey_for_path(path_str)

        # 3. Get challenge
        print('\nLogging in with mnemonic passphrase, requesting challenge')
        challenge = yield self.call(
            'com.greenaddress.login.get_challenge',
            self.wallet.bitcoin_address(),
            # disclose_me is required for authentication
            options=CallOptions(disclose_me=True)
        )

        # 4. Login
        signature = pycoin_ecdsa.sign(pycoin_ecdsa.generator_secp256k1, wallet_login.secret_exponent(), int(challenge))
        if signature[1]+signature[1] > pycoin_ecdsa.generator_secp256k1.order():
            signature = (signature[0], pycoin_ecdsa.generator_secp256k1.order() - signature[1])
        login_data = yield self.call(
            "com.greenaddress.login.authenticate",
            list(map(str, signature)),
            False,
            path,
            options=CallOptions(disclose_me=True)
        )

        if data and login_data:
            print(login_data)
            last_login = (login_data['last_login']['at'], login_data['last_login']['country'], login_data['last_login']['ip'])
            print('\nLogin successful! Last login on %s, from country %s, ip address: %s' % last_login)
        else: print('\nLogin failed')

        
        p2sh_addr = yield self.call(
                "com.greenaddress.vault.fund",
                return_pointer=True,
                options=CallOptions(disclose_me=True))

        print(p2sh_addr)
        validateGAAddr(p2sh_addr, self.wallet)

        syncWallet(p2sh_addr, self.wallet, gawallet, gawalletpath_str)
        '''
        balance = yield self.call(
                "com.greenaddress.txs.get_balance",
                options=CallOptions(disclose_me=True))
        print(balance)

        
        prep_tx = yield self.call(
                "com.greenaddress.vault.prepare_tx",
                rcpt_ad="2MtXwJyVCWLUmNeeNsQt958sV9658ZEpAdn",
                value="10000",
                add_fee='sender',
                priv_data={},
                options=CallOptions(disclose_me=True))
        print(prep_tx)
        '''
        

        reactor.stop()
开发者ID:instagibbs,项目名称:cosignd,代码行数:88,代码来源:cosign.py


示例16: pubkey_to_address

def pubkey_to_address(pubkey_hex):
    sec = binascii.unhexlify(pubkey_hex)
    compressed = encoding.is_sec_compressed(sec)
    public_pair = encoding.sec_to_public_pair(sec)
    return encoding.public_pair_to_bitcoin_address(public_pair, compressed=compressed)
开发者ID:LeeAbell79,项目名称:dogeblockd,代码行数:5,代码来源:util_bitcoin.py


示例17: solve

def solve(self, **kwargs):
    """
    The kwargs required depend upon the script type.
    hash160_lookup:
        dict-like structure that returns a secret exponent for a hash160
    existing_script:
        existing solution to improve upon (optional)
    sign_value:
        the integer value to sign (derived from the transaction hash)
    signature_type:
        usually SIGHASH_ALL (1)
    """
    # we need a hash160 => secret_exponent lookup
    db = kwargs.get("hash160_lookup")
    if db is None:
        raise SolvingError("missing hash160_lookup parameter")

    sign_value = kwargs.get("sign_value")
    signature_type = kwargs.get("signature_type")

    secs_solved = set()
    existing_signatures = []
    existing_script = kwargs.get("existing_script")
    if existing_script:
        pc = 0
        opcode, data, pc = tools.get_opcode(existing_script, pc)
        # ignore the first opcode
        while pc < len(existing_script):
            opcode, data, pc = tools.get_opcode(existing_script, pc)
            sig_pair, actual_signature_type = parse_signature_blob(data)
            for sec_key in self.sec_keys:
                try:
                    public_pair = encoding.sec_to_public_pair(sec_key)
                    sig_pair, signature_type = parse_signature_blob(data)
                    v = ecdsa.verify(ecdsa.generator_secp256k1, public_pair, sign_value, sig_pair)
                    if v:
                        existing_signatures.append(data)
                        secs_solved.add(sec_key)
                        break
                except encoding.EncodingError:
                    # if public_pair is invalid, we just ignore it
                    pass

    for sec_key in self.sec_keys:
        if sec_key in secs_solved:
            continue
        if len(existing_signatures) >= self.n:
            break
        hash160 = encoding.hash160(sec_key)
        result = db.get(hash160)
        if result is None:
            continue
        secret_exponent, public_pair, compressed = result
        binary_signature = self._create_script_signature(secret_exponent, sign_value, signature_type)
        existing_signatures.append(b2h(binary_signature))
    DUMMY_SIGNATURE = "OP_0"
    while len(existing_signatures) < self.n:
        existing_signatures.append(DUMMY_SIGNATURE)

    script = "OP_0 %s" % " ".join(s for s in existing_signatures)
    solution = tools.compile(script)
    return solution
开发者ID:hitfin,项目名称:pybitgo,代码行数:62,代码来源:bitgo.py


示例18: get_compressed_pubkey_format

def get_compressed_pubkey_format(pubkey):
    public_pair=encoding.sec_to_public_pair(encoding.binascii.unhexlify(pubkey))
    return encoding.binascii.hexlify(encoding.public_pair_to_sec(public_pair))
开发者ID:coinhelper,项目名称:mastercoin-tools,代码行数:3,代码来源:msc_utils_bitcoin.py


示例19: get_address_of_pubkey

def get_address_of_pubkey(pubkey):
    public_pair=encoding.sec_to_public_pair(encoding.binascii.unhexlify(pubkey))
    return encoding.public_pair_to_bitcoin_address(public_pair)
开发者ID:coinhelper,项目名称:mastercoin-tools,代码行数:3,代码来源:msc_utils_bitcoin.py


示例20: pubkey_to_address

def pubkey_to_address(pubkey_hex):
    sec = binascii.unhexlify(pubkey_hex)
    compressed = encoding.is_sec_compressed(sec)
    public_pair = encoding.sec_to_public_pair(sec)
    address_prefix = b'\x6f' if config.TESTNET else b'\x00'
    return encoding.public_pair_to_bitcoin_address(public_pair, compressed=compressed, address_prefix=address_prefix)
开发者ID:bradfrost1,项目名称:counterblock,代码行数:6,代码来源:blockchain.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python hexbytes.h2b函数代码示例发布时间:2022-05-25
下一篇:
Python encoding.public_pair_to_sec函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap