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

refactor: Implemented and configured the Indicio testnet. #106

Merged
merged 9 commits into from
Oct 5, 2023
2 changes: 2 additions & 0 deletions apps/agent-provisioning/AFJ/scripts/start_agent.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ CONTAINER_NAME=${11}
PROTOCOL=${12}
TENANT=${13}
AFJ_VERSION=${14}
INDY_LEDGER=${15}
ADMIN_PORT=$((8000 + $AGENCY))
INBOUND_PORT=$((9000 + $AGENCY))
CONTROLLER_PORT=$((3000 + $AGENCY))
Expand Down Expand Up @@ -55,6 +56,7 @@ cat <<EOF >>${PWD}/apps/agent-provisioning/AFJ/agent-config/${AGENCY}_${CONTAINE
"walletAdminAccount": "$WALLET_STORAGE_USER",
"walletAdminPassword": "$WALLET_STORAGE_PASSWORD",
"walletScheme": "DatabasePerWallet",
"indyLedger": $INDY_LEDGER,
"endpoint": [
"$AGENT_ENDPOINT"
],
Expand Down
8 changes: 5 additions & 3 deletions apps/agent-provisioning/AFJ/scripts/start_agent_ecs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ CONTAINER_NAME=${11}
PROTOCOL=${12}
TENANT=${13}
AFJ_VERSION=${14}
AGENT_HOST=${15}
AWS_ACCOUNT_ID=${16}
S3_BUCKET_ARN=${17}
INDY_LEDGER=${15}
AGENT_HOST=${16}
AWS_ACCOUNT_ID=${17}
S3_BUCKET_ARN=${18}
ADMIN_PORT=$((8000 + AGENCY))
INBOUND_PORT=$((9000 + AGENCY))
CONTROLLER_PORT=$((3000 + AGENCY))
Expand All @@ -45,6 +46,7 @@ cat <<EOF >>/app/agent-provisioning/AFJ/agent-config/${AGENCY}_${CONTAINER_NAME}
"walletAdminAccount": "$WALLET_STORAGE_USER",
"walletAdminPassword": "$WALLET_STORAGE_PASSWORD",
"walletScheme": "DatabasePerWallet",
"indyLedger": $INDY_LEDGER,
"endpoint": [
"$AGENT_ENDPOINT"
],
Expand Down
4 changes: 2 additions & 2 deletions apps/agent-provisioning/src/agent-provisioning.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ export class AgentProvisioningService {
async walletProvision(payload: IWalletProvision): Promise<object> {
try {

const { containerName, externalIp, orgId, seed, walletName, walletPassword, walletStorageHost, walletStoragePassword, walletStoragePort, walletStorageUser, webhookEndpoint, agentType, protocol, afjVersion, tenant } = payload;
const { containerName, externalIp, orgId, seed, walletName, walletPassword, walletStorageHost, walletStoragePassword, walletStoragePort, walletStorageUser, webhookEndpoint, agentType, protocol, afjVersion, tenant, indyLedger } = payload;

if (agentType === AgentType.AFJ) {
// The wallet provision command is used to invoke a shell script
const walletProvision = `${process.cwd() + process.env.AFJ_AGENT_SPIN_UP
} ${orgId} "${externalIp}" "${walletName}" "${walletPassword}" ${seed} ${webhookEndpoint} ${walletStorageHost} ${walletStoragePort} ${walletStorageUser} ${walletStoragePassword} ${containerName} ${protocol} ${tenant} ${afjVersion} ${process.env.AGENT_HOST} ${process.env.AWS_ACCOUNT_ID} ${process.env.S3_BUCKET_ARN}`;
} ${orgId} "${externalIp}" "${walletName}" "${walletPassword}" ${seed} ${webhookEndpoint} ${walletStorageHost} ${walletStoragePort} ${walletStorageUser} ${walletStoragePassword} ${containerName} ${protocol} ${tenant} ${afjVersion} ${indyLedger} ${process.env.AGENT_HOST} ${process.env.AWS_ACCOUNT_ID} ${process.env.S3_BUCKET_ARN}`;

const spinUpResponse: object = new Promise(async (resolve) => {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface IWalletProvision {
containerName: string;
agentType: AgentType;
orgName: string;
genesisUrl: string;
indyLedger: string;
protocol: string;
afjVersion: string;
tenant: boolean;
Expand Down
151 changes: 76 additions & 75 deletions apps/agent-service/src/agent-service.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,11 @@ export class AgentServiceService {

agentSpinupDto.agentType = agentSpinupDto.agentType ? agentSpinupDto.agentType : 1;
agentSpinupDto.tenant = agentSpinupDto.tenant ? agentSpinupDto.tenant : false;
agentSpinupDto.ledgerId = !agentSpinupDto.ledgerId || 0 === agentSpinupDto.ledgerId.length ? [1] : agentSpinupDto.ledgerId;


const platformConfig: platform_config = await this.agentServiceRepository.getPlatformConfigDetails();
const ledgerDetails: ledgers = await this.agentServiceRepository.getGenesisUrl(agentSpinupDto.ledgerId);
const ledgerDetails: ledgers[] = await this.agentServiceRepository.getGenesisUrl(agentSpinupDto.ledgerId);
const orgData: organisation = await this.agentServiceRepository.getOrgDetails(agentSpinupDto.orgId);

if (!orgData) {
Expand Down Expand Up @@ -177,6 +179,18 @@ export class AgentServiceService {
controllerIp
);

const ledgerArray = [];
for (const iterator of ledgerDetails) {
const ledgerJson = {};

ledgerJson["genesisTransactions"] = iterator.poolConfig;
ledgerJson["indyNamespace"] = iterator.indyNamespace;

ledgerArray.push(ledgerJson);
}

const ledgerString = JSON.stringify(ledgerArray);
const escapedJsonString = ledgerString.replace(/"/g, '\\"');
if (agentSpinupDto.agentType === AgentType.ACAPY) {

// TODO: ACA-PY Agent Spin-Up
Expand All @@ -197,7 +211,7 @@ export class AgentServiceService {
containerName,
agentType: AgentType.AFJ,
orgName: orgData.name,
genesisUrl: ledgerDetails?.poolConfig,
indyLedger: escapedJsonString,
afjVersion: process.env.AFJ_VERSION,
protocol: process.env.API_GATEWAY_PROTOCOL,
tenant: agentSpinupDto.tenant
Expand Down Expand Up @@ -470,14 +484,10 @@ export class AgentServiceService {
async _createTenant(payload: ITenantDto, user: IUserRequestInterface): Promise<void> {
try {

payload.ledgerId = !payload.ledgerId || 0 === payload.ledgerId.length ? [1] : payload.ledgerId;

const ledgerDetails: ledgers[] = await this.agentServiceRepository.getGenesisUrl(payload.ledgerId);
const sharedAgentSpinUpResponse = new Promise(async (resolve, _reject) => {
const { label, seed } = payload;
const createTenantOptions = {
config: {
label
},
seed
};

const socket = await io(`${process.env.SOCKET_HOST}`, {
reconnection: true,
Expand All @@ -504,45 +514,57 @@ export class AgentServiceService {
throw new NotFoundException('Platform-admin agent is not spun-up');
}

const apiKey = '';
let tenantDetails;
const url = `${platformAdminSpinnedUp.org_agents[0].agentEndPoint}${CommonConstants.URL_SHAGENT_CREATE_TENANT}`;
const tenantDetails = await this.commonService
.httpPost(url, createTenantOptions, { headers: { 'x-api-key': apiKey } })
.then(async (tenant) => {
this.logger.debug(`API Response Data: ${JSON.stringify(tenant)}`);
return tenant;
});
for (const iterator of ledgerDetails) {
const { label, seed } = payload;
const createTenantOptions = {
config: {
label
},
seed,
method: iterator.indyNamespace
};
const apiKey = '';
tenantDetails = await this.commonService
.httpPost(url, createTenantOptions, { headers: { 'x-api-key': apiKey } })
.then(async (tenant) => {
this.logger.debug(`API Response Data: ${JSON.stringify(tenant)}`);
return tenant;
});

const storeOrgAgentData: IStoreOrgAgentDetails = {
did: tenantDetails.did,
verkey: tenantDetails.verkey,
isDidPublic: true,
agentSpinUpStatus: 2,
agentsTypeId: AgentType.AFJ,
orgId: payload.orgId,
agentEndPoint: platformAdminSpinnedUp.org_agents[0].agentEndPoint,
orgAgentTypeId: OrgAgentType.SHARED,
tenantId: tenantDetails.tenantRecord.id,
walletName: label
};

if (payload.clientSocketId) {
socket.emit('agent-spinup-process-completed', { clientId: payload.clientSocketId });
}

const storeOrgAgentData: IStoreOrgAgentDetails = {
did: tenantDetails.did,
verkey: tenantDetails.verkey,
isDidPublic: true,
agentSpinUpStatus: 2,
agentsTypeId: AgentType.AFJ,
orgId: payload.orgId,
agentEndPoint: platformAdminSpinnedUp.org_agents[0].agentEndPoint,
orgAgentTypeId: OrgAgentType.SHARED,
tenantId: tenantDetails.tenantRecord.id,
walletName: label
};
const saveTenant = await this.agentServiceRepository.storeOrgAgentDetails(storeOrgAgentData);

if (payload.clientSocketId) {
socket.emit('agent-spinup-process-completed', { clientId: payload.clientSocketId });
}

const saveTenant = await this.agentServiceRepository.storeOrgAgentDetails(storeOrgAgentData);
if (payload.clientSocketId) {
socket.emit('invitation-url-creation-started', { clientId: payload.clientSocketId });
}

if (payload.clientSocketId) {
socket.emit('invitation-url-creation-started', { clientId: payload.clientSocketId });
}
await this._createLegacyConnectionInvitation(payload.orgId, user, storeOrgAgentData.walletName);

await this._createLegacyConnectionInvitation(payload.orgId, user, storeOrgAgentData.walletName);
if (payload.clientSocketId) {
socket.emit('invitation-url-creation-success', { clientId: payload.clientSocketId });
}

if (payload.clientSocketId) {
socket.emit('invitation-url-creation-success', { clientId: payload.clientSocketId });
resolve(saveTenant);
}

resolve(saveTenant);
} else {
throw new InternalServerErrorException('Agent not able to spin-up');
}
Expand Down Expand Up @@ -599,16 +621,12 @@ export class AgentServiceService {

} else if (2 === payload.agentType) {

const url = `${payload.agentEndPoint}${CommonConstants.URL_SHAGENT_WITH_TENANT_AGENT}`;
const url = `${payload.agentEndPoint}${CommonConstants.URL_SHAGENT_CREATE_SCHEMA}`.replace('#', `${payload.tenantId}`);
const schemaPayload = {
tenantId: payload.tenantId,
method: 'registerSchema',
payload: {
attributes: payload.payload.attributes,
version: payload.payload.version,
name: payload.payload.name,
issuerId: payload.payload.issuerId
}
attributes: payload.payload.attributes,
version: payload.payload.version,
name: payload.payload.name,
issuerId: payload.payload.issuerId
};
schemaResponse = await this.commonService.httpPost(url, schemaPayload, { headers: { 'x-api-key': payload.apiKey } })
.then(async (schema) => {
Expand Down Expand Up @@ -636,15 +654,9 @@ export class AgentServiceService {
});

} else if (2 === payload.agentType) {
const url = `${payload.agentEndPoint}${CommonConstants.URL_SHAGENT_WITH_TENANT_AGENT}`;
const schemaPayload = {
tenantId: payload.tenantId,
method: payload.method,
payload: {
'schemaId': `${payload.payload.schemaId}`
}
};
schemaResponse = await this.commonService.httpPost(url, schemaPayload, { headers: { 'x-api-key': payload.apiKey } })
const url = `${payload.agentEndPoint}${CommonConstants.URL_SHAGENT_GET_SCHEMA}`.replace('@', `${payload.payload.schemaId}`).replace('#', `${payload.tenantId}`);

schemaResponse = await this.commonService.httpGet(url, { headers: { 'x-api-key': payload.apiKey } })
.then(async (schema) => {
this.logger.debug(`API Response Data: ${JSON.stringify(schema)}`);
return schema;
Expand Down Expand Up @@ -674,15 +686,11 @@ export class AgentServiceService {
});

} else if (2 === payload.agentType) {
const url = `${payload.agentEndPoint}${CommonConstants.URL_SHAGENT_WITH_TENANT_AGENT}`;
const url = `${payload.agentEndPoint}${CommonConstants.URL_SHAGENT_CREATE_CRED_DEF}`.replace('#', `${payload.tenantId}`);
const credDefPayload = {
tenantId: payload.tenantId,
method: 'registerCredentialDefinition',
payload: {
tag: payload.payload.tag,
schemaId: payload.payload.schemaId,
issuerId: payload.payload.issuerId
}
tag: payload.payload.tag,
schemaId: payload.payload.schemaId,
issuerId: payload.payload.issuerId
};
credDefResponse = await this.commonService.httpPost(url, credDefPayload, { headers: { 'x-api-key': payload.apiKey } })
.then(async (credDef) => {
Expand Down Expand Up @@ -710,15 +718,8 @@ export class AgentServiceService {
});

} else if (2 === payload.agentType) {
const url = `${payload.agentEndPoint}${CommonConstants.URL_SHAGENT_WITH_TENANT_AGENT}`;
const credDefPayload = {
tenantId: payload.tenantId,
method: payload.method,
payload: {
'credentialDefinitionId': `${payload.payload.credentialDefinitionId}`
}
};
credDefResponse = await this.commonService.httpPost(url, credDefPayload, { headers: { 'x-api-key': payload.apiKey } })
const url = `${payload.agentEndPoint}${CommonConstants.URL_SHAGENT_GET_CRED_DEF}`.replace('@', `${payload.payload.credentialDefinitionId}`).replace('#', `${payload.tenantId}`);
credDefResponse = await this.commonService.httpGet(url, { headers: { 'x-api-key': payload.apiKey } })
.then(async (credDef) => {
this.logger.debug(`API Response Data: ${JSON.stringify(credDef)}`);
return credDef;
Expand Down
8 changes: 5 additions & 3 deletions apps/agent-service/src/interface/agent-service.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ export interface IAgentSpinupDto {
walletPassword: string;
seed: string;
orgId: number;
ledgerId?: number[];
agentType?: AgentType;
ledgerId?: number;
transactionApproval?: boolean;
clientSocketId?: string
tenant?: boolean;
Expand All @@ -17,8 +17,10 @@ export interface IAgentSpinupDto {
export interface ITenantDto {
label: string;
seed: string;
tenantId?: string;
ledgerId?: number[];
method: string;
orgId: number;
tenantId?: string;
clientSocketId?: string;
}

Expand Down Expand Up @@ -103,7 +105,7 @@ export interface IWalletProvision {
containerName: string;
agentType: AgentType;
orgName: string;
genesisUrl: string;
indyLedger: string;
afjVersion: string;
protocol: string;
tenant: boolean;
Expand Down
3 changes: 2 additions & 1 deletion apps/agent-service/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ async function bootstrap(): Promise<void> {
walletPassword: process.env.PLATFORM_WALLET_PASSWORD,
seed: process.env.PLATFORM_SEED,
orgId: parseInt(process.env.PLATFORM_ID),
tenant: true
tenant: true,
ledgerId: [1, 2]
};

const agentService = app.get(AgentServiceService);
Expand Down
20 changes: 11 additions & 9 deletions apps/agent-service/src/repositories/agent-service.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ export class AgentServiceRepository {
* @param id
* @returns
*/
async getGenesisUrl(id: number): Promise<ledgers> {
async getGenesisUrl(ledgerId: number[]): Promise<ledgers[]> {
try {

const genesisData = await this.prisma.ledgers.findFirst({
const genesisData = await this.prisma.ledgers.findMany({
where: {
id
id: {
in: ledgerId
}
}
});
return genesisData;
Expand Down Expand Up @@ -135,13 +137,13 @@ export class AgentServiceRepository {
}
}

/**
* Get agent details
* @param orgId
* @returns Agent health details
*/
/**
* Get agent details
* @param orgId
* @returns Agent health details
*/
// eslint-disable-next-line camelcase
async getOrgAgentDetails(orgId: number): Promise<org_agents> {
async getOrgAgentDetails(orgId: number): Promise<org_agents> {
try {
const oranizationAgentDetails = await this.prisma.org_agents.findFirst({
where: {
Expand Down
Loading