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: get credential registry state (tever vcstate) #282

Merged
merged 8 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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 () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I can get transaction state noticing working on keripy, this could be extended nicely to check for revocations w/o IPEX.

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 },
Copy link
Contributor Author

Choose a reason for hiding this comment

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

(really is an int, unlike most s fields)

Copy link
Collaborator

Choose a reason for hiding this comment

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

@iFergal but it is a sequence number anyway right? If so, Is it the sequence number of the credential state changes, or of the registry event? If the registry event, is it possible we have a similar issue as we had for KEL events where it would not handle s >= 10 (decimal) correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's still a sequence number. It's the sn of the anchoring event in the KEL for the current credential event. sn is used from below by keripy when exporting this state.

A mix of int and hex seems to be used throughout keripy, I believe it just needs to be hex when it's actually part of a KERI event and this is just an export of current state.

I think it's OK for Signify to consider s: number as a int, and if it's actually a hex being thrown out cast as number then it's a bug?

    @property
    def sn(self):
        """
        Property sn: sequence number as int
        Returns .raw converted to int
        """
        return int.from_bytes(self.raw, 'big')

    @property
    def snh(self):
        """
        Property snh:  sequence number as hex
        Returns .sn int converted to hex str
        """
        return f"{self.sn:x}"  # "{:x}".format(self.sn)

dt: string,
et: string
} & ({
et: "iss" | "rev",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lenkan Ilks is an object, and many other things in that file. Maybe a string enum would be better for our typing?

ra: Record<string, never>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This corresponds to {} - it's always empty for iss/rev.

} | {
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
Loading