Create signing keys

Creates an RSA private key in PEM and JWK formats. Key files are only displayed once after creation. Keys are created, used, and deleted independently of videos, and every key can sign any video.

Script cloudflare Verified

by hugo697 ยท 11/16/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 383 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Create signing keys
8
 * Creates an RSA private key in PEM and JWK formats. Key files are only displayed once after creation. Keys are created, used, and deleted independently of videos, and every key can sign any video.
9
 */
10
export async function main(auth: Cloudflare, account_identifier: string) {
11
  const url = new URL(
12
    `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/stream/keys`
13
  );
14

15
  const response = await fetch(url, {
16
    method: "POST",
17
    headers: {
18
      "X-AUTH-EMAIL": auth.email,
19
      "X-AUTH-KEY": auth.key,
20
      "Content-Type": "application/json",
21
      Authorization: "Bearer " + auth.token,
22
    },
23
    body: undefined,
24
  });
25
  if (!response.ok) {
26
    const text = await response.text();
27
    throw new Error(`${response.status} ${text}`);
28
  }
29
  return await response.json();
30
}
31