import { AnonCredsCredentialFormatService, AnonCredsModule, AnonCredsProofFormatService, DataIntegrityCredentialFormatService, LegacyIndyCredentialFormatService, LegacyIndyProofFormatService, V1CredentialProtocol, V1ProofProtocol } from '@credo-ts/anoncreds';
import { AskarModule } from '@credo-ts/askar';
import { AutoAcceptCredential, AutoAcceptProof, ConnectionsModule, CredentialsModule, DidsModule, DifPresentationExchangeProofFormatService, JwkDidResolver, KeyDidResolver, MediationRecipientModule, MediatorPickupStrategy, PeerDidResolver, ProofsModule, V2CredentialProtocol, V2ProofProtocol, WebDidResolver } from '@credo-ts/core';
import { IndyVdrAnonCredsRegistry, IndyVdrModule } from '@credo-ts/indy-vdr';
import { OpenId4VcHolderModule } from '@credo-ts/openid4vc';
import { PushNotificationsApnsModule, PushNotificationsFcmModule } from '@credo-ts/push-notifications';
import { WebVhAnonCredsRegistry, WebvhDidResolver } from '@credo-ts/webvh';
import { useAgent } from '@credo-ts/react-hooks';
import { anoncreds } from '@hyperledger/anoncreds-react-native';
import { ariesAskar } from '@hyperledger/aries-askar-react-native';
import { indyVdr } from '@hyperledger/indy-vdr-react-native';
/**
 * Constructs the modules to be used in the agent setup
 * @param indyNetworks
 * @param mediatorInvitationUrl determine which mediator to use
 * @param txnCache optional local cache config for indyvdr
 * @returns modules to be used in agent setup
 */
export function getAgentModules({
  indyNetworks,
  mediatorInvitationUrl,
  txnCache
}) {
  const indyCredentialFormat = new LegacyIndyCredentialFormatService();
  const indyProofFormat = new LegacyIndyProofFormatService();
  if (txnCache) {
    indyVdr.setLedgerTxnCache({
      capacity: txnCache.capacity,
      expiry_offset_ms: txnCache.expiryOffsetMs,
      path: txnCache.path
    });
  }
  return {
    askar: new AskarModule({
      ariesAskar
    }),
    anoncreds: new AnonCredsModule({
      anoncreds,
      registries: [new IndyVdrAnonCredsRegistry(), new WebVhAnonCredsRegistry()]
    }),
    indyVdr: new IndyVdrModule({
      indyVdr,
      networks: indyNetworks
    }),
    connections: new ConnectionsModule({
      autoAcceptConnections: true
    }),
    credentials: new CredentialsModule({
      autoAcceptCredentials: AutoAcceptCredential.ContentApproved,
      credentialProtocols: [new V1CredentialProtocol({
        indyCredentialFormat
      }), new V2CredentialProtocol({
        credentialFormats: [indyCredentialFormat, new AnonCredsCredentialFormatService(), new DataIntegrityCredentialFormatService()]
      })]
    }),
    proofs: new ProofsModule({
      autoAcceptProofs: AutoAcceptProof.ContentApproved,
      proofProtocols: [new V1ProofProtocol({
        indyProofFormat
      }), new V2ProofProtocol({
        proofFormats: [indyProofFormat, new AnonCredsProofFormatService(), new DifPresentationExchangeProofFormatService()]
      })]
    }),
    mediationRecipient: new MediationRecipientModule({
      mediatorInvitationUrl: mediatorInvitationUrl,
      mediatorPickupStrategy: MediatorPickupStrategy.Implicit
    }),
    pushNotificationsFcm: new PushNotificationsFcmModule(),
    pushNotificationsApns: new PushNotificationsApnsModule(),
    openId4VcHolder: new OpenId4VcHolderModule(),
    dids: new DidsModule({
      resolvers: [new WebvhDidResolver(), new WebDidResolver(), new JwkDidResolver(), new KeyDidResolver(), new PeerDidResolver()]
    })
  };
}
export const useAppAgent = useAgent;
export const createLinkSecretIfRequired = async agent => {
  // If we don't have any link secrets yet, we will create a
  // default link secret that will be used for all anoncreds
  // credential requests.
  const linkSecretIds = await agent.modules.anoncreds.getLinkSecretIds();
  if (linkSecretIds.length === 0) {
    await agent.modules.anoncreds.createLinkSecret({
      setAsDefault: true
    });
  }
};
//# sourceMappingURL=agent.js.map