web5-rust 2.0.0-beta1

A rust crate for interacting with Web5
Documentation
b0VIM 8.2FNfz)�Z]*orangeparksr-ThinkPad-T14-Gen-2i~orange/web5-rust/src/dids/bearer-did.rsutf-8
U3210#"! Utp/KmO�ad:	/�����]W	�{�
�
�
�
�

~
x

���3���mgVT=*�
�
�
�
�
n
i

�	C	%	 		�������y_D)��2,+��`ZY>#7����/,�t���E
�����nT: �����    * @remarks   *   * @remar   * @remarks   * @remarks      * @remarks   *     * @remarks   *   * `P   * @remarks   *   * `P   * @remarks   *   * `P   * @remarks   *   * `Po   * @remarks   *   * `Por   * @remarks   *   * `Po    * @remarks   *    * @remarks   *   * `PortableDid` structure.   * ex   * @remarks   *   * `PortableDid` structure.   * ex   * @remarks   *   * `PortableDid` structure.   * extracts both publi    * @remarks   *   * `PortableDid` structure.   * ext   * @remarks   *   * `PortableDid` structure.   * extracts both publi   *   * @remarks   *   * `PortableDid` structure.   * extracts both public and private keys fro   * @remarks   *   * `PortableDid` structure.   * extracts both public and private keys from the   * @remarks   *   * `PortableDid` structure.   * extracts both public and priva      * @remarks   *   * `PortableDid` structure.   * extracts both public an   * @remarks   *   * `PortableDid` structure.    *   *   * @remarks   *   * `PortableDid` structure.   * extracts both public and private keys from th   * @rema   * @remarks   *   *       * @remarks   *   * `Po    * @   * @remarks   *   * `PortableDid` structure.   *    * @remarks   *   * `PortableDid` structure.   * extracts both public and private keys from the DID's k   * @    * @remarks   *   * `PortableDi    * @   * @remarks   *   * `PortableDid` structure.   * extracts both public an   *    * @remarks   *   * `PortableDid` structure.   * extracts both public and private k   * @   * @remarks   *   * `PortableDid` structure.   *    * @remarks      * @remarks   *   * `Po   * @remarks   *   * `Po   * @remarks   *   * `P   * @r   * @remarks   *    * @remarks   *   * `Porta   * @remarks   *   * `Porta   * @remarks   *   * `PortableD          * @remarks   *   * `   * @remarks   *   * `PortableDid` structure.   * extracts both public and private keys from the DID's key manager and organizes them into a   * a DID in format that can be used independently of the specific DID method implementation. It   * This method is useful when you need to represent the key material and metadata associated with   *   * associated with the DID.   * Converts a `BearerDid` object to a portable format containing the URI and verification methods  /**  metadata: DidMetadata;  document: DidDocument;  did_uri: string;pub struct BearerDid {}  keyId: string;   */   * "did:dht:123#key-1" // A fragment identifier referring to a key in the DID document   * @example   *   * determine the DID and key that will be used for signing and verification operations.   * a specific verification method in the DID document. It allows users of a `BearerDidSigner` to   * This identifier must be a DID URI with a fragment (e.g., did:method:123#key-0) that references   *   * verification operations.   * The unique identifier of the key within the DID document that is used for signing and  /**  algorithm: string;   */   * "ES256" // ECDSA using P-256 and SHA-256   * @example   *   * {@link https://www.iana.org/assignments/jose/jose.xhtml#web-signature-encryption-algorithms | IANA JSON Web Signature and Encryption Algorithms registry}.   * registered algorithm names are defined in the   * Typically, this value is used to populate the `alg` field of a JWT or JWS header. The   *   * The cryptographic algorithm identifier used for signing operations.  /**//pub trait BearerDidSigner extends Signer {use super::portable_did::{DidMetadata, PortableDid};use super::did_core::DidDocument;use crate::crypto::jwk::JWK;ad�
���6.-���C�
�
�
^
7
&




	


}  }    return did;    });      keyManager      metadata : portableDid.metadata,      document : portableDid.document,      uri      : portableDid.uri,    const did = new BearerDid({    // Use the given PortableDid to construct the BearerDid object.    }      await keyManager.getPublicKey({ keyUri });      // Verify that the key is present in the key manager. If not, an error is thrown.      const keyUri = await keyManager.getKeyUri({ key: vm.publicKeyJwk });      // Compute the key URI of the verification method's public key.      }        throw new Error(`Verification method '${vm.id}' does not contain a public key in JWK format`);      if (!vm.publicKeyJwk) {    for (let vm of verificationMethods) {    // in the key manager.adKK�8�|w�
Z
�����{
�x�
�
�
O
�	�	�	�	=		�����Q���v
�hg-���yqD>=%! ��W50���%���9��K    const verificationMethod = this.document.verificationMethod?.find(    // find the first verification method intended for signing claims.    // Attempt to find a verification method that matches the given method ID, or if not given,  public async getSigner(params?: { methodId: string }): Promise<BearerDidSigner> {   */   * @returns An instantiated {@link Signer} that can be used to sign and verify data.   *                          verify operations. Optional.   * @param params.methodId - ID of the verification method key that will be used for sign and   * @param params - The parameters for the `getSigner` operation.   *   * If `methodID` is not given, the first verification method intended for signing claims is used.   *   * present in the DID Document.   * If given, the `methodId` parameter is used to select a key from the verification methods   *   * Return a {@link Signer} that can be used to sign messages, credentials, or arbitrary data.  /**  }    return portableDid;    }      portableDid.privateKeys = privateKeys;      }        privateKeys.push({ ...privateKey });        // Add the verification method to the key set.        const privateKey = await this.keyManager.exportKey({ keyUri }) as Jwk;        // Retrieve the private key from the key manager.        const keyUri = await this.keyManager.getKeyUri({ key: vm.publicKeyJwk });        // Compute the key URI of the verification method's public key.        }          throw new Error(`Verification method '${vm.id}' does not contain a public key in JWK format`);        if (!vm.publicKeyJwk) {      for (let vm of this.document.verificationMethod) {      const privateKeys: Jwk[] = [];    if ('exportKey' in this.keyManager && typeof this.keyManager.exportKey === 'function') {    // If the BearerDid's key manager supports exporting private keys, add them to the portable DID.    };      metadata : this.metadata      document : this.document,      uri      : this.uri,    let portableDid: PortableDid = {    // Create a new `PortableDid` object to store the exported data.    }      throw new Error(`DID document for '${this.uri}' is missing verification methods`);    if (!(Array.isArray(this.document.verificationMethod) && this.document.verificationMethod.length > 0)) {    // Verify the DID document contains at least one verification method.  public async export(): Promise<PortableDid> {   */   *         any verification method are missing in the key manager.   * @throws An error if the DID document does not contain any verification methods or the keys for   *          keys associated with the `BearerDid`.   * @returns A `PortableDid` containing the URI, DID document, metadata, and optionally private   *   * ```   * // portableDid now contains the DID URI, document, metadata, and optionally, private keys.   * const portableDid = await did.export();   * // Assuming `did` is an instance of BearerDid   * ```ts   * @example   *   * purpose(s) for which the key can be used (e.g., `authentication`, `assertionMethod`, etc.).   * verification methods as the DID document, each with its associated private key and the   * include a `privateKeys` property which contains the same number of entries as there are   * If the DID's key manager does support exporting private keys, the resulting `PortableDid` will   *   * include hardware security modules (HSMs) and cloud-based KMS services like AWS KMS.   * use the same underlying KMS even if the KMS does not support exporting private keys. Examples   * will not contain a `privateKeys` property. This enables the importing and exporting DIDs that   * If the DID's key manager does not allow private keys to be exported, the `PortableDid` returnedadZOunm)���X�
�
�
n
(
'
����POB%���2�
+




�	�	�	�	C				���P
��$�~X��r$�aC(�lk�rlk$����Z    // Validate that the key material for every verification method in the DID document is present    }      await keyManager.importKey({ key });    for (let key of portableDid.privateKeys ?? []) {    // If given, import the private key material into the key manager.    }      throw new DidError(DidErrorCode.InvalidDidDocument, `At least one verification method is required but 0 were given`);    if (verificationMethods.length === 0) {    // Validate that the DID document contains at least one verification method.    const verificationMethods = getVerificationMethods({ didDocument: portableDid.document });    // Get all verification methods from the given DID document, including embedded methods.  }): Promise<BearerDid> {    portableDid: PortableDid;    keyManager?: CryptoApi & KeyImporterExporter<KmsImportKeyParams, KeyIdentifier, KmsExportKeyParams>;  public static async import({ portableDid, keyManager = new LocalKeyManager() }: {   */   *         keys for any verification method are missing in the key manager.   * @throws An error if the PortableDid document does not contain any verification methods or the   *          provided PortableDid.   * @returns A Promise resolving to a `BearerDid` object representing the DID formed from the   *                            used.   *                            {@link LocalKeyManager} instance will be created and   *                            generate keys and sign data. If not given, a new   * @param params.keyManager - Optionally specify an external Key Management System (KMS) used to   * @param params.portableDid - The PortableDid object to import.   * @param params - The parameters for the import operation.   *   * ```   * const did = await BearerDid.import({ portableDid });   * // Reconstruct a BearerDid object from the PortableDid.   * const portableDid = await did.export();   * // Export an existing BearerDid to PortableDid format.   * ```ts   * @example   *   * key material, DID document, and metadata.   * This method allows for the creation of a `BearerDid` object using a previously created DID's   *   * Instantiates a {@link BearerDid} object from a given {@link PortableDid}.  /**  }    };      }        return isValid;        const isValid = await keyManager.verify({ data, key: publicKey!, signature }); // `publicKey` is guaranteed to be defined at this point.      async verify({ data, signature }: EnclosedVerifyParams): Promise<boolean> {      },        return signature;        const signature = await keyManager.sign({ data, keyUri: keyUri! }); // `keyUri` is guaranteed to be defined at this point.      async sign({ data }: EnclosedSignParams): Promise<Uint8Array> {      keyId     : verificationMethod.id,      algorithm : algorithm,    return {    const algorithm = cryptoUtils.getJoseSignatureAlgorithmFromPublicKey(publicKey);    // Determine the signing algorithm.    const keyManager = this.keyManager;    // Bind the DID's key manager to the signer.    const publicKey = await this.keyManager.getPublicKey({ keyUri });    // present in the key manager's store.    // Get the public key to be used for verify operations, which also verifies that the key is    const keyUri = await this.keyManager.getKeyUri({ key: verificationMethod.publicKeyJwk });    // Compute the expected key URI of the signing key.    }      throw new DidError(DidErrorCode.InternalError, 'A verification method intended for signing could not be determined from the DID Document');    if (!(verificationMethod && verificationMethod.publicKeyJwk)) {    );      vm => extractDidFragment(vm.id) === (extractDidFragment(params?.methodId) ?? extractDidFragment(this.document.assertionMethod?.[0]))