pub struct Message { /* private fields */ }
Expand description

DIDComm message structure.

Messages are used to construct new DIDComm messages.

A common flow is

For examples have a look here.

Specification

Implementations

Appends attachment into attachments field. Consumes instance of AttachmentBuilder to do so.

Parameters
  • builder - prepopulated instance of AttachmentBuilder

Returns iterator of all attachments, if any. If no attachment present - empty iterator will be returned.

Generates EMPTY default message. Use extension messages to build final one before sending.

Adds (or updates) custom unique header key-value pair to the header. This portion of header is not sent as JOSE header.

Sets message to be serialized as flat JWE JSON. If this message has multiple targets, sealing it will result in an Error.

Sets message to be serialized as flat JWS JSON and then calls as_jws. If this message has multiple targets, sealing it will result in an Error.

Shortcut to DidCommHeader::get_message_uri

Sets thid and pthid same as those in replying_to Shortcut to DidCommHeader::reply_to method

  • replying_to - ref to message we’re replying to

Sets pthid to the parent’s thid. It defaults to id if thid is missing.

Parameters
  • parent - ref to a parent threaded Message

Setter of from header Helper method.

For resolve feature will set kid header automatically based on the did document resolved.

Creates set of JWM related headers for the JWE Modifies JWM related header portion to match encryption implementation and leaves other parts unchanged. TODO + FIXME: complete implementation

Setter of the body. Note, that given text has to be a valid JSON string to be a valid body value.

Setter of didcomm_header. Replaces existing one with provided by consuming both values. Returns modified instance of Self.

Setter of from header.

Getter of the body as String.

&DidCommHeader getter.

&JwmCommHeader getter.

If message is_rotation() true - returns from_prion claims. Errors otherwise with Error::NoRotationData

Checks if message is rotation one. Exposed for explicit checks on calling code level.

Setter of jwm_header. Replaces existing one with provided by consuming both values. Returns modified instance of Self.

Setter of m_type @type header

Setter of typ header property.

Parameters
  • typ - MessageType to be set for typ property

Sets times of creation as now and, optional, expires time.

Arguments
  • expires - time in seconds since Unix Epoch when message is considered to be invalid.

Setter of to header

Setter of didcomm_header. Replaces existing one with provided by consuming both values. Returns modified instance of Self.

Gets Iterator over key-value pairs of application level headers

Setter of thid header

Setter of pthid header

Serializes current state of the message into json. Consumes original message - use as raw sealing of envelope.

Presents IV and Payload to be externally encrypted and then sealed with seal_pre_encrypted method.

Returns

Tuple of bytes where .0 is IV and .1 is payload for encryption

Builds JWE from current message and it’s pre-encrypted payload: expert_for_encryption should be used prior to this call and it’s output provided as payload.

Parameters

ciphertext - encrypted output of export_for_encryption as JWE payload

Returns serialized JSON JWE message, which is ready to be sent to receipent

Construct a message from received data. Raw, JWS or JWE payload is accepted.

Arguments
  • incoming - serialized message as Message/Jws/Jws

  • encryption_recipient_private_key - recipients private key, used to decrypt kek in JWE

  • encryption_sender_public_key - senders public key, used to decrypt kek in JWE

  • signing_sender_public_key - senders public key, the JWS envelope was signed with

Wrap self to be mediated by some mediator. Warning: Should be called on a Message instance which is ready to be sent! If message is not properly set up for crypto - this method will propagate error from called .seal() method. Takes one mediator at a time to make sure that mediated chain preserves unchanged. This method can be chained any number of times to match all the mediators in the chain.

Arguments
  • sender_private_key - encryption key for inner message payload JWE encryption

  • recipient_public_keys - keys used to encrypt content encryption key for recipient; can be provided if key should not be resolved via recipients DID

  • mediator_did - DID of message mediator, will be to of mediated envelope

  • mediator_public_key - key used to encrypt content encryption key for mediator; can be provided if key should not be resolved via mediators DID

Seals (encrypts) self and returns ready to send JWE

Arguments
  • sender_private_key - encryption key for inner message payload JWE encryption

  • recipient_public_keys - keys used to encrypt content encryption key for recipient; can be provided if key should not be resolved via recipients DID

Associated functions implementations. Possibly not required as Jwe serialization covers this.

Parses iv value as Vec<u8> from public header. Both regular JSON and Compact representations are accepted. Returns Error on failure. TODO: Add examples

Transforms incomming into Jwe if it is one Also checks if skid field is present or returns None othervise Key resolution and validation fall onto caller of this method

Parameters
  • incomming - incomming message

Returns Option<Jwe> where .header.skid is skid and .payload() is cyphertext

Transforms decrypted Jwe into Message

Parameters
  • decrypted - result of decrypting of Jwe payload retreived after decrypting content of as_jwe function call output.

Signs raw message and then packs it to encrypted envelope Spec

Arguments
  • encryption_sender_private_key - encryption key for inner message payload JWE encryption

  • encryption_recipient_public_keys - keys used to encrypt content encryption key for recipient with; can be provided if key should not be resolved via recipients DID

  • signing_algorithm - encryption algorithm used

  • signing_sender_private_key - signing key for enveloped message JWS encryption

Encrypts current message by consuming it. Uses provided cryptography function to perform the encryption. Agnostic of actual algorithm used. Consuming is to make sure no changes are possible post packaging / sending. Returns (JwmHeader, Vec<u8>) to be sent to recipient.

Arguments
  • crypter - encryptor that should be used

  • cek - content encryption key to encrypt message with

Decrypts received cypher into instance of Message. Received message should be encrypted with our pub key. Returns Ok(Message) if decryption / deserialization succeeded. Error otherwise.

Arguments
  • received_message - received message as byte array

  • decrypter - decrypter that should be used

  • cek - content encryption key to decrypt message with

Signs message and turns it into Jws envelope. Err is returned if message is not properly prepared or data is malformed. Jws enveloped payload is base64_url encoded

Verifies signature and returns payload message on verification success. Err return if signature invalid or data is malformed. Expects Jws’s payload to be a valid serialized Message and base64_url encoded.

Verifies signature and returns payload message on verification success. Err return if signature invalid or data is malformed. Expects Jws’s payload to be a valid serialized Message and base64_url encoded.

Arguments
  • jws - to be verified jws message as json Value object

  • signing_sender_public_key - optional public key used for verification, if None it will try to resolve the did in the kid field

Transforms given Message into out_of_band invitation with given body and optional attachments.

Parameters
  • body - bytes of JSON serialized message body
  • attachments - optional set of AttachmentBuilder to be attached

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.