diff --git a/src/keri/app/credentialing.ts b/src/keri/app/credentialing.ts index a13ddba3..39d535af 100644 --- a/src/keri/app/credentialing.ts +++ b/src/keri/app/credentialing.ts @@ -472,133 +472,6 @@ export class Credentials { op, }; } - - /** - * Present a credential - * @async - * @param {string} name Name or alias of the identifier - * @param {string} said SAID of the credential - * @param {string} recipient Identifier prefix of the receiver of the presentation - * @param {boolean} [include=true] Flag to indicate whether to stream credential alongside presentation exchange message - * @returns {Promise} A promise to the long-running operation - */ - async present( - name: string, - said: string, - recipient: string, - include: boolean = true - ): Promise { - const hab = await this.client.identifiers().get(name); - const pre: string = hab.prefix; - - const cred = await this.get(said); - const data = { - i: cred.sad.i, - s: cred.sad.s, - n: said, - }; - - const vs = versify(Ident.KERI, undefined, Serials.JSON, 0); - - const _sad = { - v: vs, - t: Ilks.exn, - d: '', - dt: new Date().toISOString().replace('Z', '000+00:00'), - r: '/presentation', - q: {}, - a: data, - }; - const [, sad] = Saider.saidify(_sad); - const exn = new Serder(sad); - - const keeper = this.client!.manager!.get(hab); - - const sig = await keeper.sign(b(exn.raw), true); - - const siger = new Siger({ qb64: sig[0] }); - const seal = ['SealLast', { i: pre }]; - let ims = messagize(exn, [siger], seal, undefined, undefined, true); - ims = ims.slice(JSON.stringify(exn.ked).length); - - const body = { - exn: exn.ked, - sig: new TextDecoder().decode(ims), - recipient: recipient, - include: include, - }; - - const path = `/identifiers/${name}/credentials/${said}/presentations`; - const method = 'POST'; - const headers = new Headers({ - Accept: 'application/json+cesr', - }); - const res = await this.client.fetch(path, method, body, headers); - return await res.text(); - } - - /** - * Request a presentation of a credential - * @async - * @param {string} name Name or alias of the identifier - * @param {string} recipient Identifier prefix of the receiver of the presentation - * @param {string} schema SAID of the schema - * @param {string} [issuer] Optional prefix of the issuer of the credential - * @returns {Promise} A promise to the long-running operation - */ - async request( - name: string, - recipient: string, - schema: string, - issuer?: string - ): Promise { - const hab = await this.client.identifiers().get(name); - const pre: string = hab.prefix; - - const data: any = { - s: schema, - }; - if (issuer !== undefined) { - data['i'] = issuer; - } - - const vs = versify(Ident.KERI, undefined, Serials.JSON, 0); - - const _sad = { - v: vs, - t: Ilks.exn, - d: '', - dt: new Date().toISOString().replace('Z', '000+00:00'), - r: '/presentation/request', - q: {}, - a: data, - }; - const [, sad] = Saider.saidify(_sad); - const exn = new Serder(sad); - - const keeper = this.client!.manager!.get(hab); - - const sig = await keeper.sign(b(exn.raw), true); - - const siger = new Siger({ qb64: sig[0] }); - const seal = ['SealLast', { i: pre }]; - let ims = messagize(exn, [siger], seal, undefined, undefined, true); - ims = ims.slice(JSON.stringify(exn.ked).length); - - const body = { - exn: exn.ked, - sig: new TextDecoder().decode(ims), - recipient: recipient, - }; - - const path = `/identifiers/${name}/requests`; - const method = 'POST'; - const headers = new Headers({ - Accept: 'application/json+cesr', - }); - const res = await this.client.fetch(path, method, body, headers); - return await res.text(); - } } export interface CreateRegistryArgs { diff --git a/test/app/credentialing.test.ts b/test/app/credentialing.test.ts index 99f36dcc..4156dcb6 100644 --- a/test/app/credentialing.test.ts +++ b/test/app/credentialing.test.ts @@ -315,59 +315,6 @@ describe('Credentialing', () => { ); assert.equal(lastBody.sigs[0].substring(0, 2), 'AA'); assert.equal(lastBody.sigs[0].length, 88); - - await credentials.present( - 'aid1', - credential, - 'EP10ooRj0DJF0HWZePEYMLPl-arMV-MAoTKK-o3DXbgX', - false - ); - lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length - 1]!; - lastBody = JSON.parse(lastCall[1]!.body!.toString()); - assert.equal( - lastCall[0]!, - url + - '/identifiers/aid1/credentials/' + - credential + - '/presentations' - ); - assert.equal(lastCall[1]!.method, 'POST'); - assert.equal(lastBody.exn.t, 'exn'); - assert.equal(lastBody.exn.r, '/presentation'); - assert.equal( - lastBody.exn.a.n, - 'ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK' - ); - assert.equal(lastBody.exn.a.s, schema); - assert.equal(lastBody.sig.length, 144); - assert.equal( - lastBody.recipient, - 'EP10ooRj0DJF0HWZePEYMLPl-arMV-MAoTKK-o3DXbgX' - ); - assert.equal(lastBody.include, false); - - await credentials.request( - 'aid1', - 'EP10ooRj0DJF0HWZePEYMLPl-arMV-MAoTKK-o3DXbgX', - credential, - 'EP10ooRj0DJF0HWZePEYMLPl-arMV-MAoTKK-o3DXbgX' - ); - lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length - 1]!; - lastBody = JSON.parse(lastCall[1]!.body!.toString()); - assert.equal(lastCall[0]!, url + '/identifiers/aid1/requests'); - assert.equal(lastCall[1]!.method, 'POST'); - assert.equal(lastBody.exn.t, 'exn'); - assert.equal(lastBody.exn.r, '/presentation/request'); - assert.equal(lastBody.exn.a.i, registry); - assert.equal( - lastBody.exn.a.s, - 'ELUvZ8aJEHAQE-0nsevyYTP98rBbGJUrTj5an-pCmwrK' - ); - assert.equal(lastBody.sig.length, 144); - assert.equal( - lastBody.recipient, - 'EP10ooRj0DJF0HWZePEYMLPl-arMV-MAoTKK-o3DXbgX' - ); }); });