MCPcopy Create free account
hub / github.com/adcontextprotocol/adcp / verifySlackSignature

Function verifySlackSignature

server/tests/unit/slack-integration.test.ts:15–46  ·  view source on GitHub ↗
(
  signingSecret: string,
  requestSignature: string,
  requestTimestamp: string,
  body: string
)

Source from the content-addressed store, hash-verified

13
14// Mock the verification function for testing
15function verifySlackSignature(
16 signingSecret: string,
17 requestSignature: string,
18 requestTimestamp: string,
19 body: string
20): boolean {
21 // Check timestamp is recent (within 5 minutes)
22 const timestamp = parseInt(requestTimestamp, 10);
23 const now = Math.floor(Date.now() / 1000);
24 if (Math.abs(now - timestamp) > 60 * 5) {
25 return false;
26 }
27
28 // Create signature base string
29 const sigBasestring = `v0:${requestTimestamp}:${body}`;
30
31 // Create HMAC signature
32 const mySignature = 'v0=' + crypto
33 .createHmac('sha256', signingSecret)
34 .update(sigBasestring)
35 .digest('hex');
36
37 // Compare signatures using timing-safe comparison
38 try {
39 return crypto.timingSafeEqual(
40 Buffer.from(mySignature, 'utf8'),
41 Buffer.from(requestSignature, 'utf8')
42 );
43 } catch {
44 return false;
45 }
46}
47
48describe("Slack Signature Verification", () => {
49 const testSecret = "test_signing_secret_abc123";

Callers 1

Calls 2

nowMethod · 0.80
updateMethod · 0.80

Tested by

no test coverage detected