From 07abd3189e1172e08abcd7cf8c2c77b98b791d02 Mon Sep 17 00:00:00 2001 From: Fergal Date: Tue, 5 Nov 2024 12:15:41 -0300 Subject: [PATCH] feat: get credential registry state (tever vcstate) (#282) * 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 --- .github/workflows/main.yml | 2 +- docker-compose.yaml | 2 +- .../integration-scripts/credentials.test.ts | 14 +++++++- .../integration-scripts/singlesig-drt.test.ts | 2 +- package-lock.json | 8 ++--- src/keri/app/credentialing.ts | 34 +++++++++++++++++++ src/keri/core/core.ts | 2 ++ test/app/credentialing.test.ts | 10 ++++++ 8 files changed, 66 insertions(+), 8 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 61ad49d1..382c0b6e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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 }} diff --git a/docker-compose.yaml b/docker-compose.yaml index 25d0dd40..38fd0261 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -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 diff --git a/examples/integration-scripts/credentials.test.ts b/examples/integration-scripts/credentials.test.ts index 3ae1f6d4..e9dc4174 100644 --- a/examples/integration-scripts/credentials.test.ts +++ b/examples/integration-scripts/credentials.test.ts @@ -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, @@ -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, diff --git a/examples/integration-scripts/singlesig-drt.test.ts b/examples/integration-scripts/singlesig-drt.test.ts index bb1c714f..2f099a9c 100644 --- a/examples/integration-scripts/singlesig-drt.test.ts +++ b/examples/integration-scripts/singlesig-drt.test.ts @@ -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'); diff --git a/package-lock.json b/package-lock.json index c0c5d42e..f4d19759 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7102,9 +7102,9 @@ } }, "node_modules/mermaid": { - "version": "10.9.1", - "resolved": "https://registry.npmjs.org/mermaid/-/mermaid-10.9.1.tgz", - "integrity": "sha512-Mx45Obds5W1UkW1nv/7dHRsbfMM1aOKA2+Pxs/IGHNonygDHwmng8xTHyS9z4KWVi0rbko8gjiBmuwwXQ7tiNA==", + "version": "10.9.3", + "resolved": "https://registry.npmjs.org/mermaid/-/mermaid-10.9.3.tgz", + "integrity": "sha512-V80X1isSEvAewIL3xhmz/rVmc27CVljcsbWxkxlWJWY/1kQa4XOABqpDl2qQLGKzpKm6WbTfUEKImBlUfFYArw==", "dev": true, "dependencies": { "@braintree/sanitize-url": "^6.0.1", @@ -7116,7 +7116,7 @@ "d3-sankey": "^0.12.3", "dagre-d3-es": "7.0.10", "dayjs": "^1.11.7", - "dompurify": "^3.0.5", + "dompurify": "^3.0.5 <3.1.7", "elkjs": "^0.9.0", "katex": "^0.16.9", "khroma": "^2.0.0", diff --git a/src/keri/app/credentialing.ts b/src/keri/app/credentialing.ts index 39d535af..a48928c2 100644 --- a/src/keri/app/credentialing.ts +++ b/src/keri/app/credentialing.ts @@ -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; + } + | { + et: 'bis' | 'brv'; + ra: { i: string; s: string; d: string }; + } +); + /** * Credentials */ @@ -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} A promise to the credential registry state + */ + async state(ri: string, said: string): Promise { + const path = `/registries/${ri}/${said}`; + const method = 'GET'; + const res = await this.client.fetch(path, method, null); + return res.json(); + } + /** * Issue a credential */ diff --git a/src/keri/core/core.ts b/src/keri/core/core.ts index 6d4d148f..ee75d997 100644 --- a/src/keri/core/core.ts +++ b/src/keri/core/core.ts @@ -32,6 +32,8 @@ export const Ilks = { vcp: 'vcp', iss: 'iss', rev: 'rev', + bis: 'bis', + brv: 'brv', }; export const IcpLabels = [ diff --git a/test/app/credentialing.test.ts b/test/app/credentialing.test.ts index 4156dcb6..a293a36a 100644 --- a/test/app/credentialing.test.ts +++ b/test/app/credentialing.test.ts @@ -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); }); });