@learncard/core 9.3.2 → 9.3.4
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +29 -14
- package/package.json +3 -3
package/README.md
CHANGED
@@ -67,18 +67,14 @@ if (result.errors.length > 0) console.error('This presentation is not valid!', r
|
|
67
67
|
else console.log('This presentation is valid!');
|
68
68
|
```
|
69
69
|
|
70
|
-
### Storing/Retrieving/
|
71
|
-
|
72
|
-
#### Ceramic/IDX
|
70
|
+
### Storing/Retrieving/Publishing Credentials with LearnCloud
|
73
71
|
|
74
72
|
To maintain co-ownership of credentials, it is best to store credentials in a public place, and then
|
75
73
|
store references to that public place. While this is not the only way to store credentials (and is
|
76
74
|
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.
|
78
|
-
automatically connect you to WeLibrary's ceramic node, and allow you to publish and retrieve
|
79
|
-
credentials there using IDX.
|
75
|
+
this library that it should be used by default.
|
80
76
|
|
81
|
-
#### Publish Credential
|
77
|
+
#### Publish Credential
|
82
78
|
|
83
79
|
After signing a VC, you may choose to publish that credential to Ceramic. Doing so will return a
|
84
80
|
stream ID, which you may share to the recipient. That stream ID can then be used to resolve the
|
@@ -86,15 +82,34 @@ issued credential. This means both the issuer and recipient may store the _strea
|
|
86
82
|
credential itself.
|
87
83
|
|
88
84
|
```js
|
89
|
-
|
85
|
+
|
86
|
+
// Issuer
|
87
|
+
|
88
|
+
const holderDid = 'did:key:z6MknqnHBn4Rx64gH4Dy1qjmaHjxFjaNG1WioKvQuXKhEKL5'
|
89
|
+
const uvc = learnCard.invoke.newCredential({ subject: holderDid });
|
90
|
+
const vc = await learnCard.invoke.issueCredential(uvc);
|
91
|
+
const uri = await learnCard.store.LearnCloud.upload(vc);
|
92
|
+
|
93
|
+
// Holder
|
94
|
+
|
95
|
+
const credential = await learnCard.read.get(uri);
|
96
|
+
const result = await learnCard.invoke.verifyCredential(credential);
|
97
|
+
|
98
|
+
if (result.errors.length == 0) {
|
99
|
+
await learnCard.index.LearnCloud.add({ uri, id: 'test' });
|
100
|
+
}
|
101
|
+
|
90
102
|
```
|
91
103
|
|
92
|
-
#### Reading From
|
104
|
+
#### Reading From LearnCloud
|
93
105
|
|
94
|
-
To resolve a VC from a stream ID, simply call the `readFromCeramic` method:
|
95
106
|
|
96
107
|
```js
|
97
|
-
|
108
|
+
|
109
|
+
const records = await learnCard.index.LearnCloud.get();
|
110
|
+
const record = records.find(({ id }) => id === 'test');
|
111
|
+
const storedCredential = await learnCard.read.get(record.uri);
|
112
|
+
|
98
113
|
```
|
99
114
|
|
100
115
|
#### Adding a Credential to a Wallet
|
@@ -103,7 +118,7 @@ After receiving a streamID, you can _persist_ that streamID by calling `addCrede
|
|
103
118
|
the credential a bespoke title
|
104
119
|
|
105
120
|
```js
|
106
|
-
await wallet.index.
|
121
|
+
await wallet.index.LearnCloud.add({ uri, id: 'Test VC' });
|
107
122
|
```
|
108
123
|
|
109
124
|
This will add the streamId, which can be used to resolve the verifiable credential to IDX using the
|
@@ -114,14 +129,14 @@ wallet's secret key. You can think of this as acting like the wallet's personal
|
|
114
129
|
After calling `addCredential`, you can use the bespoke title to retrieve that credential at any time
|
115
130
|
|
116
131
|
```js
|
117
|
-
const record = (await wallet.index.
|
132
|
+
const record = (await wallet.index.LearnCloud.get()).find(record => record.id === 'Test VC');
|
118
133
|
const vcFromIdx = await wallet.read.get(record.uri);
|
119
134
|
```
|
120
135
|
|
121
136
|
Alternatively, you can get an array of _all_ credentials you have added using `getCredentials`
|
122
137
|
|
123
138
|
```js
|
124
|
-
const uris = (await wallet.index.
|
139
|
+
const uris = (await wallet.index.LearnCloud.get()).map(record => record.uri);
|
125
140
|
const vcs = await Promise.all(uris.map(async uri => wallet.read.get(uri)));
|
126
141
|
```
|
127
142
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@learncard/core",
|
3
|
-
"version": "9.3.
|
3
|
+
"version": "9.3.4",
|
4
4
|
"description": "",
|
5
5
|
"main": "./dist/index.js",
|
6
6
|
"module": "./dist/core.esm.js",
|
@@ -29,7 +29,7 @@
|
|
29
29
|
"sift": "^17.0.1",
|
30
30
|
"ts-jest": "^29.0.3",
|
31
31
|
"tsc-alias": "^1.6.9",
|
32
|
-
"@learncard/types": "5.5.
|
32
|
+
"@learncard/types": "5.5.4"
|
33
33
|
},
|
34
34
|
"types": "./dist/index.d.ts",
|
35
35
|
"dependencies": {
|
@@ -38,7 +38,7 @@
|
|
38
38
|
"cross-fetch": "^3.1.5",
|
39
39
|
"isomorphic-fetch": "^3.0.0",
|
40
40
|
"isomorphic-webcrypto": "^2.3.8",
|
41
|
-
"@learncard/helpers": "1.0.
|
41
|
+
"@learncard/helpers": "1.0.16"
|
42
42
|
},
|
43
43
|
"scripts": {
|
44
44
|
"build": "node ./scripts/build.mjs && shx cp ./scripts/mixedEntypoint.js ./dist/index.js && tsc --p tsconfig.build.json && tsc-alias",
|