예제 #1
0
    def to_json(self):
        """
        Generate a dict of the fulfillment

        Returns:
            dict: representing the fulfillment
        """
        return {
            'type': Ed25519Sha256.TYPE_NAME,
            'public_key': base64_remove_padding(
                urlsafe_b64encode(self.public_key)),
            'signature': base64_remove_padding(
                urlsafe_b64encode(self.signature)) if self.signature else None
        }
예제 #2
0
    def to_json(self):
        """
        Generate a dict of the fulfillment

        Returns:
            dict: representing the fulfillment
        """
        return {
            'type': ZenroomSha256.TYPE_NAME,
            'script': base64_remove_padding(urlsafe_b64encode(self.script)),
            'data': base64_remove_padding(urlsafe_b64encode(self.data)),
            'keys': base64_remove_padding(urlsafe_b64encode(self.keys)),
            # 'conf': base64_remove_padding(
            #     urlsafe_b64encode(self.conf)),
        }
예제 #3
0
    def to_json(self):
        """
        Generate a dict of the fulfillment

        Returns:
            dict: representing the fulfillment
        """
        return {
            'type':
            Ed25519Sha256.TYPE_NAME,
            'public_key':
            base64_remove_padding(urlsafe_b64encode(self.public_key)),
            'signature':
            base64_remove_padding(urlsafe_b64encode(self.signature))
            if self.signature else None
        }
예제 #4
0
def normalize_value(value, key):
    from cryptoconditions.crypto import (base64_add_padding,
                                         base64_remove_padding)
    if key in ('public_key', 'signature'):
        value = urlsafe_b64decode(base64_add_padding(value))
    if key in ('condition_binary', 'fingerprint_contents', 'message'):
        value = unhexlify(value.encode())
    if key == 'fulfillment':
        value = base64_remove_padding(
            urlsafe_b64encode(unhexlify(value.encode()))).decode()
    return value
예제 #5
0
def normalize_value(value, key):
    from cryptoconditions.crypto import (base64_add_padding,
                                         base64_remove_padding)
    if key in ('public_key', 'signature'):
        value = urlsafe_b64decode(base64_add_padding(value))
    if key in ('condition_binary', 'fingerprint_contents', 'message'):
        value = unhexlify(value.encode())
    if key == 'fulfillment':
        value = base64_remove_padding(
            urlsafe_b64encode(unhexlify(value.encode()))).decode()
    return value
예제 #6
0
    def serialize_uri(self):
        """
        Generate the URI form encoding of this fulfillment.

        Turns the fulfillment into a URI containing only URL-safe
        characters. This format is convenient for passing around
        fulfillments in URLs, JSON and other text-based formats.

        Return:
             str: Fulfillment as a URI
        """
        return base64_remove_padding(
            base64.urlsafe_b64encode(self.serialize_binary())).decode()
예제 #7
0
    def serialize_uri(self):
        """
        Generate the URI form encoding of this fulfillment.

        Turns the fulfillment into a URI containing only URL-safe
        characters. This format is convenient for passing around
        fulfillments in URLs, JSON and other text-based formats.

        Return:
             str: Fulfillment as a URI
        """
        return base64_remove_padding(
            base64.urlsafe_b64encode(self.serialize_binary())).decode()
예제 #8
0
    def serialize_uri(self):
        """
        Generate the URI form encoding of this fulfillment.

        Turns the fulfillment into a URI containing only URL-safe characters. This
        format is convenient for passing around fulfillments in URLs, JSON and
        other text-based formats.

        "cf:" BASE16(TYPE_BIT) ":" BASE64URL(FULFILLMENT_PAYLOAD)

        Return:
             string: Fulfillment as a URI
        """
        return 'cf:{:x}:{}'.format(
            self.type_id,
            base64_remove_padding(base64.urlsafe_b64encode(self.serialize_payload())).decode('utf-8'))
예제 #9
0
    def serialize_uri(self):
        """
        Generate the URI form encoding of this condition.

        Turns the condition into a URI containing only URL-safe characters. This
        format is convenient for passing around conditions in URLs, JSON and other text-based formats.

        "cc:" BASE16(TYPE_ID) ":" BASE16(BITMASK) ":" BASE64URL(HASH) ":" BASE10(MAX_FULFILLMENT_LENGTH)

        Returns:
            string: Condition as a URI
        """

        return 'cc:{:x}:{:x}:{}:{}'.format(
            self.type_id, self.bitmask,
            base64_remove_padding(base64.urlsafe_b64encode(
                self.hash)).decode('utf-8'), self.max_fulfillment_length)
예제 #10
0
    def serialize_uri(self):
        """
        Generate the URI form encoding of this condition.

        Turns the condition into a URI containing only URL-safe characters. This
        format is convenient for passing around conditions in URLs, JSON and other text-based formats.

        "cc:" BASE16(TYPE_ID) ":" BASE16(BITMASK) ":" BASE64URL(HASH) ":" BASE10(MAX_FULFILLMENT_LENGTH)

        Returns:
            string: Condition as a URI
        """

        return 'cc:{:x}:{:x}:{}:{}'.format(
            self.type_id,
            self.bitmask,
            base64_remove_padding(base64.urlsafe_b64encode(self.hash)).decode('utf-8'),
            self.max_fulfillment_length
        )
예제 #11
0
    def serialize_uri(self):
        """
        Generate the URI form encoding of this condition.

        Turns the condition into a URI containing only URL-safe characters. This
        format is convenient for passing around conditions in URLs, JSON and other text-based formats.

        "cc:" BASE16(TYPE_ID) ":" BASE16(BITMASK) ":" BASE64URL(HASH) ":" BASE10(MAX_COST)

        Returns:
            string: Condition as a URI
        """
        condition_type = TypeRegistry.find_by_type_id(self.type_id)
        condition_class = TypeRegistry.find_by_type_id(self.type_id)['class']
        include_subtypes = condition_class.TYPE_CATEGORY == 'compound'
        uri = 'ni:///sha-256;{}?fpt={}&cost={}'.format(
            base64_remove_padding(
                base64.urlsafe_b64encode(self.hash)).decode(),
            condition_type['name'],
            self.cost,
        )
        if include_subtypes:
            uri += '&subtypes=' + ','.join(sorted(self.subtypes))
        return uri