The @zcloak/message module defines a peer-to-peer messaging protocol, it includes creating and encrypting messages, decrypting messages and verifying them.

Integration steps

  1. Installation: yarn add @zcloak/message
  2. Import the necessary classes and functions
import { encrypt, decrypt } from '@zcloak/message';

Key Classes and Functions

Message Encryption

The Encryption function enables creating encrypted message

The method:

encryptMessage(params)

export async function encryptMessage<T extends MessageType>(
  type: T,
  data: MessageData[T],
  sender: IDidKeyring,
  receiverUrl: DidUrl,
  reply?: string,
  resolver?: DidResolver
): Promise<Message<T>> {
  //......
}

Message Decryption

The Decrypt functions enable the decryption and verification of encrypted messages, ensuring the integrity and validity of the message contents

Key methods include:

verifyMessageData(params)

export function verifyMessageData(message: DecryptedMessage<MessageType>): void {
  //......
}