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

upgrade to prettier 3 #140

Merged
merged 2 commits into from
Nov 2, 2023
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 .changeset/gold-insects-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
2 changes: 1 addition & 1 deletion .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
. "$(dirname -- "$0")/_/husky.sh"

yarn pretty-quick --staged --pattern '**/*.+(ts|js)'
yarn lint-staged

bash scripts/prereleasecheck.sh
4 changes: 4 additions & 0 deletions .lintstagedrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"apps/**/*.ts": "prettier --list-different",
"packages/**/*.ts": "prettier --list-different"
}
2 changes: 0 additions & 2 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module.exports = {
semi: false,
singleQuote: true,
trailingComma: 'es5',
arrowParens: 'always',
printWidth: 100,
tabWidth: 2,
bracketSpacing: true,
Expand Down
18 changes: 9 additions & 9 deletions apps/combiner/src/common/combine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export interface ThresholdCallToSignersOptions<R extends OdisRequest> {
export async function thresholdCallToSigners<R extends OdisRequest>(
ctx: Context,
options: ThresholdCallToSignersOptions<R>,
processResult: (res: OdisResponse<R>) => Promise<boolean> = (_) => Promise.resolve(false)
processResult: (res: OdisResponse<R>) => Promise<boolean> = (_) => Promise.resolve(false),
): Promise<{ signerResponses: Array<SignerResponse<R>>; maxErrorCode?: number }> {
const {
signers,
Expand Down Expand Up @@ -72,8 +72,8 @@ export async function thresholdCallToSigners<R extends OdisRequest>(
request,
logger,
// @ts-ignore
abortSignal
)
abortSignal,
),
)

Counters.sigResponses
Expand All @@ -100,7 +100,7 @@ export async function thresholdCallToSigners<R extends OdisRequest>(
errorCount++
errorCodes.set(
signerFetchResult.status,
(errorCodes.get(signerFetchResult.status) ?? 0) + 1
(errorCodes.get(signerFetchResult.status) ?? 0) + 1,
)

if (signers.length - errorCount < requiredThreshold) {
Expand All @@ -121,14 +121,14 @@ export async function thresholdCallToSigners<R extends OdisRequest>(
const data: any = await signerFetchResult.json()
logger.info(
{ signer, res: data, status: signerFetchResult.status },
`received 'OK' response from signer`
`received 'OK' response from signer`,
)

const odisResponse: OdisResponse<R> = parseSchema(responseSchema, data, logger)
if (!odisResponse.success) {
logger.error(
{ err: odisResponse.error, signer: signer.url },
`Signer request to failed with 'OK' status`
`Signer request to failed with 'OK' status`,
)
throw new Error(ErrorMessage.SIGNER_RESPONSE_FAILED_WITH_OK_STATUS)
}
Expand Down Expand Up @@ -161,15 +161,15 @@ export async function thresholdCallToSigners<R extends OdisRequest>(
}
}
}
})
}),
)

