Copyable Example Code
You can paste this into the code editor; still verify target image, region, color, text, and timing values in your own device flow.
-- Webhook signature verification
-- Sender: signs with HMAC-SHA256
-- Receiver: same secret + constant-time comparison
local sharedSecret = "example-shared-secret"
local payload = '{"event":"macro.completed","macroId":"abc123"}'
-- Create the signature (sender)
local signature = Crypto.hmacSha256(sharedSecret, payload)
toast("Signature: " .. signature:sub(1, 16) .. "...")
-- The signature that arrived (simulated)
local receivedSignature = signature
-- Constant-time comparison resists timing attacks
if Crypto.constantTimeEquals(signature, receivedSignature) then
toast("Signature valid, payload trusted")
else
toast("Signature MISMATCH, payload rejected")
end
-- Nonce: prevents replaying an old message
local nonce = Crypto.randomBytes(16)
local stampedPayload = payload .. "|" .. nonce
local stampedSignature = Crypto.hmacSha256(sharedSecret, stampedPayload)
KV.set("last_nonce", nonce)