@digitalbazaar/ed25519-signature-2018 2.0.1 → 2.1.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/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # @digitalbazaar/ed25519-signature-2018 Changelog
2
2
 
3
+ ## 2.1.0 - 2022-02-15
4
+
5
+ ### Added
6
+ - Add compatability for 2020 keys.
7
+
3
8
  ## 2.0.1 - 2021-04-15
4
9
 
5
10
  ### Fixed
package/README.md CHANGED
@@ -37,6 +37,15 @@ cd ed25519-signature-2018
37
37
  npm install
38
38
  ```
39
39
 
40
+ ## Tests
41
+
42
+ ```
43
+ npm run test
44
+ ```
45
+
46
+ Note: To run tests for karma, you will need to have Google Chrome installed,
47
+ or otherwise set `CHROME_BIN` environment variable to Chromium.
48
+
40
49
  ## Usage
41
50
 
42
51
  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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitalbazaar/ed25519-signature-2018",
3
- "version": "2.0.1",
3
+ "version": "2.1.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": {
@@ -24,14 +24,17 @@
24
24
  "module": "lib/main.js",
25
25
  "dependencies": {
26
26
  "@digitalbazaar/ed25519-verification-key-2018": "^3.1.1",
27
+ "@digitalbazaar/ed25519-verification-key-2020": "^3.2.0",
27
28
  "@digitalbazaar/jws-linked-data-signature": "^1.0.1",
29
+ "base58-universal": "^1.0.0",
28
30
  "ed25519-signature-2018-context": "^1.0.1",
31
+ "ed25519-signature-2020-context": "^1.1.0",
29
32
  "esm": "^3.2.25",
30
33
  "jsonld": "^5.2.0"
31
34
  },
32
35
  "devDependencies": {
33
- "@transmute/jsonld-document-loader": "^0.2.0",
34
36
  "chai": "^4.2.0",
37
+ "credentials-context": "^2.0.0",
35
38
  "cross-env": "^7.0.2",
36
39
  "did-context": "^3.0.0",
37
40
  "eslint": "^7.6.0",