diff --git a/src/mailer.ts b/src/mailer.ts index d87ec72..b7f52e9 100644 --- a/src/mailer.ts +++ b/src/mailer.ts @@ -21,14 +21,14 @@ async function sendMail(options: MailerOptions): Promise { html = html.replace(/{{username}}/g, username); html = html.replace(/{{paragraph}}/g, paragraph); - html = html.replace(/{{preview}}/g, (preview || "")); - html = html.replace(/{{confirmation-href}}/g, (confirmation?.href || "")); - html = html.replace(/{{confirmation-code}}/g, (confirmation?.code || "")); + html = html.replace(/{{preview}}/g, (preview || '')); + html = html.replace(/{{confirmation-href}}/g, (confirmation?.href || '')); + html = html.replace(/{{confirmation-code}}/g, (confirmation?.code || '')); if (link) { const { href, text } = link; - const button: string = ` ${text}` + const button: string = ` ${text}`; html = html.replace(//g, button); } diff --git a/src/models/nex-account.ts b/src/models/nex-account.ts index fe8742e..abfa407 100644 --- a/src/models/nex-account.ts +++ b/src/models/nex-account.ts @@ -1,6 +1,6 @@ import { Schema, model } from 'mongoose'; import uniqueValidator from 'mongoose-unique-validator'; -import { INEXAccount, INEXAccountMethods, NEXAccountModel } from '@/types/mongoose/nex-account'; +import { HydratedNEXAccountDocument, INEXAccount, INEXAccountMethods, NEXAccountModel } from '@/types/mongoose/nex-account'; const NEXAccountSchema = new Schema({ device_type: { @@ -38,12 +38,12 @@ NEXAccountSchema.plugin(uniqueValidator, { message: '{PATH} already in use.' }); and the next few accounts counting down seem to be admin, service and internal test accounts */ NEXAccountSchema.method('generatePID', async function generatePID(): Promise { - const min = 1000000000; // The console (WiiU) seems to not accept PIDs smaller than this - const max = 1799999999; + const min: number = 1000000000; // The console (WiiU) seems to not accept PIDs smaller than this + const max: number = 1799999999; - let pid = Math.floor(Math.random() * (max - min + 1) + min); + const pid: number = Math.floor(Math.random() * (max - min + 1) + min); - const inuse = await NEXAccount.findOne({ pid }); + const inuse: HydratedNEXAccountDocument = await NEXAccount.findOne({ pid }); if (inuse) { await this.generatePID(); @@ -53,17 +53,17 @@ NEXAccountSchema.method('generatePID', async function generatePID(): Promise({ access_level: { @@ -116,12 +116,12 @@ PNIDSchema.plugin(uniqueValidator, {message: '{PATH} already in use.'}); and the next few accounts counting down seem to be admin, service and internal test accounts */ PNIDSchema.method('generatePID', async function generatePID(): Promise { - const min = 1000000000; // The console (WiiU) seems to not accept PIDs smaller than this - const max = 1799999999; + const min: number = 1000000000; // The console (WiiU) seems to not accept PIDs smaller than this + const max: number = 1799999999; - let pid = Math.floor(Math.random() * (max - min + 1) + min); + const pid: number = Math.floor(Math.random() * (max - min + 1) + min); - const inuse = await PNID.findOne({ + const inuse: HydratedPNIDDocument = await PNID.findOne({ pid }); @@ -135,15 +135,15 @@ PNIDSchema.method('generatePID', async function generatePID(): Promise { PNIDSchema.method('generateEmailValidationCode', async function generateEmailValidationCode(): Promise { // WiiU passes the PID along with the email code // Does not actually need to be unique to all users - const code = Math.random().toFixed(6).split('.')[1]; // Dirty one-liner to generate numbers of 6 length and padded 0 + const code: string = Math.random().toFixed(6).split('.')[1]; // Dirty one-liner to generate numbers of 6 length and padded 0 this.set('identification.email_code', code); }); PNIDSchema.method('generateEmailValidationToken', async function generateEmailValidationToken(): Promise { - let token = crypto.randomBytes(32).toString('hex'); + const token: string = crypto.randomBytes(32).toString('hex'); - const inuse = await PNID.findOne({ + const inuse: HydratedPNIDDocument = await PNID.findOne({ 'identification.email_token': token }); @@ -168,47 +168,49 @@ PNIDSchema.method('updateMii', async function updateMii({name, primary, data}): }); PNIDSchema.method('generateMiiImages', async function generateMiiImages(): Promise { - const miiData = this.get('mii.data'); - const mii = new Mii(Buffer.from(miiData, 'base64')); - const miiStudioUrl = mii.studioUrl({ + const miiData: string = this.get('mii.data'); + const mii: Mii = new Mii(Buffer.from(miiData, 'base64')); + const miiStudioUrl: string = mii.studioUrl({ type: 'face', width: '128', instanceCount: '1', }); - const miiStudioNormalFaceImageData = await got(miiStudioUrl).buffer(); - const pngData = await imagePixels(miiStudioNormalFaceImageData); - const tga = TGA.createTgaBuffer(pngData.width, pngData.height, pngData.data); + const miiStudioNormalFaceImageData: Buffer = await got(miiStudioUrl).buffer(); + const pngData: { + width: number; + height: number; + data: Buffer; + } = await imagePixels(miiStudioNormalFaceImageData); + const tga: Buffer = TGA.createTgaBuffer(pngData.width, pngData.height, pngData.data); - const userMiiKey = `mii/${this.get('pid')}`; + const userMiiKey: string = `mii/${this.get('pid')}`; await util.uploadCDNAsset('pn-cdn', `${userMiiKey}/standard.tga`, tga, 'public-read'); await util.uploadCDNAsset('pn-cdn', `${userMiiKey}/normal_face.png`, miiStudioNormalFaceImageData, 'public-read'); - const expressions = ['frustrated', 'smile_open_mouth', 'wink_left', 'sorrow', 'surprise_open_mouth']; + const expressions: string[] = ['frustrated', 'smile_open_mouth', 'wink_left', 'sorrow', 'surprise_open_mouth']; for (const expression of expressions) { - const miiStudioExpressionUrl = mii.studioUrl({ + const miiStudioExpressionUrl: string = mii.studioUrl({ type: 'face', expression: expression, width: '128', instanceCount: '1', }); - const miiStudioExpressionImageData = await got(miiStudioExpressionUrl).buffer(); + const miiStudioExpressionImageData: Buffer = await got(miiStudioExpressionUrl).buffer(); await util.uploadCDNAsset('pn-cdn', `${userMiiKey}/${expression}.png`, miiStudioExpressionImageData, 'public-read'); } - const miiStudioBodyUrl = mii.studioUrl({ + const miiStudioBodyUrl: string = mii.studioUrl({ type: 'all_body', width: '270', instanceCount: '1', }); - const miiStudioBodyImageData = await got(miiStudioBodyUrl).buffer(); + const miiStudioBodyImageData: Buffer = await got(miiStudioBodyUrl).buffer(); await util.uploadCDNAsset('pn-cdn', `${userMiiKey}/body.png`, miiStudioBodyImageData, 'public-read'); }); PNIDSchema.method('getServerMode', function getServerMode(): string { - const serverMode = this.get('server_mode') || 'prod'; - - return serverMode; + return this.get('server_mode') || 'prod'; }); export const PNID: PNIDModel = model('PNID', PNIDSchema); \ No newline at end of file diff --git a/src/nintendo-certificate.ts b/src/nintendo-certificate.ts index 79cfcee..0ee9ef1 100644 --- a/src/nintendo-certificate.ts +++ b/src/nintendo-certificate.ts @@ -106,7 +106,7 @@ class NintendoCertificate { } } - _parseCertificateData() { + _parseCertificateData(): void { if (this._certificate.length === 0x110) { // Assume fcdcert (3DS LFCS) this.signature = this._certificate.subarray(0x0, 0x100); @@ -149,7 +149,7 @@ class NintendoCertificate { } } - _verifySignature() { + _verifySignature(): void { switch (this.keyType) { case 0x0: this._verifySignatureRSA4096(); @@ -168,7 +168,7 @@ class NintendoCertificate { } } - _verifySignatureRSA4096() { + _verifySignatureRSA4096(): void { const publicKey: NodeRSA = new NodeRSA(); publicKey.importKey({ @@ -179,7 +179,7 @@ class NintendoCertificate { this.valid = publicKey.verify(this._certificateBody, this.signature); } - _verifySignatureRSA2048() { + _verifySignatureRSA2048(): void { const publicKey: NodeRSA = new NodeRSA(); publicKey.importKey({ @@ -194,7 +194,7 @@ class NintendoCertificate { // with Nodes native crypto module and getting the keys // from bytes to PEM! // https://github.com/Myriachan - _verifySignatureECDSA() { + _verifySignatureECDSA(): void { const pem: string = this.issuer == 'Root-CA00000003-MS00000012' ? WIIU_DEVICE_PUB_PEM : CTR_DEVICE_PUB_PEM; const key: crypto.VerifyPublicKeyInput = { key: pem, @@ -204,7 +204,7 @@ class NintendoCertificate { this.valid = crypto.verify('sha256', this._certificateBody, key, this.signature); } - _verifySignatureLFCS() { + _verifySignatureLFCS(): void { const publicKey: NodeRSA = new NodeRSA(); publicKey.importKey({