mirror of
https://github.com/PretendoNetwork/account.git
synced 2026-09-30 14:18:22 -05:00
Added missing types
This commit is contained in:
@@ -21,14 +21,14 @@ async function sendMail(options: MailerOptions): Promise<void> {
|
||||
|
||||
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 = `<tr><td width="100%" height="16px" style="line-height: 16px;"> </td></tr><tr><td class="confirm-link" bgcolor="#673db6" style="font-size: 14px; font-weight: 700; border-radius: 10px; padding: 12px" align="center"><a href="${href}" style="text-decoration: none; color: #ffffff; " width="100%">${text}</a></td></tr>`
|
||||
const button: string = `<tr><td width="100%" height="16px" style="line-height: 16px;"> </td></tr><tr><td class="confirm-link" bgcolor="#673db6" style="font-size: 14px; font-weight: 700; border-radius: 10px; padding: 12px" align="center"><a href="${href}" style="text-decoration: none; color: #ffffff; " width="100%">${text}</a></td></tr>`;
|
||||
html = html.replace(/<!--{{buttonPlaceholder}}-->/g, button);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<INEXAccount, NEXAccountModel, INEXAccountMethods>({
|
||||
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<void> {
|
||||
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<voi
|
||||
});
|
||||
|
||||
NEXAccountSchema.method('generatePassword', function generatePassword(): void {
|
||||
function character() {
|
||||
const offset = Math.floor(Math.random() * 62);
|
||||
function character(): string | number {
|
||||
const offset: number = Math.floor(Math.random() * 62);
|
||||
if (offset < 10) return offset;
|
||||
if (offset < 36) return String.fromCharCode(offset + 55);
|
||||
return String.fromCharCode(offset + 61);
|
||||
}
|
||||
|
||||
const output = [];
|
||||
const output: string[] = [];
|
||||
|
||||
while (output.length < 16) {
|
||||
output.push(character());
|
||||
output.push(String(character()));
|
||||
}
|
||||
|
||||
this.set('password', output.join(''));
|
||||
|
||||
@@ -7,7 +7,7 @@ import got from 'got';
|
||||
import Mii from 'mii-js';
|
||||
import { DeviceSchema } from '@/models/device';
|
||||
import util from '@/util';
|
||||
import { IPNID, IPNIDMethods, PNIDModel } from '@/types/mongoose/pnid';
|
||||
import { HydratedPNIDDocument, IPNID, IPNIDMethods, PNIDModel } from '@/types/mongoose/pnid';
|
||||
|
||||
const PNIDSchema = new Schema<IPNID, PNIDModel, IPNIDMethods>({
|
||||
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<void> {
|
||||
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<void> {
|
||||
PNIDSchema.method('generateEmailValidationCode', async function generateEmailValidationCode(): Promise<void> {
|
||||
// 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<void> {
|
||||
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<void> {
|
||||
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<IPNID, PNIDModel>('PNID', PNIDSchema);
|
||||
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user