Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def blockUID(self) -> BlockUID:
return BlockUID(self.number, self.proof_of_work())
version = int(head[1]) if len(head) == 2 else 0
return cls(version)
except AttributeError:
raise MalformedDocumentError("Head")
def __str__(self) -> str:
return "HEAD" if self.version == 0 else "HEAD:{}".format(str(self.version))
@attr.s()
class HeadV0(Head):
signature = attr.ib(type=str)
api = attr.ib(type=API)
head = attr.ib(type=Head)
pubkey = attr.ib(type=str)
blockstamp = attr.ib(type=BlockUID)
re_inline = re.compile(
"^(WS2P(?:{ws2p_private})?(?:{ws2p_public})?):({head}):({pubkey}):({blockstamp})(?::)?(.*)".format(
ws2p_private=WS2P_PRIVATE_PREFIX_REGEX,
ws2p_public=WS2P_PUBLIC_PREFIX_REGEX,
head=WS2P_HEAD_REGEX,
pubkey=PUBKEY_REGEX,
blockstamp=BLOCK_UID_REGEX,
)
)
re_signature = re.compile(SIGNATURE_REGEX)
@classmethod
def from_inline(cls, inline: str, signature: str):
try:
:param version: Version of document
:param currency: Name of the currency
:param blockhash: Hash of the block
:param inline: Inline document
:return:
"""
cert_data = Certification.re_inline.match(inline)
if cert_data is None:
raise MalformedDocumentError("Certification ({0})".format(inline))
pubkey_from = cert_data.group(1)
pubkey_to = cert_data.group(2)
blockid = int(cert_data.group(3))
if blockid == 0 or blockhash is None:
timestamp = BlockUID.empty()
else:
timestamp = BlockUID(blockid, blockhash)
signature = cert_data.group(4)
return cls(version, currency, pubkey_from, pubkey_to, timestamp, signature)
def block_uid(value: Union[str, BlockUID, None]) -> BlockUID:
"""
Convert value to BlockUID instance
:param value: Value to convert
:return:
"""
if isinstance(value, BlockUID):
result = value
elif isinstance(value, str):
result = BlockUID.from_str(value)
elif value is None:
result = BlockUID.empty()
else:
raise TypeError("Cannot convert {0} to BlockUID".format(type(value)))
return result
def __eq__(self, other: object) -> bool:
if not isinstance(other, BlockUID):
return NotImplemented
return self.number == other.number and self.sha_hash == other.sha_hash
def from_inline(
cls: Type[IdentityType], version: int, currency: str, inline: str
) -> IdentityType:
"""
Return Identity instance from inline Identity string
:param version: Document version number
:param currency: Name of the currency
:param inline: Inline string of the Identity
:return:
"""
selfcert_data = Identity.re_inline.match(inline)
if selfcert_data is None:
raise MalformedDocumentError("Inline self certification")
pubkey = selfcert_data.group(1)
signature = selfcert_data.group(2)
ts = BlockUID.from_str(selfcert_data.group(3))
uid = selfcert_data.group(4)
return cls(version, currency, pubkey, uid, ts, signature)
def __init__(self, number: int, sha_hash: str) -> None:
assert type(number) is int
assert BlockUID.re_hash.match(sha_hash) is not None
self.number = number
self.sha_hash = sha_hash