Skip to content

Latest commit

 

History

History
75 lines (55 loc) · 2.53 KB

File metadata and controls

75 lines (55 loc) · 2.53 KB

Construction

Depending on your use-case and specific needs, constructing a LearnCard is likely as simple as the following code:

import { initLearnCard } from '@learncard/init';

const learnCard = await initLearnCard({ seed: 'abc123' });

For a full description of instantiating a LearnCard by configuration, check out the full documentation on the initLearnCard function:

{% content-ref url="initlearncard.md" %} initlearncard.md {% endcontent-ref %}

Key Generation

{% hint style="danger" %} There be dragons here. 🐉

In production environments, take great care and caution when generating and storing key material. Insufficient entropy or insecure storage, among other vectors, can easily compromise your data and identities. {% endhint %}

How to generate and store keys is left to you, the consumer. However, if you'd like to simply generate a random key, you can do so with the following code:

{% tabs %} {% tab title="Browser" %}

const randomKey = Array.from(crypto.getRandomValues(new Uint8Array(32)), dec =>
  dec.toString(16).padStart(2, "0")
).join("");

{% endtab %}

{% tab title="Node" %}

import crypto from 'node:crypto';

const randomKey = crypto.randomBytes(32).toString('hex');

{% endtab %} {% endtabs %}

To speed up instantiation of the wallet, you can host our didkit wasm binary yourself.

{% tabs %} {% tab title="Webpack 5" %}

// Make sure you have the didkit plugin installed! pnpm i @learncard/didkit-plugin

import { initLearnCard } from '@learncard/init';
import didkit from '@learncard/didkit-plugin/dist/didkit/didkit_wasm_bg.wasm';

const learnCard = await initLearnCard({ seed: 'abc123', didkit });

{% endtab %}

{% tab title="Vite" %}

// Make sure you have the didkit plugin installed! pnpm i @learncard/didkit-plugin

import { initLearnCard } from '@learncard/init';
import didkit from '@learncard/didkit-plugin/dist/didkit/didkit_wasm_bg.wasm?url';

const learnCard = await initLearnCard({ seed: 'abc123', didkit });

{% endtab %} {% endtabs %}

If you're curious about what the above code is doing, read more here.

Next, refer to our documentation on Managing Seed Phrase:

{% content-ref url="managing-seed-phrases.md" %} managing-seed-phrases.md {% endcontent-ref %}