Skip to content
Merged
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
1 change: 1 addition & 0 deletions packages/consumption/src/consumption/ConsumptionConfig.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export interface ConsumptionConfig {
setDefaultOwnIdentityAttributes: boolean;
fetchInstance?: typeof fetch;
}
16 changes: 10 additions & 6 deletions packages/consumption/src/modules/openid4vc/OpenId4VcController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ export class OpenId4VcController extends ConsumptionBaseController {
super(ConsumptionControllerName.OpenId4VcController, parent);
}

private get fetchInstance(): typeof fetch {
return this.parent.consumptionConfig.fetchInstance ?? fetch;
}

public async fetchCredentialOffer(credentialOfferUrl: string): Promise<{ data: string }> {
const holder = new Holder(this.parent.accountController, this.parent.attributes);
const holder = new Holder(this.parent.accountController, this.parent.attributes, this.fetchInstance);
await holder.initializeAgent("96213c3d7fc8d4d6754c7a0fd969598e");
const res = await holder.resolveCredentialOffer(credentialOfferUrl);
return {
Expand All @@ -25,7 +29,7 @@ export class OpenId4VcController extends ConsumptionBaseController {
requestedCredentialOffers: string[],
pinCode?: string
): Promise<{ data: string; id: string; type: string; displayInformation: string | undefined }> {
const holder = new Holder(this.parent.accountController, this.parent.attributes);
const holder = new Holder(this.parent.accountController, this.parent.attributes, this.fetchInstance);
await holder.initializeAgent("96213c3d7fc8d4d6754c7a0fd969598e");
const credentialOffer = JSON.parse(fetchedCredentialOffer);
const credentials = await holder.requestAndStoreCredentials(credentialOffer, { credentialsToRequest: requestedCredentialOffers, txCode: pinCode });
Expand All @@ -43,7 +47,7 @@ export class OpenId4VcController extends ConsumptionBaseController {
}

public async processCredentialOffer(credentialOffer: string): Promise<{ data: string; id: string; type: string; displayInformation: string | undefined }> {
const holder = new Holder(this.parent.accountController, this.parent.attributes);
const holder = new Holder(this.parent.accountController, this.parent.attributes, this.fetchInstance);
await holder.initializeAgent("96213c3d7fc8d4d6754c7a0fd969598e");
const res = await holder.resolveCredentialOffer(credentialOffer);
const credentials = await holder.requestAndStoreCredentials(res, { credentialsToRequest: Object.keys(res.offeredCredentialConfigurations) });
Expand All @@ -63,7 +67,7 @@ export class OpenId4VcController extends ConsumptionBaseController {
public async resolveAuthorizationRequest(
requestUrl: string
): Promise<{ authorizationRequest: OpenId4VpResolvedAuthorizationRequest; usedCredentials: { id: string; data: string; type: string; displayInformation?: string }[] }> {
const holder = new Holder(this.parent.accountController, this.parent.attributes);
const holder = new Holder(this.parent.accountController, this.parent.attributes, this.fetchInstance);
await holder.initializeAgent("96213c3d7fc8d4d6754c7a0fd969598e");
const authorizationRequest = await holder.resolveAuthorizationRequest(requestUrl);

Expand All @@ -90,7 +94,7 @@ export class OpenId4VcController extends ConsumptionBaseController {
public async acceptAuthorizationRequest(
authorizationRequest: OpenId4VpResolvedAuthorizationRequest
): Promise<{ status: number; message: string | Record<string, unknown> | null }> {
const holder = new Holder(this.parent.accountController, this.parent.attributes);
const holder = new Holder(this.parent.accountController, this.parent.attributes, this.fetchInstance);
await holder.initializeAgent("96213c3d7fc8d4d6754c7a0fd969598e");
// parse the credential type to be sdjwt

Expand All @@ -101,7 +105,7 @@ export class OpenId4VcController extends ConsumptionBaseController {
}

public async getVerifiableCredentials(ids?: string[]): Promise<{ id: string; data: string; type: string; displayInformation?: string }[]> {
const holder = new Holder(this.parent.accountController, this.parent.attributes);
const holder = new Holder(this.parent.accountController, this.parent.attributes, this.fetchInstance);
await holder.initializeAgent("96213c3d7fc8d4d6754c7a0fd969598e");

const credentials = await holder.getVerifiableCredentials(ids);
Expand Down
1 change: 0 additions & 1 deletion packages/consumption/src/modules/openid4vc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@ export * from "./local/EnmeshedHolderFileSystem";
export * from "./local/EnmeshedHolderKeyManagmentService";
export * from "./local/EnmeshedStorageService";
export * from "./local/Holder";
export * from "./local/LocalAgentDependencies";
export * from "./OpenId4VcController";
17 changes: 14 additions & 3 deletions packages/consumption/src/modules/openid4vc/local/BaseAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import {
} from "@credo-ts/core";
import { KeyManagementModuleConfig } from "@credo-ts/core/build/modules/kms";
import { AccountController } from "@nmshd/transport";
import { EventEmitter } from "events";
import webSocket from "ws";
import { AttributesController } from "../../attributes";
import { EnmeshedHolderFileSystem } from "./EnmeshedHolderFileSystem";
import { EnmshedHolderKeyManagmentService } from "./EnmeshedHolderKeyManagmentService";
import { EnmeshedStorageService } from "./EnmeshedStorageService";
import { agentDependencies } from "./LocalAgentDependencies";

export class BaseAgent<AgentModules extends ModulesMap> {
public config: InitConfig;
Expand All @@ -30,7 +32,8 @@ export class BaseAgent<AgentModules extends ModulesMap> {
public readonly name: string,
public readonly modules: AgentModules,
public readonly accountController: AccountController,
public readonly attributeController: AttributesController
public readonly attributeController: AttributesController,
fetchInstance: typeof fetch
) {
this.name = name;
this.port = port;
Expand All @@ -49,7 +52,15 @@ export class BaseAgent<AgentModules extends ModulesMap> {
this.agent = new Agent(
{
config,
dependencies: agentDependencies,
dependencies: {
// eslint-disable-next-line @typescript-eslint/naming-convention
FileSystem: EnmeshedHolderFileSystem,
// eslint-disable-next-line @typescript-eslint/naming-convention
EventEmitterClass: EventEmitter,
fetch: fetchInstance,
// eslint-disable-next-line @typescript-eslint/naming-convention
WebSocketClass: webSocket
},
modules
},
dependencyManager
Expand Down
4 changes: 2 additions & 2 deletions packages/consumption/src/modules/openid4vc/local/Holder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export class Holder extends BaseAgent<ReturnType<typeof getOpenIdHolderModules>>
redirectUri: "http://localhost:3000/redirect"
};

public constructor(accountController: AccountController, attributeController: AttributesController) {
super(3000, `OpenId4VcHolder ${Math.random().toString()}`, getOpenIdHolderModules(), accountController, attributeController);
public constructor(accountController: AccountController, attributeController: AttributesController, fetchInstance: typeof fetch) {
super(3000, `OpenId4VcHolder ${Math.random().toString()}`, getOpenIdHolderModules(), accountController, attributeController, fetchInstance);
}

public async getVerifiableCredentials(ids: string[] | undefined): Promise<OwnIdentityAttribute[]> {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
ValidationResult
} from "../../../src";

import { NodeLoggerFactory } from "@js-soft/node-logger";
import { TestUtil } from "../../core/TestUtil";
import { MockEventBus } from "../MockEventBus";
import { TestObjectFactory } from "./testHelpers/TestObjectFactory";
Expand Down Expand Up @@ -78,6 +79,26 @@ export class RequestsTestsContext {
config,
new EventEmitter2EventBus(() => {
// noop
}),
new NodeLoggerFactory({
appenders: {
consoleAppender: {
type: "stdout",
layout: { type: "pattern", pattern: "%[[%p] %c - %m%]" }
},
console: {
type: "logLevelFilter",
level: "Warn",
appender: "consoleAppender"
}
},

categories: {
default: {
appenders: ["console"],
level: "TRACE"
}
}
})
).init();

Expand Down
8 changes: 7 additions & 1 deletion packages/runtime/test/consumption/openid4vc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ import { OpenId4VpResolvedAuthorizationRequest } from "@credo-ts/openid4vc";
import axios, { AxiosInstance } from "axios";
import path from "path";
import { DockerComposeEnvironment, StartedDockerComposeEnvironment, Wait } from "testcontainers";
import { Agent as UndiciAgent, fetch as undiciFetch } from "undici";
import { ConsumptionServices } from "../../src";
import { RuntimeServiceProvider } from "../lib";

const runtimeServiceProvider = new RuntimeServiceProvider();
const fetchInstance: typeof fetch = (async (input, init) => {
const response = await undiciFetch(input as any, { ...(init as any), dispatcher: new UndiciAgent({}) });
return response;
}) as typeof fetch;

const runtimeServiceProvider = new RuntimeServiceProvider(fetchInstance);
let consumptionServices: ConsumptionServices;
let axiosInstance: AxiosInstance;
let dockerComposeStack: StartedDockerComposeEnvironment | undefined;
Expand Down
5 changes: 4 additions & 1 deletion packages/runtime/test/lib/RuntimeServiceProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export interface LaunchConfiguration {
}

export class RuntimeServiceProvider {
public constructor(private readonly fetchInstance?: typeof fetch) {}

private readonly runtimes: TestRuntime[] = [];

public static get transportConfig(): Omit<IConfigOverwrite, "supportedIdentityVersion"> {
Expand Down Expand Up @@ -75,7 +77,8 @@ export class RuntimeServiceProvider {
const runtime = new TestRuntime(
config,
{
setDefaultOwnIdentityAttributes: launchConfiguration.enableDefaultOwnIdentityAttributes ?? false
setDefaultOwnIdentityAttributes: launchConfiguration.enableDefaultOwnIdentityAttributes ?? false,
fetchInstance: this.fetchInstance
},
launchConfiguration.useCorrelator ? correlator : undefined
);
Expand Down
22 changes: 1 addition & 21 deletions packages/transport/src/core/Transport.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ILogger, ILoggerFactory } from "@js-soft/logging-abstractions";
import { NodeLoggerFactory } from "@js-soft/node-logger";
import { EventBus } from "@js-soft/ts-utils";
import { SodiumWrapper } from "@nmshd/crypto";
import { AgentOptions } from "http";
Expand Down Expand Up @@ -85,26 +84,7 @@ export class Transport {
public constructor(
customConfig: IConfigOverwrite,
public readonly eventBus: EventBus,
loggerFactory: ILoggerFactory = new NodeLoggerFactory({
appenders: {
consoleAppender: {
type: "stdout",
layout: { type: "pattern", pattern: "%[[%p] %c - %m%]" }
},
console: {
type: "logLevelFilter",
level: "Warn",
appender: "consoleAppender"
}
},

categories: {
default: {
appenders: ["console"],
level: "TRACE"
}
}
}),
loggerFactory: ILoggerFactory,
public readonly correlator?: ICorrelator
) {
this._config = _.defaultsDeep({}, customConfig, Transport.defaultConfig);
Expand Down