Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Commit

Permalink
Better docker image and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pablouser1 committed Jan 25, 2024
1 parent b7c4697 commit 895e33d
Show file tree
Hide file tree
Showing 4 changed files with 206 additions and 270 deletions.
19 changes: 15 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
FROM node:18-alpine
FROM node:20-alpine
WORKDIR /usr/src/app

# Setup Alpine for building "canvas" package
RUN apk add --no-cache python3 make g++ pkgconfig cairo-dev pango-dev
# Setup Alpine for canvas
RUN apk add --no-cache \
# Build only
python3 g++ make cairo-dev pango-dev \
# Runtime
cairo pango

# Install deps
COPY package.json yarn.lock ./
RUN yarn install
COPY . .

# Copy required files for server
COPY ./src ./src
COPY ./api ./api
COPY ./js ./js

RUN apk del python3 g++ make cairo-dev pango-dev

EXPOSE 8080
CMD [ "node", "api/index.js" ]
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "signtok",
"version": "1.3.0",
"version": "1.3.1",
"description": "Sign your TikTok requests easily",
"repository": "https://github.com/pablouser1/SignTok",
"author": "Pablo Ferreiro",
"main": "src/Signer.js",
"main": "api/index.js",
"license": "MIT",
"keywords": [
"tiktok",
Expand All @@ -16,7 +16,7 @@
"vercel-build": "yum -y install libuuid-devel libmount-devel && cp /lib64/{libuuid,libmount,libblkid}.so.1 node_modules/canvas/build/Release/"
},
"dependencies": {
"jsdom": "^20.0.2",
"canvas": "^2.10.2"
"canvas": "^2.11.2",
"jsdom": "^24.0.0"
}
}
31 changes: 31 additions & 0 deletions src/Signer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,18 @@ const fs = require("fs");
const { JSDOM, ResourceLoader } = require("jsdom");
const { createCipheriv } = require("crypto");

/**
* Main Signer class
*/
class Signer {
/** Default user-agent used to signed the requests */
static DEFAULT_USERAGENT =
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.35";
/** Password for x-tt-params AES enc/dec */
static PASSWORD = "webapp1.0+202106";

/**
* JSDOM main window
* @type Window
*/
window = null;
Expand Down Expand Up @@ -34,6 +41,10 @@ class Signer {
this.window.eval(webmssdk);
}

/**
* Get current virtual browser navigator
* @returns Navigator compatible with tiktok-signature
*/
navigator() {
return {
deviceScaleFactor: this.window.devicePixelRatio,
Expand All @@ -45,14 +56,29 @@ class Signer {
};
}

/**
* Get _signature GET query
* @param {string} url Unencrypted url
* @returns {string} _signature as string
*/
signature(url) {
return this.window.byted_acrawler.sign({ url });
}

/**
* Get X-Bogus header
* @param {string} params Unencrypted GET query
* @returns {string} X-Bogus string
*/
bogus(params) {
return this.window._0x32d649(params);
}

/**
* Get x-tt-params header from GET query
* @param {string} params Unencrypted GET query
* @returns {string} Encrypted x-tt-params
*/
xttparams(params) {
params += "&verifyFp=undefined";
params += "&is_encryption=1";
Expand All @@ -61,6 +87,11 @@ class Signer {
return Buffer.concat([cipher.update(params), cipher.final()]).toString("base64");
}

/**
* Sign a TikTok URL
* @param {string} url_str Unsigned URL
* @returns Object with signed data
*/
sign(url_str) {
const url = new URL(url_str);
const signature = this.signature(url.toString());
Expand Down
Loading

0 comments on commit 895e33d

Please sign in to comment.