Sign and Verify a Webhook Payload in Larzscript
Sign an outgoing webhook payload with HMAC-SHA256, and verify an incoming one - the same shape real payment/webhook providers use.
webhook.sign()/verify() are a thin, readable wrapper over crypto's real SHA-256/HMAC-SHA256 implementation.
larzscript pkg install webhook
larzscript pkg install crypto
Code
import "webhook" as webhook
let body = "{\"event\": \"payment.succeeded\", \"amount\": 4200}"
let secret = "whsec_test_123"
let sig = webhook.sign(body, secret)
print(sig)
print(webhook.verify(body, sig, secret))
print(webhook.verify(body, sig, "wrong_secret"))Output
7a6719ca208b5b2a166808b35ff5a8488e3fcc5fc69060c2b190dd179517d547 true false
Related
larzwebhookSign/verify webhook payloads (HMAC-SHA256)→larzcryptReal SHA-256 + HMAC-SHA256, pure Larzscript→Make an HTTP GET Request in LarzscriptFetch a URL and read its status code and body - or parse a JSON API response directly.→Hash Data with SHA-256 in LarzscriptCompute a real SHA-256 hash and an HMAC-SHA256 message authentication code.→