@learncard/didkit-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/didkit/didkit_wasm.d.ts +251 -0
- package/dist/didkit/didkit_wasm.js +1135 -0
- package/dist/didkit/didkit_wasm_bg.wasm +0 -0
- package/dist/didkit/didkit_wasm_bg.wasm.d.ts +43 -0
- package/dist/didkit/index.d.ts +4 -0
- package/dist/didkit-plugin.cjs.development.js +849 -0
- package/dist/didkit-plugin.cjs.development.js.map +7 -0
- package/dist/didkit-plugin.cjs.production.min.js +3 -0
- package/dist/didkit-plugin.cjs.production.min.js.map +7 -0
- package/dist/didkit-plugin.esm.js +828 -0
- package/dist/didkit-plugin.esm.js.map +7 -0
- package/dist/didkit_wasm.d.ts +251 -0
- package/dist/didkit_wasm.js +1135 -0
- package/dist/didkit_wasm_bg.wasm +0 -0
- package/dist/didkit_wasm_bg.wasm.d.ts +43 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -0
- package/dist/plugin.d.ts +7 -0
- package/dist/types.d.ts +40 -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)
|
@@ -0,0 +1,251 @@
|
|
1
|
+
/* tslint:disable */
|
2
|
+
/* eslint-disable */
|
3
|
+
/**
|
4
|
+
* @returns {string}
|
5
|
+
*/
|
6
|
+
export function getVersion(): string;
|
7
|
+
/**
|
8
|
+
* @param {string} did
|
9
|
+
* @param {string} input_metadata
|
10
|
+
* @returns {Promise<any>}
|
11
|
+
*/
|
12
|
+
export function didResolver(did: string, input_metadata: string): Promise<any>;
|
13
|
+
/**
|
14
|
+
* @param {string} did
|
15
|
+
* @param {string} input_metadata
|
16
|
+
* @returns {Promise<any>}
|
17
|
+
*/
|
18
|
+
export function resolveDID(did: string, input_metadata: string): Promise<any>;
|
19
|
+
/**
|
20
|
+
* @returns {string}
|
21
|
+
*/
|
22
|
+
export function generateEd25519Key(): string;
|
23
|
+
/**
|
24
|
+
* @param {Uint8Array} bytes
|
25
|
+
* @returns {string}
|
26
|
+
*/
|
27
|
+
export function generateEd25519KeyFromBytes(bytes: Uint8Array): string;
|
28
|
+
/**
|
29
|
+
* @returns {string}
|
30
|
+
*/
|
31
|
+
export function generateSecp256k1Key(): string;
|
32
|
+
/**
|
33
|
+
* @param {Uint8Array} bytes
|
34
|
+
* @returns {string}
|
35
|
+
*/
|
36
|
+
export function generateSecp256k1KeyFromBytes(bytes: Uint8Array): string;
|
37
|
+
/**
|
38
|
+
* @param {string} method_pattern
|
39
|
+
* @param {string} jwk
|
40
|
+
* @returns {string}
|
41
|
+
*/
|
42
|
+
export function keyToDID(method_pattern: string, jwk: string): string;
|
43
|
+
/**
|
44
|
+
* @param {string} method_pattern
|
45
|
+
* @param {string} jwk
|
46
|
+
* @returns {Promise<any>}
|
47
|
+
*/
|
48
|
+
export function keyToVerificationMethod(method_pattern: string, jwk: string): Promise<any>;
|
49
|
+
/**
|
50
|
+
* @param {string} did
|
51
|
+
* @returns {Promise<any>}
|
52
|
+
*/
|
53
|
+
export function didToVerificationMethod(did: string): Promise<any>;
|
54
|
+
/**
|
55
|
+
* @param {string} credential
|
56
|
+
* @param {string} proof_options
|
57
|
+
* @param {string} key
|
58
|
+
* @returns {Promise<any>}
|
59
|
+
*/
|
60
|
+
export function issueCredential(credential: string, proof_options: string, key: string): Promise<any>;
|
61
|
+
/**
|
62
|
+
* @param {string} credential
|
63
|
+
* @param {string} linked_data_proof_options
|
64
|
+
* @param {string} public_key
|
65
|
+
* @returns {Promise<any>}
|
66
|
+
*/
|
67
|
+
export function prepareIssueCredential(credential: string, linked_data_proof_options: string, public_key: string): Promise<any>;
|
68
|
+
/**
|
69
|
+
* @param {string} credential
|
70
|
+
* @param {string} preparation
|
71
|
+
* @param {string} signature
|
72
|
+
* @returns {Promise<any>}
|
73
|
+
*/
|
74
|
+
export function completeIssueCredential(credential: string, preparation: string, signature: string): Promise<any>;
|
75
|
+
/**
|
76
|
+
* @param {string} vc
|
77
|
+
* @param {string} proof_options
|
78
|
+
* @returns {Promise<any>}
|
79
|
+
*/
|
80
|
+
export function verifyCredential(vc: string, proof_options: string): Promise<any>;
|
81
|
+
/**
|
82
|
+
* @param {string} presentation
|
83
|
+
* @param {string} proof_options
|
84
|
+
* @param {string} key
|
85
|
+
* @returns {Promise<any>}
|
86
|
+
*/
|
87
|
+
export function issuePresentation(presentation: string, proof_options: string, key: string): Promise<any>;
|
88
|
+
/**
|
89
|
+
* @param {string} presentation
|
90
|
+
* @param {string} linked_data_proof_options
|
91
|
+
* @param {string} public_key
|
92
|
+
* @returns {Promise<any>}
|
93
|
+
*/
|
94
|
+
export function prepareIssuePresentation(presentation: string, linked_data_proof_options: string, public_key: string): Promise<any>;
|
95
|
+
/**
|
96
|
+
* @param {string} presentation
|
97
|
+
* @param {string} preparation
|
98
|
+
* @param {string} signature
|
99
|
+
* @returns {Promise<any>}
|
100
|
+
*/
|
101
|
+
export function completeIssuePresentation(presentation: string, preparation: string, signature: string): Promise<any>;
|
102
|
+
/**
|
103
|
+
* @param {string} vp
|
104
|
+
* @param {string} proof_options
|
105
|
+
* @returns {Promise<any>}
|
106
|
+
*/
|
107
|
+
export function verifyPresentation(vp: string, proof_options: string): Promise<any>;
|
108
|
+
/**
|
109
|
+
* @param {string} holder
|
110
|
+
* @param {string} linked_data_proof_options
|
111
|
+
* @param {string} key
|
112
|
+
* @returns {Promise<any>}
|
113
|
+
*/
|
114
|
+
export function DIDAuth(holder: string, linked_data_proof_options: string, key: string): Promise<any>;
|
115
|
+
/**
|
116
|
+
* @param {string} tz
|
117
|
+
* @returns {Promise<any>}
|
118
|
+
*/
|
119
|
+
export function JWKFromTezos(tz: string): Promise<any>;
|
120
|
+
/**
|
121
|
+
* @param {string} capability
|
122
|
+
* @param {string} linked_data_proof_options
|
123
|
+
* @param {string} parents
|
124
|
+
* @param {string} key
|
125
|
+
* @returns {Promise<any>}
|
126
|
+
*/
|
127
|
+
export function delegateCapability(capability: string, linked_data_proof_options: string, parents: string, key: string): Promise<any>;
|
128
|
+
/**
|
129
|
+
* @param {string} capability
|
130
|
+
* @param {string} linked_data_proof_options
|
131
|
+
* @param {string} parents
|
132
|
+
* @param {string} public_key
|
133
|
+
* @returns {Promise<any>}
|
134
|
+
*/
|
135
|
+
export function prepareDelegateCapability(capability: string, linked_data_proof_options: string, parents: string, public_key: string): Promise<any>;
|
136
|
+
/**
|
137
|
+
* @param {string} capability
|
138
|
+
* @param {string} preparation
|
139
|
+
* @param {string} signature
|
140
|
+
* @returns {Promise<any>}
|
141
|
+
*/
|
142
|
+
export function completeDelegateCapability(capability: string, preparation: string, signature: string): Promise<any>;
|
143
|
+
/**
|
144
|
+
* @param {string} delegation
|
145
|
+
* @returns {Promise<any>}
|
146
|
+
*/
|
147
|
+
export function verifyDelegation(delegation: string): Promise<any>;
|
148
|
+
/**
|
149
|
+
* @param {string} invocation
|
150
|
+
* @param {string} target_id
|
151
|
+
* @param {string} linked_data_proof_options
|
152
|
+
* @param {string} key
|
153
|
+
* @returns {Promise<any>}
|
154
|
+
*/
|
155
|
+
export function invokeCapability(invocation: string, target_id: string, linked_data_proof_options: string, key: string): Promise<any>;
|
156
|
+
/**
|
157
|
+
* @param {string} invocation
|
158
|
+
* @param {string} target_id
|
159
|
+
* @param {string} linked_data_proof_options
|
160
|
+
* @param {string} public_key
|
161
|
+
* @returns {Promise<any>}
|
162
|
+
*/
|
163
|
+
export function prepareInvokeCapability(invocation: string, target_id: string, linked_data_proof_options: string, public_key: string): Promise<any>;
|
164
|
+
/**
|
165
|
+
* @param {string} invocation
|
166
|
+
* @param {string} preparation
|
167
|
+
* @param {string} signature
|
168
|
+
* @returns {Promise<any>}
|
169
|
+
*/
|
170
|
+
export function completeInvokeCapability(invocation: string, preparation: string, signature: string): Promise<any>;
|
171
|
+
/**
|
172
|
+
* @param {string} invocation
|
173
|
+
* @returns {Promise<any>}
|
174
|
+
*/
|
175
|
+
export function verifyInvocationSignature(invocation: string): Promise<any>;
|
176
|
+
/**
|
177
|
+
* @param {string} invocation
|
178
|
+
* @param {string} delegation
|
179
|
+
* @returns {Promise<any>}
|
180
|
+
*/
|
181
|
+
export function verifyInvocation(invocation: string, delegation: string): Promise<any>;
|
182
|
+
/**
|
183
|
+
* @param {string} url
|
184
|
+
* @returns {Promise<any>}
|
185
|
+
*/
|
186
|
+
export function contextLoader(url: string): Promise<any>;
|
187
|
+
|
188
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
189
|
+
|
190
|
+
export interface InitOutput {
|
191
|
+
readonly memory: WebAssembly.Memory;
|
192
|
+
readonly getVersion: (a: number) => void;
|
193
|
+
readonly didResolver: (a: number, b: number, c: number, d: number) => number;
|
194
|
+
readonly resolveDID: (a: number, b: number, c: number, d: number) => number;
|
195
|
+
readonly generateEd25519Key: (a: number) => void;
|
196
|
+
readonly generateEd25519KeyFromBytes: (a: number, b: number, c: number) => void;
|
197
|
+
readonly generateSecp256k1Key: (a: number) => void;
|
198
|
+
readonly generateSecp256k1KeyFromBytes: (a: number, b: number, c: number) => void;
|
199
|
+
readonly keyToDID: (a: number, b: number, c: number, d: number, e: number) => void;
|
200
|
+
readonly keyToVerificationMethod: (a: number, b: number, c: number, d: number) => number;
|
201
|
+
readonly didToVerificationMethod: (a: number, b: number) => number;
|
202
|
+
readonly issueCredential: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
|
203
|
+
readonly prepareIssueCredential: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
|
204
|
+
readonly completeIssueCredential: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
|
205
|
+
readonly verifyCredential: (a: number, b: number, c: number, d: number) => number;
|
206
|
+
readonly issuePresentation: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
|
207
|
+
readonly prepareIssuePresentation: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
|
208
|
+
readonly completeIssuePresentation: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
|
209
|
+
readonly verifyPresentation: (a: number, b: number, c: number, d: number) => number;
|
210
|
+
readonly DIDAuth: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
|
211
|
+
readonly JWKFromTezos: (a: number, b: number) => number;
|
212
|
+
readonly delegateCapability: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => number;
|
213
|
+
readonly prepareDelegateCapability: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => number;
|
214
|
+
readonly completeDelegateCapability: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
|
215
|
+
readonly verifyDelegation: (a: number, b: number) => number;
|
216
|
+
readonly invokeCapability: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => number;
|
217
|
+
readonly prepareInvokeCapability: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => number;
|
218
|
+
readonly completeInvokeCapability: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
|
219
|
+
readonly verifyInvocationSignature: (a: number, b: number) => number;
|
220
|
+
readonly verifyInvocation: (a: number, b: number, c: number, d: number) => number;
|
221
|
+
readonly contextLoader: (a: number, b: number) => number;
|
222
|
+
readonly didkit_error_message: () => number;
|
223
|
+
readonly didkit_error_code: () => number;
|
224
|
+
readonly __wbindgen_malloc: (a: number) => number;
|
225
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number) => number;
|
226
|
+
readonly __wbindgen_export_2: WebAssembly.Table;
|
227
|
+
readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__hf6251ee6687a20b8: (a: number, b: number, c: number) => void;
|
228
|
+
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
|
229
|
+
readonly __wbindgen_free: (a: number, b: number) => void;
|
230
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
231
|
+
readonly wasm_bindgen__convert__closures__invoke2_mut__h63ffd509f6690aab: (a: number, b: number, c: number, d: number) => void;
|
232
|
+
}
|
233
|
+
|
234
|
+
/**
|
235
|
+
* Synchronously compiles the given `bytes` and instantiates the WebAssembly module.
|
236
|
+
*
|
237
|
+
* @param {BufferSource} bytes
|
238
|
+
*
|
239
|
+
* @returns {InitOutput}
|
240
|
+
*/
|
241
|
+
export function initSync(bytes: BufferSource): InitOutput;
|
242
|
+
|
243
|
+
/**
|
244
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
245
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
246
|
+
*
|
247
|
+
* @param {InitInput | Promise<InitInput>} module_or_path
|
248
|
+
*
|
249
|
+
* @returns {Promise<InitOutput>}
|
250
|
+
*/
|
251
|
+
export default function init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
|