'use strict';

var base64url = require('base64url');
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('../../resolver/did/did-key-resolver.cjs');
require('../../resolver/did/did-jwk-resolver.cjs');
var resolver_did_didResolver = require('../../resolver/did/did-resolver.cjs');
require('../../utils/types/array.cjs');
var utils_types_bytes = require('../../utils/types/bytes.cjs');
require('bs58');
require('multiformats/bases/base58');
require('varint');
require('../../utils/encoding/ss-58.cjs');
var modules_abstract_did_errors = require('../abstract/did/errors.cjs');
require('../abstract/blob/module.cjs');
require('../abstract/status-list-credential/module.cjs');
require('../abstract/index.cjs');
require('../multi-api/accumulator.cjs');
require('../multi-api/attest.cjs');
require('../multi-api/blob.cjs');
require('../multi-api/did.cjs');
require('../multi-api/offchain-signatures.cjs');
require('../multi-api/status-list-credential.cjs');
require('../multi-api/trust-registry.cjs');
require('../../types/blob/index.cjs');
require('../../types/attest/index.cjs');
require('../../types/did/index.cjs');
require('../../types/generic/typed-enum.cjs');
var types_generic_typedBytes = 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('../../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 types_did_document_verificationMethodRef = require('../../types/did/document/verification-method-ref.cjs');
var types_did_onchain_typedDid_index = require('../../types/did/onchain/typed-did/index.cjs');
var modules_tests_common = require('./common.cjs');
var types_did_onchain_didKey = require('../../types/did/onchain/did-key.cjs');
var types_did_document_index = require('../../types/did/document/index.cjs');
var types_did_document_serviceEndpoint = require('../../types/did/document/service-endpoint.cjs');
var types_offchainSignatures_publicKeys_value = require('../../types/offchain-signatures/public-keys/value.cjs');
require('../../utils/inheritance.cjs');
require('../../utils/types/object.cjs');
require('../../utils/types/iterable.cjs');
require('../../utils/types/set.cjs');
require('crypto');
require('../../utils/interfaces.cjs');
require('../../utils/assert.cjs');
require('../../utils/error.cjs');
require('../../utils/types/string.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/document/verification-method-ref-or-ident-ref.cjs');
require('../../types/did/document/ident-ref.cjs');
require('../../types/generic/with-qualifier.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/generic/utils.cjs');
require('../../types/generic/typed-bytes-array.cjs');
require('../../types/did/onchain/typed-did/cheqd-did.cjs');
require('../../types/offchain-signatures/params/value.cjs');
require('../../types/generic/option.cjs');
require('../../types/offchain-signatures/params/id.cjs');
require('../../types/generic/with-from-dock-id.cjs');
require('../../types/generic/with-prop.cjs');
require('../../types/generic/with-props.cjs');
require('../../vc/crypto/Bls12381BBDT16KeyPairDock2024.cjs');
require('@docknetwork/crypto-wasm-ts');
require('../../vc/crypto/common/DockCryptoKeyPair.cjs');
require('../../vc/crypto/Bls12381BBDT16MACDock2024.cjs');
require('@docknetwork/crypto-wasm-ts/lib/index.js');
require('../../vc/crypto/common/DockCryptoSignature.cjs');
require('jsonld-signatures');
require('json-stringify-deterministic');
require('semver/preload.js');
require('../../vc/crypto/common/CustomLinkedDataSignature.cjs');
require('jsonld');
require('../../vc/jws.cjs');
require('../../vc/crypto/Bls12381BBDT16MACProofDock2024.cjs');
require('../../vc/crypto/common/DockCryptoSignatureProof.cjs');
require('../../vc/crypto/Bls12381BBSKeyPairDock2023.cjs');
require('../../vc/crypto/Bls12381BBSSignatureDock2022.cjs');
require('../../vc/crypto/Bls12381G2KeyPairDock2022.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/Bls12381PSKeyPairDock2023.cjs');
require('../../vc/crypto/Bls12381PSSignatureDock2023.cjs');
require('../../vc/crypto/Bls12381PSSignatureProofDock2023.cjs');
require('@juanelas/base64');
require('@transmute/json-web-signature');
require('../../types/offchain-signatures/public-keys/ref.cjs');
require('../../types/offchain-signatures/public-keys/id.cjs');
require('../../types/did/onchain/verification-relationship.cjs');
require('key-did-resolver');
require('../../resolver/generic/resolver.cjs');
require('../../resolver/generic/const.cjs');
require('../../utils/encoding/base-58.cjs');
require('../../utils/ident/parsers.cjs');
require('../../utils/ident/matchers.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/verification-method.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('@sphereon/ssi-sdk-ext.did-resolver-jwk');
require('../abstract/did/module.cjs');
require('../abstract/common/abstract-api-provider.cjs');
require('../abstract/common/abstract-base-module.cjs');
require('../abstract/accumulator/module.cjs');
require('../abstract/common/with-abstract-params.cjs');
require('../abstract/common/with-abstract-public-keys.cjs');
require('../../types/blob/id.cjs');
require('../../types/blob/const.cjs');
require('../../utils/mappings/dock-did-by-id.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('../../vc/status-list2021-credential.cjs');
require('@digitalcredentials/vc-status-list');
require('pako');
require('../../vc/verifiable-credential.cjs');
require('../../vc/helpers.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/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('../../vc/credentials.cjs');
require('../../vc/CredentialIssuancePurpose.cjs');
require('../../vc/schema.cjs');
require('jsonschema');
require('../../vc/constants.cjs');
require('../../vc/revocation.cjs');
require('blakejs');
require('../../utils/ident/ensure-ident.cjs');
require('../../types/status-list-credential/id.cjs');
require('../../types/accumulator/variants.cjs');
require('../abstract/anchor/module.cjs');
require('mrklt');
require('../abstract/attest/module.cjs');
require('../abstract/offchain-signatures/module.cjs');
require('../abstract/trust-registry/module.cjs');
require('../abstract/schema/module.cjs');
require('json-canonicalize');
require('../../vc/schemas/schema-draft-07.cjs');
require('../multi-api/common.cjs');
require('../../types/trust-registry/index.cjs');
require('../../types/trust-registry/schema.cjs');
require('../../types/trust-registry/issuer.cjs');
require('../../types/trust-registry/verifier.cjs');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var base64url__default = /*#__PURE__*/_interopDefault(base64url);

// eslint-disable-next-line jest/no-export
function generateDIDModuleTests(
  { did: module },
  { Did, ParamsId },
  filter = () => true,
) {
  const test = modules_tests_common.testIf(filter);

  describe(`Using ${module.constructor.name} with ${Did.name}`, () => {
    test('Creates basic `DIDDocument` with keys', async () => {
      const did = Did.random();

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

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

      await module.createDocument(document, didKeypair);

      expect((await module.getDocument(did)).eq(document)).toBe(true);
    });

    test('Creates and resolves `DIDDocument` with `JsonWebKey2020` controller key', async () => {
      const did = Did.random();

      const keyPair = keypairs_keypairEd25519.random();
      const didKeypair = new keypairs_didKeypair([did, 1], keyPair);
      const keyId = `${did}#keys-1`;
      const publicKeyJwk = {
        crv: 'Ed25519',
        kty: 'OKP',
        x: base64url__default.default.encode(Buffer.from(utils_types_bytes.valueBytes(keyPair.publicKey()))),
      };

      const document = types_did_document_index.DIDDocument.from({
        '@context': [
          'https://www.w3.org/ns/did/v1',
          'https://w3id.org/security/suites/jws-2020/v1',
        ],
        id: String(did),
        controller: [String(did)],
        verificationMethod: [
          {
            id: keyId,
            type: 'JsonWebKey2020',
            controller: String(did),
            publicKeyJwk,
          },
        ],
        authentication: [keyId],
        assertionMethod: [keyId],
        keyAgreement: [],
        capabilityInvocation: [keyId],
        capabilityDelegation: [],
        service: [],
      });

      await module.createDocument(document, didKeypair);
      const storedDocument = await module.getDocument(did);
      const storedJSON = storedDocument.toJSON();
      const possibleDidIds = new Set(types_did_onchain_typedDid_index.possibleDids(did));
      const possibleMethodIds = new Set(types_did_document_verificationMethodRef.possibleVerificationMethodRefs(keyId));
      const storedMethod = storedJSON.verificationMethod.find(
        (method) => possibleMethodIds.has(method.id),
      );

      expect(possibleDidIds.has(storedJSON.id)).toBe(true);
      expect(storedMethod).toMatchObject({
        type: 'JsonWebKey2020',
      });
      expect(possibleDidIds.has(storedMethod.controller)).toBe(true);
      expect(storedMethod.publicKeyJwk).toEqual(publicKeyJwk);
      expect(storedJSON.authentication.some((methodId) => possibleMethodIds.has(methodId))).toBe(true);
      expect(storedJSON.assertionMethod.some((methodId) => possibleMethodIds.has(methodId))).toBe(true);

      const resolver = new resolver_did_didResolver(module);
      expect(
        types_did_document_index.DIDDocument.from(await resolver.resolve(String(did))).eq(storedDocument),
      ).toBe(true);
    });

    test('Creates `DIDDocument` containing BBS/BBSPlus/PS keys', async () => {
      const did = Did.random();

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

      const paramsRef = [did, ParamsId.random()];

      const bbsKey = new types_offchainSignatures_publicKeys_value.BBSPublicKeyValue(types_generic_typedBytes.random(100), paramsRef);
      const bbsPlusKey = new types_offchainSignatures_publicKeys_value.BBSPlusPublicKeyValue(
        types_generic_typedBytes.random(100),
        paramsRef,
      );
      const psKey = new types_offchainSignatures_publicKeys_value.PSPublicKeyValue(types_generic_typedBytes.random(1000), paramsRef);

      const document = types_did_document_index.DIDDocument.create(did, [
        didKeypair.didKey(),
        new types_did_onchain_didKey.DidKey(bbsKey),
        new types_did_onchain_didKey.DidKey(bbsPlusKey),
        new types_did_onchain_didKey.DidKey(psKey),
      ]);

      await module.createDocument(document, didKeypair);

      expect((await module.getDocument(did)).eq(document)).toBe(true);
    });

    test('Updates `DIDDocument` containing BBS/BBSPlus/PS keys', async () => {
      const did = Did.random();

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

      const bbsKey = new types_did_onchain_didKey.DidKey(new types_offchainSignatures_publicKeys_value.BBSPublicKeyValue(types_generic_typedBytes.random(100)));
      const bbsPlusKey = new types_did_onchain_didKey.DidKey(
        new types_offchainSignatures_publicKeys_value.BBSPlusPublicKeyValue(types_generic_typedBytes.random(100)),
      );
      const psKey = new types_did_onchain_didKey.DidKey(new types_offchainSignatures_publicKeys_value.PSPublicKeyValue(types_generic_typedBytes.random(1000)));

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

      await module.createDocument(document, didKeypair);

      expect((await module.getDocument(did)).eq(document)).toBe(true);

      document.addKey([did, document.nextKeyIndex()], bbsKey);
      document.addKey([did, document.nextKeyIndex()], bbsPlusKey);
      document.addKey([did, document.nextKeyIndex()], psKey);

      await module.updateDocument(document, didKeypair);

      expect((await module.getDocument(did)).eq(document)).toBe(true);

      expect(document.didKeys().toJSON()).toEqual([
        [
          didKeypair.verificationMethodId.toJSON(),
          didKeypair.didKey().toJSON(),
        ],
        [new types_did_document_verificationMethodRef.VerificationMethodRef(did, 2).toJSON(), bbsKey.toJSON()],
        [new types_did_document_verificationMethodRef.VerificationMethodRef(did, 3).toJSON(), bbsPlusKey.toJSON()],
        [new types_did_document_verificationMethodRef.VerificationMethodRef(did, 4).toJSON(), psKey.toJSON()],
      ]);
    });

    test('Creates `DIDDocument` containing services', async () => {
      const did = Did.random();

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

      const service1 = types_did_document_serviceEndpoint.createServiceEndpoint('LinkedDomains', [
        'ServiceEndpoint',
      ]);
      const service2 = types_did_document_serviceEndpoint.createServiceEndpoint('DIDCommMessaging', [
        {
          uri: 'https://example.com/path1',
        },
      ]);

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

      await module.createDocument(document, didKeypair);

      expect((await module.getDocument(did)).eq(document)).toBe(true);
    });

    test('Creates `DIDDocument` containing DIDComm services with full structure', async () => {
      const did = Did.random();

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

      // Test DIDComm service with full object structure
      const expectedServiceData = {
        uri: 'https://example.com/path3',
        accept: [
          'didcomm/v2',
          'didcomm/aip2;env=rfc587',
        ],
        routingKeys: ['did:example:somemediator#somekey'],
        recipientKeys: ['did:example:somerecipient#somekey'],
        priority: 0,
      };

      const didCommService = types_did_document_serviceEndpoint.createServiceEndpoint('DIDCommMessaging', [expectedServiceData]);
      const document = types_did_document_index.DIDDocument.create(did, [didKeypair.didKey()], [], {
        didcomm: didCommService,
      });

      const createTx = (await module.createDocumentTx(document, didKeypair)).toJSON();

      expect(JSON.parse(JSON.stringify(createTx.value.payload.service[0]))).toMatchObject({
        id: expect.anything(),
        serviceType: 'DIDCommMessaging',
        serviceEndpoint: [
          expectedServiceData.uri,
        ],
        recipientKeys: expectedServiceData.recipientKeys,
        routingKeys: expectedServiceData.routingKeys,
        accept: expectedServiceData.accept,
        priority: expectedServiceData.priority,
      });

      await module.createDocument(document, didKeypair);

      // Verify the DIDComm service data structure is preserved
      const retrievedDocument = await module.getDocument(did);
      const retrievedJSON = retrievedDocument.toJSON();

      // Verify the document equality
      expect((await module.getDocument(did)).eq(document)).toBe(true);

      // Find the DIDComm service in the retrieved document
      const didCommServiceInRetrieved = retrievedJSON.service.find((service) => service.type === 'DIDCommMessaging');

      expect(didCommServiceInRetrieved).toBeDefined();
      expect(didCommServiceInRetrieved.serviceEndpoint).toHaveLength(1);

      const retrievedServiceEndpoint = didCommServiceInRetrieved.serviceEndpoint[0];

      // Verify each field individually
      expect(retrievedServiceEndpoint.uri).toBe(expectedServiceData.uri);
      expect(retrievedServiceEndpoint.accept).toEqual(expectedServiceData.accept);
      expect(retrievedServiceEndpoint.routingKeys).toEqual(expectedServiceData.routingKeys);
      expect(retrievedServiceEndpoint.recipientKeys).toEqual(expectedServiceData.recipientKeys);
      expect(retrievedServiceEndpoint.priority).toEqual(expectedServiceData.priority);

      // Also verify the entire object matches
      expect(retrievedServiceEndpoint).toEqual(expectedServiceData);
    });

    test('Serialize and deserialize `DIDDocument` gives same result', async () => {
      const did = Did.random();

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

      const service1 = types_did_document_serviceEndpoint.createServiceEndpoint('LinkedDomains', [
        'ServiceEndpoint',
      ]);
      const service2 = types_did_document_serviceEndpoint.createServiceEndpoint('DIDCommMessaging', [
        {
          uri: 'https://example.com/path',
          accept: [],
          routingKeys: [],
        },
      ]);

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

      const documentJSON = document.toJSON();

      const restoredDocument = types_did_document_index.DIDDocument.from(documentJSON);
      const restoredJSON = restoredDocument.toJSON();

      expect(restoredJSON).toMatchObject(documentJSON);
      expect(restoredDocument.eq(document)).toBe(true);
    });

    test('Updates `DIDDocument` containing services', async () => {
      const did = Did.random();

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

      const service1 = types_did_document_serviceEndpoint.createServiceEndpoint('LinkedDomains', [
        'ServiceEndpoint',
      ]);
      const service2 = types_did_document_serviceEndpoint.createServiceEndpoint('DIDCommMessaging', [
        {
          uri: 'https://example.com/path',
          accept: [],
          routingKeys: [],
        },
      ]);

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

      await module.createDocument(document, didKeypair);

      expect((await module.getDocument(did)).eq(document)).toBe(true);

      document.addServiceEndpoint([did, 'service1'], service1);
      document.addServiceEndpoint([did, 'service2'], service2);

      await module.updateDocument(document, didKeypair);

      expect((await module.getDocument(did)).eq(document)).toBe(true);

      document.removeServiceEndpoint([did, 'service2']);

      await module.updateDocument(document, didKeypair);

      expect((await module.getDocument(did)).eq(document)).toBe(true);

      expect(document.service.length).toEqual(1);
    });

    test("Updates `DIDDocument`'s keys", async () => {
      const did = Did.random();

      const keyPair1 = keypairs_keypairEd25519.random();
      const keyPair2 = keypairs_keypairEd25519.random();
      const keyPair3 = keypairs_keypairEd25519.random();

      const didKeypair1 = new keypairs_didKeypair([did, 1], keyPair1);
      const didKeypair2 = new keypairs_didKeypair([did, 2], keyPair2);
      const didKeypair3 = new keypairs_didKeypair([did, 3], keyPair3);

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

      await module.createDocument(document, didKeypair2);
      expect((await module.getDocument(did)).eq(document)).toBe(true);

      document.removeKey([did, 2]);
      await module.updateDocument(document, didKeypair1);
      expect((await module.getDocument(did)).eq(document)).toBe(true);

      document.addKey([did, 3], didKeypair3.didKey());
      await expect(() => module.updateDocument(document, didKeypair2)).rejects.toThrow();

      await module.updateDocument(document, didKeypair1);
      expect((await module.getDocument(did)).eq(document)).toBe(true);
    });

    test('Removes (deactivates) `DIDDocument`', async () => {
      const did = Did.random();

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

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

      await module.createDocument(document, didKeypair);
      expect((await module.getDocument(did)).eq(document)).toBe(true);

      await module.removeDocument(did, didKeypair);
      await expect(() => module.getDocument(did)).rejects.toThrow(
        new modules_abstract_did_errors.NoDIDError(did),
      );
    });

    test("Throws an error if `DIDDocument` doesn't exist", async () => {
      const did = Did.random();

      await expect(() => module.getDocument(did)).rejects.toThrow(
        new modules_abstract_did_errors.NoDIDError(did),
      );
    });

    test('`DIDResolver`', async () => {
      const resolver = new resolver_did_didResolver(module);
      const did = Did.random();

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

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

      await module.createDocument(document, didKeypair);

      expect(
        types_did_document_index.DIDDocument.from(await resolver.resolve(String(did))).eq(document),
      ).toBe(true);
    });
  });
}

module.exports = generateDIDModuleTests;
//# sourceMappingURL=did-module.cjs.map
