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: cannot set salts for credential creation (suggestion) #222

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
66 changes: 35 additions & 31 deletions examples/integration-scripts/credentials.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,16 @@
LEI: '5493001KJTIIGC8Y1R17',
};

const issResult = await issuerClient.credentials().issue({
issuerName: issuerAid.name,
registryId: registry.regk,
schemaId: QVI_SCHEMA_SAID,
recipient: holderAid.prefix,
data: vcdata,
});
const issResult = await issuerClient
.credentials()
.issue(issuerAid.name, {
ri: registry.regk,
s: QVI_SCHEMA_SAID,
a: {
i: holderAid.prefix,
...vcdata,
},
});

await waitOperation(issuerClient, issResult.op);
return issResult.acdc.ked.d as string;
Expand Down Expand Up @@ -229,7 +232,7 @@
datetime: dt,
});

let op = await issuerClient

Check warning on line 235 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18 and macOS-latest

'op' is never reassigned. Use 'const' instead

Check warning on line 235 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20 and macOS-latest

'op' is never reassigned. Use 'const' instead

Check warning on line 235 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18 and ubuntu-latest

'op' is never reassigned. Use 'const' instead

Check warning on line 235 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20 and ubuntu-latest

'op' is never reassigned. Use 'const' instead
.ipex()
.submitGrant(issuerAid.name, grant, gsigs, gend, [
holderAid.prefix,
Expand All @@ -252,7 +255,7 @@
grantNotification.a.d!,
createTimestamp()
);
let op = await holderClient

Check warning on line 258 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18 and macOS-latest

'op' is never reassigned. Use 'const' instead

Check warning on line 258 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20 and macOS-latest

'op' is never reassigned. Use 'const' instead

Check warning on line 258 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18 and ubuntu-latest

'op' is never reassigned. Use 'const' instead

Check warning on line 258 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20 and ubuntu-latest

'op' is never reassigned. Use 'const' instead
.ipex()
.submitAdmit(holderAid.name, admit, sigs, aend, [issuerAid.prefix]);
await waitOperation(holderClient, op);
Expand Down Expand Up @@ -299,7 +302,7 @@
datetime: createTimestamp(),
});

let op = await holderClient

Check warning on line 305 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18 and macOS-latest

'op' is never reassigned. Use 'const' instead

Check warning on line 305 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20 and macOS-latest

'op' is never reassigned. Use 'const' instead

Check warning on line 305 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18 and ubuntu-latest

'op' is never reassigned. Use 'const' instead

Check warning on line 305 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20 and ubuntu-latest

