Function getVerificationMethodByKey

  • Retrieves a verification method object from a DID document if there is a match for the given public key.

    This function searches the verification methods in a given DID document for a match with the provided public key (either in JWK or multibase format). If a matching verification method is found it is returned. If no match is found null is returned.

    Parameters

    • params: {
          didDocument: DidDocument;
          publicKeyJwk?: Jwk;
          publicKeyMultibase?: string;
      }

      An object containing input parameters for retrieving the verification method ID.

      • didDocument: DidDocument

        The DID document to search for the verification method.

      • Optional publicKeyJwk?: Jwk

        The public key in JSON Web Key (JWK) format to match against the verification methods in the DID document.

      • Optional publicKeyMultibase?: string

        The public key as a multibase encoded string to match against the verification methods in the DID document.

    Returns Promise<DidVerificationMethod | null>

    A promise that resolves with the matching verification method, or null if no match is found.

    Example

    const didDocument = {
    // ... contents of a DID document ...
    };
    const publicKeyJwk = { kty: 'OKP', crv: 'Ed25519', x: '...' };

    const verificationMethod = await getVerificationMethodByKey({
    didDocument,
    publicKeyJwk
    });

    Throws

    Throws an Error if the didDocument parameter is missing or if the didDocument does not contain any verification methods.