The requirement to anchor prevents spam by associating a small cost for each message.
Encrypted messages
Messages can be encrypted so the data can only be read or processed by a specific LTO account. Encrypting a message is done using the public key of the recipient.
To get the public key from an address, we'll need to resolve the address. This uses the LTO DID resolver internally.
import LTO from '@ltonetwork/lto';
import { Message } from '@ltonetwork/lto/messages';
const lto = new LTO('T');
const account = lto.account();
const recipient = await lto.resolveAccount('3MsAuZ59xHHa5vmoPG45fBGC7PxLCYQZnbM');
const message = new Message('hello')
.encryptFor(recipient)
.signWith(account);
Only accounts that have submitted at least one transaction on the public chain can be resolved.
The recipient can decrypt the message using its private key.
import LTO from '@ltonetwork/lto';
import { Relay } from '@ltonetwork/lto/messages';
const lto = new LTO('T');
lto.relay = new Relay('https://my-relay.example.com');