diff --git a/examples/integration-scripts/challenge.test.ts b/examples/integration-scripts/challenge.test.ts index 0f8d1217..80e79000 100644 --- a/examples/integration-scripts/challenge.test.ts +++ b/examples/integration-scripts/challenge.test.ts @@ -97,11 +97,9 @@ test('challenge', async () => { // List Client 1 contacts let contacts1 = await client1.contacts().list(); - let bobContact = contacts1.find( - (contact: { alias: string }) => contact.alias === 'bob' - ); - expect(bobContact.alias).toEqual('bob'); - expect(bobContact.challenges).toHaveLength(0); + let bobContact = contacts1.find((contact) => contact.alias === 'bob'); + expect(bobContact?.alias).toEqual('bob'); + expect(bobContact?.challenges).toHaveLength(0); // Bob responds to Alice challenge await client2.challenges().respond('bob', aid1.i, challenge1_small.words); @@ -125,10 +123,10 @@ test('challenge', async () => { // Check Bob's challenge in conctats contacts1 = await client1.contacts().list(); - bobContact = contacts1.find( - (contact: { alias: string }) => contact.alias === 'bob' - ); - expect(bobContact.challenges[0].authenticated).toEqual(true); + bobContact = contacts1.find((contact) => contact.alias === 'bob'); + + assert(Array.isArray(bobContact?.challenges)); + expect(bobContact?.challenges[0].authenticated).toBe(true); await assertOperations(client1, client2); }, 30000); diff --git a/src/keri/app/contacting.ts b/src/keri/app/contacting.ts index ef31beb4..29b4888e 100644 --- a/src/keri/app/contacting.ts +++ b/src/keri/app/contacting.ts @@ -1,11 +1,23 @@ import { SignifyClient } from './clienting'; import { Operation } from './coring'; +export interface Contact { + alias: string; + oobi: string; + id: string; + [key: string]: unknown; +} + +export interface ContactInfo { + [key: string]: unknown; +} + /** * Contacts */ export class Contacts { client: SignifyClient; + /** * Contacts * @param {SignifyClient} client @@ -26,7 +38,7 @@ export class Contacts { group?: string, filterField?: string, filterValue?: string - ): Promise { + ): Promise { const params = new URLSearchParams(); if (group !== undefined) { params.append('group', group); @@ -48,7 +60,7 @@ export class Contacts { * @param {string} pre Prefix of the contact * @returns {Promise} A promise to the contact */ - async get(pre: string): Promise { + async get(pre: string): Promise { const path = `/contacts/` + pre; const method = 'GET'; const res = await this.client.fetch(path, method, null); @@ -58,11 +70,11 @@ export class Contacts { /** * Add a contact * @async - * @param {string} pre Prefix of the contact - * @param {any} info Information about the contact - * @returns {Promise} A promise to the result of the addition + * @param pre Prefix of the contact + * @param info Information about the contact + * @returns A promise to the result of the addition */ - async add(pre: string, info: any): Promise { + async add(pre: string, info: ContactInfo): Promise { const path = `/contacts/` + pre; const method = 'POST'; @@ -90,7 +102,7 @@ export class Contacts { * @param {any} info Updated information about the contact * @returns {Promise} A promise to the result of the update */ - async update(pre: string, info: any): Promise { + async update(pre: string, info: ContactInfo): Promise { const path = `/contacts/` + pre; const method = 'PUT'; @@ -99,6 +111,10 @@ export class Contacts { } } +export interface Challenge { + words: string[]; +} + /** * Challenges */ @@ -118,7 +134,7 @@ export class Challenges { * @param {number} strength Integer representing the strength of the challenge. Typically 128 or 256 * @returns {Promise} A promise to the list of random words */ - async generate(strength: number = 128): Promise { + async generate(strength: number = 128): Promise { const path = `/challenges?strength=${strength.toString()}`; const method = 'GET'; const res = await this.client.fetch(path, method, null); @@ -128,16 +144,16 @@ export class Challenges { /** * Respond to a challenge by signing a message with the list of words * @async - * @param {string} name Name or alias of the identifier - * @param {string} recipient Prefix of the recipient of the response - * @param {Array} words List of words to embed in the signed response - * @returns {Promise} A promise to the result of the response + * @param name Name or alias of the identifier + * @param recipient Prefix of the recipient of the response + * @param words List of words to embed in the signed response + * @returns A promise to the result of the response */ async respond( name: string, recipient: string, words: string[] - ): Promise { + ): Promise { const hab = await this.client.identifiers().get(name); const exchanges = this.client.exchanges(); const resp = await exchanges.send( @@ -154,8 +170,8 @@ export class Challenges { /** * Ask Agent to verify a given sender signed the provided words - * @param {string} source Prefix of the identifier that was challenged - * @param {Array} words List of challenge words to check for + * @param source Prefix of the identifier that was challenged + * @param words List of challenge words to check for * @returns A promise to the long running operation */ async verify(source: string, words: string[]): Promise> { @@ -171,8 +187,8 @@ export class Challenges { /** * Mark challenge response as signed and accepted - * @param {string} source Prefix of the identifier that was challenged - * @param {string} said qb64 AID of exn message representing the signed response + * @param source Prefix of the identifier that was challenged + * @param said qb64 AID of exn message representing the signed response * @returns {Promise} A promise to the result */ async responded(source: string, said: string): Promise { diff --git a/test/app/contacting.test.ts b/test/app/contacting.test.ts index ea9fce52..5be1753d 100644 --- a/test/app/contacting.test.ts +++ b/test/app/contacting.test.ts @@ -71,44 +71,6 @@ const mockGetAID = { windexes: [], }; -const mockCredential = { - sad: { - v: 'ACDC10JSON000197_', - d: 'EMwcsEMUEruPXVwPCW7zmqmN8m0I3CihxolBm-RDrsJo', - i: 'EMQQpnSkgfUOgWdzQTWfrgiVHKIDAhvAZIPQ6z3EAfz1', - ri: 'EGK216v1yguLfex4YRFnG7k1sXRjh3OKY7QqzdKsx7df', - s: 'EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao', - a: { - d: 'EK0GOjijKd8_RLYz9qDuuG29YbbXjU8yJuTQanf07b6P', - i: 'EKvn1M6shPLnXTb47bugVJblKMuWC0TcLIePP8p98Bby', - dt: '2023-08-23T15:16:07.553000+00:00', - LEI: '5493001KJTIIGC8Y1R17', - }, - }, - pre: 'EMQQpnSkgfUOgWdzQTWfrgiVHKIDAhvAZIPQ6z3EAfz1', - sadsigers: [ - { - path: '-', - pre: 'EMQQpnSkgfUOgWdzQTWfrgiVHKIDAhvAZIPQ6z3EAfz1', - sn: 0, - d: 'EMQQpnSkgfUOgWdzQTWfrgiVHKIDAhvAZIPQ6z3EAfz1', - }, - ], - sadcigars: [], - chains: [], - status: { - v: 'KERI10JSON000135_', - i: 'EMwcsEMUEruPXVwPCW7zmqmN8m0I3CihxolBm-RDrsJo', - s: '0', - d: 'ENf3IEYwYtFmlq5ZzoI-zFzeR7E3ZNRN2YH_0KAFbdJW', - ri: 'EGK216v1yguLfex4YRFnG7k1sXRjh3OKY7QqzdKsx7df', - ra: {}, - a: { s: 2, d: 'EIpgyKVF0z0Pcn2_HgbWhEKmJhOXFeD4SA62SrxYXOLt' }, - dt: '2023-08-23T15:16:07.553000+00:00', - et: 'iss', - }, -}; - fetchMock.mockResponse((req) => { if (req.url.startsWith(url + '/agent')) { return Promise.resolve({ body: mockConnect, init: { status: 202 } }); @@ -143,9 +105,7 @@ fetchMock.mockResponse((req) => { req.method, requrl.pathname.split('?')[0] ); - const body = req.url.startsWith(url + '/identifiers/aid1/credentials') - ? mockCredential - : mockGetAID; + const body = mockGetAID; return Promise.resolve({ body: JSON.stringify(body),