-
-
Notifications
You must be signed in to change notification settings - Fork 11
Encrypting and Decrypting Messages
Messages and KVS records are encrypted using Curve25519, Salsa20, and Poly1305 NaCl box and NaCL.secretbox cipher algorithms respectively, then packed in transactions, which are signed and broadcasted to ADAMANT network.
The library offers methods to encrypt and decrypt messages and KVS records.
Further reading:
Decrypts a message or KVS record, retrieved from ADAMANT blockchain.
Format:
decodeMsg(msg, senderPublicKey, passPhrase, nonce)
Parameters:
-
msg
— message to decrypt -
senderPublicKey
— sender's public key -
passPhrase
— recipient's 12 words mnemonic ADM passPhrase -
nonce
— nonce
Returns:
Decrypted message, string. Or empty string, if unable to decrypt.
Example:
api.get('transactions/get', { id: '12154642911137703318', returnAsset: 1 }).then(response => {
if (response.success) {
const chat = response.data.transaction.asset.chat;
if (chat) {
msg = api.decodeMsg(chat.message, response.data.transaction.senderPublicKey, config.passPhrase, chat.own_message);
}
}
})
Encodes a message or KVS record. Use encryptor
module of the library.
Note: you don't need to encrypt a message when using sendMessage, it encrypts a message by default.
Format:
encryptor.encodeMessage(msg, keypair, recipientPublicKey)
Parameters:
-
msg
— message to encrypt -
keypair
— sender's public and private keys -
recipientPublicKey
— recipients's public key
Returns:
Object with strings of encrypted message
and nonce own_message
.