Embedded Sections
Signature Verification
Verify embedded section authenticity using HMAC-SHA512
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Verify embedded section authenticity using HMAC-SHA512
| Parameter | Description |
|---|---|
hmac | The HMAC signature |
timestamp | The timestamp of when the signature was generated |
shop_id | Your shop ID |
supporter_id | Supporter ID of the logged-in member |
tier_id | Tier ID of the supporter’s subscription |
shop_id=${shop_id}&supporter_id=${supporter_id}&tier_id=${tier_id}×tamp=${timestamp}
async function getHmacKey(secret) {
const encoder = new TextEncoder();
const keyData = encoder.encode(secret);
return await crypto.subtle.importKey(
'raw',
keyData,
{ name: 'HMAC', hash: 'SHA-512' },
false,
['sign', 'verify']
);
}
async function verifySignature(params, hmacSignature, secret) {
const { shopId, supporterId, tierId, timestamp } = params;
const encoder = new TextEncoder();
const key = await getHmacKey(secret);
const data = `shop_id=${shopId}&supporter_id=${supporterId}&tier_id=${tierId}×tamp=${timestamp}`;
const messageData = encoder.encode(data);
const signature = await crypto.subtle.sign('HMAC', key, messageData);
const generatedSignatureHex = uint8ArrayToHex(new Uint8Array(signature));
return generatedSignatureHex === hmacSignature;
}