예제 #1
0
class ClientMessageValidator(MessageValidator):
    schema = (
        (f.IDENTIFIER.nm, IdentifierField(optional=True, nullable=True)),
        (f.REQ_ID.nm, NonNegativeNumberField()),
        (OPERATION, ClientOperationField()),
        (f.SIG.nm, SignatureField(max_length=SIGNATURE_FIELD_LIMIT,
                                  optional=True)),
        (f.DIGEST.nm, LimitedLengthStringField(max_length=DIGEST_FIELD_LIMIT,
                                               optional=True)),
        (f.PROTOCOL_VERSION.nm, ProtocolVersionField()),
        (f.SIGS.nm, MapField(IdentifierField(),
                             SignatureField(max_length=SIGNATURE_FIELD_LIMIT),
                             optional=True, nullable=True)),
    )

    def __init__(self, operation_schema_is_strict, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # Following code is for support of non-strict schema
        # TODO: refactor this
        # TODO: this (and all related functionality) can be removed when
        # when fixed problem with transaction serialization (INDY-338)
        # Adding fields from enabled plugins to schema.
        self.schema = self.schema + tuple(PLUGIN_CLIENT_REQUEST_FIELDS.items())
        if operation_schema_is_strict:
            operation_field_index = 2
            op = ClientOperationField(schema_is_strict=operation_schema_is_strict)
            schema = list(self.schema)
            schema[operation_field_index] = (OPERATION, op)
            self.schema = tuple(schema)

    def validate(self, dct):
        super().validate(dct)
        if not (dct.get(f.IDENTIFIER.nm) or dct.get(f.SIGS.nm)):
            self._raise_invalid_message(
                'Missing both signatures and identifier')
예제 #2
0
class Batch(MessageBase):
    typename = BATCH

    schema = (
        (f.MSGS.nm, IterableField(SerializedValueField())),
        (f.SIG.nm, SignatureField(max_length=SIGNATURE_FIELD_LIMIT)),
    )
예제 #3
0
class TxnFeesField(FixedLengthField):
    _base_types = (list, tuple)
    inputs_validator = PublicInputsField()
    outputs_validator = PublicOutputsField()
    signatures_validator = IterableField(
        SignatureField(max_length=SIGNATURE_FIELD_LIMIT))

    def __init__(self, **kwargs):
        super().__init__(length=3, **kwargs)

    def _specific_validation(self, val):
        error = super()._specific_validation(val)
        if error:
            return error

        error = self.inputs_validator.validate(val[0])
        if error:
            return error

        error = self.outputs_validator.validate(val[1])
        if error:
            return error

        error = self.signatures_validator.validate(val[2])
        if error:
            return error

        if len(val[0]) != len(val[2]):
            return 'Number of signatures and number of inputs should match but are {} and {} ' \
                   'respectively.'.format(len(val[2]), len(val[0]))
예제 #4
0
class ClientMessageValidator(MessageValidator):
    def __init__(self, operation_schema_is_strict, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # Following code is for support of non-strict schema
        # TODO: refactor this
        # TODO: this (and all related functionality) can be removed when
        # when fixed problem with transaction serialization (INDY-338)
        strict = operation_schema_is_strict
        if not strict:
            operation_field_index = 2
            op = ClientOperationField(schema_is_strict=False)
            schema = list(self.schema)
            schema[operation_field_index] = (OPERATION, op)
            self.schema = tuple(schema)

    schema = (
        (f.IDENTIFIER.nm, IdentifierField()),
        (f.REQ_ID.nm, NonNegativeNumberField()),
        (OPERATION, ClientOperationField()),
        (f.SIG.nm,
         SignatureField(max_length=SIGNATURE_FIELD_LIMIT, optional=True)),
        (f.DIGEST.nm,
         LimitedLengthStringField(max_length=DIGEST_FIELD_LIMIT,
                                  optional=True)),
    )
예제 #5
0
class ClientMessageValidator(MessageValidator):
    schema = (
        (f.IDENTIFIER.nm, IdentifierField(optional=True, nullable=True)),
        (f.REQ_ID.nm, NonNegativeNumberField()),
        (OPERATION, ClientOperationField()),
        (f.SIG.nm,
         SignatureField(max_length=SIGNATURE_FIELD_LIMIT, optional=True)),
        (f.DIGEST.nm,
         LimitedLengthStringField(max_length=DIGEST_FIELD_LIMIT,
                                  optional=True)),
        (f.PROTOCOL_VERSION.nm, ProtocolVersionField()),
        (f.TAA_ACCEPTANCE.nm, ClientTAAAcceptance(optional=True)),
        (f.SIGS.nm,
         MapField(IdentifierField(),
                  SignatureField(max_length=SIGNATURE_FIELD_LIMIT),
                  optional=True,
                  nullable=True)),
        (f.ENDORSER.nm, IdentifierField(optional=True)),
    )

    def __init__(self, operation_schema_is_strict, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # Following code is for support of non-strict schema
        # TODO: refactor this
        # TODO: this (and all related functionality) can be removed when
        # when fixed problem with transaction serialization (INDY-338)
        # Adding fields from enabled plugins to schema.
        self.schema = self.schema + tuple(PLUGIN_CLIENT_REQUEST_FIELDS.items())
        if operation_schema_is_strict:
            operation_field_index = 2
            op = ClientOperationField(
                schema_is_strict=operation_schema_is_strict)
            schema = list(self.schema)
            schema[operation_field_index] = (OPERATION, op)
            self.schema = tuple(schema)

    def validate(self, dct):
        super().validate(dct)
        identifier = dct.get(f.IDENTIFIER.nm, None)
        signatures = dct.get(f.SIGS.nm, None)
        signature = dct.get(f.SIG.nm, None)
        endorser = dct.get(f.ENDORSER.nm, None)
        if signatures and signature:
            self._raise_invalid_message(
                'Request can not contain both fields "signatures" and "signature"'
            )
        if endorser is not None:
            if not signatures or endorser not in signatures:
                self._raise_invalid_message("Endorser must sign the request")
            if identifier is None:
                self._raise_invalid_message(
                    "Author's Identifier must be present when sending via Endorser"
                )
            if not signatures or identifier not in signatures:
                self._raise_invalid_message(
                    "Author must sign the request when sending via Endorser")
        if identifier and signatures and identifier not in signatures:
            self._raise_invalid_message(
                'The identifier is not contained in signatures')
        if not (identifier or signatures):
            self._raise_invalid_message(
                'Missing both signatures and identifier')