Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add linting to CI #197

Merged
merged 3 commits into from
Apr 10, 2024
Merged
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ jobs:
npm run build
- name: Run tests
run: ETHERSJS_VERSION=${{ matrix.ethers }} npm run test
- name: Run lints
run: npm run lint
14,890 changes: 10,535 additions & 4,355 deletions package-lock.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"scripts": {
"build": "lerna run build",
"test": "lerna run --stream test",
"lint": "lerna run lint",
"docs": "typedoc --plugin nlfurniss-typedoc-plugin-sourcefile-url --plugin typedoc-plugin-extras --sourcefile-url-prefix 'https://github.com/spruceid/siwe' --favicon ./favicon.svg --out docs packages/siwe/lib/siwe.ts"
},
"author": "Spruce Systems Inc.",
Expand All @@ -20,7 +21,7 @@
"lerna": "^6.5.1",
"nlfurniss-typedoc-plugin-sourcefile-url": "^2.0.0",
"ts-jest": "^29.0.5",
"typedoc": "^0.23.12",
"typedoc": "^0.24.8",
"typedoc-plugin-extras": "^2.2.1",
"typescript": "^4.4.4"
}
Expand Down
3 changes: 3 additions & 0 deletions packages/siwe-parser/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
node_modules
jest.config.js
11 changes: 11 additions & 0 deletions packages/siwe-parser/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"prettier"
]
}
5 changes: 3 additions & 2 deletions packages/siwe-parser/lib/parsers.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ParsedMessage } from "./abnf";
import * as fs from "fs";

const parsingPositive: Object = require("../../../test/parsing_positive.json");
const parsingNegative: Object = require("../../../test/parsing_negative.json");
const parsingPositive: object = JSON.parse(fs.readFileSync('../../test/parsing_positive.json', 'utf8'));
const parsingNegative: object = JSON.parse(fs.readFileSync('../../test/parsing_negative.json', 'utf8'));

