當前位置: 首頁>>代碼示例>>Python>>正文


Python coincurve.PrivateKey方法代碼示例

本文整理匯總了Python中coincurve.PrivateKey方法的典型用法代碼示例。如果您正苦於以下問題:Python coincurve.PrivateKey方法的具體用法?Python coincurve.PrivateKey怎麽用?Python coincurve.PrivateKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在coincurve的用法示例。


在下文中一共展示了coincurve.PrivateKey方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: login_required

# 需要導入模塊: import coincurve [as 別名]
# 或者: from coincurve import PrivateKey [as 別名]
def login_required(f):
    @functools.wraps(f)
    def decorated_function(*args, **kwargs):
        private_key_hex = session.get('private_key')
        error = None
        if private_key_hex is not None:
            if private_key_hex.startswith(('0x', '0X')):
                private_key_hex = private_key_hex[2:]
            try:
                private_key_bytes = bytes.fromhex(private_key_hex)
                private_key = PrivateKey(private_key_bytes)
            except (ValueError, TypeError):
                error = 'invalid-private-key'
            else:
                g.user = User(private_key)
                return f(*args, **kwargs)
        return redirect(url_for('.get_login', next=request.url, error=error))
    return decorated_function 
開發者ID:nekoyume,項目名稱:nekoyume,代碼行數:20,代碼來源:game.py

示例2: mine

# 需要導入模塊: import coincurve [as 別名]
# 或者: from coincurve import PrivateKey [as 別名]
def mine(private_key: PrivateKey, sleep: float):
    app.app_context().push()

    while True:
        Block.sync()
        block = Block.create(
            User(private_key),
            [m
             for m in Move.query.filter_by(block=None).limit(20).all()
             if m.valid],
            echo=echo,
            sleep=sleep,
        )
        if block:
            serialized = block.serialize(
                use_bencode=False,
                include_suffix=True,
                include_moves=True,
                include_hash=True
            )
            multicast(serialized=serialized, broadcast=broadcast_block)
            echo(block) 
開發者ID:nekoyume,項目名稱:nekoyume,代碼行數:24,代碼來源:cli.py

示例3: test_prevent_hack_and_slash_when_dead

# 需要導入模塊: import coincurve [as 別名]
# 或者: from coincurve import PrivateKey [as 別名]
def test_prevent_hack_and_slash_when_dead(
        fx_test_client: FlaskClient, fx_session: Session, fx_user: User,
        fx_private_key: PrivateKey, fx_novice_status: typing.Dict[str, str],
):
    move = fx_user.create_novice(fx_novice_status)
    Block.create(fx_user, [move])

    assert fx_user.avatar().dead is False
    while fx_user.avatar().hp > 0:
        move = fx_user.hack_and_slash()
        Block.create(fx_user, [move])
    assert fx_user.avatar().dead is True

    response = fx_test_client.post('/session_moves', data={
        'name': 'hack_and_slash'
    })
    assert response.status_code == 302 
開發者ID:nekoyume,項目名稱:nekoyume,代碼行數:19,代碼來源:game_test.py

示例4: sign

# 需要導入模塊: import coincurve [as 別名]
# 或者: from coincurve import PrivateKey [as 別名]
def sign(privkey: PrivateKey, msg_hash: bytes, v: int = 0) -> bytes:
    if not isinstance(msg_hash, bytes):
        raise TypeError("sign(): msg_hash is not an instance of bytes")
    if len(msg_hash) != 32:
        raise ValueError("sign(): msg_hash has to be exactly 32 bytes")
    if not isinstance(privkey, bytes):
        raise TypeError("sign(): privkey is not an instance of bytes")
    if v not in {0, 27}:
        raise ValueError(f"sign(): got v = {v} expected 0 or 27.")

    pk = PrivateKey(privkey)
    sig: bytes = pk.sign_recoverable(msg_hash, hasher=None)
    assert len(sig) == 65

    pub = pk.public_key
    recovered = PublicKey.from_signature_and_message(sig, msg_hash, hasher=None)
    assert pub == recovered

    sig = sig[:-1] + bytes([sig[-1] + v])

    return sig 
