import '../../utils/types/array.js';
import { normalizeToU8a } from '../../utils/types/bytes.js';
import 'bs58';
import 'multiformats/bases/base58';
import 'varint';
import '../../utils/encoding/ss-58.js';
import '../generic/typed-enum.js';
import TypedBytes from '../generic/typed-bytes.js';
import '../generic/typed-string.js';
import '../generic/typed-array.js';
import '../generic/typed-tuple.js';
import '../generic/typed-null.js';
import '../generic/typed-number.js';
import '../generic/typed-set.js';
import '../generic/typed-map.js';
import '../generic/typed-struct.js';
import 'uuid';
import 'js-sha256';
import withFrom from '../generic/with-from.js';
import StatusList2021Credential from '../../vc/status-list2021-credential.js';
import '../../utils/inheritance.js';
import '../../utils/types/object.js';
import '../../utils/types/iterable.js';
import '../../utils/types/set.js';
import 'crypto';
import '../../utils/interfaces.js';
import '../../utils/assert.js';
import '../../utils/error.js';
import '../../utils/types/string.js';
import 'blake2b';
import '../generic/with-base.js';
import '../generic/with-catch-null.js';
import '../generic/with-eq.js';
import '../generic/any-of.js';
import '../generic/with-from-json-bytes.js';
import '../generic/create-placeholder.js';
import '@digitalcredentials/vc-status-list';
import 'pako';
import '../../vc/verifiable-credential.js';
import '../../vc/helpers.js';
import 'jsonld';
import '@transmute/json-web-signature';
import '../../vc/document-loader.js';
import '../../vc/contexts.js';
import '../../vc/contexts/vc-examples-v1.js';
import '../../vc/contexts/security_context.js';
import '../../vc/contexts/status-list-21.js';
import '../../vc/contexts/private-status-list-21.js';
import '../../utils/json-fetch.js';
import '../../vc/crypto/Bls12381BBDT16KeyPairDock2024.js';
import '@docknetwork/crypto-wasm-ts';
import '../../vc/crypto/constants.js';
import '../../vc/crypto/common/DockCryptoKeyPair.js';
import '../../vc/crypto/Bls12381BBDT16MACDock2024.js';
import '@docknetwork/crypto-wasm-ts/lib/index.js';
import '../../vc/crypto/common/DockCryptoSignature.js';
import 'jsonld-signatures';
import 'json-stringify-deterministic';
import 'semver/preload.js';
import '../../vc/crypto/common/CustomLinkedDataSignature.js';
import 'base64url';
import '../did/document/verification-method-ref.js';
import '../generic/with-qualifier.js';
import '../generic/utils.js';
import '../generic/typed-bytes-array.js';
import '../did/onchain/typed-did/index.js';
import '../did/onchain/typed-did/did-method-key/did-method-key-public-key.js';
import '../../utils/encoding/base-58-btc.js';
import '../generic/sized.js';
import '../../utils/types/number.js';
import '../public-keys/public-key.js';
import '../public-keys/public-key-x25519-value.js';
import '../public-keys/public-key-ed25519-value.js';
import '../public-keys/public-key-secp256k1-value.js';
import '../public-keys/public-key-sr25519-value.js';
import '../did/onchain/constants.js';
import '../did/onchain/typed-did/signature.js';
import '../did/onchain/typed-did/did-method-key/did-method-key-signature.js';
import '../signatures/signature-value.js';
import '../signatures/signature-ed25519-value.js';
import '../signatures/signature-secp256k1-value.js';
import '../signatures/signature.js';
import '../signatures/signature-sr25519-value.js';
import '../did/onchain/typed-did/dock-did-value.js';
import '../generic/typed-uuid.js';
import '../did/onchain/typed-did/cheqd-did.js';
import '../../vc/jws.js';
import '../../vc/crypto/Bls12381BBDT16MACProofDock2024.js';
import '../../vc/crypto/common/DockCryptoSignatureProof.js';
import '../../vc/crypto/Bls12381BBSKeyPairDock2023.js';
import '../../vc/crypto/Bls12381BBSSignatureDock2022.js';
import '../../vc/crypto/Bls12381G2KeyPairDock2022.js';
import '../../vc/crypto/Bls12381BBSSignatureDock2023.js';
import '../../vc/crypto/Bls12381BBSSignatureProofDock2022.js';
import '../../vc/crypto/Bls12381BBSSignatureProofDock2023.js';
import '../../vc/crypto/Bls12381BDDT16KeyPairDock2024.js';
import '../../vc/crypto/Bls12381BDDT16MACDock2024.js';
import '../../vc/crypto/Bls12381BDDT16MACProofDock2024.js';
import '../../vc/crypto/Bls12381PSKeyPairDock2023.js';
import '../../vc/crypto/Bls12381PSSignatureDock2023.js';
import '../../vc/crypto/Bls12381PSSignatureProofDock2023.js';
import '../../vc/crypto/EcdsaSecp256k1Signature2019.js';
import '../../vc/crypto/EcdsaSecp256k1VerificationKey2019.js';
import '@juanelas/base64';
import '../../keypairs/keypair-secp256k1.js';
import 'elliptic';
import '../../keypairs/dock-keypair.js';
import '../../utils/encoding/multibase.js';
import '../../vc/crypto/Ed25519Signature2018.js';
import '../../vc/crypto/Ed25519VerificationKey2018.js';
import '../../keypairs/keypair-ed25519.js';
import '@stablelib/ed25519';
import '../../vc/crypto/Ed25519Signature2020.js';
import '../../vc/crypto/Ed25519VerificationKey2020.js';
import '../../vc/crypto/JsonWebSignature2020.js';
import '../../keypairs/did-keypair.js';
import '../did/onchain/did-key.js';
import '../offchain-signatures/params/index.js';
import '../offchain-signatures/params/value.js';
import '../generic/option.js';
import '../offchain-signatures/curve-type.js';
import '../offchain-signatures/params/id.js';
import '../generic/with-from-dock-id.js';
import '../offchain-signatures/public-keys/index.js';
import '../generic/with-prop.js';
import '../generic/with-props.js';
import '../offchain-signatures/public-keys/value.js';
import '../offchain-signatures/public-keys/ref.js';
import '../offchain-signatures/public-keys/id.js';
import '../did/onchain/verification-relationship.js';
import '../did/document/verification-method-ref-or-ident-ref.js';
import '../did/document/ident-ref.js';
import '../../vc/credentials.js';
import '../../vc/CredentialIssuancePurpose.js';
import '../../vc/schema.js';
import 'jsonschema';
import '../../vc/constants.js';
import '../../vc/revocation.js';
import 'blakejs';
import '../../utils/ident/ensure-ident.js';
import '../../utils/ident/matchers.js';

