MCPcopy Create free account
hub / github.com/middleapi/orpc / verifyDurableIteratorToken

Function verifyDurableIteratorToken

packages/durable-iterator/src/schemas.ts:27–45  ·  view source on GitHub ↗
(secret: string, token: string)

Source from the content-addressed store, hash-verified

25 * Verifies a token and returns the payload if valid.
26 */
27export async function verifyDurableIteratorToken(secret: string, token: string): Promise<DurableIteratorTokenPayload | undefined> {
28 try {
29 const payload = parseEmptyableJSON(await unsign(token, secret))
30
31 if (!v.is(DurableIteratorTokenPayloadSchema, payload)) {
32 return undefined
33 }
34
35 if (payload.exp < (Date.now() / 1000)) {
36 return undefined
37 }
38
39 return payload
40 }
41 catch {
42 // parseEmptyableJSON can throw error if the token contains invalid json
43 return undefined
44 }
45}
46
47/**
48 * Extracts the payload from a token without verifying its signature.

Callers 5

schemas.test.tsFile · 0.90
iterator.test.tsFile · 0.90
handler.tsFile · 0.90
fetchMethod · 0.90

Calls 2

parseEmptyableJSONFunction · 0.90
unsignFunction · 0.90

Tested by

no test coverage detected