The DidDhtUtils class provides utility functions to support operations in the DID DHT method. This includes functions for creating and parsing BEP44 messages, handling identity keys, and converting between different formats and representations.

Constructors

Methods

  • Splits a string into chunks of length 255 if the string exceeds length 255.

    Parameters

    • data: string

      The string to split into chunks.

    Returns string | string[]

    The original string if its length is less than or equal to 255, otherwise an array of chunked strings.

  • Creates a BEP44 put message, which is used to publish a DID document to the DHT network.

    Parameters

    • params: {
          dnsPacket: Packet;
          publicKeyBytes: Uint8Array;
          signer: Signer<EnclosedSignParams, EnclosedVerifyParams>;
      }

      The parameters to use when creating the BEP44 put message

      • dnsPacket: Packet

        The DNS packet to encode in the BEP44 message.

      • publicKeyBytes: Uint8Array

        The public key bytes of the Identity Key.

      • signer: Signer<EnclosedSignParams, EnclosedVerifyParams>

        Signer that can sign and verify data using the Identity Key.

    Returns Promise<Bep44Message>

    A promise that resolves to a BEP44 put message.

  • Converts a DID URI to a JSON Web Key (JWK) representing the Identity Key.

    Parameters

    • params: {
          didUri: string;
      }

      The parameters to use for the conversion.

      • didUri: string

        The DID URI containing the Identity Key.

    Returns Promise<Jwk>

    A promise that resolves to a JWK representing the Identity Key.

  • Converts a DID URI to the byte array representation of the Identity Key.

    Parameters

    • params: {
          didUri: string;
      }

      The parameters to use for the conversion.

      • didUri: string

        The DID URI containing the Identity Key.

    Returns Uint8Array

    A byte array representation of the Identity Key.

  • Encodes a DID DHT Identity Key into a DID identifier.

    This method first z-base-32 encodes the Identity Key. The resulting string is prefixed with did:dht: to form the DID identifier.

    Parameters

    • params: {
          identityKey: Jwk;
      }

      The parameters to use for the conversion.

      • identityKey: Jwk

        The Identity Key from which the DID identifier is computed.

    Returns Promise<string>

    A promise that resolves to a string containing the DID identifier.

  • Returns the appropriate key converter for the specified cryptographic curve.

    Parameters

    • curve: string

      The cryptographic curve to use for the key conversion.

    Returns AsymmetricKeyConverter

    An AsymmetricKeyConverter for the specified curve.

  • Parses and verifies a BEP44 Get message, converting it to a DNS packet.

    Parameters

    • params: {
          bep44Message: Bep44Message;
      }

      The parameters to use when verifying and parsing the BEP44 Get response message.

      • bep44Message: Bep44Message

        The BEP44 message to verify and parse.

    Returns Promise<Packet>

    A promise that resolves to a DNS packet.

  • Decodes and parses the data value of a DNS TXT record into a key-value object.

    Parameters

    • txtData: TxtData

      The data value of a DNS TXT record.

    Returns Record<string, string>

    An object containing the key/value pairs of the TXT record data.

  • Decodes and parses the data value of a DNS TXT record into a string.

    Parameters

    • txtData: TxtData

      The data value of a DNS TXT record.

    Returns string

    A string representation of the TXT record data.

  • Validates the proof of previous DID given.

    Parameters

    • params: {
          newDid: string;
          previousDidProof: PreviousDidProof;
      }

      The parameters to validate the previous DID proof.

      • newDid: string

        The new DID that the previous DID is linking to.

      • previousDidProof: PreviousDidProof

        The proof of the previous DID, containing the previous DID and signature signed by the previous DID.

    Returns Promise<void>