Skip to content

Commit 0765f89

Browse files
committed
feat(lib): add connect function to use remote azot API instance
1 parent 74c7953 commit 0765f89

File tree

4 files changed

+84
-2
lines changed

4 files changed

+84
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "azot",
3-
"version": "0.7.2",
3+
"version": "0.8.0",
44
"description": "Swiss Army knife for pentesting DRMs",
55
"type": "module",
66
"files": [

src/lib/connect.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
type ConnectParams = {
2+
baseUrl: string;
3+
secret: string;
4+
};
5+
6+
export const connect = ({ baseUrl, secret }: ConnectParams) => {
7+
const headers = {
8+
'x-secret-key': secret,
9+
'content-type': 'application/json',
10+
};
11+
12+
const json = (data: any) => JSON.stringify(data);
13+
14+
const post = async (route: string, body: object) => {
15+
const response = await fetch(`${baseUrl}${route}`, {
16+
method: 'POST',
17+
headers,
18+
body: json(body),
19+
});
20+
const contentLength = response.headers.get('content-length');
21+
if (contentLength === '0') return;
22+
return response.json();
23+
};
24+
25+
const get = async (route: string) => {
26+
const response = await fetch(`${baseUrl}${route}`, {
27+
method: 'GET',
28+
headers,
29+
});
30+
return response.json();
31+
};
32+
33+
const createSession = async (client: string) => {
34+
const data = await post(`/session`, { client });
35+
const sessionId = data.id;
36+
37+
const generateRequest = async (initData: string, initDataType: string) => {
38+
const data = await post(`/session/${sessionId}/generate-request`, {
39+
initDataType,
40+
initData,
41+
});
42+
return data.licenseRequest;
43+
};
44+
45+
const update = async (response: string) =>
46+
post(`/session/${sessionId}/update`, { response });
47+
48+
const keys = async () => get(`/session/${sessionId}/keys`);
49+
50+
return { sessionId, generateRequest, update, keys };
51+
};
52+
53+
return { createSession };
54+
};

src/lib/main.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ const fetchDecryptionKeys = async (params: FetchDecryptionKeysParams) => {
3232
'message',
3333
async (event: Event) => {
3434
const type = (event as MediaKeyMessageEvent).messageType;
35-
const message = (event as MediaKeyMessageEvent).message as Uint8Array;
35+
const message = (event as MediaKeyMessageEvent)
36+
.message as unknown as Uint8Array;
3637
const isIndividualization = type === 'individualization-request';
3738
const url = isIndividualization
3839
? params.individualizationServer || params.server
@@ -67,6 +68,7 @@ const fetchDecryptionKeys = async (params: FetchDecryptionKeysParams) => {
6768

6869
export { fetchDecryptionKeys };
6970
export { Session };
71+
export * from './connect';
7072
export * from './utils';
7173
export * from './client';
7274
export * from './key';

test/connect.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { expect, test } from 'vitest';
2+
import { connect } from '../src/lib';
3+
4+
test('connection to Azot API instance and generating license request', async () => {
5+
const baseUrl = 'https://azot.pw'; // Set your API base URL here
6+
const secret = 'db44ec40-3e02-47bd-8fc6-373935e30eae'; // Set your API secret here
7+
const client = 'pixel6'; // Set client name related with your API key
8+
if (secret === 'db44ec40-3e02-47bd-8fc6-373935e30eae')
9+
return console.warn('Add your API endpoint & secret to test connection');
10+
const { createSession } = connect({ baseUrl, secret });
11+
const session = await createSession(client);
12+
const licenseRequest = await session.generateRequest(
13+
'AAAAW3Bzc2gAAAAA7e+LqXnWSs6jyCfc1R0h7QAAADsIARIQ62dqu8s0Xpa7z2FmMPGj2hoNd2lkZXZpbmVfdGVzdCIQZmtqM2xqYVNkZmFsa3IzaioCSEQyAA==',
14+
'cenc',
15+
);
16+
const licenseUrl = 'https://cwip-shaka-proxy.appspot.com/no_auth';
17+
const license = await fetch(licenseUrl, {
18+
body: Buffer.from(licenseRequest, 'base64'),
19+
method: 'POST',
20+
})
21+
.then((response) => response.arrayBuffer())
22+
.then((buffer) => Buffer.from(buffer));
23+
await session.update(license.toString('base64'));
24+
const keys = await session.keys();
25+
expect(keys.length).toBe(5);
26+
});

0 commit comments

Comments
 (0)