Skip to content

Commit

Permalink
Merge pull request #87 from zCloak-Network/feat-multiple-vc
Browse files Browse the repository at this point in the history
Feat multiple vc
  • Loading branch information
whgreate committed Sep 5, 2023
2 parents 33a85cf + bd05b50 commit 0a511ee
Show file tree
Hide file tree
Showing 22 changed files with 1,548 additions and 81 deletions.
22 changes: 22 additions & 0 deletions .changeset/stupid-deers-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
"@zcloak/message": major
"@zcloak/verify": major
"@zcloak/vc": major
"@zcloak/login-did": major
"@zcloak/login-providers": major
"@zcloak/login-rpc": major
"@zcloak/login-rpc-defines": major
"@zcloak/login-verify": major
"@zcloak/ctype": major
"@zcloak/did": major
"@zcloak/did-resolver": major
"@zcloak/cross": major
"@zcloak/crypto": major
"@zcloak/keyring": major
"@zcloak/miden": major
"@zcloak/wasm": major
"@zcloak/wasm-asm": major
"@zcloak/wasm-bridge": major
---

[ upgrade to 2.0.0 ]
Empty file modified .yarn/releases/yarn-4.0.0-rc.40.cjs
100755 → 100644
Empty file.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
"test:one": "zcloak-dev-run-test --runInBand",
"test:watch": "zcloak-dev-run-test --watch"
},
"dependencies": {
"web3": "^4.1.1"
},
"devDependencies": {
"@types/jest": "^29.4.0",
"@zcloak/dev": "^0.31.0",
Expand Down
28 changes: 26 additions & 2 deletions packages/message/src/decrypt/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,19 @@ export function verifyMessageData(message: DecryptedMessage<MessageType>): void

case 'Response_Approve_Attestation':
assert(isVC(data), `Expected message data with msgType:${msgType} is VerifiableCredential object`);
assert(isSameUri(sender, data.issuer), 'Message sender is not the issuer of VerifiableCredential');

if (typeof data.issuer === 'object') {
assert(
data.issuer.some((issuer) => isSameUri(sender, issuer)),
'Message sender is not the issuer of VerifiableCredential'
);
} else if (typeof data.issuer === 'string') {
assert(isSameUri(sender, data.issuer), 'Message sender is not the issuer VerifiableCredential');
} else {
const check: never = data.issuer;

return check;
}

break;

Expand Down Expand Up @@ -73,7 +85,19 @@ export function verifyMessageData(message: DecryptedMessage<MessageType>): void

case 'Send_issuedVC':
assert(isVC(data), `Expected message data with msgType:${msgType} is VerifiableCredential object`);
assert(isSameUri(sender, data.issuer), 'Message sender is not the issuer of VerifiableCredential');

if (typeof data.issuer === 'object') {
assert(
data.issuer.some((issuer) => isSameUri(sender, issuer)),
'Message sender is not the issuer of VerifiableCredential'
);
} else if (typeof data.issuer === 'string') {
assert(isSameUri(sender, data.issuer), 'Message sender is not the issuer VerifiableCredential');
} else {
const check: never = data.issuer;

throw new Error(`Message sender type wrong, the wrong issuer is : ${check}`);
}

break;

Expand Down
52 changes: 51 additions & 1 deletion packages/message/src/message.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import type { CType } from '@zcloak/ctype/types';
import type { RawCredential } from '@zcloak/vc/types';

import { alice, bob, testResolver } from 'test-support';
import { alice, bob, charlie, testResolver } from 'test-support';

import { initCrypto } from '@zcloak/crypto';
import { getPublish } from '@zcloak/ctype';
import { Raw, VerifiableCredentialBuilder } from '@zcloak/vc';
import { addProof } from '@zcloak/verify';

import { decryptMessage } from './decrypt';
import { encryptMessage } from './encrypt';
Expand Down Expand Up @@ -110,6 +111,55 @@ describe('message encrypt and decrypt', (): void => {
});

describe('Send Extends msgType', () => {
it('Send vc to be add proof', async () => {
const vc = await VerifiableCredentialBuilder.fromRawCredential(rawCredential, ctype)
.setExpirationDate(null)
.build(alice, false);

const message = await encryptMessage(
'Extends_Request_Comfirmation',
vc,
alice,
bob.getKeyUrl('keyAgreement'),
undefined,
testResolver
);
const decrypted = await decryptMessage(message, bob, testResolver);

expect(decrypted.data).toEqual(vc);
});

it('Send multiAttester VC', async () => {
const vc = await VerifiableCredentialBuilder.fromRawCredential(rawCredential, ctype)
.setExpirationDate(null)
.build(alice, false);

const message = await encryptMessage(
'Extends_Request_Comfirmation',
vc,
alice,
bob.getKeyUrl('keyAgreement'),
undefined,
testResolver
);
const decrypted = await decryptMessage(message, bob, testResolver);
const multiAttesterVC = await addProof(bob, decrypted.data);

expect(multiAttesterVC.issuer).toEqual([alice.getDocument().id, bob.getDocument().id]);

const messageSentToUser = await encryptMessage(
'Extends_Response_Approve_Attestation message',
multiAttesterVC,
bob,
charlie.getKeyUrl('keyAgreement'),
undefined,
testResolver
);
const decryptedMultiVC = await decryptMessage(messageSentToUser, charlie, testResolver);

expect(decryptedMultiVC.data).toEqual(multiAttesterVC);
});

it('Send string data', async () => {
const message = await encryptMessage(
'Extends_send_string',
Expand Down
Loading

0 comments on commit 0a511ee

Please sign in to comment.