DICE Developer Docs
  • Developer Docs
    • DICE Test Drive
      • Sign-up for Issuer Portal
      • Issue Credentials
      • Verify Credentials
    • Key Concepts
      • DID & Verifiable Credentials
      • DICE ID Architecture
    • Platform Console
      • Dashboard
      • Customers
        • Onboard Customer
      • Credentials
        • Issue Credentials to New Customer
      • Schema
      • Batch Issuance
        • Batch Issuance - Useful Tips
      • Verifications
        • Verification Template
      • Templates
        • Certificate Template
          • Create Template
          • Manage Template
        • Email Template
          • Create Template
          • Manage Template
      • Organization
      • Departments
      • Organization Users
      • API Access
      • Callback Configuration
      • Tutorials
        • Credential Issuance from DICE ID Console
        • Credential Issuance using DICE ID APIs
        • Credential Verification using QR code
        • Credential Verification from DICE ID console
        • Batch Credential Issuance from DICE ID Console
    • Integrations
      • Auth0 Integration
        • Login using OIDC (First Factor Authentication)
        • Custom MFA Rule (For 2FA)
    • DICE ID SDK
      • DICE ID
        • DID & Verifiable Credentials
        • DICE ID Architecture
      • SDK Functionalities
      • Create Wallet
      • Create Connection
      • Creating a Schema
      • Issue a Credential
      • Send Presentation Request
      • Get Verification State
      • Configuration and Customization
      • Error Handling & Troubleshooting
      • Conclusion
      • Additional Resources
  • Getting Started with DICE ID Skill Credentials
    • Building Trust Ecosystems Powered by Credentials
    • DICE ID Integration for Issuers
    • DICE ID Integration for Verifiers
    • DICE ID Brand Usage Guidelines
    • DICE ID Onboarding Confirmation
    • Helpful Q&A
    • Troubleshooting Guide
Powered by GitBook
On this page
  1. Developer Docs
  2. DICE ID SDK

Issue a Credential

Grant credentials to users

sampleIssueCredential

The sampleIssueCredential function demonstrates how to issue a credential using the DICE ID SDK.

Importing Required Modules

The sample code begins with importing the necessary modules and dependencies. These modules are required for executing the SDK functionality. The following modules are imported:

const { CREDENTIAL_DEF, ISSUER_CONNECTION_ID } = require('./appconfig');
const { SCHEMA_ID, ISSUER_DID, SCHEMA_NAME } = require('./appconfig');
const { WALLET_TOKEN } = require('./appconfig');
const { ISSUER_XAPIKEY } = require('./appconfig');

Sample Data

The sample code defines an array called cred_def_values, which contains the attribute-value pairs for the credential being issued. Each element in the array represents a specific attribute and its corresponding value.

const cred_def_values = [ {"name":"Id",
                               "value":"myid"},
                              {"name":"TypeOfDoc",
                               "value":"Phone Bill"},
                              {"name":"ValueOfDoc",
                               "value":"Bill Amount 700"},
                              {"name":"Validity",
                               "value":"always"},
                              {"name":"Provider",
                               "value":"BSNL"}]

The sampleIssueCredential function is responsible for issuing a credential using the diceidsdk module. It performs the following steps:

  1. Calls the issuer.sendCredOffer function to send a credential offer:

diceidsdk.issuer.sendCredOffer(ISSUER_CONNECTION_ID, CREDENTIAL_DEF, cred_def_values, ISSUER_XAPIKEY)
  • ISSUER_CONNECTION_ID: The ID of the connection with the credential recipient.

  • CREDENTIAL_DEF: The credential definition ID.

  • cred_def_values: The attribute-value pairs for the credential.

  • ISSUER_XAPIKEY: The API key for the issuer.

  1. Handles the response or error:

.then(resp => console.log("cred output"))
.catch(err => console.log("error=", err))
  • If the operation is successful, it logs the credential output.

  • If an error occurs, it logs the error message.

Running the Code

Step 1: Add the sampleIssueCredential function to your code. Copy the function code provided and paste it after importing the diceidsdk module.

Step 2: Run the function by invoking it in your code. For example:

node sampleIssueCredential.js

Step 3: Make sure you have provided appropriate values for the required variables (ISSUER_CONNECTION_ID, CREDENTIAL_DEF, cred_def_values, ISSUER_XAPIKEY) and have imported the necessary configuration from the appconfig.js file.

Step 4: The function will then use the sendCredOffer API to send a credential offer with the provided parameters. The response from the API will be logged to the console as "Credential output".

PreviousCreating a SchemaNextSend Presentation Request

Last updated 1 year ago