Skip to content

Commit

Permalink
feat: get credential registry state (tever vcstate) (#282)
Browse files Browse the repository at this point in the history
* feat: get credential registry state (tever vcstate)

* refactor: prettier run

* build: dev4 keria

* build: npm audit run

* test: updates for long running op saids

* test: unit tests

* test: remove log
  • Loading branch information
iFergal authored Nov 5, 2024
1 parent 5536180 commit 07abd31
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 8 deletions.
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-dev3']
keria-version: ['0.2.0-dev4']
node-version: ['20']
env:
KERIA_IMAGE_TAG: ${{ matrix.keria-version }}
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ services:
- 7723:7723

keria:
image: ${KERIA_IMAGE:-weboftrust/keria}:${KERIA_IMAGE_TAG:-0.2.0-dev3}
image: ${KERIA_IMAGE:-weboftrust/keria}:${KERIA_IMAGE_TAG:-0.2.0-dev4}
environment:
- KERI_AGENT_CORS=1
- KERI_URL=http://keria:3902
Expand Down
14 changes: 13 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,18 @@ 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
2 changes: 1 addition & 1 deletion examples/integration-scripts/singlesig-drt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('singlesig-drt', () => {
kargs = {};
result = await delegate.identifiers().rotate('delegate1', kargs);
op = await result.op();
expect(op.name).toEqual(`delegation.${delegate1.prefix}`);
expect(op.name).toEqual(`delegation.${result.serder.ked.d}`);

// delegator approves delegate
delegate1 = await delegate.identifiers().get('delegate1');
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions src/keri/app/credentialing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,26 @@ 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 +305,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
10 changes: 10 additions & 0 deletions test/app/credentialing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,16 @@ describe('Credentialing', () => {
);
assert.equal(lastBody.sigs[0].substring(0, 2), 'AA');
assert.equal(lastBody.sigs[0].length, 88);

await credentials.state(mockCredential.sad.ri, mockCredential.sad.d);
lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length - 1]!;
assert.equal(
lastCall[0]!,
url +
'/registries/EGK216v1yguLfex4YRFnG7k1sXRjh3OKY7QqzdKsx7df/EMwcsEMUEruPXVwPCW7zmqmN8m0I3CihxolBm-RDrsJo'
);
assert.equal(lastCall[1]!.method, 'GET');
assert.equal(lastCall[1]!.body, null);
});
});

Expand Down

0 comments on commit 07abd31

Please sign in to comment.