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

Creating a Schema

Creates a customized schema as per user specifications.

Creating a Schema Definition

The sampleCreateSchemaDef function demonstrates how to create a schema definition using the DICE ID SDK. It prompts the user for the attribute name, schema name, and schema version, and then calls the createSchema function to create the schema.

API Elements

  1. schema_input: An object that holds the attribute, schema name, and schema version for creating the schema.

  2. schema_input.attributes: An object that stores the attribute name and its data type.

  3. attr_name: Stores the attribute name entered by the user.

  4. schema_name: Stores the schema name entered by the user.

  5. schema_version: Stores the schema version entered by the user.

  6. diceidsdk.issuer.createSchema(): Creates a schema using the schema_input.

  7. Imports the ISSUER_XAPIKEY constant from the appconfig module.

  8. resp: Holds the response from the createSchema API, including the schema details.

  9. schemaOutput: Stores the created schema output.

  10. err: Stores any error that occurs during the process.

function createSchema() {
  const schemaInput = {
    attributes: {},
    schema_name: '',
    schema_version: '',
  };

  const numAttr = parseInt(prompt('Enter number of attributes in the schema: '));

  for (let i = 0; i < numAttr; i++) {
    const attrName = prompt('Enter attribute name: ');
    schemaInput.attributes[attrName] = 'text';
  }

  schemaInput.schema_name = prompt('Enter schema name: ');
  schemaInput.schema_version = prompt('Enter schema version: ');

  diceidsdk.issuer.createSchema(schemaInput, ISSUER_XAPIKEY)
    .then(resp => {
      const schemaOutput = resp;
      console.log('Schema created successfully:', schemaOutput);
    })
    .catch(err => {
      console.error('Error creating schema:', err);
    });
}

createSchema();

Running the Code

Step 1: Add the sampleCreateSchemaDef function: Copy the sampleCreateSchemaDef function code and paste it into your JavaScript file after importing the diceidsdk module.

Step 2: Obtain an API Key: Make sure you have an API key from the DiceID platform. Set the ISSUER_XAPIKEY constant in the appconfig.js file to your actual API key.

Step 3: Run the function: Invoke the sampleCreateSchemaDef function in your code to execute it. For example:

node sampleCreateSchemaDef.js

Step 4: Provide input: The function will prompt you to enter the attribute name, schema name, and schema version. Enter the required information in the terminal or command prompt.

Step 4: Once the createSchema function completes, you can handle the response within the .then() block of the promise or perform any necessary error handling in the .catch() block.

PreviousCreate ConnectionNextIssue a Credential

Last updated 1 year ago