開發者ID:raiden-network,項目名稱:raiden-contracts,代碼行數:23,代碼來源:signature.py

示例5: get_web3

# 需要導入模塊: import coincurve [as 別名]
# 或者: from coincurve import PrivateKey [as 別名]
def get_web3(eth_tester: EthereumTester, deployer_key: PrivateKey) -> Web3:
    """Returns an initialized Web3 instance"""
    provider = EthereumTesterProvider(eth_tester)
    web3 = Web3(provider)

    # add faucet account to tester
    eth_tester.add_account(deployer_key.to_hex())

    # make faucet rich
    eth_tester.send_transaction(
        {
            "from": eth_tester.get_accounts()[0],
            "to": private_key_to_address(deployer_key.to_hex()),
            "gas": 21000,
            "value": FAUCET_ALLOWANCE,
        }
    )

    return web3 
開發者ID:raiden-network,項目名稱:raiden-contracts,代碼行數:21,代碼來源:contracts.py

示例6: add_privkeys

# 需要導入模塊: import coincurve [as 別名]
# 或者: from coincurve import PrivateKey [as 別名]
def add_privkeys(priv1, priv2, usehex):
    '''Add privkey 1 to privkey 2.
    Input keys must be in binary either compressed or not.
    Returned key will have the same compression state.
    Error if compression state of both input keys is not the same.'''
    y, z = [read_privkey(x) for x in [priv1, priv2]]
    if y[0] != z[0]:
        raise Exception("cannot add privkeys, mixed compression formats")
    else:
        compressed = y[0]
    newpriv1, newpriv2 = (y[1], z[1])
    p1 = secp256k1.PrivateKey(newpriv1)
    res = p1.add(newpriv2).secret
    if compressed:
        res += b'\x01'
    return res 
開發者ID:JoinMarket-Org,項目名稱:joinmarket-clientserver,代碼行數:18,代碼來源:secp256k1_main.py

示例7: hex2prv

# 需要導入模塊: import coincurve [as 別名]
# 或者: from coincurve import PrivateKey [as 別名]
def hex2prv(prv_hex: str) -> PrivateKey:
    """
    Convert ethereum hex to EllipticCurvePrivateKey

    Parameters
    ----------
    prv_hex: str
        Private key hex string

    Returns
    -------
    coincurve.PrivateKey
        A secp256k1 private key

    >>> k = generate_eth_key()
    >>> sk_hex = k.to_hex()
    >>> pk_hex = k.public_key.to_hex()
    >>> computed_prv = hex2prv(sk_hex)
    >>> computed_prv.to_int() == int(k.to_hex(), 16)
    True
    """
    return PrivateKey(decode_hex(prv_hex)) 
開發者ID:ecies,項目名稱:py,代碼行數:24,代碼來源:utils.py

示例8: test_hdkf

# 需要導入模塊: import coincurve [as 別名]
# 或者: from coincurve import PrivateKey [as 別名]
def test_hdkf(self):
        derived = HKDF(b"secret", 32, b"", SHA256).hex()
        self.assertEqual(
            derived, "2f34e5ff91ec85d53ca9b543683174d0cf550b60d5f52b24c97b386cfcf6cbbf"
        )

        k1 = PrivateKey(secret=bytes([2]))
        self.assertEqual(k1.to_int(), 2)

        k2 = PrivateKey(secret=bytes([3]))
        self.assertEqual(k2.to_int(), 3)

        self.assertEqual(encapsulate(k1, k2.public_key), decapsulate(k1.public_key, k2))
        self.assertEqual(
            encapsulate(k1, k2.public_key).hex(),
            "6f982d63e8590c9d9b5b4c1959ff80315d772edd8f60287c9361d548d5200f82",
        ) 
