Skip to content

Commit

Permalink
Merge pull request #15 from credebl/multi-tenant-connection
Browse files Browse the repository at this point in the history
Added legacy connection API and also add the get invitation by invitatioId
  • Loading branch information
tipusinghaw authored Aug 21, 2023
2 parents 2edd21f + 61586f4 commit 72d2c1f
Show file tree
Hide file tree
Showing 4 changed files with 882 additions and 509 deletions.
2 changes: 1 addition & 1 deletion src/controllers/did/DidController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class DidController extends Controller {
@Res() internalServerError: TsoaResponse<500, { message: string }>
) {
try {
const domain = 'credebl.github.io';
const domain = didOptions.domain ? didOptions.domain : 'credebl.github.io';
const did = `did:web:${domain}`;
const keyId = `${did}#key-1`;

Expand Down
41 changes: 41 additions & 0 deletions src/controllers/multi-tenancy/MultiTenancyController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,31 @@ export class MultiTenancyController extends Controller {
}
}

@Post('/create-legacy-invitation/:tenantId')
public async createLegacyInvitation(
@Res() internalServerError: TsoaResponse<500, { message: string }>,
@Path("tenantId") tenantId: string,
@Body() config?: Omit<CreateOutOfBandInvitationConfig, 'routing' | 'appendedAttachments' | 'messages'> // props removed because of issues with serialization
) {
try {
const tenantAgent = await this.agent.modules.tenants.getTenantAgent({ tenantId });
const { outOfBandRecord, invitation } = await tenantAgent.oob.createLegacyInvitation(config)

return {
invitationUrl: invitation.toUrl({
domain: this.agent.config.endpoints[0],
useDidSovPrefixWhereAllowed: this.agent.config.useDidSovPrefixWhereAllowed,
}),
invitation: invitation.toJSON({
useDidSovPrefixWhereAllowed: this.agent.config.useDidSovPrefixWhereAllowed,
}),
outOfBandRecord: outOfBandRecord.toJSON(),
}
} catch (error) {
return internalServerError(500, { message: `something went wrong: ${error}` })
}
}

@Post('/receive-invitation/:tenantId')
public async receiveInvitation(
@Body() invitationRequest: ReceiveInvitationProps,
Expand Down Expand Up @@ -272,6 +297,22 @@ export class MultiTenancyController extends Controller {
}
}

@Get('/url/:tenantId/:invitationId')
public async getInvitation(
@Path('invitationId') invitationId: string,
@Path('tenantId') tenantId: string,
@Res() notFoundError: TsoaResponse<404, { reason: string }>,
) {
const tenantAgent = await this.agent.modules.tenants.getTenantAgent({ tenantId });
const outOfBandRecord = await tenantAgent.oob.findByCreatedInvitationId(invitationId)

if (!outOfBandRecord || outOfBandRecord.state !== 'await-response')
return notFoundError(404, { reason: `connection with invitationId "${invitationId}" not found.` })

const invitationJson = outOfBandRecord.outOfBandInvitation.toJSON({ useDidSovPrefixWhereAllowed: true })
return invitationJson;
}

@Post('/schema/:tenantId')
public async createSchema(
@Body()
Expand Down
1 change: 1 addition & 0 deletions src/controllers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ export interface ResolvedDid {

export interface DidCreate {
seed: string;
domain?: string;
method?: string;
did?: string;
options?: DidRegistrationExtraOptions;
Expand Down
Loading

0 comments on commit 72d2c1f

Please sign in to comment.