Connect to Independent Network

Setting Up ConsentFlow with an Independent Network

ConsentFlow contracts allow third-party applications to read from and write to a LearnCard with the consent of the LearnCard owner. This guide will walk you through setting up a ConsentFlow with an Independent Network (instead of the default LearnCard Network) and Independent Wallet (instead of the default LearnCard App) to connect your external, 3rd party application.

Prerequisites

  • Node.js environment

  • Access to an Independent Network endpoint

  • Access to an Independent Wallet Application

Step 1: Create a Service Profile

First, you need to initialize the LearnCard CLI and create a network LearnCard that points to your Independent Network:

// Install and start LearnCard CLI
// pnpm dlx @learncard/cli

// Initialize LearnCard with your Independent Network
const networkLearnCard = await initLearnCard({ 
    seed: '[your secure key]', 
    network: 'https://network.independent.example.org/trpc'  // Point to your Independent Network
})

// Create a service profile
const serviceProfile = {
  displayName: 'Your App Name',
  profileId: 'your-app-unique-id',
  image: 'https://example.com/your-app-logo.jpg',
};

// Register the service profile
await networkLearnCard.invoke.createServiceProfile(serviceProfile);

Your service profile represents your application in the LearnCard ecosystem. Make sure to use a unique profileId and provide a clear displayName and image to help users recognize your service.

Step 2: Create a ConsentFlow Contract

Next, create a ConsentFlow contract that specifies what data your application needs to read from and write to users' LearnCard wallets:

Available Credential Categories

When specifying credential categories in your contract, ensure you are using categories supported by your network. For example, many networks support a subset of the following categories:

  • Achievement

  • Accommodation

  • Accomplishment

  • Course

  • ID

  • Job

  • Learning History

  • Membership

  • Merit Badge

  • Skill

  • Social Badge

  • Work History

Step 3: Add a "Connect Your Wallet" Button to Your Website

Add a button or link on your application that directs users to the ConsentFlow URL:

When users click this button, they'll be directed to the ConsentFlow consent page where they can review and approve the permissions your app is requesting.

After a user consents to your contract, they'll be redirected to the URL specified in your contract's redirectUrl parameter with their DID added as a query parameter:

In your application, implement a handler for this callback:

Step 5: Reading Data from Connected LearnCards

To read data from users who have consented to your contract:

Step 6: Sending Credentials to Users

Option A: Using LearnCard SDK

To issue credentials to connected users with the LearnCard SDK:

Option B: Using HTTP Endpoints

If you prefer not to use the LearnCard npm packages, you can send credentials directly using HTTP endpoints. This approach is useful for integrations in languages other than JavaScript or in environments where installing npm packages might be challenging.

Example Usage with a Complete Credential

Implementation in Other Languages

Python Example

Best Practices

  1. Security: Always use a strong, secure seed for your LearnCard initialization and keep your secret tokens secure.

  2. Privacy: Only request access to the credential categories and personal information that your application actually needs.

  3. User Experience: Clearly explain to users why your application needs access to their LearnCard and what benefits they'll receive.

  4. Error Handling: Implement robust error handling for all LearnCard operations and HTTP requests.

  5. Persistence: Store the contract URI securely - you'll need it for all future operations with that contract.

  6. Authentication: When using HTTP endpoints, ensure proper authentication mechanisms are in place to protect sensitive operations.

  7. Validation: Always validate credential data before sending to ensure it meets the required format and schema.

Step 7: Working with Boosts

Boosts are a powerful feature that allow you to create reusable credential templates that can be sent to multiple recipients while maintaining analytics and management capabilities.

What is a Boost?

A Boost is a registered credential template in the network that can be:

  • Sent to multiple recipients

  • Tracked with analytics

  • Managed through permissions

  • Organized into categories

Why Use Boosts Instead of Direct Credential Sending

Understanding the difference between Boosts and direct credential sending is important:

Feature
Direct Credential Sending
Boosts

Analytics

No analytics available

Track how many users claimed, viewed analytics

Recipients

One credential per send operation

Same template can be sent to multiple users

Management

No central management

Can edit, update, and manage permissions

Organization

No categorization

Can be organized by type and category

Permissions

Limited control

Fine-grained permission management

Creating a Boost Using HTTP Endpoints

You can create a Boost using the HTTP API:

Example Boost Creation

Here's a complete example of creating a merit badge Boost:

Sending a Boost to Recipients

Once you've created a Boost, you can send it to recipients using their profileId:

Best Practices for Working with Boosts

  1. Create Reusable Templates: Design your Boosts to be reusable across multiple recipients.

  2. Use Meaningful Categories: Organize Boosts into logical categories for easier management.

  3. Set Appropriate Permissions: Define who can issue, edit, and manage your Boosts.

  4. Use DRAFT Status: When creating a new Boost, set it to DRAFT until you're ready to start issuing.

Troubleshooting

  • Connection Issues: Ensure your network endpoint is correctly configured and accessible.

  • Missing DIDs: Verify that users are completing the consent process and your redirect handler is properly extracting the DID.

  • Credential Read Failures: Check that your contract has the necessary read permissions for the credential categories you're trying to access.

  • Credential Write Failures: Verify that your contract has the necessary write permissions and that you're using the correct profileId when sending credentials.

  • HTTP Errors: For HTTP endpoint issues, check your authorization token, ensure the correct endpoint URL, and verify your payload structure meets the API requirements.

  • Authentication Problems: Ensure you're using the correct authorization token and that it hasn't expired.

  • Profile ID Format: When extracting profileId from a DID, make sure you're using the correct format required by the network.

  • Boost Creation Failures: Verify that all required fields are provided and properly formatted in your Boost creation request.

  • Boost Sending Issues: Ensure the Boost URI is valid and that you have permission to issue the Boost.

By following this guide, you should be able to successfully integrate LearnCard with your application using an Independent Network, allowing users to connect their LearnCards and exchange credentials securely.

Last updated

Was this helpful?