22import yargs from 'yargs'
33
44import { ResolveGroup , ResolveAddress , ResolveNom } from '../src'
5+ import { ResolveCelo } from '../src'
56
6- async function main ( args : any ) {
7- const providerUrl = 'https://forno.celo.org '
7+ import { OdisUtils } from '@celo/identity'
8+ import { OdisContextName } from '@celo/identity/lib/odis/query '
89
9- const resolver = new ResolveGroup ( [
10+ import { newKit } from '@celo/contractkit'
11+
12+ const NETWORKS : Record < string , any > = {
13+ alfajores : {
14+ providerUrl : 'https://alfajores-forno.celo-testnet.org' ,
15+ ensRegistryAddress : ResolveNom . AlfajoresENSRegsitryAddress ,
16+ federatedAttestationsProxyContractAddress :
17+ ResolveCelo . AlfajoresFederatedAttestationsProxyContractAddress ,
18+ trustedIssuers : ResolveCelo . AlfajoresDefaultTrustedIssuers ,
19+ odisContextName : OdisContextName . ALFAJORES ,
20+ } ,
21+ mainnet : {
22+ providerUrl : 'https://forno.celo.org' ,
23+ ensRegistryAddress : ResolveNom . MainnetENSRegsitryAddress ,
24+ federatedAttestationsProxyContractAddress :
25+ ResolveCelo . MainnetFederatedAttestationsProxyContractAddress ,
26+ trustedIssuers : ResolveCelo . MainnetDefaultTrustedIssuers ,
27+ odisContextName : OdisContextName . MAINNET ,
28+ } ,
29+ }
30+
31+ async function main ( args : ReturnType < typeof parseArgs > ) {
32+ const network = NETWORKS [ args [ 'network-id' ] ]
33+ const providerUrl = network . providerUrl
34+
35+ const resolvers = [
1036 new ResolveAddress ( ) ,
1137 new ResolveNom ( {
1238 providerUrl,
13- ensRegistryAddress : ResolveNom . MainnetENSRegsitryAddress ,
39+ ensRegistryAddress : network . ensRegistryAddress ,
1440 } ) ,
15- ] )
41+ ]
42+
43+ if ( args [ 'private-key' ] ) {
44+ const privateKey = args [ 'private-key' ]
45+ const kit = await newKit ( providerUrl )
46+ kit . addAccount ( privateKey )
47+ const account =
48+ kit . web3 . eth . accounts . privateKeyToAccount ( privateKey ) . address
49+ const resolveCelo = new ResolveCelo ( {
50+ providerUrl,
51+ federatedAttestationsProxyContractAddress :
52+ network . federatedAttestationsProxyContractAddress ,
53+ trustedIssuers : network . trustedIssuers ,
54+ authSigner : {
55+ authenticationMethod : OdisUtils . Query . AuthenticationMethod . WALLET_KEY ,
56+ contractKit : kit ,
57+ } ,
58+ account,
59+ serviceContext : OdisUtils . Query . getServiceContext (
60+ network . odisContextName ,
61+ ) ,
62+ } )
63+
64+ resolvers . push ( resolveCelo )
65+ }
66+
67+ const resolver = new ResolveGroup ( resolvers )
1668 const resolutions = await resolver . resolve ( args . id )
1769
1870 if ( resolutions . errors . length ) {
@@ -23,12 +75,23 @@ async function main(args: any) {
2375
2476function parseArgs ( ) {
2577 return yargs
78+ . option ( 'network-id' , {
79+ description : 'Celo network' ,
80+ type : 'string' ,
81+ choices : Object . keys ( NETWORKS ) ,
82+ default : 'alfajores' ,
83+ } )
84+ . option ( 'private-key' , {
85+ description : 'Private key for ODIS lookup' ,
86+ type : 'string' ,
87+ } )
2688 . option ( 'id' , {
2789 description : 'Identifier to resolve' ,
2890 type : 'string' ,
2991 demandOption : true ,
3092 } )
31- . strict ( ) . argv
93+ . strict ( )
94+ . parseSync ( )
3295}
3396
3497main ( parseArgs ( ) )
0 commit comments