services
Get a key

library / AI and blockchain / Agent wallets and signing safety / SI0130

Sign-message payload inspector

You get a read-only script that takes the bytes an agent is about to sign as a message and blocks them when they decode as a Solana transaction, raw or hidden in base64 or base58 text. Plain sentences pass.

By Carbium · Agent wallets and signing safety · SI0130 · updated 2026-11-23

01

A signature covers bytes, not intent

An ed25519 signature is computed over bytes and nothing more. It has no field that says whether those bytes were a login sentence or the message of a Solana transaction. A wallet's signature over a transaction message is the same 64 bytes whether the wallet was asked to sign a transaction or to sign a message. So a site that asks for a plain message signature and supplies encoded transaction bytes gets back something it can attach to a transaction and submit.

That is why the button label in a wallet cannot answer the question. Trust has to come from checking the bytes before the key is used. The inspector below does that check for an agent: the signing tool passes it the payload, and it either clears the payload as text or blocks it with a reason.

02

The readings it tries

The sender of a payload picks its encoding, so the inspector reads the payload several ways.

  • As given. The bytes are tried as a bare transaction message and as a whole wire transaction, signature slots first. A match has to end exactly on the last byte, so trailing junk breaks it.
  • As text. The bytes must be valid UTF-8 with no control characters beyond tab and line breaks. A sentence a person reads is text, and a binary blob is not.
  • As base64 text. Encoded transactions travel as base64 strings, and a string of letters in a prompt looks harmless. The text is decoded and both transaction readings are tried again.
  • As base58 text. The same step for base58, the other encoding Solana tools use.
  • As framed. Off-chain messages open with the byte 0xff and then solana offchain. A legacy message opens with its signature count and a v0 message opens with 0x80, so no transaction message opens with 0xff. The inspector notes whether the frame is present. The 0xff byte is not valid UTF-8, so a payload that arrives already framed blocks as binary: hand the inspector the text and let the wallet add the frame.

The exact-end rule matters. The kit transaction decoder keeps everything after the signature slots as message bytes and reads only their start, so stray bytes after a plausible opening would pass for a transaction. The inspector decodes those message bytes again with the message decoder and requires that it consumes all of them.

03

The inspector file

One file on @solana/kit and Node's own modules. Run it on Node 24, which strips the types. The file needs CARBIUM_KEY and stops with a message without it. CARBIUM_RPC_URL points it at another RPC URL, and otherwise it calls https://services.carbium.sh.

main.ts
// SI0130 · Sign-message payload inspector// https://carbium.sh/library/si/sign-message-payload-inspector// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Sign-message payload inspector. Run: CARBIUM_KEY=... node main.ts ["text to sign" | b64:<base64 bytes>]import {  address, compileTransaction, createDefaultRpcTransport, createSolanaRpcFromTransport, createTransactionMessage,  getBase58Encoder, getBase64Decoder, getBase64Encoder, getCompiledTransactionMessageDecoder,  getTransactionDecoder, pipe, setTransactionMessageFeePayer, setTransactionMessageLifetimeUsingBlockhash,} from "@solana/kit";const key = process.env.CARBIUM_KEY;if (!key) { console.error("Set CARBIUM_KEY to your Carbium API key."); process.exit(1); }const url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));const utf8 = new TextEncoder();// Off-chain message frame: 0xff then "solana offchain". No transaction message opens with 0xff.const FRAME = Uint8Array.from([0xff, ...utf8.encode("solana offchain")]);// The bytes as a whole message, or the message part of a wire transaction, ending exactly at the last byte.function messageOf(bytes: Uint8Array): Uint8Array | null {  const tries: Uint8Array[] = [bytes];  try { tries.push(new Uint8Array(getTransactionDecoder().read(bytes, 0)[0].messageBytes)); } catch {}  for (const t of tries) {    try { if (getCompiledTransactionMessageDecoder().read(t, 0)[1] === t.length) return t; } catch {}  }  return null;}async function inspect(label: string, bytes: Uint8Array) {  const found: string[] = [];  const views: [string, Uint8Array][] = [["the bytes", bytes]];  let text: string | null = null;  try { text = new TextDecoder("utf-8", { fatal: true }).decode(bytes); } catch { found.push("not valid UTF-8, so not readable text"); }  if (text !== null) {    if ([...text].some((c) => c.charCodeAt(0) < 32 && ![9, 10, 13].includes(c.charCodeAt(0)))) found.push("control characters in the text");    try { views.push(["the text read as base64", new Uint8Array(getBase64Encoder().encode(text.trim()))]); } catch {}    try { views.push(["the text read as base58", new Uint8Array(getBase58Encoder().encode(text.trim()))]); } catch {}  }  const hits: [string, Uint8Array][] = [];  for (const [name, view] of views) { const m = messageOf(view); if (m) hits.push([name, m]); }  const fees = await Promise.allSettled(hits.map(([, m]) => rpc.getFeeForMessage(getBase64Decoder().decode(m) as any).send()));  hits.forEach(([name], i) => {    const fee = fees[i];    found.push(`${name} decode as a transaction message`);    if (fee.status === "rejected") found.push(`fee read failed: ${fee.reason}`);    else if (fee.value.value !== null) found.push("its blockhash is live, so signing would authorize a transaction that can land");  });  console.log(`${label}: ${found.length ? "BLOCK" : "SIGN-OK"}`);  for (const f of found) console.log(`  ${f}`);  console.log(`  note: ${FRAME.every((b, i) => bytes[i] === b) ? "framed as an off-chain message" : "no off-chain frame"}`);}const arg = process.argv[2];if (arg) {  try { await inspect("given payload", arg.startsWith("b64:") ? new Uint8Array(getBase64Encoder().encode(arg.slice(4))) : utf8.encode(arg)); }  catch (e) { console.log(`given payload: BLOCK\n  unreadable: ${(e as Error).message}`); }} else {  const { value } = await rpc.getLatestBlockhash().send();  const message = compileTransaction(pipe(    createTransactionMessage({ version: 0 }),    (m) => setTransactionMessageFeePayer(address("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"), m),    (m) => setTransactionMessageLifetimeUsingBlockhash(value, m),  )).messageBytes;  const sentence = utf8.encode("example.com wants you to sign in. Nonce 8f3a2c.");  await inspect("login text", sentence);  await inspect("framed text", Uint8Array.from([...FRAME, ...sentence]));  await inspect("base64 text", utf8.encode(getBase64Decoder().decode(message)));  await inspect("raw message", new Uint8Array(message));}