//
describe("Successfully parses with ABNF Client", () => {
Expand Down
14 changes: 7 additions & 7 deletions packages/siwe-parser/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import { bytesToHex } from '@noble/hashes/utils';
* @returns Either the return is or not in the EIP-55 format.
*/
export const isEIP55Address = (address: string) => {
if(address.length != 42) {
if (address.length != 42) {
return false;
}

const lowerAddress = `${address}`.toLowerCase().replace('0x', '');
var hash = bytesToHex(keccak_256(lowerAddress));
var ret = '0x';
const hash = bytesToHex(keccak_256(lowerAddress));
let ret = '0x';

for (var i = 0; i < lowerAddress.length; i++) {
for (let i = 0; i < lowerAddress.length; i++) {
if (parseInt(hash[i], 16) >= 8) {
ret += lowerAddress[i].toUpperCase();
} else {
Expand All @@ -26,7 +26,7 @@ export const isEIP55Address = (address: string) => {

export const parseIntegerNumber = (number: string): number => {
const parsed = parseInt(number);
if(parsed === NaN) throw new Error("Invalid number.");
if(parsed === Infinity) throw new Error("Invalid number.");
if (isNaN(parsed)) throw new Error("Invalid number.");
if (parsed === Infinity) throw new Error("Invalid number.");
return parsed;
}
}
11 changes: 10 additions & 1 deletion packages/siwe-parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
},
"scripts": {
"test": "jest",
"build": "tsc"
"build": "tsc",
"lint": "eslint --ext .js,.ts .",
"format": "prettier --ignore-path .gitignore --write \"**/*.+(js|ts|json)\""
},
"author": "Spruce Systems Inc.",
"keywords": [
Expand All @@ -27,6 +29,13 @@
"valid-url": "^1.0.9",
"@noble/hashes": "^1.1.2"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.23.0",
"@typescript-eslint/parser": "^5.23.0",
"eslint": "^8.15.0",
"eslint-config-prettier": "^8.5.0",
"prettier": "^2.6.2"
},
"repository": {
"type": "git",
"url": "git+https://github.com/spruceid/siwe.git"
Expand Down
4 changes: 3 additions & 1 deletion packages/siwe/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
dist
node_modules
node_modules
jest.config.js
jest.setup.js
17 changes: 9 additions & 8 deletions packages/siwe/lib/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
/* eslint @typescript-eslint/no-explicit-any: 0 */
const parsingPositive = require('../../../test/parsing_positive.json');
const parsingNegative = require('../../../test/parsing_negative.json');
const parsingNegativeObjects = require('../../../test/parsing_negative_objects.json');
const verificationPositive = require('../../../test/verification_positive.json');
const verificationNegative = require('../../../test/verification_negative.json');
const EIP1271 = require('../../../test/eip1271.json');
import * as fs from "fs";

const parsingPositive: object = JSON.parse(fs.readFileSync('../../test/parsing_positive.json', 'utf8'));
const parsingNegative: object = JSON.parse(fs.readFileSync('../../test/parsing_negative.json', 'utf8'));
const parsingNegativeObjects: object = JSON.parse(fs.readFileSync('../../test/parsing_negative_objects.json', 'utf8'));
const verificationPositive: object = JSON.parse(fs.readFileSync('../../test/verification_positive.json', 'utf8'));
const verificationNegative: object = JSON.parse(fs.readFileSync('../../test/verification_negative.json', 'utf8'));
const EIP1271: object = JSON.parse(fs.readFileSync('../../test/eip1271.json', 'utf8'));

import {
providers,
// @ts-expect-error -- ethers v6 compatibility hack
providers,
InfuraProvider,
Wallet,
} from 'ethers';
Expand Down
1 change: 1 addition & 0 deletions packages/siwe/lib/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
ParsedMessage,
parseIntegerNumber,
} from '@spruceid/siwe-parser';
// @ts-expect-error -- ethers v6 compatibility hack
import { providers } from 'ethers';
import * as uri from 'valid-url';

Expand Down
40 changes: 19 additions & 21 deletions packages/siwe/lib/ethersCompat.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import {
utils,
// @ts-expect-error -- ethers v6 compatibility hack
utils,
verifyMessage as ethersVerifyMessage,
// @ts-expect-error -- ethers v6 compatibility hack
hashMessage as ethersHashMessage,
// @ts-expect-error -- ethers v6 compatibility hack
getAddress as ethersGetAddress,
} from 'ethers';

Expand All @@ -15,26 +13,26 @@ type Ethers6BigNumberish = string | number | bigint;
type Ethers6SignatureLike =
| string
| {
r: string;
s: string;
v: Ethers6BigNumberish;
yParity?: 0 | 1;
yParityAndS?: string;
}
r: string;
s: string;
v: Ethers6BigNumberish;
yParity?: 0 | 1;
yParityAndS?: string;
}
| {
r: string;
yParityAndS: string;
yParity?: 0 | 1;
s?: string;
v?: number;
}
r: string;
yParityAndS: string;
yParity?: 0 | 1;
s?: string;
v?: number;
}
| {
r: string;
s: string;
yParity: 0 | 1;
v?: Ethers6BigNumberish;
yParityAndS?: string;
};
r: string;
s: string;
yParity: 0 | 1;
v?: Ethers6BigNumberish;
yParityAndS?: string;
};

export const verifyMessage =
utils?.verifyMessage ??
Expand Down
1 change: 1 addition & 0 deletions packages/siwe/lib/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-expect-error -- ethers v6 compatibility hack
import { providers } from 'ethers';
import { SiweMessage } from './client';

Expand Down
1 change: 1 addition & 0 deletions packages/siwe/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { randomStringForEntropy } from '@stablelib/random';
// @ts-expect-error -- ethers v6 compatibility hack
import { Contract, providers, Signer } from 'ethers';

import type { SiweMessage } from './client';
Expand Down
Loading