Skip to content

Commit

Permalink
fix(satp-hermes): service errors and some stage bugs
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Amaro <carlosrscamaro@tecnico.ulisboa.pt>

feat(satp-hermes): satp rejection

Signed-off-by: Carlos Amaro <carlosrscamaro@tecnico.ulisboa.pt>

feat(satp-hermes): handler bug correction and errors

Signed-off-by: Carlos Amaro <carlosrscamaro@tecnico.ulisboa.pt>

fix(satp-hermes): bridge erros and log messages

Signed-off-by: Carlos Amaro <carlosrscamaro@tecnico.ulisboa.pt>

fix(satp-hermes): some error fixes

Signed-off-by: Carlos Amaro <carlosrscamaro@tecnico.ulisboa.pt>

fix(satp-hermes): some fixes requested

Signed-off-by: Carlos Amaro <carlosrscamaro@tecnico.ulisboa.pt>
  • Loading branch information
LordKubaya authored and RafaelAPB committed Aug 21, 2024
1 parent 7da3f27 commit 5744312
Show file tree
Hide file tree
Showing 31 changed files with 1,211 additions and 2,368 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ message SessionData {
string server_transfer_number = 58;
uint64 lock_assertion_expiration = 59;
cacti.satp.v02.common.AssetProfile asset_profile = 60;
string resource_url = 61;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ message TransferProposalReceiptMessage {
string hash_transfer_init_claims = 2;
cacti.satp.v02.common.TransferClaims transfer_counter_claims = 3;
string timestamp = 4;
string server_signature = 5;
string server_signature = 6;
}

message TransferCommenceRequestMessage {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GetStatusError } from "../../core/errors";
import { GetStatusError } from "../../core/errors/satp-errors";
import {
StatusRequest,
StatusResponse,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
export class BridgeInternalError extends Error {
constructor(
public message: string,
// TODO internal error codes
public code: number = 500,
public traceID?: string,
public trace?: string,
) {
super(message);
this.name = this.constructor.name;
Object.setPrototypeOf(this, new.target.prototype); // make sure prototype chain is set to error
//this.stack = trace || new Error().stack;
}
}

export class OntologyError extends BridgeInternalError {
constructor(tag: string) {
super(
`${tag}, undefined Ontology, ontology is required to interact with tokens`,
500,
);
}
}

export class TransactionError extends BridgeInternalError {
constructor(tag: string) {
super(`${tag}, Transaction failed`, 500);
}
}

export class TransactionIdUndefinedError extends BridgeInternalError {
constructor(tag: string) {
super(`${tag}, Transaction id undefined`, 500);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class SATPInternalError extends Error {
super(message);
this.name = this.constructor.name;
Object.setPrototypeOf(this, new.target.prototype); // make sure prototype chain is set to error
this.stack = trace || new Error().stack;
//this.stack = trace || new Error().stack;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { SATPInternalError } from "./satp-errors";

export class SessionNotFoundError extends SATPInternalError {
constructor(tag: string) {
super(`${tag}, session not found`, 500);
}
}

export class SessionIdNotFoundError extends SATPInternalError {
constructor(tag: string) {
super(`${tag}, session id not found`, 500);
}
}

export class FailedToCreateMessageError extends SATPInternalError {
constructor(tag: string, message: string) {
super(`${tag}, failed to create message: ${message}`, 500);
}
}

export class FailedToProcessError extends SATPInternalError {
constructor(tag: string, message: string) {
super(`${tag}, failed to process: ${message}`, 500);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
import { SATPInternalError } from "./satp-errors";

export class SatpCommonBodyError extends SATPInternalError {
constructor(fnTag: string, data: string) {
super(
`${fnTag}, message satp common body is missing or is missing required fields \n ${data}`,
400,
);
}
}
export class SessionError extends SATPInternalError {
constructor(fnTag: string) {
super(`${fnTag}, session undefined`, 500);
}
}

export class SessionDataNotLoadedCorrectlyError extends SATPInternalError {
constructor(fnTag: string, data: string) {
super(`${fnTag}, session data was not loaded correctly \n ${data}`, 500);
}
}

export class SessionCompletedError extends SATPInternalError {
constructor(fnTag: string) {
super(`${fnTag}, session data already completed`, 500);
}
}

export class SATPVersionError extends SATPInternalError {
constructor(fnTag: string, unsupported: string, supported: string) {
super(
`${fnTag}, unsupported SATP version \n received: ${unsupported}, supported: ${supported}`,
400,
);
}
}

export class SignatureVerificationError extends SATPInternalError {
constructor(fnTag: string) {
super(`${fnTag}, message signature verification failed`, 400);
}
}

export class SignatureMissingError extends SATPInternalError {
constructor(fnTag: string) {
super(`${fnTag}, message signature missing`, 400);
}
}

export class MessageTypeError extends SATPInternalError {
constructor(fnTag: string, received: string, expected: string) {
super(
`${fnTag}, message type miss match \n received: ${received} \n expected: ${expected}`,
400,
);
}
}

export class TransferInitClaimsError extends SATPInternalError {
constructor(fnTag: string) {
super(`${fnTag}, transferInitClaims missing or faulty`, 400);
}
}

export class TransferInitClaimsHashError extends SATPInternalError {
constructor(fnTag: string) {
super(`${fnTag}, transferInitClaims hash missing or missmatch`, 400);
}
}

export class NetworkCapabilitiesError extends SATPInternalError {
constructor(fnTag: string) {
super(`${fnTag}, NetworkCapabilitiesError missing or faulty`, 400);
}
}

export class DLTNotSupportedError extends SATPInternalError {
constructor(fnTag: string, dlt: string) {
super(`${fnTag}, DLT not supported \n received: ${dlt}`, 400);
}
}

export class ServerGatewayPubkeyError extends SATPInternalError {
constructor(fnTag: string) {
super(`${fnTag}, serverGatewayPubkey missing or missmatch`, 400);
}
}

export class ClientGatewayPubkeyError extends SATPInternalError {
constructor(fnTag: string) {
super(`${fnTag}, clientGatewayPubkey missing or missmatch`, 400);
}
}

export class SequenceNumberError extends SATPInternalError {
constructor(fnTag: string, received: bigint, expected: bigint) {
super(
`${fnTag}, sequence number missmatch \n received: ${received} \n expected: ${expected}`,
400,
);
}
}

export class HashError extends SATPInternalError {
constructor(fnTag: string, received: string, expected: string) {
super(
`${fnTag}, hash missmatch \n received: ${received} \n expected: ${expected}`,
400,
);
}
}

export class TransferContextIdError extends SATPInternalError {
constructor(fnTag: string, received: string, expected: string) {
super(
`${fnTag}, transferContextId missing or missmatch \n received: ${received} \n expected: ${expected}`,
400,
);
}
}

export class MissingBridgeManagerError extends SATPInternalError {
constructor(fnTag: string) {
super(`${fnTag}, bridge manager missing`, 400);
}
}

export class LockAssertionClaimError extends SATPInternalError {
constructor(fnTag: string) {
super(`${fnTag}, lockAssertionClaim missing or faulty`, 400);
}
}

export class LockAssertionClaimFormatError extends SATPInternalError {
constructor(fnTag: string) {
super(`${fnTag}, lockAssertionClaimFormat missing`, 400);
}
}

export class LockAssertionExpirationError extends SATPInternalError {
constructor(fnTag: string) {
super(`${fnTag}, lockAssertionExpiration missing or faulty`, 400);
}
}

export class BurnAssertionClaimError extends SATPInternalError {
constructor(fnTag: string) {
super(`${fnTag}, burnAssertionClaim missing or faulty`, 400);
}
}

export class MintAssertionClaimError extends SATPInternalError {
constructor(fnTag: string) {
super(`${fnTag}, mintAssertionClaim missing or faulty`, 400);
}
}

export class AssignmentAssertionClaimError extends SATPInternalError {
constructor(fnTag: string) {
super(`${fnTag}, assignmentAssertionClaim missing or faulty`, 400);
}
}

export class ResourceUrlError extends SATPInternalError {
constructor(fnTag: string) {
super(`${fnTag}, resourceUrl missing or missmatch`, 400);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ import {
Stage3Signatures,
Stage3Timestamps,
} from "../generated/proto/cacti/satp/v02/common/session_pb";
import {
SATPVersionError,
SessionCompletedError,
SessionDataNotLoadedCorrectlyError,
} from "./errors/satp-service-errors";
import { SATP_VERSION } from "./constants";
import { LockType } from "../generated/proto/cacti/satp/v02/common/message_pb";
import { SessionType } from "./session-utils";

// Define interface on protos
export interface ISATPSessionOptions {
Expand Down Expand Up @@ -75,11 +83,21 @@ export class SATPSession {
sessionData.signatures.stage3 = new Stage3Signatures();
}

public getServerSessionData(): SessionData | undefined {
public getServerSessionData(): SessionData {
if (this.serverSessionData == undefined) {
throw new Error(
`${SATPSession.CLASS_NAME}#getServerSessionData(), serverSessionData is undefined`,
);
}
return this.serverSessionData;
}

public getClientSessionData(): SessionData | undefined {
public getClientSessionData(): SessionData {
if (this.clientSessionData == undefined) {
throw new Error(
`${SATPSession.CLASS_NAME}#getClientSessionData(), clientSessionData is undefined`,
);
}
return this.clientSessionData;
}

Expand All @@ -94,4 +112,58 @@ export class SATPSession {
public getSessionId(): string {
return this.serverSessionData?.id || this.clientSessionData?.id || "";
}

public verify(tag: string, type: SessionType): void {
let sessionData: SessionData | undefined;
if (type == SessionType.SERVER) {
sessionData = this.getServerSessionData();
} else if (type == SessionType.CLIENT) {
sessionData = this.getClientSessionData();
} else {
throw new Error(
`${SATPSession.CLASS_NAME}#verify(), sessionData type is not valid`,
);
}

if (sessionData == undefined) {
throw new SessionDataNotLoadedCorrectlyError(tag, "undefined");
}

if (sessionData.completed) {
throw new SessionCompletedError("Session already completed");
}

if (
sessionData.version == "" ||
sessionData.id == "" ||
sessionData.digitalAssetId == "" ||
sessionData.originatorPubkey == "" ||
sessionData.beneficiaryPubkey == "" ||
sessionData.senderGatewayNetworkId == "" ||
sessionData.recipientGatewayNetworkId == "" ||
sessionData.clientGatewayPubkey == "" ||
sessionData.serverGatewayPubkey == "" ||
sessionData.senderGatewayOwnerId == "" ||
sessionData.receiverGatewayOwnerId == "" ||
// sessionData.maxRetries == undefined ||
// sessionData.maxTimeout == undefined ||
sessionData.senderGatewayNetworkId == "" ||
sessionData.signatureAlgorithm == undefined ||
sessionData.lockType == LockType.UNSPECIFIED ||
sessionData.lockExpirationTime == BigInt(0) ||
sessionData.credentialProfile == undefined ||
sessionData.loggingProfile == "" ||
sessionData.accessControlProfile == "" ||
// sessionData.lastSequenceNumber == BigInt(0) ||
sessionData.transferContextId == ""
) {
throw new SessionDataNotLoadedCorrectlyError(
tag,
JSON.stringify(sessionData),
);
}
if (sessionData.version != SATP_VERSION) {
throw new SATPVersionError(tag, sessionData.version, SATP_VERSION);
}
}
}
Loading

0 comments on commit 5744312

Please sign in to comment.