cmd/wallet-js-sdk/src/did/didmanager.js
/**
   * Creates Orb DID and saves it in wallet content store.
   *
   * If DID is not anchored (equivalentId ID found in DID document metadata) then saves DID resolved from equivalent ID.
   *
   * @see {@link https://trustbloc.github.io/did-method-orb|The did:orb Method}
   *
   *  @param {string} auth - authorization token for wallet operations.
   *  @param {Object} options - options for creating Orb DID.
   *  @param {Object} options.keyType=ED25519 - (optional, default ED25519) type of the key to be used for creating keys for the DID, Refer agent documentation for supported key types.
   *  @param {Object} options.keyAgreementKeyType=X25519ECDHKW - (optional, default X25519ECDHKW) type of the key to be used for creating keyAgreements for the DID, Refer agent documentation for supported key types.
   *  @param {String} options.signatureType=Ed25519VerificationKey2018 - (optional, default Ed25519VerificationKey2018) signature type to be used for DID verification methods.
   *  @param {String} options.keyAgreementType=X25519KeyAgreementKey2019 - (optional, default X25519KeyAgreementKey2019) keyAgreement VM type to be used for DID key agreement (payload encryption). For JWK type, use `JsonWebKey2020`.
   *  @param {Array<String>} options.purposes=authentication - (optional, default "authentication") purpose of the key.
   *  @param {Array<String>} options.routerKeyAgreementIDs=[] - (optional, used for DIDComm V2 only, default empty list) list of router keys IDs.
   *  @param {Array<String>} options.routerConnections=[] - (optional, used for DIDComm V2 only, default empty list) list of router connections.
   *  @param {String} options.serviceID - (optional, default no serviceID set) serviceID to which this DID should belong to.
   *  @param {String} options.serviceEndpoint - (optional, default no serviceEndpoint set) serviceEndpoint to which this DID should have its service accessible.
   *  @param {String} options.didcommServiceType - (optional, default no didcommServiceType set) didcommServiceType to which this DID belong to (didcomm v1: "did-communication", or didcomm V2: "DIDCommMessaging").
   *  @param {String} options.collection - (optional, default no collection) collection to which this DID should belong in wallet content store.
   *
   * @returns {Promise<Object>} - Promise of DID Resolution response  or an error if operation fails..
   */
Creates Orb DID and saves it in wallet content store.
If DID is not anchored (equivalentId ID found in DID document metadata) then saves DID resolved from equivalent ID.



@param {string} auth - authorization token for wallet operations.
@param {Object} options - options for creating Orb DID.
@param {Object} options.keyType=ED25519 - (optional, default ED25519) type of the key to be used for creating keys for the DID, Refer agent documentation for supported key types.
@param {Object} options.keyAgreementKeyType=X25519ECDHKW - (optional, default X25519ECDHKW) type of the key to be used for creating keyAgreements for the DID, Refer agent documentation for supported key types.
@param {String} options.signatureType=Ed25519VerificationKey2018 - (optional, default Ed25519VerificationKey2018) signature type to be used for DID verification methods.
@param {String} options.keyAgreementType=X25519KeyAgreementKey2019 - (optional, default X25519KeyAgreementKey2019) keyAgreement VM type to be used for DID key agreement (payload encryption). For JWK type, use `JsonWebKey2020`.
@param {Array} options.purposes=authentication - (optional, default "authentication") purpose of the key.
@param {Array} options.routerKeyAgreementIDs=[] - (optional, used for DIDComm V2 only, default empty list) list of router keys IDs.
@param {Array} options.routerConnections=[] - (optional, used for DIDComm V2 only, default empty list) list of router connections.
@param {String} options.serviceID - (optional, default no serviceID set) serviceID to which this DID should belong to.
@param {String} options.serviceEndpoint - (optional, default no serviceEndpoint set) serviceEndpoint to which this DID should have its service accessible.
@param {String} options.didcommServiceType - (optional, default no didcommServiceType set) didcommServiceType to which this DID belong to (didcomm v1: "did-communication", or didcomm V2: "DIDCommMessaging").
@param {String} options.collection - (optional, default no collection) collection to which this DID should belong in wallet content store.

