Skip to content

Instantly share code, notes, and snippets.

@darg-2036
Last active June 3, 2026 23:50
Show Gist options
  • Select an option

  • Save darg-2036/2ae1a7c5bf715bd58aae7c1887a4381a to your computer and use it in GitHub Desktop.

Select an option

Save darg-2036/2ae1a7c5bf715bd58aae7c1887a4381a to your computer and use it in GitHub Desktop.
Implementation of ERC-6492 signature verification for acp.us using Viem
import { createPublicClient, http } from "viem";
import { base, polygon } from "viem/chains";
// Signature should be on its own on the last line
const rawMessage = "…";
const messageSignerAddress = "0x…";
// Get message and signature separately
const [message, encodedSignature] = rawMessage.trimEnd().split(/\n+(.+)$/);
// Decode Base64
const normalized = encodedSignature.replace(/-/g, "+").replace(/_/g, "/");
const response = await fetch(`data:application/octet-stream;base64,${normalized}`);
// Decompress
const decompressed = response.body?.pipeThrough(new DecompressionStream("deflate-raw"));
// Convert to byte array
const signature = new Uint8Array(await new Response(decompressed).arrayBuffer());
let isSignatureValid = false;
for (const chain of [base, polygon]) {
const client = createPublicClient({ chain, transport: http() });
try {
isSignatureValid = await client.verifyMessage({
address: messageSignerAddress,
message,
signature,
});
if (isSignatureValid) break;
} catch {}
}
console.log("Signature valid:", isSignatureValid);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment