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

Update challenge and credential endpoints to remove unneeded path parameters #209

Merged
merged 2 commits into from
Feb 4, 2024
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
6 changes: 2 additions & 4 deletions examples/integration-scripts/challenge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ test('challenge', async () => {
// Alice verifies Bob's response
const verifyOperation = await waitOperation(
client1,
await client1
.challenges()
.verify('alice', aid2.i, challenge1_small.words)
await client1.challenges().verify(aid2.i, challenge1_small.words)
);
console.log('Alice verified challenge response');

Expand All @@ -114,7 +112,7 @@ test('challenge', async () => {
};
const exn = new Serder(verifyResponse.exn);

await client1.challenges().responded('alice', aid2.i, exn.ked.d);
await client1.challenges().responded(aid2.i, exn.ked.d);
console.log('Alice marked challenge response as accepted');

// Check Bob's challenge in conctats
Expand Down
20 changes: 9 additions & 11 deletions examples/integration-scripts/credentials.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ test('single signature credentials', async () => {
await step('issuer get credential by id', async () => {
const issuerCredential = await issuerClient
.credentials()
.get(issuerAid.name, qviCredentialId);
.get(qviCredentialId);
assert.equal(issuerCredential.sad.s, QVI_SCHEMA_SAID);
assert.equal(issuerCredential.sad.i, issuerAid.prefix);
assert.equal(issuerCredential.status.s, '0');
Expand All @@ -198,7 +198,7 @@ test('single signature credentials', async () => {
const dt = createTimestamp();
const issuerCredential = await issuerClient
.credentials()
.get(issuerAid.name, qviCredentialId);
.get(qviCredentialId);
assert(issuerCredential !== undefined);

const [grant, gsigs, gend] = await issuerClient.ipex().grant({
Expand Down Expand Up @@ -244,7 +244,7 @@ test('single signature credentials', async () => {
const holderCredential = await retry(async () => {
const result = await holderClient
.credentials()
.get(holderAid.name, qviCredentialId);
.get(qviCredentialId);
assert(result !== undefined);
return result;
});
Expand All @@ -257,7 +257,7 @@ test('single signature credentials', async () => {
await step('holder IPEX present', async () => {
const holderCredential = await holderClient
.credentials()
.get(holderAid.name, qviCredentialId);
.get(qviCredentialId);

const [grant2, gsigs2, gend2] = await holderClient.ipex().grant({
senderName: holderAid.name,
Expand Down Expand Up @@ -308,7 +308,7 @@ test('single signature credentials', async () => {
await verifierClient.notifications().mark(verifierGrantNote.i);

const verifierCredential = await retry(async () =>
verifierClient.credentials().get(verifierAid.name, qviCredentialId)
verifierClient.credentials().get(qviCredentialId)
);

assert.equal(verifierCredential.sad.s, QVI_SCHEMA_SAID);
Expand Down Expand Up @@ -338,7 +338,7 @@ test('single signature credentials', async () => {
async () => {
const qviCredential = await holderClient
.credentials()
.get(holderAid.name, qviCredentialId);
.get(qviCredentialId);

const result = await holderClient.credentials().issue({
issuerName: holderAid.name,
Expand Down Expand Up @@ -375,7 +375,7 @@ test('single signature credentials', async () => {
const dt = createTimestamp();
const leCredential = await holderClient
.credentials()
.get(holderAid.name, leCredentialId);
.get(leCredentialId);
assert(leCredential !== undefined);

const [grant, gsigs, gend] = await holderClient.ipex().grant({
Expand Down Expand Up @@ -422,9 +422,7 @@ test('single signature credentials', async () => {

await step('Legal Entity has chained credential', async () => {
const legalEntityCredential = await retry(async () =>
legalEntityClient
.credentials()
.get(legalEntityAid.name, leCredentialId)
legalEntityClient.credentials().get(leCredentialId)
);

assert.equal(legalEntityCredential.sad.s, LE_SCHEMA_SAID);
Expand All @@ -443,7 +441,7 @@ test('single signature credentials', async () => {
await waitOperation(issuerClient, revokeOperation);
const issuerCredential = await issuerClient
.credentials()
.get(issuerAid.name, qviCredentialId);
.get(qviCredentialId);

assert.equal(issuerCredential.status.s, '1');
});
Expand Down
12 changes: 4 additions & 8 deletions examples/integration-scripts/multisig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,18 @@ test('multisig', async function run() {
await client3.challenges().respond('member3', aid1.prefix, words);
console.log('Member3 responded challenge with signed words');

op1 = await client1.challenges().verify('member1', aid2.prefix, words);
op1 = await client1.challenges().verify(aid2.prefix, words);
op1 = await waitOperation(client1, op1);
console.log('Member1 verified challenge response from member2');
let exnwords = new Serder(op1.response.exn);
op1 = await client1
.challenges()
.responded('member1', aid2.prefix, exnwords.ked.d);
op1 = await client1.challenges().responded(aid2.prefix, exnwords.ked.d);
console.log('Member1 marked challenge response as accepted');

op1 = await client1.challenges().verify('member1', aid3.prefix, words);
op1 = await client1.challenges().verify(aid3.prefix, words);
op1 = await waitOperation(client1, op1);
console.log('Member1 verified challenge response from member3');
exnwords = new Serder(op1.response.exn);
op1 = await client1
.challenges()
.responded('member1', aid3.prefix, exnwords.ked.d);
op1 = await client1.challenges().responded(aid3.prefix, exnwords.ked.d);
console.log('Member1 marked challenge response as accepted');

// First member start the creation of a multisig identifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ async function getOrIssueCredential(
await waitOperation(issuerClient, issResult.op);
const credential = await issuerClient
.credentials()
.get(issuerAid.name, issResult.acdc.ked.d);
.get(issResult.acdc.ked.d);

return credential;
}
Expand Down
18 changes: 4 additions & 14 deletions src/keri/app/contacting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,12 @@ export class Challenges {

/**
* Ask Agent to verify a given sender signed the provided words
* @param {string} name Name or alias of the identifier
* @param {string} source Prefix of the identifier that was challenged
* @param {Array<string>} words List of challenge words to check for
* @returns A promise to the long running operation
*/
async verify(
name: string,
source: string,
words: string[]
): Promise<Operation<unknown>> {
const path = `/challenges/${name}/verify/${source}`;
async verify(source: string, words: string[]): Promise<Operation<unknown>> {
const path = `/challenges_verify/${source}`;
const method = 'POST';
const data = {
words: words,
Expand All @@ -177,17 +172,12 @@ export class Challenges {

/**
* Mark challenge response as signed and accepted
* @param {string} name Name or alias of the identifier
* @param {string} source Prefix of the identifier that was challenged
* @param {string} said qb64 AID of exn message representing the signed response
* @returns {Promise<Response>} A promise to the result
*/
async responded(
name: string,
source: string,
said: string
): Promise<Response> {
const path = `/challenges/${name}/verify/${source}`;
async responded(source: string, said: string): Promise<Response> {
const path = `/challenges_verify/${source}`;
const method = 'PUT';
const data = {
said: said,
Expand Down
13 changes: 4 additions & 9 deletions src/keri/app/credentialing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,17 +160,12 @@ export class Credentials {
/**
* Get a credential
* @async
* @param {string} name - Name or alias of the identifier
* @param {string} said - SAID of the credential
* @param {boolean} [includeCESR=false] - Optional flag export the credential in CESR format
* @returns {Promise<any>} A promise to the credential
*/
async get(
name: string,
said: string,
includeCESR: boolean = false
): Promise<any> {
const path = `/identifiers/${name}/credentials/${said}`;
async get(said: string, includeCESR: boolean = false): Promise<any> {
const path = `/credentials/${said}`;
const method = 'GET';
const headers = includeCESR
? new Headers({ Accept: 'application/json+cesr' })
Expand Down Expand Up @@ -286,7 +281,7 @@ export class Credentials {
const vs = versify(Ident.KERI, undefined, Serials.JSON, 0);
const dt = new Date().toISOString().replace('Z', '000+00:00');

const cred = await this.get(name, said);
const cred = await this.get(said);

// Create rev
const _rev = {
Expand Down Expand Up @@ -373,7 +368,7 @@ export class Credentials {
const hab = await this.client.identifiers().get(name);
const pre: string = hab.prefix;

const cred = await this.get(name, said);
const cred = await this.get(said);
const data = {
i: cred.sad.i,
s: cred.sad.s,
Expand Down
6 changes: 2 additions & 4 deletions test/app/contacting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,30 +272,28 @@ describe('Contacting', () => {
assert.equal(lastBody.sigs[0].length, 88);

await challenges.verify(
'aid1',
'EG2XjQN-3jPN5rcR4spLjaJyM4zA6Lgg-Hd5vSMymu5p',
words
);
lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length - 1]!;
assert.equal(
lastCall[0]!,
url +
'/challenges/aid1/verify/EG2XjQN-3jPN5rcR4spLjaJyM4zA6Lgg-Hd5vSMymu5p'
'/challenges_verify/EG2XjQN-3jPN5rcR4spLjaJyM4zA6Lgg-Hd5vSMymu5p'
);
assert.equal(lastCall[1]!.method, 'POST');
lastBody = JSON.parse(lastCall[1]!.body!.toString());
assert.deepEqual(lastBody.words, words);

await challenges.responded(
'aid1',
'EG2XjQN-3jPN5rcR4spLjaJyM4zA6Lgg-Hd5vSMymu5p',
'EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao'
);
lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length - 1]!;
assert.equal(
lastCall[0]!,
url +
'/challenges/aid1/verify/EG2XjQN-3jPN5rcR4spLjaJyM4zA6Lgg-Hd5vSMymu5p'
'/challenges_verify/EG2XjQN-3jPN5rcR4spLjaJyM4zA6Lgg-Hd5vSMymu5p'
);
assert.equal(lastCall[1]!.method, 'PUT');
lastBody = JSON.parse(lastCall[1]!.body!.toString());
Expand Down
6 changes: 2 additions & 4 deletions test/app/credentialing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ fetchMock.mockResponse((req) => {
req.method,
requrl.pathname.split('?')[0]
);
const body = req.url.startsWith(url + '/identifiers/aid1/credentials')
const body = req.url.startsWith(url + '/credentials')
? mockCredential
: mockGetAID;

Expand Down Expand Up @@ -196,15 +196,13 @@ describe('Credentialing', () => {
assert.deepEqual(lastBody, kargs);

await credentials.get(
'aid1',
'EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao',
true
);
lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length - 1]!;
assert.equal(
lastCall[0]!,
url +
'/identifiers/aid1/credentials/EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao'
url + '/credentials/EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao'
);
assert.equal(lastCall[1]!.method, 'GET');

Expand Down
Loading