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

fix credentialing field ordering and related singlesig-vlei-issuance test #254

Merged
merged 23 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
29 changes: 16 additions & 13 deletions examples/integration-scripts/singlesig-vlei-issuance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const { vleiServerUrl } = resolveEnvironment();
const QVI_SCHEMA_SAID = 'EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao';
const LE_SCHEMA_SAID = 'ENPXp1vQzRF6JwIuS-mp2U8Uf1MoADoP_GqQ62VsDZWY';
const ECR_AUTH_SCHEMA_SAID = 'EH6ekLjSr8V32WyFbGe1zXjTzFs9PkTYmupJ9H65O14g';
const ECR_SCHEMA_SAID = 'EEy9PkikFcANV1l7EHukCeXqrzT1hNZjGlUk7wuMO5jw';
export const ECR_SCHEMA_SAID = 'EEy9PkikFcANV1l7EHukCeXqrzT1hNZjGlUk7wuMO5jw';
2byrds marked this conversation as resolved.
Show resolved Hide resolved
const OOR_AUTH_SCHEMA_SAID = 'EKA57bKBKxr_kN7iN5i7lMUxpMG-s19dRcmov1iDxz-E';
const OOR_SCHEMA_SAID = 'EBNaNu-M9P5cgrnfl2Fvymy4E_jvxxyjb70PRtiANlJy';

Expand Down Expand Up @@ -505,18 +505,21 @@ async function getOrIssueCredential(
if (credential) return credential;
}

