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
4 changes: 0 additions & 4 deletions src/cliAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,6 @@ export async function runRestAgent(restConfig: AriesRestConfig) {
anoncreds: new AnonCredsModule({
registries: [new IndySdkAnonCredsRegistry()],
}),
dids: new DidsModule({
resolvers: [new IndySdkIndyDidResolver(), new KeyDidResolver()],
registrars: [new IndySdkIndyDidRegistrar(), new KeyDidRegistrar()],
}),
connections: new ConnectionsModule({
autoAcceptConnections: true,
}),
Expand Down
27 changes: 21 additions & 6 deletions src/controllers/connections/ConnectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { injectable } from 'tsyringe'
import { ConnectionRecordExample, RecordId } from '../examples'

@Tags('Connections')
@Route('/connections')
@Route()
@injectable()
export class ConnectionController extends Controller {
private agent: Agent
Expand All @@ -33,7 +33,7 @@ export class ConnectionController extends Controller {
* @returns ConnectionRecord[]
*/
@Example<ConnectionRecordProps[]>([ConnectionRecordExample])
@Get('/')
@Get('/connections')
public async getAllConnections(
@Query('outOfBandId') outOfBandId?: string,
@Query('alias') alias?: string,
Expand Down Expand Up @@ -75,7 +75,7 @@ export class ConnectionController extends Controller {
* @returns ConnectionRecord
*/
@Example<ConnectionRecordProps>(ConnectionRecordExample)
@Get('/:connectionId')
@Get('/connections/:connectionId')
public async getConnectionById(
@Path('connectionId') connectionId: RecordId,
@Res() notFoundError: TsoaResponse<404, { reason: string }>
Expand All @@ -92,7 +92,7 @@ export class ConnectionController extends Controller {
*
* @param connectionId Connection identifier
*/
@Delete('/:connectionId')
@Delete('/connections/:connectionId')
public async deleteConnection(
@Path('connectionId') connectionId: RecordId,
@Res() notFoundError: TsoaResponse<404, { reason: string }>,
Expand All @@ -119,7 +119,7 @@ export class ConnectionController extends Controller {
* @returns ConnectionRecord
*/
@Example<ConnectionRecordProps>(ConnectionRecordExample)
@Post('/:connectionId/accept-request')
@Post('/connections/:connectionId/accept-request')
public async acceptRequest(
@Path('connectionId') connectionId: RecordId,
@Res() notFoundError: TsoaResponse<404, { reason: string }>,
Expand All @@ -146,7 +146,7 @@ export class ConnectionController extends Controller {
* @returns ConnectionRecord
*/
@Example<ConnectionRecordProps>(ConnectionRecordExample)
@Post('/:connectionId/accept-response')
@Post('/connections/:connectionId/accept-response')
public async acceptResponse(
@Path('connectionId') connectionId: RecordId,
@Res() notFoundError: TsoaResponse<404, { reason: string }>,
Expand All @@ -162,4 +162,19 @@ export class ConnectionController extends Controller {
return internalServerError(500, { message: `something went wrong: ${error}` })
}
}

@Get('/url/:invitationId')
public async getInvitation(
@Path('invitationId') invitationId: string,
@Res() notFoundError: TsoaResponse<404, { reason: string }>,
@Res() internalServerError: TsoaResponse<500, { message: string }>
) {
const outOfBandRecord = await this.agent.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;
}
}
38 changes: 36 additions & 2 deletions src/controllers/did/DidController.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { DidCreate, DidResolutionResultProps } from '../types'
import { KeyType, TypedArrayEncoder, KeyDidCreateOptions } from '@aries-framework/core'
import { KeyType, TypedArrayEncoder, KeyDidCreateOptions, DidDocumentBuilder, getEd25519VerificationKey2018 } from '@aries-framework/core'
import { Agent } from '@aries-framework/core'
import { Body, Controller, Example, Get, Path, Post, Res, Route, Tags, TsoaResponse } from 'tsoa'
import { injectable } from 'tsyringe'
Expand Down Expand Up @@ -118,7 +118,7 @@ export class DidController extends Controller {
}
}

@Post('/create-key-did')
@Post('/did/key')
public async createDidKey(
@Body() didOptions: DidCreate,
@Res() internalServerError: TsoaResponse<500, { message: string }>
Expand Down Expand Up @@ -149,6 +149,40 @@ export class DidController extends Controller {
}
}

@Post('/did/web')
public async createDidWeb(
@Body() didOptions: DidCreate,
@Res() internalServerError: TsoaResponse<500, { message: string }>
) {
try {
const domain = 'credebl.github.io';
const did = `did:web:${domain}`;
const keyId = `${did}#key-1`;

const key = await this.agent.wallet.createKey({
keyType: KeyType.Ed25519,
privateKey: TypedArrayEncoder.fromString(didOptions.seed)
});

const didDocument = new DidDocumentBuilder(did)
.addContext('https://w3id.org/security/suites/ed25519-2018/v1')
.addVerificationMethod(getEd25519VerificationKey2018({ key, id: keyId, controller: did }))
.addAuthentication(keyId)
.build();

await this.agent.dids.import({
did,
overwrite: true,
didDocument
});
return { did };
} catch (error) {
return internalServerError(500, { message: `something went wrong: ${error}` })
}
}



@Get('/')
public async getDids() {
const createdDids = await this.agent.dids.getCreatedDids()
Expand Down
59 changes: 58 additions & 1 deletion src/controllers/multi-tenancy/MultiTenancyController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AcceptCredentialOfferOptions, AcceptProofRequestOptions, Agent, AriesFrameworkError, ConnectionRepository, CreateOutOfBandInvitationConfig, CredentialProtocolVersionType, CredentialRepository, CredentialState, DidExchangeState, JsonTransformer, KeyType, OutOfBandInvitation, ProofExchangeRecordProps, ProofsProtocolVersionType, RecordNotFoundError, TypedArrayEncoder, injectable } from '@aries-framework/core'
import { AcceptCredentialOfferOptions, AcceptProofRequestOptions, Agent, AriesFrameworkError, ConnectionRepository, CreateOutOfBandInvitationConfig, CredentialProtocolVersionType, CredentialRepository, CredentialState, DidDocumentBuilder, DidExchangeState, JsonTransformer, KeyDidCreateOptions, KeyType, OutOfBandInvitation, ProofExchangeRecordProps, ProofsProtocolVersionType, RecordNotFoundError, TypedArrayEncoder, getEd25519VerificationKey2018, injectable } from '@aries-framework/core'
import { CreateOfferOobOptions, CreateOfferOptions, CreateProofRequestOobOptions, CreateTenantOptions, GetTenantAgentOptions, ReceiveInvitationByUrlProps, ReceiveInvitationProps, WithTenantAgentOptions } from '../types';
import { Body, Controller, Delete, Get, Post, Query, Res, Route, Tags, TsoaResponse, Path, Example } from 'tsoa'
import axios from 'axios';
Expand Down Expand Up @@ -98,6 +98,63 @@ export class MultiTenancyController extends Controller {
return { tenantRecord, did: `did:indy:indicio:${body.did}`, verkey };
}
})
} else if ('key' === createTenantOptions.method) {

const did = await this.agent.dids.create<KeyDidCreateOptions>({
method: 'key',
options: {
keyType: KeyType.Ed25519,
},
secret: {
privateKey: TypedArrayEncoder.fromString(seed)
}
});
await this.agent.dids.import({
did: `${did.didState.did}`,
overwrite: true,
privateKeys: [
{
keyType: KeyType.Ed25519,
privateKey: TypedArrayEncoder.fromString(seed)
},
],
});
const resolveResult = await this.agent.dids.resolve(`did:key:${did}`);
let verkey;
if (resolveResult.didDocument?.verificationMethod) {
verkey = resolveResult.didDocument.verificationMethod[0].publicKeyBase58;
}
return { tenantRecord, did, verkey };

} else if ('web' === createTenantOptions.method) {

const domain = 'credebl.github.io';
const did = `did:web:${domain}`;
const keyId = `${did}#key-1`;

const key = await this.agent.wallet.createKey({
keyType: KeyType.Ed25519,
privateKey: TypedArrayEncoder.fromString(seed)
});

const didDocument = new DidDocumentBuilder(did)
.addContext('https://w3id.org/security/suites/ed25519-2018/v1')
.addVerificationMethod(getEd25519VerificationKey2018({ key, id: keyId, controller: did }))
.addAuthentication(keyId)
.build();

await this.agent.dids.import({
did,
overwrite: true,
didDocument
});

const resolveResult = await this.agent.dids.resolve(did);
let verkey;
if (resolveResult.didDocument?.verificationMethod) {
verkey = resolveResult.didDocument.verificationMethod[0].publicKeyBase58;
}
return { tenantRecord, did, verkey };
}
} catch (error) {
if (error instanceof RecordNotFoundError) {
Expand Down