mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
run lint and fix errors, except mypy
This commit is contained in:
@ -1,8 +1,14 @@
|
||||
from dataclasses import dataclass
|
||||
from dataclasses import (
|
||||
dataclass,
|
||||
)
|
||||
import hmac
|
||||
from typing import Tuple
|
||||
from typing import (
|
||||
Tuple,
|
||||
)
|
||||
|
||||
from Crypto.Cipher import AES
|
||||
from Crypto.Cipher import (
|
||||
AES,
|
||||
)
|
||||
import Crypto.Util.Counter as Counter
|
||||
|
||||
|
||||
@ -61,9 +67,11 @@ class MacAndCipher:
|
||||
def initialize_pair(
|
||||
cipher_type: str, hash_type: str, secret: bytes
|
||||
) -> Tuple[EncryptionParameters, EncryptionParameters]:
|
||||
"""Return a pair of ``Keys`` for use in securing a communications channel
|
||||
"""
|
||||
Return a pair of ``Keys`` for use in securing a communications channel
|
||||
with authenticated encryption derived from the ``secret`` and using the
|
||||
requested ``cipher_type`` and ``hash_type``."""
|
||||
requested ``cipher_type`` and ``hash_type``.
|
||||
"""
|
||||
if cipher_type != "AES-128":
|
||||
raise NotImplementedError()
|
||||
if hash_type != "SHA256":
|
||||
@ -72,7 +80,7 @@ def initialize_pair(
|
||||
iv_size = 16
|
||||
cipher_key_size = 16
|
||||
hmac_key_size = 20
|
||||
seed = "key expansion".encode()
|
||||
seed = b"key expansion"
|
||||
|
||||
params_size = iv_size + cipher_key_size + hmac_key_size
|
||||
result = bytearray(2 * params_size)
|
||||
|
||||
@ -1,13 +1,25 @@
|
||||
from fastecdsa import (
|
||||
keys,
|
||||
point,
|
||||
)
|
||||
from fastecdsa import curve as curve_types
|
||||
from fastecdsa import keys, point
|
||||
from fastecdsa.encoding.sec1 import SEC1Encoder
|
||||
from fastecdsa.encoding.sec1 import (
|
||||
SEC1Encoder,
|
||||
)
|
||||
|
||||
from libp2p.crypto.keys import KeyPair, KeyType, PrivateKey, PublicKey
|
||||
from libp2p.crypto.keys import (
|
||||
KeyPair,
|
||||
KeyType,
|
||||
PrivateKey,
|
||||
PublicKey,
|
||||
)
|
||||
|
||||
|
||||
def infer_local_type(curve: str) -> curve_types.Curve:
|
||||
"""converts a ``str`` representation of some elliptic curve to a
|
||||
representation understood by the backend of this module."""
|
||||
"""
|
||||
Convert a ``str`` representation of some elliptic curve to a
|
||||
representation understood by the backend of this module.
|
||||
"""
|
||||
if curve == "P-256":
|
||||
return curve_types.P256
|
||||
else:
|
||||
@ -61,8 +73,10 @@ class ECCPrivateKey(PrivateKey):
|
||||
|
||||
|
||||
def create_new_key_pair(curve: str) -> KeyPair:
|
||||
"""Return a new ECC keypair with the requested ``curve`` type, e.g.
|
||||
"P-256"."""
|
||||
"""
|
||||
Return a new ECC keypair with the requested ``curve`` type, e.g.
|
||||
"P-256".
|
||||
"""
|
||||
private_key = ECCPrivateKey.new(curve)
|
||||
public_key = private_key.get_public_key()
|
||||
return KeyPair(private_key, public_key)
|
||||
|
||||
@ -1,11 +1,23 @@
|
||||
from Crypto.Hash import SHA256
|
||||
from nacl.exceptions import BadSignatureError
|
||||
from Crypto.Hash import (
|
||||
SHA256,
|
||||
)
|
||||
from nacl.exceptions import (
|
||||
BadSignatureError,
|
||||
)
|
||||
from nacl.public import PrivateKey as PrivateKeyImpl
|
||||
from nacl.public import PublicKey as PublicKeyImpl
|
||||
from nacl.signing import SigningKey, VerifyKey
|
||||
from nacl.signing import (
|
||||
SigningKey,
|
||||
VerifyKey,
|
||||
)
|
||||
import nacl.utils as utils
|
||||
|
||||
from libp2p.crypto.keys import KeyPair, KeyType, PrivateKey, PublicKey
|
||||
from libp2p.crypto.keys import (
|
||||
KeyPair,
|
||||
KeyType,
|
||||
PrivateKey,
|
||||
PublicKey,
|
||||
)
|
||||
|
||||
|
||||
class Ed25519PublicKey(PublicKey):
|
||||
|
||||
@ -1,4 +1,6 @@
|
||||
from libp2p.exceptions import BaseLibp2pError
|
||||
from libp2p.exceptions import (
|
||||
BaseLibp2pError,
|
||||
)
|
||||
|
||||
|
||||
class CryptographyError(BaseLibp2pError):
|
||||
@ -6,7 +8,7 @@ class CryptographyError(BaseLibp2pError):
|
||||
|
||||
|
||||
class MissingDeserializerError(CryptographyError):
|
||||
"""Raise if the requested deserialization routine is missing for some type
|
||||
of cryptographic key."""
|
||||
|
||||
pass
|
||||
"""
|
||||
Raise if the requested deserialization routine is missing for some type
|
||||
of cryptographic key.
|
||||
"""
|
||||
|
||||
@ -1,9 +1,21 @@
|
||||
from typing import Callable, Tuple, cast
|
||||
from typing import (
|
||||
Callable,
|
||||
Tuple,
|
||||
cast,
|
||||
)
|
||||
|
||||
from fastecdsa.encoding import util
|
||||
from fastecdsa.encoding import (
|
||||
util,
|
||||
)
|
||||
|
||||
from libp2p.crypto.ecc import ECCPrivateKey, ECCPublicKey, create_new_key_pair
|
||||
from libp2p.crypto.keys import PublicKey
|
||||
from libp2p.crypto.ecc import (
|
||||
ECCPrivateKey,
|
||||
ECCPublicKey,
|
||||
create_new_key_pair,
|
||||
)
|
||||
from libp2p.crypto.keys import (
|
||||
PublicKey,
|
||||
)
|
||||
|
||||
SharedKeyGenerator = Callable[[bytes], bytes]
|
||||
|
||||
|
||||
@ -1,6 +1,14 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from dataclasses import dataclass
|
||||
from enum import Enum, unique
|
||||
from abc import (
|
||||
ABC,
|
||||
abstractmethod,
|
||||
)
|
||||
from dataclasses import (
|
||||
dataclass,
|
||||
)
|
||||
from enum import (
|
||||
Enum,
|
||||
unique,
|
||||
)
|
||||
|
||||
from .pb import crypto_pb2 as protobuf
|
||||
|
||||
@ -38,8 +46,10 @@ class PublicKey(Key):
|
||||
|
||||
@abstractmethod
|
||||
def verify(self, data: bytes, signature: bytes) -> bool:
|
||||
"""Verify that ``signature`` is the cryptographic signature of the hash
|
||||
of ``data``."""
|
||||
"""
|
||||
Verify that ``signature`` is the cryptographic signature of the hash
|
||||
of ``data``.
|
||||
"""
|
||||
...
|
||||
|
||||
def _serialize_to_protobuf(self) -> protobuf.PublicKey:
|
||||
|
||||
@ -17,4 +17,4 @@ message PublicKey {
|
||||
message PrivateKey {
|
||||
required KeyType key_type = 1;
|
||||
required bytes data = 2;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,56 +1,53 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
# source: libp2p/crypto/pb/crypto.proto
|
||||
|
||||
import sys
|
||||
_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1'))
|
||||
|
||||
_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode("latin1"))
|
||||
from google.protobuf.internal import enum_type_wrapper
|
||||
from google.protobuf import descriptor as _descriptor
|
||||
from google.protobuf import message as _message
|
||||
from google.protobuf import reflection as _reflection
|
||||
from google.protobuf import symbol_database as _symbol_database
|
||||
|
||||
# @@protoc_insertion_point(imports)
|
||||
|
||||
_sym_db = _symbol_database.Default()
|
||||
|
||||
|
||||
|
||||
|
||||
DESCRIPTOR = _descriptor.FileDescriptor(
|
||||
name='libp2p/crypto/pb/crypto.proto',
|
||||
package='crypto.pb',
|
||||
syntax='proto2',
|
||||
serialized_options=None,
|
||||
serialized_pb=_b('\n\x1dlibp2p/crypto/pb/crypto.proto\x12\tcrypto.pb\"?\n\tPublicKey\x12$\n\x08key_type\x18\x01 \x02(\x0e\x32\x12.crypto.pb.KeyType\x12\x0c\n\x04\x64\x61ta\x18\x02 \x02(\x0c\"@\n\nPrivateKey\x12$\n\x08key_type\x18\x01 \x02(\x0e\x32\x12.crypto.pb.KeyType\x12\x0c\n\x04\x64\x61ta\x18\x02 \x02(\x0c*9\n\x07KeyType\x12\x07\n\x03RSA\x10\x00\x12\x0b\n\x07\x45\x64\x32\x35\x35\x31\x39\x10\x01\x12\r\n\tSecp256k1\x10\x02\x12\t\n\x05\x45\x43\x44SA\x10\x03')
|
||||
name="libp2p/crypto/pb/crypto.proto",
|
||||
package="crypto.pb",
|
||||
syntax="proto2",
|
||||
serialized_options=None,
|
||||
serialized_pb=_b(
|
||||
'\n\x1dlibp2p/crypto/pb/crypto.proto\x12\tcrypto.pb"?\n\tPublicKey\x12$\n\x08key_type\x18\x01 \x02(\x0e\x32\x12.crypto.pb.KeyType\x12\x0c\n\x04\x64\x61ta\x18\x02 \x02(\x0c"@\n\nPrivateKey\x12$\n\x08key_type\x18\x01 \x02(\x0e\x32\x12.crypto.pb.KeyType\x12\x0c\n\x04\x64\x61ta\x18\x02 \x02(\x0c*9\n\x07KeyType\x12\x07\n\x03RSA\x10\x00\x12\x0b\n\x07\x45\x64\x32\x35\x35\x31\x39\x10\x01\x12\r\n\tSecp256k1\x10\x02\x12\t\n\x05\x45\x43\x44SA\x10\x03'
|
||||
),
|
||||
)
|
||||
|
||||
_KEYTYPE = _descriptor.EnumDescriptor(
|
||||
name='KeyType',
|
||||
full_name='crypto.pb.KeyType',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
values=[
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name='RSA', index=0, number=0,
|
||||
serialized_options=None,
|
||||
type=None),
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name='Ed25519', index=1, number=1,
|
||||
serialized_options=None,
|
||||
type=None),
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name='Secp256k1', index=2, number=2,
|
||||
serialized_options=None,
|
||||
type=None),
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name='ECDSA', index=3, number=3,
|
||||
serialized_options=None,
|
||||
type=None),
|
||||
],
|
||||
containing_type=None,
|
||||
serialized_options=None,
|
||||
serialized_start=175,
|
||||
serialized_end=232,
|
||||
name="KeyType",
|
||||
full_name="crypto.pb.KeyType",
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
values=[
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name="RSA", index=0, number=0, serialized_options=None, type=None
|
||||
),
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name="Ed25519", index=1, number=1, serialized_options=None, type=None
|
||||
),
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name="Secp256k1", index=2, number=2, serialized_options=None, type=None
|
||||
),
|
||||
_descriptor.EnumValueDescriptor(
|
||||
name="ECDSA", index=3, number=3, serialized_options=None, type=None
|
||||
),
|
||||
],
|
||||
containing_type=None,
|
||||
serialized_options=None,
|
||||
serialized_start=175,
|
||||
serialized_end=232,
|
||||
)
|
||||
_sym_db.RegisterEnumDescriptor(_KEYTYPE)
|
||||
|
||||
@ -61,101 +58,146 @@ Secp256k1 = 2
|
||||
ECDSA = 3
|
||||
|
||||
|
||||
|
||||
_PUBLICKEY = _descriptor.Descriptor(
|
||||
name='PublicKey',
|
||||
full_name='crypto.pb.PublicKey',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name='key_type', full_name='crypto.pb.PublicKey.key_type', index=0,
|
||||
number=1, type=14, cpp_type=8, label=2,
|
||||
has_default_value=False, default_value=0,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='data', full_name='crypto.pb.PublicKey.data', index=1,
|
||||
number=2, type=12, cpp_type=9, label=2,
|
||||
has_default_value=False, default_value=_b(""),
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
serialized_options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto2',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=44,
|
||||
serialized_end=107,
|
||||
name="PublicKey",
|
||||
full_name="crypto.pb.PublicKey",
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name="key_type",
|
||||
full_name="crypto.pb.PublicKey.key_type",
|
||||
index=0,
|
||||
number=1,
|
||||
type=14,
|
||||
cpp_type=8,
|
||||
label=2,
|
||||
has_default_value=False,
|
||||
default_value=0,
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
serialized_options=None,
|
||||
file=DESCRIPTOR,
|
||||
),
|
||||
_descriptor.FieldDescriptor(
|
||||
name="data",
|
||||
full_name="crypto.pb.PublicKey.data",
|
||||
index=1,
|
||||
number=2,
|
||||
type=12,
|
||||
cpp_type=9,
|
||||
label=2,
|
||||
has_default_value=False,
|
||||
default_value=_b(""),
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
serialized_options=None,
|
||||
file=DESCRIPTOR,
|
||||
),
|
||||
],
|
||||
extensions=[],
|
||||
nested_types=[],
|
||||
enum_types=[],
|
||||
serialized_options=None,
|
||||
is_extendable=False,
|
||||
syntax="proto2",
|
||||
extension_ranges=[],
|
||||
oneofs=[],
|
||||
serialized_start=44,
|
||||
serialized_end=107,
|
||||
)
|
||||
|
||||
|
||||
_PRIVATEKEY = _descriptor.Descriptor(
|
||||
name='PrivateKey',
|
||||
full_name='crypto.pb.PrivateKey',
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name='key_type', full_name='crypto.pb.PrivateKey.key_type', index=0,
|
||||
number=1, type=14, cpp_type=8, label=2,
|
||||
has_default_value=False, default_value=0,
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
_descriptor.FieldDescriptor(
|
||||
name='data', full_name='crypto.pb.PrivateKey.data', index=1,
|
||||
number=2, type=12, cpp_type=9, label=2,
|
||||
has_default_value=False, default_value=_b(""),
|
||||
message_type=None, enum_type=None, containing_type=None,
|
||||
is_extension=False, extension_scope=None,
|
||||
serialized_options=None, file=DESCRIPTOR),
|
||||
],
|
||||
extensions=[
|
||||
],
|
||||
nested_types=[],
|
||||
enum_types=[
|
||||
],
|
||||
serialized_options=None,
|
||||
is_extendable=False,
|
||||
syntax='proto2',
|
||||
extension_ranges=[],
|
||||
oneofs=[
|
||||
],
|
||||
serialized_start=109,
|
||||
serialized_end=173,
|
||||
name="PrivateKey",
|
||||
full_name="crypto.pb.PrivateKey",
|
||||
filename=None,
|
||||
file=DESCRIPTOR,
|
||||
containing_type=None,
|
||||
fields=[
|
||||
_descriptor.FieldDescriptor(
|
||||
name="key_type",
|
||||
full_name="crypto.pb.PrivateKey.key_type",
|
||||
index=0,
|
||||
number=1,
|
||||
type=14,
|
||||
cpp_type=8,
|
||||
label=2,
|
||||
has_default_value=False,
|
||||
default_value=0,
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
serialized_options=None,
|
||||
file=DESCRIPTOR,
|
||||
),
|
||||
_descriptor.FieldDescriptor(
|
||||
name="data",
|
||||
full_name="crypto.pb.PrivateKey.data",
|
||||
index=1,
|
||||
number=2,
|
||||
type=12,
|
||||
cpp_type=9,
|
||||
label=2,
|
||||
has_default_value=False,
|
||||
default_value=_b(""),
|
||||
message_type=None,
|
||||
enum_type=None,
|
||||
containing_type=None,
|
||||
is_extension=False,
|
||||
extension_scope=None,
|
||||
serialized_options=None,
|
||||
file=DESCRIPTOR,
|
||||
),
|
||||
],
|
||||
extensions=[],
|
||||
nested_types=[],
|
||||
enum_types=[],
|
||||
serialized_options=None,
|
||||
is_extendable=False,
|
||||
syntax="proto2",
|
||||
extension_ranges=[],
|
||||
oneofs=[],
|
||||
serialized_start=109,
|
||||
serialized_end=173,
|
||||
)
|
||||
|
||||
_PUBLICKEY.fields_by_name['key_type'].enum_type = _KEYTYPE
|
||||
_PRIVATEKEY.fields_by_name['key_type'].enum_type = _KEYTYPE
|
||||
DESCRIPTOR.message_types_by_name['PublicKey'] = _PUBLICKEY
|
||||
DESCRIPTOR.message_types_by_name['PrivateKey'] = _PRIVATEKEY
|
||||
DESCRIPTOR.enum_types_by_name['KeyType'] = _KEYTYPE
|
||||
_PUBLICKEY.fields_by_name["key_type"].enum_type = _KEYTYPE
|
||||
_PRIVATEKEY.fields_by_name["key_type"].enum_type = _KEYTYPE
|
||||
DESCRIPTOR.message_types_by_name["PublicKey"] = _PUBLICKEY
|
||||
DESCRIPTOR.message_types_by_name["PrivateKey"] = _PRIVATEKEY
|
||||
DESCRIPTOR.enum_types_by_name["KeyType"] = _KEYTYPE
|
||||
_sym_db.RegisterFileDescriptor(DESCRIPTOR)
|
||||
|
||||
PublicKey = _reflection.GeneratedProtocolMessageType('PublicKey', (_message.Message,), {
|
||||
'DESCRIPTOR' : _PUBLICKEY,
|
||||
'__module__' : 'libp2p.crypto.pb.crypto_pb2'
|
||||
# @@protoc_insertion_point(class_scope:crypto.pb.PublicKey)
|
||||
})
|
||||
PublicKey = _reflection.GeneratedProtocolMessageType(
|
||||
"PublicKey",
|
||||
(_message.Message,),
|
||||
{
|
||||
"DESCRIPTOR": _PUBLICKEY,
|
||||
"__module__": "libp2p.crypto.pb.crypto_pb2"
|
||||
# @@protoc_insertion_point(class_scope:crypto.pb.PublicKey)
|
||||
},
|
||||
)
|
||||
_sym_db.RegisterMessage(PublicKey)
|
||||
|
||||
PrivateKey = _reflection.GeneratedProtocolMessageType('PrivateKey', (_message.Message,), {
|
||||
'DESCRIPTOR' : _PRIVATEKEY,
|
||||
'__module__' : 'libp2p.crypto.pb.crypto_pb2'
|
||||
# @@protoc_insertion_point(class_scope:crypto.pb.PrivateKey)
|
||||
})
|
||||
PrivateKey = _reflection.GeneratedProtocolMessageType(
|
||||
"PrivateKey",
|
||||
(_message.Message,),
|
||||
{
|
||||
"DESCRIPTOR": _PRIVATEKEY,
|
||||
"__module__": "libp2p.crypto.pb.crypto_pb2"
|
||||
# @@protoc_insertion_point(class_scope:crypto.pb.PrivateKey)
|
||||
},
|
||||
)
|
||||
_sym_db.RegisterMessage(PrivateKey)
|
||||
|
||||
|
||||
|
||||
@ -19,7 +19,6 @@ from typing_extensions import (
|
||||
Literal as typing_extensions___Literal,
|
||||
)
|
||||
|
||||
|
||||
class KeyType(int):
|
||||
DESCRIPTOR: google___protobuf___descriptor___EnumDescriptor = ...
|
||||
@classmethod
|
||||
@ -36,6 +35,7 @@ class KeyType(int):
|
||||
Ed25519 = typing___cast(KeyType, 1)
|
||||
Secp256k1 = typing___cast(KeyType, 2)
|
||||
ECDSA = typing___cast(KeyType, 3)
|
||||
|
||||
RSA = typing___cast(KeyType, 0)
|
||||
Ed25519 = typing___cast(KeyType, 1)
|
||||
Secp256k1 = typing___cast(KeyType, 2)
|
||||
@ -43,42 +43,72 @@ ECDSA = typing___cast(KeyType, 3)
|
||||
|
||||
class PublicKey(google___protobuf___message___Message):
|
||||
DESCRIPTOR: google___protobuf___descriptor___Descriptor = ...
|
||||
key_type = ... # type: KeyType
|
||||
data = ... # type: bytes
|
||||
key_type = ... # type: KeyType
|
||||
data = ... # type: bytes
|
||||
|
||||
def __init__(self,
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
key_type : KeyType,
|
||||
data : bytes,
|
||||
) -> None: ...
|
||||
key_type: KeyType,
|
||||
data: bytes,
|
||||
) -> None: ...
|
||||
@classmethod
|
||||
def FromString(cls, s: bytes) -> PublicKey: ...
|
||||
def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ...
|
||||
def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ...
|
||||
if sys.version_info >= (3,):
|
||||
def HasField(self, field_name: typing_extensions___Literal[u"data",u"key_type"]) -> bool: ...
|
||||
def ClearField(self, field_name: typing_extensions___Literal[u"data",u"key_type"]) -> None: ...
|
||||
def HasField(
|
||||
self, field_name: typing_extensions___Literal["data", "key_type"]
|
||||
) -> bool: ...
|
||||
def ClearField(
|
||||
self, field_name: typing_extensions___Literal["data", "key_type"]
|
||||
) -> None: ...
|
||||
else:
|
||||
def HasField(self, field_name: typing_extensions___Literal[u"data",b"data",u"key_type",b"key_type"]) -> bool: ...
|
||||
def ClearField(self, field_name: typing_extensions___Literal[u"data",b"data",u"key_type",b"key_type"]) -> None: ...
|
||||
def HasField(
|
||||
self,
|
||||
field_name: typing_extensions___Literal[
|
||||
"data", b"data", "key_type", b"key_type"
|
||||
],
|
||||
) -> bool: ...
|
||||
def ClearField(
|
||||
self,
|
||||
field_name: typing_extensions___Literal[
|
||||
"data", b"data", "key_type", b"key_type"
|
||||
],
|
||||
) -> None: ...
|
||||
|
||||
class PrivateKey(google___protobuf___message___Message):
|
||||
DESCRIPTOR: google___protobuf___descriptor___Descriptor = ...
|
||||
key_type = ... # type: KeyType
|
||||
data = ... # type: bytes
|
||||
key_type = ... # type: KeyType
|
||||
data = ... # type: bytes
|
||||
|
||||
def __init__(self,
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
key_type : KeyType,
|
||||
data : bytes,
|
||||
) -> None: ...
|
||||
key_type: KeyType,
|
||||
data: bytes,
|
||||
) -> None: ...
|
||||
@classmethod
|
||||
def FromString(cls, s: bytes) -> PrivateKey: ...
|
||||
def MergeFrom(self, other_msg: google___protobuf___message___Message) -> None: ...
|
||||
def CopyFrom(self, other_msg: google___protobuf___message___Message) -> None: ...
|
||||
if sys.version_info >= (3,):
|
||||
def HasField(self, field_name: typing_extensions___Literal[u"data",u"key_type"]) -> bool: ...
|
||||
def ClearField(self, field_name: typing_extensions___Literal[u"data",u"key_type"]) -> None: ...
|
||||
def HasField(
|
||||
self, field_name: typing_extensions___Literal["data", "key_type"]
|
||||
) -> bool: ...
|
||||
def ClearField(
|
||||
self, field_name: typing_extensions___Literal["data", "key_type"]
|
||||
) -> None: ...
|
||||
else:
|
||||
def HasField(self, field_name: typing_extensions___Literal[u"data",b"data",u"key_type",b"key_type"]) -> bool: ...
|
||||
def ClearField(self, field_name: typing_extensions___Literal[u"data",b"data",u"key_type",b"key_type"]) -> None: ...
|
||||
def HasField(
|
||||
self,
|
||||
field_name: typing_extensions___Literal[
|
||||
"data", b"data", "key_type", b"key_type"
|
||||
],
|
||||
) -> bool: ...
|
||||
def ClearField(
|
||||
self,
|
||||
field_name: typing_extensions___Literal[
|
||||
"data", b"data", "key_type", b"key_type"
|
||||
],
|
||||
) -> None: ...
|
||||
|
||||
@ -1,9 +1,20 @@
|
||||
from Crypto.Hash import SHA256
|
||||
from Crypto.Hash import (
|
||||
SHA256,
|
||||
)
|
||||
import Crypto.PublicKey.RSA as RSA
|
||||
from Crypto.PublicKey.RSA import RsaKey
|
||||
from Crypto.Signature import pkcs1_15
|
||||
from Crypto.PublicKey.RSA import (
|
||||
RsaKey,
|
||||
)
|
||||
from Crypto.Signature import (
|
||||
pkcs1_15,
|
||||
)
|
||||
|
||||
from libp2p.crypto.keys import KeyPair, KeyType, PrivateKey, PublicKey
|
||||
from libp2p.crypto.keys import (
|
||||
KeyPair,
|
||||
KeyType,
|
||||
PrivateKey,
|
||||
PublicKey,
|
||||
)
|
||||
|
||||
|
||||
class RSAPublicKey(PublicKey):
|
||||
|
||||
@ -1,6 +1,11 @@
|
||||
import coincurve
|
||||
|
||||
from libp2p.crypto.keys import KeyPair, KeyType, PrivateKey, PublicKey
|
||||
from libp2p.crypto.keys import (
|
||||
KeyPair,
|
||||
KeyType,
|
||||
PrivateKey,
|
||||
PublicKey,
|
||||
)
|
||||
|
||||
|
||||
class Secp256k1PublicKey(PublicKey):
|
||||
|
||||
@ -1,8 +1,22 @@
|
||||
from libp2p.crypto.ed25519 import Ed25519PrivateKey, Ed25519PublicKey
|
||||
from libp2p.crypto.exceptions import MissingDeserializerError
|
||||
from libp2p.crypto.keys import KeyType, PrivateKey, PublicKey
|
||||
from libp2p.crypto.rsa import RSAPublicKey
|
||||
from libp2p.crypto.secp256k1 import Secp256k1PrivateKey, Secp256k1PublicKey
|
||||
from libp2p.crypto.ed25519 import (
|
||||
Ed25519PrivateKey,
|
||||
Ed25519PublicKey,
|
||||
)
|
||||
from libp2p.crypto.exceptions import (
|
||||
MissingDeserializerError,
|
||||
)
|
||||
from libp2p.crypto.keys import (
|
||||
KeyType,
|
||||
PrivateKey,
|
||||
PublicKey,
|
||||
)
|
||||
from libp2p.crypto.rsa import (
|
||||
RSAPublicKey,
|
||||
)
|
||||
from libp2p.crypto.secp256k1 import (
|
||||
Secp256k1PrivateKey,
|
||||
Secp256k1PublicKey,
|
||||
)
|
||||
|
||||
key_type_to_public_key_deserializer = {
|
||||
KeyType.Secp256k1.value: Secp256k1PublicKey.from_bytes,
|
||||
|
||||
Reference in New Issue
Block a user