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
35 changes: 19 additions & 16 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@ import js from '@eslint/js';
import tseslint from 'typescript-eslint';

export default [
js.configs.recommended,
...tseslint.configs.recommended,
{
files: ['**/*.ts'],
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
},
],
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
'no-control-regex': 'off',
},
},
{
ignores: ['pkg/pocketbase/test/pb_migrations/*'],
},
js.configs.recommended,
...tseslint.configs.recommended,
{
files: ['**/*.ts'],
rules: {
'@typescript-eslint/no-unused-vars': [
'error',
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
},
],
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
'no-control-regex': 'off',
},
},
];
2 changes: 1 addition & 1 deletion pkg/db/test/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ test.serial('Db read from a db and write in another one', async (t) => {
let query = await Result2.findByPk(1) as Result1;
query = query?.get({ plain: true });
res2 = JSON.parse(query?.["result"] ?? "{}");
} catch (e) {
} catch {
res2 = null;
}
sequelize2.close();
Expand Down
2 changes: 1 addition & 1 deletion pkg/ethereum/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const ethBytes = p.new(
try {
const dataRead = receipt.logs[0]?.data?.slice(2);
return ctx.pass(dataRead?.toString() || '');
} catch (e) {
} catch {
return ctx.fail(new EthereumError('Empty transaction'));
}
},
Expand Down
3 changes: 2 additions & 1 deletion pkg/fs/test/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { join } from 'node:path';
import * as os from 'node:os';
import http from 'http';
import { once } from 'events';
import { AddressInfo } from 'node:net';


const zipBuffer = Buffer.from('UEsDBAoAAAAAADRzTFfps6IEBAAAAAQAAAAHABwAZm9vLnR4dFVUCQADs9cnZWELKWV1eAsAAQToAwAABOgDAABiYXIKUEsBAh4DCgAAAAAANHNMV+mzogQEAAAABAAAAAcAGAAAAAAAAQAAAICBAAAAAGZvby50eHRVVAUAA7PXJ2V1eAsAAQToAwAABOgDAABQSwUGAAAAAAEAAQBNAAAARQAAAAAA', 'base64');
Expand All @@ -26,7 +27,7 @@ const server = http.createServer((req, res) => {
}
});
await once(server.listen(0), 'listening'); // listen on random free port
const { port } = server.address() as any;
const { port } = server.address() as AddressInfo;
const zipUrl = `http://localhost:${port}/`;

// Tests in this file must be run serially, since we're modifying `process.env`
Expand Down
9 changes: 4 additions & 5 deletions pkg/json-schema/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// SPDX-License-Identifier: AGPL-3.0-or-later

import { Plugin } from '@slangroom/core';
import { Ajv, type ValidationError } from 'ajv';
import { Ajv, type ValidationError, type AnySchema } from 'ajv';
import type { Jsonable } from '@slangroom/shared';
// read the version from the package.json
import packageJson from '@slangroom/json-schema/package.json' with { type: 'json' };

Expand Down Expand Up @@ -38,18 +39,16 @@ export const validateJSON = p.new(
PHRASE_VALIDATE_JSON,
async (ctx) => {
const data = ctx.fetch(ARG_JSON_DATA);
const schema = ctx.fetch(ARG_JSON_SCHEMA);
const schema = ctx.fetch(ARG_JSON_SCHEMA) as AnySchema;

try {
const ajv = new Ajv({ allErrors: true });

// @ts-ignore
const validate = ajv.compile(schema);
validate(data);

// @ts-ignore
return ctx.pass({
errors: validate.errors ?? [],
errors: validate.errors as unknown as Jsonable[] ?? [],
});
} catch (e) {
return ctx.fail(new JsonSchemaError('JSON Schema not valid' + e.message));
Expand Down
2 changes: 1 addition & 1 deletion pkg/json-schema/test/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ test('load invalid schema', async (t) => {
},
},
});
} catch (e) {
} catch {
error = 'Invalid JSON schema';
}

