Task 3: Issue verifiable credentials

Verifiable Credentials are digital certificates that represent proof of a user's identity, achievements, contributions, or other verified information.

Developer Documentation: Issuing Verifiable Credentials using MOTI API

Overview

This document provides guidelines for developers on how to issue verifiable credentials using the MOTI API. The goal is to enable developers to create and manage verifiable credentials for users, ensuring the credentials are securely issued and can be verified by other entities.

Objectives

  1. Setup Environment:

    • Ensure the environment is ready for using the MOTI API.

    • Obtain necessary API keys and credentials.

  2. Issuing Verifiable Credentials:

    • Create verifiable credentials for users.

    • Ensure credentials are properly formatted and securely issued.

  3. Verification of Credentials:

    • Provide mechanisms for verifying the issued credentials.

Prerequisites

  1. API Access:

    • Obtain API keys and access credentials from MOTI.

    • Ensure your account has the necessary permissions to issue credentials.

  2. Development Environment:

    • Recommended tools:

      • Python (or preferred programming language)

      • HTTP client library (e.g., requests for Python)

Step-by-Step Guide

1. Setup Environment

  1. Install Dependencies:

    • Install necessary libraries for making API requests.

      pip install requests
  2. Configure API Access:

    • Store your API keys and other credentials securely.

    • Example configuration (using environment variables):

      import os
      
      MOTI_API_KEY = os.getenv('MOTI_API_KEY')
      MOTI_API_SECRET = os.getenv('MOTI_API_SECRET')
      MOTI_API_BASE_URL = 'https://api.moti.com/v1'

2. Issuing Verifiable Credentials

  1. Define Credential Schema:

    • Determine the schema for the verifiable credentials you want to issue.

    • Example schema:

      {
        "type": "VerifiableCredential",
        "issuer": "https://moti.com/issuer",
        "credentialSubject": {
          "id": "did:moti:123456789",
          "email": "[email protected]",
          "name": "John Doe",
          "socialLinks": {
            "twitter": "https://twitter.com/username",
            "linkedin": "https://linkedin.com/in/username"
          }
        },
        "issued": "2024-07-11T00:00:00Z",
        "proof": {
          "type": "Ed25519Signature2020",
          "created": "2024-07-11T00:00:00Z",
          "proofPurpose": "assertionMethod",
          "verificationMethod": "https://moti.com/issuer/keys/1",
          "jws": "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9..."
        }
      }
  2. Create Credential Payload:

    • Create the payload for the credential based on the defined schema.

      import json
      from datetime import datetime
      
      credential_payload = {
          "type": "VerifiableCredential",
          "issuer": "https://moti.com/issuer",
          "credentialSubject": {
              "id": "did:moti:123456789",
              "email": "[email protected]",
              "name": "John Doe",
              "socialLinks": {
                  "twitter": "https://twitter.com/username",
                  "linkedin": "https://linkedin.com/in/username"
              }
          },
          "issued": datetime.utcnow().isoformat() + "Z",
          "proof": {
              "type": "Ed25519Signature2020",
              "created": datetime.utcnow().isoformat() + "Z",
              "proofPurpose": "assertionMethod",
              "verificationMethod": "https://moti.com/issuer/keys/1",
              "jws": "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9..."
          }
      }
  3. Issue Credential via MOTI API:

    • Send a request to the MOTI API to issue the credential.

      import requests
      
      url = f"{MOTI_API_BASE_URL}/credentials/issue"
      headers = {
          "Authorization": f"Bearer {MOTI_API_KEY}",
          "Content-Type": "application/json"
      }
      response = requests.post(url, headers=headers, data=json.dumps(credential_payload))
      
      if response.status_code == 200:
          issued_credential = response.json()
          print("Credential issued successfully:", issued_credential)
      else:
          print("Failed to issue credential:", response.status_code, response.text)

3. Verifying Credentials

  1. Provide Verification Endpoint:

    • Ensure you have an endpoint for verifying issued credentials.

    • Example verification endpoint:

      verify_url = f"{MOTI_API_BASE_URL}/credentials/verify"
      verification_payload = {
          "credential": issued_credential
      }
      
      verification_response = requests.post(verify_url, headers=headers, data=json.dumps(verification_payload))
      
      if verification_response.status_code == 200:
          verification_result = verification_response.json()
          print("Credential verified successfully:", verification_result)
      else:
          print("Failed to verify credential:", verification_response.status_code, verification_response.text)
  2. Verification Process:

    • Provide instructions to users or other entities on how to verify the issued credentials using the provided endpoint.

Key Considerations

  • Data Security: Ensure all sensitive data is handled securely and in compliance with data protection regulations.

  • API Rate Limits: Be aware of API rate limits and implement appropriate handling for rate limit errors.

  • Error Handling: Implement robust error handling to manage cases where credential issuance or verification fails.

  • Documentation: Keep your documentation updated with any changes to the API or credential schemas.

Conclusion

By following this guide, developers can efficiently issue verifiable credentials using the MOTI API. These credentials can be used to authenticate users and provide verifiable proof of their information.

For further questions or support, please contact the MOTI development team.

Last updated