Skip to content

Commit 2290637

Browse files
authoredOct 22, 2024
Merge pull request #301 from docknetwork/DCKW-577-use-the-api-for-trust-registry-lookups
DCKW-577: use the API for trust registry lookups
2 parents 6c904c6 + 906ab61 commit 2290637

File tree

2 files changed

+54
-12
lines changed

2 files changed

+54
-12
lines changed
 

‎integration-tests/ecosystem-tools.test.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {IWallet} from '@docknetwork/wallet-sdk-core/lib/types';
22
import {closeWallet, getWallet} from './helpers/wallet-helpers';
3-
import {getEcosystems} from '@docknetwork/wallet-sdk-core/src/ecosystem-tools';
3+
import {getEcosystems, getVerifiers} from '@docknetwork/wallet-sdk-core/src/ecosystem-tools';
44

55
const biometricCredential = {
66
'@context': [
@@ -76,6 +76,7 @@ describe('BBS+ presentations', () => {
7676

7777
const result = await getEcosystems({
7878
issuerDID: biometricCredential.issuer.id,
79+
networkId: 'testnet',
7980
});
8081

8182
console.log(result);
@@ -95,6 +96,22 @@ describe('BBS+ presentations', () => {
9596
'0xc5671b2d1552db9b47a3501109ddbeb861a55fe3f7a0cb7a26791203abe9fcc8'
9697
].name,
9798
).toBe('clarity partners');
99+
100+
});
101+
102+
it('should fetch verifiers for the given registry', async () => {
103+
104+
const result = await getVerifiers({
105+
trustRegistryId: '0xdbba3dec1cb5523760480d430c3f18d96848f93a95662944a296a1753ef2860d',
106+
schemaId: 'https://schema.dock.io/BankIdentity-V5-1721219465285.json',
107+
networkId: 'testnet',
108+
});
109+
110+
console.log(result);
111+
112+
expect(result.length).toBeGreaterThan(0);
113+
expect(result).toContain('did:dock:5Fv9Gxbf37DdiNrT31zKTM7ryf8H4psoP3XXxtmVuijNiTTS');
114+
98115
});
99116

100117
afterAll(() => closeWallet());

‎packages/core/src/ecosystem-tools.ts

+36-11
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,60 @@
11
import {dockService} from '@docknetwork/wallet-sdk-wasm/src/services/dock';
22
import {trustRegistryService} from '@docknetwork/wallet-sdk-wasm/src/services/trust-registry';
3+
import assert from 'assert';
4+
import axios from 'axios';
5+
6+
7+
function getApiURL(networkId) {
8+
return networkId === 'mainnet' ? 'https://api.dock.io' : 'https://api-testnet.dock.io';
9+
}
310

411
export async function getEcosystems({
512
issuerDID,
613
verifierDID,
714
schemaId,
15+
networkId,
816
}: {
17+
networkId: string;
918
issuerDID?: string;
1019
verifierDID?: string;
1120
schemaId?: string;
1221
}) {
13-
await dockService.ensureDockReady();
14-
22+
assert(!!networkId, 'networkId is required');
23+
1524
try {
16-
return await trustRegistryService.getTrustRegistries({issuerDID, verifierDID, schemaId});
25+
// TODO: Use the SDK to fetch ecosystems when it's available
26+
const {data} = await axios.post(`${getApiURL(networkId)}/trust-registries/query`,{
27+
issuerDID,
28+
verifierDID,
29+
schemaId,
30+
})
31+
32+
const registries = {}
33+
34+
data.forEach((registry) => {
35+
registries[registry.id] = registry;
36+
});
37+
38+
return registries;
1739
} catch (error) {
1840
console.log('error', error);
1941
return [];
2042
}
2143
}
2244

23-
export async function getVerifiers({trustRegistryId, issuerDID, schemaId}) {
24-
await dockService.ensureDockReady();
45+
export async function getVerifiers({trustRegistryId, issuerDID, schemaId, networkId}: {
46+
trustRegistryId: string;
47+
issuerDID?: string;
48+
schemaId?: string;
49+
networkId: string;
50+
}) {
51+
assert(!!networkId, 'networkId is required');
52+
assert(!!trustRegistryId, 'trustRegistryId is required');
2553

2654
try {
27-
const verifiers = await trustRegistryService.getTrustRegistryVerifiers({
28-
schemaId,
29-
issuerDID: issuerDID,
30-
trustRegistryId,
31-
});
32-
return verifiers;
55+
// TODO: Use the SDK to fetch verifiers when it's available
56+
const { data } = await axios.get(`${getApiURL(networkId)}/trust-registries/${trustRegistryId}/verifiers?schemaId=${encodeURIComponent(schemaId)}&issuerDID=${issuerDID}`);
57+
return data;
3358
} catch (error) {
3459
console.log('error', error);
3560
return [];

0 commit comments

Comments
 (0)