> loading_
# To add an AI-generated summary alongside a document hash:
#
# 1. Read the document content from the file system.
# This is the raw data we will both hash and summarize.
const documentBuffer = fs.readFileSync('example-document.txt');
const documentContent = documentBuffer.toString();
# 2. Call an LLM to generate a one-sentence summary.
# This example uses a placeholder function; you would integrate your preferred LLM SDK (e.g., OpenAI, Claude).
# This function must be asynchronous and should be awaited.
async function getAiSummary(text) {
// Replace with your actual LLM API call
console.log('Generating AI summary for document...');
const response = await callYourLLM_API(text);
return response.summary;
}
# 3. Prepare both memos: the hash and the AI summary.
# First, calculate the document's SHA256 hash.
const documentHash = crypto.createHash('sha256').update(documentBuffer).digest('hex').toUpperCase();
# Second, await the asynchronous call to the LLM.
const aiSummary = await getAiSummary(documentContent);
# 4. Construct the Memos array with distinct MemoTypes.
# Each memo is an object with MemoType and MemoData, both hex-encoded.
const transactionMemos = [
{
Memo: {
MemoType: Buffer.from('hash_sha256', 'utf8').toString('hex').toUpperCase(),
MemoData: Buffer.from(documentHash, 'utf8').toString('hex').toUpperCase()
}
},
{
Memo: {
MemoType: Buffer.from('ai_summary', 'utf8').toString('hex').toUpperCase(),
MemoData: Buffer.from(aiSummary, 'utf8').toString('hex').toUpperCase()
}
}
];
# 5. Add the Memos array to your transaction object.
# The submitted transaction will now contain both the verifiable hash and the readable summary.
const tx = {
TransactionType: "Payment",
Account: sender.address,
Destination: recipient.address,
Amount: "1", // 1 drop of XRP
Memos: transactionMemos
};