From 08aeeca02cb2efc20762533001b2643706090f97 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, 29 Aug 2024 11:19:51 -0700 Subject: [PATCH] update 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> --- README.md | 4 +++- src/Agent.ts | 8 +++++++- src/InvitationFactory.ts | 18 ++++++++++++++++++ src/attestation.test.ts | 2 +- src/basic.test.ts | 8 ++++---- src/setup-from-sandbox.ts | 29 +++++++++++++++++++++-------- 6 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 src/InvitationFactory.ts diff --git a/README.md b/README.md index cd45525..cb9e6bc 100644 --- a/README.md +++ b/README.md @@ -28,5 +28,7 @@ ngrok http "file://${PWD}/tmp" ``` ## In terminal 2, run tests ``` -yarn jest --runInBand --detectOpenHandles --forceExit +## For running using the mobile app. Open tmp/__qrcode.png to see the generated QR Codes +export HOLDER_TYPE=manual +yarn jest --runInBand --detectOpenHandles --forceExit src/basic.test.ts ``` \ No newline at end of file diff --git a/src/Agent.ts b/src/Agent.ts index 6a997f8..61b9534 100644 --- a/src/Agent.ts +++ b/src/Agent.ts @@ -16,6 +16,12 @@ export type InvitationPayloadMapping = { [INVITATION_TYPE.OOB_DIDX_1_1]: InvitationRecordV2 } +export type InvitationArgumentMapping = { + [INVITATION_TYPE.CONN_1_0]: Record + [INVITATION_TYPE.OOB_CONN_1_0]: {goalCode: string} + [INVITATION_TYPE.OOB_DIDX_1_1]: {goalCode: string} +} + export type CreateInvitationResponse = {type: T, payload: InvitationPayloadMapping[T]} @@ -35,7 +41,7 @@ export type ReceiveInvitationResponse = { outOfBandRecord?: OutOfBandRecord; con export interface AriesAgent { readonly logger: Logger sendBasicMessage(connection_id: string, content: string): Promise - createInvitationToConnect(invitationType: T): Promise> + createInvitationToConnect(invitationType: T, args?: InvitationArgumentMapping[T]): Promise> receiveInvitation(invitation: ResponseCreateInvitation): Promise; startup(): Promise; shutdown(): Promise; diff --git a/src/InvitationFactory.ts b/src/InvitationFactory.ts new file mode 100644 index 0000000..14db448 --- /dev/null +++ b/src/InvitationFactory.ts @@ -0,0 +1,18 @@ +export abstract class CreateInvitationFactory { + +} +export class CreateInvitationFactoryConn1_0 extends CreateInvitationFactory { + connectionless: boolean; + constructor(connectionless:boolean = false){ + super(); + this.connectionless = connectionless + } +} + +export class CreateInvitationFactoryOOB extends CreateInvitationFactory { + connectionless: boolean; + constructor(connectionless:boolean = false){ + super(); + this.connectionless = connectionless + } +} diff --git a/src/attestation.test.ts b/src/attestation.test.ts index 13439ad..e108fbb 100644 --- a/src/attestation.test.ts +++ b/src/attestation.test.ts @@ -10,7 +10,7 @@ const stepTimeout = 999999999 const shortTimeout = (2 * 60) * 1000 import { setGlobalDispatcher, Agent } from 'undici'; -import { AriesAgent, INVITATION_TYPE, ResponseCreateInvitationV1 } from "./Agent"; +import { AriesAgent, INVITATION_TYPE } from "./Agent"; import { AgentManual } from "./AgentManual"; setGlobalDispatcher(new Agent({ connect: { timeout: 20_000 } })); diff --git a/src/basic.test.ts b/src/basic.test.ts index b3e7a8d..1705526 100644 --- a/src/basic.test.ts +++ b/src/basic.test.ts @@ -76,7 +76,7 @@ describe("Mandatory", () => { beforeEach(async () => { requests.length = 0 }) - test("connected/v1/M1", async () => { + test.skip("connected/v1/M1", async () => { const issuer = agentIssuer const holder = agentB logger.info(`Executing ${expect.getState().currentTestName}`) @@ -94,7 +94,7 @@ describe("Mandatory", () => { logger.info('Message Received:', msgRcvd) //expect(requests).toMatchSnapshot(); }, shortTimeout); - test("OOB/connected/messaging", async () => { + test.skip("OOB/connected/messaging", async () => { const issuer = agentIssuer const holder = agentB logger.info(`Executing ${expect.getState().currentTestName}`) @@ -126,11 +126,11 @@ describe("Mandatory", () => { } //expect(requests).toMatchSnapshot(); }, stepTimeout) - test.only("OOB/connected/issue", async () => { + test("OOB/connected/issue", async () => { + logger.info(`Executing ${expect.getState().currentTestName}`) const issuer = agentIssuer const holder = agentB const cred = new PersonCredential1(credDef) - const { logger } = issuer const remoteInvitation = await issuer.createOOBInvitationToConnect(INVITATION_TYPE.OOB_CONN_1_0) logger.info('remoteInvitation', remoteInvitation) logger.info(`waiting for holder to accept connection`) diff --git a/src/setup-from-sandbox.ts b/src/setup-from-sandbox.ts index 45435bd..a91a612 100644 --- a/src/setup-from-sandbox.ts +++ b/src/setup-from-sandbox.ts @@ -30,7 +30,8 @@ const checkTransactions = async (baseUrl:string, token:string) => { console.dir(['transactions', transactions], {depth: 5}) return transactions } -const run = async () => { + +const getNewTenant = async () => { console.log('Requesting tenant') const baseUrl = 'https://traction-sandbox-tenant-proxy.apps.silver.devops.gov.bc.ca' //${baseUiUrl}/api/innkeeperReservation @@ -135,18 +136,30 @@ const run = async () => { maxTransactionsChecks-- } + return { + base_url: baseUrl, + serviceEndpoint: baseUrl.replace('-tenant-proxy', '-acapy'), + tenant_id: tenant.tenant_id, + api_key: tenant.api_key, + wallet_id: checkin.wallet_id, + wallet_key: checkin.wallet_key + } +} +const run = async () => { + + const keys = ['schema_owner', 'issuer', 'verifier', 'holder'] const config:any = {} if (fs.existsSync(path.resolve('./local.env.json'))){ Object.assign(config, JSON.parse(fs.readFileSync(path.resolve('./local.env.json'), 'utf8'))) } - config['_new'] = config['default2']??{} - config['_new']['base_url'] = baseUrl - config['_new']['serviceEndpoint'] = baseUrl.replace('-tenant-proxy', '-acapy') - config['_new']['tenant_id'] = tenant.tenant_id - config['_new']['api_key'] = tenant.api_key - config['_new']['wallet_id'] = checkin.wallet_id - config['_new']['wallet_key'] = checkin.wallet_key + for (const key of keys) { + const teant = await getNewTenant() + const conf = config[key]??{} + //const config = {config[key]??{}, ...teant} + config[key] = {...conf, ...teant} + await new Promise(resolve => setTimeout(resolve, 2000)) + } fs.writeFileSync(path.resolve('./local.env.json'), JSON.stringify(config, undefined, 2), {encoding: 'utf8'}) } run()