Create a DID-Linked Resource

This guide demonstrates how to create DID-Linked Resources using the cheqd SDK, with examples based on the SDK's test suite and common usage patterns. DID-Linked Resources allow you to associate data like schemas, credential definitions, status lists, and other artifacts with DIDs.

Prerequisites

Before creating DID-Linked Resources, ensure you have:

  1. Created a DID to link resources to

  2. A funded wallet for paying transaction fees

  3. Access to a cheqd network (testnet or mainnet)

  4. The private keys associated with the DID's authentication methods

SDK Initialization

First, initialize the SDK with the required modules:

Basic SDK Setup

import { createCheqdSDK, ResourceModule, CheqdNetwork, AbstractCheqdSDKModule } from '@cheqd/sdk';
import { DirectSecp256k1HdWallet } from '@cosmjs/proto-signing';

// Initialize wallet from mnemonic
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(
  'your twelve word mnemonic phrase goes here like this example', 
  { prefix: 'cheqd' }
);

// Create SDK instance
const sdk = await createCheqdSDK({
  modules: [ResourceModule as unknown as AbstractCheqdSDKModule],
  rpcUrl: 'https://rpc.cheqd.network', // testnet
  network: CheqdNetwork.Testnet,
  wallet: wallet
});

Advanced SDK Setup with Multiple Modules

Resource Creation Examples

Example 1: Basic JSON Schema Resource

This example creates a JSON Schema as a DID-Linked Resource:

Example 2: Credential Definition Resource

This example creates an AnonCreds Credential Definition resource:

Example 3: Bitstring Status List Resource

This example creates a Bitstring Status List for credential status management:

Example 4: Image/Logo Resource

This example creates an image resource (e.g., organization logo):

Example 5: Custom Metadata Resource

This example creates a resource with custom metadata and multiple alternative URIs:

Example 6: Resource with Custom Version ID

This example creates a resource with a custom version identifier for tracking:

Complete Working Example

Here's a complete example you can run:

Error Handling and Validation

Resource Payload Validation

Before submitting to the ledger, validate your resource payload:

Content Size Limits

Check resource content size limits:

Fee Calculation by Media Type

The SDK provides specific fee calculation methods based on the resource media type:

DID Authorization Check

Verify that the signing keys have authority over the collection DID:

Best Practices

Resource Design

  1. Meaningful Names: Use descriptive names that clearly identify the resource

  2. Version Management: Use semantic versioning for resource versions

  3. Media Types: Use appropriate MIME types for your content

  4. Resource Types: Use standardized resource type names when possible

  5. Size Optimization: Keep resources reasonably sized for network efficiency

Security Considerations

  1. Key Management: Secure storage of private keys used for signing

  2. Content Validation: Validate content before creating resources

  3. Access Control: Ensure only authorized entities can create resources for a DID

  4. Backup Strategies: Maintain backups of critical resources

  5. Version Control: Track resource changes and maintain audit trails

Performance Optimization

  1. Batch Operations: Group related resource creations when possible

  2. Content Compression: Compress large text-based resources

  3. Caching: Implement caching strategies for frequently accessed resources

  4. CDN Integration: Use Content Delivery Networks for global distribution

  5. Alternative URIs: Provide multiple access methods through alsoKnownAs

Common Resource Types

Standard Resource Types

  • JSONSchema - JSON Schema definitions

  • CL_SCHEMA - AnonCreds credential definitions

  • BitstringStatusList - W3C Bitstring Status List for credential status

  • Image - Images, logos, and graphics

  • Documentation - API docs, specifications, guides

  • EntityMetadata - Organization or entity information

  • TermsOfService - Legal terms and conditions

  • PrivacyPolicy - Privacy policies and data handling terms

Custom Resource Types

You can create custom resource types for specific use cases:

Next Steps

After creating resources, you can:

Troubleshooting

Common Issues

  1. DID Not Found: Verify the collection DID exists and is active

  2. Insufficient Permissions: Ensure signing keys have authority over the collection DID

  3. Resource Too Large: Check resource size limits and compress if needed

  4. Invalid Media Type: Use proper MIME types for your content

  5. Network Errors: Verify connection to the cheqd network

  6. Fee Calculation Errors: Ensure wallet has sufficient funds

Getting Help

If you encounter issues:

Last updated

Was this helpful?