From 82d353357bc8d8cfc1a63fb6d64f43a7b7292482 Mon Sep 17 00:00:00 2001 From: Jonathan Barrow Date: Sun, 14 Apr 2024 19:41:47 -0400 Subject: [PATCH] chore: updated comments to use Better Comments syntax --- src/database.ts | 6 +-- src/middleware/nasc.ts | 20 ++++----- src/middleware/xml-parser.ts | 2 +- src/models/device.ts | 4 +- src/models/nex-account.ts | 8 ++-- src/models/pnid.ts | 14 +++--- src/nintendo-certificate.ts | 10 ++--- src/server.ts | 12 ++--- src/services/api/index.ts | 8 ++-- src/services/api/routes/v1/register.ts | 50 ++++++++++----------- src/services/api/routes/v1/resetPassword.ts | 2 +- src/services/assets/index.ts | 10 ++--- src/services/cbvc/index.ts | 10 ++--- src/services/conntest/index.ts | 12 ++--- src/services/datastore/index.ts | 8 ++-- src/services/datastore/routes/upload.ts | 2 +- src/services/grpc/api/register.ts | 48 ++++++++++---------- src/services/grpc/api/reset-password.ts | 2 +- src/services/nasc/index.ts | 10 ++--- src/services/nasc/routes/ac.ts | 2 +- src/services/nnas/index.ts | 10 ++--- src/services/nnas/routes/content.ts | 4 +- src/services/nnas/routes/people.ts | 28 ++++++------ src/services/nnas/routes/provider.ts | 2 +- src/types/mongoose/pnid.ts | 2 +- src/types/services/nnas/pnid-profile.ts | 2 +- src/util.ts | 2 +- 27 files changed, 145 insertions(+), 145 deletions(-) diff --git a/src/database.ts b/src/database.ts index 4f0e7a2..b6d443e 100644 --- a/src/database.ts +++ b/src/database.ts @@ -17,7 +17,7 @@ import { DiscordConnectionData } from '@/types/services/api/discord-connection-d const connection_string = config.mongoose.connection_string; const options = config.mongoose.options; -// TODO: Extend this later with more settings +// TODO - Extend this later with more settings const discordConnectionSchema = joi.object({ id: joi.string() }); @@ -116,7 +116,7 @@ export async function getPNIDByTokenAuth(token: string): Promise({ linked_pids: [Number], access_level: { type: Number, - default: 0 // 0: standard, 1: tester, 2: mod?, 3: dev + default: 0 // * 0: standard, 1: tester, 2: mod?, 3: dev }, server_access_level: { type: String, - default: 'prod' // everyone is in production by default + default: 'prod' // * everyone is in production by default }, certificate_hash: String }); diff --git a/src/models/nex-account.ts b/src/models/nex-account.ts index 9372ac6..c731f07 100644 --- a/src/models/nex-account.ts +++ b/src/models/nex-account.ts @@ -6,7 +6,7 @@ const NEXAccountSchema = new Schema { - const min = 1000000000; // The console (WiiU) seems to not accept PIDs smaller than this + const min = 1000000000; // * The console (WiiU) seems to not accept PIDs smaller than this const max = 1799999999; const pid = Math.floor(Math.random() * (max - min + 1) + min); diff --git a/src/models/pnid.ts b/src/models/pnid.ts index 1e19629..5e2cc34 100644 --- a/src/models/pnid.ts +++ b/src/models/pnid.ts @@ -33,11 +33,11 @@ const PNIDSchema = new Schema({ }, access_level: { type: Number, - default: 0 // 0: standard, 1: tester, 2: mod?, 3: dev + default: 0 // * 0: standard, 1: tester, 2: mod?, 3: dev }, server_access_level: { type: String, - default: 'prod' // everyone is in production by default + default: 'prod' // * everyone is in production by default }, pid: { type: Number, @@ -89,7 +89,7 @@ const PNIDSchema = new Schema({ off_device: Boolean }, devices: [DeviceSchema], - identification: { // user identification tokens + identification: { // * user identification tokens email_code: { type: String, unique: true @@ -133,7 +133,7 @@ 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 min = 1000000000; // * The console (WiiU) seems to not accept PIDs smaller than this const max = 1799999999; const pid = Math.floor(Math.random() * (max - min + 1) + min); @@ -150,9 +150,9 @@ 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 + // * 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 this.identification.email_code = code; }); diff --git a/src/nintendo-certificate.ts b/src/nintendo-certificate.ts index 8d5dce8..38e7a1a 100644 --- a/src/nintendo-certificate.ts +++ b/src/nintendo-certificate.ts @@ -41,7 +41,7 @@ const CTR_LFCS_B_PUB = Buffer.from([ 0xAF, 0x07, 0xEB, 0x9C, 0xBF, 0xA9, 0xC9 ]); -// Signature options +// * Signature options const SIGNATURE_SIZES = { RSA_4096_SHA1: { SIZE: 0x200, @@ -201,10 +201,10 @@ class NintendoCertificate { this.valid = publicKey.verify(this._certificateBody, this.signature); } - // Huge thanks to Myria for helping get ECDSA working - // with Nodes native crypto module and getting the keys - // from bytes to PEM! - // https://github.com/Myriachan + // * Huge thanks to Myria for helping get ECDSA working + // * with Nodes native crypto module and getting the keys + // * from bytes to PEM! + // * https://github.com/Myriachan _verifySignatureECDSA(): void { const pem = this.consoleType === 'wiiu' ? WIIU_DEVICE_PUB_PEM : CTR_DEVICE_PUB_PEM; const key = { diff --git a/src/server.ts b/src/server.ts index 4d90d63..6919a55 100644 --- a/src/server.ts +++ b/src/server.ts @@ -27,9 +27,9 @@ import { config } from '@/config-manager'; const app = express(); -// START APPLICATION +// * START APPLICATION -// Create router +// * Create router LOG_INFO('Setting up Middleware'); app.use(morgan('dev')); app.use(express.json()); @@ -38,7 +38,7 @@ app.use(express.urlencoded({ })); app.use(xmlparser); -// import the servers into one +// * import the servers into one app.use(conntest); app.use(cbvc); app.use(nnas); @@ -48,7 +48,7 @@ app.use(api); app.use(localcdn); app.use(assets); -// 404 handler +// * 404 handler LOG_INFO('Creating 404 status handler'); app.use((request: express.Request, response: express.Response): void => { const url = fullUrl(request); @@ -75,7 +75,7 @@ app.use((request: express.Request, response: express.Response): void => { }).end()); }); -// non-404 error handler +// * non-404 error handler LOG_INFO('Creating non-404 status handler'); app.use((error: any, request: express.Request, response: express.Response, _next: express.NextFunction): void => { const status = error.status || 500; @@ -96,7 +96,7 @@ app.use((error: any, request: express.Request, response: express.Response, _next }); async function main(): Promise { - // Starts the server + // * Starts the server LOG_INFO('Starting server'); await connectDatabase(); diff --git a/src/services/api/index.ts b/src/services/api/index.ts index 45efc53..f699f79 100644 --- a/src/services/api/index.ts +++ b/src/services/api/index.ts @@ -6,7 +6,7 @@ import { LOG_INFO } from '@/logger'; import { V1 } from '@/services/api/routes'; -// Router to handle the subdomain restriction +// * Router to handle the subdomain restriction const api = express.Router(); LOG_INFO('[USER API] Importing middleware'); @@ -14,7 +14,7 @@ api.use(APIMiddleware); api.use(cors()); api.options('*', cors()); -// Setup routes +// * Setup routes LOG_INFO('[USER API] Applying imported routes'); api.use('/v1/connections', V1.CONNECTIONS); api.use('/v1/email', V1.EMAIL); @@ -25,10 +25,10 @@ api.use('/v1/reset-password', V1.RESET_PASSWORD); api.use('/v1/user', V1.USER); -// Main router for endpoints +// * Main router for endpoints const router = express.Router(); -// Create subdomains +// * Create subdomains LOG_INFO('[USER API] Creating \'api\' subdomain'); router.use(subdomain('api', api)); diff --git a/src/services/api/routes/v1/register.ts b/src/services/api/routes/v1/register.ts index 12a1b5e..2b1928b 100644 --- a/src/services/api/routes/v1/register.ts +++ b/src/services/api/routes/v1/register.ts @@ -22,7 +22,7 @@ const PNID_PUNCTUATION_START_REGEX = /^[_\-.]/; const PNID_PUNCTUATION_END_REGEX = /[_\-.]$/; const PNID_PUNCTUATION_DUPLICATE_REGEX = /[_\-.]{2,}/; -// This sucks +// * This sucks const PASSWORD_WORD_OR_NUMBER_REGEX = /(?=.*[a-zA-Z])(?=.*\d).*/; const PASSWORD_WORD_OR_PUNCTUATION_REGEX = /(?=.*[a-zA-Z])(?=.*[_\-.]).*/; const PASSWORD_NUMBER_OR_PUNCTUATION_REGEX = /(?=.*\d)(?=.*[_\-.]).*/; @@ -250,7 +250,7 @@ router.post('/', async (request: express.Request, response: express.Response): P return; } - const miiNameBuffer = Buffer.from(miiName, 'utf16le'); // UTF8 to UTF16 + const miiNameBuffer = Buffer.from(miiName, 'utf16le'); // * UTF8 to UTF16 if (miiNameBuffer.length > 0x14) { response.status(400).json({ @@ -282,11 +282,11 @@ router.post('/', async (request: express.Request, response: express.Response): P await nexAccount.generatePID(); await nexAccount.generatePassword(); - // Quick hack to get the PIDs to match - // TODO: Change this maybe? - // NN with a NNID will always use the NNID PID - // even if the provided NEX PID is different - // To fix this we make them the same PID + // * Quick hack to get the PIDs to match + // TODO - Change this maybe? + // * NN with a NNID will always use the NNID PID + // * even if the provided NEX PID is different + // * To fix this we make them the same PID nexAccount.owning_pid = nexAccount.pid; await nexAccount.save({ session }); @@ -301,40 +301,40 @@ router.post('/', async (request: express.Request, response: express.Response): P username: username, usernameLower: username.toLowerCase(), password: passwordHash, - birthdate: '1990-01-01', // TODO: Change this - gender: 'M', // TODO: Change this - country: 'US', // TODO: Change this - language: 'en', // TODO: Change this + birthdate: '1990-01-01', // TODO - Change this + gender: 'M', // TODO - Change this + country: 'US', // TODO - Change this + language: 'en', // TODO - Change this email: { address: email.toLowerCase(), - primary: true, // TODO: Change this - parent: true, // TODO: Change this - reachable: false, // TODO: Change this - validated: false, // TODO: Change this + primary: true, // TODO - Change this + parent: true, // TODO - Change this + reachable: false, // TODO - Change this + validated: false, // TODO - Change this id: crypto.randomBytes(4).readUInt32LE() }, - region: 0x310B0000, // TODO: Change this + region: 0x310B0000, // TODO - Change this timezone: { - name: 'America/New_York', // TODO: Change this - offset: -14400 // TODO: Change this + name: 'America/New_York', // TODO - Change this + offset: -14400 // TODO - Change this }, mii: { name: miiName, - primary: true, // TODO: Change this + primary: true, // TODO - Change this data: mii.encode().toString('base64'), id: crypto.randomBytes(4).readUInt32LE(), hash: crypto.randomBytes(7).toString('hex'), - image_url: '', // deprecated, will be removed in the future + image_url: '', // * deprecated, will be removed in the future image_id: crypto.randomBytes(4).readUInt32LE() }, flags: { - active: true, // TODO: Change this - marketing: true, // TODO: Change this - off_device: true // TODO: Change this + active: true, // TODO - Change this + marketing: true, // TODO - Change this + off_device: true // TODO - Change this }, identification: { - email_code: 1, // will be overwritten before saving - email_token: '' // will be overwritten before saving + email_code: 1, // * will be overwritten before saving + email_token: '' // * will be overwritten before saving } }); diff --git a/src/services/api/routes/v1/resetPassword.ts b/src/services/api/routes/v1/resetPassword.ts index 025ca64..ad401fb 100644 --- a/src/services/api/routes/v1/resetPassword.ts +++ b/src/services/api/routes/v1/resetPassword.ts @@ -6,7 +6,7 @@ import { Token } from '@/types/common/token'; const router = express.Router(); -// This sucks +// * This sucks const PASSWORD_WORD_OR_NUMBER_REGEX = /(?=.*[a-zA-Z])(?=.*\d).*/; const PASSWORD_WORD_OR_PUNCTUATION_REGEX = /(?=.*[a-zA-Z])(?=.*[_\-.]).*/; const PASSWORD_NUMBER_OR_PUNCTUATION_REGEX = /(?=.*\d)(?=.*[_\-.]).*/; diff --git a/src/services/assets/index.ts b/src/services/assets/index.ts index 22be241..a20b710 100644 --- a/src/services/assets/index.ts +++ b/src/services/assets/index.ts @@ -1,21 +1,21 @@ -// handles serving assets +// * handles serving assets import path from 'node:path'; import express from 'express'; import subdomain from 'express-subdomain'; import { LOG_INFO } from '@/logger'; -// Router to handle the subdomain restriction +// * Router to handle the subdomain restriction const assets = express.Router(); -// Setup public folder +// * Setup public folder LOG_INFO('[assets] Setting up public folder'); assets.use(express.static(path.join(__dirname, '../../assets'))); -// Main router for endpoints +// * Main router for endpoints const router = express.Router(); -// Create subdomains +// * Create subdomains LOG_INFO('[conntest] Creating \'assets\' subdomain'); router.use(subdomain('assets', assets)); diff --git a/src/services/cbvc/index.ts b/src/services/cbvc/index.ts index 5116f93..8dd395b 100644 --- a/src/services/cbvc/index.ts +++ b/src/services/cbvc/index.ts @@ -1,13 +1,13 @@ -// handles CBVC (CTR Browser Version Check?) endpoints +// * handles CBVC (CTR Browser Version Check?) endpoints import express from 'express'; import subdomain from 'express-subdomain'; import { LOG_INFO } from '@/logger'; -// Router to handle the subdomain restriction +// * Router to handle the subdomain restriction const cbvc = express.Router(); -// Setup route +// * Setup route LOG_INFO('[cbvc] Applying imported routes'); cbvc.get('/:consoleType/:unknown/:region', (request: express.Request, response: express.Response): void => { response.set('Content-Type', 'text/plain'); @@ -21,10 +21,10 @@ cbvc.get('/:consoleType/:unknown/:region', (request: express.Request, response: response.send('0'); }); -// Main router for endpoints +// * Main router for endpoints const router = express.Router(); -// Create subdomains +// * Create subdomains LOG_INFO('[cbvc] Creating \'cbvc\' subdomain'); router.use(subdomain('cbvc.cdn', cbvc)); diff --git a/src/services/conntest/index.ts b/src/services/conntest/index.ts index 8b5f68a..47c353e 100644 --- a/src/services/conntest/index.ts +++ b/src/services/conntest/index.ts @@ -1,20 +1,20 @@ -// handles conntest endpoints +// * handles conntest endpoints import express from 'express'; import subdomain from 'express-subdomain'; import { LOG_INFO } from '@/logger'; -// Router to handle the subdomain restriction +// * Router to handle the subdomain restriction const conntest = express.Router(); -// Setup route +// * Setup route LOG_INFO('[conntest] Applying imported routes'); conntest.get('/', (request: express.Request, response: express.Response): void => { response.set('Content-Type', 'text/html'); response.set('X-Organization', 'Nintendo'); response.send(` - + HTML Page @@ -26,10 +26,10 @@ This is test.html page `); }); -// Main router for endpoints +// * Main router for endpoints const router = express.Router(); -// Create subdomains +// * Create subdomains LOG_INFO('[conntest] Creating \'conntest\' subdomain'); router.use(subdomain('conntest', conntest)); diff --git a/src/services/datastore/index.ts b/src/services/datastore/index.ts index 35b9ade..c8c3d01 100644 --- a/src/services/datastore/index.ts +++ b/src/services/datastore/index.ts @@ -4,17 +4,17 @@ import { LOG_INFO } from '@/logger'; import upload from '@/services/datastore/routes/upload'; -// Router to handle the subdomain +// * Router to handle the subdomain const datastore = express.Router(); -// Setup routes +// * Setup routes LOG_INFO('[DATASTORE] Applying imported routes'); datastore.use(upload); -// Main router for endpoints +// * Main router for endpoints const router = express.Router(); -// Create subdomains +// * Create subdomains LOG_INFO('[DATASTORE] Creating \'datastore\' subdomain'); router.use(subdomain('datastore', datastore)); diff --git a/src/services/datastore/routes/upload.ts b/src/services/datastore/routes/upload.ts index 09119d6..6e3585e 100644 --- a/src/services/datastore/routes/upload.ts +++ b/src/services/datastore/routes/upload.ts @@ -75,7 +75,7 @@ router.post('/upload', multipartParser, async (request: express.Request, respons const date = request.files.date.toString(); const signature = request.files.signature.toString(); - // Signatures only good for 1 minute + // * Signatures only good for 1 minute const minute = 1000 * 60; const minuteAgo = Date.now() - minute; diff --git a/src/services/grpc/api/register.ts b/src/services/grpc/api/register.ts index f381499..566c5a1 100644 --- a/src/services/grpc/api/register.ts +++ b/src/services/grpc/api/register.ts @@ -21,7 +21,7 @@ const PNID_PUNCTUATION_START_REGEX = /^[_\-.]/; const PNID_PUNCTUATION_END_REGEX = /[_\-.]$/; const PNID_PUNCTUATION_DUPLICATE_REGEX = /[_\-.]{2,}/; -// This sucks +// * This sucks const PASSWORD_WORD_OR_NUMBER_REGEX = /(?=.*[a-zA-Z])(?=.*\d).*/; const PASSWORD_WORD_OR_PUNCTUATION_REGEX = /(?=.*[a-zA-Z])(?=.*[_\-.]).*/; const PASSWORD_NUMBER_OR_PUNCTUATION_REGEX = /(?=.*\d)(?=.*[_\-.]).*/; @@ -146,11 +146,11 @@ export async function register(request: RegisterRequest): Promise { diff --git a/src/services/nnas/routes/people.ts b/src/services/nnas/routes/people.ts index 5d0bf3d..4e7549b 100644 --- a/src/services/nnas/routes/people.ts +++ b/src/services/nnas/routes/people.ts @@ -51,7 +51,7 @@ router.get('/:username', async (request: express.Request, response: express.Resp */ router.post('/', ratelimit, deviceCertificateMiddleware, async (request: express.Request, response: express.Response): Promise => { if (!request.certificate || !request.certificate.valid) { - // TODO: Change this to a different error + // TODO - Change this to a different error response.status(400).send(xmlbuilder.create({ error: { cause: 'Bad Request', @@ -95,11 +95,11 @@ router.post('/', ratelimit, deviceCertificateMiddleware, async (request: express await nexAccount.generatePID(); await nexAccount.generatePassword(); - // Quick hack to get the PIDs to match - // TODO: Change this maybe? - // NN with a NNID will always use the NNID PID - // even if the provided NEX PID is different - // To fix this we make them the same PID + // * Quick hack to get the PIDs to match + // TODO - Change this maybe? + // * NN with a NNID will always use the NNID PID + // * even if the provided NEX PID is different + // * To fix this we make them the same PID nexAccount.owning_pid = nexAccount.pid; await nexAccount.save({ session }); @@ -156,7 +156,7 @@ router.post('/', ratelimit, deviceCertificateMiddleware, async (request: express data: person.mii.data, id: crypto.randomBytes(4).readUInt32LE(), hash: crypto.randomBytes(7).toString('hex'), - image_url: '', // deprecated, will be removed in the future + image_url: '', // * deprecated, will be removed in the future image_id: crypto.randomBytes(4).readUInt32LE() }, flags: { @@ -165,8 +165,8 @@ router.post('/', ratelimit, deviceCertificateMiddleware, async (request: express off_device: person.off_device_flag === 'Y' }, identification: { - email_code: 1, // will be overwritten before saving - email_token: '' // will be overwritten before saving + email_code: 1, // * will be overwritten before saving + email_token: '' // * will be overwritten before saving } }); @@ -265,9 +265,9 @@ router.post('/@me/devices', async (request: express.Request, response: express.R response.set('Server', 'Nintendo 3DS (http)'); response.set('X-Nintendo-Date', new Date().getTime().toString()); - // We don't care about the device attributes - // The console ignores them and PNIDs are not tied to consoles anyway - // So the server also ignores them and does not save the ones posted here + // * We don't care about the device attributes + // * The console ignores them and PNIDs are not tied to consoles anyway + // * So the server also ignores them and does not save the ones posted here // TODO - CHANGE THIS. WE NEED TO SAVE CONSOLE DETAILS !!! @@ -652,8 +652,8 @@ router.get('/@me/emails', async (request: express.Request, response: express.Res parent: pnid.email.parent ? 'Y' : 'N', primary: pnid.email.primary ? 'Y' : 'N', reachable: pnid.email.reachable ? 'Y' : 'N', - type: 'DEFAULT', // what is this? - updated_by: 'USER', // need to actually update this + type: 'DEFAULT', // * what is this? + updated_by: 'USER', // * need to actually update this validated: pnid.email.validated ? 'Y' : 'N', validated_date: pnid.email.validated_date, } diff --git a/src/services/nnas/routes/provider.ts b/src/services/nnas/routes/provider.ts index 794c6cf..1f87e8d 100644 --- a/src/services/nnas/routes/provider.ts +++ b/src/services/nnas/routes/provider.ts @@ -214,7 +214,7 @@ router.get('/nex_token/@me', async (request: express.Request, response: express. const tokenOptions = { system_type: server.device, - token_type: 0x3, // nex token, + token_type: 0x3, // * nex token, pid: pnid.pid, access_level: pnid.access_level, title_id: BigInt(parseInt(titleID, 16)), diff --git a/src/types/mongoose/pnid.ts b/src/types/mongoose/pnid.ts index 37ab267..3252c44 100644 --- a/src/types/mongoose/pnid.ts +++ b/src/types/mongoose/pnid.ts @@ -48,7 +48,7 @@ export interface IPNID { off_device: boolean; }; devices: Types.DocumentArray; - identification: { // user identification tokens + identification: { // * user identification tokens email_code: string; email_token: string; access_token: { diff --git a/src/types/services/nnas/pnid-profile.ts b/src/types/services/nnas/pnid-profile.ts index cb02669..70adea5 100644 --- a/src/types/services/nnas/pnid-profile.ts +++ b/src/types/services/nnas/pnid-profile.ts @@ -1,7 +1,7 @@ import { YesNoBoolString } from '@/types/common/yes-no-bool-string'; export interface PNIDProfile { - //accounts: {}; // * We need to figure this out; no idea what these values mean or what they do + // *accounts: {}; // * We need to figure this out; no idea what these values mean or what they do active_flag: YesNoBoolString; birth_date: string; country: string; diff --git a/src/util.ts b/src/util.ts index f5d8b18..42b0b33 100644 --- a/src/util.ts +++ b/src/util.ts @@ -209,7 +209,7 @@ export async function sendForgotPasswordEmail(pnid: mongoose.HydratedDocument