'op' is never reassigned. Use 'const' instead
.ipex()
.submitGrant(holderAid.name, grant2, gsigs2, gend2, [
verifierAid.prefix,
Expand All @@ -324,7 +327,7 @@
createTimestamp()
);

let op = await verifierClient

Check warning on line 330 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18 and macOS-latest

'op' is never reassigned. Use 'const' instead

Check warning on line 330 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20 and macOS-latest

'op' is never reassigned. Use 'const' instead

Check warning on line 330 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18 and ubuntu-latest

'op' is never reassigned. Use 'const' instead

Check warning on line 330 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20 and ubuntu-latest

'op' is never reassigned. Use 'const' instead
.ipex()
.submitAdmit(verifierAid.name, admit3, sigs3, aend3, [
holderAid.prefix,
Expand Down Expand Up @@ -374,31 +377,32 @@
.credentials()
.get(qviCredentialId);

const result = await holderClient.credentials().issue({
issuerName: holderAid.name,
recipient: legalEntityAid.prefix,
registryId: holderRegistry.regk,
schemaId: LE_SCHEMA_SAID,
data: {
LEI: '5493001KJTIIGC8Y1R17',
},
rules: Saider.saidify({
d: '',
usageDisclaimer: {
l: 'Usage of a valid, unexpired, and non-revoked vLEI Credential, as defined in the associated Ecosystem Governance Framework, does not assert that the Legal Entity is trustworthy, honest, reputable in its business dealings, safe to do business with, or compliant with any laws or that an implied or expressly intended purpose will be fulfilled.',
},
issuanceDisclaimer: {
l: 'All information in a valid, unexpired, and non-revoked vLEI Credential, as defined in the associated Ecosystem Governance Framework, is accurate as of the date the validation process was complete. The vLEI Credential has been issued to the legal entity or person named in the vLEI Credential as the subject; and the qualified vLEI Issuer exercised reasonable care to perform the validation process set forth in the vLEI Ecosystem Governance Framework.',
},
})[1],
source: Saider.saidify({
d: '',
qvi: {
n: qviCredential.sad.d,
s: qviCredential.sad.s,
const result = await holderClient
.credentials()
.issue(holderAid.name, {
a: {
i: legalEntityAid.prefix,
LEI: '5493001KJTIIGC8Y1R17',
},
})[1],
});
ri: holderRegistry.regk,
s: LE_SCHEMA_SAID,
r: Saider.saidify({
d: '',
usageDisclaimer: {
l: 'Usage of a valid, unexpired, and non-revoked vLEI Credential, as defined in the associated Ecosystem Governance Framework, does not assert that the Legal Entity is trustworthy, honest, reputable in its business dealings, safe to do business with, or compliant with any laws or that an implied or expressly intended purpose will be fulfilled.',
},
issuanceDisclaimer: {
l: 'All information in a valid, unexpired, and non-revoked vLEI Credential, as defined in the associated Ecosystem Governance Framework, is accurate as of the date the validation process was complete. The vLEI Credential has been issued to the legal entity or person named in the vLEI Credential as the subject; and the qualified vLEI Issuer exercised reasonable care to perform the validation process set forth in the vLEI Ecosystem Governance Framework.',
},
})[1],
e: Saider.saidify({
d: '',
qvi: {
n: qviCredential.sad.d,
s: qviCredential.sad.s,
},
})[1],
});

await waitOperation(holderClient, result.op);
return result.acdc.ked.d;
Expand All @@ -422,7 +426,7 @@
datetime: dt,
});

let op = await holderClient

Check warning on line 429 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18 and macOS-latest

'op' is never reassigned. Use 'const' instead

Check warning on line 429 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20 and macOS-latest

'op' is never reassigned. Use 'const' instead

Check warning on line 429 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18 and ubuntu-latest

'op' is never reassigned. Use 'const' instead

Check warning on line 429 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20 and ubuntu-latest

'op' is never reassigned. Use 'const' instead
.ipex()
.submitGrant(holderAid.name, grant, gsigs, gend, [
legalEntityAid.prefix,
Expand All @@ -446,7 +450,7 @@
createTimestamp()
);

let op = await legalEntityClient

Check warning on line 453 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18 and macOS-latest

'op' is never reassigned. Use 'const' instead

Check warning on line 453 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20 and macOS-latest

'op' is never reassigned. Use 'const' instead

Check warning on line 453 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 18 and ubuntu-latest

'op' is never reassigned. Use 'const' instead

Check warning on line 453 in examples/integration-scripts/credentials.test.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test on Node 20 and ubuntu-latest

'op' is never reassigned. Use 'const' instead
.ipex()
.submitAdmit(legalEntityAid.name, admit, sigs, aend, [
holderAid.prefix,
Expand Down
32 changes: 14 additions & 18 deletions examples/integration-scripts/multisig-holder.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { strict as assert } from 'assert';
import signify, {
SignifyClient,
IssueCredentialArgs,
Operation,
} from 'signify-ts';
import signify, { SignifyClient, Operation, CredentialData } from 'signify-ts';
import { resolveEnvironment } from './utils/resolve-env';
import {
assertOperations,
Expand Down Expand Up @@ -354,12 +350,11 @@ test('multisig', async function run() {

console.log(`Issuer starting credential issuance to holder...`);
const registires = await client3.registries().list('issuer');
await issueCredential(client3, {
issuerName: 'issuer',
registryId: registires[0].regk,
schemaId: SCHEMA_SAID,
recipient: holderAid['prefix'],
data: {
await issueCredential(client3, 'issuer', {

Choose a reason for hiding this comment

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

The readability of code is paramount.

We should fix this at the serialization level.

One option:
https://www.npmjs.com/package/typescript-json-serializer

@JsonObject()
export class Animal extends LivingBeing {
    @JsonProperty() name: string | undefined;
    @JsonProperty() birthDate: Date;
    @JsonProperty() numberOfPaws: number;
    @JsonProperty() gender: Gender;

    // Enum value (string)
    @JsonProperty() status: Status;

    // Specify the property name of json property if needed
    @JsonProperty('childrenIdentifiers')
    childrenIds: Array<number>;

    constructor(name: string | undefined) {
        super();
        this.name = name;
    }

}

Choose a reason for hiding this comment

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

This uses decorators on the objects. And leaves the code readable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In my opinion, decorators for serialization in JavaScript do not add any value. If we want to keep the API with more descriptive property names, I would vote for reverting back to plain property mapping. But my preference would be to move towards less mapping rather than more. I.e., using the same object shapes as KERIA accepts and returns.

ri: registires[0].regk,
s: SCHEMA_SAID,
a: {
i: holderAid['prefix'],
LEI: '5493001KJTIIGC8Y1R17',
},
});
Expand Down Expand Up @@ -476,23 +471,24 @@ async function createRegistry(

async function issueCredential(
client: SignifyClient,
args: IssueCredentialArgs
name: string,
data: CredentialData
) {
const result = await client.credentials().issue(args);
const result = await client.credentials().issue(name, data);

await waitOperation(client, result.op);

const creds = await client.credentials().list();
assert.equal(creds.length, 1);
assert.equal(creds[0].sad.s, args.schemaId);
assert.equal(creds[0].sad.s, data.s);
assert.equal(creds[0].status.s, '0');

const dt = createTimestamp();

if (args.recipient) {
if (data.a.i) {
const [grant, gsigs, end] = await client.ipex().grant({
senderName: args.issuerName,
recipient: args.recipient,
senderName: name,
recipient: data.a.i,
datetime: dt,
acdc: result.acdc,
anc: result.anc,
Expand All @@ -501,7 +497,7 @@ async function issueCredential(

let op = await client
.ipex()
.submitGrant(args.issuerName, grant, gsigs, end, [args.recipient]);
.submitGrant(name, grant, gsigs, end, [data.a.i]);
op = await waitOperation(client, op);
}

Expand Down
36 changes: 10 additions & 26 deletions examples/integration-scripts/multisig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,6 @@ test('multisig', async function run() {
});
op2 = await vcpRes2.op();
serder = vcpRes2.regser;
const regk2 = serder.pre;
anc = vcpRes2.serder;
sigs = vcpRes2.sigs;

Expand Down Expand Up @@ -840,7 +839,6 @@ test('multisig', async function run() {
});
op3 = await vcpRes3.op();
serder = vcpRes3.regser;
const regk3 = serder.pre;
anc = vcpRes3.serder;
sigs = vcpRes3.sigs;

Expand Down Expand Up @@ -881,13 +879,14 @@ test('multisig', async function run() {
const holder = aid4.prefix;

const TIME = new Date().toISOString().replace('Z', '000+00:00');
const credRes = await client1.credentials().issue({
issuerName: 'multisig',
registryId: regk,
schemaId: SCHEMA_SAID,
data: vcdata,
recipient: holder,
datetime: TIME,
const credRes = await client1.credentials().issue('multisig', {
ri: regk,
s: SCHEMA_SAID,
a: {
i: holder,
dt: TIME,
...vcdata,
},
});
op1 = credRes.op;
await multisigIssue(client1, 'member1', 'multisig', credRes);
Expand All @@ -905,15 +904,7 @@ test('multisig', async function run() {
exn = res[0].exn;

const credentialSaid = exn.e.acdc.d;

const credRes2 = await client2.credentials().issue({
issuerName: 'multisig',
registryId: regk2,
schemaId: SCHEMA_SAID,
data: vcdata,
datetime: exn.e.acdc.a.dt,
recipient: holder,
});
const credRes2 = await client2.credentials().issue('multisig', exn.e.acdc);

op2 = credRes2.op;
await multisigIssue(client2, 'member2', 'multisig', credRes2);
Expand All @@ -927,14 +918,7 @@ test('multisig', async function run() {
res = await client3.groups().getRequest(msgSaid);
exn = res[0].exn;

const credRes3 = await client3.credentials().issue({
issuerName: 'multisig',
registryId: regk3,
schemaId: SCHEMA_SAID,
recipient: holder,
data: vcdata,
datetime: exn.e.acdc.a.dt,
});
const credRes3 = await client3.credentials().issue('multisig', exn.e.acdc);

op3 = credRes3.op;
await multisigIssue(client3, 'member3', 'multisig', credRes3);
Expand Down
24 changes: 13 additions & 11 deletions examples/integration-scripts/singlesig-vlei-issuance.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 { Saider, Salter, Serder, SignifyClient } from 'signify-ts';
import { resolveEnvironment } from './utils/resolve-env';
import {
assertOperations,
Expand Down Expand Up @@ -491,7 +491,7 @@ async function getOrIssueCredential(
schema: string,
rules?: any,
source?: any,
privacy: boolean = false
privacy = false
): Promise<any> {
const credentialList = await issuerClient.credentials().list();

Expand All @@ -507,15 +507,17 @@ async function getOrIssueCredential(
if (credential) return credential;
}

const issResult = await issuerClient.credentials().issue({
issuerName: issuerAid.name,
registryId: issuerRegistry.regk,
schemaId: schema,
recipient: recipientAid.prefix,
data: credData,
rules: rules,
source: source,
privacy: privacy,
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,
},
r: rules,
e: source,
});

await waitOperation(issuerClient, issResult.op);
Expand Down
Loading
Loading