@learncard/core 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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,128 @@
1
+ # learn-card-core
2
+
3
+ >
4
+
5
+ [![npm version](https://img.shields.io/npm/v/learn-card-core)](https://www.npmjs.com/package/learn-card-core)
6
+ [![npm downloads](https://img.shields.io/npm/dw/learn-card-core)](https://www.npmjs.com/package/learn-card-core)
7
+ [![vulnerabilities](https://img.shields.io/snyk/vulnerabilities/npm/learn-card-core)](https://www.npmjs.com/package/learn-card-core)
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pnpm i learn-card-core
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ### Instantiation
18
+
19
+ Instantiate a wallet using `walletFromKey`. This method accepts a unique identifier string that is
20
+ up to 64 characters long. If it is less than 64 characters, `walletFromKey` will pad the start of
21
+ the string with 0's until it is 64 characters long.
22
+
23
+ ```js
24
+ import { walletFromKey } from "learn-card-core";
25
+
26
+ const wallet = await walletFromKey('unique-identifier-that-is-up-to-and-preferably64-characters-long');
27
+ ```
28
+
29
+ ### Issuing/Verifying Credentials and Presentations
30
+
31
+ #### Issue a credential
32
+ ```js
33
+ // Grab a test VC, or create your own!
34
+ const unsignedVc = await wallet.getTestVc();
35
+
36
+ const vc = await wallet.issueCredential(unsignedVc);
37
+ ```
38
+
39
+ #### Verify a credential
40
+ ```js
41
+ const result = await wallet.verifyCredential(vc);
42
+
43
+ if (result.warnings.length > 0) console.error('Verification warnings:', result.warnings);
44
+
45
+ if (result.errors.length > 0) console.error('This credential is not valid!', result.errors);
46
+ else console.log('This credential is valid!');
47
+ ```
48
+
49
+ #### Issue a presentation
50
+ ```js
51
+ const vp = await wallet.issuePresentation(vc);
52
+ ```
53
+
54
+ #### Verify a presentation
55
+ ```js
56
+ const result = await wallet.verifyPresentation(vp);
57
+
58
+ if (result.warnings.length > 0) console.error('Verification warnings:', result.warnings);
59
+
60
+ if (result.errors.length > 0) console.error('This presentation is not valid!', result.errors);
61
+ else console.log('This presentation is valid!');
62
+ ```
63
+
64
+ ### Storing/Retrieving/Sending Credentials
65
+
66
+ #### Ceramic/IDX
67
+
68
+ To maintain co-ownership of credentials, it is best to store credentials in a public place, and then
69
+ store references to that public place. While this is not the only way to store credentials (and is
70
+ also definitely not a silver bullet! E.g. credentials containing private data), it is the opinion of
71
+ this library that it should be used by default. As a result, instantiating a wallet, will
72
+ automatically connect you to WeLibrary's ceramic node, and allow you to publish and retrieve
73
+ credentials there using IDX.
74
+
75
+ #### Publish Credential
76
+
77
+ After signing a VC, you may choose to publish that credential to Ceramic. Doing so will return a
78
+ stream ID, which you may share to the recipient. That stream ID can then be used to resolve the
79
+ issued credential. This means both the issuer and recipient may store the _stream ID_ instead of the
80
+ credential itself.
81
+
82
+ ```js
83
+ const streamId = await wallet.publishCredential(vc);
84
+ ```
85
+
86
+ #### Reading From Ceramic
87
+
88
+ To resolve a VC from a stream ID, simply call the `readFromCeramic` method:
89
+
90
+ ```js
91
+ const vcFromCeramic = await wallet.readFromCeramic(streamId);
92
+ ```
93
+
94
+ #### Adding a Credential to a Wallet
95
+
96
+ After receiving a streamID, you can _persist_ that streamID by calling `addCredential`, and giving
97
+ the credential a bespoke title
98
+
99
+ ```js
100
+ await wallet.addCredential({ id: streamId, title: 'Test VC' });
101
+ ```
102
+
103
+ This will add the streamId, which can be used to resolve the verifiable credential to IDX using the
104
+ wallet's secret key. You can think of this as acting like the wallet's personal storage.
105
+
106
+ #### Getting a credential from the Wallet
107
+
108
+ After calling `addCredential`, you can use the bespoke title to retrieve that credential at any time
109
+
110
+ ```js
111
+ const vcFromIdx = await wallet.getCredential('Test VC');
112
+ ```
113
+
114
+ Alternatively, you can get an array of _all_ credentials you have added using `getCredentials`
115
+
116
+ ```js
117
+ const vcs = await wallet.getCredentials();
118
+ ```
119
+
120
+ ## Further Reading
121
+
122
+ [Read the official docs here!](https://app.gitbook.com/o/6uDv1QDlxaaZC7i8EaGb/s/FXvEJ9j3Vf3FW5Nc557n/)
123
+
124
+ ## License
125
+
126
+ MIT © [Taylor Beeston <beeston.taylor@gmail.com>](https://github.com/TaylorBeeston)
127
+
128
+ [Created with aqu 🌊](https://github.com/ArtiomTr/aqu#readme)
package/dist/README.md ADDED
@@ -0,0 +1,89 @@
1
+ [![](https://img.shields.io/npm/v/@spruceid/didkit-wasm?label=%40spruceid%2Fdidkit-wasm&logo=npm)](https://www.npmjs.com/package/@spruceid/didkit-wasm) [![](https://img.shields.io/npm/v/@spruceid/didkit-wasm-node?label=%40spruceid%2Fdidkit-wasm-node&logo=npm)](https://www.npmjs.com/package/@spruceid/didkit-wasm-node)
2
+ <!-- Might want those badge in the main README. -->
3
+
4
+ # DIDKit WASM
5
+
6
+ ## Prerequisites to Build from Source
7
+
8
+ NPM packages are available but if you would like to compile DIDKit yourself
9
+ (e.g. to enable different cryptographic backends) you will need the WASM
10
+ compiler toolchain as well as a specific build tool:
11
+
12
+ ```bash
13
+ $ rustup target add wasm32-unknown-unknown
14
+ $ cargo install wasm-pack
15
+ # OR
16
+ # $ curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
17
+ ```
18
+
19
+ ## Installation and Usage
20
+
21
+ ### Node
22
+
23
+ WASM can be used in Node.js (any recent version):
24
+ ```bash
25
+ $ npm i @spruceid/didkit-wasm-node
26
+ ```
27
+
28
+ Or build it from source:
29
+ ```bash
30
+ $ wasm-pack build --target nodejs
31
+ ```
32
+
33
+ ### Web Frameworks (Bundled)
34
+
35
+ WASM can be used with web frameworks and bundlers like Webpack:
36
+ ```bash
37
+ $ npm i @spruceid/didkit-wasm
38
+ ```
39
+
40
+ Or build it from source:
41
+ ```bash
42
+ $ wasm-pack build
43
+ ```
44
+
45
+ > If Webpack doesn't work with the default configuration, you can have a look at
46
+ > our configuration for
47
+ > [tzprofiles](https://github.com/spruceid/tzprofiles/blob/main/dapp/webpack.config.js).
48
+
49
+ ### Vanilla Javascript
50
+
51
+ WASM can be used with plain Javascript with newer browsers. As it cannot be used
52
+ as a NPM package you have to build it manually:
53
+ ```bash
54
+ $ wasm-pack build --target web
55
+ ```
56
+
57
+ The manual tests in `test/` serve as an example on how to import DIDKit.
58
+
59
+ ## Tests
60
+
61
+ The `test/` directory contains manual tests to run in the browser. Instructions
62
+ are in the README of the directory.
63
+
64
+ ## Non-Default Compilation
65
+
66
+ _**The current version of the `ring` crate does not provide all the symbols
67
+ needed to run on the browser, see DEPS.md**_
68
+
69
+ To compile all features plus `wasm32_c` on `ring`, a C compiler is needed, see
70
+ [spruceid/ssi](https://github.com/spruceid/didkit/tree/wasm):
71
+
72
+ On Ubuntu this one option is to install `clang` and `llvm`:
73
+ ```bash
74
+ sudo apt install clang-10 llvm-10
75
+ ```
76
+
77
+ Then to compile with all features:
78
+ ```bash
79
+ TARGET_CC=clang-10 TARGET_AR=llvm-ar-10 wasm-pack build --out-dir pkg
80
+ ```
81
+
82
+ To use a custom subset of features:
83
+ ```bash
84
+ wasm-pack build --out-dir pkg -- --no-default-features --features=issue # issue credential/presentation
85
+ wasm-pack build --out-dir pkg -- --no-default-features --features=verify # verify credential/presentation
86
+ wasm-pack build --out-dir pkg -- --no-default-features --features=credential # issue/verify credential
87
+ wasm-pack build --out-dir pkg -- --no-default-features --features=presentation # issue/verify presentation
88
+ ```
89
+ *don't forget to add `TARGET_CC` and `TARGET_AR` if using `ring` with `wasm32_c`*