# learn-card-core

> >

Latest version **0.3.5** (published 2022-06-04) · MIT license · 1.3K weekly downloads

## Install

```sh
npm install learn-card-core
pnpm add learn-card-core
yarn add learn-card-core
bun add learn-card-core
```

## Health

**Score 55/100 (C)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: large bundle; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.3.5 |
| Published | 2022-06-04 |
| First published | 2022-05-31 |
| Weekly downloads | 1.3K |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 13 |
| Unpacked size | 24.5 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 70 |
| Author | Taylor Beeston |
| Maintainers | taylorbeeston |

## Links

- npm: https://www.npmjs.com/package/learn-card-core
- Repository: https://github.com/WeLibraryOS/LearnCard
- Homepage: https://github.com/WeLibraryOS/LearnCard#readme
- Issues: https://github.com/WeLibraryOS/LearnCard/issues
- npm.io page: https://npm.io/package/learn-card-core

## Dependencies (13)

- [dids](https://npm.io/package/dids.md) ^3.1.0
- [hex-lite](https://npm.io/package/hex-lite.md) ^1.5.0
- [key-did-resolver](https://npm.io/package/key-did-resolver.md) 1.2.1
- [learn-card-types](https://npm.io/package/learn-card-types.md) 1.2.1
- [@ceramicstudio/idx](https://npm.io/package/@ceramicstudio/idx.md) ^0.12.2
- [@glazed/tile-loader](https://npm.io/package/@glazed/tile-loader.md) ^0.2.0
- [@peculiar/webcrypto](https://npm.io/package/@peculiar/webcrypto.md) ^1.4.0
- [@glazed/did-datastore](https://npm.io/package/@glazed/did-datastore.md) ^0.3.1
- [@ceramicnetwork/common](https://npm.io/package/@ceramicnetwork/common.md) ^2.0.4
- [@ceramicnetwork/streamid](https://npm.io/package/@ceramicnetwork/streamid.md) ^2.0.4
- [key-did-provider-ed25519](https://npm.io/package/key-did-provider-ed25519.md) ^2.0.0
- [@ceramicnetwork/http-client](https://npm.io/package/@ceramicnetwork/http-client.md) 2.0.4
- [@ceramicnetwork/stream-tile](https://npm.io/package/@ceramicnetwork/stream-tile.md) ^2.1.3

## Recent versions

- 0.3.5 (latest) — 2022-06-04
- 0.3.4 — 2022-06-03
- 0.3.3 — 2022-06-03
- 0.3.2 — 2022-06-03
- 0.3.1 — 2022-06-03
- 0.3.0 — 2022-06-03
- 0.2.1 — 2022-06-02
- 0.2.0 — 2022-06-02
- 0.1.1 — 2022-05-31
- 0.1.0 — 2022-05-31

## README

# learn-card-core

> 

[![npm version](https://img.shields.io/npm/v/learn-card-core)](https://www.npmjs.com/package/learn-card-core)
[![npm downloads](https://img.shields.io/npm/dw/learn-card-core)](https://www.npmjs.com/package/learn-card-core)
[![vulnerabilities](https://img.shields.io/snyk/vulnerabilities/npm/learn-card-core)](https://www.npmjs.com/package/learn-card-core)

## Install

```bash
pnpm i learn-card-core
```

## Usage

### Instantiation

Instantiate a wallet using `walletFromKey`. This method accepts a unique identifier string that is 
up to 64 characters long. If it is less than 64 characters, `walletFromKey` will pad the start of
the string with 0's until it is 64 characters long.

```js
import { walletFromKey } from "learn-card-core";

const wallet = await walletFromKey('unique-identifier-that-is-up-to-and-preferably64-characters-long');
```

### Issuing/Verifying Credentials and Presentations

#### Issue a credential
```js
// Grab a test VC, or create your own!
const unsignedVc = await wallet.getTestVc();

const vc = await wallet.issueCredential(unsignedVc);
```

#### Verify a credential
```js
const result = await wallet.verifyCredential(vc);

if (result.warnings.length > 0) console.error('Verification warnings:', result.warnings);

if (result.errors.length > 0) console.error('This credential is not valid!', result.errors);
else console.log('This credential is valid!');
```

#### Issue a presentation
```js
const vp = await wallet.issuePresentation(vc);
```

#### Verify a presentation
```js
const result = await wallet.verifyPresentation(vp);

if (result.warnings.length > 0) console.error('Verification warnings:', result.warnings);

if (result.errors.length > 0) console.error('This presentation is not valid!', result.errors);
else console.log('This presentation is valid!');
```

### Storing/Retrieving/Sending Credentials

#### Ceramic/IDX

To maintain co-ownership of credentials, it is best to store credentials in a public place, and then
store references to that public place. While this is not the only way to store credentials (and is
also definitely not a silver bullet! E.g. credentials containing private data), it is the opinion of
this library that it should be used by default. As a result, instantiating a wallet, will 
automatically connect you to WeLibrary's ceramic node, and allow you to publish and retrieve 
credentials there using IDX.

#### Publish Credential

After signing a VC, you may choose to publish that credential to Ceramic. Doing so will return a
stream ID, which you may share to the recipient. That stream ID can then be used to resolve the 
issued credential. This means both the issuer and recipient may store the _stream ID_ instead of the
credential itself.

```js
const streamId = await wallet.publishCredential(vc);
```

#### Reading From Ceramic

To resolve a VC from a stream ID, simply call the `readFromCeramic` method:

```js
const vcFromCeramic = await wallet.readFromCeramic(streamId);
```

#### Adding a Credential to a Wallet

After receiving a streamID, you can _persist_ that streamID by calling `addCredential`, and giving
the credential a bespoke title

```js
await wallet.addCredential({ id: streamId, title: 'Test VC' });
```

This will add the streamId, which can be used to resolve the verifiable credential to IDX using the
wallet's secret key. You can think of this as acting like the wallet's personal storage.

#### Getting a credential from the Wallet

After calling `addCredential`, you can use the bespoke title to retrieve that credential at any time

```js
const vcFromIdx = await wallet.getCredential('Test VC');
```

Alternatively, you can get an array of _all_ credentials you have added using `getCredentials`

```js
const vcs = await wallet.getCredentials();
```

## Further Reading

[Read the official docs here!](https://app.gitbook.com/o/6uDv1QDlxaaZC7i8EaGb/s/FXvEJ9j3Vf3FW5Nc557n/)

## License

MIT © [Taylor Beeston <beeston.taylor@gmail.com>](https://github.com/TaylorBeeston)

[Created with aqu 🌊](https://github.com/ArtiomTr/aqu#readme)

---
_Source: https://npm.io/package/learn-card-core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
