Skip to content

Commit

Permalink
Merge pull request #310 from docknetwork/feat/cheqd-migration
Browse files Browse the repository at this point in the history
cheqd migration
maycon-mello authored Dec 10, 2024
2 parents 4ab356d + 15f1b3e commit d52ddcd
Showing 50 changed files with 1,103 additions and 314 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests.yaml
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ jobs:
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: '18.17.1'
node-version: '20.2.0'

- name: Install GitHub CLI
run: |
2 changes: 1 addition & 1 deletion .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ jobs:
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: '18.17.1'
node-version: '20.2.0'

- name: Cache dependencies
uses: actions/cache@v2
2 changes: 1 addition & 1 deletion .github/workflows/npm-audit.yml
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ jobs:
audit:
runs-on: ubuntu-latest
env:
NODE_VERSION: 18.x
NODE_VERSION: '20.2.0'
AVOID_LICENSES: "AGPL;GPL;AGPL-3.0"
IGNORE_PACKAGES: ""

2 changes: 1 addition & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: '18.x'
node-version: '20.2.0'
registry-url: https://registry.npmjs.org/
- run: yarn install
- run: yarn build
4 changes: 2 additions & 2 deletions examples/verify-credential.js
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ const {
didServiceRPC,
} = require('@docknetwork/wallet-sdk-wasm/src/services/dids');

const {dockService} = require('@docknetwork/wallet-sdk-wasm/src/services/dock');
const {blockchainService} = require('@docknetwork/wallet-sdk-wasm/src/services/blockchain');