class DockStatusListCredentialValue extends withFrom(TypedBytes, function from(value, fromFn) {
  if (value instanceof StatusList2021Credential) {
    return new this(value);
  } else {
    return fromFn(value);
  }
}) {
  constructor(value) {
    const [bytes, list] = value instanceof StatusList2021Credential
      ? [value.toBytes(), value]
      : [
        normalizeToU8a(value),
        StatusList2021Credential.fromBytes(normalizeToU8a(value)),
      ];
    super(bytes);
    this.list = list;
  }

  /**
   * Fail if the given verifiable credential id isn't a valid `StatusList2021Credential` id.
   * @param {*} id
   */
  static verifyID(id) {
    return StatusList2021Credential.verifyID(id);
  }

  /**
   * Creates new `StatusList2021Credential` with supplied `id` and option `statusPurpose` = `revocation` by default,
   * `length` and `revokeIndices`. Note that credential with `statusPurpose` = `revocation` can't unsuspend its indices.
   * To allow unrevoking indices in the future, use `statusPurpose` = `suspension`.
   * The proof will be generated immediately using supplied `keyDoc`.
   *
   * @param {KeyDoc} keyDoc
   * @param {string} id - on-chain hex identifier for the `StatusList2021Credential`.
   * @param {object} [params={}]
   * @param {'revocation'|'suspension'} [params.statusPurpose=revocation] - `statusPurpose` of the `StatusList2021Credential`.
   * Can be either `revocation` or `suspension`.
   * @param {number} [params.length=1e4] - length of the underlying `StatusList`.
   * @param {Iterable<number>} [params.revokeIndices=[]] - iterable producing indices to be revoked or suspended initially
   * @returns {Promise<StatusList2021Credential>}
   */
  static async create(
    keyDoc,
    id,
    { statusPurpose = 'revocation', length = 1e4, revokeIndices = [] } = {},
  ) {
    return new this(
      await StatusList2021Credential.create(keyDoc, id, {
        statusPurpose,
        length,
        revokeIndices,
      }),
    );
  }

  /**
   * Revokes indices and unsuspends other indices in the underlying status list, regenerating the proof.
   * If `statusPurpose` = `revocation`, indices can't be unsuspended.
   * The status list revoked (suspended)/unsuspended indices will be set atomically and in case of an error,
   * the underlying value won't be modified.
   * Throws an error if the underlying status list can't be decoded or any of the supplied indices is out of range.
   *
   * @param {KeyDoc} keyDoc
   * @param {object} [update={}]
   * @param {Iterable<number>} update.revokeIndices - indices to be revoked or suspended
   * @param {Iterable<number>} update.unsuspendIndices - indices to be unsuspended
   * @returns {Promise<this>}
   */
  async update(keyDoc, { revokeIndices = [], unsuspendIndices = [] }) {
    await this.list.update(keyDoc, { revokeIndices, unsuspendIndices });
    this.set(this.list.toBytes());

    return this;
  }

  /**
   * Returns a `Promise` resolving to the decoded `StatusList`.
   *
   * @returns {Promise<StatusList>}
   */
  async decodedStatusList() {
    return await this.list.decodedStatusList();
  }

  /**
   * Returns `true` if given index is revoked or suspended, `false` otherwise.
   * Throws an error if the underlying status list can't be decoded or supplied index is out of range.
   *
   * @param {number} index
   * @returns {Promise<boolean>}
   */
  async revoked(index) {
    return await this.list.revoked(index);
  }

  /**
   * Accepts an iterable of indices to be checked and returns an array containing `true` in the positions
   * of revoked (suspended) indices and `false` for non-revoked (non-suspended) indices.
   * Throws an error if the underlying status list can't be decoded or any of supplied indices is out of range.
   *
   * @param {Iterable<number>} indices
   * @returns {Promise<Array<boolean>>}
   */
  async revokedBatch(indices) {
    return await this.list.revokedBatch(indices);
  }
}

export { DockStatusListCredentialValue as default };
//# sourceMappingURL=status-list-credential-value.js.map
