Skip to content

Commit

Permalink
Merge pull request #1032 from aura-nw/Baseline/main_20231127
Browse files Browse the repository at this point in the history
Baseline/main 20231127
  • Loading branch information
nhphuc2411 authored Nov 28, 2023
2 parents 6b073c6 + 73cc0f3 commit b620afb
Show file tree
Hide file tree
Showing 63 changed files with 7,714 additions and 1,882 deletions.
17 changes: 17 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,20 @@ LIMITED_PRIVATE_NAME_TAG=10

# ReCaptcha
GOOGLE_RECAPTCHA_SECRET_KEY=

# Firebase
FCM_PROJECT_ID=
FCM_PRIVATE_KEY=
FCM_CLIENT_EMAIL=

# Watch List
WATCH_LIST_LIMIT_ADDRESS=10

COIN_MARKET_CAP_API_EP=https://pro-api.coinmarketcap.com/v2/
COIN_MARKET_CAP_API_KEY=
PRICE_HOST_SYNC=COINGECKO
PRICE_TIME_SYNC=0 */3 * * * *

GECKOTERMINAL_API=https://api.geckoterminal.com/api/v2/
GECKOTERMINAL_POOL=bsc
COIN_ADDRESS=0x9f1a332c0657ce3f90666ad38dbe2e92793abf5c
5,858 changes: 4,045 additions & 1,813 deletions package-lock.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@
"test:cov": "jest --coverage",
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
"test:e2e": "jest --config ./test/jest-e2e.json",
"migration:generate": "node_modules/.bin/typeorm migration:generate -n",
"migration:run": "node_modules/.bin/typeorm migration:run",
"migration:revert": "node_modules/.bin/typeorm migration:revert"
"migration:generate": "rm -rf dist && nest build && node_modules/.bin/typeorm migration:generate -n",
"migration:run": "rm -rf dist && nest build && node_modules/.bin/typeorm migration:run",
"migration:revert": "rm -rf dist && nest build && node_modules/.bin/typeorm migration:revert"
},
"dependencies": {
"@aws-crypto/client-node": "^4.0.0",
"@aws-sdk/client-kms": "^3.445.0",
"@bull-board/api": "^5.0.0",
"@bull-board/express": "^5.0.0",
"@cosmjs/amino": "^0.29.4",
Expand All @@ -46,7 +47,6 @@
"@nestjs/swagger": "^5.1.0",
"@nestjs/typeorm": "^8.0.2",
"@nestlab/google-recaptcha": "^3.5.0",
"aws-sdk": "^2.1429.0",
"bcrypt": "^5.1.0",
"bech32": "^2.0.0",
"bignumber.js": "^9.0.2",
Expand All @@ -56,6 +56,7 @@
"class-transformer": "^0.4.0",
"class-validator": "^0.13.1",
"cookie-parser": "^1.4.6",
"firebase-admin": "^11.11.0",
"google-auth-library": "^8.8.0",
"handlebars": "^4.7.7",
"joi": "^17.4.2",
Expand Down
4 changes: 4 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { PrivateNameTagModule } from './components/private-name-tag/private-name
import { PublicNameTagModule } from './components/public-name-tag/public-name-tag.module';
import { ExportCsvModule } from './components/export-csv/export-csv.module';
import { GoogleRecaptchaModule } from '@nestlab/google-recaptcha/google-recaptcha.module';
import { NotificationModule } from './components/notification/notification.module';
import { WatchListModule } from './components/watch-list/watch-list.module';

@Module({
imports: [
Expand All @@ -31,9 +33,11 @@ import { GoogleRecaptchaModule } from '@nestlab/google-recaptcha/google-recaptch
Cw20TokenModule,
SoulboundTokenModule,
PrivateNameTagModule,
NotificationModule,
PublicNameTagModule,
ExportCsvModule,
MailModule,
WatchListModule,
ConfigModule.forRoot({
isGlobal: true,
}),
Expand Down
5 changes: 4 additions & 1 deletion src/auth/jwt/jwt-auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { User } from '../../shared/entities/user.entity';
import { JwtPayload } from './jwt-auth.strategy';
import * as appConfig from '../../shared/configs/configuration';
import { UserService } from '../../components/user/user.service';

type JwtPayload = { sub: number; email: string };

export type Tokens = { accessToken: string; refreshToken: string };

@Injectable()
Expand Down Expand Up @@ -45,6 +46,8 @@ export class JwtAuthService {
throw new UnauthorizedException('User not found in DB.');
}

this.userService.checkLastRequiredLogin(user, refreshTokenDecoded.iat);

const newToken = this.login(user);

return newToken;
Expand Down
11 changes: 9 additions & 2 deletions src/auth/jwt/jwt-auth.strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { Injectable } from '@nestjs/common';
import { UserService } from '../../components/user/user.service';
import { ConfigService } from '@nestjs/config';

export type JwtPayload = { sub: number; email: string };
type JwtPayloadDecoded = {
sub: number;
email: string;
iat: number;
exp: number;
};

@Injectable()
export class JwtAuthStrategy extends PassportStrategy(Strategy) {
Expand All @@ -19,11 +24,13 @@ export class JwtAuthStrategy extends PassportStrategy(Strategy) {
});
}

async validate(payload: JwtPayload) {
async validate(payload: JwtPayloadDecoded) {
const user = await this.userService.findOneById(payload.sub);

this.userService.checkRole(user);

this.userService.checkLastRequiredLogin(user, payload.iat);

return { id: payload.sub, email: payload.email };
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/auth/password/dtos/create-user-with-password.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { IsEmail, Matches } from 'class-validator';
import { MatchPassword } from '../../../components/user/validators/validate-match-password';
import { IsUnique } from '../../../components/user/validators/validate-unique';
import { REGEX_PARTERN } from '../../../shared';
import { Transform } from 'class-transformer';

export class CreateUserWithPasswordDto {
@ApiProperty()
@IsEmail()
@Transform(({ value }) => value.toLowerCase())
@IsUnique('email', {
message: 'The email you entered has already been used.',
})
Expand Down
2 changes: 2 additions & 0 deletions src/auth/password/dtos/login-with-password.dto.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { ApiProperty } from '@nestjs/swagger';
import { Transform } from 'class-transformer';
import { IsString } from 'class-validator';

export class LoginUserWithPassword {
@ApiProperty()
@IsString()
@Transform(({ value }) => value.toLowerCase())
email: string;

@ApiProperty()
Expand Down
2 changes: 2 additions & 0 deletions src/auth/password/dtos/reset-password.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty, Matches } from 'class-validator';
import { MatchPassword } from '../../../components/user/validators/validate-match-password';
import { REGEX_PARTERN } from '../../../shared';
import { Transform } from 'class-transformer';

export class ResetPasswordDto {
@ApiProperty()
@IsNotEmpty()
@Transform(({ value }) => value.toLowerCase())
email: string;

@ApiProperty()
Expand Down
24 changes: 24 additions & 0 deletions src/components/cw20-token/repositories/token-markets.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,28 @@ export class TokenMarketsRepository extends Repository<TokenMarkets> {

return { list, count };
}

async countCw20TokensHavingCoinId() {
const sqlSelect = `tm.contract_address, tm.coin_id`;

const queryBuilder = this.createQueryBuilder('tm')
.select(sqlSelect)
.where("tm.coin_id <> '' ")
.andWhere("tm.coin_id <> 'aura-network' ");

return await queryBuilder.getCount();
}

async getCw20TokenMarketsHavingCoinId(limit: number, pageIndex: number) {
const sqlSelect = ` tm.coin_id`;

const queryBuilder = this.createQueryBuilder('tm')
.select(sqlSelect)
.where("tm.coin_id <> '' ")
.andWhere("tm.coin_id <> 'aura-network' ")
.limit(limit)
.offset(pageIndex * limit);

return await queryBuilder.getRawMany();
}
}
21 changes: 12 additions & 9 deletions src/components/encryption/encryption.service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Injectable, OnModuleInit } from '@nestjs/common';
import * as appConfig from '../../shared/configs/configuration';
import { KMS } from 'aws-sdk';
import { KMS } from '@aws-sdk/client-kms';
import { InjectRepository } from '@nestjs/typeorm';
import { CipherKey } from '../../shared/entities/cipher-key.entity';
import { Repository } from 'typeorm';
import { PlaintextType } from 'aws-sdk/clients/kms';
type PlaintextType = Buffer | Uint8Array | Blob | string;

@Injectable()
export class EncryptionService implements OnModuleInit {
Expand All @@ -19,8 +19,10 @@ export class EncryptionService implements OnModuleInit {
this.config = appConfig.default();

this.kms = new KMS({
accessKeyId: this.config.kms.accessKeyId,
secretAccessKey: this.config.kms.secretAccessKey,
credentials: {
accessKeyId: this.config.kms.accessKeyId,
secretAccessKey: this.config.kms.secretAccessKey,
},
region: this.config.kms.region,
apiVersion: this.config.kms.apiVersion,
});
Expand All @@ -37,12 +39,13 @@ export class EncryptionService implements OnModuleInit {
if (key) {
return;
}
const { CiphertextBlob } = await this.kms
.generateDataKey({ KeyId, KeySpec })
.promise();
const { CiphertextBlob } = await this.kms.generateDataKey({
KeyId,
KeySpec,
});

const cipherKey = new CipherKey();
cipherKey.cipher_text = CiphertextBlob.toString('hex');
cipherKey.cipher_text = CiphertextBlob.toString();
await this.cipherKeyRepository.save(cipherKey);
}

Expand All @@ -55,7 +58,7 @@ export class EncryptionService implements OnModuleInit {
}

const CiphertextBlob = Buffer.from(cipherKey.cipher_text, 'hex');
const key = await this.kms.decrypt({ CiphertextBlob }).promise();
const key = await this.kms.decrypt({ CiphertextBlob });
return key.Plaintext;
}

Expand Down
46 changes: 26 additions & 20 deletions src/components/export-csv/services/export-csv.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,24 @@ export class ExportCsvService {
userId = null,
) {
this.logger.log(ctx, `${this.exportTransactionDataToCSV.name} was called!`);

switch (payload.dataType) {
case TYPE_EXPORT.ExecutedTxs:
return this.executed(payload);
case TYPE_EXPORT.AuraTxs:
return this.coinTransfer(payload, userId);
case TYPE_EXPORT.FtsTxs:
return this.tokenTransfer(payload, userId);
case TYPE_EXPORT.NftTxs:
return this.nftTransfer(payload, userId);
default:
break;
try {
switch (payload.dataType) {
case TYPE_EXPORT.ExecutedTxs:
return this.executed(payload);
case TYPE_EXPORT.AuraTxs:
return this.coinTransfer(payload, userId);
case TYPE_EXPORT.FtsTxs:
return this.tokenTransfer(payload, userId);
case TYPE_EXPORT.NftTxs:
return this.nftTransfer(payload, userId);
default:
break;
}
} catch (err) {
this.logger.error(
ctx,
`Error export executed ${err.message} ${err.stack}`,
);
}
}

Expand Down Expand Up @@ -92,10 +98,10 @@ export class ExportCsvService {

const txs = TransactionHelper.convertDataAccountTransaction(
response,
envConfig.chain_info.currencies[0],
envConfig?.chainConfig?.chain_info?.currencies[0],
payload.dataType,
payload.address,
envConfig.coins,
envConfig?.chainConfig?.coins,
);

const fields = TX_HEADER.EXECUTED;
Expand Down Expand Up @@ -149,10 +155,10 @@ export class ExportCsvService {

const txs = TransactionHelper.convertDataAccountTransaction(
response,
envConfig.chain_info.currencies[0],
envConfig?.chainConfig?.chain_info?.currencies[0],
payload.dataType,
payload.address,
envConfig.coins,
envConfig?.chainConfig?.coins,
);

let lstPrivateName;
Expand Down Expand Up @@ -244,10 +250,10 @@ export class ExportCsvService {

const txs = TransactionHelper.convertDataAccountTransaction(
response,
envConfig.chain_info.currencies[0],
envConfig?.chainConfig?.chain_info?.currencies[0],
payload.dataType,
payload.address,
envConfig.coins,
envConfig?.chainConfig?.coins,
);

let lstPrivateName;
Expand Down Expand Up @@ -332,10 +338,10 @@ export class ExportCsvService {

const txs = TransactionHelper.convertDataAccountTransaction(
response,
envConfig.chain_info.currencies[0],
envConfig?.chainConfig?.chain_info?.currencies[0],
payload.dataType,
payload.address,
envConfig.coins,
envConfig?.chainConfig?.coins,
);

let lstPrivateName;
Expand Down
Loading

0 comments on commit b620afb

Please sign in to comment.