LearnCard Network
Using the LearnCard Network Plugin
The LearnCard Network Plugin (@learncard/network-plugin
) simplifies the process of interacting with the LearnCard Network API by providing a set of convenient methods for managing profiles, connections, credentials, presentations, and boosts. This guide will help you understand how to use this plugin in your application.
Installation
pnpm install @learncard/network-plugin
Initialization
import { initLearnCard } from '@learncard/init'
import didkit from '@learncard/didkit-plugin/dist/didkit/didkit_wasm_bg.wasm?url';
const networkLearnCard = await initLearnCard({
seed,
network: true,
didkit,
});
Accessing Plugin Methods
Once you've initialized the LearnCard Network Plugin, you can access the methods by calling learnCard.invoke.<LearnCardNetworkPluginMethods>
. For example, to get a user's profile with a profileId
of johnsmith
you can call:
await networkLearnCard.invoke.getProfile('johnsmith');
Here's a brief overview of the available methods in the LearnCardNetworkPluginMethods
:
Profile Management: Create, update, delete, and retrieve user profiles.
Connections: Manage connections between users, including sending and accepting connection requests, and fetching connection information.
Credentials: Send, accept, retrieve, and delete credentials between users.
Presentations: Send, accept, retrieve, and delete presentations between users.
Boosts: Create, send, update, delete, and claim boosts for users on the network.
Storage: Resolve a URI to a credential or presentation.
Signing Authorities: Register and retrieve signing authorities for the LearnCard Network.
For detailed information on the method signatures and their parameters, refer to the type definitions provided in the @learncard/network-plugin
package.
Examples
Here are a few examples of how to use the LearnCard Network Plugin in your application:
Create a Profile
const profile = {
profileId: 'johnsmith',
displayName: 'John Smith',
image: 'https://example.com/avatar.jpg',
};
await networkLearnCard.invoke.createProfile(profile);
Connect with Another Profile
const profileId = 'janesmith';
await networkLearnCard.invoke.connectWith(profileId);
Send a Credential
const profileId = 'janesmith';
const vc = await networkLearnCard.invoke.issueCredential(networkLearnCard.invoke.newCredential())
const encrypt = true;
await networkLearnCard.invoke.sendCredential(profileId, vc, encrypt);
Claim a Boost
const boostUri = 'https://example.com/boost-uri';
const challenge = 'example-challenge';
await networkLearnCard.invoke.claimBoostWithLink(boostUri, challenge);
These examples demonstrate some of the ways you can interact with the LearnCard Network API using the @learncard/network-plugin
.
Last updated
Was this helpful?