Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- **
- * Decodes the incoming message
- * @param {any} msg encoded message
- * @param {string} senderPublicKey sender public key
- * @param {string} privateKey our private key
- * @param {any} nonce nonce
- * @returns {string}
- */
- adamant.decodeMessage = function (msg, senderPublicKey, privateKey, nonce) {
- if (typeof msg === 'string') {
- msg = hexToBytes(msg)
- }
- if (typeof nonce === 'string') {
- nonce = hexToBytes(nonce)
- }
- if (typeof senderPublicKey === 'string') {
- senderPublicKey = hexToBytes(senderPublicKey)
- }
- if (typeof privateKey === 'string') {
- privateKey = hexToBytes(privateKey)
- }
- const DHPublicKey = ed2curve.convertPublicKey(senderPublicKey)
- const DHSecretKey = ed2curve.convertSecretKey(privateKey)
- const decrypted = nacl.box.open(msg, nonce, DHPublicKey, DHSecretKey)
- return decrypted ? decode(decrypted) : ''
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement