MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / deriveCallbackToken

Function deriveCallbackToken

packages/worker-utils/src/callback-token.ts:42–65  ·  view source on GitHub ↗
(params: CallbackTokenParams)

Source from the content-addressed store, hash-verified

40}
41
42export async function deriveCallbackToken(params: CallbackTokenParams): Promise<string> {
43 const secret = params.secret;
44 if (!hasCallbackTokenSecret(secret)) {
45 throw new Error('Callback token secret must be configured and non-empty');
46 }
47
48 const encoder = new TextEncoder();
49 const key = await crypto.subtle.importKey(
50 'raw',
51 encoder.encode(secret),
52 { name: 'HMAC', hash: 'SHA-256' },
53 false,
54 ['sign']
55 );
56 const signature = await crypto.subtle.sign(
57 'HMAC',
58 key,
59 encoder.encode(
60 buildCallbackTokenMessage({ scope: params.scope, resourceParts: params.resourceParts })
61 )
62 );
63
64 return bytesToHex(new Uint8Array(signature));
65}
66
67export async function verifyCallbackToken(params: VerifyCallbackTokenParams): Promise<boolean> {
68 if (!params.token || !CALLBACK_TOKEN_HEX_PATTERN.test(params.token)) {

Callers 15

startSecurityAnalysisFunction · 0.90
route.test.tsFile · 0.90
callbackTokenFunction · 0.90
route.test.tsFile · 0.90
callbackTargetForAttemptFunction · 0.90
callbackTokenForFunction · 0.90
launchAttemptFunction · 0.90

Calls 4

hasCallbackTokenSecretFunction · 0.85
bytesToHexFunction · 0.85
signMethod · 0.80

Tested by 3

callbackTokenFunction · 0.72
callbackTokenForFunction · 0.72