'use strict';

require('../../keypairs/dock-keypair.cjs');
var keypairs_keypairEd25519 = require('../../keypairs/keypair-ed25519.cjs');
require('../../keypairs/keypair-secp256k1.cjs');
var keypairs_didKeypair = require('../../keypairs/did-keypair.cjs');
require('../../types/blob/index.cjs');
require('../../types/attest/index.cjs');
require('../../types/did/index.cjs');
require('../../types/generic/typed-enum.cjs');
require('../../types/generic/typed-bytes.cjs');
require('../../types/generic/typed-string.cjs');
require('../../types/generic/typed-array.cjs');
require('../../types/generic/typed-tuple.cjs');
require('../../types/generic/typed-null.cjs');
require('../../utils/types/array.cjs');
require('crypto');
require('bs58');
require('multiformats/bases/base58');
require('varint');
require('../../utils/encoding/ss-58.cjs');
require('../../types/generic/typed-number.cjs');
require('../../types/generic/typed-set.cjs');
require('../../types/generic/typed-map.cjs');
require('../../types/generic/typed-struct.cjs');
require('uuid');
require('js-sha256');
require('../../types/offchain-signatures/params/index.cjs');
require('../../types/offchain-signatures/public-keys/index.cjs');
require('../../types/offchain-signatures/curve-type.cjs');
require('../../types/payload/cheqd.cjs');
require('../../types/policy/index.cjs');
require('../../types/public-keys/public-key.cjs');
require('../../types/public-keys/public-key-sr25519-value.cjs');
require('../../types/public-keys/public-key-ed25519-value.cjs');
require('../../types/public-keys/public-key-secp256k1-value.cjs');
require('../../types/public-keys/public-key-x25519-value.cjs');
require('../../types/signatures/signature-value.cjs');
require('../../types/signatures/signature.cjs');
require('../../types/status-list-credential/index.cjs');
require('../../types/anchor/index.cjs');
require('../../types/accumulator/keys.cjs');
require('../../types/accumulator/params.cjs');
require('../../types/accumulator/public-key.cjs');
require('../../types/accumulator/accumulator.cjs');
require('../../types/accumulator/id.cjs');
require('../../types/trust-registry/id.cjs');
var modules_tests_common = require('./common.cjs');
var resolver_statusList2021_statusList2021Resolver = require('../../resolver/status-list2021/status-list2021-resolver.cjs');
require('../../vc/presentations.cjs');
require('jsonld');
require('jsonld-signatures');
require('@digitalcredentials/vc-status-list');
require('base64url');
require('@docknetwork/crypto-wasm-ts');
require('../../vc/CredentialIssuancePurpose.cjs');
require('jsonschema');
require('blakejs');
var vc_helpers = require('../../vc/helpers.cjs');
require('../../vc/crypto/Bls12381BBDT16KeyPairDock2024.cjs');
require('../../vc/crypto/Bls12381BBDT16MACDock2024.cjs');
require('../../vc/crypto/Bls12381BBDT16MACProofDock2024.cjs');
require('../../vc/crypto/Bls12381BBSKeyPairDock2023.cjs');
require('../../vc/crypto/Bls12381BBSSignatureDock2022.cjs');
require('../../vc/crypto/Bls12381BBSSignatureDock2023.cjs');
require('../../vc/crypto/Bls12381BBSSignatureProofDock2022.cjs');
require('../../vc/crypto/Bls12381BBSSignatureProofDock2023.cjs');
require('../../vc/crypto/Bls12381BDDT16KeyPairDock2024.cjs');
require('../../vc/crypto/Bls12381BDDT16MACDock2024.cjs');
require('../../vc/crypto/Bls12381BDDT16MACProofDock2024.cjs');
require('../../vc/crypto/Bls12381G2KeyPairDock2022.cjs');
require('../../vc/crypto/Bls12381PSKeyPairDock2023.cjs');
require('../../vc/crypto/Bls12381PSSignatureDock2023.cjs');
require('../../vc/crypto/Bls12381PSSignatureProofDock2023.cjs');
require('@juanelas/base64');
require('../../vc/crypto/common/CustomLinkedDataSignature.cjs');
require('@transmute/json-web-signature');
require('../../vc/presentation.cjs');
var vc_statusList2021Credential = require('../../vc/status-list2021-credential.cjs');
require('../../vc/private-status-list2021-credential.cjs');
var types_did_document_index = require('../../types/did/document/index.cjs');
require('../../utils/types/bytes.cjs');
require('../../utils/interfaces.cjs');
require('../../utils/assert.cjs');
require('../../utils/error.cjs');
require('../../utils/types/string.cjs');
require('../../utils/types/iterable.cjs');
require('../../utils/types/object.cjs');
require('../../utils/inheritance.cjs');
require('../../utils/types/set.cjs');
require('blake2b');
require('@stablelib/ed25519');
require('../../vc/crypto/constants.cjs');
require('../../types/generic/with-base.cjs');
require('../../types/generic/with-catch-null.cjs');
require('../../types/generic/with-eq.cjs');
require('../../types/generic/any-of.cjs');
require('../../types/generic/with-from.cjs');
require('../../types/generic/with-from-json-bytes.cjs');
require('../../types/generic/create-placeholder.cjs');
require('../../types/generic/sized.cjs');
require('../../utils/types/number.cjs');
require('../../types/signatures/signature-ed25519-value.cjs');
require('../../types/signatures/signature-secp256k1-value.cjs');
require('../../types/signatures/signature-sr25519-value.cjs');
require('elliptic');
require('../../types/did/onchain/did-key.cjs');
require('../../types/did/onchain/verification-relationship.cjs');
require('../../types/did/document/verification-method-ref.cjs');
require('../../types/generic/with-qualifier.cjs');
require('../../types/generic/utils.cjs');
require('../../types/generic/typed-bytes-array.cjs');
require('../../types/did/onchain/typed-did/index.cjs');
require('../../types/did/onchain/typed-did/did-method-key/did-method-key-public-key.cjs');
require('../../utils/encoding/base-58-btc.cjs');
require('../../types/did/onchain/constants.cjs');
require('../../types/did/onchain/typed-did/signature.cjs');
require('../../types/did/onchain/typed-did/did-method-key/did-method-key-signature.cjs');
require('../../types/did/onchain/typed-did/dock-did-value.cjs');
require('../../types/generic/typed-uuid.cjs');
require('../../types/did/onchain/typed-did/cheqd-did.cjs');
require('../../types/offchain-signatures/public-keys/value.cjs');
require('../../types/generic/option.cjs');
require('../../types/generic/with-prop.cjs');
require('../../types/generic/with-props.cjs');
require('../../types/offchain-signatures/public-keys/ref.cjs');
require('../../types/offchain-signatures/params/id.cjs');
require('../../types/generic/with-from-dock-id.cjs');
require('../../types/offchain-signatures/params/value.cjs');
require('../../types/offchain-signatures/public-keys/id.cjs');
require('../../vc/crypto/common/DockCryptoKeyPair.cjs');
require('@docknetwork/crypto-wasm-ts/lib/index.js');
require('../../vc/crypto/common/DockCryptoSignature.cjs');
require('json-stringify-deterministic');
require('semver/preload.js');
require('../../vc/jws.cjs');
require('../../vc/crypto/common/DockCryptoSignatureProof.cjs');
require('../../types/did/document/verification-method-ref-or-ident-ref.cjs');
require('../../types/did/document/ident-ref.cjs');
require('../../types/blob/id.cjs');
require('../../types/blob/const.cjs');
require('../../utils/mappings/dock-did-by-id.cjs');
require('../../types/did/offchain/index.cjs');
require('../../types/did/offchain/doc-ref.cjs');
require('../../types/did/onchain/index.cjs');
require('../../types/did/onchain/controllers.cjs');
require('../../types/did/onchain/verification-method-signature.cjs');
require('../../types/did/document/service-endpoint.cjs');
require('../../types/did/document/verification-method.cjs');
require('../../utils/encoding/base-58.cjs');
require('../../types/generic/with-base58.cjs');
require('../../types/generic/with-base58btc.cjs');
require('../../types/generic/with-multibase.cjs');
require('../../utils/encoding/multibase.cjs');
require('../../types/did/document/verification-method-type.cjs');
require('../../types/did/document/verification-method-ref-or-cheqd-verification-method.cjs');
require('../../types/did/document/const.cjs');
require('../../types/blob/blob.cjs');
require('../../types/policy/one-of-policy-value.cjs');
require('../../types/status-list-credential/status-list-credential-value.cjs');
require('pako');
require('../../vc/verifiable-credential.cjs');
require('../../vc/credentials.cjs');
require('../../vc/document-loader.cjs');
require('../../vc/contexts.cjs');
require('../../vc/contexts/vc-examples-v1.cjs');
require('../../vc/contexts/security_context.cjs');
require('../../vc/contexts/status-list-21.cjs');
require('../../vc/contexts/private-status-list-21.cjs');
require('../../utils/json-fetch.cjs');
require('../../vc/schema.cjs');
require('../../vc/constants.cjs');
require('../../vc/revocation.cjs');
require('../../utils/ident/ensure-ident.cjs');
require('../../utils/ident/matchers.cjs');
require('../../vc/crypto/EcdsaSecp256k1Signature2019.cjs');
require('../../vc/crypto/EcdsaSecp256k1VerificationKey2019.cjs');
require('../../vc/crypto/Ed25519Signature2018.cjs');
require('../../vc/crypto/Ed25519VerificationKey2018.cjs');
require('../../vc/crypto/Ed25519Signature2020.cjs');
require('../../vc/crypto/Ed25519VerificationKey2020.cjs');
require('../../vc/crypto/JsonWebSignature2020.cjs');
require('../../types/status-list-credential/id.cjs');
require('../../types/accumulator/variants.cjs');
require('../abstract/status-list-credential/module.cjs');
require('../abstract/common/abstract-api-provider.cjs');
require('../abstract/common/abstract-base-module.cjs');
require('../../resolver/generic/resolver.cjs');
require('../../resolver/generic/const.cjs');
require('@docknetwork/vc-delegation-engine');

