Skip to content

Commit 342b59a

Browse files
committed
Add mandatoryPointers test
Signed-off-by: PatStLouis <[email protected]>
1 parent 59961a1 commit 342b59a

File tree

3 files changed

+51
-8
lines changed

3 files changed

+51
-8
lines changed

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@
5454
"@digitalcredentials/did-context": "^1.0.0",
5555
"base58-universal": "^2.0.0",
5656
"base64url-universal": "^2.0.0",
57+
"cbor": "^10.0.3",
5758
"chai": "^4.3.7",
5859
"chai-string": "^1.5.0",
5960
"data-integrity-test-suite-assertion": "github:w3c-ccg/data-integrity-test-suite-assertion",
6061
"jsonld-document-loader": "^2.2.0",
6162
"json-canon": "^1.0.1",
6263
"klona": "^2.0.6",
6364
"multibase": "^4.0.6",
65+
"multiformats": "^13.3.1",
6466
"mocha": "^10.2.0",
6567
"uuid": "^9.0.0",
6668
"varint": "^6.0.0",

tests/90-algorithms-sd.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
} from './assertions.js';
1010
import {
1111
generateCredential,
12+
inspectSdProofValue,
1213
isValidDatetime,
1314
proofExists,
1415
secureCredential,
@@ -43,16 +44,17 @@ describe('Algorithms - Create Base Proof (ecdsa-sd-2023)', function() {
4344
const [issuer] = endpoints;
4445
let securedCredential;
4546
before(async function() {
47+
const mandatoryPointers = ['/credentialSubject/name'];
4648
securedCredential = await secureCredential(
47-
{issuer, vc: generateCredential()});
49+
{issuer, vc: generateCredential(), mandatoryPointers});
4850
});
4951
beforeEach(setupRow);
5052
it('A data integrity proof (map), or an error, is produced as output.',
5153
async function() {
5254
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#create-proof-ecdsa-sd-2023';
5355
const proof = proofExists(securedCredential);
54-
assertDataIntegrityProof(proof, 'ecdsa-sd-2023');
55-
// Since we are not sending proof options, we only do a positive test
56+
assertDataIntegrityProof(proof);
57+
// We only do a positive test
5658
});
5759
it('Let proof.proofValue be a base64-url-encoded ' +
5860
'Multibase value of the proofBytes.',
@@ -77,8 +79,9 @@ describe('Algorithms - Base Proof Transformation (ecdsa-sd-2023)', function() {
7779
const [issuer] = endpoints;
7880
let securedCredential;
7981
before(async function() {
82+
const mandatoryPointers = ['/credentialSubject/name'];
8083
securedCredential = await secureCredential(
81-
{issuer, vc: generateCredential()});
84+
{issuer, vc: generateCredential(), mandatoryPointers});
8285
});
8386
beforeEach(setupRow);
8487
it('The transformation options MUST contain a type identifier for the ' +
@@ -99,7 +102,14 @@ describe('Algorithms - Base Proof Transformation (ecdsa-sd-2023)', function() {
99102
'options, such as a JSON-LD document loader.',
100103
async function() {
101104
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-sd-2023';
102-
this.skip();
105+
// Send an issuance request without mandatoryPointers
106+
const securedCredentialNoPointers = await secureCredential(
107+
{issuer, vc: generateCredential()});
108+
const proof = proofExists(securedCredentialNoPointers);
109+
const decodedProof =
110+
await inspectSdProofValue(proof);
111+
should.exist(decodedProof.mandatoryPointers,
112+
'Expected mandatoryPointers to be included in the proofValue.');
103113
});
104114
it('Whenever this algorithm encodes strings, it MUST use UTF-8 encoding.',
105115
async function() {
@@ -112,7 +122,11 @@ describe('Algorithms - Base Proof Transformation (ecdsa-sd-2023)', function() {
112122
'or 32 bytes.',
113123
async function() {
114124
this.test.link = 'https://www.w3.org/TR/vc-di-ecdsa/#transformation-ecdsa-sd-2023';
115-
this.skip();
125+
const proof = proofExists(securedCredential);
126+
const decodedProof = await inspectSdProofValue(proof);
127+
decodedProof.hmacKey.length.should.equal(32,
128+
'Expected HMAC key to be the same length as the digest size.'
129+
);
116130
});
117131
});
118132
}
@@ -126,8 +140,9 @@ describe('Algorithms - Base Proof Configuration (ecdsa-sd-2023)', function() {
126140
const [issuer] = endpoints;
127141
let securedCredential;
128142
before(async function() {
143+
const mandatoryPointers = ['/credentialSubject/name'];
129144
securedCredential = await secureCredential(
130-
{issuer, vc: generateCredential()});
145+
{issuer, vc: generateCredential(), mandatoryPointers});
131146
});
132147
it('The proof options MUST contain a type identifier for the ' +
133148
'cryptographic suite (type) and MUST contain a cryptosuite ' +
@@ -174,8 +189,9 @@ describe('Algorithms - Base Proof Serialization (ecdsa-sd-2023)', function() {
174189
const [issuer] = endpoints;
175190
let securedCredential;
176191
before(async function() {
192+
const mandatoryPointers = ['/credentialSubject/name'];
177193
securedCredential = await secureCredential(
178-
{issuer, vc: generateCredential()});
194+
{issuer, vc: generateCredential(), mandatoryPointers});
179195
});
180196
beforeEach(setupRow);
181197
it('The proof options MUST contain a type identifier for the ' +

tests/helpers.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,15 @@ import * as bs58 from 'base58-universal';
66
import * as bs64 from 'base64url-universal';
77
import * as didKey from '@digitalbazaar/did-method-key';
88
import * as EcdsaMultikey from '@digitalbazaar/ecdsa-multikey';
9+
import {base64url} from 'multiformats/bases/base64';
10+
import {bases} from 'multiformats/basics';
911
import {CachedResolver} from '@digitalbazaar/did-io';
12+
import cbor from 'cbor';
1013
import chai from 'chai';
14+
import {CID} from 'multiformats/cid';
1115
import {createRequire} from 'node:module';
1216
import {contexts as credContexts} from '@digitalbazaar/credentials-context';
17+
import {expect} from 'chai';
1318
import {isUtf8} from 'node:buffer';
1419
import {JsonLdDocumentLoader} from 'jsonld-document-loader';
1520
import {klona} from 'klona';
@@ -347,3 +352,23 @@ export async function multikeyFromVerificationMethod(
347352
}
348353
return null;
349354
}
355+
356+
export async function inspectSdProofValue(proof) {
357+
const proofValue = proof.proofValue;
358+
expect(proof.proofValue.startsWith('u')).to.be.true;
359+
const cborProof = bases.base64url.decode(proofValue);
360+
const decodedProof = await cbor.decodeFirst(cborProof, (error, obj) => {
361+
return obj;
362+
});
363+
const decodedProofValues = decodedProof.value;
364+
decodedProofValues.length.should.equal(5,
365+
'Expected decoded proof value to be of length 5.'
366+
);
367+
return {
368+
baseSignature: decodedProofValues[0],
369+
publicKey: decodedProofValues[1],
370+
hmacKey: decodedProofValues[2],
371+
signatures: decodedProofValues[3],
372+
mandatoryPointers: decodedProofValues[4]
373+
};
374+
}

0 commit comments

Comments
 (0)