Skip to content

Commit

Permalink
deep link
Browse files Browse the repository at this point in the history
Signed-off-by: Clécio Varjão <[email protected]>
  • Loading branch information
cvarjao committed Nov 28, 2024
1 parent 6f38e4d commit 6151a60
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type ResponseCreateInvitationV1 = CreateInvitationResponse<INVITATION_TYP
export type ResponseCreateInvitationV2 = CreateInvitationResponse<INVITATION_TYPE.OOB_CONN_1_0> | CreateInvitationResponse<INVITATION_TYPE.OOB_DIDX_1_1>
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

Expand Down
38 changes: 34 additions & 4 deletions src/AgentTraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,31 @@ export class AgentTraction implements AriesAgent {
}
return results[0] as ConnectionRef
})
}
}
async _waitForConnectionReadyByInvitationKey (invitation_key:string, counter: number): Promise<any> {
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:{
Expand Down Expand Up @@ -676,10 +700,16 @@ export class AgentTraction implements AriesAgent {
return credential_exchange_id
})
}
async waitFoConnectionReady <T extends INVITATION_TYPE>(invitation: CreateInvitationResponse<T>): 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<ConnectionRef> {
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`)
Expand Down
6 changes: 3 additions & 3 deletions src/basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -94,15 +94,15 @@ 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}`)
const remoteInvitation = await issuer.createInvitationToConnect(INVITATION_TYPE.OOB_DIDX_1_1)
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')
Expand Down
2 changes: 1 addition & 1 deletion src/deep-links.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6151a60

Please sign in to comment.