Module mydata_did.patched_protocols.issue_credential.v1_0.messages.credential_offer

A credential offer content message.

Expand source code
"""A credential offer content message."""

from typing import Sequence

from marshmallow import EXCLUDE, fields

from aries_cloudagent.messaging.agent_message import AgentMessage, AgentMessageSchema
from aries_cloudagent.messaging.decorators.attach_decorator import (
    AttachDecorator,
    AttachDecoratorSchema,
)

from ..message_types import ATTACH_DECO_IDS, CREDENTIAL_OFFER, PROTOCOL_PACKAGE
from .inner.credential_preview import CredentialPreview, CredentialPreviewSchema

from .....v1_0.decorators.patched_decorator_set import PatchedDecoratorSet

HANDLER_CLASS = (
    f"{PROTOCOL_PACKAGE}.handlers.credential_offer_handler.CredentialOfferHandler"
)


class CredentialOffer(AgentMessage):
    """Class representing a credential offer."""

    class Meta:
        """CredentialOffer metadata."""

        handler_class = HANDLER_CLASS
        schema_class = "CredentialOfferSchema"
        message_type = CREDENTIAL_OFFER

    def __init__(
        self,
        _id: str = None,
        *,
        comment: str = None,
        credential_preview: CredentialPreview = None,
        offers_attach: Sequence[AttachDecorator] = None,
        **kwargs,
    ):
        """
        Initialize credential offer object.

        Args:
            comment: optional human-readable comment
            credential_preview: credential preview
            offers_attach: list of offer attachments

        """
        super().__init__(_id=_id, _decorators=PatchedDecoratorSet(), **kwargs)
        self.comment = comment
        self.credential_preview = credential_preview
        self.offers_attach = list(offers_attach) if offers_attach else []

    def indy_offer(self, index: int = 0) -> dict:
        """
        Retrieve and decode indy offer from attachment.

        Args:
            index: ordinal in attachment list to decode and return
                (typically, list has length 1)

        """
        return self.offers_attach[index].indy_dict

    @classmethod
    def wrap_indy_offer(cls, indy_offer: dict) -> AttachDecorator:
        """Convert an indy credential offer to an attachment decorator."""
        return AttachDecorator.from_indy_dict(
            indy_dict=indy_offer, ident=ATTACH_DECO_IDS[CREDENTIAL_OFFER]
        )


class CredentialOfferSchema(AgentMessageSchema):
    """Credential offer schema."""

    class Meta:
        """Credential offer schema metadata."""

        model_class = CredentialOffer
        unknown = EXCLUDE

    comment = fields.Str(
        description="Human-readable comment", required=False, allow_none=True
    )
    credential_preview = fields.Nested(CredentialPreviewSchema, required=False)
    offers_attach = fields.Nested(
        AttachDecoratorSchema, required=True, many=True, data_key="offers~attach"
    )

Classes

class CredentialOffer (*, comment: str = None, credential_preview: CredentialPreview = None, offers_attach: Sequence[aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator] = None, **kwargs)

Class representing a credential offer.

Initialize credential offer object.

Args

comment
optional human-readable comment
credential_preview
credential preview
offers_attach
list of offer attachments
Expand source code
class CredentialOffer(AgentMessage):
    """Class representing a credential offer."""

    class Meta:
        """CredentialOffer metadata."""

        handler_class = HANDLER_CLASS
        schema_class = "CredentialOfferSchema"
        message_type = CREDENTIAL_OFFER

    def __init__(
        self,
        _id: str = None,
        *,
        comment: str = None,
        credential_preview: CredentialPreview = None,
        offers_attach: Sequence[AttachDecorator] = None,
        **kwargs,
    ):
        """
        Initialize credential offer object.

        Args:
            comment: optional human-readable comment
            credential_preview: credential preview
            offers_attach: list of offer attachments

        """
        super().__init__(_id=_id, _decorators=PatchedDecoratorSet(), **kwargs)
        self.comment = comment
        self.credential_preview = credential_preview
        self.offers_attach = list(offers_attach) if offers_attach else []

    def indy_offer(self, index: int = 0) -> dict:
        """
        Retrieve and decode indy offer from attachment.

        Args:
            index: ordinal in attachment list to decode and return
                (typically, list has length 1)

        """
        return self.offers_attach[index].indy_dict

    @classmethod
    def wrap_indy_offer(cls, indy_offer: dict) -> AttachDecorator:
        """Convert an indy credential offer to an attachment decorator."""
        return AttachDecorator.from_indy_dict(
            indy_dict=indy_offer, ident=ATTACH_DECO_IDS[CREDENTIAL_OFFER]
        )

Ancestors

  • aries_cloudagent.messaging.agent_message.AgentMessage
  • aries_cloudagent.messaging.models.base.BaseModel
  • abc.ABC

Class variables

var Meta

CredentialOffer metadata.

Static methods

def wrap_indy_offer(indy_offer: dict) ‑> aries_cloudagent.messaging.decorators.attach_decorator.AttachDecorator

Convert an indy credential offer to an attachment decorator.

Expand source code
@classmethod
def wrap_indy_offer(cls, indy_offer: dict) -> AttachDecorator:
    """Convert an indy credential offer to an attachment decorator."""
    return AttachDecorator.from_indy_dict(
        indy_dict=indy_offer, ident=ATTACH_DECO_IDS[CREDENTIAL_OFFER]
    )

Methods

def indy_offer(self, index: int = 0) ‑> dict

Retrieve and decode indy offer from attachment.

Args

index
ordinal in attachment list to decode and return (typically, list has length 1)
Expand source code
def indy_offer(self, index: int = 0) -> dict:
    """
    Retrieve and decode indy offer from attachment.

    Args:
        index: ordinal in attachment list to decode and return
            (typically, list has length 1)

    """
    return self.offers_attach[index].indy_dict
class CredentialOfferSchema (*args, **kwargs)

Credential offer schema.

Initialize an instance of AgentMessageSchema.

Raises

TypeError
If Meta.model_class has not been set
Expand source code
class CredentialOfferSchema(AgentMessageSchema):
    """Credential offer schema."""

    class Meta:
        """Credential offer schema metadata."""

        model_class = CredentialOffer
        unknown = EXCLUDE

    comment = fields.Str(
        description="Human-readable comment", required=False, allow_none=True
    )
    credential_preview = fields.Nested(CredentialPreviewSchema, required=False)
    offers_attach = fields.Nested(
        AttachDecoratorSchema, required=True, many=True, data_key="offers~attach"
    )

Ancestors

  • aries_cloudagent.messaging.agent_message.AgentMessageSchema
  • aries_cloudagent.messaging.models.base.BaseModelSchema
  • marshmallow.schema.Schema
  • marshmallow.base.SchemaABC

Class variables

var Meta

Credential offer schema metadata.

var opts