// eslint-disable-next-line jest/no-export
function generateStatusListCredentialModuleTests(
  { did: didModule, statusListCredential: statusListCredentialModule },
  { Did, StatusListCredentialId },
  filter = () => true,
) {
  const test = modules_tests_common.testIf(filter);

  describe(`Using ${didModule.constructor.name} and ${statusListCredentialModule.constructor.name} with ${Did.name}`, () => {
    test('Generates a `DIDDocument` and creates a `StatusListCredential` owned by this DID', async () => {
      const did = Did.random();

      const keyPair = keypairs_keypairEd25519.random();
      const didKeypair = new keypairs_didKeypair([did, 1], keyPair);
      const keyDoc = vc_helpers.getKeyDoc(did, didKeypair);

      const document = types_did_document_index.DIDDocument.create(did, [didKeypair.didKey()]);

      await didModule.createDocument(document, didKeypair);

      const id1 = StatusListCredentialId.random(did);
      const statusListCredential1 = await vc_statusList2021Credential.create(
        keyDoc,
        id1,
        { revokeIndices: [1, 10, 100] },
      );

      await statusListCredentialModule.createStatusListCredential(
        id1,
        statusListCredential1,
        didKeypair,
      );

      const written1 = await statusListCredentialModule.getStatusListCredential(
        id1,
      );
      expect(written1.toJSON()).toEqual(statusListCredential1.toJSON());

      const id2 = StatusListCredentialId.random(did);
      const statusListCredential2 = await vc_statusList2021Credential.create(
        keyDoc,
        id2,
        { revokeIndices: [2, 20, 200] },
      );

      await statusListCredentialModule.createStatusListCredential(
        id2,
        statusListCredential2,
        didKeypair,
      );

      const written2 = await statusListCredentialModule.getStatusListCredential(
        id2,
      );
      expect(written2.toJSON()).toEqual(statusListCredential2.toJSON());
    });

    test('Generates a `DIDDocument` and creates and then updates a `StatusListCredential` owned by this DID', async () => {
      const did = Did.random();

      const keyPair = keypairs_keypairEd25519.random();
      const didKeypair = new keypairs_didKeypair([did, 1], keyPair);
      const keyDoc = vc_helpers.getKeyDoc(did, didKeypair);

      const document = types_did_document_index.DIDDocument.create(did, [didKeypair.didKey()]);

      await didModule.createDocument(document, didKeypair);

      const id = StatusListCredentialId.random(did);
      const statusListCredential = await vc_statusList2021Credential.create(
        keyDoc,
        id,
        { revokeIndices: [1, 10, 100] },
      );

      await statusListCredentialModule.createStatusListCredential(
        id,
        statusListCredential,
        didKeypair,
      );
      let written = await statusListCredentialModule.getStatusListCredential(
        id,
      );
      expect(written.toJSON()).toEqual(statusListCredential.toJSON());

      await statusListCredential.update(keyDoc, { revokeIndices: [2, 3, 4] });

      await statusListCredentialModule.updateStatusListCredential(
        id,
        statusListCredential,
        didKeypair,
      );
      written = await statusListCredentialModule.getStatusListCredential(id);
      expect(written.toJSON()).toEqual(statusListCredential.toJSON());
    });

    test('Generates a `DIDDocument` and creates and then removes a `StatusListCredential` owned by this DID', async () => {
      const did = Did.random();

      const keyPair = keypairs_keypairEd25519.random();
      const didKeypair = new keypairs_didKeypair([did, 1], keyPair);
      const keyDoc = vc_helpers.getKeyDoc(did, didKeypair);

      const document = types_did_document_index.DIDDocument.create(did, [didKeypair.didKey()]);

      await didModule.createDocument(document, didKeypair);

      const id = StatusListCredentialId.random(did);
      const statusListCredential = await vc_statusList2021Credential.create(
        keyDoc,
        id,
        { revokeIndices: [1, 10, 100] },
      );

      await statusListCredentialModule.createStatusListCredential(
        id,
        statusListCredential,
        didKeypair,
      );
      let written = await statusListCredentialModule.getStatusListCredential(
        id,
      );
      expect(written.toJSON()).toEqual(statusListCredential.toJSON());

      await statusListCredentialModule.removeStatusListCredential(
        id,
        didKeypair,
      );
      written = await statusListCredentialModule.getStatusListCredential(id);
      expect(written).toEqual(null);
    });

    test('`StatusList2021Resolver`', async () => {
      const resolver = new resolver_statusList2021_statusList2021Resolver(statusListCredentialModule);
      const did = Did.random();

      const keyPair = keypairs_keypairEd25519.random();
      const didKeypair = new keypairs_didKeypair([did, 1], keyPair);
      const keyDoc = vc_helpers.getKeyDoc(did, didKeypair);

      const document = types_did_document_index.DIDDocument.create(did, [didKeypair.didKey()]);

      await didModule.createDocument(document, didKeypair);

      const id = StatusListCredentialId.random(did);
      const statusListCredential = await vc_statusList2021Credential.create(
        keyDoc,
        id,
        { revokeIndices: [1, 10, 100] },
      );

      await statusListCredentialModule.createStatusListCredential(
        id,
        statusListCredential,
        didKeypair,
      );
      expect(await resolver.resolve(String(id))).toEqual(
        statusListCredential.toJSON(),
      );
    });
  });
}

module.exports = generateStatusListCredentialModuleTests;
//# sourceMappingURL=status-list-credential-module.cjs.map
