The @zcloak/message
module defines a peer-to-peer messaging protocol, it includes creating and encrypting messages, decrypting messages and verifying them.
yarn add @zcloak/message
import { encrypt, decrypt } from '@zcloak/message';
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
object, containing the encrypted message, along with other relevant information such as the message ID, reply ID, sender, receiver, message type, and the ctype if available.Type
- The type of the message to be encrypted.Data
- The payload data to be encrypted.Sender
- The DID keyring of the sender.ReceiverUrl
- The DID URL of the recipient.Reply
(optional) - The ID of the message being replied to.Resolver
(optional) - The DID resolver to use for resolving DIDs and DID URLs.Message
- an object containing the encrypted message and relevant information.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 {
//......
}