@digitalbazaar/ed25519-signature-2018 2.0.0 → 3.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 CHANGED
@@ -27,7 +27,13 @@ TBD
27
27
 
28
28
  ## Install
29
29
 
30
- - Node.js 12+ is required.
30
+ - Browsers and Node.js 14+ are supported.
31
+
32
+ To install from NPM:
33
+
34
+ ```
35
+ npm install @digitalbazaar/ed25519-signature-2018
36
+ ```
31
37
 
32
38
  To install locally (for development):
33
39
 
@@ -37,6 +43,15 @@ cd ed25519-signature-2018
37
43
  npm install
38
44
  ```
39
45
 
46
+ ## Tests
47
+
48
+ ```
49
+ npm run test
50
+ ```
51
+
52
+ Note: To run tests for karma, you will need to have Google Chrome installed,
53
+ or otherwise set `CHROME_BIN` environment variable to Chromium.
54
+
40
55
  ## Usage
41
56
 
42
57
  TBD
@@ -1,15 +1,24 @@
1
1
  /*!
2
2
  * Copyright (c) 2020-2021 Digital Bazaar, Inc. All rights reserved.
3
3
  */
4
+ import * as base58btc from 'base58-universal';
4
5
  import jsonld from 'jsonld';
5
6
  import {JwsLinkedDataSignature} from '@digitalbazaar/jws-linked-data-signature';
6
7
  import {
7
8
  Ed25519VerificationKey2018
8
9
  } from '@digitalbazaar/ed25519-verification-key-2018';
10
+ import {
11
+ Ed25519VerificationKey2020
12
+ } from '@digitalbazaar/ed25519-verification-key-2020';
9
13
 
10
- import suiteContext from 'ed25519-signature-2018-context';
14
+ import ed25519Signature2018SuiteContext from 'ed25519-signature-2018-context';
15
+ import ed25519Signature2020SuiteContext from 'ed25519-signature-2020-context';
11
16
  // 'https://w3id.org/security/suites/ed25519-2018/v1'
12
- const SUITE_CONTEXT_URL = suiteContext.constants.CONTEXT_URL;
17
+ const SUITE_CONTEXT_URL = ed25519Signature2018SuiteContext.constants
18
+ .CONTEXT_URL;
19
+ // 'https://w3id.org/security/suites/ed25519-2020/v1'
20
+ const SUITE_CONTEXT_URL_2020 =
21
+ ed25519Signature2020SuiteContext.constants.CONTEXT_URL;
13
22
 
14
23
  export class Ed25519Signature2018 extends JwsLinkedDataSignature {
15
24
  /**
@@ -57,7 +66,8 @@ export class Ed25519Signature2018 extends JwsLinkedDataSignature {
57
66
  );
58
67
  }
59
68
 
60
- if(!jsonld.hasValue(verificationMethod, 'type', this.requiredKeyType)) {
69
+ if(!(_isEd2018Key({verificationMethod}) ||
70
+ _isEd2020Key({verificationMethod}))) {
61
71
  throw new Error(
62
72
  `Invalid key type. Key type must be "${this.requiredKeyType}".`);
63
73
  }
@@ -68,6 +78,29 @@ export class Ed25519Signature2018 extends JwsLinkedDataSignature {
68
78
  }
69
79
  }
70
80
 
81
+ async getVerificationMethod({proof, documentLoader}) {
82
+ const verificationMethod = await super.getVerificationMethod(
83
+ {proof, documentLoader});
84
+
85
+ // convert Ed25519VerificationKey2020 to Ed25519VerificationKey2018
86
+ if(_isEd2020Key({verificationMethod})) {
87
+ const key2020 = await Ed25519VerificationKey2020.from(
88
+ verificationMethod);
89
+
90
+ const key2018 = key2020.export({publicKey: true, context: true});
91
+
92
+ // remove 2020 public key representation
93
+ delete key2018.publicKeyMultibase;
94
+
95
+ // create 2018 public key representation
96
+ key2018.publicKeyBase58 = base58btc.encode(key2020._publicKeyBuffer);
97
+
98
+ return key2018;
99
+ }
100
+
101
+ return verificationMethod;
102
+ }
103
+
71
104
  /**
72
105
  * Ensures the document to be signed contains the required signature suite
73
106
  * specific `@context`, by either adding it (if `addSuiteContext` is true),
@@ -126,6 +159,9 @@ function _includesCompatibleContext({document}) {
126
159
  const hasEd2018 = _includesContext({
127
160
  document, contextUrl: SUITE_CONTEXT_URL
128
161
  });
162
+ const hasEd2020 = _includesContext({
163
+ document, contextUrl: SUITE_CONTEXT_URL_2020
164
+ });
129
165
  const hasCred = _includesContext({document, contextUrl: CRED_CONTEXT});
130
166
  const hasSecV2 = _includesContext({document, contextUrl: SECURITY_CONTEXT});
131
167
 
@@ -148,7 +184,7 @@ function _includesCompatibleContext({document}) {
148
184
  }
149
185
 
150
186
  // Either one by itself is fine, for this suite
151
- return hasEd2018 || hasCred || hasSecV2;
187
+ return hasEd2018 || hasEd2020 || hasCred || hasSecV2;
152
188
  }
153
189
 
154
190
  /**
@@ -167,5 +203,22 @@ function _includesContext({document, contextUrl}) {
167
203
  (Array.isArray(context) && context.includes(contextUrl));
168
204
  }
169
205
 
206
+ function _isEd2018Key({verificationMethod}) {
207
+ const hasEd2018 = _includesContext({
208
+ document: verificationMethod, contextUrl: SUITE_CONTEXT_URL
209
+ });
210
+ return hasEd2018 && jsonld.hasValue(
211
+ verificationMethod, 'type', 'Ed25519VerificationKey2018');
212
+ }
213
+
214
+ function _isEd2020Key({verificationMethod}) {
215
+ const hasEd2020 = _includesContext({
216
+ document: verificationMethod, contextUrl: SUITE_CONTEXT_URL_2020
217
+ });
218
+ return hasEd2020 && jsonld.hasValue(
219
+ verificationMethod, 'type', 'Ed25519VerificationKey2020');
220
+ }
221
+
170
222
  Ed25519Signature2018.CONTEXT_URL = SUITE_CONTEXT_URL;
171
- Ed25519Signature2018.CONTEXT = suiteContext.contexts.get(SUITE_CONTEXT_URL);
223
+ Ed25519Signature2018.CONTEXT = ed25519Signature2018SuiteContext
224
+ .contexts.get(SUITE_CONTEXT_URL);
package/lib/index.js CHANGED
@@ -1,8 +1,7 @@
1
1
  /*!
2
2
  * Copyright (c) 2020-2021 Digital Bazaar, Inc. All rights reserved.
3
3
  */
4
- 'use strict';
4
+ import suiteContext from 'ed25519-signature-2018-context';
5
5
 
6
- // translate `main.js` to CommonJS
7
- require = require('esm')(module);
8
- module.exports = require('./main.js');
6
+ export {Ed25519Signature2018} from './Ed25519Signature2018.js';
7
+ export {suiteContext};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalbazaar/ed25519-signature-2018",
3
- "version": "2.0.0",
3
+ "version": "3.0.0",
4
4
  "description": "Ed25519Signature2018 Linked Data Proof suite for use with jsonld-signatures.",
5
5
  "homepage": "https://github.com/digitalbazaar/ed25519-signature-2018",
6
6
  "author": {
@@ -17,67 +17,63 @@
17
17
  "email": "support@digitalbazaar.com"
18
18
  },
19
19
  "license": "BSD-3-Clause",
20
- "main": "lib/index.js",
20
+ "type": "module",
21
+ "exports": "./lib/index.js",
21
22
  "files": [
22
- "lib/*.js"
23
+ "lib/**/*.js"
23
24
  ],
24
- "module": "lib/main.js",
25
25
  "dependencies": {
26
- "@digitalbazaar/ed25519-verification-key-2018": "^3.1.1",
27
- "@digitalbazaar/jws-linked-data-signature": "^1.0.1",
28
- "esm": "^3.2.25",
29
- "jsonld": "^5.2.0"
26
+ "@digitalbazaar/ed25519-verification-key-2018": "^4.0.0",
27
+ "@digitalbazaar/ed25519-verification-key-2020": "^4.0.0",
28
+ "@digitalbazaar/jws-linked-data-signature": "^2.0.0",
29
+ "base58-universal": "^2.0.0",
30
+ "ed25519-signature-2018-context": "^1.1.0",
31
+ "ed25519-signature-2020-context": "^1.1.0",
32
+ "jsonld": "^6.0.0"
30
33
  },
31
34
  "devDependencies": {
32
- "@transmute/jsonld-document-loader": "^0.2.0",
33
- "chai": "^4.2.0",
34
- "cross-env": "^7.0.2",
35
- "did-context": "^3.0.0",
36
- "ed25519-signature-2018-context": "^1.0.1",
37
- "eslint": "^7.6.0",
38
- "eslint-config-digitalbazaar": "^2.6.1",
39
- "eslint-plugin-jsdoc": "^32.3.0",
40
- "jsonld-signatures": "^9.0.2",
41
- "karma": "^5.1.1",
35
+ "c8": "^7.11.3",
36
+ "chai": "^4.3.6",
37
+ "credentials-context": "^2.0.0",
38
+ "cross-env": "^7.0.3",
39
+ "did-context": "^3.1.1",
40
+ "eslint": "^8.17.0",
41
+ "eslint-config-digitalbazaar": "^3.0.0",
42
+ "eslint-plugin-jsdoc": "^39.3.2",
43
+ "eslint-plugin-unicorn": "^42.0.0",
44
+ "jsonld-signatures": "^10.0.0",
45
+ "karma": "^6.3.20",
42
46
  "karma-chai": "^0.1.0",
43
- "karma-chrome-launcher": "^3.1.0",
47
+ "karma-chrome-launcher": "^3.1.1",
44
48
  "karma-mocha": "^2.0.1",
45
49
  "karma-mocha-reporter": "^2.2.5",
46
- "karma-sourcemap-loader": "^0.3.7",
47
- "karma-webpack": "^4.0.2",
48
- "mocha": "^8.1.1",
50
+ "karma-sourcemap-loader": "^0.3.8",
51
+ "karma-webpack": "^5.0.0",
52
+ "mocha": "^10.0.0",
49
53
  "mocha-lcov-reporter": "^1.3.0",
50
- "nyc": "^15.1.0",
51
- "webpack": "^4.44.1"
54
+ "webpack": "^5.73.0"
52
55
  },
53
- "nyc": {
54
- "exclude": [
55
- "test"
56
- ],
56
+ "c8": {
57
57
  "reporter": [
58
- "html",
59
- "text-summary"
58
+ "lcov",
59
+ "text-summary",
60
+ "text"
60
61
  ]
61
62
  },
62
- "browser": {
63
- "buffer": false,
64
- "crypto": false,
65
- "util": false
66
- },
67
63
  "engines": {
68
- "node": ">=12"
64
+ "node": ">=14"
69
65
  },
70
66
  "keywords": [
71
67
  "Decentralized",
72
68
  "Linked Data"
73
69
  ],
74
70
  "scripts": {
75
- "test": "npm run lint && npm run test-node && npm run test-karma",
76
- "test-karma": "karma start karma.conf.js",
77
- "test-node": "cross-env NODE_ENV=test mocha -r esm --preserve-symlinks -t 30000 -R ${REPORTER:-spec} test/*.spec.js",
78
- "coverage": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text-summary npm run test-node",
79
- "coverage-ci": "cross-env NODE_ENV=test nyc --reporter=lcovonly npm run test-node",
80
- "coverage-report": "nyc report",
71
+ "test": "npm run test-node",
72
+ "test-karma": "karma start test/karma.conf.cjs",
73
+ "test-node": "cross-env NODE_ENV=test mocha --preserve-symlinks -t 30000 -R ${REPORTER:-spec} test/*.spec.js",
74
+ "coverage": "cross-env NODE_ENV=test c8 npm run test-node",
75
+ "coverage-ci": "cross-env NODE_ENV=test c8 --reporter=lcovonly --reporter=text-summary --reporter=text npm run test-node",
76
+ "coverage-report": "c8 report",
81
77
  "lint": "eslint ."
82
78
  }
83
79
  }
package/CHANGELOG.md DELETED
@@ -1,19 +0,0 @@
1
- # @digitalbazaar/ed25519-signature-2018 Changelog
2
-
3
- ## 2.0.0 - 2021-04-12
4
-
5
- ### Changed
6
- - **BREAKING**: Update to `jsonld-signatures` v9 dependency (which removes the
7
- `verificationMethod` param from suite constructor. It is now strictly
8
- initialized from `key.id` or `signer.id`. Also increases validation on either
9
- key or signer/verifier parameters.)
10
- - Enable this suite to enforce compatible contexts on `sign()`.
11
-
12
- ### Fixed
13
- - Add missing `signer` and `verifier` parameters to the `LinkedDataSignature`
14
- constructor. This issue caused `this.signer` in subclasses to be `undefined`.
15
-
16
- ## 1.0.0 - 2021-03-18
17
-
18
- ### Added
19
- - Initial files extracted from https://github.com/digitalbazaar/jsonld-signatures.
package/lib/main.js DELETED
@@ -1,7 +0,0 @@
1
- /*!
2
- * Copyright (c) 2020-2021 Digital Bazaar, Inc. All rights reserved.
3
- */
4
- import suiteContext from 'ed25519-signature-2018-context';
5
-
6
- export {Ed25519Signature2018} from './Ed25519Signature2018.js';
7
- export {suiteContext};