Skip to content

Commit

Permalink
feat: IPEX apply, offer, agree (#272)
Browse files Browse the repository at this point in the history
* feat: single-sig IPEX apply, offer, agree

* feat: IPEX apply, offer, admit msgs

* test: apply, offer, agree integration tests

* fix: correct typing

* test: ipex unit tests

* test: improve test and docs

* test: ipex better split of unit tests

* test: whitespace diff

* fix: rp field should always be set for IPEX exn messages

* test: update other admit calls to use args object

* refactor: prettier run

* refactor: prettier run again

* feat: more descriptive property names for ipex saids
  • Loading branch information
iFergal committed Aug 14, 2024
1 parent 850af59 commit 1212b54
Show file tree
Hide file tree
Showing 8 changed files with 789 additions and 72 deletions.
157 changes: 132 additions & 25 deletions examples/integration-scripts/credentials.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ let holderAid: Aid;
let verifierAid: Aid;
let legalEntityAid: Aid;

let applySaid: string;
let offerSaid: string;
let agreeSaid: string;

beforeAll(async () => {
[issuerClient, holderClient, verifierClient, legalEntityClient] =
await getOrCreateClients(4);
Expand Down Expand Up @@ -251,14 +255,13 @@ test('single signature credentials', async () => {
);
const grantNotification = holderNotifications[0]; // should only have one notification right now

const [admit, sigs, aend] = await holderClient
.ipex()
.admit(
holderAid.name,
'',
grantNotification.a.d!,
createTimestamp()
);
const [admit, sigs, aend] = await holderClient.ipex().admit({
senderName: holderAid.name,
message: '',
grantSaid: grantNotification.a.d!,
recipient: issuerAid.prefix,
datetime: createTimestamp(),
});
const op = await holderClient
.ipex()
.submitAdmit(holderAid.name, admit, sigs, aend, [issuerAid.prefix]);
Expand Down Expand Up @@ -289,7 +292,107 @@ test('single signature credentials', async () => {
assert(holderCredential.atc !== undefined);
});

await step('holder IPEX present', async () => {
await step('verifier IPEX apply', async () => {
const [apply, sigs, _] = await verifierClient.ipex().apply({

Check warning on line 296 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

'_' is assigned a value but never used

Check warning on line 296 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

'_' is assigned a value but never used

Check warning on line 296 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

'_' is assigned a value but never used

Check warning on line 296 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

'_' is assigned a value but never used
senderName: verifierAid.name,
schemaSaid: QVI_SCHEMA_SAID,
attributes: { LEI: '5493001KJTIIGC8Y1R17' },
recipient: holderAid.prefix,
datetime: createTimestamp(),
});

const op = await verifierClient
.ipex()
.submitApply(verifierAid.name, apply, sigs, [holderAid.prefix]);
await waitOperation(verifierClient, op);
});

await step('holder IPEX apply receive and offer', async () => {
const holderNotifications = await waitForNotifications(
holderClient,
'/exn/ipex/apply'
);

const holderApplyNote = holderNotifications[0];
assert(holderApplyNote.a.d);

const apply = await holderClient.exchanges().get(holderApplyNote.a.d);
applySaid = apply.exn.d;

let filter: { [x: string]: any } = { '-s': apply.exn.a.s };

Check warning on line 322 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

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

Check warning on line 322 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

Unexpected any. Specify a different type

Check warning on line 322 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

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

Check warning on line 322 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

Unexpected any. Specify a different type

Check warning on line 322 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

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

Check warning on line 322 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

Unexpected any. Specify a different type

Check warning on line 322 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

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

Check warning on line 322 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

Unexpected any. Specify a different type
for (const key in apply.exn.a.a) {
filter[`-a-${key}`] = apply.exn.a.a[key];
}

const matchingCreds = await holderClient.credentials().list({ filter });
expect(matchingCreds).toHaveLength(1);

await markAndRemoveNotification(holderClient, holderNotifications[0]);

const [offer, sigs, end] = await holderClient.ipex().offer({
senderName: holderAid.name,
recipient: verifierAid.prefix,
acdc: new Serder(matchingCreds[0].sad),
applySaid: applySaid,
datetime: createTimestamp(),
});

const op = await holderClient
.ipex()
.submitOffer(holderAid.name, offer, sigs, end, [
verifierAid.prefix,
]);
await waitOperation(holderClient, op);
});

await step('verifier receive offer and agree', async () => {
const verifierNotifications = await waitForNotifications(
verifierClient,
'/exn/ipex/offer'
);

const verifierOfferNote = verifierNotifications[0];
assert(verifierOfferNote.a.d);

const offer = await verifierClient
.exchanges()
.get(verifierOfferNote.a.d);
offerSaid = offer.exn.d;

expect(offer.exn.p).toBe(applySaid);
expect(offer.exn.e.acdc.a.LEI).toBe('5493001KJTIIGC8Y1R17');

await markAndRemoveNotification(verifierClient, verifierOfferNote);

const [agree, sigs, _] = await verifierClient.ipex().agree({

Check warning on line 367 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

'_' is assigned a value but never used

Check warning on line 367 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

'_' is assigned a value but never used

Check warning on line 367 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

'_' is assigned a value but never used

Check warning on line 367 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

'_' is assigned a value but never used
senderName: verifierAid.name,
recipient: holderAid.prefix,
offerSaid: offerSaid,
datetime: createTimestamp(),
});

const op = await verifierClient
.ipex()
.submitAgree(verifierAid.name, agree, sigs, [holderAid.prefix]);
await waitOperation(verifierClient, op);
});

await step('holder IPEX receive agree and grant/present', async () => {
const holderNotifications = await waitForNotifications(
holderClient,
'/exn/ipex/agree'
);

const holderAgreeNote = holderNotifications[0];
assert(holderAgreeNote.a.d);

const agree = await holderClient.exchanges().get(holderAgreeNote.a.d);
agreeSaid = agree.exn.d;

expect(agree.exn.p).toBe(offerSaid);

await markAndRemoveNotification(holderClient, holderAgreeNote);

const holderCredential = await holderClient
.credentials()
.get(qviCredentialId);
Expand All @@ -303,6 +406,7 @@ test('single signature credentials', async () => {
acdcAttachment: holderCredential.atc,
ancAttachment: holderCredential.ancatc,
issAttachment: holderCredential.issAtc,
agreeSaid: agreeSaid,
datetime: createTimestamp(),
});

Expand All @@ -321,15 +425,18 @@ test('single signature credentials', async () => {
);

const verifierGrantNote = verifierNotifications[0];
assert(verifierGrantNote.a.d);

const [admit3, sigs3, aend3] = await verifierClient
.ipex()
.admit(
verifierAid.name,
'',
verifierGrantNote.a.d!,
createTimestamp()
);
const grant = await holderClient.exchanges().get(verifierGrantNote.a.d);
expect(grant.exn.p).toBe(agreeSaid);

const [admit3, sigs3, aend3] = await verifierClient.ipex().admit({
senderName: verifierAid.name,
message: '',
grantSaid: verifierGrantNote.a.d!,
recipient: holderAid.prefix,
datetime: createTimestamp(),
});

const op = await verifierClient
.ipex()
Expand All @@ -354,6 +461,7 @@ test('single signature credentials', async () => {
holderClient,
'/exn/ipex/admit'
);

await markAndRemoveNotification(holderClient, holderNotifications[0]);
});

Expand Down Expand Up @@ -445,14 +553,13 @@ test('single signature credentials', async () => {
);
const grantNotification = notifications[0];

const [admit, sigs, aend] = await legalEntityClient
.ipex()
.admit(
legalEntityAid.name,
'',
grantNotification.a.d!,
createTimestamp()
);
const [admit, sigs, aend] = await legalEntityClient.ipex().admit({
senderName: legalEntityAid.name,
message: '',
grantSaid: grantNotification.a.d!,
recipient: holderAid.prefix,
datetime: createTimestamp(),
});

const op = await legalEntityClient
.ipex()
Expand Down
10 changes: 7 additions & 3 deletions examples/integration-scripts/multisig-holder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,9 +510,13 @@ async function multisigAdmitCredential(
let mHab = await client.identifiers().get(memberAlias);
let gHab = await client.identifiers().get(groupName);

const [admit, sigs, end] = await client
.ipex()
.admit(groupName, '', grantSaid, TIME);
const [admit, sigs, end] = await client.ipex().admit({
senderName: groupName,
message: '',
grantSaid: grantSaid,
recipient: issuerPrefix,
datetime: TIME,
});

let op = await client
.ipex()
Expand Down
9 changes: 6 additions & 3 deletions examples/integration-scripts/multisig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1079,9 +1079,12 @@ test('multisig', async function run() {
console.log('Holder received exchange message with the grant message');
res = await client4.exchanges().get(msgSaid);

const [admit, asigs, aend] = await client4
.ipex()
.admit('holder', '', res.exn.d);
const [admit, asigs, aend] = await client4.ipex().admit({
senderName: 'holder',
message: '',
grantSaid: res.exn.d,
recipient: m['prefix'],
});

op4 = await client4
.ipex()
Expand Down
10 changes: 7 additions & 3 deletions examples/integration-scripts/singlesig-vlei-issuance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,13 @@ async function sendAdmitMessage(
assert.equal(notifications.length, 1);
const grantNotification = notifications[0];

const [admit, sigs, aend] = await senderClient
.ipex()
.admit(senderAid.name, '', grantNotification.a.d!, createTimestamp());
const [admit, sigs, aend] = await senderClient.ipex().admit({
senderName: senderAid.name,
message: '',
grantSaid: grantNotification.a.d!,
recipient: recipientAid.prefix,
datetime: createTimestamp(),
});

let op = await senderClient
.ipex()
Expand Down
10 changes: 7 additions & 3 deletions examples/integration-scripts/utils/multisig-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,13 @@ export async function admitMultisig(
'/exn/ipex/grant'
);

const [admit, sigs, end] = await client
.ipex()
.admit(multisigAID.name, '', grantMsgSaid, timestamp);
const [admit, sigs, end] = await client.ipex().admit({
senderName: multisigAID.name,
message: '',
grantSaid: grantMsgSaid,
recipient: recipientAID.prefix,
datetime: timestamp,
});

await client
.ipex()
Expand Down
9 changes: 6 additions & 3 deletions examples/integration-scripts/utils/test-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ export async function admitSinglesig(
'/exn/ipex/grant'
);

const [admit, sigs, aend] = await client
.ipex()
.admit(aidName, '', grantMsgSaid);
const [admit, sigs, aend] = await client.ipex().admit({
senderName: aidName,
message: '',
grantSaid: grantMsgSaid,
recipient: recipientAid.prefix,
});

await client
.ipex()
Expand Down
Loading

0 comments on commit 1212b54

Please sign in to comment.