@@ -6,21 +6,37 @@ import Debug from 'debug'
6
6
7
7
const debug = Debug ( 'daf:resolver' )
8
8
9
+ interface NetworkConfig {
10
+ name : string
11
+ rpcUrl : string
12
+ }
13
+
9
14
interface Options {
10
- infuraProjectId : string
15
+ infuraProjectId ?: string
16
+ networks ?: NetworkConfig [ ]
11
17
}
12
18
13
19
export class DafResolver {
14
20
private didResolver : Resolver
15
21
16
22
constructor ( options : Options ) {
23
+ let networks : NetworkConfig [ ]
24
+ if ( ! options . networks && options . infuraProjectId ) {
25
+ networks = [
26
+ { name : 'mainnet' , rpcUrl : 'https://mainnet.infura.io/v3/' + options . infuraProjectId } ,
27
+ { name : 'rinkeby' , rpcUrl : 'https://rinkeby.infura.io/v3/' + options . infuraProjectId } ,
28
+ { name : 'ropsten' , rpcUrl : 'https://ropsten.infura.io/v3/' + options . infuraProjectId } ,
29
+ { name : 'kovan' , rpcUrl : 'https://kovan.infura.io/v3/' + options . infuraProjectId } ,
30
+ { name : 'goerli' , rpcUrl : 'https://goerli.infura.io/v3/' + options . infuraProjectId } ,
31
+ ]
32
+ } else if ( ! options . infuraProjectId && options . networks ) {
33
+ networks = options . networks
34
+ } else {
35
+ throw Error ( '[daf-resolver] infuraProjectId or networks config required' )
36
+ }
37
+ debug ( 'Networks config' , networks )
17
38
this . didResolver = new Resolver ( {
18
- ...ethrDidResolver ( {
19
- networks : [
20
- { name : 'mainnet' , rpcUrl : 'https://mainnet.infura.io/v3/' + options . infuraProjectId } ,
21
- { name : 'rinkeby' , rpcUrl : 'https://rinkeby.infura.io/v3/' + options . infuraProjectId } ,
22
- ] ,
23
- } ) ,
39
+ ...ethrDidResolver ( { networks } ) ,
24
40
...webDidResolver ( ) ,
25
41
nacl : naclDidResolver ,
26
42
} )
0 commit comments