@@ -35,17 +35,18 @@ const sleep = require('sleep-promise')
3535const FWA_KDF = 'ARGON2I_MOD'
3636
3737async function assureFwaWalletWasSetUp ( serviceIndyWallets , agencyWalletName , agencyWalletKey , agencyDid , agencySeed ) {
38- logger . info ( `FWA Assuring its wallet '${ agencyWalletName } ' exists` )
39- await serviceIndyWallets . assureWallet ( agencyWalletName , agencyWalletKey , FWA_KDF )
40-
4138 logger . info ( `Getting '${ agencyWalletName } ' wallet handle.` )
4239 const wh = await serviceIndyWallets . getWalletHandle ( agencyWalletName , agencyWalletKey , FWA_KDF )
40+ logger . info ( `Checking if agency did ${ agencyDid } exists in wallet` )
4341 const agencyDidWasSetUp = await indyDidExists ( wh , agencyDid )
4442 if ( ! agencyDidWasSetUp ) {
4543 logger . info ( `Agency DID '${ agencyDid } ' not found in wallet. Creating.` )
4644 await indyCreateAndStoreMyDid ( wh , agencyDid , agencySeed )
4745 logger . debug ( `Forward agent create ${ agencyDid } ` )
46+ } else {
47+ logger . info ( `Agency DID '${ agencyDid } ' was found in wallet.` )
4848 }
49+
4950 const agencyVerkey = await indyKeyForLocalDid ( wh , agencyDid )
5051 logger . info ( `Agency DID '${ agencyWalletName } ' has assigned verkey ${ agencyVerkey } ` )
5152 return agencyVerkey
@@ -60,17 +61,19 @@ async function assureFwaWalletWasSetUp (serviceIndyWallets, agencyWalletName, ag
6061 * This is design trade off to have simple singleton.
6162 */
6263async function buildForwardAgent ( serviceIndyWallets , serviceStorage , agencyWalletName , agencyWalletKey , agencyDid , agencySeed , waitTime = 1000 , attempts = 10 ) {
63- let router , resolver , agencyVerkey
64+ let router , resolver
6465
6566 for ( let attempt = 0 ; attempt < attempts ; attempt ++ ) {
6667 try {
67- agencyVerkey = await assureFwaWalletWasSetUp ( serviceIndyWallets , agencyWalletName , agencyWalletKey , agencyDid , agencySeed )
68+ logger . info ( `FWA Assuring its wallet '${ agencyWalletName } ' exists` )
69+ await serviceIndyWallets . assureWallet ( agencyWalletName , agencyWalletKey , FWA_KDF )
6870 break
6971 } catch ( err ) {
70- console . warn ( `Failed to build FWA agent: ${ err } \nRemaining attempts: ${ attempts - attempt - 1 } ` )
72+ logger . warn ( `Failed to assure FWA wallet due to error ${ err . stack } . Remaining attempts: ${ attempts - attempt - 1 } ` )
7173 await sleep ( waitTime )
7274 }
7375 }
76+ const agencyVerkey = await assureFwaWalletWasSetUp ( serviceIndyWallets , agencyWalletName , agencyWalletKey , agencyDid , agencySeed )
7477
7578 const whoami = `[ForwardAgent ${ agencyDid } ]`
7679
0 commit comments