From 6151a60ca803f0e47d206b9a4faf043393e499ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9cio=20Varj=C3=A3o?= <1348549+cvarjao@users.noreply.github.com> Date: Thu, 28 Nov 2024 11:17:30 -0800 Subject: [PATCH] deep link MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Clécio Varjão <1348549+cvarjao@users.noreply.github.com> --- src/Agent.ts | 2 +- src/AgentTraction.ts | 38 ++++++++++++++++++++++++++++++++++---- src/basic.test.ts | 6 +++--- src/deep-links.test.ts | 2 +- 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/src/Agent.ts b/src/Agent.ts index a5b1c43..bfe8f6a 100644 --- a/src/Agent.ts +++ b/src/Agent.ts @@ -29,7 +29,7 @@ export type ResponseCreateInvitationV1 = CreateInvitationResponse | CreateInvitationResponse export type ResponseCreateInvitation = ResponseCreateInvitationV1 | ResponseCreateInvitationV2 -export type ConnectionRef = {connection_id: string} +export type ConnectionRef = {connection_id: string, invitation_key?:string} export type Invitation = {invitation_url: string} & ConnectionRef export type CredentialOfferRef = {id: string} & ConnectionRef diff --git a/src/AgentTraction.ts b/src/AgentTraction.ts index 30d5ae3..6aaecce 100644 --- a/src/AgentTraction.ts +++ b/src/AgentTraction.ts @@ -68,7 +68,31 @@ export class AgentTraction implements AriesAgent { } return results[0] as ConnectionRef }) - } + } + async _waitForConnectionReadyByInvitationKey (invitation_key:string, counter: number): Promise { + return await this.axios.get(`/connections`, { + params: {invitation_key}, + headers:{ + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${this.config.auth_token}` + } + }) + .then((value)=>{ + if (value.data.results.length > 0 ) { + const conn = value.data.results[0] + this.logger.info(`connection state: ${conn.state}`) + if (conn.state === 'active') { + return conn + } + + } + return new Promise ((resolve) => { + setTimeout(() => { + resolve(this._waitForConnectionReadyByInvitationKey(invitation_key, counter + 1)) + }, 2000); + }) + }) + } async _waitForConnectionReady (connection_id:string, counter: number) { await this.axios.get(`/connections/${connection_id}`, { headers:{ @@ -676,10 +700,16 @@ export class AgentTraction implements AriesAgent { return credential_exchange_id }) } + async waitFoConnectionReady (invitation: CreateInvitationResponse): Promise<{ connection_id: any; }> { + if (invitation.type === INVITATION_TYPE.OOB_DIDX_1_1) { + //todo: something + } + return {connection_id:''} + } async waitForOOBConnectionReady (invi_msg_id:string): Promise { - const {connection_id} = await this._waitForOOBConnectionRecord(invi_msg_id, 0) - await this.waitForConnectionReady(connection_id) - return {connection_id} + const {invitation_key} = await this._waitForOOBConnectionRecord(invi_msg_id, 0) + const conn = await this._waitForConnectionReadyByInvitationKey(invitation_key as string, 0) + return {connection_id: conn.connection_id} } async waitForConnectionReady (connection_id:string) { this.logger.info(`Waiting for connection ${connection_id} to get stablished`) diff --git a/src/basic.test.ts b/src/basic.test.ts index d197905..bfbecdb 100644 --- a/src/basic.test.ts +++ b/src/basic.test.ts @@ -7,7 +7,7 @@ import { CredentialDefinitionBuilder, issueCredential, PinoLogger, ProofRequestB import pino from "pino"; const stepTimeout = 120_000 -const shortTimeout = 40_000 +const shortTimeout = 4_000_000 import { dir as console_dir } from "console" import { setGlobalDispatcher, Agent} from 'undici'; import { AriesAgent, INVITATION_TYPE } from "./Agent"; @@ -94,7 +94,7 @@ describe("Mandatory", () => { logger.info('Message Received:', msgRcvd) //expect(requests).toMatchSnapshot(); }, shortTimeout); - test("OOB/connected/messaging", async () => { + test.only("OOB/connected/messaging", async () => { const issuer = agentIssuer const holder = agentB logger.info(`Executing ${expect.getState().currentTestName}`) @@ -102,7 +102,7 @@ describe("Mandatory", () => { logger.info(`waiting for holder to accept connection`) const agentBConnectionRef1 = await holder.receiveInvitation(remoteInvitation) logger.info(`waiting for issuer to accept connection`) - const {connection_id} = await issuer.waitForOOBConnectionReady(remoteInvitation.payload.invi_msg_id) + const {connection_id} = await issuer.waitFoConnectionReady(remoteInvitation) logger.info(`${connection_id} connected to ${agentBConnectionRef1.connectionRecord?.connection_id}`) logger.info('agentBConnectionRef1', agentBConnectionRef1) const msgSent: any = await issuer.sendBasicMessage(connection_id, 'Hello') diff --git a/src/deep-links.test.ts b/src/deep-links.test.ts index a7926e6..292e912 100644 --- a/src/deep-links.test.ts +++ b/src/deep-links.test.ts @@ -63,7 +63,7 @@ describe("deep-links", () => { console_dir(error.response) return Promise.reject(error); }) - + await agentIssuer.clearAllRecords() await agentSchemaOwner.createSchema(schema); await agentIssuer.createSchemaCredDefinition(credDef); }, stepTimeout);