From a50f8b180d38b149fc5aa54cd2ee90d62203ff99 Mon Sep 17 00:00:00 2001 From: KulkarniShashank Date: Fri, 5 Apr 2024 19:45:00 +0530 Subject: [PATCH] feat: added messageType on the credo core Signed-off-by: KulkarniShashank --- Dockerfile | 97 +++++++++++++++++++++--------- package.json | 1 + patches/@credo-ts+core+0.5.0.patch | 50 +++++++++++++++ src/authentication.ts | 4 +- 4 files changed, 120 insertions(+), 32 deletions(-) create mode 100644 patches/@credo-ts+core+0.5.0.patch diff --git a/Dockerfile b/Dockerfile index d8d1cb3b..c9f23ad8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,43 +1,80 @@ -FROM ubuntu:20.04 +# FROM ubuntu:20.04 -ENV DEBIAN_FRONTEND noninteractive +# ENV DEBIAN_FRONTEND noninteractive -RUN apt-get update -y && apt-get install -y \ - software-properties-common \ - apt-transport-https \ - curl \ - # Only needed to build indy-sdk - build-essential +# RUN apt-get update -y && apt-get install -y \ +# software-properties-common \ +# apt-transport-https \ +# curl \ +# # Only needed to build indy-sdk +# build-essential -# nodejs -# RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash -# RUN /bin/bash -c "source /root/.nvm/nvm.sh && nvm install 18 && nvm use 18" +# # nodejs +# # RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash +# # RUN /bin/bash -c "source /root/.nvm/nvm.sh && nvm install 18 && nvm use 18" -RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - +# RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - -# yarn -RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ - echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list +# # yarn +# RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \ +# echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list -# install depdencies -RUN apt-get update -y && apt-get install -y --allow-unauthenticated \ - nodejs +# # install depdencies +# RUN apt-get update -y && apt-get install -y --allow-unauthenticated \ +# nodejs -# Install yarn seperately due to `no-install-recommends` to skip nodejs install -RUN apt-get install -y --no-install-recommends yarn +# # Install yarn seperately due to `no-install-recommends` to skip nodejs install +# RUN apt-get install -y --no-install-recommends yarn + +# RUN yarn global add patch-package +# # AFJ specifc setup +# WORKDIR /www + +# COPY bin ./bin +# COPY package.json ./package.json +# COPY patches ./patches + +# RUN yarn install --production + +# COPY build ./build +# # COPY libindy_vdr.so /usr/lib/ +# # COPY libindy_vdr.so /usr/local/lib/ + +# ENTRYPOINT [ "./bin/afj-rest.js", "start" ] + + +# Stage 1: Builder stage +FROM node:18.19.0 AS builder + +WORKDIR /app + +# Copy package.json and yarn.lock files +COPY package.json yarn.lock ./ + +# Install dependencies +RUN yarn install --frozen-lockfile + +# Copy the rest of the application code +COPY . . RUN yarn global add patch-package -# AFJ specifc setup -WORKDIR /www -COPY bin ./bin -COPY package.json ./package.json -COPY patches ./patches +# Build the application +RUN yarn build + +# Stage 2: Production stage +FROM node:18.19.0-slim + +WORKDIR /app + +# Copy built files and node_modules from the builder stage +COPY --from=builder /app/build ./build +COPY --from=builder /app/bin ./bin +COPY --from=builder /app/package.json ./ +COPY --from=builder /app/node_modules ./node_modules +COPY --from=builder /app/patches ./patches -RUN yarn install --production +# Set entry point +ENTRYPOINT ["node", "./bin/afj-rest.js", "start"] -COPY build ./build -# COPY libindy_vdr.so /usr/lib/ -# COPY libindy_vdr.so /usr/local/lib/ -ENTRYPOINT [ "./bin/afj-rest.js", "start" ] diff --git a/package.json b/package.json index 7342212b..f67626f3 100644 --- a/package.json +++ b/package.json @@ -58,6 +58,7 @@ "cors": "^2.8.5", "express": "^4.18.1", "express-rate-limit": "^7.1.5", + "joi": "^17.12.3", "jsonwebtoken": "^9.0.2", "node-fetch": "^2.6.7", "patch-package": "^8.0.0", diff --git a/patches/@credo-ts+core+0.5.0.patch b/patches/@credo-ts+core+0.5.0.patch new file mode 100644 index 00000000..7350b168 --- /dev/null +++ b/patches/@credo-ts+core+0.5.0.patch @@ -0,0 +1,50 @@ +diff --git a/node_modules/@credo-ts/core/build/agent/EnvelopeService.js b/node_modules/@credo-ts/core/build/agent/EnvelopeService.js +index 12261a9..0238d59 100644 +--- a/node_modules/@credo-ts/core/build/agent/EnvelopeService.js ++++ b/node_modules/@credo-ts/core/build/agent/EnvelopeService.js +@@ -32,12 +32,14 @@ let EnvelopeService = class EnvelopeService { + let encryptedMessage = await agentContext.wallet.pack(message, recipientKeysBase58, senderKeyBase58 !== null && senderKeyBase58 !== void 0 ? senderKeyBase58 : undefined); + // If the message has routing keys (mediator) pack for each mediator + for (const routingKeyBase58 of routingKeysBase58) { ++ console.log(`message['@type']`, JSON.stringify(message['@type'])) + const forwardMessage = new messages_1.ForwardMessage({ + // Forward to first recipient key + to: recipientKeysBase58[0], + message: encryptedMessage, + }); + recipientKeysBase58 = [routingKeyBase58]; ++ forwardMessage["messageType"] = message['@type']; + this.logger.debug('Forward message created', forwardMessage); + const forwardJson = forwardMessage.toJSON({ + useDidSovPrefixWhereAllowed: agentContext.config.useDidSovPrefixWhereAllowed, +diff --git a/node_modules/@credo-ts/core/build/modules/routing/messages/ForwardMessage.d.ts b/node_modules/@credo-ts/core/build/modules/routing/messages/ForwardMessage.d.ts +index 4f8577b..396f78a 100644 +--- a/node_modules/@credo-ts/core/build/modules/routing/messages/ForwardMessage.d.ts ++++ b/node_modules/@credo-ts/core/build/modules/routing/messages/ForwardMessage.d.ts +@@ -3,6 +3,7 @@ import { EncryptedMessage } from '../../../types'; + export interface ForwardMessageOptions { + id?: string; + to: string; ++ messageType: string; + message: EncryptedMessage; + } + /** +@@ -19,5 +20,6 @@ export declare class ForwardMessage extends AgentMessage { + readonly type: string; + static readonly type: import("../../../utils/messageType").ParsedMessageType; + to: string; ++ messageType: string; + message: EncryptedMessage; + } +diff --git a/node_modules/@credo-ts/core/build/types.d.ts b/node_modules/@credo-ts/core/build/types.d.ts +index e0384d9..0a669fb 100644 +--- a/node_modules/@credo-ts/core/build/types.d.ts ++++ b/node_modules/@credo-ts/core/build/types.d.ts +@@ -81,6 +81,7 @@ export interface PlaintextMessage { + thid?: string; + pthid?: string; + }; ++ messageType: string; + [key: string]: unknown; + } + export interface OutboundPackage { diff --git a/src/authentication.ts b/src/authentication.ts index bf8eb1d6..fd054dc5 100644 --- a/src/authentication.ts +++ b/src/authentication.ts @@ -14,8 +14,8 @@ export async function expressAuthentication( ) { const logger = new TsLogger(LogLevel.info) - logger.info(`secMethod::: ${JSON.stringify(secMethod)}`) - logger.info(`scopes::: ${JSON.stringify(scopes)}`) + logger.info(`secMethod::: ${secMethod}`) + logger.info(`scopes::: ${scopes}`) const apiKeyHeader = request.headers['authorization']