Skip to content

Commit

Permalink
feat(wip): init cleanup done
Browse files Browse the repository at this point in the history
  • Loading branch information
outSH committed Dec 7, 2023
1 parent 17a7a31 commit 9f345b3
Show file tree
Hide file tree
Showing 15 changed files with 356 additions and 277 deletions.
34 changes: 8 additions & 26 deletions packages/cactus-plugin-ledger-connector-aries/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@hyperledger/cactus-plugin-ledger-connector-aries",
"version": "2.0.0-alpha.2",
"description": "Allows Cactus nodes to connect to an Anoncreds ledger and Aries agents.",
"description": "Allows Cactus nodes to connect to an Indy ledger and Aries agents.",
"keywords": [
"Hyperledger",
"Cacti",
Expand Down Expand Up @@ -59,7 +59,6 @@
"@aries-framework/anoncreds-rs": "0.5.0-alpha.58",
"@aries-framework/askar": "0.5.0-alpha.58",
"@aries-framework/core": "0.5.0-alpha.58",
"@aries-framework/indy-sdk": "0.5.0-alpha.58",
"@aries-framework/indy-vdr": "0.5.0-alpha.58",
"@aries-framework/node": "0.5.0-alpha.58",
"@hyperledger/anoncreds-nodejs": "0.2.0-dev.4",
Expand All @@ -68,46 +67,29 @@
"@hyperledger/cactus-core": "2.0.0-alpha.2",
"@hyperledger/cactus-core-api": "2.0.0-alpha.2",
"@hyperledger/indy-vdr-nodejs": "0.2.0-dev.3",
"axios": "1.5.1",
"express": "4.18.2",
"http-proxy-middleware": "2.0.6",
"minimist": "1.2.8",
"prom-client": "13.2.0",
"run-time-error": "1.4.0",
"rxjs": "7.8.1",
"sanitize-html": "2.7.0",
"socket.io-client": "4.5.4",
"typescript-optional": "2.0.1",
"web3": "4.1.2",
"web3-eth": "4.2.0",
"web3-eth-contract": "4.1.0"
"socket.io-client": "4.5.4"
},
"devDependencies": {
"@hyperledger/cactus-plugin-keychain-memory": "2.0.0-alpha.2",
"@hyperledger/cactus-test-geth-ledger": "2.0.0-alpha.2",
"@hyperledger/cactus-test-tooling": "2.0.0-alpha.2",
"@types/body-parser": "1.19.4",
"@types/express": "4.17.19",
"@types/js-yaml": "4.0.5",
"@types/minimist": "1.2.2",
"@types/sanitize-html": "2.6.2",
"@types/uuid": "9.0.6",
"body-parser": "1.20.2",
"chalk": "4.1.2",
"js-yaml": "4.1.0",
"express": "4.18.2",
"jest": "29.6.2",
"jest-extended": "4.0.1",
"socket.io": "4.5.4",
"uuid": "9.0.1",
"web3-eth-accounts": "4.0.6"
"uuid": "9.0.1"
},
"engines": {
"node": ">=10",
"npm": ">=6"
"node": ">=18",
"npm": ">=8"
},
"publishConfig": {
"access": "public"
},
"browserMinified": "dist/cactus-plugin-ledger-connector-aries.web.umd.min.js",
"mainMinified": "dist/cactus-plugin-ledger-connector-aries.node.umd.min.js",
"watch": {
"codegen:openapi": {
"patterns": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"openapi": "3.0.3",
"info": {
"title": "Hyperledger Cacti Plugin - Connector Aries",
"description": "Can communicate with other Aries agents",
"description": "Can communicate with other Aries agents and Cacti Aries connectors",
"version": "v2.0.0-alpha.2",
"license": {
"name": "Apache-2.0",
Expand Down Expand Up @@ -58,7 +58,7 @@
},
"WatchProofStateV1": {
"type": "string",
"description": "Websocket requests for monitoring connection change events.",
"description": "Websocket requests for monitoring proof state change events.",
"enum": [
"org.hyperledger.cactus.api.async.hlaries.WatchProofStateV1.Subscribe",
"org.hyperledger.cactus.api.async.hlaries.WatchProofStateV1.Next",
Expand All @@ -76,7 +76,7 @@
},
"WatchProofStateOptionsV1": {
"type": "object",
"description": "Options passed when monitoring proof change events.",
"description": "Options passed when monitoring proof state change events.",
"required": ["agentName"],
"properties": {
"agentName": {
Expand Down Expand Up @@ -604,7 +604,6 @@
}
}
},

"/api/v1/plugins/@hyperledger/cactus-plugin-ledger-connector-aries/create-new-connection-invitation": {
"post": {
"x-hyperledger-cacti": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { Observable, ReplaySubject, Subscription } from "rxjs";
import { Observable, ReplaySubject } from "rxjs";
import { finalize } from "rxjs/operators";
import { io } from "socket.io-client";
import { Logger, Checks } from "@hyperledger/cactus-common";
import { LogLevelDesc, LoggerProvider } from "@hyperledger/cactus-common";
import { ProofState } from "@aries-framework/core";

import {
Logger,
Checks,
LogLevelDesc,
LoggerProvider,
} from "@hyperledger/cactus-common";
import { Constants } from "@hyperledger/cactus-core-api";

import {
AgentConnectionRecordV1,
AriesProofExchangeRecordV1,
Expand All @@ -17,16 +24,22 @@ import {
WatchProofStateV1,
} from "../generated/openapi/typescript-axios";
import { Configuration } from "../generated/openapi/typescript-axios/configuration";
import { ProofExchangeRecord, ProofState } from "@aries-framework/core";

export class AriesApiClientOptions extends Configuration {
readonly logLevel?: LogLevelDesc;
readonly wsApiHost?: string;
readonly wsApiPath?: string;
}

/**
* Default timeout when waiting for certain operations (accepting proof, establishing connection, etc...)
*/
const DEFAULT_ARIES_OPERATION_TIMEOUT = 60 * 1000;

/**
* How often to poll endpoints when waiting for operation to finish.
*/
const WAIT_FOR_CONNECTION_READY_POLL_INTERVAL = 500;
const DEFAULT_ARIES_OPERATION_TIMEOUT = 60 * 1000; // must be greater than 1000

export class AriesApiClient extends DefaultApi {
private readonly log: Logger;
Expand Down Expand Up @@ -54,6 +67,13 @@ export class AriesApiClient extends DefaultApi {
this.log.debug(`basePath=${this.options.basePath}`);
}

/**
* Watch for connection state changes on given agent.
* Example: New connection request, connection accepted.
*
* @param options Monitor options
* @returns rxjs `Observable`
*/
public watchConnectionStateV1(
options: WatchConnectionStateOptionsV1,
): Observable<WatchConnectionStateProgressV1> {
Expand Down Expand Up @@ -96,6 +116,13 @@ export class AriesApiClient extends DefaultApi {
);
}

/**
* Watch for proof state changes on given agent.
* Example: Proof request received, proof request was accepted by peer
*
* @param options Monitor options
* @returns rxjs `Observable`
*/
public watchProofStateV1(
options: WatchProofStateOptionsV1,
): Observable<WatchProofStateProgressV1> {
Expand Down Expand Up @@ -135,11 +162,22 @@ export class AriesApiClient extends DefaultApi {
);
}

/**
* Helper method to wait for connection record to be created.
* This does not mean that connection is ready though, just that it was accepted by the peer.
* Will block until operation is completed.
*
* @param agentName agent that requested the connection.
* @param outOfBandId new connection outOfBandId
* @param timeout how much time to wait before giving up.
*/
private async waitForConnectionRecordV1(
agentName: string,
outOfBandId: string,
timeout = DEFAULT_ARIES_OPERATION_TIMEOUT,
): Promise<void> {
Checks.truthy(agentName, "waitForConnectionRecordV1 arg agentName");
Checks.truthy(outOfBandId, "waitForConnectionRecordV1 arg outOfBandId");
this.log.debug(
"waitForConnectionRecordV1 for agent",
agentName,
Expand Down Expand Up @@ -205,7 +243,14 @@ export class AriesApiClient extends DefaultApi {
});
}

async waitForConnectionReadyV1(
/**
* Wait (block execution) until connection with specified `outOfBandId` is ready (connected).
*
* @param agentName agent with specific connection
* @param outOfBandId connection outOfBandId
* @param timeout how much time to wait before giving up. Must be at least 1 second.
*/
public async waitForConnectionReadyV1(
agentName: string,
outOfBandId: string,
timeout = DEFAULT_ARIES_OPERATION_TIMEOUT,
Expand Down Expand Up @@ -252,7 +297,15 @@ export class AriesApiClient extends DefaultApi {
);
}

async waitForInvitedPeerConnectionV1(
/**
* Wait until invitation URL is accepted by remote client and connection is established.
* Will block until operation is completed.
*
* @param agentName agent that requested the connection (sent the invitation)
* @param outOfBandId new connection outOfBandId
* @param timeout how much time to wait before giving up.
*/
public async waitForInvitedPeerConnectionV1(
agentName: string,
outOfBandId: string,
timeout = DEFAULT_ARIES_OPERATION_TIMEOUT,
Expand All @@ -273,11 +326,22 @@ export class AriesApiClient extends DefaultApi {
await this.waitForConnectionReadyV1(agentName, outOfBandId, timeout);
}

async waitForProofCompletionV1(
/**
* Wait until proof with specified ID was either accepted or denied.
* Will block until operation is completed.
*
* @param agentName agent that requested the proof.
* @param proofId id of the proof request.
* @param timeout how much time to wait before giving up.
*/
public async waitForProofCompletionV1(
agentName: string,
proofId: string,
timeout = DEFAULT_ARIES_OPERATION_TIMEOUT,
): Promise<AriesProofExchangeRecordV1> {
Checks.truthy(agentName, "waitForProofCompletionV1 arg agentName");
Checks.truthy(proofId, "waitForProofCompletionV1 arg proofId");

return new Promise<AriesProofExchangeRecordV1>((resolve, reject) => {
// Common cleanup method for leaving the method
const cleanup = () => {
Expand Down Expand Up @@ -331,12 +395,25 @@ export class AriesApiClient extends DefaultApi {
});
}

async requestProofAndWaitV1(
/**
* Send proof request and wait for response (accepted / denied by a peer)
* Will block until operation is completed.
*
* @param agentName agent that will request the proof.
* @param connectionId peer connection id that should provide the proof.
* @param proofAttributes proof attributes to validate.
* @param timeout how much time to wait before giving up.
*/
public async requestProofAndWaitV1(
agentName: string,
connectionId: string,
proofAttributes: CactiProofRequestAttributeV1[],
timeout = DEFAULT_ARIES_OPERATION_TIMEOUT,
): Promise<AriesProofExchangeRecordV1> {
Checks.truthy(agentName, "requestProofAndWaitV1 arg agentName");
Checks.truthy(connectionId, "requestProofAndWaitV1 arg connectionId");
Checks.truthy(proofAttributes, "requestProofAndWaitV1 arg proofAttributes");

const proof = await this.requestProofV1({
agentName,
connectionId,
Expand Down
Loading

0 comments on commit 9f345b3

Please sign in to comment.