diff --git a/.env.example b/.env.example index 381d0cb6c252c78a7130174c0ed384c5853aba82..7ff990004c75f3e5d50d4d3ed48fbefa033288e3 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,9 @@ LEDGERS="BCOVRIN_TEST" IDUNION_KEY=#add if you are using IDUNION as a ledger +IDUNION_BASIC_USER= +IDUNION_BASIC_PASS= -AGENT_PEER_URL="http://localhost:8001" +AGENT_PEER_URL=http://localhost:8001,ws://localhost:8002 AGENT_NAME=EXAMPTTLE_AGENT_45 AGENT_KEY=EXAMPLE_AGENT_45_KEY AGENT_DID_SEED=200000000000000000000000ExampleT21 #random string min 32 chars diff --git a/apps/gateway/src/main.ts b/apps/gateway/src/main.ts index 37b744b5ef6253acdda665b7b2002343930132c2..c6f57ec747662b0b8ee685d0811a4285cfbbf104 100644 --- a/apps/gateway/src/main.ts +++ b/apps/gateway/src/main.ts @@ -21,6 +21,7 @@ async function bootstrap() { const gatewayConfig = configService.get<IGateway>("gateway")!; const globalPrefix = "api"; + app.enableCors(); app.setGlobalPrefix(globalPrefix); app.enableShutdownHooks(); diff --git a/compose/docker-compose.simple.yml b/compose/docker-compose.simple.yml index 0d8d9ad9557fbabc3efc2789d571667cdaf0b2ac..0544a7887f2e118972e289bc1abe4f158d528686 100644 --- a/compose/docker-compose.simple.yml +++ b/compose/docker-compose.simple.yml @@ -21,6 +21,7 @@ services: ports: - "8080:8080" - "8001:8001" + - "8002:8002" depends_on: pg_db: condition: service_started @@ -35,6 +36,7 @@ services: ports: - "8081:8080" - "6001:6001" + - "6002:6002" depends_on: pg_db: condition: service_started diff --git a/compose/docker-compose.yml b/compose/docker-compose.yml index 3646983bfc3f4ac77a3889c748be603a60be8b8d..e9e3bc1f6943ea61a79a03275c7584c830f64796 100644 --- a/compose/docker-compose.yml +++ b/compose/docker-compose.yml @@ -36,6 +36,7 @@ services: ports: - "8080:8080" - "8001:8001" + - "8002:8002" env_file: - ./env/issuer.env depends_on: @@ -141,6 +142,7 @@ services: ports: - "8090:8080" - "6001:6001" + - "6002:6002" env_file: - ./env/holder.env depends_on: diff --git a/compose/env/holder.env b/compose/env/holder.env index c395fb460c8420b9007cef1380c34840040844ef..e05c13336535592a5ace6cb8b9641e78dac9c4ec 100644 --- a/compose/env/holder.env +++ b/compose/env/holder.env @@ -1,10 +1,12 @@ -LEDGERS="BCOVRIN_TEST" +LEDGERS=BCOVRIN_TEST IDUNION_KEY= +IDUNION_BASIC_USER= +IDUNION_BASIC_PASS= -AGENT_PEER_URL="http://agent-holder:6001" +AGENT_PEER_URL=http://agent-holder:6001,ws://agent-holder:6002 AGENT_NAME=DEV_AGENT_HOLDER_OCM_4 # this should be changed to company name AGENT_KEY=DEV_AGENT_HOLDER_OCM_4 #example random string -AGENT_DID_SEED=2000000000000000CCA120000000TCuste21jsjs #did private key seed min lenght 32 +AGENT_DID_SEED=2000000000000000CCA120000000TCuste21jsjs #did private key seed min length 32 AGENT_DB_HOST=pg_db:5432 AGENT_DB_USER=postgres AGENT_DB_PASS=postgres diff --git a/compose/env/holder.simple.env b/compose/env/holder.simple.env index 0db552de3ba9ba0e25e9e1a91c837aca8f4bc28e..8cf4ce257df4fbfb4295f19211769f9805ce07b8 100644 --- a/compose/env/holder.simple.env +++ b/compose/env/holder.simple.env @@ -1,10 +1,12 @@ -LEDGERS="BCOVRIN_TEST" +LEDGERS=BCOVRIN_TEST IDUNION_KEY= +IDUNION_BASIC_USER= +IDUNION_BASIC_PASS= -AGENT_PEER_URL="http://agent-holder:6001" +AGENT_PEER_URL=http://agent-holder:6001,ws://agent-holder:6002 AGENT_NAME=DEV_SIMPLE_AGENT_HOLDER_OCM # this should be changed to company name AGENT_KEY=DEV_SIMPLE_AGENT_HOLDER_OCM #example random string -AGENT_DID_SEED=200000000000000000000000TCuste21xh #did private key seed min lenght 32 +AGENT_DID_SEED=200000000000000000000000TCuste21xh #did private key seed min length 32 AGENT_DB_HOST=pg_db:5432 AGENT_DB_USER=postgres AGENT_DB_PASS=postgres diff --git a/compose/env/issuer.env b/compose/env/issuer.env index d3774abdcc0cab97012a7a3950a5ea20c4467c82..9e274c4b805ab3c73126f73e2d9cff23daa446df 100644 --- a/compose/env/issuer.env +++ b/compose/env/issuer.env @@ -1,10 +1,12 @@ -LEDGERS="BCOVRIN_TEST" +LEDGERS=BCOVRIN_TEST IDUNION_KEY= +IDUNION_BASIC_USER= +IDUNION_BASIC_PASS= -AGENT_PEER_URL="http://agent-issuer:8001" +AGENT_PEER_URL=http://agent-issuer:8001,ws://agent-issuer:8002 AGENT_NAME=DEV_AGENT_ISSUER_OCM_4 # this should be changed to company name AGENT_KEY=DEV_AGENT_ISSUER_OCM_4 #example random string -AGENT_DID_SEED=20000000000000000000000aca0xxaDTCuste21udhasjs #did private key seed min lenght 32 +AGENT_DID_SEED=20000000000000000000000aca0xxaDTCuste21udhasjs #did private key seed min length 32 AGENT_DB_HOST=pg_db:5432 AGENT_DB_USER=postgres AGENT_DB_PASS=postgres diff --git a/compose/env/issuer.simple.env b/compose/env/issuer.simple.env index 22c8de61a9796eadeda934873ca3a3f88f25a67d..913ceab365dc2b4a812dce52110904a19d9e11a4 100644 --- a/compose/env/issuer.simple.env +++ b/compose/env/issuer.simple.env @@ -1,7 +1,9 @@ -LEDGERS="BCOVRIN_TEST" +LEDGERS=BCOVRIN_TEST IDUNION_KEY= +IDUNION_BASIC_USER= +IDUNION_BASIC_PASS= -AGENT_PEER_URL="http://agent-issuer:8001" +AGENT_PEER_URL=http://agent-issuer:8001,ws://agent-issuer:8002 AGENT_NAME=DEV_SIMPLE_AGENT_ISSUER_OCM # this should be changed to company name AGENT_KEY=DEV_SIMPLE_AGENT_ISSUER_OCM #example random string AGENT_DID_SEED=200000000000000000000000TCuste21js #did private key seed min lenght 32 diff --git a/libs/askar/src/agent.utils.ts b/libs/askar/src/agent.utils.ts index 3eae5e959a039310952d4bdaadd5e631d6e54827..9f103826a8e910dedc286b4fb6ff5abfeed22d13 100644 --- a/libs/askar/src/agent.utils.ts +++ b/libs/askar/src/agent.utils.ts @@ -13,6 +13,8 @@ import { V2ProofProtocol, WalletError, WalletKeyExistsError, + KeyDidResolver, + KeyDidRegistrar, } from "@aries-framework/core"; import { AnonCredsCredentialFormatService, @@ -125,8 +127,8 @@ export const getAskarAnonCredsIndyModules = (networks: any) => { networks, }), dids: new DidsModule({ - registrars: [new IndyVdrIndyDidRegistrar()], - resolvers: [new IndyVdrIndyDidResolver()], + registrars: [new IndyVdrIndyDidRegistrar(), new KeyDidRegistrar()], + resolvers: [new IndyVdrIndyDidResolver(), new KeyDidResolver()], }), askar: new AskarModule({ ariesAskar, diff --git a/libs/askar/src/askar/agent.service.ts b/libs/askar/src/askar/agent.service.ts index 27fe92a7a1291e7fe9257731ce0f3cd8aea0a9f4..581b81ef8dec33379b18042f07fc888712ddd5e9 100644 --- a/libs/askar/src/askar/agent.service.ts +++ b/libs/askar/src/askar/agent.service.ts @@ -33,7 +33,7 @@ export class AgentService { const i = new CreateInvitationResponseDto(); i.invitationUrl = outOfBoundRecord.outOfBandInvitation.toUrl({ - domain: this.askar.agentConfig.agentPeerAddress, + domain: this.askar.agentConfig.agentHttpPeerAddress || this.askar.agentConfig.agentWsPeerAddress || '', }); return i; diff --git a/libs/askar/src/askar/askar.service.ts b/libs/askar/src/askar/askar.service.ts index e07eb52a9f77a1f1b57ff7e0df2acdeebf9ec5e8..6d68c8b0cb6eeaf89769b1bdb6314b459ee30e0f 100644 --- a/libs/askar/src/askar/askar.service.ts +++ b/libs/askar/src/askar/askar.service.ts @@ -14,7 +14,11 @@ import { TypedArrayEncoder, WsOutboundTransport, } from "@aries-framework/core"; -import { agentDependencies, HttpInboundTransport } from "@aries-framework/node"; +import { + agentDependencies, + HttpInboundTransport, + WsInboundTransport, +} from "@aries-framework/node"; import { ConfigService } from "@nestjs/config"; import { LedgersService } from "@ocm-engine/ledgers"; import { @@ -38,6 +42,12 @@ export class AskarService implements OnModuleInit, OnModuleDestroy { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion this.agentConfig = configService.get<IConfAgent>("agent")!; + const endpoints: string[] = []; + if (this.agentConfig.agentHttpPeerAddress) + endpoints.push(this.agentConfig.agentHttpPeerAddress); + if (this.agentConfig.agentWsPeerAddress) + endpoints.push(this.agentConfig.agentWsPeerAddress); + const config = { label: this.agentConfig.agentName, logger: new ConsoleLogger(LogLevel.debug), @@ -55,7 +65,7 @@ export class AskarService implements OnModuleInit, OnModuleDestroy { id: this.agentConfig.agentName, key: this.agentConfig.agentKey, }, - endpoints: [this.agentConfig.agentPeerAddress], + endpoints, } satisfies InitConfig; this.agent = new Agent({ @@ -66,9 +76,20 @@ export class AskarService implements OnModuleInit, OnModuleDestroy { ), }); - this.agent.registerInboundTransport( - new HttpInboundTransport({ port: this.agentConfig.agentPeerPort }), - ); + if (this.agentConfig.agentWsPeerPort) { + this.agent.registerInboundTransport( + new WsInboundTransport({ + port: this.agentConfig.agentWsPeerPort as number, + }), + ); + } + if (this.agentConfig.agentHttpPeerPort) { + this.agent.registerInboundTransport( + new HttpInboundTransport({ + port: this.agentConfig.agentHttpPeerPort as number, + }), + ); + } this.agent.registerOutboundTransport(new WsOutboundTransport()); this.agent.registerOutboundTransport(new HttpOutboundTransport()); diff --git a/libs/config/src/config/agent.config.ts b/libs/config/src/config/agent.config.ts index d71fa86ec0b107a39cfcc8fb60bdb28c8d62c893..c94edb13ee12f8adacf3c06965c34c65d7dc20c7 100644 --- a/libs/config/src/config/agent.config.ts +++ b/libs/config/src/config/agent.config.ts @@ -2,11 +2,34 @@ import { registerAs } from "@nestjs/config"; import * as process from "process"; import { IConfAgent } from "../interfaces/agent.config.interface"; +const endpoints = process.env["AGENT_PEER_URL"]!.split(","); +let agentWsPeerPort: number | null = null; +let agentWsPeerAddress: string | null = null; +let agentHttpPeerPort: number | null = null; +let agentHttpPeerAddress: string | null = null; + +const wsEndpoint = endpoints.find( + (p) => p.startsWith("ws") || p.startsWith("wss"), +); +if (wsEndpoint) { + agentWsPeerPort = parseInt(wsEndpoint.split(":")[2]); + agentWsPeerAddress = wsEndpoint; +} +const httpEndpoint = endpoints.find( + (p) => p.startsWith("http") || p.startsWith("https"), +); +if (httpEndpoint) { + agentHttpPeerPort = parseInt(httpEndpoint.split(":")[2]); + agentHttpPeerAddress = httpEndpoint; +} + export const agentConfig = registerAs( "agent", (): IConfAgent => ({ - agentPeerPort: parseInt(process.env["AGENT_PEER_URL"]!.split(":")[2]), - agentPeerAddress: process.env["AGENT_PEER_URL"]!, + agentWsPeerPort, + agentWsPeerAddress, + agentHttpPeerPort, + agentHttpPeerAddress, agentName: process.env["AGENT_NAME"]!, agentKey: process.env["AGENT_KEY"]!, agentDidSeed: process.env["AGENT_DID_SEED"]!, diff --git a/libs/config/src/config/ledgers.config.ts b/libs/config/src/config/ledgers.config.ts index de79f8a9af7f5173ada50f3bb31f16f2e2f9efe6..8d7c3c672df77b960758aed40014c243e0a94eeb 100644 --- a/libs/config/src/config/ledgers.config.ts +++ b/libs/config/src/config/ledgers.config.ts @@ -7,5 +7,7 @@ export const ledgersConfig = registerAs( (): ILedgers => ({ ledgers: process.env["LEDGERS"]!.split(","), idUnionApiKey: process.env["IDUNION_KEY"]!, + idUnionApiBasicUser: process.env["IDUNION_BASIC_USER"]!, + idUnionApiBasicPass: process.env["IDUNION_BASIC_PASS"]!, }), ); diff --git a/libs/config/src/interfaces/agent.config.interface.ts b/libs/config/src/interfaces/agent.config.interface.ts index 1f0e7a85caa94710dd23ede1d6ff0d5042870a86..25dee199cebc1364f7bf7603ce95b31df460e5f0 100644 --- a/libs/config/src/interfaces/agent.config.interface.ts +++ b/libs/config/src/interfaces/agent.config.interface.ts @@ -2,8 +2,10 @@ export interface IConfAgent { agentDbHost: string; agentDbUser: string; agentDbPass: string; - agentPeerPort: number; - agentPeerAddress: string; + agentWsPeerPort: number | null; + agentWsPeerAddress: string | null; + agentHttpPeerPort: number | null; + agentHttpPeerAddress: string | null; agentName: string; agentKey: string; agentDidSeed: string; diff --git a/libs/config/src/interfaces/ledgers.config.interface.ts b/libs/config/src/interfaces/ledgers.config.interface.ts index a49c9850e94d8f14581774d5fc9694dd75c1d685..c7af9b9afcf1690d455e151a55e4f4001a2ea997 100644 --- a/libs/config/src/interfaces/ledgers.config.interface.ts +++ b/libs/config/src/interfaces/ledgers.config.interface.ts @@ -1,4 +1,6 @@ export interface ILedgers { ledgers: Array<string>; idUnionApiKey: string; + idUnionApiBasicUser: string; + idUnionApiBasicPass: string; } diff --git a/libs/config/src/schemas/ledgers.schema.ts b/libs/config/src/schemas/ledgers.schema.ts index d305f72862825e6b7f89dd6dccc1972fcd9e2637..67a2cf3fc798828230d762d621e29ae4d55b3702 100644 --- a/libs/config/src/schemas/ledgers.schema.ts +++ b/libs/config/src/schemas/ledgers.schema.ts @@ -3,4 +3,6 @@ import Joi from "joi"; export const ledgersSchema = Joi.object({ LEDGERS: Joi.string().required(), IDUNION_KEY: Joi.string(), + IDUNION_BASIC_USER: Joi.string(), + IDUNION_BASIC_PASS: Joi.string(), }); diff --git a/libs/ledgers/src/idunion/idunion.provider.ts b/libs/ledgers/src/idunion/idunion.provider.ts index 5c6dcf4654797c7f773a59b9c9e9f318773441f5..0a5fa67caeef847c65e774d904dd090b86129133 100644 --- a/libs/ledgers/src/idunion/idunion.provider.ts +++ b/libs/ledgers/src/idunion/idunion.provider.ts @@ -30,11 +30,20 @@ export class IdunionProvider implements IRegistrator { this.logger.log(`Trying to register ${did} to idunion`); try { - await axios.post(`${URL}?apiKey=${this.config.idUnionApiKey}`, { - role: "ENDORSER", - did: unqualifiedIndyDid, - verkey, - }); + await axios.post( + `${URL}?apiKey=${this.config.idUnionApiKey}`, + { + role: "ENDORSER", + did: unqualifiedIndyDid, + verkey, + }, + { + auth: { + username: this.config.idUnionApiBasicUser, + password: this.config.idUnionApiBasicPass, + }, + }, + ); this.logger.log("Registration successful"); return did;