if (errorCodes.size > 0) {
if (errorCodes.size > 1) {
Counters.sigInconsistenciesErrors.labels(request.url).inc()
logger.error(
{ errorCodes: JSON.stringify([...errorCodes]) },
ErrorMessage.INCONSISTENT_SIGNER_RESPONSES
ErrorMessage.INCONSISTENT_SIGNER_RESPONSES,
)
}

Expand Down Expand Up @@ -227,7 +227,7 @@ function abortSignalAny(signals: AbortSignal[]): AbortSignal {
(e) => {
ac.abort(e)
},
{ once: true }
{ once: true },
)
}
return ac.signal
Expand Down
10 changes: 5 additions & 5 deletions apps/combiner/src/common/crypto-clients/bls-crypto-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class BLSCryptographyClient extends CryptoClient {
private verifyCombinedSignature(
blindedMessage: string,
combinedSignature: Uint8Array,
logger: Logger
logger: Logger,
) {
try {
// TODO: Address bad documentation in threshold-bls lib.
Expand All @@ -59,7 +59,7 @@ export class BLSCryptographyClient extends CryptoClient {
threshold_bls.verifyBlindSignature(
Buffer.from(this.keyVersionInfo.pubKey, 'base64'),
Buffer.from(blindedMessage, 'base64'),
combinedSignature
combinedSignature,
)
} catch (error) {
logger.error('Combined signature verification failed')
Expand All @@ -70,7 +70,7 @@ export class BLSCryptographyClient extends CryptoClient {
private verifyPartialSignature(
blindedMessage: string,
unverifiedSignature: ServicePartialSignature,
ctx: Context
ctx: Context,
) {
const sigBuffer = Buffer.from(unverifiedSignature.signature, 'base64')
if (this.isValidPartialSignature(sigBuffer, blindedMessage)) {
Expand All @@ -81,7 +81,7 @@ export class BLSCryptographyClient extends CryptoClient {
Counters.blsComputeErrors.labels(ctx.url, unverifiedSignature.url).inc()
ctx.logger.error(
{ url: unverifiedSignature.url },
ErrorMessage.VERIFY_PARTIAL_SIGNATURE_ERROR
ErrorMessage.VERIFY_PARTIAL_SIGNATURE_ERROR,
)
}
}
Expand All @@ -95,7 +95,7 @@ export class BLSCryptographyClient extends CryptoClient {
threshold_bls.partialVerifyBlindSignature(
Buffer.from(this.keyVersionInfo.polynomial, 'hex'),
Buffer.from(blindedMessage, 'base64'),
signature
signature,
)
return true
} catch {
Expand Down
4 changes: 2 additions & 2 deletions apps/combiner/src/common/crypto-clients/crypto-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ export abstract class CryptoClient {
const { threshold } = this.keyVersionInfo
ctx.logger.error(
{ signatures: this.allSignaturesLength, required: threshold },
ErrorMessage.NOT_ENOUGH_PARTIAL_SIGNATURES
ErrorMessage.NOT_ENOUGH_PARTIAL_SIGNATURES,
)
throw new Error(
`${ErrorMessage.NOT_ENOUGH_PARTIAL_SIGNATURES} ${this.allSignaturesLength}/${threshold}`
`${ErrorMessage.NOT_ENOUGH_PARTIAL_SIGNATURES} ${this.allSignaturesLength}/${threshold}`,
)
}

Expand Down
8 changes: 6 additions & 2 deletions apps/combiner/src/common/error.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { ErrorType } from '@celo/phone-number-privacy-common'

export class OdisError extends Error {
constructor(readonly code: ErrorType, readonly parent?: Error, readonly status: number = 500) {
constructor(
readonly code: ErrorType,
readonly parent?: Error,
readonly status: number = 500,
) {
// This is necessary when extending Error Classes
super(code) // 'Error' breaks prototype chain here
Object.setPrototypeOf(this, new.target.prototype) // restore prototype chain
Expand All @@ -11,7 +15,7 @@ export class OdisError extends Error {
export function wrapError<T>(
valueOrError: Promise<T>,
code: ErrorType,
status: number = 500
status: number = 500,
): Promise<T> {
return valueOrError.catch((parentErr) => {
throw new OdisError(code, parentErr, status)
Expand Down
28 changes: 14 additions & 14 deletions apps/combiner/src/common/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ export interface Locals {

export type PromiseHandler<R extends OdisRequest> = (
request: Request<{}, {}, R>,
res: Response<OdisResponse<R>, Locals>
res: Response<OdisResponse<R>, Locals>,
) => Promise<void>

export function catchErrorHandler<R extends OdisRequest>(
handler: PromiseHandler<R>
handler: PromiseHandler<R>,
): PromiseHandler<R> {
return async (req, res) => {
try {
Expand All @@ -56,7 +56,7 @@ export function catchErrorHandler<R extends OdisRequest>(
}

export function tracingHandler<R extends OdisRequest>(
handler: PromiseHandler<R>
handler: PromiseHandler<R>,
): PromiseHandler<R> {
return async (req, res) => {
return tracer.startActiveSpan(
Expand All @@ -83,19 +83,19 @@ export function tracingHandler<R extends OdisRequest>(
} finally {
span.end()
}
}
},
)
}
}

export function meteringHandler<R extends OdisRequest>(
histogram: client.Histogram<string>,
handler: PromiseHandler<R>
handler: PromiseHandler<R>,
): PromiseHandler<R> {
return async (req, res) =>
newMeter(
histogram,
req.url
req.url,
)(async () => {
const logger: Logger = res.locals.logger
logger.info({ req: req.body }, 'Request received')
Expand All @@ -116,7 +116,7 @@ export function meteringHandler<R extends OdisRequest>(

export function timeoutHandler<R extends OdisRequest>(
timeoutMs: number,
handler: PromiseHandler<R>
handler: PromiseHandler<R>,
): PromiseHandler<R> {
return async (req, res) => {
const timeoutSignal = (AbortSignal as any).timeout(timeoutMs)
Expand All @@ -127,7 +127,7 @@ export function timeoutHandler<R extends OdisRequest>(
sendFailure(ErrorMessage.TIMEOUT_FROM_SIGNER, 500, res, req.url)
}
},
{ once: true }
{ once: true },
)

await handler(req, res)
Expand All @@ -136,7 +136,7 @@ export function timeoutHandler<R extends OdisRequest>(

export async function disabledHandler<R extends OdisRequest>(
req: Request<{}, {}, R>,
response: Response<OdisResponse<R>, Locals>
response: Response<OdisResponse<R>, Locals>,
): Promise<void> {
Counters.warnings.labels(req.url, WarningMessage.API_UNAVAILABLE).inc()
sendFailure(WarningMessage.API_UNAVAILABLE, 503, response, req.url)
Expand All @@ -147,7 +147,7 @@ export function sendFailure(
status: number,
response: Response,
_endpoint: string,
body?: Record<any, any> // TODO remove any
body?: Record<any, any>, // TODO remove any
) {
send(
response,
Expand All @@ -158,7 +158,7 @@ export function sendFailure(
...body,
},
status,
response.locals.logger
response.locals.logger,
)
}

Expand All @@ -169,11 +169,11 @@ export interface Result<R extends OdisRequest> {

export type ResultHandler<R extends OdisRequest> = (
request: Request<{}, {}, R>,
res: Response<OdisResponse<R>, Locals>
res: Response<OdisResponse<R>, Locals>,
) => Promise<Result<R>>

export function resultHandler<R extends OdisRequest>(
resHandler: ResultHandler<R>
resHandler: ResultHandler<R>,
): PromiseHandler<R> {
return async (req, res) => {
const result = await resHandler(req, res)
Expand All @@ -184,7 +184,7 @@ export function resultHandler<R extends OdisRequest>(
export function errorResult(
status: number,
error: string,
quotaStatus?: PnpQuotaStatus | { status: SequentialDelayDomainState }
quotaStatus?: PnpQuotaStatus | { status: SequentialDelayDomainState },
): Result<any> {
// TODO remove any
return {
Expand Down
8 changes: 4 additions & 4 deletions apps/combiner/src/common/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export type SignerResponse<R extends OdisRequest> = {
export function requestHasSupportedKeyVersion(
request: Request<{}, {}, OdisRequest>,
config: OdisConfig,
logger: Logger
logger: Logger,
): boolean {
try {
getKeyVersionInfo(request, config, logger)
Expand All @@ -41,7 +41,7 @@ export function requestHasSupportedKeyVersion(
export function getKeyVersionInfo(
request: Request<{}, {}, OdisRequest>,
config: OdisConfig,
logger: Logger
logger: Logger,
): KeyVersionInfo {
// If an invalid key version is present, we don't want this function to throw but
// to instead replace the key version with the default
Expand All @@ -53,7 +53,7 @@ export function getKeyVersionInfo(
const keyVersion = requestKeyVersion ?? config.keys.currentVersion
const supportedVersions: KeyVersionInfo[] = JSON.parse(config.keys.versions) // TODO add io-ts checks for this and signer array
const filteredSupportedVersions: KeyVersionInfo[] = supportedVersions.filter(
(v) => v.keyVersion === keyVersion
(v) => v.keyVersion === keyVersion,
)
if (!filteredSupportedVersions.length) {
throw new Error(`key version ${keyVersion} not supported`)
Expand All @@ -67,7 +67,7 @@ export async function fetchSignerResponseWithFallback<R extends OdisRequest>(
keyVersion: number,
request: Request<{}, {}, R>,
logger: Logger,
abortSignal: AbortSignal
abortSignal: AbortSignal,
): Promise<FetchResponse> {
async function fetchSignerResponse(url: string): Promise<FetchResponse> {
// prettier-ignore
Expand Down
4 changes: 2 additions & 2 deletions apps/combiner/src/common/web3/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ export async function getDEK(kit: ContractKit, logger: Logger, account: string):
logger,
config.phoneNumberPrivacy.fullNodeTimeoutMs,
config.phoneNumberPrivacy.fullNodeRetryCount,
config.phoneNumberPrivacy.fullNodeRetryDelayMs
config.phoneNumberPrivacy.fullNodeRetryDelayMs,
).catch((err) => {
logger.error({ err, account }, 'failed to get on-chain DEK for account')
Counters.errors.labels('NA', ErrorMessage.FULL_NODE_ERROR).inc()
Counters.blockchainErrors.labels('NA', ErrorMessage.FAILURE_TO_GET_DEK).inc()
throw err
})
}),
)
}
2 changes: 1 addition & 1 deletion apps/combiner/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export let config: CombinerConfig

const defaultServiceName = 'odis-combiner'
const defaultMockDEK = ensureLeading0x(
'bf8a2b73baf8402f8fe906ad3f42b560bf14b39f7df7797ece9e293d6f162188'
'bf8a2b73baf8402f8fe906ad3f42b560bf14b39f7df7797ece9e293d6f162188',
)

if (DEV_MODE) {
Expand Down
8 changes: 4 additions & 4 deletions apps/combiner/src/domain/endpoints/disable/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { findThresholdDomainState } from '../../services/threshold-state'

export function disableDomain(
signers: Signer[],
config: OdisConfig
config: OdisConfig,
): ResultHandler<DisableDomainRequest> {
return async (request, response) => {
if (!disableDomainRequestSchema(DomainSchema).is(request.body)) {
Expand All @@ -46,15 +46,15 @@ export function disableDomain(
requestTimeoutMS: config.odisServices.timeoutMilliSeconds,
responseSchema: disableDomainResponseSchema(SequentialDelayDomainStateSchema),
shouldCheckKeyVersion: false,
}
},
)

logDomainResponseDiscrepancies(response.locals.logger, signerResponses)
try {
const disableDomainStatus = findThresholdDomainState(
keyVersionInfo,
signerResponses,
signers.length
signers.length,
)
if (disableDomainStatus.disabled) {
return {
Expand All @@ -69,7 +69,7 @@ export function disableDomain(
} catch (err) {
response.locals.logger.error(
{ err },
'Error combining signer disable domain status responses'
'Error combining signer disable domain status responses',
)
}

Expand Down
Loading
Loading