feat: eslint 적용 및 관련 코드 일괄 수정
This commit is contained in:
@@ -39,13 +39,9 @@ export interface GameSessionTokenPayload {
|
||||
const toBase64Url = (data: Buffer): string => data.toString('base64url');
|
||||
const fromBase64Url = (value: string): Buffer => Buffer.from(value, 'base64url');
|
||||
|
||||
const buildKey = (secret: string): Buffer =>
|
||||
createHash('sha256').update(secret).digest();
|
||||
const buildKey = (secret: string): Buffer => createHash('sha256').update(secret).digest();
|
||||
|
||||
export const encryptGameSessionToken = (
|
||||
payload: GameSessionTokenPayload,
|
||||
secret: string
|
||||
): string => {
|
||||
export const encryptGameSessionToken = (payload: GameSessionTokenPayload, secret: string): string => {
|
||||
const iv = randomBytes(12);
|
||||
const key = buildKey(secret);
|
||||
const cipher = createCipheriv('aes-256-gcm', key, iv);
|
||||
@@ -90,10 +86,7 @@ const parsePayload = (value: unknown): GameSessionTokenPayload | null => {
|
||||
return payload as GameSessionTokenPayload;
|
||||
};
|
||||
|
||||
export const decryptGameSessionToken = (
|
||||
token: string,
|
||||
secret: string
|
||||
): GameSessionTokenPayload | null => {
|
||||
export const decryptGameSessionToken = (token: string, secret: string): GameSessionTokenPayload | null => {
|
||||
const parts = token.split('.');
|
||||
if (parts.length !== 3) {
|
||||
return null;
|
||||
@@ -106,9 +99,7 @@ export const decryptGameSessionToken = (
|
||||
const key = buildKey(secret);
|
||||
const decipher = createDecipheriv('aes-256-gcm', key, iv);
|
||||
decipher.setAuthTag(tag);
|
||||
const plaintext = Buffer.concat([decipher.update(ciphertext), decipher.final()]).toString(
|
||||
'utf8'
|
||||
);
|
||||
const plaintext = Buffer.concat([decipher.update(ciphertext), decipher.final()]).toString('utf8');
|
||||
return parsePayload(JSON.parse(plaintext));
|
||||
} catch {
|
||||
return null;
|
||||
|
||||
@@ -1,9 +1,4 @@
|
||||
export type TurnDaemonState =
|
||||
| 'idle'
|
||||
| 'running'
|
||||
| 'flushing'
|
||||
| 'paused'
|
||||
| 'stopping';
|
||||
export type TurnDaemonState = 'idle' | 'running' | 'flushing' | 'paused' | 'stopping';
|
||||
|
||||
export type RunReason = 'schedule' | 'manual' | 'poke';
|
||||
|
||||
|
||||
@@ -1,12 +1,4 @@
|
||||
export type JosaKey =
|
||||
| '은'
|
||||
| '이'
|
||||
| '과'
|
||||
| '이나'
|
||||
| '을'
|
||||
| '으로'
|
||||
| '이라'
|
||||
| '이랑';
|
||||
export type JosaKey = '은' | '이' | '과' | '이나' | '을' | '으로' | '이라' | '이랑';
|
||||
|
||||
const DEFAULT_POSTPOSITION: Record<JosaKey, string> = {
|
||||
은: '는',
|
||||
@@ -40,10 +32,7 @@ const KO_FINISH_CODE = 0xd7a3;
|
||||
const JONGSUNG_RIEUL = 8;
|
||||
|
||||
const getLastChar = (text: string): string => {
|
||||
const cleaned = text
|
||||
.replace(REG_INVALID_CHAR, ' ')
|
||||
.replace(REG_TARGET_CHAR, '$1')
|
||||
.trim();
|
||||
const cleaned = text.replace(REG_INVALID_CHAR, ' ').replace(REG_TARGET_CHAR, '$1').trim();
|
||||
if (!cleaned) {
|
||||
return '';
|
||||
}
|
||||
@@ -51,9 +40,7 @@ const getLastChar = (text: string): string => {
|
||||
return chars[chars.length - 1] ?? '';
|
||||
};
|
||||
|
||||
const getDigitJongsung = (
|
||||
digit: number
|
||||
): { has: boolean; rieul: boolean } => {
|
||||
const getDigitJongsung = (digit: number): { has: boolean; rieul: boolean } => {
|
||||
switch (digit) {
|
||||
case 0:
|
||||
case 3:
|
||||
@@ -121,9 +108,7 @@ export class JosaUtil {
|
||||
}
|
||||
|
||||
const isRo = withJongsung === '으로';
|
||||
return hasJongsung(normalizedText, isRo)
|
||||
? withJongsung
|
||||
: withoutJongsung;
|
||||
return hasJongsung(normalizedText, isRo) ? withJongsung : withoutJongsung;
|
||||
}
|
||||
|
||||
static put(text: string, wJongsung: string, woJongsung = ''): string {
|
||||
|
||||
@@ -79,13 +79,16 @@ function calcBitMask(n: bigint): bigint {
|
||||
|
||||
// SHA-512 기반 DRBG 구현
|
||||
export class LiteHashDRBG implements RNG {
|
||||
|
||||
protected buffer!: ArrayBuffer;
|
||||
protected bufferIdx!: number;
|
||||
protected hq: DataView;
|
||||
protected hqIdxPos: number;
|
||||
|
||||
public constructor(protected seed: BytesLike, protected stateIdx = 0, bufferIdx = 0) {
|
||||
public constructor(
|
||||
protected seed: BytesLike,
|
||||
protected stateIdx = 0,
|
||||
bufferIdx = 0
|
||||
) {
|
||||
if (bufferIdx < 0) {
|
||||
throw new Error(`bufferIdx ${bufferIdx} < 0`);
|
||||
}
|
||||
@@ -215,7 +218,6 @@ export class LiteHashDRBG implements RNG {
|
||||
}
|
||||
|
||||
public nextFloat1(): number {
|
||||
// eslint-disable-next-line no-constant-condition
|
||||
while (true) {
|
||||
const nInt = this._nextInt(maxRngSupportBit + 1);
|
||||
if (nInt < maxIntMore1) {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
export interface RNG {
|
||||
|
||||
/**
|
||||
* nextInt()가 반환 가능한 최댓값
|
||||
*/
|
||||
|
||||
@@ -2,9 +2,7 @@ import type { RNG } from './RNG.js';
|
||||
|
||||
// RNG 유틸리티 모음
|
||||
export class RandUtil {
|
||||
constructor(protected rng: RNG) {
|
||||
|
||||
}
|
||||
constructor(protected rng: RNG) {}
|
||||
|
||||
public nextFloat1(): number {
|
||||
return this.rng.nextFloat1();
|
||||
@@ -12,7 +10,7 @@ export class RandUtil {
|
||||
|
||||
public nextRange(min: number, max: number): number {
|
||||
const range = max - min;
|
||||
return this.nextFloat1() * (range) + min;
|
||||
return this.nextFloat1() * range + min;
|
||||
}
|
||||
|
||||
public nextRangeInt(min: number, max: number): number {
|
||||
|
||||
@@ -5,11 +5,7 @@ export function convertBytesLikeToArrayBuffer(data: BytesLike, encodeUTF8 = true
|
||||
return data;
|
||||
}
|
||||
if (data instanceof Uint8Array) {
|
||||
if (
|
||||
data.byteOffset === 0
|
||||
&& data.byteLength === data.buffer.byteLength
|
||||
&& data.buffer instanceof ArrayBuffer
|
||||
) {
|
||||
if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength && data.buffer instanceof ArrayBuffer) {
|
||||
return data.buffer;
|
||||
}
|
||||
return data.slice().buffer;
|
||||
@@ -18,9 +14,9 @@ export function convertBytesLikeToArrayBuffer(data: BytesLike, encodeUTF8 = true
|
||||
const view = new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
||||
return view.slice().buffer;
|
||||
}
|
||||
if (typeof (data) === 'string') {
|
||||
if (typeof data === 'string') {
|
||||
if (encodeUTF8) {
|
||||
return (new TextEncoder()).encode(data).buffer;
|
||||
return new TextEncoder().encode(data).buffer;
|
||||
}
|
||||
return new Uint8Array(data.split('').map((s) => s.codePointAt(0) as number)).buffer;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
import type { BytesLike } from './BytesLike.js';
|
||||
|
||||
export function convertBytesLikeToUint8Array(
|
||||
data: BytesLike,
|
||||
encodeUTF8 = true
|
||||
): Uint8Array<ArrayBuffer> {
|
||||
export function convertBytesLikeToUint8Array(data: BytesLike, encodeUTF8 = true): Uint8Array<ArrayBuffer> {
|
||||
if (data instanceof Uint8Array) {
|
||||
if (
|
||||
data.buffer instanceof ArrayBuffer
|
||||
&& data.byteOffset === 0
|
||||
&& data.byteLength === data.buffer.byteLength
|
||||
) {
|
||||
if (data.buffer instanceof ArrayBuffer && data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
|
||||
return data;
|
||||
}
|
||||
return new Uint8Array(data) as Uint8Array<ArrayBuffer>;
|
||||
@@ -20,9 +13,9 @@ export function convertBytesLikeToUint8Array(
|
||||
if (data instanceof DataView) {
|
||||
return new Uint8Array<ArrayBuffer>(data.buffer, data.byteOffset, data.byteLength);
|
||||
}
|
||||
if (typeof (data) === 'string') {
|
||||
if (typeof data === 'string') {
|
||||
if (encodeUTF8) {
|
||||
return (new TextEncoder()).encode(data);
|
||||
return new TextEncoder().encode(data);
|
||||
}
|
||||
return new Uint8Array(data.split('').map((s) => s.codePointAt(0) as number));
|
||||
}
|
||||
|
||||
@@ -10,24 +10,19 @@ type NodeHash = {
|
||||
|
||||
type NodeCreateHash = (algorithm: 'sha512') => NodeHash;
|
||||
|
||||
const isNode = typeof process !== 'undefined'
|
||||
&& typeof process.versions?.node === 'string';
|
||||
const isNode = typeof process !== 'undefined' && typeof process.versions?.node === 'string';
|
||||
|
||||
const nodeCryptoSpecifier = 'node:crypto';
|
||||
|
||||
let nodeCreateHash: NodeCreateHash | null = null;
|
||||
|
||||
if (isNode) {
|
||||
const nodeCrypto = await import(nodeCryptoSpecifier) as typeof import('node:crypto');
|
||||
const nodeCrypto = (await import(nodeCryptoSpecifier)) as typeof import('node:crypto');
|
||||
nodeCreateHash = nodeCrypto.createHash as NodeCreateHash;
|
||||
}
|
||||
|
||||
function normalizeUint8Array(bytes: Uint8Array): Uint8Array<ArrayBuffer> {
|
||||
if (
|
||||
bytes.buffer instanceof ArrayBuffer
|
||||
&& bytes.byteOffset === 0
|
||||
&& bytes.byteLength === bytes.buffer.byteLength
|
||||
) {
|
||||
if (bytes.buffer instanceof ArrayBuffer && bytes.byteOffset === 0 && bytes.byteLength === bytes.buffer.byteLength) {
|
||||
return bytes as Uint8Array<ArrayBuffer>;
|
||||
}
|
||||
const out = new Uint8Array(bytes.byteLength);
|
||||
|
||||
Reference in New Issue
Block a user