Skip to content

Commit

Permalink
Merge branch 'master' into feat/read-ecosystem-data-from-chain
Browse files Browse the repository at this point in the history
  • Loading branch information
Jayteekay authored Mar 13, 2024
2 parents 5ee1cb4 + 4ff44bc commit 4b2bb5d
Show file tree
Hide file tree
Showing 9 changed files with 377 additions and 242 deletions.
29 changes: 12 additions & 17 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
MIT License
The Dock Labs Non-Production License (the “DL-NPL”)
Copyright (c) 2024 Dock Labs AG.

Copyright (c) 2024 Dock Labs AG
This software and associated documentation files (the "Software") may only be
used in production, if you (and any entity that you represent) have agreed to,
and are in compliance with, the Dock Labs Subscription Master Services Agreement (MSA), available at https://www.dock.io/master-services-agreement (the “Dock Terms”), or other
agreement governing the use of the Software, as agreed by you and Dock Labs,
and otherwise have a valid Dock Labs subscription that is being utilized as intended and for its designated purposes.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Subject to the foregoing sentence, you are free to modify this Software and publish patches to the Software. You agree that Dock Labs and/or its licensors (as applicable) retain all right, title and interest in and to all such modifications and/or patches, and all such modifications and/or patches may only be used, copied, modified, displayed, distributed, or otherwise exploited with a valid Dock Labs subscription that is being utilized as intended and for its designated purposes. Notwithstanding the foregoing, you may copy and modify the Software without obtaining a subscription only for non-production development and testing purposes. For the avoidance of doubt, non-production use solely consists of internal use of this software within a non-production development or test environment which uses fictitious data in non-durable identity credentials. You are not granted any other rights beyond what is expressly stated herein. Subject to the foregoing, it is forbidden to copy, merge, publish, distribute, sublicense, and/or sell the Software.

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
For all third party components incorporated into the Dock Labs Software, those components are licensed under the original license provided by the owner of the applicable component.

If you have any questions or need further assistance, please contact [email protected].
142 changes: 136 additions & 6 deletions packages/core/src/credential-provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import { ACUMM_WITNESS_PROP_KEY, ICredentialProvider, createCredentialProvider } from "./credential-provider";
import { IWallet, createWallet } from "./wallet";
import {
ACUMM_WITNESS_PROP_KEY,
CredentialStatus,
ICredentialProvider,
createCredentialProvider,
} from './credential-provider';
import {IWallet, createWallet} from './wallet';

import biometricsBBSRevocation from './fixtures/biometrics-credential-bbs-revocation.json';
import customerCredential from './fixtures/customer-credential.json';
import {credentialServiceRPC} from '@docknetwork/wallet-sdk-wasm/src/services/credential';

describe('CredentialProvider', () => {

let wallet: IWallet;
let provider: ICredentialProvider;

beforeEach(async () => {
wallet = await createWallet({
databasePath: ':memory:',
});
provider = createCredentialProvider({ wallet });

provider = createCredentialProvider({wallet});
});

describe('addCredential', () => {
Expand All @@ -31,4 +37,128 @@ describe('CredentialProvider', () => {
expect(witness).toBe(biometricsBBSRevocation[ACUMM_WITNESS_PROP_KEY]);
});
});
});

describe('syncCredentialStatus', () => {
beforeEach(async () => {
await provider.addCredential({
...customerCredential,
});
await provider.addCredential({
...biometricsBBSRevocation,
});
});

it('should create credential status doc with verified status', async () => {
const mockFn = jest
.spyOn(credentialServiceRPC, 'verifyCredential')
.mockImplementation(async () => {
return {
verified: true,
};
});

const statusDocs = await provider.syncCredentialStatus({});

expect(statusDocs.length).toBe(2);

for (const statusDoc of statusDocs) {
expect(statusDoc.status).toBe(CredentialStatus.Verified);
}
});

it('should create credential status doc with revoked status', async () => {
jest
.spyOn(credentialServiceRPC, 'verifyCredential')
.mockImplementation(async () => {
return {
verified: false,
error: 'Revocation check failed',
};
});

const statusDocs = await provider.syncCredentialStatus({});

expect(statusDocs.length).toBe(2);

for (const statusDoc of statusDocs) {
expect(statusDoc.status).toBe(CredentialStatus.Revoked);
}
});

it('should not call verifyCredential twice', async () => {
jest
.spyOn(credentialServiceRPC, 'verifyCredential')
.mockImplementation(async () => {
return {
verified: true,
};
});

// first call will do actual fetch
await provider.syncCredentialStatus({});
// additional calls will use cached data
const statusDocs = await provider.syncCredentialStatus({});

expect(statusDocs.length).toBe(2);
expect(credentialServiceRPC.verifyCredential).toHaveBeenCalledTimes(2);

for (const statusDoc of statusDocs) {
expect(statusDoc.status).toBe(CredentialStatus.Verified);
}
});

it('should update cache after 24 hours', async () => {
jest
.spyOn(credentialServiceRPC, 'verifyCredential')
.mockImplementation(async () => {
return {
verified: true,
};
});

// load data into cache
await provider.syncCredentialStatus({});

// update statusDoc updateAt to 25 hours ago
const statusDoc = await wallet.getDocumentById(`${customerCredential.id}#status`);
statusDoc.updatedAt = new Date(Date.now() - 25 * 60 * 60 * 1000).toISOString();
await wallet.updateDocument(statusDoc);

const statusDocs = await provider.syncCredentialStatus({});

expect(statusDocs.length).toBe(2);

// Expect to have a second status fetch for the customerCredential
expect(credentialServiceRPC.verifyCredential).toHaveBeenCalledTimes(3);

for (const statusDoc of statusDocs) {
expect(statusDoc.status).toBe(CredentialStatus.Verified);
}
});

it('should create status only for selected credential', async () => {
const mockFn = jest
.spyOn(credentialServiceRPC, 'verifyCredential')
.mockImplementation(async () => {
return {
verified: true,
};
});

const statusDocs = await provider.syncCredentialStatus({
credentialIds: [customerCredential.id],
});

expect(statusDocs.length).toBe(1);

for (const statusDoc of statusDocs) {
expect(statusDoc.status).toBe(CredentialStatus.Verified);
}
});


afterEach(() => {
(credentialServiceRPC.verifyCredential as any).mockReset();
});
});
});
Loading

0 comments on commit 4b2bb5d

Please sign in to comment.