LogoLogo
  • Welcome
  • XRPL Basics
    • Getting Started
    • Payments
    • Reading and subscribing to Transactions
    • Writing and reading memos
    • Non Fungible Tokens
    • PathFinding
    • Escrow
    • Price Oracles
    • Tickets
    • Multi-Signature
  • Token Issuance and Liquidity
    • Creating Accounts
    • Issuing Tokens
    • Creating an AMM Pool
  • Cyphered Chat on XRPL
    • Set up
    • Set up Keys
    • Cypher the message
    • Set up the memo & send the tx
    • Get the message and decypher it
  • EVM Sidechain
    • Connecting Metamask
    • Bridging Assets
    • Remix
    • Banking App
    • Banking Contract Key Concepts
  • Tools
    • Xaman Setup
    • Metamask Setup
Powered by GitBook
On this page
Export as PDF
  1. Cyphered Chat on XRPL

Get the message and decypher it

PreviousSet up the memo & send the txNextEVM Sidechain

Last updated 4 months ago

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();