forked from LBRYCommunity/lbry-sdk
removed legacy_schema_v1
This commit is contained in:
parent
ce9dc1836e
commit
9fd67aaad6
8 changed files with 0 additions and 242 deletions
|
@ -1,44 +0,0 @@
|
||||||
V_0_0_1 = "_0_0_1"
|
|
||||||
V_0_0_2 = "_0_0_2"
|
|
||||||
V_0_0_3 = "_0_0_3"
|
|
||||||
V_0_1_0 = "_0_1_0"
|
|
||||||
|
|
||||||
|
|
||||||
VERSION_MAP = {
|
|
||||||
V_0_0_1: 1,
|
|
||||||
V_0_0_2: 2,
|
|
||||||
V_0_0_3: 3,
|
|
||||||
V_0_1_0: 4,
|
|
||||||
}
|
|
||||||
|
|
||||||
VERSION_NAMES = {
|
|
||||||
1: V_0_0_1,
|
|
||||||
2: V_0_0_2,
|
|
||||||
3: V_0_0_3,
|
|
||||||
4: V_0_1_0
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
VERSION = "version"
|
|
||||||
STREAM_TYPE = "streamType"
|
|
||||||
CERTIFICATE_TYPE = "certificateType"
|
|
||||||
CLAIM_TYPE = "claimType"
|
|
||||||
SIGNATURE = "publisherSignature"
|
|
||||||
|
|
||||||
CLAIM_TYPES = {
|
|
||||||
STREAM_TYPE: "stream",
|
|
||||||
CERTIFICATE_TYPE: "certificate"
|
|
||||||
}
|
|
||||||
|
|
||||||
CLAIM_TYPE_NAMES = {
|
|
||||||
1: "stream",
|
|
||||||
2: "certificate"
|
|
||||||
}
|
|
||||||
|
|
||||||
LBRY_SD_HASH = "lbry_sd_hash"
|
|
||||||
LBRY_SD_HASH_LENGTH = 48
|
|
||||||
|
|
||||||
SOURCE_TYPES = {
|
|
||||||
LBRY_SD_HASH: 1
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
from copy import deepcopy
|
|
||||||
|
|
||||||
from lbrynet.schema.proto2 import certificate_pb2 as cert_pb
|
|
||||||
from lbrynet.schema.baseschema import Schema
|
|
||||||
from lbrynet.schema.legacy_schema_v1 import VERSION_MAP, V_0_0_1
|
|
||||||
from lbrynet.schema.constants import ECDSA_CURVES, CURVE_NAMES
|
|
||||||
from lbrynet.schema.validator import get_key_type_from_dem
|
|
||||||
|
|
||||||
|
|
||||||
class _ECDSAKeyHelper(object):
|
|
||||||
def __init__(self, key):
|
|
||||||
self._key = key
|
|
||||||
|
|
||||||
@property
|
|
||||||
def der(self):
|
|
||||||
return self._key.to_der()
|
|
||||||
|
|
||||||
@property
|
|
||||||
def curve_name(self):
|
|
||||||
return self._key.curve.name
|
|
||||||
|
|
||||||
|
|
||||||
class Certificate(Schema):
|
|
||||||
@classmethod
|
|
||||||
def load(cls, message):
|
|
||||||
_key = deepcopy(message)
|
|
||||||
_message_pb = cert_pb.Certificate()
|
|
||||||
if isinstance(_key, dict):
|
|
||||||
_message_pb.publicKey = _key.pop("publicKey")
|
|
||||||
_message_pb.version = VERSION_MAP[_key.pop("version")]
|
|
||||||
_message_pb.keyType = ECDSA_CURVES[_key.pop("keyType")]
|
|
||||||
else:
|
|
||||||
_message_pb.version = _key.version
|
|
||||||
_message_pb.keyType = _key.keyType
|
|
||||||
_message_pb.publicKey = _key.publicKey
|
|
||||||
if _message_pb.keyType not in CURVE_NAMES:
|
|
||||||
raise Exception("Unknown curve")
|
|
||||||
if get_key_type_from_dem(_message_pb.publicKey) != _message_pb.keyType:
|
|
||||||
raise Exception("Curve mismatch")
|
|
||||||
return cls._load(_key, _message_pb)
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def load_from_key_obj(cls, key, key_type):
|
|
||||||
if key_type in ECDSA_CURVES:
|
|
||||||
_key = _ECDSAKeyHelper(key)
|
|
||||||
else:
|
|
||||||
raise Exception("Unknown key type: %s" % str(type(key)))
|
|
||||||
if key_type != _key.curve_name:
|
|
||||||
raise Exception("Curve mismatch")
|
|
||||||
msg = {
|
|
||||||
"version": V_0_0_1,
|
|
||||||
"keyType": key_type,
|
|
||||||
"publicKey": _key.der,
|
|
||||||
}
|
|
||||||
return cls.load(msg)
|
|
|
@ -1,51 +0,0 @@
|
||||||
from copy import deepcopy
|
|
||||||
|
|
||||||
from lbrynet.schema.proto2 import legacy_claim_pb2 as claim_pb
|
|
||||||
from lbrynet.schema.legacy_schema_v1 import VERSION_MAP
|
|
||||||
from lbrynet.schema.legacy_schema_v1.signature import Signature
|
|
||||||
from lbrynet.schema.legacy_schema_v1.certificate import Certificate
|
|
||||||
from lbrynet.schema.baseschema import Schema
|
|
||||||
from lbrynet.schema.legacy_schema_v1.stream import Stream
|
|
||||||
|
|
||||||
|
|
||||||
class Claim(Schema):
|
|
||||||
CLAIM_TYPE_STREAM = 1
|
|
||||||
CLAIM_TYPE_CERT = 2
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def load(cls, message):
|
|
||||||
_claim = deepcopy(message)
|
|
||||||
_message_pb = claim_pb.Claim()
|
|
||||||
_message_pb.version = VERSION_MAP[_claim.pop("version")]
|
|
||||||
|
|
||||||
if "certificate" in _claim:
|
|
||||||
_cert = _claim.pop("certificate")
|
|
||||||
if isinstance(_cert, dict):
|
|
||||||
cert = Certificate.load(_cert)
|
|
||||||
else:
|
|
||||||
cert = _cert
|
|
||||||
claim_type = Claim.CLAIM_TYPE_CERT
|
|
||||||
_message_pb.certificate.MergeFrom(cert)
|
|
||||||
|
|
||||||
elif "stream" in _claim:
|
|
||||||
_stream = _claim.pop("stream")
|
|
||||||
if isinstance(_stream, dict):
|
|
||||||
stream = Stream.load(_stream)
|
|
||||||
else:
|
|
||||||
stream = _stream
|
|
||||||
claim_type = Claim.CLAIM_TYPE_STREAM
|
|
||||||
_message_pb.stream.MergeFrom(stream)
|
|
||||||
else:
|
|
||||||
raise AttributeError
|
|
||||||
|
|
||||||
_message_pb.claimType = claim_type
|
|
||||||
|
|
||||||
if "publisherSignature" in _claim:
|
|
||||||
_publisherSignature = _claim.pop("publisherSignature")
|
|
||||||
if isinstance(_publisherSignature, dict):
|
|
||||||
publisherSignature = Signature.load(_publisherSignature)
|
|
||||||
else:
|
|
||||||
publisherSignature = _publisherSignature
|
|
||||||
_message_pb.publisherSignature.MergeFrom(publisherSignature)
|
|
||||||
|
|
||||||
return cls._load(_claim, _message_pb)
|
|
|
@ -1,18 +0,0 @@
|
||||||
from copy import deepcopy
|
|
||||||
|
|
||||||
from lbrynet.schema.proto2 import fee_pb2 as fee_pb
|
|
||||||
from lbrynet.schema.baseschema import Schema
|
|
||||||
from lbrynet.schema.legacy_schema_v1 import VERSION_MAP
|
|
||||||
from lbrynet.schema.constants import CURRENCY_MAP
|
|
||||||
|
|
||||||
|
|
||||||
class Fee(Schema):
|
|
||||||
@classmethod
|
|
||||||
def load(cls, message):
|
|
||||||
_fee = deepcopy(message)
|
|
||||||
currency = CURRENCY_MAP[_fee.pop('currency')]
|
|
||||||
_message_pb = fee_pb.Fee()
|
|
||||||
_message_pb.version = VERSION_MAP[_fee.pop("version")]
|
|
||||||
_message_pb.currency = currency
|
|
||||||
_message_pb.address = _fee.pop('address')
|
|
||||||
return cls._load(_fee, _message_pb)
|
|
|
@ -1,17 +0,0 @@
|
||||||
from copy import deepcopy
|
|
||||||
from lbrynet.schema.proto2 import metadata_pb2 as metadata_pb
|
|
||||||
from lbrynet.schema.legacy_schema_v1.fee import Fee
|
|
||||||
from lbrynet.schema.baseschema import Schema
|
|
||||||
from lbrynet.schema.legacy_schema_v1 import VERSION_MAP
|
|
||||||
|
|
||||||
|
|
||||||
class Metadata(Schema):
|
|
||||||
@classmethod
|
|
||||||
def load(cls, message):
|
|
||||||
_metadata = deepcopy(message)
|
|
||||||
_message_pb = metadata_pb.Metadata()
|
|
||||||
_message_pb.version = VERSION_MAP[_metadata.pop("version")]
|
|
||||||
if 'fee' in _metadata:
|
|
||||||
fee_pb = Fee.load(_metadata.pop('fee'))
|
|
||||||
_message_pb.fee.CopyFrom(fee_pb)
|
|
||||||
return cls._load(_metadata, _message_pb)
|
|
|
@ -1,18 +0,0 @@
|
||||||
from copy import deepcopy
|
|
||||||
|
|
||||||
from lbrynet.schema.proto2 import signature_pb2 as signature_pb
|
|
||||||
from lbrynet.schema.legacy_schema_v1 import VERSION_MAP
|
|
||||||
from lbrynet.schema.constants import ECDSA_CURVES
|
|
||||||
from lbrynet.schema.baseschema import Schema
|
|
||||||
|
|
||||||
|
|
||||||
class Signature(Schema):
|
|
||||||
@classmethod
|
|
||||||
def load(cls, message):
|
|
||||||
_signature = deepcopy(message)
|
|
||||||
_message_pb = signature_pb.Signature()
|
|
||||||
_message_pb.version = VERSION_MAP[_signature.pop("version")]
|
|
||||||
_message_pb.signatureType = ECDSA_CURVES[_signature.pop("signatureType")]
|
|
||||||
_message_pb.certificateId = _signature.pop("certificateId")
|
|
||||||
_message_pb.signature = _signature.pop("signature")
|
|
||||||
return cls._load(_signature, _message_pb)
|
|
|
@ -1,19 +0,0 @@
|
||||||
from copy import deepcopy
|
|
||||||
from lbrynet.schema.proto2 import source_pb2 as source_pb
|
|
||||||
from lbrynet.schema.legacy_schema_v1 import SOURCE_TYPES, LBRY_SD_HASH_LENGTH, VERSION_MAP
|
|
||||||
from lbrynet.schema.baseschema import Schema
|
|
||||||
from lbrynet.schema.error import InvalidSourceHashLength
|
|
||||||
|
|
||||||
|
|
||||||
class Source(Schema):
|
|
||||||
@classmethod
|
|
||||||
def load(cls, message):
|
|
||||||
_source = deepcopy(message)
|
|
||||||
sd_hash = _source.pop('source')
|
|
||||||
assert len(sd_hash) == LBRY_SD_HASH_LENGTH, InvalidSourceHashLength(len(sd_hash))
|
|
||||||
_message_pb = source_pb.Source()
|
|
||||||
_message_pb.version = VERSION_MAP[_source.pop("version")]
|
|
||||||
_message_pb.sourceType = SOURCE_TYPES[_source.pop('sourceType')]
|
|
||||||
_message_pb.source = sd_hash
|
|
||||||
_message_pb.contentType = _source.pop('contentType')
|
|
||||||
return cls._load(_source, _message_pb)
|
|
|
@ -1,20 +0,0 @@
|
||||||
from copy import deepcopy
|
|
||||||
|
|
||||||
from lbrynet.schema.proto2 import stream_pb2 as stream_pb
|
|
||||||
from lbrynet.schema.legacy_schema_v1.source import Source
|
|
||||||
from lbrynet.schema.legacy_schema_v1 import VERSION_MAP
|
|
||||||
from lbrynet.schema.legacy_schema_v1.metadata import Metadata
|
|
||||||
from lbrynet.schema.baseschema import Schema
|
|
||||||
|
|
||||||
|
|
||||||
class Stream(Schema):
|
|
||||||
@classmethod
|
|
||||||
def load(cls, message):
|
|
||||||
_claim = deepcopy(message)
|
|
||||||
source = Source.load(_claim.pop('source'))
|
|
||||||
metadata = Metadata.load(_claim.pop('metadata'))
|
|
||||||
_message_pb = stream_pb.Stream()
|
|
||||||
_message_pb.version = VERSION_MAP[_claim.pop("version")]
|
|
||||||
_message_pb.source.CopyFrom(source)
|
|
||||||
_message_pb.metadata.CopyFrom(metadata)
|
|
||||||
return cls._load(_claim, _message_pb)
|
|
Loading…
Add table
Reference in a new issue