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: 0 additions & 1 deletion demos/connect-demo/src/pages/Connect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const Connect: React.FC = () => {
navigate('/');
} catch (err) {
setError((err as Error).message);
// tslint:disable-next-line: no-console
console.error(err);
} finally {
setLoading(false);
Expand Down
1 change: 0 additions & 1 deletion demos/connect-demo/src/pages/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const Login: React.FC = () => {
navigate('/');
} catch (err) {
setError((err as Error).message);
// tslint:disable-next-line: no-console
console.error(err);
} finally {
setLoading(false);
Expand Down
27 changes: 27 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// @ts-check

import eslint from '@eslint/js';
import { defineConfig, globalIgnores } from 'eslint/config';
import tseslint from 'typescript-eslint';
import { includeIgnoreFile } from '@eslint/compat';
import { fileURLToPath, URL } from 'node:url';
import eslintConfigPrettier from 'eslint-config-prettier/flat';

const gitignorePath = fileURLToPath(new URL('.gitignore', import.meta.url));

export default defineConfig(
eslint.configs.recommended,
tseslint.configs.recommended,
eslintConfigPrettier,
includeIgnoreFile(gitignorePath),
globalIgnores(['dist/**/*'], 'Ignore Dist Directory'),
globalIgnores(['demos/**/*'], 'Ignore Demos Directory'),
globalIgnores(['lib/wasm_exec.js'], 'Ignore Wasm Exec File'),
globalIgnores(['webpack.config.js'], 'Ignore Webpack Config File'),
{
files: ['**/*.test.ts'],
rules: {
'@typescript-eslint/no-explicit-any': 'off'
}
}
);
6 changes: 3 additions & 3 deletions lib/api/createRpc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import LNC from '../lnc';
import { subscriptionMethods } from '@lightninglabs/lnc-core';
import LNC from '../lnc';

// capitalize the first letter in the string
const capitalize = (s: string) => s && s[0].toUpperCase() + s.slice(1);
Expand All @@ -11,7 +11,7 @@ const capitalize = (s: string) => s && s[0].toUpperCase() + s.slice(1);
export function createRpc<T extends object>(packageName: string, lnc: LNC): T {
const rpc = {};
return new Proxy(rpc, {
get(target, key, c) {
get(target, key) {
const methodName = capitalize(key.toString());
// the full name of the method (ex: lnrpc.Lightning.OpenChannel)
const method = `${packageName}.${methodName}`;
Expand All @@ -27,7 +27,7 @@ export function createRpc<T extends object>(packageName: string, lnc: LNC): T {
};
} else {
// call request for unary methods
return async (request: object): Promise<any> => {
return async (request: object): Promise<unknown> => {
return await lnc.request(method, request);
};
}
Expand Down
2 changes: 1 addition & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// tslint:disable-next-line
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('./wasm_exec');

import LNC from './lnc';
Expand Down
8 changes: 4 additions & 4 deletions lib/lnc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default class LNC {
instance: WebAssembly.Instance;
};

_wasmClientCode: any;
_wasmClientCode: string;
_namespace: string;
credentials: CredentialStore;

Expand Down Expand Up @@ -84,7 +84,7 @@ export default class LNC {
return lncGlobal[this._namespace] as WasmGlobal;
}

private set wasm(value: any) {
private set wasm(value: WasmGlobal) {
lncGlobal[this._namespace] = value;
}

Expand Down Expand Up @@ -153,7 +153,7 @@ export default class LNC {
// create the namespace object in the global scope if it doesn't exist
// so that we can assign the WASM callbacks to it
if (typeof this.wasm !== 'object') {
this.wasm = {};
this.wasm = {} as WasmGlobal;
}

// assign the WASM callbacks to the namespace object if they haven't
Expand Down Expand Up @@ -293,7 +293,7 @@ export default class LNC {
const res = snakeKeysToCamel(rawRes);
log.debug(`${method} response`, res);
resolve(res as TRes);
} catch (error) {
} catch {
log.debug(`${method} raw response`, response);
reject(new Error(response));
return;
Expand Down
6 changes: 3 additions & 3 deletions lib/types/lnc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export interface WasmGlobal {
*/
wasmClientInvokeRPC: (
rpcName: string,
request: any,
callback: (response: string) => any
request: string,
callback: (response: string) => void
) => void;
/**
* Returns true if client has specific permissions
Expand Down Expand Up @@ -79,7 +79,7 @@ export interface LncConfig {
* Custom location for the WASM client code. Can be remote or local. If not
* specified we’ll default to our instance on our CDN.
*/
wasmClientCode?: any; // URL or WASM client object
wasmClientCode?: string; // URL to WASM file
/**
* JavaScript namespace used for the main WASM calls. You can maintain multiple
* connections if you use different namespaces. If not specified we'll default
Expand Down
2 changes: 1 addition & 1 deletion lib/typings.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare var global: any;
declare const global: unknown;

interface GoInstance {
run(instance: WebAssembly.Instance): Promise<void>;
Expand Down
2 changes: 1 addition & 1 deletion lib/util/credentialStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ describe('LncCredentialStore', () => {
});

it('should call _load method during construction', () => {
const store = new LncCredentialStore();
new LncCredentialStore();

// Verify localStorage.getItem was called (from _load method)
expect(mockSetup.localStorage.getItem).toHaveBeenCalledWith(
Expand Down
18 changes: 10 additions & 8 deletions lib/util/encryption.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ describe('Encryption Utilities', () => {
const password = testData.password;
const salt = 'testsalt12345678901234567890123456789012';

const result = encrypt(data, password, salt);
const result = encrypt(JSON.stringify(data), password, salt);

expect(typeof result).toBe('string');
expect(result).toHaveLength(44); // AES encrypted strings are typically 44 chars
});

it('should produce different results for different data', () => {
Expand Down Expand Up @@ -99,10 +98,11 @@ describe('Encryption Utilities', () => {
const password = testData.password;
const salt = generateSalt();

const encrypted = encrypt(originalData, password, salt);
const actual = JSON.stringify(originalData);
const encrypted = encrypt(actual, password, salt);
const decrypted = decrypt(encrypted, password, salt);

expect(decrypted).toEqual(originalData);
expect(decrypted).toEqual(actual);
});

it('should throw error for invalid encrypted data', () => {
Expand Down Expand Up @@ -214,10 +214,11 @@ describe('Encryption Utilities', () => {
const password = testData.password;
const salt = generateSalt();

const encrypted = encrypt(complexData, password, salt);
const actual = JSON.stringify(complexData);
const encrypted = encrypt(actual, password, salt);
const decrypted = decrypt(encrypted, password, salt);

expect(decrypted).toEqual(complexData);
expect(decrypted).toEqual(actual);
});

it('should maintain data integrity through encrypt/decrypt cycle', () => {
Expand All @@ -238,10 +239,11 @@ describe('Encryption Utilities', () => {
const salt = generateSalt();

testCases.forEach((data) => {
const encrypted = encrypt(data, password, salt);
const actual = typeof data === 'string' ? data : JSON.stringify(data);
const encrypted = encrypt(actual, password, salt);
const decrypted = decrypt(encrypted, password, salt);

expect(decrypted).toEqual(data);
expect(decrypted).toEqual(actual);
});
});
});
Expand Down
18 changes: 12 additions & 6 deletions lib/util/encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@ const TEST_DATA = 'Irrelevant data for password verification';
export const generateSalt = () => {
const validChars =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let array = new Uint8Array(32);
const array = new Uint8Array(32);
globalThis.crypto.getRandomValues(array);
array = array.map((x) => validChars.charCodeAt(x % validChars.length));
const salt = String.fromCharCode.apply(null, array as any);
const numbers = Array.from(array, (x) =>
validChars.charCodeAt(x % validChars.length)
);
const salt = String.fromCharCode(...numbers);
return salt;
};

export const encrypt = (data: any, password: string, salt: string) => {
export const encrypt = (data: string, password: string, salt: string) => {
return AES.encrypt(JSON.stringify(data), password + salt).toString();
};

export const decrypt = (data: any, password: string, salt: string): string => {
export const decrypt = (
data: string,
password: string,
salt: string
): string => {
const decrypted = AES.decrypt(data, password + salt);
return JSON.parse(decrypted.toString(enc.Utf8));
};
Expand All @@ -33,7 +39,7 @@ export const verifyTestCipher = (
try {
const decrypted = decrypt(testCipher, password, salt);
return decrypted === TEST_DATA;
} catch (error) {
} catch {
return false;
}
};
10 changes: 5 additions & 5 deletions lib/util/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,25 +47,25 @@ export class Logger {
/**
* log a debug message
*/
debug = (message: string, ...args: any[]) =>
debug = (message: string, ...args: unknown[]) =>
this._log(LogLevel.debug, message, args);

/**
* log an info message
*/
info = (message: string, ...args: any[]) =>
info = (message: string, ...args: unknown[]) =>
this._log(LogLevel.info, message, args);

/**
* log a warn message
*/
warn = (message: string, ...args: any[]) =>
warn = (message: string, ...args: unknown[]) =>
this._log(LogLevel.warn, message, args);

/**
* log an error message
*/
error = (message: string, ...args: any[]) =>
error = (message: string, ...args: unknown[]) =>
this._log(LogLevel.error, message, args);

/**
Expand All @@ -74,7 +74,7 @@ export class Logger {
* @param message the message to log
* @param args optional additional arguments to log
*/
private _log(level: LogLevel, message: string, args: any[]) {
private _log(level: LogLevel, message: string, args: unknown[]) {
// don't log if the level to output is greater than the level of this message
if (this._levelToOutput > level) return;

Expand Down
11 changes: 7 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"test:coverage": "vitest run --coverage",
"prettier": "prettier --check '**/*.ts*' '**/*.js*'",
"prettier-write": "prettier --check --write '**/*.ts*' '**/*.js*'",
"lint": "tslint -p tsconfig.json",
"lint": "eslint .",
"typecheck": "tsc --noEmit --project tsconfig.typecheck.json",
"prepare": "npm run build",
"prepublishOnly": "npm run lint",
Expand All @@ -38,19 +38,22 @@
},
"homepage": "https://github.com/lightninglabs/lnc-web#readme",
"devDependencies": {
"@eslint/compat": "^2.0.0",
"@eslint/js": "^9.39.1",
"@types/crypto-js": "4.1.1",
"@types/debug": "4.1.7",
"@types/node": "17.0.16",
"@vitest/coverage-v8": "3.2.4",
"@vitest/ui": "3.2.4",
"clean-webpack-plugin": "4.0.0",
"eslint": "^9.39.1",
"eslint-config-prettier": "^10.1.8",
"node-polyfill-webpack-plugin": "1.1.4",
"prettier": "2.6.0",
"ts-loader": "9.5.1",
"ts-node": "10.7.0",
"tslint": "6.1.3",
"tslint-config-prettier": "1.18.0",
"typescript": "5.9.3",
"typescript": "^5.9.3",
"typescript-eslint": "^8.47.0",
"vitest": "3.2.4",
"webpack": "5.94.0",
"webpack-cli": "5.1.4"
Expand Down
2 changes: 1 addition & 1 deletion test/utils/mock-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { globalAccess } from './test-helpers';
export interface MockSetup {
localStorage: MockLocalStorage;
wasmGlobal: WasmGlobal | null;
goInstance: any;
goInstance: ReturnType<typeof createGoInstanceMock>;
namespace: string;
cleanup: () => void;
}
Expand Down
20 changes: 0 additions & 20 deletions tslint.json

This file was deleted.

Loading