Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jest.config.integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
testEnvironment: "node",
testMatch: ["**/test/integration/**/*.test.ts"],
testPathIgnorePatterns: ["binaryen"],
modulePathIgnorePatterns: ["<rootDir>/dist/"],

// Set the timeout value for all tests to 2 minutes (default is 5 seconds)
testTimeout: 120000,
Expand Down
9 changes: 3 additions & 6 deletions src/2bytes/decodeRestrictedBase64ToBytes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,9 @@ const base64DecodeMapOffset = 0x2b;
const base64EOF = 0x3d;

export function decodeRestrictedBase64ToBytes(encoded: string) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let ch: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let code: any;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let code2: any;
let ch: number;
let code: number;
let code2: number;

const len = encoded.length;
const padding =
Expand Down
27 changes: 14 additions & 13 deletions src/c2wasm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ export async function buildCDir(
isXRPL: boolean
): Promise<void> {
// Reading all files in the directory tree
let fileObjects: any[];
let fileObjects: FileObject[];
try {
fileObjects = readFiles(dirPath);
} catch (error: any) {
} catch (error: unknown) {
console.error(`Error reading files: ${error}`);
process.exit(1);
}

let headerObjects: any[] = [];
let headerObjects: FileObject[] = [];
if (headersPath) {
try {
headerObjects = readFiles(headersPath).filter(
(file) => file.type === "h"
);
} catch (error: any) {
} catch (error: unknown) {
console.error(`Error reading header files: ${error}`);
process.exit(1);
}
Expand Down Expand Up @@ -77,16 +77,17 @@ export async function buildFile(
throw Error("Invalid file type. must be .c file");
}
const filename = filePath.split("/").pop();
const fileObject = {
if (!filename) throw Error("Invalid file name. must be a file name");
const fileObject: FileObject = {
type: "c",
name: filename,
src: fileContent,
};
let headerObjects: any[] = [];
let headerObjects: FileObject[] = [];
if (headerPath) {
try {
headerObjects = readFiles(headerPath).filter((file) => file.type === "h");
} catch (error: any) {
} catch (error: unknown) {
console.error(`Error reading header files: ${error}`);
process.exit(1);
}
Expand All @@ -105,8 +106,8 @@ export async function buildFile(
}

// Function to read all files in a directory tree
export function readFiles(dirPath: string): any[] {
const files: any[] = [];
export function readFiles(dirPath: string): FileObject[] {
const files: FileObject[] = [];
const fileNames = fs.readdirSync(dirPath);
for (const fileName of fileNames) {
const filePath = path.join(dirPath, fileName);
Expand Down Expand Up @@ -168,14 +169,14 @@ async function saveFileOrError(
const binary = await decodeBinary(result.output);
fs.writeFileSync(
path.join(outDir + "/" + filename + ".wasm"),
Buffer.from(binary)
Uint8Array.from(Buffer.from(binary))
);
}
}

export async function buildWasm(
fileObject: any,
headerObjects: any[],
fileObject: FileObject,
headerObjects: FileObject[],
outDir: string,
isXRPL: boolean
) {
Expand Down Expand Up @@ -221,7 +222,7 @@ export async function buildWasm(
} as BuildResult;
fs.mkdirSync(outDir, { recursive: true });
await saveFileOrError(outDir, filename, result);
} catch (error: any) {
} catch (error: unknown) {
throw Error(`Error sending API call: ${error}`);
}
}
4 changes: 2 additions & 2 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const compileJSCommand = async (inPath: string, outDir: string) => {
console.error("Output path must be a directory.");
process.exit(1);
}
} catch (error: any) {
} catch (error: unknown) {
mkdir(outDir, { recursive: true }, (err) => {
if (err) {
console.error(`Failed to create directory: ${outDir}`);
Expand Down Expand Up @@ -200,7 +200,7 @@ export const compileCCommand = async (
console.error("Output path must be a directory.");
process.exit(1);
}
} catch (error: any) {
} catch (error: unknown) {
mkdir(outDir, { recursive: true }, (err) => {
if (err) {
console.error(`Failed to create directory: ${outDir}`);
Expand Down
7 changes: 3 additions & 4 deletions src/debug/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import ReconnectingWebSocket from "reconnecting-websocket";
import WebSocket from "ws"; // Import the WebSocket implementation for Node.js
import WebSocket, { CloseEvent, MessageEvent } from "ws"; // Import the WebSocket implementation for Node.js

export interface ISelect<T = string> {
label: string;
Expand All @@ -19,15 +19,14 @@ const onError = () => {
console.error("Something went wrong! Check your connection and try again.");
};

const onClose = (e: any) => {
const onClose = (e: CloseEvent) => {
// 999 = closed websocket connection by switching account
if (e.code !== 4999) {
console.error(`Connection was closed. [code: ${e.code}]`);
}
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
const onMessage = (event: any) => {
const onMessage = (event: MessageEvent) => {
// Ping returns just account address, if we get that
// response we don't need to log anything
if (event.data !== selectedAccount?.value) {
Expand Down
32 changes: 14 additions & 18 deletions src/js2qjsc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,17 @@ interface BuildResult {
tasks: Task[];
}

function generateHash(dataBytes: Buffer) {
function generateHash(dataBytes: Uint8Array) {
const hash = createHash("sha512").update(dataBytes).digest();
return hash.slice(0, 32).toString("hex").toUpperCase();
return hash.subarray(0, 32).toString("hex").toUpperCase();
}

export async function buildDir(dirPath: string, outDir: string): Promise<void> {
// Reading all files in the directory tree
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let fileObjects: any[];
let fileObjects: FileObject[];
try {
fileObjects = readFiles(dirPath);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
} catch (error: unknown) {
console.error(`Error reading files: ${error}`);
process.exit(1);
}
Expand Down Expand Up @@ -73,8 +71,10 @@ export async function buildFile(
}
const filename = dirPath.split("/").pop();
const filetype = filename?.split(".").pop();
const fileObject = {
type: filetype,
if (!filetype) throw Error("Invalid file type. must be .js or .ts file");
if (!filename) throw Error("Invalid file name. must be a file name");
const fileObject: FileObject = {
type: filetype as "js" | "ts",
name: filename,
options: "-O3",
src: fileContent,
Expand All @@ -88,10 +88,8 @@ export async function buildFile(
}

// Function to read all files in a directory tree
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export function readFiles(dirPath: string): any[] {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const files: any[] = [];
export function readFiles(dirPath: string): FileObject[] {
const files: FileObject[] = [];
const fileNames = fs.readdirSync(dirPath);
for (const fileName of fileNames) {
const filePath = path.join(dirPath, fileName);
Expand Down Expand Up @@ -154,21 +152,20 @@ async function saveFileOrError(
}
console.log(
`Hook Hash: ${ConsoleColor.Green}%s${ConsoleColor.Reset}`,
`${generateHash(Buffer.from(binary))}`
`${generateHash(Uint8Array.from(Buffer.from(binary)))}`
);
console.log(
`Output: ${outDir}${filename}.bc ${ConsoleColor.Blue}%s${ConsoleColor.Reset}`,
`${binary.byteLength}b`
);
fs.writeFileSync(
path.join(outDir + "/" + filename + ".bc"),
Buffer.from(binary)
Uint8Array.from(Buffer.from(binary))
);
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export async function buildWasm(fileObject: any, outDir: string) {
export async function buildWasm(fileObject: FileObject, outDir: string) {
const filename = fileObject.name.split(".")[0];
// Sending API call to endpoint
const body = JSON.stringify({
Expand Down Expand Up @@ -209,8 +206,7 @@ export async function buildWasm(fileObject: any, outDir: string) {
} as BuildResult;
fs.mkdirSync(outDir, { recursive: true });
await saveFileOrError(outDir, filename, result);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
} catch (error: unknown) {
throw Error(`Error sending API call: ${error}`);
}
}
6 changes: 6 additions & 0 deletions src/type.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
interface FileObject {
type: "c" | "h" | "js" | "ts";
name: string;
options?: string;
src: string;
}
Loading
Loading