Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove obsolete request and present methods #287

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 0 additions & 127 deletions src/keri/app/credentialing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>} A promise to the long-running operation
*/
async present(
name: string,
said: string,
recipient: string,
include: boolean = true
): Promise<string> {
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<string>} A promise to the long-running operation
*/
async request(
name: string,
recipient: string,
schema: string,
issuer?: string
): Promise<string> {
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 {
Expand Down
53 changes: 0 additions & 53 deletions test/app/credentialing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
});
});

Expand Down
Loading