Skip to content
Snippets Groups Projects
Commit 520af0c7 authored by Berend Sliedrecht's avatar Berend Sliedrecht
Browse files

fix(ssi-abstraction): submit the rev reg def without recreating it


Signed-off-by: default avatarBerend Sliedrecht <berend@animo.id>
parent 3bf59914
Branches ssi-revocation
No related tags found
No related merge requests found
...@@ -73,13 +73,11 @@ export type EventDidcommConnectionsReceiveInvitationFromUrlInput = ...@@ -73,13 +73,11 @@ export type EventDidcommConnectionsReceiveInvitationFromUrlInput =
BaseEventInput<{ BaseEventInput<{
invitationUrl: string; invitationUrl: string;
}>; }>;
export class EventDidcommConnectionsReceiveInvitationFromUrl extends BaseEvent<ConnectionRecord | null> { export class EventDidcommConnectionsReceiveInvitationFromUrl extends BaseEvent<ConnectionRecord> {
public static token = 'didcomm.connections.receiveInvitationFromUrl'; public static token = 'didcomm.connections.receiveInvitationFromUrl';
public get instance() { public get instance() {
return this.data return JsonTransformer.fromJSON(this.data, ConnectionRecord);
? JsonTransformer.fromJSON(this.data, ConnectionRecord)
: null;
} }
public static fromEvent(e: EventDidcommConnectionsReceiveInvitationFromUrl) { public static fromEvent(e: EventDidcommConnectionsReceiveInvitationFromUrl) {
......
...@@ -78,7 +78,6 @@ export class AgentService implements OnApplicationShutdown { ...@@ -78,7 +78,6 @@ export class AgentService implements OnApplicationShutdown {
}); });
this.agent.registerInboundTransport(httpInbound); this.agent.registerInboundTransport(httpInbound);
this.agent.registerOutboundTransport(new WsOutboundTransport()); this.agent.registerOutboundTransport(new WsOutboundTransport());
this.agent.registerOutboundTransport(new HttpOutboundTransport()); this.agent.registerOutboundTransport(new HttpOutboundTransport());
} }
...@@ -96,7 +95,7 @@ export class AgentService implements OnApplicationShutdown { ...@@ -96,7 +95,7 @@ export class AgentService implements OnApplicationShutdown {
key: walletKey, key: walletKey,
}, },
endpoints, endpoints,
logger: new AgentLogger(LogLevel.warn), logger: new AgentLogger(LogLevel.off),
}; };
} }
......
...@@ -9,7 +9,7 @@ import type { ...@@ -9,7 +9,7 @@ import type {
EventDidcommConnectionsCreateInvitationInput, EventDidcommConnectionsCreateInvitationInput,
} from '@ocm/shared'; } from '@ocm/shared';
import { ConnectionRecord } from '@credo-ts/core'; import { ConnectionRecord, DidExchangeState } from '@credo-ts/core';
import { ClientsModule, Transport } from '@nestjs/microservices'; import { ClientsModule, Transport } from '@nestjs/microservices';
import { Test } from '@nestjs/testing'; import { Test } from '@nestjs/testing';
import { import {
...@@ -34,6 +34,7 @@ describe('Connections', () => { ...@@ -34,6 +34,7 @@ describe('Connections', () => {
let app: INestApplication; let app: INestApplication;
let client: ClientProxy; let client: ClientProxy;
let tenantId: string; let tenantId: string;
let tenantIdTwo: string;
beforeAll(async () => { beforeAll(async () => {
const moduleRef = await Test.createTestingModule({ const moduleRef = await Test.createTestingModule({
...@@ -59,6 +60,9 @@ describe('Connections', () => { ...@@ -59,6 +60,9 @@ describe('Connections', () => {
const ts = app.get(TenantsService); const ts = app.get(TenantsService);
const { id } = await ts.create({ label: TOKEN }); const { id } = await ts.create({ label: TOKEN });
tenantId = id; tenantId = id;
const { id: idTwo } = await ts.create({ label: `${TOKEN}-two` });
tenantIdTwo = idTwo;
}); });
afterAll(async () => { afterAll(async () => {
...@@ -138,6 +142,53 @@ describe('Connections', () => { ...@@ -138,6 +142,53 @@ describe('Connections', () => {
expect(eventInstance.instance).toBeInstanceOf(ConnectionRecord); expect(eventInstance.instance).toBeInstanceOf(ConnectionRecord);
}); });
it(`Create and receive invitation between tenants`, async () => {
const createInvitationResponse$ = client.send<
EventDidcommConnectionsCreateInvitation,
EventDidcommConnectionsCreateInvitationInput
>(EventDidcommConnectionsCreateInvitation.token, {
tenantId: tenantIdTwo,
});
const createInvitationResponse = await firstValueFrom(
createInvitationResponse$,
);
const {
instance: { invitationUrl },
} = EventDidcommConnectionsCreateInvitation.fromEvent(
createInvitationResponse,
);
const response$ = client.send<
EventDidcommConnectionsReceiveInvitationFromUrl,
EventDidcommConnectionsReceiveInvitationFromUrlInput
>(EventDidcommConnectionsReceiveInvitationFromUrl.token, {
invitationUrl,
tenantId,
});
const response = await firstValueFrom(response$);
const { instance: connectionRecord } =
EventDidcommConnectionsReceiveInvitationFromUrl.fromEvent(response);
await new Promise((r) => setTimeout(r, 2000));
const getByIdResponse$ = client.send<
EventDidcommConnectionsGetById,
EventDidcommConnectionsGetByIdInput
>(EventDidcommConnectionsGetById.token, {
tenantId,
id: connectionRecord.id,
});
const getByIdResponse = await firstValueFrom(getByIdResponse$);
const { instance: maybeRecord } =
EventDidcommConnectionsGetById.fromEvent(getByIdResponse);
if (!maybeRecord) {
throw new Error(`Record not found with id: ${connectionRecord.id}`);
}
expect(maybeRecord.state).toStrictEqual(DidExchangeState.Completed);
});
it(EventDidcommConnectionsCreateWithSelf.token, async () => { it(EventDidcommConnectionsCreateWithSelf.token, async () => {
const response$ = client.send< const response$ = client.send<
EventDidcommConnectionsCreateWithSelf, EventDidcommConnectionsCreateWithSelf,
......
...@@ -5,14 +5,21 @@ import type { ...@@ -5,14 +5,21 @@ import type {
EventAnonCredsRevocationRegisterRevocationRegistryDefinitionInput, EventAnonCredsRevocationRegisterRevocationRegistryDefinitionInput,
EventAnonCredsRevocationRegisterRevocationStatusListInput, EventAnonCredsRevocationRegisterRevocationStatusListInput,
EventAnonCredsRevocationRevokeInput, EventAnonCredsRevocationRevokeInput,
EventDidcommAnonCredsCredentialsOfferToSelfInput, EventDidcommAnonCredsCredentialsOfferInput,
EventDidcommConnectionsCreateInvitationInput,
EventDidcommConnectionsGetByIdInput,
EventDidcommConnectionsReceiveInvitationFromUrlInput,
} from '@ocm/shared'; } from '@ocm/shared';
import { DidExchangeState } from '@credo-ts/core';
import { ClientsModule, Transport } from '@nestjs/microservices'; import { ClientsModule, Transport } from '@nestjs/microservices';
import { Test } from '@nestjs/testing'; import { Test } from '@nestjs/testing';
import { import {
EventDidcommConnectionsGetById,
EventDidcommAnonCredsCredentialsOffer,
EventDidcommConnectionsReceiveInvitationFromUrl,
EventDidcommConnectionsCreateInvitation,
EventAnonCredsRevocationCheckCredentialStatus, EventAnonCredsRevocationCheckCredentialStatus,
EventDidcommAnonCredsCredentialsOfferToSelf,
EventAnonCredsRevocationRegisterRevocationRegistryDefinition, EventAnonCredsRevocationRegisterRevocationRegistryDefinition,
EventAnonCredsRevocationRegisterRevocationStatusList, EventAnonCredsRevocationRegisterRevocationStatusList,
EventAnonCredsRevocationRevoke, EventAnonCredsRevocationRevoke,
...@@ -24,7 +31,6 @@ import { firstValueFrom } from 'rxjs'; ...@@ -24,7 +31,6 @@ import { firstValueFrom } from 'rxjs';
import { AgentModule } from '../src/agent/agent.module.js'; import { AgentModule } from '../src/agent/agent.module.js';
import { AnonCredsCredentialsModule } from '../src/agent/anoncredsCredentials/anoncredsCredentials.module.js'; import { AnonCredsCredentialsModule } from '../src/agent/anoncredsCredentials/anoncredsCredentials.module.js';
import { ConnectionsModule } from '../src/agent/connections/connections.module.js'; import { ConnectionsModule } from '../src/agent/connections/connections.module.js';
import { ConnectionsService } from '../src/agent/connections/connections.service.js';
import { CredentialDefinitionsModule } from '../src/agent/credentialDefinitions/credentialDefinitions.module.js'; import { CredentialDefinitionsModule } from '../src/agent/credentialDefinitions/credentialDefinitions.module.js';
import { CredentialDefinitionsService } from '../src/agent/credentialDefinitions/credentialDefinitions.service.js'; import { CredentialDefinitionsService } from '../src/agent/credentialDefinitions/credentialDefinitions.service.js';
import { DidsModule } from '../src/agent/dids/dids.module.js'; import { DidsModule } from '../src/agent/dids/dids.module.js';
...@@ -40,10 +46,13 @@ describe('Revocation', () => { ...@@ -40,10 +46,13 @@ describe('Revocation', () => {
const TOKEN = 'REVOCATION_CLIENT_SERVICE'; const TOKEN = 'REVOCATION_CLIENT_SERVICE';
let app: INestApplication; let app: INestApplication;
let client: ClientProxy; let client: ClientProxy;
let tenantId: string; let tenantId: string;
let tenantIdTwo: string;
let issuerDid: string; let issuerDid: string;
let credentialDefinitionId: string; let credentialDefinitionId: string;
let connectionId: string;
beforeAll(async () => { beforeAll(async () => {
const moduleRef = await Test.createTestingModule({ const moduleRef = await Test.createTestingModule({
...@@ -75,8 +84,10 @@ describe('Revocation', () => { ...@@ -75,8 +84,10 @@ describe('Revocation', () => {
const { id } = await tenantsService.create({ label: TOKEN }); const { id } = await tenantsService.create({ label: TOKEN });
tenantId = id; tenantId = id;
const connectionsService = app.get(ConnectionsService); const { id: idTwo } = await tenantsService.create({
await connectionsService.createConnectionWithSelf({ tenantId }); label: `${TOKEN}-two`,
});
tenantIdTwo = idTwo;
const ds = app.get(DidsService); const ds = app.get(DidsService);
await ds.registerEndorserDids(); await ds.registerEndorserDids();
...@@ -113,7 +124,7 @@ describe('Revocation', () => { ...@@ -113,7 +124,7 @@ describe('Revocation', () => {
client.close(); client.close();
}); });
xit( it(
EventAnonCredsRevocationRegisterRevocationRegistryDefinition.token, EventAnonCredsRevocationRegisterRevocationRegistryDefinition.token,
async () => { async () => {
const response$ = client.send< const response$ = client.send<
...@@ -221,13 +232,65 @@ describe('Revocation', () => { ...@@ -221,13 +232,65 @@ describe('Revocation', () => {
expect(eventInstance.instance).toMatchObject({}); expect(eventInstance.instance).toMatchObject({});
} }
// Establish a connection with another tenant
{
const createInvitationResponse$ = client.send<
EventDidcommConnectionsCreateInvitation,
EventDidcommConnectionsCreateInvitationInput
>(EventDidcommConnectionsCreateInvitation.token, {
tenantId: tenantIdTwo,
});
const createInvitationResponse = await firstValueFrom(
createInvitationResponse$,
);
const {
instance: { invitationUrl },
} = EventDidcommConnectionsCreateInvitation.fromEvent(
createInvitationResponse,
);
const response$ = client.send<
EventDidcommConnectionsReceiveInvitationFromUrl,
EventDidcommConnectionsReceiveInvitationFromUrlInput
>(EventDidcommConnectionsReceiveInvitationFromUrl.token, {
invitationUrl,
tenantId,
});
const response = await firstValueFrom(response$);
const { instance: connectionRecord } =
EventDidcommConnectionsReceiveInvitationFromUrl.fromEvent(response);
// Wait for the connection to be established
await new Promise((r) => setTimeout(r, 2000));
const getByIdResponse$ = client.send<
EventDidcommConnectionsGetById,
EventDidcommConnectionsGetByIdInput
>(EventDidcommConnectionsGetById.token, {
tenantId,
id: connectionRecord.id,
});
const getByIdResponse = await firstValueFrom(getByIdResponse$);
const { instance: maybeRecord } =
EventDidcommConnectionsGetById.fromEvent(getByIdResponse);
if (!maybeRecord) {
throw new Error(`Record not found with id: ${connectionRecord.id}`);
}
expect(maybeRecord.state).toStrictEqual(DidExchangeState.Completed);
connectionId = connectionRecord.id;
}
// Issue a credential // Issue a credential
{ {
const response$ = client.send< const response$ = client.send<
EventDidcommAnonCredsCredentialsOfferToSelf, EventDidcommAnonCredsCredentialsOffer,
EventDidcommAnonCredsCredentialsOfferToSelfInput EventDidcommAnonCredsCredentialsOfferInput
>(EventDidcommAnonCredsCredentialsOfferToSelf.token, { >(EventDidcommAnonCredsCredentialsOffer.token, {
tenantId, tenantId,
connectionId,
attributes: [ attributes: [
{ name: 'Name', value: 'Berend' }, { name: 'Name', value: 'Berend' },
{ name: 'Age', value: '30' }, { name: 'Age', value: '30' },
...@@ -237,7 +300,7 @@ describe('Revocation', () => { ...@@ -237,7 +300,7 @@ describe('Revocation', () => {
}); });
const response = await firstValueFrom(response$); const response = await firstValueFrom(response$);
const eventInstance = const eventInstance =
EventDidcommAnonCredsCredentialsOfferToSelf.fromEvent(response); EventDidcommAnonCredsCredentialsOffer.fromEvent(response);
credentialId = eventInstance.instance.id; credentialId = eventInstance.instance.id;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment