Skip to content

Commit f90c7d3

Browse files
committed
chore: fix linter errors after new eslint config
1 parent 36b8c22 commit f90c7d3

File tree

10 files changed

+41
-33
lines changed

10 files changed

+41
-33
lines changed

lib/api/createRpc.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import LNC from '../lnc';
21
import { subscriptionMethods } from '@lightninglabs/lnc-core';
2+
import LNC from '../lnc';
33

44
// capitalize the first letter in the string
55
const capitalize = (s: string) => s && s[0].toUpperCase() + s.slice(1);
@@ -11,7 +11,7 @@ const capitalize = (s: string) => s && s[0].toUpperCase() + s.slice(1);
1111
export function createRpc<T extends object>(packageName: string, lnc: LNC): T {
1212
const rpc = {};
1313
return new Proxy(rpc, {
14-
get(target, key, c) {
14+
get(target, key) {
1515
const methodName = capitalize(key.toString());
1616
// the full name of the method (ex: lnrpc.Lightning.OpenChannel)
1717
const method = `${packageName}.${methodName}`;
@@ -27,7 +27,7 @@ export function createRpc<T extends object>(packageName: string, lnc: LNC): T {
2727
};
2828
} else {
2929
// call request for unary methods
30-
return async (request: object): Promise<any> => {
30+
return async (request: object): Promise<unknown> => {
3131
return await lnc.request(method, request);
3232
};
3333
}

lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// tslint:disable-next-line
1+
// eslint-disable-next-line @typescript-eslint/no-require-imports
22
require('./wasm_exec');
33

44
import LNC from './lnc';

lib/lnc.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default class LNC {
3737
instance: WebAssembly.Instance;
3838
};
3939

40-
_wasmClientCode: any;
40+
_wasmClientCode: string;
4141
_namespace: string;
4242
credentials: CredentialStore;
4343

@@ -84,7 +84,7 @@ export default class LNC {
8484
return lncGlobal[this._namespace] as WasmGlobal;
8585
}
8686

87-
private set wasm(value: any) {
87+
private set wasm(value: WasmGlobal) {
8888
lncGlobal[this._namespace] = value;
8989
}
9090

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

159159
// assign the WASM callbacks to the namespace object if they haven't
@@ -293,7 +293,7 @@ export default class LNC {
293293
const res = snakeKeysToCamel(rawRes);
294294
log.debug(`${method} response`, res);
295295
resolve(res as TRes);
296-
} catch (error) {
296+
} catch {
297297
log.debug(`${method} raw response`, response);
298298
reject(new Error(response));
299299
return;

lib/types/lnc.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export interface WasmGlobal {
2828
*/
2929
wasmClientInvokeRPC: (
3030
rpcName: string,
31-
request: any,
32-
callback: (response: string) => any
31+
request: string,
32+
callback: (response: string) => void
3333
) => void;
3434
/**
3535
* Returns true if client has specific permissions
@@ -79,7 +79,7 @@ export interface LncConfig {
7979
* Custom location for the WASM client code. Can be remote or local. If not
8080
* specified we’ll default to our instance on our CDN.
8181
*/
82-
wasmClientCode?: any; // URL or WASM client object
82+
wasmClientCode?: string; // URL to WASM file
8383
/**
8484
* JavaScript namespace used for the main WASM calls. You can maintain multiple
8585
* connections if you use different namespaces. If not specified we'll default

lib/typings.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
declare var global: any;
1+
declare const global: unknown;
22

33
interface GoInstance {
44
run(instance: WebAssembly.Instance): Promise<void>;

lib/util/credentialStore.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ describe('LncCredentialStore', () => {
131131
});
132132

133133
it('should call _load method during construction', () => {
134-
const store = new LncCredentialStore();
134+
new LncCredentialStore();
135135

136136
// Verify localStorage.getItem was called (from _load method)
137137
expect(mockSetup.localStorage.getItem).toHaveBeenCalledWith(

lib/util/encryption.test.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,9 @@ describe('Encryption Utilities', () => {
5555
const password = testData.password;
5656
const salt = 'testsalt12345678901234567890123456789012';
5757

58-
const result = encrypt(data, password, salt);
58+
const result = encrypt(JSON.stringify(data), password, salt);
5959

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

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

102-
const encrypted = encrypt(originalData, password, salt);
101+
const actual = JSON.stringify(originalData);
102+
const encrypted = encrypt(actual, password, salt);
103103
const decrypted = decrypt(encrypted, password, salt);
104104

105-
expect(decrypted).toEqual(originalData);
105+
expect(decrypted).toEqual(actual);
106106
});
107107

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

217-
const encrypted = encrypt(complexData, password, salt);
217+
const actual = JSON.stringify(complexData);
218+
const encrypted = encrypt(actual, password, salt);
218219
const decrypted = decrypt(encrypted, password, salt);
219220

220-
expect(decrypted).toEqual(complexData);
221+
expect(decrypted).toEqual(actual);
221222
});
222223

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

240241
testCases.forEach((data) => {
241-
const encrypted = encrypt(data, password, salt);
242+
const actual = typeof data === 'string' ? data : JSON.stringify(data);
243+
const encrypted = encrypt(actual, password, salt);
242244
const decrypted = decrypt(encrypted, password, salt);
243245

244-
expect(decrypted).toEqual(data);
246+
expect(decrypted).toEqual(actual);
245247
});
246248
});
247249
});

lib/util/encryption.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,24 @@ const TEST_DATA = 'Irrelevant data for password verification';
55
export const generateSalt = () => {
66
const validChars =
77
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
8-
let array = new Uint8Array(32);
8+
const array = new Uint8Array(32);
99
globalThis.crypto.getRandomValues(array);
10-
array = array.map((x) => validChars.charCodeAt(x % validChars.length));
11-
const salt = String.fromCharCode.apply(null, array as any);
10+
const numbers = Array.from(array, (x) =>
11+
validChars.charCodeAt(x % validChars.length)
12+
);
13+
const salt = String.fromCharCode(...numbers);
1214
return salt;
1315
};
1416

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

19-
export const decrypt = (data: any, password: string, salt: string): string => {
21+
export const decrypt = (
22+
data: string,
23+
password: string,
24+
salt: string
25+
): string => {
2026
const decrypted = AES.decrypt(data, password + salt);
2127
return JSON.parse(decrypted.toString(enc.Utf8));
2228
};
@@ -33,7 +39,7 @@ export const verifyTestCipher = (
3339
try {
3440
const decrypted = decrypt(testCipher, password, salt);
3541
return decrypted === TEST_DATA;
36-
} catch (error) {
42+
} catch {
3743
return false;
3844
}
3945
};

lib/util/log.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,25 @@ export class Logger {
4747
/**
4848
* log a debug message
4949
*/
50-
debug = (message: string, ...args: any[]) =>
50+
debug = (message: string, ...args: unknown[]) =>
5151
this._log(LogLevel.debug, message, args);
5252

5353
/**
5454
* log an info message
5555
*/
56-
info = (message: string, ...args: any[]) =>
56+
info = (message: string, ...args: unknown[]) =>
5757
this._log(LogLevel.info, message, args);
5858

5959
/**
6060
* log a warn message
6161
*/
62-
warn = (message: string, ...args: any[]) =>
62+
warn = (message: string, ...args: unknown[]) =>
6363
this._log(LogLevel.warn, message, args);
6464

6565
/**
6666
* log an error message
6767
*/
68-
error = (message: string, ...args: any[]) =>
68+
error = (message: string, ...args: unknown[]) =>
6969
this._log(LogLevel.error, message, args);
7070

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

test/utils/mock-factory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { globalAccess } from './test-helpers';
1313
export interface MockSetup {
1414
localStorage: MockLocalStorage;
1515
wasmGlobal: WasmGlobal | null;
16-
goInstance: any;
16+
goInstance: ReturnType<typeof createGoInstanceMock>;
1717
namespace: string;
1818
cleanup: () => void;
1919
}

0 commit comments

Comments
 (0)