Skip to content

Commit

Permalink
Merge pull request #301 from docknetwork/DCKW-577-use-the-api-for-tru…
Browse files Browse the repository at this point in the history
…st-registry-lookups

DCKW-577: use the API for trust registry lookups
  • Loading branch information
maycon-mello authored Oct 22, 2024
2 parents 6c904c6 + 906ab61 commit 2290637
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 12 deletions.
19 changes: 18 additions & 1 deletion integration-tests/ecosystem-tools.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {IWallet} from '@docknetwork/wallet-sdk-core/lib/types';
import {closeWallet, getWallet} from './helpers/wallet-helpers';
import {getEcosystems} from '@docknetwork/wallet-sdk-core/src/ecosystem-tools';
import {getEcosystems, getVerifiers} from '@docknetwork/wallet-sdk-core/src/ecosystem-tools';

const biometricCredential = {
'@context': [
Expand Down Expand Up @@ -76,6 +76,7 @@ describe('BBS+ presentations', () => {

const result = await getEcosystems({
issuerDID: biometricCredential.issuer.id,
networkId: 'testnet',
});

console.log(result);
Expand All @@ -95,6 +96,22 @@ describe('BBS+ presentations', () => {
'0xc5671b2d1552db9b47a3501109ddbeb861a55fe3f7a0cb7a26791203abe9fcc8'
].name,
).toBe('clarity partners');

});

it('should fetch verifiers for the given registry', async () => {

const result = await getVerifiers({
trustRegistryId: '0xdbba3dec1cb5523760480d430c3f18d96848f93a95662944a296a1753ef2860d',
schemaId: 'https://schema.dock.io/BankIdentity-V5-1721219465285.json',
networkId: 'testnet',
});

console.log(result);

expect(result.length).toBeGreaterThan(0);
expect(result).toContain('did:dock:5Fv9Gxbf37DdiNrT31zKTM7ryf8H4psoP3XXxtmVuijNiTTS');

});

afterAll(() => closeWallet());
Expand Down
47 changes: 36 additions & 11 deletions packages/core/src/ecosystem-tools.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,60 @@
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';


function getApiURL(networkId) {
return networkId === 'mainnet' ? 'https://api.dock.io' : 'https://api-testnet.dock.io';
}

export async function getEcosystems({
issuerDID,
verifierDID,
schemaId,
networkId,
}: {
networkId: string;
issuerDID?: string;
verifierDID?: string;
schemaId?: string;
}) {
await dockService.ensureDockReady();

assert(!!networkId, 'networkId is required');
try {
return await trustRegistryService.getTrustRegistries({issuerDID, verifierDID, schemaId});
// TODO: Use the SDK to fetch ecosystems when it's available
const {data} = await axios.post(`${getApiURL(networkId)}/trust-registries/query`,{
issuerDID,
verifierDID,
schemaId,
})

const registries = {}

data.forEach((registry) => {
registries[registry.id] = registry;
});

return registries;
} catch (error) {
console.log('error', error);
return [];
}
}

export async function getVerifiers({trustRegistryId, issuerDID, schemaId}) {
await dockService.ensureDockReady();
export async function getVerifiers({trustRegistryId, issuerDID, schemaId, networkId}: {
trustRegistryId: string;
issuerDID?: string;
schemaId?: string;
networkId: string;
}) {
assert(!!networkId, 'networkId is required');
assert(!!trustRegistryId, 'trustRegistryId is required');

try {
const verifiers = await trustRegistryService.getTrustRegistryVerifiers({
schemaId,
issuerDID: issuerDID,
trustRegistryId,
});
return verifiers;
// TODO: Use the SDK to fetch verifiers when it's available
const { data } = await axios.get(`${getApiURL(networkId)}/trust-registries/${trustRegistryId}/verifiers?schemaId=${encodeURIComponent(schemaId)}&issuerDID=${issuerDID}`);
return data;
} catch (error) {
console.log('error', error);
return [];
Expand Down

0 comments on commit 2290637

Please sign in to comment.