Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
138 commits
Select commit Hold shift + click to select a range
464c77f
feat: implement basic proto file
OmegaCreations Jun 8, 2025
268a99a
feat: Duplex stream with specific payload message events.
OmegaCreations Jun 10, 2025
7b7888a
feat: Duplex stream with specific payload message events.
OmegaCreations Jun 10, 2025
6373548
feat: Create typescript interfaces for duplex stream message model
OmegaCreations Jun 10, 2025
255e567
feat: Add description to typescript interfaces
OmegaCreations Jun 10, 2025
7edca58
feat: implement serialization and deserialization methods
OmegaCreations Jun 10, 2025
0485204
feat: add package dependencies and write unit tests for serialization…
OmegaCreations Jun 10, 2025
58666d5
fix: fixed oneof variable naming
OmegaCreations Jun 10, 2025
0118271
feat: Duplex stream with specific payload message events.
OmegaCreations Jun 10, 2025
7c5d552
feat: Create typescript interfaces for duplex stream message model
OmegaCreations Jun 10, 2025
4b18459
feat: implement serialization and deserialization methods
OmegaCreations Jun 10, 2025
dba904c
feat: add package dependencies and write unit tests for serialization…
OmegaCreations Jun 10, 2025
273b8e2
feat: Create grpc wrapper with basic connection manager and central s…
OmegaCreations Jun 10, 2025
6467c55
fix: fix grpc addresses to properly connect both client and central s…
OmegaCreations Jun 10, 2025
1a86d49
fix: refactor comments
OmegaCreations Jun 11, 2025
bec195c
fix: change central system class name to avoid conflicts with central…
OmegaCreations Jun 11, 2025
c6a3f01
feat: implement Connection class and a map storing all receiving and …
OmegaCreations Jun 11, 2025
fb12e55
feat: implement replacing new token for client from central system
OmegaCreations Jun 11, 2025
63faee3
feat: implement token revokation by changing connection status
OmegaCreations Jun 11, 2025
456bf84
fix: remove unnecessary params
OmegaCreations Jun 11, 2025
93c3a51
fix: fix enum naming
OmegaCreations Jun 17, 2025
ff0faf0
fix: fix proto types order based on Bookkeeping standards
OmegaCreations Jun 17, 2025
d207f78
Merge branch 'feature/TKN/OGUI-1702/basic-proto-file' of github.com:A…
OmegaCreations Jun 17, 2025
fb6c39c
fix: add copyright banner
OmegaCreations Jun 17, 2025
8106fe1
Merge branch 'feature/TKN/OGUI-1702/basic-proto-file' of github.com:A…
OmegaCreations Jun 17, 2025
72042c8
fix: add copyright banner and change enum naming convention
OmegaCreations Jun 17, 2025
d762f9f
Merge branch 'feature/TKN/OGUI-1703/basic-typescript-interfaces' of g…
OmegaCreations Jun 17, 2025
b70cf9e
fix: fix serialization comments and tests
OmegaCreations Jun 17, 2025
aff4c59
Merge branch 'feature/TKN/OGUI-1704/data-serialization-utils' of gith…
OmegaCreations Jun 17, 2025
9de3ce5
Merge branch 'dev' into feature/TKN/OGUI-1703/basic-typescript-interf…
graduta Jun 18, 2025
bdba63d
feat: add description comments and implement .listen() instead of aut…
OmegaCreations Jul 8, 2025
326eea5
fix: change enum values to numbers
OmegaCreations Jul 8, 2025
4011499
Merge branch 'feature/TKN/OGUI-1703/basic-typescript-interfaces' of g…
OmegaCreations Jul 8, 2025
5857652
fix: move test directory
OmegaCreations Jul 8, 2025
54447ea
feat: add webui logger instead of console logs and fix paths
OmegaCreations Jul 8, 2025
af429ce
Merge branch 'feature/TKN/OGUI-1703/basic-typescript-interfaces' of g…
OmegaCreations Jul 8, 2025
9db612e
feat: write tests for central system and connection manager
OmegaCreations Jul 9, 2025
ec193ca
Merge branch 'feature/TKN/OGUI-1705/client-central-basic-stream' of g…
OmegaCreations Jul 9, 2025
d0f4dad
feat: muldularize connection management. Add project building.
OmegaCreations Jul 10, 2025
b4a0bf9
fix: fix connection and remove exponential backoff for simplified ver…
OmegaCreations Jul 10, 2025
3b49923
Fix: Unused function import
OmegaCreations Jul 13, 2025
8d9c89a
fix: test setup fixes
OmegaCreations Jul 20, 2025
1081941
Merge branch 'feature/TKN/OGUI-1708/basic-connection-class' of github…
OmegaCreations Jul 20, 2025
b6695a4
fix: fix tscofing for js builds and typescript files/tests runtime
OmegaCreations Jul 28, 2025
e79215c
feat: refactor code for command design pattern
OmegaCreations Aug 4, 2025
90d713d
feat: unit tests for token revokation
OmegaCreations Aug 4, 2025
e079438
feat: implement token revokation logic and testing
OmegaCreations Aug 5, 2025
5527944
feat: implement connection direction info inside of payload
OmegaCreations Aug 5, 2025
090da6b
fix: fix tests
OmegaCreations Aug 7, 2025
fd0e1dd
feat: implement command for new token from central system
OmegaCreations Aug 7, 2025
5965abe
feat: add missing comments, banners and tests
OmegaCreations Aug 7, 2025
4562762
fix: fixed banner processing. removed console logs
OmegaCreations Aug 7, 2025
1fd0579
fix: fix logging
OmegaCreations Aug 16, 2025
079d811
Merge branch 'feature/TKN/OGUI-1705/client-central-basic-stream' of g…
OmegaCreations Aug 16, 2025
99530a8
feat: change parameters to config objects
OmegaCreations Aug 16, 2025
5efb5ca
fix: fix deafult values in config
OmegaCreations Aug 16, 2025
ec36841
feat: add github actions for wrapper tests
OmegaCreations Aug 16, 2025
836ff51
fix: paths
OmegaCreations Aug 16, 2025
c61ac97
fix: pathing
OmegaCreations Aug 16, 2025
351099d
Merge branch 'feature/TKN/OGUI-1710/handle-newly-generated-token' of …
OmegaCreations Aug 16, 2025
ec8ea1a
fix: fix tests
OmegaCreations Aug 16, 2025
6ac9f71
feat: implement simple connection peer to peers
OmegaCreations Aug 27, 2025
5b759d8
fix: refactor ConnectionManager and remove unnecessary code.
OmegaCreations Aug 28, 2025
f49939a
Merge branch 'dev' of github.com:AliceO2Group/WebUi into feature/TKN/…
OmegaCreations Aug 28, 2025
d43912a
fix: remove unused imports
OmegaCreations Aug 28, 2025
6ba86f2
fix: remove unnecessary utils
OmegaCreations Aug 31, 2025
2569c5c
fix: remove unused variable
OmegaCreations Aug 31, 2025
dd246bd
Merge branch 'dev' of github.com:AliceO2Group/WebUi into feature/TKN/…
OmegaCreations Aug 31, 2025
21fb63e
fix: refactor unit tests
OmegaCreations Aug 31, 2025
957a7be
feat: update unit tests for p2p connections
OmegaCreations Aug 31, 2025
a7b81a2
Potential fix for code scanning alert no. 236: Unused variable, impor…
OmegaCreations Sep 2, 2025
b8edd56
feat: implement reconnection scheduler
OmegaCreations Sep 2, 2025
863438b
fix: fix scheduler
OmegaCreations Sep 3, 2025
542e0f6
fix: fix imports
OmegaCreations Sep 3, 2025
789afb6
Merge branch 'feature/TKN/OGUI-1705/client-central-basic-stream' of g…
OmegaCreations Sep 25, 2025
b866463
feat: implement secure connection and fix unit tests
OmegaCreations Sep 25, 2025
8c7bceb
feat: add testing certificates
OmegaCreations Sep 25, 2025
1ce0588
Potential fix for code scanning alert no. 252: Unused variable, impor…
OmegaCreations Sep 26, 2025
27f7015
feat: add implementation of auth interceptor
OmegaCreations Sep 27, 2025
e0da424
feat: update connection for tokens, fix decryption in auth intercepto…
OmegaCreations Sep 28, 2025
20d6244
feat: add handling failed auths in the auth interceptor
OmegaCreations Sep 28, 2025
37e43ec
feat: create SecurityContext class and add signing alg verification t…
OmegaCreations Sep 28, 2025
fe15cd3
fix: fix interceptor and write tests
OmegaCreations Sep 29, 2025
cbc3ede
fix: unit tests and update token interface
OmegaCreations Oct 1, 2025
cd070f4
Merge branch 'dev' of github.com:AliceO2Group/WebUi into feature/TKN/…
OmegaCreations Oct 1, 2025
8104655
feat: implement broadcasting on central system
OmegaCreations Oct 1, 2025
e5151f1
Potential fix for code scanning alert no. 254: Unused variable, impor…
OmegaCreations Oct 4, 2025
8c72e04
Potential fix for code scanning alert no. 254: Unused variable, impor…
OmegaCreations Oct 4, 2025
f41266f
Merge branch 'dev' of github.com:AliceO2Group/WebUi into feature/TKN/…
OmegaCreations Nov 6, 2025
37a8021
fix: remove duplicates
OmegaCreations Nov 6, 2025
feeb637
fix: unit tests
OmegaCreations Nov 6, 2025
44f58e4
fix: move .gitignore to parent .gitignore
OmegaCreations Nov 6, 2025
c87f1f1
fix: default wrapper port changed to 4100
OmegaCreations Nov 6, 2025
b2f24c6
fix: change private variables naming
OmegaCreations Nov 6, 2025
d043717
fix: rename directories to start with small letters
OmegaCreations Nov 6, 2025
48c51dc
fix: fix imports and add breaklines after banners
OmegaCreations Nov 6, 2025
9ae5c9b
feat: inform about central system address on connection
OmegaCreations Nov 6, 2025
75a9f14
fix: tests testing initializtion of object shouuld have object creati…
OmegaCreations Nov 6, 2025
f6cb712
feat: implement missing descriptions
OmegaCreations Nov 6, 2025
d0c57bf
fix: make sure that proto file enums have number 0 with default, unde…
OmegaCreations Nov 6, 2025
3c82edc
feat: implement eslint and fix its errors
OmegaCreations Nov 6, 2025
6552480
Merge branch 'feature/TKN/OGUI-1710/handle-newly-generated-token' of …
OmegaCreations Nov 11, 2025
95ff34f
Merge branch 'feature/TKN/OGUI-1746/add-github-actions-for-wrapper' o…
OmegaCreations Nov 11, 2025
a253f51
fix: fix files, unit tests and add tests for connection
OmegaCreations Nov 12, 2025
866f599
fix: rebuild package lock
OmegaCreations Nov 12, 2025
b85554f
Merge branch 'dev' into feature/TKN/OGUI-1747/simple-client-p2p-conne…
OmegaCreations Nov 12, 2025
9d05309
Merge branch 'dev' of github.com:AliceO2Group/WebUi into feature/TKN/…
OmegaCreations Nov 13, 2025
74af151
Merge branch 'feature/TKN/OGUI-1747/simple-client-p2p-connection' of …
OmegaCreations Nov 13, 2025
3d832ba
fix: fix rebase
OmegaCreations Nov 13, 2025
f0e4643
fix: tests, remove express, fix comments in gRPCWrapper
OmegaCreations Nov 13, 2025
baa9511
fix: tests
OmegaCreations Nov 13, 2025
6d658fb
feat: move peer listening to separate method and util file
OmegaCreations Nov 13, 2025
16a2ec6
fix: remove additional description
OmegaCreations Nov 13, 2025
b742ccc
Merge branch 'dev' into feature/TKN/OGUI-1747/simple-client-p2p-conne…
OmegaCreations Nov 13, 2025
0d22a81
Merge branch 'dev' into feature/TKN/OGUI-1747/simple-client-p2p-conne…
OmegaCreations Nov 16, 2025
1009225
Merge branch 'dev' into feature/TKN/OGUI-1747/simple-client-p2p-conne…
OmegaCreations Nov 18, 2025
a2d72da
Merge branch 'feature/TKN/OGUI-1747/simple-client-p2p-connection' of …
OmegaCreations Nov 18, 2025
3bbc627
feat: rebase, write tests for reconnection schaduler and fix it
OmegaCreations Nov 18, 2025
0eda640
Merge branch 'feature/TKN/OGUI-1754/create-reconnection-scheduler' of…
OmegaCreations Nov 20, 2025
3960bb1
fix: rebase and fix rebase and unit tests
OmegaCreations Nov 20, 2025
2526344
fix: binding in peerListener, imports and unit tests
OmegaCreations Nov 20, 2025
2e5061d
Merge branch 'dev' into feature/TKN/OGUI-1755/secure-connections-with…
OmegaCreations Nov 26, 2025
c6851e2
Merge branch 'feature/TKN/OGUI-1755/secure-connections-with-certifica…
OmegaCreations Nov 26, 2025
a3b8c55
Merge branch 'feature/TKN/OGUI-1773/handle-token-validation-for-p2p-c…
OmegaCreations Nov 26, 2025
9237316
Merge branch 'dev' of github.com:AliceO2Group/WebUi into feature/TKN/…
OmegaCreations Nov 27, 2025
0e256d6
fix: rebase
OmegaCreations Nov 27, 2025
0e1f7d4
Merge branch 'dev' into feature/TKN/OGUI-1755/secure-connections-with…
OmegaCreations Dec 4, 2025
5149f88
Merge branch 'feature/TKN/OGUI-1755/secure-connections-with-certifica…
OmegaCreations Dec 4, 2025
95c13cf
fix: fix rebase
OmegaCreations Dec 4, 2025
e6b20e9
fix: rebase and coverage of branches
OmegaCreations Dec 4, 2025
722fe43
fix: package-lock reinstall for pipeline
OmegaCreations Dec 4, 2025
eeb5207
fix: remove unused var
OmegaCreations Dec 4, 2025
e35533b
fix: tests
OmegaCreations Dec 4, 2025
bc520d2
fix: temp rename
OmegaCreations Dec 4, 2025
d2234c4
fix: rename back
OmegaCreations Dec 4, 2025
5348b12
fix: unit test
OmegaCreations Dec 4, 2025
b4ac84e
fix: imports
OmegaCreations Dec 4, 2025
c334481
Merge branch 'feature/TKN/OGUI-1773/handle-token-validation-for-p2p-c…
OmegaCreations Dec 4, 2025
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
756 changes: 749 additions & 7 deletions Tokenization/backend/wrapper/package-lock.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Tokenization/backend/wrapper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"dependencies": {
"@grpc/grpc-js": "^1.13.4",
"@grpc/proto-loader": "^0.7.15",
"express": "^5.1.0",
"jose": "^6.1.0",
"ts-node": "^10.9.2",
"typescript": "^5.8.3"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import * as grpc from '@grpc/grpc-js';
import * as protoLoader from '@grpc/proto-loader';
import { LogManager } from '@aliceo2/web-ui';
import * as fs from 'fs';
import type { CentralSystemConfig } from '../models/config.model';
import type { DuplexMessageModel } from '../models/message.model';

/**
Expand All @@ -24,11 +26,15 @@ export class CentralSystemWrapper {
// Config
private _protoPath: string;

// Utilities
private _logger = LogManager.getLogger('CentralSystemWrapper');

// Class properties
private _server: grpc.Server;
private _port: number;

// Certificates paths
private _serverCerts: CentralSystemConfig['serverCerts'];

// Utilities
private _logger = LogManager.getLogger('CentralSystemWrapper');

// Clients management
private _clients = new Map<string, grpc.ServerDuplexStream<any, any>>();
Expand All @@ -38,8 +44,15 @@ export class CentralSystemWrapper {
* Initializes the Wrapper for CentralSystem.
* @param port The port number to bind the gRPC server to.
*/
constructor(protoPath: string, private port: number) {
this._protoPath = protoPath;
constructor(config: CentralSystemConfig) {
if (!config.protoPath || !config.serverCerts?.caCertPath || !config.serverCerts?.certPath || !config.serverCerts?.keyPath) {
throw new Error('Invalid CentralSystemConfig provided');
}

this._protoPath = config.protoPath;
this._serverCerts = config.serverCerts;
this._port = config.port ?? 50051;

this._server = new grpc.Server();
this.setupService();
}
Expand Down Expand Up @@ -115,7 +128,7 @@ export class CentralSystemWrapper {

// Handle stream error event
call.on('error', (err) => {
this._logger.infoMessage(`Stream error from client ${clientIp}:`, err);
this._logger.errorMessage(`Stream error from client ${clientIp}:`, err);
this.cleanupClient(peer);
});
}
Expand Down Expand Up @@ -156,6 +169,17 @@ export class CentralSystemWrapper {
}
}

public broadcastEvent(data: DuplexMessageModel): void {
this.clients.forEach((client, ip) => {
try {
client.write(data);
this.logger.infoMessage(`Broadcasted event to ${ip}:`, data);
} catch (err) {
this.logger.errorMessage(`Error broadcasting to ${ip}:`, err);
}
});
}

/**
* Gets all connected client IPs
* @returns Array of connected client IPs
Expand All @@ -168,10 +192,27 @@ export class CentralSystemWrapper {
* Starts the gRPC server and binds it to the specified in class port.
*/
public listen() {
const addr = `localhost:${this.port}`;
this._server.bindAsync(addr, grpc.ServerCredentials.createInsecure(), (err, _port) => {
const addr = `localhost:${this._port}`;

// Create mTLS secure gRPC server
const caCert = fs.readFileSync(this._serverCerts.caCertPath);
const centralKey = fs.readFileSync(this._serverCerts.keyPath);
const centralCert = fs.readFileSync(this._serverCerts.certPath);

const sslCreds = grpc.ServerCredentials.createSsl(
caCert,
[
{
private_key: centralKey,
cert_chain: centralCert,
},
],
true
);

this._server.bindAsync(addr, sslCreds, (err, _port) => {
if (err) {
this._logger.infoMessage('Server bind error:', err);
this._logger.errorMessage('Server bind error:', err);
return;
}
this._logger.infoMessage(`CentralSytem started listening on ${addr}`);
Expand Down
159 changes: 134 additions & 25 deletions Tokenization/backend/wrapper/src/client/connection/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,60 +12,132 @@
* or submit itself to any jurisdiction.
*/

import type { ConnectionDirection } from '../../models/message.model';
import type { ConnectionHeaders, FetchOptions, FetchResponse } from '../../models/connection.model';
import { ConnectionDirection } from '../../models/message.model';
import type { ConnectionHeaders, FetchOptions, FetchResponse, TokenPayload } from '../../models/connection.model';
import { ConnectionStatus } from '../../models/connection.model';
import * as grpc from '@grpc/grpc-js';
import { LogManager } from '@aliceo2/web-ui';

type ConnectionCerts = {
caCert: Buffer;
clientCert: Buffer;
clientKey: Buffer;
};

/**
* @description This class represents a connection to a target client and manages sending messages to it.
*/
export class Connection {
private _token: string;
private _targetAddress: string;
private _jweToken: string;
private _status: ConnectionStatus;
private _peerClient: any;
private _peerClient?: any; // A client grpc connection instance

// Security management variables
private _clientSerialNumber?: string; // The certificate SN used to uniquely identify the peer.
private _lastActiveTimestamp: number; // Timestamp of the last successful request (for garbage collection).
private _authFailures: number; // Counter for consecutive authentication failures (for anti-DDoS/throttling).
private _cachedTokenPayload?: TokenPayload; // Cache of the successfully verified token payload.

public targetAddress: string;
public direction: ConnectionDirection;

// Utils
private _logger;

/**
* Creates a new Connection instance with the given token, target address, and connection direction.
*
* @param token - The authentication token for the connection.
* @param jweToken - The encrypted JWE token for the connection.
* @param targetAddress - The unique address of the target client.
* @param direction - The direction of the connection (e.g., sending or receiving).
* @param clientSN - Optional serial number of the peer's certificate (used for lookups).
*/
constructor(token: string, targetAddress: string, direction: ConnectionDirection, peerCtor: any) {
this._token = token;
this._targetAddress = targetAddress;
this._peerClient = new peerCtor(targetAddress, grpc.credentials.createInsecure());
constructor(jweToken: string, targetAddress: string, direction: ConnectionDirection, clientSN?: string) {
this._jweToken = jweToken;
this.targetAddress = targetAddress;
this.direction = direction;

// Initialize state fields
this._clientSerialNumber = clientSN;
this._lastActiveTimestamp = Date.now();
this._authFailures = 0;
this._status = ConnectionStatus.CONNECTED;

this._logger = LogManager.getLogger(`Connection ${targetAddress}`);
}

/**
* Creates the mTLS gRPC client and attaches it to the connection.
* This method is REQUIRED ONLY for outbound (SENDING) connections.
* * @param peerCtor - The constructor for the gRPC client to be used for communication.
* @param connectionCerts - Required sending client certificates for mTLS.
*/
public createSslTunnel(peerCtor: any, connectionCerts: ConnectionCerts): void {
if (this.direction !== ConnectionDirection.SENDING) {
this._logger.warnMessage('Attempted to create SSL tunnel on a RECEIVING connection. This is usually unnecessary.');
}

if (!connectionCerts.caCert || !connectionCerts.clientCert || !connectionCerts.clientKey) {
throw new Error('Connection certificates are required to create an mTLS tunnel.');
}

// Create grpc credentials
const sslCreds = grpc.credentials.createSsl(connectionCerts.caCert, connectionCerts.clientKey, connectionCerts.clientCert);

this._peerClient = new peerCtor(this.targetAddress, sslCreds);
this.status = ConnectionStatus.CONNECTED;
}

/**
* Replace newly generated token
* @param token New token to be replaced
* @param jweToken New token to be replaced
*/
public set token(token: string) {
this._token = token;
public set token(jweToken: string) {
this._jweToken = jweToken;
}

/**
* Revokes the token of the connection, effectively invalidating it.
* The connection status is set to UNAUTHORIZED.
* Revoke current token and set status of unauthorized connection
*/
public handleRevokeToken(): void {
this._token = '';
this._status = ConnectionStatus.UNAUTHORIZED;
this._jweToken = '';
this.status = ConnectionStatus.UNAUTHORIZED;
}

/**
* Handles a successful authentication event. Updates the active timestamp,
* resets the failure counter, and caches the new token payload.
* This is crucial for high-performance applications to avoid re-validating the same token.
* @param payload The decoded and verified token payload.
*/
public handleSuccessfulAuth(payload: TokenPayload): void {
this._lastActiveTimestamp = Date.now();
this._authFailures = 0;
this._cachedTokenPayload = payload;
this.status = ConnectionStatus.CONNECTED;
}

/**
* Handles an authentication failure. Increments the failure counter.
* If the failure count exceeds a local threshold, the connection is locally marked as BLOCKED.
* @returns The new count of consecutive failures.
*/
public handleFailedAuth(): number {
this._authFailures += 1;

// Local throttling mechanism
if (this._authFailures >= 5) {
this.status = ConnectionStatus.BLOCKED;
}
return this._authFailures;
}

/**
* Returns token for this Connection object
* @returns Connection token
*/
public get token(): string {
return this._token;
return this._jweToken;
}

/**
Expand All @@ -77,19 +149,51 @@ export class Connection {
}

/**
* Sets the status of this connection.
* @param status The new status of the connection.
* Updates the status of the connection.
* @param status New status
*/
public set status(status: ConnectionStatus) {
this._status = status;
}

/**
* Returns target address for this Connection object
* @returns Target address
* Returns the client's Serial Number (SN).
* @returns The client's serial number or undefined.
*/
public get serialNumber(): string | undefined {
return this._clientSerialNumber;
}

/**
* Sets the client's Serial Number. Primarily used for RECEIVING connections
* where the SN is extracted during the first mTLS handshake in the interceptor.
* @param serialNumber The serial number string.
*/
public set serialNumber(serialNumber: string | undefined) {
this._clientSerialNumber = serialNumber;
}

/**
* Returns the timestamp of the last successful interaction.
* @returns UNIX timestamp in milliseconds.
*/
public get lastActiveTimestamp(): number {
return this._lastActiveTimestamp;
}

/**
* Returns the cached token payload.
* @returns The cached payload or undefined.
*/
public get targetAddress(): string {
return this._targetAddress;
public get cachedTokenPayload(): TokenPayload | undefined {
return this._cachedTokenPayload;
}

/**
* Attaches gRPC client to that connection
*/
public attachGrpcClient(client: any): void {
this._peerClient = client;
}

/**
Expand All @@ -106,6 +210,11 @@ export class Connection {
const path = options.path ?? '/';
const headers: ConnectionHeaders = { ...(options.headers ?? {}) };

// Set mandatory grpc metadata
const metadata = new grpc.Metadata();
metadata.set('jwetoken', this._jweToken);

// Build body buffer
let bodyBuf: Buffer = Buffer.alloc(0);
const b = options.body;
if (b != null) {
Expand All @@ -119,7 +228,7 @@ export class Connection {

// Return promise with response
return new Promise<FetchResponse>((resolve, reject) => {
this._peerClient.Fetch(req, (err: any, resp: any) => {
this._peerClient.Fetch(req, metadata, (err: any, resp: any) => {
if (err) return reject(err);

const resBody = resp?.body ? Buffer.from(resp.body) : Buffer.alloc(0);
Expand Down
Loading
Loading