-
Notifications
You must be signed in to change notification settings - Fork 3
/
resolver.js
79 lines (75 loc) · 2.55 KB
/
resolver.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import axios from 'axios';
import { Resolver as lac, Lac1Resolver as lac1 } from '@lacchain/did';
import ethr from 'ethr-did-resolver';
import web from 'web-did-resolver';
import DIDResolver from 'did-resolver';
import config from "./config.js";
export default class ResolverDID {
async resolve( did ) {
const ethrNetworks = config.ethr.networks.split( ',' ).map( n => ( {
name: n.split( '|' )[0],
registry: n.split( '|' )[1],
rpcUrl: n.split( '|' )[2]
} ) );
const lacNetworks = config.lac.networks.split( ',' ).map( node => {
const split = node.split('|');
return {
name: split[0],
registry: split[1],
rpcUrl: split[2],
nodeAddress: split.length > 3 ? split[3] : undefined,
expiration: split.length > 4 ? split[4] : undefined,
}
} );
const lac1Networks = config.lac1.networks.split( ',' ).map( node => {
const split = node.split('|');
return {
registry: split[0],
rpcUrl: split[1],
nodeAddress: split.length > 2 ? split[2] : undefined,
chainId: split.length > 3 ? parseInt(split[3]) : undefined,
}
} );
const lacResolver = config.lac.resolve ? lac( { networks: lacNetworks, mode: 'explicit' } ) : {};
const lac1Resolver = config.lac1.resolve ? lac1( { networks: lac1Networks, mode: 'explicit' } ) : {};
const ethrResolver = config.ethr.resolve ? ethr.getResolver( { networks: ethrNetworks } ) : {};
const webResolver = config.web.resolve ? web.getResolver() : {};
const resolver = new DIDResolver.Resolver( {
...lacResolver,
...lac1Resolver,
...ethrResolver,
...webResolver,
...config.btcr.resolve ? {
btcr: async( did, parsed ) => {
const didDoc = await axios.get( `${config.btcr.endpoint}/${parsed.did}` );
return didDoc.data;
}
} : {},
...config.sov.resolve ? {
sov: async( did, parsed ) => {
const didDoc = await axios.get( `${config.sov.endpoint}/${parsed.did}` );
return didDoc.data;
}
} : {},
...config.nacl.resolve ? {
nacl: async( did, parsed ) => {
const didDoc = await axios.get( `${config.nacl.endpoint}/${parsed.did}` );
return didDoc.data;
}
} : {},
...config.elem.resolve ? {
elem: async( did, parsed ) => {
const didDoc = await axios.get( `${config.elem.endpoint}/${parsed.did}` );
return didDoc.data;
}
} : {},
...config.elsi.resolve ? {
elsi: async( did, parsed ) => {
const didDoc = await axios.get( `${config.elsi.endpoint}/${parsed.did}` );
return didDoc.data.payload;
}
} : {}
});
return await resolver.resolve( did );
}
}