|
1 | 1 | import {dockService} from '@docknetwork/wallet-sdk-wasm/src/services/dock';
|
2 | 2 | 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 | +} |
3 | 10 |
|
4 | 11 | export async function getEcosystems({
|
5 | 12 | issuerDID,
|
6 | 13 | verifierDID,
|
7 | 14 | schemaId,
|
| 15 | + networkId, |
8 | 16 | }: {
|
| 17 | + networkId: string; |
9 | 18 | issuerDID?: string;
|
10 | 19 | verifierDID?: string;
|
11 | 20 | schemaId?: string;
|
12 | 21 | }) {
|
13 |
| - await dockService.ensureDockReady(); |
14 |
| - |
| 22 | + assert(!!networkId, 'networkId is required'); |
| 23 | + |
15 | 24 | 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; |
17 | 39 | } catch (error) {
|
18 | 40 | console.log('error', error);
|
19 | 41 | return [];
|
20 | 42 | }
|
21 | 43 | }
|
22 | 44 |
|
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'); |
25 | 53 |
|
26 | 54 | 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; |
33 | 58 | } catch (error) {
|
34 | 59 | console.log('error', error);
|
35 | 60 | return [];
|
|
0 commit comments