Skip to content

Commit

Permalink
chore: added typings for sec ya headers
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyhalight committed Feb 8, 2025
1 parent 079b9eb commit 9a34e2c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/shared/src/data/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ export default {
defaultDuration: 343,
minChunkSize: 5295308,
loggerLevel: 1,
version: "2.2.2",
version: "2.2.3",
} as ConfigSchema;
12 changes: 6 additions & 6 deletions packages/shared/src/secure.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import config from "./data/config";
import Logger from "./utils/logger";
import { SecType, ClientSession, HashName } from "./types/secure";
import { SecType, ClientSession, HashName, SecYaHeaders } from "./types/secure";

const { componentVersion } = config;

Expand Down Expand Up @@ -38,12 +38,12 @@ export async function getSignature(body: Uint8Array) {
);
}

export async function getSecYaHeaders(
secType: SecType,
export async function getSecYaHeaders<T extends SecType>(
secType: T,
session: ClientSession,
body: Uint8Array,
path: string,
) {
): Promise<SecYaHeaders<T>> {
const { secretKey, uuid } = session;
const sign = await getSignature(body);

Expand All @@ -56,7 +56,7 @@ export async function getSecYaHeaders(
[`${secType}-Signature`]: sign,
[`Sec-${secType}-Sk`]: secretKey,
[`Sec-${secType}-Token`]: `${tokenSign}:${token}`,
};
} as SecYaHeaders<T>;
}

// yandex uuid
Expand Down Expand Up @@ -87,4 +87,4 @@ export const browserSecHeaders = {
"sec-ch-ua": `"Chromium";v="130", "YaBrowser";v="${componentVersion.slice(0, 5)}", "Not?A_Brand";v="99", "Yowser";v="2.5"`,
"sec-ch-ua-full-version-list": `"Chromium";v="130.0.6723.152", "YaBrowser";v="${componentVersion}", "Not?A_Brand";v="99.0.0.0", "Yowser";v="2.5"`,
"Sec-Fetch-Mode": "no-cors",
};
} as const;
6 changes: 6 additions & 0 deletions packages/shared/src/types/secure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ export type ClientSession = {
uuid: string;
secretKey: string;
};

export type SecYaHeader<T extends SecType> =
| `${T}-Signature`
| `Sec-${T}-Sk`
| `Sec-${T}-Token`;
export type SecYaHeaders<T extends SecType> = Record<SecYaHeader<T>, string>;

0 comments on commit 9a34e2c

Please sign in to comment.