const issResult = await issuerClient.credentials().issue(issuerAid.name, {
ri: issuerRegistry.regk,
s: schema,
u: privacy ? new Salter({}).qb64 : undefined,
a: {
i: recipientAid.prefix,
u: privacy ? new Salter({}).qb64 : undefined,
...credData,
const issResult = await issuerClient.credentials().issue(
2byrds marked this conversation as resolved.
Show resolved Hide resolved
issuerAid.name,
{
ri: issuerRegistry.regk,
s: schema,
a: {
i: recipientAid.prefix,
u: privacy ? new Salter({}).qb64 : undefined,
...credData,
},
e: source,
r: rules,
},
r: rules,
e: source,
});
privacy
);

await waitOperation(issuerClient, issResult.op);
const credential = await issuerClient
Expand All @@ -526,7 +529,7 @@ async function getOrIssueCredential(
return credential;
}

async function getGrantedCredential(
export async function getGrantedCredential(
2byrds marked this conversation as resolved.
Show resolved Hide resolved
client: SignifyClient,
credId: string
): Promise<any> {
Expand Down
45 changes: 45 additions & 0 deletions examples/integration-scripts/vlei-verification.test.ts
2byrds marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { strict as assert } from 'assert';
import { getOrCreateClients } from './utils/test-setup';
import {
getGrantedCredential,
ECR_SCHEMA_SAID,
} from './singlesig-vlei-issuance.test';

// This test assumes you have run a vlei test that sets up the glief, qvi, le, and
// role identifiers and Credentials.
test('vlei-verification', async function run() {
// // these come from a previous test (ex. singlesig-vlei-issuance.test.ts)
// const bran = 'DbH7DF2uJgXg8gTRpM2ar'; //taken from SIGNIFY_SECRETS
// const aidName = 'role';
// const [roleClient] = await getOrCreateClients(1,[bran]);
// try {
// // let resp = await roleClient.signedFetch(
// // 'http://localhost:7676',
// // '/health',
// // 'GET',
// // null,
// // aidName
// // );
// // assert.equal(200,resp.status)
// let ecrCreds = (await roleClient.credentials().list());
// let ecrCred = ecrCreds.find((cred: any) => cred.sad.s === ECR_SCHEMA_SAID);
// let ecrCredHolder = await getGrantedCredential(roleClient, ecrCred.sad.d);
// assert(ecrCred !== undefined);
// assert.equal(ecrCredHolder.sad.d, ecrCred.sad.d);
// assert.equal(ecrCredHolder.sad.s, ECR_SCHEMA_SAID);
// assert.equal(ecrCredHolder.status.s, '0');
// assert(ecrCredHolder.atc !== undefined);
// let ecrCredCesr = (await roleClient.credentials().get(ecrCred.sad.d,true));
// let resp = await roleClient.signedFetch(
// 'http://localhost:7676',
// `/presentations/${ecrCred.sad.d}`,
// 'PUT',
// ecrCredCesr,
// aidName,
// true)
// assert.equal(202,resp.status)
// } catch (e) {
// console.log(e);
// fail(e);
// }
});
38 changes: 37 additions & 1 deletion package-lock.json
2byrds marked this conversation as resolved.
Show resolved Hide resolved

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

31 changes: 14 additions & 17 deletions src/keri/app/clienting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,20 @@ export class SignifyClient {
* @param {string} url URL of the resource
* @param {string} path Path to the resource
* @param {string} method HTTP method
* @param {any} data Data to be sent in the body of the resource
* @param {any} data Data to be sent in the body of the resource.
* If the data is a CESR JSON string then you should also set contentType to 'application/json+cesr'
* If the data is a FormData object then you should not set the contentType and the browser will set it to 'multipart/form-data'
* If the data is an object then you should use JSON.stringify to convert it to a string and set the contentType to 'application/json'
* @param {string} contentType Content type of the request.
* @param {string} aidName Name or alias of the AID to be used for signing
* @returns {Promise<Response>} A promise to the result of the fetch
*/
async signedFetch(
url: string,
path: string,
method: string,
data: any,
data: string,
contentType: string,
2byrds marked this conversation as resolved.
Show resolved Hide resolved
aidName: string
): Promise<Response> {
const hab = await this.identifiers().get(aidName);
Expand All @@ -261,33 +266,25 @@ export class SignifyClient {
new Date().toISOString().replace('Z', '000+00:00')
);

if (contentType !== null) {
headers.set('Content-Type', contentType);
}

if (data !== null) {
headers.set('Content-Length', data.length);
headers.set('Content-Length', data.length.toString());
2byrds marked this conversation as resolved.
Show resolved Hide resolved
} else {
headers.set('Content-Length', '0');
}

const signed_headers = authenticator.sign(
headers,
method,
path.split('?')[0]
);
let _body = null;
if (method != 'GET') {
if (data instanceof FormData) {
_body = data;
// do not set the content type, let the browser do it
// headers.set('Content-Type', 'multipart/form-data')
} else {
_body = JSON.stringify(data);
headers.set('Content-Type', 'application/json');
}
} else {
headers.set('Content-Type', 'application/json');
}

return await fetch(url + path, {
method: method,
body: _body,
body: data,
headers: signed_headers,
});
}
Expand Down
4 changes: 3 additions & 1 deletion src/keri/app/credentialing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ export class Credentials {
*/
async issue(
name: string,
args: CredentialData
args: CredentialData,
privacy: boolean = false
): Promise<IssueCredentialResult> {
const hab = await this.client.identifiers().get(name);
const estOnly = hab.state.c !== undefined && hab.state.c.includes('EO');
Expand All @@ -211,6 +212,7 @@ export class Credentials {
const [, acdc] = Saider.saidify({
v: versify(Ident.ACDC, undefined, Serials.JSON, 0),
d: '',
u: privacy ? new Salter({}).qb64 : undefined,
2byrds marked this conversation as resolved.
Show resolved Hide resolved
i: args.i ?? hab.prefix,
...args,
a: subject,
Expand Down
3 changes: 2 additions & 1 deletion test/app/clienting.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ describe('SignifyClient', () => {
'http://example.com',
'/test',
'POST',
{ foo: true },
JSON.stringify({ foo: true }),
'application/json',
'aid1'
);
lastCall = fetchMock.mock.calls[fetchMock.mock.calls.length - 1]!;
Expand Down
Loading