Get the message and decypher it

When you receive a 1-drop transaction, it might contain a hidden message for you. By checking the raw transaction data in your block explorer and looking at the memo field, you can find an encrypted message. You'll see a scrambled string of characters - this is your encrypted message. Since this message was encrypted using your public (outside) key, only your private (inside) key can decrypt it. By copying this encrypted text and using your private key, you can transform this unreadable data back into the original message that was meant for your eyes only.

import tweetnacl from 'tweetnacl';
import { Wallet } from "xrpl";
import {
  edwardsToMontgomeryPub,
  edwardsToMontgomeryPriv,
} from "@noble/curves/ed25519";

const { box } = tweetnacl;

export function decryptMessage(
  messageWithNonce: string,
  recipientPublicKey: string,
  senderSecretKey: string,
): string {
  const pubKeyBytes = Buffer.from(recipientPublicKey.slice(2), "hex");
  const secretKeyBytes = Buffer.from(senderSecretKey.slice(2), "hex");

  const pubKeyCurve = edwardsToMontgomeryPub(pubKeyBytes);
  const privKeyCurve = edwardsToMontgomeryPriv(secretKeyBytes);
  console.log(messageWithNonce)
  const { encrypted, nonce } = JSON.parse(messageWithNonce);
  const messageBytes = Buffer.from(encrypted,"base64");
  const nonceBytes = Buffer.from(nonce,"base64");
  const decryptedMessage = box.open(
    messageBytes,
    nonceBytes,
    pubKeyCurve,
    privKeyCurve,
  );
  if (!decryptedMessage) {
    throw new Error("Failed to decrypt message");
  }
  return new TextDecoder().decode(decryptedMessage);
}

function main() {
  const cypherMessage =
    "Your cypher message goes here";
  const senderPubKey =
    "The sender public key goes here";
  const mySeed = "your seed goes here";

  const myPrivateKey = Wallet.fromSeed(mySeed).privateKey;
  const clearMessage = decryptMessage(
    Buffer.from(cypherMessage, "hex").toString(),
    senderPubKey,
    myPrivateKey,
  );

  console.log("==============CLEAR MESSAGE==============");
  console.log(clearMessage);
  
    console.log("all done");
}
main();


Last updated