Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redis Sentinel support for api-gateway and bs58 version upgrade. #4395

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions api-gateway/configs/.env.gateway
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ MQ_MAX_PAYLOAD="1048576"
HOST_CACHE='localhost'
PORT_CACHE='6379'
ENABLE_CACHE='true'
USE_SENTINEL='false'
SENTINEL_HOSTS=''
REDIS_MASTER_NAME=''

#PINO_LOGGER
TRANSPORTS="CONSOLE, MONGO"
Expand Down
3 changes: 3 additions & 0 deletions api-gateway/configs/.env.gateway.develop
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ MQ_MAX_PAYLOAD="1048576"
HOST_CACHE='localhost'
PORT_CACHE='6379'
ENABLE_CACHE='true'
USE_SENTINEL='false'
SENTINEL_HOSTS=''
REDIS_MASTER_NAME=''

#PINO_LOGGER
TRANSPORTS="CONSOLE, MONGO"
Expand Down
3 changes: 3 additions & 0 deletions api-gateway/configs/.env.gateway.template
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ MQ_MAX_PAYLOAD=""
HOST_CACHE=''
PORT_CACHE=''
ENABLE_CACHE='true'
USE_SENTINEL='false'
SENTINEL_HOSTS=''
REDIS_MASTER_NAME=''

#PINO_LOGGER
TRANSPORTS="CONSOLE, MONGO"
Expand Down
22 changes: 18 additions & 4 deletions api-gateway/src/helpers/providers/cache-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,27 @@ export const CACHE_CLIENT = 'CACHE_CLIENT'

const HOST = process.env.HOST_CACHE;
const PORT = Number(process.env.PORT_CACHE);
const USE_SENTINEL = process.env.USE_SENTINEL === 'true';
const SENTINEL_HOSTS = process.env.SENTINEL_HOSTS?.split(',') || [];
const MASTER_NAME = process.env.REDIS_MASTER_NAME;

export const cacheProvider: Provider = {
useFactory: (): CacheClient => {
return new Cache({
host: HOST,
port: PORT,
});
if (USE_SENTINEL && SENTINEL_HOSTS.length > 0) {
return new Cache({
sentinels: SENTINEL_HOSTS.map(host => {
const [hostName, port] = host.split(':');
return { host: hostName, port: Number(port) };
}),
name: MASTER_NAME,
});
} else {
// Direct Redis connection
return new Cache({
host: HOST,
port: PORT,
});
}
},
provide: CACHE_CLIENT,
};
2 changes: 1 addition & 1 deletion common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"ajv": "^8.10.0",
"ajv-formats": "^2.1.1",
"axios": "^1.3.6",
"bs58": "^4.0.1",
"bs58": "^6.0.0",
"bson": "^6.5.0",
"dotenv": "^16.0.0",
"exceljs": "^4.4.0",
Expand Down
4 changes: 2 additions & 2 deletions common/src/hedera-modules/hashing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export class Hashing {
encode: (data: Uint8Array): string => {
return bs58.encode(data);
},
decode: (data: string): Uint8Array => {
return bs58.decode(data);
decode: (data: string): Buffer => {
return Buffer.from(bs58.decode(data));
}
}
/**
Expand Down
10 changes: 5 additions & 5 deletions common/src/helpers/vc-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { KeyType, Users, Wallet } from '../helpers/index.js';
import { IAuthUser } from '../interfaces/index.js';
import { Ed25519VerificationKey2018 } from '@transmute/ed25519-signature-2018';
import { bls12_381 } from '@noble/curves/bls12-381';
import bs58 from 'bs58';
import { Hashing } from '../hedera-modules/hashing.js';
import { DatabaseServer } from '../database-modules/index.js';

/**
Expand Down Expand Up @@ -501,10 +501,10 @@ export class VcHelper extends VCJS {
const option = method.toObject(true) as any;
switch (option.type) {
case 'Ed25519VerificationKey2018': {
const privateKeyHex = bs58
const privateKeyHex = Hashing.base58
.decode(option.privateKeyBase58)
.toString('hex')
const publicKeyHex = bs58
const publicKeyHex = Hashing.base58
.decode(option.publicKeyBase58)
.toString('hex')
if (!privateKeyHex.endsWith(publicKeyHex)) {
Expand All @@ -516,12 +516,12 @@ export class VcHelper extends VCJS {
case 'Bls12381G2Key2020': {
const privateKeyBase58 = option.privateKeyBase58;
const publicKeyBase58 = option.publicKeyBase58;
const privateKeyHex = bs58
const privateKeyHex = Hashing.base58
.decode(privateKeyBase58)
.toString('hex')
.toUpperCase();
const publicKey = bls12_381.getPublicKeyForShortSignatures(privateKeyHex);
if (publicKeyBase58 !== bs58.encode(publicKey)) {
if (publicKeyBase58 !== Hashing.base58.encode(publicKey)) {
return false;
}
keyPair = await Bls12381G2KeyPair.from(option);
Expand Down
4 changes: 2 additions & 2 deletions common/src/wallet/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SecretManager, SecretManagerBase, SecretManagerType } from '../secret-manager/index.js';
import crypto from 'crypto';
import * as bs58 from 'bs58';
import { Hashing } from '../hedera-modules/hashing.js';
import { AzureSecretManager } from '../secret-manager/azure/azure-secret-manager.js';
import { GcpSecretManager } from '../secret-manager/gcp/gcp-secret-manager.js';

Expand Down Expand Up @@ -64,7 +64,7 @@ export class Wallet {
// convert hashedKey from hex to Base58 to shoeten key length, Azure does not accept keys longet than 128 chars
// convert hashedKey from hex to Base58 to shoeten key length, GCP does not accept keys longet than 255 chars
const buffer = Buffer.from(hashedKey, 'hex');
const hashedKeyBase58 = bs58.encode(buffer);
const hashedKeyBase58 = Hashing.base58.encode(buffer);
return hashedKeyBase58;
}

Expand Down
1 change: 0 additions & 1 deletion guardian-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"ajv": "^8.10.0",
"ajv-formats": "^2.1.1",
"axios": "^1.3.6",
"bs58": "^4.0.1",
"bson": "^6.5.0",
"cors": "^2.8.5",
"cron": "^2.0.0",
Expand Down
2 changes: 1 addition & 1 deletion indexer-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"@nestjs/core": "^9.4.1",
"@nestjs/microservices": "^9.4.1",
"axios": "^1.7.2",
"bs58": "^4.0.1",
"bs58": "^6.0.0",
"axios-retry": "^3.2.4",
"cron": "^3.1.7",
"cross-blob": "^2.0.1",
Expand Down
1 change: 0 additions & 1 deletion policy-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"ajv": "^8.10.0",
"ajv-formats": "^2.1.1",
"axios": "^1.3.6",
"bs58": "^4.0.1",
"bson": "^6.5.0",
"cors": "^2.8.5",
"cron": "^2.0.0",
Expand Down