const exampleCredential = require('./example-credential.json');
const presentationDefinition = require('./presentation-definition.json');
@@ -19,7 +19,7 @@ async function main() {

console.log('Connecting to dock network');

await dockService.ensureDockReady();
await blockchainService.ensureBlockchainReady();

// generate new DID
const keyDoc = await didServiceRPC.generateKeyDoc({});
57 changes: 57 additions & 0 deletions integration-tests/cheqd-credentials.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { IWallet } from '@docknetwork/wallet-sdk-core/lib/types';
import { createVerificationController } from '@docknetwork/wallet-sdk-core/src/verification-controller';
import { CheqdCredentialNonZKP, CheqdCredentialZKP } from './data/credentials/cheqd-credentials';
import { closeWallet, createNewWallet, getCredentialProvider, getWallet } from './helpers';
import { ProofTemplateIds, createProofRequest } from './helpers/certs-helpers';

describe('Cheq integration tests', () => {
beforeAll(async () => {
await createNewWallet();
});

it('should verify a non ZKP cheqd credential', async () => {
const wallet: IWallet = await getWallet();

getCredentialProvider().addCredential(CheqdCredentialNonZKP);

const proofRequest = await createProofRequest(
ProofTemplateIds.ANY_CREDENTIAL,
);

const result: any = await getCredentialProvider().isValid(CheqdCredentialNonZKP);

expect(result).toBeTruthy();

const controller = await createVerificationController({
wallet,
});

await controller.start({
template: proofRequest,
});

controller.selectedCredentials.set(CheqdCredentialNonZKP.id, {
credential: CheqdCredentialNonZKP,
});

const presentation = await controller.createPresentation();
console.log('Presentation generated');
console.log(JSON.stringify(presentation, null, 2));
console.log('Sending presentation to Certs API');

let certsResponse;
try {
certsResponse = await controller.submitPresentation(presentation);
console.log('CERTS response');
console.log(JSON.stringify(certsResponse, null, 2));
} catch (err) {
certsResponse = err.response.data;
console.log('Certs API returned an error');
console.log(JSON.stringify(certsResponse, null, 2));
}

expect(certsResponse.verified).toBe(true);

Check failure on line 53 in integration-tests/cheqd-credentials.test.ts

GitHub Actions / Integration Test Report

integration-tests/cheqd-credentials.test.ts ► Cheq integration tests ► should verify a non ZKP cheqd credential

Failed test found in: reports/jest-junit.xml Error: Error: expect(received).toBe(expected) // Object.is equality
Raw output
Error: expect(received).toBe(expected) // Object.is equality

Expected: true
Received: undefined
    at Object.<anonymous> (/home/runner/work/react-native-sdk/react-native-sdk/integration-tests/cheqd-credentials.test.ts:53:36)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
});

afterAll(() => closeWallet());
});
113 changes: 113 additions & 0 deletions integration-tests/data/credentials/cheqd-credentials.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions integration-tests/helpers/wallet-helpers.ts
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ import {
ICredentialProvider,
createCredentialProvider,
} from '@docknetwork/wallet-sdk-core/src/credential-provider';
import {dockService} from '@docknetwork/wallet-sdk-wasm/src/services/dock';
import {blockchainService} from '@docknetwork/wallet-sdk-wasm/src/services/blockchain';
import {createDataStore} from '@docknetwork/wallet-sdk-data-store-typeorm/src';
import {DataStore} from '@docknetwork/wallet-sdk-data-store/src/types';

@@ -131,7 +131,7 @@ export async function closeWallet(wallet?: IWallet) {
setTimeout(async () => {
try {
wallet.dataStore.db.destroy();
await dockService.disconnect();
await blockchainService.disconnect();
} catch (err) {
console.error(err);
}
4 changes: 2 additions & 2 deletions integration-tests/verification-flow/bbs-plus-expired.test.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ import {createVerificationController} from '@docknetwork/wallet-sdk-core/src/ver
import {verifyPresentation} from '@docknetwork/sdk/utils/vc/presentations';
import assert from 'assert';
import {initializeWasm} from '@docknetwork/crypto-wasm-ts/lib/index';
import { dockService } from '@docknetwork/wallet-sdk-wasm/src/services/dock';
import { blockchainService } from '@docknetwork/wallet-sdk-wasm/src/services/blockchain';

const testAPIURL = process.env.TESTING_API_URL || null;

@@ -129,7 +129,7 @@ describe('BBS+ presentations', () => {

const verificationResults = await verifyPresentation(presentation, {
compactProof: true,
resolver: dockService.resolver,
resolver: blockchainService.resolver,
challenge: proofRequest.nonce,
unsignedPresentation: true,
domain: 'dock.io',
4 changes: 2 additions & 2 deletions integration-tests/verification-flow/bbs-plus-valid.test.ts
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import {IWallet} from '@docknetwork/wallet-sdk-core/lib/types';
import {closeWallet, getWallet} from '../helpers/wallet-helpers';
import {createVerificationController} from '@docknetwork/wallet-sdk-core/src/verification-controller';
import {verifyPresentation} from '@docknetwork/sdk/utils/vc/presentations';
import { dockService } from '@docknetwork/wallet-sdk-wasm/src/services/dock';
import { blockchainService } from '@docknetwork/wallet-sdk-wasm/src/services/blockchain';

const credential = {
'@context': [
@@ -135,7 +135,7 @@ describe('BBS+ presentations', () => {

const verificationResults = await verifyPresentation(presentation, {
compactProof: true,
resolver: dockService.resolver,
resolver: blockchainService.resolver,
challenge: proofRequest.nonce,
unsignedPresentation: true,
domain: 'dock.io',
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ import {IWallet} from '@docknetwork/wallet-sdk-core/lib/types';
import {closeWallet, getWallet} from '../helpers/wallet-helpers';
import {createVerificationController} from '@docknetwork/wallet-sdk-core/src/verification-controller';
import {verifyPresentation} from '@docknetwork/sdk/utils/vc/presentations';
import {dockService} from '@docknetwork/wallet-sdk-wasm/src/services/dock';
import {blockchainService} from '@docknetwork/wallet-sdk-wasm/src/services/blockchain';
import {autoLoanProofRequest} from './proof-requests';

const biometricCredential = {
@@ -344,7 +344,7 @@ describe('BBS+ presentations', () => {

const verificationResults = await verifyPresentation(presentation, {
compactProof: true,
resolver: dockService.resolver,
resolver: blockchainService.resolver,
challenge: proofRequest.nonce,
unsignedPresentation: true,
domain: 'dock.io',
6 changes: 3 additions & 3 deletions integration-tests/wallet-backup.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {closeWallet, createNewWallet} from './helpers';
import {WalletBackupJSON, WalletBackupPasssword} from './data/wallet-backup';
import { dockService } from '@docknetwork/wallet-sdk-wasm/lib/services/dock';
import {blockchainService} from '@docknetwork/wallet-sdk-wasm/lib/services/blockchain';

describe('Wallet backups', () => {
it('expect to import wallet from backup', async () => {
@@ -15,7 +15,7 @@ describe('Wallet backups', () => {

const documents = await wallet.getAllDocuments();

expect(documents.length).toBe(6);
expect(documents.length).toBe(7);
});

it('expect to export wallet backup', async () => {
@@ -34,7 +34,7 @@ describe('Wallet backups', () => {
});

afterEach(async () => {
await dockService.disconnect();
await blockchainService.disconnect();
})

afterAll(() => closeWallet());
2 changes: 1 addition & 1 deletion integration-tests/wallet-snapshot-v1.test.ts
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ describe('Wallet Snapshot V1', () => {

it('expect to have load all documents', async () => {
const documents = await wallet.query({});
expect(documents.length).toBe(9);
expect(documents.length).toBe(10);
});

it('expect to have load accounts', async () => {
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -108,7 +108,10 @@
"@babel/plugin-transform-modules-commonjs": "^7.18.6",
"@babel/preset-flow": "^7.16.7",
"@babel/preset-typescript": "^7.22.5",
"@cosmjs/proto-signing": "^0.32.4",
"@digitalbazaar/x25519-key-agreement-key-2020": "2.1.0",
"@docknetwork/cheqd-blockchain-api": "0.14.1",
"@docknetwork/cheqd-blockchain-modules": "0.11.2",
"@docknetwork/credential-sdk": "0.16.0",
"@docknetwork/dock-blockchain-api": "0.8.2",
"@docknetwork/dock-blockchain-modules": "0.9.2",
26 changes: 13 additions & 13 deletions packages/cli/src/commands/ecosystem.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Command} from 'commander';
import {typedHexDID} from '@docknetwork/sdk/utils/did/typed-did/helpers';
import {dockService} from '@docknetwork/wallet-sdk-wasm/src/services/dock/service';
import {blockchainService} from '@docknetwork/wallet-sdk-wasm/src/services/blockchain/service';
import {getWallet} from '../helpers';
import {getDIDKeyPairs} from '@docknetwork/wallet-sdk-core/src/did-provider';
import {randomAsHex} from '@polkadot/util-crypto';
@@ -18,50 +18,50 @@ ecosystemCommands
const didKeyPairs = await getDIDKeyPairs({wallet});
const didKeyPair = didKeyPairs[0];

await dockService.init({
await blockchainService.init({
address: 'wss://knox-1.dock.io',
});

await dockService.waitDockReady();
await dockService.ensureDockReady();
await blockchainService.waitBlockchainReady();
await blockchainService.ensureBlockchainReady();

const trustRegistryId = randomAsHex(32);

const trustRegistry = await dockService.dock.trustRegistry.initOrUpdate(
const trustRegistry = await blockchainService.dock.trustRegistry.initOrUpdate(
didKeyPair.id,
trustRegistryId,
'Test Registry II',
'Gov framework II',
didKeyPair,
dockService.dock,
blockchainService.dock,
);
console.log(trustRegistry);

await dockService.disconnect();
await blockchainService.disconnect();
});

ecosystemCommands
.command('getEcosystemFromDID')
.option('-d, --did <did>', 'DID')
.description('Get ecosystem from issuer DID')
.action(async ({did}) => {
await dockService.init({
await blockchainService.init({
address: 'wss://knox-1.dock.io',
});

await dockService.waitDockReady();
await dockService.ensureDockReady();
await blockchainService.waitBlockchainReady();
await blockchainService.ensureBlockchainReady();

const issuerDIDMethodKey = typedHexDID(
dockService.dock.api,
blockchainService.dock.api,
did,
);
const registryInfo = await dockService.dock.trustRegistry?.registriesInfo({
const registryInfo = await blockchainService.dock.trustRegistry?.registriesInfo({
Issuer: issuerDIDMethodKey,
});
console.log(registryInfo);

await dockService.disconnect();
await blockchainService.disconnect();
});

export {ecosystemCommands};
4 changes: 2 additions & 2 deletions packages/core/src/credential-provider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {credentialServiceRPC} from '@docknetwork/wallet-sdk-wasm/src/services/credential';
import {IWallet} from './types';
import assert from 'assert';
import {dockService} from '@docknetwork/wallet-sdk-wasm/src/services/dock';
import {blockchainService} from '@docknetwork/wallet-sdk-wasm/src/services/blockchain';
import {acquireOpenIDCredentialFromURI} from './credentials/oidvc';
import {IDIDProvider} from './did-provider';

@@ -259,7 +259,7 @@ async function syncCredentialStatus({
}

if (!isApiConnected) {
await dockService.ensureDockReady();
await blockchainService.ensureBlockchainReady();
isApiConnected = true;
}

2 changes: 0 additions & 2 deletions packages/core/src/ecosystem-tools.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {dockService} from '@docknetwork/wallet-sdk-wasm/src/services/dock';
import {trustRegistryService} from '@docknetwork/wallet-sdk-wasm/src/services/trust-registry';
import assert from 'assert';
import axios from 'axios';

Loading

0 comments on commit d52ddcd

Please sign in to comment.