@learncard/learn-cloud-plugin 2.3.50 → 2.3.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -108
- package/dist/learn-cloud-plugin.cjs.development.cjs +605 -53
- package/dist/learn-cloud-plugin.cjs.development.cjs.map +3 -3
- package/dist/learn-cloud-plugin.cjs.production.min.cjs +23 -23
- package/dist/learn-cloud-plugin.cjs.production.min.cjs.map +3 -3
- package/dist/learn-cloud-plugin.esm.js +605 -53
- package/dist/learn-cloud-plugin.esm.js.map +3 -3
- package/dist/plugin.d.ts.map +1 -1
- package/package.json +8 -8
- package/src/plugin.ts +11 -2
- package/src/test/index.test.ts +57 -0
package/README.md
CHANGED
|
@@ -4,9 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@learncard/learn-cloud-plugin)
|
|
6
6
|
[](https://www.npmjs.com/package/@learncard/learn-cloud-plugin)
|
|
7
|
-
[](https://www.npmjs.com/package/@learncard/learn-cloud-plugin)
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
Stores, indexes, and syncs a wallet's credentials (encrypted) in LearnCloud.
|
|
10
9
|
|
|
11
10
|
## Documentation
|
|
12
11
|
|
|
@@ -16,116 +15,24 @@ https://docs.learncard.com
|
|
|
16
15
|
## Install
|
|
17
16
|
|
|
18
17
|
```bash
|
|
19
|
-
bun add @learncard/
|
|
18
|
+
bun add @learncard/init @learncard/learn-cloud-plugin
|
|
20
19
|
```
|
|
21
20
|
|
|
22
21
|
## Usage
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
This package exports `getLearnCloudPlugin`.
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
```ts
|
|
26
|
+
import { initLearnCard } from '@learncard/init';
|
|
27
|
+
import { getLearnCloudPlugin } from '@learncard/learn-cloud-plugin';
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
### Issuing/Verifying Credentials and Presentations
|
|
37
|
-
|
|
38
|
-
#### Issue a credential
|
|
39
|
-
|
|
40
|
-
```js
|
|
41
|
-
// Grab a test VC, or create your own!
|
|
42
|
-
const unsignedVc = await wallet.invoke.getTestVc();
|
|
43
|
-
|
|
44
|
-
const vc = await wallet.invoke.issueCredential(unsignedVc);
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
#### Verify a credential
|
|
48
|
-
|
|
49
|
-
```js
|
|
50
|
-
const result = await wallet.invoke.verifyCredential(vc, {}, true);
|
|
51
|
-
|
|
52
|
-
if (result.warnings.length > 0) console.error('Verification warnings:', result.warnings);
|
|
53
|
-
|
|
54
|
-
if (result.errors.length > 0) console.error('This credential is not valid!', result.errors);
|
|
55
|
-
else console.log('This credential is valid!');
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
#### Issue a presentation
|
|
59
|
-
|
|
60
|
-
```js
|
|
61
|
-
const vp = await wallet.invoke.issuePresentation(vc);
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
#### Verify a presentation
|
|
65
|
-
|
|
66
|
-
```js
|
|
67
|
-
const result = await wallet.invoke.verifyPresentation(vp);
|
|
68
|
-
|
|
69
|
-
if (result.warnings.length > 0) console.error('Verification warnings:', result.warnings);
|
|
70
|
-
|
|
71
|
-
if (result.errors.length > 0) console.error('This presentation is not valid!', result.errors);
|
|
72
|
-
else console.log('This presentation is valid!');
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
### Storing/Retrieving/Publishing Credentials with LearnCloud
|
|
76
|
-
|
|
77
|
-
To maintain co-ownership of credentials, it is best to store credentials in a public place, and then
|
|
78
|
-
store references to that public place. While this is not the only way to store credentials (and is
|
|
79
|
-
also definitely not a silver bullet! E.g. credentials containing private data), it is the opinion of
|
|
80
|
-
this library that it should be used by default.
|
|
81
|
-
|
|
82
|
-
#### Publish Credential
|
|
83
|
-
|
|
84
|
-
After signing a VC, you may choose to publish that credential to LearnCloud. Doing so will return a
|
|
85
|
-
URI, which you may share to the recipient. That URI can then be used to resolve the
|
|
86
|
-
issued credential. This means both the issuer and recipient may store the _URI_ instead of the
|
|
87
|
-
credential itself.
|
|
88
|
-
|
|
89
|
-
```js
|
|
90
|
-
const uri = await wallet.store.LearnCloud.upload(vc);
|
|
29
|
+
const learnCard = await initLearnCard({ seed: 'a'.repeat(64) });
|
|
30
|
+
const cloudLearnCard = await learnCard.addPlugin(
|
|
31
|
+
await getLearnCloudPlugin(learnCard, 'https://cloud.learncard.com/trpc')
|
|
32
|
+
);
|
|
91
33
|
```
|
|
92
34
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
To resolve a VC from a URI:
|
|
96
|
-
|
|
97
|
-
```js
|
|
98
|
-
const vcFromLearnCloud = await wallet.read.get(uri);
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
#### Adding a Credential to a Wallet
|
|
102
|
-
|
|
103
|
-
After receiving a URI, you can _persist_ that URI by calling `add` and giving
|
|
104
|
-
the credential a bespoke title
|
|
105
|
-
|
|
106
|
-
```js
|
|
107
|
-
await wallet.index.LearnCloud.add({ uri, id: 'Test VC' });
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
This will add the URI, which can be used to resolve the verifiable credential using the
|
|
111
|
-
wallet's secret key. You can think of this as acting like the wallet's personal storage.
|
|
112
|
-
|
|
113
|
-
#### Getting a credential from the Wallet
|
|
114
|
-
|
|
115
|
-
After calling `addCredential`, you can use the bespoke title to retrieve that credential at any time
|
|
116
|
-
|
|
117
|
-
```js
|
|
118
|
-
const record = (await wallet.index.LearnCloud.get()).find(record => record.id === 'Test VC');
|
|
119
|
-
const vcFromLearnCloud = await wallet.read.get(record.uri);
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
Alternatively, you can get an array of _all_ your stored credentials:
|
|
123
|
-
|
|
124
|
-
```js
|
|
125
|
-
const records = await wallet.index.LearnCloud.get();
|
|
126
|
-
const uris = records.map(record => record.uri);
|
|
127
|
-
const vcs = await Promise.all(uris.map(async uri => wallet.read.get(uri)));
|
|
128
|
-
```
|
|
35
|
+
Seed-based `initLearnCard` wallets already include it, pointed at `https://cloud.learncard.com/trpc`. Optional args after the URL: `unencryptedFields`, `unencryptedCustomFields`, `automaticallyAssociateDids` (default `true`).
|
|
129
36
|
|
|
130
37
|
## Contributing
|
|
131
38
|
|
|
@@ -133,10 +40,6 @@ Pull requests are welcome. For major changes, please open an issue first to disc
|
|
|
133
40
|
|
|
134
41
|
Please make sure to update tests as appropriate.
|
|
135
42
|
|
|
136
|
-
## Who is Learning Economy Foundation?
|
|
137
|
-
|
|
138
|
-
**[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:
|
|
139
|
-
|
|
140
43
|
## License
|
|
141
44
|
|
|
142
45
|
MIT © [Learning Economy Foundation](https://github.com/Learning-Economy-Foundation)
|