Skip to content

Commit

Permalink
feat: get credential registry state (tever vcstate)
Browse files Browse the repository at this point in the history
  • Loading branch information
iFergal committed Oct 11, 2024
1 parent 1b747f8 commit e032084
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
11 changes: 10 additions & 1 deletion examples/integration-scripts/credentials.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { strict as assert } from 'assert';
import { Saider, Serder, SignifyClient } from 'signify-ts';
import { Ilks, Saider, Serder, SignifyClient } from 'signify-ts';
import { resolveEnvironment } from './utils/resolve-env';
import {
assertNotifications,
Expand Down Expand Up @@ -248,6 +248,15 @@ test('single signature credentials', async () => {
await waitOperation(issuerClient, op);
});

await step('holder can get the credential status before or without holding', async () => {
const state = await retry(async () =>
holderClient.credentials().state(registry.regk, qviCredentialId)
);
assert.equal(state.i, qviCredentialId);
assert.equal(state.ri, registry.regk);
assert.equal(state.et, Ilks.iss);
});

await step('holder IPEX admit', async () => {
const holderNotifications = await waitForNotifications(
holderClient,
Expand Down
31 changes: 31 additions & 0 deletions src/keri/app/credentialing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,23 @@ export interface IpexAdmitArgs {
datetime?: string;
}

export type CredentialState = {
vn: [number, number],
i: string,
s: string,
d: string,
ri: string,
a: { s: number, d: string },
dt: string,
et: string
} & ({
et: "iss" | "rev",
ra: Record<string, never>
} | {
et: "bis" | "brv",
ra: { i: string, s: string, d: string }
});

/**
* Credentials
*/
Expand Down Expand Up @@ -285,6 +302,20 @@ export class Credentials {
return includeCESR ? await res.text() : await res.json();
}

/**
* Get the state of a credential
* @async
* @param {string} ri - management registry identifier
* @param {string} said - SAID of the credential
* @returns {Promise<CredentialState>} A promise to the credential registry state
*/
async state(ri: string, said: string): Promise<CredentialState> {
const path = `/registries/${ri}/${said}`;
const method = "GET";
const res = await this.client.fetch(path, method, null);
return res.json();
}

/**
* Issue a credential
*/
Expand Down
2 changes: 2 additions & 0 deletions src/keri/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export const Ilks = {
vcp: 'vcp',
iss: 'iss',
rev: 'rev',
bis: 'bis',
brv: 'brv'
};

export const IcpLabels = [
Expand Down
8 changes: 8 additions & 0 deletions test/app/credentialing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,14 @@ describe('Credentialing', () => {
lastBody.recipient,
'EP10ooRj0DJF0HWZePEYMLPl-arMV-MAoTKK-o3DXbgX'
);

await credentials.state("EACehJRd0wfteUAJgaTTJjMSaQqWvzeeHqAMMqxuqxU4", "EBVaw6pCqfMIiZGkA6qevzRUGsxTRuZXxl6YG1neeCGF");
lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length - 1]!;
assert.equal(
lastCall[0]!,
url + "/registries/EACehJRd0wfteUAJgaTTJjMSaQqWvzeeHqAMMqxuqxU4/EBVaw6pCqfMIiZGkA6qevzRUGsxTRuZXxl6YG1neeCGF"
);
assert.equal(lastCall[1]!.method, "GET");
});
});

Expand Down

0 comments on commit e032084

Please sign in to comment.