開發者ID:ecies,項目名稱:py,代碼行數:19,代碼來源:test_crypt.py

示例9: ecsign

# 需要導入模塊: import coincurve [as 別名]
# 或者: from coincurve import PrivateKey [as 別名]
def ecsign(rawhash, key):
    if coincurve and hasattr(coincurve, "PrivateKey"):
        pk = coincurve.PrivateKey(key)
        signature = pk.sign_recoverable(rawhash, hasher=None)
        v = safe_ord(signature[64]) + 27
        r = big_endian_to_int(signature[0:32])
        s = big_endian_to_int(signature[32:64])
    else:
        v, r, s = ecdsa_raw_sign(rawhash, key)
    return v, r, s 
開發者ID:QuarkChain,項目名稱:pyquarkchain,代碼行數:12,代碼來源:utils.py

示例10: ecsign

# 需要導入模塊: import coincurve [as 別名]
# 或者: from coincurve import PrivateKey [as 別名]
def ecsign(rawhash, key):
    if coincurve and hasattr(coincurve, 'PrivateKey'):
        pk = coincurve.PrivateKey(key)
        signature = pk.sign_recoverable(rawhash, hasher=None)
        v = safe_ord(signature[64]) + 27
        r = big_endian_to_int(signature[0:32])
        s = big_endian_to_int(signature[32:64])
    else:
        v, r, s = ecdsa_raw_sign(rawhash, key)
    return v, r, s


# Functions - sha3 
開發者ID:sammchardy,項目名稱:python-idex,代碼行數:15,代碼來源:utils.py

示例11: convert

# 需要導入模塊: import coincurve [as 別名]
# 或者: from coincurve import PrivateKey [as 別名]
def convert(self, value, param, ctx) -> PrivateKey:
        val = value[2:] if value.startswith(('0x', '0X')) else value
        try:
            num = bytes.fromhex(val)
            return PrivateKey(num)
        except (ValueError, TypeError):
            self.fail('%s is not a valid private key of 64 hexadecimal digits') 
開發者ID:nekoyume,項目名稱:nekoyume,代碼行數:9,代碼來源:cli.py

示例12: fx_user2

# 需要導入模塊: import coincurve [as 別名]
# 或者: from coincurve import PrivateKey [as 別名]
def fx_user2(fx_session):
    user = User(PrivateKey())
    user.session = fx_session
    return user 
開發者ID:nekoyume,項目名稱:nekoyume,代碼行數:6,代碼來源:move_test.py

示例13: fx_private_key

# 需要導入模塊: import coincurve [as 別名]
# 或者: from coincurve import PrivateKey [as 別名]
def fx_private_key() -> PrivateKey:
    return PrivateKey() 
開發者ID:nekoyume,項目名稱:nekoyume,代碼行數:4,代碼來源:conftest.py

示例14: fx_other_user

# 需要導入模塊: import coincurve [as 別名]
# 或者: from coincurve import PrivateKey [as 別名]
def fx_other_user(fx_other_session):
    user = User(PrivateKey())
    user.session = fx_other_session
    return user 
開發者ID:nekoyume,項目名稱:nekoyume,代碼行數:6,代碼來源:conftest.py

示例15: test_new_character_creation

# 需要導入模塊: import coincurve [as 別名]
# 或者: from coincurve import PrivateKey [as 別名]
def test_new_character_creation(fx_test_client, fx_session):
    privkey = PrivateKey()
    fx_test_client.post('/login', data={
        'private_key': privkey.to_hex(),
        'name': 'test_user',
    }, follow_redirects=True)

    assert fx_session.query(Move).filter_by(
        user_address=get_address(privkey.public_key),
        user_public_key=privkey.public_key.format(compressed=True),
        name='create_novice'
    ).first() 
開發者ID:nekoyume,項目名稱:nekoyume,代碼行數:14,代碼來源:game_test.py


注:本文中的coincurve.PrivateKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。