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

feat: delete credential by said #297

Merged
merged 7 commits into from
Jan 7, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
strategy:
matrix:
os: ['ubuntu-latest']
keria-version: ['0.2.0-dev5']
keria-version: ['0.2.0-dev6']
node-version: ['20']
env:
KERIA_IMAGE_TAG: ${{ matrix.keria-version }}
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ services:
- 7723:7723

keria:
image: ${KERIA_IMAGE:-weboftrust/keria}:${KERIA_IMAGE_TAG:-0.2.0-dev5}
image: ${KERIA_IMAGE:-weboftrust/keria}:${KERIA_IMAGE_TAG:-0.2.0-dev6}
environment:
KERI_AGENT_CORS: 1
<<: *python-env
volumes:
- ./config/keria.json:/keria/config/keri/cf/keria.json
command: --config-dir /keria/config --config-file keria --name agent
command: start --config-dir /keria/config --config-file keria --name agent
iFergal marked this conversation as resolved.
Show resolved Hide resolved
healthcheck:
test: wget --spider http://keria:3902/spec.yaml
<<: *healthcheck
Expand Down
14 changes: 14 additions & 0 deletions examples/integration-scripts/credentials.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
});

await step('verifier IPEX apply', async () => {
const [apply, sigs, _] = await verifierClient.ipex().apply({

Check warning on line 308 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18 and macOS-latest

'_' is assigned a value but never used

Check warning on line 308 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20 and macOS-latest

'_' is assigned a value but never used

Check warning on line 308 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18 and ubuntu-latest

'_' is assigned a value but never used

Check warning on line 308 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20 and ubuntu-latest

'_' is assigned a value but never used
senderName: verifierAid.name,
schemaSaid: QVI_SCHEMA_SAID,
attributes: { LEI: '5493001KJTIIGC8Y1R17' },
Expand All @@ -331,7 +331,7 @@
const apply = await holderClient.exchanges().get(holderApplyNote.a.d);
applySaid = apply.exn.d;

let filter: { [x: string]: any } = { '-s': apply.exn.a.s };

Check warning on line 334 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18 and macOS-latest

'filter' is never reassigned. Use 'const' instead

Check warning on line 334 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18 and macOS-latest

Unexpected any. Specify a different type

Check warning on line 334 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20 and macOS-latest

'filter' is never reassigned. Use 'const' instead

Check warning on line 334 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20 and macOS-latest

Unexpected any. Specify a different type

Check warning on line 334 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18 and ubuntu-latest

'filter' is never reassigned. Use 'const' instead

Check warning on line 334 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18 and ubuntu-latest

Unexpected any. Specify a different type

Check warning on line 334 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20 and ubuntu-latest

'filter' is never reassigned. Use 'const' instead

Check warning on line 334 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20 and ubuntu-latest

Unexpected any. Specify a different type
for (const key in apply.exn.a.a) {
filter[`-a-${key}`] = apply.exn.a.a[key];
}
Expand Down Expand Up @@ -376,7 +376,7 @@

await markAndRemoveNotification(verifierClient, verifierOfferNote);

const [agree, sigs, _] = await verifierClient.ipex().agree({

Check warning on line 379 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18 and macOS-latest

'_' is assigned a value but never used

Check warning on line 379 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20 and macOS-latest

'_' is assigned a value but never used

Check warning on line 379 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18 and ubuntu-latest

'_' is assigned a value but never used

Check warning on line 379 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20 and ubuntu-latest

'_' is assigned a value but never used
senderName: verifierAid.name,
recipient: holderAid.prefix,
offerSaid: offerSaid,
Expand Down Expand Up @@ -616,4 +616,18 @@

assert.equal(issuerCredential.status.s, '1');
});

await step('Holder deletes LE credential', async () => {
await holderClient.credentials().delete(leCredentialId);
await assert.rejects(
async () => {
await holderClient.credentials().get(leCredentialId);
},
{
name: 'Error',
message: `HTTP GET /credentials/${leCredentialId} - 404 Not Found - {"title": "404 Not Found", "description": "credential for said ${leCredentialId} not found."}`,
}
);
assert.equal((await holderClient.credentials().list()).length, 1);
});
}, 90000);
2 changes: 1 addition & 1 deletion src/keri/app/contacting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class Contacts {
const path = `/contacts/` + pre;
const method = 'DELETE';

await this.client.fetch(path, method, null);
await this.client.fetch(path, method, undefined);
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/keri/app/credentialing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,18 @@ export class Credentials {
return includeCESR ? await res.text() : await res.json();
}

/**
* Delete a credential from the DB
* @async
* @param {string} said - SAID of the credential
* @returns {Promise<void>}
*/
async delete(said: string): Promise<void> {
const path = `/credentials/${said}`;
const method = 'DELETE';
await this.client.fetch(path, method, undefined);
}

/**
* Get the state of a credential
* @async
Expand Down
4 changes: 2 additions & 2 deletions src/keri/app/notifying.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ export class Notifications {
* Delete a notification
* @async
* @param {string} said SAID of the notification
* @returns {Promise<any>} A promise to the result of the deletion
* @returns {Promise<void>}
*/
async delete(said: string): Promise<void> {
const path = `/notifications/` + said;
const method = 'DELETE';
await this.client.fetch(path, method, null);
await this.client.fetch(path, method, undefined);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON.stringify(undefined) is undefined whereas JSON.stringify(null) is "null"

}
}
1 change: 1 addition & 0 deletions src/keri/core/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export interface HabState {
transferable: boolean;
state: State;
windexes: unknown[];
icp_dt: string;
[Algos.salty]?: SaltyState;
[Algos.randy]?: RandyState;
[Algos.group]?: GroupState;
Expand Down
6 changes: 4 additions & 2 deletions test/app/clienting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,9 @@ describe('SignifyClient', () => {
headers: badAgentHeaders,
});
let t = async () => await client.fetch('/contacts', 'GET', undefined);
expect(t).rejects.toThrowError('message from a different remote agent');
await expect(t).rejects.toThrowError(
'message from a different remote agent'
);

badAgentHeaders = {
'signify-resource': 'EEXekkGu9IAzav6pZVJhkLnjtjM5v3AcyA-pdKUcaGei',
Expand All @@ -319,7 +321,7 @@ describe('SignifyClient', () => {
headers: badAgentHeaders,
});
t = async () => await client.fetch('/contacts', 'GET', undefined);
expect(t).rejects.toThrowError(
await expect(t).rejects.toThrowError(
'Signature for EEXekkGu9IAzav6pZVJhkLnjtjM5v3AcyA-pdKUcaGei invalid.'
);

Expand Down
2 changes: 1 addition & 1 deletion test/app/contacting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ describe('Contacting', () => {

await contacts.delete('EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao');
lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length - 1]!;
lastBody = JSON.parse(lastCall[1]!.body!.toString());
assert.equal(
lastCall[0]!,
url + '/contacts/EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao'
);
assert.equal(lastCall[1]!.method, 'DELETE');
assert.equal(lastCall[1]!.body, undefined);
});

it('Challenges', async () => {
Expand Down
9 changes: 9 additions & 0 deletions test/app/credentialing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,15 @@ describe('Credentialing', () => {
);
assert.equal(lastCall[1]!.method, 'GET');
assert.equal(lastCall[1]!.body, null);

await credentials.delete(mockCredential.sad.d);
lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length - 1]!;
assert.equal(
lastCall[0]!,
url + '/credentials/EMwcsEMUEruPXVwPCW7zmqmN8m0I3CihxolBm-RDrsJo'
);
assert.equal(lastCall[1]!.method, 'DELETE');
assert.equal(lastCall[1]!.body, undefined);
});
});

Expand Down
3 changes: 2 additions & 1 deletion test/app/registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ describe('registry', () => {
name: 'a name',
transferable: true,
windexes: [],
icp_dt: '2023-12-01T10:05:25.062609+00:00',
} as HabState;

when(mockedIdentifiers.get('a name')).thenResolve(hab);
Expand All @@ -79,7 +80,7 @@ describe('registry', () => {

const registries = new Registries(instance(mockedClient));

assert.rejects(
await assert.rejects(
async () => {
await registries.create({
name: 'a name',
Expand Down
1 change: 1 addition & 0 deletions test/app/test-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,6 @@ export async function createMockIdentifierState(
c: [],
di: serder.ked.di ?? '',
} as State,
icp_dt: '2023-12-01T10:05:25.062609+00:00',
};
}
4 changes: 4 additions & 0 deletions test/core/manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ describe('Manager', () => {
randy: keeper0.params() as RandyState,
transferable: false,
windexes: [],
icp_dt: '2023-12-01T10:05:25.062609+00:00',
});

assert(keeper0 instanceof RandyKeeper);
Expand All @@ -744,6 +745,7 @@ describe('Manager', () => {
state: {} as State,
transferable: false,
windexes: [],
icp_dt: '2023-12-01T10:05:25.062609+00:00',
})
).toThrow('Algo not allowed yet');
});
Expand Down Expand Up @@ -821,6 +823,7 @@ describe('Manager', () => {
param,
},
transferable: true,
icp_dt: '2023-12-01T10:05:25.062609+00:00',
});

assert(keeper instanceof MockModule);
Expand All @@ -847,6 +850,7 @@ describe('Manager', () => {
param,
},
transferable: true,
icp_dt: '2023-12-01T10:05:25.062609+00:00',
})
).toThrow('unsupported external module type mock');
});
Expand Down
Loading