@returns {Promise} - Promise of DID Resolution response  or an error if operation fails
Creates Orb DID and saves it in wallet content store . If DID is not anchored ( equivalentId ID found in DID document metadata ) then saves DID resolved from equivalent ID . @param { string } auth - authorization token for wallet operations . @param { Object } options - options for creating Orb DID . @param { Object } options . keyType = ED25519 - ( optional default ED25519 ) type of the key to be used for creating keys for the DID Refer agent documentation for supported key types . @param { Object } options . keyAgreementKeyType = X25519ECDHKW - ( optional default X25519ECDHKW ) type of the key to be used for creating keyAgreements for the DID Refer agent documentation for supported key types . @param { String } options . signatureType = Ed25519VerificationKey2018 - ( optional default Ed25519VerificationKey2018 ) signature type to be used for DID verification methods . @param { String } options . keyAgreementType = X25519KeyAgreementKey2019 - ( optional default X25519KeyAgreementKey2019 ) keyAgreement VM type to be used for DID key agreement ( payload encryption ) . For JWK type use ` JsonWebKey2020 ` . @param { Array } options . purposes = authentication - ( optional default " authentication " ) purpose of the key . @param { Array } options . routerKeyAgreementIDs = [] - ( optional used for DIDComm V2 only default empty list ) list of router keys IDs . @param { Array } options . routerConnections = [] - ( optional used for DIDComm V2 only default empty list ) list of router connections . @param { String } options . serviceID - ( optional default no serviceID set ) serviceID to which this DID should belong to . @param { String } options . serviceEndpoint - ( optional default no serviceEndpoint set ) serviceEndpoint to which this DID should have its service accessible . @param { String } options . didcommServiceType - ( optional default no didcommServiceType set ) didcommServiceType to which this DID belong to ( didcomm v1 : " did - communication " or didcomm V2 : " DIDCommMessaging " ) . @param { String } options . collection - ( optional default no collection ) collection to which this DID should belong in wallet content store . @returns { Promise } - Promise of DID Resolution response or an error if operation fails
async createOrbDID(
    auth,
    {
      keyType = DEFAULT_KEY_TYPE,
      keyAgreementKeyType = DEFAULT_KEYAGREEMENT_KEY_TYPE,
      signatureType = DEFAULT_SIGNATURE_TYPE,
      keyAgreementType = DEFAULT_KEYAGREEMENT_TYPE,
      purposes = ["authentication"],
      routerKeyAgreementIDs = [],
      routerConnections = [],
      serviceID = "",
      serviceEndpoint = "",
      didcommServiceType = "",
      collection,
    } = {}
  ) {
    const [keySet, recoveryKeySet, updateKeySet, keyAgreementKeySet] =
      await Promise.all([
        this.wallet.createKeyPair(auth, { keyType }),
        this.wallet.createKeyPair(auth, { keyType: DEFAULT_KEY_TYPE }),
        this.wallet.createKeyPair(auth, { keyType: DEFAULT_KEY_TYPE }),
        this.wallet.createKeyPair(auth, { keyType: keyAgreementKeyType }),
      ]);
    const createDIDRequest = {
      publicKeys: [
        {
          id: keySet.keyID,
          type: signatureType,
          value: keySet.publicKey,
          encoding: "Jwk",
          keyType: keyType,
          purposes: purposes,
        },
        {
          id: recoveryKeySet.keyID,
          type: DEFAULT_SIGNATURE_TYPE,
          value: recoveryKeySet.publicKey,
          encoding: "Jwk",
          keyType: DEFAULT_KEY_TYPE,
          recovery: true,
        },
        {
          id: updateKeySet.keyID,
          type: DEFAULT_SIGNATURE_TYPE,
          value: updateKeySet.publicKey,
          encoding: "Jwk",
          keyType: DEFAULT_KEY_TYPE,
          update: true,
        },
        {
          id: keyAgreementKeySet.keyID,
          type: keyAgreementType,
          value: keyAgreementKeySet.publicKey,
          encoding: "JWK",
          keyType: keyAgreementKeyType,
          purposes: ["keyAgreement"],
        },
      ],
      routerKAIDS: routerKeyAgreementIDs,
      routerConnections: routerConnections,
    };
    if (serviceID) {
      createDIDRequest["serviceID"] = serviceID;
    }
    if (serviceEndpoint) {
      createDIDRequest["serviceEndpoint"] = serviceEndpoint;
    }
    if (didcommServiceType) {
      createDIDRequest["didcommServiceType"] = didcommServiceType;
    }
    let content = await this.agent.didclient.createOrbDID(createDIDRequest);
    if (
      content.didDocumentMetadata.equivalentId &&
      content.didDocumentMetadata.equivalentId.length > 0
    ) {
      const resolveWithRetry = async (retryCount = 5) => {
        if (retryCount == 0)
          throw new Error(
            "exceeded all retry attempts to resolve odb DID by equivalent ID"
          );
        try {
          return await this.resolveOrbDID(
            auth,
            content.didDocumentMetadata.equivalentId[0]
          );
        } catch (e) {
          console.error("failed to resolve orb DID, retrying due to error", e);
          await waitFor(1000);
          return await resolveWithRetry(retryCount - 1);
        }
      };
      content = await resolveWithRetry();
    }
    await this.saveDID(auth, { content, collection });
    console.debug(
      "created and saved Orb DID successfully",
      content.didDocument.id
    );
    return content;
  }
