Skip to content

Commit 02c2492

Browse files
committed
add create proof algorithm
Signed-off-by: PatStLouis <[email protected]>
1 parent 67f25ae commit 02c2492

File tree

8 files changed

+162
-223
lines changed

8 files changed

+162
-223
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@
5555
"base58-universal": "^2.0.0",
5656
"base64url-universal": "^2.0.0",
5757
"chai": "^4.3.7",
58+
"chai-string": "^1.5.0",
5859
"data-integrity-test-suite-assertion": "github:w3c-ccg/data-integrity-test-suite-assertion",
5960
"jsonld-document-loader": "^2.0.0",
61+
"json-canon": "^1.0.1",
6062
"klona": "^2.0.6",
63+
"multibase": "^4.0.6",
6164
"mocha": "^10.2.0",
6265
"uuid": "^9.0.0",
6366
"varint": "^6.0.0",

tests/10-rdfc-create.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright 2023-2024 Digital Bazaar, Inc.
33
* SPDX-License-Identifier: BSD-3-Clause
44
*/
5-
import {createInitialVc, endpointCheck} from './helpers.js';
5+
import {endpointCheck, secureCredential} from './helpers.js';
66
import {
77
shouldBeBs58,
88
shouldBeMulticodecEncoded,
@@ -53,7 +53,7 @@ describe('ecdsa-rdfc-2019 (create)', function() {
5353
let proofs;
5454
const verificationMethodDocuments = [];
5555
before(async function() {
56-
issuedVc = await createInitialVc({
56+
issuedVc = await secureCredential({
5757
issuer,
5858
vc: credentials.create[vcVersion].document,
5959
vcVersion

tests/30-rdfc-interop.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* SPDX-License-Identifier: BSD-3-Clause
44
*/
55
import chai from 'chai';
6-
import {createInitialVc} from './helpers.js';
76
import {endpoints} from 'vc-test-suite-implementations';
87
import {getSuiteConfig} from './test-config.js';
8+
import {secureCredential} from './helpers.js';
99
import {verificationSuccess} from './assertions.js';
1010

1111
const {
@@ -81,7 +81,7 @@ const {
8181
}
8282
let issuedVc;
8383
before(async function() {
84-
issuedVc = await createInitialVc({
84+
issuedVc = await secureCredential({
8585
issuer: issuerEndpoint,
8686
vc: credentials.interop[vcVersion].document,
8787
vcVersion

tests/40-sd-create.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55
import * as ecdsaSd2023Cryptosuite
66
from '@digitalbazaar/ecdsa-sd-2023-cryptosuite';
7-
import {createInitialVc, endpointCheck} from './helpers.js';
7+
import {endpointCheck, secureCredential} from './helpers.js';
88
import {
99
shouldBeBs58,
1010
shouldBeBs64UrlNoPad,
@@ -51,7 +51,7 @@ describe('ecdsa-sd-2023 (create)', function() {
5151
let proofs;
5252
const verificationMethodDocuments = [];
5353
before(async function() {
54-
issuedVc = await createInitialVc({
54+
issuedVc = await secureCredential({
5555
issuer,
5656
vc: credentials.create[vcVersion].document,
5757
mandatoryPointers:

tests/60-sd-interop.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Copyright 2023 Digital Bazaar, Inc.
33
* SPDX-License-Identifier: BSD-3-Clause
44
*/
5-
import {createDisclosedVc, createInitialVc} from './helpers.js';
5+
import {createDisclosedVc, secureCredential} from './helpers.js';
66
import chai from 'chai';
77
import {endpoints} from 'vc-test-suite-implementations';
88
import {getSuiteConfig} from './test-config.js';
@@ -83,7 +83,7 @@ const {
8383
}
8484
let disclosedCredential;
8585
before(async function() {
86-
const issuedVc = await createInitialVc({
86+
const issuedVc = await secureCredential({
8787
issuer: issuerEndpoint,
8888
vc: credentials.interop[vcVersion].document,
8989
mandatoryPointers: credentials.interop[vcVersion].mandatoryPointers,

tests/90-algorithms-jcs.js

Lines changed: 56 additions & 209 deletions
Original file line numberDiff line numberDiff line change
@@ -3,254 +3,101 @@
33
* SPDX-License-Identifier: BSD-3-Clause
44
*/
55
import {
6-
assertIssuedVc,
7-
config,
8-
createInitialVc,
9-
createValidCredential,
6+
assertDataIntegrityProof,
7+
assertSecuredCredential
8+
} from './assertions.js';
9+
import {
10+
baseCredential,
1011
getProofs,
11-
isValidDatetime,
12-
isValidUtf8,
12+
secureCredential,
1313
setupReportableTestSuite,
1414
setupRow
1515
} from './helpers.js';
16+
import canonicalize from 'json-canon';
1617
import chai from 'chai';
1718
import {endpoints} from 'vc-test-suite-implementations';
19+
import {expect} from 'chai';
1820

1921
const should = chai.should();
2022

21-
const cryptosuite = 'ecdsa-jcs-2019';
22-
const {tags} = config.suites[
23-
cryptosuite
23+
const cryptosuites = [
24+
'ecdsa-jcs-2019',
2425
];
26+
2527
const {match: issuers} = endpoints.filterByTag({
26-
tags: [...tags],
28+
tags: cryptosuites,
2729
property: 'issuers'
2830
});
2931

30-
describe('ecdsa-jcs-2019 - Algorithms - Create Proof', function() {
31-
setupReportableTestSuite(this);
32-
this.implemented = [...issuers.keys()];
33-
let validCredential;
34-
before(async function() {
35-
validCredential = await createValidCredential();
36-
});
37-
for(const [columnId, {endpoints}] of issuers) {
38-
describe(columnId, function() {
39-
const [issuer] = endpoints;
40-
let issuedVc;
41-
let proofs;
42-
let filteredProofs = [];
43-
before(async function() {
44-
issuedVc = await createInitialVc({issuer, vc: validCredential});
45-
proofs = getProofs(issuedVc);
46-
if(proofs?.length) {
47-
filteredProofs = proofs.filter(
48-
proof => proof?.cryptosuite === cryptosuite);
49-
}
50-
});
51-
beforeEach(setupRow);
52-
it('If unsecuredDocument.@context is present, ' +
53-
'set proof.@context to unsecuredDocument.@context.',
54-
async function() {
55-
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#create-proof-ecdsa-jcs-2019';
56-
assertIssuedVc(issuedVc, proofs, filteredProofs);
57-
for(const proof of filteredProofs) {
58-
proof.should.have('@context',
59-
'Expected proof to have context.');
60-
}
61-
});
62-
});
63-
}
64-
});
65-
66-
describe('ecdsa-jcs-2019 - Algorithms - Transformation', function() {
67-
setupReportableTestSuite(this);
68-
this.implemented = [...issuers.keys()];
69-
let validCredential;
70-
before(async function() {
71-
validCredential = await createValidCredential();
72-
});
73-
for(const [columnId, {endpoints}] of issuers) {
74-
describe(columnId, function() {
75-
const [issuer] = endpoints;
76-
let issuedVc;
77-
let proofs;
78-
let filteredProofs = [];
79-
before(async function() {
80-
issuedVc = await createInitialVc({issuer, vc: validCredential});
81-
proofs = getProofs(issuedVc);
82-
if(proofs?.length) {
83-
filteredProofs = proofs.filter(
84-
proof => proof?.cryptosuite === cryptosuite);
85-
}
86-
});
87-
beforeEach(setupRow);
88-
it('The proof options MUST contain a type identifier for the ' +
89-
'cryptographic suite (type) and MAY contain a cryptosuite ' +
90-
'identifier (cryptosuite).',
91-
async function() {
92-
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-serialization-ecdsa-jcs-2019';
93-
assertIssuedVc(issuedVc, proofs, filteredProofs);
94-
for(const proof of filteredProofs) {
95-
should.exist(proof.type,
96-
'Expected a type identifier on the proof.');
97-
}
98-
});
99-
it('The transformation options MUST contain a type identifier ' +
100-
'for the cryptographic suite (type) and a cryptosuite identifier ' +
101-
'(cryptosuite).',
102-
async function() {
103-
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-jcs-2019';
104-
assertIssuedVc(issuedVc, proofs, filteredProofs);
105-
for(const proof of filteredProofs) {
106-
should.exist(proof.type, 'Expected a type identifier on ' +
107-
'the proof.');
108-
should.exist(proof.cryptosuite,
109-
'Expected a cryptosuite identifier on the proof.');
110-
}
111-
});
112-
it('Whenever this algorithm encodes strings, ' +
113-
'it MUST use UTF-8 encoding.',
114-
async function() {
115-
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-jcs-2019';
116-
assertIssuedVc(issuedVc, proofs, filteredProofs);
117-
for(const proof of filteredProofs) {
118-
should.exist(proof?.proofValue,
119-
'Expected proofValue to exist.');
120-
isValidUtf8(proof.proofValue).should.equal(
121-
true,
122-
'Expected proofValue value to be a valid UTF-8 encoded string.'
123-
);
124-
}
125-
});
126-
it('If options.type is not set to the string DataIntegrityProof or ' +
127-
'options.cryptosuite is not set to the string ecdsa-jcs-2019, ' +
128-
'an error MUST be raised and SHOULD convey an error type ' +
129-
'of PROOF_TRANSFORMATION_ERROR.',
130-
async function() {
131-
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-jcs-2019';
132-
assertIssuedVc(issuedVc, proofs, filteredProofs);
133-
for(const proof of filteredProofs) {
134-
should.exist(proof.type,
135-
'Expected a type identifier on the proof.');
136-
should.exist(proof.cryptosuite,
137-
'Expected a cryptosuite identifier on the proof.');
138-
proof.type.should.equal('DataIntegrityProof',
139-
'Expected DataIntegrityProof type.');
140-
proof.cryptosuite.should.equal('ecdsa-jcs-2019',
141-
'Expected ecdsa-jcs-2019 cryptosuite.');
142-
}
143-
});
144-
});
145-
}
32+
const {match: verifiers} = endpoints.filterByTag({
33+
tags: cryptosuites,
34+
property: 'verifiers'
14635
});
14736

148-
describe('ecdsa-jcs-2019 - Algorithms - Proof Configuration', function() {
37+
describe('Create Proof (ecdsa-jcs-2019)', function() {
14938
setupReportableTestSuite(this);
15039
this.implemented = [...issuers.keys()];
151-
let validCredential;
152-
before(async function() {
153-
validCredential = await createValidCredential();
154-
});
15540
for(const [columnId, {endpoints}] of issuers) {
15641
describe(columnId, function() {
15742
const [issuer] = endpoints;
158-
let issuedVc;
159-
let proofs;
160-
let filteredProofs = [];
43+
let securedCredential;
44+
let proof;
16145
before(async function() {
162-
issuedVc = await createInitialVc({issuer, vc: validCredential});
163-
proofs = getProofs(issuedVc);
164-
if(proofs?.length) {
165-
filteredProofs = proofs.filter(
166-
proof => proof?.cryptosuite === cryptosuite);
167-
}
46+
securedCredential = await secureCredential(
47+
{issuer, vc: baseCredential()});
48+
proof = getProofs(securedCredential)[0];
16849
});
16950
beforeEach(setupRow);
170-
it('The proof options MUST contain a type identifier for the ' +
171-
'cryptographic suite (type) and MUST contain a cryptosuite ' +
172-
'identifier (cryptosuite).',
51+
it('The following algorithm specifies how to create a ' +
52+
'data integrity proof given an unsecured data document. ' +
53+
'Required inputs are an unsecured data document ' +
54+
'(map unsecuredDocument), and a set of proof options ' +
55+
'(map options). A data integrity proof (map), or an error, ' +
56+
'is produced as output.',
17357
async function() {
174-
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-jcs-2019';
175-
assertIssuedVc(issuedVc, proofs, filteredProofs);
176-
for(const proof of filteredProofs) {
177-
should.exist(proof.type,
178-
'Expected a type identifier on the proof.');
179-
should.exist(proof.cryptosuite,
180-
'Expected a cryptosuite identifier on the proof.');
181-
}
58+
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#create-proof-ecdsa-jcs-2019';
59+
assertSecuredCredential(securedCredential);
60+
assertDataIntegrityProof(proof, 'ecdsa-jcs-2019');
18261
});
183-
it('If proofConfig.type is not set to DataIntegrityProof ' +
184-
'and/or proofConfig.cryptosuite is not set to ecdsa-jcs-2019, ' +
185-
'an error MUST be raised and SHOULD convey an error type ' +
186-
'of PROOF_GENERATION_ERROR.',
62+
it('If unsecuredDocument.@context is present, ' +
63+
'set proof.@context to unsecuredDocument.@context.',
18764
async function() {
188-
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-jcs-2019';
189-
assertIssuedVc(issuedVc, proofs, filteredProofs);
190-
for(const proof of filteredProofs) {
191-
should.exist(proof.type,
192-
'Expected a type identifier on the proof.');
193-
should.exist(proof.cryptosuite,
194-
'Expected a cryptosuite identifier on the proof.');
195-
proof.type.should.equal('DataIntegrityProof',
196-
'Expected DataIntegrityProof type.');
197-
proof.cryptosuite.should.equal('ecdsa-jcs-2019',
198-
'Expected ecdsa-jcs-2019 cryptosuite.');
199-
}
65+
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#create-proof-ecdsa-jcs-2019';
66+
should.exist(proof['@context'],
67+
'Expected proof to have context.');
68+
canonicalize(proof['@context']).should.equal(
69+
canonicalize(securedCredential['@context']),
70+
'Expected proof context to match document context.'
71+
);
20072
});
201-
it('If proofConfig.created is set and if the value is not a ' +
202-
'valid [XMLSCHEMA11-2] datetime, an error MUST be raised and ' +
203-
'SHOULD convey an error type of PROOF_GENERATION_ERROR.',
73+
it('Let proof.proofValue be a base58-btc-encoded ' +
74+
'Multibase value of the proofBytes.',
20475
async function() {
205-
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-configuration-ecdsa-jcs-2019';
206-
assertIssuedVc(issuedVc, proofs, filteredProofs);
207-
for(const proof of filteredProofs) {
208-
if(proof?.created) {
209-
isValidDatetime(proof.created).should.equal(
210-
true,
211-
'Expected created value to be a valid datetime string.'
212-
);
213-
}
214-
}
76+
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#create-proof-ecdsa-jcs-2019';
77+
should.exist(proof.proofValue,
78+
'Expected proof to have proofValue.');
79+
expect(proof.proofValue.startsWith('z')).to.be.true;
21580
});
21681
});
21782
}
21883
});
21984

220-
describe('ecdsa-jcs-2019 - Algorithms - Proof Serialization', function() {
85+
describe('Algorithms - Verify Proof (ecdsa-jcs-2019)', function() {
22186
setupReportableTestSuite(this);
222-
this.implemented = [...issuers.keys()];
223-
let validCredential;
224-
before(async function() {
225-
validCredential = await createValidCredential();
226-
});
227-
for(const [columnId, {endpoints}] of issuers) {
87+
for(const [columnId, {endpoints}] of verifiers) {
22888
describe(columnId, function() {
229-
const [issuer] = endpoints;
230-
let issuedVc;
231-
let proofs;
232-
let filteredProofs = [];
89+
const [issuer] = issuers.get(columnId).endpoints;
90+
const [verifier] = endpoints;
91+
let securedCredential;
23392
before(async function() {
234-
issuedVc = await createInitialVc({issuer, vc: validCredential});
235-
proofs = getProofs(issuedVc);
236-
if(proofs?.length) {
237-
filteredProofs = proofs.filter(
238-
proof => proof?.cryptosuite === cryptosuite);
239-
}
93+
securedCredential = await secureCredential(
94+
{issuer, vc: baseCredential()});
24095
});
24196
beforeEach(setupRow);
242-
it('The proof options MUST contain a type identifier for the ' +
243-
'cryptographic suite (type) and MAY contain a cryptosuite identifier ' +
244-
'(cryptosuite).',
245-
async function() {
246-
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#proof-serialization-ecdsa-jcs-2019';
247-
assertIssuedVc(issuedVc, proofs, filteredProofs);
248-
for(const proof of filteredProofs) {
249-
should.exist(proof.type,
250-
'Expected a type identifier on the proof.');
251-
}
252-
});
97+
it('',
98+
async function() {
99+
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#verify-proof-ecdsa-rdfc-2019';
100+
});
253101
});
254102
}
255103
});
256-

0 commit comments

Comments
 (0)