import { DockDIDQualifier } from '../constants.js';
import '../../../../utils/types/array.js';
import { isHex } from '../../../../utils/types/bytes.js';
import 'bs58';
import 'multiformats/bases/base58';
import 'varint';
import { decodeFromSS58, encodeAsSS58 } from '../../../../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 sized from '../../../generic/sized.js';
import TypedNumber from '../../../generic/typed-number.js';
import '../../../generic/typed-set.js';
import '../../../generic/typed-map.js';
import TypedStruct from '../../../generic/typed-struct.js';
import 'uuid';
import 'js-sha256';
import withQualifier from '../../../generic/with-qualifier.js';
import DidOrDidMethodKeySignature from './signature.js';
import '../../../public-keys/public-key.js';
import '../../../public-keys/public-key-sr25519-value.js';
import '../../../public-keys/public-key-ed25519-value.js';
import '../../../public-keys/public-key-secp256k1-value.js';
import '../../../public-keys/public-key-x25519-value.js';
import '../../../signatures/signature-value.js';
import { Signature } from '../../../signatures/signature.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.js';
import '../../../generic/with-from-json-bytes.js';
import '../../../generic/create-placeholder.js';
import '../../../../utils/types/number.js';
import '../../../../vc/crypto/constants.js';
import '../../../signatures/signature-ed25519-value.js';
import '../../../signatures/signature-secp256k1-value.js';
import '../../../signatures/signature-sr25519-value.js';

/**
 * `did:dock:*`
 */
class DockDidValue extends sized(withQualifier(TypedBytes)) {
  static Qualifier = DockDIDQualifier;

  static Type = 'did';

  static Size = 32;

  static fromUnqualifiedString(did) {
    return new this(isHex(did) ? did : decodeFromSS58(did));
  }

  /**
   * Returns unqualified DID encoded as a `SS58` address.
   */
  toEncodedString() {
    return encodeAsSS58(this.value);
  }

  signWith(keyPair, bytes) {
    // eslint-disable-next-line no-use-before-define
    return new DockDidSignature(
      // eslint-disable-next-line no-use-before-define
      new DockDidSignatureValue(this, keyPair.keyId, keyPair.sign(bytes)),
    );
  }
}

class DockDidSignatureValue extends TypedStruct {
  static Classes = {
    did: DockDidValue,
    keyId: class KeyId extends TypedNumber {},
    sig: Signature,
  };
}

class DockDidSignature extends DidOrDidMethodKeySignature {
  static Type = 'didSignature';

  static Class = DockDidSignatureValue;
}

export { DockDidSignature, DockDidSignatureValue, DockDidValue as default };
//# sourceMappingURL=dock-did-value.js.map
