@learncard/vpqr-plugin 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +21 -0
- package/README.md +140 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/types.d.ts +12 -0
- package/dist/vpqr-plugin.cjs.development.js +5432 -0
- package/dist/vpqr-plugin.cjs.development.js.map +7 -0
- package/dist/vpqr-plugin.cjs.production.min.js +24 -0
- package/dist/vpqr-plugin.cjs.production.min.js.map +7 -0
- package/dist/vpqr-plugin.esm.js +5422 -0
- package/dist/vpqr-plugin.esm.js.map +7 -0
- package/package.json +44 -0
package/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2022 Taylor Beeston <beeston.taylor@gmail.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
[<img src="https://user-images.githubusercontent.com/2185016/190510561-294db809-09fd-4771-9749-6c0e0f4144fd.png" width="215"/>](https://learncard.com)
|
2
|
+
|
3
|
+
# @learncard/core
|
4
|
+
|
5
|
+
[![npm version](https://img.shields.io/npm/v/@learncard/core)](https://www.npmjs.com/package/@learncard/core)
|
6
|
+
[![npm downloads](https://img.shields.io/npm/dw/@learncard/core)](https://www.npmjs.com/package/@learncard/core)
|
7
|
+
[![vulnerabilities](https://img.shields.io/snyk/vulnerabilities/npm/@learncard/core)](https://www.npmjs.com/package/@learncard/core)
|
8
|
+
|
9
|
+
The LearnCard Core is a pluggable, open-source, universal digital wallet to enable any individual or organization to seamlessly **issue, earn, store, share, and spend currency and credentials** built for the future of education and work.
|
10
|
+
|
11
|
+
## Documentation
|
12
|
+
All LearnCard documentation can be found at:
|
13
|
+
https://docs.learncard.com
|
14
|
+
|
15
|
+
## Install
|
16
|
+
|
17
|
+
```bash
|
18
|
+
pnpm i @learncard/core
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Instantiation
|
24
|
+
|
25
|
+
Instantiate a wallet using `initLearnCard`. This method accepts a unique identifier string that is
|
26
|
+
up to 64 characters long. If it is less than 64 characters, `initLearnCard` will pad the start of
|
27
|
+
the string with 0's until it is 64 characters long.
|
28
|
+
|
29
|
+
```js
|
30
|
+
import { initLearnCard } from "@learncard/core";
|
31
|
+
|
32
|
+
const wallet = await initLearnCard({ seed: 'a'.repeat(64) });
|
33
|
+
```
|
34
|
+
|
35
|
+
### Issuing/Verifying Credentials and Presentations
|
36
|
+
|
37
|
+
#### Issue a credential
|
38
|
+
```js
|
39
|
+
// Grab a test VC, or create your own!
|
40
|
+
const unsignedVc = await wallet.invoke.getTestVc();
|
41
|
+
|
42
|
+
const vc = await wallet.invoke.issueCredential(unsignedVc);
|
43
|
+
```
|
44
|
+
|
45
|
+
#### Verify a credential
|
46
|
+
```js
|
47
|
+
const result = await wallet.invoke.verifyCredential(vc, {}, true);
|
48
|
+
|
49
|
+
if (result.warnings.length > 0) console.error('Verification warnings:', result.warnings);
|
50
|
+
|
51
|
+
if (result.errors.length > 0) console.error('This credential is not valid!', result.errors);
|
52
|
+
else console.log('This credential is valid!');
|
53
|
+
```
|
54
|
+
|
55
|
+
#### Issue a presentation
|
56
|
+
```js
|
57
|
+
const vp = await wallet.invoke.issuePresentation(vc);
|
58
|
+
```
|
59
|
+
|
60
|
+
#### Verify a presentation
|
61
|
+
```js
|
62
|
+
const result = await wallet.invoke.verifyPresentation(vp);
|
63
|
+
|
64
|
+
if (result.warnings.length > 0) console.error('Verification warnings:', result.warnings);
|
65
|
+
|
66
|
+
if (result.errors.length > 0) console.error('This presentation is not valid!', result.errors);
|
67
|
+
else console.log('This presentation is valid!');
|
68
|
+
```
|
69
|
+
|
70
|
+
### Storing/Retrieving/Sending Credentials
|
71
|
+
|
72
|
+
#### Ceramic/IDX
|
73
|
+
|
74
|
+
To maintain co-ownership of credentials, it is best to store credentials in a public place, and then
|
75
|
+
store references to that public place. While this is not the only way to store credentials (and is
|
76
|
+
also definitely not a silver bullet! E.g. credentials containing private data), it is the opinion of
|
77
|
+
this library that it should be used by default. As a result, instantiating a wallet, will
|
78
|
+
automatically connect you to WeLibrary's ceramic node, and allow you to publish and retrieve
|
79
|
+
credentials there using IDX.
|
80
|
+
|
81
|
+
#### Publish Credential
|
82
|
+
|
83
|
+
After signing a VC, you may choose to publish that credential to Ceramic. Doing so will return a
|
84
|
+
stream ID, which you may share to the recipient. That stream ID can then be used to resolve the
|
85
|
+
issued credential. This means both the issuer and recipient may store the _stream ID_ instead of the
|
86
|
+
credential itself.
|
87
|
+
|
88
|
+
```js
|
89
|
+
const uri = await wallet.store.Ceramic.upload(vc);
|
90
|
+
```
|
91
|
+
|
92
|
+
#### Reading From Ceramic
|
93
|
+
|
94
|
+
To resolve a VC from a stream ID, simply call the `readFromCeramic` method:
|
95
|
+
|
96
|
+
```js
|
97
|
+
const vcFromCeramic = await wallet.read.get(uri);
|
98
|
+
```
|
99
|
+
|
100
|
+
#### Adding a Credential to a Wallet
|
101
|
+
|
102
|
+
After receiving a streamID, you can _persist_ that streamID by calling `addCredential`, and giving
|
103
|
+
the credential a bespoke title
|
104
|
+
|
105
|
+
```js
|
106
|
+
await wallet.index.IDX.add({ uri, id: 'Test VC' });
|
107
|
+
```
|
108
|
+
|
109
|
+
This will add the streamId, which can be used to resolve the verifiable credential to IDX using the
|
110
|
+
wallet's secret key. You can think of this as acting like the wallet's personal storage.
|
111
|
+
|
112
|
+
#### Getting a credential from the Wallet
|
113
|
+
|
114
|
+
After calling `addCredential`, you can use the bespoke title to retrieve that credential at any time
|
115
|
+
|
116
|
+
```js
|
117
|
+
const record = (await wallet.index.all.get()).find(record => record.id === 'Test VC');
|
118
|
+
const vcFromIdx = await wallet.read.get(record.uri);
|
119
|
+
```
|
120
|
+
|
121
|
+
Alternatively, you can get an array of _all_ credentials you have added using `getCredentials`
|
122
|
+
|
123
|
+
```js
|
124
|
+
const uris = (await wallet.index.all.get()).map(record => record.uri);
|
125
|
+
const vcs = await Promise.all(uris.map(async uri => wallet.read.get(uri)));
|
126
|
+
```
|
127
|
+
|
128
|
+
## Contributing
|
129
|
+
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
|
130
|
+
|
131
|
+
Please make sure to update tests as appropriate.
|
132
|
+
|
133
|
+
## Who is Learning Economy Foundation?
|
134
|
+
|
135
|
+
**[Learning Economy Foundation (LEF)](https://www.learningeconomy.io)** is a 501(c)(3) non-profit organization leveraging global standards and web3 protocols to bring quality skills and equal opportunity to every human on earth, and address the persistent inequities that exist around the globe in education and employment. We help you build the future of education and work with:
|
136
|
+
|
137
|
+
|
138
|
+
## License
|
139
|
+
|
140
|
+
MIT © [Learning Economy Foundation](https://github.com/Learning-Economy-Foundation)
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
import { VpqrPlugin, VpqrPluginDependentMethods } from './types';
|
2
|
+
import { LearnCard } from '@learncard/core';
|
3
|
+
export * from './types';
|
4
|
+
/**
|
5
|
+
* @group Plugins
|
6
|
+
*/
|
7
|
+
export declare const getVpqrPlugin: (learnCard: LearnCard<any, any, VpqrPluginDependentMethods>) => VpqrPlugin;
|
package/dist/index.js
ADDED
package/dist/types.d.ts
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
import { VP } from '@learncard/types';
|
2
|
+
import { Plugin } from '@learncard/core';
|
3
|
+
/** @group VPQR Plugin */
|
4
|
+
export type VpqrPluginMethods = {
|
5
|
+
vpFromQrCode: (text: string) => Promise<VP>;
|
6
|
+
vpToQrCode: (vp: VP) => Promise<string>;
|
7
|
+
};
|
8
|
+
/** @group VPQR Plugin */
|
9
|
+
export type VpqrPluginDependentMethods = {
|
10
|
+
contextLoader: (url: string) => Promise<Record<string, any>>;
|
11
|
+
};
|
12
|
+
export type VpqrPlugin = Plugin<'Vpqr', any, VpqrPluginMethods, any, VpqrPluginDependentMethods>;
|