当前位置: 首页>>代码示例>>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;未经允许,请勿转载。