@learncard/network-plugin 3.2.2 → 4.0.0
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 +18 -123
- package/dist/lcn-plugin.cjs.development.cjs +986 -79
- package/dist/lcn-plugin.cjs.development.cjs.map +3 -3
- package/dist/lcn-plugin.cjs.production.min.cjs +29 -29
- package/dist/lcn-plugin.cjs.production.min.cjs.map +3 -3
- package/dist/lcn-plugin.esm.js +992 -81
- package/dist/lcn-plugin.esm.js.map +3 -3
- package/dist/plugin.d.ts.map +1 -1
- package/dist/test/holder-send.test.d.ts +2 -0
- package/dist/test/holder-send.test.d.ts.map +1 -0
- package/dist/types.d.ts +95 -12
- package/dist/types.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/plugin.ts +604 -38
- package/src/test/campaigns.test.ts +87 -1
- package/src/test/holder-send.test.ts +735 -0
- package/src/test/index.test.ts +71 -0
- package/src/test/refresh-send.test.ts +149 -4
- package/src/types.ts +122 -10
package/README.md
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
[<img src="https://user-images.githubusercontent.com/2185016/190510561-294db809-09fd-4771-9749-6c0e0f4144fd.png" width="215"/>](https://learncard.com)
|
|
2
2
|
|
|
3
|
-
# @learncard/
|
|
3
|
+
# @learncard/network-plugin
|
|
4
4
|
|
|
5
|
-
[](https://www.npmjs.com/package/@learncard/core)
|
|
5
|
+
[](https://www.npmjs.com/package/@learncard/network-plugin)
|
|
6
|
+
[](https://www.npmjs.com/package/@learncard/network-plugin)
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
Connects a LearnCard to LearnCard Network (profiles, connections, boosts, consent flows) and adds Boost verification against a trusted registry.
|
|
10
9
|
|
|
11
10
|
## Documentation
|
|
12
11
|
|
|
@@ -16,131 +15,31 @@ https://docs.learncard.com
|
|
|
16
15
|
## Install
|
|
17
16
|
|
|
18
17
|
```bash
|
|
19
|
-
bun add @learncard/
|
|
18
|
+
bun add @learncard/init @learncard/network-plugin
|
|
20
19
|
```
|
|
21
20
|
|
|
22
21
|
## Usage
|
|
23
22
|
|
|
24
|
-
|
|
23
|
+
This package exports `getLearnCardNetworkPlugin` and `getVerifyBoostPlugin`.
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
```ts
|
|
26
|
+
import { initLearnCard } from '@learncard/init';
|
|
27
|
+
import { getLearnCardNetworkPlugin, getVerifyBoostPlugin } from '@learncard/network-plugin';
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
import { initLearnCard } from '@learncard/core';
|
|
29
|
+
const learnCard = await initLearnCard({ seed: 'a'.repeat(64) });
|
|
32
30
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
### Acting as a Managed Profile
|
|
37
|
-
|
|
38
|
-
Pass `actAs` (a managed profile ID or `did:web`) to `getLearnCardNetworkPlugin`/`initLearnCard` to
|
|
39
|
-
send every network request on behalf of a profile you manage, via the `X-LearnCard-Act-As` header.
|
|
40
|
-
Token scope is unchanged, and the server returns `403` if you don't manage that profile.
|
|
41
|
-
|
|
42
|
-
```js
|
|
43
|
-
const wallet = await initLearnCard({ seed: 'a'.repeat(64), network: true, actAs: childProfileId });
|
|
44
|
-
// or, from an existing wallet:
|
|
45
|
-
const asChild = await wallet.invoke.actAs(childProfileId);
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
### Issuing/Verifying Credentials and Presentations
|
|
49
|
-
|
|
50
|
-
#### Issue a credential
|
|
51
|
-
|
|
52
|
-
```js
|
|
53
|
-
// Grab a test VC, or create your own!
|
|
54
|
-
const unsignedVc = await wallet.invoke.getTestVc();
|
|
55
|
-
|
|
56
|
-
const vc = await wallet.invoke.issueCredential(unsignedVc);
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
#### Verify a credential
|
|
60
|
-
|
|
61
|
-
```js
|
|
62
|
-
const result = await wallet.invoke.verifyCredential(vc, {}, true);
|
|
63
|
-
|
|
64
|
-
if (result.warnings.length > 0) console.error('Verification warnings:', result.warnings);
|
|
65
|
-
|
|
66
|
-
if (result.errors.length > 0) console.error('This credential is not valid!', result.errors);
|
|
67
|
-
else console.log('This credential is valid!');
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
#### Issue a presentation
|
|
71
|
-
|
|
72
|
-
```js
|
|
73
|
-
const vp = await wallet.invoke.issuePresentation(vc);
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
#### Verify a presentation
|
|
77
|
-
|
|
78
|
-
```js
|
|
79
|
-
const result = await wallet.invoke.verifyPresentation(vp);
|
|
80
|
-
|
|
81
|
-
if (result.warnings.length > 0) console.error('Verification warnings:', result.warnings);
|
|
82
|
-
|
|
83
|
-
if (result.errors.length > 0) console.error('This presentation is not valid!', result.errors);
|
|
84
|
-
else console.log('This presentation is valid!');
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
### Storing/Retrieving/Sending Credentials
|
|
88
|
-
|
|
89
|
-
#### Ceramic/IDX
|
|
90
|
-
|
|
91
|
-
To maintain co-ownership of credentials, it is best to store credentials in a public place, and then
|
|
92
|
-
store references to that public place. While this is not the only way to store credentials (and is
|
|
93
|
-
also definitely not a silver bullet! E.g. credentials containing private data), it is the opinion of
|
|
94
|
-
this library that it should be used by default. As a result, instantiating a wallet, will
|
|
95
|
-
automatically connect you to WeLibrary's ceramic node, and allow you to publish and retrieve
|
|
96
|
-
credentials there using IDX.
|
|
97
|
-
|
|
98
|
-
#### Publish Credential
|
|
99
|
-
|
|
100
|
-
After signing a VC, you may choose to publish that credential to Ceramic. Doing so will return a
|
|
101
|
-
stream ID, which you may share to the recipient. That stream ID can then be used to resolve the
|
|
102
|
-
issued credential. This means both the issuer and recipient may store the _stream ID_ instead of the
|
|
103
|
-
credential itself.
|
|
104
|
-
|
|
105
|
-
```js
|
|
106
|
-
const uri = await wallet.store.Ceramic.upload(vc);
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
#### Reading From Ceramic
|
|
110
|
-
|
|
111
|
-
To resolve a VC from a stream ID, simply call the `readFromCeramic` method:
|
|
112
|
-
|
|
113
|
-
```js
|
|
114
|
-
const vcFromCeramic = await wallet.read.get(uri);
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
#### Adding a Credential to a Wallet
|
|
31
|
+
// Verify Boost credentials against a trusted registry (URL optional)
|
|
32
|
+
const verifyLearnCard = await learnCard.addPlugin(await getVerifyBoostPlugin(learnCard));
|
|
118
33
|
|
|
119
|
-
|
|
120
|
-
|
|
34
|
+
// Talk to LearnCard Network
|
|
35
|
+
const networkLearnCard = await verifyLearnCard.addPlugin(
|
|
36
|
+
await getLearnCardNetworkPlugin(verifyLearnCard, 'https://network.learncard.com/trpc')
|
|
37
|
+
);
|
|
121
38
|
|
|
122
|
-
|
|
123
|
-
await wallet.index.IDX.add({ uri, id: 'Test VC' });
|
|
39
|
+
const profile = await networkLearnCard.invoke.getProfile();
|
|
124
40
|
```
|
|
125
41
|
|
|
126
|
-
|
|
127
|
-
wallet's secret key. You can think of this as acting like the wallet's personal storage.
|
|
128
|
-
|
|
129
|
-
#### Getting a credential from the Wallet
|
|
130
|
-
|
|
131
|
-
After calling `addCredential`, you can use the bespoke title to retrieve that credential at any time
|
|
132
|
-
|
|
133
|
-
```js
|
|
134
|
-
const record = (await wallet.index.all.get()).find(record => record.id === 'Test VC');
|
|
135
|
-
const vcFromIdx = await wallet.read.get(record.uri);
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
Alternatively, you can get an array of _all_ credentials you have added using `getCredentials`
|
|
139
|
-
|
|
140
|
-
```js
|
|
141
|
-
const uris = (await wallet.index.all.get()).map(record => record.uri);
|
|
142
|
-
const vcs = await Promise.all(uris.map(async uri => wallet.read.get(uri)));
|
|
143
|
-
```
|
|
42
|
+
Most apps don't wire this by hand: `initLearnCard({ seed, network: true })` (or `{ apiKey, network: true }`) adds both plugins and points at `https://network.learncard.com/trpc`. `getLearnCardNetworkPlugin` also takes an options object (e.g. `actAs`) or an API token as its third argument.
|
|
144
43
|
|
|
145
44
|
## Contributing
|
|
146
45
|
|
|
@@ -148,10 +47,6 @@ Pull requests are welcome. For major changes, please open an issue first to disc
|
|
|
148
47
|
|
|
149
48
|
Please make sure to update tests as appropriate.
|
|
150
49
|
|
|
151
|
-
## Who is Learning Economy Foundation?
|
|
152
|
-
|
|
153
|
-
**[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:
|
|
154
|
-
|
|
155
50
|
## License
|
|
156
51
|
|
|
157
52
|
MIT © [Learning Economy Foundation](https://github.com/Learning-Economy-Foundation)
|