hive-tx v7
GitHub npm

Use

Memos

Memo.encode encrypts a private message. Memo.decode decrypts the message.

Rules

  • If the memo text starts with #, the library encrypts the text.
  • If the memo text does not start with #, the library returns the text with no change.
  • Use the sender memo private key to encrypt.
  • Use the recipient memo public key to encrypt.
  • Use the recipient memo private key to decrypt.

Encrypt

import { Memo, PrivateKey } from 'hive-tx'

const senderMemoKey = PrivateKey.from('5J...sender-memo-key')
const encrypted = Memo.encode(
  senderMemoKey,
  'STM...recipient-memo-public-key',
  '#Hello'
)

Put the encrypted string in a transfer memo field.

Decrypt

const recipientMemoKey = PrivateKey.from('5J...recipient-memo-key')
const text = Memo.decode(recipientMemoKey, encryptedMemo)
// text starts with '#'
Caution Encryption uses AES in CBC mode. The memo key is not the posting key. The memo key is not the active key.