Expand Down
10 changes: 8 additions & 2 deletions pkg/oauth/src/authenticateHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ import { importJWK, jwtVerify } from 'jose';
import bs58 from 'bs58';
import { InMemoryCache } from '@slangroom/oauth';

type VerificationMethod = {
type?: string;
publicKeyBase58?: string;
[key: string]: unknown;
};

export class AuthenticateHandler {
addAcceptedScopesHeader: boolean | undefined;
addAuthorizedScopesHeader: boolean | undefined;
Expand Down Expand Up @@ -113,7 +119,7 @@ export class AuthenticateHandler {

const result = await response.json();

const base58Key = result.didDocument.verificationMethod.find((value: any) => value.type == 'EcdsaSecp256r1VerificationKey').publicKeyBase58;
const base58Key = result.didDocument.verificationMethod.find((value: VerificationMethod) => value?.type == 'EcdsaSecp256r1VerificationKey').publicKeyBase58;
const uint8Key = bs58.decode(base58Key);
const x_base64Key = Buffer.from(uint8Key.buffer.slice(0, 32)).toString('base64url');
const y_base64Key = Buffer.from(uint8Key.buffer.slice(32)).toString('base64url');
Expand Down Expand Up @@ -182,7 +188,7 @@ export class AuthenticateHandler {
}
const result = await response.json();
const credentials_supported = result.credential_configurations_supported;
var valid_credentials = Object.values(credentials_supported).some((value: any) => value.vct === scope);
const valid_credentials = Object.values(credentials_supported).some((value: any) => value.vct === scope);
return valid_credentials;
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/oauth/src/authorizeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ export class AuthorizeHandler {
*/

async saveAuthorizationCode(authorizationCode: string, expiresAt: Date, redirectUri: string, scope: string[], client: Client, user: User, codeChallenge: string, codeChallengeMethod: string, authorization_details: { [key: string]: any }[], rand_uri: string) {
let code: AuthorizationCode = {
const code: AuthorizationCode = {
authorizationCode: authorizationCode,
expiresAt: expiresAt,
redirectUri: redirectUri,
Expand Down
2 changes: 1 addition & 1 deletion pkg/oauth/src/isFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const rules = {
VSCHAR: /^[\u0020-\u007E]+$/
};

/* eslint-enable no-control-regex */

/**
* Minimal, RFC 6749, compliant unicode validator.
Expand Down
34 changes: 17 additions & 17 deletions pkg/oauth/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export class InMemoryCache implements AuthorizationCodeModel {
codeChallengeMethod: code['codeChallengeMethod'],
};

var keys = Object.keys(code);
const keys = Object.keys(code);
keys.forEach((key: string) => {
if (!codeSaved[key]) {
codeSaved[key] = code[key];
Expand All @@ -169,7 +169,7 @@ export class InMemoryCache implements AuthorizationCodeModel {
const base_uri = "urn:ietf:params:oauth:request_uri:";
const rand_uri = request_uri.replace(base_uri, "");
const auth_code = this.getAuthCodeFromUri(rand_uri);
let auth_details = this.getAuthorizationDetails(auth_code.authorizationCode);
const auth_details = this.getAuthorizationDetails(auth_code.authorizationCode);
//TODO: case of multiple elem in auth_details
if (auth_details[0]) {
auth_details[0]['claims'] = data;
Expand All @@ -187,7 +187,7 @@ export class InMemoryCache implements AuthorizationCodeModel {
*
*/
getAuthorizationCode(authorizationCode: string): Promise<Falsey | AuthorizationCode> {
var codes = this.codes.filter(function (code) {
const codes = this.codes.filter(function (code) {
return code.authorizationCode === authorizationCode;
});
return Promise.resolve(codes[0]);
Expand Down Expand Up @@ -217,7 +217,7 @@ export class InMemoryCache implements AuthorizationCodeModel {
*
*/
saveAuthorizationCode(code: Pick<AuthorizationCode, "authorizationCode" | "expiresAt" | "redirectUri" | "scope" | "codeChallenge" | "codeChallengeMethod">, client: Client, user: User, authorization_details?: { [key: string]: any }[], rand_uri?: string): Promise<Falsey | AuthorizationCode> {
let codeSaved: AuthorizationCode = {
const codeSaved: AuthorizationCode = {
authorizationCode: code.authorizationCode,
expiresAt: code.expiresAt,
redirectUri: code.redirectUri,
Expand Down Expand Up @@ -257,7 +257,7 @@ export class InMemoryCache implements AuthorizationCodeModel {
*/

getAccessToken(bearerToken: string): Promise<Token | Falsey> {
var tokens = this.tokens.filter(function (token) {
const tokens = this.tokens.filter(function (token) {
return token.accessToken === bearerToken;
});

Expand All @@ -269,7 +269,7 @@ export class InMemoryCache implements AuthorizationCodeModel {
*/

getRefreshToken(bearerToken: string) {
var tokens = this.tokens.filter(function (token) {
const tokens = this.tokens.filter(function (token) {
return token.refreshToken === bearerToken;
});

Expand Down Expand Up @@ -324,7 +324,7 @@ export class InMemoryCache implements AuthorizationCodeModel {
tokenSaved['jkt'] = this.createJWKThumbprint(dpop_jwk['jwk']);
}
if (this.options && this.options['allowExtendedTokenAttributes']) {
var keys = Object.keys(token);
const keys = Object.keys(token);
keys.forEach((key: string) => {
if (!tokenSaved[key]) {
tokenSaved[key] = token[key];
Expand All @@ -345,9 +345,9 @@ export class InMemoryCache implements AuthorizationCodeModel {

async createServerJWS(clientId: string) {
if (this.serverData.jwk == null) throw new OAuthError("Missing server private JWK");
let privateKey = await importJWK(this.serverData.jwk);
let alg = this.serverData.jwk.alg || 'ES256';
let public_jwk: JWK = {
const privateKey = await importJWK(this.serverData.jwk);
const alg = this.serverData.jwk.alg || 'ES256';
const public_jwk: JWK = {
kty: this.serverData.jwk.kty!,
x: this.serverData.jwk.x!,
y: this.serverData.jwk.y!,
Expand Down Expand Up @@ -388,7 +388,7 @@ export class InMemoryCache implements AuthorizationCodeModel {

// For reference see Section 4.3 of RFC9449 https://datatracker.ietf.org/doc/html/rfc9449.html
async verifyDpopProof(dpop: string, request: Request) {
let FIVE_MIN = 300000;
const FIVE_MIN = 300000;
const defaultValues = {
typ: 'dpop+jwt',
alg: 'ES256',
Expand Down Expand Up @@ -429,9 +429,9 @@ export class InMemoryCache implements AuthorizationCodeModel {

async verifyDpopHeader(request: Request) {
if (request.headers) {
var dpop = request.headers['dpop'];
const dpop = request.headers['dpop'];
if (dpop) {
var check = await this.verifyDpopProof(dpop, request);
const check = await this.verifyDpopProof(dpop, request);
if (!check) throw new OAuthError('Invalid request: DPoP header parameter is not valid');
const header = decodeProtectedHeader(dpop);
const dpop_saved = { id: request.body['client_id'], jwk: header.jwk };
Expand All @@ -442,7 +442,7 @@ export class InMemoryCache implements AuthorizationCodeModel {
}

getDpopJWK(id: string) {
var jwks = this.dpop_jwks.filter(function (dpop_jwk: any) {
const jwks = this.dpop_jwks.filter(function (dpop_jwk: any) {
return dpop_jwk.id === id;
});
return Promise.resolve(jwks[0]);
Expand Down Expand Up @@ -473,8 +473,8 @@ export class InMemoryCache implements AuthorizationCodeModel {
}
const result = await response.json();
const credentials_supported: { [key: string]: { vct: string, claims?: { [key: string]: { mandatory?: boolean }}}} = result.credential_configurations_supported;
var valid_credentials = [];
var credential_claims = new Map<string, string[]>();
const valid_credentials = [];
const credential_claims = new Map<string, string[]>();

for (const value of Object.values(credentials_supported)) {
if (value.vct === scope) {
Expand Down Expand Up @@ -509,7 +509,7 @@ export class InMemoryCache implements AuthorizationCodeModel {
throw new OAuthError('Invalid request: needed resource to verify scope');
}

var verified_credentials = await this.verifyCredentialId(scope[0]!, resource);
const verified_credentials = await this.verifyCredentialId(scope[0]!, resource);

if (verified_credentials.valid_credentials.length > 0) return Promise.resolve(scope);
else return false;
Expand Down
18 changes: 9 additions & 9 deletions pkg/oauth/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const p = new Plugin();

/* Parse QueryString using String Splitting */
function parseQueryStringToDictionary(queryString: string) {
var dictionary: { [key: string]: string } = {};
const dictionary: { [key: string]: string } = {};

// remove the '?' from the beginning of the
// if it exists
Expand All @@ -33,16 +33,16 @@ function parseQueryStringToDictionary(queryString: string) {
}

// Step 1: separate out each key/value pair
var parts = queryString.split('&');
const parts = queryString.split('&');

for (var i = 0; i < parts.length; i++) {
var p = parts[i];
for (let i = 0; i < parts.length; i++) {
const p = parts[i];
// Step 2: Split Key/Value pair
var keyValuePair = p!.split('=');
const keyValuePair = p!.split('=');

// Step 3: Add Key/Value pair to Dictionary object
var key = keyValuePair[0];
var value = keyValuePair[1];
const key = keyValuePair[0];
let value = keyValuePair[1];

// decode URI encoded string
value = decodeURIComponent(value!);
Expand Down Expand Up @@ -76,8 +76,8 @@ const getInMemoryCache = (
return inMemoryCache;
};

let authenticateHandler: any;
const getAuthenticateHandler = (model: InMemoryCache, authenticationUrl?: string): any => {
let authenticateHandler: AuthenticateHandler;
const getAuthenticateHandler = (model: InMemoryCache, authenticationUrl?: string): AuthenticateHandler => {
if (!authenticateHandler) {
authenticateHandler = new AuthenticateHandler({ model: model }, authenticationUrl);
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/oauth/test/e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ const server = {
async function create_dpop_proof() {
//this is done client side for token request
// here for now, just for testing
var private_jwk = {
const private_jwk = {
kty: 'EC',
x: 'iyuaHgjseiWTdKd_EuhxO43oayK05z_wEb2SlsxofSo',
y: 'EJBrgZE_wqm3P0bPuuYpO-5wbEbk9xy-8hdOiVODjOM',
d: 'neBDuFx9xMkXWpoU+Tk9KAofgH3qzN0e3jSSjssrM8U=',
crv: 'P-256',
};

var privateKey = await importJWK(private_jwk);
const privateKey = await importJWK(private_jwk);

const dpop = new SignJWT({
jti: randomBytes(16).toString('base64url'),
Expand Down
4 changes: 2 additions & 2 deletions pkg/pocketbase/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export class PocketBaseError extends Error {
let pb: PocketBase;
const p = new Plugin();

const serverUrlSchema = z.literal(
const _serverUrlSchema = z.literal(
`http${z.union([z.literal('s'), z.literal('')])}://${z.string()}/`,
);
export type ServerUrl = z.infer<typeof serverUrlSchema>;
export type ServerUrl = z.infer<typeof _serverUrlSchema>;

const credentialsSchema = z.object({
email: z.string().email(),
Expand Down
2 changes: 1 addition & 1 deletion pkg/wallet/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export const prettyPrintSdJwt = p.new(['token'], 'pretty print sd jwt', async (c
const tryDecode = (s: string) => {
try {
return JSON.parse(atob(s));
} catch (e) {
} catch {
return s;
}
};
Expand Down