Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync develop to main branch #105

Merged
merged 6 commits into from
Apr 30, 2024
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
20 changes: 18 additions & 2 deletions src/controllers/multi-tenancy/MultiTenancyController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@
private async handleKey(createDidOptions: DidCreate, tenantId: string) {
let didResponse
let did: string
let didDocument: any

Check warning on line 386 in src/controllers/multi-tenancy/MultiTenancyController.ts

View workflow job for this annotation

GitHub Actions / Validate

Unexpected any. Specify a different type

await this.agent.modules.tenants.withTenantAgent({ tenantId }, async (tenantAgent) => {
if (!createDidOptions.seed) {
Expand Down Expand Up @@ -438,7 +438,7 @@

private async handleWeb(createDidOptions: DidCreate, tenantId: string) {
let did
let didDocument: any

Check warning on line 441 in src/controllers/multi-tenancy/MultiTenancyController.ts

View workflow job for this annotation

GitHub Actions / Validate

Unexpected any. Specify a different type

if (!createDidOptions.domain) {
throw Error('For web method domain is required')
Expand Down Expand Up @@ -639,12 +639,27 @@
public async createInvitation(
@Res() internalServerError: TsoaResponse<500, { message: string }>,
@Path('tenantId') tenantId: string,
@Body() config?: Omit<CreateOutOfBandInvitationConfig, 'routing' | 'appendedAttachments' | 'messages'> // props removed because of issues with serialization
@Body() config?: Omit<CreateOutOfBandInvitationConfig, 'routing'> & RecipientKeyOption // Remove routing property from type
) {
let outOfBandRecord: OutOfBandRecord | undefined
let finalConfig: Omit<CreateOutOfBandInvitationConfig, 'routing'> & RecipientKeyOption & { routing?: Routing } = {} // Initialize finalConfig

try {
await this.agent.modules.tenants.withTenantAgent({ tenantId }, async (tenantAgent) => {
outOfBandRecord = await tenantAgent.oob.createInvitation(config)
if (config?.recipientKey) {
const routing: Routing = {
// Initialize routing object
endpoints: tenantAgent.config.endpoints,
routingKeys: [],
recipientKey: Key.fromPublicKeyBase58(config.recipientKey, KeyType.Ed25519),
mediatorId: undefined,
}
finalConfig = { ...config, routing } // Assign finalConfig
} else {
finalConfig = { ...config, routing: await tenantAgent.mediationRecipient.getRouting({}) } // Assign finalConfig
}

outOfBandRecord = await tenantAgent.oob.createInvitation(finalConfig)
})

return {
Expand All @@ -655,6 +670,7 @@
useDidSovPrefixWhereAllowed: this.agent.config.useDidSovPrefixWhereAllowed,
}),
outOfBandRecord: outOfBandRecord?.toJSON(),
...(finalConfig?.recipientKey ? {} : { recipientKey: finalConfig.routing?.recipientKey.publicKeyBase58 }), // Access recipientKey from routing
}
} catch (error) {
return internalServerError(500, { message: `something went wrong: ${error}` })
Expand Down Expand Up @@ -769,8 +785,8 @@
outOfBandRecords = await tenantAgent.oob.getAll()

if (invitationId)
outOfBandRecords = outOfBandRecords.filter((o: any) => o.outOfBandInvitation.id === invitationId)

Check warning on line 788 in src/controllers/multi-tenancy/MultiTenancyController.ts

View workflow job for this annotation

GitHub Actions / Validate

Unexpected any. Specify a different type
outOfBandRecordsRes = outOfBandRecords.map((c: any) => c.toJSON())

Check warning on line 789 in src/controllers/multi-tenancy/MultiTenancyController.ts

View workflow job for this annotation

GitHub Actions / Validate

Unexpected any. Specify a different type
})

return outOfBandRecordsRes
Expand Down
25 changes: 17 additions & 8 deletions src/controllers/outofband/OutOfBandController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { OutOfBandInvitationProps, OutOfBandRecordWithInvitationProps } from '../examples'
import type { AgentMessageType, RecipientKeyOption } from '../types'
import type { AgentMessageType, RecipientKeyOption, CreateInvitationOptions } from '../types'
import type { ConnectionRecordProps, CreateLegacyInvitationConfig, Routing } from '@credo-ts/core'

import {
Expand All @@ -14,12 +14,7 @@ import {
import { injectable } from 'tsyringe'

import { ConnectionRecordExample, outOfBandInvitationExample, outOfBandRecordExample, RecordId } from '../examples'
import {
AcceptInvitationConfig,
ReceiveInvitationByUrlProps,
ReceiveInvitationProps,
CreateInvitationOptions,
} from '../types'
import { AcceptInvitationConfig, ReceiveInvitationByUrlProps, ReceiveInvitationProps } from '../types'

import {
Body,
Expand Down Expand Up @@ -101,9 +96,22 @@ export class OutOfBandController extends Controller {
@Post('/create-invitation')
public async createInvitation(
@Res() internalServerError: TsoaResponse<500, { message: string }>,
@Body() config: CreateInvitationOptions // props removed because of issues with serialization
@Body() config: CreateInvitationOptions & RecipientKeyOption // props removed because of issues with serialization
) {
try {
let routing: Routing
if (config?.recipientKey) {
routing = {
endpoints: this.agent.config.endpoints,
routingKeys: [],
recipientKey: Key.fromPublicKeyBase58(config.recipientKey, KeyType.Ed25519),
mediatorId: undefined,
}
} else {
routing = await this.agent.mediationRecipient.getRouting({})
}

config.routing = routing
const outOfBandRecord = await this.agent.oob.createInvitation(config)
return {
invitationUrl: outOfBandRecord.outOfBandInvitation.toUrl({
Expand All @@ -113,6 +121,7 @@ export class OutOfBandController extends Controller {
useDidSovPrefixWhereAllowed: this.agent.config.useDidSovPrefixWhereAllowed,
}),
outOfBandRecord: outOfBandRecord.toJSON(),
...(config?.recipientKey ? {} : { recipientKey: routing.recipientKey.publicKeyBase58 }),
}
} catch (error) {
return internalServerError(500, { message: `something went wrong: ${error}` })
Expand Down
Loading