async createOrbDID ( auth , { keyType = DEFAULT_KEY_TYPE , keyAgreementKeyType = DEFAULT_KEYAGREEMENT_KEY_TYPE , signatureType = DEFAULT_SIGNATURE_TYPE , keyAgreementType = DEFAULT_KEYAGREEMENT_TYPE , purposes = [ "authentication" ] , routerKeyAgreementIDs = [ ] , routerConnections = [ ] , serviceID = "" , serviceEndpoint = "" , didcommServiceType = "" , collection , } = { } ) { const [ keySet , recoveryKeySet , updateKeySet , keyAgreementKeySet ] = await Promise . all ( [ this . wallet . createKeyPair ( auth , { keyType } ) , this . wallet . createKeyPair ( auth , { keyType : DEFAULT_KEY_TYPE } ) , this . wallet . createKeyPair ( auth , { keyType : DEFAULT_KEY_TYPE } ) , this . wallet . createKeyPair ( auth , { keyType : keyAgreementKeyType } ) , ] ) ; const createDIDRequest = { publicKeys : [ { id : keySet . keyID , type : signatureType , value : keySet . publicKey , encoding : "Jwk" , keyType : keyType , purposes : purposes , } , { id : recoveryKeySet . keyID , type : DEFAULT_SIGNATURE_TYPE , value : recoveryKeySet . publicKey , encoding : "Jwk" , keyType : DEFAULT_KEY_TYPE , recovery : true , } , { id : updateKeySet . keyID , type : DEFAULT_SIGNATURE_TYPE , value : updateKeySet . publicKey , encoding : "Jwk" , keyType : DEFAULT_KEY_TYPE , update : true , } , { id : keyAgreementKeySet . keyID , type : keyAgreementType , value : keyAgreementKeySet . publicKey , encoding : "JWK" , keyType : keyAgreementKeyType , purposes : [ "keyAgreement" ] , } , ] , routerKAIDS : routerKeyAgreementIDs , routerConnections : routerConnections , } ; if ( serviceID ) { createDIDRequest [ "serviceID" ] = serviceID ; } if ( serviceEndpoint ) { createDIDRequest [ "serviceEndpoint" ] = serviceEndpoint ; } if ( didcommServiceType ) { createDIDRequest [ "didcommServiceType" ] = didcommServiceType ; } let content = await this . agent . didclient . createOrbDID ( createDIDRequest ) ; if ( content . didDocumentMetadata . equivalentId && content . didDocumentMetadata . equivalentId . length > 0 ) { const resolveWithRetry = async ( retryCount = 5 ) => { if ( retryCount == 0 ) throw new Error ( "exceeded all retry attempts to resolve odb DID by equivalent ID" ) ; try { return await this . resolveOrbDID ( auth , content . didDocumentMetadata . equivalentId [ 0 ] ) ; } catch ( e ) { console . error ( "failed to resolve orb DID, retrying due to error" , e ) ; await waitFor ( 1000 ) ; return await resolveWithRetry ( retryCount - 1 ) ; } } ; content = await resolveWithRetry ( ) ; } await this . saveDID ( auth , { content , collection } ) ; console . debug ( "created and saved Orb DID successfully" , content . didDocument . id ) ; return content ; }
Creates Orb DID and saves it in wallet content store.
Creates Orb DID and saves it in wallet content store .
// we are using `https` domain now here.