@digitalbazaar/eddsa-rdfc-2022-cryptosuite 0.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/LICENSE ADDED
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2023, Digital Bazaar, Inc.
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,169 @@
1
+ # EdDSA RDFC 2022 Data Integrity Cryptosuite _(@digitalbazaar/eddsa-rdfc-2022-cryptosuite)_
2
+
3
+ [![Build status](https://img.shields.io/github/actions/workflow/status/digitalbazaar/eddsa-rdfc-2022-cryptosuite/main.yml)](https://github.com/digitalbazaar/eddsa-rdfc-2022-cryptosuite/actions?query=workflow%3A%22Node.js+CI%22)
4
+ [![Coverage status](https://img.shields.io/codecov/c/github/digitalbazaar/eddsa-rdfc-2022-cryptosuite)](https://codecov.io/gh/digitalbazaar/eddsa-rdfc-2022-cryptosuite)
5
+ [![NPM Version](https://img.shields.io/npm/v/@digitalbazaar/eddsa-rdfc-2022-cryptosuite.svg)](https://npm.im/@digitalbazaar/eddsa-rdfc-2022-cryptosuite)
6
+
7
+ > EdDSA 2022 Data Integrity Cryptosuite for use with jsonld-signatures.
8
+
9
+ ## Table of Contents
10
+
11
+ - [Background](#background)
12
+ - [Security](#security)
13
+ - [Install](#install)
14
+ - [Usage](#usage)
15
+ - [Contribute](#contribute)
16
+ - [Commercial Support](#commercial-support)
17
+ - [License](#license)
18
+
19
+ ## Background
20
+
21
+ For use with https://github.com/digitalbazaar/jsonld-signatures v11.0 and above.
22
+
23
+ See also related specs:
24
+
25
+ * [Verifiable Credential Data Integrity](https://w3c.github.io/vc-data-integrity/)
26
+
27
+ ## Security
28
+
29
+ TBD
30
+
31
+ ## Install
32
+
33
+ - Browsers and Node.js 16+ are supported.
34
+
35
+ To install from NPM:
36
+
37
+ ```
38
+ npm install @digitalbazaar/eddsa-rdfc-2022-cryptosuite
39
+ ```
40
+
41
+ To install locally (for development):
42
+
43
+ ```
44
+ git clone https://github.com/digitalbazaar/eddsa-rdfc-2022-cryptosuite.git
45
+ cd eddsa-rdfc-2022-cryptosuite
46
+ npm install
47
+ ```
48
+
49
+ ## Usage
50
+
51
+ The following code snippet provides a complete example of digitally signing
52
+ a verifiable credential using this library:
53
+
54
+ ```javascript
55
+ import * as Ed25519Multikey from '@digitalbazaar/ed25519-multikey';
56
+ import {DataIntegrityProof} from '@digitalbazaar/data-integrity';
57
+ import {cryptosuite as eddsaRdfc2022CryptoSuite} from
58
+ '@digitalbazaar/eddsa-rdfc-2022-cryptosuite';
59
+ import jsigs from 'jsonld-signatures';
60
+ const {purposes: {AssertionProofPurpose}} = jsigs;
61
+
62
+
63
+ // create the unsigned credential
64
+ const unsignedCredential = {
65
+ '@context': [
66
+ 'https://www.w3.org/2018/credentials/v1',
67
+ {
68
+ AlumniCredential: 'https://schema.org#AlumniCredential',
69
+ alumniOf: 'https://schema.org#alumniOf'
70
+ }
71
+ ],
72
+ id: 'http://example.edu/credentials/1872',
73
+ type: [ 'VerifiableCredential', 'AlumniCredential' ],
74
+ issuer: 'https://example.edu/issuers/565049',
75
+ issuanceDate: '2010-01-01T19:23:24Z',
76
+ credentialSubject: {
77
+ id: 'https://example.edu/students/alice',
78
+ alumniOf: 'Example University'
79
+ }
80
+ };
81
+
82
+ // create the keypair to use when signing
83
+ const controller = 'https://example.edu/issuers/565049';
84
+ const keyPair = await Ed25519Multikey.from({
85
+ '@context': 'https://w3id.org/security/multikey/v1',
86
+ type: 'Multikey',
87
+ controller,
88
+ id: controller + '#z6MkwXG2WjeQnNxSoynSGYU8V9j3QzP3JSqhdmkHc6SaVWoT',
89
+ publicKeyMultibase: 'z6MkwXG2WjeQnNxSoynSGYU8V9j3QzP3JSqhdmkHc6SaVWoT',
90
+ secretKeyMultibase: 'zrv3rbPamVDGvrm7LkYPLWYJ35P9audujKKsWn3x29EUiGwwhdZQd' +
91
+ '1iHhrsmZidtVALBQmhX3j9E5Fvx6Kr29DPt6LH'
92
+ });
93
+
94
+ // export public key and add to document loader
95
+ const publicKey = await keyPair.export({publicKey: true, includeContext: true});
96
+ addDocumentToLoader({url: publicKey.id, document: publicKey});
97
+
98
+ // create key's controller document
99
+ const controllerDoc = {
100
+ '@context': [
101
+ 'https://www.w3.org/ns/did/v1',
102
+ 'https://w3id.org/security/multikey/v1'
103
+ ],
104
+ id: controller,
105
+ assertionMethod: [publicKey]
106
+ };
107
+ addDocumentToLoader({url: controllerDoc.id, document: controllerDoc});
108
+
109
+ // create suite
110
+ const suite = new DataIntegrityProof({
111
+ signer: keyPair.signer(), cryptosuite: eddsaRdfc2022CryptoSuite
112
+ });
113
+
114
+ // create signed credential
115
+ const signedCredential = await jsigs.sign(unsignedCredential, {
116
+ suite,
117
+ purpose: new AssertionProofPurpose(),
118
+ documentLoader
119
+ });
120
+
121
+ // results in the following signed VC
122
+ {
123
+ "@context": [
124
+ "https://www.w3.org/2018/credentials/v1",
125
+ {
126
+ "AlumniCredential": "https://schema.org#AlumniCredential",
127
+ "alumniOf": "https://schema.org#alumniOf"
128
+ },
129
+ "https://w3id.org/security/data-integrity/v2"
130
+ ],
131
+ "id": "http://example.edu/credentials/1872",
132
+ "type": [
133
+ "VerifiableCredential",
134
+ "AlumniCredential"
135
+ ],
136
+ "issuer": "https://example.edu/issuers/565049",
137
+ "issuanceDate": "2010-01-01T19:23:24Z",
138
+ "credentialSubject": {
139
+ "id": "https://example.edu/students/alice",
140
+ "alumniOf": "Example University"
141
+ },
142
+ "proof": {
143
+ "type": "DataIntegrityProof",
144
+ "created": "2022-09-06T21:29:24Z",
145
+ "verificationMethod": "https://example.edu/issuers/565049#z6MkwXG2WjeQnNxSoynSGYU8V9j3QzP3JSqhdmkHc6SaVWoT",
146
+ "cryptosuite": "eddsa-rdfc-2022",
147
+ "proofPurpose": "assertionMethod",
148
+ "proofValue": "z4uwHCobmxKqQfZb7i8QRnNR9J4TR6u4Wkm4DB3ms337gfSpL4UwhTD7KKdPjyAaVJQ4y896FEnB1Vz3uEz14jWoC"
149
+ }
150
+ }
151
+ ```
152
+
153
+ ## Contribute
154
+
155
+ See [the contribute file](https://github.com/digitalbazaar/bedrock/blob/master/CONTRIBUTING.md)!
156
+
157
+ PRs accepted.
158
+
159
+ If editing the Readme, please conform to the
160
+ [standard-readme](https://github.com/RichardLitt/standard-readme) specification.
161
+
162
+ ## Commercial Support
163
+
164
+ Commercial support for this library is available upon request from
165
+ Digital Bazaar: support@digitalbazaar.com
166
+
167
+ ## License
168
+
169
+ [New BSD License (3-clause)](LICENSE) © 2023 Digital Bazaar
@@ -0,0 +1,12 @@
1
+ /*!
2
+ * Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ import jsonld from 'jsonld';
5
+
6
+ export function canonize(input, options) {
7
+ return jsonld.canonize(input, {
8
+ algorithm: 'URDNA2015',
9
+ format: 'application/n-quads',
10
+ ...options
11
+ });
12
+ }
@@ -0,0 +1,10 @@
1
+ /*!
2
+ * Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ import * as Ed25519Multikey from '@digitalbazaar/ed25519-multikey';
5
+
6
+ export async function createVerifier({verificationMethod}) {
7
+ const key = await Ed25519Multikey.from(verificationMethod);
8
+ const verifier = key.verifier();
9
+ return verifier;
10
+ }
package/lib/index.js ADDED
@@ -0,0 +1,14 @@
1
+ /*!
2
+ * Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ import {canonize} from './canonize.js';
5
+ import {createVerifier} from './createVerifier.js';
6
+ import {name} from './name.js';
7
+ import {requiredAlgorithm} from './requiredAlgorithm.js';
8
+
9
+ export const cryptosuite = {
10
+ canonize,
11
+ createVerifier,
12
+ name,
13
+ requiredAlgorithm,
14
+ };
package/lib/name.js ADDED
@@ -0,0 +1,4 @@
1
+ /*!
2
+ * Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ export const name = 'eddsa-rdfc-2022';
@@ -0,0 +1,4 @@
1
+ /*!
2
+ * Copyright (c) 2023 Digital Bazaar, Inc. All rights reserved.
3
+ */
4
+ export const requiredAlgorithm = 'Ed25519';
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@digitalbazaar/eddsa-rdfc-2022-cryptosuite",
3
+ "version": "0.0.0",
4
+ "description": "An EdDSA-RDFC-2022 Data Integrity cryptosuite for use with jsonld-signatures.",
5
+ "homepage": "https://github.com/digitalbazaar/eddsa-rdfc-2022-cryptosuite",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/digitalbazaar/eddsa-rdfc-2022-cryptosuite"
9
+ },
10
+ "license": "BSD-3-Clause",
11
+ "type": "module",
12
+ "exports": "./lib/index.js",
13
+ "files": [
14
+ "lib/**/*.js"
15
+ ],
16
+ "dependencies": {
17
+ "@digitalbazaar/ed25519-multikey": "^1.0.0",
18
+ "jsonld": "^8.1.0"
19
+ },
20
+ "devDependencies": {
21
+ "@digitalbazaar/ed25519-verification-key-2018": "^4.0.0",
22
+ "@digitalbazaar/ed25519-verification-key-2020": "^4.1.0",
23
+ "@digitalbazaar/data-integrity": "^2.0.0",
24
+ "@digitalbazaar/data-integrity-context": "^2.0.0",
25
+ "@digitalbazaar/ed25519-multikey": "^1.0.0",
26
+ "@digitalbazaar/multikey-context": "^1.0.0",
27
+ "@digitalbazaar/security-document-loader": "^2.0.0",
28
+ "c8": "^7.11.3",
29
+ "chai": "^4.3.6",
30
+ "cross-env": "^7.0.3",
31
+ "eslint": "^8.53.0",
32
+ "eslint-config-digitalbazaar": "^5.0.1",
33
+ "eslint-plugin-jsdoc": "^46.8.2",
34
+ "eslint-plugin-unicorn": "^49.0.0",
35
+ "jsonld-signatures": "^11.2.1",
36
+ "karma": "^6.3.20",
37
+ "karma-chai": "^0.1.0",
38
+ "karma-chrome-launcher": "^3.1.1",
39
+ "karma-mocha": "^2.0.1",
40
+ "karma-mocha-reporter": "^2.2.5",
41
+ "karma-sourcemap-loader": "^0.3.8",
42
+ "karma-webpack": "^5.0.0",
43
+ "mocha": "^10.0.0",
44
+ "mocha-lcov-reporter": "^1.3.0",
45
+ "webpack": "^5.73.0"
46
+ },
47
+ "engines": {
48
+ "node": ">=18"
49
+ },
50
+ "scripts": {
51
+ "test": "npm run test-node",
52
+ "test-karma": "karma start karma.conf.cjs",
53
+ "test-node": "cross-env NODE_ENV=test mocha --preserve-symlinks -t 30000 -A -R ${REPORTER:-spec} --require test/test-mocha.js test/*.spec.js",
54
+ "coverage": "cross-env NODE_ENV=test c8 npm run test-node",
55
+ "coverage-ci": "cross-env NODE_ENV=test c8 --reporter=lcovonly --reporter=text-summary --reporter=text npm run test-node",
56
+ "coverage-report": "c8 report",
57
+ "lint": "eslint ."
58
+ },
59
+ "c8": {
60
+ "reporter": [
61
+ "lcov",
62
+ "text-summary",
63
+ "text"
64
+ ]
65
+ }
66
+ }