(method, url, secret, cv = "")
| 164 | } |
| 165 | |
| 166 | function makePopToken(method, url, secret, cv = "") { |
| 167 | if (!secret) return ""; |
| 168 | const header = base64url(JSON.stringify({ alg: "HS256", typ: "JWT" })); |
| 169 | const body = { |
| 170 | htm: String(method || "GET").toUpperCase(), |
| 171 | htu: new URL(url).pathname, |
| 172 | iat: Math.floor(Date.now() / 1000), |
| 173 | }; |
| 174 | if (cv) body.cv = cv; |
| 175 | const payload = base64url(JSON.stringify(body)); |
| 176 | const sig = crypto.createHmac("sha256", Buffer.from(secret)).update(`${header}.${payload}`).digest("base64url"); |
| 177 | return `${header}.${payload}.${sig}`; |
| 178 | } |
| 179 | |
| 180 | function genEcKeyPair() { |
| 181 | return crypto.generateKeyPairSync("ec", { namedCurve: "prime256v1" }); |
no test coverage detected