run: node main.ts

Pass a sentence to inspect it, or b64: followed by base64 to inspect raw bytes. With no argument the file fetches a recent blockhash, compiles an empty transaction message and inspects four payloads: a login sentence, the same sentence in the off-chain frame, the message's base64 pasted as text, and the message's raw bytes. The login sentence prints SIGN-OK. The other three print BLOCK: the framed copy because its 0xff byte is not valid UTF-8, and the two transaction payloads because they decode as a message whose blockhash is live. Compiling only produces bytes, and nothing is signed.

Output lineMeaning
<label>: SIGN-OKno reading decoded as a transaction and the text is clean
<label>: BLOCKone or more finding lines follow
not valid UTF-8, so not readable textthe payload is binary
control characters in the textthe text holds bytes below 32 other than tab and line breaks
<view> decode as a transaction messagethe bytes, or the text read as base64 or base58, form a message or wire transaction
its blockhash is live, so signing would authorize a transaction that can landthe node still knows the blockhash of the decoded message
note: framed as an off-chain messagethe payload opens with the off-chain frame, and the line reads no off-chain frame otherwise
04

The read from the chain

A decode shows the bytes could be a transaction, and one read shows whether it could land now. getFeeForMessage takes the message in base64 and answers null once the node no longer knows its blockhash. A fee that comes back means the blockhash is live, and the inspector adds a line saying so. With commitment left out, @solana/kit sends confirmed, where a bare JSON-RPC call would default to finalized.

The read only adds information. The decode already blocked the payload, so a rejected read, for example a 429 with a retry-after hint, adds a line and leaves the verdict where it was. Plain text triggers no read. The demo run makes one getLatestBlockhash call to build its sample message and one getFeeForMessage call for each payload that decodes.

05

Placing it before the signer

Put the inspector inside the tool that signs messages, so the model has no path around it. The tool receives the payload, decodes it once into a Uint8Array, inspects those bytes, and hands the same array to the signer on SIGN-OK. Inspecting a string and signing a re-encoded copy leaves a gap between the two.

Return the finding lines to the model on a BLOCK. A sentence that arrives as base64 is a bug in the caller, and the line the text read as base64 decode as a transaction message tells the agent what to fix. Give it no way to skip the check.

Transactions have their own path. The swap method returns an unsigned transaction that you sign and send through any RPC, and a tool built for sign-in text that receives one will block it here, as it should. Send a deliberate swap through a transaction check such as Pre-sign transaction guard, which reads the instructions this inspector never looks at.

06

Where it ends

  • It recognizes Solana message layouts. Bytes meant for another chain, or a custom program's own message format, are not tested.
  • Only base64 and base58 are tried. Hex, a double encoding or a compressed blob passes as text if it is valid UTF-8, so add a view for any encoding your callers use.
  • Text that reads cleanly can still be a bad request, such as a sentence that asks the user to approve something unrelated. The inspector reads format and has no view on meaning.
  • A missing live line proves little. A transaction that uses a durable nonce stays valid long after an ordinary blockhash expires, so a null fee does not make a decoded message harmless. The BLOCK stands either way.
  • A SIGN-OK holds for the bytes inspected. It says nothing about a key that signs a different array afterward.
07

When it goes wrong

what goes wrongwhat to do
Every sign-in sentence blocks with control characters in the text.The text carries a null terminator or another control byte, often from a C-style string. Strip it before signing. Tab, line feed and carriage return are allowed.
A payload meant as text blocks with not valid UTF-8.The caller sent another encoding such as UTF-16, cut a multi-byte character in half, or added the off-chain frame itself. Send UTF-8 bytes of the whole sentence and let the wallet add the frame.
A payload you know holds a transaction prints SIGN-OK.It sits in an encoding the file does not try, such as hex or a double base64. Add a view for that encoding next to the base64 and base58 ones.
The fee read fails with a 429 and the output shows fee read failed.The BLOCK from the decode stands, so nothing unsafe passes. Wait for the retry-after hint and inspect again if you need the live line.
401 from the RPC on the first call.The key is unknown at the door. Copy the whole key into CARBIUM_KEY, with nothing cut off.
08

Questions

Does the 0xff frame make signing safe on its own?

It does when the wallet adds the frame itself, because no transaction message opens with 0xff and a site then cannot get a usable transaction signature out of it. A wallet that signs the site's bytes as given gets no such protection, which is why the inspector also decodes.

Why not just check the first byte?

The first byte only separates framed from unframed payloads. Base64 text opens like any sentence, so a first-byte check misses the encoded transaction this inspector exists to catch.

Why read the text as base58 as well as base64?

Wallet adapters and RPC tools pass transactions around in both encodings, so a payload hiding in either one reaches the signer unless both are tried.

What does one inspection cost on the RPC?

Plain text makes no call. A payload that decodes costs one getFeeForMessage for each reading that decodes, which is one in the common case.